137535Sdes/*- 2236103Sdes * Copyright (c) 1998-2004 Dag-Erling 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$ 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 { 4190267Sdes char scheme[URL_SCHEMELEN+1]; 4290267Sdes char user[URL_USERLEN+1]; 4390267Sdes char pwd[URL_PWDLEN+1]; 4490267Sdes char host[MAXHOSTNAMELEN+1]; 4590267Sdes int port; 4690267Sdes char *doc; 4790267Sdes off_t offset; 4890267Sdes size_t length; 49186124Smurray time_t ims_time; 5037535Sdes}; 5137535Sdes 5240975Sdesstruct url_stat { 5390267Sdes off_t size; 5490267Sdes time_t atime; 5590267Sdes time_t mtime; 5640975Sdes}; 5737535Sdes 5841989Sdesstruct url_ent { 5990267Sdes char name[PATH_MAX]; 6090267Sdes struct url_stat stat; 6141989Sdes}; 6241989Sdes 6367041Sdes/* Recognized schemes */ 6467041Sdes#define SCHEME_FTP "ftp" 6567041Sdes#define SCHEME_HTTP "http" 6669464Sdes#define SCHEME_HTTPS "https" 6767041Sdes#define SCHEME_FILE "file" 6867041Sdes 6960924Sdes/* Error codes */ 7060924Sdes#define FETCH_ABORT 1 7160924Sdes#define FETCH_AUTH 2 7260924Sdes#define FETCH_DOWN 3 7360924Sdes#define FETCH_EXISTS 4 7460924Sdes#define FETCH_FULL 5 7560924Sdes#define FETCH_INFO 6 7660924Sdes#define FETCH_MEMORY 7 7760924Sdes#define FETCH_MOVED 8 7860924Sdes#define FETCH_NETWORK 9 7960924Sdes#define FETCH_OK 10 8060924Sdes#define FETCH_PROTO 11 8160924Sdes#define FETCH_RESOLV 12 8260924Sdes#define FETCH_SERVER 13 8360924Sdes#define FETCH_TEMP 14 8460924Sdes#define FETCH_TIMEOUT 15 8560924Sdes#define FETCH_UNAVAIL 16 8660924Sdes#define FETCH_UNKNOWN 17 8760924Sdes#define FETCH_URL 18 8860924Sdes#define FETCH_VERBOSE 19 8960924Sdes 90100510Sdes__BEGIN_DECLS 91100510Sdes 9237535Sdes/* FILE-specific functions */ 9375891SarchieFILE *fetchXGetFile(struct url *, struct url_stat *, const char *); 9475891SarchieFILE *fetchGetFile(struct url *, const char *); 9575891SarchieFILE *fetchPutFile(struct url *, const char *); 9675891Sarchieint fetchStatFile(struct url *, struct url_stat *, const char *); 9775891Sarchiestruct url_ent *fetchListFile(struct url *, const char *); 9837535Sdes 9937535Sdes/* HTTP-specific functions */ 10075891SarchieFILE *fetchXGetHTTP(struct url *, struct url_stat *, const char *); 10175891SarchieFILE *fetchGetHTTP(struct url *, const char *); 10275891SarchieFILE *fetchPutHTTP(struct url *, const char *); 10375891Sarchieint fetchStatHTTP(struct url *, struct url_stat *, const char *); 10475891Sarchiestruct url_ent *fetchListHTTP(struct url *, const char *); 10537535Sdes 10637535Sdes/* FTP-specific functions */ 10775891SarchieFILE *fetchXGetFTP(struct url *, struct url_stat *, const char *); 10875891SarchieFILE *fetchGetFTP(struct url *, const char *); 10975891SarchieFILE *fetchPutFTP(struct url *, const char *); 11075891Sarchieint fetchStatFTP(struct url *, struct url_stat *, const char *); 11175891Sarchiestruct url_ent *fetchListFTP(struct url *, const char *); 11237535Sdes 11337535Sdes/* Generic functions */ 11475891SarchieFILE *fetchXGetURL(const char *, struct url_stat *, const char *); 11575891SarchieFILE *fetchGetURL(const char *, const char *); 11675891SarchieFILE *fetchPutURL(const char *, const char *); 11775891Sarchieint fetchStatURL(const char *, struct url_stat *, const char *); 11875891Sarchiestruct url_ent *fetchListURL(const char *, const char *); 11975891SarchieFILE *fetchXGet(struct url *, struct url_stat *, const char *); 12075891SarchieFILE *fetchGet(struct url *, const char *); 12175891SarchieFILE *fetchPut(struct url *, const char *); 12275891Sarchieint fetchStat(struct url *, struct url_stat *, const char *); 12375891Sarchiestruct url_ent *fetchList(struct url *, const char *); 12437535Sdes 12560376Sdes/* URL parsing */ 12675891Sarchiestruct url *fetchMakeURL(const char *, const char *, int, 12790267Sdes const char *, const char *, const char *); 12875891Sarchiestruct url *fetchParseURL(const char *); 12960376Sdesvoid fetchFreeURL(struct url *); 13060376Sdes 131100510Sdes__END_DECLS 132100510Sdes 13377238Sdes/* Authentication */ 13477238Sdestypedef int (*auth_t)(struct url *); 13590267Sdesextern auth_t fetchAuthMethod; 13677238Sdes 13741862Sdes/* Last error code */ 13890267Sdesextern int fetchLastErrCode; 13960924Sdes#define MAXERRSTRING 256 14090267Sdesextern char fetchLastErrString[MAXERRSTRING]; 14141862Sdes 14290267Sdes/* I/O timeout */ 14390267Sdesextern int fetchTimeout; 14490267Sdes 14590267Sdes/* Restart interrupted syscalls */ 14690267Sdesextern int fetchRestartCalls; 14790267Sdes 14887560Sdes/* Extra verbosity */ 14990267Sdesextern int fetchDebug; 15087560Sdes 15137535Sdes#endif 152