Home | History | Annotate | Line # | Download | only in libfetch
      1 /*	$NetBSD: fetch.h,v 1.1.1.7 2010/01/30 21:26:11 joerg Exp $	*/
      2 /*-
      3  * Copyright (c) 1998-2004 Dag-Erling Codan Smrgrav
      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: fetch.h,v 1.26 2004/09/21 18:35:20 des Exp $
     30  */
     31 
     32 #ifndef _FETCH_H_INCLUDED
     33 #define _FETCH_H_INCLUDED
     34 
     35 #include <sys/types.h>
     36 #include <limits.h>
     37 #include <stdio.h>
     38 
     39 #define _LIBFETCH_VER "libfetch/2.0"
     40 
     41 #define URL_HOSTLEN 255
     42 #define URL_SCHEMELEN 16
     43 #define URL_USERLEN 256
     44 #define URL_PWDLEN 256
     45 
     46 typedef struct fetchIO fetchIO;
     47 
     48 struct url {
     49 	char		 scheme[URL_SCHEMELEN + 1];
     50 	char		 user[URL_USERLEN + 1];
     51 	char		 pwd[URL_PWDLEN + 1];
     52 	char		 host[URL_HOSTLEN + 1];
     53 	int		 port;
     54 	char		*doc;
     55 	off_t		 offset;
     56 	size_t		 length;
     57 	time_t		 last_modified;
     58 };
     59 
     60 struct url_stat {
     61 	off_t		 size;
     62 	time_t		 atime;
     63 	time_t		 mtime;
     64 };
     65 
     66 struct url_list {
     67 	size_t		 length;
     68 	size_t		 alloc_size;
     69 	struct url	*urls;
     70 };
     71 
     72 /* Recognized schemes */
     73 #define SCHEME_FTP	"ftp"
     74 #define SCHEME_HTTP	"http"
     75 #define SCHEME_HTTPS	"https"
     76 #define SCHEME_FILE	"file"
     77 
     78 /* Error codes */
     79 #define	FETCH_ABORT	 1
     80 #define	FETCH_AUTH	 2
     81 #define	FETCH_DOWN	 3
     82 #define	FETCH_EXISTS	 4
     83 #define	FETCH_FULL	 5
     84 #define	FETCH_INFO	 6
     85 #define	FETCH_MEMORY	 7
     86 #define	FETCH_MOVED	 8
     87 #define	FETCH_NETWORK	 9
     88 #define	FETCH_OK	10
     89 #define	FETCH_PROTO	11
     90 #define	FETCH_RESOLV	12
     91 #define	FETCH_SERVER	13
     92 #define	FETCH_TEMP	14
     93 #define	FETCH_TIMEOUT	15
     94 #define	FETCH_UNAVAIL	16
     95 #define	FETCH_UNKNOWN	17
     96 #define	FETCH_URL	18
     97 #define	FETCH_VERBOSE	19
     98 #define	FETCH_UNCHANGED	20
     99 
    100 #if defined(__cplusplus)
    101 extern "C" {
    102 #endif
    103 
    104 void		fetchIO_close(fetchIO *);
    105 ssize_t		fetchIO_read(fetchIO *, void *, size_t);
    106 ssize_t		fetchIO_write(fetchIO *, const void *, size_t);
    107 
    108 /* fetchIO-specific functions */
    109 fetchIO		*fetchXGetFile(struct url *, struct url_stat *, const char *);
    110 fetchIO		*fetchGetFile(struct url *, const char *);
    111 fetchIO		*fetchPutFile(struct url *, const char *);
    112 int		 fetchStatFile(struct url *, struct url_stat *, const char *);
    113 int		 fetchListFile(struct url_list *, struct url *, const char *,
    114 		    const char *);
    115 
    116 /* HTTP-specific functions */
    117 fetchIO		*fetchXGetHTTP(struct url *, struct url_stat *, const char *);
    118 fetchIO		*fetchGetHTTP(struct url *, const char *);
    119 fetchIO		*fetchPutHTTP(struct url *, const char *);
    120 int		 fetchStatHTTP(struct url *, struct url_stat *, const char *);
    121 int		 fetchListHTTP(struct url_list *, struct url *, const char *,
    122 		    const char *);
    123 
    124 /* FTP-specific functions */
    125 fetchIO		*fetchXGetFTP(struct url *, struct url_stat *, const char *);
    126 fetchIO		*fetchGetFTP(struct url *, const char *);
    127 fetchIO		*fetchPutFTP(struct url *, const char *);
    128 int		 fetchStatFTP(struct url *, struct url_stat *, const char *);
    129 int		 fetchListFTP(struct url_list *, struct url *, const char *,
    130 		    const char *);
    131 
    132 /* Generic functions */
    133 fetchIO		*fetchXGetURL(const char *, struct url_stat *, const char *);
    134 fetchIO		*fetchGetURL(const char *, const char *);
    135 fetchIO		*fetchPutURL(const char *, const char *);
    136 int		 fetchStatURL(const char *, struct url_stat *, const char *);
    137 int		 fetchListURL(struct url_list *, const char *, const char *,
    138 		    const char *);
    139 fetchIO		*fetchXGet(struct url *, struct url_stat *, const char *);
    140 fetchIO		*fetchGet(struct url *, const char *);
    141 fetchIO		*fetchPut(struct url *, const char *);
    142 int		 fetchStat(struct url *, struct url_stat *, const char *);
    143 int		 fetchList(struct url_list *, struct url *, const char *,
    144 		    const char *);
    145 
    146 /* URL parsing */
    147 struct url	*fetchMakeURL(const char *, const char *, int,
    148 		     const char *, const char *, const char *);
    149 struct url	*fetchParseURL(const char *);
    150 struct url	*fetchCopyURL(const struct url *);
    151 char		*fetchStringifyURL(const struct url *);
    152 void		 fetchFreeURL(struct url *);
    153 
    154 /* URL listening */
    155 void		 fetchInitURLList(struct url_list *);
    156 int		 fetchAppendURLList(struct url_list *, const struct url_list *);
    157 void		 fetchFreeURLList(struct url_list *);
    158 char		*fetchUnquotePath(struct url *);
    159 char		*fetchUnquoteFilename(struct url *);
    160 
    161 /* Connection caching */
    162 void		 fetchConnectionCacheInit(int, int);
    163 void		 fetchConnectionCacheClose(void);
    164 
    165 /* Authentication */
    166 typedef int (*auth_t)(struct url *);
    167 extern auth_t		 fetchAuthMethod;
    168 
    169 /* Last error code */
    170 extern int		 fetchLastErrCode;
    171 #define MAXERRSTRING 256
    172 extern char		 fetchLastErrString[MAXERRSTRING];
    173 
    174 /* I/O timeout */
    175 extern int		 fetchTimeout;
    176 
    177 /* Restart interrupted syscalls */
    178 extern volatile int	 fetchRestartCalls;
    179 
    180 /* Extra verbosity */
    181 extern int		 fetchDebug;
    182 
    183 #if defined(__cplusplus)
    184 }
    185 #endif
    186 
    187 #endif
    188