version 1.176, 2007/05/10 12:22:04 |
version 1.177, 2007/05/15 23:54:18 |
Line 286 url_decode(char *url) |
|
Line 286 url_decode(char *url) |
|
|
|
|
|
/* |
/* |
* Parse URL of form: |
* Parse URL of form (per RFC3986): |
* <type>://[<user>[:<password>]@]<host>[:<port>][/<path>] |
* <type>://[<user>[:<password>]@]<host>[:<port>][/<path>] |
* Returns -1 if a parse error occurred, otherwise 0. |
* Returns -1 if a parse error occurred, otherwise 0. |
* It's the caller's responsibility to url_decode() the returned |
* It's the caller's responsibility to url_decode() the returned |
Line 296 url_decode(char *url) |
|
Line 296 url_decode(char *url) |
|
* malloc(3)ed strings of the relevant section, and port to |
* malloc(3)ed strings of the relevant section, and port to |
* the number given, or ftpport if ftp://, or httpport if http://. |
* the number given, or ftpport if ftp://, or httpport if http://. |
* |
* |
* If <host> is surrounded by `[' and ']', it's parsed as an |
* XXX: this is not totally RFC3986 compliant; <path> will have the |
* IPv6 address (as per RFC 2732). |
|
* |
|
* XXX: this is not totally RFC 1738 compliant; <path> will have the |
|
* leading `/' unless it's an ftp:// URL, as this makes things easier |
* leading `/' unless it's an ftp:// URL, as this makes things easier |
* for file:// and http:// URLs. ftp:// URLs have the `/' between the |
* for file:// and http:// URLs. ftp:// URLs have the `/' between the |
* host and the URL-path removed, but any additional leading slashes |
* host and the URL-path removed, but any additional leading slashes |
* in the URL-path are retained (because they imply that we should |
* in the URL-path are retained (because they imply that we should |
* later do "CWD" with a null argument). |
* later do "CWD" with a null argument). |
Line 309 url_decode(char *url) |
|
Line 306 url_decode(char *url) |
|
* Examples: |
* Examples: |
* input URL output path |
* input URL output path |
* --------- ----------- |
* --------- ----------- |
* "ftp://host" NULL |
* "http://host" "/" |
* "http://host/" NULL |
* "http://host/" "/" |
|
* "http://host/path" "/path" |
* "file://host/dir/file" "dir/file" |
* "file://host/dir/file" "dir/file" |
|
* "ftp://host" "" |
* "ftp://host/" "" |
* "ftp://host/" "" |
* "ftp://host//" NULL |
* "ftp://host//" "/" |
|
* "ftp://host/dir/file" "dir/file" |
* "ftp://host//dir/file" "/dir/file" |
* "ftp://host//dir/file" "/dir/file" |
*/ |
*/ |
static int |
static int |
Line 398 parse_url(const char *url, const char *d |
|
Line 398 parse_url(const char *url, const char *d |
|
#ifdef INET6 |
#ifdef INET6 |
/* |
/* |
* Check if thost is an encoded IPv6 address, as per |
* Check if thost is an encoded IPv6 address, as per |
* RFC 2732: |
* RFC3986: |
* `[' ipv6-address ']' |
* `[' ipv6-address ']' |
*/ |
*/ |
if (*thost == '[') { |
if (*thost == '[') { |
Line 424 parse_url(const char *url, const char *d |
|
Line 424 parse_url(const char *url, const char *d |
|
cp = NULL; |
cp = NULL; |
} else |
} else |
#endif /* INET6 */ |
#endif /* INET6 */ |
if ((cp = strchr(thost, ':')) != NULL) |
if ((cp = strchr(thost, ':')) != NULL) |
*cp++ = '\0'; |
*cp++ = '\0'; |
*host = thost; |
*host = thost; |
|
|
/* look for [:port] */ |
/* look for [:port] */ |
Line 444 parse_url(const char *url, const char *d |
|
Line 444 parse_url(const char *url, const char *d |
|
|
|
if (tport != NULL) |
if (tport != NULL) |
*port = ftp_strdup(tport); |
*port = ftp_strdup(tport); |
if (*path == NULL) |
if (*path == NULL) { |
*path = ftp_strdup("/"); |
const char *emptypath = "/"; |
|
if (*type == FTP_URL_T) /* skip first / for ftp URLs */ |
|
emptypath++; |
|
*path = ftp_strdup(emptypath); |
|
} |
|
|
DPRINTF("parse_url: user `%s' pass `%s' host %s port %s(%d) " |
DPRINTF("parse_url: user `%s' pass `%s' host %s port %s(%d) " |
"path `%s'\n", |
"path `%s'\n", |
Line 925 fetch_url(const char *url, const char *p |
|
Line 929 fetch_url(const char *url, const char *p |
|
struct tm parsed; |
struct tm parsed; |
char *t; |
char *t; |
|
|
/* RFC 1123 */ |
/* RFC1123 */ |
if ((t = strptime(cp, |
if ((t = strptime(cp, |
"%a, %d %b %Y %H:%M:%S GMT", |
"%a, %d %b %Y %H:%M:%S GMT", |
&parsed)) |
&parsed)) |
/* RFC 850 */ |
/* RFC0850 */ |
|| (t = strptime(cp, |
|| (t = strptime(cp, |
"%a, %d-%b-%y %H:%M:%S GMT", |
"%a, %d-%b-%y %H:%M:%S GMT", |
&parsed)) |
&parsed)) |
Line 1483 fetch_ftp(const char *url) |
|
Line 1487 fetch_ftp(const char *url) |
|
* directories in one step. |
* directories in one step. |
* |
* |
* If we are dealing with an `ftp://host/path' URL |
* If we are dealing with an `ftp://host/path' URL |
* (urltype is FTP_URL_T), then RFC 1738 says we need to |
* (urltype is FTP_URL_T), then RFC3986 says we need to |
* send a separate CWD command for each unescaped "/" |
* send a separate CWD command for each unescaped "/" |
* in the path, and we have to interpret %hex escaping |
* in the path, and we have to interpret %hex escaping |
* *after* we find the slashes. It's possible to get |
* *after* we find the slashes. It's possible to get |
* empty components here, (from multiple adjacent |
* empty components here, (from multiple adjacent |
* slashes in the path) and RFC 1738 says that we should |
* slashes in the path) and RFC3986 says that we should |
* still do `CWD ' (with a null argument) in such cases. |
* still do `CWD ' (with a null argument) in such cases. |
* |
* |
* Many ftp servers don't support `CWD ', so if there's an |
* Many ftp servers don't support `CWD ', so if there's an |
Line 1560 fetch_ftp(const char *url) |
|
Line 1564 fetch_ftp(const char *url) |
|
fprintf(stderr, |
fprintf(stderr, |
"\n" |
"\n" |
"ftp: The `CWD ' command (without a directory), which is required by\n" |
"ftp: The `CWD ' command (without a directory), which is required by\n" |
" RFC 1738 to support the empty directory in the URL pathname (`//'),\n" |
" RFC3986 to support the empty directory in the URL pathname (`//'),\n" |
" conflicts with the server's conformance to RFC 959.\n" |
" conflicts with the server's conformance to RFC0959.\n" |
" Try the same URL without the `//' in the URL pathname.\n" |
" Try the same URL without the `//' in the URL pathname.\n" |
"\n"); |
"\n"); |
goto cleanup_fetch_ftp; |
goto cleanup_fetch_ftp; |