Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/b4e21b76fd0b8b4a048f0d8125bc5a36c0ca8d42
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/b4e21b76fd0b8b4a048f0d8125bc5a36c0ca8d42
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/b4e21b76fd0b8b4a048f0d8125bc5a36c0ca8d42

The branch, master has been updated
       via  b4e21b76fd0b8b4a048f0d8125bc5a36c0ca8d42 (commit)
       via  fa2e3b778465cd496aedde8e187038835a765c4f (commit)
       via  cf753f20cc2a8506c831a5cedd933e3e78417261 (commit)
       via  a543206075d86cc7c4ea3db96b96e94a12cf8c7f (commit)
       via  7202ff2f649561dd98cb721bdf88b4735127bba9 (commit)
       via  90a260a2ccf33a399c87b1619d3b82e19b84020f (commit)
       via  f9870c41f5404be33a15fe75f8a431053782597b (commit)
      from  83f95fe05e98464ffa832df6f17ca619cc173bc2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=b4e21b76fd0b8b4a048f0d8125bc5a36c0ca8d42
commit b4e21b76fd0b8b4a048f0d8125bc5a36c0ca8d42
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    URL unescape: Calculate new_len at end, rather than maintaining it.

diff --git a/utils/url.c b/utils/url.c
index 9294e3d..40f3708 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -71,8 +71,6 @@ nserror url_unescape(const char *str, size_t length,
                return NSERROR_NOMEM;
        }
 
