-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCmdProcessor.cpp
More file actions
62 lines (59 loc) · 2.53 KB
/
CmdProcessor.cpp
File metadata and controls
62 lines (59 loc) · 2.53 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
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include "CmdProcessor.h"
filter_map CmdProcessor::filters;
std::map<unsigned int, User*> CmdProcessor::userMap;
std::map<unsigned int, unsigned int> CmdProcessor::acc2connMap;
std::map<unsigned int, unsigned int> CmdProcessor::adminSet;
std::map<unsigned int, std::string> CmdProcessor::disableBuildAccountIdSet;
std::map<unsigned int, unsigned int> CmdProcessor::disableBuildConnIdSet;
void CmdProcessor::init() {
//filters[onDisableBuild] = new std::regex("\\b(GET /disableBuild?id=)([^\r]+)");
//filters.insert(std::pair<handler_method, std::string>(onDisableBuild, "GET /disableBuild?id="));
filters["GET /disableBuild?id="] = onDisableBuild;
}
void CmdProcessor::process(char* buf, int len) {
std::vector<std::string> vargs;
long unsigned int eqsign, amp, i;
std::string* args;
//std::smatch match;
std::string buffer(buf);
printf("Sv: CmdProcessor: processing received command\r\n");
for(filter_iterator iter = filters.begin(); iter != filters.end(); ++iter) {
// function = iterator->first = key
// regex = iterator->second = value
//std::regex re = iter->second;
/*
if (std::regex_search(buf, match, iter->second)) {
// The first sub_match is the whole string; the next
// sub_match is the first parenthesized expression.
if (match.size() == 0) continue;
string args[] = new string[match.size()];
for(int i = 0; i < match.size(); ++i) {
args[i] = match[i].str();
}
iterator->first(match.size(), args);
break;
}
*/
std::string pattern = iter->first;
std::string param;
if(std::string::npos != buffer.find(pattern)) {
printf("Sv: CmdProcessor: found matching command handler\r\n");
buffer = buffer.substr(0, buffer.find("HTTP/")) + "\0";
amp = 0;
do {
eqsign = buffer.find("=", amp, 1);
amp = buffer.find("&", eqsign + 1, 1);
vargs.push_back(buffer.substr(eqsign + 1, amp) + "\0");
printf("Sv: CmdProcessor: %s\r\n", (buffer.substr(eqsign + 1, amp) + "\0").c_str());
} while(amp ^ std::string::npos);
args = new std::string[vargs.size()];
for(i = 0; i < vargs.size(); ++i)
args[i] = vargs.at(i);
printf("Sv: CmdProcessor: calling handler function\r\n");
iter->second(vargs.size(), args);
}
}
}