commit 44ea50b91b80e9c2f08d2c2843e62d99338c5737 Author: Carsten Larsen Date: Fri Sep 1 00:20:11 2017 +0200 Initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4252e9c --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +# Portable Makefile generated by configure + +all: http_get help + +CC = m68k-amigaos-gcc +CFLAGS = -O2 -noixemul $(SSL_DEFS) $(SSL_INC) -Iinclude -Wall +LDFLAGS = -s $(SSL_LIBS) + +http_get.o: http_get.c + +http_get_amiga.o: http_get_amiga.c version.h + + +http_get: http_get.o http_get_amiga.o + ${CC} ${CFLAGS} -o http_get http_get.o http_get_amiga.o ${LDFLAGS} + +help: + man ./http_get.1 > http_get.help + +clean: + rm -f http_get.o http_get_amiga.o http_get http_get.help + +depend: + @echo Dependencies already done diff --git a/README b/README new file mode 100644 index 0000000..fea97a3 --- /dev/null +++ b/README @@ -0,0 +1,22 @@ + http_get - get the contents of an http URL + +http_get fetches an http URL and dumps the contents to stdout. It +does not do gopher, ftp, file, news, or any other type of URL, only http. +It can be configured to do https fetches as well. + +Files in this distribution: + + README this + Makefile guess + http_get.c source file + http_get.1 manual entry + +To build: If you're on a SysV-like machine (which includes old Linux systems +but not new Linux systems), edit the Makefile and uncomment the SYSV_LIBS +line. If you're doing SSL, uncomment those lines too. Otherwise, just do +a make. + +Feedback is welcome - send bug reports, enhancements, checks, money +orders, etc. to the addresses below. + + Jef Poskanzer jef@mail.acme.com http://www.acme.com/jef/ diff --git a/configure b/configure new file mode 100644 index 0000000..4e110bb --- /dev/null +++ b/configure @@ -0,0 +1,124 @@ +#!/bin/sh +# +# Copyright (c) 2015 Carsten Larsen +# Copyright (c) 2014 Poul-Henning Kamp +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +set -e + +# CONFIGURE: If you want to compile in support for https, uncomment these +# definitions. You will need to have already built OpenSSL, available at +# http://www.openssl.org/ Make sure the SSL_TREE definition points to the +# tree with your OpenSSL installation - depending on how you installed it, +# it may be in /usr/local instead of /usr/local/ssl. +#SSL_TREE = /usr/local/ssl +#SSL_DEFS = -DUSE_SSL +#SSL_INC = -I$(SSL_TREE)/include +#SSL_LIBS = -L$(SSL_TREE)/lib -lssl -lcrypto + +EXEC='http_get' + +HDRS=' + version.h +' + +SRCS=' + http_get.c + http_get_amiga.c +' + +if make -v 2>&1 | grep GNU > /dev/null 2>&1 ; then + echo "make is GNU make." + VALID=true +#else +# echo "Wrong version of make." +# VALID=false +fi + +if $VALID ; then + ( + echo '# Portable Makefile generated by configure' + echo '' + echo "all: $EXEC help" + echo '' + if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then + echo 'CC = m68k-amigaos-gcc' + echo "CFLAGS = -O2 -noixemul \$(SSL_DEFS) \$(SSL_INC) -Iinclude -Wall" + echo "LDFLAGS = -s \$(SSL_LIBS)" + elif [ -n "$1" ] && [ $1 = "AROS" ] ; then + echo 'CC = gcc' + echo "CFLAGS = -O2 -noixemul \$(SSL_DEFS) \$(SSL_INC) -Iinclude -Wall" + echo "LDFLAGS = \$(SSL_LIBS)" + else + echo "CFLAGS = -O2 -Wall -Werror" + echo "LDFLAGS = -s \$(SSL_LIBS)" + fi + echo '' + + for f in ${HDRS} + do + b=`basename $f .h` + i=`sed -n -e '/#include.*"/{ + s/"$// + s/.*"// + p + }' $f | sort -u` + if [ "x${i}" != "x" ] ; then + echo "${b}.h: " ${i} + echo " touch ${b}.h" + echo + fi + done + + l="" + for f in ${SRCS} + do + b=`basename $f .c` + i=`sed -n -e '/#include.*"/{ + s/"$// + s/.*"// + p + }' $f | sort -u` + echo "${b}.o: ${b}.c" ${i} + echo + l="${l} ${b}.o" + done + + echo + echo "$EXEC: ${l}" + echo " \${CC} \${CFLAGS} -o $EXEC ${l} \${LDFLAGS}" + echo + echo "help:" + echo " man ./$EXEC.1 > $EXEC.help" + echo + echo "clean:" + echo " rm -f ${l} $EXEC $EXEC.help" + echo + echo "depend:" + echo " @echo Dependencies already done" + ) > Makefile + + echo "Makefile generated" +fi diff --git a/http_get.1 b/http_get.1 new file mode 100644 index 0000000..bd04174 --- /dev/null +++ b/http_get.1 @@ -0,0 +1,74 @@ +.TH http_get 1 "01 November 2015" +.SH NAME +http_get - get the contents of an http URL +.SH SYNOPSIS +.B http_get +.RB [ -t +.IR timeout ] +.RB [ -r +.IR referrer ] +.RB [ -u +.IR user-agent ] +.RB [ -a +.IR username:password ] +.RB [ -c +.IR cookie ] +.RB [ -a +.I header value +.R ] +.RB [ -v ] +.I url +.SH DESCRIPTION +.PP +.I http_get +fetches an http URL and dumps the contents to stdout. +It does not do gopher, ftp, file, news, or any other type of URL, only http. +It can be configured to do https fetches as well. +.PP +The -t flag specifies a timeout in seconds. +If that much time passes with no activity, the fetch is aborted. +The default is 60 seconds. +.PP +The -r flag specifies a referrer header to send. +Some tightly-clenched web admins like to jigger their server to only +return files if the proper referrer is given. +.PP +The -u flag specifies a User-Agent header to send. +Some *really* tightly-clenched web admins like to jigger their server to only +return files if a well-known User-Agent is given. +.PP +The -a flag lets you do Basic Authentication. +.PP +The -c flag lets you pass in a cookie. +.PP +The -h flag lets you pass in one extra header. +.PP +The -v flag is for debugging; it tells http_get to show the HTTP headers +as well as the rest of the response. +.SH "EXIT STATUS" +.PP +If the fetch is successful (HTTP status 200), the command's exit status is 0. +Otherwise the exit status is the HTTP status code. +However, since a Unix command exit status is only one byte, the HTTP codes +show up mod 256. +Adding to the confusion, csh interprets the status byte as signed, while +in other shells it is unsigned. +Anyway, here is a table of some common status values: +.nf + HTTP sh csh + 200 0 0 + 302 46 46 + 304 48 48 + 400 144 -112 + 401 145 -111 + 403 147 -109 + 404 148 -108 + 408 152 -104 + 500 244 -12 + 501 245 -11 + 503 247 -9 +.fi +.SH AUTHOR +Originally based on a simple version by Al Globus . +Debugged, prettified, and extended by Jef Poskanzer . +AmigaOS adaption by Carsten Larsen . diff --git a/http_get.c b/http_get.c new file mode 100644 index 0000000..24aa4e4 --- /dev/null +++ b/http_get.c @@ -0,0 +1,762 @@ +/* http_get - fetch the contents of an http URL +** +** Originally based on a simple version by Al Globus . +** Debugged and prettified by Jef Poskanzer . Also includes +** ifdefs to handle https via OpenSSL. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef USE_SSL +#include +#include +#endif + +#include +#include +#define alarm(x) ; +int open_libs(); +extern struct Library *SocketBase; + + +/* Forwards. */ +static void usage( void ); +static int getURL( char* u, char* referrer, char* user_agent, char* auth_token, int ncookies, char** cookies, char* header_name, char* header_value ); +static int getURLbyParts( int protocol, char* host, unsigned short port, char* file, char* referrer, char* user_agent, char* auth_token, int ncookies, char** cookies, char* header_name, char* header_value ); +static int open_client_socket( char* hostname, unsigned short port ); +static void show_error( char* cause ); +static void sigcatch( int sig ); +static int b64_encode( unsigned char* ptr, int len, char* space, int size ); + + +/* Globals. */ +static char* argv0; +static int verbose; +static int timeout; +static char* url; + +/* Protocol symbols. */ +#define PROTO_HTTP 0 +#ifdef USE_SSL +#define PROTO_HTTPS 1 +#endif + +/* Header FSM states. */ +#define HDST_LINE1_PROTOCOL 0 +#define HDST_LINE1_WHITESPACE 1 +#define HDST_LINE1_STATUS 2 +#define HDST_BOL 10 +#define HDST_TEXT 11 +#define HDST_LF 12 +#define HDST_CR 13 +#define HDST_CRLF 14 +#define HDST_CRLFCR 15 + +#define MAX_COOKIES 20 + + +int +main( int argc, char** argv ) +{ + int argn; + char* referrer; + char* user_agent; + char* auth_token; + int ncookies; + char* cookies[MAX_COOKIES]; + char* header_name; + char* header_value; + int status; + + open_libs(); + + argv0 = argv[0]; + argn = 1; + timeout = 60; + referrer = (char*) 0; + user_agent = "http_get"; + auth_token = (char*) 0; + ncookies = 0; + header_name = (char*) 0; + header_value = (char*) 0; + verbose = 0; + while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) + { + if ( strcmp( argv[argn], "-t" ) == 0 && argn + 1 < argc ) + { + ++argn; + timeout = atoi( argv[argn] ); + } + else if ( strcmp( argv[argn], "-r" ) == 0 && argn + 1 < argc ) + { + ++argn; + referrer = argv[argn]; + } + else if ( strcmp( argv[argn], "-u" ) == 0 && argn + 1 < argc ) + { + ++argn; + user_agent = argv[argn]; + } + else if ( strcmp( argv[argn], "-a" ) == 0 && argn + 1 < argc ) + { + ++argn; + auth_token = argv[argn]; + } + else if ( strcmp( argv[argn], "-c" ) == 0 && argn + 1 < argc ) + { + if ( ncookies >= MAX_COOKIES ) + { + (void) fprintf( stderr, "%s: too many cookies\n", argv0 ); + exit( 1 ); + } + ++argn; + cookies[ncookies++] = argv[argn]; + } + else if ( strcmp( argv[argn], "-h" ) == 0 && argn + 2 < argc ) + { + ++argn; + header_name = argv[argn]; + ++argn; + header_value = argv[argn]; + } + else if ( strcmp( argv[argn], "-v" ) == 0 ) + verbose = 1; + else + usage(); + ++argn; + } + if ( argn >= argc ) + usage(); + url = argv[argn]; + ++argn; + if ( argn != argc ) + usage(); + + (void) signal( SIGALRM, sigcatch ); + status = getURL( url, referrer, user_agent, auth_token, ncookies, cookies, header_name, header_value ); + + if ( status == 200 ) + exit( 0 ); + else if ( status == 0 ) + exit( 1 ); + else + exit( status ); +} + + +static void +usage( void ) +{ + (void) fprintf( stderr, "usage: %s [-c cookie] [-t timeout] [-r referrer] [-u user-agent] [-a username:password] [-h header value] [-v] url\n", argv0 ); + exit( 1 ); +} + + +/* URL must be of the form http://host-name[:port]/file-name */ +static int +getURL( char* u, char* referrer, char* user_agent, char* auth_token, int ncookies, char** cookies, char* header_name, char* header_value ) +{ + char* s; + int protocol; + char host[2000]; + int host_len; + unsigned short port; + char* file = (char*) 0; + char* http = "http://"; + int http_len = strlen( http ); +#ifdef USE_SSL + char* https = "https://"; + int https_len = strlen( https ); +#endif /* USE_SSL */ + int proto_len; + + if ( u == (char*) 0 ) + { + (void) fprintf( stderr, "%s: null URL\n", argv0 ); + exit( 1 ); + } + if ( strncmp( http, u, http_len ) == 0 ) + { + proto_len = http_len; + protocol = PROTO_HTTP; + } +#ifdef USE_SSL + else if ( strncmp( https, u, https_len ) == 0 ) + { + proto_len = https_len; + protocol = PROTO_HTTPS; + } +#endif /* USE_SSL */ + else + { + (void) fprintf( stderr, "%s: non-http URL\n", argv0 ); + exit( 1 ); + } + + /* Get the host name. */ + for ( s = u + proto_len; *s != '\0' && *s != ':' && *s != '/'; ++s ) + ; + host_len = s - u; + host_len -= proto_len; + strncpy( host, u + proto_len, host_len ); + host[host_len] = '\0'; + + /* Get port number. */ + if ( *s == ':' ) + { + port = (unsigned short) atoi( ++s ); + while ( *s != '\0' && *s != '/' ) + ++s; + } + else + { +#ifdef USE_SSL + if ( protocol == PROTO_HTTPS ) + port = 443; + else +#endif + port = 80; + } + + /* Get the file name. */ + if ( *s == '\0' ) + file = "/"; + else + file = s; + + return getURLbyParts( protocol, host, port, file, referrer, user_agent, auth_token, ncookies, cookies, header_name, header_value ); +} + + +static int +getURLbyParts( int protocol, char* host, unsigned short port, char* file, char* referrer, char* user_agent, char* auth_token, int ncookies, char** cookies, char* header_name, char* header_value ) +{ + int sockfd; +#ifdef USE_SSL + SSL_CTX* ssl_ctx = (SSL_CTX*) 0; + SSL* ssl = (SSL*) 0; +#endif + char buf[20000]; + int i, bytes, header_state, status; + int b = 0; + + alarm( timeout ); + sockfd = open_client_socket( host, port ); + +#ifdef USE_SSL + if ( protocol == PROTO_HTTPS ) + { + /* Make SSL connection. */ + int r; + SSL_load_error_strings(); + SSLeay_add_ssl_algorithms(); + ssl_ctx = SSL_CTX_new( SSLv23_client_method() ); + ssl = SSL_new( ssl_ctx ); + SSL_set_fd( ssl, sockfd ); + r = SSL_connect( ssl ); + if ( r <= 0 ) + { + (void) fprintf( + stderr, "%s: %s - SSL connection failed - %d\n", + argv0, url, r ); + ERR_print_errors_fp( stderr ); + exit( 1 ); + } + } +#endif + + /* Build request buffer, starting with the GET. */ + alarm( timeout ); + bytes = snprintf( buf, sizeof(buf), "GET %s HTTP/1.0\r\n", file ); + /* HTTP/1.1 host header - some servers want it even in HTTP/1.0. */ + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Host: %s\r\n", host ); + if ( referrer != (char*) 0 ) + { + /* We generate both the standard Referer and the correctly + ** spelled Referrer. + */ + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Referer: %s\r\n", referrer ); + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Referrer: %s\r\n", referrer ); + } + /* User-agent. */ + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "User-Agent: %s\r\n", user_agent ); + /* Fixed headers. */ + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Accept: */*\r\n" ); + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Accept-Language: en\r\n" ); + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Accept-Charset: iso-8859-1,*,utf-8\r\n" ); + if ( auth_token != (char*) 0 ) + { + /* Basic Auth info. */ + char token_buf[1000]; + token_buf[b64_encode( (unsigned char*) auth_token, strlen( auth_token ), token_buf, sizeof(token_buf) )] = '\0'; + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Authorization: Basic %s\r\n", token_buf ); + } + /* Cookies. */ + for ( i = 0; i < ncookies; ++i ) + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "Cookie: %s\r\n", cookies[i] ); + /* Optional extra header. */ + if ( header_name != (char*) 0 ) + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "%s: %s\r\n", header_name, header_value ); + /* Blank line. */ + bytes += snprintf( &buf[bytes], sizeof(buf) - bytes, "\r\n" ); + /* Now actually send it. */ +#ifdef USE_SSL + if ( protocol == PROTO_HTTPS ) + (void) SSL_write( ssl, buf, bytes ); + else +#endif + (void) Send( sockfd, buf, bytes, 0 ); + + /* Get lines until a blank one. */ + alarm( timeout ); + header_state = HDST_LINE1_PROTOCOL; + status = 0; + for (;;) + { +#ifdef USE_SSL + if ( protocol == PROTO_HTTPS ) + bytes = SSL_read( ssl, buf, sizeof(buf) ); + else +#endif + bytes = Recv( sockfd, buf, sizeof(buf), 0 ); + if ( bytes <= 0 ) + break; + for ( b = 0; b < bytes; ++b ) + { + if ( verbose ) + (void) write( 1, &buf[b], 1 ); + switch ( header_state ) + { + case HDST_LINE1_PROTOCOL: + switch ( buf[b] ) + { + case ' ': + case '\t': + header_state = HDST_LINE1_WHITESPACE; ; + break; + case '\n': + header_state = HDST_LF ; + break; + case '\r': + header_state = HDST_CR; + break; + } + break; + case HDST_LINE1_WHITESPACE: + switch ( buf[b] ) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + status = buf[b] - '0'; + header_state = HDST_LINE1_STATUS; + break; + case '\n': + header_state = HDST_LF ; + break; + case '\r': + header_state = HDST_CR; + break; + default: + header_state = HDST_TEXT; + break; + } + break; + case HDST_LINE1_STATUS: + switch ( buf[b] ) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + status = status * 10 + buf[b] - '0'; + break; + case '\n': + header_state = HDST_LF ; + break; + case '\r': + header_state = HDST_CR; + break; + default: + header_state = HDST_TEXT; + break; + } + break; + case HDST_BOL: + switch ( buf[b] ) + { + case '\n': + header_state = HDST_LF; + break; + case '\r': + header_state = HDST_CR; + break; + default: + header_state = HDST_TEXT; + break; + } + break; + case HDST_TEXT: + switch ( buf[b] ) + { + case '\n': + header_state = HDST_LF; + break; + case '\r': + header_state = HDST_CR; + break; + } + break; + + case HDST_LF: + switch ( buf[b] ) + { + case '\n': + goto end_of_headers; + case '\r': + header_state = HDST_CR; + break; + default: + header_state = HDST_TEXT; + break; + } + break; + + case HDST_CR: + switch ( buf[b] ) + { + case '\n': + header_state = HDST_CRLF; + break; + case '\r': + goto end_of_headers; + default: + header_state = HDST_TEXT; + break; + } + break; + + case HDST_CRLF: + switch ( buf[b] ) + { + case '\n': + goto end_of_headers; + case '\r': + header_state = HDST_CRLFCR; + break; + default: + header_state = HDST_TEXT; + break; + } + break; + + case HDST_CRLFCR: + switch ( buf[b] ) + { + case '\n': + case '\r': + goto end_of_headers; + default: + header_state = HDST_TEXT; + break; + } + break; + } + } + } +end_of_headers: + /* Dump out the rest of the headers buffer. */ + if ( bytes > 0 ) + { + ++b; + (void) write( 1, &buf[b], bytes - b ); + } + + /* Copy the data. */ + for (;;) + { + alarm( timeout ); +#ifdef USE_SSL + if ( protocol == PROTO_HTTPS ) + bytes = SSL_read( ssl, buf, sizeof(buf) ); + else +#endif + bytes = Recv( sockfd, buf, sizeof(buf), 0 ); + if ( bytes == 0 ) + break; + if ( bytes < 0 ) + show_error( "read" ); + (void) write( 1, buf, bytes ); + } +#ifdef USE_SSL + if ( protocol == PROTO_HTTPS ) + { + SSL_free( ssl ); + SSL_CTX_free( ssl_ctx ); + } +#endif + (void) CloseSocket( sockfd ); + return status; +} + + +#if defined(AF_INET6) && defined(IN6_IS_ADDR_V4MAPPED) +#define USE_IPV6 +#endif + +static int +open_client_socket( char* hostname, unsigned short port ) +{ +#ifdef USE_IPV6 + struct addrinfo hints; + char portstr[10]; + int gaierr; + struct addrinfo* ai; + struct addrinfo* ai2; + struct addrinfo* aiv4; + struct addrinfo* aiv6; + struct sockaddr_in6 sa_in; +#else /* USE_IPV6 */ + struct hostent *he; + struct sockaddr_in sa_in; +#endif /* USE_IPV6 */ + int sa_len, sock_family, sock_type, sock_protocol; + int sockfd; + + (void) memset( (void*) &sa_in, 0, sizeof(sa_in) ); + +#ifdef USE_IPV6 + + (void) memset( &hints, 0, sizeof(hints) ); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + (void) snprintf( portstr, sizeof(portstr), "%d", (int) port ); + if ( (gaierr = getaddrinfo( hostname, portstr, &hints, &ai )) != 0 ) + { + (void) fprintf( + stderr, "%s: getaddrinfo %s - %s\n", argv0, hostname, + gai_strerror( gaierr ) ); + exit( 1 ); + } + + /* Find the first IPv4 and IPv6 entries. */ + aiv4 = (struct addrinfo*) 0; + aiv6 = (struct addrinfo*) 0; + for ( ai2 = ai; ai2 != (struct addrinfo*) 0; ai2 = ai2->ai_next ) + { + switch ( ai2->ai_family ) + { + case AF_INET: + if ( aiv4 == (struct addrinfo*) 0 ) + aiv4 = ai2; + break; + case AF_INET6: + if ( aiv6 == (struct addrinfo*) 0 ) + aiv6 = ai2; + break; + } + } + + /* If there's an IPv4 address, use that, otherwise try IPv6. */ + if ( aiv4 != (struct addrinfo*) 0 ) + { + if ( sizeof(sa_in) < aiv4->ai_addrlen ) + { + (void) fprintf( + stderr, "%s - sockaddr too small (%lu < %lu)\n", + hostname, (unsigned long) sizeof(sa_in), + (unsigned long) aiv4->ai_addrlen ); + exit( 1 ); + } + sock_family = aiv4->ai_family; + sock_type = aiv4->ai_socktype; + sock_protocol = aiv4->ai_protocol; + sa_len = aiv4->ai_addrlen; + (void) memmove( &sa_in, aiv4->ai_addr, sa_len ); + goto ok; + } + if ( aiv6 != (struct addrinfo*) 0 ) + { + if ( sizeof(sa_in) < aiv6->ai_addrlen ) + { + (void) fprintf( + stderr, "%s - sockaddr too small (%lu < %lu)\n", + hostname, (unsigned long) sizeof(sa_in), + (unsigned long) aiv6->ai_addrlen ); + exit( 1 ); + } + sock_family = aiv6->ai_family; + sock_type = aiv6->ai_socktype; + sock_protocol = aiv6->ai_protocol; + sa_len = aiv6->ai_addrlen; + (void) memmove( &sa_in, aiv6->ai_addr, sa_len ); + goto ok; + } + + (void) fprintf( + stderr, "%s: no valid address found for host %s\n", argv0, hostname ); + exit( 1 ); + +ok: + freeaddrinfo( ai ); + +#else /* USE_IPV6 */ + + he = gethostbyname( hostname ); // Socket Operation + if ( he == (struct hostent*) 0 ) + { + (void) fprintf( stderr, "%s: unknown host - %s\n", argv0, hostname ); + exit( 1 ); + } + sock_family = sa_in.sin_family = he->h_addrtype; + sock_type = SOCK_STREAM; + sock_protocol = 0; + sa_len = sizeof(sa_in); + (void) memmove( &sa_in.sin_addr, he->h_addr, he->h_length ); + sa_in.sin_port = htons( port ); + +#endif /* USE_IPV6 */ + + sockfd = socket( sock_family, sock_type, sock_protocol ); // Socket Operation + if ( sockfd < 0 ) + show_error( "socket" ); + + if ( connect( sockfd, (struct sockaddr*) &sa_in, sa_len ) < 0 ) // Socket Operation + show_error( "connect" ); + + return sockfd; +} + + +static void +show_error( char* cause ) +{ + char buf[5000]; + (void) sprintf( buf, "%s: %s - %s", argv0, url, cause ); + perror( buf ); + exit( 1 ); +} + + +static void +sigcatch( int sig ) +{ + (void) fprintf( stderr, "%s: %s - timed out\n", argv0, url ); + exit( 1 ); +} + + +/* Base-64 encoding. This encodes binary data as printable ASCII characters. +** Three 8-bit binary bytes are turned into four 6-bit values, like so: +** +** [11111111] [22222222] [33333333] +** +** [111111] [112222] [222233] [333333] +** +** Then the 6-bit values are represented using the characters "A-Za-z0-9+/". +*/ + +static char b64_encode_table[64] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /* 0-7 */ + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', /* 8-15 */ + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', /* 16-23 */ + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', /* 24-31 */ + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 32-39 */ + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', /* 40-47 */ + 'w', 'x', 'y', 'z', '0', '1', '2', '3', /* 48-55 */ + '4', '5', '6', '7', '8', '9', '+', '/' /* 56-63 */ +}; + +static int b64_decode_table[256] = { + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */ + 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */ + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */ + 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */ + -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */ + 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */ +}; + +/* Do base-64 encoding on a hunk of bytes. Return the actual number of +** bytes generated. Base-64 encoding takes up 4/3 the space of the original, +** plus a bit for end-padding. 3/2+5 gives a safe margin. +*/ +static int +b64_encode( unsigned char* ptr, int len, char* space, int size ) +{ + int ptr_idx, space_idx, phase; + char c; + + space_idx = 0; + phase = 0; + for ( ptr_idx = 0; ptr_idx < len; ++ptr_idx ) + { + switch ( phase ) + { + case 0: + c = b64_encode_table[ptr[ptr_idx] >> 2]; + if ( space_idx < size ) + space[space_idx++] = c; + c = b64_encode_table[( ptr[ptr_idx] & 0x3 ) << 4]; + if ( space_idx < size ) + space[space_idx++] = c; + ++phase; + break; + case 1: + space[space_idx - 1] = + b64_encode_table[ + b64_decode_table[(int) ((unsigned char) space[space_idx - 1])] | + ( ptr[ptr_idx] >> 4 ) ]; + c = b64_encode_table[( ptr[ptr_idx] & 0xf ) << 2]; + if ( space_idx < size ) + space[space_idx++] = c; + ++phase; + break; + case 2: + space[space_idx - 1] = + b64_encode_table[ + b64_decode_table[(int) ((unsigned char) space[space_idx - 1])] | + ( ptr[ptr_idx] >> 6 ) ]; + c = b64_encode_table[ptr[ptr_idx] & 0x3f]; + if ( space_idx < size ) + space[space_idx++] = c; + phase = 0; + break; + } + } + /* Pad with ='s. */ + while ( phase++ < 3 ) + if ( space_idx < size ) + space[space_idx++] = '='; + return space_idx; +} diff --git a/http_get.guide b/http_get.guide new file mode 100644 index 0000000..c79410e --- /dev/null +++ b/http_get.guide @@ -0,0 +1,66 @@ +@database http_get.guide +@author Carsten Larsen +@(c) Carsten Larsen +@$VER: http_get.guide 1.00 (02.11.2015) +@node Main "HTTP Get" +@title "HTTP Get" + +NAME + http_get - get the contents of an http URL + +SYNOPSIS + http_get [-t timeout] [-r referrer] [-u user-agent] + [-a username:password] [-c cookie] [-a header value ] + [-v] url + +DESCRIPTION + http_get fetches an http URL and dumps the contents to stdout. It does + not do gopher, ftp, file, news, or any other type of URL, only http. + It can be configured to do https fetches as well. + + The -t flag specifies a timeout in seconds. If that much time passes + with no activity, the fetch is aborted. The default is 60 seconds. + + The -r flag specifies a referrer header to send. Some tightly-clenched + web admins like to jigger their server to only return files if the + proper referrer is given. + + The -u flag specifies a User-Agent header to send. Some *really* + tightly-clenched web admins like to jigger their server to only return + files if a well-known User-Agent is given. + + The -a flag lets you do Basic Authentication. + + The -c flag lets you pass in a cookie. + + The -h flag lets you pass in one extra header. + + The -v flag is for debugging; it tells http_get to show the HTTP + headers as well as the rest of the response. + +EXIT STATUS + If the fetch is successful (HTTP status 200), the command's exit status + is 0. Otherwise the exit status is the HTTP status code. However, + since a Unix command exit status is only one byte, the HTTP codes show + up mod 256. Adding to the confusion, csh interprets the status byte as + signed, while in other shells it is unsigned. Anyway, here is a table + of some common status values: + HTTP sh csh + 200 0 0 + 302 46 46 + 304 48 48 + 400 144 -112 + 401 145 -111 + 403 147 -109 + 404 148 -108 + 408 152 -104 + 500 244 -12 + 501 245 -11 + 503 247 -9 + +AUTHOR + Originally based on a simple version by Al Globus . + Debugged, prettified, and extended by Jef Poskanzer . + AmigaOS adaption by Carsten Larsen . + +@endnode diff --git a/http_get_amiga.c b/http_get_amiga.c new file mode 100644 index 0000000..75234a8 --- /dev/null +++ b/http_get_amiga.c @@ -0,0 +1,79 @@ +/* + * Written by Carsten Larsen. + * Public domain. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "version.h" + +#define OPEN_ERROR "Cannot open %s.\n" +#define OPEN_VER_ERROR "Cannot open %s (%d.0)\n" +#define DOSLIB_NAME "dos.library" +#define DOSLIB_REV 33L +#define BSDLIB_NAME "bsdsocket.library" +#define BSDLIB_REV 03L + +int CreateTimer(); +void DeleteTimer(); + +const char *vers = "\0$VER: " PACKAGE_NAME " " PACKAGE_VERSION " (" PACKAGE_DATE ")"; + +struct Library *DOSBase; +struct Library *SocketBase; + +void amiga_open_error(char *name) +{ + printf(OPEN_ERROR, name); +} + +void amiga_open_lib_error(char *name, int version) +{ + printf(OPEN_VER_ERROR, name, version); +} + +void close_libs() +{ + if (DOSBase != NULL) { + CloseLibrary(DOSBase); + DOSBase = NULL; + } + + if (SocketBase != NULL) { + CloseLibrary(SocketBase); + SocketBase = NULL; + } +} + +int open_libs() +{ + atexit(close_libs); + + if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) { + amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV); + return 5; + } + + if(!(SocketBase = OpenLibrary((STRPTR)BSDLIB_NAME, BSDLIB_REV))) { + amiga_open_lib_error(BSDLIB_NAME, BSDLIB_REV); + return 5; + } + + return 0; +} + +#ifdef USE_SSL +int getuid() { return 55; } +void sigaction(int signum, void *act, void *oldact) { } +void tcgetattr(int fd, void *termios_p) { } +int tcsetattr(int fd, void *termios_p) { return 0; } +#endif diff --git a/include/clib/amitcp_protos.h b/include/clib/amitcp_protos.h new file mode 100644 index 0000000..856a082 --- /dev/null +++ b/include/clib/amitcp_protos.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2015 Carsten Larsen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SOCKET_AMITCP_H +#define _SOCKET_AMITCP_H +//--------------------------------------------------------------------------// +#define AMITCP_BASE_NAME SocketBase +#include "inline/amitcp.h" +//--------------------------------------------------------------------------// +#define socket Socket +#define bind Bind +#define listen Listen +#define accept Accept +#define connect Connect +#define send Send +#define sendto SendTo +#define sendmsg SendMsg +#define recv Recv +#define recvfrom RecvFrom +#define recvmsg RecvMsg +#define select Select +#define shutdown ShutDown +#define setsockopt SetSockOpt +#define getsockopt GetSockOpt +#define getsockname GetSockName +#define getpeername GetPeerName +#define inet_addr Inet_Addr +#define inet_network Inet_Network +#define inet_ntoa Inet_NtoA +#define gethostbyname GetHostByName +#define gethostbyaddr GetHostByAddr +#define getnetbyname GetNetByName +#define getnetbyaddr GetNetByAddr +#define getservbyname GetServByName +#define getservbyport GetServByPort +#define getprotobyname GetProtoByName +#define getprotobynumber GetProtoByNumber +#define getdtablesize GetDTableSize +#define gethostname GetHostName +#define gethostid GetHostId +#define vsyslog SyslogA +#define syslog Syslog +//--------------------------------------------------------------------------// +#define Accept TCP_Accept +#define Bind TCP_Bind +#define CloseSocket TCP_CloseSocket +#define Connect TCP_Connect +#define Dup2Socket TCP_Dup2Socket +#define Errno TCP_Errno +#define GetDTableSize TCP_GetDTableSize +#define GetHostByAddr TCP_GetHostByAddr +#define GetHostByName TCP_GetHostByName +#define GetHostId TCP_GetHostId +#define GetHostName TCP_GetHostName +#define GetNetByAddr TCP_GetNetByAddr +#define GetNetByName TCP_GetNetByName +#define GetPeerName TCP_GetPeerName +#define GetProtoByName TCP_GetProtoByName +#define GetProtoByNumber TCP_GetProtoByNumber +#define GetServByName TCP_GetServByName +#define GetServByPort TCP_GetServByPort +#define GetSockName TCP_GetSockName +#define GetSockOpt TCP_GetSockOpt +#define GetSocketEvents TCP_GetSocketEvents +#define Inet_Addr TCP_Inet_Addr +#define Inet_LnaOf TCP_Inet_LnaOf +#define Inet_MakeAddr TCP_Inet_MakeAddr +#define Inet_NetOf TCP_Inet_NetOf +#define Inet_Network TCP_Inet_Network +#define Inet_NtoA(x) TCP_Inet_NtoA((x).s_addr) +#define IoctlSocket TCP_IoctlSocket +#define Listen TCP_Listen +#define ObtainSocket TCP_ObtainSocket +#define Recv TCP_Recv +#define RecvFrom TCP_RecvFrom +#define RecvMsg TCP_RecvMsg +#define ReleaseCopyOfSocket TCP_ReleaseCopyOfSocket +#define ReleaseSocket TCP_ReleaseSocket +#define Send TCP_Send +#define SendMsg TCP_SendMsg +#define SendTo TCP_SendTo +#define SetErrnoPtr TCP_SetErrnoPtr +#define SetSockOpt TCP_SetSockOpt +#define SetSocketSignals TCP_SetSocketSignals +#define ShutDown TCP_ShutDown +#define Socket TCP_Socket +#define SocketBaseTagList TCP_SocketBaseTagList +#define SocketBaseTags TCP_SocketBaseTags +#define SyslogA TCP_SyslogA +#define WaitSelect TCP_WaitSelect +#define Select(n,r,w,e,t) TCP_WaitSelect(n,r,w,e,t,0) +//--------------------------------------------------------------------------// +#endif diff --git a/include/inline/amitcp.h b/include/inline/amitcp.h new file mode 100644 index 0000000..1ee4f30 --- /dev/null +++ b/include/inline/amitcp.h @@ -0,0 +1,203 @@ +/* Automatically generated header! Do not edit! */ + +#ifndef _INLINE_AMITCP_H +#define _INLINE_AMITCP_H + +#ifndef __INLINE_MACROS_H +#include +#endif /* !__INLINE_MACROS_H */ + +#ifndef AMITCP_BASE_NAME +#define AMITCP_BASE_NAME lss->lx_BsdSocketBase +#endif /* !AMITCP_BASE_NAME */ + +#define TCP_Accept(s, addr, addrlen) \ + LP3(0x30, LONG, TCP_Accept, LONG, s, d0, struct sockaddr *, addr, a0, int *, addrlen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_Bind(s, name, namelen) \ + LP3(0x24, LONG, TCP_Bind, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_CloseSocket(d) \ + LP1(0x78, LONG, TCP_CloseSocket, LONG, d, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_Connect(s, name, namelen) \ + LP3(0x36, LONG, TCP_Connect, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Dup2Socket(fd1, fd2) \ + LP2(0x108, LONG, TCP_Dup2Socket, LONG, fd1, d0, LONG, fd2, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Errno() \ + LP0(0xa2, LONG, TCP_Errno, \ + , AMITCP_BASE_NAME) + +#define TCP_GetDTableSize() \ + LP0(0x8a, LONG, TCP_GetDTableSize, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostByAddr(addr, len, type) \ + LP3(0xd8, struct hostent *, TCP_GetHostByAddr, const UBYTE *, addr, a0, LONG, len, d0, LONG, type, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostByName(name) \ + LP1(0xd2, struct hostent *, TCP_GetHostByName, const UBYTE *, name, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostId() \ + LP0(0x120, ULONG, TCP_GetHostId, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostName(hostname, size) \ + LP2(0x11a, LONG, TCP_GetHostName, STRPTR, hostname, a0, LONG, size, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetNetByAddr(net, type) \ + LP2(0xe4, struct netent *, TCP_GetNetByAddr, LONG, net, d0, LONG, type, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetNetByName(name) \ + LP1(0xde, struct netent *, TCP_GetNetByName, const UBYTE *, name, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetPeerName(s, hostname, namelen) \ + LP3(0x6c, LONG, TCP_GetPeerName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetProtoByName(name) \ + LP1(0xf6, struct protoent *, TCP_GetProtoByName, const UBYTE *, name, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetProtoByNumber(proto) \ + LP1(0xfc, struct protoent *, TCP_GetProtoByNumber, LONG, proto, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetServByName(name, proto) \ + LP2(0xea, struct servent *, TCP_GetServByName, const UBYTE *, name, a0, const UBYTE *, proto, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetServByPort(port, proto) \ + LP2(0xf0, struct servent *, TCP_GetServByPort, LONG, port, d0, const UBYTE *, proto, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetSockName(s, hostname, namelen) \ + LP3(0x66, LONG, TCP_GetSockName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetSockOpt(s, level, optname, optval, optlen) \ + LP5(0x60, LONG, TCP_GetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, void *, optval, a0, int *, optlen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetSocketEvents(eventmaskp) \ + LP1(0x12c, LONG, TCP_GetSocketEvents, ULONG *, eventmaskp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_Addr(cp) \ + LP1(0xb4, ULONG, TCP_Inet_Addr, const UBYTE *, cp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_LnaOf(in) \ + LP1(0xba, ULONG, TCP_Inet_LnaOf, LONG, in, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_MakeAddr(net, host) \ + LP2(0xc6, ULONG, TCP_Inet_MakeAddr, ULONG, net, d0, ULONG, host, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_NetOf(in) \ + LP1(0xc0, ULONG, TCP_Inet_NetOf, LONG, in, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_Network(cp) \ + LP1(0xcc, ULONG, TCP_Inet_Network, const UBYTE *, cp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_NtoA(in) \ + LP1(0xae, char *, TCP_Inet_NtoA, ULONG, in, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_IoctlSocket(d, request, argp) \ + LP3(0x72, LONG, TCP_IoctlSocket, LONG, d, d0, ULONG, request, d1, char *, argp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Listen(s, backlog) \ + LP2(0x2a, LONG, TCP_Listen, LONG, s, d0, LONG, backlog, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_ObtainSocket(id, domain, type, protocol) \ + LP4(0x90, LONG, TCP_ObtainSocket, LONG, id, d0, LONG, domain, d1, LONG, type, d2, LONG, protocol, d3, \ + , AMITCP_BASE_NAME) + +#define TCP_Recv(s, buf, len, flags) \ + LP4(0x4e, LONG, TCP_Recv, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_RecvFrom(s, buf, len, flags, from, fromlen) \ + LP6(0x48, LONG, TCP_RecvFrom, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, struct sockaddr *, from, a1, int *, fromlen, a2, \ + , AMITCP_BASE_NAME) + +#define TCP_RecvMsg(s, msg, flags) \ + LP3(0x114, LONG, TCP_RecvMsg, LONG, s, d0, struct msghdr *, msg, a0, LONG, flags, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_ReleaseCopyOfSocket(fd, id) \ + LP2(0x9c, LONG, TCP_ReleaseCopyOfSocket, LONG, fd, d0, LONG, id, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_ReleaseSocket(fd, id) \ + LP2(0x96, LONG, TCP_ReleaseSocket, LONG, fd, d0, LONG, id, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Send(s, msg, len, flags) \ + LP4(0x42, LONG, TCP_Send, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_SendMsg(s, msg, flags) \ + LP3(0x10e, LONG, TCP_SendMsg, LONG, s, d0, const struct msghdr *, msg, a0, LONG, flags, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_SendTo(s, msg, len, flags, to, tolen) \ + LP6(0x3c, LONG, TCP_SendTo, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, const struct sockaddr *, to, a1, LONG, tolen, d3, \ + , AMITCP_BASE_NAME) + +#define TCP_SetErrnoPtr(errno_p, size) \ + LP2(0xa8, LONG, TCP_SetErrnoPtr, void *, errno_p, a0, LONG, size, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_SetSockOpt(s, level, optname, optval, optlen) \ + LP5(0x5a, LONG, TCP_SetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, const void *, optval, a0, LONG, optlen, d3, \ + , AMITCP_BASE_NAME) + +#define TCP_SetSocketSignals(SIGINTR, SIGIO, SIGURG) \ + LP3NR(0x84, TCP_SetSocketSignals, ULONG, SIGINTR, d0, ULONG, SIGIO, d1, ULONG, SIGURG, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_ShutDown(s, how) \ + LP2(0x54, LONG, TCP_ShutDown, LONG, s, d0, LONG, how, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Socket(domain, type, protocol) \ + LP3(0x1e, LONG, TCP_Socket, LONG, domain, d0, LONG, type, d1, LONG, protocol, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_SocketBaseTagList(taglist) \ + LP1(0x126, LONG, TCP_SocketBaseTagList, struct TagItem *, taglist, a0, \ + , AMITCP_BASE_NAME) + +#ifndef NO_INLINE_STDARG +#define TCP_SocketBaseTags(tags...) \ + ({ULONG _tags[] = { tags }; TCP_SocketBaseTagList((struct TagItem *)_tags);}) +#endif + +#define TCP_SyslogA(level, format, ap) \ + LP3NR(0x102, TCP_SyslogA, ULONG, level, d0, const char *, format, a0, va_list, ap, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp) \ + LP6(0x7e, LONG, TCP_WaitSelect, LONG, nfds, d0, fd_set *, readfds, a0, fd_set *, writefds, a1, fd_set *, execptfds, a2, struct timeval *, timeout, a3, ULONG *, maskp, d1, \ + , AMITCP_BASE_NAME) + +#endif /* !_INLINE_AMITCP_H */ diff --git a/version.h b/version.h new file mode 100644 index 0000000..3a1b62c --- /dev/null +++ b/version.h @@ -0,0 +1,3 @@ +#define PACKAGE_NAME "http_get" +#define PACKAGE_VERSION "1.00" +#define PACKAGE_DATE "02.11.2015"