1 #pragma warning(disable : 4789)
2 #pragma warning(disable : 4786)
4 #include "parsedhttprequest.h"
7 inline std::string & trimleft_inplace(std::string & s)
9 s.erase(0, s.find_first_not_of(
" \t\n\r"));
15 inline std::string & trimright_inplace(std::string & s)
17 size_t idx = s.find_last_not_of(
" \t\n\r");
19 if (std::string::npos == idx)
26 s.erase(idx, std::string::npos);
33 inline std::string & trim_inplace(std::string & s)
40 inline std::string trim_tonew(
const std::string &in)
43 return trim_inplace(ss);
49 std::string ParsedHttpRequest::deCanonicalize(std::string &inval)
53 while (x < inval.size())
63 if(x+2 < inval.size())
71 char c = ( char ) strtoul(aa,&end,16);
86 size_t ParsedHttpRequest::PullCR(std::string &src, std::string &dst)
88 size_t offset = src.find(
' ');
91 dst = src.substr(0,offset);
92 src = src.substr(offset+1);
98 void ParsedHttpRequest::clear(
void)
104 const std::string * ParsedHttpRequest::GetOption(
const std::string & query)
106 std::map<std::string,std::string>::iterator ii;
107 ii = _parameters.find(query);
108 if(ii == _parameters.end())
115 bool ParsedHttpRequest::GetOption(
const std::string & query, std::string & out_value)
117 std::map<std::string,std::string>::iterator ii;
118 ii = _parameters.find(query);
119 if(ii == _parameters.end())
124 out_value = ii->second;
128 bool ParsedHttpRequest::ParseThis(
char * request)
134 std::string work1(_Raw_Text);
135 for(
size_t pos = work1.find_first_of(
"\n\r\0") ; pos != std::string::npos ; pos = work1.find_first_of(
"\n\r\0") )
137 std::string line1 = work1.substr(0,pos);
138 work1 = work1.substr(pos+1);
142 size_t i_pos = line1.find(
':');
143 if(i_pos != std::string::npos && i_pos > 1)
145 std::string noune = trim_tonew(line1.substr(0,i_pos));
146 std::string verb = trim_tonew(line1.substr(i_pos+1));
149 _header_Lines[noune] = verb;
158 std::string work(request);
159 std::string line1 = work.substr(0,work.find_first_of(
"\n\r\0"));
163 if(PullCR(line1,_RequestType) < 3)
166 if(PullCR(line1,_RequestText) < 1)
169 size_t loc = (int)_RequestText.find(
'?');
170 if(loc != std::string::npos)
172 _Requestoptions = _RequestText.substr(loc+1);
173 _RequestText = _RequestText.substr(0,loc);
176 return ProcessOptionString(_Requestoptions);
179 std::string & ParsedHttpRequest::GetRequestURL(
void)
184 bool ParsedHttpRequest::ProcessOptionString(std::string str)
187 for(loc = str.find(
'&'); loc != std::string::npos; loc = str.find(
'&'))
189 std::string valset = str.substr(0,loc);
190 str = str.substr(loc+1);
191 if(ProcessParamSet(valset) !=
true)
194 return ProcessParamSet(str);
197 bool ParsedHttpRequest::ProcessParamSet(std::string &str)
200 size_t loc = str.find(
'=');
202 if(loc != std::string::npos)
204 val = str.substr(loc+1);
205 str = str.substr(0,loc);
207 std::string ind1 = deCanonicalize(str);
208 _parameters[ind1] = deCanonicalize(val);