1 /* $NetBSD: common.h,v 1.16 2010/03/21 16:48:43 joerg Exp $ */
3 * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer
11 * in this position and unchanged.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * $FreeBSD: common.h,v 1.30 2007/12/18 11:03:07 des Exp $
32 #ifndef _COMMON_H_INCLUDED
33 #define _COMMON_H_INCLUDED
37 #define FTP_DEFAULT_PORT 21
38 #define HTTP_DEFAULT_PORT 80
39 #define FTP_DEFAULT_PROXY_PORT 21
40 #define HTTP_DEFAULT_PROXY_PORT 3128
43 #include <openssl/crypto.h>
44 #include <openssl/x509.h>
45 #include <openssl/pem.h>
46 #include <openssl/ssl.h>
47 #include <openssl/err.h>
50 #if !defined(__sun) && !defined(__hpux) && !defined(__INTERIX) && \
51 !defined(__digital__) && !defined(__linux) && !defined(__MINT__) && \
52 !defined(__sgi) && !defined(__minix)
57 typedef struct fetchconn conn_t
;
60 int sd
; /* socket descriptor */
61 char *buf
; /* buffer */
62 size_t bufsize
; /* buffer size */
63 size_t buflen
; /* length of buffer contents */
64 char *next_buf
; /* pending buffer, e.g. after getln */
65 size_t next_len
; /* size of pending buffer */
66 int err
; /* last protocol reply code */
68 SSL
*ssl
; /* SSL handle */
69 SSL_CTX
*ssl_ctx
; /* SSL context */
70 X509
*ssl_cert
; /* server certificate */
71 # if OPENSSL_VERSION_NUMBER < 0x00909000L
72 SSL_METHOD
*ssl_meth
; /* SSL method */
74 const SSL_METHOD
*ssl_meth
; /* SSL method */
80 struct url
*cache_url
;
82 int (*cache_close
)(conn_t
*);
86 /* Structure used for error message lists */
93 void fetch_seterr(struct fetcherr
*, int);
94 void fetch_syserr(void);
95 void fetch_info(const char *, ...);
96 int fetch_default_port(const char *);
97 int fetch_default_proxy_port(const char *);
98 int fetch_bind(int, int, const char *);
99 conn_t
*fetch_cache_get(const struct url
*, int);
100 void fetch_cache_put(conn_t
*, int (*)(conn_t
*));
101 conn_t
*fetch_connect(struct url
*, int, int);
102 conn_t
*fetch_reopen(int);
103 int fetch_ssl(conn_t
*, int);
104 ssize_t
fetch_read(conn_t
*, char *, size_t);
105 int fetch_getln(conn_t
*);
106 ssize_t
fetch_write(conn_t
*, const void *, size_t);
107 int fetch_close(conn_t
*);
108 int fetch_add_entry(struct url_list
*, struct url
*, const char *, int);
109 int fetch_netrc_auth(struct url
*url
);
110 int fetch_no_proxy_match(const char *);
111 int fetch_urlpath_safe(char);
113 #define ftp_seterr(n) fetch_seterr(ftp_errlist, n)
114 #define http_seterr(n) fetch_seterr(http_errlist, n)
115 #define netdb_seterr(n) fetch_seterr(netdb_errlist, n)
116 #define url_seterr(n) fetch_seterr(url_errlist, n)
118 fetchIO
*fetchIO_unopen(void *, ssize_t (*)(void *, void *, size_t),
119 ssize_t (*)(void *, const void *, size_t), void (*)(void *));
122 * I don't really like exporting http_request() and ftp_request(),
123 * but the HTTP and FTP code occasionally needs to cross-call
124 * eachother, and this saves me from adding a lot of special-case code
125 * to handle those cases.
127 * Note that _*_request() free purl, which is way ugly but saves us a
128 * whole lot of trouble.
130 fetchIO
*http_request(struct url
*, const char *,
131 struct url_stat
*, struct url
*, const char *);
132 fetchIO
*ftp_request(struct url
*, const char *, const char *,
133 struct url_stat
*, struct url
*, const char *);
137 * Check whether a particular flag is set
139 #define CHECK_FLAG(x) (flags && strchr(flags, (x)))