summaryrefslogtreecommitdiff
path: root/cocoa
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-01-25 23:00:22 +0000
committerVincent Sanders <vince@kyllikki.org>2014-01-25 23:01:32 +0000
commit8ce0a10670e655d9e3a4f31fedd34baf1a3189b9 (patch)
treec1aa73bf937d097a6d2cb7efe3777cb6c720e7f7 /cocoa
parent46b8fbaeac4dd1e35945ae1338056156e5b3b86b (diff)
downloadnetsurf-8ce0a10670e655d9e3a4f31fedd34baf1a3189b9.tar.gz
netsurf-8ce0a10670e655d9e3a4f31fedd34baf1a3189b9.tar.bz2
move path_to_url and url_to_path to fetch operation table
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/BrowserViewController.m1
-rw-r--r--cocoa/Makefile.target1
-rw-r--r--cocoa/NetsurfApp.m1
-rw-r--r--cocoa/fetch.h4
-rw-r--r--cocoa/fetch.m61
-rw-r--r--cocoa/gui.h1
-rw-r--r--cocoa/gui.m32
-rw-r--r--cocoa/url.m34
8 files changed, 58 insertions, 77 deletions
diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m
index 77ee57bd1..956654aba 100644
--- a/cocoa/BrowserViewController.m
+++ b/cocoa/BrowserViewController.m
@@ -19,6 +19,7 @@
#import "cocoa/BrowserViewController.h"
#import "cocoa/BrowserView.h"
#import "cocoa/BrowserWindowController.h"
+#import "cocoa/fetch.h"
#import "desktop/browser_private.h"
#import "desktop/local_history.h"
diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target
index 8bd13c29b..49f67f085 100644
--- a/cocoa/Makefile.target
+++ b/cocoa/Makefile.target
@@ -95,7 +95,6 @@ S_COCOA := \
schedule.m \
selection.m \
thumbnail.m \
- url.m \
utf8.m \
utils.m \
ArrowBox.m \
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 5643efd6c..32ad8f1fb 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -25,7 +25,6 @@
#import "desktop/gui.h"
#import "content/urldb.h"
-#import "content/fetch.h"
#import "css/utils.h"
#import "desktop/gui.h"
#import "desktop/local_history.h"
diff --git a/cocoa/fetch.h b/cocoa/fetch.h
index 4a50b6e8d..5d2e9288d 100644
--- a/cocoa/fetch.h
+++ b/cocoa/fetch.h
@@ -16,4 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-const char *fetch_filetype(const char *unix_path);
+extern struct gui_fetch_table *cocoa_fetch_table;
+
+char *url_to_path(const char *url);
diff --git a/cocoa/fetch.m b/cocoa/fetch.m
index b1c7aea9e..7bf00e0ba 100644
--- a/cocoa/fetch.m
+++ b/cocoa/fetch.m
@@ -19,7 +19,7 @@
#import <Cocoa/Cocoa.h>
#import "utils/log.h"
-#import "content/fetch.h"
+#import "desktop/gui.h"
#import "cocoa/fetch.h"
@@ -42,9 +42,9 @@ static const struct mimemap_s {
};
-const char *fetch_filetype(const char *unix_path)
+static const char *fetch_filetype(const char *unix_path)
{
- NSString *uti;
+ NSString *uti;
NSString *mimeType = nil;
NSError *utiError = nil;
@@ -58,7 +58,7 @@ const char *fetch_filetype(const char *unix_path)
LOG(("uti call failed"));
- strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype));
+ strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype));
return cocoafiletype;
}
@@ -83,13 +83,60 @@ const char *fetch_filetype(const char *unix_path)
eidx++;
}
- strncpy(cocoafiletype,
- cocoamimemap[eidx].mimetype,
+ strncpy(cocoafiletype,
+ cocoamimemap[eidx].mimetype,
sizeof(cocoafiletype));
}
}
LOG(( "\tMIME type for '%s' is '%s'", unix_path, cocoafiletype ));
-
+
return cocoafiletype;
}
+
+char *url_to_path(const char *url)
+{
+ NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
+ return strdup([[nsurl path] UTF8String]);
+}
+
+static char *path_to_url(const char *path)
+{
+ return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]]
+ absoluteString] UTF8String] );
+}
+
+static char *filename_from_path(char *path)
+{
+ return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
+}
+
+static bool path_add_part(char *path, int length, const char *newpart)
+{
+ NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
+
+ strncpy( path, [newPath UTF8String], length );
+
+ return true;
+}
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ 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;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+};
+
+struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
diff --git a/cocoa/gui.h b/cocoa/gui.h
index 55b69072e..757140030 100644
--- a/cocoa/gui.h
+++ b/cocoa/gui.h
@@ -20,7 +20,6 @@
extern struct gui_window_table *cocoa_window_table;
extern struct gui_clipboard_table *cocoa_clipboard_table;
-extern struct gui_fetch_table *cocoa_fetch_table;
extern struct gui_browser_table *cocoa_browser_table;
extern NSString * const kCookiesFileOption;
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 2a97df39d..750d9fca4 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -46,15 +46,6 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
-static nsurl *gui_get_resource_url(const char *path)
-{
- 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;
-}
-
static void gui_poll(bool active)
{
cocoa_autorelease();
@@ -273,20 +264,6 @@ static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
cb( false, cbpw );
}
-static char *filename_from_path(char *path)
-{
- return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
-}
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
-
- strncpy( path, [newPath UTF8String], length );
-
- return true;
-}
-
static struct gui_window_table window_table = {
.create = gui_window_create,
@@ -312,15 +289,6 @@ static struct gui_window_table window_table = {
struct gui_window_table *cocoa_window_table = &window_table;
-static struct gui_fetch_table fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-};
-
-struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
static struct gui_browser_table browser_table = {
.poll = gui_poll,
diff --git a/cocoa/url.m b/cocoa/url.m
deleted file mode 100644
index 931f459a3..000000000
--- a/cocoa/url.m
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#import <Cocoa/Cocoa.h>
-
-#import "utils/url.h"
-
-
-char *url_to_path(const char *url)
-{
- NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
- return strdup([[nsurl path] UTF8String]);
-}
-
-char *path_to_url(const char *path)
-{
- return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]]
- absoluteString] UTF8String] );
-}