mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-11 09:43:38 +00:00
conditionally compile ODBC
framework in place to conditionally compile with CURL but what is the master switch? git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12995 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
ca39144a1e
commit
0fd4003ed7
@ -1,31 +1,5 @@
|
|||||||
MEMCACHED=libmemcached-0.27
|
|
||||||
switch_srcdir=../../../..
|
|
||||||
|
|
||||||
WANT_CURL=yes
|
WANT_CURL=yes
|
||||||
|
|
||||||
MEMCACHED_DIR=$(switch_srcdir)/libs/$(MEMCACHED)
|
BASE=../../../..
|
||||||
|
include $(BASE)/build/modmake.rules
|
||||||
MEMCACHEDLA=$(MEMCACHED_DIR)/libmemcached/libmemcached.la
|
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
|
||||||
|
|
||||||
LOCAL_CFLAGS=-I$(MEMCACHED_DIR)
|
|
||||||
LOCAL_LIBADD=$(MEMCACHEDLA)
|
|
||||||
|
|
||||||
include $(switch_srcdir)/build/modmake.rules
|
|
||||||
|
|
||||||
DEFAULT_ARGS=--prefix=$(PREFIX) --disable-shared --with-pic
|
|
||||||
|
|
||||||
$(LOCAL_OBJS): $(LOCAL_SOURCES)
|
|
||||||
|
|
||||||
$(MEMCACHED_DIR):
|
|
||||||
$(GETLIB) $(MEMCACHED).tar.gz
|
|
||||||
|
|
||||||
$(MEMCACHED_DIR)/Makefile: $(MEMCACHED_DIR)
|
|
||||||
cd $(MEMCACHED_DIR) && CFLAGS=$(AM_CFLAGS) CC=$(CC) CXX=$(CXX) ./configure --disable-shared --with-pic CPPFLAGS= LDFLAGS=
|
|
||||||
$(TOUCH_TARGET)
|
|
||||||
|
|
||||||
$(MEMCACHEDLA): $(MEMCACHED_DIR)/Makefile
|
|
||||||
cd $(MEMCACHED_DIR) && $(MAKE)
|
|
||||||
$(TOUCH_TARGET)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,9 +31,19 @@
|
|||||||
* mod_cidlookup.c -- API for querying cid->name services
|
* mod_cidlookup.c -- API for querying cid->name services
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* ok, what is the right way to conditionally compile CURL? */
|
||||||
|
#ifndef HAVE_CURL
|
||||||
|
#define HAVE_CURL
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
#include <switch_odbc.h>
|
#include <switch_odbc.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_CURL
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown);
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown);
|
||||||
@ -56,12 +66,20 @@ static struct {
|
|||||||
char *odbc_dsn;
|
char *odbc_dsn;
|
||||||
char *sql;
|
char *sql;
|
||||||
|
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
switch_mutex_t *db_mutex;
|
switch_mutex_t *db_mutex;
|
||||||
switch_odbc_handle_t *master_odbc;
|
#else
|
||||||
|
void *filler1;
|
||||||
|
#endif
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
|
switch_odbc_handle_t *master_odbc;
|
||||||
|
#else
|
||||||
|
void *filler2;
|
||||||
|
#endif
|
||||||
} globals;
|
} globals;
|
||||||
|
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
struct odbc_obj {
|
struct odbc_obj {
|
||||||
switch_odbc_handle_t *handle;
|
switch_odbc_handle_t *handle;
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
@ -73,6 +91,7 @@ struct odbc_obj {
|
|||||||
|
|
||||||
typedef struct odbc_obj odbc_obj_t;
|
typedef struct odbc_obj odbc_obj_t;
|
||||||
typedef odbc_obj_t *odbc_handle;
|
typedef odbc_obj_t *odbc_handle;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct http_data {
|
struct http_data {
|
||||||
switch_stream_handle_t stream;
|
switch_stream_handle_t stream;
|
||||||
@ -94,6 +113,7 @@ static switch_event_node_t *reload_xml_event = NULL;
|
|||||||
static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
|
static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
|
||||||
{
|
{
|
||||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
char *odbc_user = NULL;
|
char *odbc_user = NULL;
|
||||||
char *odbc_pass = NULL;
|
char *odbc_pass = NULL;
|
||||||
|
|
||||||
@ -136,8 +156,12 @@ static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, switc
|
|||||||
/* and swap in new connection */
|
/* and swap in new connection */
|
||||||
globals.master_odbc = odbc;
|
globals.master_odbc = odbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
|
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
|
||||||
|
#else
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC is not compiled in. Do not configure odbc-dsn parameter!\n");
|
||||||
|
switch_goto_status(SWITCH_STATUS_FALSE, done);
|
||||||
|
#endif
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (globals.db_mutex) {
|
if (globals.db_mutex) {
|
||||||
@ -164,7 +188,12 @@ static switch_status_t do_config(switch_bool_t reload)
|
|||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_CURL
|
||||||
|
if (globals.url) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No LIBCURL - compile with LIBCURL or remove url param\n");
|
||||||
|
return SWITCH_STATUS_GENERR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +203,7 @@ static void event_handler(switch_event_t *event)
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "cidlookup Reloaded\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "cidlookup Reloaded\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
static switch_bool_t cidlookup_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata)
|
static switch_bool_t cidlookup_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata)
|
||||||
{
|
{
|
||||||
switch_bool_t retval = SWITCH_FALSE;
|
switch_bool_t retval = SWITCH_FALSE;
|
||||||
@ -207,6 +237,7 @@ static int cidlookup_callback(void *pArg, int argc, char **argv, char **columnNa
|
|||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* make a new string with digits only */
|
/* make a new string with digits only */
|
||||||
static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
|
static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
|
||||||
@ -274,6 +305,7 @@ switch_bool_t set_cache(switch_memory_pool_t *pool, const char *number, const ch
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_CURL
|
||||||
static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||||
{
|
{
|
||||||
register unsigned int realsize = (unsigned int) (size * nmemb);
|
register unsigned int realsize = (unsigned int) (size * nmemb);
|
||||||
@ -343,7 +375,9 @@ static char *do_lookup_url(switch_memory_pool_t *pool, switch_core_session_t *se
|
|||||||
switch_safe_free(http_data.stream.data);
|
switch_safe_free(http_data.stream.data);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
static char *do_db_lookup(switch_memory_pool_t *pool, switch_core_session_t *session, switch_event_t *event, const char *num) {
|
static char *do_db_lookup(switch_memory_pool_t *pool, switch_core_session_t *session, switch_event_t *event, const char *num) {
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char *newsql = NULL;
|
char *newsql = NULL;
|
||||||
@ -364,6 +398,7 @@ static char *do_db_lookup(switch_memory_pool_t *pool, switch_core_session_t *ses
|
|||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *do_lookup(switch_memory_pool_t *pool, switch_core_session_t *session, switch_event_t *event, const char *num) {
|
static char *do_lookup(switch_memory_pool_t *pool, switch_core_session_t *session, switch_event_t *event, const char *num) {
|
||||||
char *number = NULL;
|
char *number = NULL;
|
||||||
@ -375,16 +410,19 @@ static char *do_lookup(switch_memory_pool_t *pool, switch_core_session_t *sessio
|
|||||||
if (globals.cache) {
|
if (globals.cache) {
|
||||||
name = check_cache(pool, number);
|
name = check_cache(pool, number);
|
||||||
}
|
}
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
if (!name && globals.master_odbc && globals.sql) {
|
if (!name && globals.master_odbc && globals.sql) {
|
||||||
name = do_db_lookup(pool, session, event, number);
|
name = do_db_lookup(pool, session, event, number);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_CURL
|
||||||
if (!name && globals.url) {
|
if (!name && globals.url) {
|
||||||
name = do_lookup_url(pool, session, event, number);
|
name = do_lookup_url(pool, session, event, number);
|
||||||
if (globals.cache && name) {
|
if (globals.cache && name) {
|
||||||
set_cache(pool, number, name);
|
set_cache(pool, number, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,6 +464,16 @@ SWITCH_STANDARD_API(cidlookup_function)
|
|||||||
stream->write_function(stream, " odbc-dsn: %s\n sql: %s\n",
|
stream->write_function(stream, " odbc-dsn: %s\n sql: %s\n",
|
||||||
globals.odbc_dsn,
|
globals.odbc_dsn,
|
||||||
globals.sql);
|
globals.sql);
|
||||||
|
#ifdef HAVE_CURL
|
||||||
|
stream->write_function(stream, " LIBCURL: true");
|
||||||
|
#else
|
||||||
|
stream->write_function(stream, " LIBCURL: false");
|
||||||
|
#endif
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
|
stream->write_function(stream, " ODBC: true");
|
||||||
|
#else
|
||||||
|
stream->write_function(stream, " ODBC: false");
|
||||||
|
#endif
|
||||||
|
|
||||||
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
|
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
|
||||||
}
|
}
|
||||||
@ -463,11 +511,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load)
|
|||||||
|
|
||||||
globals.pool = pool;
|
globals.pool = pool;
|
||||||
|
|
||||||
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
if (!globals.db_mutex) {
|
if (!globals.db_mutex) {
|
||||||
if (switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_UNNESTED, globals.pool) != SWITCH_STATUS_SUCCESS) {
|
if (switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_UNNESTED, globals.pool) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize db_mutex\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize db_mutex\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
do_config(SWITCH_FALSE);
|
do_config(SWITCH_FALSE);
|
||||||
|
|
||||||
@ -488,9 +538,15 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load)
|
|||||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown)
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown)
|
||||||
{
|
{
|
||||||
/* Cleanup dynamically allocated config settings */
|
/* Cleanup dynamically allocated config settings */
|
||||||
switch_mutex_destroy(globals.db_mutex);
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
switch_odbc_handle_disconnect(globals.master_odbc);
|
if (globals.db_mutex) {
|
||||||
switch_odbc_handle_destroy(&globals.master_odbc);
|
switch_mutex_destroy(globals.db_mutex);
|
||||||
|
}
|
||||||
|
if (globals.master_odbc) {
|
||||||
|
switch_odbc_handle_disconnect(globals.master_odbc);
|
||||||
|
switch_odbc_handle_destroy(&globals.master_odbc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
switch_event_unbind(&reload_xml_event);
|
switch_event_unbind(&reload_xml_event);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user