-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockfcgi.c
93 lines (84 loc) · 2.14 KB
/
mockfcgi.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
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
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "mockfcgi.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
char *FCGX_GetParam(const char *name, FCGX_ParamArray envp) {
int p;
for (p = 0; envp->param[p]; p += 2) {
if (strcmp(name, envp->param[p])) {
return envp->param[p + 1];
}
}
return 0;
}
int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...) {
assert(stream);
assert(format);
return 0;
}
int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream) {
assert(str);
assert(n >= 0);
assert(stream);
return 0;
}
int FCGX_GetStr(char *str, int n, FCGX_Stream *stream) {
assert(str);
assert(n >= 0);
assert(stream);
return 0;
}
FCGX_Stream *FCGM_CreateStream(const void *data, size_t size) {
FCGX_Stream *strm = malloc(sizeof(FCGX_Stream));
if (!strm) {
return NULL;
}
if (!size) {
strm->data = 0;
}
else {
strm->data = malloc(size);
if (!strm->data) {
free(strm);
return NULL;
}
memcpy(strm->data, data, size);
}
strm->pos = strm->data;
strm->length = size;
return strm;
}
FCGX_Request *FCGM_CreateRequest(const char *body, const char *env) {
FCGX_Request *req = malloc(sizeof(FCGX_Request));
char *tok;
if (*env) {
int p;
size_t len = strlen(env) + 1;
req->envp = malloc(sizeof(struct FCGX_ParamArray));
req->envp->paramstr = malloc(len);
memcpy(req->envp->paramstr, env, len);
// strcpy(req->envp->paramstr, env);
tok = strtok(req->envp->paramstr, "=");
for (p=0; tok && p != MAXPARAM;p+=2) {
req->envp->param[p] = tok;
if (tok) {
tok = strtok(NULL, " ");
req->envp->param[p+1] = tok;
assert(tok);
tok = strtok(NULL, "=");
}
}
if (p < MAXPARAM) {
req->envp->param[p] = 0;
}
}
else {
req->envp = 0;
}
req->out = FCGM_CreateStream(NULL, 0);
req->in = FCGM_CreateStream(body, strlen(body));
return req;
}