fetch.h revision 87560
137535Sdes/*-
237535Sdes * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
337535Sdes * All rights reserved.
437535Sdes *
537535Sdes * Redistribution and use in source and binary forms, with or without
637535Sdes * modification, are permitted provided that the following conditions
737535Sdes * are met:
837535Sdes * 1. Redistributions of source code must retain the above copyright
937535Sdes *    notice, this list of conditions and the following disclaimer
1037535Sdes *    in this position and unchanged.
1137535Sdes * 2. Redistributions in binary form must reproduce the above copyright
1237535Sdes *    notice, this list of conditions and the following disclaimer in the
1337535Sdes *    documentation and/or other materials provided with the distribution.
1437535Sdes * 3. The name of the author may not be used to endorse or promote products
1537535Sdes *    derived from this software without specific prior written permission
1637535Sdes *
1737535Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1837535Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1937535Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2037535Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2137535Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2237535Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2337535Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2437535Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2537535Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2637535Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2737535Sdes *
2850476Speter * $FreeBSD: head/lib/libfetch/fetch.h 87560 2001-12-09 15:05:19Z des $
2937535Sdes */
3037535Sdes
3137535Sdes#ifndef _FETCH_H_INCLUDED
3237535Sdes#define _FETCH_H_INCLUDED
3337535Sdes
3460924Sdes#define _LIBFETCH_VER "libfetch/2.0"
3540975Sdes
3637535Sdes#define URL_SCHEMELEN 16
3737535Sdes#define URL_USERLEN 256
3837535Sdes#define URL_PWDLEN 256
3937535Sdes
4040975Sdesstruct url {
4140975Sdes    char	 scheme[URL_SCHEMELEN+1];
4240975Sdes    char	 user[URL_USERLEN+1];
4340975Sdes    char	 pwd[URL_PWDLEN+1];
4440975Sdes    char	 host[MAXHOSTNAMELEN+1];
4540975Sdes    int		 port;
4660376Sdes    char	*doc;
4760376Sdes    off_t	 offset;
4860376Sdes    size_t	 length;
4937535Sdes};
5037535Sdes
5140975Sdesstruct url_stat {
5240975Sdes    off_t	 size;
5341862Sdes    time_t	 atime;
5441862Sdes    time_t	 mtime;
5540975Sdes};
5637535Sdes
5741989Sdesstruct url_ent {
5877238Sdes    char	 name[PATH_MAX];
5941989Sdes    struct url_stat stat;
6041989Sdes};
6141989Sdes
6267041Sdes/* Recognized schemes */
6367041Sdes#define SCHEME_FTP	"ftp"
6467041Sdes#define SCHEME_HTTP	"http"
6569464Sdes#define SCHEME_HTTPS	"https"
6667041Sdes#define SCHEME_FILE	"file"
6767041Sdes
6860924Sdes/* Error codes */
6960924Sdes#define	FETCH_ABORT	 1
7060924Sdes#define	FETCH_AUTH	 2
7160924Sdes#define	FETCH_DOWN	 3
7260924Sdes#define	FETCH_EXISTS	 4
7360924Sdes#define	FETCH_FULL	 5
7460924Sdes#define	FETCH_INFO	 6
7560924Sdes#define	FETCH_MEMORY	 7
7660924Sdes#define	FETCH_MOVED	 8
7760924Sdes#define	FETCH_NETWORK	 9
7860924Sdes#define	FETCH_OK	10
7960924Sdes#define	FETCH_PROTO	11
8060924Sdes#define	FETCH_RESOLV	12
8160924Sdes#define	FETCH_SERVER	13
8260924Sdes#define	FETCH_TEMP	14
8360924Sdes#define	FETCH_TIMEOUT	15
8460924Sdes#define	FETCH_UNAVAIL	16
8560924Sdes#define	FETCH_UNKNOWN	17
8660924Sdes#define	FETCH_URL	18
8760924Sdes#define	FETCH_VERBOSE	19
8860924Sdes
8937535Sdes/* FILE-specific functions */
9075891SarchieFILE		*fetchXGetFile(struct url *, struct url_stat *, const char *);
9175891SarchieFILE		*fetchGetFile(struct url *, const char *);
9275891SarchieFILE		*fetchPutFile(struct url *, const char *);
9375891Sarchieint		 fetchStatFile(struct url *, struct url_stat *, const char *);
9475891Sarchiestruct url_ent	*fetchListFile(struct url *, const char *);
9537535Sdes
9637535Sdes/* HTTP-specific functions */
9775891SarchieFILE		*fetchXGetHTTP(struct url *, struct url_stat *, const char *);
9875891SarchieFILE		*fetchGetHTTP(struct url *, const char *);
9975891SarchieFILE		*fetchPutHTTP(struct url *, const char *);
10075891Sarchieint		 fetchStatHTTP(struct url *, struct url_stat *, const char *);
10175891Sarchiestruct url_ent	*fetchListHTTP(struct url *, const char *);
10237535Sdes
10337535Sdes/* FTP-specific functions */
10475891SarchieFILE		*fetchXGetFTP(struct url *, struct url_stat *, const char *);
10575891SarchieFILE		*fetchGetFTP(struct url *, const char *);
10675891SarchieFILE		*fetchPutFTP(struct url *, const char *);
10775891Sarchieint		 fetchStatFTP(struct url *, struct url_stat *, const char *);
10875891Sarchiestruct url_ent	*fetchListFTP(struct url *, const char *);
10937535Sdes
11037535Sdes/* Generic functions */
11175891SarchieFILE		*fetchXGetURL(const char *, struct url_stat *, const char *);
11275891SarchieFILE		*fetchGetURL(const char *, const char *);
11375891SarchieFILE		*fetchPutURL(const char *, const char *);
11475891Sarchieint		 fetchStatURL(const char *, struct url_stat *, const char *);
11575891Sarchiestruct url_ent	*fetchListURL(const char *, const char *);
11675891SarchieFILE		*fetchXGet(struct url *, struct url_stat *, const char *);
11775891SarchieFILE		*fetchGet(struct url *, const char *);
11875891SarchieFILE		*fetchPut(struct url *, const char *);
11975891Sarchieint		 fetchStat(struct url *, struct url_stat *, const char *);
12075891Sarchiestruct url_ent	*fetchList(struct url *, const char *);
12137535Sdes
12260376Sdes/* URL parsing */
12375891Sarchiestruct url	*fetchMakeURL(const char *, const char *, int,
12475891Sarchie			const char *, const char *, const char *);
12575891Sarchiestruct url	*fetchParseURL(const char *);
12660376Sdesvoid		 fetchFreeURL(struct url *);
12760376Sdes
12877238Sdes/* Authentication */
12977238Sdestypedef int (*auth_t)(struct url *);
13077238Sdesextern auth_t	 fetchAuthMethod;
13177238Sdes
13241862Sdes/* Last error code */
13341862Sdesextern int	 fetchLastErrCode;
13460924Sdes#define MAXERRSTRING 256
13560924Sdesextern char	 fetchLastErrString[MAXERRSTRING];
13655557Sdesextern int	 fetchTimeout;
13763335Sdesextern int	 fetchRestartCalls;
13841862Sdes
13987560Sdes/* Extra verbosity */
14087560Sdesextern int	 fetchDebug;
14187560Sdes
14237535Sdes#endif
143