-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadForm.cpp
More file actions
97 lines (88 loc) · 2.41 KB
/
Copy pathReadForm.cpp
File metadata and controls
97 lines (88 loc) · 2.41 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
#include "ReadForm.h"
#include "FilterSearch.h"
#include "Util.h"
ReadForm::ReadForm():body(NULL), areadBytes(0){}
ReadForm::~ReadForm(){
bodyParams.clear();
if(body){
delete[] body;
}
}
bool ReadForm::onReadBodyEvent(const char* buff, size_t n){
if(request->contentType && strcmp(request->contentType, "application/x-www-form-urlencoded")==0){
if(!body){
body = new char[request->contentLength + 1];
}
if(HttpUtils::readBody(body, &areadBytes, request->contentLength, buff, n)){
HttpUtils::parseParameters(body, &bodyParams);
return true;
}
}else{
response->setStatus(400, "Content-Type not is application/x-www-form-urlencoded");
return true;
}
return false;
}
void ReadForm::service(Request& req, Response& resp){
LOG(Util::INFO, "request /search/");
resp.setContentType("text/html; charset=utf-8");
std::vector<string> ret;
/*
const char *content = req.getParameter("content");
string cont2="";
cont2+=content;
string str;
Util::URLDecode(cont2, str);
GentFind f;
f.Search(str, ret);
if(ret.size() > 0) {
for(size_t i=0;i<ret.size();i++) {
resp.write(ret[i].c_str());
resp.write("<br>");
}
}else{
resp.write("not found");
}
return;
*/
vector<const char*> bnames;
bodyParams.getNames(bnames);
int iscontent = 0;
for(vector<const char*>::const_iterator it = bnames.begin(); it != bnames.end(); it++){
if(strncmp(*it, "content",7) != 0) continue;
string cont="";
vector<const char*> pvalues;
bodyParams.gets(*it, pvalues);
for(vector<const char*>::iterator vit = pvalues.begin(); vit != pvalues.end(); vit++){
cont+=*vit;
}
string str;
Util::URLDecode(cont, str);
GentFind f;
f.Search(str, ret);
iscontent = 1;
break;
}
LOG(Util::WARN,"ok");
if(iscontent == 0) {
LOG(Util::WARN,"/search/ not content param");
resp.write("not content param");
return;
}
if(ret.size() > 0) {
string sp = "";
for(size_t i=0;i<ret.size();i++) {
resp.write(sp.c_str());
resp.write(ret[i].c_str());
sp = ",";
}
resp.setAsynAnswerMode(false);
LOG(Util::WARN,"respose over.");
return;
}else{
resp.write("not found");
}
}
const char* ReadForm::value(const char* v){
return v?v:"null";
}