mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
use BSONObj for params so order is preserved
This commit is contained in:
parent
81ff09077c
commit
0797f88800
@ -364,7 +364,7 @@ namespace mongo {
|
||||
string coll = url.substr( first + 1 );
|
||||
string action = "";
|
||||
|
||||
map<string,string> params;
|
||||
BSONObj params;
|
||||
if ( coll.find( "?" ) != string::npos ) {
|
||||
parseParams( params , coll.substr( coll.find( "?" ) + 1 ) );
|
||||
coll = coll.substr( 0 , coll.find( "?" ) );
|
||||
@ -410,26 +410,29 @@ namespace mongo {
|
||||
responseMsg = ss.str();
|
||||
}
|
||||
|
||||
void handleRESTQuery( string ns , string action , map<string,string> & params , int & responseCode , stringstream & out ) {
|
||||
void handleRESTQuery( string ns , string action , BSONObj & params , int & responseCode , stringstream & out ) {
|
||||
Timer t;
|
||||
|
||||
int skip = _getOption( params["skip"] , 0 );
|
||||
int num = _getOption( params["limit"] , _getOption( params["count" ] , 1000 ) ); // count is old, limit is new
|
||||
|
||||
int one = 0;
|
||||
if ( params["one"].size() > 0 && tolower( params["one"][0] ) == 't' ) {
|
||||
if ( params["one"].type() == String && tolower( params["one"].valuestr()[0] ) == 't' ) {
|
||||
num = 1;
|
||||
one = 1;
|
||||
}
|
||||
|
||||
BSONObjBuilder queryBuilder;
|
||||
|
||||
for ( map<string,string>::iterator i = params.begin(); i != params.end(); i++ ) {
|
||||
if ( ! i->first.find( "filter_" ) == 0 )
|
||||
BSONObjIterator i(params);
|
||||
while ( i.more() ){
|
||||
BSONElement e = i.next();
|
||||
string name = e.fieldName();
|
||||
if ( ! name.find( "filter_" ) == 0 )
|
||||
continue;
|
||||
|
||||
const char * field = i->first.substr( 7 ).c_str();
|
||||
const char * val = i->second.c_str();
|
||||
const char * field = name.substr( 7 ).c_str();
|
||||
const char * val = e.valuestr();
|
||||
|
||||
char * temp;
|
||||
|
||||
@ -477,7 +480,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
// TODO Generate id and revision per couch POST spec
|
||||
void handlePost( string ns, const char *body, map<string,string> & params, int & responseCode, stringstream & out ) {
|
||||
void handlePost( string ns, const char *body, BSONObj& params, int & responseCode, stringstream & out ) {
|
||||
try {
|
||||
BSONObj obj = fromjson( body );
|
||||
db.insert( ns.c_str(), obj );
|
||||
@ -491,10 +494,12 @@ namespace mongo {
|
||||
out << "{ \"ok\" : true }";
|
||||
}
|
||||
|
||||
int _getOption( string val , int def ) {
|
||||
if ( val.size() == 0 )
|
||||
return def;
|
||||
return atoi( val.c_str() );
|
||||
int _getOption( BSONElement e , int def ) {
|
||||
if ( e.isNumber() )
|
||||
return e.numberInt();
|
||||
if ( e.type() == String )
|
||||
return atoi( e.valuestr() );
|
||||
return def;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -82,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;
|
||||
@ -104,9 +105,10 @@ namespace mongo {
|
||||
if ( eq == string::npos )
|
||||
continue;
|
||||
|
||||
params[urlDecode(cur.substr(0,eq))] = urlDecode(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 ) {
|
||||
|
@ -17,7 +17,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "message.h"
|
||||
#include "../db/jsobj.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -45,7 +47,7 @@ namespace mongo {
|
||||
string parseURL( const char * buf );
|
||||
string parseMethod( const char * headers );
|
||||
string getHeader( const char * headers , string name );
|
||||
void parseParams( map<string,string> & params , string query );
|
||||
void parseParams( BSONObj & params , string query );
|
||||
static const char *body( const char *buf );
|
||||
|
||||
static string urlDecode(const char* s);
|
||||
|
Loading…
Reference in New Issue
Block a user