1998-11-05 19:48:17 +00:00
|
|
|
/*-
|
2014-02-27 13:27:04 +00:00
|
|
|
* Copyright (c) 1998-2014 Dag-Erling Smørgrav
|
1998-11-05 19:48:17 +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.
|
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1998-11-05 19:48:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COMMON_H_INCLUDED
|
|
|
|
#define _COMMON_H_INCLUDED
|
|
|
|
|
2000-07-25 11:45:38 +00:00
|
|
|
#define FTP_DEFAULT_PORT 21
|
|
|
|
#define HTTP_DEFAULT_PORT 80
|
2000-11-10 08:43:40 +00:00
|
|
|
#define FTP_DEFAULT_PROXY_PORT 21
|
|
|
|
#define HTTP_DEFAULT_PROXY_PORT 3128
|
2000-07-25 11:45:38 +00:00
|
|
|
|
2002-06-05 21:35:35 +00:00
|
|
|
#ifdef WITH_SSL
|
2002-06-05 10:05:03 +00:00
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
2002-06-05 21:35:35 +00:00
|
|
|
#endif
|
2002-06-05 10:05:03 +00:00
|
|
|
|
|
|
|
/* Connection */
|
|
|
|
typedef struct fetchconn conn_t;
|
|
|
|
struct fetchconn {
|
|
|
|
int sd; /* socket descriptor */
|
|
|
|
char *buf; /* buffer */
|
|
|
|
size_t bufsize; /* buffer size */
|
|
|
|
size_t buflen; /* length of buffer contents */
|
|
|
|
int err; /* last protocol reply code */
|
2002-06-05 21:35:35 +00:00
|
|
|
#ifdef WITH_SSL
|
2002-06-05 12:19:08 +00:00
|
|
|
SSL *ssl; /* SSL handle */
|
|
|
|
SSL_CTX *ssl_ctx; /* SSL context */
|
2002-06-05 10:05:03 +00:00
|
|
|
X509 *ssl_cert; /* server certificate */
|
2012-07-12 19:30:53 +00:00
|
|
|
const SSL_METHOD *ssl_meth; /* SSL method */
|
2002-06-05 21:35:35 +00:00
|
|
|
#endif
|
2002-06-11 11:27:28 +00:00
|
|
|
int ref; /* reference count */
|
2002-06-05 10:05:03 +00:00
|
|
|
};
|
|
|
|
|
1998-11-05 19:48:17 +00:00
|
|
|
/* Structure used for error message lists */
|
2002-06-05 12:46:36 +00:00
|
|
|
struct fetcherr {
|
2002-02-05 22:13:51 +00:00
|
|
|
const int num;
|
|
|
|
const int cat;
|
|
|
|
const char *string;
|
1998-11-05 19:48:17 +00:00
|
|
|
};
|
|
|
|
|
2007-12-14 10:26:58 +00:00
|
|
|
/* for fetch_writev */
|
2002-10-27 16:11:21 +00:00
|
|
|
struct iovec;
|
|
|
|
|
2007-12-14 10:26:58 +00:00
|
|
|
void fetch_seterr(struct fetcherr *, int);
|
|
|
|
void fetch_syserr(void);
|
|
|
|
void fetch_info(const char *, ...);
|
|
|
|
int fetch_default_port(const char *);
|
|
|
|
int fetch_default_proxy_port(const char *);
|
|
|
|
int fetch_bind(int, int, const char *);
|
|
|
|
conn_t *fetch_connect(const char *, int, int, int);
|
|
|
|
conn_t *fetch_reopen(int);
|
|
|
|
conn_t *fetch_ref(conn_t *);
|
2013-07-26 15:53:43 +00:00
|
|
|
#ifdef WITH_SSL
|
|
|
|
int fetch_ssl_cb_verify_crt(int, X509_STORE_CTX*);
|
|
|
|
#endif
|
|
|
|
int fetch_ssl(conn_t *, const struct url *, int);
|
2007-12-14 10:26:58 +00:00
|
|
|
ssize_t fetch_read(conn_t *, char *, size_t);
|
|
|
|
int fetch_getln(conn_t *);
|
|
|
|
ssize_t fetch_write(conn_t *, const char *, size_t);
|
|
|
|
ssize_t fetch_writev(conn_t *, struct iovec *, int);
|
|
|
|
int fetch_putln(conn_t *, const char *, size_t);
|
|
|
|
int fetch_close(conn_t *);
|
|
|
|
int fetch_add_entry(struct url_ent **, int *, int *,
|
2002-02-05 22:13:51 +00:00
|
|
|
const char *, struct url_stat *);
|
2007-12-14 10:26:58 +00:00
|
|
|
int fetch_netrc_auth(struct url *url);
|
2007-12-18 11:03:07 +00:00
|
|
|
int fetch_no_proxy_match(const char *);
|
1998-12-21 19:41:50 +00:00
|
|
|
|
2007-12-14 10:26:58 +00:00
|
|
|
#define ftp_seterr(n) fetch_seterr(ftp_errlist, n)
|
|
|
|
#define http_seterr(n) fetch_seterr(http_errlist, n)
|
|
|
|
#define netdb_seterr(n) fetch_seterr(netdb_errlist, n)
|
|
|
|
#define url_seterr(n) fetch_seterr(url_errlist, n)
|
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
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2001-12-09 15:05:19 +00:00
|
|
|
#define DEBUG(x) do { if (fetchDebug) { x; } } while (0)
|
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
|
|
|
#else
|
|
|
|
#define DEBUG(x) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2000-10-12 22:10:43 +00:00
|
|
|
/*
|
2007-12-14 10:26:58 +00:00
|
|
|
* I don't really like exporting http_request() and ftp_request(),
|
2001-12-04 01:10:34 +00:00
|
|
|
* but the HTTP and FTP code occasionally needs to cross-call
|
|
|
|
* eachother, and this saves me from adding a lot of special-case code
|
|
|
|
* to handle those cases.
|
2000-10-12 22:10:43 +00:00
|
|
|
*
|
2001-12-04 01:10:34 +00:00
|
|
|
* Note that _*_request() free purl, which is way ugly but saves us a
|
2000-10-12 22:10:43 +00:00
|
|
|
* whole lot of trouble.
|
|
|
|
*/
|
2007-12-14 10:26:58 +00:00
|
|
|
FILE *http_request(struct url *, const char *,
|
2002-02-05 22:13:51 +00:00
|
|
|
struct url_stat *, struct url *, const char *);
|
2014-07-20 00:29:41 +00:00
|
|
|
FILE *http_request_body(struct url *, const char *,
|
|
|
|
struct url_stat *, struct url *, const char *,
|
|
|
|
const char *, const char *);
|
2007-12-14 10:26:58 +00:00
|
|
|
FILE *ftp_request(struct url *, const char *,
|
2002-02-05 22:13:51 +00:00
|
|
|
struct url_stat *, struct url *, const char *);
|
2000-10-12 22:10:43 +00:00
|
|
|
|
2000-10-29 15:45:31 +00:00
|
|
|
/*
|
|
|
|
* Check whether a particular flag is set
|
|
|
|
*/
|
|
|
|
#define CHECK_FLAG(x) (flags && strchr(flags, (x)))
|
|
|
|
|
1998-11-05 19:48:17 +00:00
|
|
|
#endif
|