Handle file url
This commit is contained in:
parent
2dfbf78259
commit
d0a0e2499d
84
src/main.c
84
src/main.c
|
@ -14,15 +14,85 @@ static void makeRender (FILE *file);
|
||||||
static void
|
static void
|
||||||
loadPage (const char *link)
|
loadPage (const char *link)
|
||||||
{
|
{
|
||||||
FILE *file = tmpfile ();
|
char *cursor = strchr (link, ':');
|
||||||
if (file != NULL)
|
|
||||||
{
|
|
||||||
GEM_send_request ("gemini://rdelaage.ovh\r\n", "rdelaage.ovh:1965", file);
|
|
||||||
makeRender (file);
|
|
||||||
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL);
|
|
||||||
|
|
||||||
fclose (file);
|
if (cursor == NULL)
|
||||||
|
{
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
addH1 (render, "Invalid URL !");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int len = cursor - link;
|
||||||
|
char scheme[30];
|
||||||
|
strncpy (scheme, link, len);
|
||||||
|
scheme[len] = '\0';
|
||||||
|
|
||||||
|
if (strcmp (scheme, "gemini") == 0)
|
||||||
|
{
|
||||||
|
FILE *file = tmpfile ();
|
||||||
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
GEM_send_request ("gemini://rdelaage.ovh\r\n", "rdelaage.ovh:1965", file);
|
||||||
|
makeRender (file);
|
||||||
|
|
||||||
|
fclose (file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
addH1 (render, "Failed to open a temp file !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strcmp (scheme, "file") == 0)
|
||||||
|
{
|
||||||
|
cursor++;
|
||||||
|
len = strlen (cursor);
|
||||||
|
|
||||||
|
if (len >= 2 && cursor[0] == '/' && cursor[1] != '/')
|
||||||
|
{
|
||||||
|
FILE *file = fopen (cursor, "r");
|
||||||
|
|
||||||
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
makeRender (file);
|
||||||
|
fclose (file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
addH1 (render, "Failed to open the file !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (len > 3 && cursor[0] == '/' && cursor[1] == '/' && cursor[2] == '/')
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
cursor += 2;
|
||||||
|
file = fopen (cursor, "r");
|
||||||
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
makeRender (file);
|
||||||
|
fclose (file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
addH1 (render, "Failed to open the file !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
addH1 (render, "File url not supported !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
addH1 (render, "This type of URL is not supported yet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue