diff --git a/libs/libdingaling/src/libdingaling.c b/libs/libdingaling/src/libdingaling.c index 37dd67ba5f..3b5fb39c1a 100644 --- a/libs/libdingaling/src/libdingaling.c +++ b/libs/libdingaling/src/libdingaling.c @@ -107,6 +107,7 @@ struct ldl_handle { apr_hash_t *sessions; apr_hash_t *retry_hash; apr_hash_t *probe_hash; + apr_hash_t *sub_hash; apr_thread_mutex_t *lock; apr_thread_mutex_t *flag_mutex; ldl_loop_callback_t loop_callback; @@ -438,6 +439,7 @@ static ldl_status parse_session_code(ldl_handle_t *handle, char *id, char *from, return LDL_STATUS_SUCCESS; } +const char *marker = "TRUE"; static int on_presence(void *user_data, ikspak *pak) { @@ -447,10 +449,12 @@ static int on_presence(void *user_data, ikspak *pak) char *resource; struct ldl_buffer *buffer; size_t x; - - //iks *msg = iks_make_s10n (IKS_TYPE_SUBSCRIBED, from, "Ding A Ling...."); - //apr_queue_push(handle->queue, msg); - + + if (!apr_hash_get(handle->sub_hash, from, APR_HASH_KEY_STRING)) { + apr_hash_set(handle->sub_hash, apr_pstrdup(handle->pool, from), APR_HASH_KEY_STRING, &marker); + iks *msg = iks_make_s10n (IKS_TYPE_SUBSCRIBED, from, "Ding A Ling...."); + apr_queue_push(handle->queue, msg); + } apr_cpystrn(id, from, sizeof(id)); if ((resource = strchr(id, '/'))) { @@ -517,42 +521,21 @@ static int on_commands(void *user_data, ikspak *pak) if (!strcasecmp(iks_name(tag), "bind")) { char *jid = iks_find_cdata(tag, "jid"); char *resource = strchr(jid, '/'); - iks *iq, *usersetting, *x; + iks *iq, *x; handle->acc->resource = apr_pstrdup(handle->pool, resource); handle->login = apr_pstrdup(handle->pool, jid); if ((iq = iks_new("iq"))) { - char *njid = strdup(handle->login); - if ((resource = strchr(njid, '/'))) { - *resource++ = '\0'; - } - iks_insert_attrib(iq, "type", "set"); - iks_insert_attrib(iq, "to", njid); - iks_insert_attrib(iq, "id", "params"); - - usersetting = iks_insert(iq, "usersetting"); - iks_insert_attrib(usersetting, "xmlns", "google:setting"); - x = iks_insert(usersetting, "autoacceptrequests"); - iks_insert_attrib(x, "value", "true"); - x = iks_insert(usersetting, "mailnotifications"); - iks_insert_attrib(x, "value", "false"); - free(njid); + iks_insert_attrib(iq, "type", "get"); + iks_insert_attrib(iq, "id", "roster"); + x = iks_insert(iq, "query"); + iks_insert_attrib(x, "xmlns", "jabber:iq:roster"); + iks_insert_attrib(x, "xmlns:gr", "google:roster"); + iks_insert_attrib(x, "gr:ext", "2"); + iks_insert_attrib(x, "gr:include", "all"); iks_send(handle->parser, iq); iks_delete(iq); - if ((iq = iks_new("iq"))) { - iks_insert_attrib(iq, "type", "get"); - iks_insert_attrib(iq, "id", "roster"); - x = iks_insert(iq, "query"); - iks_insert_attrib(x, "xmlns", "jabber:iq:roster"); - iks_insert_attrib(x, "xmlns:gr", "google:roster"); - iks_insert_attrib(x, "gr:ext", "2"); - iks_insert_attrib(x, "gr:include", "all"); - iks_send(handle->parser, iq); - iks_delete(iq); - } - - + break; } - break; } tag = iks_next_tag(tag); } @@ -1488,6 +1471,7 @@ ldl_status ldl_handle_init(ldl_handle_t **handle, new_handle->sessions = apr_hash_make(new_handle->pool); new_handle->retry_hash = apr_hash_make(new_handle->pool); new_handle->probe_hash = apr_hash_make(new_handle->pool); + new_handle->sub_hash = apr_hash_make(new_handle->pool); apr_thread_mutex_create(&new_handle->lock, APR_THREAD_MUTEX_NESTED, new_handle->pool); apr_thread_mutex_create(&new_handle->flag_mutex, APR_THREAD_MUTEX_NESTED, new_handle->pool); diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 381cad1b85..147f4ffa8b 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -173,6 +173,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses \param table optional state handler table to install on the channel \param cid_name_override override the caller id name \param cid_num_override override the caller id number + \param caller_profile_override override the entire calling caller profile \return SWITCH_STATUS_SUCCESS if bleg is a running session. */ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session, @@ -181,7 +182,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess uint32_t timelimit_sec, const switch_state_handler_table_t *table, char *cid_name_override, - char *cid_num_override); + char *cid_num_override, + switch_caller_profile_t *caller_profile_override); /*! \brief Bridge Audio from one session to another diff --git a/src/mod/applications/mod_bridgecall/mod_bridgecall.c b/src/mod/applications/mod_bridgecall/mod_bridgecall.c index 8192cce3a7..cc18d87d63 100644 --- a/src/mod/applications/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/applications/mod_bridgecall/mod_bridgecall.c @@ -50,7 +50,7 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) timelimit = atoi(var); } - if (switch_ivr_originate(session, &peer_session, data, timelimit, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_ivr_originate(session, &peer_session, data, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n"); switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL); return; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index cd7424fda1..4e9fb61845 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -260,7 +260,7 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises return SWITCH_STATUS_SUCCESS; } - if (switch_ivr_originate(NULL, &caller_session, aleg, timeout, NULL, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) { + if (switch_ivr_originate(NULL, &caller_session, aleg, timeout, NULL, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "Cannot Create Outgoing Channel! [%s]\n", aleg); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 2648b3e480..bf9632ab64 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1989,7 +1989,7 @@ static switch_status_t conference_outcall(conference_obj_t *conference, switch_channel_t *caller_channel = NULL; - if (switch_ivr_originate(session, &peer_session, bridgeto, timeout, &audio_bridge_peer_state_handlers, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) { + if (switch_ivr_originate(session, &peer_session, bridgeto, timeout, &audio_bridge_peer_state_handlers, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n"); if (session) { caller_channel = switch_core_session_get_channel(session); diff --git a/src/mod/codecs/mod_speex/Makefile b/src/mod/codecs/mod_speex/Makefile index 58ad5a6eb6..333989694a 100644 --- a/src/mod/codecs/mod_speex/Makefile +++ b/src/mod/codecs/mod_speex/Makefile @@ -1,7 +1,7 @@ all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) depends: - MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install speex-1.1.12.tar.gz --prefix=$(PREFIX) + MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install speex-1.1.12.tar.gz --prefix=$(PREFIX) --disable-shared --with-pic $(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(CC) $(CFLAGS) -fPIC -c $(MODNAME).c -o $(MODNAME).o diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index 6b11374488..302be63469 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -1500,22 +1500,34 @@ static void destroy_call_by_event(eXosip_event_t *event) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "destroy %s\n", switch_channel_get_name(channel)); exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL); + switch (event->type) { case EXOSIP_CALL_RELEASED: + switch_channel_set_variable(channel, "exosip_disposition", "RELEASED"); + cause = SWITCH_CAUSE_NORMAL_CLEARING; + break; case EXOSIP_CALL_CLOSED: + switch_channel_set_variable(channel, "exosip_disposition", "CLOSED"); cause = SWITCH_CAUSE_NORMAL_CLEARING; break; case EXOSIP_CALL_NOANSWER: + switch_channel_set_variable(channel, "exosip_disposition", "NO ANSWER"); cause = SWITCH_CAUSE_NO_ANSWER; break; case EXOSIP_CALL_REQUESTFAILURE: + switch_channel_set_variable(channel, "exosip_disposition", "REQUEST FAILURE"); cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL; break; case EXOSIP_CALL_SERVERFAILURE: + switch_channel_set_variable(channel, "exosip_disposition", "SERVER FAILURE"); + cause = SWITCH_CAUSE_CALL_REJECTED; + break; case EXOSIP_CALL_GLOBALFAILURE: + switch_channel_set_variable(channel, "exosip_disposition", "GLOBAL FAILURE"); cause = SWITCH_CAUSE_CALL_REJECTED; break; default: + switch_channel_set_variable(channel, "exosip_disposition", "UNKNOWN"); cause = SWITCH_CAUSE_SWITCH_CONGESTION; break; } diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index be62712df2..9bd0e4009a 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -1337,12 +1337,11 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { switch_memory_pool_t *pool = NULL; - if (argc > 2) { + if (argc > 1) { struct js_session *jss = NULL; JSObject *session_obj; switch_core_session_t *session = NULL, *peer_session = NULL; switch_caller_profile_t *caller_profile = NULL; - char *channel_type = NULL; char *dest = NULL; char *dialplan = NULL; char *cid_name = ""; @@ -1353,6 +1352,7 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval char *rdnis = ""; char *context = ""; char *username = NULL; + char *to = NULL; *rval = BOOLEAN_TO_JSVAL( JS_FALSE ); if (JS_ValueToObject(cx, argv[0], &session_obj)) { @@ -1362,35 +1362,37 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval } } - channel_type = JS_GetStringBytes(JS_ValueToString(cx, argv[1])); - dest = JS_GetStringBytes(JS_ValueToString(cx, argv[2])); + dest = JS_GetStringBytes(JS_ValueToString(cx, argv[1])); + if (argc > 2) { + dialplan = JS_GetStringBytes(JS_ValueToString(cx, argv[2])); + } if (argc > 3) { - dialplan = JS_GetStringBytes(JS_ValueToString(cx, argv[3])); + context = JS_GetStringBytes(JS_ValueToString(cx, argv[3])); } if (argc > 4) { - context = JS_GetStringBytes(JS_ValueToString(cx, argv[4])); + cid_name = JS_GetStringBytes(JS_ValueToString(cx, argv[4])); } if (argc > 5) { - cid_name = JS_GetStringBytes(JS_ValueToString(cx, argv[5])); + cid_num = JS_GetStringBytes(JS_ValueToString(cx, argv[5])); } if (argc > 6) { - cid_num = JS_GetStringBytes(JS_ValueToString(cx, argv[6])); + network_addr = JS_GetStringBytes(JS_ValueToString(cx, argv[6])); } if (argc > 7) { - network_addr = JS_GetStringBytes(JS_ValueToString(cx, argv[7])); + ani = JS_GetStringBytes(JS_ValueToString(cx, argv[7])); } if (argc > 8) { - ani = JS_GetStringBytes(JS_ValueToString(cx, argv[8])); + ani2 = JS_GetStringBytes(JS_ValueToString(cx, argv[8])); } if (argc > 9) { - ani2 = JS_GetStringBytes(JS_ValueToString(cx, argv[9])); + rdnis = JS_GetStringBytes(JS_ValueToString(cx, argv[9])); } if (argc > 10) { - rdnis = JS_GetStringBytes(JS_ValueToString(cx, argv[10])); + username = JS_GetStringBytes(JS_ValueToString(cx, argv[10])); } if (argc > 11) { - username = JS_GetStringBytes(JS_ValueToString(cx, argv[11])); + to = JS_GetStringBytes(JS_ValueToString(cx, argv[11])); } @@ -1399,20 +1401,34 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval return JS_FALSE; } - caller_profile = switch_caller_profile_new(pool, username, dialplan, cid_name, cid_num, network_addr, ani, ani2, rdnis, (char *)modname, context, dest); - if (switch_core_session_outgoing_channel(session, channel_type, caller_profile, &peer_session, pool) == SWITCH_STATUS_SUCCESS) { - jss = switch_core_session_alloc(peer_session, sizeof(*jss)); - jss->session = peer_session; - jss->flags = 0; - jss->cx = cx; - jss->obj = obj; - JS_SetPrivate(cx, obj, jss); - switch_core_session_thread_launch(peer_session); - switch_set_flag(jss, S_HUP); + caller_profile = switch_caller_profile_new(pool, + username, + dialplan, + cid_name, + cid_num, + network_addr, + ani, + ani2, + rdnis, + (char *)modname, + context, + dest); + + if (switch_ivr_originate(NULL, &peer_session, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot Create Outgoing Channel! [%s]\n", dest); return JS_TRUE; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Channel\n"); } + + switch_core_session_rwunlock(peer_session); + + jss = switch_core_session_alloc(peer_session, sizeof(*jss)); + jss->session = peer_session; + jss->flags = 0; + jss->cx = cx; + jss->obj = obj; + JS_SetPrivate(cx, obj, jss); + switch_set_flag(jss, S_HUP); + } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing Args\n"); } @@ -1494,6 +1510,9 @@ static void fileio_destroy(JSContext *cx, JSObject *obj) struct fileio_obj *fio = JS_GetPrivate(cx, obj); if (fio) { + if (fio->fd) { + switch_file_close(fio->fd); + } switch_memory_pool_t *pool = fio->pool; switch_core_destroy_memory_pool(&pool); pool = NULL; @@ -2214,7 +2233,6 @@ static JSBool js_bridge(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j { struct js_session *jss_a = NULL, *jss_b = NULL; JSObject *session_obj_a = NULL, *session_obj_b = NULL; - int32 timelimit = 60; if (argc > 1) { if (JS_ValueToObject(cx, argv[0], &session_obj_a)) { @@ -2231,12 +2249,6 @@ static JSBool js_bridge(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j } } - if (argc > 3) { - if (!JS_ValueToInt32(cx, argv[3], &timelimit)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Convert to INT\n"); - return JS_FALSE; - } - } if (!(jss_a && jss_b)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure! %s %s\n", jss_a ? "y" : "n", jss_b ? "y" : "n"); return JS_FALSE; diff --git a/src/switch_core.c b/src/switch_core.c index de6adf00f8..474a42aa72 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -247,11 +247,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_sessio { switch_status_t status = SWITCH_STATUS_SUCCESS; - if (!switch_channel_test_flag(session->channel, CF_LOCK_THREAD)) { - if ((status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock)) == SWITCH_STATUS_SUCCESS) { - switch_channel_set_flag(session->channel, CF_LOCK_THREAD); - } - } + + status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock); return status; } @@ -263,8 +260,9 @@ SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *sessi SWITCH_DECLARE(void) switch_core_session_rwunlock(switch_core_session_t *session) { - switch_channel_clear_flag(session->channel, CF_LOCK_THREAD); + switch_thread_rwlock_unlock(session->rwlock); + } SWITCH_DECLARE(switch_core_session_t *) switch_core_session_locate(char *uuid_str) diff --git a/src/switch_ivr.c b/src/switch_ivr.c index c8cdda3ad4..01b80e986a 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1280,7 +1280,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess uint32_t timelimit_sec, const switch_state_handler_table_t *table, char *cid_name_override, - char *cid_num_override) + char *cid_num_override, + switch_caller_profile_t *caller_profile_override + ) { char *peer_names[MAX_PEERS]; @@ -1361,8 +1363,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess goto done; } - caller_caller_profile = switch_channel_get_caller_profile(caller_channel); - + caller_caller_profile = caller_profile_override ? caller_profile_override : switch_channel_get_caller_profile(caller_channel); + if (!cid_name_override) { cid_name_override = caller_caller_profile->caller_id_name; } @@ -1515,14 +1517,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } - switch_core_session_reset(session); + if (session) { + switch_core_session_reset(session); + } for (i = 0; i < argc; i++) { if (!peer_channels[i]) { continue; } if (i != idx) { - switch_channel_hangup(peer_channels[i], SWITCH_CAUSE_LOSE_RACE); + if (caller_channel) { + switch_channel_set_variable(caller_channel, "originate_disposition", "lost race"); + switch_channel_hangup(peer_channels[i], SWITCH_CAUSE_LOSE_RACE); + } } } @@ -1542,9 +1549,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) { switch_core_session_read_lock(peer_session); *bleg = peer_session; + if (caller_channel) { + switch_channel_set_variable(caller_channel, "originate_disposition", "call accepted"); + } status = SWITCH_STATUS_SUCCESS; } else { - switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER); + if (caller_channel) { + switch_channel_set_variable(caller_channel, "originate_disposition", "no answer"); + switch_channel_hangup(caller_channel, SWITCH_CAUSE_NO_ANSWER); + } status = SWITCH_STATUS_FALSE; }