get_body.c
1013 Bytes
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
#include <stdlib.h>
#include "http/header.h"
#include "http/message.h"
#include "http/request/parser.h"
#include "cbuf.h"
#define MAX(a,b) (((a) > (b))? (a) : (b))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
/**
* @TODO: not final...input buffer handling not final
*/
void
httpRequestParserGetBody(HttpRequestParser this)
{
HttpMessage message = (HttpMessage)(this->cur_request);
size_t len;
if (0 == message->nbody) {
char * nbody = httpHeaderGet(
&(message->header),
"Content-Length");
if (NULL == nbody) {
this->state = HTTP_REQUEST_DONE;
return;
}
else {
message->type = HTTP_MESSAGE_BUFFERED;
message->nbody = atoi(nbody);
message->body = calloc(1, message->nbody);
message->dbody = 0;
}
}
this->buffer->bused -= len;
if (message->dbody < message->nbody) {
len = MAX(
message->nbody - message->dbody,
this->buffer->bused);
memcpy(message->body, cbufGetData(this->buffer, len), len);
message->dbody += len;
}
}
// vim: set ts=4 sw=4: