├── .gitignore ├── Changes ├── LICENSE ├── Makefile ├── README ├── README.md ├── http-basic-auth.c ├── http-man.txt ├── http.c ├── http.html ├── http_lib.c ├── http_lib.h ├── http_lib.html ├── man1 └── http.1 └── man3 ├── http_delete.3 ├── http_get.3 ├── http_head.3 ├── http_lib.3 ├── http_parse_url.3 ├── http_port.3 ├── http_proxy_port.3 ├── http_proxy_server.3 ├── http_put.3 └── http_server.3 /.gitignore: -------------------------------------------------------------------------------- 1 | http 2 | http.o 3 | http_lib.o 4 | libhttp.a 5 | 6 | -------------------------------------------------------------------------------- /Changes: -------------------------------------------------------------------------------- 1 | ##### Changes log: 2 | Sept 22 1998 (yes, two and half years since last release, pretty stable :-) 3 | + Released as 1.2 4 | + Added compatibility with 1.1 servers (but does not take 5 | advantage of 1.1 yet) 6 | + small Makefile change for better portability 7 | + contact, url, etc... updates 8 | Apr 25/26 1996 9 | + Released as 1.1a 10 | + renamed libdoc as man3 and created man1 for http.1 11 | + tiny change for better portability (freebsd) 12 | Apr 24 1996 13 | + released as 1.1 14 | + added http_proxy env var support 15 | Apr 18 1996 16 | + released as 1.0 17 | + first public release! 18 | ##### 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | 3 | The "Artistic License" 4 | 5 | Preamble 6 | 7 | The intent of this document is to state the conditions under which a 8 | Package may be copied, such that the Copyright Holder maintains some 9 | semblance of artistic control over the development of the package, 10 | while giving the users of the package the right to use and distribute 11 | the Package in a more-or-less customary fashion, plus the right to make 12 | reasonable modifications. 13 | 14 | Definitions: 15 | 16 | "Package" refers to the collection of files distributed by the 17 | Copyright Holder, and derivatives of that collection of files 18 | created through textual modification. 19 | 20 | "Standard Version" refers to such a Package if it has not been 21 | modified, or has been modified in accordance with the wishes 22 | of the Copyright Holder. 23 | 24 | "Copyright Holder" is whoever is named in the copyright or 25 | copyrights for the package. 26 | 27 | "You" is you, if you're thinking about copying or distributing 28 | this Package. 29 | 30 | "Reasonable copying fee" is whatever you can justify on the 31 | basis of media cost, duplication charges, time of people involved, 32 | and so on. (You will not be required to justify it to the 33 | Copyright Holder, but only to the computing community at large 34 | as a market that must bear the fee.) 35 | 36 | "Freely Available" means that no fee is charged for the item 37 | itself, though there may be fees involved in handling the item. 38 | It also means that recipients of the item may redistribute it 39 | under the same conditions they received it. 40 | 41 | 1. You may make and give away verbatim copies of the source form of the 42 | Standard Version of this Package without restriction, provided that you 43 | duplicate all of the original copyright notices and associated disclaimers. 44 | 45 | 2. You may apply bug fixes, portability fixes and other modifications 46 | derived from the Public Domain or from the Copyright Holder. A Package 47 | modified in such a way shall still be considered the Standard Version. 48 | 49 | 3. You may otherwise modify your copy of this Package in any way, provided 50 | that you insert a prominent notice in each changed file stating how and 51 | when you changed that file, and provided that you do at least ONE of the 52 | following: 53 | 54 | a) place your modifications in the Public Domain or otherwise make them 55 | Freely Available, such as by posting said modifications to Usenet or 56 | an equivalent medium, or placing the modifications on a major archive 57 | site such as uunet.uu.net, or by allowing the Copyright Holder to include 58 | your modifications in the Standard Version of the Package. 59 | 60 | b) use the modified Package only within your corporation or organization. 61 | 62 | c) rename any non-standard executables so the names do not conflict 63 | with standard executables, which must also be provided, and provide 64 | a separate manual page for each non-standard executable that clearly 65 | documents how it differs from the Standard Version. 66 | 67 | d) make other distribution arrangements with the Copyright Holder. 68 | 69 | 4. You may distribute the programs of this Package in object code or 70 | executable form, provided that you do at least ONE of the following: 71 | 72 | a) distribute a Standard Version of the executables and library files, 73 | together with instructions (in the manual page or equivalent) on where 74 | to get the Standard Version. 75 | 76 | b) accompany the distribution with the machine-readable source of 77 | the Package with your modifications. 78 | 79 | c) accompany any non-standard executables with their corresponding 80 | Standard Version executables, giving the non-standard executables 81 | non-standard names, and clearly documenting the differences in manual 82 | pages (or equivalent), together with instructions on where to get 83 | the Standard Version. 84 | 85 | d) make other distribution arrangements with the Copyright Holder. 86 | 87 | 5. You may charge a reasonable copying fee for any distribution of this 88 | Package. You may charge any fee you choose for support of this Package. 89 | You may not charge a fee for this Package itself. However, 90 | you may distribute this Package in aggregate with other (possibly 91 | commercial) programs as part of a larger (possibly commercial) software 92 | distribution provided that you do not advertise this Package as a 93 | product of your own. 94 | 95 | 6. The scripts and library files supplied as input to or produced as 96 | output from the programs of this Package do not automatically fall 97 | under the copyright of this Package, but belong to whomever generated 98 | them, and may be sold commercially, and may be aggregated with this 99 | Package. 100 | 101 | 7. C subroutines supplied by you and linked into this Package in order 102 | to emulate subroutines and variables of the language defined by this 103 | Package shall not be considered part of this Package, but are the 104 | equivalent of input as in Paragraph 6, provided these subroutines do 105 | not change the language in any way that would cause it to fail the 106 | regression tests for the language. 107 | 108 | 8. The name of the Copyright Holder may not be used to endorse or promote 109 | products derived from this software without specific prior written permission. 110 | 111 | 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR 112 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 113 | WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 114 | 115 | The End 116 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for http-tiny 3 | # written by L. Demailly 4 | # 5 | # (c)1998 Laurent Demailly 6 | # (c)1996 Observatoire de Paris 7 | # 8 | # $Id: Makefile,v 1.2 1998/09/23 06:17:55 dl Exp $ 9 | # 10 | # 11 | 12 | # Check the following : 13 | 14 | prefix=/usr/local 15 | 16 | # where to install executable 17 | BINDIR=$(prefix)/bin 18 | # where to put man pages 19 | MANDIR=$(prefix)/man 20 | # where to put lib 21 | LIBDIR=$(prefix)/lib 22 | # where to put include 23 | INCDIR=$(prefix)/include 24 | 25 | # Your compiler 26 | CC = gcc 27 | # Compile flags 28 | CDEBUGFLAGS = -O -Wall # -g 29 | 30 | # defines (needed for string ops on linux2/glibc for instance) 31 | DEFINES= -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_GNU_SOURCE #-D_DEBUG 32 | 33 | # for HPUX (ansi) 34 | #DEFINES= -D_HPUX_SOURCE 35 | # for solaris some defines are needed for strncmp,... but can't find the good 36 | # one... maybe the one above (for linux) work too, I haven't checked yet. 37 | #DEFINES= -D 38 | # others, may need something... 39 | 40 | 41 | # Solaris 42 | #SYSLIBS= -lsocket -lnsl 43 | 44 | #INCLPATH = 45 | 46 | # mostly standard 47 | RM= rm -f 48 | CP = cp -f 49 | CHMOD= chmod 50 | MKDIR= mkdir -p 51 | AR = ar 52 | RANLIB = ranlib 53 | TAR= gtar 54 | 55 | # no edit should be needed below... 56 | 57 | CFLAGS = $(CDEBUGFLAGS) $(INCLPATH) $(DEFINES) 58 | LDFLAGS= $(CFLAGS) -L. 59 | 60 | LIBOBJS = http_lib.o 61 | 62 | TARGETS = libhttp.a http 63 | 64 | all: $(TARGETS) 65 | 66 | http: http.o libhttp.a 67 | $(CC) $(LDFLAGS) $@.o -lhttp $(SYSLIBS) -o $@ 68 | 69 | http-basic-auth: http-basic-auth.o libhttp.a 70 | $(CC) $(LDFLAGS) $@.o -lhttp -lb64 $(SYSLIBS) -o $@ 71 | 72 | libhttp.a: $(LIBOBJS) 73 | $(RM) $@ 74 | $(AR) r $@ $(LIBOBJS) 75 | $(RANLIB) $@ 76 | 77 | install: $(TARGETS) 78 | $(CP) http $(BINDIR) 79 | $(CP) libhttp.a $(LIBDIR) 80 | $(CP) man1/http.1 $(MANDIR)/man1 81 | $(CP) man3/http_lib.3 $(MANDIR)/man3 82 | $(CP) http_lib.h $(INCDIR) 83 | 84 | clean: 85 | $(RM) $(TARGETS) 86 | $(RM) *.tgz 87 | $(RM) *.o 88 | $(RM) *~ 89 | $(RM) #* 90 | $(RM) core 91 | $(RM) http-basic-auth 92 | 93 | depend: 94 | makedepend $(INCLPATH) $(DEFINES) *.c 95 | 96 | # internal use 97 | 98 | man3: http_lib.c 99 | $(MKDIR) $@ 100 | ( cd $@ ; c2man -i \"http_lib.h\" -ngv -ls ../http_lib.c ) 101 | 102 | fdoc: 103 | $(RM) -r man3 104 | $(MAKE) man3 105 | 106 | pure: 107 | $(MAKE) clean 108 | $(MAKE) CC="purify gcc -g" 109 | 110 | tar: 111 | $(MAKE) clean 112 | $(RM) -r http-tiny-$(VERSION) 113 | $(RM) -f http-tiny-*.tar.gz 114 | $(MKDIR) http-tiny-$(VERSION) 115 | -$(CP) * http-tiny-$(VERSION) 116 | $(TAR) cf - man1 | (cd http-tiny-$(VERSION) ; $(TAR) xvf - ) 117 | $(TAR) cf - man3 | (cd http-tiny-$(VERSION) ; $(TAR) xvf - ) 118 | $(TAR) cvfz http-tiny-$(VERSION).tar.gz http-tiny-$(VERSION) 119 | 120 | #distrib: tar 121 | # $(CP) http-tiny-$(VERSION).tar.gz /poubelle/ftp/www/ 122 | # $(CP) http-tiny-$(VERSION).tar.gz /users/dl/public_html/ 123 | 124 | 125 | # DO NOT DELETE THIS LINE -- make depend depends on it. 126 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | *** Http tiny library & command line program package *** release 1.2 3 | (c) 2013 Anibal Limon 4 | (c) 1998 Laurent Demailly - see LICENSE 5 | (c) 1996 Observatoire de Paris 6 | Author(s): Laurent Demailly - http://www.demailly.com/~dl/ 7 | 8 | 9 | http_lib.c is a small library for http commands, 10 | see nroff -man man3/http_lib.3 | more 11 | 12 | http is a example of use. see nroff -man man1/http.1 | more 13 | (or see http-man.txt if you don't have nroff/man) 14 | 15 | 16 | To compile / INSTALL: 17 | You need a C compiler, preferably ansi, like gcc 18 | 19 | 1) EDIT makefile 20 | 2) type make depend (or remove everything after the # DO NOT DELETE ... line) 21 | 3) type make 22 | (you might have edit http_lib.c for includes, in that case, 23 | Please tell me...) 24 | 3-x) for build http-basic-auth type make http-basic-auth you need libb64 25 | 4) type make install 26 | 5) enjoy using "http" and/or the library in your programs (-lhttp) 27 | 6) send feedback and your best uses of the lib to 28 | ! 29 | 30 | Tested succesfully on Linux, Solaris, Hp-Ux(8), and OS/9 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | http-tiny 2 | ========= 3 | 4 | http-tiny 1.2 improvments 5 | 6 | http-tiny is good implementation of HTTP for embedded 7 | applications. 8 | 9 | For support basic auth you should be implement your own 10 | function for base64 encoding or use another one, see 11 | http-basic-auth.c for example of implementation. 12 | 13 | Added multi-thread support with functions httpmt. 14 | 15 | - http\_post added 16 | - http\_set\_basic\_auth added 17 | - http_read_buffer_eof (GET/POST support for read body without Content length header field) 18 | - httpmt\_\*. 19 | 20 | TODO 21 | 22 | - Update manual pages. 23 | -------------------------------------------------------------------------------- /http-basic-auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Http put/get/post standalone program using Http put mini lib 3 | * written by L. Demailly 4 | * (c) 2013 Anibal Limon - limon.anibal@gmail.com 5 | * (c) 1998 Laurent Demailly - http://www.demailly.com/~dl/ 6 | * (c) 1996 Observatoire de Paris - Meudon - France 7 | * see LICENSE for terms, conditions and DISCLAIMER OF ALL WARRANTIES 8 | * 9 | * $Id: http.c,v 1.4 1998/09/23 06:11:55 dl Exp $ 10 | * 11 | * Revision 1.5.x 2013/08/07 21:41:42 -0500 12 | * Added Basic auth support, base64 encoding is provided for external 13 | * function trought http_set_base64_encoder. 14 | * Author: alimon 15 | * 16 | * Revision 1.5.x 2013/08/07 08:30:42 -0500 17 | * Removed no used code for OS9, and code functions to access global 18 | * variables now static instead extern. 19 | * Author: alimon 20 | * 21 | * Revisionq 1.5.x 2013/08/07 00:20:42 -0500 22 | * Added support for POST 23 | * Author: alimon 24 | * $Log: http.c,v $ 25 | * Revision 1.4 1998/09/23 06:11:55 dl 26 | * one more lint 27 | * 28 | * Revision 1.3 1998/09/23 06:03:45 dl 29 | * proxy support (old change which was not checked in back in 96) 30 | * contact, etc.. infos update 31 | * 32 | * Revision 1.2 1996/04/18 13:52:14 dl 33 | * strings.h->string.h 34 | * 35 | * Revision 1.1 1996/04/18 12:17:25 dl 36 | * Initial revision 37 | * 38 | */ 39 | 40 | 41 | static char *rcsid="$Id: http.c,v 1.4 1998/09/23 06:11:55 dl Exp $"; 42 | 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #include 53 | 54 | #include "http_lib.h" 55 | 56 | static int myb64enc(const char *in, char **out); 57 | 58 | int main(argc,argv) 59 | int argc; 60 | char **argv; 61 | { 62 | int ret,lg,blocksize,r,i; 63 | char typebuf[70]; 64 | char *data=NULL,*filename=NULL,*proxy=NULL; 65 | int data_len = 0; 66 | char *type = NULL; 67 | enum { 68 | ERR, 69 | DOPUT, 70 | DOGET, 71 | DODEL, 72 | DOHEA, 73 | DOPOST 74 | } todo=ERR; 75 | 76 | if (argc!=5) { 77 | fprintf(stderr,"usage: http \n\tby \n"); 78 | return 1; 79 | } 80 | i=1; 81 | 82 | http_set_base64_encoder(&myb64enc); 83 | if ((ret = http_set_basic_auth(argv[3], argv[4])) < 0) 84 | return ret; 85 | 86 | if (!strcasecmp(argv[i],"put")) { 87 | todo=DOPUT; 88 | } else if (!strcasecmp(argv[i],"get")) { 89 | todo=DOGET; 90 | } else if (!strcasecmp(argv[i],"delete")) { 91 | todo=DODEL; 92 | } else if (!strcasecmp(argv[i],"head")) { 93 | todo=DOHEA; 94 | } else if (!strcasecmp(argv[i],"post")) { 95 | todo=DOPOST; 96 | } 97 | if (todo==ERR) { 98 | fprintf(stderr, 99 | "Invalid '%s',\nmust be " 100 | "'put', 'get', 'post', 'delete', or 'head'\n", 101 | argv[i]); 102 | return 2; 103 | } 104 | i++; 105 | 106 | 107 | if ((proxy=getenv("http_proxy"))) { 108 | ret=http_proxy_url(proxy); 109 | if (ret<0) return ret; 110 | } 111 | 112 | ret=http_parse_url(argv[i],&filename); 113 | if (ret<0) 114 | return ret; 115 | 116 | switch (todo) { 117 | /* *** PUT *** */ 118 | case DOPUT: 119 | fprintf(stderr,"reading stdin...\n"); 120 | /* read stdin into memory */ 121 | blocksize=16384; 122 | lg=0; 123 | if (!(data=malloc(blocksize))) { 124 | return 3; 125 | } 126 | while (1) { 127 | r=read(0,data+lg,blocksize-lg); 128 | if (r<=0) break; 129 | lg+=r; 130 | if ((3*lg/2)>blocksize) { 131 | blocksize *= 4; 132 | fprintf(stderr, 133 | "read to date: %9d bytes, reallocating buffer to %9d\n", 134 | lg,blocksize); 135 | if (!(data=realloc(data,blocksize))) { 136 | return 4; 137 | } 138 | } 139 | } 140 | fprintf(stderr,"read %d bytes\n",lg); 141 | ret=http_put(filename,data,lg,0,NULL); 142 | fprintf(stderr,"res=%d\n",ret); 143 | break; 144 | /* *** GET *** */ 145 | case DOGET: 146 | ret=http_get(filename,&data,&lg,typebuf); 147 | fprintf(stderr,"res=%d,type='%s',lg=%d\n",ret,typebuf,lg); 148 | fwrite(data,lg,1,stdout); 149 | break; 150 | /* *** HEAD *** */ 151 | case DOHEA: 152 | ret=http_head(filename,&lg,typebuf); 153 | fprintf(stderr,"res=%d,type='%s',lg=%d\n",ret,typebuf,lg); 154 | break; 155 | /* *** DELETE *** */ 156 | case DODEL: 157 | ret=http_delete(filename); 158 | fprintf(stderr,"res=%d\n",ret); 159 | break; 160 | case DOPOST: 161 | ret = http_post(filename, "your_name=1", 11, NULL, &data, &data_len, &type); 162 | fprintf(stderr,"res=%d\n",ret); 163 | fprintf(stderr,"%s\n", type); 164 | fprintf(stderr,"%s\n", data); 165 | break; 166 | /* impossible... */ 167 | default: 168 | fprintf(stderr,"impossible todo value=%d\n",todo); 169 | return 5; 170 | } 171 | 172 | if (type) free(type); 173 | if (data) free(data); 174 | free(filename); 175 | 176 | return ( (ret==201) || (ret==200) ) ? 0 : ret; 177 | } 178 | 179 | static int 180 | myb64enc(const char *in, char **out) 181 | { 182 | int r = 0; 183 | int b64_max_size; 184 | 185 | if (in == NULL) { 186 | errno = EINVAL; 187 | return -1; 188 | } 189 | 190 | b64_max_size = (((strlen(in) + 1) * 8) + 5) / 6; 191 | *out = malloc(b64_max_size); 192 | if (*out == NULL) { 193 | errno = ENOMEM; 194 | return -1; 195 | } 196 | 197 | { 198 | char* c = *out; 199 | int cnt = 0; 200 | base64_encodestate s; 201 | 202 | base64_init_encodestate(&s); 203 | cnt = base64_encode_block(in, strlen(in), c, &s); 204 | c += cnt; 205 | cnt = base64_encode_blockend(c, &s); 206 | c += cnt; 207 | *c = '\0'; 208 | } 209 | 210 | return r; 211 | } 212 | -------------------------------------------------------------------------------- /http-man.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HTTP(1) dl's free utilities HTTP(1) 5 | V1.2 - 24 Apr 1996 6 | 7 | 8 | 9 | NAME 10 | http - perform HTTP queries from command line 11 | 12 | 13 | SYNOPSIS 14 | http 15 | 16 | 17 | DESCRIPTION 18 | http is a tool to perform HTTP queries from the command line. 19 | Informations and diagnostic goes to stderr. Data is taken from stdin 20 | (for put) or output to stdout (for get). If the environement variable 21 | http_proxy exists it will be used as a proxy url. 22 | 23 | The following commands are supported 24 | 25 | get to send an http GET query. It fetches the given url to standard 26 | output. 27 | 28 | head gets the header only of the url. 29 | 30 | put to send an http PUT query (not recognized by all servers). It 31 | reads data from standard input and then send them to the server. 32 | 33 | delete 34 | to send an http DELETE query (not recognized by all servers). 35 | 36 | 37 | LIMITATIONS 38 | The url is limited to 256 characters. 39 | 40 | 41 | EXAMPLE 42 | http get http://www.demailly.com/~dl/wwwtools.html > wwwtools.html 43 | 44 | 45 | AUTHOR 46 | Laurent Demailly . Free software. 47 | (See LICENSE file) 48 | 49 | 50 | SEE ALSO 51 | http_lib(3) 52 | 53 | 54 | 55 | 56 | 57 | 58 | - 1 - Formatted: April 24, 1996 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /http.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Http put/get/post standalone program using Http put mini lib 3 | * written by L. Demailly 4 | * (c) 2013 Anibal Limon - limon.anibal@gmail.com 5 | * (c) 1998 Laurent Demailly - http://www.demailly.com/~dl/ 6 | * (c) 1996 Observatoire de Paris - Meudon - France 7 | * see LICENSE for terms, conditions and DISCLAIMER OF ALL WARRANTIES 8 | * 9 | * $Id: http.c,v 1.4 1998/09/23 06:11:55 dl Exp $ 10 | * 11 | * $Log: http.c,v $ 12 | * 13 | * Revision 1.5.x 2013/08/07 08:30:42 -0500 14 | * Removed no used code for OS9, and code functions to access global 15 | * variables now static instead extern. 16 | * Author: alimon 17 | * 18 | * Revisionq 1.5.x 2013/08/07 00:20:42 -0500 19 | * Added support for POST 20 | * Author: alimon 21 | * 22 | * Revision 1.4 1998/09/23 06:11:55 dl 23 | * one more lint 24 | * 25 | * Revision 1.3 1998/09/23 06:03:45 dl 26 | * proxy support (old change which was not checked in back in 96) 27 | * contact, etc.. infos update 28 | * 29 | * Revision 1.2 1996/04/18 13:52:14 dl 30 | * strings.h->string.h 31 | * 32 | * Revision 1.1 1996/04/18 12:17:25 dl 33 | * Initial revision 34 | * 35 | */ 36 | 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "http_lib.h" 46 | 47 | int main(int argc,char* argv[]) 48 | { 49 | int ret,lg,blocksize,r,i; 50 | char typebuf[70]; 51 | char *data=NULL,*filename=NULL,*proxy=NULL; 52 | int data_len = 0; 53 | char *type = NULL; 54 | enum { 55 | ERR, 56 | DOPUT, 57 | DOGET, 58 | DODEL, 59 | DOHEA, 60 | DOPOST 61 | } todo=ERR; 62 | 63 | if (argc!=3) { 64 | fprintf(stderr,"usage: http \n\tby \n"); 65 | return 1; 66 | } 67 | 68 | i=1; 69 | 70 | if (!strcasecmp(argv[i],"put")) { 71 | todo=DOPUT; 72 | } else if (!strcasecmp(argv[i],"get")) { 73 | todo=DOGET; 74 | } else if (!strcasecmp(argv[i],"delete")) { 75 | todo=DODEL; 76 | } else if (!strcasecmp(argv[i],"head")) { 77 | todo=DOHEA; 78 | } else if (!strcasecmp(argv[i],"post")) { 79 | todo=DOPOST; 80 | } 81 | 82 | if (todo==ERR) { 83 | fprintf(stderr, 84 | "Invalid '%s',\nmust be " 85 | "'put', 'get', 'post', 'delete', or 'head'\n", 86 | argv[i] 87 | ); 88 | return 2; 89 | } 90 | 91 | i++; 92 | 93 | if ((proxy=getenv("http_proxy"))) { 94 | ret=http_proxy_url(proxy); 95 | if (ret<0) { 96 | return ret; 97 | } 98 | } 99 | 100 | ret=http_parse_url(argv[i],&filename); 101 | if (ret<0) { 102 | return ret; 103 | } 104 | 105 | switch (todo) { 106 | /* *** PUT *** */ 107 | case DOPUT: 108 | fprintf(stderr,"reading stdin...\n"); 109 | /* read stdin into memory */ 110 | blocksize=16384; 111 | lg=0; 112 | 113 | if (!(data=malloc(blocksize))) { 114 | return 3; 115 | } 116 | 117 | while (1) { 118 | r=read(0,data+lg,blocksize-lg); 119 | if (r<=0) break; 120 | lg+=r; 121 | if ((3*lg/2)>blocksize) { 122 | blocksize *= 4; 123 | fprintf(stderr, 124 | "read to date: %9d bytes, reallocating buffer to %9d\n", 125 | lg,blocksize); 126 | if (!(data=realloc(data,blocksize))) { 127 | return 4; 128 | } 129 | } 130 | } 131 | 132 | fprintf(stderr,"read %d bytes\n",lg); 133 | ret=http_put(filename,data,lg,0,NULL); 134 | fprintf(stderr,"res=%d\n",ret); 135 | break; 136 | /* *** GET *** */ 137 | case DOGET: 138 | ret=http_get(filename,&data,&lg,typebuf); 139 | fprintf(stderr,"res=%d,type='%s',lg=%d\n",ret,typebuf,lg); 140 | fwrite(data,lg,1,stdout); 141 | fprintf(stderr, "%s\n", data); 142 | break; 143 | /* *** HEAD *** */ 144 | case DOHEA: 145 | ret=http_head(filename,&lg,typebuf); 146 | fprintf(stderr,"res=%d,type='%s',lg=%d\n",ret,typebuf,lg); 147 | break; 148 | /* *** DELETE *** */ 149 | case DODEL: 150 | ret=http_delete(filename); 151 | fprintf(stderr,"res=%d\n",ret); 152 | break; 153 | case DOPOST: 154 | ret = http_post(filename, "your_name=1", 11, NULL, &data, &data_len, &type); 155 | fprintf(stderr,"res=%d\n",ret); 156 | fprintf(stderr,"%s\n", type); 157 | fprintf(stderr,"data: %s\n", data); 158 | break; 159 | /* impossible... */ 160 | default: 161 | fprintf(stderr,"impossible todo value=%d\n",todo); 162 | return 5; 163 | } 164 | 165 | if (type) { 166 | free(type); 167 | } 168 | 169 | if (data) { 170 | free(data); 171 | } 172 | 173 | free(filename); 174 | 175 | return ( (ret==201) || (ret==200) ) ? 0 : ret; 176 | } 177 | -------------------------------------------------------------------------------- /http.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | http(1) manual page 4 | 5 | 6 |

