summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-10-01 21:31:55 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-10-01 21:31:55 +0000
commit49ce807e3cebf9f36fc908d7b7c0bfe00ce32e2c (patch)
treef3750ef9047ff8493715e10e2b84e292c1b56fe1 /utils
parent39ad1632eb78e8c632d3e66711d09f2bb982a4e8 (diff)
downloadnetsurf-49ce807e3cebf9f36fc908d7b7c0bfe00ce32e2c.tar.gz
netsurf-49ce807e3cebf9f36fc908d7b7c0bfe00ce32e2c.tar.bz2
[project @ 2004-10-01 21:31:55 by jmb]
A somewhat better implementation of referrers which no longer sends the referer if the URL schemes don't match. Things to do: 1) Preservation of referer across redirects (see comment in browser.c:284) 2) GUI templates/code for configuration of referer sending (simple on/off toggle only) 3) Make referer sending when fetching objects/stylesheets for a page pay attention to option_send_referer? 4) Handle the case where the referer is in the form of http://moo:foo@mysite.com/ (ie the login details embedded in the referer - not good). svn path=/import/netsurf/; revision=1297
Diffstat (limited to 'utils')
-rw-r--r--utils/url.c45
-rw-r--r--utils/url.h1
2 files changed, 40 insertions, 6 deletions
diff --git a/utils/url.c b/utils/url.c
index 1ea8a7c72..00a88a0e4 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -411,6 +411,39 @@ url_func_result url_host(const char *url, char **result)
return URL_FUNC_OK;
}
+/**
+ * Return the scheme name from an URL
+ *
+ * \param url an absolute URL
+ * \param result pointer to pointer to buffer to hold scheme name
+ * \return URL_FUNC_OK on success
+ */
+url_func_result url_scheme(const char *url, char **result)
+{
+ int m;
+ regmatch_t match[10];
+
+ (*result) = 0;
+
+ m = regexec(&url_re, url, 10, match, 0);
+ if (m) {
+ LOG(("url '%s' failed to match regex", url));
+ return URL_FUNC_FAILED;
+ }
+ if (match[2].rm_so == -1)
+ return URL_FUNC_FAILED;
+
+ (*result) = malloc(match[2].rm_eo - match[2].rm_so + 1);
+ if (!(*result)) {
+ LOG(("malloc failed"));
+ return URL_FUNC_NOMEM;
+ }
+
+ strncpy((*result), url + match[2].rm_so, match[2].rm_eo - match[2].rm_so);
+ (*result)[match[2].rm_eo - match[2].rm_so] = 0;
+
+ return URL_FUNC_OK;
+}
/**
* Attempt to find a nice filename for a URL.
@@ -514,8 +547,8 @@ int main(int argc, char *argv[])
url_func_result res;
char *s;
url_init();
-/* for (i = 1; i != argc; i++) {
- printf("==> '%s'\n", argv[i]);
+ for (i = 1; i != argc; i++) {
+/* printf("==> '%s'\n", argv[i]);
res = url_normalize(argv[i], &s);
if (res == URL_FUNC_OK) {
printf("<== '%s'\n", s);
@@ -527,19 +560,19 @@ int main(int argc, char *argv[])
printf("<== '%s'\n", s);
free(s);
}*/
-/* if (1 != i) {
+ if (1 != i) {
res = url_join(argv[i], argv[1], &s);
if (res == URL_FUNC_OK) {
printf("'%s' + '%s' \t= '%s'\n", argv[1],
argv[i], s);
free(s);
}
- }*/
- res = url_nice(argv[i], &s);
+ }
+/* res = url_nice(argv[i], &s);
if (res == URL_FUNC_OK) {
printf("'%s'\n", s);
free(s);
- }
+ }*/
}
return 0;
}
diff --git a/utils/url.h b/utils/url.h
index cc373b257..6bd536cb2 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -22,6 +22,7 @@ void url_init(void);
url_func_result url_normalize(const char *url, char **result);
url_func_result url_join(const char *rel, const char *base, char **result);
url_func_result url_host(const char *url, char **result);
+url_func_result url_scheme(const char *url, char **result);
url_func_result url_nice(const char *url, char **result);
#endif