40 #define SWITCH_SQL_QUEUE_LEN 100000 41 #define SWITCH_SQL_QUEUE_PAUSE_LEN 90000 79 #define database_interface_handle_callback_exec(database_interface, dih, sql, callback, pdata, err) database_interface->callback_exec_detailed(__FILE__, (char *)__SWITCH_FUNC__, __LINE__, dih, sql, callback, pdata, err) 80 #define database_interface_handle_exec(database_interface, dih, sql, err) database_interface->exec_detailed(__FILE__, (char *)__SWITCH_FUNC__, __LINE__, dih, sql, err) 98 if (dbh && *dbh && (*dbh)->
pool) {
132 for (dbh_ptr =
sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->
next) {
133 if (dbh_ptr == dbh) {
156 for (dbh_ptr =
sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->
next) {
197 for (dbh_ptr =
sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->
next) {
209 for (dbh_ptr =
sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->
next) {
259 #define SQL_CACHE_TIMEOUT 30 260 #define SQL_REG_TIMEOUT 15 276 if (prune > 0 && prune > dbh->
last_used) {
329 if (sanity) sanity--;
353 switch((*dbh)->type) {
356 switch_database_interface_t *database_interface = (*dbh)->native_handle.database_interface_dbh->connection_options.database_interface;
357 database_interface->
flush((*dbh)->native_handle.database_interface_dbh);
365 if ((*dbh)->use_count) {
385 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 397 char *colon_slashes = NULL;
398 if (NULL != (colon_slashes = strstr(dsn,
"://")))
400 char prefix[16] =
"";
401 strncpy(prefix, dsn,
MIN(colon_slashes - dsn, 15));
403 if (!strncasecmp(prefix,
"odbc", 4)) {
406 else if (!strncasecmp(prefix,
"sqlite", 6)) {
414 else if (strchr(dsn + 2,
':')) {
428 const char *file,
const char *func,
int line)
434 const char *file,
const char *func,
int line)
444 char *colon_slashes = NULL;
445 if ( NULL != (colon_slashes = strstr(dsn,
"://")) )
447 char prefix[16] =
"";
448 strncpy(prefix, dsn,
MIN(colon_slashes - dsn, 15));
463 if (!strncasecmp(dsn,
"sqlite://", 9)) {
471 else if ((!(i = strncasecmp(dsn,
"odbc://", 7))) || (strchr(dsn + 2,
':') && !colon_slashes)) {
483 if ((p = strchr(tmp,
':'))) {
510 const char *file,
const char *func,
int line)
518 uint32_t yield_len = 100000, total_yield = 0;
520 const char *db_name = NULL;
521 const char *odbc_user = NULL;
522 const char *odbc_pass = NULL;
523 const char *db_type = NULL;
532 total_yield += yield_len;
547 db_type =
"database_interface";
572 if (odbc_user || odbc_pass) {
573 snprintf(db_str,
sizeof(db_str) - 1,
"db=\"%s\";type=\"%s\"user=\"%s\";pass=\"%s\"", db_name, db_type, odbc_user, odbc_pass);
575 snprintf(db_str,
sizeof(db_str) - 1,
"db=\"%s\",type=\"%s\"", db_name, db_type);
577 snprintf(db_callsite_str,
sizeof(db_callsite_str) - 1,
"%s:%d", file, line);
578 snprintf(thread_str,
sizeof(thread_str) - 1,
"thread=\"%lu\"", (
unsigned long) (intptr_t)
self);
580 if ((new_dbh =
get_handle(db_str, db_callsite_str, thread_str))) {
603 if (database_interface_dbh) {
644 if (!db && !odbc_dbh && !database_interface_dbh) {
654 if (database_interface_dbh) {
664 }
else if (odbc_dbh) {
668 add_handle(new_dbh, db_str, db_callsite_str, thread_str);
756 if (chunk_size > len) {
760 if (!(strlen(sql) / chunk_size)) {
775 if (*p ==
'\n' && *(p - 1) ==
';') {
831 int affected_rows = 0;
833 return affected_rows;
881 while (running < 5000) {
883 const unsigned char *txt;
935 while (retries > 0) {
944 if (retries == 0 && forever) {
959 char *sql, uint32_t retries,
960 const char *pre_trans_execute,
961 const char *post_trans_execute,
962 const char *inner_pre_trans_execute,
963 const char *inner_post_trans_execute)
968 unsigned begin_retries = 100;
976 if (!
zstr(pre_trans_execute)) {
986 while (begin_retries > 0) {
1001 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to Set AutoCommit Off", result);
1002 errmsg = strdup(tmp);
1013 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to Set AutoCommit Off", result);
1014 errmsg = strdup(tmp);
1022 if (strstr(errmsg,
"cannot start a transaction within a transaction")) {
1049 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to commit transaction", result);
1060 if (begin_retries == 0) {
1071 if (!
zstr(inner_pre_trans_execute)) {
1079 while (retries > 0) {
1089 if (retries == 0 && forever) {
1099 if (!
zstr(inner_post_trans_execute)) {
1128 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to commit transaction", result);
1134 if (!
zstr(post_trans_execute)) {
1169 char *errmsg = NULL;
1179 switch (dbh->
type) {
1186 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to execute_sql_event_callback", status);
1205 if (!strstr(errmsg,
"query abort")) {
1220 void *
pdata,
char **err)
1223 char *errmsg = NULL;
1234 switch (dbh->
type) {
1241 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to execute_sql_event_callback_err", status);
1245 (*err_callback)(
pdata, (
const char*)*err);
1253 (*err_callback)(
pdata, (
const char*)*err);
1267 if (!strstr(errmsg,
"query abort")) {
1272 (*err_callback)(
pdata, errmsg);
1289 char *errmsg = NULL;
1295 switch (dbh->
type) {
1302 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to execute_sql_callback", status);
1321 if (!strstr(errmsg,
"query abort")) {
1338 char *errmsg = NULL;
1344 switch (dbh->
type) {
1351 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to execute_sql_callback_err", status);
1355 (*err_callback)(
pdata, (
const char*)*err);
1363 (*err_callback)(
pdata, (
const char*)*err);
1377 if (!strstr(errmsg,
"query abort")) {
1382 (*err_callback)(
pdata, errmsg);
1423 const char *test_sql,
const char *drop_sql,
const char *reactive_sql)
1429 const char *test_sql,
const char *drop_sql,
const char *reactive_sql,
const char *row_size_limited_reactive_sql)
1446 switch (dbh->
type) {
1454 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to test_reactive with test_sql", result);
1459 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to test_reactive with drop_sql", result);
1465 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to test_reactive with reactive_sql", result);
1469 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to test_reactive with row_size_limited_reactive_sql", result);
1490 char *errmsg = NULL;
1525 int sec = 0, reg_sec = 0;;
1608 for (i = 0; i < qm->
numq; i++) {
1688 }
else if (event_callback) {
1705 if ((td =
new_job(qm, sql, callback, NULL, NULL, NULL, pdata))) {
1716 if ((td =
new_job(qm, sql, callback, err_callback, NULL, NULL, pdata))) {
1726 if ((td =
new_job(qm, sql, NULL, NULL, callback, NULL, pdata))) {
1738 if ((td =
new_job(qm, sql, NULL, NULL, callback, err_callback, pdata))) {
1782 for(i = 0; i < qm->
numq; i++) {
1794 if (index < qm->numq) {
1805 uint32_t i, sanity = 100;
1811 for(i = 0; i < qm->
numq; i++) {
1880 for(i = 0; i < qm->
numq; i++) {
1892 char *sqlptr = NULL;
1898 if (!dup) free((
char *)sql);
1904 if (!dup) free((
char *)sql);
1908 if (pos > qm->
numq - 1) {
1912 sqlptr = dup ? strdup(sql) : (
char *)sql;
1940 if (!dup) free((
char *)sql);
1950 if (!dup) free((
char *)sql);
1954 int size, x = 0, sanity = 0;
1955 uint32_t written, want;
1958 if (!dup) free((
char *)sql);
1964 if (!dup) free((
char *)sql);
1968 if (pos > qm->
numq - 1) {
1977 want = written + size;
1982 while((qm->
written[pos] < want) || (qm->
written[pos] >= written && want < written && qm->written[pos] > want)) {
1988 if (++sanity == 20) {
2008 uint32_t numq,
const char *dsn, uint32_t max_trans,
2009 const char *pre_trans_execute,
2010 const char *post_trans_execute,
2011 const char *inner_pre_trans_execute,
2012 const char *inner_post_trans_execute)
2018 if (!numq) numq = 1;
2038 for (i = 0; i < qm->
numq; i++) {
2042 if (pre_trans_execute) {
2045 if (post_trans_execute) {
2048 if (inner_pre_trans_execute) {
2051 if (inner_post_trans_execute) {
2063 char *errmsg = NULL;
2090 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to Set AutoCommit Off", result);
2091 errmsg = strdup(tmp);
2102 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to Set AutoCommit Off", result);
2103 errmsg = strdup(tmp);
2125 while(qm->
max_trans == 0 || ttl <= qm->max_trans) {
2180 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to commit transaction", result);
2196 for (i = 0; i < qm->
numq; i++) {
2208 uint32_t sanity = 120;
2248 uint32_t written = 0, iterations = 0;
2255 for (i = 0; i < qm->
numq; i++) {
2266 iterations += written;
2270 char line[128] =
"";
2275 for (i = 0; i < qm->
numq; i++) {
2302 while (--i > 0 &&
qm_ttl(qm) < 500) {
2311 for(i = 0; i < qm->
numq; i++) {
2325 char *cols[128] = { 0 };
2331 char col_name[128] =
"";
2338 data_copy = strdup(data);
2344 for (i = 0; i < col_count; i++) {
2345 const char *val = NULL;
2356 r = (
char *) stream.
data;
2370 #define new_sql() switch_assert(sql_idx+1 < MAX_SQL); if (exists) sql[sql_idx++] 2371 #define new_sql_a() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++] 2415 new_sql() =
switch_mprintf(
"insert into tasks (task_id, task_desc, task_group, task_runtime, task_sql_manager, hostname) " 2416 "values(%q,'%q','%q',%q,%q,'%q')",
2421 manager ? manager :
"0",
2438 new_sql() =
switch_mprintf(
"update tasks set task_desc='%q',task_group='%q', task_runtime=%q, task_sql_manager=%q where task_id=%q and hostname='%q'",
2442 manager ? manager :
"0",
2477 new_sql() =
switch_mprintf(
"insert into channels (uuid,direction,created,created_epoch, name,state,callstate,dialplan,context,hostname,initial_cid_name,initial_cid_num,initial_ip_addr,initial_dest,initial_dialplan,initial_context) " 2478 "values('%q','%q','%q','%ld','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
2501 (
"update channels set read_codec='%q',read_rate='%q',read_bit_rate='%q',write_codec='%q',write_rate='%q',write_bit_rate='%q' where uuid='%q'",
2515 "presence_id='%q',presence_data='%q',accountcode='%q' where uuid='%q'",
2531 "presence_id='%q',presence_data='%q',accountcode='%q',call_uuid='%q',%s where uuid='%q'",
2541 "presence_id='%q',presence_data='%q',accountcode='%q',call_uuid='%q' where uuid='%q'",
2554 new_sql() =
switch_mprintf(
"update channels set callee_name='%q',callee_num='%q',sent_callee_name='%q',sent_callee_num='%q',callee_direction='%q'," 2555 "cid_name='%q',cid_num='%q' where uuid='%q'",
2573 callstate = atoi(num);
2598 state_i = atoi(state);
2605 #ifndef SWITCH_DEPRECATED_CORE_DB 2610 #ifdef SWITCH_DEPRECATED_CORE_DB 2633 new_sql() =
switch_mprintf(
"update channels set state='%q',cid_name='%q',cid_num='%q',callee_name='%q',callee_num='%q'," 2634 "sent_callee_name='%q',sent_callee_num='%q'," 2635 "ip_addr='%q',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q',accountcode='%q',%s " 2655 new_sql() =
switch_mprintf(
"update channels set state='%q',cid_name='%q',cid_num='%q',callee_name='%q',callee_num='%q'," 2656 "sent_callee_name='%q',sent_callee_num='%q'," 2657 "ip_addr='%q',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q',accountcode='%q' " 2689 const char *a_uuid, *b_uuid, *uuid;
2695 if (
zstr(a_uuid) ||
zstr(b_uuid)) {
2710 "caller_uuid,callee_uuid,hostname) " 2711 "values ('%q','%q','%ld','%q','%q','%q')",
2740 "delete from interfaces where hostname='%q';" 2741 "delete from calls where hostname='%q'",
2758 (
"insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')", type, name,
2770 new_sql() =
switch_mprintf(
"delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
2791 if (!strcmp(
"add", op)) {
2792 new_sql() =
switch_mprintf(
"insert into nat (port, proto, sticky, hostname) values (%q, %q, %d,'%q')",
2796 }
else if (!strcmp(
"del", op)) {
2800 }
else if (!strcmp(
"status", op)) {
2802 }
else if (!strcmp(
"status_response", op)) {
2817 for (i = 0; i < sql_idx; i++) {
2830 "CREATE TABLE complete (\n" 2831 " sticky INTEGER,\n" 2832 " a1 VARCHAR(128),\n" 2833 " a2 VARCHAR(128),\n" 2834 " a3 VARCHAR(128),\n" 2835 " a4 VARCHAR(128),\n" 2836 " a5 VARCHAR(128),\n" 2837 " a6 VARCHAR(128),\n" 2838 " a7 VARCHAR(128),\n" 2839 " a8 VARCHAR(128),\n" 2840 " a9 VARCHAR(128),\n" 2841 " a10 VARCHAR(128),\n" 2842 " hostname VARCHAR(256)\n" 2846 "CREATE TABLE aliases (\n" 2847 " sticky INTEGER,\n" 2848 " alias VARCHAR(128),\n" 2849 " command VARCHAR(4096),\n" 2850 " hostname VARCHAR(256)\n" 2854 "CREATE TABLE channels (\n" 2855 " uuid VARCHAR(256),\n" 2856 " direction VARCHAR(32),\n" 2857 " created VARCHAR(128),\n" 2858 " created_epoch INTEGER,\n" 2859 " name VARCHAR(1024),\n" 2860 " state VARCHAR(64),\n" 2861 " cid_name VARCHAR(1024),\n" 2862 " cid_num VARCHAR(256),\n" 2863 " ip_addr VARCHAR(256),\n" 2864 " dest VARCHAR(1024),\n" 2865 " application VARCHAR(128),\n" 2866 " application_data VARCHAR(4096),\n" 2867 " dialplan VARCHAR(128),\n" 2868 " context VARCHAR(128),\n" 2869 " read_codec VARCHAR(128),\n" 2870 " read_rate VARCHAR(32),\n" 2871 " read_bit_rate VARCHAR(32),\n" 2872 " write_codec VARCHAR(128),\n" 2873 " write_rate VARCHAR(32),\n" 2874 " write_bit_rate VARCHAR(32),\n" 2875 " secure VARCHAR(64),\n" 2876 " hostname VARCHAR(256),\n" 2877 " presence_id VARCHAR(4096),\n" 2878 " presence_data VARCHAR(4096),\n" 2879 " accountcode VARCHAR(256),\n" 2880 " callstate VARCHAR(64),\n" 2881 " callee_name VARCHAR(1024),\n" 2882 " callee_num VARCHAR(256),\n" 2883 " callee_direction VARCHAR(5),\n" 2884 " call_uuid VARCHAR(256),\n" 2885 " sent_callee_name VARCHAR(1024),\n" 2886 " sent_callee_num VARCHAR(256),\n" 2887 " initial_cid_name VARCHAR(1024),\n" 2888 " initial_cid_num VARCHAR(256),\n" 2889 " initial_ip_addr VARCHAR(256),\n" 2890 " initial_dest VARCHAR(1024),\n" 2891 " initial_dialplan VARCHAR(128),\n" 2892 " initial_context VARCHAR(128)\n" 2896 "CREATE TABLE channels (\n" 2897 " uuid VARCHAR(256),\n" 2898 " direction VARCHAR(32),\n" 2899 " created VARCHAR(128),\n" 2900 " created_epoch INTEGER,\n" 2901 " name VARCHAR(1024),\n" 2902 " state VARCHAR(64),\n" 2903 " cid_name VARCHAR(1024),\n" 2904 " cid_num VARCHAR(256),\n" 2905 " ip_addr VARCHAR(256),\n" 2906 " dest VARCHAR(1024),\n" 2907 " application VARCHAR(128),\n" 2908 " application_data TEXT,\n" 2909 " dialplan VARCHAR(128),\n" 2910 " context VARCHAR(128),\n" 2911 " read_codec VARCHAR(128),\n" 2912 " read_rate VARCHAR(32),\n" 2913 " read_bit_rate VARCHAR(32),\n" 2914 " write_codec VARCHAR(128),\n" 2915 " write_rate VARCHAR(32),\n" 2916 " write_bit_rate VARCHAR(32),\n" 2917 " secure VARCHAR(64),\n" 2918 " hostname VARCHAR(256),\n" 2919 " presence_id VARCHAR(4096),\n" 2920 " presence_data TEXT,\n" 2921 " accountcode VARCHAR(256),\n" 2922 " callstate VARCHAR(64),\n" 2923 " callee_name VARCHAR(1024),\n" 2924 " callee_num VARCHAR(256),\n" 2925 " callee_direction VARCHAR(5),\n" 2926 " call_uuid VARCHAR(256),\n" 2927 " sent_callee_name VARCHAR(1024),\n" 2928 " sent_callee_num VARCHAR(256),\n" 2929 " initial_cid_name VARCHAR(1024),\n" 2930 " initial_cid_num VARCHAR(256),\n" 2931 " initial_ip_addr VARCHAR(256),\n" 2932 " initial_dest VARCHAR(1024),\n" 2933 " initial_dialplan VARCHAR(128),\n" 2934 " initial_context VARCHAR(128)\n" 2938 "CREATE TABLE calls (\n" 2939 " call_uuid VARCHAR(255),\n" 2940 " call_created VARCHAR(128),\n" 2941 " call_created_epoch INTEGER,\n" 2942 " caller_uuid VARCHAR(256),\n" 2943 " callee_uuid VARCHAR(256),\n" 2944 " hostname VARCHAR(256)\n" 2948 "CREATE TABLE interfaces (\n" 2949 " type VARCHAR(128),\n" 2950 " name VARCHAR(1024),\n" 2951 " description VARCHAR(4096),\n" 2952 " ikey VARCHAR(1024),\n" 2953 " filename VARCHAR(4096),\n" 2954 " syntax VARCHAR(4096),\n" 2955 " hostname VARCHAR(256)\n" 2959 "CREATE TABLE tasks (\n" 2960 " task_id INTEGER,\n" 2961 " task_desc VARCHAR(4096),\n" 2962 " task_group VARCHAR(1024),\n" 2963 " task_runtime BIGINT,\n" 2964 " task_sql_manager INTEGER,\n" 2965 " hostname VARCHAR(256)\n" 2969 "CREATE TABLE nat (\n" 2970 " sticky INTEGER,\n" 2973 " hostname VARCHAR(256)\n" 2978 "CREATE TABLE registrations (\n" 2979 " reg_user VARCHAR(256),\n" 2980 " realm VARCHAR(256),\n" 2981 " token VARCHAR(256),\n" 2984 " expires INTEGER,\n" 2985 " network_ip VARCHAR(256),\n" 2986 " network_port VARCHAR(256),\n" 2987 " network_proto VARCHAR(256),\n" 2988 " hostname VARCHAR(256),\n" 2989 " metadata VARCHAR(256)\n" 2996 "create view detailed_calls as select " 2998 "a.direction as direction," 2999 "a.created as created," 3000 "a.created_epoch as created_epoch," 3003 "a.cid_name as cid_name," 3004 "a.cid_num as cid_num," 3005 "a.ip_addr as ip_addr," 3007 "a.application as application," 3008 "a.application_data as application_data," 3009 "a.dialplan as dialplan," 3010 "a.context as context," 3011 "a.read_codec as read_codec," 3012 "a.read_rate as read_rate," 3013 "a.read_bit_rate as read_bit_rate," 3014 "a.write_codec as write_codec," 3015 "a.write_rate as write_rate," 3016 "a.write_bit_rate as write_bit_rate," 3017 "a.secure as secure," 3018 "a.hostname as hostname," 3019 "a.presence_id as presence_id," 3020 "a.presence_data as presence_data," 3021 "a.accountcode as accountcode," 3022 "a.callstate as callstate," 3023 "a.callee_name as callee_name," 3024 "a.callee_num as callee_num," 3025 "a.callee_direction as callee_direction," 3026 "a.call_uuid as call_uuid," 3027 "a.sent_callee_name as sent_callee_name," 3028 "a.sent_callee_num as sent_callee_num," 3030 "b.direction as b_direction," 3031 "b.created as b_created," 3032 "b.created_epoch as b_created_epoch," 3034 "b.state as b_state," 3035 "b.cid_name as b_cid_name," 3036 "b.cid_num as b_cid_num," 3037 "b.ip_addr as b_ip_addr," 3039 "b.application as b_application," 3040 "b.application_data as b_application_data," 3041 "b.dialplan as b_dialplan," 3042 "b.context as b_context," 3043 "b.read_codec as b_read_codec," 3044 "b.read_rate as b_read_rate," 3045 "b.read_bit_rate as b_read_bit_rate," 3046 "b.write_codec as b_write_codec," 3047 "b.write_rate as b_write_rate," 3048 "b.write_bit_rate as b_write_bit_rate," 3049 "b.secure as b_secure," 3050 "b.hostname as b_hostname," 3051 "b.presence_id as b_presence_id," 3052 "b.presence_data as b_presence_data," 3053 "b.accountcode as b_accountcode," 3054 "b.callstate as b_callstate," 3055 "b.callee_name as b_callee_name," 3056 "b.callee_num as b_callee_num," 3057 "b.callee_direction as b_callee_direction," 3058 "b.call_uuid as b_call_uuid," 3059 "b.sent_callee_name as b_sent_callee_name," 3060 "b.sent_callee_num as b_sent_callee_num," 3061 "c.call_created_epoch as call_created_epoch " 3063 "left join calls c on a.uuid = c.caller_uuid and a.hostname = c.hostname " 3064 "left join channels b on b.uuid = c.callee_uuid and b.hostname = c.hostname " 3065 "where a.uuid = c.caller_uuid or a.uuid not in (select callee_uuid from calls)";
3069 "CREATE TABLE recovery (\n" 3070 " runtime_uuid VARCHAR(255),\n" 3071 " technology VARCHAR(255),\n" 3072 " profile_name VARCHAR(255),\n" 3073 " hostname VARCHAR(255),\n" 3074 " uuid VARCHAR(255),\n" 3079 "create view basic_calls as select " 3081 "a.direction as direction," 3082 "a.created as created," 3083 "a.created_epoch as created_epoch," 3086 "a.cid_name as cid_name," 3087 "a.cid_num as cid_num," 3088 "a.ip_addr as ip_addr," 3091 "a.presence_id as presence_id," 3092 "a.presence_data as presence_data," 3093 "a.accountcode as accountcode," 3094 "a.callstate as callstate," 3095 "a.callee_name as callee_name," 3096 "a.callee_num as callee_num," 3097 "a.callee_direction as callee_direction," 3098 "a.call_uuid as call_uuid," 3099 "a.hostname as hostname," 3100 "a.sent_callee_name as sent_callee_name," 3101 "a.sent_callee_num as sent_callee_num," 3105 "b.direction as b_direction," 3106 "b.created as b_created," 3107 "b.created_epoch as b_created_epoch," 3109 "b.state as b_state," 3110 "b.cid_name as b_cid_name," 3111 "b.cid_num as b_cid_num," 3112 "b.ip_addr as b_ip_addr," 3115 "b.presence_id as b_presence_id," 3116 "b.presence_data as b_presence_data," 3117 "b.accountcode as b_accountcode," 3118 "b.callstate as b_callstate," 3119 "b.callee_name as b_callee_name," 3120 "b.callee_num as b_callee_num," 3121 "b.callee_direction as b_callee_direction," 3122 "b.sent_callee_name as b_sent_callee_name," 3123 "b.sent_callee_num as b_sent_callee_num," 3124 "c.call_created_epoch as call_created_epoch " 3127 "left join calls c on a.uuid = c.caller_uuid and a.hostname = c.hostname " 3128 "left join channels b on b.uuid = c.callee_uuid and b.hostname = c.hostname " 3129 "where a.uuid = c.caller_uuid or a.uuid not in (select callee_uuid from calls)";
3143 if (
zstr(technology)) {
3145 if (
zstr(profile_name)) {
3152 if (
zstr(profile_name)) {
3153 sql =
switch_mprintf(
"delete from recovery where technology='%q' ", technology);
3155 sql =
switch_mprintf(
"delete from recovery where technology='%q' and profile_name='%q'", technology, profile_name);
3170 int *rp = (
int *) pArg;
3233 int recovery_skip_announcement_type_applications =
switch_channel_var_true(channel,
"recovery_skip_announcement_type_applications");
3238 if (!recovery_skip_announcement_type_applications || (strcasecmp(var,
"speak") && strcasecmp(var,
"playback") && strcasecmp(var,
"gentones") && strcasecmp(var,
"say"))) {
3274 char *errmsg = NULL;
3288 if (
zstr(technology)) {
3290 if (
zstr(profile_name)) {
3291 sql =
switch_mprintf(
"select technology, profile_name, hostname, uuid, metadata " 3292 "from recovery where runtime_uuid!='%q'",
3295 sql =
switch_mprintf(
"select technology, profile_name, hostname, uuid, metadata " 3296 "from recovery where runtime_uuid!='%q' and profile_name='%q'",
3302 if (
zstr(profile_name)) {
3303 sql =
switch_mprintf(
"select technology, profile_name, hostname, uuid, metadata " 3304 "from recovery where technology='%q' and runtime_uuid!='%q'",
3307 sql =
switch_mprintf(
"select technology, profile_name, hostname, uuid, metadata " 3308 "from recovery where technology='%q' and runtime_uuid!='%q' and profile_name='%q'",
3323 if (
zstr(technology)) {
3324 if (
zstr(profile_name)) {
3325 sql =
switch_mprintf(
"delete from recovery where runtime_uuid!='%q'",
3328 sql =
switch_mprintf(
"delete from recovery where runtime_uuid!='%q' and profile_name='%q'",
3332 if (
zstr(profile_name)) {
3333 sql =
switch_mprintf(
"delete from recovery where runtime_uuid!='%q' and technology='%q' ",
3336 sql =
switch_mprintf(
"delete from recovery where runtime_uuid!='%q' and technology='%q' and profile_name='%q'",
3404 sql =
switch_mprintf(
"delete from recovery where runtime_uuid='%q' and uuid='%q'",
3418 char *xml_cdr_text = NULL;
3421 const char *profile_name;
3422 const char *technology;
3448 sql =
switch_mprintf(
"insert into recovery (runtime_uuid, technology, profile_name, hostname, uuid, metadata) " 3449 "values ('%q','%q','%q','%q','%q','%q')",
3466 const char *network_ip,
const char *network_port,
const char *network_proto,
3467 const char *metadata)
3476 sql =
switch_mprintf(
"delete from registrations where hostname='%q' and (url='%q' or token='%q')",
3479 sql =
switch_mprintf(
"delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'",
3485 if ( !
zstr(metadata) ) {
3486 sql =
switch_mprintf(
"insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname,metadata) " 3487 "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%q')",
3500 sql =
switch_mprintf(
"insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) " 3501 "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
3602 char *tables[] = {
"channels",
"calls",
"tasks", NULL };
3606 for (i = 0; tables[i]; i++) {
3607 switch_snprintfv(sql,
sizeof(sql),
"delete from %q where hostname='%q'", tables[i], hostname);
3654 switch_cache_db_test_reactive_ex(
sql_manager.dbh,
"select call_uuid, read_bit_rate, sent_callee_name, initial_cid_name, initial_cid_num, initial_ip_addr, initial_dest, initial_dialplan, initial_context, accountcode from channels",
"DROP TABLE channels",
create_channels_sql,
create_row_size_limited_channels_sql);
3664 "DROP TABLE registrations", tmp);
3684 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to Set AutoCommit Off", result);
3696 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to Set AutoCommit Off", result);
3718 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to commit transaction.", result);
3730 switch_snprintfv(tmp,
sizeof(tmp),
"%q-%i",
"Unable to commit transaction", result);
3770 char *tables[] = {
"complete",
"aliases",
"nat", NULL };
3774 for (i = 0; tables[i]; i++) {
3775 switch_snprintfv(sql,
sizeof(sql),
"delete from %q where sticky=0 and hostname='%q'", tables[i], hostname);
3779 switch_snprintfv(sql,
sizeof(sql),
"delete from interfaces where hostname='%q'", hostname);
3795 switch_cache_db_create_schema(
sql_manager.dbh,
"create index complete11 on complete (a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,hostname)", NULL);
3818 #ifdef SWITCH_SQL_BIND_EVERY_EVENT 3944 int count = 0, used = 0;
3953 needles[0] =
"pass=\"";
3954 needles[1] =
"password=";
3955 needles[2] =
"password='";
3967 memset(cleankey_str, 0,
sizeof(cleankey_str));
3968 for (i = 0; i < 3; i++) {
3969 if((pos1 = strstr(dbh->
name, needles[i]))) {
3970 pos1 += strlen(needles[i]);
3972 if (!(pos2 = strstr(pos1,
"\""))) {
3973 if (!(pos2 = strstr(pos1,
"'"))) {
3974 if (!(pos2 = strstr(pos1,
" "))) {
3975 pos2 = pos1 + strlen(pos1);
3979 strncpy(cleankey_str, dbh->
name, pos1 - dbh->
name);
3980 strcpy(&cleankey_str[pos1 - dbh->
name], pos2);
3985 snprintf(cleankey_str,
sizeof(cleankey_str),
"%s", dbh->
name);
3994 stream->
write_function(stream,
"%s\n\tType: %s\n\tLast used: %d\n\tTotal used: %ld\n\tFlags: %s, %s(%d)%s\n" 3995 "\tCreator: %s\n\tLast User: %s\n",
4000 locked ?
"Locked" :
"Unlocked",
4004 stream->
write_function(stream,
"%d total. %d in use.\n", count, used);
#define SWITCH_SQL_QUEUE_LEN
#define switch_event_get_header_nil(e, h)
switch_status_t switch_cache_db_create_schema(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the create schema sql.
const char * switch_core_get_switchname(void)
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
switch_mutex_t * cond2_mutex
unsigned int switch_queue_size(switch_queue_t *queue)
#define switch_strdup(ptr, s)
switch_event_types_t event_id
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_bool_t make_module_no_unloadable
char * core_db_inner_post_trans_execute
switch_cache_db_native_handle_t native_handle
char * switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err)
Executes the sql and returns the result as a string.
const char * switch_xml_attr_soft(_In_ switch_xml_t xml, _In_z_ const char *attr)
returns the value of the requested tag attribute, or "" if not found
switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
switch_odbc_status_t switch_odbc_handle_exec_string(switch_odbc_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err)
#define SWITCH_CHANNEL_SESSION_LOG(x)
An Abstract Representation of a dialplan extension.
switch_core_db_t * handle
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
#define SWITCH_CHANNEL_LOG
void switch_cache_db_database_interface_flush_handles(switch_database_interface_t *database_interface)
switch_xml_t switch_xml_parse_str_dynamic(_In_z_ char *s, _In_ switch_bool_t dup)
Parses a string into a switch_xml_t, ensuring the memory will be freed with switch_xml_free.
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
switch_status_t(* commit)(switch_database_interface_handle_t *dih)
switch_cache_db_handle_t * event_db
static char create_interfaces_sql[]
struct switch_odbc_handle switch_odbc_handle_t
#define switch_odbc_handle_callback_exec(handle, sql, callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
static switch_cache_db_handle_t * create_handle(switch_cache_db_handle_type_t type)
Abstraction of an module endpoint interface This is the glue between the abstract idea of a "channel"...
char * inner_pre_trans_execute
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
switch_status_t _switch_core_db_handle(switch_cache_db_handle_t **dbh, const char *file, const char *func, int line)
Open the default system database.
switch_status_t switch_core_check_core_db_dsn(void)
Returns error if no suitable database interface found to serve core db dsn.
static void del_handle(switch_cache_db_handle_t *dbh)
switch_status_t(* exec_string)(switch_database_interface_handle_t *dih, const char *sql, char *resbuf, size_t len, char **err)
char * core_db_post_trans_execute
switch_cache_db_handle_type_t type
switch_cache_db_core_db_options_t core_db_options
int switch_odbc_handle_affected_rows(switch_odbc_handle_t *handle)
switch_status_t switch_cache_db_persistant_execute_trans_full(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries, const char *pre_trans_execute, const char *post_trans_execute, const char *inner_pre_trans_execute, const char *inner_post_trans_execute)
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
switch_core_db_event_callback_func_t callback
#define switch_split(_data, _delim, _array)
void switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
switch_mutex_t * cond_mutex
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
switch_status_t(* sql_set_auto_commit_attr)(switch_database_interface_handle_t *dih, switch_bool_t on)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
#define SWITCH_EVENT_SUBCLASS_ANY
Representation of an event.
#define SQL_CACHE_TIMEOUT
switch_core_session_t * switch_core_session_request_xml(switch_endpoint_interface_t *endpoint_interface, switch_memory_pool_t **pool, switch_xml_t xml)
char * inner_post_trans_execute
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
static char create_tasks_sql[]
switch_odbc_status_t switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err)
switch_core_db_t * switch_core_db_open_in_memory(const char *uri)
Open a core db (SQLite) in-memory.
void switch_sql_queue_manager_pause(switch_sql_queue_manager_t *qm, switch_bool_t flush)
static const char * switch_cache_db_type_name(switch_cache_db_handle_type_t type)
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
void switch_sql_queue_manager_resume(switch_sql_queue_manager_t *qm)
switch_cache_db_database_interface_options_t connection_options
switch_status_t switch_cache_db_execute_sql_event_callback(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_event_callback_func_t callback, void *pdata, char **err)
int switch_core_db_close(switch_core_db_t *db)
A representation of an XML tree.
#define switch_cache_db_get_db_handle_dsn(_a, _b)
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
switch_status_t switch_core_del_registration(const char *user, const char *realm, const char *token)
Delete user registration.
void switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, immediately available for other threads to use.
switch_memory_pool_t * pool
char creator[CACHE_DB_LEN]
switch_memory_pool_t * memory_pool
#define SWITCH_CORE_DB_BUSY
switch_status_t switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm)
void switch_core_recovery_track(switch_core_session_t *session)
int switch_core_recovery_recover(const char *technology, const char *profile_name)
static switch_thread_t * thread
switch_status_t switch_database_available(char *dsn)
Returns error if no suitable database interface found for a dsn.
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
int switch_core_db_finalize(switch_core_db_stmt_t *pStmt)
void switch_core_recovery_flush(const char *technology, const char *profile_name)
struct switch_runtime runtime
switch_status_t switch_sql_queue_manager_push_confirm(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
char last_user[CACHE_DB_LEN]
switch_status_t switch_loadable_module_protect(const char *mod)
Protect module from beeing unloaded.
switch_sql_queue_manager_t * qm
static void switch_core_sqldb_start_thread(void)
switch_coredb_handle_t * core_db_dbh
switch_status_t(* flush)(switch_database_interface_handle_t *dih)
const char * original_dsn
int switch_core_db_step(switch_core_db_stmt_t *stmt)
switch_mutex_t * dbh_mutex
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
#define SWITCH_CORE_DB_OK
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_status_t switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries)
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
static void add_handle(switch_cache_db_handle_t *dbh, const char *db_str, const char *db_callsite_str, const char *thread_str)
struct switch_cache_db_handle * next
#define UNPROTECT_INTERFACE(_it)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
#define SWITCH_MUTEX_NESTED
int switch_sql_queue_manager_size(switch_sql_queue_manager_t *qm, uint32_t index)
void switch_cache_db_flush_handles(void)
switch_status_t _switch_cache_db_get_db_handle_dsn(switch_cache_db_handle_t **dbh, const char *dsn, const char *file, const char *func, int line)
static char recovery_sql[]
static char * parse_presence_data_cols(switch_event_t *event)
switch_status_t switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data)
Bind an event callback to a specific event.
switch_dbtype_t odbc_dbtype
void switch_core_sqldb_stop(void)
switch_database_interface_t * switch_loadable_module_get_database_interface(const char *name, const char *modname)
Retrieve the database interface by it's registered name.
switch_cache_db_handle_type_t switch_cache_db_get_type(switch_cache_db_handle_t *dbh)
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
switch_channel_t * channel
static switch_thread_data_t * new_job(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, switch_core_db_event_callback_func_t event_callback, switch_core_db_err_callback_func_t event_err_callback, void *pdata)
static uint32_t do_trans(switch_sql_queue_manager_t *qm)
switch_queue_t ** sql_queue
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
switch_core_db_err_callback_func_t event_err_callback
static char create_channels_sql[]
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
int switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh)
Get the affected rows of the last performed query.
switch_cache_db_handle_type_t
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
#define switch_channel_get_variable(_c, _v)
#define SWITCH_THREAD_STACKSIZE
uint64_t total_used_count
int switch_core_db_load_extension(switch_core_db_t *db, const char *extension)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
static char create_nat_sql[]
switch_thread_start_t func
switch_status_t(* affected_rows)(switch_database_interface_handle_t *dih, int *affected_rows)
const char * interface_name
switch_core_db_err_callback_func_t err_callback
switch_memory_pool_t * pool
static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread, void *obj)
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
void switch_core_sqldb_resume(void)
switch_sql_queue_manager_t * qm
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
switch_bool_t switch_odbc_available(void)
void switch_core_sql_exec(const char *sql)
void switch_sql_queue_manager_execute_sql_event_callback_err(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_event_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata)
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
void switch_channel_set_caller_extension(switch_channel_t *channel, switch_caller_extension_t *caller_extension)
Assign a caller extension to a given channel.
int switch_cache_db_load_extension(switch_cache_db_handle_t *dbh, const char *extension)
load an external extension to db
uint32_t db_handle_timeout
void switch_caller_extension_add_application(_In_ switch_core_session_t *session, _In_ switch_caller_extension_t *caller_extension, _In_z_ const char *application_name, _In_z_ const char *extra_data)
Add an application (instruction) to the given extension.
static char create_calls_sql[]
int(* switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames)
pthread_t switch_thread_id_t
void switch_cond_next(void)
switch_status_t switch_cache_db_execute_sql_event_callback_err(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_event_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata, char **err)
static char detailed_calls_sql[]
void switch_cache_db_status(switch_stream_handle_t *stream)
Provides some feedback as to the status of the db connection pool.
#define SWITCH_STANDARD_STREAM(s)
switch_odbc_handle_t * odbc_dbh
switch_channel_callstate_t
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
switch_cache_db_odbc_options_t odbc_options
switch_database_interface_handle_t * database_interface_dbh
switch_caller_extension_t * switch_caller_extension_new(_In_ switch_core_session_t *session, _In_z_ const char *extension_name, _In_z_ const char *extension_number)
Create a new extension with desired parameters.
switch_cache_db_handle_t * handle_pool
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_cache_db_handle_t * dbh
switch_status_t(* handle_destroy)(switch_database_interface_handle_t **dih)
#define switch_core_db_handle(_a)
#define switch_str_nil(s)
Make a null string a blank string instead.
struct fspr_thread_mutex_t switch_mutex_t
void switch_core_sqldb_pause(void)
switch_memory_pool_t * pool
switch_status_t switch_thread_cond_signal(switch_thread_cond_t *cond)
static int switch_channel_var_true(switch_channel_t *channel, const char *variable)
void switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, handle is NOT available to other threads until the allocating thread ...
void switch_core_recovery_untrack(switch_core_session_t *session, switch_bool_t force)
switch_core_recover_callback_t recover_callback
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
static switch_cache_db_handle_t * get_handle(const char *db_str, const char *user_str, const char *thread_str)
uint32_t total_used_handles
switch_stream_handle_write_function_t write_function
switch_status_t
Common return values.
static char basic_calls_sql[]
char * switch_string_replace(const char *string, const char *search, const char *replace)
static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t *dbh, const char *sql, char **err)
#define switch_xml_toxml_nolock(xml, prn_header)
switch_status_t switch_sql_queue_manager_init_name(const char *name, switch_sql_queue_manager_t **qmp, uint32_t numq, const char *dsn, uint32_t max_trans, const char *pre_trans_execute, const char *post_trans_execute, const char *inner_pre_trans_execute, const char *inner_post_trans_execute)
switch_endpoint_interface_t * switch_loadable_module_get_endpoint_interface(const char *name)
Retrieve the endpoint interface by it's registered name.
void switch_sql_queue_manager_execute_sql_callback(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, void *pdata)
switch_status_t _switch_cache_db_get_db_handle_dsn_ex(switch_cache_db_handle_t **dbh, const char *dsn, switch_bool_t make_module_no_unloadable, const char *file, const char *func, int line)
static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *thread, void *obj)
const char * switch_core_get_hostname(void)
switch_status_t switch_core_expire_registration(int force)
Expire user registrations.
static int helper_callback(void *pArg, int argc, char **argv, char **columnNames)
unsigned long thread_hash
struct sqlite3 switch_core_db_t
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
static struct @4 sql_manager
switch_odbc_status_t switch_odbc_handle_connect(switch_odbc_handle_t *handle)
static int recover_callback(void *pArg, int argc, char **argv, char **columnNames)
switch_core_db_callback_func_t callback
int(* switch_core_db_event_callback_func_t)(void *pArg, switch_event_t *event)
int(* switch_core_db_err_callback_func_t)(void *pArg, const char *errmsg)
switch_cache_db_database_interface_options_t database_interface_options
int(* switch_core_recover_callback_t)(switch_core_session_t *session)
struct fspr_thread_cond_t switch_thread_cond_t
#define switch_event_get_header(_e, _h)
switch_odbc_status_t switch_odbc_SQLEndTran(switch_odbc_handle_t *handle, switch_bool_t commit)
#define switch_channel_set_flag(_c, _f)
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
switch_bool_t switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh, const char *test_sql, const char *drop_sql, const char *reactive_sql)
Performs test_sql and if it fails performs drop_sql and reactive_sql.
#define SWITCH_CORE_DB_ABORT
static char create_registrations_sql[]
static int qm_wake(switch_sql_queue_manager_t *qm)
#define switch_set_string(_dst, _src)
switch_thread_cond_t * cond
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
switch_status_t switch_event_create_array_pair(switch_event_t **event, char **names, char **vals, int len)
char * core_db_pre_trans_execute
static void switch_core_sqldb_stop_thread(void)
void switch_core_db_free(char *z)
struct sqlite3_stmt switch_core_db_stmt_t
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
switch_status_t switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp)
#define SWITCH_CORE_DB_ROW
switch_core_recover_callback_t switch_core_get_secondary_recover_callback(const char *key)
switch_status_t switch_sql_queue_manager_start(switch_sql_queue_manager_t *qm)
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
switch_status_t switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
Executes the sql and uses callback for row-by-row processing.
switch_bool_t switch_cache_db_test_reactive_ex(switch_cache_db_handle_t *dbh, const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql)
switch_status_t switch_event_unbind_callback(switch_event_callback_t callback)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
#define database_interface_handle_exec(database_interface, dih, sql, err)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
int switch_core_db_changes(switch_core_db_t *db)
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
#define PROTECT_INTERFACE(_it)
switch_endpoint_interface_t * endpoint_interface
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
struct fspr_pool_t switch_memory_pool_t
int switch_core_db_column_count(switch_core_db_stmt_t *pStmt)
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
static uint32_t qm_ttl(switch_sql_queue_manager_t *qm)
switch_thread_id_t switch_thread_self(void)
void switch_event_destroy(switch_event_t **event)
Destroy an event.
char * switch_sql_concat(void)
switch_mutex_t * ctl_mutex
switch_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
switch_core_db_event_callback_func_t event_callback
const unsigned char * switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
static char create_complete_sql[]
void switch_sql_queue_manager_execute_sql_event_callback(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_event_callback_func_t callback, void *pdata)
static void core_event_handler(switch_event_t *event)
char * core_db_inner_pre_trans_execute
int multiple_registrations
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
struct fspr_thread_t switch_thread_t
void switch_sql_queue_manager_execute_sql_callback_err(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata)
switch_odbc_handle_t * switch_odbc_handle_new(const char *dsn, const char *username, const char *password)
static void sql_close(time_t prune)
switch_database_interface_t * database_interface
switch_thread_t * db_thread
switch_status_t switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
Generate an XML CDR report.
switch_core_db_t * switch_core_db_open_file(const char *filename)
Open a core db (SQLite) file.
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t(* handle_new)(switch_cache_db_database_interface_options_t database_interface_options, switch_database_interface_handle_t **dih)
#define database_interface_handle_callback_exec(database_interface, dih, sql, callback, pdata, err)
Abstract interface to a database module.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
switch_status_t switch_cache_db_execute_sql_callback_err(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata, char **err)
Executes the sql and uses callback for row-by-row processing.
static void *SWITCH_THREAD_FUNC sql_in_thread(switch_thread_t *thread, void *obj)
switch_odbc_status_t switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
static char create_row_size_limited_channels_sql[]
int switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail)
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)
static void destroy_handle(switch_cache_db_handle_t **dbh)
char * post_trans_execute
static char create_alias_sql[]
switch_status_t switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires, const char *network_ip, const char *network_port, const char *network_proto, const char *metadata)
Add user registration.
switch_status_t _switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh, switch_cache_db_handle_type_t type, switch_cache_db_connection_options_t *connection_options, const char *file, const char *func, int line)
Gets a new cached handle from the pool, potentially creating a new connection. The connection is boun...
switch_loadable_module_interface_t * parent
switch_status_t switch_core_session_thread_launch(_In_ switch_core_session_t *session)
Launch the session thread (state machine) on a given session.
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
static switch_status_t switch_cache_db_execute_sql_chunked(switch_cache_db_handle_t *dbh, char *sql, uint32_t chunk_size, char **err)
switch_cache_db_handle_type_t switch_core_dbtype(void)
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)