1998-07-09 16:52:44 +00:00
|
|
|
|
/*-
|
2004-09-21 18:35:21 +00:00
|
|
|
|
* Copyright (c) 1998-2004 Dag-Erling Co<EFBFBD>dan Sm<EFBFBD>rgrav
|
1998-07-09 16:52:44 +00:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
|
* in this position and unchanged.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-09-30 21:36:09 +00:00
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
1998-07-09 16:52:44 +00:00
|
|
|
|
#include <sys/param.h>
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
#include <sys/errno.h>
|
1998-07-09 16:52:44 +00:00
|
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "fetch.h"
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
#include "common.h"
|
1998-07-09 16:52:44 +00:00
|
|
|
|
|
2001-05-26 19:37:15 +00:00
|
|
|
|
auth_t fetchAuthMethod;
|
2000-05-25 16:24:31 +00:00
|
|
|
|
int fetchLastErrCode;
|
|
|
|
|
char fetchLastErrString[MAXERRSTRING];
|
|
|
|
|
int fetchTimeout;
|
2000-07-17 20:49:39 +00:00
|
|
|
|
int fetchRestartCalls = 1;
|
2001-12-09 15:05:19 +00:00
|
|
|
|
int fetchDebug;
|
1998-12-16 10:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
/*** Local data **************************************************************/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Error messages for parser errors
|
|
|
|
|
*/
|
|
|
|
|
#define URL_MALFORMED 1
|
|
|
|
|
#define URL_BAD_SCHEME 2
|
|
|
|
|
#define URL_BAD_PORT 3
|
2007-12-14 10:26:58 +00:00
|
|
|
|
static struct fetcherr url_errlist[] = {
|
2002-02-05 22:13:51 +00:00
|
|
|
|
{ URL_MALFORMED, FETCH_URL, "Malformed URL" },
|
|
|
|
|
{ URL_BAD_SCHEME, FETCH_URL, "Invalid URL scheme" },
|
|
|
|
|
{ URL_BAD_PORT, FETCH_URL, "Invalid server port" },
|
|
|
|
|
{ -1, FETCH_UNKNOWN, "Unknown parser error" }
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** Public API **************************************************************/
|
1998-07-09 16:52:44 +00:00
|
|
|
|
|
1998-11-05 19:48:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* Select the appropriate protocol for the URL scheme, and return a
|
|
|
|
|
* read-only stream connected to the document referenced by the URL.
|
2000-07-17 21:25:00 +00:00
|
|
|
|
* Also fill out the struct url_stat.
|
1998-11-05 19:48:17 +00:00
|
|
|
|
*/
|
1998-08-17 09:30:19 +00:00
|
|
|
|
FILE *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
|
1998-08-17 09:30:19 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
|
2003-01-22 17:53:15 +00:00
|
|
|
|
if (us != NULL) {
|
|
|
|
|
us->size = -1;
|
|
|
|
|
us->atime = us->mtime = 0;
|
|
|
|
|
}
|
2002-02-05 22:13:51 +00:00
|
|
|
|
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
|
|
|
|
return (fetchXGetFile(URL, us, flags));
|
2002-06-05 12:46:36 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
|
|
|
|
|
return (fetchXGetFTP(URL, us, flags));
|
2002-02-05 22:13:51 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
|
|
|
|
return (fetchXGetHTTP(URL, us, flags));
|
2002-06-05 12:46:36 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
|
|
|
|
|
return (fetchXGetHTTP(URL, us, flags));
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_BAD_SCHEME);
|
2002-06-05 12:46:36 +00:00
|
|
|
|
return (NULL);
|
1998-08-17 09:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-17 21:25:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Select the appropriate protocol for the URL scheme, and return a
|
|
|
|
|
* read-only stream connected to the document referenced by the URL.
|
|
|
|
|
*/
|
|
|
|
|
FILE *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchGet(struct url *URL, const char *flags)
|
2000-07-17 21:25:00 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (fetchXGet(URL, NULL, flags));
|
2000-07-17 21:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-05 19:48:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* Select the appropriate protocol for the URL scheme, and return a
|
|
|
|
|
* write-only stream connected to the document referenced by the URL.
|
|
|
|
|
*/
|
1998-08-17 09:30:19 +00:00
|
|
|
|
FILE *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchPut(struct url *URL, const char *flags)
|
1998-08-17 09:30:19 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
|
|
|
|
|
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
|
|
|
|
return (fetchPutFile(URL, flags));
|
2002-06-05 12:46:36 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
|
|
|
|
|
return (fetchPutFTP(URL, flags));
|
2002-02-05 22:13:51 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
|
|
|
|
return (fetchPutHTTP(URL, flags));
|
2002-06-05 12:46:36 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
|
|
|
|
|
return (fetchPutHTTP(URL, flags));
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_BAD_SCHEME);
|
2002-06-05 12:46:36 +00:00
|
|
|
|
return (NULL);
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Select the appropriate protocol for the URL scheme, and return the
|
|
|
|
|
* size of the document referenced by the URL if it exists.
|
|
|
|
|
*/
|
|
|
|
|
int
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchStat(struct url *URL, struct url_stat *us, const char *flags)
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
|
2003-01-22 17:53:15 +00:00
|
|
|
|
if (us != NULL) {
|
|
|
|
|
us->size = -1;
|
|
|
|
|
us->atime = us->mtime = 0;
|
|
|
|
|
}
|
2002-02-05 22:13:51 +00:00
|
|
|
|
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
|
|
|
|
return (fetchStatFile(URL, us, flags));
|
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
|
|
|
|
|
return (fetchStatFTP(URL, us, flags));
|
2002-06-05 12:46:36 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
|
|
|
|
return (fetchStatHTTP(URL, us, flags));
|
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
|
|
|
|
|
return (fetchStatHTTP(URL, us, flags));
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_BAD_SCHEME);
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (-1);
|
1998-08-17 09:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-12-21 19:41:50 +00:00
|
|
|
|
/*
|
|
|
|
|
* Select the appropriate protocol for the URL scheme, and return a
|
|
|
|
|
* list of files in the directory pointed to by the URL.
|
|
|
|
|
*/
|
|
|
|
|
struct url_ent *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchList(struct url *URL, const char *flags)
|
1998-12-21 19:41:50 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
|
|
|
|
|
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
|
|
|
|
return (fetchListFile(URL, flags));
|
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
|
|
|
|
|
return (fetchListFTP(URL, flags));
|
2002-06-05 12:46:36 +00:00
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
|
|
|
|
return (fetchListHTTP(URL, flags));
|
|
|
|
|
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
|
|
|
|
|
return (fetchListHTTP(URL, flags));
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_BAD_SCHEME);
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (NULL);
|
1998-12-21 19:41:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-05 19:48:17 +00:00
|
|
|
|
/*
|
2000-07-17 21:25:00 +00:00
|
|
|
|
* Attempt to parse the given URL; if successful, call fetchXGet().
|
1998-11-05 19:48:17 +00:00
|
|
|
|
*/
|
1998-07-09 16:52:44 +00:00
|
|
|
|
FILE *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchXGetURL(const char *URL, struct url_stat *us, const char *flags)
|
1998-07-09 16:52:44 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
struct url *u;
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
|
|
if ((u = fetchParseURL(URL)) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
f = fetchXGet(u, us, flags);
|
|
|
|
|
|
|
|
|
|
fetchFreeURL(u);
|
|
|
|
|
return (f);
|
1998-07-09 16:52:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-17 21:25:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Attempt to parse the given URL; if successful, call fetchGet().
|
|
|
|
|
*/
|
|
|
|
|
FILE *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchGetURL(const char *URL, const char *flags)
|
2000-07-17 21:25:00 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (fetchXGetURL(URL, NULL, flags));
|
2000-07-17 21:25:00 +00:00
|
|
|
|
}
|
1998-07-09 16:52:44 +00:00
|
|
|
|
|
1998-11-05 19:48:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* Attempt to parse the given URL; if successful, call fetchPut().
|
|
|
|
|
*/
|
1998-07-09 16:52:44 +00:00
|
|
|
|
FILE *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchPutURL(const char *URL, const char *flags)
|
1998-07-09 16:52:44 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
struct url *u;
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
|
|
if ((u = fetchParseURL(URL)) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
f = fetchPut(u, flags);
|
|
|
|
|
|
|
|
|
|
fetchFreeURL(u);
|
|
|
|
|
return (f);
|
1998-07-09 16:52:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
/*
|
|
|
|
|
* Attempt to parse the given URL; if successful, call fetchStat().
|
|
|
|
|
*/
|
|
|
|
|
int
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchStatURL(const char *URL, struct url_stat *us, const char *flags)
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
struct url *u;
|
|
|
|
|
int s;
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
if ((u = fetchParseURL(URL)) == NULL)
|
|
|
|
|
return (-1);
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
s = fetchStat(u, us, flags);
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
fetchFreeURL(u);
|
|
|
|
|
return (s);
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-12-21 19:41:50 +00:00
|
|
|
|
/*
|
|
|
|
|
* Attempt to parse the given URL; if successful, call fetchList().
|
|
|
|
|
*/
|
|
|
|
|
struct url_ent *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchListURL(const char *URL, const char *flags)
|
1998-12-21 19:41:50 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
struct url *u;
|
|
|
|
|
struct url_ent *ue;
|
1998-12-21 19:41:50 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
if ((u = fetchParseURL(URL)) == NULL)
|
|
|
|
|
return (NULL);
|
1998-12-21 19:41:50 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
ue = fetchList(u, flags);
|
1998-12-21 19:41:50 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
fetchFreeURL(u);
|
|
|
|
|
return (ue);
|
1998-12-21 19:41:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-25 16:46:09 +00:00
|
|
|
|
/*
|
|
|
|
|
* Make a URL
|
|
|
|
|
*/
|
|
|
|
|
struct url *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchMakeURL(const char *scheme, const char *host, int port, const char *doc,
|
|
|
|
|
const char *user, const char *pwd)
|
2000-05-25 16:46:09 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
struct url *u;
|
|
|
|
|
|
|
|
|
|
if (!scheme || (!host && !doc)) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_MALFORMED);
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (port < 0 || port > 65535) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_BAD_PORT);
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* allocate struct url */
|
2003-01-28 08:04:40 +00:00
|
|
|
|
if ((u = calloc(1, sizeof(*u))) == NULL) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
fetch_syserr();
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((u->doc = strdup(doc ? doc : "/")) == NULL) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
fetch_syserr();
|
2002-02-05 22:13:51 +00:00
|
|
|
|
free(u);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-28 08:04:40 +00:00
|
|
|
|
#define seturl(x) snprintf(u->x, sizeof(u->x), "%s", x)
|
2002-02-05 22:13:51 +00:00
|
|
|
|
seturl(scheme);
|
|
|
|
|
seturl(host);
|
|
|
|
|
seturl(user);
|
|
|
|
|
seturl(pwd);
|
2000-05-25 16:46:09 +00:00
|
|
|
|
#undef seturl
|
2002-02-05 22:13:51 +00:00
|
|
|
|
u->port = port;
|
2000-05-25 16:46:09 +00:00
|
|
|
|
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (u);
|
2000-05-25 16:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-07-09 16:52:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* Split an URL into components. URL syntax is:
|
2000-10-12 22:07:49 +00:00
|
|
|
|
* [method:/][/[user[:pwd]@]host[:port]/][document]
|
1998-07-09 16:52:44 +00:00
|
|
|
|
* This almost, but not quite, RFC1738 URL syntax.
|
|
|
|
|
*/
|
Second of a series of cleanups to libfetch.
This commit introduces the following features:
a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.
b) the use of the com_err(3) facilities to report errors.
It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.
Changed files, in alphabetical order:
Makefile:
Don't generate macros in {ftp,http}err.c.
Generate category fields for the error message lists.
Compile the error table.
Install fetch_err.h along with fetch.h.
common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.
Add categories to the _netdb_errlist table.
Report errors through the Common Error library.
common.h:
Add the DEBUG macros.
Add prototype for fetchConnect().
Remove the prototype for _fetch_errstring(), which is local to common.c
Add a categroy field to struct fetcherr, and define constants for
error categories.
Define macros for _{url,netdb,ftp,http}_seterr().
errors.et: (new file)
List error categories.
fetch.3:
Document the fetchStat*() functions.
Move the "unimplemented functionality" comments from NOTES to BUGS.
Document that applications which use libfetch must also use
libcom_err, and list existing error codes.
Undocument fetchLastErr{Code,String}.
Remove the (empty) DIAGNOSTICS section.
Mention Eugene Skepner in the AUTHORS section.
fetch.c:
Move the DEBUG macros to common.c
Add fetchStat() and fetchStatURL().
Generate error messages for URL parser errors, and fix a minor bug
in the parser.
Use 'struct url' instead of 'url_t'.
Remove fetchLastErr{Code,String}.
fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.
Define struct url_stat (used by fetchStat()).
Add prototypes for fetchStat*().
Remove the declarations for fetchLastErr{Code,String}.
Include fetch_err.h.
fetch_err.et: (new file)
Error table for libfetch.
file.c:
Add fetchStatFile().
Use 'struct url' instead of 'url_t'.
ftp.c:
Add fetchStatFTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErrCode.
ftp.errors:
Add categories to all error messages.
http.c:
Add fetchStatHTTP().
Use 'struct url' instead of 'url_t'.
Don't use fetchLastErr{Code,Text}.
http.errors:
Add categories to all error messages.
Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner
1998-11-06 22:14:08 +00:00
|
|
|
|
struct url *
|
2001-04-24 00:06:21 +00:00
|
|
|
|
fetchParseURL(const char *URL)
|
1998-07-09 16:52:44 +00:00
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
char *doc;
|
|
|
|
|
const char *p, *q;
|
|
|
|
|
struct url *u;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* allocate struct url */
|
2003-01-28 08:04:40 +00:00
|
|
|
|
if ((u = calloc(1, sizeof(*u))) == NULL) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
fetch_syserr();
|
2002-02-05 22:13:51 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* scheme name */
|
|
|
|
|
if ((p = strstr(URL, ":/"))) {
|
|
|
|
|
snprintf(u->scheme, URL_SCHEMELEN+1,
|
|
|
|
|
"%.*s", (int)(p - URL), URL);
|
|
|
|
|
URL = ++p;
|
|
|
|
|
/*
|
|
|
|
|
* Only one slash: no host, leave slash as part of document
|
|
|
|
|
* Two slashes: host follows, strip slashes
|
|
|
|
|
*/
|
|
|
|
|
if (URL[1] == '/')
|
|
|
|
|
URL = (p += 2);
|
|
|
|
|
} else {
|
|
|
|
|
p = URL;
|
|
|
|
|
}
|
|
|
|
|
if (!*URL || *URL == '/' || *URL == '.' ||
|
|
|
|
|
(u->scheme[0] == '\0' &&
|
|
|
|
|
strchr(URL, '/') == NULL && strchr(URL, ':') == NULL))
|
|
|
|
|
goto nohost;
|
|
|
|
|
|
|
|
|
|
p = strpbrk(URL, "/@");
|
|
|
|
|
if (p && *p == '@') {
|
|
|
|
|
/* username */
|
|
|
|
|
for (q = URL, i = 0; (*q != ':') && (*q != '@'); q++)
|
|
|
|
|
if (i < URL_USERLEN)
|
|
|
|
|
u->user[i++] = *q;
|
|
|
|
|
|
|
|
|
|
/* password */
|
|
|
|
|
if (*q == ':')
|
|
|
|
|
for (q++, i = 0; (*q != ':') && (*q != '@'); q++)
|
|
|
|
|
if (i < URL_PWDLEN)
|
|
|
|
|
u->pwd[i++] = *q;
|
|
|
|
|
|
|
|
|
|
p++;
|
|
|
|
|
} else {
|
|
|
|
|
p = URL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* hostname */
|
2000-05-20 18:23:51 +00:00
|
|
|
|
#ifdef INET6
|
2002-02-05 22:13:51 +00:00
|
|
|
|
if (*p == '[' && (q = strchr(p + 1, ']')) != NULL &&
|
|
|
|
|
(*++q == '\0' || *q == '/' || *q == ':')) {
|
|
|
|
|
if ((i = q - p - 2) > MAXHOSTNAMELEN)
|
|
|
|
|
i = MAXHOSTNAMELEN;
|
|
|
|
|
strncpy(u->host, ++p, i);
|
|
|
|
|
p = q;
|
|
|
|
|
} else
|
2000-05-20 18:23:51 +00:00
|
|
|
|
#endif
|
2002-02-05 22:13:51 +00:00
|
|
|
|
for (i = 0; *p && (*p != '/') && (*p != ':'); p++)
|
|
|
|
|
if (i < MAXHOSTNAMELEN)
|
|
|
|
|
u->host[i++] = *p;
|
|
|
|
|
|
|
|
|
|
/* port */
|
|
|
|
|
if (*p == ':') {
|
|
|
|
|
for (q = ++p; *q && (*q != '/'); q++)
|
2007-12-19 00:26:36 +00:00
|
|
|
|
if (isdigit((unsigned char)*q))
|
2002-02-05 22:13:51 +00:00
|
|
|
|
u->port = u->port * 10 + (*q - '0');
|
|
|
|
|
else {
|
|
|
|
|
/* invalid port */
|
2007-12-14 10:26:58 +00:00
|
|
|
|
url_seterr(URL_BAD_PORT);
|
2002-02-05 22:13:51 +00:00
|
|
|
|
goto ouch;
|
|
|
|
|
}
|
|
|
|
|
p = q;
|
|
|
|
|
}
|
1998-07-09 16:52:44 +00:00
|
|
|
|
|
|
|
|
|
nohost:
|
2002-02-05 22:13:51 +00:00
|
|
|
|
/* document */
|
|
|
|
|
if (!*p)
|
|
|
|
|
p = "/";
|
|
|
|
|
|
|
|
|
|
if (strcasecmp(u->scheme, SCHEME_HTTP) == 0 ||
|
|
|
|
|
strcasecmp(u->scheme, SCHEME_HTTPS) == 0) {
|
|
|
|
|
const char hexnums[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
|
|
/* percent-escape whitespace. */
|
|
|
|
|
if ((doc = malloc(strlen(p) * 3 + 1)) == NULL) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
fetch_syserr();
|
2002-02-05 22:13:51 +00:00
|
|
|
|
goto ouch;
|
|
|
|
|
}
|
|
|
|
|
u->doc = doc;
|
|
|
|
|
while (*p != '\0') {
|
2007-12-19 00:26:36 +00:00
|
|
|
|
if (!isspace((unsigned char)*p)) {
|
2002-02-05 22:13:51 +00:00
|
|
|
|
*doc++ = *p++;
|
|
|
|
|
} else {
|
|
|
|
|
*doc++ = '%';
|
|
|
|
|
*doc++ = hexnums[((unsigned int)*p) >> 4];
|
|
|
|
|
*doc++ = hexnums[((unsigned int)*p) & 0xf];
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*doc = '\0';
|
|
|
|
|
} else if ((u->doc = strdup(p)) == NULL) {
|
2007-12-14 10:26:58 +00:00
|
|
|
|
fetch_syserr();
|
2002-02-05 22:13:51 +00:00
|
|
|
|
goto ouch;
|
2000-10-21 14:58:18 +00:00
|
|
|
|
}
|
2002-02-05 22:13:51 +00:00
|
|
|
|
|
|
|
|
|
DEBUG(fprintf(stderr,
|
2002-01-01 14:48:09 +00:00
|
|
|
|
"scheme: [%s]\n"
|
|
|
|
|
"user: [%s]\n"
|
|
|
|
|
"password: [%s]\n"
|
|
|
|
|
"host: [%s]\n"
|
|
|
|
|
"port: [%d]\n"
|
|
|
|
|
"document: [%s]\n",
|
1998-07-09 16:52:44 +00:00
|
|
|
|
u->scheme, u->user, u->pwd,
|
|
|
|
|
u->host, u->port, u->doc));
|
2002-02-05 22:13:51 +00:00
|
|
|
|
|
|
|
|
|
return (u);
|
1998-07-09 16:52:44 +00:00
|
|
|
|
|
|
|
|
|
ouch:
|
2002-02-05 22:13:51 +00:00
|
|
|
|
free(u);
|
|
|
|
|
return (NULL);
|
1998-07-09 16:52:44 +00:00
|
|
|
|
}
|
2000-05-11 13:31:02 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Free a URL
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
fetchFreeURL(struct url *u)
|
|
|
|
|
{
|
2002-02-05 22:13:51 +00:00
|
|
|
|
free(u->doc);
|
|
|
|
|
free(u);
|
2000-05-11 13:31:02 +00:00
|
|
|
|
}
|