NAME

7 | 8 | http - perform HTTP queries from command line 9 |

10 | 11 |

SYNOPSIS

12 | 13 | http <get|head|put|delete> <url> 14 |

15 | 16 |

DESCRIPTION

17 | 18 | http is a tool to perform HTTP queries from the command line. 19 | Informations and diagnostic goes to stderr. Data is taken from stdin 20 | (for put) or output to stdout (for get). 21 | If the environement variable http_proxy exists it will be used as a 22 | proxy url. 23 |

24 | The following commands are supported 25 |

26 | get to send an http GET query. It fetches the given url to standard 27 | output. 28 |

29 | head gets the header only of the url. 30 |

31 | put to send an http PUT query (not recognized by all servers). It 32 | reads data from standard input and then send them to the server. 33 |

34 | delete
35 | 36 | to send an http DELETE query (not recognized by all servers). 37 |

38 | 39 |

LIMITATIONS

40 | 41 | The url is limited to 256 characters. 42 |

43 | 44 |

EXAMPLE

45 | 46 | http get http://www.demailly.com/~dl/wwwtools.html > wwwtools.html 47 |

48 | 49 |

AUTHOR

50 | 51 | Laurent Demailly 52 | <L@Demailly.com>. Free software. 53 |
54 | (See LICENSE file) 55 |

