diff options
author | Antonin Kral <a.kral@bobek.cz> | 2010-03-25 19:21:32 +0100 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2010-03-25 19:21:32 +0100 |
commit | 0ca01a91ae0a3562e54c226e7b9512feb2ea83d0 (patch) | |
tree | 2b3886e435b0217d6afd63a213b04d32bb4b4f6f /util/miniwebserver.cpp | |
parent | a696359b248adef0cc8576fce3f473535e995136 (diff) | |
download | mongodb-0ca01a91ae0a3562e54c226e7b9512feb2ea83d0.tar.gz |
Imported Upstream version 1.4.0
Diffstat (limited to 'util/miniwebserver.cpp')
-rw-r--r-- | util/miniwebserver.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
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 <pcrecpp.h> @@ -81,12 +82,13 @@ namespace mongo { return string( urlStart , (int)(end-urlStart) ); } - void MiniWebServer::parseParams( map<string,string> & 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 |