+
+ // HTTPResponse methods
+
+ void setResponseHeader(const char* name, const char* value) {
+ m_headers[name] = value ? value : "";
+ }
+
+ // The amount of error checking missing from this is incredible, but as long
+ // as the test data isn't unexpected or malformed, it should work.
+
+ long sendRedirect(const char* url) {
+ m_method = "GET";
+ char* dup = strdup(url);
+ char* pch = strchr(dup,'?');
+ if (pch) {
+ *pch++=0;
+ m_query = pch;
+ char* name=pch;
+ while (name && *name) {
+ pch=strchr(pch,'=');
+ *pch++=0;
+ char* value=pch;
+ pch=strchr(pch,'&');
+ if (pch)
+ *pch++=0;
+ XMLToolingConfig::getConfig().getURLEncoder()->decode(value);
+ m_fields[name] = value;
+ name = pch;
+ }
+ }
+ m_url = dup;
+ free(dup);
+ return m_fields.size();
+ }
+
+ string html_decode(const string& s) const {
+ string decoded;
+ const char* ch=s.c_str();
+ while (*ch) {
+ if (*ch=='&') {
+ if (!strncmp(ch,"<",4)) {
+ decoded+='<'; ch+=4;
+ }
+ else if (!strncmp(ch,">",4)) {
+ decoded+='>'; ch+=4;
+ }
+ else if (!strncmp(ch,""",6)) {
+ decoded+='"'; ch+=6;
+ }
+ else if (*++ch=='#') {
+ decoded+=(char)atoi(++ch);
+ ch=strchr(ch,';')+1;
+ }
+ }
+ else {
+ decoded+=*ch++;
+ }
+ }
+ return decoded;
+ }
+
+ using HTTPResponse::sendResponse;
+
+ long sendResponse(std::istream& inputStream, long status) {
+ m_method="POST";
+ string page,line;
+ while (getline(inputStream,line))
+ page += line + '\n';
+
+ const char* pch=strstr(page.c_str(),"action=\"");
+ pch+=strlen("action=\"");
+ m_url = html_decode(page.substr(pch-page.c_str(),strchr(pch,'"')-pch));
+
+ while ((pch = strstr(pch,"<input type=\"hidden\" name=\""))) {
+ pch+=strlen("<input type=\"hidden\" name=\"");
+ string name = page.substr(pch-page.c_str(),strchr(pch,'"')-pch);
+ pch=strstr(pch,"value=\"");
+ pch+=strlen("value=\"");
+ m_fields[name] = html_decode(page.substr(pch-page.c_str(),strchr(pch,'"')-pch));
+ }
+ return m_fields.size();
+ }