]> sjero.net Git - wget/commitdiff
Get rid of the supplementary bool pointer in url_parse () arguments; UGLY :)
authorSaint Xavier <wget@sxav.eu>
Sun, 20 Jul 2008 16:47:52 +0000 (18:47 +0200)
committerSaint Xavier <wget@sxav.eu>
Sun, 20 Jul 2008 16:47:52 +0000 (18:47 +0200)
src/html-url.c
src/iri.c
src/iri.h
src/main.c
src/recur.c
src/retr.c
src/url.c
src/url.h

index 0d580f9aaf74b3df8032756fc0ac929b541ea540..5a0682d3f80eaab886cdc997fa08ab3c5d26ef54 100644 (file)
@@ -274,7 +274,6 @@ append_url (const char *link_uri,
   struct urlpos *newel;
   const char *base = ctx->base ? ctx->base : ctx->parent_base;
   struct url *url;
-  bool utf8_encode = false;
 
   if (!base)
     {
@@ -293,7 +292,9 @@ append_url (const char *link_uri,
           return NULL;
         }
 
-      url = url_parse (link_uri, NULL, &utf8_encode);
+      set_ugly_no_encode (true);
+      url = url_parse (link_uri, NULL);
+      set_ugly_no_encode (false);
       if (!url)
         {
           DEBUGP (("%s: link \"%s\" doesn't parse.\n",
@@ -312,7 +313,9 @@ append_url (const char *link_uri,
       DEBUGP (("%s: merge(\"%s\", \"%s\") -> %s\n",
                ctx->document_file, base, link_uri, complete_uri));
 
-      url = url_parse (complete_uri, NULL, &utf8_encode);
+      set_ugly_no_encode (true);
+      url = url_parse (complete_uri, NULL);
+      set_ugly_no_encode (false);
       if (!url)
         {
           DEBUGP (("%s: merged link \"%s\" doesn't parse.\n",
@@ -661,7 +664,6 @@ get_urls_file (const char *file)
   struct file_memory *fm;
   struct urlpos *head, *tail;
   const char *text, *text_end;
-  bool utf8_encode = false;
 
   /* Load the file.  */
   fm = read_file (file);
@@ -713,7 +715,9 @@ get_urls_file (const char *file)
           url_text = merged;
         }
 
-      url = url_parse (url_text, &up_error_code, &utf8_encode);
+      set_ugly_no_encode (true);
+      url = url_parse (url_text, &up_error_code);
+      set_ugly_no_encode (false);
       if (!url)
         {
           logprintf (LOG_NOTQUIET, _("%s: Invalid URL %s: %s\n"),
index 32eb7210fdea7d2cbca2d8ab2414510611404c79..e5be2cf86bf3a171c14d0af191268f4d69ca85c7 100644 (file)
--- a/src/iri.c
+++ b/src/iri.c
@@ -43,6 +43,8 @@ as that of the covered work.  */
 
 char *remote;
 char *current;
+bool utf8_encode;
+bool ugly_no_encode;
 
 static iconv_t locale2utf8;
 
@@ -358,3 +360,28 @@ set_remote_as_current (void)
   remote = current ? xstrdup (current) : NULL;
 }
 
+void reset_utf8_encode (void)
+{
+  set_utf8_encode (opt.enable_iri);
+}
+
+void set_utf8_encode (bool encode)
+{
+  utf8_encode = encode;
+}
+
+bool get_utf8_encode (void)
+{
+  return utf8_encode;
+}
+
+void set_ugly_no_encode (bool ugly)
+{
+  ugly_no_encode = ugly;
+}
+
+bool get_ugly_no_encode (void)
+{
+  return ugly_no_encode;
+}
+
index 837dbfdda7d3761788fca1defe2e71d82fd82a07..413fb2f614f2c569569fd721cb5e768b8e4f3bb3 100644 (file)
--- a/src/iri.h
+++ b/src/iri.h
@@ -46,6 +46,13 @@ void set_current_charset (char *charset);
 void set_remote_charset (char *charset);
 void set_remote_as_current (void);
 bool remote_to_utf8 (const char *str, const char **new);
+void reset_utf8_encode (void);
+void set_utf8_encode (bool encode);
+bool get_utf8_encode (void);
+
+/* ugly ugly ugly */
+void set_ugly_no_encode (bool ugly);
+bool get_ugly_no_encode (void);
 
 #else /* ENABLE_IRI */
 
@@ -63,6 +70,9 @@ bool remote_to_utf8 (const char *str, const char **new);
 #define set_remote_charset(str)
 #define set_remote_as_current()
 #define remote_to_utf8(a,b)         false
+#define reset_utf8_encode()
+#define set_utf8_encode(a)
+#define get_utf8_encode()           false
 
 #endif /* ENABLE_IRI */
 #endif /* IRI_H */
index d0ff1d2194b267e8d12e8f5e32a377ea1de163e6..bf49bf8973b3bff84882ecd49f023bb9ea0a21a8 100644 (file)
@@ -1191,6 +1191,7 @@ WARNING: Can't reopen standard output in binary mode;\n\
       int dt;
 
       set_current_as_locale ();
+      set_ugly_no_encode (false);
 
       if ((opt.recursive || opt.page_requisites)
           && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (*t)))
index d8279c39e4b868b69a59cfbb958851e926cb8dd5..6f5da2ae77b9b33dfa612a10c2e8a847adc47f2f 100644 (file)
@@ -190,7 +190,6 @@ uerr_t
 retrieve_tree (const char *start_url)
 {
   uerr_t status = RETROK;
-  bool utf8_encode = false;
 
   /* The queue of URLs we need to load. */
   struct url_queue *queue;
@@ -200,8 +199,11 @@ retrieve_tree (const char *start_url)
   struct hash_table *blacklist;
 
   int up_error_code;
-  struct url *start_url_parsed = url_parse (start_url, &up_error_code, &utf8_encode);
+  struct url *start_url_parsed;
 
+  set_ugly_no_encode (true);
+  start_url_parsed= url_parse (start_url, &up_error_code);
+  set_ugly_no_encode (false);
   if (!start_url_parsed)
     {
       logprintf (LOG_NOTQUIET, "%s: %s.\n", start_url,
@@ -338,7 +340,9 @@ retrieve_tree (const char *start_url)
           if (children)
             {
               struct urlpos *child = children;
-              struct url *url_parsed = url_parsed = url_parse (url, NULL, &utf8_encode);
+              set_ugly_no_encode (true);
+              struct url *url_parsed = url_parse (url, NULL);
+              set_ugly_no_encode (false);
               char *referer_url = url;
               bool strip_auth = (url_parsed != NULL
                                  && url_parsed->user != NULL);
@@ -641,13 +645,14 @@ descend_redirect_p (const char *redirected, const char *original, int depth,
   struct url *orig_parsed, *new_parsed;
   struct urlpos *upos;
   bool success;
-  bool utf8_encode = false;
 
-  orig_parsed = url_parse (original, NULL, &utf8_encode);
+  set_ugly_no_encode (true);
+  orig_parsed = url_parse (original, NULL);
   assert (orig_parsed != NULL);
 
-  new_parsed = url_parse (redirected, NULL, &utf8_encode);
+  new_parsed = url_parse (redirected, NULL);
   assert (new_parsed != NULL);
+  set_ugly_no_encode (false);
 
   upos = xnew0 (struct urlpos);
   upos->url = new_parsed;
index 021060819d3aa8e36b44c539d0aee46908a1ad3a..dd4978a7acb17297d54b81e51fe4abc50b4f7384 100644 (file)
@@ -613,8 +613,6 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   char *saved_post_data = NULL;
   char *saved_post_file_name = NULL;
 
-  bool utf8_encoded = opt.enable_iri;
-
   /* If dt is NULL, use local storage.  */
   if (!dt)
     {
@@ -627,8 +625,10 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   if (file)
     *file = NULL;
 
+  reset_utf8_encode ();
+
  second_try:
-  u = url_parse (url, &up_error_code, &utf8_encoded);
+  u = url_parse (url, &up_error_code);
   if (!u)
     {
       logprintf (LOG_NOTQUIET, "%s: %s.\n", url, url_error (up_error_code));
@@ -652,9 +652,10 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   if (proxy)
     {
       /* sXXXav : support IRI for proxy */
-      bool proxy_utf8_encode = false;
       /* Parse the proxy URL.  */
-      proxy_url = url_parse (proxy, &up_error_code, &proxy_utf8_encode);
+      set_ugly_no_encode (true);
+      proxy_url = url_parse (proxy, &up_error_code);
+      set_ugly_no_encode (false);
       if (!proxy_url)
         {
           logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
@@ -729,10 +730,10 @@ retrieve_url (const char *origurl, char **file, char **newloc,
       xfree (mynewloc);
       mynewloc = construced_newloc;
 
-      utf8_encoded = opt.enable_iri;
+      reset_utf8_encode ();
 
       /* Now, see if this new location makes sense. */
-      newloc_parsed = url_parse (mynewloc, &up_error_code, &utf8_encoded);
+      newloc_parsed = url_parse (mynewloc, &up_error_code);
       if (!newloc_parsed)
         {
           logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc),
@@ -780,9 +781,9 @@ retrieve_url (const char *origurl, char **file, char **newloc,
     }
 
   /* Try to not encode in UTF-8 if fetching failed */
-  if (!(*dt & RETROKF) && utf8_encoded)
+  if (!(*dt & RETROKF) && get_utf8_encode ())
     {
-      utf8_encoded = false;
+      set_utf8_encode (false);
       /*printf ("[Fallbacking to non-utf8 for `%s'\n", url);*/
       goto second_try;
     }
@@ -1036,8 +1037,11 @@ getproxy (struct url *u)
 bool
 url_uses_proxy (const char *url)
 {
-  bool ret, utf8_encode = false;
-  struct url *u = url_parse (url, NULL, &utf8_encode);
+  bool ret;
+  struct url *u;
+  set_ugly_no_encode(true);
+  u= url_parse (url, NULL);
+  set_ugly_no_encode(false);
   if (!u)
     return false;
   ret = getproxy (u) != NULL;
index 32de9c751fdc358e94ed9422d2d191493b7a0949..c94895979a7c9f532f6497fcf9c0659efd55c18a 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -641,7 +641,7 @@ static const char *parse_errors[] = {
    error, and if ERROR is not NULL, also set *ERROR to the appropriate
    error code. */
 struct url *
-url_parse (const char *url, int *error, bool *utf8_encode)
+url_parse (const char *url, int *error)
 {
   struct url *u;
   const char *p;
@@ -671,12 +671,14 @@ url_parse (const char *url, int *error, bool *utf8_encode)
       goto error;
     }
 
-  if (opt.enable_iri && *utf8_encode)
+  if (opt.enable_iri && get_utf8_encode () && !get_ugly_no_encode ())
     {
       const char *new;
+      bool utf8_encode;
       url_unescape ((char *) url);
-      *utf8_encode = remote_to_utf8 (url, &new);
-      if (*utf8_encode)
+      utf8_encode = remote_to_utf8 (url, &new);
+      set_utf8_encode (utf8_encode);
+      if (utf8_encode)
         url = new;
     }
 
@@ -856,7 +858,7 @@ url_parse (const char *url, int *error, bool *utf8_encode)
 
   if (opt.enable_iri)
     {
-      char *new = idn_encode (u->host, *utf8_encode);
+      char *new = idn_encode (u->host, get_utf8_encode ());
       if (new)
         {
           xfree (u->host);
index a174568ed83d8c0c31986069510ab6e088c73d4c..7c8bcfed92875dbd21e98084a798e5b10761c448 100644 (file)
--- a/src/url.h
+++ b/src/url.h
@@ -84,7 +84,7 @@ struct url
 
 char *url_escape (const char *);
 
-struct url *url_parse (const char *, int *, bool *);
+struct url *url_parse (const char *, int *);
 const char *url_error (int);
 char *url_full_path (const struct url *);
 void url_set_dir (struct url *, const char *);