]> sjero.net Git - wget/commitdiff
The prefered way is to avoid #ifdef flooding, so take it that way. Introduce iri...
authorSaint Xavier <wget@sxav.eu>
Thu, 19 Jun 2008 20:07:03 +0000 (22:07 +0200)
committerSaint Xavier <wget@sxav.eu>
Thu, 19 Jun 2008 20:07:03 +0000 (22:07 +0200)
ChangeLog
configure.ac
src/ChangeLog
src/Makefile.am
src/build_info.c
src/http.c
src/init.c
src/iri.c [new file with mode: 0644]
src/iri.h [new file with mode: 0644]
src/main.c
src/options.h

index 407ce64cf8222706348e5aa55d7ee3345595f81a..8177dc97a6c1404b92913c58f20bf23a80e97e10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-06-14  Xavier Saint  <wget@sxav.eu>
+
+       * configure.ac: Add support for IRIs
+
 2008-05-29  Micah Cowan  <micah@cowan.name>
 
        * po/*.po: Updated from TP (the 1.11.3 set).
index 8100f48b3fe6e424b4211080674e89aaa361bf80..44f397b91b23054eaa98c2766bcfac3450c4243a 100644 (file)
@@ -512,6 +512,10 @@ if test "X$iri" != "Xno"; then
 fi
 
 
+dnl Needed by src/Makefile.am
+AM_CONDITIONAL([IRI_IS_ENABLED], [test "X$iri" != "Xno"])
+
+
 dnl
 dnl Create output
 dnl
index 9af9267b4495c37851f5d0fac24aeb40bb2a969d..ac27e15afa7cb3c034eaad64852efc9b0d0d42ff 100644 (file)
@@ -1,3 +1,18 @@
+2008-06-14  Xavier Saint  <wget@sxav.eu>
+
+       * iri.c, iri.h : New files.
+
+       * Makefile.am : Add files iri.h and conditional iri.c.
+
+       * build_info.c : Add compiled feature "iri".
+
+       * http.c : include iri.h and parse charset from Content-Type
+       header.
+
+       * init.c, main.c, options.h : if an options isn't supported
+       at compiled time, don't get rid off it and show a dummy
+       message instead if they are used.
+
 2008-06-13  Micah Cowan  <micah@cowan.name>
 
        * build_info.c: ENABLE_NTLM, not HAVE_NTLM.
index c8485cfd8125d3877160f990d1a805aa02ee10d2..379a9b8cd791f535957a49bcef28cbb63a51b3e3 100644 (file)
 # Version: @VERSION@
 #
 
+if IRI_IS_ENABLED
+IRI_OBJ = iri.c
+endif
+
 # The following line is losing on some versions of make!
 DEFS     = @DEFS@ -DSYSTEM_WGETRC=\"$(sysconfdir)/wgetrc\" -DLOCALEDIR=\"$(localedir)\"
 LIBS     = @LIBSSL@ @LIBGNUTLS@ @LIBINTL@ @LIBS@
@@ -39,10 +43,10 @@ wget_SOURCES = build_info.c cmpt.c connect.c convert.c cookies.c ftp.c    \
               ftp-basic.c ftp-ls.c hash.c host.c html-parse.c html-url.c \
               http.c init.c log.c main.c netrc.c progress.c ptimer.c     \
               recur.c res.c retr.c snprintf.c spider.c url.c             \
-              utils.c                                    \
+              utils.c $(IRI_OBJ)                                         \
               connect.h convert.h cookies.h                              \
               ftp.h gen-md5.h hash.h host.h html-parse.h                 \
-              http.h http-ntlm.h init.h log.h mswindows.h netrc.h        \
+              http.h http-ntlm.h init.h iri.h log.h mswindows.h netrc.h  \
               options.h progress.h ptimer.h recur.h res.h retr.h         \
               spider.h ssl.h sysdep.h url.h utils.h wget.h
 nodist_wget_SOURCES = version.c
index 1ac682a75be9b7a313f7555e5fbc2cd779a38e53..129bf7264dae6f5d867a32413bc9b6d3d50b4431 100644 (file)
@@ -100,6 +100,13 @@ const char* (compiled_features[]) =
 #else
   "-gettext",
 #endif
+
+#ifdef ENABLE_IRI
+  "+iri",
+#else
+  "-iri",
+#endif
+
   /* sentinel value */
   NULL
 };
