diff --git a/debian/changelog b/debian/changelog index 2aa9e75555..d49637cfc0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +freeswitch (1.0.6-1ubuntu1) maverick; urgency=low + + * upgrade: Added mod_callcenter and pulled out Python into its own + package. + + -- Gabriel Gunderson Thu, 16 Nov 2010 18:28:30 -0800 + freeswitch (1.0.4-1ubuntu2) karmic; urgency=low * upgrade: Add more verbosity when building to make it easier to find build diff --git a/debian/control b/debian/control index 8e52e3d6c1..145f28d767 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: freeswitch Section: comm Priority: extra Maintainer: Michal Bielicki -Build-Depends: debhelper (>= 5), fakeroot, wget, automake (>=1.9), autoconf, libtool, unixodbc-dev, libasound2-dev, libcurl3-openssl-dev|libcurl4-openssl-dev, libssl-dev, ncurses-dev, libogg-dev, libvorbis-dev, libperl-dev, libgdbm-dev, libdb-dev, libgnutls-dev, libtiff4-dev, python, libx11-dev, uuid-dev +Build-Depends: debhelper (>= 5), fakeroot, wget, automake (>=1.9), autoconf, libtool, unixodbc-dev, libasound2-dev, libcurl3-openssl-dev|libcurl4-openssl-dev, libssl-dev, ncurses-dev, libogg-dev, libvorbis-dev, libperl-dev, libgdbm-dev, libdb-dev, libgnutls-dev, libtiff4-dev, python-dev, libx11-dev, uuid-dev Homepage: http://freeswitch.org/ Standards-Version: 3.8.4 Vcs-Svn: http://svn.freeswitch.org/svn/freeswitch/trunk/ @@ -86,6 +86,18 @@ Description: Lua engine for FreeSWITCH . This package contains the mod_lua language module. +Package: freeswitch-python +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, freeswitch +Description: Python engine for FreeSWITCH + FreeSWITCH is an open source telephony platform designed to facilitate the + creation of voice and chat driven products scaling from a soft-phone up to a + soft-switch. It can be used as a simple switching engine, a PBX, a media + gateway or a media server to host IVR applications using simple scripts or XML + to control the callflow. + . + This package contains the mod_python language module. + Package: freeswitch-codec-passthru-g7231 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, freeswitch diff --git a/debian/freeswitch.conffiles b/debian/freeswitch.conffiles index 342ec5fc02..a6f9ce380f 100644 --- a/debian/freeswitch.conffiles +++ b/debian/freeswitch.conffiles @@ -1,5 +1,6 @@ /opt/freeswitch/conf/autoload_configs/acl.conf.xml /opt/freeswitch/conf/autoload_configs/alsa.conf.xml +/opt/freeswitch/conf/autoload_configs/callcenter.conf.xml /opt/freeswitch/conf/autoload_configs/cdr_csv.conf.xml /opt/freeswitch/conf/autoload_configs/cidlookup.conf.xml /opt/freeswitch/conf/autoload_configs/conference.conf.xml @@ -26,7 +27,6 @@ /opt/freeswitch/conf/autoload_configs/pocketsphinx.conf.xml /opt/freeswitch/conf/autoload_configs/portaudio.conf.xml /opt/freeswitch/conf/autoload_configs/post_load_modules.conf.xml -/opt/freeswitch/conf/autoload_configs/python.conf.xml /opt/freeswitch/conf/autoload_configs/rss.conf.xml /opt/freeswitch/conf/autoload_configs/shout.conf.xml /opt/freeswitch/conf/autoload_configs/skinny.conf.xml @@ -43,7 +43,6 @@ /opt/freeswitch/conf/autoload_configs/zeroconf.conf.xml /opt/freeswitch/conf/dialplan/default/00_pizza_demo.xml /opt/freeswitch/conf/dialplan/default/01_example.com.xml -/opt/freeswitch/conf/dialplan/default/99999_enum.xml /opt/freeswitch/conf/dialplan/default.xml /opt/freeswitch/conf/dialplan/features.xml /opt/freeswitch/conf/dialplan/public/00_inbound_did.xml diff --git a/debian/freeswitch.install b/debian/freeswitch.install index 0bf0c156e7..087d167859 100644 --- a/debian/freeswitch.install +++ b/debian/freeswitch.install @@ -6,6 +6,7 @@ opt/freeswitch/bin/gentls_cert opt/freeswitch/bin/scripts/* opt/freeswitch/conf/autoload_configs/acl.conf.xml opt/freeswitch/conf/autoload_configs/alsa.conf.xml +opt/freeswitch/conf/autoload_configs/callcenter.conf.xml opt/freeswitch/conf/autoload_configs/cdr_csv.conf.xml opt/freeswitch/conf/autoload_configs/cidlookup.conf.xml opt/freeswitch/conf/autoload_configs/conference.conf.xml @@ -34,7 +35,6 @@ opt/freeswitch/conf/autoload_configs/openzap.conf.xml opt/freeswitch/conf/autoload_configs/pocketsphinx.conf.xml opt/freeswitch/conf/autoload_configs/portaudio.conf.xml opt/freeswitch/conf/autoload_configs/post_load_modules.conf.xml -opt/freeswitch/conf/autoload_configs/python.conf.xml opt/freeswitch/conf/autoload_configs/rss.conf.xml opt/freeswitch/conf/autoload_configs/shout.conf.xml opt/freeswitch/conf/autoload_configs/skinny.conf.xml @@ -51,7 +51,6 @@ opt/freeswitch/conf/autoload_configs/xml_rpc.conf.xml opt/freeswitch/conf/autoload_configs/zeroconf.conf.xml opt/freeswitch/conf/dialplan/default/00_pizza_demo.xml opt/freeswitch/conf/dialplan/default/01_example.com.xml -opt/freeswitch/conf/dialplan/default/99999_enum.xml opt/freeswitch/conf/dialplan/default.xml opt/freeswitch/conf/dialplan/features.xml opt/freeswitch/conf/dialplan/public/00_inbound_did.xml @@ -113,6 +112,7 @@ opt/freeswitch/conf/zt.conf opt/freeswitch/htdocs/* opt/freeswitch/lib/libfreeswitch*.so* opt/freeswitch/lib/libopenzap*.so* +opt/freeswitch/mod/mod_callcenter.so* opt/freeswitch/mod/mod_cdr_csv.so* opt/freeswitch/mod/mod_celt.so* opt/freeswitch/mod/mod_cidlookup.so* diff --git a/debian/rules b/debian/rules index 05ab4c1bc4..114ad64f34 100755 --- a/debian/rules +++ b/debian/rules @@ -13,7 +13,7 @@ export APPLICATIONS_MODULES=applications/mod_cluechoo applications/mod_commands applications/mod_hash applications/mod_db applications/mod_valet_parking applications/mod_voicemail applications/mod_rss \ applications/mod_spandsp applications/mod_cidlookup applications/mod_curl applications/mod_easyroute \ applications/mod_lcr applications/mod_nibblebill applications/mod_snom \ - applications/mod_spy applications/mod_vmd applications/mod_directory + applications/mod_spy applications/mod_vmd applications/mod_directory applications/mod_callcenter export ASR_TTS_MODULES=asr_tts/mod_tts_commandline export CODECS_MODULES=codecs/mod_ilbc codecs/mod_h26x codecs/mod_speex codecs/mod_siren codecs/mod_celt export DIALPLANS_MODULES=dialplans/mod_dialplan_asterisk dialplans/mod_dialplan_directory dialplans/mod_dialplan_xml @@ -24,11 +24,11 @@ export ENDPOINTS_MODULES=endpoints/mod_dingaling endpoints/mod_portaudio endpoin endpoints/mod_skinny export EVENT_HANDLERS_MODULES=event_handlers/mod_event_multicast event_handlers/mod_event_socket event_handlers/mod_cdr_csv export FORMATS_MODULES=formats/mod_local_stream formats/mod_native_file formats/mod_sndfile formats/mod_tone_stream formats/mod_shout -export LANGUAGES_MODULES=languages/mod_spidermonkey languages/mod_perl languages/mod_lua +export LANGUAGES_MODULES=languages/mod_spidermonkey languages/mod_perl languages/mod_lua languages/mod_python export LOGGERS_MODULES=loggers/mod_console loggers/mod_logfile loggers/mod_syslog export SAY_MODULES=say/mod_say_en say/mod_say_it say/mod_say_de say/mod_say_fr say/mod_say_es say/mod_say_nl say/mod_say_ru export TIMERS_MODULES= -export DISABLED_MODULES=applications/mod_memcache applications/mod_soundtouch directories/mod_ldap languages/mod_java languages/mod_python \ +export DISABLED_MODULES=applications/mod_memcache applications/mod_soundtouch directories/mod_ldap languages/mod_java \ asr_tts/mod_cepstral asr_tts/mod_lumenvox endpoints/mod_wanpipe \ event_handlers/mod_event_test event_handlers/mod_radius_cdr event_handlers/mod_zeroconf export XML_INT_MODULES=xml_int/mod_xml_rpc xml_int/mod_xml_curl xml_int/mod_xml_cdr diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index cc47ce1ba1..2a46539a73 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -4063,7 +4063,7 @@ SWITCH_STANDARD_API(uuid_dump_function) return SWITCH_STATUS_SUCCESS; } -#define GLOBAL_SETVAR_SYNTAX " []" +#define GLOBAL_SETVAR_SYNTAX "= [=]" SWITCH_STANDARD_API(global_setvar_function) { char *mycmd = NULL, *argv[3] = { 0 }; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index 1c825ec8dd..2ea3eb00a3 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -120,6 +120,21 @@ static struct { int thread_running; } t38_state_list; + + +static void wake_thread(int force) +{ + if (force) { + switch_thread_cond_signal(globals.cond); + return; + } + + if (switch_mutex_trylock(globals.cond_mutex) == SWITCH_STATUS_SUCCESS) { + switch_thread_cond_signal(globals.cond); + switch_mutex_unlock(globals.cond_mutex); + } +} + static int add_pvt(pvt_t *pvt) { int r = 0; @@ -130,7 +145,7 @@ static int add_pvt(pvt_t *pvt) t38_state_list.head = pvt; switch_mutex_unlock(t38_state_list.mutex); r = 1; - switch_thread_cond_broadcast(globals.cond); + wake_thread(0); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error launching thread\n"); } @@ -165,7 +180,7 @@ static int del_pvt(pvt_t *del_pvt) switch_mutex_unlock(t38_state_list.mutex); - switch_thread_cond_broadcast(globals.cond); + wake_thread(0); return r; } @@ -1335,7 +1350,7 @@ void mod_spandsp_fax_shutdown(void) switch_status_t tstatus = SWITCH_STATUS_SUCCESS; t38_state_list.thread_running = 0; - switch_thread_cond_broadcast(globals.cond); + wake_thread(1); switch_thread_join(&tstatus, t38_state_list.thread); memset(&globals, 0, sizeof(globals)); } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index a1642fff69..7c81cd2c08 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3166,6 +3166,21 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t goto done; } + + if (!strcasecmp(argv[1], "gwlist")) { + int up = 1; + + if (argc > 2) { + if (!strcasecmp(argv[2], "down")) { + up = 0; + } + } + + sofia_glue_gateway_list(profile, stream, up); + goto done; + } + + stream->write_function(stream, "-ERR Unknown command!\n"); done: @@ -4707,8 +4722,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia help"); switch_console_set_complete("add sofia status"); switch_console_set_complete("add sofia xmlstatus"); - switch_console_set_complete("add sofia loglevel"); - switch_console_set_complete("add sofia tracelevel"); + + switch_console_set_complete("add sofia loglevel ::[all:default:tport:iptsec:nea:nta:nth_client:nth_server:nua:soa:sresolv:stun ::[0:1:2:3:4:5:6:7:8:9"); + switch_console_set_complete("add sofia tracelevel ::[console:alert:crit:err:warning:notice:info:debug"); + switch_console_set_complete("add sofia profile"); switch_console_set_complete("add sofia profile restart all"); @@ -4724,6 +4741,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia profile ::sofia::list_profiles siptrace on"); switch_console_set_complete("add sofia profile ::sofia::list_profiles siptrace off"); + switch_console_set_complete("add sofia profile ::sofia::list_profiles gwlist up"); + switch_console_set_complete("add sofia profile ::sofia::list_profiles gwlist down"); + switch_console_set_complete("add sofia status profile ::sofia::list_profiles"); switch_console_set_complete("add sofia status profile ::sofia::list_profiles reg"); switch_console_set_complete("add sofia status gateway ::sofia::list_gateways"); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 3a23da85d8..1858e4e4f2 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -942,6 +942,7 @@ switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int const char *sofia_glue_strip_proto(const char *uri); switch_status_t reconfig_sofia(sofia_profile_t *profile); void sofia_glue_del_gateway(sofia_gateway_t *gp); +void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up); void sofia_glue_del_every_gateway(sofia_profile_t *profile); void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index e76a56a4aa..e8bbb6f76e 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4109,7 +4109,8 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status } } - if (tech_pvt && tech_pvt->remote_sdp_str && switch_stristr("m=image", tech_pvt->remote_sdp_str)) { + + if (sip->sip_payload && sip->sip_payload->pl_data && switch_stristr("m=image", sip->sip_payload->pl_data)) { has_t38 = 1; } @@ -4164,12 +4165,12 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status } if (status == 200 && sofia_test_flag(tech_pvt, TFLAG_T38_PASSTHRU) && has_t38) { - switch_core_session_receive_message(other_session, msg); if (switch_rtp_ready(tech_pvt->rtp_session) && switch_rtp_ready(other_tech_pvt->rtp_session)) { switch_rtp_udptl_mode(tech_pvt->rtp_session); switch_rtp_udptl_mode(other_tech_pvt->rtp_session); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating T38 Passthru\n"); } + switch_core_session_receive_message(other_session, msg); } else { switch_core_session_queue_message(other_session, msg); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index d17981c9d0..4018407961 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -4267,6 +4267,28 @@ void sofia_glue_del_every_gateway(sofia_profile_t *profile) } +void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up) +{ + sofia_gateway_t *gp = NULL; + char *r = (char *) stream->data; + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + for (gp = profile->gateways; gp; gp = gp->next) { + int reged = (gp->status == SOFIA_GATEWAY_UP); + + if (up ? reged : !reged) { + stream->write_function(stream, "%s ", gp->name); + } + } + + if (r) { + end_of(r) = '\0'; + } + + switch_mutex_unlock(mod_sofia_globals.hash_mutex); +} + + void sofia_glue_del_gateway(sofia_gateway_t *gp) { if (!gp->deleted) { diff --git a/src/switch_console.c b/src/switch_console.c index 60c8ca9345..61d9b76ee8 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -483,9 +483,29 @@ static int comp_callback(void *pArg, int argc, char **argv, char **columnNames) return -1; } + if (!zstr(target) && *target == ':' && *(target + 1) == ':' && *(target + 2) == '[') { + char *p = target + 3, *list = NULL; + + if (p) { + char *argv[100] = { 0 }; + char *r_argv[1] = { 0 }, *r_cols[1] = {0}; + list = strdup(p); + + argc = switch_separate_string(list, ':', argv, (sizeof(argv) / sizeof(argv[0]))); + + for (i = 0; i < argc; i++) { + if (!cur || !strncmp(argv[i], cur, strlen(cur))) { + r_argv[0] = argv[i]; + comp_callback(h, 1, r_argv, r_cols); + } + } + switch_safe_free(list); + } + return 0; + } + if (!zstr(target) && *target == ':' && *(target + 1) == ':') { - char *r_argv[1] = { 0 }, *r_cols[1] = { - 0}; + char *r_argv[1] = { 0 }, *r_cols[1] = {0}; switch_console_callback_match_t *matches; if (switch_console_run_complete_func(target, str, cur, &matches) == SWITCH_STATUS_SUCCESS) { switch_console_callback_match_node_t *m; @@ -797,6 +817,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch } stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_variable("hostname"), h.words + 1); + switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg); if (errmsg) { diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 4a53c8d1fd..c6b7f8d970 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -34,6 +34,7 @@ #include #include "private/switch_core_pvt.h" +//*#define DEBUG_SQL 1 static struct { switch_cache_db_handle_t *event_db; @@ -41,7 +42,9 @@ static struct { switch_memory_pool_t *memory_pool; switch_event_node_t *event_node; switch_thread_t *thread; + switch_thread_t *db_thread; int thread_running; + int db_thread_running; switch_bool_t manage; switch_mutex_t *io_mutex; switch_mutex_t *dbh_mutex; @@ -464,6 +467,19 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t return status; } +static void wake_thread(int force) +{ + if (force) { + switch_thread_cond_signal(sql_manager.cond); + return; + } + + if (switch_mutex_trylock(sql_manager.cond_mutex) == SWITCH_STATUS_SUCCESS) { + switch_thread_cond_signal(sql_manager.cond); + switch_mutex_unlock(sql_manager.cond_mutex); + } +} + /** OMFG you cruel bastards. Who chooses 64k as a max buffer len for a sql statement, have you ever heard of transactions? **/ @@ -846,7 +862,24 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand } +static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *thread, void *obj) +{ + int sec = 0; + sql_manager.db_thread_running = 1; + + while (sql_manager.db_thread_running == 1) { + if (++sec == SQL_CACHE_TIMEOUT) { + sql_close(switch_epoch_time_now(NULL)); + wake_thread(1); + sec = 0; + } + switch_yield(1000); + } + + + return NULL; +} static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, void *obj) { @@ -859,16 +892,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, char *sql = NULL; switch_size_t newlen; int lc = 0; - uint32_t loops = 0, sec = 0; - uint32_t l1 = 1000; uint32_t sanity = 120; switch_assert(sqlbuf); - if (!sql_manager.manage) { - l1 = 10; - } - while (!sql_manager.event_db) { if (switch_core_db_handle(&sql_manager.event_db) == SWITCH_STATUS_SUCCESS && sql_manager.event_db) break; @@ -882,26 +909,12 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, return NULL; } - sql_manager.thread_running = 1; while (sql_manager.thread_running == 1) { switch_mutex_lock(sql_manager.cond_mutex); - if (++loops == l1) { - if (++sec == SQL_CACHE_TIMEOUT) { - sql_close(switch_epoch_time_now(NULL)); - sec = 0; - } - loops = 0; - } - - if (!sql_manager.manage) { - switch_yield(100000); - continue; - } - if (sql || switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS || switch_queue_trypop(sql_manager.sql_queue[1], &pop) == SWITCH_STATUS_SUCCESS) { @@ -919,9 +932,11 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, if (new_mlen < runtime.max_sql_buffer_len) { sql_len = new_mlen; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, +#ifdef DEBUG_SQL + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1])); +#endif if (!(tmp = realloc(sqlbuf, sql_len))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n"); abort(); @@ -929,8 +944,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, } sqlbuf = tmp; } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, +#ifdef DEBUG_SQL + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SAVE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1])); +#endif goto skip; } } @@ -951,12 +968,16 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, lc = sql ? 1 : 0 + switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]); if (trans && iterations && (iterations > target || !lc)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, +#ifdef DEBUG_SQL + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "RUN %d %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]), iterations); +#endif if (switch_cache_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 1) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n"); } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "DONE\n"); +#ifdef DEBUG_SQL + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n"); +#endif iterations = 0; trans = 0; len = 0; @@ -965,6 +986,8 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, switch_yield(400000); } + lc = sql ? 1 : 0 + switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]); + if (!lc) { switch_thread_cond_wait(sql_manager.cond, sql_manager.cond_mutex); } @@ -1399,7 +1422,7 @@ static void core_event_handler(switch_event_t *event) switch_queue_push(sql_manager.sql_queue[0], sql[i]); } sql[i] = NULL; - switch_thread_cond_broadcast(sql_manager.cond); + wake_thread(1); } } } @@ -1650,7 +1673,10 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_threadattr_create(&thd_attr, sql_manager.memory_pool); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool); + if (sql_manager.manage) { + switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool); + } + switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool); while (!sql_manager.thread_running) { switch_yield(10000); @@ -1673,13 +1699,19 @@ void switch_core_sqldb_stop(void) switch_queue_push(sql_manager.sql_queue[0], NULL); switch_queue_push(sql_manager.sql_queue[1], NULL); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n"); - switch_thread_cond_broadcast(sql_manager.cond); + wake_thread(1); } sql_manager.thread_running = -1; switch_thread_join(&st, sql_manager.thread); } + + if (sql_manager.thread && sql_manager.db_thread_running) { + sql_manager.db_thread_running = -1; + switch_thread_join(&st, sql_manager.db_thread); + } + switch_cache_db_flush_handles(); sql_close(0);