56 | 57 |

SEE ALSO

58 | 59 | http_lib(3) 60 |

61 | 62 | -------------------------------------------------------------------------------- /http_lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Http put/get/post mini lib 3 | * written by L. Demailly 4 | * (c) 2013 Anibal Limon - limon.anibal@gmail.com 5 | * (c) 1998 Laurent Demailly - http://www.demailly.com/~dl/ 6 | * (c) 1996 Observatoire de Paris - Meudon - France 7 | * see LICENSE for terms, conditions and DISCLAIMER OF ALL WARRANTIES 8 | * 9 | * $Id: http_lib.c,v 3.5 1998/09/23 06:19:15 dl Exp $ 10 | * 11 | * Description : Use http protocol, connects to server to echange data 12 | * 13 | * Revision 4.1 2013/10/13 14:15:00 -0500 14 | * Added function pointer for custom buffer EOF reader. 15 | * Author: alimon 16 | * 17 | * Revision 4.0 2013/10/13 13:15:00 -0500 18 | * Added functions for multi-thread support httpmt_. 19 | * Author: alimon 20 | * 21 | * Revision 3.6.x 2013/08/23 20:41:42 -0500 22 | * Added support for read Content without length in GET/POST. 23 | * Author: alimon 24 | * 25 | * Revision 3.6.x 2013/08/07 21:41:42 -0500 26 | * Added Basic auth support, base64 encoding is provided for external 27 | * function trought http_set_base64_encoder. 28 | * Author: alimon 29 | * 30 | * Revision 3.6.x 2013/08/07 08:30:42 -0500 31 | * Removed no used code for OS9, and code functions to access global 32 | * variables now static instead extern. 33 | * Author: alimon 34 | * 35 | * Revisionq 3.6.x 2013/08/07 00:20:42 -0500 36 | * Added support for POST 37 | * Author: alimon 38 | * 39 | * $Log: http_lib.c,v $ 40 | * Revision 3.5 1998/09/23 06:19:15 dl 41 | * portability and http 1.x (1.1 and later) compatibility 42 | * 43 | * Revision 3.4 1998/09/23 05:44:27 dl 44 | * added support for HTTP/1.x answers 45 | * 46 | * Revision 3.3 1996/04/25 19:07:22 dl 47 | * using intermediate variable for htons (port) so it does not yell 48 | * on freebsd (thx pp for report) 49 | * 50 | * Revision 3.2 1996/04/24 13:56:08 dl 51 | * added proxy support through http_proxy_server & http_proxy_port 52 | * some httpd *needs* cr+lf so provide them 53 | * simplification + cleanup 54 | * 55 | * Revision 3.1 1996/04/18 13:53:13 dl 56 | * http-tiny release 1.0 57 | * 58 | * 59 | */ 60 | 61 | #ifdef _bsd 62 | static char *rcsid="$Id: http_lib.c,v 3.5 1998/09/23 06:19:15 dl Exp $"; 63 | #endif 64 | 65 | /* http_lib - Http data exchanges mini library. 66 | */ 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | 80 | #include "http_lib.h" 81 | 82 | #define SERVER_DEFAULT "adonis" 83 | /* beware that filename+type+rest of header must not exceed MAXBUF */ 84 | /* so we limit filename to 256 and type to 64 chars in put & get */ 85 | #define MAXBUF 512 86 | 87 | typedef enum 88 | { 89 | CLOSE, /* Close the socket after the query (for put) */ 90 | KEEP_OPEN /* Keep it open */ 91 | } querymode; 92 | 93 | static http_retcode http_query(http_ctx *ctx, char *command, char *url, 94 | char *additional_header, querymode mode, 95 | char *data, int length, int *pfd); 96 | static int http_read_line(int fd, char *buffer, int max); 97 | static int http_read_buffer(int fd, char *buffer, int max); 98 | static int http_read_buffer_eof(int fd, char **buffer, int *length); 99 | 100 | /* user agent id string */ 101 | static char *http_user_agent="adlib/3 ($Date: 1998/09/23 06:19:15 $)"; 102 | 103 | static http_ctx _ctx = { 104 | .server = NULL, 105 | .port = 5757, 106 | .proxy_server = NULL, 107 | .proxy_port = 0, 108 | 109 | .b64_enc = NULL, 110 | .b64_auth = NULL, 111 | 112 | .reader = NULL 113 | }; 114 | 115 | /* parses an url : setting the http_server and http_port global variables 116 | * and returning the filename to pass to http_get/put/... 117 | * returns a negative error code or 0 if sucessfully parsed. 118 | * writeable copy of an url 119 | * char *url; 120 | * address of a pointer that will be filled with allocated filename 121 | * the pointer must be equal to NULL before calling or it will be 122 | * automatically freed (free(3)) 123 | * char **pfilename; 124 | */ 125 | extern http_retcode 126 | http_parse_url(char *url, char **pfilename) 127 | { 128 | return httpmt_parse_url(&_ctx, url, pfilename); 129 | } 130 | 131 | extern http_retcode 132 | httpmt_parse_url(http_ctx *ctx, char *url, char **pfilename) 133 | { 134 | char *pc, c; 135 | 136 | if (ctx == NULL) 137 | return ERRNULL; 138 | 139 | ctx->port = 80; 140 | if (ctx->server) { 141 | free(ctx->server); 142 | ctx->server = NULL; 143 | } 144 | if (*pfilename) { 145 | free(*pfilename); 146 | *pfilename = NULL; 147 | } 148 | 149 | if (strncasecmp("http://", url, 7)) { 150 | #ifdef _DEBUG 151 | fprintf(stderr,"invalid url (must start with 'http://')\n"); 152 | #endif 153 | return ERRURLH; 154 | } 155 | 156 | url += 7; 157 | for (pc = url, c = *pc; (c && c != ':' && c != '/');) 158 | c = *pc++; 159 | *(pc - 1) = 0; 160 | 161 | if (c == ':') { 162 | if (sscanf(pc, "%d", &ctx->port) != 1) { 163 | #ifdef _DEBUG 164 | fprintf(stderr,"invalid port in url\n"); 165 | #endif 166 | return ERRURLP; 167 | } 168 | 169 | for (pc++; (*pc && *pc != '/'); pc++); 170 | if (*pc) pc++; 171 | } 172 | 173 | ctx->server = strdup(url); 174 | if (ctx->server == NULL) 175 | return ERRMEM; 176 | 177 | *pfilename = strdup(c ? pc : ""); 178 | if (*pfilename == NULL) { 179 | free(ctx->server); 180 | ctx->server = NULL; 181 | return ERRMEM; 182 | } 183 | 184 | #ifdef _DEBUG 185 | fprintf(stderr,"host=(%s), port=%d, filename=(%s)\n", 186 | ctx->server, ctx->port, *pfilename); 187 | #endif 188 | return OK0; 189 | } 190 | 191 | /* 192 | * sets proxy to use 193 | */ 194 | extern http_retcode 195 | http_proxy_url(char *proxy) 196 | { 197 | return httpmt_proxy_url(&_ctx, proxy); 198 | } 199 | 200 | extern http_retcode 201 | httpmt_proxy_url(http_ctx *ctx, char *proxy) 202 | { 203 | http_retcode r = OK0; 204 | char *filename = NULL; 205 | 206 | if (ctx == NULL) 207 | return ERRNULL; 208 | 209 | r = httpmt_parse_url(ctx, proxy, &filename); 210 | if (r < 0) 211 | return r; 212 | 213 | if (ctx->proxy_server) { 214 | free(ctx->proxy_server); 215 | ctx->proxy_server = NULL; 216 | } 217 | 218 | ctx->proxy_server = ctx->server; 219 | ctx->server = NULL; 220 | ctx->proxy_port = ctx->port; 221 | 222 | free(filename); 223 | 224 | return r; 225 | } 226 | 227 | /* 228 | * Put data on the server 229 | * 230 | * This function sends data to the http data server. 231 | * The data will be stored under the ressource name filename. 232 | * returns a negative error code or a positive code from the server 233 | * 234 | * limitations: filename is truncated to first 256 characters 235 | * and type to 64. 236 | * char *filename name of the ressource to create 237 | * char *data pointer to the data to send 238 | * int length length of the data to send 239 | * int overwrite flag to request to overwrite the ressource if it 240 | * was already existing 241 | * char *type type of the data, if NULL default type is used 242 | */ 243 | extern http_retcode 244 | http_put(char *filename, char *data, int length, int overwrite, char *type) 245 | { 246 | return httpmt_put(&_ctx, filename, data, length, overwrite, type); 247 | } 248 | 249 | extern http_retcode 250 | httpmt_put(http_ctx *ctx, char *filename, char *data, int length, int overwrite, char *type) 251 | { 252 | char header[MAXBUF]; 253 | 254 | if (ctx == NULL) 255 | return ERRNULL; 256 | 257 | if (type) 258 | sprintf(header,"Content-length: %d\015\012Content-type: %.64s\015\012%s", 259 | length, 260 | type , 261 | overwrite ? "Control: overwrite=1\015\012" : "" 262 | ); 263 | else 264 | sprintf(header,"Content-length: %d\015\012%s",length, 265 | overwrite ? "Control: overwrite=1\015\012" : "" 266 | ); 267 | 268 | return http_query(ctx, "PUT", filename, header, CLOSE, data, length, NULL); 269 | } 270 | 271 | /* 272 | * Get data from the server 273 | * 274 | * This function gets data from the http data server. 275 | * The data is read from the ressource named filename. 276 | * Address of new new allocated memory block is filled in pdata 277 | * whose length is returned via plength. 278 | * 279 | * returns a negative error code or a positive code from the server 280 | * 281 | * char *filename name of the ressource to read 282 | * char **pdata address of a pointer variable which will be set 283 | * to point toward allocated memory containing read data. 284 | * int *plength address of integer variable which will be set to 285 | * length of the cead data 286 | * char *typebuf allocated buffer where the read data type is returned. 287 | * If NULL, the type is not returned 288 | * 289 | * 290 | * limitations: filename is truncated to first 256 characters 291 | */ 292 | extern http_retcode 293 | http_get(char *filename, char **pdata, int *plength, char *typebuf) 294 | { 295 | return httpmt_get(&_ctx, filename, pdata, plength, typebuf); 296 | } 297 | 298 | extern http_retcode 299 | httpmt_get(http_ctx *ctx, char *filename, char **pdata, int *plength, char *typebuf) 300 | { 301 | http_retcode ret; 302 | 303 | char header[MAXBUF]; 304 | char *pc; 305 | int fd; 306 | int n, length = -1; 307 | 308 | if (ctx == NULL) 309 | return ERRNULL; 310 | 311 | if (!pdata) 312 | return ERRNULL; 313 | else 314 | *pdata = NULL; 315 | 316 | if (plength) *plength = 0; 317 | if (typebuf) *typebuf = '\0'; 318 | 319 | ret = http_query(ctx, "GET", filename, "", KEEP_OPEN, NULL, 0, &fd); 320 | if (ret == OK200) { 321 | while (1) { 322 | n = http_read_line(fd, header , MAXBUF - 1); 323 | #ifdef _DEBUG 324 | fputs(header, stderr); 325 | putc('\n', stderr); 326 | #endif 327 | if (n <= 0) { 328 | close(fd); 329 | return ERRRDHD; 330 | } 331 | /* empty line ? (=> end of header) */ 332 | if (n > 0 && (*header) == '\0') break; 333 | /* try to parse some keywords : */ 334 | /* convert to lower case 'till a : is found or end of string */ 335 | for (pc = header; (*pc != ':' && *pc); pc++) 336 | *pc = tolower(*pc); 337 | sscanf(header, "content-length: %d", &length); 338 | if (typebuf) 339 | sscanf(header, "content-type: %s", typebuf); 340 | } 341 | 342 | if (length <= 0) { 343 | if (ctx->reader) { 344 | (*ctx->reader)(fd); 345 | } else { 346 | if (http_read_buffer_eof(fd, pdata, plength) == -1) 347 | ret = ERRNOLG; 348 | } 349 | close(fd); 350 | } else { 351 | *plength = length; 352 | if (!(*pdata = malloc(length))) { 353 | close(fd); 354 | return ERRMEM; 355 | } 356 | n = http_read_buffer(fd, *pdata, length); 357 | close(fd); 358 | if (n != length) 359 | ret = ERRRDDT; 360 | } 361 | } else if (ret >= OK0) { 362 | close(fd); 363 | } 364 | 365 | return ret; 366 | } 367 | 368 | /* 369 | * Request the header 370 | * 371 | * This function outputs the header of thehttp data server. 372 | * The header is from the ressource named filename. 373 | * The length and type of data is eventually returned (like for http_get(3)) 374 | * 375 | * returns a negative error code or a positive code from the server 376 | * 377 | * char *filename name of the ressource to read 378 | * int *plength address of integer variable which will be set to 379 | * length of the data 380 | * char *typebuf allocated buffer where the data type is returned. 381 | * If NULL, the type is not returned 382 | * limitations: filename is truncated to first 256 characters 383 | */ 384 | extern http_retcode 385 | http_head(char *filename, int *plength, char *typebuf) 386 | { 387 | return httpmt_head(&_ctx, filename, plength, typebuf); 388 | } 389 | 390 | extern http_retcode 391 | httpmt_head(http_ctx *ctx, char *filename, int *plength, char *typebuf) 392 | { 393 | /* mostly copied from http_get : */ 394 | http_retcode ret; 395 | 396 | char header[MAXBUF]; 397 | char *pc; 398 | int fd; 399 | int n, length=-1; 400 | 401 | if (ctx == NULL) 402 | return ERRNULL; 403 | 404 | if (plength) 405 | *plength = 0; 406 | if (typebuf) 407 | *typebuf = '\0'; 408 | 409 | ret = http_query(ctx, "HEAD", filename, "", KEEP_OPEN, NULL, 0, &fd); 410 | 411 | if (ret == OK200) { 412 | while (1) { 413 | n = http_read_line(fd, header, MAXBUF - 1); 414 | #ifdef _DEBUG 415 | fputs(header, stderr); 416 | putc('\n', stderr); 417 | #endif 418 | if (n <= 0) { 419 | close(fd); 420 | return ERRRDHD; 421 | } 422 | /* empty line ? (=> end of header) */ 423 | if (n > 0 && (*header) == '\0') 424 | break; 425 | /* try to parse some keywords : */ 426 | /* convert to lower case 'till a : is found or end of string */ 427 | for (pc = header; (*pc != ':' && *pc); pc++) 428 | *pc = tolower(*pc); 429 | sscanf(header, "content-length: %d", &length); 430 | if (typebuf) 431 | sscanf(header, "content-type: %s", typebuf); 432 | } 433 | if (plength) 434 | *plength = length; 435 | close(fd); 436 | } else if (ret >= OK0) { 437 | close(fd); 438 | } 439 | 440 | return ret; 441 | } 442 | 443 | /* 444 | * Delete data on the server 445 | * 446 | * This function request a DELETE on the http data server. 447 | * 448 | * returns a negative error code or a positive code from the server 449 | * 450 | * char *filename name of the ressource to create 451 | * limitations: filename is truncated to first 256 characters 452 | */ 453 | extern http_retcode 454 | http_delete(char *filename) 455 | { 456 | return httpmt_delete(&_ctx, filename); 457 | } 458 | 459 | extern http_retcode 460 | httpmt_delete(http_ctx *ctx, char *filename) 461 | { 462 | if (ctx == NULL) 463 | return ERRNULL; 464 | else 465 | return http_query(ctx, "DELETE", filename, "", CLOSE, NULL, 0, NULL); 466 | } 467 | 468 | /* 469 | * post data 470 | */ 471 | extern http_retcode 472 | http_post(char *filename, char *data, int length, char *type, char **pdata, 473 | int *plength, char **ptype) 474 | { 475 | return httpmt_post(&_ctx, filename, data, length, type, pdata, plength, 476 | ptype); 477 | } 478 | 479 | extern http_retcode 480 | httpmt_post(http_ctx *ctx, char *filename, char *data, int length, char *type, 481 | char **pdata, int *plength, char **ptype) 482 | { 483 | int fd; 484 | char *pc; 485 | int n; 486 | char header[MAXBUF]; 487 | char typebuf[MAXBUF]; 488 | http_retcode ret; 489 | 490 | if (ctx == NULL) 491 | return ERRNULL; 492 | 493 | if (data == NULL || length <= 0 || pdata == NULL || plength == NULL) 494 | return ERRNULL; 495 | 496 | *pdata = NULL; 497 | *plength = 0; 498 | 499 | header[0] = '\0'; 500 | typebuf[0] = '\0'; 501 | 502 | if (type) 503 | sprintf(header, "Content-length: %d\015\012Content-type: %.64s\015\012", 504 | length, type); 505 | else 506 | sprintf(header, "Content-length: %d\015\012", length); 507 | 508 | ret = http_query(ctx, "POST", filename, header, KEEP_OPEN, data, length, &fd); 509 | 510 | if (ret==OK200) { 511 | while (1) { 512 | n = http_read_line(fd, header, MAXBUF - 1); 513 | #ifdef _DEBUG 514 | fputs(header, stderr); 515 | putc('\n', stderr); 516 | #endif 517 | if (n <= 0) { 518 | close(fd); 519 | return ERRRDHD; 520 | } 521 | 522 | /* empty line ? (=> end of header) */ 523 | if (n > 0 && (*header) =='\0') 524 | break; 525 | 526 | /* try to parse some keywords : */ 527 | /* convert to lower case 'till a : is found or end of string */ 528 | for (pc = header; (*pc != ':' && *pc); pc++) 529 | *pc = tolower(*pc); 530 | sscanf(header, "content-length: %d", plength); 531 | sscanf(header, "content-type: %s", typebuf); 532 | } 533 | 534 | if (ptype) 535 | *ptype = strdup(typebuf); 536 | 537 | if (*plength <= 0) { 538 | if (ctx->reader) { 539 | (*ctx->reader)(fd); 540 | } else { 541 | if (http_read_buffer_eof(fd, pdata, plength) == -1) { 542 | ret = ERRNOLG; 543 | if (ptype) { 544 | free(*ptype); 545 | *ptype = NULL; 546 | } 547 | } 548 | } 549 | 550 | close(fd); 551 | } else { 552 | if (!(*pdata = malloc(*plength))) { 553 | close(fd); 554 | if (ptype) { 555 | free(*ptype); 556 | *ptype = NULL; 557 | } 558 | return ERRMEM; 559 | } 560 | 561 | n = http_read_buffer(fd, *pdata, *plength); 562 | close(fd); 563 | 564 | if (n != *plength) { 565 | free(*pdata); 566 | *pdata = NULL; 567 | if (ptype) { 568 | free(*ptype); 569 | *ptype = NULL; 570 | } 571 | ret = ERRRDDT; 572 | } 573 | } 574 | } else if (ret >= OK0) { 575 | close(fd); 576 | } 577 | 578 | return ret; 579 | } 580 | 581 | /** 582 | * set external base64 encoder for basic auth 583 | */ 584 | extern void 585 | http_set_base64_encoder(http_base64_encoder enc) 586 | { 587 | httpmt_set_base64_encoder(&_ctx, enc); 588 | } 589 | 590 | extern void 591 | httpmt_set_base64_encoder(http_ctx *ctx, http_base64_encoder enc) 592 | { 593 | if (ctx != NULL) 594 | ctx->b64_enc = enc; 595 | } 596 | 597 | /** 598 | * set basic auth for use in all requests, calls external 599 | * base64 encoder 600 | */ 601 | extern http_retcode 602 | http_set_basic_auth(char *user, char *pass) 603 | { 604 | return httpmt_set_basic_auth(&_ctx, user, pass); 605 | } 606 | 607 | extern http_retcode 608 | httpmt_set_basic_auth(http_ctx *ctx, char *user, char *pass) 609 | { 610 | http_retcode r = OK0; 611 | char userpass[MAXBUF]; 612 | char *b64; 613 | 614 | if (ctx == NULL) 615 | return ERRNULL; 616 | 617 | if (ctx->b64_enc == NULL || user == NULL || pass == NULL) 618 | return ERRNULL; 619 | 620 | snprintf(userpass, MAXBUF, "%s:%s", user, pass); 621 | if ((*ctx->b64_enc)(userpass, &b64) == -1) 622 | return ERRMEM; 623 | 624 | if (ctx->b64_auth) 625 | free(ctx->b64_auth); 626 | 627 | ctx->b64_auth = b64; 628 | 629 | return r; 630 | } 631 | /** 632 | * set custom buffer reader 633 | */ 634 | extern void 635 | http_set_buffer_eof_reader(http_buffer_eof_reader reader) 636 | { 637 | return httpmt_set_buffer_eof_reader(&_ctx, reader); 638 | } 639 | 640 | extern void 641 | httpmt_set_buffer_eof_reader(http_ctx *ctx, http_buffer_eof_reader reader) 642 | { 643 | if (ctx != NULL) 644 | ctx->reader = reader; 645 | } 646 | 647 | /* 648 | * Pseudo general http query 649 | * 650 | * send a command and additional headers to the http server. 651 | * optionally through the proxy (if http_proxy_server and http_proxy_port are 652 | * set). 653 | * 654 | * Limitations: the url is truncated to first 256 chars and 655 | * the server name to 128 in case of proxy request. 656 | * 657 | * char *command Command to send 658 | * char *url; url / filename queried 659 | * char *additional_header Additional header 660 | * querymode mode; Type of query 661 | * char *data Data to send after header. 662 | * If NULL, not data is sent 663 | * int length size of data 664 | * int *pfd pointer to variable where to 665 | * set file descriptor value 666 | */ 667 | static http_retcode 668 | http_query(http_ctx *ctx, char *command, char *url, char *additional_header, 669 | querymode mode, char *data, int length, int *pfd) 670 | { 671 | int s; 672 | struct hostent *hp; 673 | struct sockaddr_in server; 674 | char header[MAXBUF]; 675 | int hlg; 676 | http_retcode ret; 677 | int proxy; 678 | int port; 679 | 680 | proxy = (ctx->proxy_server != NULL && ctx->proxy_port != 0); 681 | port = proxy ? ctx->proxy_port : ctx->port; 682 | 683 | if (pfd) *pfd=-1; 684 | 685 | /* get host info by name :*/ 686 | if ((hp = gethostbyname( proxy ? ctx->proxy_server 687 | : (ctx->server ? ctx->server : SERVER_DEFAULT)))) { 688 | memset((char *) &server,0, sizeof(server)); 689 | memmove((char *) &server.sin_addr, hp->h_addr, hp->h_length); 690 | server.sin_family = hp->h_addrtype; 691 | server.sin_port = (unsigned short) htons( port ); 692 | } else { 693 | return ERRHOST; 694 | } 695 | 696 | /* create socket */ 697 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) 698 | return ERRSOCK; 699 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0); 700 | 701 | /* connect to server */ 702 | if (connect(s, (const struct sockaddr *) &server, sizeof(server)) < 0) { 703 | ret = ERRCONN; 704 | } else { 705 | if (pfd) *pfd = s; 706 | 707 | /* create header */ 708 | if (proxy) { 709 | if (ctx->b64_auth) { 710 | sprintf(header, 711 | "%s http://%.128s:%d/%.256s HTTP/1.0\015\012User-Agent: %s\015\012" 712 | "Authorization: Basic %s\015\012%s\015\012", 713 | command, 714 | ctx->server, 715 | ctx->port, 716 | url, 717 | http_user_agent, 718 | ctx->b64_auth, 719 | additional_header 720 | ); 721 | } else { 722 | sprintf(header, 723 | "%s http://%.128s:%d/%.256s HTTP/1.0\015\012" 724 | "User-Agent: %s\015\012%s\015\012", 725 | command, 726 | ctx->server, 727 | ctx->port, 728 | url, 729 | http_user_agent, 730 | additional_header 731 | ); 732 | } 733 | } else { 734 | if (ctx->b64_auth) { 735 | sprintf(header, 736 | "%s /%.256s HTTP/1.0\015\012User-Agent: %s\015\012" 737 | "Authorization: Basic %s\015\012%s\015\012", 738 | command, 739 | url, 740 | http_user_agent, 741 | ctx->b64_auth, 742 | additional_header 743 | ); 744 | } else { 745 | sprintf(header, 746 | "%s /%.256s HTTP/1.0\015\012User-Agent: %s\015\012%s\015\012", 747 | command, 748 | url, 749 | http_user_agent, 750 | additional_header 751 | ); 752 | } 753 | } 754 | 755 | hlg = strlen(header); 756 | 757 | #ifdef _DEBUG 758 | fputs(header, stderr); 759 | putc('\n', stderr); 760 | #endif 761 | 762 | /* send header */ 763 | if (write(s, header, hlg) != hlg) { 764 | ret = ERRWRHD; 765 | /* send data */ 766 | } else if (length && data && (write(s, data, length) != length)) { 767 | ret = ERRWRDT; 768 | } else { 769 | /* read result & check */ 770 | ret = http_read_line(s, header, MAXBUF - 1); 771 | 772 | if (ret <= 0) 773 | ret = ERRRDHD; 774 | else if (sscanf(header, "HTTP/1.%*d %03d", (int*)&ret) != 1) 775 | ret = ERRPAHD; 776 | else if (mode == KEEP_OPEN) 777 | return ret; 778 | } 779 | } 780 | 781 | /* close socket */ 782 | close(s); 783 | return ret; 784 | } 785 | 786 | /* 787 | * read a line from file descriptor 788 | * returns the number of bytes read. negative if a read error occured 789 | * before the end of line or the max. 790 | * cariage returns (CR) are ignored. 791 | * int fd File descriptor to read from 792 | * char *buffer Placeholder for data 793 | * int max Max number of bytes to read 794 | */ 795 | static int http_read_line (int fd, char *buffer, int max) 796 | { 797 | /* not efficient on long lines (multiple unbuffered 1 char reads) */ 798 | int n=0; 799 | while (n= size) { 865 | size += page_size; 866 | data = realloc(*pbuffer, size); 867 | if (data == NULL) { 868 | r = -1; 869 | free(*pbuffer); 870 | *plength = 0; 871 | break; 872 | } else { 873 | *pbuffer = data; 874 | } 875 | } 876 | 877 | to_read = -1 * ((*plength % page_size) - page_size); 878 | r = read(fd, *pbuffer + *plength, to_read); 879 | 880 | if (r == -1) { 881 | if (errno == ECONNRESET) { 882 | r = 0; 883 | } else { 884 | free(*pbuffer); 885 | *plength = 0; 886 | } 887 | break; 888 | } else if (r == 0) { 889 | break; 890 | } else { 891 | *plength += r; 892 | } 893 | } while (1); 894 | 895 | return r; 896 | } 897 | -------------------------------------------------------------------------------- /http_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Http put/get/post mini lib 3 | * written by L. Demailly 4 | * (c) 2013 Anibal Limon - limon.anibal@gmail.com 5 | * (c) 1998 Laurent Demailly - http://www.demailly.com/~dl/ 6 | * (c) 1996 Observatoire de Paris - Meudon - France 7 | * see LICENSE for terms, conditions and DISCLAIMER OF ALL WARRANTIES 8 | * 9 | * $Id: http_lib.h,v 1.4 1998/09/23 06:14:15 dl Exp $ 10 | * 11 | */ 12 | 13 | /* declarations */ 14 | typedef int (*http_base64_encoder)(const char *in, char **out); 15 | 16 | /* custom function to read buffer eof */ 17 | typedef void (*http_buffer_eof_reader)(int fd); 18 | 19 | /* return type */ 20 | typedef enum { 21 | 22 | /* Client side errors */ 23 | ERRHOST=-1, /* No such host */ 24 | ERRSOCK=-2, /* Can't create socket */ 25 | ERRCONN=-3, /* Can't connect to host */ 26 | ERRWRHD=-4, /* Write error on socket while writing header */ 27 | ERRWRDT=-5, /* Write error on socket while writing data */ 28 | ERRRDHD=-6, /* Read error on socket while reading result */ 29 | ERRPAHD=-7, /* Invalid answer from data server */ 30 | ERRNULL=-8, /* Null data pointer */ 31 | ERRNOLG=-9, /* No/Bad length in header */ 32 | ERRMEM=-10, /* Can't allocate memory */ 33 | ERRRDDT=-11,/* Read error while reading data */ 34 | ERRURLH=-12,/* Invalid url - must start with 'http://' */ 35 | ERRURLP=-13,/* Invalid port in url */ 36 | 37 | 38 | /* Return code by the server */ 39 | ERR400=400, /* Invalid query */ 40 | ERR403=403, /* Forbidden */ 41 | ERR408=408, /* Request timeout */ 42 | ERR500=500, /* Server error */ 43 | ERR501=501, /* Not implemented */ 44 | ERR503=503, /* Service overloaded */ 45 | 46 | /* Succesful results */ 47 | OK0 = 0, /* successfull parse */ 48 | OK201=201, /* Ressource succesfully created */ 49 | OK200=200 /* Ressource succesfully read */ 50 | 51 | } http_retcode; 52 | 53 | /* CTX */ 54 | typedef struct _http_ctx { 55 | char *server; 56 | int port; 57 | char *proxy_server; 58 | int proxy_port; 59 | 60 | http_base64_encoder b64_enc; 61 | char *b64_auth; 62 | 63 | http_buffer_eof_reader reader; 64 | } http_ctx; 65 | 66 | /* Functions */ 67 | extern http_retcode http_parse_url(char *url, char **pfilename); 68 | extern http_retcode http_proxy_url(char *url); 69 | extern http_retcode http_put(char *filename, char *data, int length, 70 | int overwrite, char *type); 71 | extern http_retcode http_get(char *filename, char **pdata,int *plength, 72 | char *typebuf); 73 | extern http_retcode http_delete(char *filename); 74 | extern http_retcode http_head(char *filename, int *plength, char *typebuf); 75 | extern http_retcode http_post(char *filename, char *data, int length, 76 | char *type, char **pdata, int *plength, char **ptype); 77 | extern void http_set_base64_encoder(http_base64_encoder enc); 78 | extern http_retcode http_set_basic_auth(char *user, char *pass); 79 | extern void http_set_buffer_eof_reader(http_buffer_eof_reader reader); 80 | 81 | /* Multi-thread functions */ 82 | extern http_retcode httpmt_parse_url(http_ctx *ctx, char *url, char **pfilename); 83 | extern http_retcode httpmt_proxy_url(http_ctx *ctx, char *url); 84 | extern http_retcode httpmt_put(http_ctx *ctx, char *filename, char *data, int length, 85 | int overwrite, char *type); 86 | extern http_retcode httpmt_get(http_ctx *ctx, char *filename, char **pdata, 87 | int *plength, char *typebuf); 88 | extern http_retcode httpmt_delete(http_ctx *ctx, char *filename); 89 | extern http_retcode httpmt_head(http_ctx *ctx, char *filename, int *plength, 90 | char *typebuf); 91 | extern http_retcode httpmt_post(http_ctx *ctx, char *filename, char *data, int length, 92 | char *type, char **pdata, int *plength, char **ptype); 93 | extern void httpmt_set_base64_encoder(http_ctx *ctx, http_base64_encoder enc); 94 | extern http_retcode httpmt_set_basic_auth(http_ctx *ctx, char *user, char *pass); 95 | extern void httpmt_set_buffer_eof_reader(http_ctx *ctx, http_buffer_eof_reader reader); 96 | -------------------------------------------------------------------------------- /http_lib.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | http_lib(3) manual page 4 | 5 | 6 | Table of Contents