index 543165fdd0a7b75f05859b7ad021ccec8b539144..741ed2c003fb9a29855725c49fec1b86979c2d48 100644 (file)
@@ -49,6 +49,7 @@ as that of the covered work.  */
 #include "retr.h"
 #include "connect.h"
 #include "netrc.h"
+#include "iri.h"
 #ifdef HAVE_SSL
 # include "ssl.h"
 #endif
@@ -2040,32 +2041,16 @@ File %s already there; not retrieving.\n\n"), quote (hs->local_file));
       char *tmp = strchr (type, ';');
       if (tmp)
         {
-#ifdef ENABLE_IRI
+          /* sXXXav: only needed if IRI support is enabled */
           char *tmp2 = tmp + 1;
-#endif
 
           while (tmp > type && c_isspace (tmp[-1]))
             --tmp;
           *tmp = '\0';
 
-#ifdef ENABLE_IRI
-          if (opt.enable_iri && *tmp2 != '\0' &&
-              (tmp = strstr (tmp2, "charset=")) != NULL)
-            {
-              tmp += 8;
-              tmp2 = tmp;
-
-              while (*tmp2 && !c_isspace (*tmp2))
-                tmp2++;
-
-              if (tmp2 > tmp)
-                {
-                  *tmp2 = '\0';
-                  /* sXXXav : check given charset */
-                  logprintf (LOG_VERBOSE, "HTTP charset: `%s'\n", tmp);
-                }
-            }
-#endif
+          /* Try to get remote encoding if needed */
+          if (opt.enable_iri && !opt.encoding_remote)
+            /* xxx = */ parse_charset (tmp2);
         }
     }
   hs->newloc = resp_header_strdup (resp, "Location");
