1 | /* ------------------------------------------------------------------- */
|
---|
2 | /* wfetch : Fetch a remote file using the htget() "HTTP client" */
|
---|
3 | /* */
|
---|
4 | /* syntax : wfatch(char *url, char *filename) */
|
---|
5 | /* */
|
---|
6 | /* The file will be written to "filename" */
|
---|
7 | /* */
|
---|
8 | /* Returns : 0 if fail */
|
---|
9 | /* : 1 if HTML file (text/html) */
|
---|
10 | /* : 2 if MARC file (application/marc) */
|
---|
11 | /* */
|
---|
12 | /* NOTE : Timeout period (HTTP) is set here. */
|
---|
13 | /* */
|
---|
14 | /* Author : Ole Husby, BIBSYS */
|
---|
15 | /* Updated : 1998-08-11 */
|
---|
16 | /* ------------------------------------------------------------------- */
|
---|
17 |
|
---|
18 | #include <stdlib.h>
|
---|
19 | #include <stdio.h>
|
---|
20 | #include <string.h>
|
---|
21 |
|
---|
22 | #define TIMEOUT_SECONDS 10
|
---|
23 |
|
---|
24 | int wfetch(char *url, char *filename)
|
---|
25 | {
|
---|
26 | int i, type, argtype, timeout, rc, retc;
|
---|
27 | char iurl[1024], content_type[128], location[128];
|
---|
28 |
|
---|
29 | retc = 1;
|
---|
30 |
|
---|
31 | strcpy(iurl, url);
|
---|
32 | timeout = TIMEOUT_SECONDS;
|
---|
33 |
|
---|
34 | type = 6; /* Fetch HTML HEAD or MARC */
|
---|
35 |
|
---|
36 | rc = htget(iurl, type, timeout, filename, content_type, location);
|
---|
37 |
|
---|
38 |
|
---|
39 | /* Try again if redirect */
|
---|
40 |
|
---|
41 | if ( ( ( rc == 301 ) || ( rc == 302 ) ) && *location )
|
---|
42 | {
|
---|
43 | strcpy(iurl, location);
|
---|
44 | rc = htget(iurl, type, timeout, filename, content_type, location);
|
---|
45 | }
|
---|
46 |
|
---|
47 | if (rc)
|
---|
48 | retc = 0;
|
---|
49 | else if (strcmp(content_type, "application/marc") == 0)
|
---|
50 | retc = 2;
|
---|
51 |
|
---|
52 | return retc;
|
---|
53 | }
|
---|