From d4186faa095c808548294f3d087f28dd4aaca624 Mon Sep 17 00:00:00 2001 From: anthony Date: Sat, 21 Nov 2020 15:14:19 +0000 Subject: [PATCH] fetch mimetype and missing fetch resource path --- frontends/gnustep/AppDelegate.m | 2 ++ frontends/gnustep/tables/fetch.m | 44 +++++++++++++++++++++++++++----- frontends/gnustep/tables/misc.m | 6 ++--- frontends/gtk/schedule.c | 2 ++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/frontends/gnustep/AppDelegate.m b/frontends/gnustep/AppDelegate.m index 808f8865d..8cc184d4f 100644 --- a/frontends/gnustep/AppDelegate.m +++ b/frontends/gnustep/AppDelegate.m @@ -3,6 +3,7 @@ #import "netsurf/netsurf.h" #import "utils/nsoption.h" #import "utils/nsurl.h" +#import "utils/log.h" #import "AppDelegate.h" #import "BrowserWindowController.h" @@ -58,6 +59,7 @@ static nserror set_defaults(struct nsoption_s *defaults) int main(int argc, char **argv) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; + nslog_init(NULL, &argc, argv); nserror error; struct netsurf_table gnustep_table = { .misc = &gnustep_misc_table, diff --git a/frontends/gnustep/tables/fetch.m b/frontends/gnustep/tables/fetch.m index 2eb5509b7..c8fc63b4d 100644 --- a/frontends/gnustep/tables/fetch.m +++ b/frontends/gnustep/tables/fetch.m @@ -1,8 +1,10 @@ #import - -#import "netsurf/netsurf.h" +#import +#import +#import "utils/url.h" #import "netsurf/fetch.h" + /*******************/ /****** Fetch ******/ /*******************/ @@ -10,11 +12,41 @@ // Return the MIME type of the specified file. Returned string can be inval on next req. static const char *gnustep_fetch_filetype(const char *unix_path) { NSLog(@"gnustep_fetch_filetype"); - static char filetype[100]; - filetype[0] = '\0'; - return filetype; + char *bnam; + char *ext; + + bnam = basename(unix_path); + ext = strrchr(bnam, '.'); + if (ext == NULL) { + return "text/html"; + } + ext += 1; + + if (strncmp(ext, "css", 3) == 0) { + return "text/css"; + } else if (strncmp(ext, "jpeg", 4) == 0 || strncmp(ext, "jpg", 3) == 0) { + return "image/jpeg"; + } else if (strncmp(ext, "gif", 3) == 0) { + return "image/gif"; + } else if (strncmp(ext, "png", 3) == 0) { + return "image/png"; + } else { + return "text/html"; + } +} + +static const char *gnustep_fetch_get_resource_url(const char *path) { + struct nsurl *url = NULL; + NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString + stringWithUTF8String: path] ofType: @""]; + if (nspath == nil) { + return NULL; + } + nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url); + return url; } struct gui_fetch_table gnustep_fetch_table = { - .filetype = gnustep_fetch_filetype + .filetype = gnustep_fetch_filetype, + .get_resource_url = gnustep_fetch_get_resource_url }; \ No newline at end of file diff --git a/frontends/gnustep/tables/misc.m b/frontends/gnustep/tables/misc.m index ff3d17d70..819b1734f 100644 --- a/frontends/gnustep/tables/misc.m +++ b/frontends/gnustep/tables/misc.m @@ -10,10 +10,10 @@ /*******************/ // Schedule a callback to be run after t ms, or removed if ngtv, func and param. -static nserror gnustep_misc_schedule(int t, void (*callback)(void *p), void *p) { - NSLog(@"gnustep_misc_schedule in %dms", t); +static nserror gnustep_misc_schedule(int t, void (*callback)(void *p), void *cbctx) { + //NSLog(@"gnustep_misc_schedule in %dms", t); NetsurfCallback *nsCallback = [NetsurfCallback newOrScheduledWithFunctionPointer: - callback parameter: p]; + callback parameter: cbctx]; if (t < 0) { [nsCallback cancel]; return NSERROR_OK; diff --git a/frontends/gtk/schedule.c b/frontends/gtk/schedule.c index 69678924d..737163ad2 100644 --- a/frontends/gtk/schedule.c +++ b/frontends/gtk/schedule.c @@ -105,6 +105,8 @@ nserror nsgtk_schedule(int t, void (*callback)(void *p), void *cbctx) _nsgtk_callback_t *cb; nserror res; + printf("nsgtk_schedule %p in %dms\n", callback, t); + /* Kill any pending schedule of this kind. */ res = schedule_remove(callback, cbctx);