]> sjero.net Git - wget/blob - src/url.h
[svn] Handle <base href=...> when converting links.
[wget] / src / url.h
1 /* Declarations for url.c.
2    Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3
4 This file is part of GNU Wget.
5
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.
10
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.
15
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.  */
19
20 #ifndef URL_H
21 #define URL_H
22
23 /* Default port definitions */
24 #define DEFAULT_HTTP_PORT 80
25 #define DEFAULT_FTP_PORT 21
26 #define DEFAULT_HTTPS_PORT 443
27
28 /* Note: the ordering here is related to the order of elements in
29    `supported_schemes' in url.c.  */
30
31 enum url_scheme {
32   SCHEME_HTTP,
33 #ifdef HAVE_SSL
34   SCHEME_HTTPS,
35 #endif
36   SCHEME_FTP,
37   SCHEME_INVALID
38 };
39
40 /* Structure containing info on a URL.  */
41 struct url
42 {
43   char *url;                    /* Original URL */
44   enum url_scheme scheme;       /* URL scheme */
45
46   char *host;                   /* Extracted hostname */
47   int port;                     /* Port number */
48
49   /* URL components (URL-quoted). */
50   char *path;
51   char *params;
52   char *query;
53   char *fragment;
54
55   /* Extracted path info (unquoted). */
56   char *dir;
57   char *file;
58
59   /* Username and password (unquoted). */
60   char *user;
61   char *passwd;
62 };
63
64 enum convert_options {
65   CO_NOCONVERT = 0,             /* don't convert this URL */
66   CO_CONVERT_TO_RELATIVE,       /* convert to relative, e.g. to
67                                    "../../otherdir/foo.gif" */
68   CO_CONVERT_TO_COMPLETE,       /* convert to absolute, e.g. to
69                                    "http://orighost/somedir/bar.jpg". */
70   CO_NULLIFY_BASE               /* change to empty string. */
71 };
72
73 /* A structure that defines the whereabouts of a URL, i.e. its
74    position in an HTML document, etc.  */
75
76 struct urlpos {
77   struct url *url;              /* the URL of the link, after it has
78                                    been merged with the base */
79   char *local_name;             /* local file to which it was saved
80                                    (used by convert_links) */
81
82   int ignore_when_downloading;  /* reserved for special links such as
83                                    <base href="..."> which are used
84                                    when converting links, but ignored
85                                    when downloading.  */
86
87   /* Information about the original link: */
88   int link_relative_p;          /* was the link relative? */
89   int link_complete_p;          /* was the link complete (with the
90                                    host name, etc.) */
91   int link_base_p;              /* was the link <base href=...> */
92
93   /* Conversion requirements: */
94   enum convert_options convert; /* is conversion required? */
95
96   /* URL's position in the buffer. */
97   int pos, size;
98
99   struct urlpos *next;          /* next list element */
100 };
101
102 /* downloaded_file() takes a parameter of this type and returns this type. */
103 typedef enum
104 {
105   /* Return enumerators: */
106   FILE_NOT_ALREADY_DOWNLOADED = 0,
107
108   /* Return / parameter enumerators: */
109   FILE_DOWNLOADED_NORMALLY,
110   FILE_DOWNLOADED_AND_HTML_EXTENSION_ADDED,
111
112   /* Parameter enumerators: */
113   CHECK_FOR_FILE
114 } downloaded_file_t;
115
116 /* Function declarations */
117
118 char *encode_string PARAMS ((const char *));
119
120 struct url *url_parse PARAMS ((const char *, int *));
121 const char *url_error PARAMS ((int));
122 char *url_full_path PARAMS ((const struct url *));
123 void url_set_dir PARAMS ((struct url *, const char *));
124 void url_set_file PARAMS ((struct url *, const char *));
125 void url_free PARAMS ((struct url *));
126
127 enum url_scheme url_scheme PARAMS ((const char *));
128 int url_skip_scheme PARAMS ((const char *));
129 int url_has_scheme PARAMS ((const char *));
130 int scheme_default_port PARAMS ((enum url_scheme));
131
132 int url_skip_uname PARAMS ((const char *));
133
134 char *url_string PARAMS ((const struct url *, int));
135
136 struct urlpos *get_urls_file PARAMS ((const char *));
137 struct urlpos *get_urls_html PARAMS ((const char *, const char *, int, int *));
138 void free_urlpos PARAMS ((struct urlpos *));
139
140 char *uri_merge PARAMS ((const char *, const char *));
141
142 void rotate_backups PARAMS ((const char *));
143 int mkalldirs PARAMS ((const char *));
144 char *url_filename PARAMS ((const struct url *));
145
146 char *getproxy PARAMS ((enum url_scheme));
147 int no_proxy_match PARAMS ((const char *, const char **));
148
149 void convert_links PARAMS ((const char *, struct urlpos *));
150
151 downloaded_file_t downloaded_file PARAMS ((downloaded_file_t, const char *));
152
153 char *rewrite_shorthand_url PARAMS ((const char *));
154
155 #endif /* URL_H */