7 | 8 |

NAME

9 | 10 | http_server, http_port, http_put, http_get, http_head, http_delete, 11 | http_parse_url - Http data exchanges mini library. 12 |

13 | 14 |

SYNOPSIS

15 | 16 | #include "http_lib.h" 17 |

18 | extern char *http_server; 19 |

20 | extern int http_port; 21 |

22 | extern char *http_proxy_server; 23 |

24 | extern int http_proxy_port; 25 |

26 | http_retcode http_put
27 | 28 | (
29 | 30 | char *filename,
31 | 32 | char *data,
33 | 34 | int length,
35 | 36 | int overwrite,
37 | 38 | char *type
39 | 40 | ); 41 |

42 | http_retcode http_get
43 | 44 | (
45 | 46 | char *filename,
47 | 48 | char **pdata,
49 | 50 | int *plength,
51 | 52 | char *typebuf
53 | 54 | ); 55 |

56 | http_retcode http_head
57 | 58 | (
59 | 60 | char *filename,
61 | 62 | int *plength,
63 | 64 | char *typebuf
65 | 66 | ); 67 |

68 | http_retcode http_delete(char *filename); 69 |

70 | http_retcode http_parse_url
71 | 72 | (
73 | 74 | char *url,
75 | 76 | char **pfilename
77 | 78 | ); 79 |