-       new_len = length;
-
        res_pos = result;
        str_end = str + length;
        if (length >= 3) {
@@ -85,7 +83,6 @@ nserror url_unescape(const char *str, size_t length,
                        if (c == '%' && isxdigit(c1) && isxdigit(c2)) {
                                c = xdigit_to_hex(c1) << 4 | xdigit_to_hex(c2);
                                str += 2;
-                               new_len -= 2;
                        }
                        *res_pos++ = c;
                        str++;
@@ -97,7 +94,8 @@ nserror url_unescape(const char *str, size_t length,
                *res_pos++ = *str++;
        }
 
-       *res_pos++ = '\0';
+       *res_pos = '\0';
+       new_len = res_pos - result;
 
        if (new_len != length) {
                /* Shrink wrap the allocaiton around the string */


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=fa2e3b778465cd496aedde8e187038835a765c4f
commit fa2e3b778465cd496aedde8e187038835a765c4f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    URL unescape: return the new length to the caller.
    
    The avoids situations were we threw away the length, only for
    the caller to have to strlen the returned string.
    
    Note, there seems to be a case of the amiga front end writing
    beyond end of allocation.  Added a TODO for now.

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 6b8be8d..65d99cf 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -138,7 +138,7 @@ static bool fetch_data_process(struct fetch_data_context *c)
        char *params;
        char *comma;
        char *unescaped;
-       int unescaped_len;
+       size_t unescaped_len;
        
        /* format of a data: URL is:
         *   data:[<mimetype>][;base64],<data>
@@ -193,14 +193,13 @@ static bool fetch_data_process(struct fetch_data_context 
*c)
        /* URL unescape the data first, just incase some insane page
         * decides to nest URL and base64 encoding.  Like, say, Acid2.
         */
-       res = url_unescape(comma + 1, 0, &unescaped);
+       res = url_unescape(comma + 1, 0, &unescaped_len, &unescaped);
        if (res != NSERROR_OK) {
                msg.type = FETCH_ERROR;
                msg.data.error = "Unable to URL decode data: URL";
                fetch_data_send_callback(&msg, c);
                return false;
        }
-       unescaped_len = strlen(unescaped);
        
        if (c->base64) {
                base64_decode_alloc(unescaped, unescaped_len, &c->data, 
&c->datalen);
diff --git a/frontends/amiga/misc.c b/frontends/amiga/misc.c
index 2388651..f15eb48 100755
--- a/frontends/amiga/misc.c
+++ b/frontends/amiga/misc.c
@@ -189,6 +189,7 @@ int32 amiga_warn_user_multi(const char *body, const char 
*opt1, const char *opt2
 static nserror amiga_nsurl_to_path(struct nsurl *url, char **path_out)
 {
        lwc_string *urlpath;
+       size_t path_len;
        char *path;
        bool match;
        lwc_string *scheme;
@@ -217,7 +218,7 @@ static nserror amiga_nsurl_to_path(struct nsurl *url, char 
**path_out)
                return NSERROR_BAD_PARAMETER;
        }
 
-       res = url_unescape(lwc_string_data(urlpath) + 1, 0, &path);
+       res = url_unescape(lwc_string_data(urlpath) + 1, 0, &path_len, &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
                return res;
@@ -233,9 +234,10 @@ static nserror amiga_nsurl_to_path(struct nsurl *url, char 
**path_out)
                }
                else
                {
-                       int len = strlen(path);
-                       path[len] = ':';
-                       path[len + 1] = '\0';
+                       path[path_len] = ':';
+                       /* TODO: Looks like we are writing past the end of
+                        * path's allocation here. */
+                       path[path_len + 1] = '\0';
                }
        }
 
diff --git a/frontends/atari/file.c b/frontends/atari/file.c
index 7bc11da..3816e47 100644
--- a/frontends/atari/file.c
+++ b/frontends/atari/file.c
@@ -112,6 +112,7 @@ static nserror atari_basename(const char *path, char **str, 
size_t *size)
 static nserror atari_nsurl_to_path(struct nsurl *url, char **path_out)
 {
        lwc_string *urlpath;
+       size_t path_len;
        char *path;
        bool match;
        lwc_string *scheme;
@@ -140,6 +141,7 @@ static nserror atari_nsurl_to_path(struct nsurl *url, char 
**path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          &path_len,
                           &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
@@ -153,7 +155,7 @@ static nserror atari_nsurl_to_path(struct nsurl *url, char 
**path_out)
                 * strlen is *not* copying too much data as we are
                 * moving the null too!
                 */
-               memmove(path, path + 1, strlen(path));
+               memmove(path, path + 1, path_len);
        }
        /* if the path does not have a drive letter we return the
         * complete path.
diff --git a/frontends/beos/gui.cpp b/frontends/beos/gui.cpp
index 53387ad..8c6614d 100644
--- a/frontends/beos/gui.cpp
+++ b/frontends/beos/gui.cpp
@@ -797,7 +797,7 @@ static char *url_to_path(const char *url)
        char *url_path;
        char *path = NULL;
 
-       if (url_unescape(url, 0, &url_path) == NSERROR_OK) {
+       if (url_unescape(url, 0, NULL, &url_path) == NSERROR_OK) {
                /* return the absolute path including leading / */
                path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
                free(url_path);
diff --git a/frontends/riscos/download.c b/frontends/riscos/download.c
index 1a0249e..561409e 100644
--- a/frontends/riscos/download.c
+++ b/frontends/riscos/download.c
@@ -241,6 +241,7 @@ static nserror download_ro_filetype(download_context *ctx, 
bits *ftype_out)
                                char *raw_path;
                                if (url_unescape(lwc_string_data(path),
                                                 lwc_string_length(path),
+                                                NULL,
                                                 &raw_path) == NSERROR_OK) {
                                        ftype = 
ro_filetype_from_unix_path(raw_path);
                                        free(raw_path);
diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index f55392f..72eeb62 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -1485,6 +1485,7 @@ static nserror ro_path_to_nsurl(const char *path, struct 
nsurl **url_out)
 static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out)
 {
        lwc_string *urlpath;
+       size_t unpath_len;
        char *unpath;
        char *path;
        bool match;
@@ -1515,6 +1516,7 @@ static nserror ro_nsurl_to_path(struct nsurl *url, char 
**path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          &unpath_len,
                           &unpath);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
@@ -1522,14 +1524,14 @@ static nserror ro_nsurl_to_path(struct nsurl *url, char 
**path_out)
        }
 
        /* RISC OS path should not be more than 100 characters longer */
-       path = malloc(strlen(unpath) + 100);
+       path = malloc(unpath_len + 100);
        if (path == NULL) {
                free(unpath);
                return NSERROR_NOMEM;
        }
 
        r = __riscosify(unpath, 0, __RISCOSIFY_NO_SUFFIX,
-                       path, strlen(unpath) + 100, 0);
+                       path, unpath_len + 100, 0);
        free(unpath);
        if (r == NULL) {
                free(path);
diff --git a/frontends/windows/file.c b/frontends/windows/file.c
index 7583790..90e6ef4 100644
--- a/frontends/windows/file.c
+++ b/frontends/windows/file.c
@@ -143,6 +143,7 @@ static nserror windows_nsurl_to_path(struct nsurl *url, 
char **path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          NULL,
                           &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
diff --git a/test/llcache.c b/test/llcache.c
index df51386..8aae357 100644
--- a/test/llcache.c
+++ b/test/llcache.c
@@ -95,7 +95,7 @@ char *url_to_path(const char *url)
        char *url_path;
        char *path = NULL;
 
-       if (url_unescape(url, 0, &url_path) == NSERROR_OK) {
+       if (url_unescape(url, 0, NULL, &url_path) == NSERROR_OK) {
                /* return the absolute path including leading / */
                path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
                free(url_path);
diff --git a/utils/file.c b/utils/file.c
index 6224d1c..3ec97de 100644
--- a/utils/file.c
+++ b/utils/file.c
@@ -138,6 +138,7 @@ static nserror posix_nsurl_to_path(struct nsurl *url, char 
**path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          NULL,
                           &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
diff --git a/utils/url.c b/utils/url.c
index 3be983d..9294e3d 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -54,7 +54,8 @@ static inline char xdigit_to_hex(char c)
 
 
 /* exported interface documented in utils/url.h */
-nserror url_unescape(const char *str, size_t length, char **result_out)
+nserror url_unescape(const char *str, size_t length,
+               size_t *length_out, char **result_out)
 {
        const char *str_end;
        size_t new_len;
@@ -106,6 +107,9 @@ nserror url_unescape(const char *str, size_t length, char 
**result_out)
                }
        }
 
+       if (length_out != NULL) {
+               *length_out = new_len;
+       }
        *result_out = result;
        return NSERROR_OK;
 }
diff --git a/utils/url.h b/utils/url.h
index e67d69a..07ad1a7 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -45,11 +45,15 @@ nserror url_escape(const char *unescaped, size_t toskip, 
bool sptoplus,
 /**
  * Convert an escaped string to plain.
  *
- * \param[in] str String to unescape.
- * \param[in] length Length of string or 0 to use strlen
- * \param[out] result unescaped string owned by caller must be freed with 
free()
+ * \param[in]  str         String to unescape.
+ * \param[in]  length      Length of string or 0 to use strlen.
+ * \param[out] length_out  Iff non-NULL, value updated to length of returned
+ *                         result_out string.
+ * \param[out] result_out  Returns unescaped string, owned by caller.
+ *                         Must be freed with free().
  * \return NSERROR_OK on success
  */
-nserror url_unescape(const char *str, size_t length, char **result);
+nserror url_unescape(const char *str, size_t length,
+               size_t *length_out, char **result_out);
 
 #endif


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=cf753f20cc2a8506c831a5cedd933e3e78417261
commit cf753f20cc2a8506c831a5cedd933e3e78417261
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Avoid using curl for URL unescaping.
    
    This moves us towards working without curl.

diff --git a/utils/url.c b/utils/url.c
index efbc769..3be983d 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -23,6 +23,7 @@
  */
 
 #include <ctype.h>
+#include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 #include <curl/curl.h>
@@ -32,25 +33,80 @@
 #include "utils/url.h"
 
 
+/**
+ * Convert a hex digit to a hex value
+ *
+ * Must be called with valid hex char, results undefined otherwise.
+ *
+ * \param[in]  c  char to convert yo value
+ * \return the value of c
+ */
+static inline char xdigit_to_hex(char c)
+{
+       if (c >= '0' && c <= '9') {
+               return c - '0';
+       } else if (c >= 'A' && c <= 'F') {
+               return c - 'A' + 10;
+       } else {
+               return c - 'a' + 10;
+       }
+}
+
+
 /* exported interface documented in utils/url.h */
-nserror url_unescape(const char *str, size_t length, char **result)
+nserror url_unescape(const char *str, size_t length, char **result_out)
 {
-       char *curlstr;
-       char *retstr;
+       const char *str_end;
+       size_t new_len;
+       char *res_pos;
+       char *result;
+
+       if (length == 0) {
+               length = strlen(str);
+       }
 
-       curlstr = curl_unescape(str, length);
-       if (curlstr == NULL) {
+       result = malloc(length + 1);
+       if (result == NULL) {
                return NSERROR_NOMEM;
        }
 
-       retstr = strdup(curlstr);
-       curl_free(curlstr);
+       new_len = length;
+
+       res_pos = result;
+       str_end = str + length;
+       if (length >= 3) {
+               str_end -= 2;
+               while (str < str_end) {
+                       char c = *str;
+                       char c1 = *(str + 1);
+                       char c2 = *(str + 2);
+
+                       if (c == '%' && isxdigit(c1) && isxdigit(c2)) {
+                               c = xdigit_to_hex(c1) << 4 | xdigit_to_hex(c2);
+                               str += 2;
+                               new_len -= 2;
+                       }
+                       *res_pos++ = c;
+                       str++;
+               }
+               str_end += 2;
+       }
 
-       if (retstr == NULL) {
-               return NSERROR_NOMEM;
+       while (str < str_end) {
+               *res_pos++ = *str++;
+       }
+
+       *res_pos++ = '\0';
+
+       if (new_len != length) {
+               /* Shrink wrap the allocaiton around the string */
+               char *tmp = realloc(result, new_len + 1);
+               if (tmp != NULL) {
+                       result = tmp;
+               }
        }
 
-       *result = retstr;
+       *result_out = result;
        return NSERROR_OK;
 }
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=a543206075d86cc7c4ea3db96b96e94a12cf8c7f
commit a543206075d86cc7c4ea3db96b96e94a12cf8c7f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    URL unescape: Use size_t for length.

diff --git a/utils/url.c b/utils/url.c
index 4fcbccd..efbc769 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -33,7 +33,7 @@
 
 
 /* exported interface documented in utils/url.h */
-nserror url_unescape(const char *str, int length, char **result)
+nserror url_unescape(const char *str, size_t length, char **result)
 {
        char *curlstr;
        char *retstr;
diff --git a/utils/url.h b/utils/url.h
index 8bbd68d..e67d69a 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -50,6 +50,6 @@ nserror url_escape(const char *unescaped, size_t toskip, bool 
sptoplus,
  * \param[out] result unescaped string owned by caller must be freed with 
free()
  * \return NSERROR_OK on success
  */
-nserror url_unescape(const char *str, int length, char **result);
+nserror url_unescape(const char *str, size_t length, char **result);
 
 #endif


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=7202ff2f649561dd98cb721bdf88b4735127bba9
commit 7202ff2f649561dd98cb721bdf88b4735127bba9
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Data URL handling: Use url_unescape rather than curl.

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index bbd4395..6b8be8d 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -24,9 +24,9 @@
 #include <stdbool.h>
 #include <string.h>
 #include <stdlib.h>
-#include <curl/curl.h> /* for URL unescaping functions */
 #include <libwapcaplet/libwapcaplet.h>
 
+#include "utils/url.h"
 #include "utils/nsurl.h"
 #include "utils/corestrings.h"
 #include "utils/log.h"
@@ -54,21 +54,16 @@ struct fetch_data_context {
 
 static struct fetch_data_context *ring = NULL;
 
-static CURL *curl;
-
 static bool fetch_data_initialise(lwc_string *scheme)
 {
        LOG("fetch_data_initialise called for %s", lwc_string_data(scheme));
-       if ( (curl = curl_easy_init()) == NULL)
-               return false;
-       else
-               return true;
+
+       return true;
 }
 
 static void fetch_data_finalise(lwc_string *scheme)
 {
        LOG("fetch_data_finalise called for %s", lwc_string_data(scheme));
-       curl_easy_cleanup(curl);
 }
 
 static bool fetch_data_can_fetch(const nsurl *url)
@@ -138,6 +133,7 @@ static void fetch_data_send_callback(const fetch_msg *msg,
 
 static bool fetch_data_process(struct fetch_data_context *c)
 {
+       nserror res;
        fetch_msg msg;
        char *params;
        char *comma;
@@ -197,13 +193,14 @@ static bool fetch_data_process(struct fetch_data_context 
*c)
        /* URL unescape the data first, just incase some insane page
         * decides to nest URL and base64 encoding.  Like, say, Acid2.
         */
-       unescaped = curl_easy_unescape(curl, comma + 1, 0, &unescaped_len);
-       if (unescaped == NULL) {
+       res = url_unescape(comma + 1, 0, &unescaped);
+       if (res != NSERROR_OK) {
                msg.type = FETCH_ERROR;
                msg.data.error = "Unable to URL decode data: URL";
                fetch_data_send_callback(&msg, c);
                return false;
        }
+       unescaped_len = strlen(unescaped);
        
        if (c->base64) {
                base64_decode_alloc(unescaped, unescaped_len, &c->data, 
&c->datalen);
@@ -211,7 +208,7 @@ static bool fetch_data_process(struct fetch_data_context *c)
                        msg.type = FETCH_ERROR;
                        msg.data.error = "Unable to Base64 decode data: URL";
                        fetch_data_send_callback(&msg, c);
-                       curl_free(unescaped);
+                       free(unescaped);
                        return false;
                }
        } else {
@@ -221,14 +218,14 @@ static bool fetch_data_process(struct fetch_data_context 
*c)
                        msg.data.error =
                                "Unable to allocate memory for data: URL";
                        fetch_data_send_callback(&msg, c);
-                       curl_free(unescaped);
+                       free(unescaped);
                        return false;
                }
                c->datalen = unescaped_len;
                memcpy(c->data, unescaped, unescaped_len);
        }
        
-       curl_free(unescaped);
+       free(unescaped);
        
        return true;
 }


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=90a260a2ccf33a399c87b1619d3b82e19b84020f
commit 90a260a2ccf33a399c87b1619d3b82e19b84020f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Doxygen: Fix instance of bad function comment syntax.

diff --git a/utils/url.h b/utils/url.h
index 94579e3..8bbd68d 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -46,7 +46,7 @@ nserror url_escape(const char *unescaped, size_t toskip, bool 
sptoplus,
  * Convert an escaped string to plain.
  *
  * \param[in] str String to unescape.
- * \parm[in] length Length of string or 0 to use strlen
+ * \param[in] length Length of string or 0 to use strlen
  * \param[out] result unescaped string owned by caller must be freed with 
free()
  * \return NSERROR_OK on success
  */


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=f9870c41f5404be33a15fe75f8a431053782597b
commit f9870c41f5404be33a15fe75f8a431053782597b
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Whitespace: Convert spaces to tab for indent.

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 84d0aa3..bbd4395 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -142,7 +142,7 @@ static bool fetch_data_process(struct fetch_data_context *c)
        char *params;
        char *comma;
        char *unescaped;
-        int unescaped_len;
+       int unescaped_len;
        
        /* format of a data: URL is:
         *   data:[<mimetype>][;base64],<data>
@@ -197,8 +197,8 @@ static bool fetch_data_process(struct fetch_data_context *c)
        /* URL unescape the data first, just incase some insane page
         * decides to nest URL and base64 encoding.  Like, say, Acid2.
         */
-        unescaped = curl_easy_unescape(curl, comma + 1, 0, &unescaped_len);
-        if (unescaped == NULL) {
+       unescaped = curl_easy_unescape(curl, comma + 1, 0, &unescaped_len);
+       if (unescaped == NULL) {
                msg.type = FETCH_ERROR;
                msg.data.error = "Unable to URL decode data: URL";
                fetch_data_send_callback(&msg, c);


-----------------------------------------------------------------------

Summary of changes:
 content/fetchers/data.c     |   24 ++++++-------
 frontends/amiga/misc.c      |   10 +++---
 frontends/atari/file.c      |    4 ++-
 frontends/beos/gui.cpp      |    2 +-
 frontends/riscos/download.c |    1 +
 frontends/riscos/gui.c      |    6 ++--
 frontends/windows/file.c    |    1 +
 test/llcache.c              |    2 +-
 utils/file.c                |    1 +
 utils/url.c                 |   78 +++++++++++++++++++++++++++++++++++++------
 utils/url.h                 |   12 ++++---
 11 files changed, 104 insertions(+), 37 deletions(-)

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 84d0aa3..65d99cf 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -24,9 +24,9 @@
 #include <stdbool.h>
 #include <string.h>
 #include <stdlib.h>
-#include <curl/curl.h> /* for URL unescaping functions */
 #include <libwapcaplet/libwapcaplet.h>
 
+#include "utils/url.h"
 #include "utils/nsurl.h"
 #include "utils/corestrings.h"
 #include "utils/log.h"
@@ -54,21 +54,16 @@ struct fetch_data_context {
 
 static struct fetch_data_context *ring = NULL;
 
-static CURL *curl;
-
 static bool fetch_data_initialise(lwc_string *scheme)
 {
        LOG("fetch_data_initialise called for %s", lwc_string_data(scheme));
-       if ( (curl = curl_easy_init()) == NULL)
-               return false;
-       else
-               return true;
+
+       return true;
 }
 
 static void fetch_data_finalise(lwc_string *scheme)
 {
        LOG("fetch_data_finalise called for %s", lwc_string_data(scheme));
-       curl_easy_cleanup(curl);
 }
 
 static bool fetch_data_can_fetch(const nsurl *url)
@@ -138,11 +133,12 @@ static void fetch_data_send_callback(const fetch_msg *msg,
 
 static bool fetch_data_process(struct fetch_data_context *c)
 {
+       nserror res;
        fetch_msg msg;
        char *params;
        char *comma;
        char *unescaped;
-        int unescaped_len;
+       size_t unescaped_len;
        
        /* format of a data: URL is:
         *   data:[<mimetype>][;base64],<data>
@@ -197,8 +193,8 @@ static bool fetch_data_process(struct fetch_data_context *c)
        /* URL unescape the data first, just incase some insane page
         * decides to nest URL and base64 encoding.  Like, say, Acid2.
         */
-        unescaped = curl_easy_unescape(curl, comma + 1, 0, &unescaped_len);
-        if (unescaped == NULL) {
+       res = url_unescape(comma + 1, 0, &unescaped_len, &unescaped);
+       if (res != NSERROR_OK) {
                msg.type = FETCH_ERROR;
                msg.data.error = "Unable to URL decode data: URL";
                fetch_data_send_callback(&msg, c);
@@ -211,7 +207,7 @@ static bool fetch_data_process(struct fetch_data_context *c)
                        msg.type = FETCH_ERROR;
                        msg.data.error = "Unable to Base64 decode data: URL";
                        fetch_data_send_callback(&msg, c);
-                       curl_free(unescaped);
+                       free(unescaped);
                        return false;
                }
        } else {
@@ -221,14 +217,14 @@ static bool fetch_data_process(struct fetch_data_context 
*c)
                        msg.data.error =
                                "Unable to allocate memory for data: URL";
                        fetch_data_send_callback(&msg, c);
-                       curl_free(unescaped);
+                       free(unescaped);
                        return false;
                }
                c->datalen = unescaped_len;
                memcpy(c->data, unescaped, unescaped_len);
        }
        
-       curl_free(unescaped);
+       free(unescaped);
        
        return true;
 }
diff --git a/frontends/amiga/misc.c b/frontends/amiga/misc.c
index 2388651..f15eb48 100755
--- a/frontends/amiga/misc.c
+++ b/frontends/amiga/misc.c
@@ -189,6 +189,7 @@ int32 amiga_warn_user_multi(const char *body, const char 
*opt1, const char *opt2
 static nserror amiga_nsurl_to_path(struct nsurl *url, char **path_out)
 {
        lwc_string *urlpath;
+       size_t path_len;
        char *path;
        bool match;
        lwc_string *scheme;
@@ -217,7 +218,7 @@ static nserror amiga_nsurl_to_path(struct nsurl *url, char 
**path_out)
                return NSERROR_BAD_PARAMETER;
        }
 
-       res = url_unescape(lwc_string_data(urlpath) + 1, 0, &path);
+       res = url_unescape(lwc_string_data(urlpath) + 1, 0, &path_len, &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
                return res;
@@ -233,9 +234,10 @@ static nserror amiga_nsurl_to_path(struct nsurl *url, char 
**path_out)
                }
                else
                {
-                       int len = strlen(path);
-                       path[len] = ':';
-                       path[len + 1] = '\0';
+                       path[path_len] = ':';
+                       /* TODO: Looks like we are writing past the end of
+                        * path's allocation here. */
+                       path[path_len + 1] = '\0';
                }
        }
 
diff --git a/frontends/atari/file.c b/frontends/atari/file.c
index 7bc11da..3816e47 100644
--- a/frontends/atari/file.c
+++ b/frontends/atari/file.c
@@ -112,6 +112,7 @@ static nserror atari_basename(const char *path, char **str, 
size_t *size)
 static nserror atari_nsurl_to_path(struct nsurl *url, char **path_out)
 {
        lwc_string *urlpath;
+       size_t path_len;
        char *path;
        bool match;
        lwc_string *scheme;
@@ -140,6 +141,7 @@ static nserror atari_nsurl_to_path(struct nsurl *url, char 
**path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          &path_len,
                           &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
@@ -153,7 +155,7 @@ static nserror atari_nsurl_to_path(struct nsurl *url, char 
**path_out)
                 * strlen is *not* copying too much data as we are
                 * moving the null too!
                 */
-               memmove(path, path + 1, strlen(path));
+               memmove(path, path + 1, path_len);
        }
        /* if the path does not have a drive letter we return the
         * complete path.
diff --git a/frontends/beos/gui.cpp b/frontends/beos/gui.cpp
index 53387ad..8c6614d 100644
--- a/frontends/beos/gui.cpp
+++ b/frontends/beos/gui.cpp
@@ -797,7 +797,7 @@ static char *url_to_path(const char *url)
        char *url_path;
        char *path = NULL;
 
-       if (url_unescape(url, 0, &url_path) == NSERROR_OK) {
+       if (url_unescape(url, 0, NULL, &url_path) == NSERROR_OK) {
                /* return the absolute path including leading / */
                path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
                free(url_path);
diff --git a/frontends/riscos/download.c b/frontends/riscos/download.c
index 1a0249e..561409e 100644
--- a/frontends/riscos/download.c
+++ b/frontends/riscos/download.c
@@ -241,6 +241,7 @@ static nserror download_ro_filetype(download_context *ctx, 
bits *ftype_out)
                                char *raw_path;
                                if (url_unescape(lwc_string_data(path),
                                                 lwc_string_length(path),
+                                                NULL,
                                                 &raw_path) == NSERROR_OK) {
                                        ftype = 
ro_filetype_from_unix_path(raw_path);
                                        free(raw_path);
diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index f55392f..72eeb62 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -1485,6 +1485,7 @@ static nserror ro_path_to_nsurl(const char *path, struct 
nsurl **url_out)
 static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out)
 {
        lwc_string *urlpath;
+       size_t unpath_len;
        char *unpath;
        char *path;
        bool match;
@@ -1515,6 +1516,7 @@ static nserror ro_nsurl_to_path(struct nsurl *url, char 
**path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          &unpath_len,
                           &unpath);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
@@ -1522,14 +1524,14 @@ static nserror ro_nsurl_to_path(struct nsurl *url, char 
**path_out)
        }
 
        /* RISC OS path should not be more than 100 characters longer */
-       path = malloc(strlen(unpath) + 100);
+       path = malloc(unpath_len + 100);
        if (path == NULL) {
                free(unpath);
                return NSERROR_NOMEM;
        }
 
        r = __riscosify(unpath, 0, __RISCOSIFY_NO_SUFFIX,
-                       path, strlen(unpath) + 100, 0);
+                       path, unpath_len + 100, 0);
        free(unpath);
        if (r == NULL) {
                free(path);
diff --git a/frontends/windows/file.c b/frontends/windows/file.c
index 7583790..90e6ef4 100644
--- a/frontends/windows/file.c
+++ b/frontends/windows/file.c
@@ -143,6 +143,7 @@ static nserror windows_nsurl_to_path(struct nsurl *url, 
char **path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          NULL,
                           &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
diff --git a/test/llcache.c b/test/llcache.c
index df51386..8aae357 100644
--- a/test/llcache.c
+++ b/test/llcache.c
@@ -95,7 +95,7 @@ char *url_to_path(const char *url)
        char *url_path;
        char *path = NULL;
 
-       if (url_unescape(url, 0, &url_path) == NSERROR_OK) {
+       if (url_unescape(url, 0, NULL, &url_path) == NSERROR_OK) {
                /* return the absolute path including leading / */
                path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
                free(url_path);
diff --git a/utils/file.c b/utils/file.c
index 6224d1c..3ec97de 100644
--- a/utils/file.c
+++ b/utils/file.c
@@ -138,6 +138,7 @@ static nserror posix_nsurl_to_path(struct nsurl *url, char 
**path_out)
 
        res = url_unescape(lwc_string_data(urlpath),
                           lwc_string_length(urlpath),
+                          NULL,
                           &path);
        lwc_string_unref(urlpath);
        if (res != NSERROR_OK) {
diff --git a/utils/url.c b/utils/url.c
index 4fcbccd..40f3708 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -23,6 +23,7 @@
  */
 
 #include <ctype.h>
+#include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 #include <curl/curl.h>
@@ -32,25 +33,82 @@
 #include "utils/url.h"
 
 
+/**
+ * Convert a hex digit to a hex value
+ *
+ * Must be called with valid hex char, results undefined otherwise.
+ *
+ * \param[in]  c  char to convert yo value
+ * \return the value of c
+ */
+static inline char xdigit_to_hex(char c)
+{
+       if (c >= '0' && c <= '9') {
+               return c - '0';
+       } else if (c >= 'A' && c <= 'F') {
+               return c - 'A' + 10;
+       } else {
+               return c - 'a' + 10;
+       }
+}
+
+
 /* exported interface documented in utils/url.h */
-nserror url_unescape(const char *str, int length, char **result)
+nserror url_unescape(const char *str, size_t length,
+               size_t *length_out, char **result_out)
 {
-       char *curlstr;
-       char *retstr;
+       const char *str_end;
+       size_t new_len;
+       char *res_pos;
+       char *result;
+
+       if (length == 0) {
+               length = strlen(str);
+       }
 
-       curlstr = curl_unescape(str, length);
-       if (curlstr == NULL) {
+       result = malloc(length + 1);
+       if (result == NULL) {
                return NSERROR_NOMEM;
        }
 
-       retstr = strdup(curlstr);
-       curl_free(curlstr);
+       res_pos = result;
+       str_end = str + length;
+       if (length >= 3) {
+               str_end -= 2;
+               while (str < str_end) {
+                       char c = *str;
+                       char c1 = *(str + 1);
+                       char c2 = *(str + 2);
+
+                       if (c == '%' && isxdigit(c1) && isxdigit(c2)) {
+                               c = xdigit_to_hex(c1) << 4 | xdigit_to_hex(c2);
+                               str += 2;
+                       }
+                       *res_pos++ = c;
+                       str++;
+               }
+               str_end += 2;
+       }
 
-       if (retstr == NULL) {
-               return NSERROR_NOMEM;
+       while (str < str_end) {
+               *res_pos++ = *str++;
        }
 
-       *result = retstr;
+       *res_pos = '\0';
+       new_len = res_pos - result;
+
+       if (new_len != length) {
+               /* Shrink wrap the allocaiton around the string */
+               char *tmp = realloc(result, new_len + 1);
+               if (tmp != NULL) {
+                       result = tmp;
+               }
+       }
+
+       if (length_out != NULL) {
+               *length_out = new_len;
+       }
+       *result_out = result;
        return NSERROR_OK;
 }
 
diff --git a/utils/url.h b/utils/url.h
index 94579e3..07ad1a7 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -45,11 +45,15 @@ nserror url_escape(const char *unescaped, size_t toskip, 
bool sptoplus,
 /**
  * Convert an escaped string to plain.
  *
- * \param[in] str String to unescape.
- * \parm[in] length Length of string or 0 to use strlen
- * \param[out] result unescaped string owned by caller must be freed with 
free()
+ * \param[in]  str         String to unescape.
+ * \param[in]  length      Length of string or 0 to use strlen.
+ * \param[out] length_out  Iff non-NULL, value updated to length of returned
+ *                         result_out string.
+ * \param[out] result_out  Returns unescaped string, owned by caller.
+ *                         Must be freed with free().
  * \return NSERROR_OK on success
  */
-nserror url_unescape(const char *str, int length, char **result);
+nserror url_unescape(const char *str, size_t length,
+               size_t *length_out, char **result_out);
 
 #endif


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to