index 167c84fea7a6dd297be54fdb98a1e638fcf040bc..a7a4ee01e5eda918aaeba5eb97ccec9d103a1722 100644 (file)
@@ -181,15 +181,11 @@ static const struct {
   { "inet6only",        &opt.ipv6_only,         cmd_boolean },
 #endif
   { "input",            &opt.input_filename,    cmd_file },
-#ifdef ENABLE_IRI
   { "iri",              &opt.enable_iri,        cmd_boolean },
-#endif
   { "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean },
   { "limitrate",        &opt.limit_rate,        cmd_bytes },
   { "loadcookies",      &opt.cookies_input,     cmd_file },
-#ifdef ENABLE_IRI
   { "locale",           &opt.locale,            cmd_string },
-#endif
   { "logfile",          &opt.lfilename,         cmd_file },
   { "login",            &opt.ftp_user,          cmd_string },/* deprecated*/
   { "maxredirect",      &opt.max_redirect,      cmd_number },
@@ -229,9 +225,7 @@ static const struct {
   { "referer",          &opt.referer,           cmd_string },
   { "reject",           &opt.rejects,           cmd_vector },
   { "relativeonly",     &opt.relative_only,     cmd_boolean },
-#ifdef ENABLE_IRI
   { "remoteencoding",   &opt.encoding_remote,   cmd_string },
-#endif
   { "removelisting",    &opt.remove_listing,    cmd_boolean },
   { "restrictfilenames", NULL,                  cmd_spec_restrict_file_names },
   { "retrsymlinks",     &opt.retr_symlinks,     cmd_boolean },
diff --git a/src/iri.c b/src/iri.c
new file mode 100644 (file)
index 0000000..e4f4622
--- /dev/null
+++ b/src/iri.c
@@ -0,0 +1,70 @@
+/* IRI related functions.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2008 Free Software Foundation, Inc.
+
+This file is part of GNU Wget.
+
+GNU Wget is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at
+your option) any later version.
+
+GNU Wget is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Wget.  If not, see <http://www.gnu.org/licenses/>.
+
+Additional permission under GNU GPL version 3 section 7
+
+If you modify this program, or any covered work, by linking or
+combining it with the OpenSSL project's OpenSSL library (or a
+modified version of that library), containing parts covered by the
+terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
+grants you additional permission to convey the resulting work.
+Corresponding Source for a non-source form of such a combination
+shall include the source code for the parts of OpenSSL used as well
+as that of the covered work.  */
+
+#include "wget.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+#include "utils.h"
+#include "iri.h"
+
+
+/* Given a string containing "charset=XXX", return the encoding if found,
+   or NULL otherwise */
+char *
+parse_charset (char *str)
+{
+  char *charset;
+
+  if (!str || !*str)
+    return NULL;
+
+  str = strcasestr (str, "charset=");
+  if (!str)
+    return NULL;
+
+  str += 8;
+  charset = str;
+
+  /* sXXXav: which chars should be banned ??? */
+  while (*charset && !c_isspace (*charset))
+    charset++;
+
+  /* sXXXav: could strdupdelim return NULL ? */
+  charset = strdupdelim (str, charset);
+  logprintf (LOG_VERBOSE, "parse_charset: %s\n", quote (charset));
+
+  return charset;
+}
+
+
diff --git a/src/iri.h b/src/iri.h
new file mode 100644 (file)
index 0000000..d135e86
--- /dev/null
+++ b/src/iri.h
@@ -0,0 +1,43 @@
+/* Internationalization related declarations.
+   Copyright (C) 2000, 2007, 2008 Free Software Foundation, Inc.
+
+This file is part of GNU Wget.
+
+GNU Wget is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+GNU Wget is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Wget.  If not, see <http://www.gnu.org/licenses/>.
+
+Additional permission under GNU GPL version 3 section 7
+
+If you modify this program, or any covered work, by linking or
+combining it with the OpenSSL project's OpenSSL library (or a
+modified version of that library), containing parts covered by the
+terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
+grants you additional permission to convey the resulting work.
+Corresponding Source for a non-source form of such a combination
+shall include the source code for the parts of OpenSSL used as well
+as that of the covered work.  */
+
+#ifndef IRI_H
+#define IRI_H
+
+#ifdef ENABLE_IRI
+
+char *parse_charset (char *str);
+
+
+#else /* ENABLE_IRI */
+
+#define parse_charset(str)     /* no-op */
+
+#endif /* ENABLE_IRI */
+#endif /* IRI_H */
index 9b449438468c7e31dea9d2c18528863bb7a1e4e9..8002c1be2a0303e08702fab8f4556665f4de5169 100644 (file)
@@ -203,16 +203,12 @@ static struct cmdline_option option_data[] =
     { "inet6-only", '6', OPT_BOOLEAN, "inet6only", -1 },
 #endif
     { "input-file", 'i', OPT_VALUE, "input", -1 },
-#ifdef ENABLE_IRI
     { "iri", 0, OPT_BOOLEAN, "iri", -1 },
-#endif
     { "keep-session-cookies", 0, OPT_BOOLEAN, "keepsessioncookies", -1 },
     { "level", 'l', OPT_VALUE, "reclevel", -1 },
     { "limit-rate", 0, OPT_VALUE, "limitrate", -1 },
     { "load-cookies", 0, OPT_VALUE, "loadcookies", -1 },
-#ifdef ENABLE_IRI
     { "locale", 0, OPT_VALUE, "locale", -1 },
-#endif
     { "max-redirect", 0, OPT_VALUE, "maxredirect", -1 },
     { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
     { "no", 'n', OPT__NO, NULL, required_argument },
@@ -246,9 +242,7 @@ static struct cmdline_option option_data[] =
     { "referer", 0, OPT_VALUE, "referer", -1 },
     { "reject", 'R', OPT_VALUE, "reject", -1 },
     { "relative", 'L', OPT_BOOLEAN, "relativeonly", -1 },
-#ifdef ENABLE_IRI
     { "remote-encoding", 0, OPT_VALUE, "remoteencoding", -1},
-#endif
     { "remove-listing", 0, OPT_BOOLEAN, "removelisting", -1 },
     { "restrict-file-names", 0, OPT_BOOLEAN, "restrictfilenames", -1 },
     { "retr-symlinks", 0, OPT_BOOLEAN, "retrsymlinks", -1 },
@@ -1085,6 +1079,13 @@ for details.\n\n"));
           logprintf (LOG_VERBOSE, "Check the locale...\n");
         }
     }
+#else
+  if (opt.enable_iri || opt.locale || opt.encoding_remote)
+    {
+      /* sXXXav : be more specific... */
+      printf(_("This version does not have support for IRIs\n"));
+      exit(1);
+    }
 #endif
 
   if (opt.ask_passwd)
index 2927a37cf6a2307d2437777baf8255eecb1fd268..723f80a170951e8b1c9e78e2990b5b02b7c22e80 100644 (file)
@@ -238,11 +238,9 @@ struct options
   bool auth_without_challenge;  /* Issue Basic authentication creds without
                                    waiting for a challenge. */
 
-#ifdef ENABLE_IRI
   bool enable_iri;
   char *encoding_remote;
   char *locale;
-#endif
 };
 
 extern struct options opt;