fetch.c (1ba84976606b34e81005aefcb131d48fe22a1118) fetch.c (38c7e4a631ce968b02e4a08944aabad9b57844e8)
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 56 unchanged lines hidden (view full) ---

65/*** Public API **************************************************************/
66
67/*
68 * Select the appropriate protocol for the URL scheme, and return a
69 * read-only stream connected to the document referenced by the URL.
70 * Also fill out the struct url_stat.
71 */
72FILE *
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 56 unchanged lines hidden (view full) ---

65/*** Public API **************************************************************/
66
67/*
68 * Select the appropriate protocol for the URL scheme, and return a
69 * read-only stream connected to the document referenced by the URL.
70 * Also fill out the struct url_stat.
71 */
72FILE *
73fetchXGet(struct url *URL, struct url_stat *us, char *flags)
73fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
74{
75 int direct;
76
77 direct = CHECK_FLAG('d');
78 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
79 return fetchXGetFile(URL, us, flags);
80 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
81 return fetchXGetHTTP(URL, us, flags);

--- 5 unchanged lines hidden (view full) ---

87 }
88}
89
90/*
91 * Select the appropriate protocol for the URL scheme, and return a
92 * read-only stream connected to the document referenced by the URL.
93 */
94FILE *
74{
75 int direct;
76
77 direct = CHECK_FLAG('d');
78 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
79 return fetchXGetFile(URL, us, flags);
80 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
81 return fetchXGetHTTP(URL, us, flags);

--- 5 unchanged lines hidden (view full) ---

87 }
88}
89
90/*
91 * Select the appropriate protocol for the URL scheme, and return a
92 * read-only stream connected to the document referenced by the URL.
93 */
94FILE *
95fetchGet(struct url *URL, char *flags)
95fetchGet(struct url *URL, const char *flags)
96{
97 return fetchXGet(URL, NULL, flags);
98}
99
100/*
101 * Select the appropriate protocol for the URL scheme, and return a
102 * write-only stream connected to the document referenced by the URL.
103 */
104FILE *
96{
97 return fetchXGet(URL, NULL, flags);
98}
99
100/*
101 * Select the appropriate protocol for the URL scheme, and return a
102 * write-only stream connected to the document referenced by the URL.
103 */
104FILE *
105fetchPut(struct url *URL, char *flags)
105fetchPut(struct url *URL, const char *flags)
106{
107 int direct;
108
109 direct = CHECK_FLAG('d');
110 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
111 return fetchPutFile(URL, flags);
112 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
113 return fetchPutHTTP(URL, flags);

--- 5 unchanged lines hidden (view full) ---

119 }
120}
121
122/*
123 * Select the appropriate protocol for the URL scheme, and return the
124 * size of the document referenced by the URL if it exists.
125 */
126int
106{
107 int direct;
108
109 direct = CHECK_FLAG('d');
110 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
111 return fetchPutFile(URL, flags);
112 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
113 return fetchPutHTTP(URL, flags);

--- 5 unchanged lines hidden (view full) ---

119 }
120}
121
122/*
123 * Select the appropriate protocol for the URL scheme, and return the
124 * size of the document referenced by the URL if it exists.
125 */
126int
127fetchStat(struct url *URL, struct url_stat *us, char *flags)
127fetchStat(struct url *URL, struct url_stat *us, const char *flags)
128{
129 int direct;
130
131 direct = CHECK_FLAG('d');
132 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
133 return fetchStatFile(URL, us, flags);
134 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
135 return fetchStatHTTP(URL, us, flags);

--- 5 unchanged lines hidden (view full) ---

141 }
142}
143
144/*
145 * Select the appropriate protocol for the URL scheme, and return a
146 * list of files in the directory pointed to by the URL.
147 */
148struct url_ent *
128{
129 int direct;
130
131 direct = CHECK_FLAG('d');
132 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
133 return fetchStatFile(URL, us, flags);
134 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
135 return fetchStatHTTP(URL, us, flags);

--- 5 unchanged lines hidden (view full) ---

141 }
142}
143
144/*
145 * Select the appropriate protocol for the URL scheme, and return a
146 * list of files in the directory pointed to by the URL.
147 */
148struct url_ent *
149fetchList(struct url *URL, char *flags)
149fetchList(struct url *URL, const char *flags)
150{
151 int direct;
152
153 direct = CHECK_FLAG('d');
154 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
155 return fetchListFile(URL, flags);
156 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
157 return fetchListHTTP(URL, flags);

--- 4 unchanged lines hidden (view full) ---

162 return NULL;
163 }
164}
165
166/*
167 * Attempt to parse the given URL; if successful, call fetchXGet().
168 */
169FILE *
150{
151 int direct;
152
153 direct = CHECK_FLAG('d');
154 if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
155 return fetchListFile(URL, flags);
156 else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
157 return fetchListHTTP(URL, flags);

--- 4 unchanged lines hidden (view full) ---

162 return NULL;
163 }
164}
165
166/*
167 * Attempt to parse the given URL; if successful, call fetchXGet().
168 */
169FILE *
170fetchXGetURL(char *URL, struct url_stat *us, char *flags)
170fetchXGetURL(const char *URL, struct url_stat *us, const char *flags)
171{
172 struct url *u;
173 FILE *f;
174
175 if ((u = fetchParseURL(URL)) == NULL)
176 return NULL;
177
178 f = fetchXGet(u, us, flags);
179
180 fetchFreeURL(u);
181 return f;
182}
183
184/*
185 * Attempt to parse the given URL; if successful, call fetchGet().
186 */
187FILE *
171{
172 struct url *u;
173 FILE *f;
174
175 if ((u = fetchParseURL(URL)) == NULL)
176 return NULL;
177
178 f = fetchXGet(u, us, flags);
179
180 fetchFreeURL(u);
181 return f;
182}
183
184/*
185 * Attempt to parse the given URL; if successful, call fetchGet().
186 */
187FILE *
188fetchGetURL(char *URL, char *flags)
188fetchGetURL(const char *URL, const char *flags)
189{
190 return fetchXGetURL(URL, NULL, flags);
191}
192
193/*
194 * Attempt to parse the given URL; if successful, call fetchPut().
195 */
196FILE *
189{
190 return fetchXGetURL(URL, NULL, flags);
191}
192
193/*
194 * Attempt to parse the given URL; if successful, call fetchPut().
195 */
196FILE *
197fetchPutURL(char *URL, char *flags)
197fetchPutURL(const char *URL, const char *flags)
198{
199 struct url *u;
200 FILE *f;
201
202 if ((u = fetchParseURL(URL)) == NULL)
203 return NULL;
204
205 f = fetchPut(u, flags);
206
207 fetchFreeURL(u);
208 return f;
209}
210
211/*
212 * Attempt to parse the given URL; if successful, call fetchStat().
213 */
214int
198{
199 struct url *u;
200 FILE *f;
201
202 if ((u = fetchParseURL(URL)) == NULL)
203 return NULL;
204
205 f = fetchPut(u, flags);
206
207 fetchFreeURL(u);
208 return f;
209}
210
211/*
212 * Attempt to parse the given URL; if successful, call fetchStat().
213 */
214int
215fetchStatURL(char *URL, struct url_stat *us, char *flags)
215fetchStatURL(const char *URL, struct url_stat *us, const char *flags)
216{
217 struct url *u;
218 int s;
219
220 if ((u = fetchParseURL(URL)) == NULL)
221 return -1;
222
223 s = fetchStat(u, us, flags);
224
225 fetchFreeURL(u);
226 return s;
227}
228
229/*
230 * Attempt to parse the given URL; if successful, call fetchList().
231 */
232struct url_ent *
216{
217 struct url *u;
218 int s;
219
220 if ((u = fetchParseURL(URL)) == NULL)
221 return -1;
222
223 s = fetchStat(u, us, flags);
224
225 fetchFreeURL(u);
226 return s;
227}
228
229/*
230 * Attempt to parse the given URL; if successful, call fetchList().
231 */
232struct url_ent *
233fetchListURL(char *URL, char *flags)
233fetchListURL(const char *URL, const char *flags)
234{
235 struct url *u;
236 struct url_ent *ue;
237
238 if ((u = fetchParseURL(URL)) == NULL)
239 return NULL;
240
241 ue = fetchList(u, flags);
242
243 fetchFreeURL(u);
244 return ue;
245}
246
247/*
248 * Make a URL
249 */
250struct url *
234{
235 struct url *u;
236 struct url_ent *ue;
237
238 if ((u = fetchParseURL(URL)) == NULL)
239 return NULL;
240
241 ue = fetchList(u, flags);
242
243 fetchFreeURL(u);
244 return ue;
245}
246
247/*
248 * Make a URL
249 */
250struct url *
251fetchMakeURL(char *scheme, char *host, int port, char *doc,
252 char *user, char *pwd)
251fetchMakeURL(const char *scheme, const char *host, int port, const char *doc,
252 const char *user, const char *pwd)
253{
254 struct url *u;
255
256 if (!scheme || (!host && !doc)) {
257 _url_seterr(URL_MALFORMED);
258 return NULL;
259 }
260

--- 26 unchanged lines hidden (view full) ---

287}
288
289/*
290 * Split an URL into components. URL syntax is:
291 * [method:/][/[user[:pwd]@]host[:port]/][document]
292 * This almost, but not quite, RFC1738 URL syntax.
293 */
294struct url *
253{
254 struct url *u;
255
256 if (!scheme || (!host && !doc)) {
257 _url_seterr(URL_MALFORMED);
258 return NULL;
259 }
260

--- 26 unchanged lines hidden (view full) ---

287}
288
289/*
290 * Split an URL into components. URL syntax is:
291 * [method:/][/[user[:pwd]@]host[:port]/][document]
292 * This almost, but not quite, RFC1738 URL syntax.
293 */
294struct url *
295fetchParseURL(char *URL)
295fetchParseURL(const char *URL)
296{
296{
297 char *doc, *p, *q;
297 char *doc;
298 const char *p, *q;
298 struct url *u;
299 int i;
300
301 /* allocate struct url */
302 if ((u = calloc(1, sizeof *u)) == NULL) {
303 _fetch_syserr();
304 return NULL;
305 }

--- 118 unchanged lines hidden ---
299 struct url *u;
300 int i;
301
302 /* allocate struct url */
303 if ((u = calloc(1, sizeof *u)) == NULL) {
304 _fetch_syserr();
305 return NULL;
306 }

--- 118 unchanged lines hidden ---