struct urlpos *newel;
const char *base = ctx->base ? ctx->base : ctx->parent_base;
struct url *url;
- bool utf8_encode = false;
if (!base)
{
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",
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",
struct file_memory *fm;
struct urlpos *head, *tail;
const char *text, *text_end;
- bool utf8_encode = false;
/* Load the file. */
fm = read_file (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"),
char *remote;
char *current;
+bool utf8_encode;
+bool ugly_no_encode;
static iconv_t locale2utf8;
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;
+}
+
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 */
#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 */
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)))
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;
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,
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);
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;
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)
{
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));
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"),
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),
}
/* 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;
}
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;
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;
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;
}
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);
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 *);