-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_wsgi.cpp
More file actions
134 lines (104 loc) · 2.29 KB
/
test_wsgi.cpp
File metadata and controls
134 lines (104 loc) · 2.29 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
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "wsgi.h"
using namespace fcgid;
char *g_envp[] = {
"DOCUMENT_ROOT=/home/bce/chenyifei/lighttpd/htdocs/osqa.baidu.com",
"HTTP_HOST=osqa.baidu.com",
"REQUEST_URI=/",
"HTTP_ACCEPT=*/*",
"SCRIPT_FILENAME=/home/bce/chenyifei/lighttpd/htdocs/osqa.baidu.com/index.py",
"SCRIPT_NAME=index.py",
"REQUEST_METHOD=GET",
NULL
};
class MockRequest: public IRequest
{
public:
MockRequest() {
m_envp = g_envp;
}
virtual ~MockRequest() {
}
int GetData(char *buf, int len) {
return len;
}
int PutData(const char *buf, int len) {
char *s = strndup(buf, len);
printf("output1: (%s) \n", s);
free(s);
return len;
}
int PutStr(const char *str) {
printf("output2: (%s)\n", str);
return strlen(str);
}
int FPrintF(const char *fmt, ...) {
int result;
va_list ap;
va_start(ap, fmt);
result = printf(fmt, ap);
va_end(ap);
return result;
}
int FPrintFErr(const char *fmt, ...) {
int result;
va_list ap;
va_start(ap, fmt);
result = fprintf(stderr, fmt, ap);
va_end(ap);
return result;
}
int FlushOut() {
return 0;
}
int PutDataErr(const char *buf, int len) {
char *s = strndup(buf, len);
fprintf(stderr, "output1: (%s) \n", s);
free(s);
return len;
}
int PutStrErr(const char *str) {
fprintf(stderr, "output2: (%s)\n", str);
return strlen(str);
}
int FlushErr() {
return 0;
}
char **GetEnv() {
return m_envp;
}
char* GetParam(const char *name) {
int len;
char **p;
if (name == NULL || m_envp == NULL) return NULL;
len = strlen(name);
for (p = m_envp; *p; ++p) {
if((strncmp(name, *p, len) == 0) && ((*p)[len] == '=')) {
return *p+len+1;
}
}
return NULL;
}
private:
char **m_envp;
};
int main(int argc, char **argv)
{
wsgi_python_init();
int count = 1;
if(argc > 1) {
count = atoi(argv[1]);
}
for(int i = 0; i < count; i++) {
printf("=======================%d test===========================\n", i);
const char *script = "/home/bce/chenyifei/lighttpd/htdocs/osqa.baidu.com/index.py";
MockRequest *r = new MockRequest();
wsgi_execute_script(r, script);
delete r;
printf("=========================================================\n");
}
return 0;
}