summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-02-03 12:04:48 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-02-03 12:04:48 +0000
commitad6fcea6b008638ca532436ecf8ba9fe7e41ffdd (patch)
tree7928f5211a6cd644dcfd764b1c67cf3f6b8ed121 /utils
parenteb2c2e3f63056e7f8b992f17f94a9418ac311a0f (diff)
downloadnetsurf-ad6fcea6b008638ca532436ecf8ba9fe7e41ffdd.tar.gz
netsurf-ad6fcea6b008638ca532436ecf8ba9fe7e41ffdd.tar.bz2
Add url_fragment to extract fragment from URL
Optionally allow url_compare to ignore fragments in comparison Fix handling of url_compare result in a few places Fix redirects which contain fragments in the Location header svn path=/trunk/netsurf/; revision=3826
Diffstat (limited to 'utils')
-rw-r--r--utils/url.c53
-rw-r--r--utils/url.h3
2 files changed, 49 insertions, 7 deletions
diff --git a/utils/url.c b/utils/url.c
index 3a43e1765..ac46944eb 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -30,6 +30,7 @@
#include <strings.h>
#include <sys/types.h>
#include <regex.h>
+#include "curl/curl.h"
#include "utils/log.h"
#include "utils/url.h"
#include "utils/utils.h"
@@ -719,6 +720,44 @@ url_func_result url_leafname(const char *url, char **result)
}
/**
+ * Extract fragment from an URL
+ * This will unescape any %xx entities in the fragment
+ *
+ * \param url an absolute URL
+ * \param result pointer to pointer to buffer to hold result
+ * \return URL_FUNC_OK on success
+ */
+
+url_func_result url_fragment(const char *url, char **result)
+{
+ url_func_result status;
+ struct url_components components;
+
+ assert(url);
+
+ status = url_get_components(url, &components);
+ if (status == URL_FUNC_OK) {
+ if (!components.fragment) {
+ status = URL_FUNC_FAILED;
+ } else {
+ char *frag = curl_unescape(components.fragment,
+ strlen(components.fragment));
+ if (!frag) {
+ status = URL_FUNC_NOMEM;
+ } else {
+ *result = strdup(frag);
+ if (!(*result))
+ status = URL_FUNC_NOMEM;
+ curl_free(frag);
+ }
+ }
+ }
+
+ url_destroy_components(&components);
+ return status;
+}
+
+/**
* Attempt to find a nice filename for a URL.
*
* \param url an absolute URL
@@ -897,12 +936,14 @@ url_func_result url_escape(const char *unescaped, bool sptoplus,
/**
* Compare two absolute, normalized URLs
*
- * \param url1 URL 1
- * \param url2 URL 2
- * \param result Pointer to location to store result (true if URLs match)
+ * \param url1 URL 1
+ * \param url2 URL 2
+ * \param nofrag Ignore fragment part in comparison
+ * \param result Pointer to location to store result (true if URLs match)
* \return URL_FUNC_OK on success
*/
-url_func_result url_compare(const char *url1, const char *url2, bool *result)
+url_func_result url_compare(const char *url1, const char *url2,
+ bool nofrag, bool *result)
{
url_func_result status;
struct url_components c1, c2;
@@ -930,7 +971,7 @@ url_func_result url_compare(const char *url1, const char *url2, bool *result)
((c1.path && c2.path) || (!c1.path && !c2.path)) &&
((c1.query && c2.query) ||
(!c1.query && !c2.query)) &&
- ((c1.fragment && c2.fragment) ||
+ (nofrag || (c1.fragment && c2.fragment) ||
(!c1.fragment && !c2.fragment))) {
if (c1.scheme)
@@ -946,7 +987,7 @@ url_func_result url_compare(const char *url1, const char *url2, bool *result)
if (c1.query)
res &= strcmp(c1.query, c2.query) == 0;
- if (c1.fragment)
+ if (!nofrag && c1.fragment)
res &= strcmp(c1.fragment, c2.fragment) == 0;
} else {
/* Can't match */
diff --git a/utils/url.h b/utils/url.h
index b35b6e376..9a1b934a5 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -54,8 +54,9 @@ url_func_result url_parent(const char *url, char **result);
url_func_result url_plq(const char *url, char **result);
url_func_result url_path(const char *url, char **result);
url_func_result url_leafname(const char *url, char **result);
+url_func_result url_fragment(const char *url, char **result);
url_func_result url_compare(const char *url1, const char *url2,
- bool *result);
+ bool nofrag, bool *result);
url_func_result url_get_components(const char *url,
struct url_components *result);