14ca1ab94SDag-Erling Smørgrav /*- 2*5e53a4f9SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*5e53a4f9SPedro F. Giffuni * 4578153f1SDag-Erling Smørgrav * Copyright (c) 1998-2004 Dag-Erling Smørgrav 54ca1ab94SDag-Erling Smørgrav * All rights reserved. 64ca1ab94SDag-Erling Smørgrav * 74ca1ab94SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 84ca1ab94SDag-Erling Smørgrav * modification, are permitted provided that the following conditions 94ca1ab94SDag-Erling Smørgrav * are met: 104ca1ab94SDag-Erling Smørgrav * 1. Redistributions of source code must retain the above copyright 114ca1ab94SDag-Erling Smørgrav * notice, this list of conditions and the following disclaimer 124ca1ab94SDag-Erling Smørgrav * in this position and unchanged. 134ca1ab94SDag-Erling Smørgrav * 2. Redistributions in binary form must reproduce the above copyright 144ca1ab94SDag-Erling Smørgrav * notice, this list of conditions and the following disclaimer in the 154ca1ab94SDag-Erling Smørgrav * documentation and/or other materials provided with the distribution. 164ca1ab94SDag-Erling Smørgrav * 3. The name of the author may not be used to endorse or promote products 174ca1ab94SDag-Erling Smørgrav * derived from this software without specific prior written permission 184ca1ab94SDag-Erling Smørgrav * 194ca1ab94SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 204ca1ab94SDag-Erling Smørgrav * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 214ca1ab94SDag-Erling Smørgrav * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 224ca1ab94SDag-Erling Smørgrav * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 234ca1ab94SDag-Erling Smørgrav * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 244ca1ab94SDag-Erling Smørgrav * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 254ca1ab94SDag-Erling Smørgrav * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 264ca1ab94SDag-Erling Smørgrav * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 274ca1ab94SDag-Erling Smørgrav * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 284ca1ab94SDag-Erling Smørgrav * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 294ca1ab94SDag-Erling Smørgrav */ 304ca1ab94SDag-Erling Smørgrav 314ca1ab94SDag-Erling Smørgrav #ifndef _FETCH_H_INCLUDED 324ca1ab94SDag-Erling Smørgrav #define _FETCH_H_INCLUDED 334ca1ab94SDag-Erling Smørgrav 34ba101983SDag-Erling Smørgrav #define _LIBFETCH_VER "libfetch/2.0" 354ca1ab94SDag-Erling Smørgrav 364ca1ab94SDag-Erling Smørgrav #define URL_SCHEMELEN 16 374ca1ab94SDag-Erling Smørgrav #define URL_USERLEN 256 384ca1ab94SDag-Erling Smørgrav #define URL_PWDLEN 256 394ca1ab94SDag-Erling Smørgrav 40d8acd8dcSDag-Erling Smørgrav struct url { 414ca1ab94SDag-Erling Smørgrav char scheme[URL_SCHEMELEN+1]; 424ca1ab94SDag-Erling Smørgrav char user[URL_USERLEN+1]; 434ca1ab94SDag-Erling Smørgrav char pwd[URL_PWDLEN+1]; 444ca1ab94SDag-Erling Smørgrav char host[MAXHOSTNAMELEN+1]; 454ca1ab94SDag-Erling Smørgrav int port; 4660245e42SDag-Erling Smørgrav char *doc; 4760245e42SDag-Erling Smørgrav off_t offset; 4860245e42SDag-Erling Smørgrav size_t length; 497f92799fSMurray Stokely time_t ims_time; 50d8713bf3SBaptiste Daroussin int netrcfd; 514ca1ab94SDag-Erling Smørgrav }; 524ca1ab94SDag-Erling Smørgrav 53d8acd8dcSDag-Erling Smørgrav struct url_stat { 54d8acd8dcSDag-Erling Smørgrav off_t size; 550fba3a00SDag-Erling Smørgrav time_t atime; 560fba3a00SDag-Erling Smørgrav time_t mtime; 57d8acd8dcSDag-Erling Smørgrav }; 584ca1ab94SDag-Erling Smørgrav 59ce71b736SDag-Erling Smørgrav struct url_ent { 606490b215SDag-Erling Smørgrav char name[PATH_MAX]; 61ce71b736SDag-Erling Smørgrav struct url_stat stat; 62ce71b736SDag-Erling Smørgrav }; 63ce71b736SDag-Erling Smørgrav 64be9e1d8aSDag-Erling Smørgrav /* Recognized schemes */ 65be9e1d8aSDag-Erling Smørgrav #define SCHEME_FTP "ftp" 66be9e1d8aSDag-Erling Smørgrav #define SCHEME_HTTP "http" 67025bb05aSDag-Erling Smørgrav #define SCHEME_HTTPS "https" 68be9e1d8aSDag-Erling Smørgrav #define SCHEME_FILE "file" 69be9e1d8aSDag-Erling Smørgrav 70ba101983SDag-Erling Smørgrav /* Error codes */ 71ba101983SDag-Erling Smørgrav #define FETCH_ABORT 1 72ba101983SDag-Erling Smørgrav #define FETCH_AUTH 2 73ba101983SDag-Erling Smørgrav #define FETCH_DOWN 3 74ba101983SDag-Erling Smørgrav #define FETCH_EXISTS 4 75ba101983SDag-Erling Smørgrav #define FETCH_FULL 5 76ba101983SDag-Erling Smørgrav #define FETCH_INFO 6 77ba101983SDag-Erling Smørgrav #define FETCH_MEMORY 7 78ba101983SDag-Erling Smørgrav #define FETCH_MOVED 8 79ba101983SDag-Erling Smørgrav #define FETCH_NETWORK 9 80ba101983SDag-Erling Smørgrav #define FETCH_OK 10 81ba101983SDag-Erling Smørgrav #define FETCH_PROTO 11 82ba101983SDag-Erling Smørgrav #define FETCH_RESOLV 12 83ba101983SDag-Erling Smørgrav #define FETCH_SERVER 13 84ba101983SDag-Erling Smørgrav #define FETCH_TEMP 14 85ba101983SDag-Erling Smørgrav #define FETCH_TIMEOUT 15 86ba101983SDag-Erling Smørgrav #define FETCH_UNAVAIL 16 87ba101983SDag-Erling Smørgrav #define FETCH_UNKNOWN 17 88ba101983SDag-Erling Smørgrav #define FETCH_URL 18 89ba101983SDag-Erling Smørgrav #define FETCH_VERBOSE 19 90ba101983SDag-Erling Smørgrav 91190c185eSDag-Erling Smørgrav __BEGIN_DECLS 92190c185eSDag-Erling Smørgrav 934ca1ab94SDag-Erling Smørgrav /* FILE-specific functions */ 9438c7e4a6SArchie Cobbs FILE *fetchXGetFile(struct url *, struct url_stat *, const char *); 9538c7e4a6SArchie Cobbs FILE *fetchGetFile(struct url *, const char *); 9638c7e4a6SArchie Cobbs FILE *fetchPutFile(struct url *, const char *); 9738c7e4a6SArchie Cobbs int fetchStatFile(struct url *, struct url_stat *, const char *); 9838c7e4a6SArchie Cobbs struct url_ent *fetchListFile(struct url *, const char *); 994ca1ab94SDag-Erling Smørgrav 1004ca1ab94SDag-Erling Smørgrav /* HTTP-specific functions */ 10138c7e4a6SArchie Cobbs FILE *fetchXGetHTTP(struct url *, struct url_stat *, const char *); 10238c7e4a6SArchie Cobbs FILE *fetchGetHTTP(struct url *, const char *); 10338c7e4a6SArchie Cobbs FILE *fetchPutHTTP(struct url *, const char *); 10438c7e4a6SArchie Cobbs int fetchStatHTTP(struct url *, struct url_stat *, const char *); 10538c7e4a6SArchie Cobbs struct url_ent *fetchListHTTP(struct url *, const char *); 106c4199130SBaptiste Daroussin FILE *fetchReqHTTP(struct url *, const char *, const char *, 107c4199130SBaptiste Daroussin const char *, const char *); 1084ca1ab94SDag-Erling Smørgrav 1094ca1ab94SDag-Erling Smørgrav /* FTP-specific functions */ 11038c7e4a6SArchie Cobbs FILE *fetchXGetFTP(struct url *, struct url_stat *, const char *); 11138c7e4a6SArchie Cobbs FILE *fetchGetFTP(struct url *, const char *); 11238c7e4a6SArchie Cobbs FILE *fetchPutFTP(struct url *, const char *); 11338c7e4a6SArchie Cobbs int fetchStatFTP(struct url *, struct url_stat *, const char *); 11438c7e4a6SArchie Cobbs struct url_ent *fetchListFTP(struct url *, const char *); 1154ca1ab94SDag-Erling Smørgrav 1164ca1ab94SDag-Erling Smørgrav /* Generic functions */ 11738c7e4a6SArchie Cobbs FILE *fetchXGetURL(const char *, struct url_stat *, const char *); 11838c7e4a6SArchie Cobbs FILE *fetchGetURL(const char *, const char *); 11938c7e4a6SArchie Cobbs FILE *fetchPutURL(const char *, const char *); 12038c7e4a6SArchie Cobbs int fetchStatURL(const char *, struct url_stat *, const char *); 12138c7e4a6SArchie Cobbs struct url_ent *fetchListURL(const char *, const char *); 12238c7e4a6SArchie Cobbs FILE *fetchXGet(struct url *, struct url_stat *, const char *); 12338c7e4a6SArchie Cobbs FILE *fetchGet(struct url *, const char *); 12438c7e4a6SArchie Cobbs FILE *fetchPut(struct url *, const char *); 12538c7e4a6SArchie Cobbs int fetchStat(struct url *, struct url_stat *, const char *); 12638c7e4a6SArchie Cobbs struct url_ent *fetchList(struct url *, const char *); 1274ca1ab94SDag-Erling Smørgrav 12860245e42SDag-Erling Smørgrav /* URL parsing */ 12938c7e4a6SArchie Cobbs struct url *fetchMakeURL(const char *, const char *, int, 13038c7e4a6SArchie Cobbs const char *, const char *, const char *); 13138c7e4a6SArchie Cobbs struct url *fetchParseURL(const char *); 13260245e42SDag-Erling Smørgrav void fetchFreeURL(struct url *); 13360245e42SDag-Erling Smørgrav 134190c185eSDag-Erling Smørgrav __END_DECLS 135190c185eSDag-Erling Smørgrav 1366490b215SDag-Erling Smørgrav /* Authentication */ 1376490b215SDag-Erling Smørgrav typedef int (*auth_t)(struct url *); 1386490b215SDag-Erling Smørgrav extern auth_t fetchAuthMethod; 1396490b215SDag-Erling Smørgrav 1400fba3a00SDag-Erling Smørgrav /* Last error code */ 1410fba3a00SDag-Erling Smørgrav extern int fetchLastErrCode; 142ba101983SDag-Erling Smørgrav #define MAXERRSTRING 256 143ba101983SDag-Erling Smørgrav extern char fetchLastErrString[MAXERRSTRING]; 144e19e6098SDag-Erling Smørgrav 145e19e6098SDag-Erling Smørgrav /* I/O timeout */ 146fc6e9e65SDag-Erling Smørgrav extern int fetchTimeout; 147e19e6098SDag-Erling Smørgrav 148e19e6098SDag-Erling Smørgrav /* Restart interrupted syscalls */ 149d999dcacSDag-Erling Smørgrav extern int fetchRestartCalls; 1500fba3a00SDag-Erling Smørgrav 1517eb2f34dSDag-Erling Smørgrav /* Extra verbosity */ 1527eb2f34dSDag-Erling Smørgrav extern int fetchDebug; 1537eb2f34dSDag-Erling Smørgrav 1544ca1ab94SDag-Erling Smørgrav #endif 155