File: http.h

package info (click to toggle)
gtimer 2.0.0-1.2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 1,380 kB
  • ctags: 849
  • sloc: ansic: 8,122; sh: 821; perl: 651; makefile: 86
file content (152 lines) | stat: -rw-r--r-- 3,745 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * GTimer
 *
 * Copyright:
 *	(C) 1999 Craig Knudsen, cknudsen@cknudsen.com
 *	See accompanying file "COPYING".
 * 
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License
 *	as published by the Free Software Foundation; either version 2
 *	of the License, or (at your option) any later version.
 * 
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 * 
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the
 *	Free Software Foundation, Inc., 59 Temple Place,
 *	Suite 330, Boston, MA  02111-1307, USA
 *
 * Description:
 *	Routines for using HTTP.
 *
 * Author:
 *	Craig Knudsen, cknudsen@cknudsen.com, http://www.cknudsen.com
 *
 * Home Page:
 *	http://www.cknudsen.com/gtimer/
 *
 * History:
 *	19-May-1999	Stole from another project to use on GTimer :-)
 *	15-Aug-1995	Createdandle box to menu.
 *
 ****************************************************************************/


#ifndef _HTTP_H
#define _HTTP_H

#include "tcpt.h"	/* provides a little portability between UNIX/Win32 */

#define HTTP_PORT		80
#define HTTP_MAX_LINE_LEN	2048


/*
** Errors
*/
typedef enum {
  HTTP_NO_ERROR = 0,		/* success */
  HTTP_INVALID_HOST = 1,	/* invalid host specified */
  HTTP_SYSTEM_ERROR = 2,	/* error returned from system call */
				/* error value set in errno */
  HTTP_SOCKET_ERROR = 3,	/* error returned from socket function */
				/* winsock does not use error for errors */
  HTTP_HTTP_ERROR = 4,		/* error returned from server */
  HTTP_NO_REQUESTS = 5,		/* no requests on queue */
  HTTP_TOO_MANY_REQUESTS = 6,	/* too many requests queued */
  HTTP_OTHER_ERROR = 7,		/* other error */
  HTTP_HOST_LOOKUP_FAILED = 8,	/* unable to resolve name */
  HTTP_UNKNOWN_ERROR = 9	/* unknown error */
} httpError;


/*
** Encode text suitable for use in a URL.
*/
char *url_encode (
#ifndef _NO_PROTO
  char *str
#endif
);

/*
** httpErrorString - Translate a httpError value into a text string.
** If HTTP_SYSTEM_ERROR, then lookup the error using errno.  If
** HTTP_SOCKET_ERROR, then use winsock to get an error value.
*/
char *httpErrorString (
#ifndef _NO_PROTO
  httpError error_num		/* Error value */
#endif
);

/*
** httpProcessRead - Perform what's been queued up now that data is
** ready to be read from the socket.
*/
httpError httpProcessRead (
#ifndef _NO_PROTO
  sockfd connection
#endif
);

/*
** httpConnect - Attempt to connect to a server.
*/
httpError httpOpenConnection (
#ifndef _NO_PROTO
  char *servername,		/* in: hostname of http server */
  int port,			/* in: port to use (80) */
  sockfd *connection		/* return: socket (if successful) */
#endif
);



/*
** httpKillConnnection - Just close the socket immediately.
** Also removes all requests from the queue.
*/
httpError httpKillConnection (
#ifndef _NO_PROTO
  sockfd connection		/* in: connection to server */
#endif
);


/*
** Enable an HTTP proxy
*/
void httpEnableProxy (
#ifndef _NO_PROTO
  char *server,
  int port
#endif
);

/*
** Disable an HTTP proxy
*/
void httpDisableProxy ();

/*
** Generic http request
*/
httpError httpGet (
#ifndef _NO_PROTO
  sockfd connection,		/* in: connection to server */
  char *virthost,		/* in: hostname of server */
  char *path,			/* in: path to CGI */
  char *qs_names[],		/* in: names in form */
  char *qs_values[],		/* in: values in form */
  int num,			/* in: size of above arrays */
  void (*callback)(char *,int)	/* in: callback to call with data */
#endif
);


#endif /* _HTTP_H */