xref: /netbsd-src/external/bsd/fetch/dist/libfetch/fetch.h (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: fetch.h,v 1.1.1.2 2008/10/07 15:55:20 joerg 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: 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 };
58 
59 struct url_stat {
60 	off_t		 size;
61 	time_t		 atime;
62 	time_t		 mtime;
63 };
64 
65 struct url_list {
66 	size_t		 length;
67 	size_t		 alloc_size;
68 	struct url	*urls;
69 };
70 
71 /* Recognized schemes */
72 #define SCHEME_FTP	"ftp"
73 #define SCHEME_HTTP	"http"
74 #define SCHEME_HTTPS	"https"
75 #define SCHEME_FILE	"file"
76 
77 /* Error codes */
78 #define	FETCH_ABORT	 1
79 #define	FETCH_AUTH	 2
80 #define	FETCH_DOWN	 3
81 #define	FETCH_EXISTS	 4
82 #define	FETCH_FULL	 5
83 #define	FETCH_INFO	 6
84 #define	FETCH_MEMORY	 7
85 #define	FETCH_MOVED	 8
86 #define	FETCH_NETWORK	 9
87 #define	FETCH_OK	10
88 #define	FETCH_PROTO	11
89 #define	FETCH_RESOLV	12
90 #define	FETCH_SERVER	13
91 #define	FETCH_TEMP	14
92 #define	FETCH_TIMEOUT	15
93 #define	FETCH_UNAVAIL	16
94 #define	FETCH_UNKNOWN	17
95 #define	FETCH_URL	18
96 #define	FETCH_VERBOSE	19
97 
98 #if defined(__cplusplus)
99 extern "C" {
100 #endif
101 
102 void		fetchIO_close(fetchIO *);
103 ssize_t		fetchIO_read(fetchIO *, void *, size_t);
104 ssize_t		fetchIO_write(fetchIO *, const void *, size_t);
105 
106 /* fetchIO-specific functions */
107 fetchIO		*fetchXGetFile(struct url *, struct url_stat *, const char *);
108 fetchIO		*fetchGetFile(struct url *, const char *);
109 fetchIO		*fetchPutFile(struct url *, const char *);
110 int		 fetchStatFile(struct url *, struct url_stat *, const char *);
111 int		 fetchListFile(struct url_list *, struct url *, const char *,
112 		    const char *);
113 
114 /* HTTP-specific functions */
115 fetchIO		*fetchXGetHTTP(struct url *, struct url_stat *, const char *);
116 fetchIO		*fetchGetHTTP(struct url *, const char *);
117 fetchIO		*fetchPutHTTP(struct url *, const char *);
118 int		 fetchStatHTTP(struct url *, struct url_stat *, const char *);
119 int		 fetchListHTTP(struct url_list *, struct url *, const char *,
120 		    const char *);
121 
122 /* FTP-specific functions */
123 fetchIO		*fetchXGetFTP(struct url *, struct url_stat *, const char *);
124 fetchIO		*fetchGetFTP(struct url *, const char *);
125 fetchIO		*fetchPutFTP(struct url *, const char *);
126 int		 fetchStatFTP(struct url *, struct url_stat *, const char *);
127 int		 fetchListFTP(struct url_list *, struct url *, const char *,
128 		    const char *);
129 
130 /* Generic functions */
131 fetchIO		*fetchXGetURL(const char *, struct url_stat *, const char *);
132 fetchIO		*fetchGetURL(const char *, const char *);
133 fetchIO		*fetchPutURL(const char *, const char *);
134 int		 fetchStatURL(const char *, struct url_stat *, const char *);
135 int		 fetchListURL(struct url_list *, const char *, const char *,
136 		    const char *);
137 fetchIO		*fetchXGet(struct url *, struct url_stat *, const char *);
138 fetchIO		*fetchGet(struct url *, const char *);
139 fetchIO		*fetchPut(struct url *, const char *);
140 int		 fetchStat(struct url *, struct url_stat *, const char *);
141 int		 fetchList(struct url_list *, struct url *, const char *,
142 		    const char *);
143 
144 /* URL parsing */
145 struct url	*fetchMakeURL(const char *, const char *, int,
146 		     const char *, const char *, const char *);
147 struct url	*fetchParseURL(const char *);
148 struct url	*fetchCopyURL(const struct url *);
149 char		*fetchStringifyURL(const struct url *);
150 void		 fetchFreeURL(struct url *);
151 
152 /* URL listening */
153 void		 fetchInitURLList(struct url_list *);
154 void		 fetchFreeURLList(struct url_list *);
155 char		*fetchUnquotePath(struct url *);
156 char		*fetchUnquoteFilename(struct url *);
157 
158 /* Authentication */
159 typedef int (*auth_t)(struct url *);
160 extern auth_t		 fetchAuthMethod;
161 
162 /* Last error code */
163 extern int		 fetchLastErrCode;
164 #define MAXERRSTRING 256
165 extern char		 fetchLastErrString[MAXERRSTRING];
166 
167 /* I/O timeout */
168 extern int		 fetchTimeout;
169 
170 /* Restart interrupted syscalls */
171 extern int		 fetchRestartCalls;
172 
173 /* Extra verbosity */
174 extern int		 fetchDebug;
175 
176 #if defined(__cplusplus)
177 }
178 #endif
179 
180 #endif
181