to_string.c
1.03 KB
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
#include <search.h>
#include <string.h>
#include <stdio.h>
#include "http/response.h"
#include "http/header.h"
static char * string;
void
addHeaderString(const void * node, const VISIT which, const int depth)
{
if (endorder == which || leaf == which) {
string += httpHeaderToString(*(HttpHeader *)node, string);
*string++ = '\r';
*string++ = '\n';
}
}
char *
httpResponseToString(HttpResponse response, char * _string)
{
HttpMessage message = (HttpMessage)response;
char status[4];
string = _string;
snprintf(status, 4, "%d", response->status);
strcpy(string, message->version);
string += strlen(string);
*string++ = ' ';
strcpy(string, status);
string += strlen(string);
*string++ = ' ';
strcpy(string, response->reason);
string += strlen(string);
*string++ = '\r';
*string++ = '\n';
twalk(message->header, addHeaderString);
*string++ = '\r';
*string++ = '\n';
if (HTTP_MESSAGE_BUFFERED == message->type) {
memcpy(string, message->body, message->nbody);
}
return string;
}
// vim: set ts=4 sw=4: