[Asterisk-code-review] cel/mongodb: Added mongodb backend for cel (asterisk[master])
Catalin Stanciu
asteriskteam at digium.com
Mon Mar 7 11:54:12 CST 2016
Catalin Stanciu has uploaded a new change for review.
https://gerrit.asterisk.org/2361
Change subject: cel/mongodb: Added mongodb backend for cel
......................................................................
cel/mongodb: Added mongodb backend for cel
The CEL events can be added to the most important
databases. The cel mongodb backend it's intended to cover
the necessity of saving cel events to MongoDB database.
It was used the MongoDB C Driver to implement the
integration.
The module maintain a continuous connection to MongoDB
and when it gets a connection failure it try to connect
again.
* Added cel_mongo.c with the backend implementation.
* Added the MongoDB C Driver to the build architecture
ASTERISK-25831
Reported by: Catalin Stanciu
Tested by: Catalin Stanciu
Change-Id: I8bf4f02fbc6a3a5edd7f10256ea0e14f49193c4f
---
M build_tools/menuselect-deps.in
A cel/cel_mongodb.c
A configs/samples/cel_mongodb.conf.samples
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M makeopts.in
7 files changed, 618 insertions(+), 5 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/2361/1
diff --git a/build_tools/menuselect-deps.in b/build_tools/menuselect-deps.in
index f194482..066bf66 100644
--- a/build_tools/menuselect-deps.in
+++ b/build_tools/menuselect-deps.in
@@ -34,6 +34,7 @@
LUA=@PBX_LUA@
MISDN=@PBX_MISDN@
MYSQLCLIENT=@PBX_MYSQLCLIENT@
+MONGOCLIENT=@PBX_MONGOCLIENT@
NBS=@PBX_NBS@
NETSNMP=@PBX_NETSNMP@
NEWT=@PBX_NEWT@
diff --git a/cel/cel_mongodb.c b/cel/cel_mongodb.c
new file mode 100644
index 0000000..d37b711
--- /dev/null
+++ b/cel/cel_mongodb.c
@@ -0,0 +1,398 @@
+ /*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2015 Catalin [catacs] Stanciu <catacsdev at gmail.com>
+ *
+ * Catalin Stanciu - adapted to MongoDB backend, from:
+ * Steve Murphy <murf at digium.com>
+ * Adapted from the PostgreSQL CEL logger
+ *
+ *
+ * Modified March 2016
+ * Catalin Stanciu <catacsdev at gmail.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+ /*! \file
+ *
+ * \brief MongoDB CEL logger
+ *
+ * \author Catalin Stanciu <catacsdev at gmail.com>
+ * MongoDB https://www.mongodb.org/
+ *
+ * See also
+ * \arg \ref Config_cel
+ * MongoDB https://www.mongodb.org/
+ * \ingroup cel_drivers
+ */
+
+/*** MODULEINFO
+ <depend>mongoclient</depend>
+ <support_level>extended</support_level>
+ ***/
+
+#include "asterisk.h"
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <bson.h>
+#include <bcon.h>
+#include <mongoc.h>
+
+#include "asterisk/config.h"
+#include "asterisk/options.h"
+#include "asterisk/channel.h"
+#include "asterisk/cel.h"
+#include "asterisk/module.h"
+#include "asterisk/logger.h"
+#include "asterisk.h"
+
+#define MONGODB_BACKEND_NAME "CEL MongoDB backend"
+
+static char *config = "cel_mongodb.conf";
+
+static struct ast_event_sub *event_sub = NULL;
+
+static char *hostname = NULL;
+static char *dbname = NULL;
+static char *dbcollection = NULL;
+static char *dbuser = NULL;
+static char *password = NULL;
+static char *dbport = 0;
+
+static int connected = 0;
+static int MAXSIZE = 512;
+
+/*! \brief show_user_def is off by default */
+#define CEL_SHOW_USERDEF_DEFAULT 0
+
+/*! TRUE if we should set the eventtype field to USER_DEFINED on user events. */
+static unsigned char cel_show_user_def;
+
+AST_MUTEX_DEFINE_STATIC(mongodb_lock);
+
+static mongoc_client_t *client;
+
+static void mongodb_reconnect(void) {
+ struct ast_str *dburi = ast_str_create(MAXSIZE);
+ if (!dburi) {
+ ast_log(LOG_ERROR, "Failed to allocate memory for connection string.\n");
+ return;
+ }
+
+ if (client) {
+ mongoc_client_destroy(client);
+ client = NULL;
+ mongoc_cleanup();
+ }
+
+ if (ast_str_strlen(dbuser) && ast_str_strlen(password)) {
+ ast_str_set(&dburi, 0, "mongodb://%s:%s@%s:%s", dbuser, password, hostname, dbport);
+ } else {
+ ast_str_set(&dburi, 0, "mongodb://%s:%s", hostname, dbport);
+ }
+ ast_debug(1, "mongodb_reconnect: Using mongo uri %s.\n", ast_str_buffer(dburi));
+
+ mongoc_init ();
+ client = mongoc_client_new(ast_str_buffer(dburi));
+ ast_free(dburi);
+}
+
+
+static void mongodb_log(struct ast_event *event)
+{
+ mongoc_collection_t *collection;
+ bson_error_t error;
+ bson_oid_t oid;
+ bson_t *doc;
+
+ struct ast_cel_event_record record = {
+ .version = AST_CEL_EVENT_RECORD_VERSION,
+ };
+
+ if (ast_cel_fill_record(event, &record)) {
+ return;
+ }
+
+ ast_debug(1, "mongodb_log: Locking mongodb_lock.\n");
+ ast_mutex_lock(&mongodb_lock);
+
+ if ((!connected) && hostname && dbport) {
+ mongodb_reconnect();
+ if (client) {
+ connected = 1;
+ } else {
+ ast_log(LOG_ERROR, "cel_mongodb: Unable to connect to database server %s. Calls will not be logged!\n", hostname);
+ client = NULL;
+ mongoc_cleanup();
+ }
+ }
+ if (connected) {
+ collection = mongoc_client_get_collection (client, dbname, dbcollection);
+
+ if (!collection) {
+ ast_log(LOG_ERROR, "mongodb_log: Unable to connect to database server %s at colection %s. Calls will not be logged!\n", hostname, dbcollection);
+ return;
+ }
+
+ ast_log(LOG_NOTICE, "mongodb_log: MongoDB event from cell.\n");
+ ast_debug(1, "mongodb_log: Got connection, Preparing document.\n");
+
+ doc = bson_new ();
+ bson_oid_init (&oid, NULL);
+ BSON_APPEND_OID (doc, "_id", &oid);
+ BSON_APPEND_INT32 (doc, "eventtype", record.event_type);
+ BSON_APPEND_DATE_TIME (doc, "eventtime", record.event_time.tv_sec*1000);
+ BSON_APPEND_UTF8 (doc, "cid_name", record.caller_id_name);
+ BSON_APPEND_UTF8 (doc, "cid_num", record.caller_id_num);
+ BSON_APPEND_UTF8 (doc, "cid_ani", record.caller_id_ani);
+ BSON_APPEND_UTF8 (doc, "cid_rdnis", record.caller_id_rdnis);
+ BSON_APPEND_UTF8 (doc, "cid_dnid", record.caller_id_dnid);
+ BSON_APPEND_UTF8 (doc, "exten", record.extension);
+ BSON_APPEND_UTF8 (doc, "context", record.context);
+ BSON_APPEND_UTF8 (doc, "channame", record.channel_name);
+ BSON_APPEND_UTF8 (doc, "appname", record.application_name);
+ BSON_APPEND_UTF8 (doc, "appdata", record.application_data);
+ BSON_APPEND_INT64 (doc, "amaflags", record.amaflag);
+ BSON_APPEND_UTF8 (doc, "accountcode", record.account_code);
+ BSON_APPEND_UTF8 (doc, "peeraccount", record.peer_account);
+ BSON_APPEND_UTF8 (doc, "uniqueid", record.unique_id);
+ BSON_APPEND_UTF8 (doc, "linkedid", record.linked_id);
+ BSON_APPEND_UTF8 (doc, "userfield", record.user_field);
+ BSON_APPEND_UTF8 (doc, "peer", record.peer);
+ if (record.event_type == 0) {
+ BSON_APPEND_INT32 (doc, "userdeftype", record.user_defined_name);
+ }
+ BSON_APPEND_UTF8 (doc, "extra", record.extra);
+ BSON_APPEND_INT32 (doc, "version", record.version);
+
+ ast_debug(1, "Inserting a CEL record.\n");
+ if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {
+ fprintf (stderr, "%s\n", error.message);
+ ast_log(LOG_ERROR, "mongodb_log: MongoDB failed to insert to %s!\n", error.message);
+ }
+
+ bson_destroy (doc);
+ mongoc_collection_destroy(collection);
+ }
+
+ ast_mutex_unlock(&mongodb_lock);
+}
+
+
+static int process_load_module(struct ast_config *cfg)
+{
+ struct ast_variable *var;
+ struct ast_str *dburi = ast_str_create(MAXSIZE);
+ const char *tmp;
+
+ mongoc_collection_t *collection;
+ bson_error_t error;
+
+ if (!(var = ast_variable_browse(cfg, "global"))) {
+ ast_log(LOG_WARNING,"CEL mongodb config file missing global section.\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ if (!(tmp = ast_variable_retrieve(cfg,"global","hostname"))) {
+ ast_log(LOG_WARNING,"MongoDB server hostname not specified. Assuming unix socket connection\n");
+ tmp = ""; /* connect via UNIX-socket by default */
+ }
+ if (hostname) {
+ ast_free(hostname);
+ }
+ if (!(hostname = ast_strdup(tmp))) {
+ ast_log(LOG_WARNING,"MongoDB Ran out of memory copying host info\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ if (!(tmp = ast_variable_retrieve(cfg, "global", "dbname"))) {
+ ast_log(LOG_WARNING,"MongoDB database not specified. Assuming asterisk\n");
+ tmp = "asteriskceldb";
+ }
+ if (dbname) {
+ ast_free(dbname);
+ }
+ if (!(dbname = ast_strdup(tmp))) {
+ ast_log(LOG_WARNING,"MongoDB Ran out of memory copying dbname info\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ if (!(tmp = ast_variable_retrieve(cfg, "global", "username"))) {
+ ast_log(LOG_WARNING,"MongoDB database user not specified. Assuming blank\n");
+ tmp = "";
+ }
+ if (dbuser) {
+ ast_free(dbuser);
+ }
+ if (!(dbuser = ast_strdup(tmp))) {
+ ast_log(LOG_WARNING,"MongoDB Ran out of memory copying user info\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ if (!(tmp = ast_variable_retrieve(cfg, "global", "password"))) {
+ ast_log(LOG_WARNING, "MongoDB database password not specified. Assuming blank\n");
+ tmp = "";
+ }
+ if (password) {
+ ast_free(password);
+ }
+ if (!(password = ast_strdup(tmp))) {
+ ast_log(LOG_WARNING,"MongoDB Ran out of memory copying password info\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ if (!(tmp = ast_variable_retrieve(cfg,"global","port"))) {
+ ast_log(LOG_WARNING,"MongoDB database port not specified. Using default 27017.\n");
+ tmp = "27017";
+ }
+ if (dbport) {
+ ast_free(dbport);
+ }
+ if (!(dbport = ast_strdup(tmp))) {
+ ast_log(LOG_WARNING,"MongoDB Ran out of memory copying port info\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ if (!(tmp = ast_variable_retrieve(cfg, "global", "collection"))) {
+ ast_log(LOG_WARNING,"CEL table not specified. Assuming cel\n");
+ tmp = "cel";
+ }
+ if (dbcollection)
+ ast_free(dbcollection);
+ if (!(dbcollection = ast_strdup(tmp))) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT;
+ if ((tmp = ast_variable_retrieve(cfg, "global", "show_user_defined"))) {
+ cel_show_user_def = ast_true(tmp) ? 1 : 0;
+ }
+
+ if (option_debug) {
+ if (ast_strlen_zero(hostname)) {
+ ast_debug(3, "cel_mongodb: using default unix socket\n");
+ } else {
+ ast_debug(3, "cel_mongodb: got hostname of %s\n", hostname);
+ }
+ ast_debug(3, "cel_mongodb: got port of %s\n", dbport);
+ ast_debug(3, "cel_mongodb: got user of %s\n", dbuser);
+ ast_debug(3, "cel_mongodb: got dbname of %s\n", dbname);
+ ast_debug(3, "cel_mongodb: got password of %s\n", password);
+ ast_debug(3, "cel_mongodb: got collection name of %s\n", dbcollection);
+ ast_debug(3, "cel_mongodb: got show_user_defined of %s\n",
+ cel_show_user_def ? "Yes" : "No");
+ }
+
+ mongodb_reconnect();
+ if (client) {
+ collection = mongoc_client_get_collection (client, dbname, dbcollection);
+ if (mongoc_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error) < 0) {
+ ast_log(LOG_ERROR, "Method: process_load_module, MongoDB failed to connect to %s!\n", ast_str_buffer(dburi));
+ ast_log(LOG_ERROR, "Method: process_load_module, Error %s \n", error.message);
+ } else {
+ ast_debug(1, "Successfully connected to MongoDB database.\n");
+ }
+ mongoc_collection_destroy(collection);
+ } else {
+ ast_log(LOG_ERROR, "cel_mongodb: Unable to connect to database server %s. Calls will not be logged!\n", hostname);
+ client = NULL;
+ connected = 0;
+ mongoc_cleanup();
+ }
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+
+static int _load_module(int reload)
+{
+
+ struct ast_config *cfg;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+ ast_log(LOG_WARNING, "_load_module: Start\n");
+
+ if ((cfg = ast_config_load(config, config_flags)) == NULL || cfg == CONFIG_STATUS_FILEINVALID) {
+ ast_log(LOG_WARNING, "Unable to load config for MongoDB CEL's: %s\n", config);
+ return AST_MODULE_LOAD_DECLINE;
+ } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
+ return AST_MODULE_LOAD_SUCCESS;
+ }
+
+ process_load_module(cfg);
+ ast_config_destroy(cfg);
+
+ if (ast_cel_backend_register(MONGODB_BACKEND_NAME, mongodb_log)) {
+ ast_log(LOG_WARNING, "Unable to subscribe to CEL events for mongodb\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+
+static int load_module(void)
+{
+ return _load_module(0);
+}
+
+
+static int _unload_module(void)
+{
+ ast_cel_backend_unregister(MONGODB_BACKEND_NAME);
+
+ if (client) {
+ mongoc_client_destroy(client);
+ client = NULL;
+ mongoc_cleanup();
+ }
+
+ mongoc_cleanup();
+
+ if (hostname) {
+ ast_free(hostname);
+ hostname = NULL;
+ }
+ if (dbname) {
+ ast_free(dbname);
+ dbname = NULL;
+ }
+ if (dbuser) {
+ ast_free(dbuser);
+ dbuser = NULL;
+ }
+ if (password) {
+ ast_free(password);
+ password = NULL;
+ }
+ if (dbport) {
+ ast_free(dbport);
+ dbport = NULL;
+ }
+ if (dbcollection) {
+ ast_free(dbcollection);
+ dbcollection = NULL;
+ }
+ return 0;
+}
+
+
+static int unload_module(void)
+{
+ return _unload_module();
+}
+
+
+static int reload(void)
+{
+ return _load_module(1);
+}
+
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "MongoDB CEL Backend",
+ .support_level = AST_MODULE_SUPPORT_EXTENDED,
+ .load = load_module,
+ .unload = unload_module,
+ .reload = reload,
+ .load_pri = AST_MODPRI_CDR_DRIVER,
+);
diff --git a/configs/samples/cel_mongodb.conf.samples b/configs/samples/cel_mongodb.conf.samples
new file mode 100644
index 0000000..5354d61
--- /dev/null
+++ b/configs/samples/cel_mongodb.conf.samples
@@ -0,0 +1,67 @@
+;
+; Asterisk Channel Event Logging (CEL) - MongoDB Backend
+;
+
+; Sample Asterisk config file for CEL logging to MongoDB
+;
+; CEL field names:
+;
+; eventtype
+; CHANNEL_START = 1
+; CHANNEL_END = 2
+; HANGUP = 3
+; ANSWER = 4
+; APP_START = 5
+; APP_END = 6
+; BRIDGE_START = 7
+; BRIDGE_END = 8
+; CONF_START = 9
+; CONF_END = 10
+; PARK_START = 11
+; PARK_END = 12
+; BLINDTRANSFER = 13
+; ATTENDEDTRANSFER = 14
+; TRANSFER = 15
+; HOOKFLASH = 16
+; 3WAY_START = 17
+; 3WAY_END = 18
+; CONF_ENTER = 19
+; CONF_EXIT = 20
+; USER_DEFINED = 21
+; LINKEDID_END = 22
+; BRIDGE_UPDATE = 23
+; PICKUP = 24
+; FORWARD = 25
+; eventtime (timeval, includes microseconds)
+; userdeftype (set only if eventtype == USER_DEFINED)
+; cid_name
+; cid_num
+; cid_ani
+; cid_rdnis
+; cid_dnid
+; exten
+; context
+; channame
+; appname
+; appdata
+; accountcode
+; peeraccount
+; uniqueid
+; linkedid
+; amaflags (an int)
+; userfield
+; peer
+; extra
+
+[global]
+; Use 'show_user_defined' to put "USER_DEFINED" in the eventtype field,
+; instead of (by default) just putting the user defined event name there.
+;
+;show_user_defined=yes
+
+;hostname=localhost
+;port=27017
+;dbname=asterisk
+;password=password
+;username=mongodb
+collection=cel ;Collection where CEL's will be inserted
diff --git a/configure b/configure
index 3967cec..7056e2d 100755
--- a/configure
+++ b/configure
@@ -680,6 +680,8 @@
ILBC_INTERNAL
GSM_INTERNAL
PBX_DAHDI_HALF_FULL
+MONGOCLIENT_LIBS
+MONGOCLIENT_CFLAGS
PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH
PKG_CONFIG
@@ -1156,6 +1158,10 @@
BKTR_DIR
BKTR_INCLUDE
BKTR_LIB
+PBX_MONGOCLIENT
+MONGOCLIENT_DIR
+MONGOCLIENT_INCLUDE
+MONGOCLIENT_LIB
PBX_BFD
BFD_DIR
BFD_INCLUDE
@@ -1315,6 +1321,7 @@
enable_coverage
with_asound
with_bfd
+with_mongo_client
with_execinfo
with_bluetooth
with_cap
@@ -1415,6 +1422,8 @@
PKG_CONFIG
PKG_CONFIG_PATH
PKG_CONFIG_LIBDIR
+MONGOCLIENT_CFLAGS
+MONGOCLIENT_LIBS
ILBC_CFLAGS
ILBC_LIBS
LIBEDIT_CFLAGS
@@ -2052,6 +2061,8 @@
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-asound=PATH use Advanced Linux Sound Architecture files in PATH
--with-bfd=PATH use Debug symbol decoding files in PATH
+ --with-mongo-client=PATH
+ use MongoDB C Driver files in PATH
--with-execinfo=PATH use Stack Backtrace files in PATH
--with-bluetooth=PATH use Bluetooth files in PATH
--with-cap=PATH use POSIX 1.e capabilities files in PATH
@@ -2154,6 +2165,10 @@
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
+ MONGOCLIENT_CFLAGS
+ C compiler flags for MONGOCLIENT, overriding pkg-config
+ MONGOCLIENT_LIBS
+ linker flags for MONGOCLIENT, overriding pkg-config
ILBC_CFLAGS C compiler flags for ILBC, overriding pkg-config
ILBC_LIBS linker flags for ILBC, overriding pkg-config
LIBEDIT_CFLAGS
@@ -8507,6 +8522,38 @@
+ MONGOCLIENT_DESCRIP="MongoDB C Driver"
+ MONGOCLIENT_OPTION="mongo-client"
+ PBX_MONGOCLIENT=0
+
+# Check whether --with-mongo-client was given.
+if test "${with_mongo_client+set}" = set; then :
+ withval=$with_mongo_client;
+ case ${withval} in
+ n|no)
+ USE_MONGOCLIENT=no
+ # -1 is a magic value used by menuselect to know that the package
+ # was disabled, other than 'not found'
+ PBX_MONGOCLIENT=-1
+ ;;
+ y|ye|yes)
+ ac_mandatory_list="${ac_mandatory_list} MONGOCLIENT"
+ ;;
+ *)
+ MONGOCLIENT_DIR="${withval}"
+ ac_mandatory_list="${ac_mandatory_list} MONGOCLIENT"
+ ;;
+ esac
+
+fi
+
+
+
+
+
+
+
+
# BKTR is used for backtrace support on platforms that do not
# have it natively.
@@ -13746,7 +13793,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -13792,7 +13839,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -13816,7 +13863,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -13861,7 +13908,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -13885,7 +13932,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -18981,6 +19028,96 @@
+# Tested in ubuntu with mongdb c driver from source code
+
+ if test "x${PBX_MONGOCLIENT}" != "x1" -a "${USE_MONGOCLIENT}" != "no"; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for MONGOCLIENT" >&5
+$as_echo_n "checking for MONGOCLIENT... " >&6; }
+
+if test -n "$MONGOCLIENT_CFLAGS"; then
+ pkg_cv_MONGOCLIENT_CFLAGS="$MONGOCLIENT_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libmongoc-1.0\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "libmongoc-1.0") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_MONGOCLIENT_CFLAGS=`$PKG_CONFIG --cflags "libmongoc-1.0" 2>/dev/null`
+ test "x$?" != "x0" && pkg_failed=yes
+else
+ pkg_failed=yes
+fi
+ else
+ pkg_failed=untried
+fi
+if test -n "$MONGOCLIENT_LIBS"; then
+ pkg_cv_MONGOCLIENT_LIBS="$MONGOCLIENT_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libmongoc-1.0\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "libmongoc-1.0") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_MONGOCLIENT_LIBS=`$PKG_CONFIG --libs "libmongoc-1.0" 2>/dev/null`
+ test "x$?" != "x0" && pkg_failed=yes
+else
+ pkg_failed=yes
+fi
+ else
+ pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+ _pkg_short_errors_supported=yes
+else
+ _pkg_short_errors_supported=no
+fi
+ if test $_pkg_short_errors_supported = yes; then
+ MONGOCLIENT_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libmongoc-1.0" 2>&1`
+ else
+ MONGOCLIENT_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libmongoc-1.0" 2>&1`
+ fi
+ # Put the nasty error message in config.log where it belongs
+ echo "$MONGOCLIENT_PKG_ERRORS" >&5
+
+
+ PBX_MONGOCLIENT=0
+
+
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+ PBX_MONGOCLIENT=0
+
+
+else
+ MONGOCLIENT_CFLAGS=$pkg_cv_MONGOCLIENT_CFLAGS
+ MONGOCLIENT_LIBS=$pkg_cv_MONGOCLIENT_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+ PBX_MONGOCLIENT=1
+ MONGOCLIENT_INCLUDE="$MONGOCLIENT_CFLAGS"
+ MONGOCLIENT_LIB="$MONGOCLIENT_LIBS"
+
+$as_echo "#define HAVE_MONGOCLIENT 1" >>confdefs.h
+
+
+fi
+ fi
+
+
if test "x${PBX_BFD}" != "x1" -a "${USE_BFD}" != "no"; then
pbxlibdir=""
diff --git a/configure.ac b/configure.ac
index 12cc8d2..37cf1eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -398,6 +398,7 @@
AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
AST_EXT_LIB_SETUP([BFD], [Debug symbol decoding], [bfd])
+AST_EXT_LIB_SETUP([MONGOCLIENT], [MongoDB C Driver], [mongo-client])
# BKTR is used for backtrace support on platforms that do not
# have it natively.
@@ -1375,6 +1376,9 @@
AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])
+# Tested in ubuntu with mongdb c driver from source code
+AST_PKG_CONFIG_CHECK([MONGOCLIENT], [libmongoc-1.0])
+
AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_openr], [bfd.h])
if test "${PBX_BFD}" = "0"; then
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 43f86b0..e11770d 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -484,6 +484,9 @@
/* Define to 1 if you have a working `mmap' system call. */
#undef HAVE_MMAP
+/* Define if your system has the MONGOCLIENT libraries. */
+#undef HAVE_MONGOCLIENT
+
/* Define if your system has the MSG_NOSIGNAL headers. */
#undef HAVE_MSG_NOSIGNAL
diff --git a/makeopts.in b/makeopts.in
index 6baef1b..ea9e06b 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -194,6 +194,9 @@
MYSQLCLIENT_INCLUDE=@MYSQLCLIENT_INCLUDE@
MYSQLCLIENT_LIB=@MYSQLCLIENT_LIB@
+MONGOCLIENT_INCLUDE=@MONGOC_INCLUDE@
+MONGOCLIENT_LIB=@MONGOC_LIB@
+
NBS_INCLUDE=@NBS_INCLUDE@
NBS_LIB=@NBS_LIB@
--
To view, visit https://gerrit.asterisk.org/2361
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bf4f02fbc6a3a5edd7f10256ea0e14f49193c4f
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Catalin Stanciu <catacsdev at gmail.com>
More information about the asterisk-code-review
mailing list