80 | 81 |

PARAMETERS

82 | 83 | char *filename (http_put)
84 | 85 | Name of the ressource to create. 86 |

87 | char *data
88 | 89 | Pointer to the data to send. 90 |

91 | int length
92 | 93 | Length of the data to send. 94 |

95 | int overwrite
96 | 97 | Flag to request to overwrite the ressource if it was already 98 | existing. 99 |

100 | char *type
101 | 102 | Type of the data, if NULL default type is used. 103 |

104 | char *filename (http_get)
105 | 106 | Name of the ressource to read. 107 |

108 | char **pdata
109 | 110 | Address of a pointer variable which will be set to point toward 111 | allocated memory containing read data. 112 |

113 |

114 |
int *plength
(http_get) 115 | Address of integer variable which will be set to length of the 116 | read data. 117 |

118 |

119 |
120 | char *typebuf (http_get)
121 | 122 | Allocated buffer where the read data type is returned. If NULL, 123 | the type is not returned. 124 |

125 |

126 |
int *plength
(http_head) 127 | Address of integer variable which will be set to length of the 128 | data. 129 |

130 |

131 |
132 | char *typebuf (http_head)
133 | 134 | Allocated buffer where the data type is returned. If NULL, the 135 | type is not returned. 136 |

137 | char *url
138 | 139 | Writeable copy of an url. 140 |

