Module: kamailio
Branch: master
Commit: dcce311f4fd4a3a330d80294fc1137b66ea1f7d9
URL:
https://github.com/kamailio/kamailio/commit/dcce311f4fd4a3a330d80294fc1137b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-04-17T15:46:06+02:00
ndb_mongodb: exported inter-module api
---
Added: modules/ndb_mongodb/api.h
Modified: modules/ndb_mongodb/mongodb_client.c
Modified: modules/ndb_mongodb/ndb_mongodb_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/dcce311f4fd4a3a330d80294fc1137b…
Patch:
https://github.com/kamailio/kamailio/commit/dcce311f4fd4a3a330d80294fc1137b…
---
diff --git a/modules/ndb_mongodb/api.h b/modules/ndb_mongodb/api.h
new file mode 100644
index 0000000..4ffd43f
--- /dev/null
+++ b/modules/ndb_mongodb/api.h
@@ -0,0 +1,69 @@
+/**
+ * ndb_mongodb module
+ *
+ * Copyright (C) 2015 Daniel-Constantin Mierla (
asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef _NDB_MONGODB_API_H_
+#define _NDB_MONGODB_API_H_
+
+#include "../../sr_module.h"
+
+typedef int (*mongodbc_exec_simple_f)(str *srv, str *dname, str *cname, str *cmd, str
*res);
+typedef int (*mongodbc_exec_f)(str *srv, str *dname, str *cname, str *cmd, str *res);
+typedef int (*mongodbc_find_f)(str *srv, str *dname, str *cname, str *cmd, str *res);
+typedef int (*mongodbc_find_one_f)(str *srv, str *dname, str *cname, str *cmd, str
*res);
+typedef int (*mongodbc_next_reply_f)(str *name);
+typedef int (*mongodbc_free_reply_f)(str *name);
+
+
+typedef struct ndb_mongodb_api {
+ mongodbc_exec_simple_f cmd_simple;
+ mongodbc_exec_f cmd;
+ mongodbc_find_f find;
+ mongodbc_find_one_f find_one;
+ mongodbc_next_reply_f next_reply;
+ mongodbc_next_reply_f free_reply;
+} ndb_mongodb_api_t;
+
+typedef int (*bind_ndb_mongodb_f)(ndb_mongodb_api_t* api);
+int bind_ndb_mongodb(ndb_mongodb_api_t* api);
+
+/**
+ * @brief Load the dispatcher API
+ */
+static inline int ndb_mongodb_load_api(ndb_mongodb_api_t *api)
+{
+ bind_ndb_mongodb_f bindndbmongodb;
+
+ bindndbmongodb = (bind_ndb_mongodb_f)find_export("bind_ndb_mongodb", 0, 0);
+ if(bindndbmongodb == 0) {
+ LM_ERR("cannot find bind_ndb_mongodb\n");
+ return -1;
+ }
+ if(bindndbmongodb(api)<0)
+ {
+ LM_ERR("cannot bind ndb mongodb api\n");
+ return -1;
+ }
+ return 0;
+}
+
+#endif
diff --git a/modules/ndb_mongodb/mongodb_client.c b/modules/ndb_mongodb/mongodb_client.c
index 5b82c44..5765a1a 100644
--- a/modules/ndb_mongodb/mongodb_client.c
+++ b/modules/ndb_mongodb/mongodb_client.c
@@ -32,6 +32,7 @@
#include "../../ut.h"
#include "mongodb_client.h"
+#include "api.h"
static mongodbc_server_t *_mongodbc_srv_list=NULL;
@@ -489,3 +490,25 @@ int mongodbc_next_reply(str *name)
LM_DBG("next cursor result: [[%s]]\n",
(rpl->jsonrpl.s)?rpl->jsonrpl.s:"<null>");
return 0;
}
+
+/**
+ *
+ */
+int bind_ndb_mongodb(ndb_mongodb_api_t* api)
+{
+ if (!api) {
+ ERR("Invalid parameter value\n");
+ return -1;
+ }
+
+ memset(api, 0, sizeof(ndb_mongodb_api_t));
+ api->cmd = mongodbc_exec;
+ api->cmd_simple = mongodbc_exec_simple;
+ api->find = mongodbc_find;
+ api->find_one = mongodbc_find_one;
+ api->next_reply = mongodbc_next_reply;
+ api->free_reply = mongodbc_free_reply;
+
+ return 0;
+}
+
diff --git a/modules/ndb_mongodb/ndb_mongodb_mod.c
b/modules/ndb_mongodb/ndb_mongodb_mod.c
index 25c7fef..775ff6f 100644
--- a/modules/ndb_mongodb/ndb_mongodb_mod.c
+++ b/modules/ndb_mongodb/ndb_mongodb_mod.c
@@ -31,6 +31,7 @@
#include "../../trim.h"
#include "mongodb_client.h"
+#include "api.h"
MODULE_VERSION
@@ -76,6 +77,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE},
{"mongodb_next", (cmd_function)w_mongodb_next_reply, 1, fixup_spve_null,
0, ANY_ROUTE},
+ {"bind_ndb_mongodb", (cmd_function)bind_ndb_mongodb, 0,
+ 0, 0, 0},
{0, 0, 0, 0, 0, 0}
};