-
Notifications
You must be signed in to change notification settings - Fork 1
/
ghttp.h
executable file
·263 lines (201 loc) · 5.45 KB
/
ghttp.h
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* ghttp.h -- A public interface to common http functions
* Created: Christopher Blizzard <blizzard@appliedtheory.com>, 21-Aug-1998
*
* Copyright (C) 1998 Free Software Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef GHTTP_H
#define GHTTP_H
#include "ghttp_constants.h"
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _ghttp_request ghttp_request;
typedef enum ghttp_type_tag
{
ghttp_type_get = 0,
ghttp_type_options,
ghttp_type_head,
ghttp_type_post,
ghttp_type_put,
ghttp_type_delete,
ghttp_type_trace,
ghttp_type_connect,
ghttp_type_propfind,
ghttp_type_proppatch,
ghttp_type_mkcol,
ghttp_type_copy,
ghttp_type_move,
ghttp_type_lock,
ghttp_type_unlock
} ghttp_type;
typedef enum ghttp_sync_mode_tag
{
ghttp_sync = 0,
ghttp_async
} ghttp_sync_mode;
typedef enum ghttp_status_tag
{
ghttp_error = -1,
ghttp_not_done,
ghttp_done
} ghttp_status;
typedef enum ghttp_proc_tag
{
ghttp_proc_none = 0,
ghttp_proc_request,
ghttp_proc_response_hdrs,
ghttp_proc_response
} ghttp_proc;
typedef struct ghttp_current_status_tag
{
ghttp_proc proc; /* what's it doing? */
int bytes_read; /* how many bytes have been read? */
int bytes_total; /* how many total */
} ghttp_current_status;
/* create a new request object */
ghttp_request *
ghttp_request_new(void);
/* delete a current request object */
void
ghttp_request_destroy(ghttp_request *a_request);
/* Validate a uri
* This will return -1 if a uri is invalid
*/
int
ghttp_uri_validate(char *a_uri);
/* Set a uri in a request
* This will return -1 if the uri is invalid
*/
int
ghttp_set_uri(ghttp_request *a_request, char *a_uri);
/* Set a proxy for a request
* This will return -1 if the uri is invalid
*/
int
ghttp_set_proxy(ghttp_request *a_request, char *a_uri);
/* Set a request type
* This will return -1 if the request type is invalid or
* unsupported
*/
int
ghttp_set_type(ghttp_request *a_request, ghttp_type a_type);
/* Set the body.
* This will return -1 if the request type doesn't support it
*/
int
ghttp_set_body(ghttp_request *a_request, char *a_body, int a_len);
/* Set whether or not you want to use sync or async mode.
*/
int
ghttp_set_sync(ghttp_request *a_request,
ghttp_sync_mode a_mode);
/* Prepare a request.
* Call this before trying to process a request or if you change the
* uri.
*/
int
ghttp_prepare(ghttp_request *a_request);
/* Set the chunk size
* You might want to do this to optimize for different connection speeds.
*/
void
ghttp_set_chunksize(ghttp_request *a_request, int a_size);
/* Set a random request header
*/
void
ghttp_set_header(ghttp_request *a_request,
const char *a_hdr, const char *a_val);
/* Process a request
*/
ghttp_status
ghttp_process(ghttp_request *a_request);
/* Get the status of a request
*/
ghttp_current_status
ghttp_get_status(ghttp_request *a_request);
/* Flush the received data (so far) into the response body. This is
* useful for asynchronous requests with large responses: you can
* periodically flush the response buffer and parse the data that's
* arrived so far.
*/
void
ghttp_flush_response_buffer(ghttp_request *a_request);
/* Get the value of a random response header
*/
const char *
ghttp_get_header(ghttp_request *a_request,
const char *a_hdr);
/* Get the list of headers that were returned in the response. You
must free the returned string values. This function will return 0
on success, -1 on some kind of error. */
int
ghttp_get_header_names(ghttp_request *a_request,
char ***a_hdrs, int *a_num_hdrs);
/* Abort a currently running request. */
int
ghttp_close(ghttp_request *a_request);
/* Clean a request
*/
void
ghttp_clean(ghttp_request *a_request);
/* Get the socket associated with a particular connection
*/
int
ghttp_get_socket(ghttp_request *a_request);
/* get the return entity body
*/
char *
ghttp_get_body(ghttp_request *a_request);
/* get the returned length
*/
int
ghttp_get_body_len(ghttp_request *a_request);
/* Get an error message for a request that has failed.
*/
const char *
ghttp_get_error(ghttp_request *a_request);
/* Parse a date string that is one of the standard
* date formats
*/
time_t
ghttp_parse_date(char *a_date);
/* Return the status code.
*/
int
ghttp_status_code(ghttp_request *a_request);
/* Return the reason phrase.
*/
const char *
ghttp_reason_phrase(ghttp_request *a_request);
/* Set your username/password pair
*/
int
ghttp_set_authinfo(ghttp_request *a_request,
const char *a_user,
const char *a_pass);
/* Set your username/password pair for proxy
*/
int
ghttp_set_proxy_authinfo(ghttp_request *a_request,
const char *a_user,
const char *a_pass);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* GHTTP_H */