1 /* Miscellaneous declarations.
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GNU Wget.
6 GNU Wget is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 GNU Wget is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Wget; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 In addition, as a special exception, the Free Software Foundation
21 gives permission to link the code of its release of Wget with the
22 OpenSSL project's "OpenSSL" library (or with modified versions of it
23 that use the same license as the "OpenSSL" library), and distribute
24 the linked executables. You must obey the GNU General Public License
25 in all respects for all of the code used other than "OpenSSL". If you
26 modify this file, you may extend this exception to your version of the
27 file, but you are not obligated to do so. If you do not wish to do
28 so, delete this exception statement from your version. */
30 /* This file contains some declarations that don't fit anywhere else.
31 It also contains some useful includes, like the obnoxious TIME_H
37 /* Disable assertions when debug support is not compiled in. */
42 /* Define this if you want primitive but extensive malloc debugging.
43 It will make Wget extremely slow, so only do it in development
49 # define PARAMS(args) args
51 # define PARAMS(args) ()
55 /* `gettext (FOO)' is long to write, so we use `_(FOO)'. If NLS is
56 unavailable, _(STRING) simply returns STRING. */
58 # define _(string) gettext (string)
59 # ifdef HAVE_LIBINTL_H
61 # endif /* HAVE_LIBINTL_H */
62 #else /* not HAVE_NLS */
63 # define _(string) string
64 #endif /* not HAVE_NLS */
66 /* No-op version of gettext, used for constant strings. */
67 #define N_(string) (string)
69 /* I18N NOTE: You will notice that none of the DEBUGP messages are
70 marked as translatable. This is intentional, for a few reasons:
72 1) The debug messages are not meant for the users to look at, but
73 for the developers; as such, they should be considered more like
74 source comments than real program output.
76 2) The messages are numerous, and yet they are random and frivolous
77 ("double yuck!" and such). There would be a lot of work with no
80 3) Finally, the debug messages are meant to be a clue for me to
81 debug problems with Wget. If I get them in a language I don't
82 understand, debugging will become a new challenge of its own! */
85 /* Include these, so random files need not include them. */
88 /* locale independent replacement for ctype.h */
89 #include "safe-ctype.h"
91 #define DO_NOTHING do {} while (0)
93 /* Print X if debugging is enabled; a no-op otherwise. */
95 # define DEBUGP(x) do { if (opt.debug) { debug_logprintf x; } } while (0)
96 #else /* not ENABLE_DEBUG */
97 # define DEBUGP(x) DO_NOTHING
98 #endif /* not ENABLE_DEBUG */
100 /* Everything uses this, so include them here directly. */
103 /* Likewise for logging functions. */
106 /* #### Find a better place for this. */
107 /* The log file to which Wget writes to after HUP. */
108 #define DEFAULT_LOGFILE "wget-log"
110 /* Useful macros used across the code: */
112 /* The number of elements in an array. For example:
113 static char a[] = "foo"; -- countof(a) == 4 (for terminating \0)
114 int a[5] = {1, 2}; -- countof(a) == 5
115 char *a[] = { -- countof(a) == 3
118 #define countof(array) (sizeof (array) / sizeof ((array)[0]))
120 /* Zero out a value. */
121 #define xzero(x) memset (&(x), '\0', sizeof ((x)))
123 /* Convert an ASCII hex digit to the corresponding number between 0
124 and 15. X should be a hexadecimal digit that satisfies isxdigit;
125 otherwise, the result is undefined. */
126 #define XDIGIT_TO_NUM(h) ((h) < 'A' ? (h) - '0' : TOUPPER (h) - 'A' + 10)
127 #define X2DIGITS_TO_NUM(h1, h2) ((XDIGIT_TO_NUM (h1) << 4) + XDIGIT_TO_NUM (h2))
129 /* The reverse of the above: convert a number in the [0, 16) range to
130 the ASCII representation of the corresponding hex digit. The `+ 0'
131 is so you don't accidentally use it as an lvalue. */
132 #define XNUM_TO_DIGIT(x) ("0123456789ABCDEF"[x] + 0)
133 #define XNUM_TO_digit(x) ("0123456789abcdef"[x] + 0)
135 /* Copy the data delimited with BEG and END to alloca-allocated
136 storage, and zero-terminate it. Arguments are evaluated only once,
137 in the order BEG, END, PLACE. */
138 #define BOUNDED_TO_ALLOCA(beg, end, place) do { \
139 const char *BTA_beg = (beg); \
140 int BTA_len = (end) - BTA_beg; \
141 char **BTA_dest = &(place); \
142 *BTA_dest = alloca (BTA_len + 1); \
143 memcpy (*BTA_dest, BTA_beg, BTA_len); \
144 (*BTA_dest)[BTA_len] = '\0'; \
147 /* Return non-zero if string bounded between BEG and END is equal to
148 STRING_LITERAL. The comparison is case-sensitive. */
149 #define BOUNDED_EQUAL(beg, end, string_literal) \
150 ((end) - (beg) == sizeof (string_literal) - 1 \
151 && !memcmp ((beg), (string_literal), \
152 sizeof (string_literal) - 1))
154 /* The same as above, except the comparison is case-insensitive. */
155 #define BOUNDED_EQUAL_NO_CASE(beg, end, string_literal) \
156 ((end) - (beg) == sizeof (string_literal) - 1 \
157 && !strncasecmp ((beg), (string_literal), \
158 sizeof (string_literal) - 1))
160 /* Note that this much more elegant definition cannot be used:
162 #define STRDUP_ALLOCA(str) (strcpy ((char *)alloca (strlen (str) + 1), str))
164 This is because some compilers don't handle alloca() as argument to
165 function correctly. Gcc on Intel platforms has been reported to
166 offend in this case. */
168 #define STRDUP_ALLOCA(ptr, str) do { \
169 char **SA_dest = &(ptr); \
170 const char *SA_src = (str); \
171 *SA_dest = (char *)alloca (strlen (SA_src) + 1); \
172 strcpy (*SA_dest, SA_src); \
175 /* Generally useful if you want to avoid arbitrary size limits but
176 don't need a full dynamic array. Assumes that BASEVAR points to a
177 malloced array of TYPE objects (or possibly a NULL pointer, if
178 SIZEVAR is 0), with the total size stored in SIZEVAR. This macro
179 will realloc BASEVAR as necessary so that it can hold at least
180 NEEDED_SIZE objects. The reallocing is done by doubling, which
181 ensures constant amortized time per element. */
182 #define DO_REALLOC(basevar, sizevar, needed_size, type) do { \
183 /* Avoid side effects by prefixing the local vars. */ \
184 long do_realloc_needed_size = (needed_size); \
185 long do_realloc_newsize = 0; \
186 while ((sizevar) < (do_realloc_needed_size)) { \
187 do_realloc_newsize = 2*(sizevar); \
188 if (do_realloc_newsize < 32) \
189 do_realloc_newsize = 32; \
190 (sizevar) = do_realloc_newsize; \
192 if (do_realloc_newsize) \
193 basevar = (type *)xrealloc (basevar, do_realloc_newsize * sizeof (type)); \
196 /* Free FOO if it is non-NULL. */
197 #define FREE_MAYBE(foo) do { if (foo) xfree ((foo)); } while (0)
199 extern const char *exec_name;
201 /* Document type ("dt") flags */
204 TEXTHTML = 0x0001, /* document is of type text/html
205 or application/xhtml+xml */
206 RETROKF = 0x0002, /* retrieval was OK */
207 HEAD_ONLY = 0x0004, /* only send the HEAD request */
208 SEND_NOCACHE = 0x0008, /* send Pragma: no-cache directive */
209 ACCEPTRANGES = 0x0010, /* Accept-ranges header was found */
210 ADDED_HTML_EXTENSION = 0x0020 /* added ".html" extension due to -E */
213 /* Universal error type -- used almost everywhere. Error reporting of
214 this detail is not generally used or needed and should be
218 NOCONERROR, HOSTERR, CONSOCKERR, CONERROR, CONSSLERR,
219 CONIMPOSSIBLE, NEWLOCATION, NOTENOUGHMEM, CONPORTERR,
220 BINDERR, BINDOK, LISTENERR, ACCEPTERR, ACCEPTOK,
221 CONCLOSED, FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR,
222 FTPNSFOD, FTPRETROK, FTPUNKNOWNTYPE, FTPRERR,
223 FTPREXC, FTPSRVERR, FTPRETRINT, FTPRESTFAIL, URLERROR,
224 FOPENERR, FWRITEERR, HOK, HLEXC, HEOF,
225 HERR, RETROK, RECLEVELEXC, FTPACCDENIED, WRONGCODE,
226 FTPINVPASV, FTPNOPASV,
227 CONTNOTSUPPORTED, RETRUNNEEDED, RETRFINISHED, READERR, TRYLIMEXC,
228 URLBADPATTERN, FILEBADFILE, RANGEERR, RETRBADPATTERN,
229 RETNOTSUP, ROBOTSOK, NOROBOTS, PROXERR, AUTHFAILED,
230 QUOTEXC, WRITEFAILED,
231 SSLERRCERTFILE,SSLERRCERTKEY,SSLERRCTXCREATE
234 /* These are not used widely. They should either be removed or used
236 typedef unsigned char boolean;
244 /* For most options, 0 means no limits, but with -p in the picture,
245 that causes a problem on the maximum recursion depth variable. To
246 retain backwards compatibility we allow users to consider "0" to be
247 synonymous with "inf" for -l, but internally infinite recursion is
248 specified by -1 and 0 means to only retrieve the requisites of a
250 #define INFINITE_RECURSION -1
252 /* In case old systems don't have EAFNOSUPPORT, which we use below. */
254 # define EAFNOSUPPORT EINVAL
257 #define CONNECT_ERROR(err) (( (err) == EAFNOSUPPORT \
259 || ((err) == ECONNREFUSED \
260 && !opt.retry_connrefused)) \
261 ? CONIMPOSSIBLE : CONERROR)