Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 531 lines (467 sloc) 13.203 kB
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
1 /* url.c */
2
3 #include "elvis.h"
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
4 #ifdef FEATURE_RCSID
5 char id_url[] = "$Id: url.c,v 2.24 2003/10/18 17:01:29 steve Exp $";
6 #endif
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
7
8 static char url_protocol[10];
9 static char url_site_port[50];
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
10 static char url_resource[1000];
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
11
12 #if USE_PROTOTYPES
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
13 static ELVBOOL parseurl(char *url);
14 # if defined(PROTOCOL_HTTP) || defined(PROTOCOL_FTP)
15 static char *findproxy(ELVBOOL never_direct);
16 # endif
17 #endif
18
19 #ifdef FEATURE_PROTO
20 /* This indicates whether we're current running a URL protocol alias. This is
21 * important because URL protocol aliases such as readMAILTO aren't allowed
22 * to switch buffers.
23 */
24 ELVBOOL urlprotobusy;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
25 #endif
26
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
27 /* Parse an URL, and return ElvTrue if successful. */
28 static ELVBOOL parseurl(url)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
29 char *url;
30 {
31 int i;
32
33 /* Copy the protocol into url_protocol[], converting to lowercase */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
34 for (i = 0; i < QTY(url_protocol) - 1 && elvalpha(url[i]); i++)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
35 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
36 url_protocol[i] = elvtolower(url[i]);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
37 }
38 url_protocol[i] = '\0';
39
40 /* We expect a colon after the protocol. If we don't have that, then
41 * fail. Also fail if the protocol is less than two characters long,
42 * so we don't mistake the "C:" drive letter for a protocol.
43 */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
44 if (url[i++] != ':' || i < 3)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
45 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
46 /* Directories are treated like "dir:" protocol */
47 if (dirperm(url) == DIR_DIRECTORY)
48 {
49 strcpy(url_protocol, "dir");
50 *url_site_port = '\0';
51 strcpy(url_resource, url);
52 return ElvTrue;
53 }
54
55 /* else non-file or a normal file */
56 return ElvFalse;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
57 }
58
59 /* Check for a host. Not all protocols require one. */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
60 url += i;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
61 url_site_port[0] = '\0';
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
62 if ((url[0] == '/' || url[0] == '\\') && url[1] == url[0])
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
63 {
64 url += 2;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
65 for (i = 0; i < QTY(url_site_port) - 1 && *url && *url != '/' && *url != '\\'; i++, url++)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
66 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
67 url_site_port[i] = elvtolower(*url);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
68 }
69 url_site_port[i] = '\0';
70 }
71
72 /* The rest of the URL is assumed to be a resource name. If it is a
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
73 * null string, then assume it should be "/". Convert backslashes to
74 * forward slashes.
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
75 */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
76 if (!*url)
77 strcpy(url_resource, "/");
78 else
79 {
80 for (i = 0; i < QTY(url_resource) - 1 && *url; url++, i++)
81 if (*url == '\\')
82 url_resource[i] = '/';
83 else
84 url_resource[i] = *url;
85 url_resource[i] = '\0';
86 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
87
88 /* some debugging code */
3a9bb55 @mbert Import Elvis 2.1_3 (written by Steve Kirkendall)
authored
89 if (o_verbose >= 4)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
90 msg(MSG_INFO, "[sss]protocol=$1, site_port=$2, resource=$3",
91 url_protocol, url_site_port, url_resource);
92
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
93 return ElvTrue;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
94 }
95
96 /* If the URL refers to a local file, this returns the name of the
97 * file. This handles "file:" protocol and names which have no
98 * protocol; for all others it returns NULL. It is also smart enough
99 * to realize that "C:" is a drive letter rather than a protocol.
100 */
101 char *urllocal(url)
102 char *url;
103 {
104 if (!parseurl(url))
105 return url;
106 else if (!strcmp(url_protocol, "file"))
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
107 return url + 5;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
108 return NULL;
109 }
110
111 /* Check the permissions on a URL. */
112 DIRPERM urlperm(url)
113 char *url;
114 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
115 /* "-" is used for stdio -- not an actual filename */
116 if (!strcmp(url, "-"))
117 return DIR_READWRITE;
118
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
119 #if defined(PROTOCOL_HTTP) || defined(PROTOCOL_FTP)
120 /* Verify that this is a remote URL, other than mailto:. This also
121 * has the side-effect of parsing the URL. For local URLs try using
122 * the dirperm() function.
123 */
124 if (!urlremote(url))
125 return dirperm(url);
126
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
127 # ifdef PROTOCOL_FTP
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
128 /* If the protocol is anything other than "ftp" then assume the URL
129 * exists and is readonly.
130 */
131 if (strcmp(url_protocol, "ftp"))
132 return DIR_READONLY;
133
134 /* Else use FTP to inspect the file (not easy!) and then return
135 * whatever permissions it found.
136 */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
137 (void)ftpopen(url_site_port, url_resource, ElvFalse, 'p');
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
138 return ftpperms;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
139 # else /* PROTOCOL_HTTP but not PROTOCOL_FTP */
140 /* it must be HTTP, which is readonly */
141 return DIR_READONLY;
142 # endif
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
143
144 #else /* no network protocols */
145
146 return dirperm(url);
147 #endif
148 }
149
150
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
151 #ifdef FEATURE_PROTO
152
153 /* If this is a URL and its protocol is the same as a readXXX or writeXXX
154 * alias, then run the alias and return RESULT_COMPLETE or RESULT_ERROR
155 * to indicate the result. Otherwise return RESULT_MORE.
156 */
157 RESULT urlalias(from, to, url)
158 MARK from; /* starting mark */
159 MARK to; /* ending mark when writing, or NULL when reading */
160 char *url; /* URL to read */
161 {
162 char name[20];/* name of a possible alias */
163 EXINFO xinf; /* a constructed ex command line */
164 RESULT result;
165 int i, j;
166
167 /* try to extract the protocol */
168 if (!parseurl(url))
169 return RESULT_MORE;
170
171 /* is there an alias with this name? */
172 strcpy(name, to ? "write" : "read");
173 for (i=0, j=strlen(name); (name[j++] = elvtoupper(url_protocol[i++])); )
174 {
175 }
176 memset(&xinf, 0, sizeof xinf);
177 xinf.cmdname = exisalias(name, ElvFalse);
178 if (!xinf.cmdname)
179 return RESULT_MORE;
180
181 /* turn on the buffer's userprotocol option */
182 o_userprotocol(markbuffer(from)) = ElvTrue;
183
184 /* construct an ex command, and execute it */
185 xinf.command = EX_DOPROTO;
186 xinf.window = windefault;
187 xinf.defaddr = *from;
188 xinf.fromaddr = from;
189 xinf.toaddr = to ? to : from;
190 xinf.from = markline(from);
191 xinf.to = markline(xinf.toaddr) - 1;
192 xinf.anyaddr = (ELVBOOL)(markoffset(xinf.toaddr) > 0);
193 (void)buildstr(&xinf.rhs, url);
194 urlprotobusy = ElvTrue;
195 result = ex_doalias(&xinf);
196 urlprotobusy = ElvFalse;
197 safefree(xinf.rhs);
198
199 /* return the result */
200 return result;
201 }
202
203 #endif /* FEATURE_PROTO */
204
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
205
206 #if defined(PROTOCOL_HTTP) || defined(PROTOCOL_FTP)
207
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
208 /* Return ElvTrue if the url uses a protocol other than "mailto:" or
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
209 * "file:".
210 */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
211 ELVBOOL urlremote(url)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
212 char *url;
213 {
214 /* Parse the url. If parsing fails, then it isn't remote. Also,
215 * check for a few specific protocols which aren't supported.
216 */
217 if (!parseurl(url)
218 || !strcmp(url_protocol, "mailto")
219 || !strcmp(url_protocol, "file"))
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
220 return ElvFalse;
221 return ElvTrue;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
222 }
223
224 static long totalbytes;
225 static long expectbytes;
226 static long oldpollfreq;
227 #ifdef PROTOCOL_FTP
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
228 static ELVBOOL useftp;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
229 #endif
230
231 /* Scan through the elvis.net file for this URL's domain. Return the proxy
232 * site's name if found, or NULL if the URL should be accessed directly.
233 * The proxy name will be in a dynamically-allocated buffer, which must be
234 * freed by the calling function.
235 *
236 * This assumes that parseurl() was recently called on the URL, so the site
237 * name can be found in url_site_port[].
238 */
239 static char *findproxy(never_direct)
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
240 ELVBOOL never_direct; /* protocol isn't supported directly by elvis */
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
241 {
242 CHAR *word, *proxy; /* words from file */
243 int sitelen, len; /* lengths of site name and current word */
244 FILE *fp; /* stream used for reading from file */
245 int ch; /* character from file */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
246 ELVBOOL expect_proxy; /* is next word expected to be proxy name? */
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
247 char *tmp;
248
249 /* compute the length of the site name, excluding the port number */
250 tmp = strchr(url_site_port, ':');
251 if (tmp)
252 sitelen = (int)(tmp - url_site_port);
253 else
254 sitelen = strlen(url_site_port);
255
256 /* find the "elvis.net" file (actually the buffer containing it) */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
257 tmp = iopath(tochar8(o_elvispath), NET_FILE, ElvFalse);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
258 if (!tmp)
259 return NULL;
260
261 /* scan for the domain in the "elvis.net" file */
262 fp = fopen(tmp, "r");
263 proxy = word = NULL;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
264 expect_proxy = ElvFalse;
265 if (fp != NULL)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
266 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
267 while ((ch = getc(fp)) != EOF)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
268 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
269 /* If '#' is encountered, then skip ahead to the next
270 * newline. Later code will then see the newline and
271 * hence treat the entire comment like whitespace.
272 */
273 if (ch == '#')
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
274 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
275 do
276 {
277 if ((ch = getc(fp)) == EOF)
278 goto End;
279 } while (ch != '\n');
280 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
281
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
282 /* non-whitespace just adds the character to the current word */
283 if (!elvspace(ch))
284 {
285 buildCHAR(&word, ch);
286 continue;
287 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
288
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
289 /* if we have no word (multiple spaces) then continue */
290 if (!word)
291 continue;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
292
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
293 /* if this word is supposed to be a proxy name, then use it */
294 if (expect_proxy)
295 {
296 expect_proxy = ElvFalse;
297 assert(!proxy);
298 proxy = word;
299 word = NULL;
300 continue;
301 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
302
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
303 /* Handle the "direct" keyword */
304 if (!strcmp(tochar8(word), "direct"))
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
305 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
306 /* forget the current proxy */
307 if (proxy && !never_direct)
308 {
309 safefree(proxy);
310 proxy = NULL;
311 }
312 goto NextWord;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
313 }
314
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
315 /* handle the "proxy" keyword */
316 if (!strcmp(tochar8(word), "proxy"))
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
317 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
318 if (proxy)
319 {
320 safefree(proxy);
321 proxy = NULL;
322 }
323 expect_proxy = ElvTrue;
324 goto NextWord;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
325 }
326
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
327 /* Then it must be a domain name. Is the the URL's? */
328 len = CHARlen(word);
329 if ((len < sitelen && *word == '.' && !strncmp(&url_site_port[len - sitelen], tochar8(word), len))
330 || (len == sitelen && !strncmp(url_site_port, tochar8(word), len)))
331 {
332 /* Found it! Stop looking! */
333 break;
334 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
335
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
336 /* otherwise we can forget the current word */
337 NextWord:
338 safefree(word);
339 word = NULL;
340 }
341 fclose(fp);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
342 }
343
344 /* if there was a last word, free it */
345 End:
346 if (word)
347 safefree(word);
348
349 /* return the proxy (which may be NULL) */
350 return tochar8(proxy);
351 }
352
353
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
354 /* Open a remote URL for reading or writing. Returns ElvTrue if successful. If
355 * error, it gives an error message and returns ElvFalse.
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
356 */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
357 ELVBOOL urlopen(url, force, rwa)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
358 char *url;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
359 ELVBOOL force;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
360 _char_ rwa;
361 {
362 char *proxy;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
363 ELVBOOL unsupported;
364 ELVBOOL reading;
365 ELVBOOL retval;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
366
367 /* reset the expectbytes/totalbytes values to an impossible value */
368 expectbytes = -1L;
369 totalbytes = 0;
370
371 /* Verify that this is a remote URL, other than mailto:. This also
372 * has the side-effect of parsing the URL.
373 */
374 if (!urlremote(url))
375 {
376 msg(MSG_ERROR, "[s]$1 not a remote url", url);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
377 return ElvFalse;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
378 }
379
380 /* set "unsupported" if this isn't a built-in protocol */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
381 unsupported = (ELVBOOL)!(
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
382 #ifdef PROTOCOL_FTP
383 !strcmp(url_protocol, "ftp") ||
384 #endif
385 !strcmp(url_protocol, "http"));
386
387 /* If a proxy is specified in "elvis.net", then use it. Otherwise
388 * we'll access the site/port directly.
389 */
390 proxy = findproxy(unsupported);
391 if (proxy)
392 {
393 /* Use the proxy. Assume it uses the HTTP protocol */
394 strcpy(url_protocol, "http");
395 strcpy(url_site_port, proxy);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
396 strcpy(url_resource, url);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
397
398 /* Free the proxy name, but don't zero the proxy pointer.
399 * Later, we can still compare proxt against NULL, to detect
400 * whether we're using a proxy.
401 */
402 safefree(proxy);
403 }
404 else
405 {
406 /* We'll access it directly... unless we don't know how! */
407 if (unsupported)
408 {
409 msg(MSG_ERROR, "[s]unsupported protocol $1", url_protocol);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
410 return ElvFalse;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
411 }
412 }
413
414 /* Will we be reading or writing? */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
415 reading = (ELVBOOL)(rwa == 'r');
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
416
417 /* arrange for frequent polling during the network operation */
418 oldpollfreq = o_pollfrequency;
419 o_pollfrequency = 1L;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
420 (void)guipoll(ElvTrue);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
421
422 /* At this point, we know we have a supported protocol. Which one? */
423 #ifdef PROTOCOL_FTP
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
424 useftp = (ELVBOOL)!strcmp(url_protocol, "ftp");
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
425 if (useftp)
426 retval = ftpopen(url_site_port, url_resource, force, rwa);
427 else
428 #endif
429 {
430 if (!reading)
431 {
432 msg(MSG_ERROR, "[s]can only READ from http $1", proxy ? "proxy" : "server");
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
433 retval = ElvFalse;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
434 }
435 else
436 retval = httpopen(url_site_port, url_resource);
437 }
438
439 /* restore pollfrequency */
440 o_pollfrequency = oldpollfreq;
441 return retval;
442 }
443
444 /* During a "write" operation, this value will be displayed to the
445 * user as the total number of bytes to be transferred. You should
446 * call urlbytes() after calling urlopen() with 'w' or 'a' as the
447 * rwa parameter. Alternatively, you may omit calling this function
448 * in which case elvis simply won't display the total number of bytes
449 * to the user. When rwa is 'r', this function does nothing.
450 *
451 * Is is also harmless to call urlbytes() after other flavors of ioopen()
452 * for writing; i.e., you can safely call urlbytes() after any ioopen() which
453 * has an rwa argument of anything except 'r'. The httpopen() and ftpopen()
454 * functions call urlbytes() for 'r' operations.
455 */
456 void urlbytes(totbytes)
457 long totbytes; /* number of bytes we expect to write */
458 {
459 expectbytes = totbytes;
460 }
461
462 /* Read data from an URL. Returns the number of bytes read (0 at EOF);
463 * if error or user-abort, it given an error message and returns -1.
464 */
465 int urlread(buf, bytes)
466 CHAR *buf;
467 int bytes;
468 {
469 #ifdef PROTOCOL_FTP
470 if (useftp)
471 bytes = ftpread(buf, bytes);
472 else
473 #endif
474 bytes = httpread(buf, bytes);
475 if (bytes > 0)
476 {
477 totalbytes += bytes;
478 if (windefault)
479 {
480 if (totalbytes <= expectbytes)
481 msg(MSG_STATUS, "[dd]receiving... $1 of $2 bytes", totalbytes, expectbytes);
482 else
483 msg(MSG_STATUS, "[d]receiving... $1 bytes", totalbytes);
484 }
485 }
486 return bytes;
487 }
488
489 /* Write data to an URL. Returns the number of bytes written;
490 * if error or user-abort, it given an error message and returns -1.
491 */
492 int urlwrite(buf, bytes)
493 CHAR *buf;
494 int bytes;
495 {
496 #ifdef PROTOCOL_FTP
497 if (useftp)
498 bytes = ftpwrite(buf, bytes);
499 /* there is no httpwrite() */
500
501 if (bytes > 0)
502 {
503 totalbytes += bytes;
504 if (windefault)
505 {
506 if (totalbytes <= expectbytes)
507 msg(MSG_STATUS, "[dd]sending... $1 of $2 bytes", totalbytes, expectbytes);
508 else
509 msg(MSG_STATUS, "[d]sending... $1 bytes", totalbytes);
510 }
511 }
512 #endif
513 return bytes;
514 }
515
516 /* Close an URL. */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
517 void urlclose()
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
518 {
519 #ifdef PROTOCOL_FTP
520 if (useftp)
521 ftpclose();
522 else
523 #endif
524 httpclose();
525
526 /* restore the old poll frequency */
527 o_pollfrequency = oldpollfreq;
528 }
529
530 #endif /* PROTOCOL_HTTP || PROTOCOL_FTP */
Something went wrong with that request. Please try again.