141 | char **pfilename
142 | 143 | Address of a pointer that will be filled with allocated filename 144 | the pointer must be equal to NULL before calling or it will be 145 | automatically freed (free(3)). 146 |

147 | 148 |

DESCRIPTION

149 | 150 | http_server
151 | 152 | Pointer to a mallocated string containing server name or NULL. 153 |

154 | http_port
155 | 156 | Server port number. 157 |

158 | http_proxy_server
159 | 160 | Pointer a string containing proxy server name to use or NULL for noproxy. 161 |

162 | http_port
163 | 164 | Proxy server port number (or 0). 165 |

166 | http_put
167 | 168 | Put data on the server
169 | 170 |

171 | This function sends data to the http data server. The data will be 172 | stored under the ressource name filename. 173 |

174 | http_get
175 | 176 | Get data from the server 177 |

178 | This function gets data from the http data server. The data is read 179 | from the ressource named filename. Address of new new allocated 180 | memory block is filled in pdata whose length is returned via plength. 181 |

182 | http_head
183 | 184 | Request the header 185 |

186 | This function outputs the header of thehttp data server. The header 187 | is from the ressource named filename. The length and type of data is 188 | eventually returned (like for http_get(3)). 189 |

190 | http_delete
191 | 192 | Delete data on the server 193 |

194 | This function request a DELETE on the http data server. 195 |

196 | http_parse_url
197 | 198 | Parses an url : setting the http_server and http_port global variables 199 | and returning the filename to pass to http_get/put/... 200 |

201 | 202 |

RETURNS

203 | 204 | http_put
205 | 206 | A negative error code or a positive code from the server. 207 |

208 | 209 | http_get
210 | 211 | A negative error code or a positive code from the server. 212 |

213 | http_head
214 | 215 | A negative error code or a positive code from the server. 216 |

217 | http_delete
218 | 219 | A negative error code or a positive code from the server. 220 |

221 | http_parse_url
222 | 223 | A negative error code or 0 if sucessfully parsed. 224 |

225 | Possible values for a http_retcode are as follows: 226 |

227 | Client side errors.
228 | 229 | ERRHOST No such host.
230 | 231 | ERRSOCK Can't create socket.
232 | 233 | ERRCONN Can't connect to host.
234 | 235 | ERRWRHD Write error on socket while writing header. 236 | ERRWRDT Write error on socket while writing data. 237 | ERRRDHD Read error on socket while reading result. 238 | ERRPAHD Invalid answer from data server. 239 | ERRNULL Null data pointer.
240 | 241 | ERRNOLG No/Bad length in header.
242 | 243 |

244 |
ERRMEM
Can't allocate memory. 245 | ERRRDDT Read error while reading data. 246 | ERRURLH Invalid url - must start with `http://'. 247 | ERRURLP Invalid port in url. 248 |

249 |

250 |
251 | Return code by the server.
252 | 253 |
254 |
ERR400
Invalid query. 255 | ERR403 Forbidden. 256 |
257 |
258 |
259 |
ERR408
Request timeout. 260 |
261 |
262 |
263 |
ERR500
Server error. 264 |
265 |
266 |
267 |
ERR501
Not implemented. 268 |
269 |
270 |
271 |
ERR503
Service overloaded. 272 |

273 |

274 |
275 | Succesful results.
276 | 277 |
278 |
OK0
Successfull parse. 279 |
280 |
281 |
282 |
OK201
Ressource succesfully created. 283 |
284 |
285 |
286 |
OK200
Ressource succesfully read. 287 |

288 |

289 |
290 | 291 |

LIMITATIONS

292 | 293 | http_put
294 | 295 | Filename is truncated to first 256 characters and type to 64. 296 |

297 | http_get
298 | 299 | Filename is truncated to first 256 characters. 300 |

301 | http_head
302 | 303 | Filename is truncated to first 256 characters. 304 |

305 | http_delete
306 | 307 | Filename is truncated to first 256 characters. 308 |

309 | 310 |


311 | Table of Contents

312 |

