-
Notifications
You must be signed in to change notification settings - Fork 1
/
HTTPClient.c
66 lines (54 loc) · 1.18 KB
/
HTTPClient.c
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
#include "HTTPClient.h"
#include "Mem.h"
void HTTP_clear(HTTPTransaction ** t)
{
if ((*t)->comm) {
Comm_free(&((*t)->comm));
}
Mem_free(*t);
*t = NULL;
}
void HTTP_init_get(HTTPTransaction ** t, String * url)
{
if (t) {
fprintf(stderr, "%s: warning, stale transaction struct lost\n", __func__);
}
*t = Mem_calloc(1, sizeof(HTTPTransaction *));
(*t)->comm = Comm_new(s(url));
(*t)->code = 0;
(*t)->state = HTTP_STATE_GET_XMIT;
}
void HTTP_init_put(HTTPTransaction ** t, String * url, ArrayU8 * postdata)
{
}
void HTTP_process(HTTPTransaction * t)
{
#if 0
// In progress, commented out so I can work on other code.
//HTTP_STATE_NONE,
//HTTP_STATE_INIT,
//HTTP_STATE_ACTIVE,
//HTTP_STATE_COMPLETE,
if (t->comm->state == IO_CLOSED) {
t->code = 500;
t->state = HTTP_STATE_COMPLETE;
return;
}
if (t->state == HTTP_STATE_NONE) {
/* FIXME: Error. Sleep and return? */
}
else if (t->state == HTTP_STATE_COMPLETE) {
/* Nothing to do. */
}
else if (t->state == HTTP_STATE_GET_XMIT) {
// ...
}
else if (t->state == HTTP_STATE_POST_XMIT) {
// ...
}
#endif
}
int HTTP_state(HTTPTransaction * t)
{
return (t->state);
}