1 /* 2 * GTimer 3 * 4 * Copyright: 5 * (C) 1999 Craig Knudsen, cknudsen@cknudsen.com 6 * See accompanying file "COPYING". 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the 20 * Free Software Foundation, Inc., 59 Temple Place, 21 * Suite 330, Boston, MA 02111-1307, USA 22 * 23 * Description: 24 * Routines for using HTTP. 25 * 26 * Author: 27 * Craig Knudsen, cknudsen@cknudsen.com, http://www.cknudsen.com 28 * 29 * Home Page: 30 * http://www.cknudsen.com/gtimer/ 31 * 32 * History: 33 * 19-May-1999 Stole from another project to use on GTimer :-) 34 * 15-Aug-1995 Createdandle box to menu. 35 * 36 ****************************************************************************/ 37 38 39 #ifndef _HTTP_H 40 #define _HTTP_H 41 42 #include "tcpt.h" /* provides a little portability between UNIX/Win32 */ 43 44 #define HTTP_PORT 80 45 #define HTTP_MAX_LINE_LEN 2048 46 47 48 /* 49 ** Errors 50 */ 51 typedef enum { 52 HTTP_NO_ERROR = 0, /* success */ 53 HTTP_INVALID_HOST = 1, /* invalid host specified */ 54 HTTP_SYSTEM_ERROR = 2, /* error returned from system call */ 55 /* error value set in errno */ 56 HTTP_SOCKET_ERROR = 3, /* error returned from socket function */ 57 /* winsock does not use error for errors */ 58 HTTP_HTTP_ERROR = 4, /* error returned from server */ 59 HTTP_NO_REQUESTS = 5, /* no requests on queue */ 60 HTTP_TOO_MANY_REQUESTS = 6, /* too many requests queued */ 61 HTTP_OTHER_ERROR = 7, /* other error */ 62 HTTP_HOST_LOOKUP_FAILED = 8, /* unable to resolve name */ 63 HTTP_UNKNOWN_ERROR = 9 /* unknown error */ 64 } httpError; 65 66 67 /* 68 ** Encode text suitable for use in a URL. 69 */ 70 char *url_encode ( 71 #ifndef _NO_PROTO 72 char *str 73 #endif 74 ); 75 76 /* 77 ** httpErrorString - Translate a httpError value into a text string. 78 ** If HTTP_SYSTEM_ERROR, then lookup the error using errno. If 79 ** HTTP_SOCKET_ERROR, then use winsock to get an error value. 80 */ 81 char *httpErrorString ( 82 #ifndef _NO_PROTO 83 httpError error_num /* Error value */ 84 #endif 85 ); 86 87 /* 88 ** httpProcessRead - Perform what's been queued up now that data is 89 ** ready to be read from the socket. 90 */ 91 httpError httpProcessRead ( 92 #ifndef _NO_PROTO 93 sockfd connection 94 #endif 95 ); 96 97 /* 98 ** httpConnect - Attempt to connect to a server. 99 */ 100 httpError httpOpenConnection ( 101 #ifndef _NO_PROTO 102 char *servername, /* in: hostname of http server */ 103 int port, /* in: port to use (80) */ 104 sockfd *connection /* return: socket (if successful) */ 105 #endif 106 ); 107 108 109 110 /* 111 ** httpKillConnnection - Just close the socket immediately. 112 ** Also removes all requests from the queue. 113 */ 114 httpError httpKillConnection ( 115 #ifndef _NO_PROTO 116 sockfd connection /* in: connection to server */ 117 #endif 118 ); 119 120 121 /* 122 ** Enable an HTTP proxy 123 */ 124 void httpEnableProxy ( 125 #ifndef _NO_PROTO 126 char *server, 127 int port 128 #endif 129 ); 130 131 /* 132 ** Disable an HTTP proxy 133 */ 134 void httpDisableProxy (); 135 136 /* 137 ** Generic http request 138 */ 139 httpError httpGet ( 140 #ifndef _NO_PROTO 141 sockfd connection, /* in: connection to server */ 142 char *virthost, /* in: hostname of server */ 143 char *path, /* in: path to CGI */ 144 char *qs_names[], /* in: names in form */ 145 char *qs_values[], /* in: values in form */ 146 int num, /* in: size of above arrays */ 147 void (*callback)(char *,int) /* in: callback to call with data */ 148 #endif 149 ); 150 151 152 #endif /* _HTTP_H */ 153