320 | 321 | -------------------------------------------------------------------------------- /man1/http.1: -------------------------------------------------------------------------------- 1 | .TH HTTP 1 "V1.2 - 24 Apr 1996" "dl's free utilities" 2 | .SH NAME 3 | 4 | http \- perform HTTP queries from command line 5 | 6 | .SH SYNOPSIS 7 | 8 | .B http 9 | <\fIget\fR|\fIhead\fR|\fIput\fR|\fIdelete\fR> <\fBurl\fR> 10 | 11 | .SH DESCRIPTION 12 | .BR http 13 | is a tool to perform HTTP queries from the command line. 14 | Informations and diagnostic goes to stderr. Data is taken from stdin 15 | (for \fIput\fR) or output to stdout (for \fIget\fR). If the 16 | environement variable \fBhttp_proxy\fR exists it will be used as a 17 | proxy url. 18 | .PP 19 | The following commands are supported 20 | .TP 21 | .I get 22 | to send an http GET query. It fetches the given \fBurl\fR to 23 | standard output. 24 | .TP 25 | .I head 26 | gets the header only of the \fBurl\fR. 27 | .TP 28 | .I put 29 | to send an http PUT query (not recognized by all servers). It reads 30 | data from standard input and then send them to the server. 31 | .TP 32 | .I delete 33 | to send an http DELETE query (not recognized by all servers). 34 | 35 | .SH LIMITATIONS 36 | The url is limited to 256 characters. 37 | 38 | .SH EXAMPLE 39 | http get http://www.demailly.com/~dl/wwwtools.html > wwwtools.html 40 | 41 | .SH AUTHOR 42 | Laurent Demailly . Free software. 43 | (See LICENSE file) 44 | 45 | .SH SEE ALSO 46 | http_lib(3) 47 | -------------------------------------------------------------------------------- /man3/http_delete.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_get.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_head.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_lib.3: -------------------------------------------------------------------------------- 1 | .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man! 2 | .\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST! 3 | .TH "http_lib" 3 "25 April 1996" "c2man http_lib.c" 4 | .SH "NAME" 5 | http_server, 6 | http_port, 7 | http_proxy_server, 8 | http_proxy_port, 9 | http_put, 10 | http_get, 11 | http_head, 12 | http_delete, 13 | http_parse_url \- Http data exchanges mini library. 14 | .SH "SYNOPSIS" 15 | .ft B 16 | #include "http_lib.h" 17 | .br 18 | .sp 19 | extern char *http_server; 20 | .sp 21 | extern int http_port; 22 | .sp 23 | extern char *http_proxy_server; 24 | .sp 25 | extern int http_proxy_port; 26 | .sp 27 | http_retcode http_put 28 | .br 29 | ( 30 | .br 31 | char *filename, 32 | .br 33 | char *data, 34 | .br 35 | int length, 36 | .br 37 | int overwrite, 38 | .br 39 | char *type 40 | .br 41 | ); 42 | .sp 43 | http_retcode http_get 44 | .br 45 | ( 46 | .br 47 | char *filename, 48 | .br 49 | char **pdata, 50 | .br 51 | int *plength, 52 | .br 53 | char *typebuf 54 | .br 55 | ); 56 | .sp 57 | http_retcode http_head 58 | .br 59 | ( 60 | .br 61 | char *filename, 62 | .br 63 | int *plength, 64 | .br 65 | char *typebuf 66 | .br 67 | ); 68 | .sp 69 | http_retcode http_delete(char *filename); 70 | .sp 71 | http_retcode http_parse_url 72 | .br 73 | ( 74 | .br 75 | char *url, 76 | .br 77 | char **pfilename 78 | .br 79 | ); 80 | .ft R 81 | .SH "PARAMETERS" 82 | .TP 83 | .BR "char *filename" " (http_put)" 84 | Name of the ressource to create. 85 | .TP 86 | .B "char *data" 87 | Pointer to the data to send. 88 | .TP 89 | .B "int length" 90 | Length of the data to send. 91 | .TP 92 | .B "int overwrite" 93 | Flag to request to overwrite the ressource if it 94 | was already existing. 95 | .TP 96 | .B "char *type" 97 | Type of the data, if NULL default type is used. 98 | .TP 99 | .BR "char *filename" " (http_get)" 100 | Name of the ressource to read. 101 | .TP 102 | .B "char **pdata" 103 | Address of a pointer variable which will be set 104 | to point toward allocated memory containing read data. 105 | .TP 106 | .BR "int *plength" " (http_get)" 107 | Address of integer variable which will be set to 108 | length of the read data. 109 | .TP 110 | .BR "char *typebuf" " (http_get)" 111 | Allocated buffer where the read data type is returned. 112 | If NULL, the type is not returned. 113 | .TP 114 | .BR "int *plength" " (http_head)" 115 | Address of integer variable which will be set to 116 | length of the data. 117 | .TP 118 | .BR "char *typebuf" " (http_head)" 119 | Allocated buffer where the data type is returned. 120 | If NULL, the type is not returned. 121 | .TP 122 | .B "char *url" 123 | Writeable copy of an url. 124 | .TP 125 | .B "char **pfilename" 126 | Address of a pointer that will be filled with allocated filename 127 | the pointer must be equal to NULL before calling or it will be 128 | automatically freed (free(3)). 129 | .SH "DESCRIPTION" 130 | .SS "http_server" 131 | Pointer to a mallocated string containing server name or NULL. 132 | .SS "http_port" 133 | Server port number. 134 | .SS "http_proxy_server" 135 | Pointer to proxy server name or NULL. 136 | .SS "http_proxy_port" 137 | Proxy server port number or 0. 138 | .SS "http_put" 139 | Put data on the server 140 | 141 | This function sends data to the http data server. 142 | The data will be stored under the ressource name filename. 143 | .SS "http_get" 144 | Get data from the server 145 | 146 | This function gets data from the http data server. 147 | The data is read from the ressource named filename. 148 | Address of new new allocated memory block is filled in pdata 149 | whose length is returned via plength. 150 | .SS "http_head" 151 | Request the header 152 | 153 | This function outputs the header of thehttp data server. 154 | The header is from the ressource named filename. 155 | The length and type of data is eventually returned (like for http_get(3)). 156 | .SS "http_delete" 157 | Delete data on the server 158 | 159 | This function request a DELETE on the http data server. 160 | .SS "http_parse_url" 161 | Parses an url : setting the http_server and http_port global variables 162 | and returning the filename to pass to http_get/put/... 163 | .SH "RETURNS" 164 | .SS "http_put" 165 | A negative error code or a positive code from the server. 166 | .sp 167 | Possible values for a \fBhttp_retcode\fR are as follows: 168 | .IP 169 | Client side errors. 170 | .RS 0.75in 171 | .PD 0 172 | .ft B 173 | .nr TL \w'ERRHOST'u+0.2i 174 | .ft R 175 | .TP \n(TLu 176 | \fBERRHOST\fR 177 | No such host. 178 | .TP \n(TLu 179 | \fBERRSOCK\fR 180 | Can't create socket. 181 | .TP \n(TLu 182 | \fBERRCONN\fR 183 | Can't connect to host. 184 | .TP \n(TLu 185 | \fBERRWRHD\fR 186 | Write error on socket while writing header. 187 | .TP \n(TLu 188 | \fBERRWRDT\fR 189 | Write error on socket while writing data. 190 | .TP \n(TLu 191 | \fBERRRDHD\fR 192 | Read error on socket while reading result. 193 | .TP \n(TLu 194 | \fBERRPAHD\fR 195 | Invalid answer from data server. 196 | .TP \n(TLu 197 | \fBERRNULL\fR 198 | Null data pointer. 199 | .TP \n(TLu 200 | \fBERRNOLG\fR 201 | No/Bad length in header. 202 | .TP \n(TLu 203 | \fBERRMEM\fR 204 | Can't allocate memory. 205 | .TP \n(TLu 206 | \fBERRRDDT\fR 207 | Read error while reading data. 208 | .TP \n(TLu 209 | \fBERRURLH\fR 210 | Invalid url - must start with 'http://'. 211 | .TP \n(TLu 212 | \fBERRURLP\fR 213 | Invalid port in url. 214 | .RE 215 | .PD 216 | .IP 217 | Return code by the server. 218 | .RS 0.75in 219 | .PD 0 220 | .ft B 221 | .nr TL \w'ERRHOST'u+0.2i 222 | .ft R 223 | .TP \n(TLu 224 | \fBERR400\fR 225 | Invalid query. 226 | .TP \n(TLu 227 | \fBERR403\fR 228 | Forbidden. 229 | .TP \n(TLu 230 | \fBERR408\fR 231 | Request timeout. 232 | .TP \n(TLu 233 | \fBERR500\fR 234 | Server error. 235 | .TP \n(TLu 236 | \fBERR501\fR 237 | Not implemented. 238 | .TP \n(TLu 239 | \fBERR503\fR 240 | Service overloaded. 241 | .RE 242 | .PD 243 | .IP 244 | Succesful results. 245 | .RS 0.75in 246 | .PD 0 247 | .ft B 248 | .nr TL \w'ERRHOST'u+0.2i 249 | .ft R 250 | .TP \n(TLu 251 | \fBOK0\fR 252 | Successfull parse. 253 | .TP \n(TLu 254 | \fBOK201\fR 255 | Ressource succesfully created. 256 | .TP \n(TLu 257 | \fBOK200\fR 258 | Ressource succesfully read. 259 | .RE 260 | .PD 261 | .SS "http_get" 262 | A negative error code or a positive code from the server. 263 | .sp 264 | Possible values for a \fBhttp_retcode\fR are as follows: 265 | .IP 266 | Client side errors. 267 | .RS 0.75in 268 | .PD 0 269 | .ft B 270 | .nr TL \w'ERRHOST'u+0.2i 271 | .ft R 272 | .TP \n(TLu 273 | \fBERRHOST\fR 274 | No such host. 275 | .TP \n(TLu 276 | \fBERRSOCK\fR 277 | Can't create socket. 278 | .TP \n(TLu 279 | \fBERRCONN\fR 280 | Can't connect to host. 281 | .TP \n(TLu 282 | \fBERRWRHD\fR 283 | Write error on socket while writing header. 284 | .TP \n(TLu 285 | \fBERRWRDT\fR 286 | Write error on socket while writing data. 287 | .TP \n(TLu 288 | \fBERRRDHD\fR 289 | Read error on socket while reading result. 290 | .TP \n(TLu 291 | \fBERRPAHD\fR 292 | Invalid answer from data server. 293 | .TP \n(TLu 294 | \fBERRNULL\fR 295 | Null data pointer. 296 | .TP \n(TLu 297 | \fBERRNOLG\fR 298 | No/Bad length in header. 299 | .TP \n(TLu 300 | \fBERRMEM\fR 301 | Can't allocate memory. 302 | .TP \n(TLu 303 | \fBERRRDDT\fR 304 | Read error while reading data. 305 | .TP \n(TLu 306 | \fBERRURLH\fR 307 | Invalid url - must start with 'http://'. 308 | .TP \n(TLu 309 | \fBERRURLP\fR 310 | Invalid port in url. 311 | .RE 312 | .PD 313 | .IP 314 | Return code by the server. 315 | .RS 0.75in 316 | .PD 0 317 | .ft B 318 | .nr TL \w'ERRHOST'u+0.2i 319 | .ft R 320 | .TP \n(TLu 321 | \fBERR400\fR 322 | Invalid query. 323 | .TP \n(TLu 324 | \fBERR403\fR 325 | Forbidden. 326 | .TP \n(TLu 327 | \fBERR408\fR 328 | Request timeout. 329 | .TP \n(TLu 330 | \fBERR500\fR 331 | Server error. 332 | .TP \n(TLu 333 | \fBERR501\fR 334 | Not implemented. 335 | .TP \n(TLu 336 | \fBERR503\fR 337 | Service overloaded. 338 | .RE 339 | .PD 340 | .IP 341 | Succesful results. 342 | .RS 0.75in 343 | .PD 0 344 | .ft B 345 | .nr TL \w'ERRHOST'u+0.2i 346 | .ft R 347 | .TP \n(TLu 348 | \fBOK0\fR 349 | Successfull parse. 350 | .TP \n(TLu 351 | \fBOK201\fR 352 | Ressource succesfully created. 353 | .TP \n(TLu 354 | \fBOK200\fR 355 | Ressource succesfully read. 356 | .RE 357 | .PD 358 | .SS "http_head" 359 | A negative error code or a positive code from the server. 360 | .sp 361 | Possible values for a \fBhttp_retcode\fR are as follows: 362 | .IP 363 | Client side errors. 364 | .RS 0.75in 365 | .PD 0 366 | .ft B 367 | .nr TL \w'ERRHOST'u+0.2i 368 | .ft R 369 | .TP \n(TLu 370 | \fBERRHOST\fR 371 | No such host. 372 | .TP \n(TLu 373 | \fBERRSOCK\fR 374 | Can't create socket. 375 | .TP \n(TLu 376 | \fBERRCONN\fR 377 | Can't connect to host. 378 | .TP \n(TLu 379 | \fBERRWRHD\fR 380 | Write error on socket while writing header. 381 | .TP \n(TLu 382 | \fBERRWRDT\fR 383 | Write error on socket while writing data. 384 | .TP \n(TLu 385 | \fBERRRDHD\fR 386 | Read error on socket while reading result. 387 | .TP \n(TLu 388 | \fBERRPAHD\fR 389 | Invalid answer from data server. 390 | .TP \n(TLu 391 | \fBERRNULL\fR 392 | Null data pointer. 393 | .TP \n(TLu 394 | \fBERRNOLG\fR 395 | No/Bad length in header. 396 | .TP \n(TLu 397 | \fBERRMEM\fR 398 | Can't allocate memory. 399 | .TP \n(TLu 400 | \fBERRRDDT\fR 401 | Read error while reading data. 402 | .TP \n(TLu 403 | \fBERRURLH\fR 404 | Invalid url - must start with 'http://'. 405 | .TP \n(TLu 406 | \fBERRURLP\fR 407 | Invalid port in url. 408 | .RE 409 | .PD 410 | .IP 411 | Return code by the server. 412 | .RS 0.75in 413 | .PD 0 414 | .ft B 415 | .nr TL \w'ERRHOST'u+0.2i 416 | .ft R 417 | .TP \n(TLu 418 | \fBERR400\fR 419 | Invalid query. 420 | .TP \n(TLu 421 | \fBERR403\fR 422 | Forbidden. 423 | .TP \n(TLu 424 | \fBERR408\fR 425 | Request timeout. 426 | .TP \n(TLu 427 | \fBERR500\fR 428 | Server error. 429 | .TP \n(TLu 430 | \fBERR501\fR 431 | Not implemented. 432 | .TP \n(TLu 433 | \fBERR503\fR 434 | Service overloaded. 435 | .RE 436 | .PD 437 | .IP 438 | Succesful results. 439 | .RS 0.75in 440 | .PD 0 441 | .ft B 442 | .nr TL \w'ERRHOST'u+0.2i 443 | .ft R 444 | .TP \n(TLu 445 | \fBOK0\fR 446 | Successfull parse. 447 | .TP \n(TLu 448 | \fBOK201\fR 449 | Ressource succesfully created. 450 | .TP \n(TLu 451 | \fBOK200\fR 452 | Ressource succesfully read. 453 | .RE 454 | .PD 455 | .SS "http_delete" 456 | A negative error code or a positive code from the server. 457 | .sp 458 | Possible values for a \fBhttp_retcode\fR are as follows: 459 | .IP 460 | Client side errors. 461 | .RS 0.75in 462 | .PD 0 463 | .ft B 464 | .nr TL \w'ERRHOST'u+0.2i 465 | .ft R 466 | .TP \n(TLu 467 | \fBERRHOST\fR 468 | No such host. 469 | .TP \n(TLu 470 | \fBERRSOCK\fR 471 | Can't create socket. 472 | .TP \n(TLu 473 | \fBERRCONN\fR 474 | Can't connect to host. 475 | .TP \n(TLu 476 | \fBERRWRHD\fR 477 | Write error on socket while writing header. 478 | .TP \n(TLu 479 | \fBERRWRDT\fR 480 | Write error on socket while writing data. 481 | .TP \n(TLu 482 | \fBERRRDHD\fR 483 | Read error on socket while reading result. 484 | .TP \n(TLu 485 | \fBERRPAHD\fR 486 | Invalid answer from data server. 487 | .TP \n(TLu 488 | \fBERRNULL\fR 489 | Null data pointer. 490 | .TP \n(TLu 491 | \fBERRNOLG\fR 492 | No/Bad length in header. 493 | .TP \n(TLu 494 | \fBERRMEM\fR 495 | Can't allocate memory. 496 | .TP \n(TLu 497 | \fBERRRDDT\fR 498 | Read error while reading data. 499 | .TP \n(TLu 500 | \fBERRURLH\fR 501 | Invalid url - must start with 'http://'. 502 | .TP \n(TLu 503 | \fBERRURLP\fR 504 | Invalid port in url. 505 | .RE 506 | .PD 507 | .IP 508 | Return code by the server. 509 | .RS 0.75in 510 | .PD 0 511 | .ft B 512 | .nr TL \w'ERRHOST'u+0.2i 513 | .ft R 514 | .TP \n(TLu 515 | \fBERR400\fR 516 | Invalid query. 517 | .TP \n(TLu 518 | \fBERR403\fR 519 | Forbidden. 520 | .TP \n(TLu 521 | \fBERR408\fR 522 | Request timeout. 523 | .TP \n(TLu 524 | \fBERR500\fR 525 | Server error. 526 | .TP \n(TLu 527 | \fBERR501\fR 528 | Not implemented. 529 | .TP \n(TLu 530 | \fBERR503\fR 531 | Service overloaded. 532 | .RE 533 | .PD 534 | .IP 535 | Succesful results. 536 | .RS 0.75in 537 | .PD 0 538 | .ft B 539 | .nr TL \w'ERRHOST'u+0.2i 540 | .ft R 541 | .TP \n(TLu 542 | \fBOK0\fR 543 | Successfull parse. 544 | .TP \n(TLu 545 | \fBOK201\fR 546 | Ressource succesfully created. 547 | .TP \n(TLu 548 | \fBOK200\fR 549 | Ressource succesfully read. 550 | .RE 551 | .PD 552 | .SS "http_parse_url" 553 | A negative error code or 0 if sucessfully parsed. 554 | .sp 555 | Possible values for a \fBhttp_retcode\fR are as follows: 556 | .IP 557 | Client side errors. 558 | .RS 0.75in 559 | .PD 0 560 | .ft B 561 | .nr TL \w'ERRHOST'u+0.2i 562 | .ft R 563 | .TP \n(TLu 564 | \fBERRHOST\fR 565 | No such host. 566 | .TP \n(TLu 567 | \fBERRSOCK\fR 568 | Can't create socket. 569 | .TP \n(TLu 570 | \fBERRCONN\fR 571 | Can't connect to host. 572 | .TP \n(TLu 573 | \fBERRWRHD\fR 574 | Write error on socket while writing header. 575 | .TP \n(TLu 576 | \fBERRWRDT\fR 577 | Write error on socket while writing data. 578 | .TP \n(TLu 579 | \fBERRRDHD\fR 580 | Read error on socket while reading result. 581 | .TP \n(TLu 582 | \fBERRPAHD\fR 583 | Invalid answer from data server. 584 | .TP \n(TLu 585 | \fBERRNULL\fR 586 | Null data pointer. 587 | .TP \n(TLu 588 | \fBERRNOLG\fR 589 | No/Bad length in header. 590 | .TP \n(TLu 591 | \fBERRMEM\fR 592 | Can't allocate memory. 593 | .TP \n(TLu 594 | \fBERRRDDT\fR 595 | Read error while reading data. 596 | .TP \n(TLu 597 | \fBERRURLH\fR 598 | Invalid url - must start with 'http://'. 599 | .TP \n(TLu 600 | \fBERRURLP\fR 601 | Invalid port in url. 602 | .RE 603 | .PD 604 | .IP 605 | Return code by the server. 606 | .RS 0.75in 607 | .PD 0 608 | .ft B 609 | .nr TL \w'ERRHOST'u+0.2i 610 | .ft R 611 | .TP \n(TLu 612 | \fBERR400\fR 613 | Invalid query. 614 | .TP \n(TLu 615 | \fBERR403\fR 616 | Forbidden. 617 | .TP \n(TLu 618 | \fBERR408\fR 619 | Request timeout. 620 | .TP \n(TLu 621 | \fBERR500\fR 622 | Server error. 623 | .TP \n(TLu 624 | \fBERR501\fR 625 | Not implemented. 626 | .TP \n(TLu 627 | \fBERR503\fR 628 | Service overloaded. 629 | .RE 630 | .PD 631 | .IP 632 | Succesful results. 633 | .RS 0.75in 634 | .PD 0 635 | .ft B 636 | .nr TL \w'ERRHOST'u+0.2i 637 | .ft R 638 | .TP \n(TLu 639 | \fBOK0\fR 640 | Successfull parse. 641 | .TP \n(TLu 642 | \fBOK201\fR 643 | Ressource succesfully created. 644 | .TP \n(TLu 645 | \fBOK200\fR 646 | Ressource succesfully read. 647 | .RE 648 | .PD 649 | .SH "LIMITATIONS" 650 | .SS "http_put" 651 | Filename is truncated to first 256 characters 652 | and type to 64. 653 | .SS "http_get" 654 | Filename is truncated to first 256 characters. 655 | .SS "http_head" 656 | Filename is truncated to first 256 characters. 657 | .SS "http_delete" 658 | Filename is truncated to first 256 characters. 659 | -------------------------------------------------------------------------------- /man3/http_parse_url.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_port.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_proxy_port.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_proxy_server.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_put.3: -------------------------------------------------------------------------------- 1 | http_lib.3 -------------------------------------------------------------------------------- /man3/http_server.3: -------------------------------------------------------------------------------- 1 | http_lib.3 --------------------------------------------------------------------------------