-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMygSoapGetProcess.h
212 lines (204 loc) · 4.8 KB
/
MygSoapGetProcess.h
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
FILE* SelectFileCRT(struct soap *soap, FileType ft)
{
FILE *pFile;
switch (ft)
{
// HTTP response header with text/html
case HTML:
{
if (strstr(soap->path, "test"))
{
pFile = OpenReadCRT("./test.htm");
}
else
{
pFile = OpenReadCRT("./index.htm");
}
break;
}
case JS:
{
if (strstr(soap->path, "main"))
{
pFile = OpenReadCRT("./main.js");
}
else
{
pFile = OpenReadCRT("./jquery-1.4.4.min.js");
}
break;
}
case CSS:
{
pFile = OpenReadCRT("./main.css");
break;
}
default:
{
if (rand() % 2 + 1)
{
pFile = OpenReadCRT("./ns.winconfig.req.xml");
}
else
{
pFile = OpenReadCRT("./ns.add.req.xml");
}
}
}
return pFile;
}
HRESULT SendConfigTableCRT(struct soap* pSoap, poutStackBuffer pStack)
{
HRESULT hr = S_OK;
const int BUFFER_SIZE = 128;
FILE *pCfgFile = OpenReadCRT(pszCfgFile);
if (pCfgFile == NULL)
{
return E_FAIL;
}
LPSTR lpBuffer = new CHAR[BUFFER_SIZE];
if (lpBuffer)
{
ZeroMemory(lpBuffer, BUFFER_SIZE);
}
LPCSTR table = "<table id='config'>";
pushStack(pStack, table, strlen(table));
DWORD dwBytesRead = 0;
int state = 0;
do {
dwBytesRead = fread(lpBuffer, sizeof(char), BUFFER_SIZE, pCfgFile);
//CopyMemory(lpHtmlBuffer, lpBuffer, dwBytesRead);
int start = 0;
int indexHtml = 0;
for (int i = 0; i < dwBytesRead; i++)
{
switch (PushStackAsStateChanged(pStack, &state, lpBuffer + i))
{
case 1:
case 3:
{
pushStack(pStack, lpBuffer + i);
}
default:
break;
}
}
if (pStack->index > 0)
{
soap_send_raw(pSoap, pStack->pBuffer, pStack->index);
emptyStack(pStack);
}
} while (!(dwBytesRead < BUFFER_SIZE));
pushStack(pStack, "</table>", strlen("</table>"));
if (lpBuffer)
{
delete[] lpBuffer;
lpBuffer = NULL;
}
fclose(pCfgFile);
return hr;
}
int MyHttpGetCRT(struct soap *soap)
{
const int BUFFER_SIZE = 1024 * 8;
HRESULT hr = S_OK;
DWORD dwBytesRead = 0;
char read_buf[BUFFER_SIZE] = {0};
outStackBuffer bufStack;
initStack(&bufStack, BUFFER_SIZE * 2);
soap_response(soap, SOAP_FILE);
soap->http_content = "text/html; charset=gb2312";
ShowInfo(soap->path);
FileType ft = GetFileType(soap->path);
//hfile = selectfile(soap, ft);
//if (hfile == invalid_handle_value)
//{
// showinfo("get file error!");
// hr = hresult_from_win32(::getlasterror());
//}
FILE *p = SelectFileCRT(soap, ft);
if (p != NULL)
{
ShowInfo("get file success!");
int status = 0;
int pushed = -1;
do {
int start = -1;
int end = -1;
dwBytesRead = fread(read_buf, sizeof(char), BUFFER_SIZE,p);
if (ft == HTML)
{
// search for <% %>
for (int i = 0; i < dwBytesRead; i++)
{
switch (ChangeState(&status, read_buf + i))
{
case 0:
{
while (pushed < i)
{
pushed++;
if (pushed < 0)
{
pushStack(&bufStack, "<");
}
else
{
pushStack(&bufStack, read_buf + pushed);
}
}
break;
}
case 1:
{
if (pushed + 1 < i)
{
pushed++;
if (pushed < 0)
{
pushStack(&bufStack, "<");
}
else
{
pushStack(&bufStack, read_buf + pushed);
}
}
break;
}
case 4:
{
pushed = i;
status = 0;
SendConfigTableCRT(soap, &bufStack);
break;
}
default:
break;
}
}
if (status == 1)
{
pushed -= dwBytesRead;
}
else
{
pushed = -1;
}
if (bufStack.index > 0)
{
soap_send_raw(soap, bufStack.pBuffer, bufStack.index);
emptyStack(&bufStack);
}
}
else
{
soap_send_raw(soap, read_buf, dwBytesRead);
}
} while (!(dwBytesRead < BUFFER_SIZE));
}
soap_end_send(soap);
fclose(p);
WriteLog("MyHttpGet %s", soap->path);
deleteStack(&bufStack);
return SOAP_OK;
}