18 |
|
program = argv[0]; |
19 |
|
|
20 |
|
int port(8080); |
21 |
< |
bool daemon(false), redirector(false); |
21 |
> |
bool fork(false), daemon(false), redirector(false); |
22 |
|
string redirect; |
23 |
|
|
24 |
|
for (int index(1); index < argc; ++index) |
26 |
|
string arg(argv[index]); |
27 |
|
Matcher matcher; |
28 |
|
|
29 |
< |
if (arg == "-D") |
30 |
< |
{ |
31 |
< |
if (!debug) debug = true; |
32 |
< |
} |
33 |
< |
else if (arg == "-daemon") |
29 |
> |
if (arg == "-daemon") |
30 |
|
{ |
31 |
|
if (!daemon) daemon = true; |
32 |
|
} |
40 |
|
{ |
41 |
|
port = lexical_cast<int>(matcher[1]); |
42 |
|
} |
43 |
+ |
else if (arg == "-fork") |
44 |
+ |
{ |
45 |
+ |
if (!fork) fork = true; |
46 |
+ |
} |
47 |
+ |
else if (arg == "-D") |
48 |
+ |
{ |
49 |
+ |
if (!debug) debug = true; |
50 |
+ |
} |
51 |
+ |
else |
52 |
+ |
{ |
53 |
+ |
cout << "Usage: " << program << " [-daemon|-redirector=redirect] [" |
54 |
+ |
<< "-port=port] [-fork] [-D]\n"; |
55 |
+ |
|
56 |
+ |
return 1; |
57 |
+ |
} |
58 |
|
} |
59 |
|
|
60 |
|
if (daemon) |
61 |
|
{ |
62 |
< |
Daemon daemon(port); |
62 |
> |
Daemon daemon(port, fork); |
63 |
|
} |
64 |
|
else if (redirector) |
65 |
|
{ |
66 |
< |
Redirector redirector(port, redirect); |
66 |
> |
Redirector redirector(port, fork, redirect); |
67 |
|
} |
68 |
|
else |
69 |
|
{ |
81 |
|
|
82 |
|
void Smersh::parse(istream& sin) |
83 |
|
{ |
84 |
< |
string query(sgetenv("QUERY_STRING")); |
84 |
> |
stringstream query(sgetenv("QUERY_STRING")); |
85 |
|
|
86 |
< |
if (sgetenv("REQUEST_METHOD") == "POST") getline(sin, query); |
87 |
< |
if (query == "") return; |
86 |
> |
if (sgetenv("REQUEST_METHOD") == "POST") |
87 |
> |
{ |
88 |
> |
streamsize length(lexical_cast<streamsize>(sgetenv("CONTENT_LENGTH"))); |
89 |
> |
char* content = new char[length]; |
90 |
|
|
91 |
< |
istringstream input(query); |
91 |
> |
sin.read(content, length); |
92 |
> |
query.write(content, length); |
93 |
> |
|
94 |
> |
delete [] content; |
95 |
> |
} |
96 |
> |
if (query.str() == "") return; |
97 |
|
|
98 |
|
do |
99 |
|
{ |
100 |
|
string name, value; |
101 |
|
|
102 |
< |
getline(input, name, '='); |
103 |
< |
getline(input, value, '&'); |
102 |
> |
getline(query, name, '='); |
103 |
> |
getline(query, value, '&'); |
104 |
|
|
105 |
|
cgi.insert(pair<string, string>(name, value)); |
106 |
|
} |
107 |
< |
while (input.good()); |
107 |
> |
while (query.good()); |
108 |
|
} |
109 |
|
|
110 |
|
void Smersh::smersh(ostream& sout) |
120 |
|
|
121 |
|
for (string::size_type index(0); index < sn.length(); ++index) |
122 |
|
{ |
123 |
< |
if (sn[index] == '%' && index + 2 < sn.length()) |
123 |
> |
while (!isalnum(sn[index]) && index < sn.length()) |
124 |
|
{ |
125 |
< |
istringstream code(sn.substr(index + 1, 2)); |
126 |
< |
unsigned short character; |
125 |
> |
if (sn[index] == '%' && index + 2 < sn.length()) |
126 |
> |
{ |
127 |
> |
istringstream code(sn.substr(index + 1, 2)); |
128 |
> |
unsigned short character; |
129 |
|
|
130 |
< |
code.setf(ios_base::hex, ios_base::basefield); |
130 |
> |
code.setf(ios_base::hex, ios_base::basefield); |
131 |
|
|
132 |
< |
code >> character; |
132 |
> |
code >> character; |
133 |
|
|
134 |
< |
sn.replace(index, 3, 1, character); |
135 |
< |
} |
134 |
> |
sn.replace(index, 3, 1, character); |
135 |
> |
|
136 |
> |
if (isalnum(sn[index])) break; |
137 |
> |
} |
138 |
|
|
117 |
– |
while (!isalnum(sn[index]) && index < sn.length()) |
118 |
– |
{ |
139 |
|
sn.erase(index, 1); |
140 |
|
} |
141 |
|
} |