common.h revision 1.1.1.2.2.2
1/* $NetBSD: common.h,v 1.1.1.2.2.2 2008/10/19 22:39:50 haad Exp $ */ 2/*- 3 * Copyright (c) 1998-2004 Dag-Erling Co�dan Sm�rgrav 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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 17 * 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. 28 * 29 * $FreeBSD: common.h,v 1.30 2007/12/18 11:03:07 des Exp $ 30 */ 31 32#ifndef _COMMON_H_INCLUDED 33#define _COMMON_H_INCLUDED 34 35#define FTP_DEFAULT_PORT 21 36#define HTTP_DEFAULT_PORT 80 37#define FTP_DEFAULT_PROXY_PORT 21 38#define HTTP_DEFAULT_PROXY_PORT 3128 39 40#ifdef WITH_SSL 41#include <openssl/crypto.h> 42#include <openssl/x509.h> 43#include <openssl/pem.h> 44#include <openssl/ssl.h> 45#include <openssl/err.h> 46#endif 47 48#if !defined(__sun) && !defined(__hpux) && !defined(__INTERIX) && \ 49 !defined(__digital__) && !defined(__linux) && !defined(__sgi) 50#define HAVE_SA_LEN 51#endif 52 53/* Connection */ 54typedef struct fetchconn conn_t; 55struct fetchconn { 56 int sd; /* socket descriptor */ 57 char *buf; /* buffer */ 58 size_t bufsize; /* buffer size */ 59 size_t buflen; /* length of buffer contents */ 60 char *next_buf; /* pending buffer, e.g. after getln */ 61 size_t next_len; /* size of pending buffer */ 62 int err; /* last protocol reply code */ 63#ifdef WITH_SSL 64 SSL *ssl; /* SSL handle */ 65 SSL_CTX *ssl_ctx; /* SSL context */ 66 X509 *ssl_cert; /* server certificate */ 67# if OPENSSL_VERSION_NUMBER < 0x00909000L 68 SSL_METHOD *ssl_meth; /* SSL method */ 69# else 70 const SSL_METHOD *ssl_meth; /* SSL method */ 71# endif 72#endif 73 int ref; /* reference count */ 74}; 75 76/* Structure used for error message lists */ 77struct fetcherr { 78 const int num; 79 const int cat; 80 const char *string; 81}; 82 83/* for fetch_writev */ 84struct iovec; 85 86void fetch_seterr(struct fetcherr *, int); 87void fetch_syserr(void); 88void fetch_info(const char *, ...); 89int fetch_default_port(const char *); 90int fetch_default_proxy_port(const char *); 91int fetch_bind(int, int, const char *); 92conn_t *fetch_connect(const char *, int, int, int); 93conn_t *fetch_reopen(int); 94conn_t *fetch_ref(conn_t *); 95int fetch_ssl(conn_t *, int); 96ssize_t fetch_read(conn_t *, char *, size_t); 97int fetch_getln(conn_t *); 98ssize_t fetch_write(conn_t *, const char *, size_t); 99ssize_t fetch_writev(conn_t *, struct iovec *, int); 100int fetch_putln(conn_t *, const char *, size_t); 101int fetch_close(conn_t *); 102int fetch_add_entry(struct url_list *, struct url *, const char *, int); 103int fetch_netrc_auth(struct url *url); 104int fetch_no_proxy_match(const char *); 105int fetch_urlpath_safe(char); 106 107#define ftp_seterr(n) fetch_seterr(ftp_errlist, n) 108#define http_seterr(n) fetch_seterr(http_errlist, n) 109#define netdb_seterr(n) fetch_seterr(netdb_errlist, n) 110#define url_seterr(n) fetch_seterr(url_errlist, n) 111 112fetchIO *fetchIO_unopen(void *, ssize_t (*)(void *, void *, size_t), 113 ssize_t (*)(void *, const void *, size_t), void (*)(void *)); 114 115/* 116 * I don't really like exporting http_request() and ftp_request(), 117 * but the HTTP and FTP code occasionally needs to cross-call 118 * eachother, and this saves me from adding a lot of special-case code 119 * to handle those cases. 120 * 121 * Note that _*_request() free purl, which is way ugly but saves us a 122 * whole lot of trouble. 123 */ 124fetchIO *http_request(struct url *, const char *, 125 struct url_stat *, struct url *, const char *); 126fetchIO *ftp_request(struct url *, const char *, const char *, 127 struct url_stat *, struct url *, const char *); 128 129 130/* 131 * Check whether a particular flag is set 132 */ 133#define CHECK_FLAG(x) (flags && strchr(flags, (x))) 134 135#endif 136