From 0ca01a91ae0a3562e54c226e7b9512feb2ea83d0 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Thu, 25 Mar 2010 19:21:32 +0100 Subject: Imported Upstream version 1.4.0 --- util/miniwebserver.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'util/miniwebserver.cpp') diff --git a/util/miniwebserver.cpp b/util/miniwebserver.cpp index b492153..61619d8 100644 --- a/util/miniwebserver.cpp +++ b/util/miniwebserver.cpp @@ -17,6 +17,7 @@ #include "stdafx.h" #include "miniwebserver.h" +#include "hex.h" #include @@ -81,12 +82,13 @@ namespace mongo { return string( urlStart , (int)(end-urlStart) ); } - void MiniWebServer::parseParams( map & params , string query ) { + void MiniWebServer::parseParams( BSONObj & params , string query ) { if ( query.size() == 0 ) return; - + + BSONObjBuilder b; while ( query.size() ) { - + string::size_type amp = query.find( "&" ); string cur; @@ -103,9 +105,10 @@ namespace mongo { if ( eq == string::npos ) continue; - params[cur.substr(0,eq)] = cur.substr(eq+1); + b.append( urlDecode(cur.substr(0,eq)).c_str() , urlDecode(cur.substr(eq+1) ) ); } - return; + + params = b.obj(); } string MiniWebServer::parseMethod( const char * headers ) { @@ -203,7 +206,7 @@ namespace mongo { void MiniWebServer::run() { SockAddr from; - while ( 1 ) { + while ( ! inShutdown() ) { int s = accept(sock, (sockaddr *) &from.sa, &from.addressSize); if ( s < 0 ) { if ( errno == ECONNABORTED ) { @@ -221,4 +224,20 @@ namespace mongo { } } + string MiniWebServer::urlDecode(const char* s){ + stringstream out; + while(*s){ + if (*s == '+'){ + out << ' '; + }else if (*s == '%'){ + out << fromHex(s+1); + s+=2; + }else{ + out << *s; + } + s++; + } + return out.str(); + } + } // namespace mongo -- cgit v1.2.3