137535Sdes/*- 2226537Sdes * 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: stable/10/lib/libfetch/fetch.h 315904 2017-03-24 14:26:01Z 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 { 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; 50315904Sdes int netrcfd; 5137535Sdes}; 5237535Sdes 5340975Sdesstruct url_stat { 5490267Sdes off_t size; 5590267Sdes time_t atime; 5690267Sdes time_t mtime; 5740975Sdes}; 5837535Sdes 5941989Sdesstruct url_ent { 6090267Sdes char name[PATH_MAX]; 6190267Sdes struct url_stat stat; 6241989Sdes}; 6341989Sdes 6467041Sdes/* Recognized schemes */ 6567041Sdes#define SCHEME_FTP "ftp" 6667041Sdes#define SCHEME_HTTP "http" 6769464Sdes#define SCHEME_HTTPS "https" 6867041Sdes#define SCHEME_FILE "file" 6967041Sdes 7060924Sdes/* Error codes */ 7160924Sdes#define FETCH_ABORT 1 7260924Sdes#define FETCH_AUTH 2 7360924Sdes#define FETCH_DOWN 3 7460924Sdes#define FETCH_EXISTS 4 7560924Sdes#define FETCH_FULL 5 7660924Sdes#define FETCH_INFO 6 7760924Sdes#define FETCH_MEMORY 7 7860924Sdes#define FETCH_MOVED 8 7960924Sdes#define FETCH_NETWORK 9 8060924Sdes#define FETCH_OK 10 8160924Sdes#define FETCH_PROTO 11 8260924Sdes#define FETCH_RESOLV 12 8360924Sdes#define FETCH_SERVER 13 8460924Sdes#define FETCH_TEMP 14 8560924Sdes#define FETCH_TIMEOUT 15 8660924Sdes#define FETCH_UNAVAIL 16 8760924Sdes#define FETCH_UNKNOWN 17 8860924Sdes#define FETCH_URL 18 8960924Sdes#define FETCH_VERBOSE 19 9060924Sdes 91100510Sdes__BEGIN_DECLS 92100510Sdes 9337535Sdes/* FILE-specific functions */ 9475891SarchieFILE *fetchXGetFile(struct url *, struct url_stat *, const char *); 9575891SarchieFILE *fetchGetFile(struct url *, const char *); 9675891SarchieFILE *fetchPutFile(struct url *, const char *); 9775891Sarchieint fetchStatFile(struct url *, struct url_stat *, const char *); 9875891Sarchiestruct url_ent *fetchListFile(struct url *, const char *); 9937535Sdes 10037535Sdes/* HTTP-specific functions */ 10175891SarchieFILE *fetchXGetHTTP(struct url *, struct url_stat *, const char *); 10275891SarchieFILE *fetchGetHTTP(struct url *, const char *); 10375891SarchieFILE *fetchPutHTTP(struct url *, const char *); 10475891Sarchieint fetchStatHTTP(struct url *, struct url_stat *, const char *); 10575891Sarchiestruct url_ent *fetchListHTTP(struct url *, const char *); 106268900SbaptFILE *fetchReqHTTP(struct url *, const char *, const char *, 107268900Sbapt const char *, const char *); 10837535Sdes 10937535Sdes/* FTP-specific functions */ 11075891SarchieFILE *fetchXGetFTP(struct url *, struct url_stat *, const char *); 11175891SarchieFILE *fetchGetFTP(struct url *, const char *); 11275891SarchieFILE *fetchPutFTP(struct url *, const char *); 11375891Sarchieint fetchStatFTP(struct url *, struct url_stat *, const char *); 11475891Sarchiestruct url_ent *fetchListFTP(struct url *, const char *); 11537535Sdes 11637535Sdes/* Generic functions */ 11775891SarchieFILE *fetchXGetURL(const char *, struct url_stat *, const char *); 11875891SarchieFILE *fetchGetURL(const char *, const char *); 11975891SarchieFILE *fetchPutURL(const char *, const char *); 12075891Sarchieint fetchStatURL(const char *, struct url_stat *, const char *); 12175891Sarchiestruct url_ent *fetchListURL(const char *, const char *); 12275891SarchieFILE *fetchXGet(struct url *, struct url_stat *, const char *); 12375891SarchieFILE *fetchGet(struct url *, const char *); 12475891SarchieFILE *fetchPut(struct url *, const char *); 12575891Sarchieint fetchStat(struct url *, struct url_stat *, const char *); 12675891Sarchiestruct url_ent *fetchList(struct url *, const char *); 12737535Sdes 12860376Sdes/* URL parsing */ 12975891Sarchiestruct url *fetchMakeURL(const char *, const char *, int, 13090267Sdes const char *, const char *, const char *); 13175891Sarchiestruct url *fetchParseURL(const char *); 13260376Sdesvoid fetchFreeURL(struct url *); 13360376Sdes 134100510Sdes__END_DECLS 135100510Sdes 13677238Sdes/* Authentication */ 13777238Sdestypedef int (*auth_t)(struct url *); 13890267Sdesextern auth_t fetchAuthMethod; 13977238Sdes 14041862Sdes/* Last error code */ 14190267Sdesextern int fetchLastErrCode; 14260924Sdes#define MAXERRSTRING 256 14390267Sdesextern char fetchLastErrString[MAXERRSTRING]; 14441862Sdes 14590267Sdes/* I/O timeout */ 14690267Sdesextern int fetchTimeout; 14790267Sdes 14890267Sdes/* Restart interrupted syscalls */ 14990267Sdesextern int fetchRestartCalls; 15090267Sdes 15187560Sdes/* Extra verbosity */ 15290267Sdesextern int fetchDebug; 15387560Sdes 15437535Sdes#endif 155