FS-5921 --resolve mod_mongo: use jsonString() instead of toString(), tabs instead of spaces

This commit is contained in:
Chris Rienzo
2013-11-04 14:28:07 -05:00
parent ad8796f581
commit 381caad87f
3 changed files with 157 additions and 158 deletions
+50 -50
View File
@@ -1,6 +1,6 @@
/*
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2013, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -22,7 +22,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Tamas Cseke <cstomi.levlist@gmail.com>
*
* mod_mongo.cpp -- API for MongoDB
@@ -53,7 +53,7 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
switch_assert(ns != NULL);
if ((json_query = strchr(ns, DELIMITER))) {
*json_query++ = '\0';
*json_query++ = '\0';
}
if (!zstr(ns) && !zstr(json_query)) {
@@ -82,7 +82,7 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
conn->runCommand(conn->nsGetDB(ns), cmd.done(), out);
mongo_connection_pool_put(globals.conn_pool, conn, SWITCH_FALSE);
stream->write_function(stream, "-OK\n%s\n", out.toString().c_str());
stream->write_function(stream, "-OK\n%s\n", out.jsonString().c_str());
} else {
stream->write_function(stream, "-ERR\nNo connection\n");
}
@@ -93,7 +93,7 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
stream->write_function(stream, "-ERR\n%s\n", e.toString().c_str());
}
} else {
stream->write_function(stream, "-ERR\n%s\n", MAPREDUCE_SYNTAX);
stream->write_function(stream, "-ERR\n%s\n", MAPREDUCE_SYNTAX);
}
switch_safe_free(ns);
@@ -104,50 +104,50 @@ SWITCH_STANDARD_API(mongo_mapreduce_function)
SWITCH_STANDARD_API(mongo_find_one_function)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *ns = NULL, *json_query = NULL, *json_fields = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *ns = NULL, *json_query = NULL, *json_fields = NULL;
ns = strdup(cmd);
switch_assert(ns != NULL);
ns = strdup(cmd);
switch_assert(ns != NULL);
if ((json_query = strchr(ns, DELIMITER))) {
*json_query++ = '\0';
if ((json_fields = strchr(json_query, DELIMITER))) {
*json_fields++ = '\0';
}
}
if ((json_query = strchr(ns, DELIMITER))) {
*json_query++ = '\0';
if ((json_fields = strchr(json_query, DELIMITER))) {
*json_fields++ = '\0';
}
}
if (!zstr(ns) && !zstr(json_query) && !zstr(json_fields)) {
if (!zstr(ns) && !zstr(json_query) && !zstr(json_fields)) {
DBClientBase *conn = NULL;
DBClientBase *conn = NULL;
try {
BSONObj query = fromjson(json_query);
BSONObj fields = fromjson(json_fields);
try {
BSONObj query = fromjson(json_query);
BSONObj fields = fromjson(json_fields);
conn = mongo_connection_pool_get(globals.conn_pool);
if (conn) {
BSONObj res = conn->findOne(ns, Query(query), &fields);
mongo_connection_pool_put(globals.conn_pool, conn, SWITCH_FALSE);
conn = mongo_connection_pool_get(globals.conn_pool);
if (conn) {
BSONObj res = conn->findOne(ns, Query(query), &fields);
mongo_connection_pool_put(globals.conn_pool, conn, SWITCH_FALSE);
stream->write_function(stream, "-OK\n%s\n", res.toString().c_str());
} else {
stream->write_function(stream, "-ERR\nNo connection\n");
}
} catch (DBException &e) {
if (conn) {
mongo_connection_pool_put(globals.conn_pool, conn, SWITCH_TRUE);
}
stream->write_function(stream, "-ERR\n%s\n", e.toString().c_str());
}
stream->write_function(stream, "-OK\n%s\n", res.jsonString().c_str());
} else {
stream->write_function(stream, "-ERR\nNo connection\n");
}
} catch (DBException &e) {
if (conn) {
mongo_connection_pool_put(globals.conn_pool, conn, SWITCH_TRUE);
}
stream->write_function(stream, "-ERR\n%s\n", e.toString().c_str());
}
} else {
} else {
stream->write_function(stream, "-ERR\n%s\n", FIND_ONE_SYNTAX);
}
}
switch_safe_free(ns);
switch_safe_free(ns);
return status;
return status;
}
static switch_status_t config(void)
@@ -214,21 +214,21 @@ SWITCH_MODULE_DEFINITION(mod_mongo, mod_mongo_load, mod_mongo_shutdown, NULL);
SWITCH_MODULE_LOAD_FUNCTION(mod_mongo_load)
{
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
memset(&globals, 0, sizeof(globals));
memset(&globals, 0, sizeof(globals));
if (config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
SWITCH_ADD_API(api_interface, "mongo_find_one", "findOne", mongo_find_one_function, FIND_ONE_SYNTAX);
SWITCH_ADD_API(api_interface, "mongo_mapreduce", "Map/Reduce", mongo_mapreduce_function, MAPREDUCE_SYNTAX);
if (config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
return SWITCH_STATUS_SUCCESS;
SWITCH_ADD_API(api_interface, "mongo_find_one", "findOne", mongo_find_one_function, FIND_ONE_SYNTAX);
SWITCH_ADD_API(api_interface, "mongo_mapreduce", "Map/Reduce", mongo_mapreduce_function, MAPREDUCE_SYNTAX);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_mongo_shutdown)