From 73ea37c5abbc26c79a8508271c8109b35666e7e9 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 5 Apr 2023 18:54:11 +0300 Subject: [PATCH 001/123] [Core] Coverity fixes * [core] coverity CID 1320751 (Dereference before null check) * [core] coverity CID 1294546 (Unchecked return value) * [core] coverity CID 1227661 (Logically dead code) * [core] coverity CID 1227656 (Logically dead code) * [core] coverity CID 1060948 (Explicit null dereferenced) * [core] coverity CID 1346465 (Unchecked return value) * [core] coverity CID 1364953 (Logically dead code) * [core] coverity CID 1468210 (Dereference before null check) * [core] coverity CID 1468546 (Dereference before null check) * [core] coverity CID 1468342 (Dereference before null check) --- src/switch_core_media.c | 8 ++------ src/switch_ivr_async.c | 11 ++++++----- src/switch_ivr_bridge.c | 2 +- src/switch_nat.c | 4 ++-- src/switch_rtp.c | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index d4954ee6b1..912d5a5012 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -6672,10 +6672,6 @@ SWITCH_DECLARE(void) switch_core_session_write_blank_video(switch_core_session_t if (!height) height = 288; if (!fps) fps = 15; - if (!(width && height && fps)) { - return; - } - fr.packet = buf; fr.packetlen = buflen; fr.data = buf + 12; @@ -12439,7 +12435,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_media_params(switch_core_sessi *val++ = '\0'; } - if (name && val) { + if (val) { if (!strcmp(name, "aspect")) { aspect = val; vid++; @@ -15860,7 +15856,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess if (!(switch_core_codec_ready(session->write_codec) && switch_core_codec_ready(frame->codec))) goto error; - if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) { + if (frame->codec && session->write_codec->implementation != frame->codec->implementation) { if (session->write_impl.codec_id == frame->codec->implementation->codec_id || session->write_impl.microseconds_per_packet != frame->codec->implementation->microseconds_per_packet) { ptime_mismatch = TRUE; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index d00b75d40c..9a33b43340 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -2130,7 +2130,7 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data break; } - if (ep->eavesdropper && switch_core_session_read_lock(ep->eavesdropper) == SWITCH_STATUS_SUCCESS) { + if (switch_core_session_read_lock(ep->eavesdropper) == SWITCH_STATUS_SUCCESS) { if (switch_core_session_write_video_frame(ep->eavesdropper, bug->video_ping_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error writing video to %s\n", switch_core_session_get_name(ep->eavesdropper)); ep->errs++; @@ -2178,10 +2178,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_pop_eavesdropper(switch_cor struct eavesdrop_pvt *ep = (struct eavesdrop_pvt *) switch_core_media_bug_get_user_data(bug); if (ep && ep->eavesdropper && ep->eavesdropper != session) { - switch_core_session_read_lock(ep->eavesdropper); - *sessionp = ep->eavesdropper; - switch_core_media_bug_set_flag(bug, SMBF_PRUNE); - status = SWITCH_STATUS_SUCCESS; + if (switch_core_session_read_lock(ep->eavesdropper) == SWITCH_STATUS_SUCCESS) { + *sessionp = ep->eavesdropper; + switch_core_media_bug_set_flag(bug, SMBF_PRUNE); + status = SWITCH_STATUS_SUCCESS; + } } } diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index f91fc2c69f..527058f70c 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -237,7 +237,7 @@ static void video_bridge_thread(switch_core_session_t *session, void *obj) continue; } - if (switch_channel_media_up(b_channel)) { + if (read_frame && switch_channel_media_up(b_channel)) { if (switch_core_session_write_video_frame(vh->session_b, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { switch_cond_next(); continue; diff --git a/src/switch_nat.c b/src/switch_nat.c index f6b9bc553b..a1620b4bfd 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -506,7 +506,7 @@ static switch_status_t switch_nat_add_mapping_upnp(switch_port_t port, switch_na if (r == UPNPCOMMAND_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mapped public port %s protocol %s to localport %s\n", port_str, - (proto == SWITCH_NAT_TCP) ? "TCP" : (proto == SWITCH_NAT_UDP ? "UDP" : "UNKNOWN"), port_str); + (proto == SWITCH_NAT_TCP) ? "TCP" : "UDP", port_str); status = SWITCH_STATUS_SUCCESS; } @@ -566,7 +566,7 @@ static switch_status_t switch_nat_del_mapping_upnp(switch_port_t port, switch_na if (r == UPNPCOMMAND_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unmapped public port %s protocol %s to localport %s\n", port_str, - (proto == SWITCH_NAT_TCP) ? "TCP" : (proto == SWITCH_NAT_UDP ? "UDP" : "UNKNOWN"), port_str); + (proto == SWITCH_NAT_TCP) ? "TCP" : "UDP", port_str); status = SWITCH_STATUS_SUCCESS; } return status; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 8398717818..ad9f8eef1c 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1277,7 +1277,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d } - if (ice->ice_params && ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type && + if (ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type && !strcasecmp(ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type, "relay")) { do_adj++; } @@ -3010,7 +3010,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_ rtp_session->dtls->sock_output = rtp_session->sock_output; if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { - switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool); + status = switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool); } } From 80d5790274ec85ba39c34fc9831867695c348986 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 12:42:23 +0100 Subject: [PATCH 002/123] [mod_xml_scgi] Coverity CID 1468595 (Resource leak) --- src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c b/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c index 63306c76a3..24c0270a57 100644 --- a/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c +++ b/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c @@ -176,6 +176,10 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con if (bytes > XML_SCGI_MAX_BYTES) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Data too big!\n"); len = -1; + if (expanded != (char*)buf) { + free(expanded); + } + break; } From b02fbc702df3849981d116565f3ca42a5bc72e2b Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 13:26:42 +0100 Subject: [PATCH 003/123] [mod_java] Coverity CID 1320753 (Resource leak) --- src/mod/languages/mod_java/modjava.c | 93 +++++++++++++--------------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/src/mod/languages/mod_java/modjava.c b/src/mod/languages/mod_java/modjava.c index a334af302d..899fee2b60 100644 --- a/src/mod/languages/mod_java/modjava.c +++ b/src/mod/languages/mod_java/modjava.c @@ -294,64 +294,57 @@ static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount, static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm_control_t * vmControl) { - jint (JNICALL *pJNI_CreateJavaVM)(JavaVM**,void**,void*); - switch_status_t status; + jint (JNICALL *pJNI_CreateJavaVM)(JavaVM**,void**,void*); + switch_status_t status; char *derr = NULL; pJNI_CreateJavaVM = (jint (*)(JavaVM **, void **, void *))switch_dso_func_sym(javaVMHandle, "JNI_CreateJavaVM", &derr); - if (!derr) - { - JNIEnv *env; - JavaVMInitArgs initArgs; - jint res; + if (!derr) { + JNIEnv *env; + JavaVMInitArgs initArgs; + jint res; - memset(&initArgs, 0, sizeof(initArgs)); - initArgs.version = JNI_VERSION_1_4; - initArgs.nOptions = optionCount; - initArgs.options = options; - initArgs.ignoreUnrecognized = JNI_TRUE; + memset(&initArgs, 0, sizeof(initArgs)); + initArgs.version = JNI_VERSION_1_4; + initArgs.nOptions = optionCount; + initArgs.options = options; + initArgs.ignoreUnrecognized = JNI_TRUE; - res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs); - if (res == JNI_OK) - { - // call FindClass here already so that the Java VM executes the static - // initializer (@see org.freeswitch.Launcher) which loads the jni library - // so we can use jni functions right away (for example in the startup method) - launcherClass = (*env)->FindClass(env, "org/freeswitch/Launcher"); - if ( launcherClass == NULL ) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find 'org.freeswitch.Launcher' class!\n"); - (*env)->ExceptionDescribe(env); - } + res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs); + if (res == JNI_OK) { + /* call FindClass here already so that the Java VM executes the static + initializer (@see org.freeswitch.Launcher) which loads the jni library + so we can use jni functions right away (for example in the startup method) */ - // store a global reference for use in the launch_java() function - launcherClass = (*env)->NewGlobalRef(env, launcherClass); - if ( launcherClass == NULL ) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); - (*env)->ExceptionDescribe(env); - status = SWITCH_STATUS_FALSE; - } - else - { - status = SWITCH_STATUS_SUCCESS; - } + launcherClass = (*env)->FindClass(env, "org/freeswitch/Launcher"); + if ( launcherClass == NULL ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find 'org.freeswitch.Launcher' class!\n"); + (*env)->ExceptionDescribe(env); + } - (*javaVM)->DetachCurrentThread(javaVM); - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n"); - status = SWITCH_STATUS_FALSE; - } - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n"); - status = SWITCH_STATUS_FALSE; - } - return status; + /* store a global reference for use in the launch_java() function */ + launcherClass = (*env)->NewGlobalRef(env, launcherClass); + if ( launcherClass == NULL ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); + (*env)->ExceptionDescribe(env); + status = SWITCH_STATUS_FALSE; + } else { + status = SWITCH_STATUS_SUCCESS; + } + + (*javaVM)->DetachCurrentThread(javaVM); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n"); + status = SWITCH_STATUS_FALSE; + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n"); + switch_safe_free(derr); + status = SWITCH_STATUS_FALSE; + } + + return status; } SWITCH_MODULE_LOAD_FUNCTION(mod_java_load) From 0e9954467f1dfbd83d6ab747c4736dd2b831f00a Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 12:25:48 +0100 Subject: [PATCH 004/123] [mod_imagick] Coverity CID 1500258 (Resource leak) --- src/mod/formats/mod_imagick/mod_imagick.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mod/formats/mod_imagick/mod_imagick.c b/src/mod/formats/mod_imagick/mod_imagick.c index beb60387bf..5c185a5e44 100644 --- a/src/mod/formats/mod_imagick/mod_imagick.c +++ b/src/mod/formats/mod_imagick/mod_imagick.c @@ -384,6 +384,7 @@ static switch_status_t read_page(pdf_file_context_t *context) if (ret == MagickFalse && context->exception->severity != UndefinedException) { CatchException(context->exception); free(storage); + return SWITCH_STATUS_FALSE; } @@ -397,6 +398,8 @@ static switch_status_t read_page(pdf_file_context_t *context) if (ret == MagickFalse && context->exception->severity != UndefinedException) { CatchException(context->exception); + switch_img_free(&img); + return SWITCH_STATUS_FALSE; } From a9e81ae0b81d8a894efce43b12312cb7a7ada4c2 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 12:10:55 +0100 Subject: [PATCH 005/123] [mod_verto] Coverity CID 1320754 (Resource leak) --- src/mod/endpoints/mod_verto/mcast/mcast.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_verto/mcast/mcast.c b/src/mod/endpoints/mod_verto/mcast/mcast.c index fcb3035872..aaa6da995c 100644 --- a/src/mod/endpoints/mod_verto/mcast/mcast.c +++ b/src/mod/endpoints/mod_verto/mcast/mcast.c @@ -86,6 +86,7 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, if ( setsockopt(handle->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)) != 0 ) { mcast_socket_close(handle); + return -1; } @@ -103,11 +104,13 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, if (setsockopt(handle->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { mcast_socket_close(handle); + return -1; } if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr, sizeof(handle->recv_addr)) < 0) { mcast_socket_close(handle); + return -1; } @@ -124,7 +127,11 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, addr_criteria.ai_flags |= AI_NUMERICHOST; snprintf(service, sizeof(service), "%d", port); - getaddrinfo(host, service, &addr_criteria, &mcast_addr); + if (getaddrinfo(host, service, &addr_criteria, &mcast_addr) != 0) { + mcast_socket_close(handle); + + return -1; + } memset(&handle->recv_addr6, 0, sizeof(handle->recv_addr6)); @@ -134,11 +141,14 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, memcpy(&mreq.ipv6mr_multiaddr, &((struct sockaddr_in6 *)mcast_addr->ai_addr)->sin6_addr, sizeof(struct in6_addr)); + freeaddrinfo(mcast_addr); + mreq.ipv6mr_interface = 0; setsockopt(handle->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, (const char *)&mreq, sizeof(mreq)); if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr6, sizeof(handle->recv_addr6)) < 0) { mcast_socket_close(handle); + return -1; } } From 99e26d34487c6cb33847c5635e5ecf416096d2c3 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 11:27:19 +0100 Subject: [PATCH 006/123] [mod_dialplan_asterisk] Coverity CID 1214207 (Resource leak) --- .../mod_dialplan_asterisk/mod_dialplan_asterisk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c index 24119f6f8c..652d292e65 100644 --- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c +++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c @@ -142,6 +142,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) if (!caller_profile || zstr(caller_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n"); + return NULL; } @@ -150,6 +151,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) if (!switch_config_open_file(&cfg, cf)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + return NULL; } @@ -226,12 +228,14 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) } } else { if (pattern && strcasecmp(pattern, field_data)) { + switch_safe_free(field_expanded); continue; } } if (cid) { if (strcasecmp(cid, caller_profile->caller_id_number)) { + switch_safe_free(field_expanded); continue; } } @@ -266,15 +270,19 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) switch_perform_substitution(re, proceed, argument, field_data, substituted, sizeof(substituted), ovector); argument = substituted; } + switch_regex_safe_free(re); if (!extension) { if (zstr(field_data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No extension!\n"); + switch_safe_free(field_expanded); break; } + if ((extension = switch_caller_extension_new(session, field_data, field_data)) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); + switch_safe_free(field_expanded); break; } } From 875a1b04ff57074b66fb964e3928f67fd01dc5f1 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 11:03:02 +0100 Subject: [PATCH 007/123] [mod_av] Coverity CID 1500320 (Resource leak) --- src/mod/applications/mod_av/avformat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index a791665c08..1f767d0bde 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -1591,6 +1591,8 @@ GCC_DIAG_ON(deprecated-declarations) context->vid_ready = 1; switch_queue_push(context->eh.video_queue, img); context->last_vid_push = switch_time_now(); + } else { + switch_img_free(&img); } } } From 5388319dd3673614349704bad1ee40d5b2a00a66 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 01:30:38 +0100 Subject: [PATCH 008/123] [mod_xml_curl] Coverity CID 1468413 (Resource leak) --- src/mod/xml_int/mod_xml_curl/mod_xml_curl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c b/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c index 6a8f2aac53..67181e26c4 100644 --- a/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c +++ b/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c @@ -210,13 +210,6 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con switch_uuid_format(uuid_str, &uuid); switch_snprintf(filename, sizeof(filename), "%s%s%s.tmp.xml", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str); - curl_handle = switch_curl_easy_init(); - headers = switch_curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded"); - - if (!strncasecmp(binding->url, "https", 5)) { - switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); - switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); - } memset(&config_data, 0, sizeof(config_data)); @@ -224,6 +217,14 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con config_data.max_bytes = binding->curl_max_bytes; if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + curl_handle = switch_curl_easy_init(); + headers = switch_curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded"); + + if (!strncasecmp(binding->url, "https", 5)) { + switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); + switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); + } + if (!zstr(binding->cred)) { switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, binding->auth_scheme); switch_curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred); From a8f6625d12e140a44a60962af5a56092bdee15f8 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 00:43:08 +0100 Subject: [PATCH 009/123] [mod_amqp] Coverity CID 1468426 (Resource leak) --- src/mod/event_handlers/mod_amqp/mod_amqp_connection.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c b/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c index 91feec93d5..73cf09a354 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c @@ -203,7 +203,11 @@ switch_status_t mod_amqp_connection_create(mod_amqp_connection_t **conn, switch_ amqp_boolean_t ssl_verify_peer = 1; if (zstr(name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Connection missing name attribute\n%s\n", switch_xml_toxml(cfg, 1)); + char *str_tmp = switch_xml_toxml(cfg, 1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Connection missing name attribute\n%s\n", str_tmp); + switch_safe_free(str_tmp); + return SWITCH_STATUS_GENERR; } @@ -260,6 +264,7 @@ switch_status_t mod_amqp_connection_create(mod_amqp_connection_t **conn, switch_ new_con->ssl_verify_peer = ssl_verify_peer; *conn = new_con; + return SWITCH_STATUS_SUCCESS; } From 11b9c1d1042f0c05a3090c054de4dedf1aaa0e8d Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 00:56:56 +0100 Subject: [PATCH 010/123] [mod_event_multicast] Coverity CID 1468504 (Resource leak) --- .../mod_event_multicast/mod_event_multicast.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 2a52ca0778..ac58ee8ed9 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -153,16 +153,18 @@ static switch_status_t load_config(switch_xml_t input_cfg) } if ((settings = switch_xml_child(cfg, "settings"))) { + for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); + char *val_no_whitespace = switch_strip_whitespace(val); if (!strcasecmp(var, "address")) { - set_global_dst_addrs(switch_strip_whitespace(val)); + set_global_dst_addrs(val_no_whitespace); } else if (!strcasecmp(var, "source_address")) { - set_global_src_addr(switch_strip_whitespace(val)); + set_global_src_addr(val_no_whitespace); } else if (!strcasecmp(var, "source_address_ipv6")) { - set_global_src_addr6(switch_strip_whitespace(val)); + set_global_src_addr6(val_no_whitespace); } else if (!strcasecmp(var, "bindings")) { set_global_bindings(val); } else if (!strcasecmp(var, "port")) { @@ -183,6 +185,8 @@ static switch_status_t load_config(switch_xml_t input_cfg) } else if (!strcasecmp(var, "loopback")) { globals.loopback = switch_true(val); } + + switch_safe_free(val_no_whitespace); } } @@ -190,6 +194,7 @@ static switch_status_t load_config(switch_xml_t input_cfg) if (globals.bindings) { + for (cur = globals.bindings; cur; count++) { switch_event_types_t type; From 9994c5149958a52855a19ce79e484c06380b6332 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 01:11:35 +0100 Subject: [PATCH 011/123] [mod_xml_rpc] Coverity CID 1294469 (Resource leak) --- src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index 43e25b6f9e..8e49462d2c 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -614,7 +614,7 @@ abyss_bool websocket_hook(TSession *r) if (ret != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "handshake error %d\n", ret); - return FALSE; + goto err; } if (switch_event_bind_removable("websocket", SWITCH_EVENT_CUSTOM, "websocket::stophook", stop_hook_event_handler, wsh, &nodes[node_count++]) != SWITCH_STATUS_SUCCESS) { @@ -696,8 +696,11 @@ abyss_bool websocket_hook(TSession *r) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "wsh->down = %d, node_count = %d\n", wsh->down, node_count); switch_yield(2000); + while (--node_count >= 0) switch_event_unbind(&nodes[node_count]); + err: + ws_destroy(wsh); switch_safe_free(wsh); return FALSE; From 4d3b0a5778be5d321aaf6605fddd95d1a1e1fbe4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 28 Oct 2022 03:15:15 +0300 Subject: [PATCH 012/123] [mod_opus] Fix buf scope in switch_opus_decode(). --- src/mod/codecs/mod_opus/mod_opus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index d24590f37a..04850a672e 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -817,6 +817,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, int fec = 0, plc = 0; int32_t frame_size = 0, last_frame_size = 0; uint32_t frame_samples; + uint8_t buf[SWITCH_RTP_MAX_BUF_LEN]; if (!context) { return SWITCH_STATUS_FALSE; @@ -842,7 +843,6 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, } if (codec->cur_frame && (jb = switch_core_session_get_jb(session, SWITCH_MEDIA_TYPE_AUDIO))) { switch_frame_t frame = { 0 }; - uint8_t buf[SWITCH_RTP_MAX_BUF_LEN]; uint32_t ts = 0; uint16_t seq = 0; From eec1fd737c6829a29c18db22e10ddbcf32e81b88 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 14:23:17 +0100 Subject: [PATCH 013/123] [mod_signalwire] Make this module working with libks and signalwire-c in versions 2.0 * [mod_signalwire] Fix load credentials data from json * [mod_signalwire] Fix parsing of configuration response --- .../applications/mod_signalwire/mod_signalwire.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mod/applications/mod_signalwire/mod_signalwire.c b/src/mod/applications/mod_signalwire/mod_signalwire.c index 5b0be47a91..9846e7e1d2 100644 --- a/src/mod/applications/mod_signalwire/mod_signalwire.c +++ b/src/mod/applications/mod_signalwire/mod_signalwire.c @@ -228,7 +228,7 @@ static ks_status_t load_credentials_from_json(ks_json_t *json) const char *relay_connector_id = NULL; #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - if ((bootstrap = ks_json_get_string(json, "bootstrap")) == NULL) { + if ((bootstrap = ks_json_get_object_string(json, "bootstrap", NULL)) == NULL) { #else if ((bootstrap = ks_json_get_object_cstr(json, "bootstrap")) == NULL) { #endif @@ -238,7 +238,7 @@ static ks_status_t load_credentials_from_json(ks_json_t *json) } #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - if ((relay_connector_id = ks_json_get_string(json, "relay_connector_id")) == NULL) { + if ((relay_connector_id = ks_json_get_object_string(json, "relay_connector_id", NULL)) == NULL) { #else if ((relay_connector_id = ks_json_get_object_cstr(json, "relay_connector_id")) == NULL) { #endif @@ -797,6 +797,7 @@ static ks_status_t load_credentials(void) status = KS_STATUS_FAIL; goto done; } + fclose(fp); json = ks_json_parse(data); @@ -805,6 +806,7 @@ static ks_status_t load_credentials(void) status = KS_STATUS_FAIL; goto done; } + status = load_credentials_from_json(json); ks_json_delete(&json); @@ -981,7 +983,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_signalwire_load) #ifdef WIN32 sslLoadWindowsCACertificate(); #endif - // Configuration swclt_config_create(&globals.config); load_config(); @@ -1206,6 +1207,7 @@ static void mod_signalwire_state_configure(void) #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 if (!swclt_sess_provisioning_configure(globals.signalwire_session, "freeswitch", local_endpoint, external_endpoint, globals.relay_connector_id, &reply)) { if (reply->type == SWCLT_CMD_TYPE_RESULT) { + ks_json_t *result; #else if (!swclt_sess_provisioning_configure(globals.signalwire_session, "freeswitch", local_endpoint, external_endpoint, globals.relay_connector_id, &cmd)) { SWCLT_CMD_TYPE cmd_type; @@ -1215,7 +1217,8 @@ static void mod_signalwire_state_configure(void) #endif signalwire_provisioning_configure_response_t *configure_res; #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - if (!SIGNALWIRE_PROVISIONING_CONFIGURE_RESPONSE_PARSE(reply->pool, reply->json, &configure_res)) { + result = ks_json_get_object_item(reply->json, "result"); + if (!SIGNALWIRE_PROVISIONING_CONFIGURE_RESPONSE_PARSE(reply->pool, result, &configure_res)) { #else swclt_cmd_result(cmd, &result); result = ks_json_get_object_item(result, "result"); @@ -1223,7 +1226,7 @@ static void mod_signalwire_state_configure(void) #endif ks_json_t *configuration = configure_res->configuration; #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - const char *configuration_profile = ks_json_get_string(configuration, "profile"); + const char *configuration_profile = ks_json_get_object_string(configuration, "profile", NULL); #else const char *configuration_profile = ks_json_get_object_cstr(configuration, "profile"); #endif @@ -1231,6 +1234,7 @@ static void mod_signalwire_state_configure(void) switch_xml_free(globals.signalwire_profile); globals.signalwire_profile = NULL; } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\"%s\"\n", configuration_profile); globals.signalwire_profile = switch_xml_parse_str_dynamic((char *)configuration_profile, SWITCH_TRUE); if (!globals.signalwire_profile) { From 7f3a833466a470687dbd9e407c049f7e74704e99 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 14 Apr 2023 14:48:41 +0300 Subject: [PATCH 014/123] [mod_commands] Fix leaking session readlock in uuid_capture_text --- src/mod/applications/mod_commands/mod_commands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 4394d9b02f..5b9620a781 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -3225,6 +3225,7 @@ SWITCH_STANDARD_API(uuid_capture_text) } else { if ((tsession = switch_core_session_locate(uuid))) { switch_ivr_capture_text(tsession, switch_true(onoff)); + switch_core_session_rwunlock(tsession); } else { stream->write_function(stream, "-ERR No such channel %s!\n", uuid); } From 70c144309c16eed5b875214ff28e42d412a2a91b Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 19:46:51 +0100 Subject: [PATCH 015/123] [mod_v8] Coverity CID 1468570 (Resource leak) --- src/mod/languages/mod_v8/src/fsglobal.cpp | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_v8/src/fsglobal.cpp b/src/mod/languages/mod_v8/src/fsglobal.cpp index 99a0626f8f..c360955687 100644 --- a/src/mod/languages/mod_v8/src/fsglobal.cpp +++ b/src/mod/languages/mod_v8/src/fsglobal.cpp @@ -169,6 +169,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash) } else { /* The var exists, but is wrong type - exit with error */ info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Second argument is the name of an existing var of the wrong type")); + return; } } else if (info.Length() > 1 && info[1]->IsArray()) { @@ -177,6 +178,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash) } else if (info.Length() > 1) { /* The var exists, but is wrong type - exit with error */ info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Second argument is of the wrong type")); + return; } else { /* Second argument doesn't exist, this is also ok. The hash will be returned as the result */ @@ -185,6 +187,11 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash) } curl_handle = switch_curl_easy_init(); + if (!curl_handle) { + info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session.")); + + return; + } if (!strncasecmp(js_safe_str(*url), "https", 5)) { switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); @@ -224,14 +231,22 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLFile) const char *url = NULL, *filename = NULL; String::Utf8Value str1(info[0]); String::Utf8Value str2(info[1]); + url = js_safe_str(*str1); filename = js_safe_str(*str2); curl_handle = switch_curl_easy_init(); + if (!curl_handle) { + info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session.")); + + return; + } + if (!strncasecmp(url, "https", 5)) { switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); } + config_data.isolate = info.GetIsolate(); if ((config_data.fileHandle = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { @@ -245,13 +260,14 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLFile) switch_curl_easy_perform(curl_handle); - switch_curl_easy_cleanup(curl_handle); close(config_data.fileHandle); info.GetReturnValue().Set(true); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file [%s]\n", filename); info.GetReturnValue().Set(false); } + + switch_curl_easy_cleanup(curl_handle); } else { info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments")); } @@ -270,12 +286,19 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL) if (info.Length() >= 1) { const char *url; String::Utf8Value str(info[0]); + url = js_safe_str(*str); if (info.Length() > 1) { buffer_size = info[1]->Int32Value(); } curl_handle = switch_curl_easy_init(); + if (!curl_handle) { + info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session.")); + + return; + } + if (!strncasecmp(url, "https", 5)) { switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); @@ -289,6 +312,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL) if (config_data.buffer == NULL) { info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to allocate data buffer.")); switch_curl_easy_cleanup(curl_handle); + return; } From 85a109617f769d401d9b35df6beb2cfc0f69d3b6 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 13:58:08 +0100 Subject: [PATCH 016/123] [mod_java] Coverity CID 1320752 (Resource leak) --- src/mod/languages/mod_java/modjava.c | 179 ++++++++++++++------------- 1 file changed, 90 insertions(+), 89 deletions(-) diff --git a/src/mod/languages/mod_java/modjava.c b/src/mod/languages/mod_java/modjava.c index 899fee2b60..9c38bdb70f 100644 --- a/src/mod/languages/mod_java/modjava.c +++ b/src/mod/languages/mod_java/modjava.c @@ -189,107 +189,108 @@ SWITCH_STANDARD_APP(java_function) static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount, vm_control_t * vmControl) { - switch_xml_t cfg, xml; - switch_status_t status = SWITCH_STATUS_SUCCESS; + switch_xml_t cfg, xml; + switch_status_t status = SWITCH_STATUS_SUCCESS; char *derr = NULL; - xml = switch_xml_open_cfg("java.conf", &cfg, NULL); - if (xml) - { - switch_xml_t javavm; - switch_xml_t options; - switch_xml_t startup; - switch_xml_t shutdown; + xml = switch_xml_open_cfg("java.conf", &cfg, NULL); + if (xml) { + switch_xml_t javavm; + switch_xml_t options; + switch_xml_t startup; + switch_xml_t shutdown; - javavm = switch_xml_child(cfg, "javavm"); - if (javavm != NULL) - { - const char *path = switch_xml_attr_soft(javavm, "path"); - if (path != NULL) - { + javavm = switch_xml_child(cfg, "javavm"); + if (javavm != NULL) { + const char *path = switch_xml_attr_soft(javavm, "path"); + + if (path != NULL) { javaVMHandle = switch_dso_open(path, 0, &derr); if (derr || !javaVMHandle) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path); + switch_safe_free(derr); } - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n"); - status = SWITCH_STATUS_FALSE; - } - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n"); - status = SWITCH_STATUS_FALSE; - goto close; - } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n"); + status = SWITCH_STATUS_FALSE; + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n"); + status = SWITCH_STATUS_FALSE; + goto close; + } + + options = switch_xml_child(cfg, "options"); + if (options != NULL) { + switch_xml_t option; + int i = 0; + + *optionCount = 0; + + for (option = switch_xml_child(options, "option"); option; option = option->next) { + const char *value = switch_xml_attr_soft(option, "value"); + + if (value != NULL) { + ++*optionCount; + } + } + + *optionCount += 1; + *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption))); + if (*javaOptions == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); + status = SWITCH_STATUS_FALSE; + goto close; + } + + for (option = switch_xml_child(options, "option"); option; option = option->next) { + const char *value = switch_xml_attr_soft(option, "value"); + + if (value == NULL) { + continue; + } + + (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value); + if ((*javaOptions)[i].optionString == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); + status = SWITCH_STATUS_FALSE; + goto close; + } + + ++i; + } - options = switch_xml_child(cfg, "options"); - if (options != NULL) - { - switch_xml_t option; - int i = 0; - *optionCount = 0; - for (option = switch_xml_child(options, "option"); option; option = option->next) - { - const char *value = switch_xml_attr_soft(option, "value"); - if (value != NULL) - ++*optionCount; - } - *optionCount += 1; - *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption))); - if (*javaOptions == NULL) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); - status = SWITCH_STATUS_FALSE; - goto close; - } - for (option = switch_xml_child(options, "option"); option; option = option->next) - { - const char *value = switch_xml_attr_soft(option, "value"); - if (value == NULL) - continue; - (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value); - if ((*javaOptions)[i].optionString == NULL) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); - status = SWITCH_STATUS_FALSE; - goto close; - } - ++i; - } (*javaOptions)[i].optionString = switch_core_sprintf(memoryPool, "-Djava.library.path=%s", SWITCH_GLOBAL_dirs.mod_dir); - } + } - /* - - - */ + /* + + + */ - memset(vmControl, 0, sizeof(struct vm_control)); - startup = switch_xml_child(cfg, "startup"); - if (startup != NULL) { - vmControl->startup.class = switch_xml_attr_soft(startup, "class"); - vmControl->startup.method = switch_xml_attr_soft(startup, "method"); - vmControl->startup.arg = switch_xml_attr_soft(startup, "arg"); - } - shutdown = switch_xml_child(cfg, "shutdown"); - if (shutdown != NULL) { - vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class"); - vmControl->shutdown.method = switch_xml_attr_soft(shutdown, "method"); - vmControl->shutdown.arg = switch_xml_attr_soft(shutdown, "arg"); - } + memset(vmControl, 0, sizeof(struct vm_control)); + startup = switch_xml_child(cfg, "startup"); + if (startup != NULL) { + vmControl->startup.class = switch_xml_attr_soft(startup, "class"); + vmControl->startup.method = switch_xml_attr_soft(startup, "method"); + vmControl->startup.arg = switch_xml_attr_soft(startup, "arg"); + } - close: - switch_xml_free(xml); - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n"); - status = SWITCH_STATUS_FALSE; - } - return status; + shutdown = switch_xml_child(cfg, "shutdown"); + if (shutdown != NULL) { + vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class"); + vmControl->shutdown.method = switch_xml_attr_soft(shutdown, "method"); + vmControl->shutdown.arg = switch_xml_attr_soft(shutdown, "arg"); + } + + close: + switch_xml_free(xml); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n"); + status = SWITCH_STATUS_FALSE; + } + + return status; } static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm_control_t * vmControl) From 0b05623cef5c3425831a7bbf28580b30a04eda3e Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 14:54:50 +0100 Subject: [PATCH 017/123] [mod_translate] Coverity CID 1301006 (Resource leak) --- src/mod/applications/mod_translate/mod_translate.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_translate/mod_translate.c b/src/mod/applications/mod_translate/mod_translate.c index efbcd3f14b..34b1ad54fc 100644 --- a/src/mod/applications/mod_translate/mod_translate.c +++ b/src/mod/applications/mod_translate/mod_translate.c @@ -130,6 +130,7 @@ static void translate_number(char *number, char *profile, char **translated, swi hi = switch_core_hash_find_rdlock(globals.translate_profiles, (const char *)profile, globals.profile_hash_rwlock); if (!hi) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "can't find key for profile matching [%s]\n", profile); + return; } @@ -142,6 +143,7 @@ static void translate_number(char *number, char *profile, char **translated, swi switch_regex_safe_free(re); goto end; } + memset(substituted, 0, len); switch_perform_substitution(re, proceed, rule->replace, number, substituted, len, ovector); @@ -153,16 +155,21 @@ static void translate_number(char *number, char *profile, char **translated, swi } else if (event) { subbed = switch_event_expand_headers(event, substituted); } + + if (subbed != substituted) { + switch_safe_free(substituted); + } + if (session) { substituted = switch_core_session_strdup(session, subbed); } else { substituted = switch_core_strdup(pool, subbed); } - if (subbed != substituted) { - switch_safe_free(subbed); - } + + switch_safe_free(subbed); } + switch_regex_safe_free(re); break; } } From bc00add2542b22afd9c86068ad1cdd6684603564 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Mon, 17 Apr 2023 11:53:26 +0100 Subject: [PATCH 018/123] [mod_kazoo] Coverity fixes (#2043) * [mod_kazoo] Coverity CID 1395503 (Resource leak) * [mod_kazoo] Coverity CID 1468146 (Resource leak) * [mod_kazoo] Coverity CID 1468483 (Resource leak) --- .../mod_kazoo/kazoo_ei_config.c | 19 ++++++++++++----- .../event_handlers/mod_kazoo/kazoo_message.c | 21 +++++++++++++++---- src/mod/event_handlers/mod_kazoo/kazoo_node.c | 10 +++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c b/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c index f1726b677b..3c626c15da 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c @@ -564,13 +564,16 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c switch_memory_pool_t *pool = NULL; char *name = (char *) switch_xml_attr_soft(cfg, "name"); + if (zstr(name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing name in profile\n"); + return SWITCH_STATUS_GENERR; } if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocation pool for new profile : %s\n", name); + return SWITCH_STATUS_GENERR; } @@ -582,6 +585,7 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c fetch_section = switch_xml_parse_section_string(name); if ((params = switch_xml_child(cfg, "params")) != NULL) { + for (param = switch_xml_child(params, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -605,7 +609,9 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c } if (fetch_section == SWITCH_XML_SECTION_RESULT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, switch_xml_toxml(cfg, SWITCH_FALSE)); + char *tmp = switch_xml_toxml(cfg, SWITCH_FALSE); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, tmp); + free(tmp); goto err; } @@ -622,17 +628,20 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c } } - if(ptr) + if (ptr) { *ptr = profile; + } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "fetch handler profile %s successfully configured\n", name); + return SWITCH_STATUS_SUCCESS; err: /* Cleanup */ - if(pool) { - switch_core_destroy_memory_pool(&pool); - } + if(pool) { + switch_core_destroy_memory_pool(&pool); + } + return SWITCH_STATUS_GENERR; } diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_message.c b/src/mod/event_handlers/mod_kazoo/kazoo_message.c index e43d656b4c..43716a8e02 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_message.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_message.c @@ -233,9 +233,11 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie } else if((header = switch_event_get_header_ptr(src, field->name)) != NULL) { if (header->idx) { item = cJSON_CreateArray(); + for(i = 0; i < header->idx; i++) { cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i])); } + kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); } else if (field->out_type_as_array) { item = cJSON_CreateArray(); @@ -251,13 +253,16 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie expanded = kz_event_expand_headers(src, field->value); if(expanded != NULL && !zstr(expanded)) { item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, expanded); - if(expanded != field->value) { - free(expanded); - } } + + if (expanded != field->value) { + switch_safe_free(expanded); + } + break; case FIELD_FIRST_OF: + for(n = 0; n < field->list.size; n++) { if(*field->list.value[n] == '#') { item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, ++field->list.value[n]); @@ -267,33 +272,41 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie if(header) { if (header->idx) { item = cJSON_CreateArray(); + for(i = 0; i < header->idx; i++) { cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i])); } + kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); } else { item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, header->value); } + break; } } } + break; case FIELD_PREFIX: + for (header = src->headers; header; header = header->next) { if(!strncmp(header->name, field->name, strlen(field->name))) { if (header->idx) { cJSON *array = cJSON_CreateArray(); + for(i = 0; i < header->idx; i++) { cJSON_AddItemToArray(array, kazoo_event_json_value(field->out_type, header->array[i])); } + kazoo_cJSON_AddItemToObject(dst, field->exclude_prefix ? header->name+strlen(field->name) : header->name, array); } else { kazoo_event_add_json_value(dst, field, field->exclude_prefix ? header->name+strlen(field->name) : header->name, header->value); } } } + break; case FIELD_STATIC: @@ -308,7 +321,7 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie break; } - return item; + return item; } static switch_status_t kazoo_event_add_fields_to_json(kazoo_logging_ptr logging, cJSON *dst, switch_event_t *src, kazoo_field_ptr field) { diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_node.c b/src/mod/event_handlers/mod_kazoo/kazoo_node.c index feb8970a86..f75c327023 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_node.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_node.c @@ -1097,23 +1097,27 @@ static switch_status_t handle_request_fetch_reply(ei_node_t *ei_node, erlang_pid if (ei_decode_atom_safe(buf->buff, &buf->index, section_str) || !(section = switch_xml_parse_section_string(section_str))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without a configuration section\n"); + return erlang_response_badarg(rbuf); } if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str) || zstr_buf(uuid_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without request UUID\n"); + return erlang_response_badarg(rbuf); } if (ei_decode_string_or_binary(buf->buff, &buf->index, &xml_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without XML : %s \n", uuid_str); + return erlang_response_badarg(rbuf); } if (zstr(xml_str)) { switch_safe_free(xml_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring an empty fetch reply : %s\n", uuid_str); + return erlang_response_badarg(rbuf); } @@ -1138,13 +1142,19 @@ static switch_status_t handle_request_fetch_reply(ei_node_t *ei_node, erlang_pid break; default: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s for an unknown configuration section: %s : %s\n", uuid_str, section_str, xml_str); + switch_safe_free(xml_str); + return erlang_response_badarg(rbuf); } if (result == SWITCH_STATUS_SUCCESS) { + switch_safe_free(xml_str); + return erlang_response_ok(rbuf); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s is unknown or has expired : %s\n", uuid_str, xml_str); + switch_safe_free(xml_str); + return erlang_response_baduuid(rbuf); } } From 0c2edc4f56a64ddab1a94a91981517df20d83139 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 14 Apr 2023 11:28:01 +0100 Subject: [PATCH 019/123] [mod_radius_cdr] Coverity CID 1395529 (Resource leak) --- .../mod_radius_cdr/mod_radius_cdr.c | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c b/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c index 490a7911f1..153ec6252d 100644 --- a/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c +++ b/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c @@ -166,8 +166,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session) if (channel) { const char *disable_flag = switch_channel_get_variable(channel, "disable_radius_start"); + if (switch_true(disable_flag)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Not Sending RADIUS Start\n"); + return SWITCH_STATUS_SUCCESS; } } @@ -250,6 +252,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->caller_id_number) { if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number); @@ -257,6 +260,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->caller_id_name) { if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name); @@ -264,6 +268,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->destination_number) { if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number); @@ -271,6 +276,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->dialplan) { if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan); @@ -278,6 +284,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->network_addr) { inet_pton(AF_INET, (void *) profile->network_addr, &framed_addr); framed_addr = htonl(framed_addr); @@ -287,6 +294,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->rdnis) { if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis); @@ -294,6 +302,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->context) { if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context); @@ -301,6 +310,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->ani) { if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani); @@ -308,6 +318,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->aniii) { if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii); @@ -315,6 +326,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->source) { if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source); @@ -322,6 +334,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (callstartdate > 0) { switch_time_exp_tz(&tm, callstartdate, requested_tm.tm_gmtoff); switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", @@ -380,25 +393,33 @@ static switch_status_t my_on_routing(switch_core_session_t *session) } if (radius_avpair) { + char *radius_avpair_data_tmp = NULL; + radius_avpair_data = strdup(radius_avpair + (strncmp(radius_avpair, "ARRAY::", 7) ? 0 : 7)); + radius_avpair_data_tmp = radius_avpair_data; + do { - delim = strstr(radius_avpair_data, "|:"); + delim = strstr(radius_avpair_data_tmp, "|:"); if (delim) { *delim = '\0'; } - if (rc_avpair_add(rad_config, &send, PW_FS_AVPAIR, (void *) radius_avpair_data, -1, PW_FS_PEC) == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-AVPair: %s\n", radius_avpair_data); + if (rc_avpair_add(rad_config, &send, PW_FS_AVPAIR, (void *)radius_avpair_data_tmp, -1, PW_FS_PEC) == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-AVPair: %s\n", radius_avpair_data_tmp); rc_destroy(rad_config); + switch_safe_free(radius_avpair_data); goto end; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added Freeswitch-AVPair: %s\n", radius_avpair_data); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added Freeswitch-AVPair: %s\n", radius_avpair_data_tmp); if (delim) { - radius_avpair_data = delim + 2; + radius_avpair_data_tmp = delim + 2; } } while (delim); + + switch_safe_free(radius_avpair_data); } } else { @@ -413,11 +434,13 @@ static switch_status_t my_on_routing(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[mod_radius_cdr] RADIUS Accounting Failed\n"); retval = SWITCH_STATUS_TERM; } + rc_avpair_free(send); rc_destroy(rad_config); end: switch_xml_free(cdr); switch_thread_rwlock_unlock(globals.rwlock); + return (retval); } From 98c0482844a51a99197906983c0b7942b7993130 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 15:29:47 +0300 Subject: [PATCH 020/123] [mod_opusfile] coverity CID 1468424 (Missing break in switch) --- src/mod/formats/mod_opusfile/mod_opusfile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/formats/mod_opusfile/mod_opusfile.c b/src/mod/formats/mod_opusfile/mod_opusfile.c index 1560142263..a065108f5c 100644 --- a/src/mod/formats/mod_opusfile/mod_opusfile.c +++ b/src/mod/formats/mod_opusfile/mod_opusfile.c @@ -654,6 +654,7 @@ static switch_status_t switch_opusstream_stream_decode(opus_stream_context_t *co } switch_goto_status(SWITCH_STATUS_SUCCESS, end); } + break; case OP_EREAD: /*An underlying read operation failed. This may signal a truncation attack from an source.*/ case OP_EFAULT: /* An internal memory allocation failed. */ From 01e960cd90c32b59b695421388d2522a0178b28e Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 17:48:33 +0300 Subject: [PATCH 021/123] [mod_erlang_event] coverity CID 1500239 (Uninitialized scalar variable) --- src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index d15f748eb7..bd7bf8e26c 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1998,7 +1998,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime) struct ei_cnode_s ec; ErlConnect conn; int clientfd; - switch_os_socket_t epmdfd; + switch_os_socket_t epmdfd = SWITCH_SOCK_INVALID; switch_socket_t *epmd_sock = NULL; if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { From aab9839678e506ee50c76421acce5f76f5962d97 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 18:22:45 +0300 Subject: [PATCH 022/123] [mod_sofia] coverity CID 1468496 (Unchecked return value) --- src/mod/endpoints/mod_sofia/sip-dig.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sip-dig.c b/src/mod/endpoints/mod_sofia/sip-dig.c index e89f5aef44..c9a6f5b463 100644 --- a/src/mod/endpoints/mod_sofia/sip-dig.c +++ b/src/mod/endpoints/mod_sofia/sip-dig.c @@ -815,8 +815,12 @@ sres_record_t ** dig_addr_simple(struct dig *dig, uint16_t type) { sres_record_t **answers = NULL; + int error; - sres_blocking_query(dig->sres, type, host, 0, &answers); + error = sres_blocking_query(dig->sres, type, host, 0, &answers); + if (error < 0) { + return NULL; + } return answers; } From 075724845e1c9795ccb6625912b4f81e87401a1e Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 14 Apr 2023 10:25:40 +0100 Subject: [PATCH 023/123] [mod_rayo] Coverity CID 1395579 (Resource leak) --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 6ed46489a7..228e89b323 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -4765,7 +4765,7 @@ static void send_console_command(struct rayo_client *client, const char *to, con iks *command = NULL; iksparser *p = iks_dom_new(&command); - if (iks_parse(p, command_str, 0, 1) == IKS_OK && command) { + if (p && iks_parse(p, command_str, 0, 1) == IKS_OK && command) { char *str; iks *iq = NULL; @@ -4784,9 +4784,11 @@ static void send_console_command(struct rayo_client *client, const char *to, con if (!iks_find_attrib(iq, "type")) { iks_insert_attrib(iq, "type", "set"); } + if (!iks_find_attrib(iq, "id")) { iks_insert_attrib_printf(iq, "id", "console-%i", RAYO_SEQ_NEXT(client)); } + iks_insert_attrib(iq, "from", RAYO_JID(client)); /* send command */ @@ -4794,10 +4796,13 @@ static void send_console_command(struct rayo_client *client, const char *to, con switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nSEND: to %s, %s\n", to, str); rayo_client_command_recv(client, iq); iks_delete(command); + iks_parser_delete(p); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "bad request xml\n"); + if (p) { + iks_parser_delete(p); + } } - iks_parser_delete(p); } /** From 6eefc674fe1bf75122dc511ea4a8fb0367167210 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Mon, 17 Apr 2023 19:49:42 +0100 Subject: [PATCH 024/123] [mod_avmd] Coverity fixes * [mod_avmd] Coverity CID 1395501 (Dereference null return value) * [mod_avmd] Coverity CID 1395478 (Resource leak) --- .../applications/mod_avmd/avmd_fast_acosf.c | 20 +++++++++++-------- src/mod/applications/mod_avmd/mod_avmd.c | 18 +++-------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/mod/applications/mod_avmd/avmd_fast_acosf.c b/src/mod/applications/mod_avmd/avmd_fast_acosf.c index 572c6a84f9..59b581b98d 100644 --- a/src/mod/applications/mod_avmd/avmd_fast_acosf.c +++ b/src/mod/applications/mod_avmd/avmd_fast_acosf.c @@ -86,7 +86,6 @@ typedef union { static uint32_t index_from_float(float f); static float float_from_index(uint32_t d); static float *acos_table = NULL; -static int acos_fd = -1; #ifdef FAST_ACOSF_TESTING @@ -112,6 +111,10 @@ extern int compute_table(void) acos_table_file = fopen(ACOS_TABLE_FILENAME, "w"); + if (!acos_table_file) { + return -3; + } + for (i = 0; i < ACOS_TABLE_LENGTH; i++) { f = acosf(float_from_index(i)); res = fwrite(&f, sizeof(f), 1, acos_table_file); @@ -124,10 +127,12 @@ extern int compute_table(void) if (res != 0) { return -2; } + return 0; fail: fclose(acos_table_file); + return -1; } @@ -144,8 +149,9 @@ extern int init_fast_acosf(void) * or some other error occured */ errsv = errno; strerror_r(errsv, err, 150); - if (errsv != ENOENT) return -1; - else { + if (errsv != ENOENT) { + return -1; + } else { switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, @@ -166,10 +172,10 @@ extern int init_fast_acosf(void) acos_fp = fopen(ACOS_TABLE_FILENAME, "r"); if (acos_fp == NULL) return -3; /* can't fail */ - acos_fd = fileno(acos_fp); acos_table = (float *) mmap( NULL, /* kernel chooses the address at which to create the mapping */ - ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, acos_fd, 0); + ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, fileno(acos_fp), 0); + fclose(acos_fp); if (acos_table == MAP_FAILED) return -4; return 0; @@ -178,9 +184,7 @@ extern int init_fast_acosf(void) extern int destroy_fast_acosf(void) { if (munmap(acos_table, ACOS_TABLE_LENGTH) == -1) return -1; - if (acos_fd != -1) { - if (close(acos_fd) == -1) return -2; - } + /* disable use of fast arc cosine file */ acos_table = NULL; diff --git a/src/mod/applications/mod_avmd/mod_avmd.c b/src/mod/applications/mod_avmd/mod_avmd.c index dde3dfbf93..6c59256eda 100644 --- a/src/mod/applications/mod_avmd/mod_avmd.c +++ b/src/mod/applications/mod_avmd/mod_avmd.c @@ -1622,9 +1622,6 @@ SWITCH_STANDARD_APP(avmd_start_function) { SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) { size_t session_n; -#ifndef WIN32 - int res; -#endif switch_mutex_lock(avmd_globals.mutex); @@ -1638,18 +1635,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) { #ifndef WIN32 if (avmd_globals.settings.fast_math == 1) { - res = destroy_fast_acosf(); - if (res != 0) { - switch (res) { - case -1: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n"); - break; - case -2: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed closing arc cosine table\n"); - break; - default: - break; - } + if (destroy_fast_acosf()) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n"); } } #endif @@ -1658,6 +1645,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) { switch_mutex_unlock(avmd_globals.mutex); switch_mutex_destroy(avmd_globals.mutex); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection disabled\n"); + return SWITCH_STATUS_SUCCESS; } From e1d966ed0a362c9c001071c69e8afb8599ad50e6 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 17:05:49 +0300 Subject: [PATCH 025/123] [mod_dptools] coverity CID 1468646 (Unsigned compared against 0) --- src/mod/applications/mod_dptools/mod_dptools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index f38509016b..e91ec53d47 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -4584,7 +4584,7 @@ SWITCH_STANDARD_APP(wait_for_silence_function) timeout_ms = switch_atoui(argv[3]); } - if (thresh > 0 && silence_hits > 0 && listen_hits >= 0) { + if (thresh > 0 && silence_hits > 0) { switch_ivr_wait_for_silence(session, thresh, silence_hits, listen_hits, timeout_ms, argv[4]); return; } From 5597fe30983a580bc009eb9e769e185d3c9035b6 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 18:15:42 +0300 Subject: [PATCH 026/123] [mod_avmd] coverity CID 1395555 (Dereference before null check) --- src/mod/applications/mod_avmd/mod_avmd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_avmd/mod_avmd.c b/src/mod/applications/mod_avmd/mod_avmd.c index 6c59256eda..e5076c1500 100644 --- a/src/mod/applications/mod_avmd/mod_avmd.c +++ b/src/mod/applications/mod_avmd/mod_avmd.c @@ -1138,6 +1138,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_avmd_load) { switch_application_interface_t *app_interface; switch_api_interface_t *api_interface; + + if (pool == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No memory pool assigned!\n"); + + return SWITCH_STATUS_TERM; + } + /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); @@ -1147,10 +1154,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_avmd_load) { } memset(&avmd_globals, 0, sizeof(avmd_globals)); - if (pool == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No memory pool assigned!\n"); - return SWITCH_STATUS_TERM; - } switch_mutex_init(&avmd_globals.mutex, SWITCH_MUTEX_NESTED, pool); avmd_globals.pool = pool; From b5cb26dc479860c62fa9d6e064f893779d27fe21 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Tue, 18 Apr 2023 19:30:22 +0300 Subject: [PATCH 027/123] [Core] Coverity fixes * [core] coverity CID 1024482 (Dereference after null check) * [core] coverity CID 1468368 (Logically dead code) * [core] coverity CID 1468459 (Logically dead code) * [core] coverity CID 1232742 (Dereference before null check) --- src/switch_core.c | 2 +- src/switch_packetizer.c | 2 -- src/switch_rtp.c | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/switch_core.c b/src/switch_core.c index cf2343482a..4e2b70778a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -147,7 +147,7 @@ static void check_ip(void) } else if (strcmp(hostname, runtime.hostname)) { if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "hostname-change"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "old-hostname", hostname ? hostname : "nil"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "old-hostname", hostname); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "new-hostname", runtime.hostname); switch_event_fire(&event); } diff --git a/src/switch_packetizer.c b/src/switch_packetizer.c index 05688f8a86..626e85ba8e 100644 --- a/src/switch_packetizer.c +++ b/src/switch_packetizer.c @@ -160,8 +160,6 @@ SWITCH_DECLARE(switch_status_t) switch_packetizer_feed_extradata(switch_packetiz p += 5; left -= 5; - if (left < 0) return SWITCH_STATUS_FALSE; - //sps n_sps = *p & 0x1f; p += 1; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index ad9f8eef1c..614d79bf78 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1353,7 +1353,6 @@ SWITCH_DECLARE(void) switch_srtp_err_to_txt(srtp_err_status_t stat, char **msg) else if (stat == srtp_err_status_read_fail) *msg="couldn't read data"; else if (stat == srtp_err_status_write_fail) *msg="couldn't write data"; else if (stat == srtp_err_status_parse_err) *msg="error parsing data"; - else if (stat == srtp_err_status_write_fail) *msg="couldn't read data"; else if (stat == srtp_err_status_encode_err) *msg="error encoding data"; else if (stat == srtp_err_status_semaphore_err) *msg="error while using semaphores"; else if (stat == srtp_err_status_pfkey_err) *msg="error while using pfkey "; @@ -4947,7 +4946,7 @@ SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session) } if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) { - if (rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) { + if (rtp_session->sock_input && rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) { ping_socket(rtp_session); switch_socket_shutdown(rtp_session->rtcp_sock_input, SWITCH_SHUTDOWN_READWRITE); } From 039823848906b11fd6183ba81f037b7211a29497 Mon Sep 17 00:00:00 2001 From: Clarence Date: Fri, 28 Apr 2023 04:43:32 +0800 Subject: [PATCH 028/123] [Core, mod_curl, mod_httapi, mod_http_cache] Compatible with libcurl>=7.87.0 * [core] fix deprecated with libcurl>=7.56.0 * [mod_httpapi] fix deprecated with libcurl>=7.56.0 * [mod_curl] fix deprecated with libcurl>=7.56.0 * [mod_http_cache] fix deprecated with libcurl>=7.12.1 --- src/include/switch_curl.h | 4 +++ src/mod/applications/mod_curl/mod_curl.c | 36 +++++++++++++++++++ src/mod/applications/mod_httapi/mod_httapi.c | 12 +++++++ src/mod/applications/mod_http_cache/azure.c | 4 +++ .../mod_http_cache/mod_http_cache.c | 2 ++ src/switch_curl.c | 31 ++++++++++++++-- 6 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/include/switch_curl.h b/src/include/switch_curl.h index 5872527865..389548791a 100644 --- a/src/include/switch_curl.h +++ b/src/include/switch_curl.h @@ -50,7 +50,11 @@ SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt(CURL *handle, switch_CUR SWITCH_DECLARE(const char *) switch_curl_easy_strerror(switch_CURLcode errornum ); SWITCH_DECLARE(void) switch_curl_init(void); SWITCH_DECLARE(void) switch_curl_destroy(void); +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) +SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, curl_mime **mimep); +#else SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp); +#endif #define switch_curl_easy_setopt curl_easy_setopt SWITCH_END_EXTERN_C diff --git a/src/mod/applications/mod_curl/mod_curl.c b/src/mod/applications/mod_curl/mod_curl.c index 02079d6767..c780e6947e 100644 --- a/src/mod/applications/mod_curl/mod_curl.c +++ b/src/mod/applications/mod_curl/mod_curl.c @@ -104,8 +104,13 @@ struct http_sendfile_data_obj { char *extrapost_elements; switch_CURL *curl_handle; char *cacert; +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_mime *mime; + curl_mimepart *part; +#else struct curl_httppost *formpost; struct curl_httppost *lastptr; +#endif uint8_t flags; /* This is for where to send output of the curl_sendfile commands */ switch_stream_handle_t *stream; char *sendfile_response; @@ -456,8 +461,19 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data) curl_easy_setopt(http_data->curl_handle, CURLOPT_WRITEFUNCTION, http_sendfile_response_callback); curl_easy_setopt(http_data->curl_handle, CURLOPT_WRITEDATA, (void *) http_data); + /* Initial http_data->mime */ +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + http_data->mime = curl_mime_init(http_data->curl_handle); +#endif + /* Add the file to upload as a POST form field */ +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + http_data->part = curl_mime_addpart(http_data->mime); + curl_mime_name(http_data->part, http_data->filename_element_name); + curl_mime_filedata(http_data->part, http_data->filename_element); +#else curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, http_data->filename_element_name, CURLFORM_FILE, http_data->filename_element, CURLFORM_END); +#endif if(!zstr(http_data->extrapost_elements)) { @@ -476,16 +492,32 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data) if(argc2 == 2) { switch_url_decode(argv2[0]); switch_url_decode(argv2[1]); +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + http_data->part = curl_mime_addpart(http_data->mime); + curl_mime_name(http_data->part, argv2[0]); + curl_mime_data(http_data->part, argv2[1], CURL_ZERO_TERMINATED); +#else curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, argv2[0], CURLFORM_COPYCONTENTS, argv2[1], CURLFORM_END); +#endif } } } /* Fill in the submit field too, even if this isn't really needed */ +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + http_data->part = curl_mime_addpart(http_data->mime); + curl_mime_name(http_data->part, "submit"); + curl_mime_data(http_data->part, "or_die", CURL_ZERO_TERMINATED); +#else curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "or_die", CURLFORM_END); +#endif /* what URL that receives this POST */ +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_easy_setopt(http_data->curl_handle, CURLOPT_MIMEPOST, http_data->mime); +#else curl_easy_setopt(http_data->curl_handle, CURLOPT_HTTPPOST, http_data->formpost); +#endif // This part actually fires off the curl, captures the HTTP response code, and then frees up the handle. curl_easy_perform(http_data->curl_handle); @@ -494,7 +526,11 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data) curl_easy_cleanup(http_data->curl_handle); // Clean up the form data from POST +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_mime_free(http_data->mime); +#else curl_formfree(http_data->formpost); +#endif } static switch_status_t http_sendfile_test_file_open(http_sendfile_data_t *http_data, switch_event_t *event) diff --git a/src/mod/applications/mod_httapi/mod_httapi.c b/src/mod/applications/mod_httapi/mod_httapi.c index 4b32d87c6d..4da0deeb49 100644 --- a/src/mod/applications/mod_httapi/mod_httapi.c +++ b/src/mod/applications/mod_httapi/mod_httapi.c @@ -1419,7 +1419,11 @@ static switch_status_t httapi_sync(client_t *client) switch_status_t status = SWITCH_STATUS_FALSE; int get_style_method = 0; char *method = NULL; +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_mime *formpost = NULL; +#else struct curl_httppost *formpost=NULL; +#endif switch_event_t *save_params = NULL; const char *put_file; FILE *fd = NULL; @@ -1588,7 +1592,11 @@ static switch_status_t httapi_sync(client_t *client) curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, put_file_read); } else if (formpost) { +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_easy_setopt(curl_handle, CURLOPT_MIMEPOST, formpost); +#else curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost); +#endif } else { switch_curl_easy_setopt(curl_handle, CURLOPT_POST, !get_style_method); } @@ -1671,7 +1679,11 @@ static switch_status_t httapi_sync(client_t *client) switch_curl_slist_free_all(headers); if (formpost) { +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_mime_free(formpost); +#else curl_formfree(formpost); +#endif } if (client->err) { diff --git a/src/mod/applications/mod_http_cache/azure.c b/src/mod/applications/mod_http_cache/azure.c index f1e4cf8925..a16d2e9f94 100644 --- a/src/mod/applications/mod_http_cache/azure.c +++ b/src/mod/applications/mod_http_cache/azure.c @@ -279,7 +279,11 @@ switch_status_t azure_blob_finalise_put(http_profile_t *profile, const char *url goto done; } +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x070c01) + switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1); +#else switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1); +#endif switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url); diff --git a/src/mod/applications/mod_http_cache/mod_http_cache.c b/src/mod/applications/mod_http_cache/mod_http_cache.c index 9d19099e56..365ba27425 100644 --- a/src/mod/applications/mod_http_cache/mod_http_cache.c +++ b/src/mod/applications/mod_http_cache/mod_http_cache.c @@ -393,7 +393,9 @@ static switch_status_t http_put(url_cache_t *cache, http_profile_t *profile, swi goto done; } switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1); +#if !defined(LIBCURL_VERSION_NUM) || (LIBCURL_VERSION_NUM < 0x070c01) switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1); +#endif switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url); diff --git a/src/switch_curl.c b/src/switch_curl.c index c99a5f61de..2612faa0da 100644 --- a/src/switch_curl.c +++ b/src/switch_curl.c @@ -58,11 +58,19 @@ SWITCH_DECLARE(void) switch_curl_destroy(void) curl_global_cleanup(); } +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) +SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, curl_mime **mimep) +#else SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp) +#endif { - +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + curl_mime *mime = NULL; + curl_mimepart *part = NULL; +#else struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; +#endif switch_event_header_t *hp; int go = 0; @@ -77,6 +85,9 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_even return SWITCH_STATUS_FALSE; } +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + mime = curl_mime_init(curl_handle); +#endif for (hp = event->headers; hp; hp = hp->next) { if (!strncasecmp(hp->name, "attach_file:", 12)) { @@ -87,26 +98,42 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_even if (fname) { *fname++ = '\0'; +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + part = curl_mime_addpart(mime); + curl_mime_name(part, pname); + curl_mime_filename(part, fname); + curl_mime_filedata(part, hp->value); +#else curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, pname, CURLFORM_FILENAME, fname, CURLFORM_FILE, hp->value, CURLFORM_END); +#endif } free(pname); } } else { +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + part = curl_mime_addpart(mime); + curl_mime_name(part, hp->name); + curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED); +#else curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, hp->name, CURLFORM_COPYCONTENTS, hp->value, CURLFORM_END); - +#endif } } +#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + *mimep = mime; +#else *formpostp = formpost; +#endif return SWITCH_STATUS_SUCCESS; From f377a0ff578ba950191b4629eae35f82bcd79388 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 1 May 2023 20:38:51 +0300 Subject: [PATCH 029/123] Revert "[Core, mod_curl, mod_httapi, mod_http_cache] Compatible with libcurl>=7.87.0" (#2070) This reverts commit 039823848906b11fd6183ba81f037b7211a29497. --- src/include/switch_curl.h | 4 --- src/mod/applications/mod_curl/mod_curl.c | 36 ------------------- src/mod/applications/mod_httapi/mod_httapi.c | 12 ------- src/mod/applications/mod_http_cache/azure.c | 4 --- .../mod_http_cache/mod_http_cache.c | 2 -- src/switch_curl.c | 31 ++-------------- 6 files changed, 2 insertions(+), 87 deletions(-) diff --git a/src/include/switch_curl.h b/src/include/switch_curl.h index 389548791a..5872527865 100644 --- a/src/include/switch_curl.h +++ b/src/include/switch_curl.h @@ -50,11 +50,7 @@ SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt(CURL *handle, switch_CUR SWITCH_DECLARE(const char *) switch_curl_easy_strerror(switch_CURLcode errornum ); SWITCH_DECLARE(void) switch_curl_init(void); SWITCH_DECLARE(void) switch_curl_destroy(void); -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) -SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, curl_mime **mimep); -#else SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp); -#endif #define switch_curl_easy_setopt curl_easy_setopt SWITCH_END_EXTERN_C diff --git a/src/mod/applications/mod_curl/mod_curl.c b/src/mod/applications/mod_curl/mod_curl.c index c780e6947e..02079d6767 100644 --- a/src/mod/applications/mod_curl/mod_curl.c +++ b/src/mod/applications/mod_curl/mod_curl.c @@ -104,13 +104,8 @@ struct http_sendfile_data_obj { char *extrapost_elements; switch_CURL *curl_handle; char *cacert; -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_mime *mime; - curl_mimepart *part; -#else struct curl_httppost *formpost; struct curl_httppost *lastptr; -#endif uint8_t flags; /* This is for where to send output of the curl_sendfile commands */ switch_stream_handle_t *stream; char *sendfile_response; @@ -461,19 +456,8 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data) curl_easy_setopt(http_data->curl_handle, CURLOPT_WRITEFUNCTION, http_sendfile_response_callback); curl_easy_setopt(http_data->curl_handle, CURLOPT_WRITEDATA, (void *) http_data); - /* Initial http_data->mime */ -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - http_data->mime = curl_mime_init(http_data->curl_handle); -#endif - /* Add the file to upload as a POST form field */ -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - http_data->part = curl_mime_addpart(http_data->mime); - curl_mime_name(http_data->part, http_data->filename_element_name); - curl_mime_filedata(http_data->part, http_data->filename_element); -#else curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, http_data->filename_element_name, CURLFORM_FILE, http_data->filename_element, CURLFORM_END); -#endif if(!zstr(http_data->extrapost_elements)) { @@ -492,32 +476,16 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data) if(argc2 == 2) { switch_url_decode(argv2[0]); switch_url_decode(argv2[1]); -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - http_data->part = curl_mime_addpart(http_data->mime); - curl_mime_name(http_data->part, argv2[0]); - curl_mime_data(http_data->part, argv2[1], CURL_ZERO_TERMINATED); -#else curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, argv2[0], CURLFORM_COPYCONTENTS, argv2[1], CURLFORM_END); -#endif } } } /* Fill in the submit field too, even if this isn't really needed */ -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - http_data->part = curl_mime_addpart(http_data->mime); - curl_mime_name(http_data->part, "submit"); - curl_mime_data(http_data->part, "or_die", CURL_ZERO_TERMINATED); -#else curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "or_die", CURLFORM_END); -#endif /* what URL that receives this POST */ -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_easy_setopt(http_data->curl_handle, CURLOPT_MIMEPOST, http_data->mime); -#else curl_easy_setopt(http_data->curl_handle, CURLOPT_HTTPPOST, http_data->formpost); -#endif // This part actually fires off the curl, captures the HTTP response code, and then frees up the handle. curl_easy_perform(http_data->curl_handle); @@ -526,11 +494,7 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data) curl_easy_cleanup(http_data->curl_handle); // Clean up the form data from POST -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_mime_free(http_data->mime); -#else curl_formfree(http_data->formpost); -#endif } static switch_status_t http_sendfile_test_file_open(http_sendfile_data_t *http_data, switch_event_t *event) diff --git a/src/mod/applications/mod_httapi/mod_httapi.c b/src/mod/applications/mod_httapi/mod_httapi.c index 4da0deeb49..4b32d87c6d 100644 --- a/src/mod/applications/mod_httapi/mod_httapi.c +++ b/src/mod/applications/mod_httapi/mod_httapi.c @@ -1419,11 +1419,7 @@ static switch_status_t httapi_sync(client_t *client) switch_status_t status = SWITCH_STATUS_FALSE; int get_style_method = 0; char *method = NULL; -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_mime *formpost = NULL; -#else struct curl_httppost *formpost=NULL; -#endif switch_event_t *save_params = NULL; const char *put_file; FILE *fd = NULL; @@ -1592,11 +1588,7 @@ static switch_status_t httapi_sync(client_t *client) curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, put_file_read); } else if (formpost) { -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_easy_setopt(curl_handle, CURLOPT_MIMEPOST, formpost); -#else curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost); -#endif } else { switch_curl_easy_setopt(curl_handle, CURLOPT_POST, !get_style_method); } @@ -1679,11 +1671,7 @@ static switch_status_t httapi_sync(client_t *client) switch_curl_slist_free_all(headers); if (formpost) { -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_mime_free(formpost); -#else curl_formfree(formpost); -#endif } if (client->err) { diff --git a/src/mod/applications/mod_http_cache/azure.c b/src/mod/applications/mod_http_cache/azure.c index a16d2e9f94..f1e4cf8925 100644 --- a/src/mod/applications/mod_http_cache/azure.c +++ b/src/mod/applications/mod_http_cache/azure.c @@ -279,11 +279,7 @@ switch_status_t azure_blob_finalise_put(http_profile_t *profile, const char *url goto done; } -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x070c01) - switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1); -#else switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1); -#endif switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url); diff --git a/src/mod/applications/mod_http_cache/mod_http_cache.c b/src/mod/applications/mod_http_cache/mod_http_cache.c index 365ba27425..9d19099e56 100644 --- a/src/mod/applications/mod_http_cache/mod_http_cache.c +++ b/src/mod/applications/mod_http_cache/mod_http_cache.c @@ -393,9 +393,7 @@ static switch_status_t http_put(url_cache_t *cache, http_profile_t *profile, swi goto done; } switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1); -#if !defined(LIBCURL_VERSION_NUM) || (LIBCURL_VERSION_NUM < 0x070c01) switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1); -#endif switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url); diff --git a/src/switch_curl.c b/src/switch_curl.c index 2612faa0da..c99a5f61de 100644 --- a/src/switch_curl.c +++ b/src/switch_curl.c @@ -58,19 +58,11 @@ SWITCH_DECLARE(void) switch_curl_destroy(void) curl_global_cleanup(); } -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) -SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, curl_mime **mimep) -#else SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp) -#endif { -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - curl_mime *mime = NULL; - curl_mimepart *part = NULL; -#else + struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; -#endif switch_event_header_t *hp; int go = 0; @@ -85,9 +77,6 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_even return SWITCH_STATUS_FALSE; } -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - mime = curl_mime_init(curl_handle); -#endif for (hp = event->headers; hp; hp = hp->next) { if (!strncasecmp(hp->name, "attach_file:", 12)) { @@ -98,42 +87,26 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_even if (fname) { *fname++ = '\0'; -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - part = curl_mime_addpart(mime); - curl_mime_name(part, pname); - curl_mime_filename(part, fname); - curl_mime_filedata(part, hp->value); -#else curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, pname, CURLFORM_FILENAME, fname, CURLFORM_FILE, hp->value, CURLFORM_END); -#endif } free(pname); } } else { -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - part = curl_mime_addpart(mime); - curl_mime_name(part, hp->name); - curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED); -#else curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, hp->name, CURLFORM_COPYCONTENTS, hp->value, CURLFORM_END); -#endif + } } -#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) - *mimep = mime; -#else *formpostp = formpost; -#endif return SWITCH_STATUS_SUCCESS; From 21613b6f683843bfa73008fa044827a133b0e7c3 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 13 May 2023 15:25:51 +0300 Subject: [PATCH 030/123] Bump sofia-sip library requirement to version 1.13.15 --- configure.ac | 2 +- debian/bootstrap.sh | 4 ++-- freeswitch.spec | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 7ca19e49e8..04738e93c1 100644 --- a/configure.ac +++ b/configure.ac @@ -716,7 +716,7 @@ PKG_CHECK_MODULES([SPANDSP], [spandsp >= 3.0],[ AC_MSG_ERROR([no usable spandsp; please install spandsp3 devel package or equivalent]) ]) -PKG_CHECK_MODULES([SOFIA_SIP], [sofia-sip-ua >= 1.13.14],[ +PKG_CHECK_MODULES([SOFIA_SIP], [sofia-sip-ua >= 1.13.15],[ AM_CONDITIONAL([HAVE_SOFIA_SIP],[true])],[ AC_MSG_ERROR([no usable sofia-sip; please install sofia-sip-ua devel package or equivalent]) ]) diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index e3f0b1b9db..c207036757 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -332,7 +332,7 @@ Build-Depends: uuid-dev, libexpat1-dev, libgdbm-dev, libdb-dev, # used by many modules libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl-dev, - bison, zlib1g-dev, libsofia-sip-ua-dev (>= 1.13.14), + bison, zlib1g-dev, libsofia-sip-ua-dev (>= 1.13.15), libspandsp3-dev, # used to format the private freeswitch apt-repo key properly gnupg, @@ -371,7 +371,7 @@ Description: Cross-Platform Scalable Multi-Protocol Soft Switch Package: libfreeswitch1 Architecture: amd64 armhf -Depends: \${shlibs:Depends}, \${misc:Depends}, libsofia-sip-ua0 (>= 1.13.14) +Depends: \${shlibs:Depends}, \${misc:Depends}, libsofia-sip-ua0 (>= 1.13.15) Recommends: Suggests: libfreeswitch1-dbg Conflicts: freeswitch-all (<= 1.6.7) diff --git a/freeswitch.spec b/freeswitch.spec index f3904afa2c..1d985cc299 100644 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -140,7 +140,7 @@ BuildRequires: curl-devel >= 7.19 BuildRequires: gcc-c++ BuildRequires: libtool >= 1.5.17 BuildRequires: openssl-devel >= 1.0.1e -BuildRequires: sofia-sip-devel >= 1.13.14 +BuildRequires: sofia-sip-devel >= 1.13.15 BuildRequires: spandsp3-devel >= 3.0 BuildRequires: pcre-devel BuildRequires: speex-devel From a3a4244f21472fd42490575a6a01a1f76d264ca9 Mon Sep 17 00:00:00 2001 From: ping Date: Wed, 17 May 2023 00:29:13 +0800 Subject: [PATCH 031/123] [mod_sofia] fix sofia_glue_get_extra_headers memory leak --- src/mod/endpoints/mod_sofia/sofia_glue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 8c9dfcc57a..0eb0dcf601 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -929,9 +929,9 @@ char *sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix if ( !exclude_regex || !(/*proceed*/ switch_regex_perform(name, exclude_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { const char *hname = name + strlen(prefix); stream.write_function(&stream, "%s: %s\r\n", hname, value); - switch_regex_safe_free(re); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ignoring Extra Header [%s] , matches exclude_outgoing_extra_header [%s]\n", name, exclude_regex); + switch_regex_safe_free(re); } } } From a4af2ea7de6e3eaff8aed1fb788a962db81739b4 Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 23 May 2023 20:14:22 -0300 Subject: [PATCH 032/123] [mod_png] Fix unexpected png video blocked read --- src/mod/formats/mod_png/mod_png.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/formats/mod_png/mod_png.c b/src/mod/formats/mod_png/mod_png.c index 36e38e9c83..fbbe6aaf20 100644 --- a/src/mod/formats/mod_png/mod_png.c +++ b/src/mod/formats/mod_png/mod_png.c @@ -215,7 +215,7 @@ static switch_status_t png_file_read_video(switch_file_handle_t *handle, switch_ switch_goto_status(SWITCH_STATUS_FALSE, end); } - if ((flags && SVR_BLOCK)) { + if ((flags & SVR_BLOCK)) { switch_yield(33000); have_frame = 1; } else if ((context->reads++ % 20) == 0) { From 35823b650a62e83a21b664b2e802b92215e92ac6 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 30 May 2023 22:45:54 +0300 Subject: [PATCH 033/123] [mod_verto] Include libks/ks.h instead of ks.h --- src/mod/endpoints/mod_verto/mod_verto.c | 2 +- src/mod/endpoints/mod_verto/mod_verto.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index e7defb99aa..38a3bc302a 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -43,7 +43,7 @@ SWITCH_MODULE_DEFINITION(mod_verto, mod_verto_load, mod_verto_shutdown, mod_vert #define HTTP_CHUNK_SIZE 1024 * 32 #define EP_NAME "verto.rtc" //#define WSS_STANDALONE 1 -#include "ks.h" +#include "libks/ks.h" #include #ifndef WIN32 diff --git a/src/mod/endpoints/mod_verto/mod_verto.h b/src/mod/endpoints/mod_verto/mod_verto.h index f3326f605d..f13e8ef2b9 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.h +++ b/src/mod/endpoints/mod_verto/mod_verto.h @@ -62,7 +62,7 @@ #include #include "mcast.h" -#include "ks.h" +#include "libks/ks.h" #define MAX_QUEUE_LEN 100000 #define MAX_MISSED 500 From ef275aec8a31a97faf7ddef1e4e4c009fa2ffcf6 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 31 May 2023 15:58:19 +0300 Subject: [PATCH 034/123] [mod_portaudio] coverity CID 1024263 (Dereference before null check) --- src/mod/endpoints/mod_portaudio/mod_portaudio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 62eba524d3..acd578e2e2 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -1296,9 +1296,9 @@ error: } switch_mutex_unlock(endpoint->mutex); } - if (new_session && *new_session) { - switch_core_session_destroy(new_session); - } + + switch_core_session_destroy(new_session); + return retcause; } From d7a4ab7dce65e4b828272bd93719b50faeb27d40 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 1 Jun 2023 17:24:37 +0300 Subject: [PATCH 035/123] [mod_spandsp] Coverity CID 1024263 (Dereference before null check) --- src/mod/applications/mod_spandsp/mod_spandsp_modem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_modem.c b/src/mod/applications/mod_spandsp/mod_spandsp_modem.c index 560a78be44..1f8a88cc75 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_modem.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_modem.c @@ -897,9 +897,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi fail: - if (new_session) { - switch_core_session_destroy(new_session); - } + switch_core_session_destroy(new_session); if (modem) { modem_set_state(modem, MODEM_STATE_ONHOOK); From b0a52eb1feaade9f0c0a89813fe4faf9dc5fab5c Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 9 Jun 2023 18:25:25 +0000 Subject: [PATCH 036/123] [core] Add switch_core_media_get_engine() and switch_core_media_get_codec() functions --- src/include/switch_core_media.h | 4 ++++ src/switch_core_media.c | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/include/switch_core_media.h b/src/include/switch_core_media.h index 8694a0bc88..1c1c321cb3 100644 --- a/src/include/switch_core_media.h +++ b/src/include/switch_core_media.h @@ -399,6 +399,10 @@ SWITCH_DECLARE(void) switch_core_media_set_smode(switch_core_session_t *session, SWITCH_DECLARE(void) switch_core_media_set_resolveice(switch_bool_t resolve_ice); SWITCH_DECLARE(switch_bool_t) switch_core_media_has_resolveice(void); +typedef struct switch_rtp_engine_s switch_rtp_engine_t; +SWITCH_DECLARE(switch_rtp_engine_t *) switch_core_media_get_engine(switch_core_session_t *session, int media_type); +SWITCH_DECLARE(switch_codec_t*) switch_core_media_get_codec(switch_core_session_t *session, switch_media_type_t type); + SWITCH_END_EXTERN_C #endif /* For Emacs: diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 912d5a5012..ae5dbf6d45 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -110,7 +110,7 @@ struct switch_rtp_text_factory_s { }; -typedef struct switch_rtp_engine_s { +struct switch_rtp_engine_s { switch_secure_settings_t ssec[CRYPTO_INVALID+1]; switch_rtp_crypto_key_type_t crypto_type; @@ -204,7 +204,7 @@ typedef struct switch_rtp_engine_s { void *engine_user_data; int8_t engine_function_running; switch_frame_buffer_t *write_fb; -} switch_rtp_engine_t; +}; #define MAX_REJ_STREAMS 10 @@ -16421,7 +16421,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess return status; } +SWITCH_DECLARE(switch_rtp_engine_t *) switch_core_media_get_engine(switch_core_session_t *session, int media_type) +{ + if (!session) return NULL; + return &session->media_handle->engines[media_type]; +} + +SWITCH_DECLARE(switch_codec_t*) switch_core_media_get_codec(switch_core_session_t *session, switch_media_type_t type) +{ + switch_rtp_engine_t *engine = switch_core_media_get_engine(session, type); + + if (!engine) return NULL; + + return &engine->read_codec; +} /* For Emacs: * Local Variables: From 86875d238167c3f54d347c29816f45b727a87fc8 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 12 Jun 2023 17:25:37 +0300 Subject: [PATCH 037/123] [mod_verto] Coverity fixes [mod_verto] coverity CID 1468439 (Dereference after null check) [mod_verto] coverity CID 1294451 (Dereference before null check) [mod_verto] coverity CID 1468443 (Logically dead code) --- src/mod/endpoints/mod_verto/mod_verto.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 38a3bc302a..8920de7e02 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -836,7 +836,7 @@ static void set_perm(const char *str, switch_event_t **event, switch_bool_t add) switch_event_create(event, SWITCH_EVENT_REQUEST_PARAMS); } - if (!zstr(str)) { + if (!zstr(str) && event && *event) { edup = strdup(str); switch_assert(edup); @@ -1059,7 +1059,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * *code = CODE_AUTH_FAILED; switch_snprintf(message, mlen, "Login Incorrect"); login_fire_custom_event(jsock, params, 0, "Login Incorrect"); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Login incorrect for user: %s domain: %s\n", id, domain ? domain : "N/A"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Login incorrect for user: %s domain: %s\n", id, domain); } else { switch_xml_t x_param, x_params; const char *use_passwd = NULL, *verto_context = NULL, *verto_dialplan = NULL; @@ -3954,7 +3954,7 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock cJSON *obj = cJSON_CreateObject(), *vobj = NULL, *dedEnc = NULL, *mirrorInput, *bandwidth = NULL, *canvas = NULL; switch_core_session_t *session = NULL; switch_channel_t *channel; - switch_event_t *var_event; + switch_event_t *var_event = NULL; switch_call_cause_t reason = SWITCH_CAUSE_INVALID_MSG_UNSPECIFIED, cancel_cause = 0; switch_caller_profile_t *caller_profile; int err = 0; @@ -4756,14 +4756,12 @@ static int start_jsock(verto_profile_t *profile, ks_socket_t sock, int family) error: - if (jsock) { - if (jsock->client_socket != KS_SOCK_INVALID) { - close_socket(&jsock->client_socket); - } - - switch_core_destroy_memory_pool(&pool); + if (jsock->client_socket != KS_SOCK_INVALID) { + close_socket(&jsock->client_socket); } + switch_core_destroy_memory_pool(&pool); + return -1; } From b4e43214f7c29e658e9a44239a45343d28186779 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 23 Mar 2023 23:01:17 +0300 Subject: [PATCH 038/123] [Core] Fix possible deadlock in switch_core_media_set_codec() --- src/switch_core_media.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index ae5dbf6d45..c6ed02cfe1 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -3601,11 +3601,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_codec(switch_core_session_ int resetting = 0; switch_media_handle_t *smh; switch_rtp_engine_t *a_engine; - switch_time_t start = switch_micro_time_now(); switch_assert(session); -retry: + switch_core_session_lock_codec_write(session); + switch_core_session_lock_codec_read(session); + switch_mutex_lock(session->codec_init_mutex); if (!(smh = session->media_handle)) { @@ -3627,17 +3628,7 @@ retry: (uint32_t) a_engine->read_impl.microseconds_per_packet / 1000 != a_engine->cur_payload_map->codec_ms || a_engine->read_impl.samples_per_second != a_engine->cur_payload_map->rm_rate ) { - if (switch_core_session_try_reset(session, 0, 0) != SWITCH_STATUS_SUCCESS) { - switch_time_t elapsed = switch_micro_time_now() - start; - if (elapsed > 1000000) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Could not reset session in %"SWITCH_TIME_T_FMT" us. Give up.\n", elapsed); - switch_goto_status(SWITCH_STATUS_FALSE, end); - } - - switch_mutex_unlock(session->codec_init_mutex); - switch_yield(10000); - goto retry; - } + switch_core_session_reset(session, 0, 0); switch_channel_audio_sync(session->channel); @@ -3651,9 +3642,6 @@ retry: a_engine->cur_payload_map->codec_ms, a_engine->cur_payload_map->rm_rate); - switch_yield(a_engine->read_impl.microseconds_per_packet); - switch_core_session_lock_codec_write(session); - switch_core_session_lock_codec_read(session); resetting = 1; switch_yield(a_engine->read_impl.microseconds_per_packet); switch_core_codec_destroy(&a_engine->read_codec); @@ -3767,12 +3755,13 @@ retry: if (resetting) { switch_channel_execute_on(session->channel, "execute_on_audio_change"); - switch_core_session_unlock_codec_write(session); - switch_core_session_unlock_codec_read(session); } switch_mutex_unlock(session->codec_init_mutex); + switch_core_session_unlock_codec_read(session); + switch_core_session_unlock_codec_write(session); + return status; } static void clear_ice(switch_core_session_t *session, switch_media_type_t type) From 9b20b324f5128d8a455342796674f2a9895976ff Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 12 Jun 2023 18:17:12 +0300 Subject: [PATCH 039/123] [mod_sofia] Coverity fixes [mod_sofia] coverity CID 1024253 (Dereference before null check) [mod_sofia] coverity CID 1024254 (Dereference before null check) [mod_sofia] coverity CID 1257620 (Logically dead code) [mod_sofia] coverity CID 1024750 (Dereference null return value) --- src/mod/endpoints/mod_sofia/mod_sofia.c | 12 ++++-------- src/mod/endpoints/mod_sofia/sofia.c | 5 ++++- src/mod/endpoints/mod_sofia/sofia_glue.c | 21 ++++++++------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 0b74b89c9d..4ff6f2fcff 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -472,7 +472,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_core_hash_delete_locked(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt->profile->flag_mutex); } - if (session && tech_pvt->profile->pres_type) { + if (tech_pvt->profile->pres_type) { char *sql = switch_mprintf("delete from sip_dialogs where uuid='%q'", switch_core_session_get_uuid(session)); switch_assert(sql); sofia_glue_execute_sql_now(tech_pvt->profile, &sql, SWITCH_TRUE); @@ -2205,11 +2205,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi argv[i], (double)((double)(MAX_REDIR + 1 - i))/1000); } } else { - if (i == argc - 1) { - switch_snprintf(newdest + strlen(newdest), len - strlen(newdest), "\"unknown\" <%s>", argv[i]); - } else { - switch_snprintf(newdest + strlen(newdest), len - strlen(newdest), "\"unknown\" <%s>,", argv[i]); - } + switch_snprintf(newdest + strlen(newdest), len - strlen(newdest), "\"unknown\" <%s>", argv[i]); } } else { if (i == argc - 1) { @@ -4313,6 +4309,8 @@ SWITCH_STANDARD_API(sofia_presence_data_function) user = argv[1]; } + if (!user) goto end; + if ((domain = strchr(user, '@'))) { *domain++ = '\0'; if ((concat = strchr(domain, '/'))) { @@ -4329,8 +4327,6 @@ SWITCH_STANDARD_API(sofia_presence_data_function) domain = dup_domain; } - if (!user) goto end; - if (zstr(profile_name) || strcmp(profile_name, "*") || zstr(domain)) { if (!zstr(profile_name)) { profile = sofia_glue_find_profile(profile_name); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index f14b574adf..c5b5bcc190 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2818,7 +2818,10 @@ void event_handler(switch_event_t *event) if ((sptr = strstr(fixed_contact_str, needle))) { char *origsptr = strstr(contact_str, needle); - eptr = strchr(++origsptr, ';'); + + if (origsptr) { + eptr = strchr(++origsptr, ';'); + } } else { sptr = strchr(fixed_contact_str, '\0') - 1; } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 0eb0dcf601..eceae218f8 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2282,8 +2282,7 @@ int sofia_recover_callback(switch_core_session_t *session) switch_channel_t *channel = switch_core_session_get_channel(session); private_object_t *tech_pvt = NULL; sofia_profile_t *profile = NULL; - const char *tmp; - const char *rr; + const char *tmp, *rr, *use_uuid; int r = 0; const char *profile_name = switch_channel_get_variable_dup(channel, "recovery_profile_name", SWITCH_FALSE, -1); int swap = switch_channel_var_true(channel, "dlg_req_swap_direction"); @@ -2374,17 +2373,13 @@ int sofia_recover_callback(switch_core_session_t *session) ); } - if (session) { - const char *use_uuid; - - if ((use_uuid = switch_channel_get_variable(channel, "origination_uuid"))) { - if (switch_core_session_set_uuid(session, use_uuid) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(channel), - use_uuid); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n", - switch_channel_get_name(channel), use_uuid); - } + if ((use_uuid = switch_channel_get_variable(channel, "origination_uuid"))) { + if (switch_core_session_set_uuid(session, use_uuid) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(channel), + use_uuid); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n", + switch_channel_get_name(channel), use_uuid); } } From 24452ff104af3282ba4a4a66522c4008bf91d07a Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Sat, 8 Jan 2022 12:14:16 +0200 Subject: [PATCH 040/123] [mod_opus] fix configuration glitches (switch_true() instead of atoi()). --- src/mod/codecs/mod_opus/mod_opus.c | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 04850a672e..6f061d1ce7 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -145,22 +145,22 @@ struct opus_context { }; struct { - int use_vbr; - int use_dtx; + switch_bool_t use_vbr; + switch_bool_t use_dtx; int complexity; int maxaveragebitrate; int maxplaybackrate; int sprop_maxcapturerate; int plpct; - int asymmetric_samplerates; - int bitrate_negotiation; - int keep_fec; - int fec_decode; - int adjust_bitrate; + switch_bool_t asymmetric_samplerates; + switch_bool_t bitrate_negotiation; + switch_bool_t keep_fec; + switch_bool_t fec_decode; + switch_bool_t adjust_bitrate; int debuginfo; - uint32_t use_jb_lookahead; + switch_bool_t use_jb_lookahead; switch_mutex_t *mutex; - int mono; + switch_bool_t mono; } opus_prefs; static struct { @@ -1052,25 +1052,25 @@ static switch_status_t opus_load_config(switch_bool_t reload) char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(key, "use-vbr") && !zstr(val)) { - opus_prefs.use_vbr = atoi(val); + opus_prefs.use_vbr = switch_true(val); } else if (!strcasecmp(key, "use-dtx")) { - opus_prefs.use_dtx = atoi(val); + opus_prefs.use_dtx = switch_true(val); } else if (!strcasecmp(key, "complexity")) { opus_prefs.complexity = atoi(val); } else if (!strcasecmp(key, "packet-loss-percent")) { opus_prefs.plpct = atoi(val); } else if (!strcasecmp(key, "asymmetric-sample-rates")) { - opus_prefs.asymmetric_samplerates = atoi(val); + opus_prefs.asymmetric_samplerates = switch_true(val); } else if (!strcasecmp(key, "bitrate-negotiation")) { - opus_prefs.bitrate_negotiation = atoi(val); + opus_prefs.bitrate_negotiation = switch_true(val); } else if (!strcasecmp(key, "use-jb-lookahead")) { opus_prefs.use_jb_lookahead = switch_true(val); } else if (!strcasecmp(key, "keep-fec-enabled")) { /* encoder */ - opus_prefs.keep_fec = atoi(val); + opus_prefs.keep_fec = switch_true(val); } else if (!strcasecmp(key, "advertise-useinbandfec")) { /*decoder, has meaning only for FMTP: useinbandfec=1 by default */ - opus_prefs.fec_decode = atoi(val); + opus_prefs.fec_decode = switch_true(val); } else if (!strcasecmp(key, "adjust-bitrate")) { /* encoder, this setting will make the encoder adjust its bitrate based on a feedback loop (RTCP). This is not "VBR".*/ - opus_prefs.adjust_bitrate = atoi(val); + opus_prefs.adjust_bitrate = switch_true(val); } else if (!strcasecmp(key, "maxaveragebitrate")) { opus_prefs.maxaveragebitrate = atoi(val); if (opus_prefs.maxaveragebitrate < SWITCH_OPUS_MIN_BITRATE || opus_prefs.maxaveragebitrate > SWITCH_OPUS_MAX_BITRATE) { @@ -1087,7 +1087,7 @@ static switch_status_t opus_load_config(switch_bool_t reload) opus_prefs.sprop_maxcapturerate = 0; /* value not supported */ } } else if (!strcasecmp(key, "mono")) { - opus_prefs.mono = atoi(val); + opus_prefs.mono = switch_true(val); } } } From a458d704abafb9ad26d431924ece44449cdd7fda Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Thu, 18 Aug 2022 19:48:20 +0300 Subject: [PATCH 041/123] [mod_opus] show uuid in logs. --- src/mod/codecs/mod_opus/mod_opus.c | 82 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 6f061d1ce7..9f34c193db 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -142,6 +142,7 @@ struct opus_context { dec_stats_t decoder_stats; enc_stats_t encoder_stats; codec_control_state_t control_state; + switch_bool_t recreate_decoder; }; struct { @@ -471,7 +472,7 @@ static int switch_opus_get_fec_bitrate(int fs, int loss) return SWITCH_STATUS_FALSE ; } -static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint32_t samples_per_second, char *print_text) +static switch_status_t switch_opus_info(switch_core_session_t *session, void * encoded_data, uint32_t len, uint32_t samples_per_second, char *print_text) { int nb_samples, nb_opus_frames, nb_channels; int audiobandwidth; @@ -483,18 +484,18 @@ static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint3 if (!encoded_data) { /* print stuff, even if encoded_data is NULL. eg: "PLC correction" */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s", print_text); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s", print_text); return SWITCH_STATUS_FALSE; } audiobandwidth = opus_packet_get_bandwidth(encoded_data); if (!switch_opus_show_audio_bandwidth(audiobandwidth,audiobandwidth_str)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s: OPUS_INVALID_PACKET !\n", print_text); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s: OPUS_INVALID_PACKET !\n", print_text); } if ((nb_opus_frames = opus_packet_parse(encoded_data, len, NULL, frame_data, frame_sizes, NULL)) <= 0 ) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s: OPUS_INVALID_PACKET ! frames: %d\n", print_text, nb_opus_frames); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s: OPUS_INVALID_PACKET ! frames: %d\n", print_text, nb_opus_frames); return SWITCH_STATUS_FALSE; } @@ -504,7 +505,7 @@ static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint3 nb_channels = opus_packet_get_nb_channels(payload); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: opus_frames [%d] samples [%d] audio bandwidth [%s] bytes [%d] FEC[%s] channels[%d]\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s: opus_frames [%d] samples [%d] audio bandwidth [%s] bytes [%d] FEC[%s] channels[%d]\n", print_text, nb_opus_frames, nb_samples, audiobandwidth_str, len, has_fec ? "yes" : "no", nb_channels); return SWITCH_STATUS_SUCCESS; @@ -518,6 +519,7 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag switch_codec_fmtp_t codec_fmtp, codec_fmtp_only_remote = { 0 }; opus_codec_settings_t opus_codec_settings = { 0 }; opus_codec_settings_t opus_codec_settings_remote = { 0 }; + switch_core_session_t *session = codec->session; if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(*context))))) { return SWITCH_STATUS_FALSE; @@ -591,7 +593,7 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag if (settings && settings->maxplaybackrate < enc_samplerate && settings->maxplaybackrate) { enc_samplerate = settings->maxplaybackrate; /*R1*/ context->enc_frame_size = enc_samplerate * (codec->implementation->microseconds_per_packet / 1000) / 1000; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder will be created at sample rate %d hz\n",enc_samplerate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus encoder will be created at sample rate %d hz\n",enc_samplerate); } else { enc_samplerate = codec->implementation->actual_samples_per_second; } @@ -604,19 +606,19 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag codec->implementation->number_of_channels == 1 ? OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO, &err); if (err != OPUS_OK) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create encoder: %s\n", opus_strerror(err)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create encoder: %s\n", opus_strerror(err)); return SWITCH_STATUS_GENERR; } /* https://tools.ietf.org/html/rfc7587 */ if (opus_codec_settings.maxaveragebitrate) { opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(opus_codec_settings.maxaveragebitrate)); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: set bitrate based on maxaveragebitrate value found in SDP or local config [%dbps]\n", opus_codec_settings.maxaveragebitrate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus encoder: set bitrate based on maxaveragebitrate value found in SDP or local config [%dbps]\n", opus_codec_settings.maxaveragebitrate); } else { opus_encoder_ctl(context->encoder_object, OPUS_SET_BANDWIDTH(OPUS_AUTO)); opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(bitrate_bps)); /* OPUS_AUTO */ opus_encoder_ctl(context->encoder_object, OPUS_GET_BITRATE(&bitrate_bps)); /* return average bps for this audio bandwidth */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: set bitrate to local settings [%dbps]\n", bitrate_bps); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus encoder: set bitrate to local settings [%dbps]\n", bitrate_bps); } /* Another fmtp setting from https://tools.ietf.org/html/rfc7587 - "RTP Payload Format for the Opus Speech and Audio Codec" */ if (opus_codec_settings.maxplaybackrate) { @@ -627,14 +629,14 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag if (!switch_opus_show_audio_bandwidth(audiobandwidth,audiobandwidth_str)) { snprintf(audiobandwidth_str, sizeof(audiobandwidth_str), "%s", "OPUS_AUTO"); } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: set audio bandwidth to [%s] based on maxplaybackrate value found in SDP or local config [%dHz]\n",audiobandwidth_str,opus_codec_settings.maxplaybackrate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus encoder: set audio bandwidth to [%s] based on maxplaybackrate value found in SDP or local config [%dHz]\n",audiobandwidth_str,opus_codec_settings.maxplaybackrate); } if (use_vbr) { /* VBR is default*/ opus_encoder_ctl(context->encoder_object, OPUS_SET_VBR(use_vbr)); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: CBR mode enabled\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus encoder: CBR mode enabled\n"); opus_encoder_ctl(context->encoder_object, OPUS_SET_VBR(0)); } @@ -684,7 +686,7 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag if (settings && dec_samplerate > settings->sprop_maxcapturerate && settings->sprop_maxcapturerate) { dec_samplerate = settings->sprop_maxcapturerate; /* R2 */ context->dec_frame_size = dec_samplerate*(codec->implementation->microseconds_per_packet / 1000) / 1000; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus decoder will be created at sample rate %d hz\n",dec_samplerate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus decoder will be created at sample rate %d hz\n",dec_samplerate); } else { dec_samplerate = codec->implementation->actual_samples_per_second; } @@ -697,7 +699,7 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag switch_set_flag(codec, SWITCH_CODEC_FLAG_HAS_PLC); if (err != OPUS_OK) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create decoder: %s\n", opus_strerror(err)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create decoder: %s\n", opus_strerror(err)); if (context->encoder_object) { opus_encoder_destroy(context->encoder_object); @@ -774,7 +776,7 @@ static switch_status_t switch_opus_encode(switch_codec_t *codec, if (globals.debug || context->debug > 1) { int samplerate = context->enc_frame_size * 1000 / (codec->implementation->microseconds_per_packet / 1000); - switch_opus_info(encoded_data, bytes, samplerate, "encode"); + switch_opus_info(codec->session, encoded_data, bytes, samplerate, "encode"); } if (bytes > 0) { @@ -796,7 +798,7 @@ static switch_status_t switch_opus_encode(switch_codec_t *codec, return SWITCH_STATUS_SUCCESS; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "Encoder Error: %s Decoded Datalen %u Codec NumberChans %u Len %u DecodedDate %p EncodedData %p ContextEncoderObject %p!\n", opus_strerror(bytes),decoded_data_len,codec->implementation->number_of_channels,len,(void *) decoded_data, (void *) encoded_data,(void *) context->encoder_object); @@ -818,6 +820,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, int32_t frame_size = 0, last_frame_size = 0; uint32_t frame_samples; uint8_t buf[SWITCH_RTP_MAX_BUF_LEN]; + switch_core_session_t *session = codec->session; if (!context) { return SWITCH_STATUS_FALSE; @@ -827,7 +830,6 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, frame_size = frame_samples - (frame_samples % (codec->implementation->actual_samples_per_second / 400)); if (*flag & SFF_PLC) { - switch_core_session_t *session = codec->session; switch_jb_t *jb = NULL; plc = 1; @@ -856,12 +858,12 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, frame.buflen = sizeof(buf); if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Missing %s %u Checking JB\n", seq ? "SEQ" : "TS", seq ? seq : ts); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Missing %s %u Checking JB\n", seq ? "SEQ" : "TS", seq ? seq : ts); } if (switch_jb_peek_frame(jb, ts, seq, 1, &frame) == SWITCH_STATUS_SUCCESS) { if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Lookahead frame found: %u:%u\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Lookahead frame found: %u:%u\n", frame.timestamp, frame.seq); } @@ -873,10 +875,10 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, if (globals.debug || context->debug) { if (fec) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FEC info available in packet with SEQ: %d LEN: %d\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "FEC info available in packet with SEQ: %d LEN: %d\n", frame.seq, frame.datalen); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO FEC info in this packet with SEQ: %d LEN: %d\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "NO FEC info in this packet with SEQ: %d LEN: %d\n", frame.seq, frame.datalen); } } @@ -890,9 +892,9 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, if (globals.debug || context->debug) { if (opus_prefs.use_jb_lookahead || context->use_jb_lookahead) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "MISSING FRAME: %s\n", fec ? "Look-ahead FEC" : "PLC"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "MISSING FRAME: %s\n", fec ? "Look-ahead FEC" : "PLC"); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "MISSING FRAME: OPUS_PLC\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "MISSING FRAME: OPUS_PLC\n"); } } @@ -901,7 +903,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, if (globals.debug || context->debug > 1) { int samplerate = context->dec_frame_size * 1000 / (codec->implementation->microseconds_per_packet / 1000); - switch_opus_info(encoded_data, encoded_data_len, + switch_opus_info(codec->session, encoded_data, encoded_data_len, samplerate ? samplerate : codec->implementation->actual_samples_per_second, !encoded_data ? "PLC correction" : fec ? "FEC correction" : "decode"); } @@ -918,8 +920,8 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, samples = opus_decode(context->decoder_object, encoded_data, encoded_data_len, decoded_data, frame_size, fec); if (samples < 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error: %s fs:%u plc:%s!\n", - opus_strerror(samples), frame_size, plc ? "true" : "false"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Decoder Error: %s fs:%u plc:%s!\n", + opus_strerror(samples), frame_size, plc ? "true" : "false"); return SWITCH_STATUS_NOOP; } @@ -962,7 +964,7 @@ static switch_status_t switch_opus_encode_repacketize(switch_codec_t *codec, } frame_size = (decoded_data_len / 2) / nb_frames; if((frame_size * nb_frames) != context->enc_frame_size) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Encoder Error: Decoded Datalen %u Number of frames: %u Encoder frame size: %u\n",decoded_data_len,nb_frames,context->enc_frame_size); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR,"Encoder Error: Decoded Datalen %u Number of frames: %u Encoder frame size: %u\n",decoded_data_len,nb_frames,context->enc_frame_size); switch_goto_status(SWITCH_STATUS_GENERR, end); } opus_repacketizer_init(rp); @@ -982,7 +984,7 @@ static switch_status_t switch_opus_encode_repacketize(switch_codec_t *codec, bytes = opus_encode(context->encoder_object, (opus_int16 *) dec_ptr_buf, frame_size, enc_ptr_buf, len); if (bytes < 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoder Error: %s Decoded Datalen %u Codec NumberChans %u" \ + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "Encoder Error: %s Decoded Datalen %u Codec NumberChans %u" \ "Len %u DecodedDate %p EncodedData %p ContextEncoderObject %p enc_frame_size: %d\n", opus_strerror(bytes), decoded_data_len, codec->implementation->number_of_channels, len, (void *) decoded_data, (void *) encoded_data, (void *) context->encoder_object, context->enc_frame_size); @@ -991,7 +993,7 @@ static switch_status_t switch_opus_encode_repacketize(switch_codec_t *codec, /* enc_ptr_buf : Opus API manual: "The application must ensure this pointer remains valid until the next call to opus_repacketizer_init() or opus_repacketizer_destroy()." */ ret = opus_repacketizer_cat(rp, enc_ptr_buf, bytes); if (ret != OPUS_OK) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opus encoder: error while repacketizing (cat) : %s !\n",opus_strerror(ret)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "Opus encoder: error while repacketizing (cat) : %s !\n",opus_strerror(ret)); switch_goto_status(SWITCH_STATUS_GENERR, end); } enc_ptr_buf += bytes; @@ -1000,18 +1002,18 @@ static switch_status_t switch_opus_encode_repacketize(switch_codec_t *codec, } /* this will never happen, unless there is a huge and unsupported number of frames */ if (total_len + opus_repacketizer_get_nb_frames(rp) > len / 2) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opus encoder: error while repacketizing: not enough buffer space\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "Opus encoder: error while repacketizing: not enough buffer space\n"); switch_goto_status(SWITCH_STATUS_GENERR, end); } ret = opus_repacketizer_out(rp, encoded_data, total_len+opus_repacketizer_get_nb_frames(rp)); if (globals.debug || context->debug) { int samplerate = context->enc_frame_size * 1000 / (codec->implementation->microseconds_per_packet / 1000); - switch_opus_info(encoded_data, ret, samplerate, "encode_repacketize"); + switch_opus_info(codec->session, encoded_data, ret, samplerate, "encode_repacketize"); } if (ret <= 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opus encoder: error while repacketizing (out) : %s ! packed nb_frames: %d\n", opus_strerror(ret), opus_repacketizer_get_nb_frames(rp)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "Opus encoder: error while repacketizing (out) : %s ! packed nb_frames: %d\n", opus_strerror(ret), opus_repacketizer_get_nb_frames(rp)); switch_goto_status(SWITCH_STATUS_GENERR, end); } if (want_fec) { @@ -1132,7 +1134,7 @@ static switch_status_t switch_opus_keep_fec_enabled(switch_codec_t *codec) LBRR_threshold_bitrate = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16); if (!real_target_bitrate || !LBRR_threshold_bitrate) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opus encoder: error while controlling FEC params\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "Opus encoder: error while controlling FEC params\n"); return SWITCH_STATUS_FALSE; } @@ -1141,7 +1143,7 @@ static switch_status_t switch_opus_keep_fec_enabled(switch_codec_t *codec) if (real_target_bitrate > LBRR_threshold_bitrate) { /*FEC is already enabled, do nothing*/ if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: FEC is enabled\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: FEC is enabled\n"); } return SWITCH_STATUS_SUCCESS; } else { @@ -1153,7 +1155,7 @@ static switch_status_t switch_opus_keep_fec_enabled(switch_codec_t *codec) opus_encoder_ctl(context->encoder_object,OPUS_SET_BITRATE(current_bitrate)); if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: increased bitrate to [%d] to keep FEC enabled\n", current_bitrate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: increased bitrate to [%d] to keep FEC enabled\n", current_bitrate); } return SWITCH_STATUS_SUCCESS; @@ -1229,7 +1231,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, } if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting packet loss percent from %d%% to %d%%!\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: Adjusting packet loss percent from %d%% to %d%%!\n", context->old_plpct, plpct); } } @@ -1243,7 +1245,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, float steps = (float)((float)(range / 100) / base_step); int br_step = (int)(round(steps) * base_step) * plpct; if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: bitrate increase/decrease step now is: %d bps, range:%d\n", br_step, range); } context->control_state.increase_step = context->control_state.decrease_step = br_step; @@ -1269,7 +1271,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, opus_prefs.keep_fec = 1; /* enable back FEC if it was disabled by SCC_AUDIO_ADJUST_BITRATE, we have enough network bandwidth now */ } if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (increase)\n", current_bitrate+br_step); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (increase)\n", current_bitrate+br_step); } } } else if (!strcasecmp(cmd, "decrease")) { @@ -1283,7 +1285,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, } opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(current_bitrate-br_step)); if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (decrease)\n", current_bitrate-br_step); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (decrease)\n", current_bitrate-br_step); } } } else if (!strcasecmp(cmd, "default")) { @@ -1293,7 +1295,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, opus_prefs.keep_fec = 1; /* enable back FEC, we have enough network bandwidth now */ } if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (configured maxaveragebitrate)\n", opus_prefs.maxaveragebitrate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (configured maxaveragebitrate)\n", opus_prefs.maxaveragebitrate); } } else { /* set Opus minimum bitrate */ @@ -1302,7 +1304,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, opus_prefs.keep_fec = 0; /* do not enforce FEC anymore, we're low on network bandwidth */ } if (globals.debug || context->debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (minimum)\n", SWITCH_OPUS_MIN_BITRATE); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (minimum)\n", SWITCH_OPUS_MIN_BITRATE); } } } From 5065c0b11869007809f4983432f93e068d43ac0e Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 24 Aug 2022 13:02:35 +0300 Subject: [PATCH 042/123] [mod_opus] fix samples_per_packet for 8khz, 16khz, 24khz. --- src/mod/codecs/mod_opus/mod_opus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 9f34c193db..1ab7d9fba1 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -1342,7 +1342,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load) { switch_codec_interface_t *codec_interface; switch_api_interface_t *commands_api_interface; - int samples = 480; + int samples = 480; /* start with 10 ms ptime */ int bytes = 960; int mss = 10000; int x = 0; @@ -1443,7 +1443,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load) } /* 16 khz */ - samples = 480; + samples = 160; bytes = 320; mss = 10000; rate = 16000; @@ -1540,7 +1540,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load) } /* 8 khz */ - samples = 480; + samples = 80; bytes = 160; mss = 10000; rate = 8000; From f90aeade4fcb5cec6884833442ae1111fcf027e9 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Thu, 26 Jan 2023 20:14:35 +0200 Subject: [PATCH 043/123] [core] Opus RTP timestamp: adding an exception on RTP session creation. https://www.rfc-editor.org/rfc/rfc7587.html "The RTP timestamp is incremented with a 48000 Hz clock rate for all modes of Opus and all sampling rates. The unit for the timestamp is samples per single (mono) channel" Follow up: 50f57f85732b0d5a58a39f3fca7b654f894b0c9d, ccbef9e0c7e31c410ce08b5276c3e2e5a2f69883 . --- src/switch_core_media.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index c6ed02cfe1..8ed496bda7 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -8724,7 +8724,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi a_engine->cur_payload_map->remote_sdp_ip, a_engine->cur_payload_map->remote_sdp_port, a_engine->cur_payload_map->pt, - a_engine->read_impl.samples_per_packet, + strcasecmp("opus", a_engine->read_impl.iananame) ? a_engine->read_impl.samples_per_packet : + a_engine->read_impl.samples_per_second * (a_engine->read_impl.microseconds_per_packet / 1000) / 1000, a_engine->cur_payload_map->codec_ms * 1000, flags, timer_name, &err, switch_core_session_get_pool(session), 0, 0); From 5e914efc8c0452647dc33f810dd020f8e93d4f5d Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Thu, 11 May 2023 03:55:11 +0300 Subject: [PATCH 044/123] [core, mod_opus] bring more fmtp params to core (offer/answer). --- src/include/switch_module_interfaces.h | 10 ++++++++-- src/mod/codecs/mod_opus/mod_opus.c | 3 +++ src/switch_core_media.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 7c54ed67df..ddaaf120a1 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -676,8 +676,14 @@ struct switch_codec_fmtp { int bits_per_second; /*! number of microseconds of media in one packet (ptime * 1000) */ int microseconds_per_packet; - /*! stereo */ - int stereo; + /*! maximum ptime in ms */ + int max_ptime; + /*! minimum ptime in ms */ + int min_ptime; + /*! stereo, typically bidirectional */ + int stereo; + /* sender properties (stereo) */ + int sprop_stereo; /*! private data for the codec module to store handle specific info */ void *private_info; diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 1ab7d9fba1..ce364cc3ef 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -273,10 +273,12 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt if (!strcasecmp(data, "maxptime")) { codec_settings->maxptime = atoi(arg); + codec_fmtp->max_ptime = codec_settings->maxptime; } if (!strcasecmp(data, "minptime")) { codec_settings->minptime = atoi(arg); + codec_fmtp->min_ptime = codec_settings->minptime; } if (!strcasecmp(data, "ptime")) { @@ -291,6 +293,7 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt if (!strcasecmp(data, "sprop-stereo")) { codec_settings->sprop_stereo = atoi(arg); + codec_fmtp->sprop_stereo = codec_settings->sprop_stereo; } if (!strcasecmp(data, "maxaveragebitrate")) { diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 8ed496bda7..60cc3d531c 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -5497,6 +5497,10 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s } else if (!strcasecmp(map->rm_encoding, "opus")) { map_channels = 1; } + + if (codec_fmtp.max_ptime) { + maxptime = codec_fmtp.max_ptime; + } } } From 7bc999309cd2b9be2420f30dde9ef20b8c92ed96 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Thu, 15 Jun 2023 16:29:43 +0300 Subject: [PATCH 045/123] [mod_opus] fix remote codec rate to match. --- src/mod/codecs/mod_opus/mod_opus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index ce364cc3ef..4a47b45df4 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -314,6 +314,10 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt if (!switch_opus_acceptable_rate(codec_settings->sprop_maxcapturerate)) { codec_settings->sprop_maxcapturerate = 0; /* value not supported */ } + + if (codec_settings->sprop_maxcapturerate) { + codec_fmtp->actual_samples_per_second = codec_settings->sprop_maxcapturerate; + } } } } From 9c63f03b453e5b935cefd697e9b987d6f0987dca Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Fri, 16 Jun 2023 17:30:15 +0000 Subject: [PATCH 046/123] [Core] Add new cause REJECT_ALL --- src/include/switch_types.h | 3 ++- src/switch_channel.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 7b519899af..82639c2ca6 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -2249,7 +2249,8 @@ typedef enum { SWITCH_CAUSE_BAD_IDENTITY_INFO = 821, SWITCH_CAUSE_UNSUPPORTED_CERTIFICATE = 822, SWITCH_CAUSE_INVALID_IDENTITY = 823, - SWITCH_CAUSE_STALE_DATE = 824 + SWITCH_CAUSE_STALE_DATE = 824, + SWITCH_CAUSE_REJECT_ALL = 825 } switch_call_cause_t; typedef enum { diff --git a/src/switch_channel.c b/src/switch_channel.c index ea3f66c246..6f0ad7a964 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -135,6 +135,7 @@ static struct switch_cause_table CAUSE_CHART[] = { {"UNSUPPORTED_CERTIFICATE", SWITCH_CAUSE_UNSUPPORTED_CERTIFICATE}, {"INVALID_IDENTITY", SWITCH_CAUSE_INVALID_IDENTITY}, {"STALE_DATE", SWITCH_CAUSE_STALE_DATE}, + {"REJECT_ALL", SWITCH_CAUSE_REJECT_ALL}, {NULL, 0} }; From f64314ff485a6fa7ea9eb48156bb84f28544504f Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 22 Jun 2023 18:02:20 +0300 Subject: [PATCH 047/123] [mod_sofia] Map SWITCH_CAUSE_REJECT_ALL cause to 603 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 4ff6f2fcff..2fdf0063a9 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -348,6 +348,7 @@ static int hangup_cause_to_sip(switch_call_cause_t cause) case SWITCH_CAUSE_BUSY_EVERYWHERE: return 600; case SWITCH_CAUSE_DECLINE: + case SWITCH_CAUSE_REJECT_ALL: return 603; case SWITCH_CAUSE_DOES_NOT_EXIST_ANYWHERE: return 604; From 67840823c178153cb013014c4fa780fe233612cb Mon Sep 17 00:00:00 2001 From: Julien Chavanton Date: Fri, 23 Jun 2023 09:45:31 -0400 Subject: [PATCH 048/123] [core, mod_opus] more elastic jitterbuffer with Opus codec (#2069) --- scripts/lua/hangup_jitterbuffer_metrics.lua | 53 +++ src/include/switch_jitterbuffer.h | 1 + src/include/switch_types.h | 1 + src/mod/codecs/mod_opus/Makefile.am | 2 +- src/mod/codecs/mod_opus/mod_opus.c | 30 ++ src/mod/codecs/mod_opus/opus_parse.c | 366 ++++++++++++++++++++ src/mod/codecs/mod_opus/opus_parse.h | 66 ++++ src/switch_jitterbuffer.c | 239 ++++++++++++- src/switch_rtp.c | 1 + 9 files changed, 756 insertions(+), 3 deletions(-) create mode 100755 scripts/lua/hangup_jitterbuffer_metrics.lua create mode 100644 src/mod/codecs/mod_opus/opus_parse.c create mode 100644 src/mod/codecs/mod_opus/opus_parse.h diff --git a/scripts/lua/hangup_jitterbuffer_metrics.lua b/scripts/lua/hangup_jitterbuffer_metrics.lua new file mode 100755 index 0000000000..8e3dd37623 --- /dev/null +++ b/scripts/lua/hangup_jitterbuffer_metrics.lua @@ -0,0 +1,53 @@ +local https = require("socket.http") +local ip = os.getenv("LOCAL_IPV4") +local response_body = {} +-- jitter buffer stats +local size_max_ms = session:getVariable("rtp_jb_size_max_ms"); +local size_est_ms = session:getVariable("rtp_jb_size_est_ms"); +local acceleration_ms = session:getVariable("rtp_jb_acceleration_ms"); +local expand_ms = session:getVariable("rtp_jb_expand_ms"); +local jitter_max_ms = session:getVariable("rtp_jb_jitter_max_ms"); +local jitter_est_ms = session:getVariable("rtp_jb_jitter_est_ms"); + +local reset_count = session:getVariable("rtp_jb_reset_count"); +local reset_too_big = session:getVariable("rtp_jb_reset_too_big"); +local reset_missing_frames = session:getVariable("rtp_jb_reset_missing_frames"); +local reset_ts_jump = session:getVariable("rtp_jb_reset_ts_jump"); +local reset_error = session:getVariable("rtp_jb_reset_error"); +local call_id = session:getVariable("sip_call_id"); +local out_call_id = session:getVariable("last_bridge_to"); + +if size_max_ms == nil or size_est_ms == nil or acceleration_ms == nil or expand_ms == nil or jitter_max_ms == nil or jitter_est_ms == nil then + session:consoleLog("info", "[metrics] jitter no data\n"); + return +end +local request_body = '{"in_call_id": "'..call_id..'", "out_call_id": "'..out_call_id..'", "jb":{"size_max_ms":'..size_max_ms.. + ',"size_est_ms":'..size_est_ms..',"acceleration_ms":'..acceleration_ms..',"expand_ms":'..expand_ms.. + ',"jitter_max_ms":'..jitter_max_ms..',"jitter_est_ms":'..jitter_est_ms..',"reset":'..reset_count +-- if reset_too_big ~= "0" then + request_body = request_body .. ',"reset_too_big":'..reset_too_big +-- end +if reset_missing_frames ~= "0" then + request_body = request_body .. ',"reset_missing_frames":'..reset_missing_frames +end +if reset_ts_jump ~= "0" then + request_body = request_body .. ',"reset_ts_jump":'..reset_ts_jump +end +if reset_error ~= "0" then + request_body = request_body .. ',"reset_error":'..reset_error +end + +local v = request_body .. '}}'; + +local r, c, h, s = https.request{ + method = 'POST', + url = "http://"..ip..":80/freeswitch_metrics", + headers = { + ["Content-Type"] = "application/json", + ["Content-Length"] = string.len(v) + }, + source = ltn12.source.string(v), + sink = ltn12.sink.table(response_body) +} +-- print('statusCode ', c) +session:consoleLog("info", "[metrics] jitter:".. v .. "\n"); diff --git a/src/include/switch_jitterbuffer.h b/src/include/switch_jitterbuffer.h index bee0fa02f8..f098ede2db 100644 --- a/src/include/switch_jitterbuffer.h +++ b/src/include/switch_jitterbuffer.h @@ -61,6 +61,7 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp SWITCH_DECLARE(uint32_t) switch_jb_pop_nack(switch_jb_t *jb); SWITCH_DECLARE(switch_status_t) switch_jb_get_packet_by_seq(switch_jb_t *jb, uint16_t seq, switch_rtp_packet_t *packet, switch_size_t *len); SWITCH_DECLARE(void) switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session); +SWITCH_DECLARE(void) switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jitter, uint32_t samples_per_frame, uint32_t samples_per_second); SWITCH_DECLARE(void) switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_frame, uint32_t samples_per_second); SWITCH_DECLARE(void) switch_jb_set_flag(switch_jb_t *jb, switch_jb_flag_t flag); SWITCH_DECLARE(void) switch_jb_clear_flag(switch_jb_t *jb, switch_jb_flag_t flag); diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 82639c2ca6..94a4c62cca 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -2425,6 +2425,7 @@ typedef enum { SCC_VIDEO_RESET, SCC_AUDIO_PACKET_LOSS, SCC_AUDIO_ADJUST_BITRATE, + SCC_AUDIO_VAD, SCC_DEBUG, SCC_CODEC_SPECIFIC } switch_codec_control_command_t; diff --git a/src/mod/codecs/mod_opus/Makefile.am b/src/mod/codecs/mod_opus/Makefile.am index 690c5fa471..70710898e7 100644 --- a/src/mod/codecs/mod_opus/Makefile.am +++ b/src/mod/codecs/mod_opus/Makefile.am @@ -4,7 +4,7 @@ MODNAME=mod_opus if HAVE_OPUS mod_LTLIBRARIES = mod_opus.la -mod_opus_la_SOURCES = mod_opus.c +mod_opus_la_SOURCES = mod_opus.c opus_parse.c mod_opus_la_CFLAGS = $(AM_CFLAGS) $(OPUS_CFLAGS) mod_opus_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(OPUS_LIBS) mod_opus_la_LDFLAGS = -avoid-version -module -no-undefined -shared -lm -lz diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 4a47b45df4..ce9aff52a3 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -33,6 +33,7 @@ #include "switch.h" #include "opus.h" +#include "opus_parse.h" #define SWITCH_OPUS_MIN_BITRATE 6000 #define SWITCH_OPUS_MAX_BITRATE 510000 @@ -1169,6 +1170,27 @@ static switch_status_t switch_opus_keep_fec_enabled(switch_codec_t *codec) } } +static switch_bool_t switch_opus_vad(struct opus_context *context, void *encoded_data, uint32_t encoded_data_len) { + const uint8_t *payload = (const uint8_t *) encoded_data; + opus_packet_info_t opus_packet_info; + switch_bool_t debug = (globals.debug || context->debug > 1); + if (!switch_opus_packet_parse(payload, encoded_data_len, &opus_packet_info, debug)) { + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "OPUS PACKET PARSING ERROR len:%d bytes:%02x %02x\n", + (int)encoded_data_len, payload[0], payload[1]); + } + return SWITCH_TRUE; + } + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "OPUS EXTRACT PAYLOAD VAD len:%d vad_ms:%d bytes:%02x %02x\n", + (int)encoded_data_len, opus_packet_info.vad_ms, payload[0], payload[1]); + } + if (opus_packet_info.vad_ms == 0) { + return SWITCH_FALSE; + } + return SWITCH_TRUE; +} + static switch_status_t switch_opus_control(switch_codec_t *codec, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, @@ -1260,6 +1282,14 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, context->old_plpct = plpct; } break; + case SCC_AUDIO_VAD: + { + void* encoded_data = (void *)cmd_data; + uint16_t* encoded_data_len = (uint16_t *)cmd_arg; + switch_bool_t *ret = (switch_bool_t *) *ret_data; + *ret = switch_opus_vad(context, encoded_data, *encoded_data_len); + } + break; case SCC_AUDIO_ADJUST_BITRATE: { const char *cmd = (const char *)cmd_data; diff --git a/src/mod/codecs/mod_opus/opus_parse.c b/src/mod/codecs/mod_opus/opus_parse.c new file mode 100644 index 0000000000..41e1ec6490 --- /dev/null +++ b/src/mod/codecs/mod_opus/opus_parse.c @@ -0,0 +1,366 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2023, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Claude Lamblin + * Julien Chavanton + * + */ + +#include "switch.h" +#include +#include "opus_parse.h" +/* Tables for LBRR_sympbol decoding */ + +static const opus_int16 silk_LBRR_flags_2_PDFCum[3] = {53, 106, 256}; /* 256 - silk_LBRR_flags_2_iCDF[i] ; silk_LBRR_flags_2_iCDF[ 3 ] = { 203, 150, 0 }; */ +static const opus_int16 silk_LBRR_flags_3_PDFCum[7] = {41, 61, 90, 131, 146, 174, 256}; /* 256 - silk_LBRR_flags_3_iCDF[i] ; silk_LBRR_flags_3_iCDF[ 7 ] = { 215, 195, 166, 125, 110, 82, 0 }; */ + +/* get the number of VAD flags - i.e. number of 20 ms frame - from the config */ +/* in a silk-only or hybrid opus frame mono or stereo*/ +/* 5 MSB TOC byte (see table 2 of IETF RFC6716 clause 3.1) */ +/* if 10 ms frame (config=0, 4, 8, 12, 14) : return 1 */ +/* if CELT_only frame no VAD flag =>return 0 */ +static opus_int16 switch_opus_get_nb_flags_in_silk_frame(int16_t config) +{ + opus_int16 silk_frame_nb_flags; + if (config > 15) { + /* CELT_only frame no VAD flag nor LBRR flag */ + silk_frame_nb_flags = 0; + } else { + silk_frame_nb_flags = 1; /*default*/ + if (config < 12) { + /* silk-only NB, MB or WB */ + /* The least two significant bits give the number of VAD flags inside the silk frame 1, 2 or 3 */ + silk_frame_nb_flags = config & 0x3; + if (silk_frame_nb_flags == 0) { /* 0 => 10ms frame : one VAD flag */ + silk_frame_nb_flags++; + } + } + } + return silk_frame_nb_flags; +} + +/* get the time in ms corresponding to one VAD flag from the config */ +/* in a silk-only or hybrid opus frame mono or stereo*/ +/* 5 MSB TOC byte (see table 2 of IETF RFC6716 clause 3.1) */ +/* if CELT_only frame (config >15) no VAD flag =>return FALSE */ +/* if 10 ms frame (config=0, 4, 8, 12, 14) : return 10 */ +/* otherwise return 20 */ +static opus_int16 switch_opus_get_silk_frame_ms_per_flag(int16_t config, opus_int16 silk_frame_nb_flags) +{ + opus_int16 silk_size_frame_ms_per_flag; + if (config > 15) { + /* CELT_only frame no VAD flag nor LBRR flag */ + /* switch_opus_get_silk_frame_ms_per_flag: code not written for CELT-only mode */ + return FALSE; + } + silk_size_frame_ms_per_flag = 20; /* default*/ + if (silk_frame_nb_flags == 1) { /* could be 10 or 20 ms */ + if ((config &0x01) == 0) { + silk_size_frame_ms_per_flag = 10; + } + } + return silk_size_frame_ms_per_flag; +} + +/* code written only for mono, silk-only or hybrid mode */ +/* for CELT-only frame no vad flags for LBRR flag the routine must not be called */ +/* for stereo : the mid frame VAD_flags and the LBRR_flag could be obtained */ +/* yet, to get the LBRR_flags of the mid frame the routine should be modified */ +/* to skip the side VAD flags and the side LBRR flag and to get the mid LBRR_symbol */ +static bool_t switch_opus_get_VAD_LBRR_flags(const uint8_t *buf, opus_int16 silk_frame_nb_flags, + opus_int16 *VAD_flags, opus_int16 *LBRR_flags, opus_int16 *nb_VAD1, opus_int16 *nb_FEC) +{ + const opus_int16 *ptr_pdf_cum; + opus_int nb_pdf_symbol; + opus_uint16 LBRR_symbol; + opus_int16 val, nb_bit, compl_nb_bit, mask, mask2; + opus_int16 *ptr_flags; + opus_int16 LBRR_flag; + opus_int16 nb_vad, nb_fec; + int i; + + nb_vad = 0; + nb_fec = 0; + + /* get VAD_FLAGS & LBRR_FLAG */ + /* silk_frame_nb_flags = 1 (10 or 20 ms), the two MSB of the first byte are the VAD flag and the LBRR flag */ + /* silk_frame_nb_flags = 2 (40 ms), the three MSB of the first byte are the two VAD flags and the LBRR flag */ + /* silk_frame_nb_flags = 3 (60 ms), the four MSB of the first byte are the three VAD flags and the LBRR flag */ + /* compute the number of MSB to analyse */ + nb_bit = silk_frame_nb_flags + 1; + /* number of right shifts to appply to the first byte to only have the bits of LBRR flag and of the VAD flags */ + compl_nb_bit = 8 - nb_bit; + mask = (1 << nb_bit) - 1; + + /* the bits of the silk_frame_nb_flags VAD flags and the LBRR flag are the MSB of the first byte */ + /* silk_frame_nb_flags = 1 (10 or 20 ms), VAD_flags(0) | LBRR_flag */ + /* silk_frame_nb_flags = 2 (40 ms), VAD_flags(0) | VAD_flags(1) | LBRR_flag */ + /* silk_frame_nb_flags = 3 (60 ms), VAD_flags(0) | VAD_flags(1) | VAD_flags(2) |LBRR_flag */ + val = (buf[0] >> compl_nb_bit) & mask; + + LBRR_flag = val & 0x1; /* LBRR_FLAG LSB */ + + /* get VAD_flags */ + ptr_flags = VAD_flags + silk_frame_nb_flags; + for (i=0; i < silk_frame_nb_flags; i++) { + LBRR_flags[i] = 0; /* init */ + val >>= 1; + *(--ptr_flags) = val & 0x1; + } + if (LBRR_flag != 0) { /* there is at least one LBRR frame */ + if (silk_frame_nb_flags == 1) { + LBRR_flags[0] = 1; + nb_fec = 1; + } else { /* get LBRR_symbol then LBRR_flags */ + /* LBRR symbol is encoded with range encoder : range on 8 bits */ + /* silk_frame_nb_flags = 2 ; 3 possible values for LBRR_flags(1) | LBRR_flags(0))= 01, 10, 11 */ + /* silk_frame_nb_flags = 3 ; 7 possible values for LBRR_flags(2) | LBRR_flags(1) | LBRR_flags(0))= 001, 010, 011, 100, 101, 110, 111 */ + mask2 = (1 << compl_nb_bit) - 1; + /* get next 8 bits: (8-nb_bit) LSB of the first byte and nb_bit MSB of the second byte */ + val = (((buf[0]) & mask2) << nb_bit) | ((buf[1] >> compl_nb_bit) & mask); + + if (silk_frame_nb_flags == 2) { + nb_pdf_symbol = 3; + ptr_pdf_cum = silk_LBRR_flags_2_PDFCum; + } else { + nb_pdf_symbol = 7; + ptr_pdf_cum = silk_LBRR_flags_3_PDFCum; + } + LBRR_symbol = 0; + for (i = 1; i <= nb_pdf_symbol; i++) { + if (val < *ptr_pdf_cum++) { + LBRR_symbol = i; + break; + } + } + for (i = 0; i < silk_frame_nb_flags; i++) { + LBRR_flags[i] = LBRR_symbol & 0x01; + LBRR_symbol >>= 1; + nb_fec += LBRR_flags[i]; + } + } + } + for (i = 0; i < silk_frame_nb_flags; i++) { + nb_vad += VAD_flags[i]; + } + + *nb_VAD1 = nb_vad; + *nb_FEC = nb_fec; + return TRUE; +} + +/* Parse the packet to retrieve informations about its content + * RFC6716: Definition of the Opus Audio Codec + * return: FALSE if there was a problem found parsing the packet, the info returned should be ignored. + * */ +bool_t switch_opus_packet_parse(const uint8_t *payload, int payload_length_bytes, opus_packet_info_t *packet_info, bool_t debug) +{ + int f; + int32_t samplerate; + int i, shift_silk, silk_frame_packet; + int16_t vad_flags_per_silk_frame, fec_flags_per_silk_frame; + opus_int16 frame_sizes[48]; + const unsigned char *frame_data[48]; + opus_int16 packet_LBBR_FLAGS[3 * 48], packet_VAD_FLAGS[3 * 48]; + opus_int16 *ptr_LBBR_FLAGS, *ptr_VAD_FLAGS; + opus_int16 silk_frame_nb_flags, silk_size_frame_ms_per_flag; + opus_int16 silk_frame_nb_fec, silk_frame_nb_vad1; + opus_int sample_per_frame; + packet_info->config = 0; + packet_info->fec = 0; + packet_info->fec_ms = 0; + packet_info->vad = 0; + packet_info->vad_ms = 0; + packet_info->stereo = FALSE; + packet_info->frames = 0; + packet_info->channels = 1; /* as stereo is set to FALSE */ + packet_info->ms_per_frame = 0; + packet_info->ptime_ts = 0; + if (payload == NULL || payload_length_bytes <= 0) { + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: payload null."); + } + return FALSE; + } + + /* In CELT_ONLY mode, packets should not have FEC. */ + if (payload[0] & 0x80) { + /* opus_packet_parse: CELT_ONLY mode, we do not support this mode. */ + return FALSE; + } else { + int mode = (payload[0] >> 3); + if (mode <= 3) { + samplerate = 8000; + } else if (mode <= 7) { + samplerate = 12000; + } else if (mode <= 11) { + samplerate = 16000; + } else if (mode <= 13) { + samplerate = 24000; + } else if (mode <= 15) { + samplerate = 48000; + } else { + /* opus_packet_parse: CELT_ONLY mode, we do not support this mode. */ + return FALSE; + } + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: mode[%d]s[%d]c[%d] [%d]Hz\n", mode, (payload[0]>>2)&0x1 ,(payload[0])&0x3, samplerate); + } + } + if (payload[0] & 0x04) { + packet_info->stereo = TRUE; + packet_info->channels = 2; + } + packet_info->config = payload[0] >> 3; + sample_per_frame = opus_packet_get_samples_per_frame(payload, samplerate); + packet_info->ms_per_frame = sample_per_frame * 1000 / samplerate; + if (packet_info->ms_per_frame < 10 || packet_info->ms_per_frame > 120) { + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: invalid packet."); + } + return FALSE; + } + + packet_info->frames = opus_packet_parse(payload, payload_length_bytes, NULL, frame_data, frame_sizes, NULL); + if (packet_info->frames < 0) { + packet_info->frames = 0; + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: opus_packet_parse found no frame.\n"); + } + return FALSE; + } + packet_info->ptime_ts = packet_info->frames * sample_per_frame; + + if (frame_sizes[0] <= 1) { + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: opus_packet_parse frame size too small.\n"); + } + return FALSE; + } + + /* +---------------+-----------+-----------+-------------------+ */ + /* | Configuration | Mode | Bandwidth | Frame Sizes | */ + /* | Number(s) | | | | */ + /* +---------------+-----------+-----------+-------------------+ */ + /* | 0...3 | SILK-only | NB | 10, 20, 40, 60 ms | */ + /* | 4...7 | SILK-only | MB | 10, 20, 40, 60 ms | */ + /* | 8...11 | SILK-only | WB | 10, 20, 40, 60 ms | */ + /* | 12...13 | Hybrid | SWB | 10, 20 ms | */ + /* | 14...15 | Hybrid | FB | 10, 20 ms | */ + /* | 16...19 | CELT-only | NB | 2.5, 5, 10, 20 ms | */ + /* | 20...23 | CELT-only | WB | 2.5, 5, 10, 20 ms | */ + /* | 24...27 | CELT-only | SWB | 2.5, 5, 10, 20 ms | */ + /* | 28...31 | CELT-only | FB | 2.5, 5, 10, 20 ms | */ + /* +---------------+-----------+-----------+-------------------+ */ + + if (!packet_info->stereo) { + /* the routines opus_get_nb_flags_in_silk_frame and opus_get_silk_frame_ms_per_flag are also valid for stereo frames */ + /* yet the routine opus_get_VAD_LBRR_flags is currently only for mono frame*/ + silk_frame_nb_flags = switch_opus_get_nb_flags_in_silk_frame(packet_info->config); /* =1 for 10 or 20 ms frame; = 2 for 40 ms; = 3 for 60 ms */ + if (!silk_frame_nb_flags) { + /* We should not go there as CELT_ONLY is already tested above */ + return FALSE; + } + + packet_info->frames_silk = silk_frame_nb_flags; + silk_size_frame_ms_per_flag = switch_opus_get_silk_frame_ms_per_flag(packet_info->config, silk_frame_nb_flags); /* 10 or 20 ms frame*/ + if (!silk_size_frame_ms_per_flag) { + /* we should not go there as CELT_ONLY is already tested above */ + return FALSE; + } + + ptr_LBBR_FLAGS = packet_LBBR_FLAGS; + ptr_VAD_FLAGS = packet_VAD_FLAGS; + + for (f = 0; f < packet_info->frames; f++) { + switch_opus_get_VAD_LBRR_flags(frame_data[f], silk_frame_nb_flags, ptr_VAD_FLAGS, ptr_LBBR_FLAGS, + &silk_frame_nb_vad1, &silk_frame_nb_fec); + packet_info->vad += silk_frame_nb_vad1; + packet_info->fec += silk_frame_nb_fec; + packet_info->vad_ms += silk_frame_nb_vad1 * silk_size_frame_ms_per_flag; + packet_info->fec_ms += silk_frame_nb_fec * silk_size_frame_ms_per_flag; + + ptr_VAD_FLAGS += silk_frame_nb_flags; + ptr_LBBR_FLAGS += silk_frame_nb_flags; + } + /* store the VAD & LBRR flags of all 20 ms silk-frames of the packet; LSB the first frame, MSB: the last */ + vad_flags_per_silk_frame = 0; + fec_flags_per_silk_frame = 0; + silk_frame_packet = packet_info->frames * packet_info->frames_silk; + if (silk_frame_packet > 15) { + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: more than %d 20-ms frames in the packet ; only first 15 silk-frames data will be stored (pb silkFastAccelerate)\n", silk_frame_packet); + } + silk_frame_packet = 15; + } + ptr_LBBR_FLAGS = packet_LBBR_FLAGS; + ptr_VAD_FLAGS = packet_VAD_FLAGS; + shift_silk = 0; + for (i=0; i < silk_frame_packet; i++) { + vad_flags_per_silk_frame += (*ptr_VAD_FLAGS) << shift_silk; + fec_flags_per_silk_frame += (*ptr_LBBR_FLAGS) << shift_silk; + shift_silk++; + ptr_LBBR_FLAGS++; ptr_VAD_FLAGS++; + } + packet_info->vad_flags_per_silk_frame = vad_flags_per_silk_frame; + packet_info->fec_flags_per_silk_frame = fec_flags_per_silk_frame; + return TRUE; + } + + if (packet_info->config != 1 && packet_info->config != 5 && packet_info->config != 9) { + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: the current parser implementation does not support muliple SILK frames for VAD or FEC detection.\n"); + } + return FALSE; + } + /* + * Parse the VAD and LBRR flags in each Opus frame + * */ + for (f = 0; f < packet_info->frames; f++) { + if (frame_data[f][0] & 0x80) { + packet_info->vad++; + } + if (frame_data[f][0] & 0x40) { + packet_info->fec++; + } + if (debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: LP layer opus_frame[%d] VAD[%d] FEC[%d]\n", f+1, (frame_data[f][0]&0x80)>>7, (frame_data[f][0]&0x40)>>6); + } + } + packet_info->vad_ms = packet_info->vad * packet_info->ms_per_frame; + packet_info->fec_ms = packet_info->fec * packet_info->ms_per_frame; + return TRUE; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: + */ diff --git a/src/mod/codecs/mod_opus/opus_parse.h b/src/mod/codecs/mod_opus/opus_parse.h new file mode 100644 index 0000000000..8dd61500cd --- /dev/null +++ b/src/mod/codecs/mod_opus/opus_parse.h @@ -0,0 +1,66 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2023, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Julien Chavanton + * + */ + +#ifndef SWITCH_OPUS_PARSE_H +#define SWITCH_OPUS_PARSE_H + +typedef enum { false, true } bool_t; + +typedef struct opus_packet_info { + int16_t vad; + int16_t vad_ms; + int16_t fec; + int16_t fec_ms; + bool_t stereo; + int16_t frames; /* number of opus frames in the packet */ + int16_t config; + int16_t channels; + int16_t ms_per_frame; + int32_t ptime_ts; + bool_t valid; + int16_t frames_silk; /* number of silk_frames in an opus frame */ + /* VAD flag of all 20 ms silk-frames of the packet; LSB the first frame, MSB: the last */ + int16_t vad_flags_per_silk_frame; + /* LBRR (FEC) flag of all 20 ms silk-frames of the packet; LSB the first frame, MSB: the last */ + int16_t fec_flags_per_silk_frame; +} opus_packet_info_t; + +bool_t switch_opus_packet_parse(const uint8_t *payload, int payload_length_bytes, opus_packet_info_t *packet_info, bool_t debug); +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: + */ diff --git a/src/switch_jitterbuffer.c b/src/switch_jitterbuffer.c index d68b269024..d8d9df3a33 100644 --- a/src/switch_jitterbuffer.c +++ b/src/switch_jitterbuffer.c @@ -44,6 +44,8 @@ struct switch_jb_s; +static inline int check_jb_size(switch_jb_t *jb); + typedef struct switch_jb_node_s { struct switch_jb_s *parent; switch_rtp_packet_t packet; @@ -56,6 +58,29 @@ typedef struct switch_jb_node_s { switch_bool_t complete_frame_mark; } switch_jb_node_t; +typedef struct switch_jb_stats_s { + uint32_t reset_too_big; + uint32_t reset_missing_frames; + uint32_t reset_ts_jump; + uint32_t reset_error; + uint32_t reset; + uint32_t size_max; + uint32_t size_est; + uint32_t acceleration; + uint32_t expand; + uint32_t jitter_max_ms; + int estimate_ms; + int buffer_size_ms; +} switch_jb_stats_t; + +typedef struct switch_jb_jitter_s { + double *estimate; + uint32_t samples_per_second; + uint32_t samples_per_frame; + uint32_t drop_gap; + switch_jb_stats_t stats; +} switch_jb_jitter_t; + struct switch_jb_s { struct switch_jb_node_s *node_list; uint32_t last_target_seq; @@ -104,6 +129,7 @@ struct switch_jb_s { switch_jb_flag_t flags; switch_jb_type_t type; switch_core_session_t *session; + switch_jb_jitter_t jitter; switch_channel_t *channel; uint32_t buffer_lag; uint32_t flush; @@ -112,6 +138,8 @@ struct switch_jb_s { uint32_t period_len; uint32_t nack_saved_the_day; uint32_t nack_didnt_save_the_day; + switch_bool_t elastic; + switch_codec_t *codec; }; @@ -233,6 +261,7 @@ static inline switch_jb_node_t *new_node(switch_jb_t *jb) if (jb->allocated_nodes > jb->max_frame_len * mult) { jb_debug(jb, 2, "ALLOCATED FRAMES TOO HIGH! %d\n", jb->allocated_nodes); + jb->jitter.stats.reset_too_big++; switch_jb_reset(jb); switch_mutex_unlock(jb->list_mutex); return NULL; @@ -332,6 +361,29 @@ static inline void hide_nodes(switch_jb_t *jb) switch_mutex_unlock(jb->list_mutex); } +static inline switch_bool_t packet_vad(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t len) { + void* payload; + uint16_t payload_len = len; + + if (packet->ebody) { + payload = packet->ebody; + } else { + payload = packet->body; + } + if (payload && payload_len > 0) { + switch_bool_t ret; + switch_bool_t *ret_p = &ret; + switch_codec_control_type_t ret_t; + switch_core_media_codec_control(jb->session, SWITCH_MEDIA_TYPE_AUDIO, + SWITCH_IO_WRITE, SCC_AUDIO_VAD, + SCCT_STRING, (void *)payload, + SCCT_INT, (void *)&payload_len, + &ret_t, (void *)&ret_p); + return ret; + } + return SWITCH_TRUE; +} + static inline void drop_ts(switch_jb_t *jb, uint32_t ts) { switch_jb_node_t *np; @@ -667,6 +719,7 @@ static inline void add_node(switch_jb_t *jb, switch_rtp_packet_t *packet, switch if (((seq_diff >= 100) || (ts_diff > (900000 * 5)))) { jb_debug(jb, 2, "CHANGE DETECTED, PUNT %u\n", abs(((int)ntohs(packet->header.seq) - ntohs(jb->highest_wrote_seq)))); + jb->jitter.stats.reset_ts_jump++; switch_jb_reset(jb); } } @@ -732,6 +785,12 @@ static inline void increment_seq(switch_jb_t *jb) jb->target_seq = htons((ntohs(jb->target_seq) + 1)); } +static inline void decrement_seq(switch_jb_t *jb) +{ + jb->last_target_seq = jb->target_seq; + jb->target_seq = htons((ntohs(jb->target_seq) - 1)); +} + static inline void set_read_seq(switch_jb_t *jb, uint16_t seq) { jb->last_target_seq = seq; @@ -854,12 +913,128 @@ static inline switch_status_t jb_next_packet_by_ts(switch_jb_t *jb, switch_jb_no } +static inline int check_jb_size(switch_jb_t *jb) +{ + switch_jb_node_t *np; + uint16_t seq; + uint16_t l_seq=0; + uint16_t h_seq=0; + uint16_t count=0; + uint16_t old=0; + switch_mutex_lock(jb->list_mutex); + + for (np = jb->node_list; np; np = np->next) { + if (!np->visible) { + continue; + } + + seq = ntohs(np->packet.header.seq); + if (ntohs(jb->target_seq) > seq) { + hide_node(np, SWITCH_FALSE); + old++; + continue; + } + if (count == 0) { + l_seq = h_seq = seq; + } + count++; + if (seq < l_seq) + l_seq = seq; + if (seq > h_seq) + h_seq = seq; + } + if (count > jb->jitter.stats.size_max) { + jb->jitter.stats.size_max = count; + } + if (jb->jitter.stats.size_est == 0) { + jb->jitter.stats.size_est = count; + } else { + jb->jitter.stats.size_est = ((99*jb->jitter.stats.size_est)+(1*count))/100; + } + if (ntohs(jb->target_seq) % 50 == 0) { /* update the stats every x packets */ + int packet_ms = jb->jitter.samples_per_frame / (jb->jitter.samples_per_second / 1000); + jb->jitter.stats.estimate_ms = (*jb->jitter.estimate) / jb->jitter.samples_per_second * 1000; + switch_channel_set_variable_printf(jb->channel, "rtp_jb_size_max_ms", "%u", jb->jitter.stats.size_max*packet_ms); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_size_est_ms", "%u", jb->jitter.stats.size_est*packet_ms); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_acceleration_ms", "%u", jb->jitter.stats.acceleration*packet_ms); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_expand_ms", "%u", jb->jitter.stats.expand*packet_ms); + if (jb->jitter.stats.jitter_max_ms < jb->jitter.stats.estimate_ms) { + jb->jitter.stats.jitter_max_ms = jb->jitter.stats.estimate_ms; + } + switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_max_ms", "%u", jb->jitter.stats.jitter_max_ms); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_est_ms", "%u", jb->jitter.stats.estimate_ms); + } + if (old) { + sort_free_nodes(jb); + } + switch_mutex_unlock(jb->list_mutex); + jb_debug(jb, SWITCH_LOG_INFO, "JITTER buffersize %u == %u old[%u] target[%u] seq[%u|%u]\n", count, h_seq-l_seq+1, old, ntohs(jb->target_seq), l_seq, h_seq); + return count; +} + +static inline switch_status_t jb_next_packet_by_seq_with_acceleration(switch_jb_t *jb, switch_jb_node_t **nodep) +{ + switch_status_t status = jb_next_packet_by_seq(jb, nodep); + switch_rtp_packet_t *packet; + uint32_t len; + uint16_t seq = ntohs(jb->target_seq); + + /* When using a Codec that provides voice activity detection ex. Opus, use it to + select packet to drop/accelerate. */ + + if (jb->elastic && jb->jitter.estimate && (jb->visible_nodes*jb->jitter.samples_per_frame)>0 && jb->jitter.samples_per_second) { + int visible_not_old = check_jb_size(jb); + jb->jitter.stats.estimate_ms = (int)((*jb->jitter.estimate)/((jb->jitter.samples_per_second))*1000); + jb->jitter.stats.buffer_size_ms = (int)((visible_not_old*jb->jitter.samples_per_frame)/(jb->jitter.samples_per_second/1000)); + + // We try to accelerate in order to remove delay when the jitter buffer is 3x larger than the estimation. + if (jb->jitter.stats.buffer_size_ms > (3*jb->jitter.stats.estimate_ms) && jb->jitter.stats.buffer_size_ms > 60) { + if (status == SWITCH_STATUS_SUCCESS) { + packet = &(*nodep)->packet; + seq = ntohs((*nodep)->packet.header.seq); + len = (*nodep)->len; + } + if (jb->jitter.drop_gap > 0) { + jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms seq:%u [drop-gap][%d]\n", + jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq, jb->jitter.drop_gap); + jb->jitter.drop_gap--; + } else { + if (status != SWITCH_STATUS_SUCCESS || packet_vad(jb, packet, len) == SWITCH_FALSE) { + jb->jitter.drop_gap = 3; + if (status != SWITCH_STATUS_SUCCESS) { + jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation n/a buffersize %d/%d %dms seq:%u [drop-missing/no-plc]\n", + jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq); + } else { + jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms seq:%u ACCELERATE [drop]\n", + jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq); + } + jb->jitter.stats.acceleration++; + return jb_next_packet_by_seq(jb, nodep); + } else { + jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms seq:%u [drop-skip-vad]\n", + jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq); + } + } + } else { + jb_debug(jb, 2, "JITTER estimation %dms buffersize %d/%d %dms\n", + jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms); + } + } + return status; +} + static inline switch_status_t jb_next_packet(switch_jb_t *jb, switch_jb_node_t **nodep) { if (jb->samples_per_frame) { return jb_next_packet_by_ts(jb, nodep); } else { - return jb_next_packet_by_seq(jb, nodep); + switch_status_t status; + if (jb->elastic && jb->jitter.estimate) { + status = jb_next_packet_by_seq_with_acceleration(jb, nodep); + } else { + status = jb_next_packet_by_seq(jb, nodep); + } + return status; } } @@ -877,13 +1052,50 @@ SWITCH_DECLARE(void) switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_fra switch_core_inthash_init(&jb->node_hash_ts); } +SWITCH_DECLARE(void) switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jitter, uint32_t samples_per_frame, uint32_t samples_per_second) +{ + if (jb && jitter) { + memset(&jb->jitter,0,sizeof(switch_jb_jitter_t)); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_max_ms", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_size_ms", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_acceleration_ms", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_expand_ms", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_max_ms", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_ms", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_count", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_too_big", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_missing_frames", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_ts_jump", "%u", 0); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_error", "%u", 0); + jb->jitter.estimate = jitter; + jb->jitter.samples_per_frame = samples_per_frame; + jb->jitter.samples_per_second = samples_per_second; + jb->jitter.drop_gap = 5; + } +} + SWITCH_DECLARE(void) switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session) { const char *var; if (session) { + jb->codec = switch_core_session_get_read_codec(session); jb->session = session; jb->channel = switch_core_session_get_channel(session); + if (!strcmp(jb->codec->implementation->iananame, "opus")) { + if (switch_true(switch_channel_get_variable(jb->channel, "rtp_jitter_buffer_accelerate"))) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec is %s, accelerate on\n", jb->codec->implementation->iananame); + jb->elastic = SWITCH_TRUE; + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec is %s, accelerate off\n", jb->codec->implementation->iananame); + jb->elastic = SWITCH_FALSE; + } + + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec not opus: %s\n", jb->codec->implementation->iananame); + jb->elastic = SWITCH_FALSE; + } + if (jb->type == SJB_VIDEO && !switch_test_flag(jb, SJB_QUEUE_ONLY) && (var = switch_channel_get_variable_dup(jb->channel, "jb_video_low_bitrate", SWITCH_FALSE, -1))) { int tmp = atoi(var); @@ -932,6 +1144,12 @@ SWITCH_DECLARE(void) switch_jb_debug_level(switch_jb_t *jb, uint8_t level) SWITCH_DECLARE(void) switch_jb_reset(switch_jb_t *jb) { + jb->jitter.stats.reset++; + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_count", "%u", jb->jitter.stats.reset); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_too_big", "%u", jb->jitter.stats.reset_too_big); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_missing_frames", "%u", jb->jitter.stats.reset_missing_frames); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_ts_jump", "%u", jb->jitter.stats.reset_ts_jump); + switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_error", "%u", jb->jitter.stats.reset_error); if (jb->type == SJB_VIDEO) { switch_mutex_lock(jb->mutex); @@ -1257,6 +1475,7 @@ SWITCH_DECLARE(switch_status_t) switch_jb_put_packet(switch_jb_t *jb, switch_rtp if (got > want) { if (got - want > jb->max_frame_len && got - want > 17) { jb_debug(jb, 2, "Missing %u frames, Resetting\n", got - want); + jb->jitter.stats.reset_missing_frames++; switch_jb_reset(jb); } else { @@ -1434,6 +1653,7 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp switch(status) { case SWITCH_STATUS_RESTART: jb_debug(jb, 2, "%s", "Error encountered\n"); + jb->jitter.stats.reset_error++; switch_jb_reset(jb); switch_goto_status(SWITCH_STATUS_RESTART, end); case SWITCH_STATUS_NOTFOUND: @@ -1444,7 +1664,22 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp jb_debug(jb, 2, "%s", "Too many frames not found, RESIZE\n"); switch_goto_status(SWITCH_STATUS_RESTART, end); } else { - jb_debug(jb, 2, "%s", "Frame not found suggest PLC\n"); + if (jb->elastic) { + int visible_not_old = check_jb_size(jb); + jb->jitter.stats.estimate_ms = (int)((*jb->jitter.estimate)/((jb->jitter.samples_per_second))*1000); + jb->jitter.stats.buffer_size_ms = (int)((visible_not_old*jb->jitter.samples_per_frame)/(jb->jitter.samples_per_second/1000)); + /* When playing PLC, we take the oportunity to expand the buffer if the jitter buffer is smaller than the 3x the estimated jitter. */ + if (jb->jitter.stats.buffer_size_ms < (3*jb->jitter.stats.estimate_ms)) { + jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms EXPAND [plc]\n", + jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms); + jb->jitter.stats.expand++; + decrement_seq(jb); + } else { + jb_debug(jb, 2, "%s", "Frame not found suggest PLC\n"); + } + } else { + jb_debug(jb, 2, "%s", "Frame not found suggest PLC\n"); + } plc = 1; switch_goto_status(SWITCH_STATUS_NOTFOUND, end); } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 614d79bf78..05b0858313 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -4676,6 +4676,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t * READ_INC(rtp_session); status = switch_jb_create(&rtp_session->jb, SJB_AUDIO, queue_frames, max_queue_frames, rtp_session->pool); switch_jb_set_session(rtp_session->jb, rtp_session->session); + switch_jb_set_jitter_estimator(rtp_session->jb, &rtp_session->stats.rtcp.inter_jitter, samples_per_packet, samples_per_second); if (switch_true(switch_channel_get_variable_dup(switch_core_session_get_channel(rtp_session->session), "jb_use_timestamps", SWITCH_FALSE, -1))) { switch_jb_ts_mode(rtp_session->jb, samples_per_packet, samples_per_second); } From 25afda9be002a2edd7311d2d10531ce88431b5c3 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 23 Jun 2023 21:25:16 +0300 Subject: [PATCH 049/123] [mod_opus] Fix Windows build regression made by previous commit --- src/mod/codecs/mod_opus/mod_opus.2017.vcxproj | 4 ++++ src/mod/codecs/mod_opus/opus_parse.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj b/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj index 3b73a6c42f..18478701c8 100644 --- a/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj +++ b/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj @@ -130,6 +130,10 @@ + + + + diff --git a/src/mod/codecs/mod_opus/opus_parse.c b/src/mod/codecs/mod_opus/opus_parse.c index 41e1ec6490..b94f491ca0 100644 --- a/src/mod/codecs/mod_opus/opus_parse.c +++ b/src/mod/codecs/mod_opus/opus_parse.c @@ -29,7 +29,7 @@ */ #include "switch.h" -#include +#include "opus.h" #include "opus_parse.h" /* Tables for LBRR_sympbol decoding */ From b355bf21e6685a7f88b67d682a8ec761ba4ee4fc Mon Sep 17 00:00:00 2001 From: David Villasmil Date: Wed, 28 Jun 2023 18:39:22 +0200 Subject: [PATCH 050/123] [mod_conference] Add flag to destroy the conference only when all mandatory members disconnect. And set endconf to end the conference when any member with the flag disconnects (#2079) * feature/mod_conference_mandatory_member_flag: Add flag to destroy the conference only when all mandatory members disconnect. And set endconf to end the conference when any member with the flag disconnects --- src/mod/applications/mod_conference/conference_cdr.c | 3 +++ .../applications/mod_conference/conference_member.c | 12 +++++++++++- .../applications/mod_conference/conference_utils.c | 2 ++ src/mod/applications/mod_conference/mod_conference.c | 4 ++++ src/mod/applications/mod_conference/mod_conference.h | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_conference/conference_cdr.c b/src/mod/applications/mod_conference/conference_cdr.c index b6eb630540..f7ed7ddf27 100644 --- a/src/mod/applications/mod_conference/conference_cdr.c +++ b/src/mod/applications/mod_conference/conference_cdr.c @@ -662,6 +662,9 @@ void conference_cdr_render(conference_obj_t *conference) x_tag = switch_xml_add_child_d(x_flags, "end_conference", flag_off++); switch_xml_set_txt_d(x_tag, conference_cdr_test_mflag(np, MFLAG_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "mandatory_member_end_conference", flag_off++); + switch_xml_set_txt_d(x_tag, conference_cdr_test_mflag(np, MFLAG_MANDATORY_MEMBER_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "was_kicked", flag_off++); switch_xml_set_txt_d(x_tag, conference_cdr_test_mflag(np, MFLAG_KICKED) ? "true" : "false"); diff --git a/src/mod/applications/mod_conference/conference_member.c b/src/mod/applications/mod_conference/conference_member.c index 6112a2890c..c258e59783 100644 --- a/src/mod/applications/mod_conference/conference_member.c +++ b/src/mod/applications/mod_conference/conference_member.c @@ -766,7 +766,12 @@ switch_status_t conference_member_add(conference_obj_t *conference, conference_m conference->count++; } + if (conference_utils_member_test_flag(member, MFLAG_ENDCONF)) { + conference->endconference_time = 0; + } + + if (conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF)) { if (conference->end_count++) { conference->endconference_time = 0; } @@ -1314,9 +1319,14 @@ switch_status_t conference_member_del(conference_obj_t *conference, conference_m conference_video_check_flush(member, SWITCH_FALSE); + /* End conference when any member with "endconf" flag disconnects */ if (conference_utils_member_test_flag(member, MFLAG_ENDCONF)) { + conference_utils_set_flag_locked(conference, CFLAG_DESTRUCT); + } + + /* End conference only if all mandatory members have disconnected */ + if (conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF)) { if (!--conference->end_count) { - //conference_utils_set_flag_locked(conference, CFLAG_DESTRUCT); conference->endconference_time = switch_epoch_time_now(NULL); } } diff --git a/src/mod/applications/mod_conference/conference_utils.c b/src/mod/applications/mod_conference/conference_utils.c index c8dd0fd4e9..a441594ddc 100644 --- a/src/mod/applications/mod_conference/conference_utils.c +++ b/src/mod/applications/mod_conference/conference_utils.c @@ -132,6 +132,8 @@ void conference_utils_set_mflags(const char *flags, member_flag_t *f) f[MFLAG_NOMOH] = 1; } else if (!strcasecmp(argv[i], "endconf")) { f[MFLAG_ENDCONF] = 1; + } else if (!strcasecmp(argv[i], "mandatory_member_endconf")) { + f[MFLAG_MANDATORY_MEMBER_ENDCONF] = 1; } else if (!strcasecmp(argv[i], "mintwo")) { f[MFLAG_MINTWO] = 1; } else if (!strcasecmp(argv[i], "talk-data-events")) { diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 619cd8c4a6..bf03d2a5bc 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1347,6 +1347,9 @@ void conference_xlist(conference_obj_t *conference, switch_xml_t x_conference, i x_tag = switch_xml_add_child_d(x_flags, "end_conference", count++); switch_xml_set_txt_d(x_tag, conference_utils_member_test_flag(member, MFLAG_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "mandatory_member_end_conference", count++); + switch_xml_set_txt_d(x_tag, conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "is_ghost", count++); switch_xml_set_txt_d(x_tag, conference_utils_member_test_flag(member, MFLAG_GHOST) ? "true" : "false"); @@ -1456,6 +1459,7 @@ void conference_jlist(conference_obj_t *conference, cJSON *json_conferences) ADDBOOL(json_conference_member_flags, "has_floor", member->id == member->conference->floor_holder); ADDBOOL(json_conference_member_flags, "is_moderator", conference_utils_member_test_flag(member, MFLAG_MOD)); ADDBOOL(json_conference_member_flags, "end_conference", conference_utils_member_test_flag(member, MFLAG_ENDCONF)); + ADDBOOL(json_conference_member_flags, "mandatory_member_end_conference", conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF)); ADDBOOL(json_conference_member_flags, "pass_digits", conference_utils_member_test_flag(member, MFLAG_DIST_DTMF)); } switch_mutex_unlock(conference->member_mutex); diff --git a/src/mod/applications/mod_conference/mod_conference.h b/src/mod/applications/mod_conference/mod_conference.h index 3c28634264..21baaadc82 100644 --- a/src/mod/applications/mod_conference/mod_conference.h +++ b/src/mod/applications/mod_conference/mod_conference.h @@ -178,6 +178,7 @@ typedef enum { MFLAG_NO_MINIMIZE_ENCODING, MFLAG_FLUSH_BUFFER, MFLAG_ENDCONF, + MFLAG_MANDATORY_MEMBER_ENDCONF, MFLAG_HAS_AUDIO, MFLAG_TALKING, MFLAG_RESTART, From a160eced994d528ac0b461af0a9cb128690465a4 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Tue, 4 Jul 2023 09:51:37 +0100 Subject: [PATCH 051/123] [core,libyuv,modules] Fix function declarations without a prototype --- libs/libyuv/include/libyuv/planar_functions.h | 2 +- libs/libyuv/source/planar_functions.cc | 2 +- src/fs_encode.c | 2 +- src/fs_tts.c | 2 +- src/mod/applications/mod_av/avcodec.c | 2 +- src/mod/applications/mod_av/avformat.c | 2 +- .../applications/mod_conference/conference_loop.c | 2 +- .../applications/mod_conference/mod_conference.h | 2 +- src/mod/applications/mod_db/mod_db.c | 2 +- .../applications/mod_signalwire/mod_signalwire.c | 4 ++-- src/mod/endpoints/mod_skinny/mod_skinny.c | 2 +- src/mod/endpoints/mod_skinny/mod_skinny.h | 2 +- src/mod/endpoints/mod_skinny/skinny_api.c | 2 +- src/mod/endpoints/mod_skinny/skinny_api.h | 2 +- src/mod/endpoints/mod_sofia/mod_sofia.c | 4 ++-- .../endpoints/mod_sofia/test/sipp-based-tests.c | 6 +++--- src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c | 4 ++-- src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c | 2 +- src/switch.c | 2 +- src/switch_core.c | 4 ++-- src/switch_log.c | 2 +- src/switch_msrp.c | 14 +++++++------- src/switch_rtp.c | 10 +++++----- src/switch_speex.c | 2 +- src/switch_vpx.c | 2 +- 25 files changed, 41 insertions(+), 41 deletions(-) diff --git a/libs/libyuv/include/libyuv/planar_functions.h b/libs/libyuv/include/libyuv/planar_functions.h index 5299fe2c0e..50fe5f681d 100644 --- a/libs/libyuv/include/libyuv/planar_functions.h +++ b/libs/libyuv/include/libyuv/planar_functions.h @@ -582,7 +582,7 @@ typedef void (*ARGBBlendRow)(const uint8_t* src_argb0, // Get function to Alpha Blend ARGB pixels and store to destination. LIBYUV_API -ARGBBlendRow GetARGBBlend(); +ARGBBlendRow GetARGBBlend(void); // Alpha Blend ARGB images and store to destination. // Source is pre-multiplied by alpha using ARGBAttenuate. diff --git a/libs/libyuv/source/planar_functions.cc b/libs/libyuv/source/planar_functions.cc index 5a9d56d88a..c07f0943d3 100644 --- a/libs/libyuv/source/planar_functions.cc +++ b/libs/libyuv/source/planar_functions.cc @@ -1185,7 +1185,7 @@ int ARGBMirror(const uint8_t* src_argb, // As there are 6 blenders to choose from, the caller should try to use // the same blend function for all pixels if possible. LIBYUV_API -ARGBBlendRow GetARGBBlend() { +ARGBBlendRow GetARGBBlend(void) { void (*ARGBBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) = ARGBBlendRow_C; #if defined(HAS_ARGBBLENDROW_SSSE3) diff --git a/src/fs_encode.c b/src/fs_encode.c index 235a5d9f11..527dc3eeff 100644 --- a/src/fs_encode.c +++ b/src/fs_encode.c @@ -46,7 +46,7 @@ #pragma warning (disable:167) #endif -static void fs_encode_cleanup() +static void fs_encode_cleanup(void) { switch_safe_free(SWITCH_GLOBAL_dirs.conf_dir); switch_safe_free(SWITCH_GLOBAL_dirs.mod_dir); diff --git a/src/fs_tts.c b/src/fs_tts.c index 2a963ee68e..6632e86566 100644 --- a/src/fs_tts.c +++ b/src/fs_tts.c @@ -46,7 +46,7 @@ #pragma warning (disable:167) #endif -static void fs_tts_cleanup() +static void fs_tts_cleanup(void) { switch_safe_free(SWITCH_GLOBAL_dirs.conf_dir); switch_safe_free(SWITCH_GLOBAL_dirs.mod_dir); diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index a9f6d0927e..b4eaeadd2e 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -2208,7 +2208,7 @@ static void parse_codecs(avcodec_profile_t *aprofile, switch_xml_t codecs) } -static void load_config() +static void load_config(void) { switch_xml_t cfg = NULL, xml = NULL; diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 1f767d0bde..d52e141b6b 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -2861,7 +2861,7 @@ static char *supported_formats[SWITCH_MAX_CODECS] = { 0 }; static const char modname[] = "mod_av"; -static switch_status_t load_config() +static switch_status_t load_config(void) { char *cf = "avformat.conf"; switch_xml_t cfg, xml, param, settings; diff --git a/src/mod/applications/mod_conference/conference_loop.c b/src/mod/applications/mod_conference/conference_loop.c index f6c2856892..8f112f5453 100644 --- a/src/mod/applications/mod_conference/conference_loop.c +++ b/src/mod/applications/mod_conference/conference_loop.c @@ -75,7 +75,7 @@ struct _mapping control_mappings[] = { {"deaf off", conference_loop_deaf_off} }; -int conference_loop_mapping_len() +int conference_loop_mapping_len(void) { return (sizeof(control_mappings)/sizeof(control_mappings[0])); } diff --git a/src/mod/applications/mod_conference/mod_conference.h b/src/mod/applications/mod_conference/mod_conference.h index 21baaadc82..e45a921c21 100644 --- a/src/mod/applications/mod_conference/mod_conference.h +++ b/src/mod/applications/mod_conference/mod_conference.h @@ -1124,7 +1124,7 @@ void conference_video_canvas_del_fnode_layer(conference_obj_t *conference, confe void conference_video_canvas_set_fnode_layer(mcu_canvas_t *canvas, conference_file_node_t *fnode, int idx); void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim); const char *conference_utils_combine_flag_var(switch_core_session_t *session, const char *var_name); -int conference_loop_mapping_len(); +int conference_loop_mapping_len(void); void conference_api_set_agc(conference_member_t *member, const char *data); switch_status_t conference_outcall(conference_obj_t *conference, diff --git a/src/mod/applications/mod_db/mod_db.c b/src/mod/applications/mod_db/mod_db.c index 0e3e227de7..5f14792f2c 100644 --- a/src/mod/applications/mod_db/mod_db.c +++ b/src/mod/applications/mod_db/mod_db.c @@ -280,7 +280,7 @@ static switch_xml_config_item_t config_settings[] = { SWITCH_CONFIG_ITEM_END() }; -static switch_status_t do_config() +static switch_status_t do_config(void) { switch_cache_db_handle_t *dbh = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; diff --git a/src/mod/applications/mod_signalwire/mod_signalwire.c b/src/mod/applications/mod_signalwire/mod_signalwire.c index 9846e7e1d2..108f99b2c5 100644 --- a/src/mod/applications/mod_signalwire/mod_signalwire.c +++ b/src/mod/applications/mod_signalwire/mod_signalwire.c @@ -704,7 +704,7 @@ done: return status; } -static switch_status_t load_config() +static switch_status_t load_config(void) { char *cf = "signalwire.conf"; switch_xml_t cfg, xml; @@ -1390,7 +1390,7 @@ static void mod_signalwire_state_register(void) } } -static void mod_signalwire_state_ready() +static void mod_signalwire_state_ready(void) { if (globals.profile_update) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Signalwire SIP profile update initiated\n"); diff --git a/src/mod/endpoints/mod_skinny/mod_skinny.c b/src/mod/endpoints/mod_skinny/mod_skinny.c index c6cfc716c7..64464e4ef6 100644 --- a/src/mod/endpoints/mod_skinny/mod_skinny.c +++ b/src/mod/endpoints/mod_skinny/mod_skinny.c @@ -2136,7 +2136,7 @@ void launch_skinny_profile_thread(skinny_profile_t *profile) { /*****************************************************************************/ /* MODULE FUNCTIONS */ /*****************************************************************************/ -switch_endpoint_interface_t *skinny_get_endpoint_interface() +switch_endpoint_interface_t *skinny_get_endpoint_interface(void) { return skinny_endpoint_interface; } diff --git a/src/mod/endpoints/mod_skinny/mod_skinny.h b/src/mod/endpoints/mod_skinny/mod_skinny.h index 69096ab64e..aff2ee92c0 100644 --- a/src/mod/endpoints/mod_skinny/mod_skinny.h +++ b/src/mod/endpoints/mod_skinny/mod_skinny.h @@ -355,7 +355,7 @@ switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); /*****************************************************************************/ /* MODULE FUNCTIONS */ /*****************************************************************************/ -switch_endpoint_interface_t *skinny_get_endpoint_interface(); +switch_endpoint_interface_t *skinny_get_endpoint_interface(void); /*****************************************************************************/ /* TEXT FUNCTIONS */ diff --git a/src/mod/endpoints/mod_skinny/skinny_api.c b/src/mod/endpoints/mod_skinny/skinny_api.c index f79f36c014..4657a5a9d3 100644 --- a/src/mod/endpoints/mod_skinny/skinny_api.c +++ b/src/mod/endpoints/mod_skinny/skinny_api.c @@ -697,7 +697,7 @@ switch_status_t skinny_api_register(switch_loadable_module_interface_t **module_ return SWITCH_STATUS_SUCCESS; } -switch_status_t skinny_api_unregister() +switch_status_t skinny_api_unregister(void) { switch_console_set_complete("del skinny"); diff --git a/src/mod/endpoints/mod_skinny/skinny_api.h b/src/mod/endpoints/mod_skinny/skinny_api.h index e246957f0d..833d0c15da 100644 --- a/src/mod/endpoints/mod_skinny/skinny_api.h +++ b/src/mod/endpoints/mod_skinny/skinny_api.h @@ -34,7 +34,7 @@ #define _SKINNY_API_H switch_status_t skinny_api_register(switch_loadable_module_interface_t **module_interface); -switch_status_t skinny_api_unregister(); +switch_status_t skinny_api_unregister(void); #endif /* _SKINNY_API_H */ diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 2fdf0063a9..9255c02664 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -54,7 +54,7 @@ switch_endpoint_interface_t *sofia_endpoint_interface; #define STRLEN 15 -void mod_sofia_shutdown_cleanup(); +void mod_sofia_shutdown_cleanup(void); static switch_status_t sofia_on_init(switch_core_session_t *session); static switch_status_t sofia_on_exchange_media(switch_core_session_t *session); @@ -6833,7 +6833,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) return status; } -void mod_sofia_shutdown_cleanup() { +void mod_sofia_shutdown_cleanup(void) { int sanity = 0; int i; switch_status_t st; diff --git a/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c b/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c index 60a7b61a3a..7b2d7964c9 100644 --- a/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c +++ b/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c @@ -90,7 +90,7 @@ static const char *test_wait_for_chan_var(switch_channel_t *channel, const char return var; } -static switch_bool_t has_ipv6() +static switch_bool_t has_ipv6(void) { switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); @@ -110,7 +110,7 @@ static switch_bool_t has_ipv6() return SWITCH_TRUE; } -static void register_gw() +static void register_gw(void) { switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); @@ -118,7 +118,7 @@ static void register_gw() switch_safe_free(stream.data); } -static void unregister_gw() +static void unregister_gw(void) { switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); diff --git a/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c b/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c index 20259251de..3ec8b060df 100644 --- a/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c +++ b/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c @@ -272,7 +272,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) } -static void do_rotate_all() +static void do_rotate_all(void) { switch_hash_index_t *hi; void *val; @@ -294,7 +294,7 @@ static void do_rotate_all() } -static void do_teardown() +static void do_teardown(void) { switch_hash_index_t *hi; void *val; diff --git a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c index 4e3bd81f78..da038ff37f 100644 --- a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c +++ b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c @@ -88,7 +88,7 @@ static size_t httpCallBack(char *buffer, size_t size, size_t nitems, void *outst return size * nitems; } -static switch_status_t set_xml_cdr_log_dirs() +static switch_status_t set_xml_cdr_log_dirs(void) { switch_time_exp_t tm; char *path = NULL; diff --git a/src/switch.c b/src/switch.c index 19a3d93fad..5011ff2d46 100644 --- a/src/switch.c +++ b/src/switch.c @@ -101,7 +101,7 @@ static void handle_SIGTERM(int sig) } /* kill a freeswitch process running in background mode */ -static int freeswitch_kill_background() +static int freeswitch_kill_background(void) { FILE *f; /* FILE handle to open the pid file */ char path[PATH_MAX] = ""; /* full path of the PID file */ diff --git a/src/switch_core.c b/src/switch_core.c index 4e2b70778a..7ec10d8885 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -3566,7 +3566,7 @@ SWITCH_DECLARE(int) switch_stream_system(const char *cmd, switch_stream_handle_t } } -SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_start_port() +SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_start_port(void) { uint16_t start_port = 0; @@ -3577,7 +3577,7 @@ SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_start_port() return start_port; } -SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_end_port() +SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_end_port(void) { uint16_t end_port = 0; diff --git a/src/switch_log.c b/src/switch_log.c index 74a5713635..563a554510 100644 --- a/src/switch_log.c +++ b/src/switch_log.c @@ -246,7 +246,7 @@ SWITCH_DECLARE(cJSON *) switch_log_node_to_json(const switch_log_node_t *node, i return json; } -static switch_log_node_t *switch_log_node_alloc() +static switch_log_node_t *switch_log_node_alloc(void) { switch_log_node_t *node = NULL; #ifdef SWITCH_LOG_RECYCLE diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 1f5db7ac20..9fd84d846b 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -99,7 +99,7 @@ static switch_bool_t msrp_check_success_report(switch_msrp_msg_t *msrp_msg) return (msrp_h_success_report && !strcmp(msrp_h_success_report, "yes")); } -static void msrp_deinit_ssl() +static void msrp_deinit_ssl(void) { globals.ssl_ready = 0; if (globals.ssl_ctx) { @@ -112,7 +112,7 @@ static void msrp_deinit_ssl() } } -static void msrp_init_ssl() +static void msrp_init_ssl(void) { const char *err = ""; @@ -187,7 +187,7 @@ static void msrp_init_ssl() SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip); -static switch_status_t load_config() +static switch_status_t load_config(void) { char *cf = "msrp.conf"; switch_xml_t cfg, xml = NULL, settings, param; @@ -286,12 +286,12 @@ sock_fail: return rv; } -SWITCH_DECLARE(const char *) switch_msrp_listen_ip() +SWITCH_DECLARE(const char *) switch_msrp_listen_ip(void) { return globals.ip; } -SWITCH_DECLARE(switch_status_t) switch_msrp_init() +SWITCH_DECLARE(switch_status_t) switch_msrp_init(void) { switch_memory_pool_t *pool; switch_thread_t *thread; @@ -346,7 +346,7 @@ SWITCH_DECLARE(switch_status_t) switch_msrp_init() return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status_t) switch_msrp_destroy() +SWITCH_DECLARE(switch_status_t) switch_msrp_destroy(void) { switch_status_t st = SWITCH_STATUS_SUCCESS; switch_socket_t *sock; @@ -1622,7 +1622,7 @@ SWITCH_DECLARE (switch_status_t) switch_msrp_perform_send(switch_msrp_session_t return status; } -SWITCH_DECLARE(switch_msrp_msg_t *) switch_msrp_msg_create() +SWITCH_DECLARE(switch_msrp_msg_t *) switch_msrp_msg_create(void) { switch_msrp_msg_t *msg = malloc(sizeof(switch_msrp_msg_t)); switch_assert(msg); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 05b0858313..ce6f3062df 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -262,8 +262,8 @@ typedef struct { struct switch_rtp; -static void switch_rtp_dtls_init(); -static void switch_rtp_dtls_destroy(); +static void switch_rtp_dtls_init(void); +static void switch_rtp_dtls_destroy(void); #define MAX_DTLS_MTU 4096 @@ -1660,7 +1660,7 @@ static void rtcp_generate_sender_info(switch_rtp_t *rtp_session, struct switch_r ); } -static inline uint32_t calc_local_lsr_now() +static inline uint32_t calc_local_lsr_now(void) { switch_time_t now; uint32_t ntp_sec, ntp_usec, lsr_now, sec; @@ -3493,7 +3493,7 @@ static BIO_METHOD dtls_bio_filter_methods = { static BIO_METHOD *dtls_bio_filter_methods = NULL; #endif -static void switch_rtp_dtls_init() { +static void switch_rtp_dtls_init(void) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L dtls_bio_filter_methods = BIO_meth_new(BIO_TYPE_FILTER | BIO_get_new_index(), "DTLS filter"); BIO_meth_set_write(dtls_bio_filter_methods, dtls_bio_filter_write); @@ -3503,7 +3503,7 @@ static void switch_rtp_dtls_init() { #endif } -static void switch_rtp_dtls_destroy() { +static void switch_rtp_dtls_destroy(void) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L if (dtls_bio_filter_methods) { BIO_meth_free(dtls_bio_filter_methods); diff --git a/src/switch_speex.c b/src/switch_speex.c index 122ae79a73..5a97b082f2 100644 --- a/src/switch_speex.c +++ b/src/switch_speex.c @@ -470,7 +470,7 @@ static switch_status_t switch_speex_destroy(switch_codec_t *codec) /** * read default settings from speex.conf */ -static void load_configuration() +static void load_configuration(void) { switch_xml_t xml = NULL, cfg = NULL; diff --git a/src/switch_vpx.c b/src/switch_vpx.c index e35d87712f..751f2b8c5b 100644 --- a/src/switch_vpx.c +++ b/src/switch_vpx.c @@ -1853,7 +1853,7 @@ static void parse_codecs(my_vpx_cfg_t *my_cfg, switch_xml_t codecs) } } -static void load_config() +static void load_config(void) { switch_xml_t cfg = NULL, xml = NULL; my_vpx_cfg_t *my_cfg = NULL; From 5656972bfe2539158c14b9a44aacfb1da86a29ea Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Tue, 4 Jul 2023 10:12:44 +0100 Subject: [PATCH 052/123] [core,miniupnpc,modules] Fix not used variables --- libs/miniupnpc/miniupnpc.c | 2 -- .../applications/mod_conference/conference_api.c | 4 +--- .../applications/mod_conference/conference_cdr.c | 2 +- src/mod/applications/mod_dptools/mod_dptools.c | 2 -- src/mod/endpoints/mod_sofia/mod_sofia.c | 5 ----- src/mod/endpoints/mod_sofia/sofia_presence.c | 2 -- src/mod/endpoints/mod_verto/mod_verto.c | 7 +------ .../mod_event_socket/mod_event_socket.c | 16 +++++++--------- src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c | 4 ++-- src/switch_core_media.c | 16 +++------------- src/switch_event.c | 2 -- src/switch_ivr_play_say.c | 5 ----- src/switch_loadable_module.c | 3 +-- src/switch_rtp.c | 3 --- src/switch_time.c | 5 ++--- src/switch_utils.c | 3 --- 16 files changed, 18 insertions(+), 63 deletions(-) diff --git a/libs/miniupnpc/miniupnpc.c b/libs/miniupnpc/miniupnpc.c index 88faea1c37..a72ef892b6 100644 --- a/libs/miniupnpc/miniupnpc.c +++ b/libs/miniupnpc/miniupnpc.c @@ -679,7 +679,6 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, char * descXML; int descXMLsize = 0; struct UPNPDev * dev; - int ndev = 0; int state; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */ if(!devlist) { @@ -698,7 +697,6 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, lanaddr, lanaddrlen); if(descXML) { - ndev++; memset(data, 0, sizeof(struct IGDdatas)); memset(urls, 0, sizeof(struct UPNPUrls)); parserootdesc(descXML, descXMLsize, data); diff --git a/src/mod/applications/mod_conference/conference_api.c b/src/mod/applications/mod_conference/conference_api.c index 8bcfc5862f..7e566367fb 100644 --- a/src/mod/applications/mod_conference/conference_api.c +++ b/src/mod/applications/mod_conference/conference_api.c @@ -4087,7 +4087,6 @@ switch_status_t conference_api_sub_set(conference_obj_t *conference, switch_status_t conference_api_sub_xml_list(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv) { - int count = 0; switch_hash_index_t *hi; void *val; switch_xml_t x_conference, x_conferences; @@ -4106,7 +4105,6 @@ switch_status_t conference_api_sub_xml_list(conference_obj_t *conference, switch x_conference = switch_xml_add_child_d(x_conferences, "conference", off++); switch_assert(conference); - count++; conference_xlist(conference, x_conference, off); } @@ -4114,7 +4112,7 @@ switch_status_t conference_api_sub_xml_list(conference_obj_t *conference, switch } else { x_conference = switch_xml_add_child_d(x_conferences, "conference", off++); switch_assert(conference); - count++; + conference_xlist(conference, x_conference, off); } diff --git a/src/mod/applications/mod_conference/conference_cdr.c b/src/mod/applications/mod_conference/conference_cdr.c index f7ed7ddf27..9f2ccba63c 100644 --- a/src/mod/applications/mod_conference/conference_cdr.c +++ b/src/mod/applications/mod_conference/conference_cdr.c @@ -740,7 +740,7 @@ void conference_cdr_render(conference_obj_t *conference) #endif int wrote; wrote = write(fd, xml_text, (unsigned) strlen(xml_text)); - wrote++; + (void)wrote; close(fd); } else { char ebuf[512] = { 0 }; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index e91ec53d47..f52b1184e5 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -161,7 +161,6 @@ static switch_status_t digit_action_callback(switch_ivr_dmachine_match_t *match) char *string = NULL; switch_channel_t *channel; switch_core_session_t *use_session = act->session; - int x = 0; char *flags = ""; if (act->target == DIGIT_TARGET_PEER || act->target == DIGIT_TARGET_BOTH) { @@ -171,7 +170,6 @@ static switch_status_t digit_action_callback(switch_ivr_dmachine_match_t *match) } top: - x++; string = switch_core_session_strdup(use_session, act->string); exec = 0; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 2fdf0063a9..9cd447ef71 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3255,8 +3255,6 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl switch_hash_index_t *hi; void *val; const void *vvar; - int c = 0; - int ac = 0; const char *header = ""; if (argc > 0) { @@ -3466,7 +3464,6 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl if (sofia_test_pflag(profile, PFLAG_RUNNING)) { if (strcmp(vvar, profile->name)) { - ac++; stream->write_function(stream, "\n%s\n%s\n%s\n%s\n\n", vvar, "alias", profile->name, "ALIASED"); } else { @@ -3492,8 +3489,6 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl profile->inuse); } - c++; - for (gp = profile->gateways; gp; gp = gp->next) { switch_assert(gp->state < REG_STATE_LAST); stream->write_function(stream, "\n%s\n%s\n%s\n%s\n\n", diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index b8576ae7f5..579cea83e2 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1621,7 +1621,6 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Started\n"); while (mod_sofia_globals.running == 1) { - int count = 0; if (switch_queue_pop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) { switch_event_t *event = (switch_event_t *) pop; @@ -1656,7 +1655,6 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread } switch_event_destroy(&event); - count++; } } diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 8920de7e02..6d49fc022b 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -823,7 +823,6 @@ static void set_perm(const char *str, switch_event_t **event, switch_bool_t add) { char delim = ','; char *cur, *next; - int count = 0; char *edup; if (!zstr(str)) { @@ -844,7 +843,7 @@ static void set_perm(const char *str, switch_event_t **event, switch_bool_t add) delim = ' '; } - for (cur = edup; cur; count++) { + for (cur = edup; cur;) { if ((next = strchr(cur, delim))) { *next++ = '\0'; } @@ -5579,8 +5578,6 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl { verto_profile_t *profile = NULL; jsock_t *jsock; - int cp = 0; - int cc = 0; const char *header = ""; int i; @@ -5594,14 +5591,12 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl stream->write_function(stream, "\n%s\n%s\n%s\n%s\n\n", profile->name, "profile", tmpurl, (profile->running) ? "RUNNING" : "DOWN"); switch_safe_free(tmpurl); } - cp++; switch_mutex_lock(profile->mutex); for(jsock = profile->jsock_head; jsock; jsock = jsock->next) { char *tmpname = switch_mprintf("%s@%s", jsock->id, jsock->domain); stream->write_function(stream, "\n%s\n%s\n%s\n%s\n%s (%s)\n\n", profile->name, tmpname, "client", jsock->name, (!zstr(jsock->uid)) ? "CONN_REG" : "CONN_NO_REG", (jsock->ptype & PTYPE_CLIENT_SSL) ? "WSS": "WS"); - cc++; switch_safe_free(tmpname); } switch_mutex_unlock(profile->mutex); diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 70331a95e2..520bd92ac7 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -866,7 +866,7 @@ SWITCH_STANDARD_API(event_sink_function) char *loglevel = switch_event_get_header(stream->param_event, "loglevel"); switch_memory_pool_t *pool; char *next, *cur; - uint32_t count = 0, key_count = 0; + uint32_t key_count = 0; uint8_t custom = 0; char *edup; @@ -925,7 +925,7 @@ SWITCH_STANDARD_API(event_sink_function) delim = ' '; } - for (cur = edup; cur; count++) { + for (cur = edup; cur;) { switch_event_types_t type; if ((next = strchr(cur, delim))) { @@ -1846,7 +1846,7 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even if (allowed_events) { char delim = ','; char *cur, *next; - int count = 0, custom = 0, key_count = 0; + int custom = 0; switch_set_flag(listener, LFLAG_AUTH_EVENTS); @@ -1862,7 +1862,7 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even delim = ' '; } - for (cur = edup; cur; count++) { + for (cur = edup; cur;) { switch_event_types_t type; if ((next = strchr(cur, delim))) { @@ -1872,7 +1872,6 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even if (custom) { switch_core_hash_insert(listener->allowed_event_hash, cur, MARKER); } else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) { - key_count++; if (type == SWITCH_EVENT_ALL) { uint32_t x = 0; switch_set_flag(listener, LFLAG_ALL_EVENTS_AUTHED); @@ -1904,7 +1903,6 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even if (allowed_api) { char delim = ','; char *cur, *next; - int count = 0; switch_snprintf(api_reply, sizeof(api_reply), "Allowed-API: %s\n", allowed_api); @@ -1916,7 +1914,7 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even delim = ' '; } - for (cur = edup; cur; count++) { + for (cur = edup; cur;) { if ((next = strchr(cur, delim))) { *next++ = '\0'; } @@ -2540,14 +2538,14 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even } else if (!strncasecmp(cmd, "nixevent", 8)) { char *next, *cur; - uint32_t count = 0, key_count = 0; + uint32_t key_count = 0; uint8_t custom = 0; strip_cr(cmd); cur = cmd + 8; if ((cur = strchr(cur, ' '))) { - for (cur++; cur; count++) { + for (cur++; cur;) { switch_event_types_t type; if ((next = strchr(cur, ' '))) { diff --git a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c index 4e3bd81f78..f8c98f6392 100644 --- a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c +++ b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c @@ -254,7 +254,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) #endif int wrote; wrote = write(fd, xml_text, (unsigned) strlen(xml_text)); - wrote++; + (void)wrote; close(fd); } else { char ebuf[512] = { 0 }; @@ -427,7 +427,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) #endif int wrote; wrote = write(fd, xml_text, (unsigned) strlen(xml_text)); - wrote++; + (void)wrote; close(fd); } else { char ebuf[512] = { 0 }; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 60cc3d531c..e75387581d 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -4762,7 +4762,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_channel_t *channel = switch_core_session_get_channel(session); const char *val; const char *crypto = NULL; - int got_crypto = 0, got_video_crypto = 0, got_audio = 0, saw_audio = 0, saw_video = 0, got_avp = 0, got_video_avp = 0, got_video_savp = 0, got_savp = 0, got_udptl = 0, got_webrtc = 0, got_text = 0, got_text_crypto = 0, got_msrp = 0; + int got_crypto = 0, got_video_crypto = 0, got_audio = 0, saw_audio = 0, saw_video = 0, got_avp = 0, got_savp = 0, got_udptl = 0, got_webrtc = 0, got_text = 0, got_text_crypto = 0, got_msrp = 0; int scrooge = 0; sdp_parser_t *parser = NULL; sdp_session_t *sdp; @@ -4958,14 +4958,10 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s if (m->m_proto == sdp_proto_srtp || m->m_proto == sdp_proto_extended_srtp) { if (m->m_type == sdp_media_audio) { got_savp++; - } else { - got_video_savp++; } } else if (m->m_proto == sdp_proto_rtp) { if (m->m_type == sdp_media_audio) { got_avp++; - } else { - got_video_avp++; } } else if (m->m_proto == sdp_proto_udptl) { got_udptl++; @@ -7406,7 +7402,7 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi switch_status_t status; switch_frame_t *read_frame = NULL; switch_media_handle_t *smh; - uint32_t loops = 0, xloops = 0, vloops = 0; + uint32_t loops = 0, xloops = 0; switch_image_t *blank_img = NULL; switch_frame_t fr = { 0 }; unsigned char *buf = NULL; @@ -7531,8 +7527,6 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi continue; } - vloops++; - send_blank = blank_enabled || switch_channel_test_flag(channel, CF_VIDEO_ECHO); if (switch_channel_test_flag(channel, CF_VIDEO_READY) && !switch_test_flag(read_frame, SFF_CNG)) { @@ -14243,7 +14237,7 @@ SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp_str, const c switch_size_t len; const char *i; char *o; - int in_m = 0, m_tally = 0, slash = 0; + int in_m = 0, slash = 0; int number = 0, skip = 0; int remove = !strcasecmp(cmd, "remove"); int only = !strcasecmp(cmd, "only"); @@ -14277,7 +14271,6 @@ SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp_str, const c if (*i == 'm' && *(i+1) == '=') { in_m = 1; - m_tally++; } if (in_m) { @@ -14981,7 +14974,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core { switch_status_t status = SWITCH_STATUS_FALSE; switch_io_event_hook_video_read_frame_t *ptr; - uint32_t loops = 0; switch_media_handle_t *smh; int is_keyframe = 0; @@ -14993,8 +14985,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core top: - loops++; - if (switch_channel_down_nosig(session->channel)) { return SWITCH_STATUS_FALSE; } diff --git a/src/switch_event.c b/src/switch_event.c index be49f2fc14..272255d31c 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -651,7 +651,6 @@ SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max) { switch_threadattr_t *thd_attr; uint32_t index = 0; - int launched = 0; uint32_t sanity = 200; switch_memory_pool_t *pool = RUNTIME_POOL; @@ -682,7 +681,6 @@ SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max) } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Create additional event dispatch thread %d\n", index); } - launched++; } SOFT_MAX_DISPATCH = index; diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 25486eee7f..33f3a4e51a 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -1271,7 +1271,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess int sleep_val_i = 250; int eof = 0; switch_size_t bread = 0; - int l16 = 0; switch_codec_implementation_t read_impl = { 0 }; char *file_dup; char *argv[128] = { 0 }; @@ -1334,10 +1333,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess arg_recursion_check_start(args); - if (!zstr(read_impl.iananame) && !strcasecmp(read_impl.iananame, "l16")) { - l16++; - } - if (play_delimiter) { file_dup = switch_core_session_strdup(session, file); argc = switch_separate_string(file_dup, play_delimiter, argv, (sizeof(argv) / sizeof(argv[0]))); diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index f782e89f6e..bacd2f012a 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -115,12 +115,11 @@ static void *SWITCH_THREAD_FUNC switch_loadable_module_exec(switch_thread_t *thr switch_status_t status = SWITCH_STATUS_SUCCESS; switch_core_thread_session_t *ts = obj; switch_loadable_module_t *module = ts->objs[0]; - int restarts; switch_assert(thread != NULL); switch_assert(module != NULL); - for (restarts = 0; status != SWITCH_STATUS_TERM && !module->shutting_down; restarts++) { + while (status != SWITCH_STATUS_TERM && !module->shutting_down) { status = module->switch_module_runtime(); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Thread ended for %s\n", module->module_interface->module_name); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 05b0858313..40c913e2b9 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -5494,7 +5494,6 @@ static switch_size_t do_flush(switch_rtp_t *rtp_session, int force, switch_size_ { int was_blocking = 0; switch_size_t bytes; - uint32_t flushed = 0; switch_size_t bytes_out = 0; if (!switch_rtp_ready(rtp_session)) { @@ -5576,8 +5575,6 @@ static switch_size_t do_flush(switch_rtp_t *rtp_session, int force, switch_size_ #endif } - flushed++; - rtp_session->stats.inbound.raw_bytes += bytes; rtp_session->stats.inbound.flush_packet_count++; rtp_session->stats.inbound.packet_count++; diff --git a/src/switch_time.c b/src/switch_time.c index 445e698f9b..a56c5e96f1 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -1173,9 +1173,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime) } else { if (tfd > -1 && globals.RUNNING == 1) { uint64_t exp; - int r; - r = read(tfd, &exp, sizeof(exp)); - r++; + read(tfd, &exp, sizeof(exp)); + (void)exp; } else { switch_time_t timediff = runtime.reference - ts; diff --git a/src/switch_utils.c b/src/switch_utils.c index d8b830943a..332137ebda 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -139,13 +139,10 @@ struct switch_frame_buffer_s { static switch_frame_t *find_free_frame(switch_frame_buffer_t *fb, switch_frame_t *orig) { switch_frame_node_t *np; - int x = 0; switch_mutex_lock(fb->mutex); for (np = fb->head; np; np = np->next) { - x++; - if (!np->inuse && ((orig->packet && np->frame->packet) || (!orig->packet && !np->frame->packet))) { if (np == fb->head) { From 2afad15f480065a3f5f44401b2de4d45f7d327b0 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Tue, 4 Jul 2023 10:37:48 +0100 Subject: [PATCH 053/123] [mod_sofia] Remove non-implemented verbose feature --- src/mod/endpoints/mod_sofia/sip-dig.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sip-dig.c b/src/mod/endpoints/mod_sofia/sip-dig.c index c9a6f5b463..10a0a26763 100644 --- a/src/mod/endpoints/mod_sofia/sip-dig.c +++ b/src/mod/endpoints/mod_sofia/sip-dig.c @@ -82,9 +82,6 @@ *
-6
*
Query IP6 addresses (AAAA records). *
- *
-v
- *
Be verbatim. - *
*
*
*
@@ -201,7 +198,7 @@ switch_bool_t verify_ip(sres_record_t **answers, const char *ip, switch_bool_t i switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream) { - int o_sctp = 1, o_tls_sctp = 1, o_verbatim = 1; + int o_sctp = 1, o_tls_sctp = 1; int family = 0, multiple = 0; char const *string; url_t *uri = NULL; @@ -247,9 +244,7 @@ switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_cor } while (argv[i] && argv[i][0] == '-') { - if (strcmp(argv[i], "-v") == 0) { - o_verbatim++; - } else if (strcmp(argv[i], "-6") == 0) { + if (strcmp(argv[i], "-6") == 0) { dig->ip6 = ++family; } else if (strcmp(argv[i], "-4") == 0) { dig->ip4 = ++family; From eec311d8d7509f1b748beca6d2c41446bdebe497 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 28 Jun 2023 23:12:00 +0300 Subject: [PATCH 054/123] [Build-System] Update commit hash of SpanDSP on Windows. --- w32/download_spandsp.props | 2 +- w32/spandsp-version.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/w32/download_spandsp.props b/w32/download_spandsp.props index 39b7f2b81b..f02c66a9bd 100644 --- a/w32/download_spandsp.props +++ b/w32/download_spandsp.props @@ -29,7 +29,7 @@ - master + 0d2e6ac65e0e8f53d652665a743015a88bf048d4 true From 921eebdbeac0972d08870c652eab2848aec98dcd Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Tue, 4 Jul 2023 10:42:38 +0100 Subject: [PATCH 055/123] [xmlrpc-c] Fix MacOS build --- libs/xmlrpc-c/include/xmlrpc-c/string_int.h | 5 +++++ libs/xmlrpc-c/lib/abyss/src/server.c | 3 +++ libs/xmlrpc-c/lib/abyss/src/thread_fork.c | 4 ++++ libs/xmlrpc-c/lib/libutil/asprintf.c | 3 +++ 4 files changed, 15 insertions(+) diff --git a/libs/xmlrpc-c/include/xmlrpc-c/string_int.h b/libs/xmlrpc-c/include/xmlrpc-c/string_int.h index 04ac8c782b..a0cc58605f 100644 --- a/libs/xmlrpc-c/include/xmlrpc-c/string_int.h +++ b/libs/xmlrpc-c/include/xmlrpc-c/string_int.h @@ -3,7 +3,12 @@ #include + +#ifdef __APPLE__ +#include +#else #include +#endif #include "xmlrpc_config.h" #include "c_util.h" diff --git a/libs/xmlrpc-c/lib/abyss/src/server.c b/libs/xmlrpc-c/lib/abyss/src/server.c index 6337dcfd78..ca05011b83 100644 --- a/libs/xmlrpc-c/lib/abyss/src/server.c +++ b/libs/xmlrpc-c/lib/abyss/src/server.c @@ -1,6 +1,9 @@ /* Copyright information is at end of file */ #define _XOPEN_SOURCE 600 /* Make sure strdup() is in */ +#ifdef __APPLE__ +#define _DARWIN_C_SOURCE +#endif #define _BSD_SOURCE /* Make sure setgroups()is in */ #ifndef _DEFAULT_SOURCE #define _DEFAULT_SOURCE diff --git a/libs/xmlrpc-c/lib/abyss/src/thread_fork.c b/libs/xmlrpc-c/lib/abyss/src/thread_fork.c index d96bf59eb1..7ea382918a 100644 --- a/libs/xmlrpc-c/lib/abyss/src/thread_fork.c +++ b/libs/xmlrpc-c/lib/abyss/src/thread_fork.c @@ -3,7 +3,11 @@ #include #include #include +#ifdef __APPLE__ +#include +#else #include +#endif #include #include "xmlrpc_config.h" diff --git a/libs/xmlrpc-c/lib/libutil/asprintf.c b/libs/xmlrpc-c/lib/libutil/asprintf.c index b52523065a..f078518bb5 100644 --- a/libs/xmlrpc-c/lib/libutil/asprintf.c +++ b/libs/xmlrpc-c/lib/libutil/asprintf.c @@ -1,4 +1,7 @@ #define _XOPEN_SOURCE 600 /* Make sure strdup() is in */ +#ifdef __APPLE__ +#define _DARWIN_C_SOURCE +#endif #ifndef _GNU_SOURCE #define _GNU_SOURCE /* But only when HAVE_ASPRINTF */ #endif From c9fb586c34780da6115cd341277d4082ac0c7a1e Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Sat, 8 Jul 2023 06:29:23 -0500 Subject: [PATCH 056/123] [mod_verto] Fix function declarations without a prototype --- src/mod/endpoints/mod_verto/mod_verto.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 6d49fc022b..9423d03c28 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -5606,7 +5606,7 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl return SWITCH_STATUS_SUCCESS; } -static cJSON *json_status() +static cJSON *json_status(void) { cJSON *obj, *profiles, *jprofile, *users, *user; verto_profile_t *profile = NULL; @@ -6735,14 +6735,14 @@ static void mod_verto_ks_logger(const char *file, const char *func, int line, in va_end(ap); } -static void verto_event_free_subclass() +static void verto_event_free_subclass(void) { switch_event_free_subclass(MY_EVENT_LOGIN); switch_event_free_subclass(MY_EVENT_CLIENT_DISCONNECT); switch_event_free_subclass(MY_EVENT_CLIENT_CONNECT); } -static void verto_destroy_globals_hash_tables() +static void verto_destroy_globals_hash_tables(void) { if (verto_globals.method_hash) { switch_core_hash_destroy(&verto_globals.method_hash); From 930341ba86d252f9b1c96333ab546b267119cbb3 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Mon, 10 Jul 2023 10:31:09 +0000 Subject: [PATCH 057/123] [core,mod_av,unit-tests] Make transition to core packetizer --- src/mod/applications/mod_av/avcodec.c | 138 +++++++++---------------- src/mod/applications/mod_av/avformat.c | 10 ++ src/switch_packetizer.c | 6 +- tests/unit/switch_packetizer.c | 4 + 4 files changed, 65 insertions(+), 93 deletions(-) diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index b4eaeadd2e..94cc9b36bf 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -399,6 +399,7 @@ typedef struct h264_codec_context_s { enum AVCodecID av_codec_id; uint16_t last_seq; // last received frame->seq int hw_encoder; + switch_packetizer_t *packetizer; } h264_codec_context_t; #ifndef AV_INPUT_BUFFER_PADDING_SIZE @@ -1088,64 +1089,6 @@ static switch_status_t consume_h263p_bitstream(h264_codec_context_t *context, sw return SWITCH_STATUS_MORE_DATA; } -static switch_status_t consume_h264_bitstream(h264_codec_context_t *context, switch_frame_t *frame) -{ - AVPacket *pkt = &context->encoder_avpacket; - our_h264_nalu_t *nalu = &context->nalus[context->nalu_current_index]; - uint8_t nalu_hdr = *(uint8_t *)(nalu->start); - uint8_t nalu_type = nalu_hdr & 0x1f; - uint8_t nri = nalu_hdr & 0x60; - int left = nalu->len - (nalu->eat - nalu->start); - uint8_t *p = frame->data; - uint8_t start = nalu->start == nalu->eat ? 0x80 : 0; - int n = nalu->len / SLICE_SIZE; - int slice_size = nalu->len / (n + 1) + 1 + 2; - - if (nalu->len <= SLICE_SIZE) { - memcpy(frame->data, nalu->start, nalu->len); - frame->datalen = nalu->len; - context->nalu_current_index++; - - if (context->nalus[context->nalu_current_index].len) { - frame->m = 0; - return SWITCH_STATUS_MORE_DATA; - } - - if (pkt->size > 0) av_packet_unref(pkt); - - switch_clear_flag(frame, SFF_CNG); - frame->m = 1; - - return SWITCH_STATUS_SUCCESS; - } - - if (left <= (slice_size - 2)) { - p[0] = nri | 28; // FU-A - p[1] = 0x40 | nalu_type; - memcpy(p+2, nalu->eat, left); - nalu->eat += left; - frame->datalen = left + 2; - context->nalu_current_index++; - - if (!context->nalus[context->nalu_current_index].len) { - if (pkt->size > 0) av_packet_unref(pkt); - frame->m = 1; - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MORE_DATA; - } - - p[0] = nri | 28; // FU-A - p[1] = start | nalu_type; - if (start) nalu->eat++; - memcpy(p+2, nalu->eat, slice_size - 2); - nalu->eat += (slice_size - 2); - frame->datalen = slice_size; - frame->m = 0; - return SWITCH_STATUS_MORE_DATA; -} - static switch_status_t consume_nalu(h264_codec_context_t *context, switch_frame_t *frame) { AVPacket *pkt = &context->encoder_avpacket; @@ -1154,8 +1097,12 @@ static switch_status_t consume_nalu(h264_codec_context_t *context, switch_frame_ if (!nalu->len) { frame->datalen = 0; frame->m = 0; - if (pkt->size > 0) av_packet_unref(pkt); + if (pkt->size > 0) { + av_packet_unref(pkt); + } + context->nalu_current_index = 0; + return SWITCH_STATUS_NOTFOUND; } @@ -1167,7 +1114,9 @@ static switch_status_t consume_nalu(h264_codec_context_t *context, switch_frame_ return consume_h263p_bitstream(context, frame); } - return consume_h264_bitstream(context, frame); + switch_assert(0); + + return SWITCH_STATUS_FALSE; } static void set_h264_private_data(h264_codec_context_t *context, avcodec_profile_t *profile) @@ -1436,6 +1385,14 @@ static switch_status_t switch_h264_init(switch_codec_t *codec, switch_codec_flag } } + switch (context->av_codec_id) { + case AV_CODEC_ID_H264: + context->packetizer = switch_packetizer_create(SPT_H264_BITSTREAM, SLICE_SIZE); + break; + default: + break; + } + switch_buffer_create_dynamic(&(context->nalu_buffer), H264_NALU_BUFFER_SIZE, H264_NALU_BUFFER_SIZE * 8, 0); codec->private_info = context; @@ -1480,6 +1437,16 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t } if (frame->flags & SFF_SAME_IMAGE) { + if (context->packetizer) { + switch_status_t status = switch_packetizer_read(context->packetizer, frame); + + if (status == SWITCH_STATUS_SUCCESS && pkt->size > 0) { + av_packet_unref(pkt); + } + + return status; + } + // read from nalu buffer return consume_nalu(context, frame); } @@ -1511,7 +1478,9 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t switch_set_flag(frame, SFF_WAIT_KEY_FRAME); } +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(pkt); +GCC_DIAG_ON(deprecated-declarations) pkt->data = NULL; // packet data will be allocated by the encoder pkt->size = 0; @@ -1596,8 +1565,7 @@ GCC_DIAG_ON(deprecated-declarations) // process: if (*got_output) { - const uint8_t *p = pkt->data; - int i = 0; + switch_status_t status = SWITCH_STATUS_SUCCESS; *got_output = 0; @@ -1626,38 +1594,22 @@ GCC_DIAG_ON(deprecated-declarations) "Encoded frame %" SWITCH_INT64_T_FMT " (size=%5d) nalu_type=0x%x %d\n", context->pts, pkt->size, *((uint8_t *)pkt->data +4), *got_output); } - /* split into nalus */ - memset(context->nalus, 0, sizeof(context->nalus)); - while ((p = fs_avc_find_startcode(p, pkt->data+pkt->size)) < (pkt->data + pkt->size)) { - if (!context->nalus[i].start) { - while (!(*p++)) ; /* eat the sync bytes, what ever 0 0 1 or 0 0 0 1 */ - context->nalus[i].start = p; - context->nalus[i].eat = p; + status = switch_packetizer_feed(context->packetizer, pkt->data, pkt->size); + if (status != SWITCH_STATUS_SUCCESS) { + if (pkt->size > 0) { + av_packet_unref(pkt); + } - if ((*p & 0x1f) == 7) { // Got Keyframe - // prevent to generate key frame too frequently - context->last_keyframe_request = switch_time_now(); - if (mod_av_globals.debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "KEY FRAME GENERATED\n"); - } - } - } else { - context->nalus[i].len = p - context->nalus[i].start; - while (!(*p++)) ; /* eat the sync bytes, what ever 0 0 1 or 0 0 0 1 */ - i++; - context->nalus[i].start = p; - context->nalus[i].eat = p; - } - if (i >= MAX_NALUS - 2) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TOO MANY SLICES!\n"); - break; - } + return status; } - context->nalus[i].len = p - context->nalus[i].start; - context->nalu_current_index = 0; - return consume_nalu(context, frame); + status = switch_packetizer_read(context->packetizer, frame); + if (status == SWITCH_STATUS_SUCCESS && pkt->size > 0) { + av_packet_unref(pkt); + } + + return status; } error: @@ -1708,7 +1660,9 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t int decoded_len; if (size > 0) { +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(&pkt); +GCC_DIAG_ON(deprecated-declarations) switch_buffer_zero_fill(context->nalu_buffer, AV_INPUT_BUFFER_PADDING_SIZE); switch_buffer_peek_zerocopy(context->nalu_buffer, (const void **)&pkt.data); pkt.size = size; @@ -1825,6 +1779,10 @@ static switch_status_t switch_h264_destroy(switch_codec_t *codec) av_free(context->encoder_ctx); } + if (context->packetizer) { + switch_packetizer_close(&context->packetizer); + } + if (context->encoder_avframe) { av_frame_free(&context->encoder_avframe); } diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index d52e141b6b..d17f4eac39 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -877,7 +877,9 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void * context->eh.in_callback = 1; +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(&pkt); +GCC_DIAG_ON(deprecated-declarations) if (context->eh.video_st->frame) { ret = av_frame_make_writable(context->eh.video_st->frame); @@ -971,7 +973,9 @@ GCC_DIAG_ON(deprecated-declarations) int got_packet = 0; int ret = 0; +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(&pkt); +GCC_DIAG_ON(deprecated-declarations) GCC_DIAG_OFF(deprecated-declarations) ret = avcodec_encode_video2(context->eh.video_st->st->codec, &pkt, NULL, &got_packet); @@ -1427,7 +1431,9 @@ GCC_DIAG_ON(deprecated-declarations) +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(&pkt); +GCC_DIAG_ON(deprecated-declarations) pkt.data = NULL; pkt.size = 0; @@ -1464,7 +1470,9 @@ GCC_DIAG_ON(deprecated-declarations) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "size = %u %x %x %x %x %x %x\n", pkt.size, *p, *(p+1), *(p+2), *(p+3), *(p+4), *(p+5)); } +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(new_pkt); +GCC_DIAG_ON(deprecated-declarations) av_packet_ref(new_pkt, &pkt); status = switch_queue_push(context->video_pkt_queue, new_pkt); // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "size = %4u flag=%x pts=%" SWITCH_INT64_T_FMT " dts=%" SWITCH_INT64_T_FMT "\n", pkt.size, pkt.flags, pkt.pts, pkt.dts); @@ -2102,8 +2110,10 @@ GCC_DIAG_ON(deprecated-declarations) int j = 0, ret = -1, audio_stream_count = 1; AVFrame *use_frame = NULL; +GCC_DIAG_OFF(deprecated-declarations) av_init_packet(&pkt[0]); av_init_packet(&pkt[1]); +GCC_DIAG_ON(deprecated-declarations) if (context->audio_st[1].active) { switch_size_t len = 0; diff --git a/src/switch_packetizer.c b/src/switch_packetizer.c index 626e85ba8e..c9cdcbf3e7 100644 --- a/src/switch_packetizer.c +++ b/src/switch_packetizer.c @@ -265,7 +265,7 @@ SWITCH_DECLARE(switch_status_t) switch_packetizer_feed(switch_packetizer_t *pack context->nalus[i].eat = p; } else { context->nalus[i].len = p - context->nalus[i].start; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "#%d %x len=%u\n", i, *context->nalus[i].start, context->nalus[i].len); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "#%d %x len=%u\n", i, *context->nalus[i].start, context->nalus[i].len); while (!(*p++)) ; /* eat the sync bytes, what ever 0 0 1 or 0 0 0 1 */ i++; context->nalus[i].start = p; @@ -307,8 +307,8 @@ SWITCH_DECLARE(switch_status_t) switch_packetizer_read(switch_packetizer_t *pack nri = nalu_hdr & 0x60; if (real_slice_size > slice_size) real_slice_size = slice_size; - if (frame->buflen < slice_size) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "frame buffer too small %u < %u\n", frame->buflen, slice_size); + if (frame->datalen < slice_size) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "frame buffer too small %u < %u\n", frame->datalen, slice_size); return SWITCH_STATUS_FALSE; } diff --git a/tests/unit/switch_packetizer.c b/tests/unit/switch_packetizer.c index 242ca6ae33..006af5a74b 100644 --- a/tests/unit/switch_packetizer.c +++ b/tests/unit/switch_packetizer.c @@ -52,6 +52,7 @@ FST_CORE_BEGIN("conf") frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed(packetizer, h264data, sizeof(h264data)); @@ -94,6 +95,7 @@ FST_CORE_BEGIN("conf") frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed(packetizer, h264data, sizeof(h264data)); @@ -138,6 +140,7 @@ FST_CORE_BEGIN("conf") // 1 fps 3 bytes 1pps 3 bytes frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed_extradata(packetizer, extradata, sizeof(extradata)); @@ -210,6 +213,7 @@ FST_CORE_BEGIN("conf") frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed(packetizer, h264data, sizeof(h264data)); From 2cf57c41b634ba8821d9e65360c1a25159b9ad4c Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 4 Jul 2023 15:25:05 +0200 Subject: [PATCH 058/123] [mod_python3] fix build on Python 3.10+ fix #2145 --- src/mod/languages/mod_python3/mod_python3.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_python3/mod_python3.c b/src/mod/languages/mod_python3/mod_python3.c index ca05f18710..263c2de1d4 100644 --- a/src/mod/languages/mod_python3/mod_python3.c +++ b/src/mod/languages/mod_python3/mod_python3.c @@ -86,6 +86,9 @@ static void print_python_error(const char * script) { PyObject *pyType = NULL, *pyValue = NULL, *pyTraceback = NULL, *pyString = NULL; PyObject *pyModule=NULL, *pyFunction = NULL, *pyResult = NULL; +#if PY_VERSION_HEX >= 0x030B0000 + PyCodeObject *pcode = NULL; +#endif char * buffer = (char*) malloc( 20 * 1024 * sizeof(char)); /* Variables for the traceback */ PyTracebackObject * pyTB = NULL/*, *pyTB2 = NULL*/; @@ -153,10 +156,23 @@ static void print_python_error(const char * script) /* Traceback */ do { - sprintf((char*)sTemp, "\n\tFile: \"%s\", line %i, in %s", +#if PY_VERSION_HEX >= 0x030B0000 + if (pyTB->tb_frame != NULL) { + pcode = PyFrame_GetCode(pyTB->tb_frame); + } else { + pcode = NULL; + } + + snprintf((char*)sTemp, sizeof(sTemp), "\n\tFile: \"%s\", line %i, in %s", + (pcode)?PyString_AsString(pcode->co_filename):"", + pyTB->tb_lineno, + (pcode)?PyString_AsString(pcode->co_name):"" ); +#else + snprintf((char*)sTemp, sizeof(sTemp), "\n\tFile: \"%s\", line %i, in %s", PyString_AsString(pyTB->tb_frame->f_code->co_filename), pyTB->tb_lineno, PyString_AsString(pyTB->tb_frame->f_code->co_name) ); +#endif strcat(buffer, (char*)sTemp); pyTB=pyTB->tb_next; From 95457f79226ea68f8ba49051eda7ba661da1e36c Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 12 Jul 2023 18:17:52 +0300 Subject: [PATCH 059/123] Revert "[mod_opus] Fix Windows build regression made by previous commit" This reverts commit 25afda9be002a2edd7311d2d10531ce88431b5c3. --- src/mod/codecs/mod_opus/mod_opus.2017.vcxproj | 4 ---- src/mod/codecs/mod_opus/opus_parse.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj b/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj index 18478701c8..3b73a6c42f 100644 --- a/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj +++ b/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj @@ -130,10 +130,6 @@ - - - - diff --git a/src/mod/codecs/mod_opus/opus_parse.c b/src/mod/codecs/mod_opus/opus_parse.c index b94f491ca0..41e1ec6490 100644 --- a/src/mod/codecs/mod_opus/opus_parse.c +++ b/src/mod/codecs/mod_opus/opus_parse.c @@ -29,7 +29,7 @@ */ #include "switch.h" -#include "opus.h" +#include #include "opus_parse.h" /* Tables for LBRR_sympbol decoding */ From 34f1d974f50f1c1f819b102550395b0b240d386e Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 12 Jul 2023 18:18:17 +0300 Subject: [PATCH 060/123] Revert "[core, mod_opus] more elastic jitterbuffer with Opus codec (#2069)" This reverts commit 67840823c178153cb013014c4fa780fe233612cb. --- scripts/lua/hangup_jitterbuffer_metrics.lua | 53 --- src/include/switch_jitterbuffer.h | 1 - src/include/switch_types.h | 1 - src/mod/codecs/mod_opus/Makefile.am | 2 +- src/mod/codecs/mod_opus/mod_opus.c | 30 -- src/mod/codecs/mod_opus/opus_parse.c | 366 -------------------- src/mod/codecs/mod_opus/opus_parse.h | 66 ---- src/switch_jitterbuffer.c | 239 +------------ src/switch_rtp.c | 1 - 9 files changed, 3 insertions(+), 756 deletions(-) delete mode 100755 scripts/lua/hangup_jitterbuffer_metrics.lua delete mode 100644 src/mod/codecs/mod_opus/opus_parse.c delete mode 100644 src/mod/codecs/mod_opus/opus_parse.h diff --git a/scripts/lua/hangup_jitterbuffer_metrics.lua b/scripts/lua/hangup_jitterbuffer_metrics.lua deleted file mode 100755 index 8e3dd37623..0000000000 --- a/scripts/lua/hangup_jitterbuffer_metrics.lua +++ /dev/null @@ -1,53 +0,0 @@ -local https = require("socket.http") -local ip = os.getenv("LOCAL_IPV4") -local response_body = {} --- jitter buffer stats -local size_max_ms = session:getVariable("rtp_jb_size_max_ms"); -local size_est_ms = session:getVariable("rtp_jb_size_est_ms"); -local acceleration_ms = session:getVariable("rtp_jb_acceleration_ms"); -local expand_ms = session:getVariable("rtp_jb_expand_ms"); -local jitter_max_ms = session:getVariable("rtp_jb_jitter_max_ms"); -local jitter_est_ms = session:getVariable("rtp_jb_jitter_est_ms"); - -local reset_count = session:getVariable("rtp_jb_reset_count"); -local reset_too_big = session:getVariable("rtp_jb_reset_too_big"); -local reset_missing_frames = session:getVariable("rtp_jb_reset_missing_frames"); -local reset_ts_jump = session:getVariable("rtp_jb_reset_ts_jump"); -local reset_error = session:getVariable("rtp_jb_reset_error"); -local call_id = session:getVariable("sip_call_id"); -local out_call_id = session:getVariable("last_bridge_to"); - -if size_max_ms == nil or size_est_ms == nil or acceleration_ms == nil or expand_ms == nil or jitter_max_ms == nil or jitter_est_ms == nil then - session:consoleLog("info", "[metrics] jitter no data\n"); - return -end -local request_body = '{"in_call_id": "'..call_id..'", "out_call_id": "'..out_call_id..'", "jb":{"size_max_ms":'..size_max_ms.. - ',"size_est_ms":'..size_est_ms..',"acceleration_ms":'..acceleration_ms..',"expand_ms":'..expand_ms.. - ',"jitter_max_ms":'..jitter_max_ms..',"jitter_est_ms":'..jitter_est_ms..',"reset":'..reset_count --- if reset_too_big ~= "0" then - request_body = request_body .. ',"reset_too_big":'..reset_too_big --- end -if reset_missing_frames ~= "0" then - request_body = request_body .. ',"reset_missing_frames":'..reset_missing_frames -end -if reset_ts_jump ~= "0" then - request_body = request_body .. ',"reset_ts_jump":'..reset_ts_jump -end -if reset_error ~= "0" then - request_body = request_body .. ',"reset_error":'..reset_error -end - -local v = request_body .. '}}'; - -local r, c, h, s = https.request{ - method = 'POST', - url = "http://"..ip..":80/freeswitch_metrics", - headers = { - ["Content-Type"] = "application/json", - ["Content-Length"] = string.len(v) - }, - source = ltn12.source.string(v), - sink = ltn12.sink.table(response_body) -} --- print('statusCode ', c) -session:consoleLog("info", "[metrics] jitter:".. v .. "\n"); diff --git a/src/include/switch_jitterbuffer.h b/src/include/switch_jitterbuffer.h index f098ede2db..bee0fa02f8 100644 --- a/src/include/switch_jitterbuffer.h +++ b/src/include/switch_jitterbuffer.h @@ -61,7 +61,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp SWITCH_DECLARE(uint32_t) switch_jb_pop_nack(switch_jb_t *jb); SWITCH_DECLARE(switch_status_t) switch_jb_get_packet_by_seq(switch_jb_t *jb, uint16_t seq, switch_rtp_packet_t *packet, switch_size_t *len); SWITCH_DECLARE(void) switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session); -SWITCH_DECLARE(void) switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jitter, uint32_t samples_per_frame, uint32_t samples_per_second); SWITCH_DECLARE(void) switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_frame, uint32_t samples_per_second); SWITCH_DECLARE(void) switch_jb_set_flag(switch_jb_t *jb, switch_jb_flag_t flag); SWITCH_DECLARE(void) switch_jb_clear_flag(switch_jb_t *jb, switch_jb_flag_t flag); diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 94a4c62cca..82639c2ca6 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -2425,7 +2425,6 @@ typedef enum { SCC_VIDEO_RESET, SCC_AUDIO_PACKET_LOSS, SCC_AUDIO_ADJUST_BITRATE, - SCC_AUDIO_VAD, SCC_DEBUG, SCC_CODEC_SPECIFIC } switch_codec_control_command_t; diff --git a/src/mod/codecs/mod_opus/Makefile.am b/src/mod/codecs/mod_opus/Makefile.am index 70710898e7..690c5fa471 100644 --- a/src/mod/codecs/mod_opus/Makefile.am +++ b/src/mod/codecs/mod_opus/Makefile.am @@ -4,7 +4,7 @@ MODNAME=mod_opus if HAVE_OPUS mod_LTLIBRARIES = mod_opus.la -mod_opus_la_SOURCES = mod_opus.c opus_parse.c +mod_opus_la_SOURCES = mod_opus.c mod_opus_la_CFLAGS = $(AM_CFLAGS) $(OPUS_CFLAGS) mod_opus_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(OPUS_LIBS) mod_opus_la_LDFLAGS = -avoid-version -module -no-undefined -shared -lm -lz diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index ce9aff52a3..4a47b45df4 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -33,7 +33,6 @@ #include "switch.h" #include "opus.h" -#include "opus_parse.h" #define SWITCH_OPUS_MIN_BITRATE 6000 #define SWITCH_OPUS_MAX_BITRATE 510000 @@ -1170,27 +1169,6 @@ static switch_status_t switch_opus_keep_fec_enabled(switch_codec_t *codec) } } -static switch_bool_t switch_opus_vad(struct opus_context *context, void *encoded_data, uint32_t encoded_data_len) { - const uint8_t *payload = (const uint8_t *) encoded_data; - opus_packet_info_t opus_packet_info; - switch_bool_t debug = (globals.debug || context->debug > 1); - if (!switch_opus_packet_parse(payload, encoded_data_len, &opus_packet_info, debug)) { - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "OPUS PACKET PARSING ERROR len:%d bytes:%02x %02x\n", - (int)encoded_data_len, payload[0], payload[1]); - } - return SWITCH_TRUE; - } - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "OPUS EXTRACT PAYLOAD VAD len:%d vad_ms:%d bytes:%02x %02x\n", - (int)encoded_data_len, opus_packet_info.vad_ms, payload[0], payload[1]); - } - if (opus_packet_info.vad_ms == 0) { - return SWITCH_FALSE; - } - return SWITCH_TRUE; -} - static switch_status_t switch_opus_control(switch_codec_t *codec, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, @@ -1282,14 +1260,6 @@ static switch_status_t switch_opus_control(switch_codec_t *codec, context->old_plpct = plpct; } break; - case SCC_AUDIO_VAD: - { - void* encoded_data = (void *)cmd_data; - uint16_t* encoded_data_len = (uint16_t *)cmd_arg; - switch_bool_t *ret = (switch_bool_t *) *ret_data; - *ret = switch_opus_vad(context, encoded_data, *encoded_data_len); - } - break; case SCC_AUDIO_ADJUST_BITRATE: { const char *cmd = (const char *)cmd_data; diff --git a/src/mod/codecs/mod_opus/opus_parse.c b/src/mod/codecs/mod_opus/opus_parse.c deleted file mode 100644 index 41e1ec6490..0000000000 --- a/src/mod/codecs/mod_opus/opus_parse.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2023, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Claude Lamblin - * Julien Chavanton - * - */ - -#include "switch.h" -#include -#include "opus_parse.h" -/* Tables for LBRR_sympbol decoding */ - -static const opus_int16 silk_LBRR_flags_2_PDFCum[3] = {53, 106, 256}; /* 256 - silk_LBRR_flags_2_iCDF[i] ; silk_LBRR_flags_2_iCDF[ 3 ] = { 203, 150, 0 }; */ -static const opus_int16 silk_LBRR_flags_3_PDFCum[7] = {41, 61, 90, 131, 146, 174, 256}; /* 256 - silk_LBRR_flags_3_iCDF[i] ; silk_LBRR_flags_3_iCDF[ 7 ] = { 215, 195, 166, 125, 110, 82, 0 }; */ - -/* get the number of VAD flags - i.e. number of 20 ms frame - from the config */ -/* in a silk-only or hybrid opus frame mono or stereo*/ -/* 5 MSB TOC byte (see table 2 of IETF RFC6716 clause 3.1) */ -/* if 10 ms frame (config=0, 4, 8, 12, 14) : return 1 */ -/* if CELT_only frame no VAD flag =>return 0 */ -static opus_int16 switch_opus_get_nb_flags_in_silk_frame(int16_t config) -{ - opus_int16 silk_frame_nb_flags; - if (config > 15) { - /* CELT_only frame no VAD flag nor LBRR flag */ - silk_frame_nb_flags = 0; - } else { - silk_frame_nb_flags = 1; /*default*/ - if (config < 12) { - /* silk-only NB, MB or WB */ - /* The least two significant bits give the number of VAD flags inside the silk frame 1, 2 or 3 */ - silk_frame_nb_flags = config & 0x3; - if (silk_frame_nb_flags == 0) { /* 0 => 10ms frame : one VAD flag */ - silk_frame_nb_flags++; - } - } - } - return silk_frame_nb_flags; -} - -/* get the time in ms corresponding to one VAD flag from the config */ -/* in a silk-only or hybrid opus frame mono or stereo*/ -/* 5 MSB TOC byte (see table 2 of IETF RFC6716 clause 3.1) */ -/* if CELT_only frame (config >15) no VAD flag =>return FALSE */ -/* if 10 ms frame (config=0, 4, 8, 12, 14) : return 10 */ -/* otherwise return 20 */ -static opus_int16 switch_opus_get_silk_frame_ms_per_flag(int16_t config, opus_int16 silk_frame_nb_flags) -{ - opus_int16 silk_size_frame_ms_per_flag; - if (config > 15) { - /* CELT_only frame no VAD flag nor LBRR flag */ - /* switch_opus_get_silk_frame_ms_per_flag: code not written for CELT-only mode */ - return FALSE; - } - silk_size_frame_ms_per_flag = 20; /* default*/ - if (silk_frame_nb_flags == 1) { /* could be 10 or 20 ms */ - if ((config &0x01) == 0) { - silk_size_frame_ms_per_flag = 10; - } - } - return silk_size_frame_ms_per_flag; -} - -/* code written only for mono, silk-only or hybrid mode */ -/* for CELT-only frame no vad flags for LBRR flag the routine must not be called */ -/* for stereo : the mid frame VAD_flags and the LBRR_flag could be obtained */ -/* yet, to get the LBRR_flags of the mid frame the routine should be modified */ -/* to skip the side VAD flags and the side LBRR flag and to get the mid LBRR_symbol */ -static bool_t switch_opus_get_VAD_LBRR_flags(const uint8_t *buf, opus_int16 silk_frame_nb_flags, - opus_int16 *VAD_flags, opus_int16 *LBRR_flags, opus_int16 *nb_VAD1, opus_int16 *nb_FEC) -{ - const opus_int16 *ptr_pdf_cum; - opus_int nb_pdf_symbol; - opus_uint16 LBRR_symbol; - opus_int16 val, nb_bit, compl_nb_bit, mask, mask2; - opus_int16 *ptr_flags; - opus_int16 LBRR_flag; - opus_int16 nb_vad, nb_fec; - int i; - - nb_vad = 0; - nb_fec = 0; - - /* get VAD_FLAGS & LBRR_FLAG */ - /* silk_frame_nb_flags = 1 (10 or 20 ms), the two MSB of the first byte are the VAD flag and the LBRR flag */ - /* silk_frame_nb_flags = 2 (40 ms), the three MSB of the first byte are the two VAD flags and the LBRR flag */ - /* silk_frame_nb_flags = 3 (60 ms), the four MSB of the first byte are the three VAD flags and the LBRR flag */ - /* compute the number of MSB to analyse */ - nb_bit = silk_frame_nb_flags + 1; - /* number of right shifts to appply to the first byte to only have the bits of LBRR flag and of the VAD flags */ - compl_nb_bit = 8 - nb_bit; - mask = (1 << nb_bit) - 1; - - /* the bits of the silk_frame_nb_flags VAD flags and the LBRR flag are the MSB of the first byte */ - /* silk_frame_nb_flags = 1 (10 or 20 ms), VAD_flags(0) | LBRR_flag */ - /* silk_frame_nb_flags = 2 (40 ms), VAD_flags(0) | VAD_flags(1) | LBRR_flag */ - /* silk_frame_nb_flags = 3 (60 ms), VAD_flags(0) | VAD_flags(1) | VAD_flags(2) |LBRR_flag */ - val = (buf[0] >> compl_nb_bit) & mask; - - LBRR_flag = val & 0x1; /* LBRR_FLAG LSB */ - - /* get VAD_flags */ - ptr_flags = VAD_flags + silk_frame_nb_flags; - for (i=0; i < silk_frame_nb_flags; i++) { - LBRR_flags[i] = 0; /* init */ - val >>= 1; - *(--ptr_flags) = val & 0x1; - } - if (LBRR_flag != 0) { /* there is at least one LBRR frame */ - if (silk_frame_nb_flags == 1) { - LBRR_flags[0] = 1; - nb_fec = 1; - } else { /* get LBRR_symbol then LBRR_flags */ - /* LBRR symbol is encoded with range encoder : range on 8 bits */ - /* silk_frame_nb_flags = 2 ; 3 possible values for LBRR_flags(1) | LBRR_flags(0))= 01, 10, 11 */ - /* silk_frame_nb_flags = 3 ; 7 possible values for LBRR_flags(2) | LBRR_flags(1) | LBRR_flags(0))= 001, 010, 011, 100, 101, 110, 111 */ - mask2 = (1 << compl_nb_bit) - 1; - /* get next 8 bits: (8-nb_bit) LSB of the first byte and nb_bit MSB of the second byte */ - val = (((buf[0]) & mask2) << nb_bit) | ((buf[1] >> compl_nb_bit) & mask); - - if (silk_frame_nb_flags == 2) { - nb_pdf_symbol = 3; - ptr_pdf_cum = silk_LBRR_flags_2_PDFCum; - } else { - nb_pdf_symbol = 7; - ptr_pdf_cum = silk_LBRR_flags_3_PDFCum; - } - LBRR_symbol = 0; - for (i = 1; i <= nb_pdf_symbol; i++) { - if (val < *ptr_pdf_cum++) { - LBRR_symbol = i; - break; - } - } - for (i = 0; i < silk_frame_nb_flags; i++) { - LBRR_flags[i] = LBRR_symbol & 0x01; - LBRR_symbol >>= 1; - nb_fec += LBRR_flags[i]; - } - } - } - for (i = 0; i < silk_frame_nb_flags; i++) { - nb_vad += VAD_flags[i]; - } - - *nb_VAD1 = nb_vad; - *nb_FEC = nb_fec; - return TRUE; -} - -/* Parse the packet to retrieve informations about its content - * RFC6716: Definition of the Opus Audio Codec - * return: FALSE if there was a problem found parsing the packet, the info returned should be ignored. - * */ -bool_t switch_opus_packet_parse(const uint8_t *payload, int payload_length_bytes, opus_packet_info_t *packet_info, bool_t debug) -{ - int f; - int32_t samplerate; - int i, shift_silk, silk_frame_packet; - int16_t vad_flags_per_silk_frame, fec_flags_per_silk_frame; - opus_int16 frame_sizes[48]; - const unsigned char *frame_data[48]; - opus_int16 packet_LBBR_FLAGS[3 * 48], packet_VAD_FLAGS[3 * 48]; - opus_int16 *ptr_LBBR_FLAGS, *ptr_VAD_FLAGS; - opus_int16 silk_frame_nb_flags, silk_size_frame_ms_per_flag; - opus_int16 silk_frame_nb_fec, silk_frame_nb_vad1; - opus_int sample_per_frame; - packet_info->config = 0; - packet_info->fec = 0; - packet_info->fec_ms = 0; - packet_info->vad = 0; - packet_info->vad_ms = 0; - packet_info->stereo = FALSE; - packet_info->frames = 0; - packet_info->channels = 1; /* as stereo is set to FALSE */ - packet_info->ms_per_frame = 0; - packet_info->ptime_ts = 0; - if (payload == NULL || payload_length_bytes <= 0) { - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: payload null."); - } - return FALSE; - } - - /* In CELT_ONLY mode, packets should not have FEC. */ - if (payload[0] & 0x80) { - /* opus_packet_parse: CELT_ONLY mode, we do not support this mode. */ - return FALSE; - } else { - int mode = (payload[0] >> 3); - if (mode <= 3) { - samplerate = 8000; - } else if (mode <= 7) { - samplerate = 12000; - } else if (mode <= 11) { - samplerate = 16000; - } else if (mode <= 13) { - samplerate = 24000; - } else if (mode <= 15) { - samplerate = 48000; - } else { - /* opus_packet_parse: CELT_ONLY mode, we do not support this mode. */ - return FALSE; - } - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: mode[%d]s[%d]c[%d] [%d]Hz\n", mode, (payload[0]>>2)&0x1 ,(payload[0])&0x3, samplerate); - } - } - if (payload[0] & 0x04) { - packet_info->stereo = TRUE; - packet_info->channels = 2; - } - packet_info->config = payload[0] >> 3; - sample_per_frame = opus_packet_get_samples_per_frame(payload, samplerate); - packet_info->ms_per_frame = sample_per_frame * 1000 / samplerate; - if (packet_info->ms_per_frame < 10 || packet_info->ms_per_frame > 120) { - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: invalid packet."); - } - return FALSE; - } - - packet_info->frames = opus_packet_parse(payload, payload_length_bytes, NULL, frame_data, frame_sizes, NULL); - if (packet_info->frames < 0) { - packet_info->frames = 0; - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: opus_packet_parse found no frame.\n"); - } - return FALSE; - } - packet_info->ptime_ts = packet_info->frames * sample_per_frame; - - if (frame_sizes[0] <= 1) { - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: opus_packet_parse frame size too small.\n"); - } - return FALSE; - } - - /* +---------------+-----------+-----------+-------------------+ */ - /* | Configuration | Mode | Bandwidth | Frame Sizes | */ - /* | Number(s) | | | | */ - /* +---------------+-----------+-----------+-------------------+ */ - /* | 0...3 | SILK-only | NB | 10, 20, 40, 60 ms | */ - /* | 4...7 | SILK-only | MB | 10, 20, 40, 60 ms | */ - /* | 8...11 | SILK-only | WB | 10, 20, 40, 60 ms | */ - /* | 12...13 | Hybrid | SWB | 10, 20 ms | */ - /* | 14...15 | Hybrid | FB | 10, 20 ms | */ - /* | 16...19 | CELT-only | NB | 2.5, 5, 10, 20 ms | */ - /* | 20...23 | CELT-only | WB | 2.5, 5, 10, 20 ms | */ - /* | 24...27 | CELT-only | SWB | 2.5, 5, 10, 20 ms | */ - /* | 28...31 | CELT-only | FB | 2.5, 5, 10, 20 ms | */ - /* +---------------+-----------+-----------+-------------------+ */ - - if (!packet_info->stereo) { - /* the routines opus_get_nb_flags_in_silk_frame and opus_get_silk_frame_ms_per_flag are also valid for stereo frames */ - /* yet the routine opus_get_VAD_LBRR_flags is currently only for mono frame*/ - silk_frame_nb_flags = switch_opus_get_nb_flags_in_silk_frame(packet_info->config); /* =1 for 10 or 20 ms frame; = 2 for 40 ms; = 3 for 60 ms */ - if (!silk_frame_nb_flags) { - /* We should not go there as CELT_ONLY is already tested above */ - return FALSE; - } - - packet_info->frames_silk = silk_frame_nb_flags; - silk_size_frame_ms_per_flag = switch_opus_get_silk_frame_ms_per_flag(packet_info->config, silk_frame_nb_flags); /* 10 or 20 ms frame*/ - if (!silk_size_frame_ms_per_flag) { - /* we should not go there as CELT_ONLY is already tested above */ - return FALSE; - } - - ptr_LBBR_FLAGS = packet_LBBR_FLAGS; - ptr_VAD_FLAGS = packet_VAD_FLAGS; - - for (f = 0; f < packet_info->frames; f++) { - switch_opus_get_VAD_LBRR_flags(frame_data[f], silk_frame_nb_flags, ptr_VAD_FLAGS, ptr_LBBR_FLAGS, - &silk_frame_nb_vad1, &silk_frame_nb_fec); - packet_info->vad += silk_frame_nb_vad1; - packet_info->fec += silk_frame_nb_fec; - packet_info->vad_ms += silk_frame_nb_vad1 * silk_size_frame_ms_per_flag; - packet_info->fec_ms += silk_frame_nb_fec * silk_size_frame_ms_per_flag; - - ptr_VAD_FLAGS += silk_frame_nb_flags; - ptr_LBBR_FLAGS += silk_frame_nb_flags; - } - /* store the VAD & LBRR flags of all 20 ms silk-frames of the packet; LSB the first frame, MSB: the last */ - vad_flags_per_silk_frame = 0; - fec_flags_per_silk_frame = 0; - silk_frame_packet = packet_info->frames * packet_info->frames_silk; - if (silk_frame_packet > 15) { - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: more than %d 20-ms frames in the packet ; only first 15 silk-frames data will be stored (pb silkFastAccelerate)\n", silk_frame_packet); - } - silk_frame_packet = 15; - } - ptr_LBBR_FLAGS = packet_LBBR_FLAGS; - ptr_VAD_FLAGS = packet_VAD_FLAGS; - shift_silk = 0; - for (i=0; i < silk_frame_packet; i++) { - vad_flags_per_silk_frame += (*ptr_VAD_FLAGS) << shift_silk; - fec_flags_per_silk_frame += (*ptr_LBBR_FLAGS) << shift_silk; - shift_silk++; - ptr_LBBR_FLAGS++; ptr_VAD_FLAGS++; - } - packet_info->vad_flags_per_silk_frame = vad_flags_per_silk_frame; - packet_info->fec_flags_per_silk_frame = fec_flags_per_silk_frame; - return TRUE; - } - - if (packet_info->config != 1 && packet_info->config != 5 && packet_info->config != 9) { - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: the current parser implementation does not support muliple SILK frames for VAD or FEC detection.\n"); - } - return FALSE; - } - /* - * Parse the VAD and LBRR flags in each Opus frame - * */ - for (f = 0; f < packet_info->frames; f++) { - if (frame_data[f][0] & 0x80) { - packet_info->vad++; - } - if (frame_data[f][0] & 0x40) { - packet_info->fec++; - } - if (debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opus_packet_parse: LP layer opus_frame[%d] VAD[%d] FEC[%d]\n", f+1, (frame_data[f][0]&0x80)>>7, (frame_data[f][0]&0x40)>>6); - } - } - packet_info->vad_ms = packet_info->vad * packet_info->ms_per_frame; - packet_info->fec_ms = packet_info->fec * packet_info->ms_per_frame; - return TRUE; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: - */ diff --git a/src/mod/codecs/mod_opus/opus_parse.h b/src/mod/codecs/mod_opus/opus_parse.h deleted file mode 100644 index 8dd61500cd..0000000000 --- a/src/mod/codecs/mod_opus/opus_parse.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2023, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Julien Chavanton - * - */ - -#ifndef SWITCH_OPUS_PARSE_H -#define SWITCH_OPUS_PARSE_H - -typedef enum { false, true } bool_t; - -typedef struct opus_packet_info { - int16_t vad; - int16_t vad_ms; - int16_t fec; - int16_t fec_ms; - bool_t stereo; - int16_t frames; /* number of opus frames in the packet */ - int16_t config; - int16_t channels; - int16_t ms_per_frame; - int32_t ptime_ts; - bool_t valid; - int16_t frames_silk; /* number of silk_frames in an opus frame */ - /* VAD flag of all 20 ms silk-frames of the packet; LSB the first frame, MSB: the last */ - int16_t vad_flags_per_silk_frame; - /* LBRR (FEC) flag of all 20 ms silk-frames of the packet; LSB the first frame, MSB: the last */ - int16_t fec_flags_per_silk_frame; -} opus_packet_info_t; - -bool_t switch_opus_packet_parse(const uint8_t *payload, int payload_length_bytes, opus_packet_info_t *packet_info, bool_t debug); -#endif - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: - */ diff --git a/src/switch_jitterbuffer.c b/src/switch_jitterbuffer.c index d8d9df3a33..d68b269024 100644 --- a/src/switch_jitterbuffer.c +++ b/src/switch_jitterbuffer.c @@ -44,8 +44,6 @@ struct switch_jb_s; -static inline int check_jb_size(switch_jb_t *jb); - typedef struct switch_jb_node_s { struct switch_jb_s *parent; switch_rtp_packet_t packet; @@ -58,29 +56,6 @@ typedef struct switch_jb_node_s { switch_bool_t complete_frame_mark; } switch_jb_node_t; -typedef struct switch_jb_stats_s { - uint32_t reset_too_big; - uint32_t reset_missing_frames; - uint32_t reset_ts_jump; - uint32_t reset_error; - uint32_t reset; - uint32_t size_max; - uint32_t size_est; - uint32_t acceleration; - uint32_t expand; - uint32_t jitter_max_ms; - int estimate_ms; - int buffer_size_ms; -} switch_jb_stats_t; - -typedef struct switch_jb_jitter_s { - double *estimate; - uint32_t samples_per_second; - uint32_t samples_per_frame; - uint32_t drop_gap; - switch_jb_stats_t stats; -} switch_jb_jitter_t; - struct switch_jb_s { struct switch_jb_node_s *node_list; uint32_t last_target_seq; @@ -129,7 +104,6 @@ struct switch_jb_s { switch_jb_flag_t flags; switch_jb_type_t type; switch_core_session_t *session; - switch_jb_jitter_t jitter; switch_channel_t *channel; uint32_t buffer_lag; uint32_t flush; @@ -138,8 +112,6 @@ struct switch_jb_s { uint32_t period_len; uint32_t nack_saved_the_day; uint32_t nack_didnt_save_the_day; - switch_bool_t elastic; - switch_codec_t *codec; }; @@ -261,7 +233,6 @@ static inline switch_jb_node_t *new_node(switch_jb_t *jb) if (jb->allocated_nodes > jb->max_frame_len * mult) { jb_debug(jb, 2, "ALLOCATED FRAMES TOO HIGH! %d\n", jb->allocated_nodes); - jb->jitter.stats.reset_too_big++; switch_jb_reset(jb); switch_mutex_unlock(jb->list_mutex); return NULL; @@ -361,29 +332,6 @@ static inline void hide_nodes(switch_jb_t *jb) switch_mutex_unlock(jb->list_mutex); } -static inline switch_bool_t packet_vad(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t len) { - void* payload; - uint16_t payload_len = len; - - if (packet->ebody) { - payload = packet->ebody; - } else { - payload = packet->body; - } - if (payload && payload_len > 0) { - switch_bool_t ret; - switch_bool_t *ret_p = &ret; - switch_codec_control_type_t ret_t; - switch_core_media_codec_control(jb->session, SWITCH_MEDIA_TYPE_AUDIO, - SWITCH_IO_WRITE, SCC_AUDIO_VAD, - SCCT_STRING, (void *)payload, - SCCT_INT, (void *)&payload_len, - &ret_t, (void *)&ret_p); - return ret; - } - return SWITCH_TRUE; -} - static inline void drop_ts(switch_jb_t *jb, uint32_t ts) { switch_jb_node_t *np; @@ -719,7 +667,6 @@ static inline void add_node(switch_jb_t *jb, switch_rtp_packet_t *packet, switch if (((seq_diff >= 100) || (ts_diff > (900000 * 5)))) { jb_debug(jb, 2, "CHANGE DETECTED, PUNT %u\n", abs(((int)ntohs(packet->header.seq) - ntohs(jb->highest_wrote_seq)))); - jb->jitter.stats.reset_ts_jump++; switch_jb_reset(jb); } } @@ -785,12 +732,6 @@ static inline void increment_seq(switch_jb_t *jb) jb->target_seq = htons((ntohs(jb->target_seq) + 1)); } -static inline void decrement_seq(switch_jb_t *jb) -{ - jb->last_target_seq = jb->target_seq; - jb->target_seq = htons((ntohs(jb->target_seq) - 1)); -} - static inline void set_read_seq(switch_jb_t *jb, uint16_t seq) { jb->last_target_seq = seq; @@ -913,128 +854,12 @@ static inline switch_status_t jb_next_packet_by_ts(switch_jb_t *jb, switch_jb_no } -static inline int check_jb_size(switch_jb_t *jb) -{ - switch_jb_node_t *np; - uint16_t seq; - uint16_t l_seq=0; - uint16_t h_seq=0; - uint16_t count=0; - uint16_t old=0; - switch_mutex_lock(jb->list_mutex); - - for (np = jb->node_list; np; np = np->next) { - if (!np->visible) { - continue; - } - - seq = ntohs(np->packet.header.seq); - if (ntohs(jb->target_seq) > seq) { - hide_node(np, SWITCH_FALSE); - old++; - continue; - } - if (count == 0) { - l_seq = h_seq = seq; - } - count++; - if (seq < l_seq) - l_seq = seq; - if (seq > h_seq) - h_seq = seq; - } - if (count > jb->jitter.stats.size_max) { - jb->jitter.stats.size_max = count; - } - if (jb->jitter.stats.size_est == 0) { - jb->jitter.stats.size_est = count; - } else { - jb->jitter.stats.size_est = ((99*jb->jitter.stats.size_est)+(1*count))/100; - } - if (ntohs(jb->target_seq) % 50 == 0) { /* update the stats every x packets */ - int packet_ms = jb->jitter.samples_per_frame / (jb->jitter.samples_per_second / 1000); - jb->jitter.stats.estimate_ms = (*jb->jitter.estimate) / jb->jitter.samples_per_second * 1000; - switch_channel_set_variable_printf(jb->channel, "rtp_jb_size_max_ms", "%u", jb->jitter.stats.size_max*packet_ms); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_size_est_ms", "%u", jb->jitter.stats.size_est*packet_ms); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_acceleration_ms", "%u", jb->jitter.stats.acceleration*packet_ms); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_expand_ms", "%u", jb->jitter.stats.expand*packet_ms); - if (jb->jitter.stats.jitter_max_ms < jb->jitter.stats.estimate_ms) { - jb->jitter.stats.jitter_max_ms = jb->jitter.stats.estimate_ms; - } - switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_max_ms", "%u", jb->jitter.stats.jitter_max_ms); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_est_ms", "%u", jb->jitter.stats.estimate_ms); - } - if (old) { - sort_free_nodes(jb); - } - switch_mutex_unlock(jb->list_mutex); - jb_debug(jb, SWITCH_LOG_INFO, "JITTER buffersize %u == %u old[%u] target[%u] seq[%u|%u]\n", count, h_seq-l_seq+1, old, ntohs(jb->target_seq), l_seq, h_seq); - return count; -} - -static inline switch_status_t jb_next_packet_by_seq_with_acceleration(switch_jb_t *jb, switch_jb_node_t **nodep) -{ - switch_status_t status = jb_next_packet_by_seq(jb, nodep); - switch_rtp_packet_t *packet; - uint32_t len; - uint16_t seq = ntohs(jb->target_seq); - - /* When using a Codec that provides voice activity detection ex. Opus, use it to - select packet to drop/accelerate. */ - - if (jb->elastic && jb->jitter.estimate && (jb->visible_nodes*jb->jitter.samples_per_frame)>0 && jb->jitter.samples_per_second) { - int visible_not_old = check_jb_size(jb); - jb->jitter.stats.estimate_ms = (int)((*jb->jitter.estimate)/((jb->jitter.samples_per_second))*1000); - jb->jitter.stats.buffer_size_ms = (int)((visible_not_old*jb->jitter.samples_per_frame)/(jb->jitter.samples_per_second/1000)); - - // We try to accelerate in order to remove delay when the jitter buffer is 3x larger than the estimation. - if (jb->jitter.stats.buffer_size_ms > (3*jb->jitter.stats.estimate_ms) && jb->jitter.stats.buffer_size_ms > 60) { - if (status == SWITCH_STATUS_SUCCESS) { - packet = &(*nodep)->packet; - seq = ntohs((*nodep)->packet.header.seq); - len = (*nodep)->len; - } - if (jb->jitter.drop_gap > 0) { - jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms seq:%u [drop-gap][%d]\n", - jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq, jb->jitter.drop_gap); - jb->jitter.drop_gap--; - } else { - if (status != SWITCH_STATUS_SUCCESS || packet_vad(jb, packet, len) == SWITCH_FALSE) { - jb->jitter.drop_gap = 3; - if (status != SWITCH_STATUS_SUCCESS) { - jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation n/a buffersize %d/%d %dms seq:%u [drop-missing/no-plc]\n", - jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq); - } else { - jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms seq:%u ACCELERATE [drop]\n", - jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq); - } - jb->jitter.stats.acceleration++; - return jb_next_packet_by_seq(jb, nodep); - } else { - jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms seq:%u [drop-skip-vad]\n", - jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms, seq); - } - } - } else { - jb_debug(jb, 2, "JITTER estimation %dms buffersize %d/%d %dms\n", - jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms); - } - } - return status; -} - static inline switch_status_t jb_next_packet(switch_jb_t *jb, switch_jb_node_t **nodep) { if (jb->samples_per_frame) { return jb_next_packet_by_ts(jb, nodep); } else { - switch_status_t status; - if (jb->elastic && jb->jitter.estimate) { - status = jb_next_packet_by_seq_with_acceleration(jb, nodep); - } else { - status = jb_next_packet_by_seq(jb, nodep); - } - return status; + return jb_next_packet_by_seq(jb, nodep); } } @@ -1052,50 +877,13 @@ SWITCH_DECLARE(void) switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_fra switch_core_inthash_init(&jb->node_hash_ts); } -SWITCH_DECLARE(void) switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jitter, uint32_t samples_per_frame, uint32_t samples_per_second) -{ - if (jb && jitter) { - memset(&jb->jitter,0,sizeof(switch_jb_jitter_t)); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_max_ms", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_size_ms", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_acceleration_ms", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_expand_ms", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_max_ms", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_jitter_ms", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_count", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_too_big", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_missing_frames", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_ts_jump", "%u", 0); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_error", "%u", 0); - jb->jitter.estimate = jitter; - jb->jitter.samples_per_frame = samples_per_frame; - jb->jitter.samples_per_second = samples_per_second; - jb->jitter.drop_gap = 5; - } -} - SWITCH_DECLARE(void) switch_jb_set_session(switch_jb_t *jb, switch_core_session_t *session) { const char *var; if (session) { - jb->codec = switch_core_session_get_read_codec(session); jb->session = session; jb->channel = switch_core_session_get_channel(session); - if (!strcmp(jb->codec->implementation->iananame, "opus")) { - if (switch_true(switch_channel_get_variable(jb->channel, "rtp_jitter_buffer_accelerate"))) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec is %s, accelerate on\n", jb->codec->implementation->iananame); - jb->elastic = SWITCH_TRUE; - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec is %s, accelerate off\n", jb->codec->implementation->iananame); - jb->elastic = SWITCH_FALSE; - } - - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec not opus: %s\n", jb->codec->implementation->iananame); - jb->elastic = SWITCH_FALSE; - } - if (jb->type == SJB_VIDEO && !switch_test_flag(jb, SJB_QUEUE_ONLY) && (var = switch_channel_get_variable_dup(jb->channel, "jb_video_low_bitrate", SWITCH_FALSE, -1))) { int tmp = atoi(var); @@ -1144,12 +932,6 @@ SWITCH_DECLARE(void) switch_jb_debug_level(switch_jb_t *jb, uint8_t level) SWITCH_DECLARE(void) switch_jb_reset(switch_jb_t *jb) { - jb->jitter.stats.reset++; - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_count", "%u", jb->jitter.stats.reset); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_too_big", "%u", jb->jitter.stats.reset_too_big); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_missing_frames", "%u", jb->jitter.stats.reset_missing_frames); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_ts_jump", "%u", jb->jitter.stats.reset_ts_jump); - switch_channel_set_variable_printf(jb->channel, "rtp_jb_reset_error", "%u", jb->jitter.stats.reset_error); if (jb->type == SJB_VIDEO) { switch_mutex_lock(jb->mutex); @@ -1475,7 +1257,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_put_packet(switch_jb_t *jb, switch_rtp if (got > want) { if (got - want > jb->max_frame_len && got - want > 17) { jb_debug(jb, 2, "Missing %u frames, Resetting\n", got - want); - jb->jitter.stats.reset_missing_frames++; switch_jb_reset(jb); } else { @@ -1653,7 +1434,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp switch(status) { case SWITCH_STATUS_RESTART: jb_debug(jb, 2, "%s", "Error encountered\n"); - jb->jitter.stats.reset_error++; switch_jb_reset(jb); switch_goto_status(SWITCH_STATUS_RESTART, end); case SWITCH_STATUS_NOTFOUND: @@ -1664,22 +1444,7 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp jb_debug(jb, 2, "%s", "Too many frames not found, RESIZE\n"); switch_goto_status(SWITCH_STATUS_RESTART, end); } else { - if (jb->elastic) { - int visible_not_old = check_jb_size(jb); - jb->jitter.stats.estimate_ms = (int)((*jb->jitter.estimate)/((jb->jitter.samples_per_second))*1000); - jb->jitter.stats.buffer_size_ms = (int)((visible_not_old*jb->jitter.samples_per_frame)/(jb->jitter.samples_per_second/1000)); - /* When playing PLC, we take the oportunity to expand the buffer if the jitter buffer is smaller than the 3x the estimated jitter. */ - if (jb->jitter.stats.buffer_size_ms < (3*jb->jitter.stats.estimate_ms)) { - jb_debug(jb, SWITCH_LOG_INFO, "JITTER estimation %dms buffersize %d/%d %dms EXPAND [plc]\n", - jb->jitter.stats.estimate_ms, jb->complete_frames , jb->frame_len, jb->jitter.stats.buffer_size_ms); - jb->jitter.stats.expand++; - decrement_seq(jb); - } else { - jb_debug(jb, 2, "%s", "Frame not found suggest PLC\n"); - } - } else { - jb_debug(jb, 2, "%s", "Frame not found suggest PLC\n"); - } + jb_debug(jb, 2, "%s", "Frame not found suggest PLC\n"); plc = 1; switch_goto_status(SWITCH_STATUS_NOTFOUND, end); } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index fe97840cc7..4aa68061ab 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -4676,7 +4676,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t * READ_INC(rtp_session); status = switch_jb_create(&rtp_session->jb, SJB_AUDIO, queue_frames, max_queue_frames, rtp_session->pool); switch_jb_set_session(rtp_session->jb, rtp_session->session); - switch_jb_set_jitter_estimator(rtp_session->jb, &rtp_session->stats.rtcp.inter_jitter, samples_per_packet, samples_per_second); if (switch_true(switch_channel_get_variable_dup(switch_core_session_get_channel(rtp_session->session), "jb_use_timestamps", SWITCH_FALSE, -1))) { switch_jb_ts_mode(rtp_session->jb, samples_per_packet, samples_per_second); } From 7c1faeff48aef815b4cc5f22eb9ead52726dbd95 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 2 Jun 2023 21:58:41 +0300 Subject: [PATCH 061/123] [Build-System] Update libks and signalwire-c requirements to 2.0 --- configure.ac | 34 ++++++++++++++++----------- debian/control-modules | 2 +- freeswitch.spec | 2 +- w32/libks-version.props | 2 +- w32/libks.props | 12 +++++----- w32/signalwire-client-c-version.props | 2 +- w32/signalwire-client-c.props | 6 ++--- 7 files changed, 33 insertions(+), 27 deletions(-) diff --git a/configure.ac b/configure.ac index 04738e93c1..8a8bb102a7 100644 --- a/configure.ac +++ b/configure.ac @@ -1518,26 +1518,32 @@ PKG_CHECK_MODULES([V8FS_STATIC], [v8-6.1_static >= 6.1.298],[ ]) ]) -PKG_CHECK_MODULES([KS], [libks >= 1.8.2],[ +PKG_CHECK_MODULES([KS], [libks2 >= 2.0.0],[ AM_CONDITIONAL([HAVE_KS],[true])],[ - if module_enabled mod_verto; then - AC_MSG_ERROR([You need to either install libks or disable mod_verto in modules.conf]) - else - if module_enabled mod_signalwire; then - AC_MSG_ERROR([You need to either install libks or disable mod_signalwire in modules.conf]) + PKG_CHECK_MODULES([KS], [libks >= 1.8.2],[ + AM_CONDITIONAL([HAVE_KS],[true])],[ + if module_enabled mod_verto; then + AC_MSG_ERROR([You need to either install libks2 or libks or disable mod_verto in modules.conf]) else - AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_KS],[false]) + if module_enabled mod_signalwire; then + AC_MSG_ERROR([You need to either install libks2 or libks or disable mod_signalwire in modules.conf]) + else + AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_KS],[false]) + fi fi - fi + ]) ]) -PKG_CHECK_MODULES([SIGNALWIRE_CLIENT], [signalwire_client >= 1.0.0],[ +PKG_CHECK_MODULES([SIGNALWIRE_CLIENT], [signalwire_client2 >= 2.0.0],[ AM_CONDITIONAL([HAVE_SIGNALWIRE_CLIENT],[true])],[ - if module_enabled mod_signalwire; then - AC_MSG_ERROR([You need to either install signalwire-client-c or disable mod_signalwire in modules.conf]) - else - AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_SIGNALWIRE_CLIENT],[false]) - fi + PKG_CHECK_MODULES([SIGNALWIRE_CLIENT], [signalwire_client >= 1.0.0],[ + AM_CONDITIONAL([HAVE_SIGNALWIRE_CLIENT],[true])],[ + if module_enabled mod_signalwire; then + AC_MSG_ERROR([You need to either install signalwire-client-c2 or signalwire-client-c or disable mod_signalwire in modules.conf]) + else + AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_SIGNALWIRE_CLIENT],[false]) + fi + ]) ]) PKG_CHECK_MODULES([AMQP], [librabbitmq >= 0.5.2],[ diff --git a/debian/control-modules b/debian/control-modules index b9d7a05933..a578ad3ff3 100644 --- a/debian/control-modules +++ b/debian/control-modules @@ -209,7 +209,7 @@ Description: Adds mod_skel Module: applications/mod_signalwire Description: mod_signalwire Adds mod_signalwire. -Build-Depends: libks, signalwire-client-c +Build-Depends: libks2, signalwire-client-c2 Module: applications/mod_sms Description: Astract SMS diff --git a/freeswitch.spec b/freeswitch.spec index 1d985cc299..ecf9dacf13 100644 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -497,7 +497,7 @@ the entries aloud via a TTS engine Summary: FreeSWITCH mod_signalwire Group: System/Libraries Requires: %{name} = %{version}-%{release} -BuildRequires: libks signalwire-client-c +BuildRequires: libks2 signalwire-client-c2 %description application-signalwire Provides FreeSWITCH mod_signalwire diff --git a/w32/libks-version.props b/w32/libks-version.props index 44246b4d90..9e013ef808 100644 --- a/w32/libks-version.props +++ b/w32/libks-version.props @@ -4,7 +4,7 @@ - 1.8.2 + 2.0.0 1 diff --git a/w32/libks.props b/w32/libks.props index fb7a82f200..df0b9721f3 100644 --- a/w32/libks.props +++ b/w32/libks.props @@ -37,7 +37,7 @@ - @@ -67,12 +67,12 @@ - $(libksDir)\src\include;$(libksDir)\src\include\libks;%(AdditionalIncludeDirectories) - __PRETTY_FUNCTION__=__FUNCSIG__;WIN32;_WINDOWS;SWCLT_VERSION_MAJOR=1;SWCLT_VERSION_MINOR=0;SWCLT_VERSION_REVISION=0;_WIN32_WINNT=0x0600;_WINSOCK_DEPRECATED_NO_WARNINGS=1;WIN32_LEAN_AND_MEAN=1;KS_PLAT_WIN=1;NOMAXMIN=1;_CRT_SECURE_NO_WARNINGS=1;SWCLT_EXPORTS;%(PreprocessorDefinitions) + $(libksDir)\libks\src\include;$(libksDir)\libks\src\include\libks;%(AdditionalIncludeDirectories) + __KS_FUNC__=__FUNCSIG__;WIN32;_WINDOWS;SWCLT_VERSION_MAJOR=1;SWCLT_VERSION_MINOR=0;SWCLT_VERSION_REVISION=0;_WIN32_WINNT=0x0600;_WINSOCK_DEPRECATED_NO_WARNINGS=1;WIN32_LEAN_AND_MEAN=1;KS_PLAT_WIN=1;NOMAXMIN=1;_CRT_SECURE_NO_WARNINGS=1;SWCLT_EXPORTS;%(PreprocessorDefinitions) $(libksDir)\binaries\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories) - ks.lib;%(AdditionalDependencies) + ks2.lib;%(AdditionalDependencies) diff --git a/w32/signalwire-client-c-version.props b/w32/signalwire-client-c-version.props index 337dc4cc19..db6eb873cb 100644 --- a/w32/signalwire-client-c-version.props +++ b/w32/signalwire-client-c-version.props @@ -4,7 +4,7 @@ - 1.3.2 + 2.0.0 1 diff --git a/w32/signalwire-client-c.props b/w32/signalwire-client-c.props index 4d5f917b7e..df82dff00e 100644 --- a/w32/signalwire-client-c.props +++ b/w32/signalwire-client-c.props @@ -35,7 +35,7 @@
- @@ -70,7 +70,7 @@ $(signalwire-client-cDir)\binaries\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories) - signalwire_client.lib;%(AdditionalDependencies) + signalwire_client2.lib;%(AdditionalDependencies) From fdce50e420b9946125f9ddd3a48ad14b684f6ee4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sun, 16 Jul 2023 21:20:56 +0300 Subject: [PATCH 062/123] [Core] Fix missing MEDIA_PARAMS in message_names. --- src/switch_core_session.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/switch_core_session.c b/src/switch_core_session.c index a103a6e964..61aa500070 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -799,6 +799,7 @@ static const char *message_names[] = { "DEFLECT", "VIDEO_REFRESH_REQ", "DISPLAY", + "MEDIA_PARAMS", "TRANSCODING_NECESSARY", "AUDIO_SYNC", "VIDEO_SYNC", From 667783831bdc09d847f31510032901518a5fba9c Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Mon, 17 Jul 2023 15:36:27 +0000 Subject: [PATCH 063/123] [mod_av] Migrate to FFmpeg 5.1 --- src/mod/applications/mod_av/avcodec.c | 168 ++++- src/mod/applications/mod_av/avformat.c | 911 ++++++++++++++++++++----- src/mod/applications/mod_av/mod_av.c | 3 + src/mod/applications/mod_av/mod_av.h | 5 + 4 files changed, 872 insertions(+), 215 deletions(-) diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index 94cc9b36bf..d84362eb28 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -26,6 +26,7 @@ * Seven Du * Anthony Minessale * Emmanuel Schmidbauer + * Jakub Karolczyk * * mod_avcodec -- Codec with libav.org and ffmpeg * @@ -373,8 +374,13 @@ typedef struct our_h264_nalu_s { typedef struct h264_codec_context_s { switch_buffer_t *nalu_buffer; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) AVCodec *decoder; AVCodec *encoder; +#else + const AVCodec *decoder; + const AVCodec *encoder; +#endif AVCodecContext *decoder_ctx; int got_pps; /* if pps packet received */ int64_t pts; @@ -393,7 +399,7 @@ typedef struct h264_codec_context_s { switch_codec_settings_t codec_settings; AVCodecContext *encoder_ctx; AVFrame *encoder_avframe; - AVPacket encoder_avpacket; + AVPacket *encoder_avpacket; AVFrame *decoder_avframe; our_h264_nalu_t nalus[MAX_NALUS]; enum AVCodecID av_codec_id; @@ -826,7 +832,11 @@ static void fs_rtp_parse_h263_rfc2190(h264_codec_context_t *context, AVPacket *p const uint8_t *p = buf; const uint8_t *buf_base = buf; uint32_t code = (ntohl(*(uint32_t *)buf) & 0xFFFFFC00) >> 10; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) int mb_info_size = 0; +#else + switch_size_t mb_info_size = 0; +#endif int mb_info_pos = 0, mb_info_count = 0; const uint8_t *mb_info; @@ -890,7 +900,11 @@ static void fs_rtp_parse_h263_rfc2190(h264_codec_context_t *context, AVPacket *p "Unable to split H263 packet! mb_info_pos=%d mb_info_count=%d pos=%d max=%"SWITCH_SIZE_T_FMT"\n", mb_info_pos, mb_info_count, pos, (switch_size_t)(end - buf_base)); } } else { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Should Not Happen!!! mb_info_pos=%d mb_info_count=%d mb_info_size=%d\n", mb_info_pos, mb_info_count, mb_info_size); +#else + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Should Not Happen!!! mb_info_pos=%d mb_info_count=%d mb_info_size=%ld\n", mb_info_pos, mb_info_count, mb_info_size); +#endif } } } @@ -1034,7 +1048,7 @@ static switch_status_t consume_h263_bitstream(h264_codec_context_t *context, swi } if (!context->nalus[context->nalu_current_index].len) { - av_packet_unref(&context->encoder_avpacket); + av_packet_unref(context->encoder_avpacket); frame->m = 1; } @@ -1082,7 +1096,7 @@ static switch_status_t consume_h263p_bitstream(h264_codec_context_t *context, sw #endif if (frame->m) { - av_packet_unref(&context->encoder_avpacket); + av_packet_unref(context->encoder_avpacket); return SWITCH_STATUS_SUCCESS; } @@ -1091,7 +1105,7 @@ static switch_status_t consume_h263p_bitstream(h264_codec_context_t *context, sw static switch_status_t consume_nalu(h264_codec_context_t *context, switch_frame_t *frame) { - AVPacket *pkt = &context->encoder_avpacket; + AVPacket *pkt = context->encoder_avpacket; our_h264_nalu_t *nalu = &context->nalus[context->nalu_current_index]; if (!nalu->len) { @@ -1291,9 +1305,7 @@ FF_ENABLE_DEPRECATION_WARNINGS set_h264_private_data(context, aprofile); } -GCC_DIAG_OFF(deprecated-declarations) avcodec_string(codec_string, sizeof(codec_string), context->encoder_ctx, 0); -GCC_DIAG_ON(deprecated-declarations) dump_encoder_ctx(context->encoder_ctx); @@ -1393,6 +1405,8 @@ static switch_status_t switch_h264_init(switch_codec_t *codec, switch_codec_flag break; } + context->encoder_avpacket = av_packet_alloc(); + switch_buffer_create_dynamic(&(context->nalu_buffer), H264_NALU_BUFFER_SIZE, H264_NALU_BUFFER_SIZE * 8, 0); codec->private_info = context; @@ -1417,7 +1431,7 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t int ret; int *got_output = &context->got_encoded_output; AVFrame *avframe = NULL; - AVPacket *pkt = &context->encoder_avpacket; + AVPacket **pkt = &context->encoder_avpacket; uint32_t width = 0; uint32_t height = 0; switch_image_t *img = frame->img; @@ -1440,8 +1454,8 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t if (context->packetizer) { switch_status_t status = switch_packetizer_read(context->packetizer, frame); - if (status == SWITCH_STATUS_SUCCESS && pkt->size > 0) { - av_packet_unref(pkt); + if (status == SWITCH_STATUS_SUCCESS && (*pkt)->size > 0) { + av_packet_unref(*pkt); } return status; @@ -1456,6 +1470,7 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t if (open_encoder(context, width, height) != SWITCH_STATUS_SUCCESS) { goto error; } + avctx = context->encoder_ctx; } @@ -1465,6 +1480,7 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t if (open_encoder(context, width, height) != SWITCH_STATUS_SUCCESS) { goto error; } + avctx = context->encoder_ctx; } @@ -1474,15 +1490,13 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t if (open_encoder(context, width, height) != SWITCH_STATUS_SUCCESS) { goto error; } + avctx = context->encoder_ctx; switch_set_flag(frame, SFF_WAIT_KEY_FRAME); } -GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(pkt); -GCC_DIAG_ON(deprecated-declarations) - pkt->data = NULL; // packet data will be allocated by the encoder - pkt->size = 0; + av_packet_unref(*pkt); + /* packet data will be allocated by the encoder */ avframe = context->encoder_avframe; @@ -1547,14 +1561,42 @@ GCC_DIAG_ON(deprecated-declarations) /* encode the image */ memset(context->nalus, 0, sizeof(context->nalus)); context->nalu_current_index = 0; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) GCC_DIAG_OFF(deprecated-declarations) - ret = avcodec_encode_video2(avctx, pkt, avframe, got_output); + ret = avcodec_encode_video2(avctx, *pkt, avframe, got_output); GCC_DIAG_ON(deprecated-declarations) if (ret < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding Error %d\n", ret); goto error; } +#else + ret = avcodec_send_frame(avctx, avframe); + + if (ret == AVERROR_EOF) { + ret = 0; + } else if (ret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each encode call, so this should not ever happen */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder - BUG, should never happen\n"); + ret = AVERROR_BUG; + goto error; + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error sending frame to encoder\n"); + goto error; + } + + while (ret >= 0) { + ret = avcodec_receive_packet(avctx, *pkt); + if (ret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video packets at the moment\n"); + } else if (ret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video packets at all\n"); + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding error\n"); + av_packet_unref(*pkt); + goto error; + } +#endif if (context->need_key_frame && avframe->key_frame == 1) { avframe->pict_type = 0; @@ -1564,7 +1606,11 @@ GCC_DIAG_ON(deprecated-declarations) // process: +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) if (*got_output) { +#else + if (ret >= 0) { +#endif switch_status_t status = SWITCH_STATUS_SUCCESS; *got_output = 0; @@ -1572,56 +1618,66 @@ GCC_DIAG_ON(deprecated-declarations) if (context->av_codec_id == AV_CODEC_ID_H263) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG5, "Encoded frame %" SWITCH_INT64_T_FMT " (size=%5d) [0x%02x 0x%02x 0x%02x 0x%02x] got_output: %d slices: %d\n", - context->pts, pkt->size, *((uint8_t *)pkt->data), *((uint8_t *)(pkt->data + 1)), *((uint8_t *)(pkt->data + 2)), - *((uint8_t *)(pkt->data + 3)), *got_output, avctx->slices); + context->pts, (*pkt)->size, *((uint8_t *)(*pkt)->data), *((uint8_t *)((*pkt)->data + 1)), *((uint8_t *)((*pkt)->data + 2)), + *((uint8_t *)((*pkt)->data + 3)), *got_output, avctx->slices); #ifdef H263_MODE_B - fs_rtp_parse_h263_rfc2190(context, pkt); + fs_rtp_parse_h263_rfc2190(context, *pkt); #endif context->nalu_current_index = 0; + return consume_nalu(context, frame); } else if (context->av_codec_id == AV_CODEC_ID_H263P){ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG5, "Encoded frame %" SWITCH_INT64_T_FMT " (size=%5d) [0x%02x 0x%02x 0x%02x 0x%02x] got_output: %d slices: %d\n", - context->pts, pkt->size, *((uint8_t *)pkt->data), *((uint8_t *)(pkt->data + 1)), *((uint8_t *)(pkt->data + 2)), - *((uint8_t *)(pkt->data + 3)), *got_output, avctx->slices); - fs_rtp_parse_h263_rfc4629(context, pkt); + context->pts, (*pkt)->size, *((uint8_t *)(*pkt)->data), *((uint8_t *)((*pkt)->data + 1)), *((uint8_t *)((*pkt)->data + 2)), + *((uint8_t *)((*pkt)->data + 3)), *got_output, avctx->slices); + fs_rtp_parse_h263_rfc4629(context, *pkt); context->nalu_current_index = 0; + return consume_nalu(context, frame); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG5, "Encoded frame %" SWITCH_INT64_T_FMT " (size=%5d) nalu_type=0x%x %d\n", - context->pts, pkt->size, *((uint8_t *)pkt->data +4), *got_output); + context->pts, (*pkt)->size, *((uint8_t *)(*pkt)->data +4), *got_output); } - status = switch_packetizer_feed(context->packetizer, pkt->data, pkt->size); + status = switch_packetizer_feed(context->packetizer, (*pkt)->data, (*pkt)->size); if (status != SWITCH_STATUS_SUCCESS) { - if (pkt->size > 0) { - av_packet_unref(pkt); + if ((*pkt)->size > 0) { + av_packet_unref(*pkt); } return status; } status = switch_packetizer_read(context->packetizer, frame); - if (status == SWITCH_STATUS_SUCCESS && pkt->size > 0) { - av_packet_unref(pkt); + if (status == SWITCH_STATUS_SUCCESS && (*pkt)->size > 0) { + av_packet_unref(*pkt); } return status; } +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + break; + } +#endif + error: frame->datalen = 0; + return SWITCH_STATUS_FALSE; } static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t *frame) { h264_codec_context_t *context = (h264_codec_context_t *)codec->private_info; - AVCodecContext *avctx= context->decoder_ctx; switch_status_t status; +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + int ret = 0; +#endif switch_assert(frame); @@ -1654,29 +1710,57 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t if (frame->m) { uint32_t size = switch_buffer_inuse(context->nalu_buffer); - AVPacket pkt = { 0 }; + AVPacket *pkt = NULL; AVFrame *picture; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) int got_picture = 0; int decoded_len; +#endif if (size > 0) { -GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(&pkt); -GCC_DIAG_ON(deprecated-declarations) + pkt = av_packet_alloc(); switch_buffer_zero_fill(context->nalu_buffer, AV_INPUT_BUFFER_PADDING_SIZE); - switch_buffer_peek_zerocopy(context->nalu_buffer, (const void **)&pkt.data); - pkt.size = size; + switch_buffer_peek_zerocopy(context->nalu_buffer, (const void **)&pkt->data); + pkt->size = size; if (!context->decoder_avframe) context->decoder_avframe = av_frame_alloc(); picture = context->decoder_avframe; switch_assert(picture); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) GCC_DIAG_OFF(deprecated-declarations) - decoded_len = avcodec_decode_video2(avctx, picture, &got_picture, &pkt); + decoded_len = avcodec_decode_video2(context->decoder_ctx, picture, &got_picture, pkt); GCC_DIAG_ON(deprecated-declarations) +#else + ret = avcodec_send_packet(context->decoder_ctx, pkt); + + if (ret == AVERROR_EOF) { + ret = 0; + } else if (ret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each decode call, so this should not ever happen */ + ret = AVERROR_BUG; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error sending packet to decoder BUG, should never happen\n"); + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error sending packet to decoder\n"); + } + + while (ret >= 0) { + ret = avcodec_receive_frame(context->decoder_ctx, picture); + if (ret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video frames at the moment\n"); + } else if (ret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video frames at all\n"); + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Video decoding error\n"); + } +#endif // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer: %d got pic: %d len: %d [%dx%d]\n", size, got_picture, decoded_len, picture->width, picture->height); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) if (got_picture && decoded_len > 0) { +#else + if (ret >= 0) { +#endif int width = picture->width; int height = picture->height; @@ -1698,7 +1782,15 @@ GCC_DIAG_ON(deprecated-declarations) frame->img = context->img; } +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + if (ret < 0) { + break; + } + } +#endif + av_frame_unref(picture); + av_packet_free(&pkt); } switch_buffer_zero(context->nalu_buffer); @@ -1791,6 +1883,10 @@ static switch_status_t switch_h264_destroy(switch_codec_t *codec) av_frame_free(&context->decoder_avframe); } + if (context->encoder_avpacket) { + av_packet_free(&context->encoder_avpacket); + } + return SWITCH_STATUS_SUCCESS; } @@ -1818,8 +1914,10 @@ static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev, #endif if (prev->id == id && (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev))) + return prev; } + return NULL; } diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index d17f4eac39..624af8f4ea 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -25,6 +25,7 @@ * * Seven Du * Anthony Minessale + * Jakub Karolczyk * * mod_avformat -- File Formats with libav.org * @@ -88,7 +89,9 @@ typedef struct MediaStream { AVStream *st; AVFrame *frame; AVFrame *tmp_frame; - +#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_V) + AVCodecContext *codec; +#endif // audio int channels; int sample_rate; @@ -137,8 +140,13 @@ struct av_file_context { MediaStream video_st; MediaStream audio_st[2]; AVFormatContext *fc; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) AVCodec *audio_codec; AVCodec *video_codec; +#else + const AVCodec *audio_codec; + const AVCodec *video_codec; +#endif enum AVColorSpace colorspace; int has_audio; @@ -220,9 +228,57 @@ static inline char *av_ts_make_time_string(char *buf, int64_t ts, AVRational *tb static switch_status_t av_file_close(switch_file_handle_t *handle); SWITCH_MODULE_LOAD_FUNCTION(mod_avformat_load); +static inline AVCodecContext *av_get_codec_context(MediaStream *stream) +{ + AVCodecContext *c = NULL; + +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) +GCC_DIAG_OFF(deprecated-declarations) + if (stream->st) { + c = stream->st->codec; + } +GCC_DIAG_ON(deprecated-declarations) +#else + c = stream->codec; +#endif + + return c; +} + +static inline enum AVCodecID av_get_codec_id(AVStream *av_stream) +{ + if (!av_stream) { + return AV_CODEC_ID_NONE; + } + +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) +GCC_DIAG_OFF(deprecated-declarations) + return av_stream->codec->codec_id; +GCC_DIAG_ON(deprecated-declarations) +#else + return av_stream->codecpar->codec_id; +#endif +} + +static inline enum AVMediaType av_get_codec_type(AVStream *av_stream) +{ + if (!av_stream) { + return AVMEDIA_TYPE_UNKNOWN; + } + +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) +GCC_DIAG_OFF(deprecated-declarations) + return av_stream->codec->codec_type; +GCC_DIAG_ON(deprecated-declarations) +#else + return av_stream->codecpar->codec_type; +#endif +} + static char *const get_error_text(const int error, char *error_buffer, switch_size_t error_buflen) { av_strerror(error, error_buffer, error_buflen); + return error_buffer; } @@ -354,18 +410,24 @@ static int interrupt_cb(void *cp) } -static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, - const char *format, const char *filename, av_file_context_t *context) +static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, const char *format, const char *filename, av_file_context_t *context) { AVFormatContext *s = avformat_alloc_context(); int ret = 0; +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) + AVOutputFormat *oformat = NULL; +#else + const AVOutputFormat *oformat = NULL; +#endif + s->interrupt_callback.callback = interrupt_cb; s->interrupt_callback.opaque = context; - + *avctx = NULL; - if (!s) + if (!s) { goto nomem; + } if (!oformat) { if (format) { @@ -389,14 +451,17 @@ static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputF s->oformat = oformat; if (s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); - if (!s->priv_data) + if (!s->priv_data) { goto nomem; + } + if (s->oformat->priv_class) { *(const AVClass**)s->priv_data= s->oformat->priv_class; av_opt_set_defaults(s->priv_data); } - } else + } else { s->priv_data = NULL; + } if (filename) { #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,7,100)) @@ -408,12 +473,14 @@ static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputF } *avctx = s; + return 0; nomem: av_log(s, AV_LOG_ERROR, "Out of memory\n"); ret = AVERROR(ENOMEM); error: avformat_free_context(s); + return ret; } @@ -429,9 +496,13 @@ static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AV } /* Add an output stream. */ +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst, AVFormatContext *fc, AVCodec **codec, enum AVCodecID codec_id, switch_mm_t *mm) +#else +static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst, AVFormatContext *fc, const AVCodec **codec, enum AVCodecID codec_id, switch_mm_t *mm) +#endif { - AVCodecContext *c; + AVCodecContext *c = NULL; switch_status_t status = SWITCH_STATUS_FALSE; //int threads = switch_core_cpu_count(); int buffer_bytes = 2097152; /* 2 mb */ @@ -457,9 +528,19 @@ static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst, return status; } mst->st->id = fc->nb_streams - 1; -GCC_DIAG_OFF(deprecated-declarations) - c = mst->st->codec; -GCC_DIAG_ON(deprecated-declarations) + +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + mst->codec = avcodec_alloc_context3(*codec); + + if (!mst->codec) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate codec context\n"); + + return status; + } +#endif + + c = av_get_codec_context(mst); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "id:%d den:%d num:%d\n", mst->st->id, mst->st->time_base.den, mst->st->time_base.num); //if (threads > 4) { @@ -471,8 +552,12 @@ GCC_DIAG_ON(deprecated-declarations) c->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; c->bit_rate = 128000; c->sample_rate = mst->sample_rate = context->handle->samplerate; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) c->channels = mst->channels; c->channel_layout = av_get_default_channel_layout(c->channels); +#else + av_channel_layout_default(&c->ch_layout, mst->channels); +#endif if (mm) { if (mm->ab) { @@ -651,23 +736,28 @@ static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, int width, int height) return picture; } +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) static switch_status_t open_video(AVFormatContext *fc, AVCodec *codec, MediaStream *mst) +#else +static switch_status_t open_video(AVFormatContext *fc, const AVCodec *codec, MediaStream *mst) +#endif { int ret; -GCC_DIAG_OFF(deprecated-declarations) - AVCodecContext *c = mst->st->codec; -GCC_DIAG_ON(deprecated-declarations) + AVCodecContext *c = NULL; switch_status_t status = SWITCH_STATUS_FALSE; //int threads = switch_core_cpu_count(); // if (threads > 4) threads = 4; // c->thread_count = threads; + c = av_get_codec_context(mst); + /* open the codec */ ret = avcodec_open2(c, codec, NULL); if (ret < 0) { char ebuf[255] = ""; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open video codec: %s\n", get_error_text(ret, ebuf, sizeof(ebuf))); + return status; } @@ -679,17 +769,29 @@ GCC_DIAG_ON(deprecated-declarations) // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pix_fmt: %d\n", c->pix_fmt); switch_assert(c->pix_fmt == AV_PIX_FMT_YUV420P); // always I420 for NOW +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + if (((ret = avcodec_parameters_from_context(mst->st->codecpar, mst->codec)) < 0)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not copy to codec params ret=%d\n", ret); + + return SWITCH_STATUS_FALSE; + } +#endif + return SWITCH_STATUS_SUCCESS; } +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) static switch_status_t open_audio(AVFormatContext *fc, AVCodec *codec, MediaStream *mst) +#else +static switch_status_t open_audio(AVFormatContext *fc, const AVCodec *codec, MediaStream *mst) +#endif { - AVCodecContext *c; + AVCodecContext *c = NULL; int ret; switch_status_t status = SWITCH_STATUS_FALSE; -GCC_DIAG_OFF(deprecated-declarations) - c = mst->st->codec; -GCC_DIAG_ON(deprecated-declarations) + + c = av_get_codec_context(mst); + ret = avcodec_open2(c, codec, NULL); if (ret == AVERROR_EXPERIMENTAL) { @@ -711,11 +813,19 @@ GCC_DIAG_ON(deprecated-declarations) mst->frame->sample_rate = c->sample_rate; mst->frame->format = AV_SAMPLE_FMT_S16; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) mst->frame->channel_layout = c->channel_layout; +#else + mst->frame->ch_layout = c->ch_layout; +#endif if (c->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) { //mst->frame->nb_samples = 10000; - mst->frame->nb_samples = (mst->frame->sample_rate / 50) * c->channels; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + mst->frame->nb_samples = (mst->frame->sample_rate / 50) * c->channels; +#else + mst->frame->nb_samples = (mst->frame->sample_rate / 50) * c->ch_layout.nb_channels; +#endif } else { mst->frame->nb_samples = c->frame_size; } @@ -733,19 +843,33 @@ GCC_DIAG_ON(deprecated-declarations) } /* set options */ +#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) /* FFmpeg 5.0 */ av_opt_set_int(mst->resample_ctx, "in_channel_count", c->channels, 0); +#else /* FFmpeg 5.1 */ + av_opt_set_chlayout(mst->resample_ctx, "in_chlayout", &c->ch_layout, 0); +#endif av_opt_set_int(mst->resample_ctx, "in_sample_rate", c->sample_rate, 0); +#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) av_opt_set_int(mst->resample_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0); av_opt_set_int(mst->resample_ctx, "in_channel_layout", c->channel_layout, 0); av_opt_set_int(mst->resample_ctx, "out_channel_count", c->channels, 0); +#else + av_opt_set_sample_fmt(mst->resample_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0); + av_opt_set_chlayout(mst->resample_ctx, "out_chlayout", &c->ch_layout, 0); +#endif av_opt_set_int(mst->resample_ctx, "out_sample_rate", c->sample_rate, 0); +#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) av_opt_set_int(mst->resample_ctx, "out_sample_fmt", c->sample_fmt, 0); av_opt_set_int(mst->resample_ctx, "out_channel_layout", c->channel_layout, 0); +#else + av_opt_set_sample_fmt(mst->resample_ctx, "out_sample_fmt", c->sample_fmt, 0); +#endif if (swr_init(mst->resample_ctx) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to initialize the resampling context\n"); av_free(mst->resample_ctx); mst->resample_ctx = NULL; + return status; } } @@ -753,6 +877,7 @@ GCC_DIAG_ON(deprecated-declarations) ret = av_frame_get_buffer(mst->frame, 0); if (ret < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate audio frame.\n"); + return status; } @@ -762,7 +887,11 @@ GCC_DIAG_ON(deprecated-declarations) mst->tmp_frame->sample_rate = c->sample_rate; mst->tmp_frame->format = c->sample_fmt; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) mst->tmp_frame->channel_layout = c->channel_layout; +#else + mst->tmp_frame->ch_layout = c->ch_layout; +#endif mst->tmp_frame->nb_samples = mst->frame->nb_samples; ret = av_frame_get_buffer(mst->tmp_frame, 0); @@ -772,6 +901,14 @@ GCC_DIAG_ON(deprecated-declarations) } } +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + if (((ret = avcodec_parameters_from_context(mst->st->codecpar, mst->codec)) < 0)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not copy to codec params ret=%d\n", ret); + + return SWITCH_STATUS_FALSE; + } +#endif + return SWITCH_STATUS_SUCCESS; } @@ -797,8 +934,7 @@ static void flush_video_pkt_queue(switch_queue_t *q) AVPacket *pkt; while (switch_queue_trypop(q, (void **)&pkt) == SWITCH_STATUS_SUCCESS) { - av_packet_unref(pkt); - free(pkt); + av_packet_free(&pkt); } } @@ -811,12 +947,16 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void * int size = 0, skip = 0, skip_freq = 0, skip_count = 0, skip_total = 0, skip_total_count = 0; uint64_t delta_avg = 0, delta_sum = 0, delta_i = 0, delta = 0; int first = 1; + AVCodecContext *c = NULL; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "video thread start\n"); - switch_assert(context->eh.video_queue); + switch_assert(context->eh.video_queue); + for(;;) { - AVPacket pkt = { 0 }; + AVPacket *pkt = NULL; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) int got_packet; +#endif int ret = -1; top: @@ -829,7 +969,7 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void * switch_img_free(&tmp_img); } if (switch_queue_pop(context->eh.video_queue, &pop) == SWITCH_STATUS_SUCCESS) { - switch_img_free(&img); + switch_img_free(&img); if (!pop) { goto endfor; @@ -877,10 +1017,6 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void * context->eh.in_callback = 1; -GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(&pkt); -GCC_DIAG_ON(deprecated-declarations) - if (context->eh.video_st->frame) { ret = av_frame_make_writable(context->eh.video_st->frame); } @@ -892,7 +1028,7 @@ GCC_DIAG_ON(deprecated-declarations) if (context->eh.record_timer_paused) { context->eh.last_ts = 0; continue; - } + } fill_avframe(context->eh.video_st->frame, img); @@ -939,61 +1075,149 @@ GCC_DIAG_ON(deprecated-declarations) } } + pkt = av_packet_alloc(); + context->eh.last_ts = context->eh.video_st->frame->pts; // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pts: %" SWITCH_INT64_T_FMT "\n", context->eh.video_st->frame->pts); /* encode the image */ + c = av_get_codec_context(context->eh.video_st); + +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) GCC_DIAG_OFF(deprecated-declarations) - ret = avcodec_encode_video2(context->eh.video_st->st->codec, &pkt, context->eh.video_st->frame, &got_packet); + ret = avcodec_encode_video2(c, pkt, context->eh.video_st->frame, &got_packet); GCC_DIAG_ON(deprecated-declarations) - + if (ret < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding Error %d\n", ret); + c = NULL; + av_packet_free(&pkt); continue; } if (got_packet) { +#else + ret = avcodec_send_frame(c, context->eh.video_st->frame); + + if (ret == AVERROR_EOF) { + ret = 0; + } else if (ret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each encode call, so this should not ever happen */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder AVERROR_BUG - should never happen\n"); + ret = AVERROR_BUG; + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder\n"); + } + + while (ret >= 0) { + ret = avcodec_receive_packet(c, pkt); + if (ret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video packets at the moment\n"); + break; + } else if (ret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video packets at all\n"); + break; + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding error\n"); + break; + } +#endif + switch_mutex_lock(context->eh.mutex); -GCC_DIAG_OFF(deprecated-declarations) - write_frame(context->eh.fc, &context->eh.video_st->st->codec->time_base, context->eh.video_st->st, &pkt); -GCC_DIAG_ON(deprecated-declarations) + write_frame(context->eh.fc, &c->time_base, context->eh.video_st->st, pkt); switch_mutex_unlock(context->eh.mutex); - av_packet_unref(&pkt); } context->eh.in_callback = 0; + av_packet_free(&pkt); + c = NULL; //switch_mutex_unlock(context->eh.mutex); } endfor: for(;;) { - AVPacket pkt = { 0 }; - int got_packet = 0; + AVPacket *pkt = av_packet_alloc(); int ret = 0; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + int got_packet = 0; +#else + int wret = 0; +#endif + c = av_get_codec_context(context->eh.video_st); + +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(&pkt); -GCC_DIAG_ON(deprecated-declarations) - -GCC_DIAG_OFF(deprecated-declarations) - ret = avcodec_encode_video2(context->eh.video_st->st->codec, &pkt, NULL, &got_packet); + ret = avcodec_encode_video2(c, pkt, NULL, &got_packet); GCC_DIAG_ON(deprecated-declarations) if (ret < 0) { - break; + goto do_break; } else if (got_packet) { - switch_mutex_lock(context->eh.mutex); -GCC_DIAG_OFF(deprecated-declarations) - ret = write_frame(context->eh.fc, &context->eh.video_st->st->codec->time_base, context->eh.video_st->st, &pkt); -GCC_DIAG_ON(deprecated-declarations) - switch_mutex_unlock(context->eh.mutex); - av_packet_unref(&pkt); - if (ret < 0) break; - } else { +#else + ret = avcodec_send_frame(c, NULL); + + if (ret == AVERROR_EOF) { + ret = 0; + } else if (ret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each encode call, so this should not ever happen */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder on draining AVERROR_BUG - should never happen\n"); + ret = AVERROR_BUG; + goto do_break; + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder on draining\n"); + c = NULL; + goto do_break; + } + + while (ret >= 0) { + ret = avcodec_receive_packet(c, pkt); + if (ret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video packets at the moment on draining\n"); + break; + } else if (ret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video packets at all on draining \n"); + break; + } else if (ret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding error on draining\n"); break; } +#endif + switch_mutex_lock(context->eh.mutex); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + ret = write_frame(context->eh.fc, &c->time_base, context->eh.video_st->st, pkt); +#else + wret = write_frame(context->eh.fc, &c->time_base, context->eh.video_st->st, pkt); +#endif + switch_mutex_unlock(context->eh.mutex); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + if (ret < 0) { + goto do_break; + } + } else { + goto do_break; +#else + if (wret < 0) { + goto do_break; + } +#endif + } + + av_packet_free(&pkt); + c = NULL; + +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + if (ret < 0 && ret != AVERROR(EAGAIN)) { + break; + } +#endif + + continue; + do_break: + av_packet_free(&pkt); + break; } while(switch_queue_trypop(context->eh.video_queue, &pop) == SWITCH_STATUS_SUCCESS) { @@ -1010,6 +1234,8 @@ GCC_DIAG_ON(deprecated-declarations) static void close_stream(AVFormatContext *fc, MediaStream *mst) { + AVCodecContext *c = NULL; + if (!mst->active) return; if (mst->resample_ctx) swr_free(&mst->resample_ctx); @@ -1017,12 +1243,13 @@ static void close_stream(AVFormatContext *fc, MediaStream *mst) if (mst->frame) av_frame_free(&mst->frame); if (mst->tmp_frame) av_frame_free(&mst->tmp_frame); -GCC_DIAG_OFF(deprecated-declarations) - if (mst->st && mst->st->codec) { - avcodec_close(mst->st->codec); - } -GCC_DIAG_ON(deprecated-declarations) - + c = av_get_codec_context(mst); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + avcodec_close(c); +#else + /* avcodec_close() will be called in avcodec_free_context() */ + avcodec_free_context(&c); +#endif mst->active = 0; } @@ -1140,8 +1367,15 @@ static void mod_avformat_destroy_output_context(av_file_context_t *context) static switch_status_t open_input_file(av_file_context_t *context, switch_file_handle_t *handle, const char *filename) { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) AVCodec *audio_codec = NULL; AVCodec *video_codec = NULL; +#else + const AVCodec *audio_codec = NULL; + const AVCodec *video_codec = NULL; +#endif + enum AVCodecID codec_id; + AVCodecContext *cc = NULL; AVDictionary *opts = NULL; int error; int i, idx = 0; @@ -1151,7 +1385,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h /** Open the input file to read from it. */ - if (!context->fc) { + if (!context->fc) { context->fc = avformat_alloc_context(); } @@ -1170,7 +1404,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h context->fc = NULL; switch_goto_status(SWITCH_STATUS_FALSE, err); } - + handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "file %s is %sseekable\n", filename, handle->seekable ? "" : "not "); @@ -1187,15 +1421,16 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h av_dump_format(context->fc, 0, filename, 0); for (i = 0; i< context->fc->nb_streams; i++) { -GCC_DIAG_OFF(deprecated-declarations) - if (context->fc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && context->has_audio < 2 && idx < 2) { + enum AVMediaType codec_type = av_get_codec_type(context->fc->streams[i]); + + if (codec_type == AVMEDIA_TYPE_AUDIO && context->has_audio < 2 && idx < 2) { context->audio_st[idx++].st = context->fc->streams[i]; context->has_audio++; - } else if (context->fc->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && !context->has_video) { -GCC_DIAG_ON(deprecated-declarations) + } else if (codec_type == AVMEDIA_TYPE_VIDEO && !context->has_video) { context->video_st.st = context->fc->streams[i]; if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) { context->has_video = 1; +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) handle->duration = av_rescale_q(context->video_st.st->duration != AV_NOPTS_VALUE ? context->video_st.st->duration : context->fc->duration / AV_TIME_BASE * 1000, context->video_st.st->time_base, AV_TIME_BASE_Q); } @@ -1211,42 +1446,95 @@ GCC_DIAG_ON(deprecated-declarations) } context->read_fps = (int)handle->mm.source_fps; +#else + } +#endif } } /** Find a decoder for the audio stream. */ -GCC_DIAG_OFF(deprecated-declarations) - if (context->has_audio && !(audio_codec = avcodec_find_decoder(context->audio_st[0].st->codec->codec_id))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not find input codec %d\n", context->audio_st[0].st->codec->codec_id); + if (context->has_audio && !(audio_codec = avcodec_find_decoder((codec_id = av_get_codec_id(context->audio_st[0].st))))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not find input codec %d\n", codec_id); context->has_audio = 0; } - if (context->has_video && !(video_codec = avcodec_find_decoder(context->video_st.st->codec->codec_id))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find input codec %d\n", context->video_st.st->codec->codec_id); + if (context->has_video && !(video_codec = avcodec_find_decoder((codec_id = av_get_codec_id(context->video_st.st))))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find input codec %d\n", codec_id); context->has_video = 0; } - if (context->has_audio && (error = avcodec_open2(context->audio_st[0].st->codec, audio_codec, NULL)) < 0) { +#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_V) + if (context->has_audio == 2) { + context->audio_st[1].codec = avcodec_alloc_context3(audio_codec); + context->audio_st[0].codec = avcodec_alloc_context3(audio_codec); + } else if (context->has_audio) { + context->audio_st[0].codec = avcodec_alloc_context3(audio_codec); + } + + if (context->has_video) { + context->video_st.codec = avcodec_alloc_context3(video_codec); + } +#endif + + cc = av_get_codec_context(&context->audio_st[0]); +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) + if (context->has_audio && ((error = avcodec_open2(cc, audio_codec, NULL)) < 0)) { +#else + if (context->has_audio && (((error = avcodec_parameters_to_context(cc, context->audio_st[0].st->codecpar)) < 0) || ((error = avcodec_open2(cc, audio_codec, NULL)) < 0))) { +#endif char ebuf[255] = ""; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open input audio codec (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); context->has_audio = 0; } - if (context->has_audio == 2 && (error = avcodec_open2(context->audio_st[1].st->codec, audio_codec, NULL)) < 0) { + cc = av_get_codec_context(&context->audio_st[1]); +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) + if (context->has_audio == 2 && ((error = avcodec_open2(cc, audio_codec, NULL)) < 0)) { +#else + if (context->has_audio == 2 && (((error = avcodec_parameters_to_context(cc, context->audio_st[1].st->codecpar)) < 0) || ((error = avcodec_open2(cc, audio_codec, NULL)) < 0))) { +#endif char ebuf[255] = ""; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open input audio codec channel 2 (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); - if (context->audio_st[0].st->codec) { - avcodec_close(context->audio_st[0].st->codec); + if ((cc = av_get_codec_context(&context->audio_st[0]))) { + avcodec_close(cc); } + context->has_audio = 0; } - if (context->has_video && (error = avcodec_open2(context->video_st.st->codec, video_codec, NULL)) < 0) { + cc = av_get_codec_context(&context->video_st); + +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) + if (context->has_video && (error = avcodec_open2(cc, video_codec, NULL)) < 0) { +#else + if (context->has_video) { + if (((error = avcodec_parameters_to_context(cc, context->video_st.st->codecpar)) < 0) || ((error = avcodec_open2(cc, video_codec, NULL)) < 0)) { +#endif char ebuf[255] = ""; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open input codec (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); context->has_video = 0; } -GCC_DIAG_ON(deprecated-declarations) + +#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_V) + handle->duration = av_rescale_q(context->video_st.st->duration != AV_NOPTS_VALUE ? context->video_st.st->duration : context->fc->duration / AV_TIME_BASE * 1000, + context->video_st.st->time_base, AV_TIME_BASE_Q); + + if (context->fc->bit_rate) { + handle->mm.source_kps = context->fc->bit_rate / 1024; + } + + if (context->video_st.st->avg_frame_rate.num) { + handle->mm.source_fps = ceil(av_q2d(context->video_st.st->avg_frame_rate)); + } else { + handle->mm.source_fps = 25; + } + + context->read_fps = (int)handle->mm.source_fps; + + } +#endif context->video_st.active = 1; @@ -1258,16 +1546,14 @@ GCC_DIAG_ON(deprecated-declarations) } if (context->has_audio) { -GCC_DIAG_OFF(deprecated-declarations) AVCodecContext *c[2] = { NULL }; - c[0] = context->audio_st[0].st->codec; + c[0] = av_get_codec_context(&context->audio_st[0]); - if (context->audio_st[1].st && context->audio_st[1].st->codec) { - c[1] = context->audio_st[1].st->codec; + if ((cc = av_get_codec_context(&context->audio_st[1]))) { + c[1] = cc; } -GCC_DIAG_ON(deprecated-declarations) - + context->audio_st[0].frame = av_frame_alloc(); switch_assert(context->audio_st[0].frame); @@ -1282,33 +1568,49 @@ GCC_DIAG_ON(deprecated-declarations) context->audio_st[0].channels = 1; context->audio_st[1].channels = 1; } else { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVFORMAT_V) handle->channels = c[0]->channels > 2 ? 2 : c[0]->channels; +#else + handle->channels = c[0]->ch_layout.nb_channels > 2 ? 2 : c[0]->ch_layout.nb_channels; +#endif context->audio_st[0].channels = handle->channels; } context->audio_st[0].sample_rate = handle->samplerate; context->audio_st[1].sample_rate = handle->samplerate; -GCC_DIAG_OFF(deprecated-declarations) - if (context->audio_st[0].st->codec->sample_fmt != AV_SAMPLE_FMT_S16 || context->audio_st[0].st->codec->sample_rate != handle->samplerate) { -GCC_DIAG_ON(deprecated-declarations) + if (c[0]->sample_fmt != AV_SAMPLE_FMT_S16 || c[0]->sample_rate != handle->samplerate) { int x; + for (x = 0; x < context->has_audio && x < 2 && c[x]; x++) { struct SwrContext *resample_ctx = swr_alloc(); if (resample_ctx) { int ret; - + +#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) /* FFmpeg 5.0 */ av_opt_set_int(resample_ctx, "in_channel_count", c[x]->channels, 0); +#else /* FFmpeg 5.1 */ + av_opt_set_chlayout(resample_ctx, "in_chlayout", &c[x]->ch_layout, 0); +#endif av_opt_set_int(resample_ctx, "in_sample_rate", c[x]->sample_rate, 0); +#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) av_opt_set_int(resample_ctx, "in_sample_fmt", c[x]->sample_fmt, 0); av_opt_set_int(resample_ctx, "in_channel_layout", (c[x]->channel_layout == 0 && c[x]->channels == 2) ? AV_CH_LAYOUT_STEREO : c[x]->channel_layout, 0); av_opt_set_int(resample_ctx, "out_channel_count", handle->channels, 0); +#else + av_opt_set_sample_fmt(resample_ctx, "in_sample_fmt", c[x]->sample_fmt, 0); + av_opt_set_chlayout(resample_ctx, "out_chlayout", &c[x]->ch_layout, 0); +#endif av_opt_set_int(resample_ctx, "out_sample_rate", handle->samplerate,0); +#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) av_opt_set_int(resample_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); av_opt_set_int(resample_ctx, "out_channel_layout", handle->channels == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO, 0); - +#else + av_opt_set_sample_fmt(resample_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); +#endif + if ((ret = swr_init(resample_ctx)) < 0) { char errbuf[1024]; av_strerror(ret, errbuf, 1024); @@ -1327,8 +1629,11 @@ GCC_DIAG_ON(deprecated-declarations) if (!context->has_video) { switch_clear_flag(handle, SWITCH_FILE_FLAG_VIDEO); } else { -GCC_DIAG_OFF(deprecated-declarations) - switch (context->video_st.st->codec->pix_fmt) { + if (!(cc = av_get_codec_context(&context->video_st))) { + goto err; + } + + switch (cc->pix_fmt) { case AV_PIX_FMT_YUVA420P: case AV_PIX_FMT_RGBA: case AV_PIX_FMT_ARGB: @@ -1339,8 +1644,7 @@ GCC_DIAG_OFF(deprecated-declarations) context->handle->mm.fmt = SWITCH_IMG_FMT_I420; break; } -GCC_DIAG_ON(deprecated-declarations) - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening file in mode: %s\n", context->handle->mm.fmt == SWITCH_IMG_FMT_ARGB ? "ARGB" : "I420"); } @@ -1372,12 +1676,20 @@ err: static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, void *obj) { av_file_context_t *context = (av_file_context_t *) obj; - AVPacket pkt = { 0 }; + AVPacket *pkt = NULL; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) int got_data = 0; +#else + int dret = -1; +#endif int error; int sync = 0; int eof = 0; - + AVCodecContext *c = NULL; +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + AVFrame *vframe = NULL; +#endif + switch_mutex_lock(context->mutex); context->file_read_thread_started = 1; context->file_read_thread_running = 1; @@ -1394,8 +1706,6 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo switch_buffer_zero(context->audio_buffer); switch_mutex_unlock(context->mutex); - - // if (context->has_audio) stream_id = context->audio_st.st->index; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "seeking to %" SWITCH_INT64_T_FMT "\n", context->seek_ts); avformat_seek_file(context->fc, stream_id, 0, context->seek_ts, INT64_MAX, 0); @@ -1406,10 +1716,12 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo context->video_st.next_pts = 0; context->video_start_time = 0; -GCC_DIAG_OFF(deprecated-declarations) - avcodec_flush_buffers(context->video_st.st->codec); -GCC_DIAG_ON(deprecated-declarations) - + if (!(c = av_get_codec_context(&context->video_st))) { + break; + } + + avcodec_flush_buffers(c); + while(switch_queue_trypop(context->eh.video_queue, &pop) == SWITCH_STATUS_SUCCESS) { switch_image_t *img; if (!pop) break; @@ -1429,23 +1741,18 @@ GCC_DIAG_ON(deprecated-declarations) continue; } + if (pkt) av_packet_free(&pkt); + pkt = av_packet_alloc(); - -GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(&pkt); -GCC_DIAG_ON(deprecated-declarations) - pkt.data = NULL; - pkt.size = 0; - - if ((error = av_read_frame(context->fc, &pkt)) < 0) { + if ((error = av_read_frame(context->fc, pkt)) < 0) { if (error == AVERROR_EOF) { if (!context->has_video) break; eof = 1; /* just make sure*/ - pkt.data = NULL; - pkt.size = 0; - pkt.stream_index = context->video_st.st->index; + pkt->data = NULL; + pkt->size = 0; + pkt->stream_index = context->video_st.st->index; } else { char ebuf[255] = ""; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not read frame (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); @@ -1454,8 +1761,11 @@ GCC_DIAG_ON(deprecated-declarations) } // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "stream: %d, pkt size %d\n", pkt.stream_index, pkt.size); - if (context->has_video && pkt.stream_index == context->video_st.st->index) { - AVFrame *vframe; + + if (context->has_video && pkt->stream_index == context->video_st.st->index) { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + AVFrame *vframe = NULL; +#endif switch_image_t *img; if (context->no_video_decode) { @@ -1463,26 +1773,22 @@ GCC_DIAG_ON(deprecated-declarations) break; } else { switch_status_t status; - AVPacket *new_pkt = malloc(sizeof(AVPacket)); + AVPacket *new_pkt = av_packet_alloc(); if (0) { // debug - uint8_t *p = pkt.data; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "size = %u %x %x %x %x %x %x\n", pkt.size, *p, *(p+1), *(p+2), *(p+3), *(p+4), *(p+5)); + uint8_t *p = pkt->data; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "size = %u %x %x %x %x %x %x\n", pkt->size, *p, *(p+1), *(p+2), *(p+3), *(p+4), *(p+5)); } -GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(new_pkt); -GCC_DIAG_ON(deprecated-declarations) - av_packet_ref(new_pkt, &pkt); + av_packet_ref(new_pkt, pkt); status = switch_queue_push(context->video_pkt_queue, new_pkt); // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "size = %4u flag=%x pts=%" SWITCH_INT64_T_FMT " dts=%" SWITCH_INT64_T_FMT "\n", pkt.size, pkt.flags, pkt.pts, pkt.dts); context->vid_ready = 1; if (status != SWITCH_STATUS_SUCCESS) { - av_packet_unref(new_pkt); - free(new_pkt); + av_packet_free(&new_pkt); } - av_packet_unref(&pkt); + continue; } } @@ -1496,18 +1802,57 @@ again: vframe = av_frame_alloc(); switch_assert(vframe); + if (!(c = av_get_codec_context(&context->video_st))) { + break; + } + +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) GCC_DIAG_OFF(deprecated-declarations) - if ((error = avcodec_decode_video2(context->video_st.st->codec, vframe, &got_data, &pkt)) < 0) { + error = avcodec_decode_video2(c, vframe, &got_data, pkt); GCC_DIAG_ON(deprecated-declarations) +#else + if (eof) { + dret = avcodec_send_packet(c, NULL); + } else { + dret = avcodec_send_packet(c, pkt); + } + + if (dret == AVERROR_EOF) { + dret = 0; + } else if (dret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each decode call, so this should not ever happen */ + dret = AVERROR_BUG; + goto check_errors; + } else if (dret < 0) { + goto check_errors; + } + + while (dret >= 0) { + dret = avcodec_receive_frame(c, vframe); + if (dret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video frames at the moment\n"); + } else if (dret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more video frames at all\n"); + } else if (dret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Video decoding error\n"); + } +#endif + +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + check_errors: + if (dret < 0 && dret != AVERROR(EAGAIN) && dret != AVERROR_EOF) { +#else + if (error < 0) { +#endif char ebuf[255] = ""; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not decode frame (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); - av_packet_unref(&pkt); av_frame_free(&vframe); continue; } // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pkt: %d, pts: %lld dts: %lld\n", pkt.size, pkt.pts, pkt.dts); - av_packet_unref(&pkt); + av_packet_unref(pkt); //if (switch_queue_size(context->eh.video_queue) > 300) { // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Dropping frames\n"); @@ -1516,7 +1861,11 @@ GCC_DIAG_ON(deprecated-declarations) //} // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "got_data=%d, error=%d\n", got_data, error); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) if (got_data && error >= 0) { +#else + if (dret >= 0) { +#endif switch_img_fmt_t fmt = SWITCH_IMG_FMT_I420; if (( vframe->format == AV_PIX_FMT_YUVA420P || @@ -1538,7 +1887,7 @@ GCC_DIAG_ON(deprecated-declarations) if (!context->video_st.sws_ctx) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot init sws context\n"); av_frame_free(&frm); - continue; + goto do_continue; } } @@ -1549,9 +1898,11 @@ GCC_DIAG_ON(deprecated-declarations) vframe->width = frm->width; vframe->height = frm->height; vframe->pts = frm->pts; +#if (LIBAVUTIL_VERSION_MAJOR < LIBAVUTIL_V) GCC_DIAG_OFF(deprecated-declarations) vframe->pkt_pts = frm->pkt_pts; GCC_DIAG_ON(deprecated-declarations) +#endif vframe->pkt_dts = frm->pkt_dts; ret = av_frame_get_buffer(vframe, 32); @@ -1564,7 +1915,7 @@ GCC_DIAG_ON(deprecated-declarations) if (ret <= 0 ) { av_frame_free(&vframe); - continue; + goto do_continue; } } @@ -1580,9 +1931,13 @@ GCC_DIAG_ON(deprecated-declarations) int diff; int sleep = 66000; #endif +#if (LIBAVUTIL_VERSION_MAJOR < LIBAVUTIL_V) GCC_DIAG_OFF(deprecated-declarations) *pts = vframe->pkt_pts; GCC_DIAG_ON(deprecated-declarations) +#else + *pts = vframe->pts; +#endif avframe2img(vframe, img); img->user_priv = pts; @@ -1605,32 +1960,83 @@ GCC_DIAG_ON(deprecated-declarations) } } +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) av_frame_free(&vframe); +#endif if (eof) { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) if (got_data) { +#else + if (dret != AVERROR_EOF) { +#endif +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) goto again; // to get all delayed video frames in decoder +#else + av_frame_free(&vframe); + goto again; // to get all delayed video frames in decoder +#endif } else { - break; + goto do_break; } } - continue; - } else if (context->has_audio && pkt.stream_index == context->audio_st[0].st->index) { + +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + } + + av_frame_free(&vframe); +#endif + goto do_continue; + } else if (context->has_audio && pkt->stream_index == context->audio_st[0].st->index) { AVFrame in_frame = { { 0 } }; -GCC_DIAG_OFF(deprecated-declarations) - if ((error = avcodec_decode_audio4(context->audio_st[0].st->codec, &in_frame, &got_data, &pkt)) < 0) { -GCC_DIAG_ON(deprecated-declarations) - char ebuf[255] = ""; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not decode frame (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); - av_packet_unref(&pkt); + if (!(c = av_get_codec_context(&context->audio_st[0]))) { continue; } - // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pkt: %d, decodedddd: %d pts: %lld dts: %lld\n", pkt.size, error, pkt.pts, pkt.dts); - av_packet_unref(&pkt); +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) +GCC_DIAG_OFF(deprecated-declarations) + if ((error = avcodec_decode_audio4(c, &in_frame, &got_data, pkt)) < 0) { +GCC_DIAG_ON(deprecated-declarations) + char ebuf[255] = ""; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not decode frame (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf))); + continue; + } +#else + dret = avcodec_send_packet(c, pkt); + if (dret == AVERROR_EOF) { + dret = 0; + } else if (dret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each decode call, so this should not ever happen */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending audio packet to decoder - BUG, should never happen\n"); + dret = AVERROR_BUG; + goto do_continue; + } else if (dret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending audio packet to decoder\n"); + goto do_continue; + } + + while (dret >= 0) { + dret = avcodec_receive_frame(c, &in_frame); + if (dret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more audio frames at the moment\n"); + } else if (dret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more audio frames at all\n"); + } else if (dret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Video decoding error\n"); + goto do_continue; + } +#endif + + // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pkt: %d, decodedddd: %d pts: %lld dts: %lld\n", pkt.size, error, pkt.pts, pkt.dts); + av_packet_unref(pkt); + +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) if (got_data) { +#else + if (dret >= 0) { +#endif // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "got data frm->format: %d samples: %d\n", in_frame.format, in_frame.nb_samples); if (context->audio_st[0].resample_ctx) { @@ -1669,12 +2075,26 @@ GCC_DIAG_ON(deprecated-declarations) } } - - } else { - av_packet_unref(&pkt); +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + } } +#else + } else { + av_packet_unref(pkt); + } +#endif + + do_continue: + continue; + do_break: + break; } + av_packet_free(&pkt); +#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_V) + av_frame_free(&vframe); +#endif + if (context->has_video) switch_queue_push(context->eh.video_queue, NULL); context->file_read_thread_running = 0; @@ -1687,7 +2107,13 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa av_file_context_t *context = NULL; char *ext; const char *tmp = NULL; +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) AVOutputFormat *fmt; +#else + const AVOutputFormat *fmt; + enum AVCodecID video_codec = AV_CODEC_ID_NONE; + enum AVCodecID audio_codec = AV_CODEC_ID_NONE; +#endif const char *format = NULL; int ret; char file[1024]; @@ -1805,18 +2231,28 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa return SWITCH_STATUS_SUCCESS; } - mod_avformat_alloc_output_context2(&context->fc, NULL, format, (char *)file, context); + mod_avformat_alloc_output_context2(&context->fc, format, (char *)file, context); if (!context->fc) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not deduce output format from file extension\n"); switch_goto_status(SWITCH_STATUS_GENERR, end); } +#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_V) + fmt = context->fc->oformat; + video_codec = fmt->video_codec; + audio_codec = fmt->audio_codec; +#endif + fmt = context->fc->oformat; if (handle->params && (tmp = switch_event_get_header(handle->params, "av_audio_codec"))) { if ((context->audio_codec = avcodec_find_encoder_by_name(tmp))) { +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) fmt->audio_codec = context->audio_codec->id; +#else + audio_codec = context->audio_codec->id; +#endif switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "specified audio codec %s %s [%s]\n", tmp, context->audio_codec->name, context->audio_codec->long_name); @@ -1837,7 +2273,11 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa if (handle->params && (tmp = switch_event_get_header(handle->params, "av_video_codec"))) { if ((context->video_codec = avcodec_find_encoder_by_name(tmp))) { +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) fmt->video_codec = context->video_codec->id; +#else + video_codec = context->video_codec->id; +#endif switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "specified video codec %s %s [%s]\n", tmp, context->video_codec->name, context->video_codec->long_name); } @@ -1874,16 +2314,28 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa handle->mm.vb = switch_calc_bitrate(handle->mm.vw, handle->mm.vh, 1, handle->mm.fps); } +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO) && fmt->video_codec != AV_CODEC_ID_NONE) { +#else + if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO) && video_codec != AV_CODEC_ID_NONE) { +#endif const AVCodecDescriptor *desc; if ((handle->stream_name && (!strcasecmp(handle->stream_name, "rtmp") || !strcasecmp(handle->stream_name, "rtmps") || !strcasecmp(handle->stream_name, "youtube")))) { - +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) if (fmt->video_codec != AV_CODEC_ID_H264 ) { fmt->video_codec = AV_CODEC_ID_H264; // force H264 +#else + if (video_codec != AV_CODEC_ID_H264 ) { + video_codec = AV_CODEC_ID_H264; // force H264 +#endif } +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) fmt->audio_codec = AV_CODEC_ID_AAC; +#else + audio_codec = AV_CODEC_ID_AAC; +#endif handle->samplerate = 44100; handle->mm.samplerate = 44100; handle->mm.ab = 128; @@ -1919,12 +2371,21 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa } } +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) desc = avcodec_descriptor_get(fmt->video_codec); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "use video codec: [%d] %s (%s)\n", fmt->video_codec, desc->name, desc->long_name); +#else + desc = avcodec_descriptor_get(video_codec); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "use video codec: [%d] %s (%s)\n", video_codec, desc->name, desc->long_name); +#endif } +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) if (fmt->audio_codec != AV_CODEC_ID_NONE) { +#else + if (audio_codec != AV_CODEC_ID_NONE) { +#endif const char *issplit = 0; context->audio_st[0].channels = handle->channels; @@ -1937,8 +2398,13 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa if (lr || rl) { context->audio_st[0].channels = 1; context->audio_st[1].channels = 1; +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) add_stream(context, &context->audio_st[0], context->fc, &context->audio_codec, fmt->audio_codec, &handle->mm); add_stream(context, &context->audio_st[1], context->fc, &context->audio_codec, fmt->audio_codec, &handle->mm); +#else + add_stream(context, &context->audio_st[0], context->fc, &context->audio_codec, audio_codec, &handle->mm); + add_stream(context, &context->audio_st[1], context->fc, &context->audio_codec, audio_codec, &handle->mm); +#endif } if (lr) { @@ -1949,7 +2415,11 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa } if (!context->audio_st[0].active) { +#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_V) add_stream(context, &context->audio_st[0], context->fc, &context->audio_codec, fmt->audio_codec, &handle->mm); +#else + add_stream(context, &context->audio_st[0], context->fc, &context->audio_codec, audio_codec, &handle->mm); +#endif } if (open_audio(context->fc, context->audio_codec, &context->audio_st[0]) != SWITCH_STATUS_SUCCESS) { @@ -2022,11 +2492,16 @@ static switch_status_t av_file_write(switch_file_handle_t *handle, void *data, s uint32_t bytes; int inuse; int sample_start = 0; + AVCodecContext *c = NULL; if (!switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { return SWITCH_STATUS_FALSE; } + if (!context->has_audio) { + return SWITCH_STATUS_SUCCESS; + } + if (!context->vid_ready) { if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) { switch_buffer_zero(context->audio_buffer); @@ -2059,9 +2534,7 @@ static switch_status_t av_file_write(switch_file_handle_t *handle, void *data, s switch_buffer_write(context->audio_buffer, data, datalen); } -GCC_DIAG_OFF(deprecated-declarations) bytes = context->audio_st[0].frame->nb_samples * 2 * context->handle->channels; //context->audio_st[0].st->codec->channels; -GCC_DIAG_ON(deprecated-declarations) //{ // int inuse = switch_buffer_inuse(context->audio_buffer); @@ -2105,15 +2578,18 @@ GCC_DIAG_ON(deprecated-declarations) } while (switch_buffer_inuse(context->audio_buffer) >= bytes) { - AVPacket pkt[2] = { {0} }; + AVPacket *pkt[2]; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) int got_packet[2] = {0}; + int result[2] = {0}; +#else + int dret = -1; +#endif int j = 0, ret = -1, audio_stream_count = 1; AVFrame *use_frame = NULL; -GCC_DIAG_OFF(deprecated-declarations) - av_init_packet(&pkt[0]); - av_init_packet(&pkt[1]); -GCC_DIAG_ON(deprecated-declarations) + pkt[0] = av_packet_alloc(); + pkt[1] = av_packet_alloc(); if (context->audio_st[1].active) { switch_size_t len = 0; @@ -2149,17 +2625,17 @@ GCC_DIAG_ON(deprecated-declarations) if (context->audio_st[j].resample_ctx) { int out_samples = swr_get_out_samples(context->audio_st[j].resample_ctx, context->audio_st[j].frame->nb_samples); - av_frame_make_writable(context->audio_st[j].tmp_frame); + av_frame_make_writable(context->audio_st[j].tmp_frame); /* convert to destination format */ ret = swr_convert(context->audio_st[j].resample_ctx, - context->audio_st[j].tmp_frame->data, out_samples, - (const uint8_t **)context->audio_st[j].frame->data, context->audio_st[j].frame->nb_samples); + context->audio_st[j].tmp_frame->data, out_samples, + (const uint8_t **)context->audio_st[j].frame->data, context->audio_st[j].frame->nb_samples); if (ret < 0) { char ebuf[255] = ""; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error while converting %d samples, error text: %s\n", - context->audio_st[j].frame->nb_samples, get_error_text(ret, ebuf, sizeof(ebuf))); + context->audio_st[j].frame->nb_samples, get_error_text(ret, ebuf, sizeof(ebuf))); continue; } @@ -2170,24 +2646,90 @@ GCC_DIAG_ON(deprecated-declarations) // context->audio_st[j].next_pts = use_frame->pts + use_frame->nb_samples; -GCC_DIAG_OFF(deprecated-declarations) - ret = avcodec_encode_audio2(context->audio_st[j].st->codec, &pkt[j], use_frame, &got_packet[j]); -GCC_DIAG_ON(deprecated-declarations) + if (!(c = av_get_codec_context(&context->audio_st[j]))) { + continue; + } +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) +GCC_DIAG_OFF(deprecated-declarations) + result[j] = avcodec_encode_audio2(c, pkt[j], use_frame, &got_packet[j]); +GCC_DIAG_ON(deprecated-declarations) +#else + dret = avcodec_send_frame(c, use_frame); + + if (dret == AVERROR_EOF) { + dret = 0; + } else if (dret == AVERROR(EAGAIN)) { + /* we fully drain all the output in each decode call, so this should not ever happen */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Encoding error for channel %d on sending frame to encode - BUG, should never happen\n", j); + dret = AVERROR_BUG; + } else if (dret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding error for channel %d on sending frame to encode\n", j); + } + + while (dret >= 0) { + dret = avcodec_receive_packet(c, pkt[j]); + if (dret == AVERROR(EAGAIN)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more audio packets at the moment for channel %d\n", j); + break; + } else if (dret == AVERROR_EOF) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "No more audio packets at all for channel %d\n", j); + break; + } else if (dret < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Encoding error for channel %d\n", j); + break; + } + + if (context->mutex) switch_mutex_lock(context->mutex); + + ret = write_frame(context->fc, &c->time_base, context->audio_st[j].st, pkt[j]); + + if (context->mutex) switch_mutex_unlock(context->mutex); + + if (ret < 0) { + context->errs++; + if ((context->errs % 10) == 0) { + char ebuf[255] = ""; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error while writing audio frame: %d %s\n", ret, get_error_text(ret, ebuf, sizeof(ebuf))); + if ((ret == -5 || ret == -104) && handle->stream_name) { + context->errs = 1001; + } + } + //switch_goto_status(SWITCH_STATUS_FALSE, end); + } else { + context->errs = 0; + } + + if (context->errs > 1000) { + av_packet_free(&pkt[0]); + av_packet_free(&pkt[1]); + switch_goto_status(SWITCH_STATUS_FALSE, end); + } + } +#endif context->audio_st[j].next_pts += use_frame->nb_samples; - } - - if (ret < 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error encoding audio frame: %d\n", ret); + } + +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) + if (result[0] < 0 || result[1] < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error encoding audio frame: %d %d \n", result[0], result[1]); + av_packet_free(&pkt[0]); + av_packet_free(&pkt[1]); continue; } - + for (j = 0; j < audio_stream_count; j++) { if (got_packet[j]) { if (context->mutex) switch_mutex_lock(context->mutex); -GCC_DIAG_OFF(deprecated-declarations) - ret = write_frame(context->fc, &context->audio_st[j].st->codec->time_base, context->audio_st[j].st, &pkt[j]); -GCC_DIAG_ON(deprecated-declarations) + + if (!(c = av_get_codec_context(&context->audio_st[j]))) { + if (context->mutex) switch_mutex_unlock(context->mutex); + continue; + } + + ret = write_frame(context->fc, &c->time_base, context->audio_st[j].st, pkt[j]); + if (context->mutex) switch_mutex_unlock(context->mutex); if (ret < 0) { @@ -2207,6 +2749,10 @@ GCC_DIAG_ON(deprecated-declarations) } } } +#endif + + av_packet_free(&pkt[0]); + av_packet_free(&pkt[1]); } end: @@ -2479,10 +3025,10 @@ static switch_status_t no_video_decode_packets(switch_file_handle_t *handle, swi if (context->last_read_pkt) { status = switch_packetizer_read(context->packetizer, frame); if (status == SWITCH_STATUS_SUCCESS) { - av_packet_unref(context->last_read_pkt); - free(context->last_read_pkt); + av_packet_free(&context->last_read_pkt); context->last_read_pkt = NULL; } + return status; } @@ -2490,6 +3036,7 @@ static switch_status_t no_video_decode_packets(switch_file_handle_t *handle, swi if (status != SWITCH_STATUS_SUCCESS || !pkt) { switch_cond_next(); + return SWITCH_STATUS_BREAK; } @@ -2501,12 +3048,10 @@ static switch_status_t no_video_decode_packets(switch_file_handle_t *handle, swi // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "pts=%" SWITCH_INT64_T_FMT " status = %d\n", pts, status); if (status == SWITCH_STATUS_SUCCESS) { - av_packet_unref(context->last_read_pkt); - free(context->last_read_pkt); + av_packet_free(&context->last_read_pkt); context->last_read_pkt = NULL; } - if (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_MORE_DATA) { if (!context->video_start_time) { context->video_start_time = switch_time_now() - pts; @@ -2541,6 +3086,8 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f double fl_to = 0.02; int do_fl = 0; int smaller_ts = context->read_fps; + AVCodecContext *c = NULL; + AVCodecParserContext *cp = NULL; if (!context->has_video) return SWITCH_STATUS_FALSE; @@ -2648,18 +3195,17 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f } #endif -GCC_DIAG_OFF(deprecated-declarations) - if (st->codec->time_base.num) { - ticks = st->parser ? st->parser->repeat_pict + 1 : st->codec->ticks_per_frame; + if ((c = av_get_codec_context(mst)) && c->time_base.num) { + cp = av_stream_get_parser(st); + ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame; // mst->next_pts += ((int64_t)AV_TIME_BASE * st->codec->time_base.num * ticks) / st->codec->time_base.den; } if (!context->video_start_time) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "start: %" SWITCH_INT64_T_FMT " ticks: %d ticks_per_frame: %d st num:%d st den:%d codec num:%d codec den:%d start: %" SWITCH_TIME_T_FMT ", duration:%" SWITCH_INT64_T_FMT " nb_frames:%" SWITCH_INT64_T_FMT " q2d:%f\n", - context->video_start_time, ticks, st->codec->ticks_per_frame, st->time_base.num, st->time_base.den, st->codec->time_base.num, st->codec->time_base.den, + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "start: %" SWITCH_INT64_T_FMT " ticks: %d ticks_per_frame: %d st num:%d st den:%d codec num:%d codec den:%d start: %" SWITCH_TIME_T_FMT ", duration:%" SWITCH_INT64_T_FMT " nb_frames:%" SWITCH_INT64_T_FMT " q2d:%f\n", + context->video_start_time, ticks, c ? c->ticks_per_frame : -1, st->time_base.num, st->time_base.den, c ? c->time_base.num : -1, c ? c->time_base.den : -1, st->start_time, st->duration == AV_NOPTS_VALUE ? context->fc->duration / AV_TIME_BASE * 1000 : st->duration, st->nb_frames, av_q2d(st->time_base)); } -GCC_DIAG_ON(deprecated-declarations) again: @@ -2760,6 +3306,7 @@ static switch_status_t av_file_write_video(switch_file_handle_t *handle, switch_ switch_status_t status = SWITCH_STATUS_SUCCESS; av_file_context_t *context = (av_file_context_t *)handle->private_info; switch_image_t *img = NULL; + AVCodecContext *c = NULL; if (!switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) { return SWITCH_STATUS_FALSE; @@ -2776,12 +3323,13 @@ static switch_status_t av_file_write_video(switch_file_handle_t *handle, switch_ if (add_stream(context, &context->video_st, context->fc, &context->video_codec, context->fc->oformat->video_codec, &handle->mm) == SWITCH_STATUS_SUCCESS && open_video(context->fc, context->video_codec, &context->video_st) == SWITCH_STATUS_SUCCESS) { - char codec_str[256]; + char codec_str[256] = ""; int ret; -GCC_DIAG_OFF(deprecated-declarations) - avcodec_string(codec_str, sizeof(codec_str), context->video_st.st->codec, 1); -GCC_DIAG_ON(deprecated-declarations) + if ((c = av_get_codec_context(&context->video_st))) { + avcodec_string(codec_str, sizeof(codec_str), c, 1); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "use video codec implementation %s\n", codec_str); context->has_video = 1; @@ -2814,8 +3362,11 @@ GCC_DIAG_ON(deprecated-declarations) switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_core_timer_init(&context->video_timer, "soft", 1, 1, context->pool); context->eh.video_timer = &context->video_timer; - context->audio_st[0].frame->pts = 0; - context->audio_st[0].next_pts = 0; + if (context->has_audio) { + context->audio_st[0].frame->pts = 0; + context->audio_st[0].next_pts = 0; + } + switch_thread_create(&context->eh.video_thread, thd_attr, video_thread_run, context, handle->memory_pool); } diff --git a/src/mod/applications/mod_av/mod_av.c b/src/mod/applications/mod_av/mod_av.c index 5d93d9adc7..97b2c8f3d7 100644 --- a/src/mod/applications/mod_av/mod_av.c +++ b/src/mod/applications/mod_av/mod_av.c @@ -25,6 +25,7 @@ * * Seven Du * Anthony Minessale + * Jakub Karolczyk * * mod_av -- FS Video Codec / File Format using libav.org * @@ -49,6 +50,7 @@ typedef struct av_mutex_helper_s { switch_memory_pool_t *pool; } av_mutex_helper_t; +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V) int mod_av_lockmgr_cb(void **m, enum AVLockOp op) { av_mutex_helper_t *context = NULL; @@ -93,6 +95,7 @@ int mod_av_lockmgr_cb(void **m, enum AVLockOp op) } return 0; } +#endif #ifndef AV_LOG_TRACE #define AV_LOG_TRACE 96 diff --git a/src/mod/applications/mod_av/mod_av.h b/src/mod/applications/mod_av/mod_av.h index b240f98aa7..a89e6cb8f7 100644 --- a/src/mod/applications/mod_av/mod_av.h +++ b/src/mod/applications/mod_av/mod_av.h @@ -30,6 +30,7 @@ * Marcel Barbulescu * Raymond Chandler * Emmanuel Schmidbauer + * Jakub Karolczyk * * * mod_av.h -- LibAV mod @@ -39,6 +40,10 @@ #ifndef MOD_AV_H #define MOD_AV_H +#define LIBAVCODEC_V 59 +#define LIBAVFORMAT_V 59 +#define LIBAVUTIL_V 57 + struct mod_av_globals { int debug; }; From 9f8de014a15fdee20a2a1bca84bd316d5d0e62d3 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 15 Jul 2023 22:15:22 +0300 Subject: [PATCH 064/123] [mod_av] Add FFmpeg 5.1.3 support on Windows. --- libs/win32/ffmpeg/ffmpeg.2017.vcxproj | 1127 ++++++++++++++++++++---- src/mod/applications/mod_av/avcodec.c | 3 + src/mod/applications/mod_av/avformat.c | 6 + src/mod/applications/mod_av/mod_av.c | 6 + w32/ffmpeg-version.props | 2 +- w32/ffmpeg.props | 2 +- 6 files changed, 952 insertions(+), 194 deletions(-) diff --git a/libs/win32/ffmpeg/ffmpeg.2017.vcxproj b/libs/win32/ffmpeg/ffmpeg.2017.vcxproj index 7eb6ef65ed..b985670dbe 100644 --- a/libs/win32/ffmpeg/ffmpeg.2017.vcxproj +++ b/libs/win32/ffmpeg/ffmpeg.2017.vcxproj @@ -24,7 +24,6 @@ 10.0.17134.0 {BC1FD72E-1CD5-4525-A7F5-17C5740BFDED} - @@ -78,7 +77,7 @@ - BUILDING_avdevice;BUILDING_avfilter;BUILDING_avformat;BUILDING_avcodec;BUILDING_avresample;BUILDING_swresample;BUILDING_swscale;BUILDING_avutil;%(PreprocessorDefinitions) + WC_ERR_INVALID_CHARS=0x00000080;BUILDING_avdevice;BUILDING_avfilter;BUILDING_avformat;BUILDING_avcodec;BUILDING_swresample;BUILDING_swscale;BUILDING_avutil;%(PreprocessorDefinitions) @@ -209,6 +208,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -242,6 +244,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -305,6 +310,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -332,6 +340,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -350,6 +361,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -392,6 +415,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -401,6 +427,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -410,6 +442,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -419,18 +457,21 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -458,15 +499,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -533,12 +574,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -548,6 +595,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -563,6 +613,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -596,7 +655,7 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -608,10 +667,13 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -638,6 +700,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -680,6 +745,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -719,6 +790,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -755,6 +835,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -764,15 +847,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -782,6 +865,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -815,6 +901,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -875,15 +967,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -908,9 +1000,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -980,6 +1069,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1001,9 +1093,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1049,6 +1150,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1097,9 +1201,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1124,6 +1225,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1133,6 +1240,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1241,6 +1354,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1271,6 +1390,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1301,6 +1423,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1406,7 +1531,7 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1415,9 +1540,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1433,9 +1555,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1454,6 +1585,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1466,6 +1600,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1484,6 +1621,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1538,6 +1678,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1559,6 +1702,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1586,6 +1732,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1595,6 +1744,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1640,6 +1792,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1673,6 +1828,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1691,48 +1849,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1748,6 +1873,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1763,6 +1891,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1793,18 +1924,36 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1832,6 +1981,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1880,6 +2032,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1964,6 +2125,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2039,6 +2203,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2060,9 +2230,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2072,13 +2239,16 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2105,6 +2275,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2126,9 +2302,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2168,6 +2341,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2177,21 +2353,24 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2222,6 +2401,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2237,9 +2419,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2282,6 +2461,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2318,12 +2503,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2444,12 +2635,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2528,6 +2725,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2636,7 +2842,7 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2726,6 +2932,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2816,9 +3025,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2828,6 +3034,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2849,18 +3058,33 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2876,6 +3100,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2897,6 +3127,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2906,12 +3142,21 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2921,12 +3166,30 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2954,6 +3217,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -2996,9 +3265,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3008,6 +3274,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3026,6 +3295,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3038,6 +3310,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3077,6 +3352,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3095,7 +3373,7 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3110,10 +3388,52 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3122,6 +3442,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3140,6 +3463,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3155,6 +3481,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3203,7 +3532,13 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3215,6 +3550,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3227,6 +3565,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3245,6 +3589,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3257,6 +3604,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3266,12 +3619,21 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3284,18 +3646,33 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3320,6 +3697,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3332,6 +3712,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3341,6 +3724,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3353,6 +3739,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3365,15 +3760,27 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3416,18 +3823,30 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3443,9 +3862,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3455,10 +3880,10 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3470,9 +3895,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3494,7 +3925,16 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3512,9 +3952,21 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3554,9 +4006,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3608,10 +4066,10 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3623,6 +4081,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3632,6 +4093,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3641,6 +4105,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3677,33 +4144,39 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3716,6 +4189,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3734,13 +4210,16 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3755,6 +4234,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3764,12 +4246,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3779,19 +4267,31 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3800,7 +4300,7 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3809,40 +4309,55 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3869,9 +4384,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3896,6 +4417,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3908,9 +4432,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3923,6 +4453,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3935,9 +4468,21 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -3971,15 +4516,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4001,6 +4549,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4010,6 +4564,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4067,9 +4624,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4085,21 +4639,36 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4157,9 +4726,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4211,6 +4777,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4259,6 +4828,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4271,6 +4846,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4319,6 +4897,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4337,15 +4918,24 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4358,6 +4948,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4376,9 +4969,15 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4397,6 +4996,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4415,6 +5017,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4457,6 +5065,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4469,6 +5083,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4520,6 +5137,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4532,6 +5152,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4589,9 +5212,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4652,6 +5272,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4871,6 +5494,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4922,6 +5548,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4934,6 +5563,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -4946,6 +5578,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5027,6 +5662,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5075,6 +5713,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5099,9 +5740,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5114,6 +5752,12 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5174,6 +5818,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5234,6 +5881,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5267,15 +5917,24 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5297,6 +5956,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5309,21 +5971,27 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5426,9 +6094,30 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5447,13 +6136,19 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5480,6 +6175,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5525,6 +6223,9 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -5543,54 +6244,6 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - Assembling %(Filename)%(Extension) - $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - Assembling %(Filename)%(Extension) - $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - - Assembling %(Filename)%(Extension) - $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" @@ -5636,6 +6289,21 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" @@ -5666,7 +6334,7 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -5856,7 +6524,7 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -6041,6 +6709,11 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" @@ -6056,6 +6729,16 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" @@ -6066,12 +6749,27 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -6086,7 +6784,7 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -6106,17 +6804,32 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -6126,12 +6839,12 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -6141,7 +6854,12 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj - + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj @@ -6151,6 +6869,11 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" @@ -6206,6 +6929,11 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + Assembling %(Filename)%(Extension) $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" @@ -6241,6 +6969,21 @@ $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + + + Assembling %(Filename)%(Extension) + $(YasmCommand) -I %(RelativeDir) -o $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj "%(FullPath)" + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_')).%(FileName).obj + @@ -6256,4 +6999,4 @@ - + \ No newline at end of file diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index d84362eb28..16d268273b 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -35,6 +35,9 @@ #include #include "mod_av.h" #include +#ifdef _MSC_VER +#include /* LIBAVCODEC_VERSION_INT */ +#endif #include #include #include diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 624af8f4ea..69475c169f 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -35,7 +35,13 @@ #include "mod_av.h" GCC_DIAG_OFF(deprecated-declarations) #include +#ifdef _MSC_VER +#include /* LIBAVCODEC_VERSION_INT */ +#endif #include +#ifdef _MSC_VER +#include /* LIBAVFORMAT_VERSION_INT */ +#endif #include #include #include diff --git a/src/mod/applications/mod_av/mod_av.c b/src/mod/applications/mod_av/mod_av.c index 97b2c8f3d7..02a481fd2e 100644 --- a/src/mod/applications/mod_av/mod_av.c +++ b/src/mod/applications/mod_av/mod_av.c @@ -34,7 +34,13 @@ #include #include "mod_av.h" #include +#ifdef _MSC_VER +#include /* LIBAVCODEC_VERSION_INT */ +#endif #include +#ifdef _MSC_VER +#include /* LIBAVFORMAT_VERSION_INT */ +#endif SWITCH_MODULE_LOAD_FUNCTION(mod_avformat_load); SWITCH_MODULE_LOAD_FUNCTION(mod_avcodec_load); diff --git a/w32/ffmpeg-version.props b/w32/ffmpeg-version.props index 012af42ccb..5e4a400557 100644 --- a/w32/ffmpeg-version.props +++ b/w32/ffmpeg-version.props @@ -4,7 +4,7 @@ - 4.1 + 5.1.3 true diff --git a/w32/ffmpeg.props b/w32/ffmpeg.props index fe039de408..775b588e4c 100644 --- a/w32/ffmpeg.props +++ b/w32/ffmpeg.props @@ -21,7 +21,7 @@ $(ffmpegDir);%(AdditionalLibraryDirectories) - Bcrypt.lib;Secur32.lib;%(AdditionalDependencies) + Bcrypt.lib;Secur32.lib;Mfuuid.lib;strmiids.lib;%(AdditionalDependencies) openh264.lib;%(AdditionalDependencies) From 55f2dc475932fd825bab1f2de1fe6565852f2e03 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 21 Jul 2023 11:49:40 +0100 Subject: [PATCH 065/123] [core] Coverity fixes * [core] Coverity CID 1024233 (Dereference before null check) * [core] Coverity CID 1024239 (Dereference before null check) * [core] Coverity CID 1024242 (Dereference before null check) * [core] Coverity CID 1024243 (Dereference before null check) * [core] Coverity CID 1024453 (Dereference before null check) * [core] Coverity CID 1024554 (Logically dead code) * [core] Coverity CID 1024868 (unchecked return value from library) * [core] Coverity CID 1024869 (unchecked return value from library) * [core] Coverity CID 1468281 (Dereference before null check) * [core] Coverity CID 1024238 (Dereference before null check) * [core] Coverity CID 1468621 (Copy into fixed size buffer) * [core] Coverity CID 1024871 (Unchecked return value) --- src/switch_core_codec.c | 10 ++++++++-- src/switch_event.c | 20 +++++++++++++++----- src/switch_ivr_originate.c | 15 +++++++++------ src/switch_rtp.c | 18 ------------------ src/switch_xml.c | 36 ++++++++++++++++++++++++++---------- 5 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index 69883f8122..e5c22cd610 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -120,8 +120,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c } } else { /* replace real_read_codec */ switch_codec_t *cur_codec; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec replaced with %s:%d\n", - switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode); + switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1); /* Set real_read_codec to front of the list of read_codecs */ cur_codec = session->read_codec; while (cur_codec != NULL) { @@ -129,8 +130,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c cur_codec->next = codec; break; } + cur_codec = cur_codec->next; } + session->real_read_codec = codec; session->real_read_impl = *codec->implementation; @@ -154,6 +157,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c session->bug_codec.implementation->iananame, session->bug_codec.implementation->ianacode); switch_core_codec_destroy(&session->bug_codec); } + switch_thread_rwlock_unlock(session->bug_rwlock); } else { status = SWITCH_STATUS_FALSE; @@ -169,6 +173,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c if (session->read_impl.actual_samples_per_second != session->read_impl.samples_per_second) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second); } + switch_event_fire(&event); } @@ -191,6 +196,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c } switch_mutex_unlock(session->codec_read_mutex); + return status; } @@ -221,7 +227,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s goto end; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Push codec %s:%d\n", - switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode); + switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1); codec->next = session->read_codec; session->read_codec = codec; if (codec->implementation) { diff --git a/src/switch_event.c b/src/switch_event.c index 272255d31c..02a6f81505 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -2071,15 +2071,18 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit switch_mutex_lock(CUSTOM_HASH_MUTEX); if (!(subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) { - switch_event_reserve_subclass_detailed(id, subclass_name); - subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name); - subclass->bind = 1; + if (switch_event_reserve_subclass_detailed(id, subclass_name) == SWITCH_STATUS_SUCCESS) { + if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) { + subclass->bind = 1; + } + } } switch_mutex_unlock(CUSTOM_HASH_MUTEX); if (!subclass) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not reserve subclass. '%s'\n", subclass_name); + return SWITCH_STATUS_FALSE; } } @@ -2094,6 +2097,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit if (subclass_name) { event_node->subclass_name = DUP(subclass_name); } + event_node->callback = callback; event_node->user_data = user_data; @@ -2952,14 +2956,17 @@ static void ecd_deliver(event_channel_data_t **ecdP) int x_argc = switch_separate_string_string(key, (char*) sep, x_argv, SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS); char buf[1024]; int i, r; + for(i=x_argc - 1; i > 0; i--) { int z; + memset(buf, 0, 1024); - sprintf(buf, "%s", x_argv[0]); + switch_snprintf(buf, sizeof(buf), "%s", x_argv[0]); for(z=1; z < i; z++) { strcat(buf, sep); - strcat(buf, x_argv[z]); + strncat(buf, x_argv[z], sizeof(buf) - strlen(buf) - 1); } + r = _switch_event_channel_broadcast(buf, ecd->event_channel, ecd->json, ecd->key, ecd->id); t += r; if (r && switch_core_test_flag(SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE)) { @@ -2968,11 +2975,13 @@ static void ecd_deliver(event_channel_data_t **ecdP) } } else { char *p = NULL; + if ((p = strchr(key, '.'))) { *p = '\0'; t += _switch_event_channel_broadcast(key, ecd->event_channel, ecd->json, ecd->key, ecd->id); } } + switch_safe_free(key); t += _switch_event_channel_broadcast(SWITCH_EVENT_CHANNEL_GLOBAL, ecd->event_channel, ecd->json, ecd->key, ecd->id); @@ -2980,6 +2989,7 @@ static void ecd_deliver(event_channel_data_t **ecdP) if(t == 0) { if (switch_core_test_flag(SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON)) { char *json = cJSON_Print(ecd->json); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no subscribers for %s , %s => %s\n", ecd->event_channel, ecd->key, json); switch_safe_free(json); } else { diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index f23549713b..a39553e2f9 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -186,15 +186,16 @@ struct key_collect { static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void *obj) { struct key_collect *collect = (struct key_collect *) obj; - switch_channel_t *channel = switch_core_session_get_channel(collect->session); + switch_channel_t *channel = NULL; char buf[10] = SWITCH_BLANK_STRING; switch_application_interface_t *application_interface = NULL; - if (collect->session) { - if (switch_core_session_read_lock(collect->session) != SWITCH_STATUS_SUCCESS) { - return NULL; - } - } else { + if (!collect->session) { + return NULL; + } + + channel = switch_core_session_get_channel(collect->session); + if (switch_core_session_read_lock(collect->session) != SWITCH_STATUS_SUCCESS) { return NULL; } @@ -232,6 +233,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void switch_channel_set_flag(channel, CF_WINNER); switch_channel_set_variable(channel, "group_dial_status", "winner"); } + goto wbreak; } @@ -271,6 +273,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void switch_ivr_play_file(collect->session, NULL, collect->error_file, NULL); } } + wbreak: switch_core_session_rwunlock(collect->session); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 4aa68061ab..db6f63e2dd 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -3934,12 +3934,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess case SWITCH_RTP_CRYPTO_RECV: switch_channel_set_variable(channel, "srtp_remote_crypto_key", (const char *)b64_key); break; - case SWITCH_RTP_CRYPTO_SEND_RTCP: - switch_channel_set_variable(channel, "srtcp_local_crypto_key", (const char *)b64_key); - break; - case SWITCH_RTP_CRYPTO_RECV_RTCP: - switch_channel_set_variable(channel, "srtcp_remote_crypto_key", (const char *)b64_key); - break; default: break; } @@ -3952,12 +3946,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess case SWITCH_RTP_CRYPTO_RECV: switch_channel_set_variable(channel, "srtp_remote_video_crypto_key", (const char *)b64_key); break; - case SWITCH_RTP_CRYPTO_SEND_RTCP: - switch_channel_set_variable(channel, "srtcp_local_video_crypto_key", (const char *)b64_key); - break; - case SWITCH_RTP_CRYPTO_RECV_RTCP: - switch_channel_set_variable(channel, "srtcp_remote_video_crypto_key", (const char *)b64_key); - break; default: break; } @@ -3970,12 +3958,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess case SWITCH_RTP_CRYPTO_RECV: switch_channel_set_variable(channel, "srtp_remote_audio_crypto_key", (const char *)b64_key); break; - case SWITCH_RTP_CRYPTO_SEND_RTCP: - switch_channel_set_variable(channel, "srtcp_local_audio_crypto_key", (const char *)b64_key); - break; - case SWITCH_RTP_CRYPTO_RECV_RTCP: - switch_channel_set_variable(channel, "srtcp_remote_audio_crypto_key", (const char *)b64_key); - break; default: break; } diff --git a/src/switch_xml.c b/src/switch_xml.c index 80b7553907..8ed7c27658 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -550,15 +550,22 @@ SWITCH_DECLARE(const char **) switch_xml_pi(switch_xml_t xml, const char *target switch_xml_root_t root = (switch_xml_root_t) xml; int i = 0; - if (!root) + if (!root) { return (const char **) SWITCH_XML_NIL; - while (root->xml.parent) + } + + while (root && root->xml.parent) { root = (switch_xml_root_t) root->xml.parent; /* root tag */ + } + if (!root || !root->pi) { return (const char **) SWITCH_XML_NIL; } - while (root->pi[i] && strcmp(target, root->pi[i][0])) + + while (root->pi[i] && strcmp(target, root->pi[i][0])) { i++; /* find target */ + } + return (const char **) ((root->pi[i]) ? root->pi[i] + 1 : SWITCH_XML_NIL); } @@ -1146,7 +1153,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len) return switch_xml_err(root, d, "unclosed From eb918fe1807fa8465a68c10088cdd81a9be1b229 Mon Sep 17 00:00:00 2001 From: Sergei Rozhkov <119299827+ghzserg@users.noreply.github.com> Date: Sat, 12 Aug 2023 01:13:00 +0500 Subject: [PATCH 084/123] [Core] Fix switch_console.c for Galera Mariadb cluster Fix in switch_console.c file. Adds column names when inserting data. Calls to use the complete table in Galera Multi-Master Cluster --- src/switch_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/switch_console.c b/src/switch_console.c index 8e26fec749..2157fda8a2 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -1849,7 +1849,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string) SWITCH_STANDARD_STREAM(mystream); if (!strcasecmp(argv[0], "stickyadd")) { - mystream.write_function(&mystream, "insert into complete values (1,"); + mystream.write_function(&mystream, "insert into complete (sticky, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, hostname) values (1,"); for (x = 0; x < 10; x++) { if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) { mystream.write_function(&mystream, "%s", "'', "); @@ -1865,7 +1865,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string) switch_core_sql_exec(mystream.data); status = SWITCH_STATUS_SUCCESS; } else if (!strcasecmp(argv[0], "add")) { - mystream.write_function(&mystream, "insert into complete values (0,"); + mystream.write_function(&mystream, "insert into complete (sticky, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, hostname) values (0,"); for (x = 0; x < 10; x++) { if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) { mystream.write_function(&mystream, "%s", "'', "); From 9347c967125bfa36ca1b049f29841e4d452815ca Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 1 Aug 2023 19:33:17 +0300 Subject: [PATCH 085/123] [Core] check_ice: sanitize second field of the candidates. Add new switch_is_uint_in_range() API. --- src/include/switch_rtp.h | 9 +++++---- src/include/switch_utils.h | 8 ++++++++ src/switch_core_media.c | 11 ++++++++--- src/switch_utils.c | 24 ++++++++++++++++++++++++ tests/unit/switch_core.c | 15 +++++++++++++++ 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index ca915cf77a..dfcad5453c 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -106,12 +106,13 @@ typedef struct icand_s { } icand_t; #define MAX_CAND 50 +#define MAX_CAND_IDX_COUNT 2 typedef struct ice_s { - icand_t cands[MAX_CAND][2]; - int cand_idx[2]; - int chosen[2]; - int is_chosen[2]; + icand_t cands[MAX_CAND][MAX_CAND_IDX_COUNT]; + int cand_idx[MAX_CAND_IDX_COUNT]; + int chosen[MAX_CAND_IDX_COUNT]; + int is_chosen[MAX_CAND_IDX_COUNT]; char *ufrag; char *pwd; char *options; diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 62f3fcd97e..1d33939f4c 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -498,6 +498,14 @@ SWITCH_DECLARE(switch_size_t) switch_fp_read_dline(FILE *fd, char **buf, switch_ SWITCH_DECLARE(switch_status_t) switch_frame_alloc(switch_frame_t **frame, switch_size_t size); SWITCH_DECLARE(switch_status_t) switch_frame_dup(switch_frame_t *orig, switch_frame_t **clone); SWITCH_DECLARE(switch_status_t) switch_frame_free(switch_frame_t **frame); + +/*! \brief Check if a 32 bit unsigned number is in a range. + * \param str string to check. Should not contain non-digit characters. + * \param from start of range including this number + * \param to end of range including this number + * \return true or false + */ +SWITCH_DECLARE(switch_bool_t) switch_is_uint_in_range(const char *str, unsigned int from, unsigned int to); SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str); SWITCH_DECLARE(switch_bool_t) switch_is_leading_number(const char *str); SWITCH_DECLARE(char *) switch_find_parameter(const char *str, const char *param, switch_memory_pool_t *pool); diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 4d11dc8b4e..252d947035 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -4167,10 +4167,15 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t argc = switch_split(data, ' ', fields); + if (argc < 6 || !switch_is_uint_in_range(fields[1], 1, MAX_CAND_IDX_COUNT)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "Invalid data\n"); + continue; + } + cid = fields[1] ? atoi(fields[1]) - 1 : 0; - if (argc < 6 || engine->ice_in.cand_idx[cid] >= MAX_CAND - 1) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "Invalid data\n"); + if (engine->ice_in.cand_idx[cid] >= MAX_CAND - 1) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "Too many candidates\n"); continue; } @@ -4250,7 +4255,7 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t relay: - for (cid = 0; cid < 2; cid++) { + for (cid = 0; cid < MAX_CAND_IDX_COUNT; cid++) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_DEBUG, "Searching for %s candidate.\n", cid ? "rtcp" : "rtp"); for (ai = 0; ai < engine->cand_acl_count; ai++) { diff --git a/src/switch_utils.c b/src/switch_utils.c index 7561835e69..c51953f0cf 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -1607,6 +1607,30 @@ SWITCH_DECLARE(char *) switch_separate_paren_args(char *str) return args; } +SWITCH_DECLARE(switch_bool_t) switch_is_uint_in_range(const char *str, unsigned int from, unsigned int to) +{ + unsigned int number; + const char *original_str = str; + + if (str == NULL || *str == '\0' || from > to) { + return SWITCH_FALSE; + } + + for (; *str != '\0'; str++) { + if (!isdigit(*str)) { + return SWITCH_FALSE; + } + } + + number = atoi(original_str); + + if (number < from || number > to) { + return SWITCH_FALSE; + } + + return SWITCH_TRUE; +} + SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str) { const char *p; diff --git a/tests/unit/switch_core.c b/tests/unit/switch_core.c index 2aa0f10231..da93fbdef4 100644 --- a/tests/unit/switch_core.c +++ b/tests/unit/switch_core.c @@ -95,6 +95,21 @@ FST_CORE_BEGIN("./conf") FST_TEST_END() #endif + FST_TEST_BEGIN(test_switch_is_number_in_range) + { + fst_check_int_equals(switch_is_uint_in_range("x5", 0, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("0", 1, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("-11", -10, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("-10", -10, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("-5", -10, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("-5", -10, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("5", -10, 10), SWITCH_FALSE); + fst_check_int_equals(switch_is_uint_in_range("0", 0, 10), SWITCH_TRUE); + fst_check_int_equals(switch_is_uint_in_range("10", 0, 10), SWITCH_TRUE); + fst_check_int_equals(switch_is_uint_in_range("11", 0, 10), SWITCH_FALSE); + } + FST_TEST_END() + FST_TEST_BEGIN(test_md5) { char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 }; From 5c289cc063c21cc7814470f92e701b6e7606dc6e Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sun, 13 Aug 2023 16:00:05 +0000 Subject: [PATCH 086/123] swigall --- .../languages/mod_managed/freeswitch_wrap.cxx | 130 ++++++++++++++++++ src/mod/languages/mod_managed/managed/swig.cs | 81 ++++++++++- 2 files changed, 210 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 89614987b5..742e4f979e 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -21077,6 +21077,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_frame_free___(void * } +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_is_uint_in_range___(char * jarg1, unsigned int jarg2, unsigned int jarg3) { + int jresult ; + char *arg1 = (char *) 0 ; + unsigned int arg2 ; + unsigned int arg3 ; + switch_bool_t result; + + arg1 = (char *)jarg1; + arg2 = (unsigned int)jarg2; + arg3 = (unsigned int)jarg3; + result = (switch_bool_t)switch_is_uint_in_range((char const *)arg1,arg2,arg3); + jresult = (int)result; + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_is_number___(char * jarg1) { int jresult ; char *arg1 = (char *) 0 ; @@ -33245,6 +33261,50 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_microsecon } +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_max_ptime_set___(void * jarg1, int jarg2) { + switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; + int arg2 ; + + arg1 = (switch_codec_fmtp *)jarg1; + arg2 = (int)jarg2; + if (arg1) (arg1)->max_ptime = arg2; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_max_ptime_get___(void * jarg1) { + int jresult ; + switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; + int result; + + arg1 = (switch_codec_fmtp *)jarg1; + result = (int) ((arg1)->max_ptime); + jresult = result; + return jresult; +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_min_ptime_set___(void * jarg1, int jarg2) { + switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; + int arg2 ; + + arg1 = (switch_codec_fmtp *)jarg1; + arg2 = (int)jarg2; + if (arg1) (arg1)->min_ptime = arg2; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_min_ptime_get___(void * jarg1) { + int jresult ; + switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; + int result; + + arg1 = (switch_codec_fmtp *)jarg1; + result = (int) ((arg1)->min_ptime); + jresult = result; + return jresult; +} + + SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_stereo_set___(void * jarg1, int jarg2) { switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; int arg2 ; @@ -33267,6 +33327,28 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_stereo_get } +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_sprop_stereo_set___(void * jarg1, int jarg2) { + switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; + int arg2 ; + + arg1 = (switch_codec_fmtp *)jarg1; + arg2 = (int)jarg2; + if (arg1) (arg1)->sprop_stereo = arg2; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_sprop_stereo_get___(void * jarg1) { + int jresult ; + switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; + int result; + + arg1 = (switch_codec_fmtp *)jarg1; + result = (int) ((arg1)->sprop_stereo); + jresult = result; + return jresult; +} + + SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_codec_fmtp_private_info_set___(void * jarg1, void * jarg2) { switch_codec_fmtp *arg1 = (switch_codec_fmtp *) 0 ; void *arg2 = (void *) 0 ; @@ -36802,6 +36884,44 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_channel_get_variab } +SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_channel_get_variable_strdup___(void * jarg1, char * jarg2) { + char * jresult ; + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + char *arg2 = (char *) 0 ; + char *result = 0 ; + + arg1 = (switch_channel_t *)jarg1; + arg2 = (char *)jarg2; + result = (char *)switch_channel_get_variable_strdup(arg1,(char const *)arg2); + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_channel_get_variable_buf___(void * jarg1, char * jarg2, char * jarg3, void * jarg4) { + int jresult ; + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + switch_size_t arg4 ; + switch_size_t *argp4 ; + switch_status_t result; + + arg1 = (switch_channel_t *)jarg1; + arg2 = (char *)jarg2; + arg3 = (char *)jarg3; + argp4 = (switch_size_t *)jarg4; + if (!argp4) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_size_t", 0); + return 0; + } + arg4 = *argp4; + result = (switch_status_t)switch_channel_get_variable_buf(arg1,(char const *)arg2,arg3,arg4); + jresult = (int)result; + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_channel_get_variables___(void * jarg1, void * jarg2) { int jresult ; switch_channel_t *arg1 = (switch_channel_t *) 0 ; @@ -45145,6 +45265,16 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_MAX_CAND_get___() { } +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_MAX_CAND_IDX_COUNT_get___() { + int jresult ; + int result; + + result = (int)(2); + jresult = result; + return jresult; +} + + SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_ice_t_cands_set___(void * jarg1, void * jarg2) { ice_s *arg1 = (ice_s *) 0 ; icand_t (*arg2)[2] ; diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index 6483ed103b..02848257bf 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -10932,6 +10932,11 @@ else return ret; } + public static switch_bool_t switch_is_uint_in_range(string str, uint from, uint to) { + switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_is_uint_in_range(str, from, to); + return ret; + } + public static switch_bool_t switch_is_number(string str) { switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_is_number(str); return ret; @@ -11884,6 +11889,17 @@ else return ret; } + public static string switch_channel_get_variable_strdup(SWIGTYPE_p_switch_channel channel, string varname) { + string ret = freeswitchPINVOKE.switch_channel_get_variable_strdup(SWIGTYPE_p_switch_channel.getCPtr(channel), varname); + return ret; + } + + public static switch_status_t switch_channel_get_variable_buf(SWIGTYPE_p_switch_channel channel, string varname, string buf, SWIGTYPE_p_switch_size_t buflen) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_get_variable_buf(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, buf, SWIGTYPE_p_switch_size_t.getCPtr(buflen)); + if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + public static switch_status_t switch_channel_get_variables(SWIGTYPE_p_switch_channel channel, SWIGTYPE_p_p_switch_event arg1) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_get_variables(SWIGTYPE_p_switch_channel.getCPtr(channel), SWIGTYPE_p_p_switch_event.getCPtr(arg1)); return ret; @@ -15223,6 +15239,7 @@ else public static readonly string SWITCH_RTP_CRYPTO_KEY_80 = freeswitchPINVOKE.SWITCH_RTP_CRYPTO_KEY_80_get(); public static readonly int SWITCH_RTP_BUNDLE_INTERNAL_PT = freeswitchPINVOKE.SWITCH_RTP_BUNDLE_INTERNAL_PT_get(); public static readonly int MAX_CAND = freeswitchPINVOKE.MAX_CAND_get(); + public static readonly int MAX_CAND_IDX_COUNT = freeswitchPINVOKE.MAX_CAND_IDX_COUNT_get(); public static readonly int SWITCH_XML_BUFSIZE = freeswitchPINVOKE.SWITCH_XML_BUFSIZE_get(); } @@ -20575,6 +20592,9 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_frame_free___")] public static extern int switch_frame_free(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_is_uint_in_range___")] + public static extern int switch_is_uint_in_range(string jarg1, uint jarg2, uint jarg3); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_is_number___")] public static extern int switch_is_number(string jarg1); @@ -23614,12 +23634,30 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_microseconds_per_packet_get___")] public static extern int switch_codec_fmtp_microseconds_per_packet_get(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_max_ptime_set___")] + public static extern void switch_codec_fmtp_max_ptime_set(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_max_ptime_get___")] + public static extern int switch_codec_fmtp_max_ptime_get(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_min_ptime_set___")] + public static extern void switch_codec_fmtp_min_ptime_set(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_min_ptime_get___")] + public static extern int switch_codec_fmtp_min_ptime_get(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_stereo_set___")] public static extern void switch_codec_fmtp_stereo_set(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2); [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_stereo_get___")] public static extern int switch_codec_fmtp_stereo_get(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_sprop_stereo_set___")] + public static extern void switch_codec_fmtp_sprop_stereo_set(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_sprop_stereo_get___")] + public static extern int switch_codec_fmtp_sprop_stereo_get(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_codec_fmtp_private_info_set___")] public static extern void switch_codec_fmtp_private_info_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); @@ -24487,6 +24525,12 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_channel_get_variable_dup___")] public static extern string switch_channel_get_variable_dup(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, int jarg3, int jarg4); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_channel_get_variable_strdup___")] + public static extern string switch_channel_get_variable_strdup(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_channel_get_variable_buf___")] + public static extern int switch_channel_get_variable_buf(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3, global::System.Runtime.InteropServices.HandleRef jarg4); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_channel_get_variables___")] public static extern int switch_channel_get_variables(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); @@ -26281,6 +26325,9 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_MAX_CAND_get___")] public static extern int MAX_CAND_get(); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_MAX_CAND_IDX_COUNT_get___")] + public static extern int MAX_CAND_IDX_COUNT_get(); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_ice_t_cands_set___")] public static extern void ice_t_cands_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); @@ -31066,7 +31113,8 @@ public enum switch_call_cause_t { SWITCH_CAUSE_BAD_IDENTITY_INFO = 821, SWITCH_CAUSE_UNSUPPORTED_CERTIFICATE = 822, SWITCH_CAUSE_INVALID_IDENTITY = 823, - SWITCH_CAUSE_STALE_DATE = 824 + SWITCH_CAUSE_STALE_DATE = 824, + SWITCH_CAUSE_REJECT_ALL = 825 } } @@ -32781,6 +32829,7 @@ public enum switch_codec_control_command_t { SCC_VIDEO_RESET, SCC_AUDIO_PACKET_LOSS, SCC_AUDIO_ADJUST_BITRATE, + SCC_AUDIO_VAD, SCC_DEBUG, SCC_CODEC_SPECIFIC } @@ -32905,6 +32954,26 @@ public class switch_codec_fmtp : global::System.IDisposable { } } + public int max_ptime { + set { + freeswitchPINVOKE.switch_codec_fmtp_max_ptime_set(swigCPtr, value); + } + get { + int ret = freeswitchPINVOKE.switch_codec_fmtp_max_ptime_get(swigCPtr); + return ret; + } + } + + public int min_ptime { + set { + freeswitchPINVOKE.switch_codec_fmtp_min_ptime_set(swigCPtr, value); + } + get { + int ret = freeswitchPINVOKE.switch_codec_fmtp_min_ptime_get(swigCPtr); + return ret; + } + } + public int stereo { set { freeswitchPINVOKE.switch_codec_fmtp_stereo_set(swigCPtr, value); @@ -32915,6 +32984,16 @@ public class switch_codec_fmtp : global::System.IDisposable { } } + public int sprop_stereo { + set { + freeswitchPINVOKE.switch_codec_fmtp_sprop_stereo_set(swigCPtr, value); + } + get { + int ret = freeswitchPINVOKE.switch_codec_fmtp_sprop_stereo_get(swigCPtr); + return ret; + } + } + public SWIGTYPE_p_void private_info { set { freeswitchPINVOKE.switch_codec_fmtp_private_info_set(swigCPtr, SWIGTYPE_p_void.getCPtr(value)); From b74245d48a1f65a05e853f24e973f9b9ff35f8f5 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sun, 13 Aug 2023 23:20:20 +0300 Subject: [PATCH 087/123] version bump --- build/next-release.txt | 2 +- configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/next-release.txt b/build/next-release.txt index b61c58c7d4..63fd3adc74 100644 --- a/build/next-release.txt +++ b/build/next-release.txt @@ -1 +1 @@ -1.10.10-dev +1.10.11-dev diff --git a/configure.ac b/configure.ac index c0d792d51e..9f852e531a 100644 --- a/configure.ac +++ b/configure.ac @@ -3,10 +3,10 @@ # Must change all of the below together # For a release, set revision for that tagged release as well and uncomment -AC_INIT([freeswitch], [1.10.10-dev], bugs@freeswitch.org) +AC_INIT([freeswitch], [1.10.11-dev], bugs@freeswitch.org) AC_SUBST(SWITCH_VERSION_MAJOR, [1]) AC_SUBST(SWITCH_VERSION_MINOR, [10]) -AC_SUBST(SWITCH_VERSION_MICRO, [10-dev]) +AC_SUBST(SWITCH_VERSION_MICRO, [11-dev]) AC_SUBST(SWITCH_VERSION_REVISION, []) AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, []) From 7d52ceb69df24188dbe44ee347e0a8fc1c6cfc92 Mon Sep 17 00:00:00 2001 From: Douglas Vought Date: Tue, 5 Sep 2023 12:46:13 -0400 Subject: [PATCH 088/123] [timezones] Update timezones to version 2023c. --- conf/curl/autoload_configs/timezones.conf.xml | 1170 ++++---- .../autoload_configs/timezones.conf.xml | 1170 ++++---- .../autoload_configs/timezones.conf.xml | 2493 +++++------------ conf/rayo/autoload_configs/timezones.conf.xml | 1170 ++++---- conf/sbc/autoload_configs/timezones.conf.xml | 1170 ++++---- .../autoload_configs/timezones.conf.xml | 2493 +++++------------ .../autoload_configs/timezones.conf.xml | 2349 ++++------------ 7 files changed, 4461 insertions(+), 7554 deletions(-) diff --git a/conf/curl/autoload_configs/timezones.conf.xml b/conf/curl/autoload_configs/timezones.conf.xml index 14f87f8c67..9ddded792c 100644 --- a/conf/curl/autoload_configs/timezones.conf.xml +++ b/conf/curl/autoload_configs/timezones.conf.xml @@ -1,551 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + - - - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/insideout/autoload_configs/timezones.conf.xml b/conf/insideout/autoload_configs/timezones.conf.xml index 14f87f8c67..9ddded792c 100644 --- a/conf/insideout/autoload_configs/timezones.conf.xml +++ b/conf/insideout/autoload_configs/timezones.conf.xml @@ -1,551 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + - - - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/minimal/autoload_configs/timezones.conf.xml b/conf/minimal/autoload_configs/timezones.conf.xml index 0af4c77d7f..9ddded792c 100644 --- a/conf/minimal/autoload_configs/timezones.conf.xml +++ b/conf/minimal/autoload_configs/timezones.conf.xml @@ -1,1850 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + diff --git a/conf/rayo/autoload_configs/timezones.conf.xml b/conf/rayo/autoload_configs/timezones.conf.xml index 14f87f8c67..9ddded792c 100644 --- a/conf/rayo/autoload_configs/timezones.conf.xml +++ b/conf/rayo/autoload_configs/timezones.conf.xml @@ -1,551 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + - - - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/sbc/autoload_configs/timezones.conf.xml b/conf/sbc/autoload_configs/timezones.conf.xml index 14f87f8c67..9ddded792c 100644 --- a/conf/sbc/autoload_configs/timezones.conf.xml +++ b/conf/sbc/autoload_configs/timezones.conf.xml @@ -1,551 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - + - - - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/testing/autoload_configs/timezones.conf.xml b/conf/testing/autoload_configs/timezones.conf.xml index 0af4c77d7f..9ddded792c 100644 --- a/conf/testing/autoload_configs/timezones.conf.xml +++ b/conf/testing/autoload_configs/timezones.conf.xml @@ -1,1850 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + diff --git a/conf/vanilla/autoload_configs/timezones.conf.xml b/conf/vanilla/autoload_configs/timezones.conf.xml index 48206d1ce4..9ddded792c 100644 --- a/conf/vanilla/autoload_configs/timezones.conf.xml +++ b/conf/vanilla/autoload_configs/timezones.conf.xml @@ -1,1816 +1,661 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - + - + - - - - - - - - - + + + + + + + + - - + + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - + - + + + + + + + + + + + - + - + - + - + - + - + - + - + - - - + - + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - - - - - - - - - - - - + - + + + + + + + + + + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + From 07f192ca03b609ab6b498490e29d849c2bf4946a Mon Sep 17 00:00:00 2001 From: Douglas Vought Date: Tue, 5 Sep 2023 16:11:01 -0400 Subject: [PATCH 089/123] [contrib/timezone-gen] Fix timezone gen (#2215) * [contrib/timezone-gen] Move timezone-gen.pl to own folder * [contrib/timezone-gen] Add fixTzstr * [contrib/timezone-gen] Add tests and zone data getter - tests.pl can be used to verify that the generated timezone conf will produce the correct datetimes by testing them against what the system's `date` says - build-zonedata.pl will download the latest tzdb data and build the posix timezone data files. It only builds what is needed rather than adding extraneous "right/" and "posix/" timezones. FreeSWITCH doesn't seem to be able to use the "right/" timezone files. - data/ is where the various files needed to generate the timezones gets stored --- scripts/perl/timezones/build-zonedata.pl | 28 +++++++++ scripts/perl/timezones/data/.gitignore | 4 ++ scripts/perl/timezones/fix-tzstr.pl | 61 ++++++++++++++++++ scripts/perl/timezones/tests.pl | 65 ++++++++++++++++++++ scripts/perl/{ => timezones}/timezone-gen.pl | 10 ++- 5 files changed, 165 insertions(+), 3 deletions(-) create mode 100755 scripts/perl/timezones/build-zonedata.pl create mode 100644 scripts/perl/timezones/data/.gitignore create mode 100644 scripts/perl/timezones/fix-tzstr.pl create mode 100644 scripts/perl/timezones/tests.pl rename scripts/perl/{ => timezones}/timezone-gen.pl (90%) diff --git a/scripts/perl/timezones/build-zonedata.pl b/scripts/perl/timezones/build-zonedata.pl new file mode 100755 index 0000000000..347a743dae --- /dev/null +++ b/scripts/perl/timezones/build-zonedata.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my $remote_version = `wget --quiet https://data.iana.org/time-zones/tzdb/version --output-document -` =~ s/\n//r; +my $local_version; + +if ( open my $in, " }; + close $in; +} + +my $up_to_date = defined($local_version) && $local_version eq $remote_version; + +if ( ! $up_to_date ) { + open my $out, ">data/version"; + print $out $remote_version; + close $out; +} + +$local_version = $remote_version; + +`wget --quiet --timestamping --directory-prefix=data https://data.iana.org/time-zones/tzdb-latest.tar.lz`; +`tar --extract --file=data/tzdb-latest.tar.lz --directory=data`; +`make DESTDIR=../ TZDIR=zones-$local_version --directory=data/tzdb-$local_version posix_only`; + +print("Yay. Now you can run\n ./timezone-gen.pl --base=data/zones-$local_version --output=timezones-$local_version.conf.xml") \ No newline at end of file diff --git a/scripts/perl/timezones/data/.gitignore b/scripts/perl/timezones/data/.gitignore new file mode 100644 index 0000000000..144983b728 --- /dev/null +++ b/scripts/perl/timezones/data/.gitignore @@ -0,0 +1,4 @@ +tzdb-* +zones-* +version +tzdb-latest.tar.lz \ No newline at end of file diff --git a/scripts/perl/timezones/fix-tzstr.pl b/scripts/perl/timezones/fix-tzstr.pl new file mode 100644 index 0000000000..224c9a550e --- /dev/null +++ b/scripts/perl/timezones/fix-tzstr.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +sub fixTzstr { + # switch_time.c expects POSIX-style TZ rule, but it won't process quoted TZ + # rules that look like this: <-04>4 or <-04>4<-03> + # See https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03 + + # Instead it defaults to UTC for these values. Here we process the quoted + # values and convert them into letters. If the zone name has "GMT", we use + # that as the replacement prefix, otherwise a default "STD" is used. Zones + # that have a quoted suffix have their suffix replaced with "DST". + + my ($tzstr, $name) = @_; + + if ( $tzstr =~ /(<(?[^>]+)>)([^<]+)(?<.+>)?(?.+)?/ ) { + my ($tzprefix, $tzsuffix, $tzrest, $offset, $offsetprefix) = ("") x 5; + + if ( defined($+{std}) ) { + my $std = $+{std}; + + if ( lc($name) =~ m/gmt/) { + $tzprefix = "GMT"; + } else { + $tzprefix = "STD"; + } + + if ( $std =~ m/\+/ ) { + $offset = sprintf "%d", $std =~ s/\+//r; + $offsetprefix = "-"; + } else { + $offset = sprintf "%d", $std =~ s/\-//r; + } + + my @chars = split(//, $offset); + if ( @chars > 2 ) { + my $hours = $chars[-3]; + if ( defined( $chars[-4] ) ) { + $hours = $chars[-4].$hours; + } + + $offset = $hours.":".$chars[-2].$chars[-1]; + } + + $offset = $offsetprefix.$offset; + } + + if ( defined($+{dst}) ) { + $tzsuffix = "DST"; + } + + if ( defined($+{rest}) ) { + $tzrest = $+{rest}; + } + + return $tzprefix.$offset.$tzsuffix.$tzrest; + } + + return $tzstr; +} + +1; \ No newline at end of file diff --git a/scripts/perl/timezones/tests.pl b/scripts/perl/timezones/tests.pl new file mode 100644 index 0000000000..3aec76ff68 --- /dev/null +++ b/scripts/perl/timezones/tests.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl +=pod +Tests to verify that the provided modifications to timezone formats produce +the correct results. The first set of tests verify the fixTzstr subroutine +converts the quoted values to something that won't make FreeSWITCH default to +UTC. + +The second set of tests confirms that those timezone changes actually produce +the correct timestamps. + +Make sure FreeSWITCH already has already loaded the timezones.conf.xml that you +want to test. + +To run tests: + +TIMEZONES_XML_PATH=path/to/timezones.conf.xml prove tests.pl +=cut + +use strict; +use warnings; +use Test::More; +use ESL; +use XML::LibXML::Reader; + +require "./fix-tzstr.pl"; + +use Env qw(TIMEZONES_XML_PATH); +die "The TIMEZONES_XML_PATH environment variable must be set to test timezones." unless ( defined($TIMEZONES_XML_PATH) ); + +ok( fixTzstr("<-02>2", "doesntmatterhere") eq "STD2" ); +ok( fixTzstr("EST5EDT,M3.2.0,M11.1.0", "US/Eastern") eq "EST5EDT,M3.2.0,M11.1.0" ); +ok( fixTzstr("<+11>-11", "GMT-11") eq "GMT-11" ); +ok( fixTzstr("<-02>2<-01>,M3.5.0/-1,M10.5.0/0", "America/Godthab") eq "STD2DST,M3.5.0/-1,M10.5.0/0" ); + +my $test_count = 4; + +my $tz_fmt = "%Y-%m-%d %H:%M:%S"; +my $c = new ESL::ESLconnection("127.0.0.1", "8021", "ClueCon"); +$c->api("reloadxml")->getBody(); +my $epoch = $c->api("strepoch")->getBody(); +run_tests($epoch); +run_tests("1699613236"); # testing DST, add more epochs as needed + +sub run_tests { + my $epoch = shift; + my $reader = XML::LibXML::Reader->new(location => $TIMEZONES_XML_PATH); + while ($reader->read) { + my $tag = $reader; + if ( $tag->name eq "zone" && $tag->hasAttributes() ) { + my $zn = $tag->getAttribute("name"); + + my $cmd = `TZ='$zn' date +'$tz_fmt' --date='\@$epoch'`; + my $sys_time = $cmd =~ s/\n//r; + my $fs_time = $c->api("strftime_tz $zn $epoch|$tz_fmt")->getBody(); + + ok ( $sys_time eq $fs_time, $zn ) or diag( + " (sys) $sys_time\t(fs) $fs_time" + ); + + $test_count++; + } + } +} + +done_testing($test_count); \ No newline at end of file diff --git a/scripts/perl/timezone-gen.pl b/scripts/perl/timezones/timezone-gen.pl similarity index 90% rename from scripts/perl/timezone-gen.pl rename to scripts/perl/timezones/timezone-gen.pl index e812023ef0..86822cc553 100755 --- a/scripts/perl/timezone-gen.pl +++ b/scripts/perl/timezones/timezone-gen.pl @@ -1,10 +1,12 @@ #!/usr/bin/perl use strict; +use warnings; use Getopt::Long; use XML::Entities; use HTML::Entities; +require "./fix-tzstr.pl"; my $base = "/usr/share/zoneinfo"; my $output = "timezones.conf.xml"; @@ -18,7 +20,7 @@ my $res = GetOptions( "base=s" => \$base, "debug+" => \$debug, "help" => \$help, - "output" => \$output + "output=s" => \$output ); if ( !$res || $help ) { print "$0 [--base=/usr/share/zoneinfo] [--output=timezones.conf.xml] [--debug] [--help]\n"; @@ -64,7 +66,9 @@ foreach my $name ( sort( keys(%name_to_file) ) ) { next; } - $zones{$name} = pop(@strings); + my $tzstr = fixTzstr( pop(@strings), $name ); + + $zones{$name} = $tzstr; } open( my $out, ">$output" ); @@ -83,7 +87,7 @@ foreach my $zone ( sort( keys(%zones) ) ) { } $lastprefix = $newprefix; - print $out "\t\n"; + print $out " " x 8, "\n"; } print $out " " x 4, "\n"; print $out "\n"; From b6ccc27e6fc8b74aacc8476c2c43f520ea03cc5d Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 4 Sep 2023 13:10:26 +0300 Subject: [PATCH 090/123] [core] JB audio: check for jb type and silence some debug. (#1191) --- src/switch_jitterbuffer.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/switch_jitterbuffer.c b/src/switch_jitterbuffer.c index 6aa872c439..6f142aec6d 100644 --- a/src/switch_jitterbuffer.c +++ b/src/switch_jitterbuffer.c @@ -1109,17 +1109,19 @@ SWITCH_DECLARE(void) switch_jb_set_session(switch_jb_t *jb, switch_core_session_ jb->codec = switch_core_session_get_read_codec(session); jb->session = session; jb->channel = switch_core_session_get_channel(session); - if (!strcmp(jb->codec->implementation->iananame, "opus")) { - if (switch_channel_var_true(jb->channel, "rtp_jitter_buffer_accelerate")) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec is %s, accelerate on\n", jb->codec->implementation->iananame); - jb->elastic = SWITCH_TRUE; + if (jb->type == SJB_AUDIO) { + if (!strcmp(jb->codec->implementation->iananame, "opus")) { + if (switch_channel_var_true(jb->channel, "rtp_jitter_buffer_accelerate")) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "audio codec is %s, accelerate on\n", jb->codec->implementation->iananame); + jb->elastic = SWITCH_TRUE; + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "audio codec is %s, accelerate off\n", jb->codec->implementation->iananame); + jb->elastic = SWITCH_FALSE; + } } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec is %s, accelerate off\n", jb->codec->implementation->iananame); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "audio codec is not Opus: %s\n", jb->codec->implementation->iananame); jb->elastic = SWITCH_FALSE; } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "codec not opus: %s\n", jb->codec->implementation->iananame); - jb->elastic = SWITCH_FALSE; } if (jb->type == SJB_VIDEO && !switch_test_flag(jb, SJB_QUEUE_ONLY) && From ebcb099a0191740832d4e0763e22bdcc3b634c37 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 1 Sep 2023 11:23:28 +0100 Subject: [PATCH 091/123] [core] Coverity 1325269 Dereference before null check --- src/switch_jitterbuffer.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/switch_jitterbuffer.c b/src/switch_jitterbuffer.c index 6f142aec6d..655fa022c2 100644 --- a/src/switch_jitterbuffer.c +++ b/src/switch_jitterbuffer.c @@ -1719,20 +1719,13 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp } } - if (node) { - status = SWITCH_STATUS_SUCCESS; + *packet = node->packet; + *len = node->len; + jb->last_len = *len; + packet->header.version = 2; + hide_node(node, SWITCH_TRUE); - *packet = node->packet; - *len = node->len; - jb->last_len = *len; - packet->header.version = 2; - hide_node(node, SWITCH_TRUE); - - jb_debug(jb, 2, "GET packet ts:%u seq:%u %s\n", ntohl(packet->header.ts), ntohs(packet->header.seq), packet->header.m ? " " : ""); - - } else { - status = SWITCH_STATUS_MORE_DATA; - } + jb_debug(jb, 2, "GET packet ts:%u seq:%u %s\n", ntohl(packet->header.ts), ntohs(packet->header.seq), packet->header.m ? " " : ""); end: From 4c51ba9064292c363d6dc85ca1ec2290c2918821 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 1 Sep 2023 11:27:01 +0100 Subject: [PATCH 092/123] [core] Coverity 1364946 Unchecked return value --- src/switch_core_media.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 252d947035..d61b39e710 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -6732,6 +6732,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void float fps = 15.0f; switch_image_t *last_frame = NULL; int last_w = 0, last_h = 0, kps = 0; + switch_status_t res; if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) { return NULL; @@ -6739,10 +6740,12 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void if (!(smh = session->media_handle)) { switch_core_session_rwunlock(session); + return NULL; } - switch_core_session_get_partner(session, &b_session); + res = switch_core_session_get_partner(session, &b_session); + (void)res; switch_channel_set_flag(session->channel, CF_VIDEO_WRITING); @@ -6763,7 +6766,6 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void fr.buflen = buflen - 12; switch_core_media_gen_key_frame(session); - if (smh->video_write_fh) { if (smh->video_write_fh->mm.fps) { fps = smh->video_write_fh->mm.fps; @@ -6803,8 +6805,6 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void switch_channel_up_nosig(session->channel) && smh->video_write_fh && switch_test_flag(smh->video_write_fh, SWITCH_FILE_OPEN)) { switch_status_t wstatus = SWITCH_STATUS_FALSE; - - switch_core_timer_next(&timer); switch_mutex_lock(v_engine->mh.file_write_mutex); @@ -6847,12 +6847,14 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void switch_set_flag_locked(smh->video_write_fh, SWITCH_FILE_FLAG_VIDEO_EOF); } } + switch_mutex_unlock(v_engine->mh.file_write_mutex); } if (last_frame) { int x = 0; switch_rgb_color_t bgcolor; + switch_color_set_rgb(&bgcolor, "#000000"); switch_img_fill(last_frame, 0, 0, last_frame->d_w, last_frame->d_h, &bgcolor); fr.img = last_frame; @@ -6863,12 +6865,12 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void fr.flags = SFF_USE_VIDEO_TIMESTAMP|SFF_RAW_RTP|SFF_RAW_RTP_PARSE_FRAME; switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_FORCE, 0); } + switch_core_media_gen_key_frame(session); switch_core_session_request_video_refresh(session); switch_img_free(&last_frame); } - switch_core_timer_destroy(&timer); switch_core_session_rwunlock(session); @@ -6878,7 +6880,6 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void switch_core_session_rwunlock(b_session); } - v_engine->thread_write_lock = 0; switch_mutex_unlock(smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO]); From bb9afcb3880c37acff83fadf0c93ce248128f592 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 8 Sep 2023 18:17:57 +0100 Subject: [PATCH 093/123] [core] Coverity fixes * [core] Coverity 1518099, 1518097, 1518098 (Unchecked return value from library) * [core] Coverity 1468551 Unchecked return value * [core] Coverity 1468293 Unchecked return value * [core] Coverity 1468274 Explicit null dereferenced * [core] Coverity 1395588 Unchecked return value * [core] Coverity 1395515 Logically dead code * [core] Coverity 1364984 Result is not floating-point * [core] Coverity 1395554, 1468440 Dereference before null check * [core] Coverity 1024487 Dereference after null check * [core] Coverity 1024872 Unchecked return value * [core] Coverity 1025822 Unchecked return value * [core] Coverity 1025823 Unchecked return value * [core] Coverity 1087637, 1346467, 1087638 Unchecked return value * [core] Coverity 1107607 Unchecked return value * [core] Coverity 1210777 Unchecked return value * [core] Coverity 1227670 Dereference before null check * [core] Coverity 1024551 Logically dead code * [core] Coverity 1024560 Logically dead code * [core] Coverity 1024664 Operands don't affect result * [core] Coverity 1364957 Dereference after null check * [core] Coverity 1395572 Logically dead code * [core] Coverity 1412459 Unchecked return value * [core] Coverity 1412490 Unchecked return value * [core] Coverity 1395515/2 Logically dead code * [core] Coverity cleanup --- src/cJSON.c | 44 +++++++++++++++++++------------------- src/switch_core_media.c | 43 ++++++++++++++++++++++--------------- src/switch_core_memory.c | 5 ++++- src/switch_core_sqldb.c | 8 ++++--- src/switch_cpp.cpp | 13 +++++------ src/switch_curl.c | 34 ++++++++++++++++++++++++----- src/switch_event.c | 9 +++++--- src/switch_ivr.c | 12 +++++++++-- src/switch_ivr_async.c | 2 +- src/switch_ivr_originate.c | 8 ++----- src/switch_ivr_play_say.c | 10 ++++++--- src/switch_stun.c | 23 ++++++++++++++++---- src/switch_vpx.c | 2 +- src/switch_xml.c | 9 +++----- 14 files changed, 142 insertions(+), 80 deletions(-) diff --git a/src/cJSON.c b/src/cJSON.c index 6d0e4946fd..ae0a2e2007 100644 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -1104,34 +1104,32 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i buffer->length = default_buffer_size; buffer->format = format; buffer->hooks = *hooks; - if (buffer->buffer == NULL) - { + + if (buffer->buffer == NULL) { goto fail; } /* print the value */ - if (!print_value(item, buffer)) - { + if (!print_value(item, buffer)) { goto fail; } + update_offset(buffer); /* check if reallocate is available */ - if (hooks->reallocate != NULL) - { + if (hooks->reallocate != NULL) { printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); if (printed == NULL) { goto fail; } + buffer->buffer = NULL; - } - else /* otherwise copy the JSON over to a new buffer */ - { + } else { /* otherwise copy the JSON over to a new buffer */ printed = (unsigned char*) hooks->allocate(buffer->offset + 1); - if (printed == NULL) - { + if (printed == NULL) { goto fail; } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); printed[buffer->offset] = '\0'; /* just to be sure */ @@ -1142,16 +1140,10 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i return printed; fail: - if (buffer->buffer != NULL) - { + if (buffer->buffer != NULL) { hooks->deallocate(buffer->buffer); } - if (printed != NULL) - { - hooks->deallocate(printed); - } - return NULL; } @@ -1942,33 +1934,41 @@ static cJSON_bool add_item_to_object(cJSON * const object, const char * const st CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { - add_item_to_object(object, string, item, &global_hooks, false); + cJSON_bool res = add_item_to_object(object, string, item, &global_hooks, false); + (void)res; } /* Add an item to an object with constant string as key */ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { - add_item_to_object(object, string, item, &global_hooks, true); + cJSON_bool res = add_item_to_object(object, string, item, &global_hooks, true); + (void)res; } CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { + cJSON_bool res; + if (array == NULL) { return; } - add_item_to_array(array, create_reference(item, &global_hooks)); + res = add_item_to_array(array, create_reference(item, &global_hooks)); + (void)res; } CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) { + cJSON_bool res; + if ((object == NULL) || (string == NULL)) { return; } - add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); + res = add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); + (void)res; } CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 252d947035..0c92a2a156 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -722,13 +722,10 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se exists = (type == pmap->type && !strcasecmp(name, pmap->iananame) && pmap->pt == pt && (!pmap->rate || rate == pmap->rate) && (!pmap->ptime || pmap->ptime == ptime)); break; case SWITCH_MEDIA_TYPE_VIDEO: - if (sdp_type == SDP_TYPE_RESPONSE) { - exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame)); - } else { - exists = (type == pmap->type && !strcasecmp(name, pmap->iananame)); - } + exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECK PMAP %s:%s %d %s:%s %d ... %d\n", - name, sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pt, + name, "RES", pt, pmap->iananame, pmap->sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pmap->pt, exists); @@ -2524,7 +2521,7 @@ static void check_jb_sync(switch_core_session_t *session) } if (!jb_sync_msec && frames) { - jb_sync_msec = (double)(1000 / fps) * frames; + jb_sync_msec = ((double)1000 / fps) * frames; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), @@ -4624,9 +4621,10 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s { switch_core_session_t *other_session = NULL; switch_core_session_message_t *msg; + switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_core_session_get_partner(session, &other_session); - + status = switch_core_session_get_partner(session, &other_session); + (void)status; if (switch_channel_test_flag(session->channel, CF_STREAM_CHANGED)) { switch_channel_clear_flag(session->channel, CF_STREAM_CHANGED); @@ -4662,13 +4660,15 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s if (switch_channel_test_flag(other_session->channel, CF_AWAITING_STREAM_CHANGE)) { uint8_t proceed = 1; const char *sdp_in, *other_ep; + uint8_t res = 0; if ((other_ep = switch_channel_get_variable(session->channel, "ep_codec_string"))) { switch_channel_set_variable(other_session->channel, "codec_string", other_ep); } sdp_in = switch_channel_get_variable(other_session->channel, SWITCH_R_SDP_VARIABLE); - switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST); + res = switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST); + (void)res; switch_core_media_activate_rtp(other_session); msg = switch_core_session_alloc(other_session, sizeof(*msg)); msg->message_id = SWITCH_MESSAGE_INDICATE_RESPOND; @@ -13587,6 +13587,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (zstr(attr->a_name)) { continue; } + if (!strcasecmp(attr->a_name, "ptime")) { dptime = atoi(attr->a_value); break; @@ -13599,22 +13600,27 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if ((m->m_type == sdp_media_audio || m->m_type == sdp_media_video) && m->m_port) { for (map = m->m_rtpmaps; map; map = map->rm_next) { int found = 0; + for (attr = m->m_attributes; attr && found < 2; attr = attr->a_next) { if (zstr(attr->a_name)) { continue; } + if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) { ptime = atoi(attr->a_value); found++; } + if (!strcasecmp(attr->a_name, "rtcp-mux")) { if (switch_channel_var_true(channel, "rtcp_mux_auto_detect")) { switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "setting rtcp-mux from sdp\n"); switch_channel_set_variable(channel, "rtcp_mux", "true"); } + found++; } } + switch_core_media_add_payload_map(session, m->m_type == sdp_media_audio ? SWITCH_MEDIA_TYPE_AUDIO : SWITCH_MEDIA_TYPE_VIDEO, map->rm_encoding, @@ -13640,11 +13646,13 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (zstr(attr->a_name)) { continue; } + if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) { ptime = atoi(attr->a_value); break; } } + connection = sdp->sdp_connection; if (m->m_connections) { connection = m->m_connections; @@ -13658,7 +13666,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) { for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13679,19 +13687,20 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (match) { add_audio_codec(map, imp, ptime, buf, sizeof(buf)); } - } } } else { for (i = 0; i < num_codecs; i++) { const switch_codec_implementation_t *imp = codecs[i]; + if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO || imp->ianacode > 127 || already_did[imp->ianacode]) { continue; } + for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13724,11 +13733,10 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess break; } - if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) { for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13752,11 +13760,11 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess } else { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame); } + already_did[imp->ianacode] = 1; } } } - } else { for (i = 0; i < num_codecs; i++) { const switch_codec_implementation_t *imp = codecs[i]; @@ -13772,7 +13780,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13793,6 +13801,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess } else { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame); } + already_did[imp->ianacode] = 1; } } diff --git a/src/switch_core_memory.c b/src/switch_core_memory.c index 7d3f4adbd7..77be1812c5 100644 --- a/src/switch_core_memory.c +++ b/src/switch_core_memory.c @@ -501,9 +501,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(switch_m #if APR_POOL_DEBUG fspr_pool_destroy_debug(tmp_pool, func); #else - fspr_pool_destroy(tmp_pool); + if (tmp_pool) { + fspr_pool_destroy(tmp_pool); + } #endif #ifdef USE_MEM_LOCK + switch_mutex_unlock(memory_manager.mem_lock); #endif } diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 5a75aeb573..817a7a7586 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -2065,6 +2065,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) switch_status_t status; uint32_t ttl = 0; uint32_t i; + switch_status_t res; if (!zstr(qm->pre_trans_execute)) { switch_cache_db_execute_sql_real(qm->event_db, qm->pre_trans_execute, &errmsg); @@ -2126,7 +2127,8 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) for (i = 0; (qm->max_trans == 0 || ttl <= qm->max_trans) && (i < qm->numq); i++) { switch_mutex_lock(qm->mutex); - switch_queue_trypop(qm->sql_queue[i], &pop); + res = switch_queue_trypop(qm->sql_queue[i], &pop); + (void)res; switch_mutex_unlock(qm->mutex); if (pop) break; } @@ -2138,6 +2140,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) switch_mutex_unlock(qm->mutex); ttl++; } + switch_safe_free(pop); if (status != SWITCH_STATUS_SUCCESS) break; } else { @@ -2153,7 +2156,6 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) } } - end: switch(qm->event_db->type) { @@ -2190,11 +2192,11 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) } } - switch_mutex_lock(qm->mutex); for (i = 0; i < qm->numq; i++) { qm->written[i] = qm->pre_written[i]; } + switch_mutex_unlock(qm->mutex); return ttl; diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index fe71a6400a..cd234a30e5 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -98,6 +98,7 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout) void *pop = NULL; Event *ret = NULL; switch_event_t *event; + switch_status_t res; if (!ready) { return NULL; @@ -105,14 +106,16 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout) if (block) { if (timeout > 0) { - switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec + res = switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec } else { - switch_queue_pop(events, &pop); + res = switch_queue_pop(events, &pop); } } else { - switch_queue_trypop(events, &pop); + res = switch_queue_trypop(events, &pop); } + (void)res; + if ((event = (switch_event_t *) pop)) { ret = new Event(event, 1); } @@ -138,9 +141,7 @@ SWITCH_DECLARE(void) EventConsumer::cleanup() node_index = 0; - if (events) { - switch_queue_interrupt_all(events); - } + switch_queue_interrupt_all(events); while(switch_queue_trypop(events, &pop) == SWITCH_STATUS_SUCCESS) { switch_event_t *event = (switch_event_t *) pop; diff --git a/src/switch_curl.c b/src/switch_curl.c index d6cfd6ce19..0a8cb682c3 100644 --- a/src/switch_curl.c +++ b/src/switch_curl.c @@ -64,6 +64,7 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, curl_mime *mime = NULL; curl_mimepart *part = NULL; uint8_t added = 0; + switch_CURLcode curl_code = CURLE_OK; #else struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; @@ -98,9 +99,21 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) part = curl_mime_addpart(mime); - curl_mime_name(part, pname); - curl_mime_filename(part, fname); - curl_mime_filedata(part, hp->value); + if ((curl_code = curl_mime_name(part, pname))) { + free(pname); + goto error; + } + + if ((curl_code = curl_mime_filename(part, fname))) { + free(pname); + goto error; + } + + if ((curl_code = curl_mime_filedata(part, hp->value))) { + free(pname); + goto error; + } + added++; #else curl_formadd(&formpost, @@ -117,8 +130,14 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, } else { #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) part = curl_mime_addpart(mime); - curl_mime_name(part, hp->name); - curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED); + if ((curl_code = curl_mime_name(part, hp->name))) { + goto error; + } + + if ((curl_code = curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED))) { + goto error; + } + added++; #else curl_formadd(&formpost, @@ -131,6 +150,11 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, } #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + error: + if (curl_code) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CURL error occured. Error code: %d Error msg: [%s]\n", curl_code, switch_curl_easy_strerror(curl_code)); + } + if (!added) { curl_mime_free(mime); mime = NULL; diff --git a/src/switch_event.c b/src/switch_event.c index 02a6f81505..8a8c8d6c35 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -553,6 +553,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) switch_hash_index_t *hi; const void *var; void *val; + switch_status_t res; if (switch_core_test_flag(SCF_MINIMAL)) { return SWITCH_STATUS_SUCCESS; @@ -565,7 +566,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) unsub_all_switch_event_channel(); if (EVENT_CHANNEL_DISPATCH_QUEUE) { - switch_queue_trypush(EVENT_CHANNEL_DISPATCH_QUEUE, NULL); + res = switch_queue_trypush(EVENT_CHANNEL_DISPATCH_QUEUE, NULL); + (void)res; switch_queue_interrupt_all(EVENT_CHANNEL_DISPATCH_QUEUE); } @@ -573,10 +575,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch queues\n"); for(x = 0; x < (uint32_t)DISPATCH_THREAD_COUNT; x++) { - switch_queue_trypush(EVENT_DISPATCH_QUEUE, NULL); + res = switch_queue_trypush(EVENT_DISPATCH_QUEUE, NULL); + (void)res; } - switch_queue_interrupt_all(EVENT_DISPATCH_QUEUE); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch threads\n"); @@ -595,6 +597,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) if (THREAD_COUNT == last) { x++; } + last = THREAD_COUNT; } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 77d957fb7c..7bfe0186f6 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1788,6 +1788,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ if (switch_channel_test_flag(channel, CF_MEDIA_TRANS)) { switch_core_session_rwunlock(session); + return SWITCH_STATUS_INUSE; } @@ -1798,6 +1799,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ } if (switch_channel_test_flag(channel, CF_PROXY_MODE)) { + switch_status_t res = SWITCH_STATUS_SUCCESS; + status = SWITCH_STATUS_SUCCESS; /* If we had early media in bypass mode before, it is no longer relevant */ @@ -1816,6 +1819,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ if (switch_core_session_receive_message(session, &msg) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't re-establsh media on %s\n", switch_channel_get_name(channel)); switch_core_session_rwunlock(session); + return SWITCH_STATUS_GENERR; } @@ -1832,7 +1836,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL); switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL); switch_channel_wait_for_flag(channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL); - switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); + res = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); } if ((flags & SMF_REBRIDGE) @@ -1844,10 +1848,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL); switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL); switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL); - switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0); + res = switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0); switch_channel_clear_state_handler(other_channel, NULL); switch_core_session_rwunlock(other_session); } + + (void)res; + if (other_channel) { switch_channel_clear_state_handler(channel, NULL); } @@ -1862,6 +1869,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ } else { switch_ivr_uuid_bridge(uuid, other_uuid); } + switch_channel_wait_for_flag(channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL); switch_channel_wait_for_flag(other_channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL); } diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 9a33b43340..4075f0adce 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -474,7 +474,7 @@ static dm_match_t switch_ivr_dmachine_check_match(switch_ivr_dmachine_t *dmachin if (is_timeout) { if (both_bp) { - r_bp = exact_bp ? exact_bp : both_bp; + r_bp = exact_bp; } } diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index a39553e2f9..0b06d6029c 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -4961,9 +4961,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_enterprise_orig_and_bridge(switch_cor switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, b_key); } - if (peer_session) { - switch_core_session_rwunlock(peer_session); - } + switch_core_session_rwunlock(peer_session); } return status; @@ -5026,9 +5024,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_orig_and_bridge(switch_core_session_t switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, b_key); } - if (peer_session) { - switch_core_session_rwunlock(peer_session); - } + switch_core_session_rwunlock(peer_session); } return status; diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 33f3a4e51a..b39d42f657 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -3202,6 +3202,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess const char *other_uuid, *moh = NULL; int moh_br = 0; switch_input_args_t args = { 0 }; + switch_status_t res; + args.input_callback = hold_on_dtmf; args.buf = (void *) unhold_key; args.buflen = (uint32_t) strlen(unhold_key); @@ -3232,11 +3234,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess } if (!zstr(moh) && strcasecmp(moh, "silence")) { - switch_ivr_play_file(session, NULL, moh, &args); + res = switch_ivr_play_file(session, NULL, moh, &args); } else { - switch_ivr_collect_digits_callback(session, &args, 0, 0); + res = switch_ivr_collect_digits_callback(session, &args, 0, 0); } + (void)res; + if (moh_br) { switch_channel_stop_broadcast(other_channel); } @@ -3246,10 +3250,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess return SWITCH_STATUS_SUCCESS; } - } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Channel %s is not in a bridge\n", switch_channel_get_name(channel)); + return SWITCH_STATUS_FALSE; } diff --git a/src/switch_stun.c b/src/switch_stun.c index b0ff45b3dc..d4a2c96503 100644 --- a/src/switch_stun.c +++ b/src/switch_stun.c @@ -696,8 +696,11 @@ SWITCH_DECLARE(char *) switch_stun_host_lookup(const char *host, switch_memory_p { switch_sockaddr_t *addr = NULL; char buf[30]; + switch_status_t res; + + res = switch_sockaddr_info_get(&addr, host, SWITCH_UNSPEC, 0, 0, pool); + (void)res; - switch_sockaddr_info_get(&addr, host, SWITCH_UNSPEC, 0, 0, pool); return switch_core_strdup(pool, switch_str_nil(switch_get_addr(buf, sizeof(buf), addr))); } @@ -720,6 +723,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, int funny = 0; int size = sizeof(buf); int xlen = sizeof(switch_stun_packet_header_t); + switch_status_t res; switch_assert(err); @@ -729,25 +733,30 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, *err = "Success"; - switch_sockaddr_info_get(&from_addr, NULL, SWITCH_UNSPEC, 0, 0, pool); + res = switch_sockaddr_info_get(&from_addr, NULL, SWITCH_UNSPEC, 0, 0, pool); + (void)res; if (switch_sockaddr_info_get(&local_addr, *ip, SWITCH_UNSPEC, *port, 0, pool) != SWITCH_STATUS_SUCCESS) { *err = "Local Address Error!"; + return SWITCH_STATUS_FALSE; } if (switch_sockaddr_info_get(&remote_addr, stunip, SWITCH_UNSPEC, stunport, 0, pool) != SWITCH_STATUS_SUCCESS) { *err = "Remote Address Error!"; + return SWITCH_STATUS_FALSE; } if (switch_socket_create(&sock, AF_INET, SOCK_DGRAM, 0, pool) != SWITCH_STATUS_SUCCESS) { *err = "Socket Error!"; + return SWITCH_STATUS_FALSE; } if (switch_socket_bind(sock, local_addr) != SWITCH_STATUS_SUCCESS) { *err = "Bind Error!"; + return SWITCH_STATUS_FALSE; } @@ -779,7 +788,6 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, *ip = NULL; *port = 0; - for (;;) { bytes = sizeof(buf); if (switch_socket_recvfrom(from_addr, sock, 0, (char *) &buf, &bytes) == SWITCH_STATUS_SUCCESS && bytes > 0) { @@ -790,10 +798,12 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, *err = "Timeout"; switch_socket_shutdown(sock, SWITCH_SHUTDOWN_READWRITE); switch_socket_close(sock); + return SWITCH_STATUS_TIMEOUT; } switch_cond_next(); } + switch_socket_close(sock); if (funny) { @@ -803,14 +813,15 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, packet = switch_stun_packet_parse(start, size); if (!packet) { *err = "Invalid STUN/ICE packet"; + return SWITCH_STATUS_FALSE; } + end_buf = buf + ((sizeof(buf) > packet->header.length) ? packet->header.length : sizeof(buf)); switch_stun_packet_first_attribute(packet, attr); switch_assert(attr); - do { switch (attr->type) { case SWITCH_STUN_ATTR_MAPPED_ADDRESS: @@ -818,6 +829,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, switch_stun_ip_t *tmp = (switch_stun_ip_t *) attr->value; tmp->address ^= ntohl(0xabcdabcd); } + switch_stun_packet_attribute_get_mapped_address(attr, rip, sizeof(rip), &rport); break; case SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS: @@ -831,12 +843,15 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, if (!switch_stun_packet_next_attribute(attr, end_buf)) { break; } + xlen += 4 + switch_stun_attribute_padded_length(attr); + } while (xlen <= packet->header.length); if (packet->header.type == SWITCH_STUN_BINDING_RESPONSE) { *ip = switch_core_strdup(pool, rip); *port = rport; + return SWITCH_STATUS_SUCCESS; } else { *err = "Invalid Reply"; diff --git a/src/switch_vpx.c b/src/switch_vpx.c index 751f2b8c5b..e65db6b6c8 100644 --- a/src/switch_vpx.c +++ b/src/switch_vpx.c @@ -1238,7 +1238,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t * if (context->last_received_seq && context->last_received_seq + 1 != frame->seq) { switch_log_printf(SWITCH_CHANNEL_LOG, VPX_SWITCH_LOG_LEVEL, "Packet loss detected last=%d got=%d lost=%d\n", context->last_received_seq, frame->seq, frame->seq - context->last_received_seq); - if (is_keyframe && context->vpx_packet_buffer) switch_buffer_zero(context->vpx_packet_buffer); + if (is_keyframe) switch_buffer_zero(context->vpx_packet_buffer); } context->last_received_seq = frame->seq; diff --git a/src/switch_xml.c b/src/switch_xml.c index 8ed7c27658..d54294df92 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1726,6 +1726,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) if ( rename(new_file_tmp,new_file) ) { goto done; } + if ((fd = open(new_file, O_RDONLY, 0)) > -1) { if ((xml = switch_xml_parse_fd(fd))) { if (strcmp(abs, SWITCH_GLOBAL_filenames.conf_name)) { @@ -1733,8 +1734,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) new_file = NULL; } } + close(fd); - fd = -1; } } @@ -1747,10 +1748,6 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) write_fd = NULL; } - if (fd > -1) { - close(fd); - } - switch_safe_free(new_file_tmp); switch_safe_free(new_file); @@ -2272,7 +2269,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key, switch_event_destroy(&my_params); } - if (status != SWITCH_STATUS_SUCCESS && root && *root) { + if (status != SWITCH_STATUS_SUCCESS && *root) { switch_xml_free(*root); *root = NULL; *domain = NULL; From dc3c0f00f31d3ab6bd58c68b6fd87edac3263b51 Mon Sep 17 00:00:00 2001 From: tmancill <1195611+tmancill@users.noreply.github.com> Date: Sat, 9 Sep 2023 09:26:04 -0700 Subject: [PATCH 094/123] misc readme updates (#2235) * Update README.md regarding the archived freeswitch-users mailing list * update docker/README.md to suggest --network host --- README.md | 4 ++-- docker/README.md | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 15cda2e22f..728486f891 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ This is the place to get answers faster and chat with other users in real time. Slack Community: * https://signalwire.community/ -Mailing list: +Mailing list (ARCHIVED): - * http://lists.freeswitch.org/mailman/listinfo/freeswitch-users + * http://lists.freeswitch.org/pipermail/freeswitch-users/ **Thank you for using FreeSWITCH!** diff --git a/docker/README.md b/docker/README.md index e9a321e699..e0ebfff2af 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,7 +2,7 @@ These are the official Docker files for master branch and the current release packages. ## Volumes -These containers are setup so that you can mount your freeswitch configuration form a host or data volume container. +These containers are set up so that you can mount your freeswitch configuration from a host or data volume container. To mount freeswitch Configuration ``` @@ -16,17 +16,19 @@ To mount tmp directory for storing recordings, etc The container also has a healthcheck where it does a fs_cli status check to make sure the freeswitch service is still running. -# Ports +## Ports -The container exposes the following ports: +The container should be run with host networking using `docker run --network host ...`. -- 5060/tcp 5060/udp 5080/tcp 5080/udp as SIP Signaling ports. -- 5066/tcp 7443/tcp as WebSocket Signaling ports. -- 8021/tcp as Event Socket port. -- 64535-65535/udp as media ports. -- 16384-32768/udp +If you prefer to (or for some reason must) publish individual ports via `--publish/-p`, refer to this [issue](https://github.com/moby/moby/issues/11185) and this [potential workaround](https://hub.docker.com/r/bettervoice/freeswitch-container/) regarding using docker with large port ranges. +The following ports will be used, depending upon your specific configuration: +- 5060/tcp, 5060/udp, 5080/tcp, 5080/udp - SIP signaling +- 5061/tcp, 5081/tcp - SIPS signaling +- 5066/tcp, 7443/tcp - WebSocket signaling +- 8021/tcp - the Event Socket +- 16384-32768/udp, 64535-65535/udp - media If you wish to help improve these please submit a pull request at: From c6ff92923d1f3ad008a0f872be6e4dc3fef72195 Mon Sep 17 00:00:00 2001 From: tmancill <1195611+tmancill@users.noreply.github.com> Date: Sat, 9 Sep 2023 09:38:50 -0700 Subject: [PATCH 095/123] updates for the Debian Dockerfile (#2234) * default to Debian bookworm * use DEBIAN_VERSION instead of lsb_release; gosu is in Debian since buster * update comments for FS_META_PACKAGE and exposed ports * fix SHELL invocation so 'RUN' works as expected in downstream builds See: https://docs.docker.com/engine/reference/builder/#shell --- docker/master/Dockerfile | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/docker/master/Dockerfile b/docker/master/Dockerfile index e9b626b400..4c73ecc6e4 100644 --- a/docker/master/Dockerfile +++ b/docker/master/Dockerfile @@ -1,56 +1,61 @@ # vim:set ft=dockerfile: -ARG DEBIAN_VERSION=buster +ARG DEBIAN_VERSION=bookworm FROM debian:${DEBIAN_VERSION} + +# ARGs are cleared after every FROM +# see: https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact +ARG DEBIAN_VERSION ARG TOKEN +# By default, install the full set of FreeSWITCH packages. Specify an alternative with: +# --build-arg="FS_META_PACKAGE=freeswitch-meta-vanilla" +# alternatives include: +# freeswitch-meta-bare +# freeswitch-meta-vanilla +# freeswitch-meta-sorbet +# freeswitch-meta-all-dbg +ARG FS_META_PACKAGE=freeswitch-meta-all + # Source Dockerfile: # https://github.com/docker-library/postgres/blob/master/9.4/Dockerfile # explicitly set user/group IDs RUN groupadd -r freeswitch --gid=999 && useradd -r -g freeswitch --uid=999 freeswitch -# grab gosu for easy step-down from root -RUN apt-get update && apt-get install -y --no-install-recommends dirmngr gnupg2 ca-certificates wget \ - && gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ - && gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 655DA1341B5207915210AFE936B4249FA7B0FB03 \ - && gpg2 --output /usr/share/keyrings/signalwire-freeswitch-repo.gpg --export 655DA1341B5207915210AFE936B4249FA7B0FB03 \ - && rm -rf /var/lib/apt/lists/* \ - && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" \ - && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" \ - && gpg --verify /usr/local/bin/gosu.asc \ - && rm /usr/local/bin/gosu.asc \ - && chmod +x /usr/local/bin/gosu \ - && apt-get purge -y --auto-remove ca-certificates wget dirmngr gnupg2 - # make the "en_US.UTF-8" locale so freeswitch will be utf-8 enabled by default -RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ +RUN apt-get update -qq \ + && apt-get install -y --no-install-recommends ca-certificates gnupg2 gosu locales wget \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 # https://freeswitch.org/confluence/display/FREESWITCH/Debian +# https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Installation/Linux/Debian_67240088/ -RUN apt-get update && apt-get install ca-certificates lsb-release -y --no-install-recommends \ +RUN wget --no-verbose --http-user=signalwire --http-password=${TOKEN} \ + -O /usr/share/keyrings/signalwire-freeswitch-repo.gpg \ + https://freeswitch.signalwire.com/repo/deb/debian-release/signalwire-freeswitch-repo.gpg \ && echo "machine freeswitch.signalwire.com login signalwire password ${TOKEN}" > /etc/apt/auth.conf \ - && echo "deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list \ - && apt-get update && apt-get install -y freeswitch-all \ - && apt-get purge -y --auto-remove ca-certificates lsb-release \ + && echo "deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ ${DEBIAN_VERSION} main" > /etc/apt/sources.list.d/freeswitch.list \ + && apt-get -qq update \ + && apt-get install -y ${FS_META_PACKAGE} \ + && apt-get purge -y --auto-remove \ && apt-get clean && rm -rf /var/lib/apt/lists/* COPY docker-entrypoint.sh / # Add anything else here ## Ports -# Open the container up to the world. -### 8021 fs_cli, 5060 5061 5080 5081 sip and sips, 64535-65535 rtp +# Document ports used by this container +### 8021 fs_cli, 5060 5061 5080 5081 sip and sips, 5066 ws, 7443 wss, 8081 8082 verto, 16384-32768, 64535-65535 rtp EXPOSE 8021/tcp EXPOSE 5060/tcp 5060/udp 5080/tcp 5080/udp EXPOSE 5061/tcp 5061/udp 5081/tcp 5081/udp +EXPOSE 5066/tcp EXPOSE 7443/tcp -EXPOSE 5070/udp 5070/tcp +EXPOSE 8081/tcp 8082/tcp EXPOSE 64535-65535/udp EXPOSE 16384-32768/udp - # Volumes ## Freeswitch Configuration VOLUME ["/etc/freeswitch"] @@ -61,11 +66,9 @@ VOLUME ["/tmp"] COPY build/freeswitch.limits.conf /etc/security/limits.d/ # Healthcheck to make sure the service is running -SHELL ["/bin/bash"] +SHELL ["/bin/bash", "-c"] HEALTHCHECK --interval=15s --timeout=5s \ CMD fs_cli -x status | grep -q ^UP || exit 1 ENTRYPOINT ["/docker-entrypoint.sh"] - - CMD ["freeswitch"] From 6f9e72c585265d8def8a613b36cd4f524c201980 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 4 Oct 2023 00:47:39 +0300 Subject: [PATCH 096/123] [libvpx] VP8: disallow thread count changes --- libs/libvpx/vp8/encoder/onyx_if.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/libvpx/vp8/encoder/onyx_if.c b/libs/libvpx/vp8/encoder/onyx_if.c index c091594121..00bab3f626 100644 --- a/libs/libvpx/vp8/encoder/onyx_if.c +++ b/libs/libvpx/vp8/encoder/onyx_if.c @@ -1447,6 +1447,11 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { last_h = cpi->oxcf.Height; prev_number_of_layers = cpi->oxcf.number_of_layers; + if (cpi->initial_width) { + // TODO(https://crbug.com/1486441): Allow changing thread counts; the + // allocation is done once in vp8_create_compressor(). + oxcf->multi_threaded = cpi->oxcf.multi_threaded; + } cpi->oxcf = *oxcf; switch (cpi->oxcf.Mode) { From c4115537e0c1c24abad011c102e25041d18bc7b4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 4 Oct 2023 18:24:16 +0300 Subject: [PATCH 097/123] [Core] Coverity: Use of 32-bit time_t * [Core] Coverity: 1500270 Use of 32-bit time_t * [Core] Coverity: 1500229 Use of 32-bit time_t * [Core] Coverity: 1500235 Use of 32-bit time_t * [Core] Coverity: 1500244 Use of 32-bit time_t * [Core] Coverity: 1500250 Use of 32-bit time_t * [Core] Coverity: 1500245 Use of 32-bit time_t * [Core] Coverity: 1500255 Use of 32-bit time_t * [Core] Coverity: 1500370 Use of 32-bit time_t * Cleanup --- src/switch_core_media.c | 12 ++++++------ src/switch_ivr_originate.c | 6 +++++- src/switch_rtp.c | 5 +++-- src/switch_utils.c | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index ca6c05e0a9..4b6d8aff8b 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -2066,13 +2066,13 @@ SWITCH_DECLARE(switch_status_t) switch_media_handle_create(switch_media_handle_t switch_mutex_init(&session->media_handle->control_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO].ssrc = - (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO] + (uint32_t) time(NULL)); + (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO] + (switch_time_t) time(NULL)); session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO].ssrc = - (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO] + (uint32_t) time(NULL) / 2); + (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO] + (switch_time_t) time(NULL) / 2); session->media_handle->engines[SWITCH_MEDIA_TYPE_TEXT].ssrc = - (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_TEXT] + (uint32_t) time(NULL) / 2); + (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_TEXT] + (switch_time_t) time(NULL) / 2); @@ -10526,7 +10526,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess } if (!smh->owner_id) { - smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) - port; + smh->owner_id = (uint32_t)(switch_time_t)switch_epoch_time_now(NULL) - port; } if (!smh->session_id) { @@ -11836,7 +11836,7 @@ SWITCH_DECLARE(void) switch_core_media_set_udptl_image_sdp(switch_core_session_t } if (!smh->owner_id) { - smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) - port; + smh->owner_id = (uint32_t)(switch_time_t)switch_epoch_time_now(NULL) - port; } if (!smh->session_id) { @@ -12050,7 +12050,7 @@ SWITCH_DECLARE(void) switch_core_media_patch_sdp(switch_core_session_t *session) family = strchr(smh->mparams->sipip, ':') ? "IP6" : "IP4"; if (!smh->owner_id) { - smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) * 31821U + 13849U; + smh->owner_id = (uint32_t)(switch_time_t) switch_epoch_time_now(NULL) * 31821U + 13849U; } if (!smh->session_id) { diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 0b06d6029c..3c1771682b 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -320,8 +320,10 @@ static int check_per_channel_timeouts(originate_global_t *oglobals, delayed_min = oglobals->originate_status[i].per_channel_delay_start; } } - early_exit_time = delayed_min - (uint32_t) elapsed; + + early_exit_time = delayed_min - (uint32_t)(switch_time_t) elapsed; } + for (i = 0; i < max; i++) { if (oglobals->originate_status[i].peer_channel && oglobals->originate_status[i].per_channel_delay_start && (elapsed > oglobals->originate_status[i].per_channel_delay_start || active_channels == 0)) { @@ -334,6 +336,7 @@ static int check_per_channel_timeouts(originate_global_t *oglobals, oglobals->originate_status[i].per_channel_timelimit_sec = 1; } } + if (oglobals->originate_status[i].per_channel_progress_timelimit_sec) { if (oglobals->originate_status[i].per_channel_progress_timelimit_sec > early_exit_time) { /* IN theory this check is not needed ( should just be if !0 then -= with no else), if its not 0 it should always be greater.... */ @@ -342,6 +345,7 @@ static int check_per_channel_timeouts(originate_global_t *oglobals, oglobals->originate_status[i].per_channel_progress_timelimit_sec = 1; } } + oglobals->originate_status[i].per_channel_delay_start -= delayed_min; } else { oglobals->originate_status[i].per_channel_delay_start = 0; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 17c93f2fa2..506085d86d 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -4324,8 +4324,9 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) { switch_sockaddr_create(&rtp_session->rtcp_from_addr, pool); } + rtp_session->seq = (uint16_t) rand(); - rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (uint32_t) switch_epoch_time_now(NULL)); + rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (switch_time_t) switch_epoch_time_now(NULL)); #ifdef DEBUG_TS_ROLLOVER rtp_session->last_write_ts = TS_ROLLOVER_START; #endif @@ -8061,7 +8062,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, /* If the marker was set, and the timestamp seems to have started over - set a new SSRC, to indicate this is a new stream */ if (m && !switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND) && (rtp_session->rtp_bugs & RTP_BUG_CHANGE_SSRC_ON_MARKER) && (rtp_session->flags[SWITCH_RTP_FLAG_RESET] || (rtp_session->ts <= rtp_session->last_write_ts && rtp_session->last_write_ts > 0))) { - switch_rtp_set_ssrc(rtp_session, (uint32_t) ((intptr_t) rtp_session + (uint32_t) switch_epoch_time_now(NULL))); + switch_rtp_set_ssrc(rtp_session, (uint32_t) ((intptr_t) rtp_session + (switch_time_t) switch_epoch_time_now(NULL))); } if (!switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO) && !switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL)) { diff --git a/src/switch_utils.c b/src/switch_utils.c index c51953f0cf..df7a507920 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -1161,7 +1161,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, switch_safe_free(dupfile); } - switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int) switch_epoch_time_now(NULL), rand() & 0xffff); + switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int)(switch_time_t) switch_epoch_time_now(NULL), rand() & 0xffff); if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) > -1) { if (file) { From 79ce08810120b681992a3e666bcbe8d2ac2a7383 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 5 Oct 2023 00:26:26 +0300 Subject: [PATCH 098/123] [Core] Coverity: Dereference before null check * [Core] Coverity: 1060958 Dereference before null check * [Core] Coverity: 1024236 Dereference before null check --- src/switch_ivr.c | 4 +++- src/switch_ivr_originate.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 7bfe0186f6..c36149c0a5 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -2814,11 +2814,13 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_ static int switch_ivr_set_xml_chan_var(switch_xml_t xml, const char *var, const char *val, int off) { char *data; - switch_size_t dlen = strlen(val) * 3 + 1; + switch_size_t dlen; switch_xml_t variable; if (!val) val = ""; + dlen = strlen(val) * 3 + 1; + if (!zstr(var) && ((variable = switch_xml_add_child_d(xml, var, off++)))) { if ((data = malloc(dlen))) { memset(data, 0, dlen); diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 3c1771682b..99c70991bd 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -1309,7 +1309,7 @@ static switch_status_t setup_ringback(originate_global_t *oglobals, originate_st } } - if (oglobals->session && (read_codec = switch_core_session_get_read_codec(oglobals->session))) { + if ((read_codec = switch_core_session_get_read_codec(oglobals->session))) { if (ringback_data && switch_is_file_path(ringback_data)) { if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR))) { ringback->asis++; From d08424384b643e6de7ef82e8d7550259e48dcc4a Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 5 Oct 2023 18:03:32 +0300 Subject: [PATCH 099/123] [Core] Coverity: 1024552 Logically dead code --- src/switch_utils.c | 23 ++++++++------- tests/unit/switch_core.c | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/src/switch_utils.c b/src/switch_utils.c index df7a507920..faffc1cc04 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -747,7 +747,7 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask, ip_t *maskv = mask; ip_t *ipv = ip; - switch_copy_string(host, string, sizeof(host)-1); + switch_copy_string(host, string, sizeof(host) - 1); bit_str = strchr(host, '/'); if (!bit_str) { @@ -758,22 +758,20 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask, bits = atoi(bit_str); ipv6 = strchr(string, ':'); if (ipv6) { - int i,n; + int32_t i, n; + uint32_t k; + if (bits < 0 || bits > 128) { return -2; } + bits = atoi(bit_str); switch_inet_pton(AF_INET6, host, (unsigned char *)ip); - for (n=bits,i=0 ;i < 16; i++){ - if (n >= 8) { - maskv->v6.s6_addr[i] = 0xFF; - n -= 8; - } else if (n < 8) { - maskv->v6.s6_addr[i] = 0xFF & ~(0xFF >> n); - n -= n; - } else if (n == 0) { - maskv->v6.s6_addr[i] = 0x00; - } + + for (n = bits, i = 0; i < 16; i++) { + k = (n > 8) ? 8 : n; + maskv->v6.s6_addr[i] = 0xFF & ~(0xFF >> k); /* k = 0 gives 0x00, k = 8 gives 0xFF */ + n -= k; } } else { if (bits < 0 || bits > 32) { @@ -786,6 +784,7 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask, maskv->v4 = 0xFFFFFFFF & ~(0xFFFFFFFF >> bits); } + *bitp = bits; return 0; diff --git a/tests/unit/switch_core.c b/tests/unit/switch_core.c index da93fbdef4..1159017571 100644 --- a/tests/unit/switch_core.c +++ b/tests/unit/switch_core.c @@ -53,6 +53,66 @@ FST_CORE_BEGIN("./conf") } FST_TEARDOWN_END() + FST_TEST_BEGIN(test_switch_parse_cidr_v6) + { + ip_t ip, mask; + uint32_t bits; + + fst_check(!switch_parse_cidr("fe80::/10", &ip, &mask, &bits)); + fst_check_int_equals(bits, 10); + fst_check_int_equals(ip.v6.s6_addr[0], 0xfe); + fst_check_int_equals(ip.v6.s6_addr[1], 0x80); + fst_check_int_equals(ip.v6.s6_addr[2], 0); + fst_check_int_equals(mask.v6.s6_addr[0], 0xff); + fst_check_int_equals(mask.v6.s6_addr[1], 0xc0); + fst_check_int_equals(mask.v6.s6_addr[2], 0); + + fst_check(!switch_parse_cidr("::/0", &ip, &mask, &bits)); + fst_check_int_equals(bits, 0); + fst_check_int_equals(ip.v6.s6_addr[0], 0); + fst_check_int_equals(ip.v6.s6_addr[1], 0); + fst_check_int_equals(ip.v6.s6_addr[2], 0); + fst_check_int_equals(mask.v6.s6_addr[0], 0); + fst_check_int_equals(mask.v6.s6_addr[1], 0); + fst_check_int_equals(mask.v6.s6_addr[2], 0); + + fst_check(!switch_parse_cidr("::1/128", &ip, &mask, &bits)); + fst_check_int_equals(bits, 128); + fst_check_int_equals(ip.v6.s6_addr[0], 0); + fst_check_int_equals(ip.v6.s6_addr[1], 0); + fst_check_int_equals(ip.v6.s6_addr[2], 0); + fst_check_int_equals(ip.v6.s6_addr[3], 0); + fst_check_int_equals(ip.v6.s6_addr[4], 0); + fst_check_int_equals(ip.v6.s6_addr[5], 0); + fst_check_int_equals(ip.v6.s6_addr[6], 0); + fst_check_int_equals(ip.v6.s6_addr[7], 0); + fst_check_int_equals(ip.v6.s6_addr[8], 0); + fst_check_int_equals(ip.v6.s6_addr[9], 0); + fst_check_int_equals(ip.v6.s6_addr[10], 0); + fst_check_int_equals(ip.v6.s6_addr[11], 0); + fst_check_int_equals(ip.v6.s6_addr[12], 0); + fst_check_int_equals(ip.v6.s6_addr[13], 0); + fst_check_int_equals(ip.v6.s6_addr[14], 0); + fst_check_int_equals(ip.v6.s6_addr[15], 1); + fst_check_int_equals(mask.v6.s6_addr[0], 0xff); + fst_check_int_equals(mask.v6.s6_addr[1], 0xff); + fst_check_int_equals(mask.v6.s6_addr[2], 0xff); + fst_check_int_equals(mask.v6.s6_addr[3], 0xff); + fst_check_int_equals(mask.v6.s6_addr[4], 0xff); + fst_check_int_equals(mask.v6.s6_addr[5], 0xff); + fst_check_int_equals(mask.v6.s6_addr[6], 0xff); + fst_check_int_equals(mask.v6.s6_addr[7], 0xff); + fst_check_int_equals(mask.v6.s6_addr[8], 0xff); + fst_check_int_equals(mask.v6.s6_addr[9], 0xff); + fst_check_int_equals(mask.v6.s6_addr[10], 0xff); + fst_check_int_equals(mask.v6.s6_addr[11], 0xff); + fst_check_int_equals(mask.v6.s6_addr[12], 0xff); + fst_check_int_equals(mask.v6.s6_addr[13], 0xff); + fst_check_int_equals(mask.v6.s6_addr[14], 0xff); + fst_check_int_equals(mask.v6.s6_addr[15], 0xff); + } + FST_TEST_END() + #if ENABLE_SNPRINTFV_TESTS FST_TEST_BEGIN(test_snprintfv_1) { From f5a41d3092acc0d64c3912a2f8b0f692618b2f24 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 5 Oct 2023 18:05:32 +0300 Subject: [PATCH 100/123] [mod_pgsql] Coverity: 1227660 Logically dead code --- src/mod/databases/mod_pgsql/mod_pgsql.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/databases/mod_pgsql/mod_pgsql.c b/src/mod/databases/mod_pgsql/mod_pgsql.c index 0308f1f1fd..09d6b32e5c 100644 --- a/src/mod/databases/mod_pgsql/mod_pgsql.c +++ b/src/mod/databases/mod_pgsql/mod_pgsql.c @@ -113,7 +113,7 @@ static int db_is_up(switch_pgsql_handle_t *handle) char *err_str = NULL; int max_tries = DEFAULT_PGSQL_RETRIES; int code = 0; - int recon = 0; + switch_status_t recon = SWITCH_STATUS_FALSE; switch_byte_t sanity = 255; if (handle) { @@ -128,6 +128,7 @@ top: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle\n"); goto done; } + if (!handle->con) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Connection\n"); goto done; @@ -141,6 +142,7 @@ top: switch_yield(1); continue; } + break; } @@ -158,6 +160,7 @@ reset: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "PQstatus returned bad connection -- reconnection failed!\n"); goto error; } + handle->state = SWITCH_PGSQL_STATE_CONNECTED; handle->sock = PQsocket(handle->con); } @@ -193,6 +196,7 @@ error: switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection could not be re-established"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The connection could not be re-established\n"); } + if (!max_tries) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "Giving up!"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up!\n"); From 2ab7a3d323984a4df969ea19dadf86213308a361 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 6 Oct 2023 00:42:10 +0300 Subject: [PATCH 101/123] [libvpx] Fix bug with smaller width bigger size --- libs/libvpx/vp9/common/vp9_alloccommon.c | 12 +++++------ libs/libvpx/vp9/encoder/vp9_encoder.c | 27 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/libs/libvpx/vp9/common/vp9_alloccommon.c b/libs/libvpx/vp9/common/vp9_alloccommon.c index 7345e259b6..e2d76880bb 100644 --- a/libs/libvpx/vp9/common/vp9_alloccommon.c +++ b/libs/libvpx/vp9/common/vp9_alloccommon.c @@ -123,12 +123,6 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { if (cm->alloc_mi(cm, new_mi_size)) goto fail; } - if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) { - // Create the segmentation map structure and set to 0. - free_seg_map(cm); - if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) goto fail; - } - if (cm->above_context_alloc_cols < cm->mi_cols) { vpx_free(cm->above_context); cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( @@ -143,6 +137,12 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { cm->above_context_alloc_cols = cm->mi_cols; } + if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) { + // Create the segmentation map structure and set to 0. + free_seg_map(cm); + if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) goto fail; + } + if (vp9_alloc_loop_filter(cm)) goto fail; return 0; diff --git a/libs/libvpx/vp9/encoder/vp9_encoder.c b/libs/libvpx/vp9/encoder/vp9_encoder.c index 7f82a470b3..80824e304c 100644 --- a/libs/libvpx/vp9/encoder/vp9_encoder.c +++ b/libs/libvpx/vp9/encoder/vp9_encoder.c @@ -1915,6 +1915,17 @@ static void alloc_copy_partition_data(VP9_COMP *cpi) { } } +static void free_copy_partition_data(VP9_COMP *cpi) { + vpx_free(cpi->prev_partition); + cpi->prev_partition = NULL; + vpx_free(cpi->prev_segment_id); + cpi->prev_segment_id = NULL; + vpx_free(cpi->prev_variance_low); + cpi->prev_variance_low = NULL; + vpx_free(cpi->copied_frame_cnt); + cpi->copied_frame_cnt = NULL; +} + void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; @@ -1999,6 +2010,8 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows); if (cm->mi_alloc_size < new_mi_size) { vp9_free_context_buffers(cm); + vp9_free_pc_tree(&cpi->td); + vpx_free(cpi->mbmi_ext_base); alloc_compressor_data(cpi); realloc_segmentation_maps(cpi); cpi->initial_width = cpi->initial_height = 0; @@ -2014,8 +2027,18 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { update_frame_size(cpi); if (last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) { - memset(cpi->consec_zero_mv, 0, - cm->mi_rows * cm->mi_cols * sizeof(*cpi->consec_zero_mv)); + vpx_free(cpi->consec_zero_mv); + CHECK_MEM_ERROR( + cm, cpi->consec_zero_mv, + vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(*cpi->consec_zero_mv))); + + vpx_free(cpi->skin_map); + CHECK_MEM_ERROR( + cm, cpi->skin_map, + vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(cpi->skin_map[0]))); + + free_copy_partition_data(cpi); + alloc_copy_partition_data(cpi); if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) vp9_cyclic_refresh_reset_resize(cpi); rc->rc_1_frame = 0; From 104c0b3fec793d414c4fdd6a18996fe9af4c0051 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 29 Sep 2023 08:21:15 +0000 Subject: [PATCH 102/123] [core] Fix flopping routes on ICE negotiation --- src/include/switch_rtp.h | 2 + src/switch_rtp.c | 335 +++++++++++++++++++++++++++++---------- 2 files changed, 251 insertions(+), 86 deletions(-) diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index dfcad5453c..7986bdb622 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -103,6 +103,8 @@ typedef struct icand_s { switch_port_t rport; char *generation; uint8_t ready; + uint8_t responsive; + uint8_t use_candidate; } icand_t; #define MAX_CAND 50 diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 506085d86d..5ddf12ec3c 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -254,10 +254,11 @@ typedef struct { uint8_t sending; uint8_t ready; uint8_t rready; - uint8_t init; + uint8_t initializing; int missed_count; char last_sent_id[13]; switch_time_t last_ok; + uint8_t cand_responsive; } switch_rtp_ice_t; struct switch_rtp; @@ -401,7 +402,6 @@ struct switch_rtp { char *eff_remote_host_str; switch_time_t first_stun; switch_time_t last_stun; - uint32_t wrong_addrs; uint32_t samples_per_interval; uint32_t samples_per_second; uint32_t conf_samples_per_interval; @@ -474,7 +474,11 @@ struct switch_rtp { payload_map_t *pmap_tail; kalman_estimator_t *estimators[KALMAN_SYSTEM_MODELS]; cusum_kalman_detector_t *detectors[KALMAN_SYSTEM_MODELS]; - int ice_adj; + switch_time_t last_adj; + switch_time_t adj_window; + uint32_t elapsed_stun; + uint32_t elapsed_media; + uint32_t elapsed_adj; uint8_t has_rtp; uint8_t has_rtcp; uint8_t has_ice; @@ -540,9 +544,25 @@ static void switch_rtp_change_ice_dest(switch_rtp_t *rtp_session, switch_rtp_ice { int is_rtcp = ice == &rtp_session->rtcp_ice; const char *err = ""; + int i; + uint8_t ice_cand_found_idx = 0; + + for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { + if (!strcmp(host, ice->ice_params->cands[i][ice->proto].con_addr) && port == ice->ice_params->cands[i][ice->proto].con_port) { + ice_cand_found_idx = i; + } + } + + if (!ice_cand_found_idx) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "ICE candidate [%s:%d] replaced with [%s:%d]\n", + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, host, port); + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr = switch_core_strdup(rtp_session->pool, host); + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port = port; + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "ICE chosen candidate [%s:%d] set to idx [%d]\n", host, port, ice_cand_found_idx); + ice->ice_params->chosen[ice->proto] = ice_cand_found_idx; + } - ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr = switch_core_strdup(rtp_session->pool, host); - ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port = port; ice->missed_count = 0; if (is_rtcp) { @@ -796,7 +816,41 @@ static int rtp_common_write(switch_rtp_t *rtp_session, rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags); -static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) +#define MEDIA_TOO_LONG 2000 +#define STUN_TOO_LONG 20000 +#define ADJ_TOO_LONG 1000 + +static void calc_elapsed(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) +{ + switch_time_t ref_point; + switch_time_t now; + + now = switch_micro_time_now(); + + if (ice->last_ok && (!rtp_session->dtls || rtp_session->dtls->state == DS_READY)) { + ref_point = ice->last_ok; + } else { + ref_point = rtp_session->first_stun; + } + + if (!ref_point) ref_point = now; + + rtp_session->elapsed_stun = (unsigned int) ((now - ref_point) / 1000); + + if (rtp_session->last_media) { + rtp_session->elapsed_media = (unsigned int) ((now - rtp_session->last_media) / 1000); + } else { + rtp_session->elapsed_media = MEDIA_TOO_LONG + 1; + } + + if (rtp_session->last_adj) { + rtp_session->elapsed_adj = (unsigned int) ((now - rtp_session->last_adj) / 1000); + } else { + rtp_session->elapsed_adj = ADJ_TOO_LONG + 1; + } +} + +static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, switch_bool_t force) { uint8_t buf[256] = { 0 }; switch_stun_packet_t *packet; @@ -812,7 +866,7 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) return SWITCH_STATUS_BREAK; } - if (ice->next_run && ice->next_run > now) { + if (!force && ice->next_run && ice->next_run >= now) { return SWITCH_STATUS_BREAK; } @@ -907,8 +961,19 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d int ok = 1; uint32_t *pri = NULL; int is_rtcp = ice == &rtp_session->rtcp_ice; - uint32_t elapsed; - switch_time_t ref_point; + switch_channel_t *channel; + int i; + switch_sockaddr_t *from_addr = rtp_session->from_addr; + const char *from_host = NULL; + switch_port_t from_port = 0; + char faddr_buf[80] = ""; + + if (is_rtcp) { + from_addr = rtp_session->rtcp_from_addr; + } + + from_host = switch_get_addr(faddr_buf, sizeof(faddr_buf), from_addr); + from_port = switch_sockaddr_get_port(from_addr); //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { // switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s CALL\n", rtp_type(rtp_session)); @@ -931,6 +996,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d cpylen = sizeof(buf); } + channel = switch_core_session_get_channel(rtp_session->session); memcpy(buf, data, cpylen); packet = switch_stun_packet_parse(buf, (uint32_t)cpylen); @@ -946,14 +1012,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d rtp_session->first_stun = rtp_session->last_stun; } - if (ice->last_ok && (!rtp_session->dtls || rtp_session->dtls->state == DS_READY)) { - ref_point = ice->last_ok; - } else { - ref_point = rtp_session->first_stun; - } - - elapsed = (unsigned int) ((switch_micro_time_now() - ref_point) / 1000); - + calc_elapsed(rtp_session, ice); end_buf = buf + ((sizeof(buf) > packet->header.length) ? packet->header.length : sizeof(buf)); @@ -968,6 +1027,12 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d case SWITCH_STUN_ATTR_USE_CAND: { ice->rready = 1; + for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { + if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, from_host) && ice->ice_params->cands[i][ice->proto].con_port == from_port) { + ice->ice_params->cands[i][ice->proto].use_candidate = 1; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG6, "Got USE-CANDIDATE on %s:%d\n", ice->ice_params->cands[i][ice->proto].con_addr, ice->ice_params->cands[i][ice->proto].con_port); + } + } } break; case SWITCH_STUN_ATTR_ERROR_CODE: @@ -1048,18 +1113,33 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d if (packet->header.type == SWITCH_STUN_BINDING_RESPONSE) { ok = 1; - if (!ice->rready) { - if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { - rtp_session->ice.rready = 1; - rtp_session->rtcp_ice.rready = 1; - } else { - ice->rready = 1; - } - if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { - switch_core_session_video_reinit(rtp_session->session); + if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { + rtp_session->ice.rready = 1; + rtp_session->rtcp_ice.rready = 1; + } else { + ice->rready = 1; + } + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG6, "Received STUN Binding Response from %s\n", from_host); + + if (ice->ice_params) { + for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { + if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, from_host) && ice->ice_params->cands[i][ice->proto].con_port == from_port) { + ice->ice_params->cands[i][ice->proto].responsive = 1; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "Marked ICE candidate %s:%d as responsive\n", ice->ice_params->cands[i][ice->proto].con_addr, ice->ice_params->cands[i][ice->proto].con_port); + if (!strcmp(ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, from_host) && ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port == from_port) { + ice->cand_responsive = 1; + ice->initializing = 0; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "Chosen ICE candidate %s:%d is responsive\n", ice->ice_params->cands[i][ice->proto].con_addr, ice->ice_params->cands[i][ice->proto].con_port); + } + } } } + + if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { + switch_core_session_video_reinit(rtp_session->session); + } } if (!ok && ice == &rtp_session->ice && rtp_session->rtcp_ice.ice_params && pri && @@ -1084,7 +1164,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d switch_port_t port = 0; char *host = NULL; - if (elapsed > 20000 && pri) { + if (rtp_session->elapsed_stun > STUN_TOO_LONG && pri) { int i, j; uint32_t old; //const char *tx_host; @@ -1176,6 +1256,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "missed too many: %d, looking for new ICE dest.\n", ice->missed_count); ice->rready = 0; + ice->cand_responsive = 0; ok = 1; } @@ -1185,9 +1266,8 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d //} if (ok) { - const char *host = NULL, *host2 = NULL; - switch_port_t port = 0, port2 = 0; - char buf[80] = ""; + const char *host2 = NULL; + switch_port_t port2 = 0; char buf2[80] = ""; if (packet->header.type == SWITCH_STUN_BINDING_REQUEST) { @@ -1196,16 +1276,13 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d const char *remote_ip; switch_size_t bytes; char ipbuf[50]; - switch_sockaddr_t *from_addr = rtp_session->from_addr; switch_socket_t *sock_output = rtp_session->sock_output; uint8_t do_adj = 0; switch_time_t now = switch_micro_time_now(); int cmp = 0; - int cur_idx = -1;//, is_relay = 0; - int i; - + int cur_idx = -1, is_relay = 0, is_responsive = 0, use_candidate = 0; + if (is_rtcp) { - from_addr = rtp_session->rtcp_from_addr; sock_output = rtp_session->rtcp_sock_output; } @@ -1231,58 +1308,123 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d bytes = switch_stun_packet_length(rpacket); - host = switch_get_addr(buf, sizeof(buf), from_addr); - port = switch_sockaddr_get_port(from_addr); host2 = switch_get_addr(buf2, sizeof(buf2), ice->addr); port2 = switch_sockaddr_get_port(ice->addr); cmp = switch_cmp_addr(from_addr, ice->addr, SWITCH_FALSE); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, - "STUN from %s:%d %s\n", host, port, cmp ? "EXPECTED" : "IGNORED"); + for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { + if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, from_host) && ice->ice_params->cands[i][ice->proto].con_port == from_port) { + if (!strcasecmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) { + is_relay = 1; + } - if (ice->init && !cmp && switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) { - do_adj++; - rtp_session->ice_adj++; - rtp_session->wrong_addrs = 0; - ice->init = 0; - } - - if (cmp) { - ice->last_ok = now; - rtp_session->wrong_addrs = 0; - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG10, "ICE %d dt:%d i:%d i2:%d w:%d cmp:%d adj:%d\n", elapsed, (rtp_session->dtls && rtp_session->dtls->state != DS_READY), !ice->ready, !ice->rready, rtp_session->wrong_addrs, switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE), rtp_session->ice_adj); + if (ice->ice_params->cands[i][ice->proto].responsive) { + is_responsive = 1; + } - if ((rtp_session->dtls && rtp_session->dtls->state != DS_READY) || - ((!ice->ready || !ice->rready) && (rtp_session->wrong_addrs > 2 || switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) && - rtp_session->ice_adj < 10)) { - do_adj++; - rtp_session->ice_adj++; - rtp_session->wrong_addrs = 0; - } else if (rtp_session->wrong_addrs > 10 || elapsed >= 5000) { - do_adj++; - } - - if (!do_adj) { - rtp_session->wrong_addrs++; - } - - for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { - if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host)) { - cur_idx = i; - //if (!strcasecmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) { - // is_relay = 1; - //} + if (ice->ice_params->cands[i][ice->proto].use_candidate) { + use_candidate = 1; } } - - - if (ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type && - !strcasecmp(ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type, "relay")) { + } + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, + "%s %s STUN from %s:%d %s is_relay: %d is_responsive: %d use_candidate: %d ready: %d, rready: %d\n", switch_channel_get_name(channel), rtp_type(rtp_session), from_host, from_port, cmp ? "EXPECTED" : "IGNORED", + is_relay, is_responsive, use_candidate, ice->ready, ice->rready); + + if (ice->initializing && !cmp) { + if (!rtp_session->adj_window && (!ice->ready || !ice->rready || (!rtp_session->dtls || rtp_session->dtls->state != DS_READY))) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE set ADJUST window to 10 seconds on binding request from %s:%d (is_relay: %d, is_responsivie: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + rtp_session->adj_window = now + 10000000; + } + + if (rtp_session->adj_window) { + if (rtp_session->adj_window > now) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE check: %d >= 3000 or window closed and not from relay on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", rtp_session->elapsed_stun, from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + if (!is_relay && (rtp_session->elapsed_stun >= 3000 || rtp_session->adj_window == (now + 10000000))) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE ADJUST HIT 1 on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + do_adj++; + rtp_session->last_adj = now; + } + } else { + rtp_session->adj_window = 0; + } + } + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE CHECK SAME IP DIFFT PORT %d %d on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp",ice->initializing, switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE), from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + if (!do_adj && (switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE) || use_candidate)) { do_adj++; + rtp_session->last_adj = now; + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE ADJUST HIT 2 on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); } } - + + if (cmp) { + ice->last_ok = now; + } else if (!do_adj) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "ICE %d/%d dt:%d i:%d i2:%d cmp:%d\n", rtp_session->elapsed_stun, rtp_session->elapsed_media, (rtp_session->dtls && rtp_session->dtls->state != DS_READY), !ice->ready, !ice->rready, switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)); + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE ADJUST ELAPSED vs 1000 %d on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp" ,rtp_session->elapsed_adj, from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + if (rtp_session->elapsed_adj > 1000) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE IF DTLS NOT READY or %d >= 3000 or media too long %d or stun too long %d on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", rtp_session->elapsed_stun, rtp_session->elapsed_media >= MEDIA_TOO_LONG, + rtp_session->elapsed_stun >= STUN_TOO_LONG, from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + if (!is_relay && ((rtp_session->dtls && rtp_session->dtls->state != DS_READY) || + ((!ice->ready || !ice->rready) && (rtp_session->elapsed_stun >= 3000 || switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE))))) { + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE ADJUST HIT 3 on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + do_adj++; + rtp_session->last_adj = now; + } else if (is_relay && ice->initializing && rtp_session->elapsed_stun >= 1000) { + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE ADJUST HIT 4 (FLIP TO TURN) on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + do_adj++; + rtp_session->last_adj = now; + } else if ((ice->initializing && rtp_session->elapsed_stun >= 3000) || + (rtp_session->elapsed_media >= MEDIA_TOO_LONG || rtp_session->elapsed_stun >= STUN_TOO_LONG)) { + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "%s %s %s ICE ADJUST HIT 5 on binding request from %s:%d (is_relay: %d, is_responsive: %d, use_candidate: %d) Current cand: %s:%d typ: %s\n", + switch_channel_get_name(channel), rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", from_host, from_port, is_relay, is_responsive, use_candidate, + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type); + + do_adj++; + rtp_session->last_adj = now; + } + + for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { + if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, from_host)) { + cur_idx = i; + } + } + } + } + if ((ice->type & ICE_VANILLA) && ice->ice_params && do_adj) { ice->missed_count = 0; ice->rready = 1; @@ -1294,15 +1436,29 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u idx:%d\n", rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", host2, port2, - host, port, cur_idx); + from_host, from_port, cur_idx); + + switch_rtp_change_ice_dest(rtp_session, ice, from_host, from_port); + + ice->cand_responsive = is_responsive; + if (ice->cand_responsive) { + ice->initializing = 0; + } - switch_rtp_change_ice_dest(rtp_session, ice, host, port); ice->last_ok = now; - rtp_session->wrong_addrs = 0; } //if (cmp) { switch_socket_sendto(sock_output, from_addr, 0, (void *) rpacket, &bytes); //} + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG6, "Send STUN Binding Response to %s:%u\n", from_host, from_port); + + if (ice->initializing && !is_responsive) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "Send STUN Binding Request on ICE candidate still unresponsive to %s:%u\n", from_host, from_port); + if (ice_out(rtp_session, ice, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Error sending STUN Binding Request on ICE candidate still unresponsive to %s:%u\n", from_host, from_port); + } + } } } else if (packet->header.type == SWITCH_STUN_BINDING_ERROR_RESPONSE) { @@ -2358,7 +2514,7 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session) } if (rtp_session->ice.ice_user) { - if (ice_out(rtp_session, &rtp_session->ice) == SWITCH_STATUS_GENERR) { + if (ice_out(rtp_session, &rtp_session->ice, SWITCH_FALSE) == SWITCH_STATUS_GENERR) { ret = -1; goto end; } @@ -2366,7 +2522,7 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session) if (!rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { if (rtp_session->rtcp_ice.ice_user) { - if (ice_out(rtp_session, &rtp_session->rtcp_ice) == SWITCH_STATUS_GENERR) { + if (ice_out(rtp_session, &rtp_session->rtcp_ice, SWITCH_FALSE) == SWITCH_STATUS_GENERR) { ret = -1; goto end; } @@ -2852,10 +3008,9 @@ SWITCH_DECLARE(void) switch_rtp_reset(switch_rtp_t *rtp_session) memset(&rtp_session->ts_norm, 0, sizeof(rtp_session->ts_norm)); rtp_session->last_stun = rtp_session->first_stun = 0; - rtp_session->wrong_addrs = 0; rtp_session->rtcp_sent_packets = 0; rtp_session->rtcp_last_sent = 0; - rtp_session->ice_adj = 0; + rtp_session->last_adj = 0; //switch_rtp_del_dtls(rtp_session, DTLS_TYPE_RTP|DTLS_TYPE_RTCP); switch_rtp_set_flag(rtp_session, SWITCH_RTP_FLAG_PAUSE); @@ -2865,6 +3020,7 @@ SWITCH_DECLARE(void) switch_rtp_reset(switch_rtp_t *rtp_session) if (rtp_session->ice.ready) { switch_rtp_reset_vb(rtp_session); rtp_session->ice.ready = rtp_session->ice.rready = 0; + rtp_session->ice.cand_responsive = 0; } } @@ -3210,13 +3366,18 @@ static int do_dtls(switch_rtp_t *rtp_session, switch_dtls_t *dtls) int r = 0, ret = 0, len; switch_size_t bytes; unsigned char buf[MAX_DTLS_MTU] = ""; - int ready = rtp_session->ice.ice_user ? (rtp_session->ice.rready && rtp_session->ice.ready) : 1; + uint8_t is_ice = rtp_session->ice.ice_user ? 1 : 0; + int ready = is_ice ? (rtp_session->ice.rready && rtp_session->ice.ready) : 1; int pending; if (!dtls->bytes && !ready) { return 0; } + if (is_ice && !rtp_session->ice.cand_responsive) { + return 0; + } + if (dtls->bytes > 0 && dtls->data) { ret = BIO_write(dtls->read_bio, dtls->data, (int)dtls->bytes); if (ret <= 0) { @@ -4764,11 +4925,13 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio switch_snprintf(user_ice, sizeof(user_ice), "%s:%s", rlogin, login); switch_snprintf(luser_ice, sizeof(luser_ice), "%s%s", rlogin, login); ice->ready = ice->rready = 0; + ice->cand_responsive = 0; } else { switch_snprintf(ice_user, sizeof(ice_user), "%s%s", login, rlogin); switch_snprintf(user_ice, sizeof(user_ice), "%s%s", rlogin, login); switch_snprintf(luser_ice, sizeof(luser_ice), ""); ice->ready = ice->rready = 1; + ice->cand_responsive = 0; } ice->ice_user = switch_core_strdup(rtp_session->pool, ice_user); @@ -4779,7 +4942,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio ice->pass = ""; ice->rpass = ""; ice->next_run = switch_micro_time_now(); - ice->init = 1; + ice->initializing = 1; if (password) { ice->pass = switch_core_strdup(rtp_session->pool, password); @@ -5725,7 +5888,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t /* version 2 probably rtp */ rtp_session->has_rtp = (rtp_session->recv_msg.header.version == 2); - if (rtp_session->media_timeout) { + if (rtp_session->media_timeout || rtp_session->ice.ice_user) { rtp_session->last_media = switch_micro_time_now(); } From f05b7507aa28c1a320d839d5c65a72210050dc4d Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Thu, 12 Oct 2023 15:42:23 -0400 Subject: [PATCH 103/123] [mod_conference] Avoid a race in member->read_impl access The conference output loop accesses the member's read_impl while resampling. The output loop also spawns off the input loop thread, which is where the member->read_impl is actually initialised. This results in an uncommon race where the output loop sometimes gets an uninitialised member->read_impl and bails with logs something like this: 2023-10-12 18:19:01.436844 [DEBUG] conference_loop.c:1340 Setup timer soft success interval: 20 samples: 960 from codec L16 2023-10-12 18:19:01.436844 [DEBUG] conference_loop.c:1497 Outbound conference channel answered, setting CFLAG_ANSWERED 2023-10-12 18:19:01.436844 [NOTICE] switch_core_media.c:15852 Activating write resampler 2023-10-12 18:19:01.436844 [DEBUG] switch_core_media.c:16097 Engaging Write Buffer at 1920 bytes to accommodate 0->1920 2023-10-12 18:19:01.436844 [ERR] switch_core_media.c:16112 Write Buffer 0 bytes Failed! As a solution, we initialise the member->read_impl even before we start up the input loop, so that this race can never happen. --- src/mod/applications/mod_conference/conference_loop.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_conference/conference_loop.c b/src/mod/applications/mod_conference/conference_loop.c index 8f112f5453..f9b7894d0e 100644 --- a/src/mod/applications/mod_conference/conference_loop.c +++ b/src/mod/applications/mod_conference/conference_loop.c @@ -1316,15 +1316,15 @@ void conference_loop_output(conference_member_t *member) uint32_t flush_len; uint32_t low_count, bytes; call_list_t *call_list, *cp; - switch_codec_implementation_t read_impl = { 0 }, real_read_impl = { 0 }; + switch_codec_implementation_t real_read_impl = { 0 }; int sanity; - switch_core_session_get_read_impl(member->session, &read_impl); + switch_core_session_get_read_impl(member->session, &member->read_impl); switch_core_session_get_real_read_impl(member->session, &real_read_impl); channel = switch_core_session_get_channel(member->session); - interval = read_impl.microseconds_per_packet / 1000; + interval = member->read_impl.microseconds_per_packet / 1000; samples = switch_samples_per_packet(member->conference->rate, interval); //csamples = samples; tsamples = real_read_impl.samples_per_packet; From f7e19e513466e2e489eeebce7a0b72d7c786cad7 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 11 Dec 2023 22:48:00 +0300 Subject: [PATCH 104/123] [mod_sofia] BYE Reason header was limited in length. --- src/mod/endpoints/mod_sofia/mod_sofia.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index f58bb40ac0..458be3f875 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -488,7 +488,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) if (sofia_test_pflag(tech_pvt->profile, PFLAG_DESTROY)) { sofia_set_flag(tech_pvt, TFLAG_BYE); } else if (tech_pvt->nh && !sofia_test_flag(tech_pvt, TFLAG_BYE)) { - char reason[128] = ""; + char *reason = switch_core_session_sprintf(session, ""); char *bye_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_BYE_HEADER_PREFIX); const char *val = NULL; const char *max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE); @@ -499,15 +499,15 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) if (!val || switch_false(val)) { if ((val = switch_channel_get_variable(tech_pvt->channel, "sip_reason"))) { - switch_snprintf(reason, sizeof(reason), "%s", val); + reason = switch_core_session_sprintf(session, "%s", val); } else { if ((switch_channel_test_flag(channel, CF_INTERCEPT) || cause == SWITCH_CAUSE_PICKED_OFF || cause == SWITCH_CAUSE_LOSE_RACE) && !switch_true(switch_channel_get_variable(channel, "ignore_completed_elsewhere"))) { - switch_snprintf(reason, sizeof(reason), "SIP;cause=200;text=\"Call completed elsewhere\""); + reason = switch_core_session_sprintf(session, "SIP;cause=200;text=\"Call completed elsewhere\""); } else if (cause > 0 && cause < 128) { - switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); + reason = switch_core_session_sprintf(session, "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); } else { - switch_snprintf(reason, sizeof(reason), "SIP;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); + reason = switch_core_session_sprintf(session, "SIP;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); } } } From 48608177d73c9797f9b98a322dcec153bf20b78d Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Tue, 12 Dec 2023 10:03:11 +0000 Subject: [PATCH 105/123] [core] Fix missing 192 key lengths --- src/switch_rtp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 5ddf12ec3c..5d58e07aad 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -4219,6 +4219,20 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess switch_channel_set_variable(channel, "rtp_has_crypto", "AES_CM_256_HMAC_SHA1_32"); } break; + case AES_CM_192_HMAC_SHA1_80: + srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy->rtp); + srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy->rtcp); + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + switch_channel_set_variable(channel, "rtp_has_crypto", "AES_CM_192_HMAC_SHA1_80"); + } + break; + case AES_CM_192_HMAC_SHA1_32: + srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&policy->rtp); + srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&policy->rtcp); + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + switch_channel_set_variable(channel, "rtp_has_crypto", "AES_CM_192_HMAC_SHA1_32"); + } + break; case AES_CM_128_NULL_AUTH: srtp_crypto_policy_set_aes_cm_128_null_auth(&policy->rtp); srtp_crypto_policy_set_aes_cm_128_null_auth(&policy->rtcp); @@ -4228,6 +4242,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess } break; default: + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "Missing crypto type!\n"); break; } From c155ea70082ea5a23e4badf757f842ecf6b6c142 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 14 Dec 2023 13:43:33 +0300 Subject: [PATCH 106/123] [Core] Fix implicit conversion from enumeration type 'switch_odbc_status_t' to different enumeration type 'switch_status_t'. --- src/switch_core_sqldb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 817a7a7586..165c9bd8b1 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -702,7 +702,7 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t case SCDB_TYPE_ODBC: { type = "ODBC"; - status = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, sql, NULL, &errmsg); + status = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, sql, NULL, &errmsg) == SWITCH_ODBC_SUCCESS ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; } break; case SCDB_TYPE_CORE_DB: @@ -904,7 +904,7 @@ SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t break; case SCDB_TYPE_ODBC: { - status = switch_odbc_handle_exec_string(dbh->native_handle.odbc_dbh, sql, str, len, err); + status = switch_odbc_handle_exec_string(dbh->native_handle.odbc_dbh, sql, str, len, err) == SWITCH_ODBC_SUCCESS ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; } break; case SCDB_TYPE_DATABASE_INTERFACE: @@ -1189,7 +1189,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_event_callback(switc break; case SCDB_TYPE_ODBC: { - status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, helper_callback, &h, err); + status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, helper_callback, &h, err) == SWITCH_ODBC_SUCCESS ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; } break; case SCDB_TYPE_CORE_DB: @@ -1248,7 +1248,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_event_callback_err(s break; case SCDB_TYPE_ODBC: { - status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, helper_callback, &h, err); + status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, helper_callback, &h, err) == SWITCH_ODBC_SUCCESS ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; if (err && *err) { (*err_callback)(pdata, (const char*)*err); } @@ -1305,7 +1305,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cach break; case SCDB_TYPE_ODBC: { - status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err); + status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err) == SWITCH_ODBC_SUCCESS ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; } break; case SCDB_TYPE_CORE_DB: @@ -1358,7 +1358,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback_err(switch_ break; case SCDB_TYPE_ODBC: { - status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err); + status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err) == SWITCH_ODBC_SUCCESS ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; if (err && *err) { (*err_callback)(pdata, (const char*)*err); } From 2e7424169e7f39ba644f498769ca6b92c4951b4c Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 19 Dec 2023 22:42:54 +0300 Subject: [PATCH 107/123] [mod_conference] Remove static from cJSON vars in conference_jlist --- src/mod/applications/mod_conference/mod_conference.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index bf03d2a5bc..aa606170d5 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1363,7 +1363,7 @@ void conference_xlist(conference_obj_t *conference, switch_xml_t x_conference, i void conference_jlist(conference_obj_t *conference, cJSON *json_conferences) { conference_member_t *member = NULL; - static cJSON *json_conference, *json_conference_variables, *json_conference_members, *json_conference_member, *json_conference_member_flags; + cJSON *json_conference, *json_conference_variables, *json_conference_members, *json_conference_member, *json_conference_member_flags; switch_event_header_t *hp; switch_assert(conference != NULL); From e9e8e7fe1aa0d62577874be244818b7e233cc296 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 22 Dec 2023 01:09:19 +0300 Subject: [PATCH 108/123] Bump sofia-sip library requirement to version 1.13.17 --- configure.ac | 2 +- debian/bootstrap.sh | 4 ++-- freeswitch.spec | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 9f852e531a..56bf86f53c 100644 --- a/configure.ac +++ b/configure.ac @@ -716,7 +716,7 @@ PKG_CHECK_MODULES([SPANDSP], [spandsp >= 3.0],[ AC_MSG_ERROR([no usable spandsp; please install spandsp3 devel package or equivalent]) ]) -PKG_CHECK_MODULES([SOFIA_SIP], [sofia-sip-ua >= 1.13.15],[ +PKG_CHECK_MODULES([SOFIA_SIP], [sofia-sip-ua >= 1.13.17],[ AM_CONDITIONAL([HAVE_SOFIA_SIP],[true])],[ AC_MSG_ERROR([no usable sofia-sip; please install sofia-sip-ua devel package or equivalent]) ]) diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index a2f0261ab6..75a8957509 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -335,7 +335,7 @@ Build-Depends: uuid-dev, libexpat1-dev, libgdbm-dev, libdb-dev, # used by many modules libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl-dev, - bison, zlib1g-dev, libsofia-sip-ua-dev (>= 1.13.15), + bison, zlib1g-dev, libsofia-sip-ua-dev (>= 1.13.17), libspandsp3-dev, # used to format the private freeswitch apt-repo key properly gnupg, @@ -374,7 +374,7 @@ Description: Cross-Platform Scalable Multi-Protocol Soft Switch Package: libfreeswitch1 Architecture: amd64 armhf -Depends: \${shlibs:Depends}, \${misc:Depends}, libsofia-sip-ua0 (>= 1.13.15) +Depends: \${shlibs:Depends}, \${misc:Depends}, libsofia-sip-ua0 (>= 1.13.17) Recommends: Suggests: libfreeswitch1-dbg Conflicts: freeswitch-all (<= 1.6.7) diff --git a/freeswitch.spec b/freeswitch.spec index ecf9dacf13..9e3d505e80 100644 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -140,7 +140,7 @@ BuildRequires: curl-devel >= 7.19 BuildRequires: gcc-c++ BuildRequires: libtool >= 1.5.17 BuildRequires: openssl-devel >= 1.0.1e -BuildRequires: sofia-sip-devel >= 1.13.15 +BuildRequires: sofia-sip-devel >= 1.13.17 BuildRequires: spandsp3-devel >= 3.0 BuildRequires: pcre-devel BuildRequires: speex-devel From 6ea8c96c3db9944d0542a4a7b04fc54712334da2 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 29 Sep 2023 15:25:53 +0000 Subject: [PATCH 109/123] [Core] Reject DTLS packets coming from a source different than the current ICE negotiated path. --- src/switch_rtp.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 5d58e07aad..1125e2f59b 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -3374,7 +3374,20 @@ static int do_dtls(switch_rtp_t *rtp_session, switch_dtls_t *dtls) return 0; } - if (is_ice && !rtp_session->ice.cand_responsive) { + if (is_ice && !(rtp_session->ice.type & ICE_LITE) && !rtp_session->ice.cand_responsive) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG6, "Got DTLS packet but candidate is not responsive\n"); + + return 0; + } + + if (is_ice && !switch_cmp_addr(rtp_session->from_addr, rtp_session->ice.addr, SWITCH_TRUE)) { + char tmp_buf1[80] = ""; + char tmp_buf2[80] = ""; + const char *host_from = switch_get_addr(tmp_buf1, sizeof(tmp_buf1), rtp_session->from_addr); + const char *host_ice_cur_addr = switch_get_addr(tmp_buf2, sizeof(tmp_buf2), rtp_session->ice.addr); + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG5, "Got DTLS packet from [%s] whilst current ICE negotiated address is [%s]. Ignored.\n", host_from, host_ice_cur_addr); + return 0; } From 6ae8ce604a7e4a55835bf3a01fd8a775c98211ff Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 22 Dec 2023 17:12:41 +0000 Subject: [PATCH 110/123] swigall --- .../languages/mod_managed/freeswitch_wrap.cxx | 44 +++++++++++++++++++ src/mod/languages/mod_managed/managed/swig.cs | 32 ++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 742e4f979e..bba26c8f9b 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -45237,6 +45237,50 @@ SWIGEXPORT unsigned char SWIGSTDCALL CSharp_FreeSWITCHfNative_icand_t_ready_get_ } +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_icand_t_responsive_set___(void * jarg1, unsigned char jarg2) { + icand_s *arg1 = (icand_s *) 0 ; + uint8_t arg2 ; + + arg1 = (icand_s *)jarg1; + arg2 = (uint8_t)jarg2; + if (arg1) (arg1)->responsive = arg2; +} + + +SWIGEXPORT unsigned char SWIGSTDCALL CSharp_FreeSWITCHfNative_icand_t_responsive_get___(void * jarg1) { + unsigned char jresult ; + icand_s *arg1 = (icand_s *) 0 ; + uint8_t result; + + arg1 = (icand_s *)jarg1; + result = (uint8_t) ((arg1)->responsive); + jresult = result; + return jresult; +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_icand_t_use_candidate_set___(void * jarg1, unsigned char jarg2) { + icand_s *arg1 = (icand_s *) 0 ; + uint8_t arg2 ; + + arg1 = (icand_s *)jarg1; + arg2 = (uint8_t)jarg2; + if (arg1) (arg1)->use_candidate = arg2; +} + + +SWIGEXPORT unsigned char SWIGSTDCALL CSharp_FreeSWITCHfNative_icand_t_use_candidate_get___(void * jarg1) { + unsigned char jresult ; + icand_s *arg1 = (icand_s *) 0 ; + uint8_t result; + + arg1 = (icand_s *)jarg1; + result = (uint8_t) ((arg1)->use_candidate); + jresult = result; + return jresult; +} + + SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_icand_t___() { void * jresult ; icand_s *result = 0 ; diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index 02848257bf..fbab2f3f77 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -26316,6 +26316,18 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_icand_t_ready_get___")] public static extern byte icand_t_ready_get(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_icand_t_responsive_set___")] + public static extern void icand_t_responsive_set(global::System.Runtime.InteropServices.HandleRef jarg1, byte jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_icand_t_responsive_get___")] + public static extern byte icand_t_responsive_get(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_icand_t_use_candidate_set___")] + public static extern void icand_t_use_candidate_set(global::System.Runtime.InteropServices.HandleRef jarg1, byte jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_icand_t_use_candidate_get___")] + public static extern byte icand_t_use_candidate_get(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_icand_t___")] public static extern global::System.IntPtr new_icand_t(); @@ -28339,6 +28351,26 @@ public class icand_t : global::System.IDisposable { } } + public byte responsive { + set { + freeswitchPINVOKE.icand_t_responsive_set(swigCPtr, value); + } + get { + byte ret = freeswitchPINVOKE.icand_t_responsive_get(swigCPtr); + return ret; + } + } + + public byte use_candidate { + set { + freeswitchPINVOKE.icand_t_use_candidate_set(swigCPtr, value); + } + get { + byte ret = freeswitchPINVOKE.icand_t_use_candidate_get(swigCPtr); + return ret; + } + } + public icand_t() : this(freeswitchPINVOKE.new_icand_t(), true) { } From 987e87bc0b37d5707b180d9834cdaf748a2e925d Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 22 Dec 2023 22:37:54 +0300 Subject: [PATCH 111/123] version bump --- build/next-release.txt | 2 +- configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/next-release.txt b/build/next-release.txt index 63fd3adc74..a3426275e7 100644 --- a/build/next-release.txt +++ b/build/next-release.txt @@ -1 +1 @@ -1.10.11-dev +1.10.12-dev diff --git a/configure.ac b/configure.ac index 56bf86f53c..e4ab33ae5c 100644 --- a/configure.ac +++ b/configure.ac @@ -3,10 +3,10 @@ # Must change all of the below together # For a release, set revision for that tagged release as well and uncomment -AC_INIT([freeswitch], [1.10.11-dev], bugs@freeswitch.org) +AC_INIT([freeswitch], [1.10.12-dev], bugs@freeswitch.org) AC_SUBST(SWITCH_VERSION_MAJOR, [1]) AC_SUBST(SWITCH_VERSION_MINOR, [10]) -AC_SUBST(SWITCH_VERSION_MICRO, [11-dev]) +AC_SUBST(SWITCH_VERSION_MICRO, [12-dev]) AC_SUBST(SWITCH_VERSION_REVISION, []) AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, []) From 0cea9811cd6c39604280ced6b16c0e2429c4ec6c Mon Sep 17 00:00:00 2001 From: tmancill <1195611+tmancill@users.noreply.github.com> Date: Fri, 5 Jan 2024 07:42:58 -0800 Subject: [PATCH 112/123] [Docker] Change default freeswitch UID and GID to 499 in docker/master/Dockerfile On several installs on recent Debian and Ubuntu systems, I have noticed that GID 999 is already allocated on the system running the container, making it a minor hassle to share a common freeswitch UID and GID between the Docker host and the container. The conflicting group id varies, but is typically either one of the systemd groups or polkitd, which are dynamically created when those packages are installed. The behavior stems from the range of system GIDs being between 100-999 ([see Debian Policy 9.2.2](https://www.debian.org/doc/debian-policy/ch-opersys.html#uid-and-gid-classes)) and the fact that system installation dynamically allocates from this range. I didn't track down exactly why these daemons are allocating from the top of the range, since the default behavior of `adduser` and `addgroup` ([link](https://salsa.debian.org/debian/adduser/-/blob/6c04aa701a2ca09efbff9094ab07e7dae14554fc/adduser#L1255-1269)) is to search from the bottom of the range, and the manpage for `groupadd` says that it's default is also to use the smallest id, but perhaps it was to avoid (other) conflicts. The approach taken in this PR is to default to 499, more in the middle of the range, which should reduce the chance of conflicting with an existing system UID and GID. The values are also now exposed as ARGs and so can be explicitly set during the build with `--build-arg="FREESWITCH_UID=xxx"` and `--build-arg="FREESWITCH_GID=yyy"` if desired. --- docker/master/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/master/Dockerfile b/docker/master/Dockerfile index 4c73ecc6e4..d036164ac7 100644 --- a/docker/master/Dockerfile +++ b/docker/master/Dockerfile @@ -20,7 +20,9 @@ ARG FS_META_PACKAGE=freeswitch-meta-all # https://github.com/docker-library/postgres/blob/master/9.4/Dockerfile # explicitly set user/group IDs -RUN groupadd -r freeswitch --gid=999 && useradd -r -g freeswitch --uid=999 freeswitch +ARG FREESWITCH_UID=499 +ARG FREESWITCH_GID=499 +RUN groupadd -r freeswitch --gid=${FREESWITCH_GID} && useradd -r -g freeswitch --uid=${FREESWITCH_UID} freeswitch # make the "en_US.UTF-8" locale so freeswitch will be utf-8 enabled by default RUN apt-get update -qq \ From a6e219062dd30a0c6b9b53b3dc0864a83924a8d9 Mon Sep 17 00:00:00 2001 From: Visytel <59720603+Visytel@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:00:28 +1100 Subject: [PATCH 113/123] [Build-System, ldns] config.h change to not define inline under Windows to avoid clash with Windows winsock2.h inline usage. Use updated ldns tarball on Windows. * [ldns] config.h change to not define inline under Windows to avoid clash with Windows winsock2.h inline usage * [Build-System] Use updated ldns tarball on Windows. --------- Co-authored-by: Andrey Volk --- libs/win32/ldns/ldns-lib/config.h | 4 +++- w32/download_LDNS.props | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/win32/ldns/ldns-lib/config.h b/libs/win32/ldns/ldns-lib/config.h index 58463456b3..fb29bc2c7c 100644 --- a/libs/win32/ldns/ldns-lib/config.h +++ b/libs/win32/ldns/ldns-lib/config.h @@ -260,7 +260,9 @@ /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus -#define inline +#ifndef _WIN32 +#define inline /* Do not define inline for Windows to avoid warnings/errors with winsock2.h usage of inline within the latest Windows SDKs */ +#endif #endif #if _MSC_VER >= 1900 diff --git a/w32/download_LDNS.props b/w32/download_LDNS.props index 445fe9a2b9..0036e1f278 100644 --- a/w32/download_LDNS.props +++ b/w32/download_LDNS.props @@ -29,7 +29,7 @@ Date: Wed, 10 Jan 2024 17:01:26 +0100 Subject: [PATCH 114/123] [mod_amqp] Adjusting to Appropriate Log Level for Message * [mod_amqp] Adjusting to Appropriate Log Level for Message Refined Logging Level for FreeSWITCH's mod_amqp: The logging level for the AMQP module in FreeSWITCH has been updated from 'warning' to 'debug'. This adjustment ensures a more suitable level for the log message and eliminates any potential impact on production environments. Previously, the 'warning' level would lead to unnecessary log entries for each individual message, although there was no actual warning condition. This change improves logging efficiency and appropriateness for mod_amqp's operations within FreeSWITCH. * [MOD_AMQP] Change LogLevel to DEBUG1 as it is more appropriate for this message --- src/mod/event_handlers/mod_amqp/mod_amqp_command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_command.c b/src/mod/event_handlers/mod_amqp/mod_amqp_command.c index 2789a6e252..48cdf55ce4 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_command.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_command.c @@ -231,7 +231,7 @@ static void mod_amqp_command_response(mod_amqp_command_profile_t *profile, char } /* Construct the api response */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Preparing api command response: [%s]\n", (char *)stream.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Preparing api command response: [%s]\n", (char *)stream.data); message = cJSON_CreateObject(); cJSON_AddItemToObject(message, "output", cJSON_CreateString((const char *) stream.data)); From d148a3e412dbe1772a0e6f8a39e9a9b480c49268 Mon Sep 17 00:00:00 2001 From: Dmitry Kunilov <38783480+dkunilov@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:50:08 +0300 Subject: [PATCH 115/123] [mod_amr, mod_amrwb] Fix input data corruption * Fix input data corruption in AMR and AMRWB codecs * [amr/amrwb] Check encoded frame size before decoding * [mod_amr, mod_amrwb] Coding guidelines cleanup. --------- Co-authored-by: Dmitry Kunilov Co-authored-by: Andrey Volk --- src/mod/codecs/mod_amr/mod_amr.c | 19 ++++++++++++++++--- src/mod/codecs/mod_amrwb/mod_amrwb.c | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/mod/codecs/mod_amr/mod_amr.c b/src/mod/codecs/mod_amr/mod_amr.c index e7c45c7aff..0769f62f3a 100644 --- a/src/mod/codecs/mod_amr/mod_amr.c +++ b/src/mod/codecs/mod_amr/mod_amr.c @@ -250,6 +250,7 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_ int x, i, argc, fmtptmp_pos; char *argv[10]; char fmtptmp[128]; + char *fmtp_dup = NULL; encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); @@ -283,13 +284,19 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_ switch_set_flag(context, AMR_OPT_OCTET_ALIGN); } if (codec->fmtp_in) { - argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0]))); + fmtp_dup = strdup(codec->fmtp_in); + switch_assert(fmtp_dup); + + argc = switch_separate_string(fmtp_dup, ';', argv, (sizeof(argv) / sizeof(argv[0]))); + for (x = 0; x < argc; x++) { char *data = argv[x]; char *arg; + while (*data && *data == ' ') { data++; } + if ((arg = strchr(data, '='))) { *arg++ = '\0'; if (!strcasecmp(data, "octet-align")) { @@ -325,13 +332,17 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_ } else if (!strcasecmp(data, "mode-set")) { int y, m_argc; char *m_argv[SWITCH_AMR_MODES-1]; + m_argc = switch_separate_string(arg, ',', m_argv, (sizeof(m_argv) / sizeof(m_argv[0]))); + for (y = 0; y < m_argc; y++) { context->enc_modes |= (1 << atoi(m_argv[y])); } } } } + + free(fmtp_dup); } if (context->enc_modes) { @@ -475,13 +486,15 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec, return SWITCH_STATUS_FALSE; #else struct amr_context *context = codec->private_info; - unsigned char *buf = encoded_data; + unsigned char buf[SWITCH_AMR_OUT_MAX_SIZE]; uint8_t tmp[SWITCH_AMR_OUT_MAX_SIZE]; - if (!context) { + if (!context || encoded_data_len > SWITCH_AMR_OUT_MAX_SIZE) { return SWITCH_STATUS_FALSE; } + memcpy(buf, encoded_data, encoded_data_len); + if (globals.debug) { switch_amr_info(codec, buf, encoded_data_len, switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, "AMR decoder"); } diff --git a/src/mod/codecs/mod_amrwb/mod_amrwb.c b/src/mod/codecs/mod_amrwb/mod_amrwb.c index 8be5f4d541..4ac3f25f37 100644 --- a/src/mod/codecs/mod_amrwb/mod_amrwb.c +++ b/src/mod/codecs/mod_amrwb/mod_amrwb.c @@ -198,6 +198,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla int x, i, argc, fmtptmp_pos; char *argv[10]; char fmtptmp[128]; + char *fmtp_dup = NULL; encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); @@ -222,13 +223,19 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla } if (codec->fmtp_in) { - argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0]))); + fmtp_dup = strdup(codec->fmtp_in); + switch_assert(fmtp_dup); + + argc = switch_separate_string(fmtp_dup, ';', argv, (sizeof(argv) / sizeof(argv[0]))); + for (x = 0; x < argc; x++) { char *data = argv[x]; char *arg; + while (*data && *data == ' ') { data++; } + if ((arg = strchr(data, '='))) { *arg++ = '\0'; if (!strcasecmp(data, "octet-align")) { @@ -264,7 +271,9 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla } else if (!strcasecmp(data, "mode-set")) { int y, m_argc; char *m_argv[SWITCH_AMRWB_MODES-1]; /* AMRWB has 9 modes */ + m_argc = switch_separate_string(arg, ',', m_argv, (sizeof(m_argv) / sizeof(m_argv[0]))); + for (y = 0; y < m_argc; y++) { context->enc_modes |= (1 << atoi(m_argv[y])); context->enc_mode = atoi(m_argv[y]); @@ -272,6 +281,8 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla } } } + + free(fmtp_dup); } if (context->enc_modes && !globals.mode_set_overwrite) { @@ -401,13 +412,15 @@ static switch_status_t switch_amrwb_decode(switch_codec_t *codec, return SWITCH_STATUS_FALSE; #else struct amrwb_context *context = codec->private_info; - unsigned char *buf = encoded_data; + unsigned char buf[SWITCH_AMRWB_OUT_MAX_SIZE]; uint8_t tmp[SWITCH_AMRWB_OUT_MAX_SIZE]; - if (!context) { + if (!context || encoded_data_len > SWITCH_AMRWB_OUT_MAX_SIZE) { return SWITCH_STATUS_FALSE; } + memcpy(buf, encoded_data, encoded_data_len); + if (globals.debug) { switch_amrwb_info(codec, buf, encoded_data_len, switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0, "AMRWB decoder"); } From 1c057191002b8fbcabf31d6810fb1a834a148607 Mon Sep 17 00:00:00 2001 From: wmasilva Date: Wed, 24 Jan 2024 19:04:32 +0000 Subject: [PATCH 116/123] [Core] softtimer: fix crash in timezones when reloading xml * switch_time: fix segfault null TIMEZONES_LIST.hash when reloading xml * Unbind before destroying TIMEZONES_LIST.hash. Protect TIMEZONES_LIST.hash with a mutex that's allocated in core's global runtime.memory_pool so the mutex does not die on softtimer shutdown. --------- Co-authored-by: Andrey Volk --- src/switch_time.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/switch_time.c b/src/switch_time.c index a56c5e96f1..1ee581453a 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -1384,10 +1384,13 @@ SWITCH_DECLARE(const char *) switch_lookup_timezone(const char *tz_name) return NULL; } + switch_mutex_lock(globals.mutex); if ((value = switch_core_hash_find(TIMEZONES_LIST.hash, tz_name)) == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timezone '%s' not found!\n", tz_name); } + switch_mutex_unlock(globals.mutex); + return value; } @@ -1522,7 +1525,7 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load) #endif memset(&globals, 0, sizeof(globals)); - switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); + switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, runtime.memory_pool); if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); @@ -1599,18 +1602,21 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown) DeleteCriticalSection(&timer_section); #endif + if (NODE) { + switch_event_unbind(&NODE); + } + + switch_mutex_lock(globals.mutex); if (TIMEZONES_LIST.hash) { switch_core_hash_destroy(&TIMEZONES_LIST.hash); } + switch_mutex_unlock(globals.mutex); + if (TIMEZONES_LIST.pool) { switch_core_destroy_memory_pool(&TIMEZONES_LIST.pool); } - if (NODE) { - switch_event_unbind(&NODE); - } - return SWITCH_STATUS_SUCCESS; } From 8b7a8c4aea5906ab3988764c4077c205151695e6 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 18 Oct 2023 20:24:14 +0300 Subject: [PATCH 117/123] [core] SDP: replace SIP lingo in SDP offer/answer. --- src/include/switch_types.h | 6 +- .../applications/mod_dptools/mod_dptools.c | 2 +- src/mod/endpoints/mod_loopback/mod_loopback.c | 2 +- src/mod/endpoints/mod_sofia/mod_sofia.c | 22 ++--- src/mod/endpoints/mod_sofia/sofia.c | 50 +++++------ src/mod/endpoints/mod_sofia/sofia_glue.c | 2 +- src/mod/endpoints/mod_verto/mod_verto.c | 22 ++--- src/mod/languages/mod_managed/managed/swig.cs | 4 +- src/switch_core_media.c | 88 +++++++++---------- src/switch_ivr.c | 2 +- tests/unit/switch_rtp.c | 2 +- tests/unit/switch_rtp_pcap.c | 2 +- 12 files changed, 103 insertions(+), 101 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 94a4c62cca..d315e46fc8 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -2656,10 +2656,12 @@ struct switch_live_array_s; typedef struct switch_live_array_s switch_live_array_t; typedef enum { - SDP_TYPE_REQUEST, - SDP_TYPE_RESPONSE + SDP_OFFER, + SDP_ANSWER } switch_sdp_type_t; +#define SDP_TYPE_REQUEST SDP_OFFER +#define SDP_TYPE_RESPONSE SDP_ANSWER typedef enum { AEAD_AES_256_GCM_8, diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index f52b1184e5..58fce5f5d3 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -593,7 +593,7 @@ SWITCH_STANDARD_APP(filter_codecs_function) r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE); if (data && r_sdp) { - switch_core_media_merge_sdp_codec_string(session, r_sdp, SDP_TYPE_REQUEST, data); + switch_core_media_merge_sdp_codec_string(session, r_sdp, SDP_OFFER, data); switch_channel_set_variable(channel, "filter_codec_string", data); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Incomplete data\n"); diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index 456936562a..f5941eae36 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -1429,7 +1429,7 @@ static switch_status_t null_tech_init(null_private_t *tech_pvt, switch_core_sess // switch_core_media_check_video_codecs(session); // switch_core_media_choose_port(session, SWITCH_MEDIA_TYPE_AUDIO, 0); // switch_core_media_choose_port(session, SWITCH_MEDIA_TYPE_VIDEO, 0); - // switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, "127.0.0.1", 2000, NULL, 0); + // switch_core_media_gen_local_sdp(session, SDP_OFFER, "127.0.0.1", 2000, NULL, 0); // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s\n", mparams.local_sdp_str); } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 458be3f875..c5ce6e3855 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -790,7 +790,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); tech_pvt->mparams.local_sdp_str = NULL; switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0); - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); } else if (is_3pcc_proxy) { if (!(sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY))) { @@ -802,7 +802,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) } else { switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0); switch_core_media_prepare_codecs(session, 1); - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 1); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 1); sofia_set_flag_locked(tech_pvt, TFLAG_3PCC); } @@ -889,7 +889,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); - if (zstr(r_sdp) || sofia_media_tech_media(tech_pvt, r_sdp, SDP_TYPE_REQUEST) != SWITCH_STATUS_SUCCESS) { + if (zstr(r_sdp) || sofia_media_tech_media(tech_pvt, r_sdp, SDP_OFFER) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); //switch_mutex_lock(tech_pvt->sofia_mutex); //nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); @@ -904,7 +904,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) return status; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } @@ -1598,7 +1598,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE); port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE); if (ip && port) { - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, ip, (switch_port_t)atoi(port), msg->string_arg, 1); + switch_core_media_gen_local_sdp(session, SDP_OFFER, ip, (switch_port_t)atoi(port), msg->string_arg, 1); } if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { @@ -1783,7 +1783,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_INBOUND) { switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); - if (sofia_media_tech_media(tech_pvt, r_sdp, SDP_TYPE_REQUEST) != SWITCH_STATUS_SUCCESS) { + if (sofia_media_tech_media(tech_pvt, r_sdp, SDP_OFFER) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); status = SWITCH_STATUS_FALSE; goto end_lock; @@ -1793,7 +1793,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } - switch_core_media_set_sdp_codec_string(tech_pvt->session, r_sdp, SDP_TYPE_RESPONSE); + switch_core_media_set_sdp_codec_string(tech_pvt->session, r_sdp, SDP_ANSWER); switch_channel_set_variable(tech_pvt->channel, "absolute_codec_string", switch_channel_get_variable(tech_pvt->channel, "ep_codec_string")); switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); @@ -1802,7 +1802,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi goto end_lock; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 1); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 1); if (!msg->numeric_arg) { if (send_invite) { @@ -2256,7 +2256,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi switch_channel_clear_flag(tech_pvt->channel, CF_AWAITING_STREAM_CHANGE); switch_core_session_local_crypto_key(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO); - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (sofia_use_soa(tech_pvt)) { nua_respond(tech_pvt->nh, SIP_200_OK, @@ -2584,7 +2584,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); - if (zstr(r_sdp) || sofia_media_tech_media(tech_pvt, r_sdp, SDP_TYPE_REQUEST) != SWITCH_STATUS_SUCCESS) { + if (zstr(r_sdp) || sofia_media_tech_media(tech_pvt, r_sdp, SDP_OFFER) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "CODEC NEGOTIATION ERROR. SDP:\n%s\n", r_sdp ? r_sdp : "NO SDP!"); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); @@ -2599,7 +2599,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); goto end_lock; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c5b5bcc190..311052a619 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6683,7 +6683,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status tech_pvt->mparams.last_sdp_response = NULL; if (sip->sip_payload && sip->sip_payload->pl_data) { - switch_core_media_set_sdp_codec_string(session, sip->sip_payload->pl_data, SDP_TYPE_RESPONSE); + switch_core_media_set_sdp_codec_string(session, sip->sip_payload->pl_data, SDP_ANSWER); if (!zstr(tech_pvt->mparams.prev_sdp_response) && !strcmp(tech_pvt->mparams.prev_sdp_response, sip->sip_payload->pl_data)) { tech_pvt->mparams.last_sdp_response = tech_pvt->mparams.prev_sdp_response; @@ -7506,9 +7506,9 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_mark_pre_answered(channel); } //if ((sofia_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) || switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND)) { - // switch_core_media_set_sdp_codec_string(session, r_sdp, status < 200 ? SDP_TYPE_REQUEST : SDP_TYPE_RESPONSE); + // switch_core_media_set_sdp_codec_string(session, r_sdp, status < 200 ? SDP_OFFER : SDP_ANSWER); //} - switch_core_media_set_sdp_codec_string(session, r_sdp, SDP_TYPE_REQUEST); + switch_core_media_set_sdp_codec_string(session, r_sdp, SDP_OFFER); sofia_glue_pass_sdp(tech_pvt, (char *) r_sdp); sofia_set_flag(tech_pvt, TFLAG_NEW_SDP); @@ -7680,7 +7680,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } } else { - if (sofia_media_tech_media(tech_pvt, (char *) r_sdp, SDP_TYPE_REQUEST) != SWITCH_STATUS_SUCCESS) { + if (sofia_media_tech_media(tech_pvt, (char *) r_sdp, SDP_OFFER) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)),TAG_END()); @@ -7776,7 +7776,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_FALSE); if (tech_pvt->mparams.num_codecs) { - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_OFFER); } if (!match) { @@ -7785,7 +7785,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)),TAG_END()); } } else { - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED"); sofia_set_flag_locked(tech_pvt, TFLAG_READY); @@ -7909,7 +7909,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, uint8_t match = 0; if (tech_pvt->mparams.num_codecs) { - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_OFFER); } if (!match) { @@ -7995,7 +7995,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0); switch_core_media_prepare_codecs(session, 1); switch_channel_set_state(channel, CS_HIBERNATE); - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 0); sofia_set_flag_locked(tech_pvt, TFLAG_3PCC); if (sofia_use_soa(tech_pvt)) { @@ -8067,10 +8067,10 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_set_flag(channel, CF_NOSDP_REINVITE); if (switch_channel_var_true(channel, "sip_unhold_nosdp")) { - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, "sendrecv", + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, "sendrecv", zstr(tech_pvt->mparams.local_sdp_str) || !switch_channel_test_flag(channel, CF_PROXY_MODE)); } else { - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, zstr(tech_pvt->mparams.local_sdp_str) || !switch_channel_test_flag(channel, CF_PROXY_MODE)); } @@ -8116,13 +8116,13 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, sofia_set_flag(tech_pvt, TFLAG_SDP); - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_RESPONSE); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_ANSWER); if (match) { if (switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0) != SWITCH_STATUS_SUCCESS) { goto done; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Early Media RTP Error!\n"); @@ -8191,7 +8191,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); - if (sofia_media_tech_media(tech_pvt, r_sdp, SDP_TYPE_REQUEST) != SWITCH_STATUS_SUCCESS) { + if (sofia_media_tech_media(tech_pvt, r_sdp, SDP_OFFER) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); switch_core_session_rwunlock(other_session); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); @@ -8210,7 +8210,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 1); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 1); if (sofia_use_soa(tech_pvt)) { nua_respond(tech_pvt->nh, SIP_200_OK, @@ -8320,7 +8320,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_set_flag(tech_pvt->channel, CF_REINVITE); if (tech_pvt->mparams.num_codecs){ - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_OFFER); } if (!match) { @@ -8369,7 +8369,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (sofia_use_soa(tech_pvt)){ nua_respond(tech_pvt->nh, SIP_200_OK, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), @@ -8419,7 +8419,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_set_flag(tech_pvt->channel, CF_REINVITE); if (tech_pvt->mparams.num_codecs) { - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_OFFER); } @@ -8438,7 +8438,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, goto done; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Reinvite RTP Error!\n"); @@ -8462,7 +8462,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (is_ok) { if (switch_core_session_local_crypto_key(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO)) { - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); } if (!switch_channel_test_flag(tech_pvt->channel, CF_AWAITING_STREAM_CHANGE)) { @@ -8507,13 +8507,13 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (tech_pvt->mparams.num_codecs) { - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_RESPONSE); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_ANSWER); } if (match) { if (switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0) != SWITCH_STATUS_SUCCESS) { goto done; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Processing updated SDP\n"); switch_channel_set_flag(tech_pvt->channel, CF_REINVITE); @@ -8571,9 +8571,9 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (tech_pvt->mparams.num_codecs) { if (sofia_test_flag(tech_pvt, TFLAG_GOT_ACK)) { - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_OFFER); } else { - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_RESPONSE); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_ANSWER); } } @@ -8668,7 +8668,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, uint8_t match = 0; - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_RESPONSE); + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_ANSWER); sofia_set_flag_locked(tech_pvt, TFLAG_ANS); @@ -10466,7 +10466,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia if (r_sdp) { - switch_core_media_set_sdp_codec_string(session, r_sdp, SDP_TYPE_REQUEST); + switch_core_media_set_sdp_codec_string(session, r_sdp, SDP_OFFER); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index eceae218f8..1452a7cf0f 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1158,7 +1158,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) } if (!switch_channel_get_private(tech_pvt->channel, "t38_options") || zstr(tech_pvt->mparams.local_sdp_str)) { - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 0); } sofia_set_flag_locked(tech_pvt, TFLAG_READY); diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index ac042fe626..48c40527b5 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1320,7 +1320,7 @@ static void tech_reattach(verto_pvt_t *tech_pvt, jsock_t *jsock) switch_channel_set_flag(tech_pvt->channel, CF_REATTACHED); switch_channel_set_flag(tech_pvt->channel, CF_REINVITE); switch_channel_set_flag(tech_pvt->channel, CF_RECOVERING); - switch_core_media_gen_local_sdp(tech_pvt->session, SDP_TYPE_REQUEST, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(tech_pvt->session, SDP_OFFER, NULL, 0, NULL, 0); switch_channel_clear_flag(tech_pvt->channel, CF_REINVITE); switch_channel_clear_flag(tech_pvt->channel, CF_RECOVERING); switch_core_session_request_video_refresh(tech_pvt->session); @@ -2405,7 +2405,7 @@ static switch_status_t verto_connect(switch_core_session_t *session, const char } } - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 0); } msg = jrpc_new_req(method, tech_pvt->call_id, ¶ms); @@ -2641,7 +2641,7 @@ static switch_status_t verto_media(switch_core_session_t *session) switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); if (tech_pvt->r_sdp) { - if (verto_tech_media(tech_pvt, tech_pvt->r_sdp, SDP_TYPE_REQUEST) != SWITCH_STATUS_SUCCESS) { + if (verto_tech_media(tech_pvt, tech_pvt->r_sdp, SDP_OFFER) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); return SWITCH_STATUS_FALSE; } @@ -2653,7 +2653,7 @@ static switch_status_t verto_media(switch_core_session_t *session) return status; } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (switch_core_media_activate_rtp(tech_pvt->session) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); @@ -2963,7 +2963,7 @@ static switch_bool_t verto__answer_func(const char *method, cJSON *params, jsock switch_channel_set_variable(tech_pvt->channel, SWITCH_R_SDP_VARIABLE, sdp); switch_channel_set_variable(tech_pvt->channel, "verto_client_address", jsock->name); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Remote SDP %s:\n%s\n", switch_channel_get_name(tech_pvt->channel), sdp); - switch_core_media_set_sdp_codec_string(session, sdp, SDP_TYPE_RESPONSE); + switch_core_media_set_sdp_codec_string(session, sdp, SDP_ANSWER); if (!switch_channel_var_true(switch_core_session_get_channel(session),"verto_skip_set_user")) { switch_ivr_set_user(session, jsock->uid); @@ -2978,7 +2978,7 @@ static switch_bool_t verto__answer_func(const char *method, cJSON *params, jsock if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE)) { pass_sdp(tech_pvt); } else { - if (verto_tech_media(tech_pvt, tech_pvt->r_sdp, SDP_TYPE_RESPONSE) != SWITCH_STATUS_SUCCESS) { + if (verto_tech_media(tech_pvt, tech_pvt->r_sdp, SDP_ANSWER) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); cJSON_AddItemToObject(obj, "message", cJSON_CreateString("CODEC ERROR")); err = 1; @@ -3448,8 +3448,8 @@ static switch_bool_t verto__modify_func(const char *method, cJSON *params, jsock //switch_channel_set_flag(tech_pvt->channel, CF_VIDEO_BREAK); //switch_core_session_kill_channel(tech_pvt->session, SWITCH_SIG_BREAK); - if (switch_core_media_negotiate_sdp(tech_pvt->session, tech_pvt->r_sdp, &p, SDP_TYPE_REQUEST)) { - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + if (switch_core_media_negotiate_sdp(tech_pvt->session, tech_pvt->r_sdp, &p, SDP_OFFER)) { + switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (switch_core_media_activate_rtp(tech_pvt->session) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "MEDIA ERROR"); @@ -3606,8 +3606,8 @@ static switch_bool_t verto__attach_func(const char *method, cJSON *params, jsock //switch_channel_set_flag(tech_pvt->channel, CF_VIDEO_BREAK); //switch_core_session_kill_channel(tech_pvt->session, SWITCH_SIG_BREAK); - if (switch_core_media_negotiate_sdp(tech_pvt->session, tech_pvt->r_sdp, &p, SDP_TYPE_RESPONSE)) { - //switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + if (switch_core_media_negotiate_sdp(tech_pvt->session, tech_pvt->r_sdp, &p, SDP_ANSWER)) { + //switch_core_media_gen_local_sdp(session, SDP_ANSWER, NULL, 0, NULL, 0); if (switch_core_media_activate_rtp(tech_pvt->session) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "MEDIA ERROR"); @@ -4020,7 +4020,7 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock tech_pvt->channel = channel; tech_pvt->jsock_uuid = switch_core_session_strdup(session, jsock->uuid_str); tech_pvt->r_sdp = switch_core_session_strdup(session, sdp); - switch_core_media_set_sdp_codec_string(session, sdp, SDP_TYPE_REQUEST); + switch_core_media_set_sdp_codec_string(session, sdp, SDP_OFFER); switch_core_session_set_private_class(session, tech_pvt, SWITCH_PVT_SECONDARY); tech_pvt->call_id = switch_core_session_strdup(session, call_id); diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index fbab2f3f77..dc3926cbbb 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -45055,8 +45055,8 @@ public class switch_scheduler_task : global::System.IDisposable { namespace FreeSWITCH.Native { public enum switch_sdp_type_t { - SDP_TYPE_REQUEST, - SDP_TYPE_RESPONSE + SDP_OFFER, + SDP_ANSWER } } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 4b6d8aff8b..58ef94a53e 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -713,7 +713,7 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se for (pmap = engine->payload_map; pmap && pmap->allocated; pmap = pmap->next) { - if (sdp_type == SDP_TYPE_RESPONSE) { + if (sdp_type == SDP_ANSWER) { switch(type) { case SWITCH_MEDIA_TYPE_TEXT: exists = (type == pmap->type && !strcasecmp(name, pmap->iananame)); @@ -722,11 +722,11 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se exists = (type == pmap->type && !strcasecmp(name, pmap->iananame) && pmap->pt == pt && (!pmap->rate || rate == pmap->rate) && (!pmap->ptime || pmap->ptime == ptime)); break; case SWITCH_MEDIA_TYPE_VIDEO: - exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame)); + exists = (pmap->sdp_type == SDP_OFFER && type == pmap->type && !strcasecmp(name, pmap->iananame)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECK PMAP %s:%s %d %s:%s %d ... %d\n", name, "RES", pt, - pmap->iananame, pmap->sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pmap->pt, exists); + pmap->iananame, pmap->sdp_type == SDP_OFFER ? "REQ" : "RES", pmap->pt, exists); break; @@ -797,7 +797,7 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se } if (!zstr(fmtp)) { - if (sdp_type == SDP_TYPE_REQUEST || !exists) { + if (sdp_type == SDP_OFFER || !exists) { pmap->rm_fmtp = switch_core_strdup(session->pool, fmtp); } } @@ -807,7 +807,7 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se pmap->recv_pt = (switch_payload_t) pt; - if (sdp_type == SDP_TYPE_REQUEST || !exists) { + if (sdp_type == SDP_OFFER || !exists) { pmap->pt = (switch_payload_t) pt; } @@ -818,7 +818,7 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se if (!exists) { pmap->sdp_type = sdp_type; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "ADD PMAP %s %s %d\n", sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", name, pt); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "ADD PMAP %s %s %d\n", sdp_type == SDP_OFFER ? "REQ" : "RES", name, pt); if (pmap == engine->payload_map) { engine->pmap_tail = pmap; @@ -1724,7 +1724,7 @@ SWITCH_DECLARE(int) switch_core_session_check_incoming_crypto(switch_core_sessio const char *a = switch_stristr("AE", engine->ssec[engine->crypto_type].remote_crypto_key); const char *b = switch_stristr("AE", crypto); - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { if (!vval) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Unsupported Crypto [%s]\n", crypto); goto end; @@ -4633,7 +4633,7 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s switch_channel_set_flag(other_session->channel, CF_PROCESSING_STREAM_CHANGE); switch_channel_set_flag(session->channel, CF_AWAITING_STREAM_CHANGE); - if (sdp_type == SDP_TYPE_REQUEST && r_sdp) { + if (sdp_type == SDP_OFFER && r_sdp) { const char *filter_codec_string = switch_channel_get_variable(session->channel, "filter_codec_string"); switch_channel_set_variable(session->channel, "codec_string", NULL); @@ -4654,7 +4654,7 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s } if (other_session) { - if (sdp_type == SDP_TYPE_RESPONSE && switch_channel_test_flag(session->channel, CF_PROCESSING_STREAM_CHANGE)) { + if (sdp_type == SDP_ANSWER && switch_channel_test_flag(session->channel, CF_PROCESSING_STREAM_CHANGE)) { switch_channel_clear_flag(session->channel, CF_PROCESSING_STREAM_CHANGE); if (switch_channel_test_flag(other_session->channel, CF_AWAITING_STREAM_CHANGE)) { @@ -4667,7 +4667,7 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s } sdp_in = switch_channel_get_variable(other_session->channel, SWITCH_R_SDP_VARIABLE); - res = switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST); + res = switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_OFFER); (void)res; switch_core_media_activate_rtp(other_session); msg = switch_core_session_alloc(other_session, sizeof(*msg)); @@ -4715,11 +4715,11 @@ SWITCH_DECLARE(void) switch_core_media_set_smode(switch_core_session_t *session, engine->pass_codecs = 0; if (switch_channel_var_true(session->channel, "rtp_pass_codecs_on_stream_change")) { - if (sdp_type == SDP_TYPE_REQUEST && switch_channel_test_flag(session->channel, CF_REINVITE) && + if (sdp_type == SDP_OFFER && switch_channel_test_flag(session->channel, CF_REINVITE) && switch_channel_media_up(session->channel) && (pass_codecs || old_smode != smode)) { if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { - switch_core_media_set_smode(other_session, type, opp_smode, SDP_TYPE_REQUEST); + switch_core_media_set_smode(other_session, type, opp_smode, SDP_OFFER); switch_channel_set_flag(session->channel, CF_STREAM_CHANGED); switch_core_session_rwunlock(other_session); } @@ -4752,7 +4752,7 @@ static void switch_core_media_set_rmode(switch_core_session_t *session, switch_m if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { - if (sdp_type == SDP_TYPE_RESPONSE && (switch_channel_test_flag(other_session->channel, CF_REINVITE) || switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_OUTBOUND)) { + if (sdp_type == SDP_ANSWER && (switch_channel_test_flag(other_session->channel, CF_REINVITE) || switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_OUTBOUND)) { switch_core_media_set_smode(other_session, type, rmode, sdp_type); } @@ -5099,7 +5099,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_channel_clear_app_flag_key("T38", session->channel, CF_APP_T38); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s T38 REFUSE on %s\n", switch_channel_get_name(channel), - sdp_type == SDP_TYPE_RESPONSE ? "response" : "request"); + sdp_type == SDP_ANSWER ? "response" : "request"); restore_pmaps(a_engine); fmatch = 0; @@ -5112,7 +5112,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s T38 ACCEPT on %s\n", switch_channel_get_name(channel), - sdp_type == SDP_TYPE_RESPONSE ? "response" : "request"); + sdp_type == SDP_ANSWER ? "response" : "request"); if (switch_channel_test_app_flag_key("T38", session->channel, CF_APP_T38)) { if (proceed) *proceed = 0; @@ -5217,7 +5217,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s T38 %s POSSIBLE on %s\n", switch_channel_get_name(channel), fmatch ? "IS" : "IS NOT", - sdp_type == SDP_TYPE_RESPONSE ? "response" : "request"); + sdp_type == SDP_ANSWER ? "response" : "request"); goto done; @@ -5249,7 +5249,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_core_media_set_rmode(smh->session, SWITCH_MEDIA_TYPE_AUDIO, sdp_media_flow(m->m_mode), sdp_type); - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { switch(a_engine->rmode) { case SWITCH_MEDIA_FLOW_RECVONLY: switch_core_media_set_smode(smh->session, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_FLOW_SENDONLY, sdp_type); @@ -5315,7 +5315,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_channel_set_variable(session->channel, "media_audio_mode", NULL); } - if (sdp_type == SDP_TYPE_RESPONSE) { + if (sdp_type == SDP_ANSWER) { if (inactive) { // When freeswitch had previously sent inactive in sip request. it should remain inactive otherwise smode should be sendrecv if (a_engine->smode==SWITCH_MEDIA_FLOW_INACTIVE) { @@ -5834,7 +5834,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s if (smh->mparams->dtmf_type == DTMF_AUTO || smh->mparams->dtmf_type == DTMF_2833 || switch_channel_test_flag(session->channel, CF_LIBERAL_DTMF)) { - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { smh->mparams->te = smh->mparams->recv_te = (switch_payload_t) best_te; switch_channel_set_variable(session->channel, "dtmf_type", "rfc2833"); smh->mparams->dtmf_type = DTMF_2833; @@ -5902,7 +5902,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s map->rm_encoding, NULL, NULL, - SDP_TYPE_REQUEST, + SDP_OFFER, map->rm_pt, 1000, 0, @@ -5980,7 +5980,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s switch_core_media_set_rmode(smh->session, SWITCH_MEDIA_TYPE_VIDEO, sdp_media_flow(m->m_mode), sdp_type); - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { sdp_bandwidth_t *bw; int tias = 0; @@ -6146,7 +6146,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s vmatch = strcasecmp(rm_encoding, imp->iananame) ? 0 : 1; } - if (sdp_type == SDP_TYPE_RESPONSE && consider_video_fmtp && vmatch && !zstr(map->rm_fmtp) && !zstr(smh->fmtps[i])) { + if (sdp_type == SDP_ANSWER && consider_video_fmtp && vmatch && !zstr(map->rm_fmtp) && !zstr(smh->fmtps[i])) { almost_vmatch = 1; vmatch = !strcasecmp(smh->fmtps[i], map->rm_fmtp); } @@ -6321,7 +6321,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s "L16", NULL, NULL, - SDP_TYPE_REQUEST, + SDP_OFFER, 97, 8000, 20, @@ -6378,7 +6378,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s if (switch_channel_test_flag(channel, CF_VIDEO) && !saw_video) { //switch_core_media_set_rmode(smh->session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_MEDIA_FLOW_INACTIVE, sdp_type); - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { switch_core_media_set_smode(smh->session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_MEDIA_FLOW_INACTIVE, sdp_type); } } @@ -9708,7 +9708,7 @@ static const char *get_media_profile_name(switch_core_session_t *session, int se static char *get_setup(switch_rtp_engine_t *engine, switch_core_session_t *session, switch_sdp_type_t sdp_type) { - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { engine->dtls_controller = 0; engine->new_dtls = 1; engine->new_ice = 1; @@ -9809,7 +9809,7 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, } if (smh->mparams->dtmf_type == DTMF_2833 && smh->mparams->te > 95) { - if (sdp_type == SDP_TYPE_RESPONSE) { + if (sdp_type == SDP_ANSWER) { switch_rtp_engine_t *a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO]; if (a_engine) { payload_map_t *pmap; @@ -9915,7 +9915,7 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, if ((smh->mparams->dtmf_type == DTMF_2833 || switch_channel_test_flag(session->channel, CF_LIBERAL_DTMF)) && smh->mparams->te > 95) { - if (smh->mparams->dtmf_type == DTMF_2833 && sdp_type == SDP_TYPE_RESPONSE) { + if (smh->mparams->dtmf_type == DTMF_2833 && sdp_type == SDP_ANSWER) { switch_rtp_engine_t *a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO]; if (a_engine) { payload_map_t *pmap; @@ -10264,7 +10264,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess v_engine->rtcp_mux = -1; } - if ((a_engine->rtcp_mux != -1 && v_engine->rtcp_mux != -1) && (sdp_type == SDP_TYPE_REQUEST)) { + if ((a_engine->rtcp_mux != -1 && v_engine->rtcp_mux != -1) && (sdp_type == SDP_OFFER)) { a_engine->rtcp_mux = 1; v_engine->rtcp_mux = 1; } @@ -10347,7 +10347,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess continue; } - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { for (j = 0; j < SWITCH_MAX_CODECS; j++) { if (smh->rates[j] == 0) { break; @@ -10365,7 +10365,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess continue; } - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { switch_core_session_t *orig_session = NULL; switch_core_session_get_partner(session, &orig_session); @@ -11180,7 +11180,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess } } - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { fir++; pli++; nack++; @@ -11441,7 +11441,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess // RTP TEXT - if (sdp_type == SDP_TYPE_RESPONSE && !switch_channel_test_flag(session->channel, CF_RTT)) { + if (sdp_type == SDP_ANSWER && !switch_channel_test_flag(session->channel, CF_RTT)) { if (switch_channel_test_flag(session->channel, CF_TEXT_SDP_RECVD)) { switch_channel_clear_flag(session->channel, CF_TEXT_SDP_RECVD); switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "m=text 0 %s 19\r\n", @@ -11456,7 +11456,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess t_engine->t140_pt = 0; t_engine->red_pt = 0; - if (sdp_type == SDP_TYPE_REQUEST) { + if (sdp_type == SDP_OFFER) { t_engine->t140_pt = 96; t_engine->red_pt = 97; @@ -11465,7 +11465,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess "red", NULL, NULL, - SDP_TYPE_REQUEST, + SDP_OFFER, t_engine->red_pt, 1000, 0, @@ -11477,7 +11477,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess "t140", NULL, NULL, - SDP_TYPE_REQUEST, + SDP_OFFER, t_engine->t140_pt, 1000, 0, @@ -11978,7 +11978,7 @@ SWITCH_DECLARE(void) switch_core_media_patch_sdp(switch_core_session_t *session) "PROXY", NULL, NULL, - SDP_TYPE_RESPONSE, + SDP_ANSWER, 0, 8000, 20, @@ -12135,7 +12135,7 @@ SWITCH_DECLARE(void) switch_core_media_patch_sdp(switch_core_session_t *session) "PROXY-VID", NULL, NULL, - SDP_TYPE_RESPONSE, + SDP_ANSWER, 0, 90000, 90000, @@ -12198,7 +12198,7 @@ SWITCH_DECLARE(void) switch_core_media_patch_sdp(switch_core_session_t *session) "PROXY-TXT", NULL, NULL, - SDP_TYPE_RESPONSE, + SDP_ANSWER, 0, 90000, 90000, @@ -13099,7 +13099,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se switch_core_media_prepare_codecs(session, 1); clear_pmaps(a_engine); clear_pmaps(v_engine); - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, ip, (switch_port_t)atoi(port), NULL, 1); + switch_core_media_gen_local_sdp(session, SDP_OFFER, ip, (switch_port_t)atoi(port), NULL, 1); } } @@ -13151,7 +13151,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se switch_core_media_prepare_codecs(session, SWITCH_TRUE); switch_core_media_check_video_codecs(session); - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 1); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 1); } if (msg->numeric_arg && switch_core_session_get_partner(session, &nsession) == SWITCH_STATUS_SUCCESS) { @@ -13964,7 +13964,7 @@ SWITCH_DECLARE(void) switch_core_media_check_outgoing_proxy(switch_core_session_ "PROXY", NULL, NULL, - SDP_TYPE_RESPONSE, + SDP_ANSWER, 0, 8000, 20, @@ -13980,7 +13980,7 @@ SWITCH_DECLARE(void) switch_core_media_check_outgoing_proxy(switch_core_session_ "PROXY-VID", NULL, NULL, - SDP_TYPE_RESPONSE, + SDP_ANSWER, 0, 90000, 90000, @@ -14001,7 +14001,7 @@ SWITCH_DECLARE(void) switch_core_media_check_outgoing_proxy(switch_core_session_ "PROXY-TXT", NULL, NULL, - SDP_TYPE_RESPONSE, + SDP_ANSWER, 0, 1000, 1000, @@ -14155,7 +14155,7 @@ SWITCH_DECLARE (void) switch_core_media_recover_session(switch_core_session_t *s } } - switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL, 0, NULL, 1); + switch_core_media_gen_local_sdp(session, SDP_OFFER, NULL, 0, NULL, 1); switch_core_media_set_video_codec(session, 1); if (switch_core_media_activate_rtp(session) != SWITCH_STATUS_SUCCESS) { diff --git a/src/switch_ivr.c b/src/switch_ivr.c index c36149c0a5..1443f989cf 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -2151,7 +2151,7 @@ SWITCH_DECLARE(void) switch_ivr_check_hold(switch_core_session_t *session) msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA_RENEG; msg.from = __FILE__; - switch_core_media_set_smode(session, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_FLOW_SENDRECV, SDP_TYPE_REQUEST); + switch_core_media_set_smode(session, SWITCH_MEDIA_TYPE_AUDIO, SWITCH_MEDIA_FLOW_SENDRECV, SDP_OFFER); switch_core_session_receive_message(session, &msg); } diff --git a/tests/unit/switch_rtp.c b/tests/unit/switch_rtp.c index 48c0f80d6b..7d22524358 100644 --- a/tests/unit/switch_rtp.c +++ b/tests/unit/switch_rtp.c @@ -187,7 +187,7 @@ FST_TEARDOWN_END() switch_core_media_prepare_codecs(session, SWITCH_FALSE); - match = switch_core_media_negotiate_sdp(session, r_sdp, &p, SDP_TYPE_REQUEST); + match = switch_core_media_negotiate_sdp(session, r_sdp, &p, SDP_OFFER); fst_requires(match == 1); status = switch_core_media_choose_ports(session, SWITCH_TRUE, SWITCH_FALSE); diff --git a/tests/unit/switch_rtp_pcap.c b/tests/unit/switch_rtp_pcap.c index 647e481c8e..eb4993a616 100644 --- a/tests/unit/switch_rtp_pcap.c +++ b/tests/unit/switch_rtp_pcap.c @@ -206,7 +206,7 @@ static switch_status_t rtp_test_start_call(switch_core_session_t **psession) return SWITCH_STATUS_FALSE; } - match = switch_core_media_negotiate_sdp(session, r_sdp, &p, SDP_TYPE_REQUEST); + match = switch_core_media_negotiate_sdp(session, r_sdp, &p, SDP_OFFER); if (match != 1) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "switch_core_media_negotiate_sdp() failed\n"); return SWITCH_STATUS_FALSE; From 9df3076f29a52a690ebd25b1972a8b97d55442e0 Mon Sep 17 00:00:00 2001 From: Anton Olofsson Date: Mon, 29 Jan 2024 17:05:45 +0100 Subject: [PATCH 118/123] [mod_event_socket] Check if listener is running before pushing more logs or events to its queue This fixes a possibility for MAX_MISSED to be exceeded if more logs are attempted to be pushed to the listener's queue after running kill_listener but before the listener thread gets CPU time and removes itself. On a heavily loaded system with a lot of logs in the event dispatch queue these excessive logs may prove fatal since socket_logger itself will produce logs about the full queue, resulting in a circular situation of never-ending logs. The same logic was applied to event_handler after finding the same behaviour mentioned in signalwire/freeswitch#2143. --- src/mod/event_handlers/mod_event_socket/mod_event_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 520bd92ac7..935f726ee1 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -173,7 +173,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l switch_status_t qstatus; switch_mutex_lock(globals.listener_mutex); for (l = listen_list.listeners; l; l = l->next) { - if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) { + if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level && switch_test_flag(l, LFLAG_RUNNING)) { switch_log_node_t *dnode = switch_log_node_dup(node); qstatus = switch_queue_trypush(l->log_queue, dnode); if (qstatus == SWITCH_STATUS_SUCCESS) { @@ -302,7 +302,7 @@ static void event_handler(switch_event_t *event) } } - if (l->expire_time || !switch_test_flag(l, LFLAG_EVENTS)) { + if (l->expire_time || !switch_test_flag(l, LFLAG_EVENTS) || !switch_test_flag(l, LFLAG_RUNNING)) { last = l; continue; } From 647035c323369acb75fac18d13f2cf1a635ffff4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 5 Feb 2024 23:50:01 +0300 Subject: [PATCH 119/123] [mod_opus] Fix status returned by switch_opus_decode(). Should be SWITCH_STATUS_FALSE instead of SWITCH_STATUS_NOOP. Add a unit-test. --- Freeswitch.2017.sln | 15 ++ src/mod/codecs/mod_opus/mod_opus.c | 2 +- tests/unit/switch_core_codec.c | 26 +++ .../unit/test_switch_core_codec.2017.vcxproj | 205 ++++++++++++++++++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_switch_core_codec.2017.vcxproj diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 5f3259a6e0..0326ffac12 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -554,6 +554,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_switch_core_db", "test EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_switch_ivr_originate", "tests\unit\test_switch_ivr_originate.2017.vcxproj", "{69A7464A-9B0D-4804-A108-835229DACF58}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_switch_core_codec", "tests\unit\test_switch_core_codec.2017.vcxproj", "{589A07E7-5DE5-49FD-A62C-27795B806AFB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution All|Win32 = All|Win32 @@ -2516,6 +2518,18 @@ Global {69A7464A-9B0D-4804-A108-835229DACF58}.Release|Win32.Build.0 = Release|Win32 {69A7464A-9B0D-4804-A108-835229DACF58}.Release|x64.ActiveCfg = Release|x64 {69A7464A-9B0D-4804-A108-835229DACF58}.Release|x64.Build.0 = Release|x64 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.All|Win32.ActiveCfg = Debug|Win32 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.All|Win32.Build.0 = Debug|Win32 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.All|x64.ActiveCfg = Debug|x64 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.All|x64.Build.0 = Debug|x64 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Debug|Win32.ActiveCfg = Debug|Win32 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Debug|Win32.Build.0 = Debug|Win32 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Debug|x64.ActiveCfg = Debug|x64 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Debug|x64.Build.0 = Debug|x64 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Release|Win32.ActiveCfg = Release|Win32 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Release|Win32.Build.0 = Release|Win32 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Release|x64.ActiveCfg = Release|x64 + {589A07E7-5DE5-49FD-A62C-27795B806AFB}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2714,6 +2728,7 @@ Global {0B612F84-7533-4DEC-AEDD-5C9CBCF15EAC} = {31C2761D-20E0-4BF8-98B9-E32F0D8DD6E1} {580675D7-C1C9-4197-AAC5-00F64FAFDE78} = {9388C266-C3FC-468A-92EF-0CBC35941412} {69A7464A-9B0D-4804-A108-835229DACF58} = {9388C266-C3FC-468A-92EF-0CBC35941412} + {589A07E7-5DE5-49FD-A62C-27795B806AFB} = {9388C266-C3FC-468A-92EF-0CBC35941412} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {09840DE7-9208-45AA-9667-1A71EE93BD1E} diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index a38389d031..96933e6ea5 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -930,7 +930,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, if (samples < 0) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Decoder Error: %s fs:%u plc:%s!\n", opus_strerror(samples), frame_size, plc ? "true" : "false"); - return SWITCH_STATUS_NOOP; + return SWITCH_STATUS_FALSE; } *decoded_data_len = samples * 2 * (!context->codec_settings.sprop_stereo ? codec->implementation->number_of_channels : 2); diff --git a/tests/unit/switch_core_codec.c b/tests/unit/switch_core_codec.c index 61a70314a4..2c499e1314 100644 --- a/tests/unit/switch_core_codec.c +++ b/tests/unit/switch_core_codec.c @@ -127,6 +127,32 @@ FST_CORE_BEGIN("./conf") } FST_TEST_END() + + FST_TEST_BEGIN(test_mod_opus_switch_status_false) + { + signed char outbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 }; + uint32_t decoded_len = 0; + uint32_t decoded_rate = 48000; + unsigned int flags = 0; + switch_codec_t orig_codec = { 0 }; + switch_status_t status; + switch_codec_settings_t codec_settings = { { 0 } }; + status = switch_core_codec_init(&orig_codec, + "OPUS", + "mod_opus", + NULL, + 48000, + 20, + 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + status = switch_core_codec_decode(&orig_codec, NULL, "test", 5, 48000, outbuf, &decoded_len, &decoded_rate, &flags); + fst_check_int_equals(status, SWITCH_STATUS_FALSE); + switch_core_codec_destroy(&orig_codec); + } + FST_TEST_END() + } FST_SUITE_END() } diff --git a/tests/unit/test_switch_core_codec.2017.vcxproj b/tests/unit/test_switch_core_codec.2017.vcxproj new file mode 100644 index 0000000000..1434d80475 --- /dev/null +++ b/tests/unit/test_switch_core_codec.2017.vcxproj @@ -0,0 +1,205 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + test_switch_core_codec + test_switch_core_codec + Win32Proj + 10.0.17134.0 + {589A07E7-5DE5-49FD-A62C-27795B806AFB} + + + + Application + MultiByte + $(DefaultPlatformToolset) + + + Application + MultiByte + $(DefaultPlatformToolset) + + + Application + MultiByte + $(DefaultPlatformToolset) + + + Application + MultiByte + $(DefaultPlatformToolset) + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(PlatformName)\$(Configuration)\ + $(PlatformName)\$(Configuration)\$(ProjectName)\ + false + $(SolutionDir)$(PlatformName)\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + false + $(SolutionDir)$(PlatformName)\$(Configuration)\ + $(PlatformName)\$(Configuration)\$(ProjectName)\ + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + false + + + + $(SolutionDir)src\include;%(AdditionalIncludeDirectories) + SWITCH_TEST_BASE_DIR_FOR_CONF="..\\..\\tests\\unit\\";%(PreprocessorDefinitions) + + + + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + ProgramDatabase + true + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + true + Console + true + + + MachineX86 + + + + + + X64 + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + ProgramDatabase + true + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + true + Console + true + + + MachineX64 + + + + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Level4 + ProgramDatabase + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + false + Console + true + true + true + + + MachineX86 + + + + + + X64 + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Level4 + ProgramDatabase + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + false + Console + true + true + true + + + MachineX64 + + + + + + + + {202d7a4e-760d-4d0e-afa1-d7459ced30ff} + false + + + + + + \ No newline at end of file From eb5476ff6659035f3bd180354f37968797a4a557 Mon Sep 17 00:00:00 2001 From: s3rj1k Date: Thu, 15 Feb 2024 18:51:46 +0100 Subject: [PATCH 120/123] [build] Split `create_dsc` and `create-orig` functions in `util.sh`. --- debian/util.sh | 140 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 26 deletions(-) diff --git a/debian/util.sh b/debian/util.sh index 110e6d8763..bc11f0bac1 100755 --- a/debian/util.sh +++ b/debian/util.sh @@ -135,50 +135,94 @@ get_nightly_revision_human () { echo "git $(git rev-list -n1 --abbrev=7 --abbrev-commit HEAD) $(date -u '+%Y-%m-%d %H:%M:%SZ')" } -create_orig () { +prep_create_orig () { { set -e + local OPTIND OPTARG - local uver="" hrev="" bundle_deps=true modules_list="" zl=9e + local uver="" hrev="" bundle_deps=true + while getopts 'bm:nv:z:' o "$@"; do case "$o" in - m) modules_list="$OPTARG";; + b) ;; + m) ;; n) uver="nightly";; v) uver="$OPTARG";; - z) zl="$OPTARG";; + z) ;; esac done shift $(($OPTIND-1)) + if [ -z "$uver" ] || [ "$uver" = "nightly" ]; then uver="$(get_nightly_version)" hrev="$(get_nightly_revision_human)" fi - local treeish="$1" dver="$(mk_dver "$uver")" - local orig="../freeswitch_$dver~$(lsb_release -sc).orig.tar.xz" + + local treeish="$1" [ -n "$treeish" ] || treeish="HEAD" + check_repo_clean git reset --hard "$treeish" + + if $bundle_deps; then + (cd libs && getlibs) + fi + + ./build/set-fs-version.sh "$uver" "$hrev" # ToDo: Handle empty $hrev + + echo "$uver" > .version + } 1>&2 + echo "$uver" +} + +create_orig () { + { + set -e + + local OPTIND OPTARG + local bundle_deps=true modules_list="" zl=9e + + local uver="$(prep_create_orig "$@")" + + while getopts 'bm:nv:z:' o "$@"; do + case "$o" in + b) ;; + m) modules_list="$OPTARG";; + n) ;; + v) ;; + z) zl="$OPTARG";; + esac + done + shift $(($OPTIND-1)) + + local dver="$(mk_dver "$uver")" + local orig="../freeswitch_$dver~$(lsb_release -sc).orig.tar.xz" + mv .gitattributes .gitattributes.orig + local -a args=(-e '\bdebian-ignore\b') test "$modules_list" = "non-dfsg" || args+=(-e '\bdfsg-nonfree\b') grep .gitattributes.orig "${args[@]}" \ | while xread l; do echo "$l export-ignore" >> .gitattributes done + if $bundle_deps; then - (cd libs && getlibs) git add -f libs fi - ./build/set-fs-version.sh "$uver" "$hrev" && git add configure.ac - echo "$uver" > .version && git add -f .version + + git add -f configure.ac .version git commit --allow-empty -m "nightly v$uver" + git archive -v \ --worktree-attributes \ --format=tar \ --prefix=freeswitch-$uver/ \ HEAD \ | xz -c -${zl}v > $orig + mv .gitattributes.orig .gitattributes + git reset --hard HEAD^ && git clean -fdx } 1>&2 echo $orig @@ -190,11 +234,12 @@ applications/mod_commands EOF } -create_dsc () { +prep_create_dsc () { { set -e - local OPTIND OPTARG modules_conf="" modules_list="" speed="normal" suite_postfix="" suite_postfix_p=false zl=9 - local modules_add="" + + local OPTIND OPTARG modules_conf="" modules_add="" modules_list="" speed="normal" + while getopts 'a:f:m:p:s:u:z:' o "$@"; do case "$o" in a) avoid_mods_arch="$OPTARG";; @@ -202,46 +247,87 @@ create_dsc () { m) modules_list="$OPTARG";; p) modules_add="$modules_add $OPTARG";; s) speed="$OPTARG";; - u) suite_postfix="$OPTARG"; suite_postfix_p=true;; - z) zl="$OPTARG";; + u) ;; + z) ;; esac done shift $(($OPTIND-1)) - local distro="$(find_distro $1)" orig="$2" - local suite="$(find_suite $distro)" - local orig_ver="$(echo "$orig" | sed -e 's/^.*_//' -e 's/\.orig\.tar.*$//')" - local dver="${orig_ver}-1~${distro}+1" - $suite_postfix_p && { suite="${distro}${suite_postfix}"; } - [ -x "$(which dch)" ] \ - || err "package devscripts isn't installed" + + local distro="$(find_distro $1)" + if [ -n "$modules_conf" ]; then cp $modules_conf debian/modules.conf fi + local bootstrap_args="" + if [ -n "$modules_list" ]; then if [ "$modules_list" = "non-dfsg" ]; then bootstrap_args="-mnon-dfsg" - else set_modules_${modules_list}; fi + else + set_modules_${modules_list} + fi fi + if test -n "$modules_add"; then for x in $modules_add; do bootstrap_args="$bootstrap_args -p${x}" done fi + (cd debian && ./bootstrap.sh -a "$avoid_mods_arch" -c $distro $bootstrap_args) + case "$speed" in paranoid) sed -i ./debian/rules \ -e '/\.stamp-bootstrap:/{:l2 n; /\.\/bootstrap.sh -j/{s/ -j//; :l3 n; b l3}; b l2};' ;; reckless) sed -i ./debian/rules \ -e '/\.stamp-build:/{:l2 n; /make/{s/$/ -j/; :l3 n; b l3}; b l2};' ;; esac + } 1>&2 +} + +create_dsc () { + { + set -e + + prep_create_dsc "$@" + + local OPTIND OPTARG suite_postfix="" suite_postfix_p=false zl=9 + + while getopts 'a:f:m:p:s:u:z:' o "$@"; do + case "$o" in + a) ;; + f) ;; + m) ;; + p) ;; + s) ;; + u) suite_postfix="$OPTARG"; suite_postfix_p=true;; + z) zl="$OPTARG";; + esac + done + shift $(($OPTIND-1)) + + local distro="$(find_distro $1)" orig="$2" + local suite="$(find_suite $distro)" + local orig_ver="$(echo "$orig" | sed -e 's/^.*_//' -e 's/\.orig\.tar.*$//')" + local dver="${orig_ver}-1~${distro}+1" + + $suite_postfix_p && { suite="${distro}${suite_postfix}"; } + + [ -x "$(which dch)" ] \ + || err "package devscripts isn't installed" + [ "$zl" -ge "1" ] || zl=1 - git add debian/rules + dch -b -m -v "$dver" --force-distribution -D "$suite" "Nightly build." - git add debian/changelog && git commit -m "nightly v$orig_ver" + + git add debian/rules debian/changelog && git commit -m "nightly v$orig_ver" + dpkg-source -i.* -Zxz -z${zl} -b . dpkg-genchanges -S > ../$(dsc_base)_source.changes + local dsc="../$(dsc_base).dsc" + git reset --hard HEAD^ && git clean -fdx } 1>&2 echo $dsc @@ -588,7 +674,7 @@ commands: create-dbg-pkgs - create-dsc + create-dsc (same for 'prep-create-dsc') -f Build only modules listed in this file @@ -602,7 +688,7 @@ commands: Specify a custom suite postfix -z Set compression level - create-orig + create-orig (same for 'prep_create_orig') -m [ quicktest | non-dfsg ] Choose custom list of modules to build @@ -629,7 +715,9 @@ case "$cmd" in build-all) build_all "$@" ;; build-debs) build_debs "$@" ;; create-dbg-pkgs) create_dbg_pkgs ;; + prep-create-dsc) prep_create_dsc "$@" ;; create-dsc) create_dsc "$@" ;; + prep-create-orig) prep_create_orig "$@" ;; create-orig) create_orig "$@" ;; *) usage ;; esac From 70d76bcc0e9970f1d0f49d16413f3e061735d87f Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 21 Feb 2024 21:27:35 +0300 Subject: [PATCH 121/123] [Core] Remove mod_kazoo from tree --- build/modules.conf.in | 1 - build/modules.conf.most | 1 - conf/vanilla/autoload_configs/kazoo.conf.xml | 215 --- configure.ac | 1 - debian/bootstrap.sh | 2 - debian/control-modules | 6 - freeswitch.spec | 16 +- src/mod/event_handlers/mod_kazoo/Makefile.am | 37 - .../event_handlers/mod_kazoo/kazoo.conf.xml | 1275 ------------- src/mod/event_handlers/mod_kazoo/kazoo_api.c | 573 ------ src/mod/event_handlers/mod_kazoo/kazoo_cdr.c | 630 ------ .../event_handlers/mod_kazoo/kazoo_commands.c | 592 ------ .../event_handlers/mod_kazoo/kazoo_config.c | 553 ------ .../event_handlers/mod_kazoo/kazoo_config.h | 63 - .../mod_kazoo/kazoo_definitions.S | 8 - src/mod/event_handlers/mod_kazoo/kazoo_defs.h | 9 - .../event_handlers/mod_kazoo/kazoo_dptools.c | 980 ---------- src/mod/event_handlers/mod_kazoo/kazoo_ei.h | 295 --- .../mod_kazoo/kazoo_ei_config.c | 708 ------- .../event_handlers/mod_kazoo/kazoo_ei_utils.c | 1089 ----------- .../mod_kazoo/kazoo_endpoints.c | 500 ----- .../mod_kazoo/kazoo_event_stream.c | 750 -------- .../mod_kazoo/kazoo_fetch_agent.c | 803 -------- .../event_handlers/mod_kazoo/kazoo_fields.h | 203 -- .../event_handlers/mod_kazoo/kazoo_message.c | 488 ----- .../event_handlers/mod_kazoo/kazoo_message.h | 66 - src/mod/event_handlers/mod_kazoo/kazoo_node.c | 1694 ----------------- .../event_handlers/mod_kazoo/kazoo_tweaks.c | 666 ------- .../event_handlers/mod_kazoo/kazoo_tweaks.h | 32 - .../event_handlers/mod_kazoo/kazoo_utils.c | 700 ------- .../event_handlers/mod_kazoo/kazoo_utils.h | 51 - src/mod/event_handlers/mod_kazoo/kz_node.c | 91 - src/mod/event_handlers/mod_kazoo/mod_kazoo.c | 152 -- src/mod/event_handlers/mod_kazoo/mod_kazoo.h | 87 - 34 files changed, 1 insertion(+), 13336 deletions(-) delete mode 100644 conf/vanilla/autoload_configs/kazoo.conf.xml delete mode 100644 src/mod/event_handlers/mod_kazoo/Makefile.am delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo.conf.xml delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_api.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_cdr.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_commands.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_config.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_config.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_definitions.S delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_defs.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_dptools.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_ei.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_ei_utils.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_endpoints.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_fetch_agent.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_fields.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_message.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_message.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_node.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_tweaks.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_tweaks.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_utils.c delete mode 100644 src/mod/event_handlers/mod_kazoo/kazoo_utils.h delete mode 100644 src/mod/event_handlers/mod_kazoo/kz_node.c delete mode 100644 src/mod/event_handlers/mod_kazoo/mod_kazoo.c delete mode 100644 src/mod/event_handlers/mod_kazoo/mod_kazoo.h diff --git a/build/modules.conf.in b/build/modules.conf.in index 7bf59e2acc..8453e290b7 100644 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -110,7 +110,6 @@ event_handlers/mod_event_socket #event_handlers/mod_json_cdr #event_handlers/mod_radius_cdr #event_handlers/mod_odbc_cdr -#event_handlers/mod_kazoo #event_handlers/mod_rayo #event_handlers/mod_smpp #event_handlers/mod_snmp diff --git a/build/modules.conf.most b/build/modules.conf.most index fbf8100a90..62595a4891 100644 --- a/build/modules.conf.most +++ b/build/modules.conf.most @@ -104,7 +104,6 @@ event_handlers/mod_event_multicast event_handlers/mod_event_socket event_handlers/mod_format_cdr event_handlers/mod_json_cdr -event_handlers/mod_kazoo #event_handlers/mod_radius_cdr event_handlers/mod_odbc_cdr event_handlers/mod_rayo diff --git a/conf/vanilla/autoload_configs/kazoo.conf.xml b/conf/vanilla/autoload_configs/kazoo.conf.xml deleted file mode 100644 index b730523d4c..0000000000 --- a/conf/vanilla/autoload_configs/kazoo.conf.xml +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - diff --git a/configure.ac b/configure.ac index e4ab33ae5c..348103f8db 100644 --- a/configure.ac +++ b/configure.ac @@ -2208,7 +2208,6 @@ AC_CONFIG_FILES([Makefile src/mod/event_handlers/mod_fail2ban/Makefile src/mod/event_handlers/mod_format_cdr/Makefile src/mod/event_handlers/mod_json_cdr/Makefile - src/mod/event_handlers/mod_kazoo/Makefile src/mod/event_handlers/mod_radius_cdr/Makefile src/mod/event_handlers/mod_odbc_cdr/Makefile src/mod/event_handlers/mod_rayo/Makefile diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index 75a8957509..aba9e38bf7 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -673,7 +673,6 @@ Depends: \${misc:Depends}, freeswitch (= \${binary:Version}), freeswitch-mod-event-multicast (= \${binary:Version}), freeswitch-mod-event-socket (= \${binary:Version}), freeswitch-mod-json-cdr (= \${binary:Version}), - freeswitch-mod-kazoo (= \${binary:Version}), freeswitch-mod-snmp (= \${binary:Version}), freeswitch-mod-local-stream (= \${binary:Version}), freeswitch-mod-native-file (= \${binary:Version}), @@ -910,7 +909,6 @@ Depends: \${misc:Depends}, freeswitch (= \${binary:Version}), freeswitch-mod-event-multicast-dbg (= \${binary:Version}), freeswitch-mod-event-socket-dbg (= \${binary:Version}), freeswitch-mod-json-cdr-dbg (= \${binary:Version}), - freeswitch-mod-kazoo-dbg (= \${binary:Version}), freeswitch-mod-snmp-dbg (= \${binary:Version}), freeswitch-mod-local-stream-dbg (= \${binary:Version}), freeswitch-mod-native-file-dbg (= \${binary:Version}), diff --git a/debian/control-modules b/debian/control-modules index 3179f8eeef..0f0784d3f5 100644 --- a/debian/control-modules +++ b/debian/control-modules @@ -542,12 +542,6 @@ Module: event_handlers/mod_json_cdr Description: mod_json_cdr Adds mod_json_cdr. -Module: event_handlers/mod_kazoo -Description: mod_kazoo - Adds mod_kazoo. -Build-Depends: erlang-dev -Depends: erlang - Module: event_handlers/mod_odbc_cdr Description: mod_odbc_cdr Adds mod_odbc_cdr. diff --git a/freeswitch.spec b/freeswitch.spec index 9e3d505e80..98ce36cb90 100644 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -952,16 +952,6 @@ Requires: %{name} = %{version}-%{release} %description event-format-cdr JSON and XML Logger for the FreeSWITCH open source telephony platform -%package kazoo -Summary: Kazoo Module for the FreeSWITCH open source telephony platform -Group: System/Libraries -Requires: %{name} = %{version}-%{release} -Requires: erlang -BuildRequires: erlang - -%description kazoo -Kazoo Module for FreeSWITCH. - %package event-multicast Summary: Multicast Event System for the FreeSWITCH open source telephony platform Group: System/Libraries @@ -1480,7 +1470,7 @@ ENDPOINTS_MODULES=" \ ###################################################################################################################### EVENT_HANDLERS_MODULES="event_handlers/mod_cdr_csv event_handlers/mod_cdr_pg_csv event_handlers/mod_cdr_sqlite \ event_handlers/mod_cdr_mongodb event_handlers/mod_format_cdr event_handlers/mod_erlang_event event_handlers/mod_event_multicast \ - event_handlers/mod_event_socket event_handlers/mod_json_cdr event_handlers/mod_kazoo event_handlers/mod_radius_cdr \ + event_handlers/mod_event_socket event_handlers/mod_json_cdr event_handlers/mod_radius_cdr \ event_handlers/mod_snmp" %if %{build_mod_rayo} EVENT_HANDLERS_MODULES+=" event_handlers/mod_rayo" @@ -1916,7 +1906,6 @@ fi %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/http_cache.conf.xml %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/ivr.conf.xml %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/java.conf.xml -%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/kazoo.conf.xml %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/lcr.conf.xml %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/local_stream.conf.xml %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/logfile.conf.xml @@ -2286,9 +2275,6 @@ fi %files event-json-cdr %{MODINSTDIR}/mod_json_cdr.so* -%files kazoo -%{MODINSTDIR}/mod_kazoo.so* - %files event-radius-cdr %{MODINSTDIR}/mod_radius_cdr.so* diff --git a/src/mod/event_handlers/mod_kazoo/Makefile.am b/src/mod/event_handlers/mod_kazoo/Makefile.am deleted file mode 100644 index 36e7a9ea4a..0000000000 --- a/src/mod/event_handlers/mod_kazoo/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -include $(top_srcdir)/build/modmake.rulesam -MODNAME=mod_kazoo - -if HAVE_ERLANG - -KAZOO_DEFS=kazoo_definitions.o - -mod_LTLIBRARIES = mod_kazoo.la -mod_kazoo_la_SOURCES = mod_kazoo.c kazoo_utils.c kazoo_dptools.c kazoo_tweaks.c -mod_kazoo_la_SOURCES += kazoo_api.c kazoo_commands.c kazoo_config.c -mod_kazoo_la_SOURCES += kazoo_message.c -mod_kazoo_la_SOURCES += kazoo_ei_config.c kazoo_ei_utils.c kazoo_event_stream.c -mod_kazoo_la_SOURCES += kazoo_fetch_agent.c kazoo_node.c -mod_kazoo_la_SOURCES += kazoo_endpoints.c -mod_kazoo_la_SOURCES += kazoo_cdr.c -mod_kazoo_la_SOURCES += kz_node.c - -mod_kazoo_la_CFLAGS = $(AM_CFLAGS) @ERLANG_CFLAGS@ -D_REENTRANT -DERLANG_VERSION=@ERLANG_VERSION@ -DERLANG_MAJOR=@ERLANG_MAJOR@ -DERLANG_MINOR=@ERLANG_MINOR@ -mod_kazoo_la_LIBADD = $(KAZOO_DEFS) $(switch_builddir)/libfreeswitch.la -mod_kazoo_la_LDFLAGS = -avoid-version -module -no-undefined -shared @ERLANG_LDFLAGS@ - -BUILT_SOURCES = $(KAZOO_DEFS) - -$(KAZOO_DEFS): kazoo.conf.xml - -.S.o: $< - @$(CC) $(CFLAGS) -o $@ -c $< - -install-exec-am: - @install `which epmd` $(DESTDIR)$(bindir)/fs_epmd - -else -install: error -all: error -error: - $(error You must install erlang to build this module) -endif diff --git a/src/mod/event_handlers/mod_kazoo/kazoo.conf.xml b/src/mod/event_handlers/mod_kazoo/kazoo.conf.xml deleted file mode 100644 index 4422af121b..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo.conf.xml +++ /dev/null @@ -1,1275 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_api.c b/src/mod/event_handlers/mod_kazoo/kazoo_api.c deleted file mode 100644 index 96f9ff7bb4..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_api.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * mod_kazoo.c -- Socket Controlled Event Handler - * - */ -#include "mod_kazoo.h" - -#define KAZOO_DESC "kazoo information" -#define KAZOO_SYNTAX " []" - -#define API_COMMAND_DISCONNECT 0 -#define API_COMMAND_REMOTE_IP 1 -#define API_COMMAND_STREAMS 2 -#define API_COMMAND_BINDINGS 3 -#define API_COMMAND_OPTION 4 - -#define API_NODE_OPTION_FRAMING 0 -#define API_NODE_OPTION_KEEPALIVE 1 -#define API_NODE_OPTION_LEGACY 2 -#define API_NODE_OPTION_MAX 99 - -static const char *node_runtime_options[] = { - "event-stream-framing", - "event-stream-keepalive", - "enable-legacy", - NULL -}; - -static int api_find_node_option(char *option) { - int i; - for(i = 0; node_runtime_options[i] != NULL; i++) { - if(!strcasecmp(option, node_runtime_options[i])) { - return i; - } - } - return API_NODE_OPTION_MAX; -} - -static switch_status_t api_get_node_option(ei_node_t *ei_node, switch_stream_handle_t *stream, char *arg) { - int option = api_find_node_option(arg); - switch_status_t ret = SWITCH_STATUS_SUCCESS; - switch (option) { - case API_NODE_OPTION_FRAMING: - stream->write_function(stream, "+OK %i", ei_node->event_stream_framing); - break; - - case API_NODE_OPTION_KEEPALIVE: - stream->write_function(stream, "+OK %i", ei_node->event_stream_keepalive); - break; - - case API_NODE_OPTION_LEGACY: - stream->write_function(stream, "+OK %s", ei_node->legacy ? "true" : "false"); - break; - - default: - stream->write_function(stream, "-ERR invalid option %s", arg); - ret = SWITCH_STATUS_NOTFOUND; - break; - } - - return ret; -} - -static switch_status_t api_set_node_option(ei_node_t *ei_node, switch_stream_handle_t *stream, char *name, char *value) { - int option = api_find_node_option(name); - short val; - switch_status_t ret = SWITCH_STATUS_SUCCESS; - switch (option) { - case API_NODE_OPTION_FRAMING: - val = atoi(value); - if (val != 1 && val != 2 && val != 4) { - stream->write_function(stream, "-ERR Invalid event stream framing value (%i)", val); - ret = SWITCH_STATUS_GENERR; - } else { - stream->write_function(stream, "+OK %i", val); - ei_node->event_stream_framing = val; - } - break; - - case API_NODE_OPTION_KEEPALIVE: - val = switch_true(value); - stream->write_function(stream, "+OK %i", val); - ei_node->event_stream_keepalive = val; - break; - - case API_NODE_OPTION_LEGACY: - ei_node->legacy = switch_true(value); - stream->write_function(stream, "+OK %s", ei_node->legacy ? "true" : "false"); - break; - - default: - stream->write_function(stream, "-ERR invalid option %s", name); - ret = SWITCH_STATUS_NOTFOUND; - break; - } - - return ret; -} - -static switch_status_t api_erlang_status(switch_stream_handle_t *stream) { - switch_sockaddr_t *sa; - uint16_t port; - char ipbuf[48]; - const char *ip_addr; - ei_node_t *ei_node; - - switch_socket_addr_get(&sa, SWITCH_FALSE, kazoo_globals.acceptor); - - port = switch_sockaddr_get_port(sa); - ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa); - - stream->write_function(stream, "Running %s\n", VERSION); - stream->write_function(stream, "Listening for new Erlang connections on %s:%u with cookie %s\n", ip_addr, port, kazoo_globals.ei_cookie); - stream->write_function(stream, "Registered as Erlang node %s, visible as %s\n", kazoo_globals.ei_cnode.thisnodename, kazoo_globals.ei_cnode.thisalivename); - - if (kazoo_globals.ei_compat_rel) { - stream->write_function(stream, "Using Erlang compatibility mode: %d\n", kazoo_globals.ei_compat_rel); - } - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - if (!ei_node) { - stream->write_function(stream, "No erlang nodes connected\n"); - } else { - stream->write_function(stream, "Connected to:\n"); - while(ei_node != NULL) { - unsigned int year, day, hour, min, sec, delta; - - delta = (switch_micro_time_now() - ei_node->created_time) / 1000000; - sec = delta % 60; - min = delta / 60 % 60; - hour = delta / 3600 % 24; - day = delta / 86400 % 7; - year = delta / 31556926 % 12; - stream->write_function(stream, " %s (%s:%d) up %d years, %d days, %d hours, %d minutes, %d seconds\n" - ,ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port, year, day, hour, min, sec); - ei_node = ei_node->next; - } - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t api_erlang_event_filter(switch_stream_handle_t *stream) { - switch_hash_index_t *hi = NULL; - int column = 0; - int idx = 0; - - for (hi = (switch_hash_index_t *)switch_core_hash_first_iter(kazoo_globals.event_filter, hi); hi; hi = switch_core_hash_next(&hi)) { - const void *key; - void *val; - switch_core_hash_this(hi, &key, NULL, &val); - stream->write_function(stream, "%-50s", (char *)key); - if (++column > 2) { - stream->write_function(stream, "\n"); - column = 0; - } - } - - if (++column > 2) { - stream->write_function(stream, "\n"); - } - - while(kazoo_globals.kazoo_var_prefixes[idx] != NULL) { - char var[100]; - char *prefix = kazoo_globals.kazoo_var_prefixes[idx]; - sprintf(var, "%s*", prefix); - stream->write_function(stream, "%-50s", var); - idx++; - } - - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t api_erlang_nodes_list(switch_stream_handle_t *stream) { - ei_node_t *ei_node; - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - stream->write_function(stream, "%s (%s)\n", ei_node->peer_nodename, ei_node->remote_ip); - ei_node = ei_node->next; - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t api_erlang_nodes_count(switch_stream_handle_t *stream) { - ei_node_t *ei_node; - int count = 0; - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - count++; - ei_node = ei_node->next; - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - stream->write_function(stream, "%d\n", count); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t api_complete_erlang_node(const char *line, const char *cursor, switch_console_callback_match_t **matches) { - switch_console_callback_match_t *my_matches = NULL; - switch_status_t status = SWITCH_STATUS_FALSE; - ei_node_t *ei_node; - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - switch_console_push_match(&my_matches, ei_node->peer_nodename); - ei_node = ei_node->next; - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - if (my_matches) { - *matches = my_matches; - status = SWITCH_STATUS_SUCCESS; - } - - return status; -} - -static switch_status_t handle_node_api_event_stream(ei_event_stream_t *event_stream, switch_stream_handle_t *stream) { - ei_event_binding_t *binding; - int column = 0; - - switch_mutex_lock(event_stream->socket_mutex); - if (event_stream->connected == SWITCH_FALSE) { - switch_sockaddr_t *sa; - uint16_t port; - char ipbuf[48] = {0}; - const char *ip_addr; - - switch_socket_addr_get(&sa, SWITCH_TRUE, event_stream->acceptor); - port = switch_sockaddr_get_port(sa); - ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa); - - if (zstr(ip_addr)) { - ip_addr = kazoo_globals.ip; - } - - stream->write_function(stream, "%s:%d -> disconnected\n" - ,ip_addr, port); - } else { - unsigned int year, day, hour, min, sec, delta; - - delta = (switch_micro_time_now() - event_stream->connected_time) / 1000000; - sec = delta % 60; - min = delta / 60 % 60; - hour = delta / 3600 % 24; - day = delta / 86400 % 7; - year = delta / 31556926 % 12; - - stream->write_function(stream, "%s:%d -> %s:%d for %d years, %d days, %d hours, %d minutes, %d seconds\n" - ,event_stream->local_ip, event_stream->local_port - ,event_stream->remote_ip, event_stream->remote_port - ,year, day, hour, min, sec); - } - - binding = event_stream->bindings; - while(binding != NULL) { - if (binding->type == SWITCH_EVENT_CUSTOM) { - stream->write_function(stream, "CUSTOM %-43s", binding->subclass_name); - } else { - stream->write_function(stream, "%-50s", switch_event_name(binding->type)); - } - - if (++column > 2) { - stream->write_function(stream, "\n"); - column = 0; - } - - binding = binding->next; - } - switch_mutex_unlock(event_stream->socket_mutex); - - if (!column) { - stream->write_function(stream, "\n"); - } else { - stream->write_function(stream, "\n\n"); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_node_api_event_streams(ei_node_t *ei_node, switch_stream_handle_t *stream) { - ei_event_stream_t *event_stream; - - switch_mutex_lock(ei_node->event_streams_mutex); - event_stream = ei_node->event_streams; - while(event_stream != NULL) { - handle_node_api_event_stream(event_stream, stream); - event_stream = event_stream->next; - } - switch_mutex_unlock(ei_node->event_streams_mutex); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_node_api_command(ei_node_t *ei_node, switch_stream_handle_t *stream, uint32_t command) { - unsigned int year, day, hour, min, sec, delta; - - switch (command) { - case API_COMMAND_DISCONNECT: - stream->write_function(stream, "Disconnecting erlang node %s at managers request\n", ei_node->peer_nodename); - switch_clear_flag(ei_node, LFLAG_RUNNING); - break; - case API_COMMAND_REMOTE_IP: - delta = (switch_micro_time_now() - ei_node->created_time) / 1000000; - sec = delta % 60; - min = delta / 60 % 60; - hour = delta / 3600 % 24; - day = delta / 86400 % 7; - year = delta / 31556926 % 12; - - stream->write_function(stream, "Uptime %d years, %d days, %d hours, %d minutes, %d seconds\n", year, day, hour, min, sec); - stream->write_function(stream, "Local Address %s:%d\n", ei_node->local_ip, ei_node->local_port); - stream->write_function(stream, "Remote Address %s:%d\n", ei_node->remote_ip, ei_node->remote_port); - break; - case API_COMMAND_STREAMS: - handle_node_api_event_streams(ei_node, stream); - break; - case API_COMMAND_BINDINGS: - handle_api_command_streams(ei_node, stream); - break; - default: - break; - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t api_erlang_node_command(switch_stream_handle_t *stream, const char *nodename, uint32_t command) { - ei_node_t *ei_node; - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - int length = strlen(ei_node->peer_nodename); - - if (!strncmp(ei_node->peer_nodename, nodename, length)) { - handle_node_api_command(ei_node, stream, command); - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - return SWITCH_STATUS_SUCCESS; - } - - ei_node = ei_node->next; - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return SWITCH_STATUS_NOTFOUND; -} - -static switch_status_t handle_node_api_command_arg(ei_node_t *ei_node, switch_stream_handle_t *stream, uint32_t command, char *arg) { - - switch (command) { - case API_COMMAND_OPTION: - return api_get_node_option(ei_node, stream, arg); - break; - default: - break; - } - - return SWITCH_STATUS_NOTFOUND; -} - -static switch_status_t handle_node_api_command_args(ei_node_t *ei_node, switch_stream_handle_t *stream, uint32_t command, int argc, char *argv[]) { - - switch (command) { - case API_COMMAND_OPTION: - return api_set_node_option(ei_node, stream, argv[0], argv[1]); - break; - default: - break; - } - - return SWITCH_STATUS_NOTFOUND; -} - -static switch_status_t api_erlang_node_command_arg(switch_stream_handle_t *stream, const char *nodename, uint32_t command, char *arg) { - ei_node_t *ei_node; - switch_status_t ret = SWITCH_STATUS_NOTFOUND; - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - int length = strlen(ei_node->peer_nodename); - - if (!strncmp(ei_node->peer_nodename, nodename, length)) { - ret = handle_node_api_command_arg(ei_node, stream, command, arg); - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - return ret ; - } - - ei_node = ei_node->next; - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return ret; -} - -static switch_status_t api_erlang_node_command_args(switch_stream_handle_t *stream, const char *nodename, uint32_t command, int argc, char *argv[]) { - ei_node_t *ei_node; - switch_status_t ret = SWITCH_STATUS_NOTFOUND; - - switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock); - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - int length = strlen(ei_node->peer_nodename); - - if (!strncmp(ei_node->peer_nodename, nodename, length)) { - ret = handle_node_api_command_args(ei_node, stream, command, argc, argv); - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - return ret; - } - - ei_node = ei_node->next; - } - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return ret; -} - -SWITCH_STANDARD_API(exec_api_cmd) -{ - char *argv[1024] = { 0 }; - int unknown_command = 1, argc = 0; - char *mycmd = NULL; - - const char *usage_string = "USAGE:\n" - "--------------------------------------------------------------------------------------------------------------------\n" - "erlang status - provides an overview of the current status\n" - "erlang event_filter - lists the event headers that will be sent to Erlang nodes\n" - "erlang nodes list - lists connected Erlang nodes (usefull for monitoring tools)\n" - "erlang nodes count - provides a count of connected Erlang nodes (usefull for monitoring tools)\n" - "erlang node disconnect - disconnects an Erlang node\n" - "erlang node connection - Shows the connection info\n" - "erlang node event_streams - lists the event streams for an Erlang node\n" - "erlang node fetch_bindings - lists the XML fetch bindings for an Erlang node\n" - "---------------------------------------------------------------------------------------------------------------------\n"; - - if (zstr(cmd)) { - stream->write_function(stream, "%s", usage_string); - return SWITCH_STATUS_SUCCESS; - } - - if (!(mycmd = strdup(cmd))) { - return SWITCH_STATUS_MEMERR; - } - - if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { - stream->write_function(stream, "%s", usage_string); - switch_safe_free(mycmd); - return SWITCH_STATUS_SUCCESS; - } - - if (zstr(argv[0])) { - stream->write_function(stream, "%s", usage_string); - switch_safe_free(mycmd); - return SWITCH_STATUS_SUCCESS; - } - - if (!strncmp(argv[0], "status", 7)) { - unknown_command = 0; - api_erlang_status(stream); - } else if (!strncmp(argv[0], "event_filter", 13)) { - unknown_command = 0; - api_erlang_event_filter(stream); - } else if (!strncmp(argv[0], "nodes", 6) && !zstr(argv[1])) { - if (!strncmp(argv[1], "list", 6)) { - unknown_command = 0; - api_erlang_nodes_list(stream); - } else if (!strncmp(argv[1], "count", 6)) { - unknown_command = 0; - api_erlang_nodes_count(stream); - } - } else if (!strncmp(argv[0], "node", 6) && !zstr(argv[1]) && !zstr(argv[2])) { - if (!strncmp(argv[2], "disconnect", 11)) { - unknown_command = 0; - api_erlang_node_command(stream, argv[1], API_COMMAND_DISCONNECT); - } else if (!strncmp(argv[2], "connection", 11)) { - unknown_command = 0; - api_erlang_node_command(stream, argv[1], API_COMMAND_REMOTE_IP); - } else if (!strncmp(argv[2], "event_streams", 14)) { - unknown_command = 0; - api_erlang_node_command(stream, argv[1], API_COMMAND_STREAMS); - } else if (!strncmp(argv[2], "fetch_bindings", 15)) { - unknown_command = 0; - api_erlang_node_command(stream, argv[1], API_COMMAND_BINDINGS); - } else if (!strncmp(argv[2], "option", 7) && !zstr(argv[3])) { - unknown_command = 0; - if(argc > 4 && !zstr(argv[4])) - api_erlang_node_command_args(stream, argv[1], API_COMMAND_OPTION, argc - 3, &argv[3]); - else - api_erlang_node_command_arg(stream, argv[1], API_COMMAND_OPTION, argv[3]); - } - } - - if (unknown_command) { - stream->write_function(stream, "%s", usage_string); - } - - switch_safe_free(mycmd); - return SWITCH_STATUS_SUCCESS; -} - -void add_cli_api(switch_loadable_module_interface_t **module_interface) -{ - switch_api_interface_t *api_interface = NULL; - SWITCH_ADD_API(api_interface, "erlang", KAZOO_DESC, exec_api_cmd, KAZOO_SYNTAX); - switch_console_set_complete("add erlang status"); - switch_console_set_complete("add erlang event_filter"); - switch_console_set_complete("add erlang nodes list"); - switch_console_set_complete("add erlang nodes count"); - switch_console_set_complete("add erlang node ::erlang::node disconnect"); - switch_console_set_complete("add erlang node ::erlang::node connection"); - switch_console_set_complete("add erlang node ::erlang::node event_streams"); - switch_console_set_complete("add erlang node ::erlang::node fetch_bindings"); - switch_console_add_complete_func("::erlang::node", api_complete_erlang_node); - -} - -void remove_cli_api() -{ - switch_console_set_complete("del erlang"); - switch_console_del_complete_func("::erlang::node"); - -} - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c b/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c deleted file mode 100644 index fef66f8be3..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c +++ /dev/null @@ -1,630 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Luis Azedo - * - * mod_hacks.c -- hacks with state handlers - * - */ -#include "mod_kazoo.h" - -#define MY_EVENT_JSON_CDR "KZ_CDR" - -#define maybe_add_json_string(_json, _name, _string) \ - if (!zstr(_string)) cJSON_AddItemToObject(_json, _name, cJSON_CreateString((char *)_string)) - -static void kz_switch_ivr_set_json_profile_data(cJSON *json, switch_caller_profile_t *caller_profile) -{ - cJSON *soft = NULL; - profile_node_t *pn = NULL; - - maybe_add_json_string(json, "Username", caller_profile->username); - maybe_add_json_string(json, "Dialplan", caller_profile->dialplan); - maybe_add_json_string(json, "ANI", caller_profile->ani); - maybe_add_json_string(json, "ANIII", caller_profile->aniii); - maybe_add_json_string(json, "Caller-ID-Name", caller_profile->caller_id_name); - maybe_add_json_string(json, "Caller-ID-Number", caller_profile->caller_id_number); - maybe_add_json_string(json, "Caller-ID-Original-Name", caller_profile->orig_caller_id_name); - maybe_add_json_string(json, "Caller-ID-Original-Number", caller_profile->orig_caller_id_number); - maybe_add_json_string(json, "Network-Address", caller_profile->network_addr); - maybe_add_json_string(json, "RDNIS", caller_profile->rdnis); - maybe_add_json_string(json, "Destination-Number", caller_profile->destination_number); - maybe_add_json_string(json, "Callee-ID-Name", caller_profile->callee_id_name); - maybe_add_json_string(json, "Callee-ID-Number", caller_profile->callee_id_number); - maybe_add_json_string(json, "UUID", caller_profile->uuid); - maybe_add_json_string(json, "Source", caller_profile->source); - maybe_add_json_string(json, "Context", caller_profile->context); - maybe_add_json_string(json, "Channel-Name", caller_profile->chan_name); - maybe_add_json_string(json, "Profile-UUID", caller_profile->uuid_str); - maybe_add_json_string(json, "Profile-Clone-Of", caller_profile->clone_of); - maybe_add_json_string(json, "Transfer-Source", caller_profile->transfer_source); - cJSON_AddItemToObject(json, "Direction", cJSON_CreateString(caller_profile->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound")); - cJSON_AddItemToObject(json, "Logical-Direction", cJSON_CreateString(caller_profile->logical_direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound")); - - soft = cJSON_CreateObject(); - for (pn = caller_profile->soft; pn; pn = pn->next) { - maybe_add_json_string(soft, pn->var, pn->val); - } - - cJSON_AddItemToObject(json, "Directory", soft); -} - -SWITCH_DECLARE(void) kz_switch_ivr_set_json_call_flaws(cJSON *json, switch_core_session_t *session, switch_media_type_t type) -{ - const char *name = (type == SWITCH_MEDIA_TYPE_VIDEO) ? "Video" : "Audio"; - cJSON *j_stat; - switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL); - - if (!stats) return; - - if (!stats->inbound.error_log && !stats->outbound.error_log) return; - - j_stat = cJSON_CreateObject(); - cJSON_AddItemToObject(json, name, j_stat); - - if (stats->inbound.error_log) { - cJSON *j_err_log, *j_err, *j_in; - switch_error_period_t *ep; - - j_in = cJSON_CreateObject(); - cJSON_AddItemToObject(j_stat, "Inbound", j_in); - - j_err_log = cJSON_CreateArray(); - cJSON_AddItemToObject(j_in, "Error-Log", j_err_log); - - for(ep = stats->inbound.error_log; ep; ep = ep->next) { - - if (!(ep->start && ep->stop)) continue; - - j_err = cJSON_CreateObject(); - - cJSON_AddItemToObject(j_err, "Start", cJSON_CreateNumber(ep->start)); - cJSON_AddItemToObject(j_err, "Stop", cJSON_CreateNumber(ep->stop)); - cJSON_AddItemToObject(j_err, "Flaws", cJSON_CreateNumber(ep->flaws)); - cJSON_AddItemToObject(j_err, "Consecutive-Flaws", cJSON_CreateNumber(ep->consecutive_flaws)); - cJSON_AddItemToObject(j_err, "Duration-MS", cJSON_CreateNumber((ep->stop - ep->start) / 1000)); - cJSON_AddItemToArray(j_err_log, j_err); - } - } - - if (stats->outbound.error_log) { - cJSON *j_err_log, *j_err, *j_out; - switch_error_period_t *ep; - - j_out = cJSON_CreateObject(); - cJSON_AddItemToObject(j_stat, "Outbound", j_out); - - j_err_log = cJSON_CreateArray(); - cJSON_AddItemToObject(j_out, "Error-Log", j_err_log); - - for(ep = stats->outbound.error_log; ep; ep = ep->next) { - - if (!(ep->start && ep->stop)) continue; - - j_err = cJSON_CreateObject(); - - cJSON_AddItemToObject(j_err, "Start", cJSON_CreateNumber(ep->start)); - cJSON_AddItemToObject(j_err, "Stop", cJSON_CreateNumber(ep->stop)); - cJSON_AddItemToObject(j_err, "Flaws", cJSON_CreateNumber(ep->flaws)); - cJSON_AddItemToObject(j_err, "Consecutive-Flaws", cJSON_CreateNumber(ep->consecutive_flaws)); - cJSON_AddItemToObject(j_err, "Duration-MS", cJSON_CreateNumber((ep->stop - ep->start) / 1000)); - cJSON_AddItemToArray(j_err_log, j_err); - } - } -} - -#define add_jstat(_j, _i, _s) \ - switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \ - cJSON_AddItemToObject(_j, _s, cJSON_CreateNumber(_i)) - -SWITCH_DECLARE(void) kz_switch_ivr_set_json_call_stats(cJSON *json, switch_core_session_t *session, switch_media_type_t type) -{ - const char *name = (type == SWITCH_MEDIA_TYPE_VIDEO) ? "Video" : "Audio"; - cJSON *j_stat, *j_in, *j_out; - switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL); - char var_val[35] = ""; - - if (!stats) return; - - j_stat = cJSON_CreateObject(); - j_in = cJSON_CreateObject(); - j_out = cJSON_CreateObject(); - - cJSON_AddItemToObject(json, name, j_stat); - cJSON_AddItemToObject(j_stat, "Inbound", j_in); - cJSON_AddItemToObject(j_stat, "Outbound", j_out); - - stats->inbound.std_deviation = sqrt(stats->inbound.variance); - - add_jstat(j_in, stats->inbound.raw_bytes, "Raw-Bytes"); - add_jstat(j_in, stats->inbound.media_bytes, "Media-Bytes"); - add_jstat(j_in, stats->inbound.packet_count, "Packet-Count"); - add_jstat(j_in, stats->inbound.media_packet_count, "Media-Packet-Count"); - add_jstat(j_in, stats->inbound.skip_packet_count, "Skip-Packet-Count"); - add_jstat(j_in, stats->inbound.jb_packet_count, "Jitter-Packet-Count"); - add_jstat(j_in, stats->inbound.dtmf_packet_count, "DTMF-Packet-Count"); - add_jstat(j_in, stats->inbound.cng_packet_count, "CNG-Packet-Count"); - add_jstat(j_in, stats->inbound.flush_packet_count, "Flush-Packet-Count"); - add_jstat(j_in, stats->inbound.largest_jb_size, "Largest-JB-Size"); - add_jstat(j_in, stats->inbound.min_variance, "Jitter-Min-Variance"); - add_jstat(j_in, stats->inbound.max_variance, "Jitter-Max-Variance"); - add_jstat(j_in, stats->inbound.lossrate, "Jitter-Loss-Rate"); - add_jstat(j_in, stats->inbound.burstrate, "Jitter-Burst-Rate"); - add_jstat(j_in, stats->inbound.mean_interval, "Mean-Interval"); - add_jstat(j_in, stats->inbound.flaws, "Flaw-Total"); - add_jstat(j_in, stats->inbound.R, "Quality-Percentage"); - add_jstat(j_in, stats->inbound.mos, "MOS"); - - - add_jstat(j_out, stats->outbound.raw_bytes, "Raw-Bytes"); - add_jstat(j_out, stats->outbound.media_bytes, "Media-Bytes"); - add_jstat(j_out, stats->outbound.packet_count, "Packet-Count"); - add_jstat(j_out, stats->outbound.media_packet_count, "Media-Packet-Count"); - add_jstat(j_out, stats->outbound.skip_packet_count, "Skip-Packet-Count"); - add_jstat(j_out, stats->outbound.dtmf_packet_count, "DTMF-Packet-Count"); - add_jstat(j_out, stats->outbound.cng_packet_count, "CNG-Packet-Count"); - add_jstat(j_out, stats->rtcp.packet_count, "RTCP-Packet-Count"); - add_jstat(j_out, stats->rtcp.octet_count, "RTCP-Octet-Count"); -} - -static switch_status_t kz_report_channel_flaws(switch_core_session_t *session, switch_event_t *cdr_event) -{ - cJSON *callStats = cJSON_CreateObject(); - - kz_switch_ivr_set_json_call_flaws(callStats, session, SWITCH_MEDIA_TYPE_AUDIO); - kz_switch_ivr_set_json_call_flaws(callStats, session, SWITCH_MEDIA_TYPE_VIDEO); - - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_channel_media_errors", cJSON_PrintUnformatted(callStats)); - - cJSON_Delete(callStats); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t kz_report_channel_stats(switch_core_session_t *session, switch_event_t *cdr_event) -{ - cJSON *callStats = cJSON_CreateObject(); - - kz_switch_ivr_set_json_call_stats(callStats, session, SWITCH_MEDIA_TYPE_AUDIO); - kz_switch_ivr_set_json_call_stats(callStats, session, SWITCH_MEDIA_TYPE_VIDEO); - - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_channel_stats", cJSON_PrintUnformatted(callStats)); - - cJSON_Delete(callStats); - - return SWITCH_STATUS_SUCCESS; - -} - -static switch_status_t kz_report_app_log(switch_core_session_t *session, switch_event_t *cdr_event) -{ - switch_app_log_t *ap, *app_log = switch_core_session_get_app_log(session); - cJSON *j_apps = NULL; - - if (!app_log) { - return SWITCH_STATUS_FALSE; - } - - j_apps = cJSON_CreateArray(); - - for (ap = app_log; ap; ap = ap->next) { - cJSON *j_application = cJSON_CreateObject(); - cJSON_AddItemToObject(j_application, "app_name", cJSON_CreateString(ap->app)); - cJSON_AddItemToObject(j_application, "app_data", cJSON_CreateString(ap->arg)); - cJSON_AddItemToObject(j_application, "app_stamp", cJSON_CreateNumber(ap->stamp)); - cJSON_AddItemToArray(j_apps, j_application); - } - - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_application_log", cJSON_PrintUnformatted(j_apps)); - - cJSON_Delete(j_apps); - - return SWITCH_STATUS_SUCCESS; - -} - -static switch_status_t kz_report_callflow_extension(switch_caller_profile_t *caller_profile, cJSON *j_profile) -{ - cJSON *j_caller_extension, *j_caller_extension_apps, *j_application, *j_inner_extension; - if (caller_profile->caller_extension) { - switch_caller_application_t *ap; - - j_caller_extension = cJSON_CreateObject(); - j_caller_extension_apps = cJSON_CreateArray(); - - cJSON_AddItemToObject(j_profile, "extension", j_caller_extension); - - cJSON_AddItemToObject(j_caller_extension, "name", cJSON_CreateString(caller_profile->caller_extension->extension_name)); - cJSON_AddItemToObject(j_caller_extension, "number", cJSON_CreateString(caller_profile->caller_extension->extension_number)); - cJSON_AddItemToObject(j_caller_extension, "applications", j_caller_extension_apps); - - if (caller_profile->caller_extension->current_application) { - cJSON_AddItemToObject(j_caller_extension, "current_app", cJSON_CreateString(caller_profile->caller_extension->current_application->application_name)); - } - - for (ap = caller_profile->caller_extension->applications; ap; ap = ap->next) { - j_application = cJSON_CreateObject(); - - cJSON_AddItemToArray(j_caller_extension_apps, j_application); - - if (ap == caller_profile->caller_extension->current_application) { - cJSON_AddItemToObject(j_application, "last_executed", cJSON_CreateString("true")); - } - cJSON_AddItemToObject(j_application, "app_name", cJSON_CreateString(ap->application_name)); - cJSON_AddItemToObject(j_application, "app_data", cJSON_CreateString(switch_str_nil(ap->application_data))); - } - - if (caller_profile->caller_extension->children) { - switch_caller_profile_t *cp = NULL; - j_inner_extension = cJSON_CreateArray(); - cJSON_AddItemToObject(j_caller_extension, "sub_extensions", j_inner_extension); - for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) { - - if (!cp->caller_extension) { - continue; - } - - j_caller_extension = cJSON_CreateObject(); - cJSON_AddItemToArray(j_inner_extension, j_caller_extension); - - cJSON_AddItemToObject(j_caller_extension, "name", cJSON_CreateString(cp->caller_extension->extension_name)); - cJSON_AddItemToObject(j_caller_extension, "number", cJSON_CreateString(cp->caller_extension->extension_number)); - - cJSON_AddItemToObject(j_caller_extension, "dialplan", cJSON_CreateString((char *)cp->dialplan)); - - if (cp->caller_extension->current_application) { - cJSON_AddItemToObject(j_caller_extension, "current_app", cJSON_CreateString(cp->caller_extension->current_application->application_name)); - } - - j_caller_extension_apps = cJSON_CreateArray(); - cJSON_AddItemToObject(j_caller_extension, "applications", j_caller_extension_apps); - for (ap = cp->caller_extension->applications; ap; ap = ap->next) { - j_application = cJSON_CreateObject(); - cJSON_AddItemToArray(j_caller_extension_apps, j_application); - - if (ap == cp->caller_extension->current_application) { - cJSON_AddItemToObject(j_application, "last_executed", cJSON_CreateString("true")); - } - cJSON_AddItemToObject(j_application, "app_name", cJSON_CreateString(ap->application_name)); - cJSON_AddItemToObject(j_application, "app_data", cJSON_CreateString(switch_str_nil(ap->application_data))); - } - } - } - } - - return SWITCH_STATUS_SUCCESS; - -} - -static switch_status_t kz_report_callflow(switch_core_session_t *session, switch_event_t *cdr_event) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_caller_profile_t *caller_profile; - cJSON *j_main_cp, *j_times, *j_callflow, *j_profile, *j_o; - - - caller_profile = switch_channel_get_caller_profile(channel); - - j_callflow = cJSON_CreateArray(); - - while (caller_profile) { - - j_profile = cJSON_CreateObject(); - - if (!zstr(caller_profile->dialplan)) { - cJSON_AddItemToObject(j_profile, "dialplan", cJSON_CreateString((char *)caller_profile->dialplan)); - } - - if (!zstr(caller_profile->profile_index)) { - cJSON_AddItemToObject(j_profile, "profile_index", cJSON_CreateString((char *)caller_profile->profile_index)); - } - - kz_report_callflow_extension(caller_profile, j_profile); - - j_main_cp = cJSON_CreateObject(); - cJSON_AddItemToObject(j_profile, "Caller-Profile", j_main_cp); - - kz_switch_ivr_set_json_profile_data(j_main_cp, caller_profile); - - if (caller_profile->originator_caller_profile) { - j_o = cJSON_CreateObject(); - cJSON_AddItemToObject(j_main_cp, "originator", j_o); - kz_switch_ivr_set_json_profile_data(j_o, caller_profile->originator_caller_profile); - kz_report_callflow_extension(caller_profile->originator_caller_profile, j_o); - } - - if (caller_profile->originatee_caller_profile) { - j_o = cJSON_CreateObject(); - cJSON_AddItemToObject(j_main_cp, "originatee", j_o); - kz_switch_ivr_set_json_profile_data(j_o, caller_profile->originatee_caller_profile); - kz_report_callflow_extension(caller_profile->originatee_caller_profile, j_o); - } - - if (caller_profile->times) { - j_times = cJSON_CreateObject(); - cJSON_AddItemToObject(j_profile, "Time", j_times); - cJSON_AddItemToObject(j_times, "Created", cJSON_CreateNumber(caller_profile->times->created)); - cJSON_AddItemToObject(j_times, "Profile-Created", cJSON_CreateNumber(caller_profile->times->profile_created)); - cJSON_AddItemToObject(j_times, "Progress", cJSON_CreateNumber(caller_profile->times->progress)); - cJSON_AddItemToObject(j_times, "Progress-Media", cJSON_CreateNumber(caller_profile->times->progress_media)); - cJSON_AddItemToObject(j_times, "Answered", cJSON_CreateNumber(caller_profile->times->answered)); - cJSON_AddItemToObject(j_times, "Bridged", cJSON_CreateNumber(caller_profile->times->bridged)); - cJSON_AddItemToObject(j_times, "Last-Hold", cJSON_CreateNumber(caller_profile->times->last_hold)); - cJSON_AddItemToObject(j_times, "Hold-Accumulated", cJSON_CreateNumber(caller_profile->times->hold_accum)); - cJSON_AddItemToObject(j_times, "Hangup", cJSON_CreateNumber(caller_profile->times->hungup)); - cJSON_AddItemToObject(j_times, "Resurrect", cJSON_CreateNumber(caller_profile->times->resurrected)); - cJSON_AddItemToObject(j_times, "Transfer", cJSON_CreateNumber(caller_profile->times->transferred)); - } - cJSON_AddItemToArray(j_callflow, j_profile); - caller_profile = caller_profile->next; - } - - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_callflow", cJSON_PrintUnformatted(j_callflow)); - - cJSON_Delete(j_callflow); - - - return SWITCH_STATUS_SUCCESS; - -} - - -#define ORIGINATED_LEGS_VARIABLE "originated_legs" -#define ORIGINATED_LEGS_ITEM_DELIM ';' - -#define ORIGINATE_CAUSES_VARIABLE "originate_causes" -#define ORIGINATE_CAUSES_ITEM_DELIM ';' - -static switch_status_t kz_report_originated_legs(switch_core_session_t *session, switch_event_t *cdr_event) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - cJSON *j_originated = cJSON_CreateArray(); - const char *originated_legs_var = NULL, *originate_causes_var = NULL; - int idx = 0; - - while(1) { - char *argv_leg[10] = { 0 }, *argv_cause[10] = { 0 }; - char *originated_legs, *originate_causes; - cJSON *j_originated_leg; - originated_legs_var = switch_channel_get_variable_dup(channel, ORIGINATED_LEGS_VARIABLE, SWITCH_FALSE, idx); - originate_causes_var = switch_channel_get_variable_dup(channel, ORIGINATE_CAUSES_VARIABLE, SWITCH_FALSE, idx); - - if (zstr(originated_legs_var) || zstr(originate_causes_var)) { - break; - } - - originated_legs = strdup(originated_legs_var); - originate_causes = strdup(originate_causes_var); - - switch_separate_string(originated_legs, ORIGINATED_LEGS_ITEM_DELIM, argv_leg, (sizeof(argv_leg) / sizeof(argv_leg[0]))); - switch_separate_string(originate_causes, ORIGINATE_CAUSES_ITEM_DELIM, argv_cause, (sizeof(argv_cause) / sizeof(argv_cause[0]))); - - j_originated_leg = cJSON_CreateObject(); - cJSON_AddItemToObject(j_originated_leg, "Call-ID", cJSON_CreateString(argv_leg[0])); - cJSON_AddItemToObject(j_originated_leg, "Caller-ID-Name", cJSON_CreateString(argv_leg[1])); - cJSON_AddItemToObject(j_originated_leg, "Caller-ID-Number", cJSON_CreateString(argv_leg[2])); - cJSON_AddItemToObject(j_originated_leg, "Result", cJSON_CreateString(argv_cause[1])); - - cJSON_AddItemToArray(j_originated, j_originated_leg); - - switch_safe_free(originated_legs); - switch_safe_free(originate_causes); - - idx++; - } - - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_originated_legs", cJSON_PrintUnformatted(j_originated)); - - cJSON_Delete(j_originated); - - return SWITCH_STATUS_SUCCESS; -} - -#define MAX_HISTORY 50 -#define HST_ARRAY_DELIM "|:" -#define HST_ITEM_DELIM ':' - -static void kz_report_transfer_history_item(char* value, cJSON *json) -{ - char *argv[4] = { 0 }; - char *item = strdup(value); - int argc = switch_separate_string(item, HST_ITEM_DELIM, argv, (sizeof(argv) / sizeof(argv[0]))); - cJSON *jitem = cJSON_CreateObject(); - char *epoch = NULL, *callid = NULL, *type = NULL; - int add = 0; - if(argc == 4) { - add = 1; - epoch = argv[0]; - callid = argv[1]; - type = argv[2]; - - if(!strncmp(type, "bl_xfer", 7)) { - //char *split = strchr(argv[3], '/'); - //if(split) *(split++) = '\0'; - cJSON_AddItemToObject(jitem, "Caller-Profile-ID", cJSON_CreateString(callid)); - cJSON_AddItemToObject(jitem, "Type", cJSON_CreateString("blind")); - cJSON_AddItemToObject(jitem, "Extension", cJSON_CreateString(argv[3])); - cJSON_AddItemToObject(jitem, "Timestamp", cJSON_CreateNumber(strtod(epoch, NULL))); - } else if(!strncmp(type, "att_xfer", 8)) { - char *split = strchr(argv[3], '/'); - if(split) { - *(split++) = '\0'; - cJSON_AddItemToObject(jitem, "Caller-Profile-ID", cJSON_CreateString(callid)); - cJSON_AddItemToObject(jitem, "Type", cJSON_CreateString("attended")); - cJSON_AddItemToObject(jitem, "Transferee", cJSON_CreateString(argv[3])); - cJSON_AddItemToObject(jitem, "Transferer", cJSON_CreateString(split)); - cJSON_AddItemToObject(jitem, "Timestamp", cJSON_CreateNumber(strtod(epoch, NULL))); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER TYPE '%s' NOT HANDLED => %s\n", type, item); - add = 0; - } - } else if(!strncmp(type, "uuid_br", 7)) { - cJSON_AddItemToObject(jitem, "Caller-Profile-ID", cJSON_CreateString(callid)); - cJSON_AddItemToObject(jitem, "Type", cJSON_CreateString("bridge")); - cJSON_AddItemToObject(jitem, "Other-Leg", cJSON_CreateString(argv[3])); - cJSON_AddItemToObject(jitem, "Timestamp", cJSON_CreateNumber(strtod(epoch, NULL))); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER TYPE '%s' NOT HANDLED => %s\n", type, item); - add = 0; - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER TYPE SPLIT ERROR %i => %s\n", argc, item); - } - if(add) { - cJSON_AddItemToArray(json, jitem); - } else { - cJSON_Delete(jitem); - } - switch_safe_free(item); -} - -static switch_status_t kz_report_transfer_history(switch_core_session_t *session, switch_event_t *cdr_event, const char* var_name) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - cJSON *j_transfer = NULL; - char *tmp_history = NULL, *history = NULL, *argv[MAX_HISTORY] = { 0 }; - char event_header[50]; - int n, argc = 0; - const char *transfer_var = switch_channel_get_variable_dup(channel, var_name, SWITCH_FALSE, -1); - if (zstr(transfer_var)) { - return SWITCH_STATUS_SUCCESS; - } - - if (!(tmp_history = strdup(transfer_var))) { - return SWITCH_STATUS_SUCCESS; - } - - sprintf(event_header, "_json_%s", var_name); - history = tmp_history; - j_transfer = cJSON_CreateArray(); - - if (!strncmp(history, "ARRAY::", 7)) { - history += 7; - argc = switch_separate_string_string(history, HST_ARRAY_DELIM, argv, (sizeof(argv) / sizeof(argv[0]))); - for(n=0; n < argc; n++) { - kz_report_transfer_history_item(argv[n], j_transfer); - } - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, event_header, cJSON_PrintUnformatted(j_transfer)); - } else if (strchr(history, HST_ITEM_DELIM)) { - kz_report_transfer_history_item(history, j_transfer); - switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, event_header, cJSON_PrintUnformatted(j_transfer)); - } - cJSON_Delete(j_transfer); - switch_safe_free(tmp_history); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t kz_report(switch_core_session_t *session, switch_event_t *cdr_event) -{ - kz_report_app_log(session, cdr_event); - kz_report_callflow(session, cdr_event); - kz_report_channel_stats(session, cdr_event); - kz_report_channel_flaws(session, cdr_event); - kz_report_originated_legs(session, cdr_event); - kz_report_transfer_history(session, cdr_event, SWITCH_TRANSFER_HISTORY_VARIABLE); - kz_report_transfer_history(session, cdr_event, SWITCH_TRANSFER_SOURCE_VARIABLE); - return SWITCH_STATUS_SUCCESS; -} - - -static switch_status_t kz_cdr_on_reporting(switch_core_session_t *session) -{ - switch_event_t *cdr_event = NULL; - switch_channel_t *channel = switch_core_session_get_channel(session); - - if (switch_event_create_subclass(&cdr_event, SWITCH_EVENT_CUSTOM, MY_EVENT_JSON_CDR) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "error creating event for report data!\n"); - return SWITCH_STATUS_FALSE; - } - - kz_report(session, cdr_event); - switch_channel_event_set_data(channel, cdr_event); - switch_event_fire(&cdr_event); - - return SWITCH_STATUS_SUCCESS; -} - - -static switch_state_handler_table_t kz_cdr_state_handlers = { - /*.on_init */ NULL, - /*.on_routing */ NULL, - /*.on_execute */ NULL, - /*.on_hangup */ NULL, - /*.on_exchange_media */ NULL, - /*.on_soft_execute */ NULL, - /*.on_consume_media */ NULL, - /*.on_hibernate */ NULL, - /*.on_reset */ NULL, - /*.on_park */ NULL, - /*.on_reporting */ kz_cdr_on_reporting -}; - - -static void kz_cdr_register_state_handlers() -{ - switch_core_add_state_handler(&kz_cdr_state_handlers); -} - -static void kz_cdr_unregister_state_handlers() -{ - switch_core_remove_state_handler(&kz_cdr_state_handlers); -} - -static void kz_cdr_register_events() -{ - if (switch_event_reserve_subclass(MY_EVENT_JSON_CDR) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!\n", MY_EVENT_JSON_CDR); - } -} - -static void kz_cdr_unregister_events() -{ - switch_event_free_subclass(MY_EVENT_JSON_CDR); -} - - -void kz_cdr_start() -{ - kz_cdr_register_events(); - kz_cdr_register_state_handlers(); -} - -void kz_cdr_stop() -{ - kz_cdr_unregister_state_handlers(); - kz_cdr_unregister_events(); -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_commands.c b/src/mod/event_handlers/mod_kazoo/kazoo_commands.c deleted file mode 100644 index 16f00ad1a0..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_commands.c +++ /dev/null @@ -1,592 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * kazoo_commands.c -- clones of mod_commands commands slightly modified for kazoo - * - */ -#include "mod_kazoo.h" -#include -#include - -#define UUID_SET_DESC "Set a variable" -#define UUID_SET_SYNTAX " [value]" - -#define UUID_MULTISET_DESC "Set multiple variables" -#define UUID_MULTISET_SYNTAX " =;=..." - -#define KZ_HTTP_PUT_DESC "upload a local freeswitch file to a url" -#define KZ_HTTP_PUT_SYNTAX "localfile url" - -#define KZ_FIRST_OF_DESC "returns first-of existing event header in params" -#define KZ_FIRST_OF_SYNTAX "list of headers to check" - -#define MAX_FIRST_OF 25 - -SWITCH_STANDARD_API(kz_first_of) -{ - char delim = '|'; - char *mycmd = NULL, *mycmd_dup = NULL, *argv[MAX_FIRST_OF] = { 0 }; - int n, argc = 0; - switch_event_header_t *header = NULL; - switch_channel_t *channel = NULL; - - if (zstr(cmd)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid arg\n"); - return SWITCH_STATUS_GENERR; - } - - if ( session ) { - channel = switch_core_session_get_channel(session); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "GOT CHANNEL\n"); - } - - mycmd_dup = mycmd = strdup(cmd); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "FIRST-OF %s\n", mycmd); - if (!zstr(mycmd) && *mycmd == '^' && *(mycmd+1) == '^') { - mycmd += 2; - delim = *mycmd++; - } - argc = switch_separate_string(mycmd, delim, argv, (sizeof(argv) / sizeof(argv[0]))); - for(n=0; n < argc; n++) { - char* item = argv[n]; - if(*item == '#' || *item == '!' || *item == '?') { - if(*(++item) != '\0') { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "RETURNING default %s\n", item); - stream->write_function(stream, item); - break; - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECKING %s\n", item); - if (channel) { - const char *var = switch_channel_get_variable_dup(channel, item, SWITCH_FALSE, -1); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECKING CHANNEL %s\n", item); - if (var) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "GOT FROM CHANNEL %s => %s\n", item, var); - stream->write_function(stream, var); - break; - } - if (!strncmp(item, "variable_", 9)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECKING CHANNEL %s\n", item+9); - var = switch_channel_get_variable_dup(channel, item+9, SWITCH_FALSE, -1); - if (var) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "GOT FROM CHANNEL %s => %s\n", item+9, var); - stream->write_function(stream, var); - break; - } - } - } - header = switch_event_get_header_ptr(stream->param_event, item); - if(header) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "RETURNING %s : %s\n", item, header->value); - stream->write_function(stream, header->value); - break; - } - } - } - - switch_safe_free(mycmd_dup); - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t kz_uuid_setvar(int urldecode, const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) -{ - switch_core_session_t *psession = NULL; - char *mycmd = NULL, *argv[3] = { 0 }; - int argc = 0; - - if (!zstr(cmd) && (mycmd = strdup(cmd))) { - argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if ((argc == 2 || argc == 3) && !zstr(argv[0])) { - char *uuid = argv[0]; - char *var_name = argv[1]; - char *var_value = NULL; - - if (argc == 3) { - var_value = argv[2]; - } - - if ((psession = switch_core_session_locate(uuid))) { - switch_channel_t *channel; - switch_event_t *event; - channel = switch_core_session_get_channel(psession); - - if (zstr(var_name)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); - stream->write_function(stream, "-ERR No variable specified\n"); - } else { - if(urldecode) { - switch_url_decode(var_value); - } - switch_channel_set_variable(channel, var_name, var_value); - kz_check_set_profile_var(channel, var_name, var_value); - stream->write_function(stream, "+OK\n"); - } - - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - - switch_core_session_rwunlock(psession); - - } else { - stream->write_function(stream, "-ERR No such channel!\n"); - } - goto done; - } - } - - stream->write_function(stream, "-USAGE: %s\n", UUID_SET_SYNTAX); - - done: - switch_safe_free(mycmd); - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_STANDARD_API(uuid_setvar_function) -{ - return kz_uuid_setvar(0, cmd, session, stream); -} - -SWITCH_STANDARD_API(uuid_setvar_encoded_function) -{ - return kz_uuid_setvar(1, cmd, session, stream); -} - -switch_status_t kz_uuid_setvar_multi(int urldecode, const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) -{ - switch_core_session_t *psession = NULL; - char delim = ';'; - char *mycmd = NULL, *vars, *argv[64] = { 0 }; - int argc = 0; - char *var_name, *var_value = NULL; - - if (!zstr(cmd) && (mycmd = strdup(cmd))) { - char *uuid = mycmd; - if (!(vars = strchr(uuid, ' '))) { - goto done; - } - *vars++ = '\0'; - if (*vars == '^' && *(vars+1) == '^') { - vars += 2; - delim = *vars++; - } - if ((psession = switch_core_session_locate(uuid))) { - switch_channel_t *channel = switch_core_session_get_channel(psession); - switch_event_t *event; - int x, y = 0; - argc = switch_separate_string(vars, delim, argv, (sizeof(argv) / sizeof(argv[0]))); - - for (x = 0; x < argc; x++) { - var_name = argv[x]; - if (var_name && (var_value = strchr(var_name, '='))) { - *var_value++ = '\0'; - } - if (zstr(var_name)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); - stream->write_function(stream, "-ERR No variable specified\n"); - } else { - if(urldecode) { - switch_url_decode(var_value); - } - switch_channel_set_variable(channel, var_name, var_value); - kz_check_set_profile_var(channel, var_name, var_value); - - y++; - } - } - - /* keep kazoo nodes in sync */ - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - - switch_core_session_rwunlock(psession); - if (y) { - stream->write_function(stream, "+OK\n"); - goto done; - } - } else { - stream->write_function(stream, "-ERR No such channel!\n"); - } - } - - stream->write_function(stream, "-USAGE: %s\n", UUID_MULTISET_SYNTAX); - - done: - switch_safe_free(mycmd); - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_STANDARD_API(uuid_setvar_multi_function) -{ - return kz_uuid_setvar_multi(0, cmd, session, stream); -} - -SWITCH_STANDARD_API(uuid_setvar_multi_encoded_function) -{ - return kz_uuid_setvar_multi(1, cmd, session, stream); -} - -static size_t body_callback(char *buffer, size_t size, size_t nitems, void *userdata) -{ - return size * nitems; -} - -static size_t header_callback(char *buffer, size_t size, size_t nitems, void *userdata) -{ - switch_event_t* event = (switch_event_t*)userdata; - int len = strlen(buffer); - char buf[1024]; - if(len > 2 && len < 1024) { - snprintf(buf, sizeof(buf), "%s", buffer); - switch_event_add_header_string(event, SWITCH_STACK_PUSH | SWITCH_STACK_BOTTOM, "Reply-Headers", buf); - } - return nitems * size; -} - -SWITCH_STANDARD_API(kz_http_put) -{ - switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_memory_pool_t *lpool = NULL; - switch_memory_pool_t *pool = NULL; - char *args = NULL; - char *argv[10] = { 0 }; - int argc = 0; - switch_event_t *params = NULL; - char *url = NULL; - char *filename = NULL; - int delete_file = 0; - - switch_curl_slist_t *headers = NULL; /* optional linked-list of HTTP headers */ - char *ext; /* file extension, used for MIME type identification */ - const char *mime_type = "application/octet-stream"; - char *buf = NULL; - char *error = NULL; - - CURL *curl_handle = NULL; - long httpRes = 0; - struct stat file_info = {0}; - FILE *file_to_put = NULL; - - if (session) { - pool = switch_core_session_get_pool(session); - } else { - switch_core_new_memory_pool(&lpool); - pool = lpool; - } - - if (zstr(cmd)) { - stream->write_function(stream, "USAGE: %s\n", KZ_HTTP_PUT_SYNTAX); - status = SWITCH_STATUS_SUCCESS; - goto done; - } - - args = strdup(cmd); - argc = switch_separate_string(args, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc != 2) { - stream->write_function(stream, "USAGE: %s\n", KZ_HTTP_PUT_SYNTAX); - status = SWITCH_STATUS_SUCCESS; - goto done; - } - - /* parse params and get profile */ - url = switch_core_strdup(pool, argv[0]); - if (*url == '{') { - if (switch_event_create_brackets(url, '{', '}', ',', ¶ms, &url, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { - status = SWITCH_STATUS_FALSE; - stream->write_function(stream, "-ERR error parsing parameters\n"); - goto done; - } - } - - filename = switch_core_strdup(pool, argv[1]); - - /* guess what type of mime content this is going to be */ - if ((ext = strrchr(filename, '.'))) { - ext++; - if (!(mime_type = switch_core_mime_ext2type(ext))) { - mime_type = "application/octet-stream"; - } - } - - buf = switch_mprintf("Content-Type: %s", mime_type); - headers = switch_curl_slist_append(headers, buf); - - /* open file and get the file size */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "opening %s for upload to %s\n", filename, url); - - /* libcurl requires FILE* */ - file_to_put = fopen(filename, "rb"); - if (!file_to_put) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fopen() error: %s\n", strerror(errno)); - stream->write_function(stream, "-ERR error opening file\n"); - status = SWITCH_STATUS_FALSE; - goto done; - } - - if (fstat(fileno(file_to_put), &file_info) == -1) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fstat() error: %s\n", strerror(errno)); - stream->write_function(stream, "-ERR fstat error\n"); - goto done; - } - - curl_handle = switch_curl_easy_init(); - if (!curl_handle) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "switch_curl_easy_init() failure\n"); - status = SWITCH_STATUS_FALSE; - stream->write_function(stream, "-ERR switch_curl_easy init failure\n"); - goto done; - } - switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1); -#if !defined(LIBCURL_VERSION_NUM) || (LIBCURL_VERSION_NUM < 0x070c01) - switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1); -#endif - switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); - switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); - switch_curl_easy_setopt(curl_handle, CURLOPT_URL, url); - switch_curl_easy_setopt(curl_handle, CURLOPT_READDATA, file_to_put); - switch_curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); - switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); - switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10); - switch_curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 1); - switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-kazoo/1.0"); - switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, stream->param_event); - switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, header_callback); - switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, body_callback); - - switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); - switch_curl_easy_perform(curl_handle); - switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes); - switch_curl_easy_cleanup(curl_handle); - - if (httpRes == 200 || httpRes == 201 || httpRes == 202 || httpRes == 204) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s saved to %s\n", filename, url); - switch_event_add_header(stream->param_event, SWITCH_STACK_BOTTOM, "API-Output", "%s saved to %s", filename, url); - stream->write_function(stream, "+OK %s saved to %s", filename, url); - delete_file = 1; - } else { - error = switch_mprintf("Received HTTP error %ld trying to save %s to %s", httpRes, filename, url); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", error); - switch_event_add_header(stream->param_event, SWITCH_STACK_BOTTOM, "API-Error", "%s", error); - switch_event_add_header(stream->param_event, SWITCH_STACK_BOTTOM, "API-HTTP-Error", "%ld", httpRes); - stream->write_function(stream, "-ERR %s", error); - status = SWITCH_STATUS_GENERR; - } - -done: - if (file_to_put) { - fclose(file_to_put); - if(delete_file) { - remove(filename); - } - } - - if (headers) { - switch_curl_slist_free_all(headers); - } - - switch_safe_free(buf); - switch_safe_free(error); - - switch_safe_free(args); - - if (lpool) { - switch_core_destroy_memory_pool(&lpool); - } - - if (params) { - switch_event_destroy(¶ms); - } - - return status; -} - -SWITCH_STANDARD_API(kz_expand_api) -{ - char *p = NULL, *input = NULL; - char *uuid = NULL, *mycmd; - - if (zstr(cmd)) { - stream->write_function(stream, "-ERR invalid input"); - return SWITCH_STATUS_GENERR; - } - - if (!(mycmd = strdup(cmd))) { - stream->write_function(stream, "-ERR no memory"); - return SWITCH_STATUS_GENERR; - } - - if (!strncasecmp(mycmd, "uuid:", 5)) { - uuid = mycmd + 5; - if ((input = strchr(uuid, ' ')) != NULL) { - *input++ = '\0'; - } else { - stream->write_function(stream, "-ERR invalid argument"); - switch_safe_free(mycmd); - return SWITCH_STATUS_GENERR; - } - } else { - input = mycmd; - } - - p = kz_expand(input, uuid); - stream->write_function(stream, "+OK %s", p); - if (p != input) { - switch_safe_free(p); - } - switch_safe_free(mycmd); - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_STANDARD_API(kz_eval_api) -{ - char *p = NULL, *input = NULL; - char *uuid = NULL, *mycmd; - switch_core_session_t *nsession = NULL; - switch_channel_t *channel = NULL; - - - if (zstr(cmd)) { - stream->write_function(stream, "-ERR invalid input"); - return SWITCH_STATUS_GENERR; - } - - if (!(mycmd = strdup(cmd))) { - stream->write_function(stream, "-ERR no memory"); - return SWITCH_STATUS_GENERR; - } - - if (!strncasecmp(mycmd, "uuid:", 5)) { - uuid = mycmd + 5; - if ((input = strchr(uuid, ' ')) != NULL) { - *input++ = '\0'; - if ((nsession = switch_core_session_locate(uuid)) != NULL) { - channel = switch_core_session_get_channel(nsession); - } else { - stream->write_function(stream, "-ERR invalid session"); - switch_safe_free(mycmd); - return SWITCH_STATUS_GENERR; - } - } else { - stream->write_function(stream, "-ERR invalid argument"); - switch_safe_free(mycmd); - return SWITCH_STATUS_GENERR; - } - } else if (session == NULL) { - stream->write_function(stream, "-ERR invalid argument"); - switch_safe_free(mycmd); - return SWITCH_STATUS_GENERR; - } else { - channel = switch_core_session_get_channel(session); - input = mycmd; - } - - p = switch_channel_expand_variables_check(channel, input, NULL, NULL, 0); - stream->write_function(stream, "+OK %s", p); - if (p != input) { - switch_safe_free(p); - } - switch_safe_free(mycmd); - if (nsession) { - switch_core_session_rwunlock(nsession); - } - return SWITCH_STATUS_SUCCESS; -} - -#define KZ_CONTACT_DESC "returns kazoo contact" -#define KZ_CONTACT_SYNTAX "endpoint@account" - -SWITCH_STANDARD_API(kz_contact_fun) -{ - switch_event_t *params = NULL; - const char *var = NULL; - switch_xml_t xml_node = NULL; - switch_xml_t xml_root = NULL; - - const char *reply = "error/subscriber_absent"; - - if (!cmd) { - stream->write_function(stream, "%s", reply); - return SWITCH_STATUS_SUCCESS; - } - - switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS); - switch_assert(params); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "call"); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Fetch-Exclude-Cache", "true"); - - /* - if (stream->param_event) { - switch_event_merge(params, stream->param_event); - } - */ - - /* - if (session) { - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Fetch-Call-UUID", switch_core_session_get_uuid(session)); - } else if (stream->param_event && (var = switch_event_get_header(stream->param_event, "ent_originate_aleg_uuid")) != NULL) { - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Fetch-Call-UUID", var); - } - */ - - if (switch_xml_locate("directory", "location", "id", cmd, &xml_root, &xml_node, params, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { - stream->write_function(stream, "%s", reply); - return SWITCH_STATUS_SUCCESS; - } - - var = switch_xml_attr(xml_node, "value"); - if (!zstr(var)) { - reply = var; - } - - stream->write_function(stream, "%s", reply); - - switch_xml_free(xml_root); - return SWITCH_STATUS_SUCCESS; -} - -void add_kz_commands(switch_loadable_module_interface_t **module_interface) { - switch_api_interface_t *api_interface = NULL; - SWITCH_ADD_API(api_interface, "kz_uuid_setvar_multi", UUID_SET_DESC, uuid_setvar_multi_function, UUID_MULTISET_SYNTAX); - SWITCH_ADD_API(api_interface, "kz_uuid_setvar_multi_encoded", UUID_SET_DESC, uuid_setvar_multi_encoded_function, UUID_MULTISET_SYNTAX); - switch_console_set_complete("add kz_uuid_setvar_multi ::console::list_uuid"); - switch_console_set_complete("add kz_uuid_setvar_multi_encoded ::console::list_uuid"); - SWITCH_ADD_API(api_interface, "kz_uuid_setvar", UUID_MULTISET_DESC, uuid_setvar_function, UUID_SET_SYNTAX); - SWITCH_ADD_API(api_interface, "kz_uuid_setvar_encoded", UUID_MULTISET_DESC, uuid_setvar_encoded_function, UUID_SET_SYNTAX); - switch_console_set_complete("add kz_uuid_setvar ::console::list_uuid"); - switch_console_set_complete("add kz_uuid_setvar_encoded ::console::list_uuid"); - SWITCH_ADD_API(api_interface, "kz_http_put", KZ_HTTP_PUT_DESC, kz_http_put, KZ_HTTP_PUT_SYNTAX); - SWITCH_ADD_API(api_interface, "first-of", KZ_FIRST_OF_DESC, kz_first_of, KZ_FIRST_OF_SYNTAX); - SWITCH_ADD_API(api_interface, "kz_expand", KZ_FIRST_OF_DESC, kz_expand_api, KZ_FIRST_OF_SYNTAX); - SWITCH_ADD_API(api_interface, "kz_eval", KZ_FIRST_OF_DESC, kz_eval_api, KZ_FIRST_OF_SYNTAX); - SWITCH_ADD_API(api_interface, "kz_contact", KZ_CONTACT_DESC, kz_contact_fun, KZ_CONTACT_SYNTAX); -} - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_config.c b/src/mod/event_handlers/mod_kazoo/kazoo_config.c deleted file mode 100644 index a64677074b..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_config.c +++ /dev/null @@ -1,553 +0,0 @@ -/* -* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II -* -* Version: MPL 1.1 -* -* The contents of this file are subject to the Mozilla Public License Version -* 1.1 (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" basis, -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -* for the specific language governing rights and limitations under the -* License. -* -* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* -* The Initial Developer of the Original Code is -* Anthony Minessale II -* Portions created by the Initial Developer are Copyright (C) -* the Initial Developer. All Rights Reserved. -* -* Based on mod_skel by -* Anthony Minessale II -* -* Contributor(s): -* -* Daniel Bryars -* Tim Brown -* Anthony Minessale II -* William King -* Mike Jerris -* -* kazoo.c -- Sends FreeSWITCH events to an AMQP broker -* -*/ - -#include "mod_kazoo.h" - -static const char *LOG_LEVEL_NAMES[] = { - "SWITCH_LOG_DEBUG10", - "SWITCH_LOG_DEBUG9", - "SWITCH_LOG_DEBUG8", - "SWITCH_LOG_DEBUG7", - "SWITCH_LOG_DEBUG6", - "SWITCH_LOG_DEBUG5", - "SWITCH_LOG_DEBUG4", - "SWITCH_LOG_DEBUG3", - "SWITCH_LOG_DEBUG2", - "SWITCH_LOG_DEBUG1", - "SWITCH_LOG_DEBUG", - "SWITCH_LOG_INFO", - "SWITCH_LOG_NOTICE", - "SWITCH_LOG_WARNING", - "SWITCH_LOG_ERROR", - "SWITCH_LOG_CRIT", - "SWITCH_LOG_ALERT", - "SWITCH_LOG_CONSOLE", - "SWITCH_LOG_INVALID", - "SWITCH_LOG_UNINIT", - NULL -}; - -static const switch_log_level_t LOG_LEVEL_VALUES[] = { - SWITCH_LOG_DEBUG10, - SWITCH_LOG_DEBUG9, - SWITCH_LOG_DEBUG8, - SWITCH_LOG_DEBUG7, - SWITCH_LOG_DEBUG6, - SWITCH_LOG_DEBUG5, - SWITCH_LOG_DEBUG4, - SWITCH_LOG_DEBUG3, - SWITCH_LOG_DEBUG2, - SWITCH_LOG_DEBUG1, - SWITCH_LOG_DEBUG, - SWITCH_LOG_INFO, - SWITCH_LOG_NOTICE, - SWITCH_LOG_WARNING, - SWITCH_LOG_ERROR, - SWITCH_LOG_CRIT, - SWITCH_LOG_ALERT, - SWITCH_LOG_CONSOLE, - SWITCH_LOG_INVALID, - SWITCH_LOG_UNINIT -}; - -switch_log_level_t log_str2level(const char *str) -{ - int x = 0; - switch_log_level_t level = SWITCH_LOG_INVALID; - - if (switch_is_number(str)) { - x = atoi(str); - - if (x > SWITCH_LOG_INVALID) { - return SWITCH_LOG_INVALID - 1; - } else if (x < 0) { - return 0; - } else { - return x; - } - } - - - for (x = 0;; x++) { - if (!LOG_LEVEL_NAMES[x]) { - break; - } - - if (!strcasecmp(LOG_LEVEL_NAMES[x], str)) { - level = LOG_LEVEL_VALUES[x]; //(switch_log_level_t) x; - break; - } - } - - return level; -} - -switch_status_t kazoo_config_loglevels(switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_loglevels_ptr *ptr) -{ - switch_xml_t xml_level, xml_logging; - kazoo_loglevels_ptr loglevels = (kazoo_loglevels_ptr) switch_core_alloc(pool, sizeof(kazoo_loglevels_t)); - - loglevels->failed_log_level = SWITCH_LOG_ALERT; - loglevels->filtered_event_log_level = SWITCH_LOG_DEBUG1; - loglevels->filtered_field_log_level = SWITCH_LOG_DEBUG1; - loglevels->info_log_level = SWITCH_LOG_INFO; - loglevels->warn_log_level = SWITCH_LOG_WARNING; - loglevels->success_log_level = SWITCH_LOG_DEBUG; - loglevels->time_log_level = SWITCH_LOG_DEBUG1; - loglevels->trace_log_level = SWITCH_LOG_DEBUG1; - loglevels->debug_log_level = SWITCH_LOG_DEBUG; - loglevels->error_log_level = SWITCH_LOG_ERROR; - loglevels->hashing_log_level = SWITCH_LOG_DEBUG1; - - if ((xml_logging = switch_xml_child(cfg, "logging")) != NULL) { - for (xml_level = switch_xml_child(xml_logging, "log"); xml_level; xml_level = xml_level->next) { - char *var = (char *) switch_xml_attr_soft(xml_level, "name"); - char *val = (char *) switch_xml_attr_soft(xml_level, "value"); - - if (!var) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "logging param missing 'name' attribute\n"); - continue; - } - - if (!val) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "logging param[%s] missing 'value' attribute\n", var); - continue; - } - - if (!strncmp(var, "success", 7)) { - loglevels->success_log_level = log_str2level(val); - } else if (!strncmp(var, "failed", 6)) { - loglevels->failed_log_level = log_str2level(val); - } else if (!strncmp(var, "info", 4)) { - loglevels->info_log_level = log_str2level(val); - } else if (!strncmp(var, "warn", 4)) { - loglevels->warn_log_level = log_str2level(val); - } else if (!strncmp(var, "time", 4)) { - loglevels->time_log_level = log_str2level(val); - } else if (!strncmp(var, "filtered-event", 14)) { - loglevels->filtered_event_log_level = log_str2level(val); - } else if (!strncmp(var, "filtered-field", 14)) { - loglevels->filtered_field_log_level = log_str2level(val); - } else if (!strncmp(var, "trace", 5)) { - loglevels->trace_log_level = log_str2level(val); - } else if (!strncmp(var, "debug", 5)) { - loglevels->debug_log_level = log_str2level(val); - } else if (!strncmp(var, "error", 5)) { - loglevels->error_log_level = log_str2level(val); - } else if (!strncmp(var, "hashing", 7)) { - loglevels->hashing_log_level = log_str2level(val); - } - } /* xml_level for loop */ - } - - *ptr = loglevels; - return SWITCH_STATUS_SUCCESS; - -} - -switch_status_t kazoo_config_filters(switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_filter_ptr *ptr) -{ - switch_xml_t filters, filter; -// char *routing_key = NULL; - kazoo_filter_ptr root = NULL, prv = NULL, cur = NULL; - - - if ((filters = switch_xml_child(cfg, "filters")) != NULL) { - for (filter = switch_xml_child(filters, "filter"); filter; filter = filter->next) { - const char *var = switch_xml_attr(filter, "name"); - const char *val = switch_xml_attr(filter, "value"); - const char *type = switch_xml_attr(filter, "type"); - const char *compare = switch_xml_attr(filter, "compare"); - cur = (kazoo_filter_ptr) switch_core_alloc(pool, sizeof(kazoo_filter)); - memset(cur, 0, sizeof(kazoo_filter)); - if(prv == NULL) { - root = prv = cur; - } else { - prv->next = cur; - prv = cur; - } - cur->type = FILTER_EXCLUDE; - cur->compare = FILTER_COMPARE_VALUE; - - if(var) - cur->name = switch_core_strdup(pool, var); - - if(val) - cur->value = switch_core_strdup(pool, val); - - if(type) { - if (!strncmp(type, "exclude", 7)) { - cur->type = FILTER_EXCLUDE; - } else if (!strncmp(type, "include", 7)) { - cur->type = FILTER_INCLUDE; - } - } - - if(compare) { - if (!strncmp(compare, "value", 7)) { - cur->compare = FILTER_COMPARE_VALUE; - } else if (!strncmp(compare, "prefix", 6)) { - cur->compare = FILTER_COMPARE_PREFIX; - } else if (!strncmp(compare, "list", 4)) { - cur->compare = FILTER_COMPARE_LIST; - } else if (!strncmp(compare, "exists", 6)) { - cur->compare = FILTER_COMPARE_EXISTS; - } else if (!strncmp(compare, "regex", 5)) { - cur->compare = FILTER_COMPARE_REGEX; - } else if (!strncmp(compare, "field", 5)) { - cur->compare = FILTER_COMPARE_FIELD; - } - } - - if(cur->value == NULL) - cur->compare = FILTER_COMPARE_EXISTS; - - if(cur->compare == FILTER_COMPARE_LIST) { - cur->list.size = switch_separate_string(cur->value, '|', cur->list.value, MAX_LIST_FIELDS); - } - - } - - } - - *ptr = root; - - return SWITCH_STATUS_SUCCESS; - -} - -switch_status_t kazoo_config_field(kazoo_config_ptr definitions, switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_field_ptr *ptr) -{ - const char *var = switch_xml_attr(cfg, "name"); - const char *val = switch_xml_attr(cfg, "value"); - const char *as = switch_xml_attr(cfg, "as"); - const char *type = switch_xml_attr(cfg, "type"); - const char *exclude_prefix = switch_xml_attr(cfg, "exclude-prefix"); - const char *serialize_as = switch_xml_attr(cfg, "serialize-as"); - const char *as_array = switch_xml_attr(cfg, "as-array"); - kazoo_field_ptr cur = (kazoo_field_ptr) switch_core_alloc(pool, sizeof(kazoo_field)); - cur->in_type = FIELD_NONE; - cur->out_type = JSON_NONE; - - if(var) - cur->name = switch_core_strdup(pool, var); - - if(val) - cur->value = switch_core_strdup(pool, val); - - if(as) - cur->as = switch_core_strdup(pool, as); - - if(type) { - if (!strncmp(type, "copy", 4)) { - cur->in_type = FIELD_COPY; - } else if (!strncmp(type, "static", 6)) { - cur->in_type = FIELD_STATIC; - } else if (!strncmp(type, "first-of", 8)) { - cur->in_type = FIELD_FIRST_OF; - } else if (!strncmp(type, "expand", 6)) { - cur->in_type = FIELD_EXPAND; - } else if (!strncmp(type, "prefix", 10)) { - cur->in_type = FIELD_PREFIX; - } else if (!strncmp(type, "group", 5)) { - cur->in_type = FIELD_GROUP; - } else if (!strncmp(type, "reference", 9)) { - cur->in_type = FIELD_REFERENCE; - } - } - - if(serialize_as) { - if (!strncmp(serialize_as, "string", 5)) { - cur->out_type = JSON_STRING; - } else if (!strncmp(serialize_as, "number", 6)) { - cur->out_type = JSON_NUMBER; - } else if (!strncmp(serialize_as, "boolean", 7)) { - cur->out_type = JSON_BOOLEAN; - } else if (!strncmp(serialize_as, "object", 6)) { - cur->out_type = JSON_OBJECT; - } else if (!strncmp(serialize_as, "raw", 6)) { - cur->out_type = JSON_RAW; - } - } - - if(as_array) { - cur->out_type_as_array = switch_true(as_array); - } - - if(exclude_prefix) - cur->exclude_prefix = switch_true(exclude_prefix); - - kazoo_config_filters(pool, cfg, &cur->filter); - kazoo_config_fields(definitions, pool, cfg, &cur->children); - - if(cur->children != NULL - && (cur->in_type == FIELD_STATIC) - && (cur->out_type == JSON_NONE) - ) { - cur->out_type = JSON_OBJECT; - } - if(cur->in_type == FIELD_NONE) { - cur->in_type = FIELD_COPY; - } - - if(cur->out_type == JSON_NONE) { - cur->out_type = JSON_STRING; - } - - if(cur->in_type == FIELD_FIRST_OF) { - cur->list.size = switch_separate_string(cur->value, '|', cur->list.value, MAX_LIST_FIELDS); - } - - if(cur->in_type == FIELD_REFERENCE) { - cur->ref = (kazoo_definition_ptr)switch_core_hash_find(definitions->hash, cur->name); - if(cur->ref == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "referenced field %s not found\n", cur->name); - } - } - - *ptr = cur; - - return SWITCH_STATUS_SUCCESS; - -} - -switch_status_t kazoo_config_fields_loop(kazoo_config_ptr definitions, switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_field_ptr *ptr) -{ - switch_xml_t field; - kazoo_field_ptr root = NULL, prv = NULL; - - - for (field = switch_xml_child(cfg, "field"); field; field = field->next) { - kazoo_field_ptr cur = NULL; - kazoo_config_field(definitions, pool, field, &cur); - if(root == NULL) { - root = prv = cur; - } else { - prv->next = cur; - prv = cur; - } - } - - *ptr = root; - - return SWITCH_STATUS_SUCCESS; - -} - -switch_status_t kazoo_config_fields(kazoo_config_ptr definitions, switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_fields_ptr *ptr) -{ - switch_xml_t fields; - kazoo_fields_ptr root = NULL; - - - if ((fields = switch_xml_child(cfg, "fields")) != NULL) { - const char *verbose = switch_xml_attr(fields, "verbose"); - root = (kazoo_fields_ptr) switch_core_alloc(pool, sizeof(kazoo_fields)); - root->verbose = SWITCH_TRUE; - if(verbose) { - root->verbose = switch_true(verbose); - } - - kazoo_config_fields_loop(definitions, pool, fields, &root->head); - - } - - *ptr = root; - - return SWITCH_STATUS_SUCCESS; - -} - -kazoo_config_ptr kazoo_config_event_handlers(kazoo_config_ptr definitions, switch_xml_t cfg) -{ - switch_xml_t xml_profiles = NULL, xml_profile = NULL; - kazoo_config_ptr profiles = NULL; - switch_memory_pool_t *pool = NULL; - - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "error creating memory pool for producers\n"); - return NULL; - } - - profiles = switch_core_alloc(pool, sizeof(kazoo_config)); - profiles->pool = pool; - switch_core_hash_init(&profiles->hash); - - if ((xml_profiles = switch_xml_child(cfg, "event-handlers"))) { - if ((xml_profile = switch_xml_child(xml_profiles, "profile"))) { - for (; xml_profile; xml_profile = xml_profile->next) { - const char *name = switch_xml_attr(xml_profile, "name"); - if(name == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing attr name\n" ); - continue; - } - kazoo_config_event_handler(definitions, profiles, xml_profile, NULL); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to locate a event-handler profile for kazoo\n" ); - } - } else { - destroy_config(&profiles); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unable to locate event-handlers section for kazoo, using default\n" ); - } - - return profiles; - -} - -kazoo_config_ptr kazoo_config_fetch_handlers(kazoo_config_ptr definitions, switch_xml_t cfg) -{ - switch_xml_t xml_profiles = NULL, xml_profile = NULL; - kazoo_config_ptr profiles = NULL; - switch_memory_pool_t *pool = NULL; - - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "error creating memory pool for producers\n"); - return NULL; - } - - profiles = switch_core_alloc(pool, sizeof(kazoo_config)); - profiles->pool = pool; - switch_core_hash_init(&profiles->hash); - - if ((xml_profiles = switch_xml_child(cfg, "fetch-handlers"))) { - if ((xml_profile = switch_xml_child(xml_profiles, "profile"))) { - for (; xml_profile; xml_profile = xml_profile->next) { - const char *name = switch_xml_attr(xml_profile, "name"); - if(name == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing attr name\n" ); - continue; - } - kazoo_config_fetch_handler(definitions, profiles, xml_profile, NULL); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to locate a fetch-handler profile for kazoo\n" ); - } - } else { - destroy_config(&profiles); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unable to locate fetch-handlers section for kazoo, using default\n" ); - } - - return profiles; - -} - - -switch_status_t kazoo_config_definition(kazoo_config_ptr root, switch_xml_t cfg) -{ - kazoo_definition_ptr definition = NULL; - char *name = (char *) switch_xml_attr_soft(cfg, "name"); - - if (zstr(name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to load kazoo profile, check definition missing name attr\n"); - return SWITCH_STATUS_GENERR; - } - - definition = switch_core_alloc(root->pool, sizeof(kazoo_definition)); - definition->name = switch_core_strdup(root->pool, name); - - kazoo_config_filters(root->pool, cfg, &definition->filter); - kazoo_config_fields_loop(root, root->pool, cfg, &definition->head); - - if ( switch_core_hash_insert(root->hash, name, (void *) definition) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to insert new definition [%s] into kazoo definitions hash\n", name); - return SWITCH_STATUS_GENERR; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "definition[%s] successfully configured\n", definition->name); - return SWITCH_STATUS_SUCCESS; -} - -kazoo_config_ptr kazoo_config_definitions(switch_xml_t cfg) -{ - switch_xml_t xml_definitions = NULL, xml_definition = NULL; - kazoo_config_ptr definitions = NULL; - switch_memory_pool_t *pool = NULL; - - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "error creating memory pool for definitions\n"); - return NULL; - } - - definitions = switch_core_alloc(pool, sizeof(kazoo_config)); - definitions->pool = pool; - switch_core_hash_init(&definitions->hash); - - if ((xml_definitions = switch_xml_child(cfg, "definitions"))) { - if ((xml_definition = switch_xml_child(xml_definitions, "definition"))) { - for (; xml_definition; xml_definition = xml_definition->next) { - kazoo_config_definition(definitions, xml_definition); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "no definitions for kazoo\n" ); - } - } else { - destroy_config(&definitions); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unable to locate definitions section for kazoo, using default\n" ); - } - - return definitions; -} - -void destroy_config(kazoo_config_ptr *ptr) -{ - kazoo_config_ptr config = NULL; - switch_memory_pool_t *pool; - - if (!ptr || !*ptr) { - return; - } - config = *ptr; - pool = config->pool; - - switch_core_hash_destroy(&(config->hash)); - switch_core_destroy_memory_pool(&pool); - - *ptr = NULL; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_config.h b/src/mod/event_handlers/mod_kazoo/kazoo_config.h deleted file mode 100644 index d0117fda5f..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_config.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II -* -* Version: MPL 1.1 -* -* The contents of this file are subject to the Mozilla Public License Version -* 1.1 (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" basis, -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -* for the specific language governing rights and limitations under the -* License. -* -* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* -* The Initial Developer of the Original Code is -* Anthony Minessale II -* Portions created by the Initial Developer are Copyright (C) -* the Initial Developer. All Rights Reserved. -* -* Based on mod_skel by -* Anthony Minessale II -* -* Contributor(s): -* -* Daniel Bryars -* Tim Brown -* Anthony Minessale II -* William King -* Mike Jerris -* -* kazoo.c -- Sends FreeSWITCH events to an AMQP broker -* -*/ - -#ifndef KAZOO_CONFIG_H -#define KAZOO_CONFIG_H - -#include - - -struct kazoo_config_t { - switch_hash_t *hash; - switch_memory_pool_t *pool; -}; - -switch_status_t kazoo_config_loglevels(switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_loglevels_ptr *ptr); -switch_status_t kazoo_config_filters(switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_filter_ptr *ptr); -switch_status_t kazoo_config_fields(kazoo_config_ptr definitions, switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_fields_ptr *ptr); - -switch_status_t kazoo_config_event_handler(kazoo_config_ptr definitions, kazoo_config_ptr root, switch_xml_t cfg, kazoo_event_profile_ptr *ptr); -switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_config_ptr root, switch_xml_t cfg, kazoo_fetch_profile_ptr *ptr); -kazoo_config_ptr kazoo_config_event_handlers(kazoo_config_ptr definitions, switch_xml_t cfg); -kazoo_config_ptr kazoo_config_fetch_handlers(kazoo_config_ptr definitions, switch_xml_t cfg); -kazoo_config_ptr kazoo_config_definitions(switch_xml_t cfg); -switch_status_t kazoo_config_field(kazoo_config_ptr definitions, switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_field_ptr *ptr); -void destroy_config(kazoo_config_ptr *ptr); - -#endif /* KAZOO_CONFIG_H */ - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_definitions.S b/src/mod/event_handlers/mod_kazoo/kazoo_definitions.S deleted file mode 100644 index 0bbe0137cb..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_definitions.S +++ /dev/null @@ -1,8 +0,0 @@ - .global kz_default_config - .global kz_default_config_size - .section .rodata -kz_default_config: - .incbin "kazoo.conf.xml" -1: -kz_default_config_size: - .int 1b - kz_default_config diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_defs.h b/src/mod/event_handlers/mod_kazoo/kazoo_defs.h deleted file mode 100644 index 7fe86dd354..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_defs.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef KAZOO_DEFS_H_ -#define KAZOO_DEFS_H_ - -#define INTERACTION_VARIABLE "Call-Interaction-ID" - -#define UNIX_EPOCH_IN_GREGORIAN 62167219200 -#define UNIX_EPOCH_IN_GREGORIAN_STR "62167219200" - -#endif /* KAZOO_DEFS_H_ */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c b/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c deleted file mode 100644 index 5a01650969..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c +++ /dev/null @@ -1,980 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * kazoo_dptools.c -- clones of mod_dptools commands slightly modified for kazoo - * - */ -#include "mod_kazoo.h" - -#define SET_SHORT_DESC "Set a channel variable" -#define SET_LONG_DESC "Set a channel variable for the channel calling the application." -#define SET_SYNTAX "=" - -#define MULTISET_SHORT_DESC "Set many channel variables" -#define MULTISET_LONG_DESC "Set many channel variables for the channel calling the application" -#define MULTISET_SYNTAX "[^^]= =" - -#define UNSET_SHORT_DESC "Unset a channel variable" -#define UNSET_LONG_DESC "Unset a channel variable for the channel calling the application." -#define UNSET_SYNTAX "" - -#define MULTIUNSET_SHORT_DESC "Unset many channel variables" -#define MULTIUNSET_LONG_DESC "Unset many channel variables for the channel calling the application." -#define MULTIUNSET_SYNTAX "[^^] " - -#define EXPORT_SHORT_DESC "Export many channel variables" -#define EXPORT_LONG_DESC "Export many channel variables for the channel calling the application" -#define EXPORT_SYNTAX "[^^]= =" - -#define PREFIX_UNSET_SHORT_DESC "clear variables by prefix" -#define PREFIX_UNSET_LONG_DESC "clears the channel variables that start with prefix supplied" -#define PREFIX_UNSET_SYNTAX "" - -#define UUID_MULTISET_SHORT_DESC "Set many channel variables" -#define UUID_MULTISET_LONG_DESC "Set many channel variables for a specific channel" -#define UUID_MULTISET_SYNTAX " [^^]= =" - -#define KZ_ENDLESS_PLAYBACK_SHORT_DESC "Playback File Endlessly until break" -#define KZ_ENDLESS_PLAYBACK_LONG_DESC "Endlessly Playback a file to the channel until a break occurs" -#define KZ_ENDLESS_PLAYBACK_SYNTAX "" - -#define NOOP_SHORT_DESC "no operation" -#define NOOP_LONG_DESC "no operation. serves as a control point" -#define NOOP_SYNTAX "[]" - -static void base_set (switch_core_session_t *session, const char *data, int urldecode, switch_stack_t stack) -{ - char *var, *val = NULL; - - if (zstr(data)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); - } else { - switch_channel_t *channel = switch_core_session_get_channel(session); - char *expanded = NULL; - - var = switch_core_session_strdup(session, data); - - if (!(val = strchr(var, '='))) { - val = strchr(var, ','); - } - - if (val) { - *val++ = '\0'; - if (zstr(val)) { - val = NULL; - } - } - - if (val) { - if(urldecode) { - switch_url_decode(val); - } - expanded = switch_channel_expand_variables(channel, val); - } - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SET [%s]=[%s] => [%s]\n", switch_channel_get_name(channel), var, val, - expanded ? expanded : "UNDEF"); - switch_channel_add_variable_var_check(channel, var, expanded, SWITCH_FALSE, stack); - kz_check_set_profile_var(channel, var, expanded); - if (expanded && expanded != val) { - switch_safe_free(expanded); - } - } -} - -static int kz_is_exported(switch_core_session_t *session, char *varname) -{ - char *array[256] = {0}; - int i, argc; - switch_channel_t *channel = switch_core_session_get_channel(session); - const char *exports = switch_channel_get_variable(channel, SWITCH_EXPORT_VARS_VARIABLE); - char *arg = switch_core_session_strdup(session, exports); - argc = switch_split(arg, ',', array); - for(i=0; i < argc; i++) { - if(!strcasecmp(array[i], varname)) - return 1; - } - - return 0; -} - -static void base_export (switch_core_session_t *session, const char *data, int urldecode, switch_stack_t stack) -{ - char *var, *val = NULL; - - if (zstr(data)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); - } else { - switch_channel_t *channel = switch_core_session_get_channel(session); - char *expanded = NULL; - - var = switch_core_session_strdup(session, data); - - if (!(val = strchr(var, '='))) { - val = strchr(var, ','); - } - - if (val) { - *val++ = '\0'; - if (zstr(val)) { - val = NULL; - } - } - - if (val) { - if(urldecode) { - switch_url_decode(val); - } - expanded = switch_channel_expand_variables(channel, val); - - if(!kz_is_exported(session, var)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s EXPORT [%s]=[%s]\n", switch_channel_get_name(channel), var, expanded ? expanded : "UNDEF"); - switch_channel_export_variable_var_check(channel, var, expanded, SWITCH_EXPORT_VARS_VARIABLE, SWITCH_FALSE); - } else { - if(strcmp(switch_str_nil(switch_channel_get_variable_dup(channel, var, SWITCH_FALSE, -1)), expanded)) { - switch_channel_set_variable(channel, var, expanded); - } - } - if (expanded && expanded != val) { - switch_safe_free(expanded); - } - } - } -} - -SWITCH_STANDARD_APP(prefix_unset_function) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_event_header_t *ei = NULL; - switch_event_t *clear; - char *arg = (char *) data; - - if(switch_event_create(&clear, SWITCH_EVENT_CLONE) != SWITCH_STATUS_SUCCESS) { - return; - } - - for (ei = switch_channel_variable_first(channel); ei; ei = ei->next) { - const char *name = ei->name; - char *value = ei->value; - if (!strncasecmp(name, arg, strlen(arg))) { - switch_event_add_header_string(clear, SWITCH_STACK_BOTTOM, name, value); - } - } - - switch_channel_variable_last(channel); - for (ei = clear->headers; ei; ei = ei->next) { - char *varname = ei->name; - switch_channel_set_variable(channel, varname, NULL); - } - - switch_event_destroy(&clear); -} - -void kz_multiset(switch_core_session_t *session, const char* data, int urldecode) -{ - char delim = ' '; - char *arg = (char *) data; - switch_event_t *event; - - if (!zstr(arg) && *arg == '^' && *(arg+1) == '^') { - arg += 2; - delim = *arg++; - } - - if(delim != '\0') { - switch_channel_t *channel = switch_core_session_get_channel(session); - if (arg) { - char *array[256] = {0}; - int i, argc; - - arg = switch_core_session_strdup(session, arg); - argc = switch_split(arg, delim, array); - - for(i = 0; i < argc; i++) { - base_set(session, array[i], urldecode, SWITCH_STACK_BOTTOM); - } - } - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "multiset with empty args\n"); - } -} - -SWITCH_STANDARD_APP(multiset_function) -{ - kz_multiset(session, data, 0); -} - -SWITCH_STANDARD_APP(multiset_encoded_function) -{ - kz_multiset(session, data, 1); -} - -void kz_uuid_multiset(switch_core_session_t *session, const char* data, int urldecode) -{ - char delim = ' '; - char *arg0 = (char *) data; - char *arg = strchr(arg0, ' '); - switch_event_t *event; - - - if(arg == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "uuid_multiset with invalid args\n"); - return; - } - *arg = '\0'; - arg++; - - if(zstr(arg0)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "uuid_multiset with invalid uuid\n"); - return; - } - - - if (!zstr(arg) && *arg == '^' && *(arg+1) == '^') { - arg += 2; - delim = *arg++; - } - - if(delim != '\0') { - switch_core_session_t *uuid_session = NULL; - if ((uuid_session = switch_core_session_locate(arg0)) != NULL) { - switch_channel_t *uuid_channel = switch_core_session_get_channel(uuid_session); - if (arg) { - char *array[256] = {0}; - int i, argc; - - arg = switch_core_session_strdup(session, arg); - argc = switch_split(arg, delim, array); - - for(i = 0; i < argc; i++) { - base_set(uuid_session, array[i], urldecode, SWITCH_STACK_BOTTOM); - } - } - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(uuid_channel, event); - switch_event_fire(&event); - } - switch_core_session_rwunlock(uuid_session); - } else { - base_set(session, data, urldecode, SWITCH_STACK_BOTTOM); - } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "multiset with empty args\n"); - } -} - -SWITCH_STANDARD_APP(uuid_multiset_function) -{ - kz_uuid_multiset(session, data, 0); -} - -SWITCH_STANDARD_APP(uuid_multiset_encoded_function) -{ - kz_uuid_multiset(session, data, 1); -} - -void kz_set(switch_core_session_t *session, const char* data, int urldecode) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_event_t *event; - - base_set(session, data, urldecode, SWITCH_STACK_BOTTOM); - - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } -} - -SWITCH_STANDARD_APP(set_function) -{ - kz_set(session, data, 0); -} - -SWITCH_STANDARD_APP(set_encoded_function) -{ - kz_set(session, data, 1); -} - -SWITCH_STANDARD_APP(unset_function) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_event_t *event; - - if (zstr(data)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "UNSET [%s]\n", (char *) data); - switch_channel_set_variable(switch_core_session_get_channel(session), data, NULL); - } - - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } -} - -SWITCH_STANDARD_APP(multiunset_function) { - char delim = ' '; - char *arg = (char *) data; - - if (!zstr(arg) && *arg == '^' && *(arg+1) == '^') { - arg += 2; - delim = *arg++; - } - - if(delim != '\0') { - if (arg) { - char *array[256] = {0}; - int i, argc; - - arg = switch_core_session_strdup(session, arg); - argc = switch_split(arg, delim, array); - - for(i = 0; i < argc; i++) { - switch_channel_set_variable(switch_core_session_get_channel(session), array[i], NULL); - } - - } else { - switch_channel_set_variable(switch_core_session_get_channel(session), arg, NULL); - } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "multiunset with empty args\n"); - } -} - - -void kz_export(switch_core_session_t *session, const char* data, int urldecode) -{ - char delim = ' '; - char *arg = (char *) data; - - if (!zstr(arg) && *arg == '^' && *(arg+1) == '^') { - arg += 2; - delim = *arg++; - } - - if(delim != '\0') { - if (arg) { - char *array[256] = {0}; - int i, argc; - - arg = switch_core_session_strdup(session, arg); - argc = switch_split(arg, delim, array); - - for(i = 0; i < argc; i++) { - base_export(session, array[i], urldecode, SWITCH_STACK_BOTTOM); - } - } else { - base_export(session, data, urldecode, SWITCH_STACK_BOTTOM); - } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "export with empty args\n"); - } -} - -SWITCH_STANDARD_APP(export_function) -{ - kz_export(session, data, 0); -} - -SWITCH_STANDARD_APP(export_encoded_function) -{ - kz_export(session, data, 1); -} - -// copied from mod_dptools with allow SWITCH_STATUS_BREAK -SWITCH_STANDARD_APP(kz_endless_playback_function) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_status_t status = SWITCH_STATUS_SUCCESS; - const char *file = data; - - while (switch_channel_ready(channel)) { - status = switch_ivr_play_file(session, NULL, file, NULL); - - if (status != SWITCH_STATUS_SUCCESS) { - break; - } - } - - switch (status) { - case SWITCH_STATUS_SUCCESS: - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "FILE PLAYED"); - break; - case SWITCH_STATUS_BREAK: - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "PLAYBACK_INTERRUPTED"); - break; - case SWITCH_STATUS_NOTFOUND: - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "FILE NOT FOUND"); - break; - default: - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "PLAYBACK ERROR"); - break; - } - -} - -SWITCH_STANDARD_APP(kz_moh_function) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_file_handle_t fh = { 0 }; - const char *var_samples = switch_channel_get_variable_dup(channel, "moh_playback_samples", SWITCH_FALSE, -1); - unsigned int samples = 0; - char * my_data = NULL; - - if (var_samples) { - fh.samples = samples = atoi(var_samples); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "SETTING SAMPLES %d\n", samples); - } - - switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, ""); - - /* - * hack for proper position - */ - if (!strncmp(data, "http_cache://", 13) && session) { - switch_channel_t *channel = switch_core_session_get_channel(session); - char * resolve = switch_mprintf("${http_get({prefetch=true}%s)}", data+13); - my_data = switch_channel_expand_variables_check(channel, resolve, NULL, NULL, 0); - } else { - my_data = strdup(data); - } - - status = switch_ivr_play_file(session, &fh, my_data, NULL); -// status = switch_ivr_play_file(session, &fh, data, NULL); - - switch_assert(!(fh.flags & SWITCH_FILE_OPEN)); - - switch (status) { - case SWITCH_STATUS_SUCCESS: - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH PLAYED SUCCESS\n"); - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "MOH FILE PLAYED"); - switch_channel_set_variable(channel, "moh_playback_samples", "0"); - break; - case SWITCH_STATUS_BREAK: - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH PLAYED BREAK\n"); - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "MOH FILE PLAYED"); - if ((var_samples = switch_channel_get_variable_dup(channel, "playback_samples", SWITCH_FALSE, -1)) != NULL) { - samples += atoi(var_samples); - if (samples >= fh.samples) { - samples = 0; - } - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "SETTING MOH SAMPLES %d\n", samples); - switch_channel_set_variable_printf(channel, "moh_playback_samples", "%d", samples); - } - break; - case SWITCH_STATUS_NOTFOUND: - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH PLAYED NOT FOUND\n"); - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "MOH FILE NOT FOUND"); - break; - default: - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "MOH PLAYED DEFAULT\n"); - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "MOH PLAYBACK ERROR"); - break; - } - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH duration %" SWITCH_INT64_T_FMT "\n", fh.duration); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH offset_pos %d\n", fh.offset_pos); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH pos %" SWITCH_INT64_T_FMT "\n", fh.pos); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH sample_count %" SWITCH_SIZE_T_FMT "\n", fh.sample_count); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "MOH samples %d\n", fh.samples); - - switch_safe_free(my_data); -} - -SWITCH_STANDARD_APP(noop_function) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - const char *response = uuid_str; - - if (zstr(data)) { - switch_uuid_str(uuid_str, sizeof(uuid_str)); - } else { - response = data; - } - - switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, response); -} - -SWITCH_STANDARD_APP(kz_restore_caller_id_function) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_caller_profile_t *cp = switch_channel_get_caller_profile(channel); - cp->caller_id_name = cp->orig_caller_id_name; - cp->caller_id_number = cp->orig_caller_id_number; -} - -SWITCH_STANDARD_APP(kz_audio_bridge_function) -{ - switch_channel_t *caller_channel = switch_core_session_get_channel(session); - switch_core_session_t *peer_session = NULL; - switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; - switch_status_t status = SWITCH_STATUS_FALSE; - - if (zstr(data)) { - return; - } - - status = switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); - - if (status != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Originate Failed. Cause: %s\n", switch_channel_cause2str(cause)); - - switch_channel_set_variable(caller_channel, "originate_failed_cause", switch_channel_cause2str(cause)); - switch_channel_set_variable(caller_channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, switch_channel_cause2str(cause)); - switch_channel_handle_cause(caller_channel, cause); - - return; - } else { - const char* uuid = switch_core_session_get_uuid(session); - const char* peer_uuid = switch_core_session_get_uuid(peer_session); - - - switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); - if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE)) || - switch_true(switch_channel_get_variable(peer_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE))) { - switch_channel_set_flag(caller_channel, CF_BYPASS_MEDIA_AFTER_BRIDGE); - } - - while(1) { - const char *xfer_uuid; - switch_channel_state_t a_state , a_running_state; - switch_channel_state_t b_state , b_running_state; - status = switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "BRIDGE RESULT %i\n", status); - if(status != 0) { - break; - } - - a_state = switch_channel_get_state(caller_channel); - a_running_state = switch_channel_get_running_state(caller_channel); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "A STATE %s %s => %s , %s\n", switch_channel_state_name(a_running_state), switch_channel_state_name(a_state), uuid, peer_uuid); - - if(a_state >= CS_HANGUP) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "A HANGUP = %s , %s\n", uuid, peer_uuid); - break; - } - - b_state = switch_channel_get_state(peer_channel); - b_running_state = switch_channel_get_running_state(peer_channel); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "B STATE %s %s => %s , %s\n", switch_channel_state_name(b_running_state), switch_channel_state_name(b_state), uuid, peer_uuid); - - if(b_state >= CS_HANGUP) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "B HANGUP = %s , %s\n", uuid, peer_uuid); - switch_channel_set_variable(caller_channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, switch_channel_cause2str(switch_channel_get_cause(peer_channel))); - break; - } - - if(!(xfer_uuid=switch_channel_get_variable(caller_channel, "att_xfer_peer_uuid"))) { - if(!(xfer_uuid=switch_channel_get_variable(peer_channel, "att_xfer_peer_uuid"))) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "XFER UUID NULL\n"); - break; - } - } - - switch_channel_set_variable(caller_channel, "att_xfer_peer_uuid", NULL); - switch_channel_set_variable(peer_channel, "att_xfer_peer_uuid", NULL); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "WAIT 1\n"); - - switch_channel_clear_flag(peer_channel, CF_UUID_BRIDGE_ORIGINATOR); - switch_channel_set_state(peer_channel, CS_RESET); - switch_channel_wait_for_state(peer_channel, NULL, CS_RESET); - switch_channel_clear_state_handler(peer_channel, NULL); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "WAIT 3\n"); - - switch_channel_set_flag(caller_channel, CF_UUID_BRIDGE_ORIGINATOR); - switch_channel_clear_flag(caller_channel, CF_TRANSFER); - switch_channel_clear_flag(caller_channel, CF_REDIRECT); - switch_channel_set_flag(peer_channel, CF_UUID_BRIDGE_ORIGINATOR); - switch_channel_clear_flag(peer_channel, CF_TRANSFER); - switch_channel_clear_flag(peer_channel, CF_REDIRECT); - - if(!switch_channel_media_up(caller_channel)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "A MEDIA DOWN HANGUP = %s, %s , %s\n", xfer_uuid, uuid, peer_uuid); - } - if(!switch_channel_media_up(peer_channel)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "B MEDIA DOWN HANGUP = %s, %s , %s\n", xfer_uuid, uuid, peer_uuid); - } - switch_channel_set_state(caller_channel, CS_EXECUTE); - switch_channel_set_state(peer_channel, CS_EXECUTE); - - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "XFER LOOP %s %s , %s\n", xfer_uuid, uuid, peer_uuid); - - } - - if (peer_session) { - switch_core_session_rwunlock(peer_session); - } - } -} - -SWITCH_STANDARD_APP(kz_audio_bridge_uuid_function) -{ - switch_core_session_t *peer_session = NULL; - const char * peer_uuid = NULL; - - if (zstr(data)) { - return; - } - - peer_uuid = switch_core_session_strdup(session, data); - if (peer_uuid && (peer_session = switch_core_session_locate(peer_uuid))) { - switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); - } - - if (peer_session) { - switch_core_session_rwunlock(peer_session); - } -} - - -struct kz_att_keys { - const char *attxfer_cancel_key; - const char *attxfer_hangup_key; - const char *attxfer_conf_key; -}; - -static switch_status_t kz_att_xfer_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen) -{ - switch_core_session_t *peer_session = (switch_core_session_t *) buf; - if (!buf || !peer_session) { - return SWITCH_STATUS_SUCCESS; - } - - switch (itype) { - case SWITCH_INPUT_TYPE_DTMF: - { - switch_dtmf_t *dtmf = (switch_dtmf_t *) input; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); - struct kz_att_keys *keys = switch_channel_get_private(channel, "__kz_keys"); - - if (dtmf->digit == *keys->attxfer_hangup_key) { - switch_channel_hangup(channel, SWITCH_CAUSE_ATTENDED_TRANSFER); - return SWITCH_STATUS_FALSE; - } - - if (dtmf->digit == *keys->attxfer_cancel_key) { - switch_channel_hangup(peer_channel, SWITCH_CAUSE_NORMAL_CLEARING); - return SWITCH_STATUS_FALSE; - } - - if (dtmf->digit == *keys->attxfer_conf_key) { - switch_caller_extension_t *extension = NULL; - const char *app = "three_way"; - const char *app_arg = switch_core_session_get_uuid(session); - const char *holding = switch_channel_get_variable(channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE); - switch_core_session_t *b_session; - - if (holding && (b_session = switch_core_session_locate(holding))) { - switch_channel_t *b_channel = switch_core_session_get_channel(b_session); - if (!switch_channel_ready(b_channel)) { - app = "intercept"; - } - switch_core_session_rwunlock(b_session); - } - - if ((extension = switch_caller_extension_new(peer_session, app, app_arg)) == 0) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Memory Error!\n"); - abort(); - } - - switch_caller_extension_add_application(peer_session, extension, app, app_arg); - switch_channel_set_caller_extension(peer_channel, extension); - switch_channel_set_state(peer_channel, CS_RESET); - switch_channel_wait_for_state(peer_channel, channel, CS_RESET); - switch_channel_set_state(peer_channel, CS_EXECUTE); - switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, NULL); - return SWITCH_STATUS_FALSE; - } - - } - break; - default: - break; - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t kz_att_xfer_tmp_hanguphook(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - - if (state == CS_HANGUP || state == CS_ROUTING) { - const char *bond = switch_channel_get_variable(channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE); - - if (!zstr(bond)) { - switch_core_session_t *b_session; - - if ((b_session = switch_core_session_locate(bond))) { - switch_channel_t *b_channel = switch_core_session_get_channel(b_session); - if (switch_channel_up(b_channel)) { - switch_channel_set_flag(b_channel, CF_REDIRECT); - } - switch_core_session_rwunlock(b_session); - } - } - - switch_core_event_hook_remove_state_change(session, kz_att_xfer_tmp_hanguphook); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t kz_att_xfer_hanguphook(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - const char *id = NULL; - const char *peer_uuid = NULL; - - if (state == CS_HANGUP || state == CS_ROUTING) { - if ((id = switch_channel_get_variable(channel, "xfer_uuids"))) { - switch_stream_handle_t stream = { 0 }; - SWITCH_STANDARD_STREAM(stream); - if ((peer_uuid = switch_channel_get_variable(channel, "xfer_peer_uuid"))) { - switch_core_session_t *peer_session = NULL; - if ((peer_session = switch_core_session_locate(peer_uuid)) != NULL ) { - switch_ivr_transfer_recordings(session, peer_session); - switch_core_session_rwunlock(peer_session); - } - } - switch_api_execute("uuid_bridge", id, NULL, &stream); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "\nHangup Command uuid_bridge(%s):\n%s\n", id, - switch_str_nil((char *) stream.data)); - switch_safe_free(stream.data); - } - - switch_core_event_hook_remove_state_change(session, kz_att_xfer_hanguphook); - } - return SWITCH_STATUS_SUCCESS; -} - - -static void kz_att_xfer_set_result(switch_channel_t *channel, switch_status_t status) -{ - switch_channel_set_variable(channel, SWITCH_ATT_XFER_RESULT_VARIABLE, status == SWITCH_STATUS_SUCCESS ? "success" : "failure"); -} - -struct kz_att_obj { - switch_core_session_t *session; - const char *data; - int running; -}; - -void *SWITCH_THREAD_FUNC kz_att_thread_run(switch_thread_t *thread, void *obj) -{ - struct kz_att_obj *att = (struct kz_att_obj *) obj; - struct kz_att_keys *keys = NULL; - switch_core_session_t *session = att->session; - switch_core_session_t *peer_session = NULL; - const char *data = att->data; - switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; - switch_channel_t *channel = switch_core_session_get_channel(session), *peer_channel = NULL; - const char *bond = NULL; - switch_bool_t follow_recording = switch_true(switch_channel_get_variable(channel, "recording_follow_attxfer")); - const char *attxfer_cancel_key = NULL, *attxfer_hangup_key = NULL, *attxfer_conf_key = NULL; - int br = 0; - switch_event_t *event = NULL; - switch_core_session_t *b_session = NULL; - switch_channel_t *b_channel = NULL; - - att->running = 1; - - if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) { - return NULL; - } - - bond = switch_channel_get_partner_uuid(channel); - if ((b_session = switch_core_session_locate(bond)) == NULL) { - switch_core_session_rwunlock(session); - return NULL; - } - switch_channel_set_variable(channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, bond); - switch_core_event_hook_add_state_change(session, kz_att_xfer_tmp_hanguphook); - - if (switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL) - != SWITCH_STATUS_SUCCESS || !peer_session) { - switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, bond); - goto end; - } - - peer_channel = switch_core_session_get_channel(peer_session); - switch_channel_set_flag(peer_channel, CF_INNER_BRIDGE); - switch_channel_set_flag(channel, CF_INNER_BRIDGE); - - if (!(attxfer_cancel_key = switch_channel_get_variable(channel, "attxfer_cancel_key"))) { - if (!(attxfer_cancel_key = switch_channel_get_variable(peer_channel, "attxfer_cancel_key"))) { - attxfer_cancel_key = "#"; - } - } - - if (!(attxfer_hangup_key = switch_channel_get_variable(channel, "attxfer_hangup_key"))) { - if (!(attxfer_hangup_key = switch_channel_get_variable(peer_channel, "attxfer_hangup_key"))) { - attxfer_hangup_key = "*"; - } - } - - if (!(attxfer_conf_key = switch_channel_get_variable(channel, "attxfer_conf_key"))) { - if (!(attxfer_conf_key = switch_channel_get_variable(peer_channel, "attxfer_conf_key"))) { - attxfer_conf_key = "0"; - } - } - - keys = switch_core_session_alloc(session, sizeof(*keys)); - keys->attxfer_cancel_key = switch_core_session_strdup(session, attxfer_cancel_key); - keys->attxfer_hangup_key = switch_core_session_strdup(session, attxfer_hangup_key); - keys->attxfer_conf_key = switch_core_session_strdup(session, attxfer_conf_key); - switch_channel_set_private(channel, "__kz_keys", keys); - - switch_channel_set_variable(channel, "att_xfer_peer_uuid", switch_core_session_get_uuid(peer_session)); - - switch_ivr_multi_threaded_bridge(session, peer_session, kz_att_xfer_on_dtmf, peer_session, NULL); - - switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE); - switch_channel_clear_flag(channel, CF_INNER_BRIDGE); - - if (switch_channel_down(peer_channel)) { - switch_core_session_rwunlock(peer_session); - switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, bond); - goto end; - } - - /* - * we're emiting the transferee event so that callctl can update - */ - b_channel = switch_core_session_get_channel(b_session); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "sofia::transferee") == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(b_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "att_xfer_replaced_call_id", switch_core_session_get_uuid(peer_session)); - switch_event_fire(&event); - } - - if (!switch_channel_ready(channel)) { - switch_status_t status; - - if (follow_recording) { - switch_ivr_transfer_recordings(session, peer_session); - } - status = switch_ivr_uuid_bridge(switch_core_session_get_uuid(peer_session), bond); - kz_att_xfer_set_result(peer_channel, status); - br++; - } else { - // switch_channel_set_variable_printf(b_channel, "xfer_uuids", "%s %s", switch_core_session_get_uuid(peer_session), switch_core_session_get_uuid(session)); - switch_channel_set_variable_printf(channel, "xfer_uuids", "%s %s", switch_core_session_get_uuid(peer_session), bond); - switch_channel_set_variable(channel, "xfer_peer_uuid", switch_core_session_get_uuid(peer_session)); - - switch_core_event_hook_add_state_change(session, kz_att_xfer_hanguphook); - // switch_core_event_hook_add_state_change(b_session, kz_att_xfer_hanguphook); - } - -/* - * this was commented so that the existing bridge - * doesn't end - * - if (!br) { - switch_status_t status = switch_ivr_uuid_bridge(switch_core_session_get_uuid(session), bond); - att_xfer_set_result(channel, status); - } -*/ - - switch_core_session_rwunlock(peer_session); - - end: - - switch_core_event_hook_remove_state_change(session, kz_att_xfer_tmp_hanguphook); - - switch_channel_set_variable(channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL); - switch_channel_clear_flag(channel, CF_XFER_ZOMBIE); - - switch_core_session_rwunlock(b_session); - switch_core_session_rwunlock(session); - att->running = 0; - - return NULL; -} - -SWITCH_STANDARD_APP(kz_att_xfer_function) -{ - switch_thread_t *thread; - switch_threadattr_t *thd_attr = NULL; - switch_memory_pool_t *pool = switch_core_session_get_pool(session); - struct kz_att_obj *att; - switch_channel_t *channel = switch_core_session_get_channel(session); - - switch_threadattr_create(&thd_attr, pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_threadattr_detach_set(thd_attr, 1); - - att = switch_core_session_alloc(session, sizeof(*att)); - att->running = -1; - att->session = session; - att->data = switch_core_session_strdup(session, data); - switch_thread_create(&thread, thd_attr, kz_att_thread_run, att, pool); - - while(att->running && switch_channel_up(channel)) { - switch_yield(100000); - } -} - -void add_kz_dptools(switch_loadable_module_interface_t **module_interface) { - switch_application_interface_t *app_interface = NULL; - SWITCH_ADD_APP(app_interface, "kz_set", SET_SHORT_DESC, SET_LONG_DESC, set_function, SET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_set_encoded", SET_SHORT_DESC, SET_LONG_DESC, set_encoded_function, SET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_multiset", MULTISET_SHORT_DESC, MULTISET_LONG_DESC, multiset_function, MULTISET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_multiset_encoded", MULTISET_SHORT_DESC, MULTISET_LONG_DESC, multiset_encoded_function, MULTISET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_unset", UNSET_SHORT_DESC, UNSET_LONG_DESC, unset_function, UNSET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_multiunset", MULTISET_SHORT_DESC, MULTISET_LONG_DESC, multiunset_function, MULTIUNSET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_export", EXPORT_SHORT_DESC, EXPORT_LONG_DESC, export_function, EXPORT_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_export_encoded", EXPORT_SHORT_DESC, EXPORT_LONG_DESC, export_encoded_function, EXPORT_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_prefix_unset", PREFIX_UNSET_SHORT_DESC, PREFIX_UNSET_LONG_DESC, prefix_unset_function, PREFIX_UNSET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_uuid_multiset", UUID_MULTISET_SHORT_DESC, UUID_MULTISET_LONG_DESC, uuid_multiset_function, UUID_MULTISET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_uuid_multiset_encoded", UUID_MULTISET_SHORT_DESC, UUID_MULTISET_LONG_DESC, uuid_multiset_encoded_function, UUID_MULTISET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); - SWITCH_ADD_APP(app_interface, "kz_endless_playback", KZ_ENDLESS_PLAYBACK_SHORT_DESC, KZ_ENDLESS_PLAYBACK_LONG_DESC, kz_endless_playback_function, KZ_ENDLESS_PLAYBACK_SYNTAX, SAF_NONE); - SWITCH_ADD_APP(app_interface, "kz_restore_caller_id", NOOP_SHORT_DESC, NOOP_LONG_DESC, kz_restore_caller_id_function, NOOP_SYNTAX, SAF_NONE); - SWITCH_ADD_APP(app_interface, "noop", NOOP_SHORT_DESC, NOOP_LONG_DESC, noop_function, NOOP_SYNTAX, SAF_NONE); - SWITCH_ADD_APP(app_interface, "kz_bridge", "Bridge Audio", "Bridge the audio between two sessions", kz_audio_bridge_function, "", SAF_SUPPORT_NOMEDIA|SAF_SUPPORT_TEXT_ONLY); - SWITCH_ADD_APP(app_interface, "kz_bridge_uuid", "Bridge Audio", "Bridge the audio between two sessions", kz_audio_bridge_uuid_function, "", SAF_SUPPORT_NOMEDIA|SAF_SUPPORT_TEXT_ONLY); - SWITCH_ADD_APP(app_interface, "kz_att_xfer", "Attended Transfer", "Attended Transfer", kz_att_xfer_function, "", SAF_NONE); - SWITCH_ADD_APP(app_interface, "kz_moh", "Kazoo MOH Playback", "Kazoo MOH Playback", kz_moh_function, "", SAF_NONE); -} diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_ei.h b/src/mod/event_handlers/mod_kazoo/kazoo_ei.h deleted file mode 100644 index 5f617b5f1d..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_ei.h +++ /dev/null @@ -1,295 +0,0 @@ -#ifndef KAZOO_EI_H -#define KAZOO_EI_H - -#include -#include - -#define MODNAME "mod_kazoo" -#define BUNDLE "community" -#define RELEASE "v1.5.0-1" -#define VERSION "mod_kazoo v1.5.0-1 community" - -#define KZ_MAX_SEPARATE_STRINGS 10 -#define HOSTNAME_MAX 1024 -#define NODENAME_MAX 1024 - -typedef enum {KAZOO_FETCH_PROFILE, KAZOO_EVENT_PROFILE} kazoo_profile_type; - -typedef enum {ERLANG_TUPLE, ERLANG_MAP} kazoo_json_term; - -typedef struct ei_xml_agent_s ei_xml_agent_t; -typedef ei_xml_agent_t *ei_xml_agent_ptr; - -typedef struct kazoo_event kazoo_event_t; -typedef kazoo_event_t *kazoo_event_ptr; - -typedef struct kazoo_event_profile kazoo_event_profile_t; -typedef kazoo_event_profile_t *kazoo_event_profile_ptr; - -typedef struct kazoo_fetch_profile kazoo_fetch_profile_t; -typedef kazoo_fetch_profile_t *kazoo_fetch_profile_ptr; - -typedef struct kazoo_config_t kazoo_config; -typedef kazoo_config *kazoo_config_ptr; - -#include "kazoo_fields.h" -#include "kazoo_config.h" - -struct ei_send_msg_s { - ei_x_buff buf; - erlang_pid pid; -}; -typedef struct ei_send_msg_s ei_send_msg_t; - -struct ei_received_msg_s { - ei_x_buff buf; - erlang_msg msg; -}; -typedef struct ei_received_msg_s ei_received_msg_t; - - -typedef struct ei_event_stream_s ei_event_stream_t; -typedef struct ei_node_s ei_node_t; - -struct ei_event_binding_s { - char id[SWITCH_UUID_FORMATTED_LENGTH + 1]; - switch_event_node_t *node; - switch_event_types_t type; - const char *subclass_name; - ei_event_stream_t* stream; - kazoo_event_ptr event; - - struct ei_event_binding_s *next; -}; -typedef struct ei_event_binding_s ei_event_binding_t; - -struct ei_event_stream_s { - switch_memory_pool_t *pool; - ei_event_binding_t *bindings; - switch_queue_t *queue; - switch_socket_t *acceptor; - switch_pollset_t *pollset; - switch_pollfd_t *pollfd; - switch_socket_t *socket; - switch_mutex_t *socket_mutex; - switch_bool_t connected; - switch_time_t connected_time; - char remote_ip[48]; - uint16_t remote_port; - char local_ip[48]; - uint16_t local_port; - erlang_pid pid; - uint32_t flags; - ei_node_t *node; - short event_stream_framing; - short event_stream_keepalive; - switch_interval_time_t queue_timeout; - struct ei_event_stream_s *next; -}; - -struct ei_node_s { - int nodefd; - switch_atomic_t pending_bgapi; - switch_atomic_t receive_handlers; - switch_memory_pool_t *pool; - ei_event_stream_t *event_streams; - switch_mutex_t *event_streams_mutex; - switch_queue_t *send_msgs; - switch_queue_t *received_msgs; - char *peer_nodename; - switch_time_t created_time; - switch_socket_t *socket; - char remote_ip[48]; - uint16_t remote_port; - char local_ip[48]; - uint16_t local_port; - uint32_t flags; - int legacy; - short event_stream_framing; - short event_stream_keepalive; - switch_interval_time_t event_stream_queue_timeout; - switch_interval_time_t receiver_queue_timeout; - switch_interval_time_t sender_queue_timeout; - struct ei_node_s *next; -}; - - -struct xml_fetch_reply_s { - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - char *xml_str; - struct xml_fetch_reply_s *next; -}; -typedef struct xml_fetch_reply_s xml_fetch_reply_t; - -struct fetch_handler_s { - erlang_pid pid; - struct fetch_handler_s *next; -}; -typedef struct fetch_handler_s fetch_handler_t; - -struct ei_xml_client_s { - ei_node_t *ei_node; - fetch_handler_t *fetch_handlers; - struct ei_xml_client_s *next; -}; -typedef struct ei_xml_client_s ei_xml_client_t; - -struct ei_xml_agent_s { - switch_memory_pool_t *pool; - switch_xml_section_t section; - switch_thread_rwlock_t *lock; - ei_xml_client_t *clients; - switch_mutex_t *current_client_mutex; - ei_xml_client_t *current_client; - switch_mutex_t *replies_mutex; - switch_thread_cond_t *new_reply; - xml_fetch_reply_t *replies; - kazoo_fetch_profile_ptr profile; - -}; - -struct kz_globals_s { - switch_memory_pool_t *pool; - switch_atomic_t threads; - switch_socket_t *acceptor; - struct ei_cnode_s ei_cnode; - switch_thread_rwlock_t *ei_nodes_lock; - ei_node_t *ei_nodes; - - switch_xml_binding_t *config_fetch_binding; - switch_xml_binding_t *directory_fetch_binding; - switch_xml_binding_t *dialplan_fetch_binding; - switch_xml_binding_t *channels_fetch_binding; - switch_xml_binding_t *languages_fetch_binding; - switch_xml_binding_t *chatplan_fetch_binding; - - switch_hash_t *event_filter; - int epmdfd; - int node_worker_threads; - switch_bool_t nat_map; - switch_bool_t ei_shortname; - int ei_compat_rel; - char *ip; - char *hostname; - struct hostent* hostname_ent; - char *ei_cookie; - char *ei_nodename; - uint32_t flags; - int send_all_headers; - int send_all_private_headers; - int connection_timeout; - int ei_receive_timeout; - switch_interval_time_t node_sender_queue_timeout; - switch_interval_time_t node_receiver_queue_timeout; - int receive_msg_preallocate; - int event_stream_preallocate; - int send_msg_batch; - short event_stream_framing; - short event_stream_keepalive; - switch_interval_time_t event_stream_queue_timeout; - switch_port_t port; - int config_fetched; - int io_fault_tolerance; - switch_interval_time_t io_fault_tolerance_sleep; - kazoo_event_profile_ptr events; - kazoo_config_ptr definitions; - kazoo_config_ptr event_handlers; - kazoo_config_ptr fetch_handlers; - kazoo_json_term json_encoding; - - char **profile_vars_prefixes; - char **kazoo_var_prefixes; - - int legacy_events; - uint8_t tweaks[KZ_TWEAK_MAX]; - switch_bool_t expand_headers_on_fetch; - - switch_interval_time_t delay_before_initial_fetch; - - -}; -typedef struct kz_globals_s kz_globals_t; -extern kz_globals_t kazoo_globals; - -/* kazoo_event_stream.c */ -ei_event_stream_t *find_event_stream(ei_event_stream_t *event_streams, const erlang_pid *from); - -//ei_event_stream_t *new_event_stream(ei_event_stream_t **event_streams, const erlang_pid *from); -ei_event_stream_t *new_event_stream(ei_node_t *ei_node, const erlang_pid *from); - - -switch_status_t remove_event_stream(ei_event_stream_t **event_streams, const erlang_pid *from); -switch_status_t remove_event_streams(ei_event_stream_t **event_streams); -unsigned long get_stream_port(const ei_event_stream_t *event_stream); -switch_status_t add_event_binding(ei_event_stream_t *event_stream, const char *event_name); -//switch_status_t add_event_binding(ei_event_stream_t *event_stream, const switch_event_types_t event_type, const char *subclass_name); -switch_status_t remove_event_binding(ei_event_stream_t *event_stream, const switch_event_types_t event_type, const char *subclass_name); -switch_status_t remove_event_bindings(ei_event_stream_t *event_stream); - -/* kazoo_node.c */ -switch_status_t new_kazoo_node(int nodefd, ErlConnect *conn); - -/* kazoo_ei_utils.c */ -void close_socket(switch_socket_t **sock); -void close_socketfd(int *sockfd); -switch_socket_t *create_socket_with_port(switch_memory_pool_t *pool, switch_port_t port); -switch_socket_t *create_socket(switch_memory_pool_t *pool); -switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei_cnode_s *ei_cnode); -switch_status_t ei_compare_pids(const erlang_pid *pid1, const erlang_pid *pid2); -void ei_encode_switch_event_headers(ei_x_buff *ebuf, switch_event_t *event); -void ei_encode_switch_event_headers_2(ei_x_buff *ebuf, switch_event_t *event, int decode); -void ei_encode_json(ei_x_buff *ebuf, cJSON *JObj); -void ei_link(ei_node_t *ei_node, erlang_pid * from, erlang_pid * to); -void ei_encode_switch_event(ei_x_buff * ebuf, switch_event_t *event); -int ei_helper_send(ei_node_t *ei_node, erlang_pid* to, ei_x_buff *buf); -int ei_decode_atom_safe(char *buf, int *index, char *dst); -int ei_decode_string_or_binary_limited(char *buf, int *index, int maxsize, char *dst); -int ei_decode_string_or_binary(char *buf, int *index, char **dst); -switch_status_t create_acceptor(); -switch_hash_t *create_default_filter(); -void kz_erl_init(); -void kz_erl_shutdown(); -SWITCH_DECLARE(switch_status_t) ei_queue_pop(switch_queue_t *queue, void **data, switch_interval_time_t timeout); - -void fetch_config(); - -switch_status_t kazoo_load_config(); -void kazoo_destroy_config(); -void kz_set_hostname(); - -#define _ei_x_encode_string(buf, string) { ei_x_encode_binary(buf, string, strlen(string)); } - -/* kazoo_fetch_agent.c */ -switch_status_t bind_fetch_agents(); -switch_status_t unbind_fetch_agents(); -switch_status_t remove_xml_clients(ei_node_t *ei_node); -switch_status_t add_fetch_handler(ei_node_t *ei_node, erlang_pid *from, switch_xml_binding_t *binding); -switch_status_t remove_fetch_handlers(ei_node_t *ei_node, erlang_pid *from); -switch_status_t fetch_reply(char *uuid_str, char *xml_str, switch_xml_binding_t *binding); -switch_status_t handle_api_command_streams(ei_node_t *ei_node, switch_stream_handle_t *stream); - -void bind_event_profiles(kazoo_event_ptr event); -void rebind_fetch_profiles(kazoo_config_ptr fetch_handlers); -switch_status_t kazoo_config_handlers(switch_xml_t cfg); - -/* runtime */ -SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime); - - - -#define kz_test_tweak(flag) (kazoo_globals.tweaks[flag] ? 1 : 0) -#define kz_set_tweak(flag) kazoo_globals.tweaks[flag] = 1 -#define kz_clear_tweak(flag) kazoo_globals.tweaks[flag] = 0 - -#endif /* KAZOO_EI_H */ - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c b/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c deleted file mode 100644 index 3c626c15da..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c +++ /dev/null @@ -1,708 +0,0 @@ -/* -* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II -* -* Version: MPL 1.1 -* -* The contents of this file are subject to the Mozilla Public License Version -* 1.1 (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" basis, -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -* for the specific language governing rights and limitations under the -* License. -* -* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* -* The Initial Developer of the Original Code is -* Anthony Minessale II -* Portions created by the Initial Developer are Copyright (C) -* the Initial Developer. All Rights Reserved. -* -* Based on mod_skel by -* Anthony Minessale II -* -* Contributor(s): -* -* Daniel Bryars -* Tim Brown -* Anthony Minessale II -* William King -* Mike Jerris -* -* kazoo.c -- Sends FreeSWITCH events to an AMQP broker -* -*/ - -#include "mod_kazoo.h" - -#define KZ_DEFAULT_STREAM_PRE_ALLOCATE 8192 - -#define KAZOO_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void __attribute__((__unused__)) fname(const char *string) { if (!string) return;\ - if (vname) {free(vname); vname = NULL;}vname = strdup(string);} static void fname(const char *string) - -KAZOO_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, kazoo_globals.ip); -KAZOO_DECLARE_GLOBAL_STRING_FUNC(set_pref_ei_cookie, kazoo_globals.ei_cookie); -KAZOO_DECLARE_GLOBAL_STRING_FUNC(set_pref_ei_nodename, kazoo_globals.ei_nodename); -//KAZOO_DECLARE_GLOBAL_STRING_FUNC(set_pref_kazoo_var_prefix, kazoo_globals.kazoo_var_prefix); - -static int read_cookie_from_file(char *filename) { - int fd; - char cookie[MAXATOMLEN + 1]; - char *end; - struct stat buf; - - if (!stat(filename, &buf)) { - if ((buf.st_mode & S_IRWXG) || (buf.st_mode & S_IRWXO)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s must only be accessible by owner only.\n", filename); - return 2; - } - if (buf.st_size > MAXATOMLEN) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s contains a cookie larger than the maximum atom size of %d.\n", filename, MAXATOMLEN); - return 2; - } - fd = open(filename, O_RDONLY); - if (fd < 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to open cookie file %s : %d.\n", filename, errno); - return 2; - } - - if (read(fd, cookie, MAXATOMLEN) < 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to read cookie file %s : %d.\n", filename, errno); - } - - cookie[MAXATOMLEN] = '\0'; - - /* replace any end of line characters with a null */ - if ((end = strchr(cookie, '\n'))) { - *end = '\0'; - } - - if ((end = strchr(cookie, '\r'))) { - *end = '\0'; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set cookie from file %s: %s\n", filename, cookie); - - set_pref_ei_cookie(cookie); - return 0; - } else { - /* don't error here, because we might be blindly trying to read $HOME/.erlang.cookie, and that can fail silently */ - return 1; - } -} - -void kz_set_hostname() -{ - if (kazoo_globals.hostname == NULL) { - char hostname[NODENAME_MAX]; - memcpy(hostname, switch_core_get_hostname(), NODENAME_MAX); - kazoo_globals.hostname_ent = gethostbyname(hostname); - if(kazoo_globals.hostname_ent != NULL) { - kazoo_globals.hostname = switch_core_strdup(kazoo_globals.pool, kazoo_globals.hostname_ent->h_name); - } else { - kazoo_globals.hostname = switch_core_strdup(kazoo_globals.pool, hostname); - } - } -} - -switch_status_t kazoo_ei_config(switch_xml_t cfg) { - switch_xml_t child, param; - char* kazoo_var_prefix = NULL; - char* profile_vars_prefix = NULL; - char* sep_array[KZ_MAX_SEPARATE_STRINGS]; - int array_len, i; - kazoo_globals.send_all_headers = 0; - kazoo_globals.send_all_private_headers = 1; - kazoo_globals.connection_timeout = 500; - kazoo_globals.ei_receive_timeout = 200; - kazoo_globals.receive_msg_preallocate = 2000; - kazoo_globals.event_stream_preallocate = KZ_DEFAULT_STREAM_PRE_ALLOCATE; - kazoo_globals.send_msg_batch = 10; - kazoo_globals.event_stream_framing = 2; - kazoo_globals.event_stream_keepalive = 1; - kazoo_globals.event_stream_queue_timeout = 200000; - kazoo_globals.node_receiver_queue_timeout = 100000; - kazoo_globals.node_sender_queue_timeout = 0; - kazoo_globals.port = 0; - kazoo_globals.io_fault_tolerance = 3; - kazoo_globals.io_fault_tolerance_sleep = 100000; // 100 ms - kazoo_globals.json_encoding = ERLANG_TUPLE; - kazoo_globals.delay_before_initial_fetch = 10000000; - - kazoo_globals.legacy_events = SWITCH_FALSE; - kazoo_globals.expand_headers_on_fetch = SWITCH_TRUE; - - kz_set_tweak(KZ_TWEAK_INTERACTION_ID); - kz_set_tweak(KZ_TWEAK_EXPORT_VARS); - kz_set_tweak(KZ_TWEAK_SWITCH_URI); - kz_set_tweak(KZ_TWEAK_REPLACES_CALL_ID); - kz_set_tweak(KZ_TWEAK_LOOPBACK_VARS); - kz_set_tweak(KZ_TWEAK_CALLER_ID); - kz_set_tweak(KZ_TWEAK_TRANSFERS); - kz_set_tweak(KZ_TWEAK_BRIDGE); - kz_set_tweak(KZ_TWEAK_BRIDGE_REPLACES_ALEG); - kz_set_tweak(KZ_TWEAK_BRIDGE_REPLACES_CALL_ID); - kz_set_tweak(KZ_TWEAK_BRIDGE_VARIABLES); - kz_set_tweak(KZ_TWEAK_RESTORE_CALLER_ID_ON_BLIND_XFER); - - - - if ((child = switch_xml_child(cfg, "settings"))) { - for (param = switch_xml_child(child, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - - if (!strcmp(var, "listen-ip")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set bind ip address: %s\n", val); - set_pref_ip(val); - } else if (!strcmp(var, "listen-port")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set bind port: %s\n", val); - kazoo_globals.port = atoi(val); - } else if (!strcmp(var, "cookie")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set cookie: %s\n", val); - set_pref_ei_cookie(val); - } else if (!strcmp(var, "cookie-file")) { - if (read_cookie_from_file(val) == 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to read cookie from %s\n", val); - } - } else if (!strcmp(var, "nodename")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set node name: %s\n", val); - set_pref_ei_nodename(val); - } else if (!strcmp(var, "shortname")) { - kazoo_globals.ei_shortname = switch_true(val); - } else if (!strcmp(var, "kazoo-var-prefix")) { - kazoo_var_prefix = switch_core_strdup(kazoo_globals.pool, val); - } else if (!strcmp(var, "set-profile-vars-prefix")) { - profile_vars_prefix = switch_core_strdup(kazoo_globals.pool, val); - } else if (!strcmp(var, "compat-rel")) { - if (atoi(val) >= 7) - kazoo_globals.ei_compat_rel = atoi(val); - else - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid compatibility release '%s' specified\n", val); - } else if (!strcmp(var, "nat-map")) { - kazoo_globals.nat_map = switch_true(val); - } else if (!strcmp(var, "send-all-headers")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set send-all-headers: %s\n", val); - kazoo_globals.send_all_headers = switch_true(val); - } else if (!strcmp(var, "send-all-private-headers")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set send-all-private-headers: %s\n", val); - kazoo_globals.send_all_private_headers = switch_true(val); - } else if (!strcmp(var, "connection-timeout")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set connection-timeout: %s\n", val); - kazoo_globals.connection_timeout = atoi(val); - } else if (!strcmp(var, "receive-timeout")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set receive-timeout: %s\n", val); - kazoo_globals.ei_receive_timeout = atoi(val); - } else if (!strcmp(var, "receive-msg-preallocate")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set receive-msg-preallocate: %s\n", val); - kazoo_globals.receive_msg_preallocate = atoi(val); - } else if (!strcmp(var, "event-stream-preallocate")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set event-stream-preallocate: %s\n", val); - kazoo_globals.event_stream_preallocate = atoi(val); - } else if (!strcmp(var, "send-msg-batch-size")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set send-msg-batch-size: %s\n", val); - kazoo_globals.send_msg_batch = atoi(val); - } else if (!strcmp(var, "event-stream-framing")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set event-stream-framing: %s\n", val); - kazoo_globals.event_stream_framing = atoi(val); - - } else if (!strcmp(var, "event-stream-keep-alive")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set event-stream-keep-alive: %s\n", val); - kazoo_globals.event_stream_keepalive = switch_true(val); - - } else if (!strcmp(var, "io-fault-tolerance")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set io-fault-tolerance: %s\n", val); - kazoo_globals.io_fault_tolerance = atoi(val); - } else if (!strcmp(var, "io-fault-tolerance-sleep-micro")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.io_fault_tolerance_sleep = atoi(val); - } else if (!strcmp(var, "io-fault-tolerance-sleep-ms")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.io_fault_tolerance_sleep = atoi(val) * 1000; - } else if (!strcmp(var, "io-fault-tolerance-sleep-sec")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.io_fault_tolerance_sleep = atoi(val) * 1000000; - - - } else if (!strcmp(var, "node-worker-threads")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set node-worker-threads: %s\n", val); - kazoo_globals.node_worker_threads = atoi(val); - } else if (!strcmp(var, "json-term-encoding")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set json-term-encoding: %s\n", val); - if(!strcmp(val, "map")) { - kazoo_globals.json_encoding = ERLANG_MAP; - } - } else if (!strcmp(var, "legacy-events")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set legacy-events: %s\n", val); - kazoo_globals.legacy_events = switch_true(val); - } else if (!strcmp(var, "expand-headers-on-fetch")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set expand-headers-on-fetch: %s\n", val); - kazoo_globals.expand_headers_on_fetch = switch_true(val); - } else if (!strcmp(var, "node-receiver-queue-timeout")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.node_receiver_queue_timeout = atoi(val); - } else if (!strcmp(var, "node-sender-queue-timeout")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.node_sender_queue_timeout = atoi(val); - } else if (!strcmp(var, "event-stream-queue-timeout")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.event_stream_queue_timeout = atoi(val); - } else if (!strcmp(var, "delay-before-initial-fetch-micro")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.delay_before_initial_fetch = atoi(val); - } else if (!strcmp(var, "delay-before-initial-fetch-ms")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.delay_before_initial_fetch = atoi(val) * 1000; - } else if (!strcmp(var, "delay-before-initial-fetch-sec")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set %s : %s\n", var, val); - kazoo_globals.delay_before_initial_fetch = atoi(val) * 1000000; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unknown config option %s : %s\n", var, val); - } - } - } - - if ((child = switch_xml_child(cfg, "tweaks"))) { - char *default_tweaks = (char *) switch_xml_attr_soft(child, "default"); - if (default_tweaks && !zstr(default_tweaks)) { - int i, v = switch_true(default_tweaks) ? 1 : 0; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set tweak default : %s\n", default_tweaks); - for (i = 0; i < KZ_TWEAK_MAX; i++) kazoo_globals.tweaks[i] = v; - } - for (param = switch_xml_child(child, "tweak"); param; param = param->next) { - kz_tweak_t tweak = KZ_TWEAK_MAX; - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - if(var && val && kz_name_tweak(var, &tweak) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set tweak %s : %s\n", var, val); - if(switch_true(val)) { - kz_set_tweak(tweak); - } else { - kz_clear_tweak(tweak); - } - } - } - } - - if ((child = switch_xml_child(cfg, "variables"))) { - for (param = switch_xml_child(child, "variable"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - if(var && val) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set core variable %s : %s\n", var, val); - switch_core_set_variable(var, val); - } - } - } - - if ((child = switch_xml_child(cfg, "event-filter"))) { - switch_hash_t *filter; - - switch_core_hash_init(&filter); - for (param = switch_xml_child(child, "header"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - switch_core_hash_insert(filter, var, "1"); - } - kazoo_globals.event_filter = filter; - } - - if (kazoo_globals.receive_msg_preallocate < 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid receive message preallocate value, disabled\n"); - kazoo_globals.receive_msg_preallocate = 0; - } - - if (kazoo_globals.event_stream_preallocate < 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid event stream preallocate value, disabled\n"); - kazoo_globals.event_stream_preallocate = 0; - } - - if (kazoo_globals.send_msg_batch < 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid send message batch size, reverting to default\n"); - kazoo_globals.send_msg_batch = 10; - } - - if (kazoo_globals.io_fault_tolerance < 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid I/O fault tolerance, reverting to default\n"); - kazoo_globals.io_fault_tolerance = 10; - } - - if (!kazoo_globals.event_filter) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Event filter not found in configuration, using default\n"); - kazoo_globals.event_filter = create_default_filter(); - } - - if (kazoo_globals.event_stream_framing < 1 || kazoo_globals.event_stream_framing > 4) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid event stream framing value, using default\n"); - kazoo_globals.event_stream_framing = 2; - } - - if (zstr(kazoo_var_prefix)) { - kazoo_var_prefix = switch_core_strdup(kazoo_globals.pool, "ecallmgr_;cav_"); - } - - if (zstr(profile_vars_prefix)) { - profile_vars_prefix = switch_core_strdup(kazoo_globals.pool, "effective_;origination_"); - } - - kazoo_globals.kazoo_var_prefixes = switch_core_alloc(kazoo_globals.pool, sizeof(char*) * KZ_MAX_SEPARATE_STRINGS); - array_len = switch_separate_string(kazoo_var_prefix, ';', sep_array, KZ_MAX_SEPARATE_STRINGS - 1); - for(i=0; i < array_len; i++) { - char var[100]; - sprintf(var, "variable_%s", sep_array[i]); - kazoo_globals.kazoo_var_prefixes[i] = switch_core_strdup(kazoo_globals.pool, var); - } - - kazoo_globals.profile_vars_prefixes = switch_core_alloc(kazoo_globals.pool, sizeof(char*) * KZ_MAX_SEPARATE_STRINGS); - array_len = switch_separate_string(profile_vars_prefix, ';', sep_array, KZ_MAX_SEPARATE_STRINGS - 1); - for(i=0; i < array_len; i++) { - kazoo_globals.profile_vars_prefixes[i] = switch_core_strdup(kazoo_globals.pool, sep_array[i]); - } - - if (!kazoo_globals.node_worker_threads) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Number of node worker threads not found in configuration, using default\n"); - kazoo_globals.node_worker_threads = 10; - } - - if (zstr(kazoo_globals.ip)) { - set_pref_ip("0.0.0.0"); - } - - if (zstr(kazoo_globals.ei_cookie)) { - int res; - char *home_dir = getenv("HOME"); - char path_buf[1024]; - - if (!zstr(home_dir)) { - /* $HOME/.erlang.cookie */ - switch_snprintf(path_buf, sizeof (path_buf), "%s%s%s", home_dir, SWITCH_PATH_SEPARATOR, ".erlang.cookie"); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for cookie at path: %s\n", path_buf); - - res = read_cookie_from_file(path_buf); - if (res) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No cookie or valid cookie file specified, using default cookie\n"); - set_pref_ei_cookie("ClueCon"); - } - } - } - - if (!kazoo_globals.ei_nodename) { - set_pref_ei_nodename("freeswitch"); - } - - if (!kazoo_globals.nat_map) { - kazoo_globals.nat_map = 0; - } - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t kazoo_config_handlers(switch_xml_t cfg) -{ - switch_xml_t def = NULL; - switch_xml_t child, param; - char* xml = NULL; - kazoo_config_ptr definitions = NULL, fetch_handlers = NULL, event_handlers = NULL; - kazoo_event_profile_ptr events = NULL; - - xml = strndup(kz_default_config, kz_default_config_size); - def = switch_xml_parse_str_dup(xml); - - kz_xml_process(def); - kz_xml_process(cfg); - - if ((child = switch_xml_child(cfg, "variables"))) { - for (param = switch_xml_child(child, "variable"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - if(var && val) { - switch_core_set_variable(var, val); - } - } - } else if ((child = switch_xml_child(def, "variables"))) { - for (param = switch_xml_child(child, "variable"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - if(var && val) { - switch_core_set_variable(var, val); - } - } - } - - definitions = kazoo_config_definitions(cfg); - if(definitions == NULL) { - if(kazoo_globals.definitions == NULL) { - definitions = kazoo_config_definitions(def); - } else { - definitions = kazoo_globals.definitions; - } - } - - fetch_handlers = kazoo_config_fetch_handlers(definitions, cfg); - if(fetch_handlers == NULL) { - if(kazoo_globals.fetch_handlers == NULL) { - fetch_handlers = kazoo_config_fetch_handlers(definitions, def); - } else { - fetch_handlers = kazoo_globals.fetch_handlers; - } - } - - event_handlers = kazoo_config_event_handlers(definitions, cfg); - if(event_handlers == NULL) { - if(kazoo_globals.event_handlers == NULL) { - event_handlers = kazoo_config_event_handlers(definitions, def); - } else { - event_handlers = kazoo_globals.event_handlers; - } - } - - if(event_handlers != NULL) { - events = (kazoo_event_profile_ptr) switch_core_hash_find(event_handlers->hash, "default"); - } - - if(events == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to get default handler for events\n"); - destroy_config(&event_handlers); - event_handlers = kazoo_config_event_handlers(definitions, def); - events = (kazoo_event_profile_ptr) switch_core_hash_find(event_handlers->hash, "default"); - } - - if(kazoo_globals.events != events) { - bind_event_profiles(events->events); - kazoo_globals.events = events; - } - - if(kazoo_globals.event_handlers != event_handlers) { - kazoo_config_ptr tmp = kazoo_globals.event_handlers; - kazoo_globals.event_handlers = event_handlers; - destroy_config(&tmp); - } - - if(kazoo_globals.fetch_handlers != fetch_handlers) { - kazoo_config_ptr tmp = kazoo_globals.fetch_handlers; - kazoo_globals.fetch_handlers = fetch_handlers; - rebind_fetch_profiles(fetch_handlers); - destroy_config(&tmp); - } - - if(kazoo_globals.definitions != definitions) { - kazoo_config_ptr tmp = kazoo_globals.definitions; - kazoo_globals.definitions = definitions; - destroy_config(&tmp); - } - - - switch_xml_free(def); - switch_safe_free(xml); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t kazoo_load_config() -{ - char *cf = "kazoo.conf"; - switch_xml_t cfg, xml; - if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open configuration file %s\n", cf); - return SWITCH_STATUS_FALSE; - } else { - kazoo_ei_config(cfg); - kazoo_config_handlers(cfg); - switch_xml_free(xml); - } - - return SWITCH_STATUS_SUCCESS; -} - -void kazoo_destroy_config() -{ - destroy_config(&kazoo_globals.event_handlers); - destroy_config(&kazoo_globals.fetch_handlers); - destroy_config(&kazoo_globals.definitions); -} - -switch_status_t kazoo_config_events(kazoo_config_ptr definitions, switch_memory_pool_t *pool, switch_xml_t cfg, kazoo_event_profile_ptr profile) -{ - switch_xml_t events, event; - kazoo_event_ptr prv = NULL, cur = NULL; - - - if ((events = switch_xml_child(cfg, "events")) != NULL) { - for (event = switch_xml_child(events, "event"); event; event = event->next) { - const char *var = switch_xml_attr(event, "name"); - cur = (kazoo_event_ptr) switch_core_alloc(pool, sizeof(kazoo_event_t)); - memset(cur, 0, sizeof(kazoo_event_t)); - if(prv == NULL) { - profile->events = prv = cur; - } else { - prv->next = cur; - prv = cur; - } - cur->profile = profile; - cur->name = switch_core_strdup(pool, var); - kazoo_config_filters(pool, event, &cur->filter); - kazoo_config_fields(definitions, pool, event, &cur->fields); - if (switch_xml_child(event, "logging") != NULL) { - kazoo_config_loglevels(pool, event, &cur->logging); - } - } - } - - return SWITCH_STATUS_SUCCESS; - -} - - -switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_config_ptr root, switch_xml_t cfg, kazoo_fetch_profile_ptr *ptr) -{ - kazoo_fetch_profile_ptr profile = NULL; - switch_xml_t params, param; - switch_xml_section_t fetch_section; - int fetch_timeout = 2000000; - switch_memory_pool_t *pool = NULL; - - char *name = (char *) switch_xml_attr_soft(cfg, "name"); - - if (zstr(name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing name in profile\n"); - - return SWITCH_STATUS_GENERR; - } - - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocation pool for new profile : %s\n", name); - - return SWITCH_STATUS_GENERR; - } - - profile = switch_core_alloc(pool, sizeof(kazoo_fetch_profile_t)); - profile->pool = pool; - profile->root = root; - profile->name = switch_core_strdup(profile->pool, name); - - fetch_section = switch_xml_parse_section_string(name); - - if ((params = switch_xml_child(cfg, "params")) != NULL) { - - for (param = switch_xml_child(params, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - - if (!var) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile[%s] param missing 'name' attribute\n", name); - continue; - } - - if (!val) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile[%s] param[%s] missing 'value' attribute\n", name, var); - continue; - } - - if (!strncmp(var, "fetch-timeout", 13)) { - fetch_timeout = atoi(val); - } else if (!strncmp(var, "fetch-section", 13)) { - fetch_section = switch_xml_parse_section_string(val); - } - } - } - - if (fetch_section == SWITCH_XML_SECTION_RESULT) { - char *tmp = switch_xml_toxml(cfg, SWITCH_FALSE); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, tmp); - free(tmp); - goto err; - } - - - profile->fetch_timeout = fetch_timeout; - profile->section = fetch_section; - kazoo_config_fields(definitions, pool, cfg, &profile->fields); - kazoo_config_loglevels(pool, cfg, &profile->logging); - - if(root) { - if ( switch_core_hash_insert(root->hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to insert new fetch profile [%s] into kazoo profile hash\n", name); - goto err; - } - } - - if (ptr) { - *ptr = profile; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "fetch handler profile %s successfully configured\n", name); - - return SWITCH_STATUS_SUCCESS; - - err: - /* Cleanup */ - if(pool) { - switch_core_destroy_memory_pool(&pool); - } - - return SWITCH_STATUS_GENERR; - -} - -switch_status_t kazoo_config_event_handler(kazoo_config_ptr definitions, kazoo_config_ptr root, switch_xml_t cfg, kazoo_event_profile_ptr *ptr) -{ - kazoo_event_profile_ptr profile = NULL; - switch_memory_pool_t *pool = NULL; - - char *name = (char *) switch_xml_attr_soft(cfg, "name"); - if (zstr(name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing name in profile\n"); - return SWITCH_STATUS_GENERR; - } - - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocation pool for new profile : %s\n", name); - return SWITCH_STATUS_GENERR; - } - - profile = switch_core_alloc(pool, sizeof(kazoo_event_profile_t)); - profile->pool = pool; - profile->root = root; - profile->name = switch_core_strdup(profile->pool, name); - - kazoo_config_filters(pool, cfg, &profile->filter); - kazoo_config_fields(definitions, pool, cfg, &profile->fields); - kazoo_config_events(definitions, pool, cfg, profile); - kazoo_config_loglevels(pool, cfg, &profile->logging); - - if(root) { - if ( switch_core_hash_insert(root->hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into kazoo profile hash\n", name); - goto err; - } - } - - if(ptr) - *ptr = profile; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "event handler profile %s successfully configured\n", name); - return SWITCH_STATUS_SUCCESS; - - err: - /* Cleanup */ - if(pool) { - switch_core_destroy_memory_pool(&pool); - } - return SWITCH_STATUS_GENERR; - -} - - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_ei_utils.c b/src/mod/event_handlers/mod_kazoo/kazoo_ei_utils.c deleted file mode 100644 index ef45af0ea3..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_ei_utils.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * Andrew Thompson - * Rob Charlton - * Karl Anderson - * - * Original from mod_erlang_event. - * ei_helpers.c -- helper functions for ei - * - */ -#include "mod_kazoo.h" - -/* Stolen from code added to ei in R12B-5. - * Since not everyone has this version yet; - * provide our own version. - * */ - -#define put8(s,n) do { \ - (s)[0] = (char)((n) & 0xff); \ - (s) += 1; \ - } while (0) - -#define put32be(s,n) do { \ - (s)[0] = ((n) >> 24) & 0xff; \ - (s)[1] = ((n) >> 16) & 0xff; \ - (s)[2] = ((n) >> 8) & 0xff; \ - (s)[3] = (n) & 0xff; \ - (s) += 4; \ - } while (0) - -#ifdef EI_DEBUG -static void ei_x_print_reg_msg(ei_x_buff *buf, char *dest, int send) { - char *mbuf = NULL; - int i = 1; - - ei_s_print_term(&mbuf, buf->buff, &i); - - if (send) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoded term %s to '%s'\n", mbuf, dest); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Decoded term %s for '%s'\n", mbuf, dest); - } - - free(mbuf); -} - -static void ei_x_print_msg(ei_x_buff *buf, erlang_pid *pid, int send) { - char *pbuf = NULL; - int i = 0; - ei_x_buff pidbuf; - - ei_x_new(&pidbuf); - ei_x_encode_pid(&pidbuf, pid); - - ei_s_print_term(&pbuf, pidbuf.buff, &i); - - ei_x_print_reg_msg(buf, pbuf, send); - free(pbuf); -} -#endif - -void ei_encode_switch_event_headers(ei_x_buff *ebuf, switch_event_t *event) -{ - ei_encode_switch_event_headers_2(ebuf, event, 1); -} - -void ei_encode_switch_event_headers_2(ei_x_buff *ebuf, switch_event_t *event, int encode) -{ - switch_event_header_t *hp; - char *uuid = switch_event_get_header(event, "unique-id"); - int i; - - for (i = 0, hp = event->headers; hp; hp = hp->next, i++) - ; - - if (event->body) - i++; - - ei_x_encode_list_header(ebuf, i + 1); - - if (uuid) { - char *unique_id = switch_event_get_header(event, "unique-id"); - ei_x_encode_binary(ebuf, unique_id, strlen(unique_id)); - } else { - ei_x_encode_atom(ebuf, "undefined"); - } - - for (hp = event->headers; hp; hp = hp->next) { - ei_x_encode_tuple_header(ebuf, 2); - ei_x_encode_binary(ebuf, hp->name, strlen(hp->name)); - if (encode) { - switch_url_decode(hp->value); - } - ei_x_encode_binary(ebuf, hp->value, strlen(hp->value)); - } - - if (event->body) { - ei_x_encode_tuple_header(ebuf, 2); - ei_x_encode_binary(ebuf, "body", strlen("body")); - ei_x_encode_binary(ebuf, event->body, strlen(event->body)); - } - - ei_x_encode_empty_list(ebuf); -} - -int ei_json_child_count(cJSON *JObj) -{ - int mask = cJSON_False | cJSON_True | cJSON_NULL | cJSON_Number | cJSON_String | cJSON_Array | cJSON_Object | cJSON_Raw; - - cJSON *item = JObj->child; - int i = 0; - while (item) { - if (item->type & mask) - i++; - item = item->next; - } - return i; - -} - -void ei_encode_json_array(ei_x_buff *ebuf, cJSON *JObj) -{ - cJSON *item; - int count = ei_json_child_count(JObj); - - ei_x_encode_list_header(ebuf, count); - if (count == 0) - return; - - item = JObj->child; - while (item) { - switch (item->type){ - case cJSON_String: - ei_x_encode_binary(ebuf, item->valuestring, strlen(item->valuestring)); - break; - - case cJSON_Number: - if ((fabs(((double) item->valueint) - item->valuedouble) <= DBL_EPSILON) && (item->valuedouble <= INT_MAX) && (item->valuedouble >= INT_MIN)) { - ei_x_encode_longlong(ebuf, item->valueint); - } else { - if (fmod(item->valuedouble, 1) == 0) { - ei_x_encode_ulonglong(ebuf, item->valuedouble); - } else { - ei_x_encode_double(ebuf, item->valuedouble); - } - } - break; - - case cJSON_True: - ei_x_encode_boolean(ebuf, 1); - break; - - case cJSON_False: - ei_x_encode_boolean(ebuf, 0); - break; - - case cJSON_Object: - ei_encode_json(ebuf, item); - break; - - case cJSON_Array: - ei_encode_json_array(ebuf, item); - break; - - case cJSON_Raw: { - cJSON *Decoded = cJSON_Parse(item->valuestring); - if (!Decoded) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR DECODING RAW JSON %s\n", item->valuestring); - ei_x_encode_tuple_header(ebuf, 0); - } else { - ei_encode_json(ebuf, Decoded); - cJSON_Delete(Decoded); - } - break; - } - - case cJSON_NULL: - ei_x_encode_atom(ebuf, "null"); - break; - - default: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NOT ENCODED %i\n", item->type); - break; - - } - item = item->next; - } - - ei_x_encode_empty_list(ebuf); - -} - -void ei_encode_json(ei_x_buff *ebuf, cJSON *JObj) -{ - cJSON *item; - int count = ei_json_child_count(JObj); - - if (kazoo_globals.json_encoding == ERLANG_TUPLE) { - ei_x_encode_tuple_header(ebuf, 1); - ei_x_encode_list_header(ebuf, count); - } else { - ei_x_encode_map_header(ebuf, count); - } - - if (count == 0) - return; - - item = JObj->child; - while (item) { - if (kazoo_globals.json_encoding == ERLANG_TUPLE) { - ei_x_encode_tuple_header(ebuf, 2); - } - ei_x_encode_binary(ebuf, item->string, strlen(item->string)); - - switch (item->type){ - case cJSON_String: - ei_x_encode_binary(ebuf, item->valuestring, strlen(item->valuestring)); - break; - - case cJSON_Number: - if ((fabs(((double) item->valueint) - item->valuedouble) <= DBL_EPSILON) && (item->valuedouble <= INT_MAX) && (item->valuedouble >= INT_MIN)) { - ei_x_encode_longlong(ebuf, item->valueint); - } else { - if (fmod(item->valuedouble, 1) == 0) { - ei_x_encode_ulonglong(ebuf, item->valuedouble); - } else { - ei_x_encode_double(ebuf, item->valuedouble); - } - } - break; - - case cJSON_True: - ei_x_encode_boolean(ebuf, 1); - break; - - case cJSON_False: - ei_x_encode_boolean(ebuf, 0); - break; - - case cJSON_Object: - ei_encode_json(ebuf, item); - break; - - case cJSON_Array: - ei_encode_json_array(ebuf, item); - break; - - case cJSON_Raw: { - cJSON *Decoded = cJSON_Parse(item->valuestring); - if (!Decoded) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR DECODING RAW JSON %s\n", item->valuestring); - ei_x_encode_tuple_header(ebuf, 0); - } else { - ei_encode_json(ebuf, Decoded); - cJSON_Delete(Decoded); - } - break; - } - - case cJSON_NULL: - ei_x_encode_atom(ebuf, "null"); - break; - - default: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NOT ENCODED %i\n", item->type); - break; - - } - item = item->next; - } - - if (kazoo_globals.json_encoding == ERLANG_TUPLE) { - ei_x_encode_empty_list(ebuf); - } - -} - -void close_socket(switch_socket_t ** sock) -{ - if (*sock) { - switch_socket_shutdown(*sock, SWITCH_SHUTDOWN_READWRITE); - switch_socket_close(*sock); - *sock = NULL; - } -} - -void close_socketfd(int *sockfd) -{ - if (*sockfd) { - shutdown(*sockfd, SHUT_RDWR); - close(*sockfd); - } -} - -switch_socket_t *create_socket_with_port(switch_memory_pool_t *pool, switch_port_t port) -{ - switch_sockaddr_t *sa; - switch_socket_t *socket; - - if (switch_sockaddr_info_get(&sa, kazoo_globals.ip, SWITCH_UNSPEC, port, 0, pool)) { - return NULL; - } - - if (switch_socket_create(&socket, switch_sockaddr_get_family(sa), SOCK_STREAM, SWITCH_PROTO_TCP, pool)) { - return NULL; - } - - if (switch_socket_opt_set(socket, SWITCH_SO_REUSEADDR, 1)) { - return NULL; - } - - if (switch_socket_bind(socket, sa)) { - return NULL; - } - - if (switch_socket_listen(socket, 5)) { - return NULL; - } - - if (kazoo_globals.nat_map && switch_nat_get_type()) { - switch_nat_add_mapping(port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE); - } - - return socket; -} - -switch_socket_t *create_socket(switch_memory_pool_t *pool) -{ - return create_socket_with_port(pool, 0); - -} - -switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei_cnode_s *ei_cnode) -{ - char hostname[EI_MAXHOSTNAMELEN + 1]; - char nodename[MAXNODELEN + 1]; - char cnodename[EI_MAXALIVELEN + 1]; - char *atsign; - - /* copy the erlang interface nodename into something we can modify */ - strncpy(cnodename, name, EI_MAXALIVELEN); - - if ((atsign = strchr(cnodename, '@'))) { - /* we got a qualified node name, don't guess the host/domain */ - snprintf(nodename, MAXNODELEN + 1, "%s", name); - /* truncate the alivename at the @ */ - *atsign++ = '\0'; - strncpy(hostname, atsign, EI_MAXHOSTNAMELEN); - } else { - strncpy(hostname, kazoo_globals.hostname, EI_MAXHOSTNAMELEN); - snprintf(nodename, MAXNODELEN + 1, "%s@%s", name, hostname); - } - - if (kazoo_globals.ei_shortname) { - char *off; - if ((off = strchr(nodename, '.'))) { - *off = '\0'; - } - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "creating nodename: %s\n", nodename); - - /* init the ec stuff */ - if (ei_connect_xinit(ei_cnode, hostname, cnodename, nodename, (Erl_IpAddr) ip_addr, kazoo_globals.ei_cookie, 0) < 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to initialize the erlang interface connection structure\n"); - return SWITCH_STATUS_FALSE; - } - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t ei_compare_pids(const erlang_pid *pid1, const erlang_pid *pid2) -{ - if ((!strcmp(pid1->node, pid2->node)) && pid1->creation == pid2->creation && pid1->num == pid2->num && pid1->serial == pid2->serial) { - return SWITCH_STATUS_SUCCESS; - } else { - return SWITCH_STATUS_FALSE; - } -} - -void ei_link(ei_node_t *ei_node, erlang_pid * from, erlang_pid * to) -{ - char msgbuf[2048]; - char *s; - int index = 0; - - index = 5; /* max sizes: */ - ei_encode_version(msgbuf, &index); /* 1 */ - ei_encode_tuple_header(msgbuf, &index, 3); - ei_encode_long(msgbuf, &index, ERL_LINK); - ei_encode_pid(msgbuf, &index, from); /* 268 */ - ei_encode_pid(msgbuf, &index, to); /* 268 */ - - /* 5 byte header missing */ - s = msgbuf; - put32be(s, index - 4); /* 4 */ - put8(s, ERL_PASS_THROUGH); /* 1 */ - /* sum: 542 */ - - if (write(ei_node->nodefd, msgbuf, index) == -1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to link to process on %s\n", ei_node->peer_nodename); - } -} - -void ei_encode_switch_event(ei_x_buff *ebuf, switch_event_t *event) -{ - ei_x_encode_tuple_header(ebuf, 2); - ei_x_encode_atom(ebuf, "event"); - ei_encode_switch_event_headers(ebuf, event); -} - -int ei_helper_send(ei_node_t *ei_node, erlang_pid *to, ei_x_buff *buf) -{ - int ret = 0; - - if (ei_node->nodefd) { -#ifdef EI_DEBUG - ei_x_print_msg(buf, to, 1); -#endif - ret = ei_send(ei_node->nodefd, to, buf->buff, buf->index); - } - - return ret; -} - -int ei_decode_atom_safe(char *buf, int *index, char *dst) -{ - int type, size; - - ei_get_type(buf, index, &type, &size); - - if (type != ERL_ATOM_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected erlang term type %d (size %d), needed atom\n", type, size); - return -1; - } else if (size > MAXATOMLEN) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested decoding of atom with size %d into a buffer of size %d\n", size, MAXATOMLEN); - return -1; - } else { - return ei_decode_atom(buf, index, dst); - } -} - -int ei_decode_string_or_binary(char *buf, int *index, char **dst) -{ - int type, size, res; - long len; - - ei_get_type(buf, index, &type, &size); - - if (type != ERL_STRING_EXT && type != ERL_BINARY_EXT && type != ERL_LIST_EXT && type != ERL_NIL_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected erlang term type %d (size %d), needed binary or string\n", type, size); - return -1; - } - - *dst = malloc(size + 1); - - if (type == ERL_NIL_EXT) { - res = 0; - **dst = '\0'; - } else if (type == ERL_BINARY_EXT) { - res = ei_decode_binary(buf, index, *dst, &len); - (*dst)[len] = '\0'; - } else { - res = ei_decode_string(buf, index, *dst); - } - - return res; -} - -int ei_decode_string_or_binary_limited(char *buf, int *index, int maxsize, char *dst) -{ - int type, size, res; - long len; - - ei_get_type(buf, index, &type, &size); - - if (type != ERL_STRING_EXT && type != ERL_BINARY_EXT && type != ERL_LIST_EXT && type != ERL_NIL_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected erlang term type %d (size %d), needed binary or string\n", type, size); - return -1; - } - - if (size > maxsize) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested decoding of %s with size %d into a buffer of size %d\n", - type == ERL_BINARY_EXT ? "binary" : "string", size, maxsize); - return -1; - } - - if (type == ERL_NIL_EXT) { - res = 0; - *dst = '\0'; - } else if (type == ERL_BINARY_EXT) { - res = ei_decode_binary(buf, index, dst, &len); - dst[len] = '\0'; /* binaries aren't null terminated */ - } else { - res = ei_decode_string(buf, index, dst); - } - - return res; -} - -switch_status_t create_acceptor() -{ - switch_sockaddr_t *sa; - uint16_t port; - char ipbuf[48]; - const char *ip_addr; - - /* if the config has specified an erlang release compatibility then pass that along to the erlang interface */ - if (kazoo_globals.ei_compat_rel) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Compatability with OTP R%d requested\n", kazoo_globals.ei_compat_rel); - ei_set_compat_rel(kazoo_globals.ei_compat_rel); - } - - if (!(kazoo_globals.acceptor = create_socket_with_port(kazoo_globals.pool, kazoo_globals.port))) { - return SWITCH_STATUS_SOCKERR; - } - - switch_socket_addr_get(&sa, SWITCH_FALSE, kazoo_globals.acceptor); - - port = switch_sockaddr_get_port(sa); - ip_addr = switch_get_addr(ipbuf, sizeof(ipbuf), sa); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Erlang connection acceptor listening on %s:%u\n", ip_addr, port); - - /* try to initialize the erlang interface */ - if (create_ei_cnode(ip_addr, kazoo_globals.ei_nodename, &kazoo_globals.ei_cnode) != SWITCH_STATUS_SUCCESS) { - return SWITCH_STATUS_SOCKERR; - } - - /* tell the erlang port manager where we can be reached. this returns a file descriptor pointing to epmd or -1 */ - if ((kazoo_globals.epmdfd = ei_publish(&kazoo_globals.ei_cnode, port)) == -1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to publish port to epmd, trying to start epmd via system()\n"); - if (system("fs_epmd -daemon")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - "Failed to start epmd manually! Is epmd in $PATH? If not, start it yourself or run an erl shell with -sname or -name\n"); - return SWITCH_STATUS_SOCKERR; - } - switch_yield(100000); - if ((kazoo_globals.epmdfd = ei_publish(&kazoo_globals.ei_cnode, port)) == -1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to publish port to epmd AGAIN\n"); - return SWITCH_STATUS_SOCKERR; - } - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to epmd and published erlang cnode name %s at port %d\n", kazoo_globals.ei_cnode.thisnodename, - port); - - return SWITCH_STATUS_SUCCESS; -} - -switch_hash_t *create_default_filter() -{ - switch_hash_t *filter; - - switch_core_hash_init(&filter); - - switch_core_hash_insert(filter, "Acquired-UUID", "1"); - switch_core_hash_insert(filter, "action", "1"); - switch_core_hash_insert(filter, "Action", "1"); - switch_core_hash_insert(filter, "alt_event_type", "1"); - switch_core_hash_insert(filter, "Answer-State", "1"); - switch_core_hash_insert(filter, "Application", "1"); - switch_core_hash_insert(filter, "Application-Data", "1"); - switch_core_hash_insert(filter, "Application-Name", "1"); - switch_core_hash_insert(filter, "Application-Response", "1"); - switch_core_hash_insert(filter, "att_xfer_replaced_by", "1"); - switch_core_hash_insert(filter, "Auth-Method", "1"); - switch_core_hash_insert(filter, "Auth-Realm", "1"); - switch_core_hash_insert(filter, "Auth-User", "1"); - switch_core_hash_insert(filter, "Bridge-A-Unique-ID", "1"); - switch_core_hash_insert(filter, "Bridge-B-Unique-ID", "1"); - switch_core_hash_insert(filter, "Call-Direction", "1"); - switch_core_hash_insert(filter, "Caller-Callee-ID-Name", "1"); - switch_core_hash_insert(filter, "Caller-Callee-ID-Number", "1"); - switch_core_hash_insert(filter, "Caller-Caller-ID-Name", "1"); - switch_core_hash_insert(filter, "Caller-Caller-ID-Number", "1"); - switch_core_hash_insert(filter, "Caller-Screen-Bit", "1"); - switch_core_hash_insert(filter, "Caller-Privacy-Hide-Name", "1"); - switch_core_hash_insert(filter, "Caller-Privacy-Hide-Number", "1"); - switch_core_hash_insert(filter, "Caller-Context", "1"); - switch_core_hash_insert(filter, "Caller-Controls", "1"); - switch_core_hash_insert(filter, "Caller-Destination-Number", "1"); - switch_core_hash_insert(filter, "Caller-Dialplan", "1"); - switch_core_hash_insert(filter, "Caller-Network-Addr", "1"); - switch_core_hash_insert(filter, "Caller-Unique-ID", "1"); - switch_core_hash_insert(filter, "Call-ID", "1"); - switch_core_hash_insert(filter, "Channel-Call-State", "1"); - switch_core_hash_insert(filter, "Channel-Call-UUID", "1"); - switch_core_hash_insert(filter, "Channel-Presence-ID", "1"); - switch_core_hash_insert(filter, "Channel-State", "1"); - switch_core_hash_insert(filter, "Chat-Permissions", "1"); - switch_core_hash_insert(filter, "Conference-Name", "1"); - switch_core_hash_insert(filter, "Conference-Profile-Name", "1"); - switch_core_hash_insert(filter, "Conference-Unique-ID", "1"); - switch_core_hash_insert(filter, "contact", "1"); - switch_core_hash_insert(filter, "Detected-Tone", "1"); - switch_core_hash_insert(filter, "dialog_state", "1"); - switch_core_hash_insert(filter, "direction", "1"); - switch_core_hash_insert(filter, "Distributed-From", "1"); - switch_core_hash_insert(filter, "DTMF-Digit", "1"); - switch_core_hash_insert(filter, "DTMF-Duration", "1"); - switch_core_hash_insert(filter, "Event-Date-Timestamp", "1"); - switch_core_hash_insert(filter, "Event-Name", "1"); - switch_core_hash_insert(filter, "Event-Subclass", "1"); - switch_core_hash_insert(filter, "expires", "1"); - switch_core_hash_insert(filter, "Expires", "1"); - switch_core_hash_insert(filter, "Ext-SIP-IP", "1"); - switch_core_hash_insert(filter, "File", "1"); - switch_core_hash_insert(filter, "FreeSWITCH-Hostname", "1"); - switch_core_hash_insert(filter, "from", "1"); - switch_core_hash_insert(filter, "Hunt-Destination-Number", "1"); - switch_core_hash_insert(filter, "ip", "1"); - switch_core_hash_insert(filter, "Message-Account", "1"); - switch_core_hash_insert(filter, "metadata", "1"); - switch_core_hash_insert(filter, "old_node_channel_uuid", "1"); - switch_core_hash_insert(filter, "Other-Leg-Callee-ID-Name", "1"); - switch_core_hash_insert(filter, "Other-Leg-Callee-ID-Number", "1"); - switch_core_hash_insert(filter, "Other-Leg-Caller-ID-Name", "1"); - switch_core_hash_insert(filter, "Other-Leg-Caller-ID-Number", "1"); - switch_core_hash_insert(filter, "Other-Leg-Destination-Number", "1"); - switch_core_hash_insert(filter, "Other-Leg-Direction", "1"); - switch_core_hash_insert(filter, "Other-Leg-Unique-ID", "1"); - switch_core_hash_insert(filter, "Other-Leg-Channel-Name", "1"); - switch_core_hash_insert(filter, "Participant-Type", "1"); - switch_core_hash_insert(filter, "Path", "1"); - switch_core_hash_insert(filter, "profile_name", "1"); - switch_core_hash_insert(filter, "Profiles", "1"); - switch_core_hash_insert(filter, "proto-specific-event-name", "1"); - switch_core_hash_insert(filter, "Raw-Application-Data", "1"); - switch_core_hash_insert(filter, "realm", "1"); - switch_core_hash_insert(filter, "Resigning-UUID", "1"); - switch_core_hash_insert(filter, "set", "1"); - switch_core_hash_insert(filter, "sip_auto_answer", "1"); - switch_core_hash_insert(filter, "sip_auth_method", "1"); - switch_core_hash_insert(filter, "sip_from_host", "1"); - switch_core_hash_insert(filter, "sip_from_user", "1"); - switch_core_hash_insert(filter, "sip_to_host", "1"); - switch_core_hash_insert(filter, "sip_to_user", "1"); - switch_core_hash_insert(filter, "sub-call-id", "1"); - switch_core_hash_insert(filter, "technology", "1"); - switch_core_hash_insert(filter, "to", "1"); - switch_core_hash_insert(filter, "Unique-ID", "1"); - switch_core_hash_insert(filter, "URL", "1"); - switch_core_hash_insert(filter, "username", "1"); - switch_core_hash_insert(filter, "variable_channel_is_moving", "1"); - switch_core_hash_insert(filter, "variable_collected_digits", "1"); - switch_core_hash_insert(filter, "variable_current_application", "1"); - switch_core_hash_insert(filter, "variable_current_application_data", "1"); - switch_core_hash_insert(filter, "variable_domain_name", "1"); - switch_core_hash_insert(filter, "variable_effective_caller_id_name", "1"); - switch_core_hash_insert(filter, "variable_effective_caller_id_number", "1"); - switch_core_hash_insert(filter, "variable_holding_uuid", "1"); - switch_core_hash_insert(filter, "variable_hold_music", "1"); - switch_core_hash_insert(filter, "variable_media_group_id", "1"); - switch_core_hash_insert(filter, "variable_originate_disposition", "1"); - switch_core_hash_insert(filter, "variable_origination_uuid", "1"); - switch_core_hash_insert(filter, "variable_playback_terminator_used", "1"); - switch_core_hash_insert(filter, "variable_presence_id", "1"); - switch_core_hash_insert(filter, "variable_record_ms", "1"); - switch_core_hash_insert(filter, "variable_recovered", "1"); - switch_core_hash_insert(filter, "variable_silence_hits_exhausted", "1"); - switch_core_hash_insert(filter, "variable_sip_auth_realm", "1"); - switch_core_hash_insert(filter, "variable_sip_from_host", "1"); - switch_core_hash_insert(filter, "variable_sip_from_user", "1"); - switch_core_hash_insert(filter, "variable_sip_from_tag", "1"); - switch_core_hash_insert(filter, "variable_sip_h_X-AUTH-IP", "1"); - switch_core_hash_insert(filter, "variable_sip_received_ip", "1"); - switch_core_hash_insert(filter, "variable_sip_to_host", "1"); - switch_core_hash_insert(filter, "variable_sip_to_user", "1"); - switch_core_hash_insert(filter, "variable_sip_to_tag", "1"); - switch_core_hash_insert(filter, "variable_sofia_profile_name", "1"); - switch_core_hash_insert(filter, "variable_transfer_history", "1"); - switch_core_hash_insert(filter, "variable_user_name", "1"); - switch_core_hash_insert(filter, "variable_endpoint_disposition", "1"); - switch_core_hash_insert(filter, "variable_originate_disposition", "1"); - switch_core_hash_insert(filter, "variable_bridge_hangup_cause", "1"); - switch_core_hash_insert(filter, "variable_hangup_cause", "1"); - switch_core_hash_insert(filter, "variable_last_bridge_proto_specific_hangup_cause", "1"); - switch_core_hash_insert(filter, "variable_proto_specific_hangup_cause", "1"); - switch_core_hash_insert(filter, "VM-Call-ID", "1"); - switch_core_hash_insert(filter, "VM-sub-call-id", "1"); - switch_core_hash_insert(filter, "whistle_application_name", "1"); - switch_core_hash_insert(filter, "whistle_application_response", "1"); - switch_core_hash_insert(filter, "whistle_event_name", "1"); - switch_core_hash_insert(filter, "kazoo_application_name", "1"); - switch_core_hash_insert(filter, "kazoo_application_response", "1"); - switch_core_hash_insert(filter, "kazoo_event_name", "1"); - switch_core_hash_insert(filter, "sip_auto_answer_notify", "1"); - switch_core_hash_insert(filter, "eavesdrop_group", "1"); - switch_core_hash_insert(filter, "origination_caller_id_name", "1"); - switch_core_hash_insert(filter, "origination_caller_id_number", "1"); - switch_core_hash_insert(filter, "origination_callee_id_name", "1"); - switch_core_hash_insert(filter, "origination_callee_id_number", "1"); - switch_core_hash_insert(filter, "sip_auth_username", "1"); - switch_core_hash_insert(filter, "sip_auth_password", "1"); - switch_core_hash_insert(filter, "effective_caller_id_name", "1"); - switch_core_hash_insert(filter, "effective_caller_id_number", "1"); - switch_core_hash_insert(filter, "effective_callee_id_name", "1"); - switch_core_hash_insert(filter, "effective_callee_id_number", "1"); - switch_core_hash_insert(filter, "variable_destination_number", "1"); - switch_core_hash_insert(filter, "variable_effective_callee_id_name", "1"); - switch_core_hash_insert(filter, "variable_effective_callee_id_number", "1"); - switch_core_hash_insert(filter, "variable_record_silence_hits", "1"); - switch_core_hash_insert(filter, "variable_refer_uuid", "1"); - switch_core_hash_insert(filter, "variable_sip_call_id", "1"); - switch_core_hash_insert(filter, "variable_sip_h_Referred-By", "1"); - switch_core_hash_insert(filter, "variable_sip_h_X-AUTH-PORT", "1"); - switch_core_hash_insert(filter, "variable_sip_loopback_req_uri", "1"); - switch_core_hash_insert(filter, "variable_sip_received_port", "1"); - switch_core_hash_insert(filter, "variable_sip_refer_to", "1"); - switch_core_hash_insert(filter, "variable_sip_req_host", "1"); - switch_core_hash_insert(filter, "variable_sip_req_uri", "1"); - switch_core_hash_insert(filter, "variable_transfer_source", "1"); - switch_core_hash_insert(filter, "variable_uuid", "1"); - - /* Registration headers */ - switch_core_hash_insert(filter, "call-id", "1"); - switch_core_hash_insert(filter, "profile-name", "1"); - switch_core_hash_insert(filter, "from-user", "1"); - switch_core_hash_insert(filter, "from-host", "1"); - switch_core_hash_insert(filter, "presence-hosts", "1"); - switch_core_hash_insert(filter, "contact", "1"); - switch_core_hash_insert(filter, "rpid", "1"); - switch_core_hash_insert(filter, "status", "1"); - switch_core_hash_insert(filter, "expires", "1"); - switch_core_hash_insert(filter, "to-user", "1"); - switch_core_hash_insert(filter, "to-host", "1"); - switch_core_hash_insert(filter, "network-ip", "1"); - switch_core_hash_insert(filter, "network-port", "1"); - switch_core_hash_insert(filter, "username", "1"); - switch_core_hash_insert(filter, "realm", "1"); - switch_core_hash_insert(filter, "user-agent", "1"); - - switch_core_hash_insert(filter, "Hangup-Cause", "1"); - switch_core_hash_insert(filter, "Unique-ID", "1"); - switch_core_hash_insert(filter, "variable_switch_r_sdp", "1"); - switch_core_hash_insert(filter, "variable_rtp_local_sdp_str", "1"); - switch_core_hash_insert(filter, "variable_sip_to_uri", "1"); - switch_core_hash_insert(filter, "variable_sip_from_uri", "1"); - switch_core_hash_insert(filter, "variable_sip_user_agent", "1"); - switch_core_hash_insert(filter, "variable_duration", "1"); - switch_core_hash_insert(filter, "variable_billsec", "1"); - switch_core_hash_insert(filter, "variable_billmsec", "1"); - switch_core_hash_insert(filter, "variable_progresssec", "1"); - switch_core_hash_insert(filter, "variable_progress_uepoch", "1"); - switch_core_hash_insert(filter, "variable_progress_media_uepoch", "1"); - switch_core_hash_insert(filter, "variable_start_uepoch", "1"); - switch_core_hash_insert(filter, "variable_digits_dialed", "1"); - switch_core_hash_insert(filter, "Member-ID", "1"); - switch_core_hash_insert(filter, "Floor", "1"); - switch_core_hash_insert(filter, "Video", "1"); - switch_core_hash_insert(filter, "Hear", "1"); - switch_core_hash_insert(filter, "Speak", "1"); - switch_core_hash_insert(filter, "Talking", "1"); - switch_core_hash_insert(filter, "Current-Energy", "1"); - switch_core_hash_insert(filter, "Energy-Level", "1"); - switch_core_hash_insert(filter, "Mute-Detect", "1"); - - /* RTMP headers */ - switch_core_hash_insert(filter, "RTMP-Session-ID", "1"); - switch_core_hash_insert(filter, "RTMP-Profile", "1"); - switch_core_hash_insert(filter, "RTMP-Flash-Version", "1"); - switch_core_hash_insert(filter, "RTMP-SWF-URL", "1"); - switch_core_hash_insert(filter, "RTMP-TC-URL", "1"); - switch_core_hash_insert(filter, "RTMP-Page-URL", "1"); - switch_core_hash_insert(filter, "User", "1"); - switch_core_hash_insert(filter, "Domain", "1"); - - /* Fax headers */ - switch_core_hash_insert(filter, "variable_fax_bad_rows", "1"); - switch_core_hash_insert(filter, "variable_fax_document_total_pages", "1"); - switch_core_hash_insert(filter, "variable_fax_document_transferred_pages", "1"); - switch_core_hash_insert(filter, "variable_fax_ecm_used", "1"); - switch_core_hash_insert(filter, "variable_fax_result_code", "1"); - switch_core_hash_insert(filter, "variable_fax_result_text", "1"); - switch_core_hash_insert(filter, "variable_fax_success", "1"); - switch_core_hash_insert(filter, "variable_fax_transfer_rate", "1"); - switch_core_hash_insert(filter, "variable_fax_local_station_id", "1"); - switch_core_hash_insert(filter, "variable_fax_remote_station_id", "1"); - switch_core_hash_insert(filter, "variable_fax_remote_country", "1"); - switch_core_hash_insert(filter, "variable_fax_remote_vendor", "1"); - switch_core_hash_insert(filter, "variable_fax_remote_model", "1"); - switch_core_hash_insert(filter, "variable_fax_image_resolution", "1"); - switch_core_hash_insert(filter, "variable_fax_file_image_resolution", "1"); - switch_core_hash_insert(filter, "variable_fax_image_size", "1"); - switch_core_hash_insert(filter, "variable_fax_image_pixel_size", "1"); - switch_core_hash_insert(filter, "variable_fax_file_image_pixel_size", "1"); - switch_core_hash_insert(filter, "variable_fax_longest_bad_row_run", "1"); - switch_core_hash_insert(filter, "variable_fax_encoding", "1"); - switch_core_hash_insert(filter, "variable_fax_encoding_name", "1"); - switch_core_hash_insert(filter, "variable_fax_header", "1"); - switch_core_hash_insert(filter, "variable_fax_ident", "1"); - switch_core_hash_insert(filter, "variable_fax_timezone", "1"); - switch_core_hash_insert(filter, "variable_fax_doc_id", "1"); - switch_core_hash_insert(filter, "variable_fax_doc_database", "1"); - switch_core_hash_insert(filter, "variable_has_t38", "1"); - - /* Secure headers */ - switch_core_hash_insert(filter, "variable_sdp_secure_savp_only", "1"); - switch_core_hash_insert(filter, "variable_rtp_has_crypto", "1"); - switch_core_hash_insert(filter, "variable_rtp_secure_media", "1"); - switch_core_hash_insert(filter, "variable_rtp_secure_media_confirmed", "1"); - switch_core_hash_insert(filter, "variable_rtp_secure_media_confirmed_audio", "1"); - switch_core_hash_insert(filter, "variable_rtp_secure_media_confirmed_video", "1"); - switch_core_hash_insert(filter, "sdp_secure_savp_only", "1"); - switch_core_hash_insert(filter, "rtp_has_crypto", "1"); - switch_core_hash_insert(filter, "rtp_secure_media", "1"); - switch_core_hash_insert(filter, "rtp_secure_media_confirmed", "1"); - switch_core_hash_insert(filter, "rtp_secure_media_confirmed_audio", "1"); - switch_core_hash_insert(filter, "rtp_secure_media_confirmed_video", "1"); - - /* Device Redirect headers */ - switch_core_hash_insert(filter, "variable_last_bridge_hangup_cause", "1"); - switch_core_hash_insert(filter, "variable_sip_redirected_by", "1"); - switch_core_hash_insert(filter, "intercepted_by", "1"); - switch_core_hash_insert(filter, "variable_bridge_uuid", "1"); - switch_core_hash_insert(filter, "Record-File-Path", "1"); - - /* Loopback headers */ - switch_core_hash_insert(filter, "variable_loopback_bowout_on_execute", "1"); - switch_core_hash_insert(filter, "variable_loopback_bowout", "1"); - switch_core_hash_insert(filter, "variable_other_loopback_leg_uuid", "1"); - switch_core_hash_insert(filter, "variable_loopback_leg", "1"); - switch_core_hash_insert(filter, "variable_is_loopback", "1"); - - // SMS - switch_core_hash_insert(filter, "Message-ID", "1"); - switch_core_hash_insert(filter, "Delivery-Failure", "1"); - switch_core_hash_insert(filter, "Delivery-Result-Code", "1"); - - return filter; -} - -static void fetch_config_filters(switch_memory_pool_t *pool) -{ - char *cf = "kazoo.conf"; - switch_xml_t cfg, xml, child, param; - switch_event_t *params; - - switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Action", "request-filter"); - - if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open configuration file %s\n", cf); - } else { - if ((child = switch_xml_child(cfg, "event-filter"))) { - switch_hash_t *filter; - switch_hash_t *old_filter; - - switch_core_hash_init(&filter); - for (param = switch_xml_child(child, "header"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - switch_core_hash_insert(filter, var, "1"); - } - - old_filter = kazoo_globals.event_filter; - kazoo_globals.event_filter = filter; - if (old_filter) { - switch_core_hash_destroy(&old_filter); - } - } - - kazoo_globals.config_fetched = 1; - switch_xml_free(xml); - } - switch_event_destroy(¶ms); - -} - -static void fetch_config_handlers(switch_memory_pool_t *pool) -{ - char *cf = "kazoo.conf"; - switch_xml_t cfg, xml; - switch_event_t *params; - - switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Action", "request-handlers"); - - if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open configuration file %s\n", cf); - } else { - kazoo_config_handlers(cfg); - kazoo_globals.config_fetched = 1; - switch_xml_free(xml); - } - switch_event_destroy(¶ms); - -} - -static void *SWITCH_THREAD_FUNC fetch_config_exec(switch_thread_t *thread, void *obj) -{ - switch_memory_pool_t *pool = (switch_memory_pool_t *) obj; - ei_node_t *node; - int fetch_filters = 0, fetch_handlers = 0; - - // give some time for node initialization - switch_sleep(kazoo_globals.delay_before_initial_fetch); - - for (node = kazoo_globals.ei_nodes; node != NULL; node = node->next) { - if (node->legacy ) { - fetch_filters++; - } else { - fetch_handlers++; - } - } - - if (fetch_filters) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "fetching filters for kazoo\n"); - fetch_config_filters(pool); - } - - if (fetch_handlers) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "fetching kazoo handlers\n"); - fetch_config_handlers(pool); - } - - kazoo_globals.config_fetched = 1; - - return NULL; -} - -void fetch_config() -{ - switch_memory_pool_t *pool; - switch_thread_t *thread; - switch_threadattr_t *thd_attr = NULL; - switch_uuid_t uuid; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "scheduling fetch for kazoo config\n"); - - switch_core_new_memory_pool(&pool); - - switch_threadattr_create(&thd_attr, pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - - switch_uuid_get(&uuid); - switch_thread_create(&thread, thd_attr, fetch_config_exec, pool, pool); - -} - -#ifdef WITH_KAZOO_ERL_SHUTDOWN -#if (ERLANG_MAJOR == 10 && ERLANG_MINOR >= 3) || ERLANG_MAJOR >= 11 -typedef struct ei_mutex_s { -#ifdef __WIN32__ - HANDLE lock; -#elif VXWORKS - SEM_ID lock; -#else /* unix */ -#if defined(HAVE_MIT_PTHREAD_H) || defined(HAVE_PTHREAD_H) - pthread_mutex_t *lock; -#else /* ! (HAVE_MIT_PTHREAD_H || HAVE_PTHREAD_H) */ - void *dummy; /* Actually never used */ -#endif /* ! (HAVE_MIT_PTHREAD_H || HAVE_PTHREAD_H) */ -#endif /* unix */ -}ei_mutex_t; - -typedef struct ei_socket_info_s { - int socket; - ei_socket_callbacks *cbs; - void *ctx; - int dist_version; - ei_cnode cnode; /* A copy, not a pointer. We don't know when freed */ - char cookie[EI_MAX_COOKIE_SIZE+1]; -}ei_socket_info; - -extern ei_socket_info *ei_sockets; -extern ei_mutex_t* ei_sockets_lock; -extern int ei_n_sockets; -extern int ei_sz_sockets; - -int ei_mutex_free(ei_mutex_t *l, int nblock); - -#endif -#endif - -void kz_erl_init() -{ -#if (ERLANG_MAJOR == 10 && ERLANG_MINOR >= 3) || ERLANG_MAJOR >= 11 - ei_init(); -#endif -} - -void kz_erl_shutdown() -{ -#ifdef WITH_KAZOO_ERL_SHUTDOWN -#if (ERLANG_MAJOR == 10 && ERLANG_MINOR >= 3) || ERLANG_MAJOR >= 11 - ei_mutex_free(ei_sockets_lock, 1); - ei_sockets_lock = NULL; - free(ei_sockets); - ei_sockets = NULL; - ei_n_sockets = ei_sz_sockets = 0; -#endif -#endif -} - -SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime) -{ - switch_os_socket_t os_socket; - - if (create_acceptor() != SWITCH_STATUS_SUCCESS) { - // TODO: what would we need to clean up here - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create erlang connection acceptor!\n"); - close_socket(&kazoo_globals.acceptor); - return SWITCH_STATUS_TERM; - } - - switch_atomic_inc(&kazoo_globals.threads); - switch_os_sock_get(&os_socket, kazoo_globals.acceptor); - - while (switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - int nodefd; - ErlConnect conn; - - /* zero out errno because ei_accept doesn't differentiate between a */ - /* failed authentication or a socket failure, or a client version */ - /* mismatch or a godzilla attack (and a godzilla attack is highly likely) */ - errno = 0; - - /* wait here for an erlang node to connect, timming out to check if our module is still running every now-and-again */ - if ((nodefd = ei_accept_tmo(&kazoo_globals.ei_cnode, (int) os_socket, &conn, kazoo_globals.connection_timeout)) == ERL_ERROR) { - if (erl_errno == ETIMEDOUT) { - continue; - } else if (errno) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Erlang connection acceptor socket error %d %d\n", erl_errno, errno); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, - "Erlang node connection failed - ensure your cookie matches '%s' and you are using a good nodename\n", kazoo_globals.ei_cookie); - } - continue; - } - - if (!switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - break; - } - - /* NEW ERLANG NODE CONNECTION! Hello friend! */ - new_kazoo_node(nodefd, &conn); - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Erlang connection acceptor shut down\n"); - - switch_atomic_dec(&kazoo_globals.threads); - - return SWITCH_STATUS_TERM; -} - -SWITCH_DECLARE(switch_status_t) ei_queue_pop(switch_queue_t *queue, void **data, switch_interval_time_t timeout) -{ - if (timeout == 0) { - return switch_queue_trypop(queue, data); - } else { - return switch_queue_pop_timeout(queue, data, timeout); - } -} -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_endpoints.c b/src/mod/event_handlers/mod_kazoo/kazoo_endpoints.c deleted file mode 100644 index 4ddfeddae4..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_endpoints.c +++ /dev/null @@ -1,500 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * kazoo_dptools.c -- clones of mod_dptools commands slightly modified for kazoo - * - */ -#include "mod_kazoo.h" - -#define INTERACTION_VARIABLE "Call-Interaction-ID" - -static const char *x_bridge_variables[] = { - "Call-Control-Queue", - "Call-Control-PID", - "Call-Control-Node", - INTERACTION_VARIABLE, - "ecallmgr_Ecallmgr-Node", - "sip_h_k-cid", - "Switch-URI", - "Switch-URL", - NULL -}; - -static void kz_tweaks_variables_to_event(switch_core_session_t *session, switch_event_t *event) -{ - int i; - switch_channel_t *channel = switch_core_session_get_channel(session); - for(i = 0; x_bridge_variables[i] != NULL; i++) { - const char *val = switch_channel_get_variable_dup(channel, x_bridge_variables[i], SWITCH_FALSE, -1); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, x_bridge_variables[i], val); - } -} - -static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *session, - switch_event_t *var_event, - switch_caller_profile_t *outbound_profile_in, - switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, - switch_call_cause_t *cancel_cause) -{ - switch_xml_t x_user = NULL, x_param, x_params, x_callfwd; - char *user = NULL, *domain = NULL, *dup_domain = NULL, *dialed_user = NULL; - char *dest = NULL; - switch_call_cause_t cause = SWITCH_CAUSE_NONE; - unsigned int timelimit = SWITCH_DEFAULT_TIMEOUT; - switch_channel_t *new_channel = NULL; - switch_event_t *params = NULL, *var_event_orig = var_event; - char stupid[128] = ""; - const char *skip = NULL, *var = NULL; - switch_core_session_t *a_session = NULL, *e_session = NULL; - cJSON * ctx = NULL; - const char *endpoint_dial = NULL; - const char *callforward_dial = NULL; - const char *failover_dial = NULL; - char *b_failover_dial = NULL; - const char *endpoint_separator = NULL; - const char *varval = NULL; - char *d_dest = NULL; - switch_channel_t *channel = NULL; - switch_originate_flag_t myflags = SOF_NONE; - char *cid_name_override = NULL; - char *cid_num_override = NULL; - switch_event_t *event = NULL; - switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_caller_profile_t *outbound_profile = NULL; - - - if (zstr(outbound_profile_in->destination_number)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "NO DESTINATION NUMBER\n"); - goto done; - } - - user = strdup(outbound_profile_in->destination_number); - - if (!user) - goto done; - - if ((domain = strchr(user, '@'))) { - *domain++ = '\0'; - } else { - domain = switch_core_get_domain(SWITCH_TRUE); - dup_domain = domain; - } - - if (!domain) { - goto done; - } - - - switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS); - switch_assert(params); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "as_channel", "true"); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "user_call"); - if (session) { - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session)); - } - - if (var_event) { - switch_event_merge(params, var_event); - } - - if (var_event && (skip = switch_event_get_header(var_event, "user_recurse_variables")) && switch_false(skip)) { - if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var = switch_event_get_header(var_event, "leg_timeout"))) { - timelimit = atoi(var); - } - var_event = NULL; - } - - if (switch_xml_locate_user_merged("id", user, domain, NULL, &x_user, params) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", user, domain); - cause = SWITCH_CAUSE_SUBSCRIBER_ABSENT; - goto done; - } - - if (var_event) { - const char * str_ctx = switch_event_get_header(var_event, "kz-endpoint-runtime-context"); - if ( str_ctx ) { - ctx = cJSON_Parse(str_ctx); - if (ctx) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "call context parsed => %s\n", str_ctx); - } - } - } - - if ((x_params = switch_xml_child(x_user, "variables"))) { - for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr_soft(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "adding variable to var_event => %s = %s\n", pvar, val); - if (!var_event) { - switch_event_create(&var_event, SWITCH_EVENT_GENERAL); - } else { - switch_event_del_header(var_event, pvar); - } - switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, pvar, val); - } - } - - if ((x_params = switch_xml_child(x_user, "params"))) { - for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr_soft(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - - if (!strcasecmp(pvar, "endpoint-dial-string")) { - endpoint_dial = val; - } else if (!strcasecmp(pvar, "callforward-dial-string")) { - callforward_dial = val; - } else if (!strcasecmp(pvar, "endpoint-separator")) { - endpoint_separator = val; - } else if (!strncasecmp(pvar, "dial-var-", 9)) { - if (!var_event) { - switch_event_create(&var_event, SWITCH_EVENT_GENERAL); - } else { - switch_event_del_header(var_event, pvar + 9); - } - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "adding dialog var to var_event => %s = %s\n", pvar + 9, val); - switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, pvar + 9, val); - } - } - } - - x_callfwd = switch_xml_child(x_user, "call-forward"); - if (x_callfwd) { - switch_bool_t call_fwd_is_substitute = SWITCH_FALSE, - call_fwd_is_failover = SWITCH_FALSE, - call_fwd_direct_calls_only = SWITCH_FALSE, - call_fwd_is_valid = SWITCH_TRUE; - for (x_param = switch_xml_child(x_callfwd, "variable"); x_param; x_param = x_param->next) { - const char *var = switch_xml_attr_soft(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "cfw %s => %s\n", var, val); - if (!strcasecmp(var, "Is-Substitute")) { - call_fwd_is_substitute = switch_true(val); - } else if (!strcasecmp(var, "Is-Failover")) { - call_fwd_is_failover = switch_true(val); - } else if (!strcasecmp(var, "Direct-Calls-Only")) { - call_fwd_direct_calls_only = switch_true(val); - } - } - - if (call_fwd_direct_calls_only) { - call_fwd_is_valid = SWITCH_FALSE; - if (ctx ) { - cJSON *json_flags = cJSON_GetObjectItem(ctx, "Flags"); - if (json_flags && json_flags->type == cJSON_Array) { - cJSON *item; - cJSON_ArrayForEach(item, json_flags) { - if (!strcmp(item->valuestring, "direct_call")) { - call_fwd_is_valid = SWITCH_TRUE; - break; - } - } - if (!call_fwd_is_valid) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "call fwd requires direct_call and it was not found\n"); - } - } - } - } - - if (!call_fwd_is_valid) { - dest = endpoint_dial ? strdup(endpoint_dial) : strdup(""); - } else if (call_fwd_is_failover) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "setting failover => %s\n", callforward_dial); - dest = endpoint_dial ? strdup(endpoint_dial) : strdup(""); - failover_dial = callforward_dial; - } else if (call_fwd_is_substitute) { - dest = callforward_dial ? strdup(callforward_dial) : strdup(""); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "setting call fwd substitute => %s\n", dest); - } else { - dest = switch_mprintf("%s%s%s", endpoint_dial ? endpoint_dial : "", (endpoint_dial ? endpoint_separator ? endpoint_separator : "," : ""), callforward_dial); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "setting call fwd append => %s => %s\n", callforward_dial, dest); - } - } else { - dest = endpoint_dial ? strdup(endpoint_dial) : strdup(""); - } - - dialed_user = (char *)switch_xml_attr(x_user, "id"); - - if (var_event) { - switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "dialed_user", dialed_user); - switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "dialed_domain", domain); - } - - if (!dest) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No dial-string available, please check your user directory.\n"); - cause = SWITCH_CAUSE_MANDATORY_IE_MISSING; - goto done; - } - - if (var_event) { - cid_name_override = switch_event_get_header(var_event, "origination_caller_id_name"); - cid_num_override = switch_event_get_header(var_event, "origination_caller_id_number"); - } - - if(session) { - a_session = session; - } else if(var_event) { - const char* uuid_e_session = switch_event_get_header(var_event, "ent_originate_aleg_uuid"); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHECKING ORIGINATE-UUID : %s\n", uuid_e_session); - if (uuid_e_session && (e_session = switch_core_session_locate(uuid_e_session)) != NULL) { - a_session = e_session; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FOUND ORIGINATE-UUID : %s\n", uuid_e_session); - } - } - - if (a_session) { - switch_event_create(&event, SWITCH_EVENT_GENERAL); - channel = switch_core_session_get_channel(a_session); - if ((varval = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE)) - || (var_event && (varval = switch_event_get_header(var_event, "leg_timeout")))) { - timelimit = atoi(varval); - } - switch_channel_event_set_data(channel, event); - - switch_channel_set_variable(channel, "dialed_user", dialed_user); - switch_channel_set_variable(channel, "dialed_domain", domain); - - } else { - if (var_event) { - switch_event_dup(&event, var_event); - switch_event_del_header(event, "dialed_user"); - switch_event_del_header(event, "dialed_domain"); - if ((varval = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) || - (varval = switch_event_get_header(var_event, "leg_timeout"))) { - timelimit = atoi(varval); - } - } else { - switch_event_create(&event, SWITCH_EVENT_REQUEST_PARAMS); - switch_assert(event); - } - - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_user", dialed_user); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_domain", domain); - } - - if ((x_params = switch_xml_child(x_user, "profile-variables"))) { - for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr_soft(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "adding profile variable to event => %s = %s\n", pvar, val); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, pvar, val); - } - } - - if ((x_params = switch_xml_child(x_user, "variables"))) { - for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr_soft(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "adding variable to event => %s = %s\n", pvar, val); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, pvar, val); - } - } - - if ((x_params = switch_xml_child(x_user, "params"))) { - for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr_soft(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - - if (!strncasecmp(pvar, "dial-var-", 9)) { - switch_event_del_header(event, pvar + 9); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "adding dialog var to event => %s = %s\n", pvar + 9, val); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, pvar + 9, val); - } - } - } - - // add runtime vars to event for expand - if (ctx) { - kz_expand_json_to_event(ctx, event, "kz_ctx"); - } - - d_dest = kz_event_expand_headers(event, dest); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "dialing %s => %s\n", dest, d_dest); - - if(failover_dial) { - b_failover_dial = kz_event_expand_headers(event, failover_dial); - } - - if (var_event) { - kz_expand_headers(event, var_event); - } - - switch_event_destroy(&event); - - - if ((flags & SOF_NO_LIMITS)) { - myflags |= SOF_NO_LIMITS; - } - - if ((flags & SOF_FORKED_DIAL)) { - myflags |= SOF_NOBLOCK; - } - - if ( a_session ) { - if(var_event) { - kz_tweaks_variables_to_event(a_session, var_event); - } - } - - if(e_session) { - switch_core_session_rwunlock(e_session); - } - - switch_snprintf(stupid, sizeof(stupid), "kz/%s", dialed_user); - if (switch_stristr(stupid, d_dest)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Waddya Daft? You almost called '%s' in an infinate loop!\n", stupid); - cause = SWITCH_CAUSE_INVALID_IE_CONTENTS; - goto done; - } - - // - outbound_profile = outbound_profile_in; - /* - outbound_profile = switch_caller_profile_dup(outbound_profile_in->pool, outbound_profile_in); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "CHECKING CALLER-ID\n"); - if ((x_params = switch_xml_child(x_user, "profile-variables"))) { - const char* val = NULL; - outbound_profile->soft = NULL; - for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "setting profile var %s = %s\n", pvar, val); - switch_caller_profile_set_var(outbound_profile, pvar, val); - } - // * TODO * verify onnet/offnet - if((val=switch_caller_get_field_by_name(outbound_profile, "Endpoint-Caller-ID-Name"))) { - outbound_profile->callee_id_name = val; - outbound_profile->orig_caller_id_name = val; - } - if((val=switch_caller_get_field_by_name(outbound_profile, "Endpoint-Caller-ID-Number"))) { - outbound_profile->callee_id_number = val; - outbound_profile->orig_caller_id_number = val; - } - } - */ - - status = switch_ivr_originate(session, new_session, &cause, d_dest, timelimit, NULL, - cid_name_override, cid_num_override, outbound_profile, var_event, myflags, - cancel_cause, NULL); - - if (status != SWITCH_STATUS_SUCCESS && b_failover_dial) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "trying failover => %s\n", failover_dial); - status = switch_ivr_originate(session, new_session, &cause, b_failover_dial, timelimit, NULL, - cid_name_override, cid_num_override, outbound_profile, var_event, myflags, - cancel_cause, NULL); - } - - if (status == SWITCH_STATUS_SUCCESS) { - const char *context; - switch_caller_profile_t *cp; - - if (var_event) { - switch_event_del_header(var_event, "origination_uuid"); - } - - new_channel = switch_core_session_get_channel(*new_session); - - if ((context = switch_channel_get_variable(new_channel, "user_context"))) { - if ((cp = switch_channel_get_caller_profile(new_channel))) { - cp->context = switch_core_strdup(cp->pool, context); - } - } - - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "CHECKING CALLER-ID\n"); - if ((x_params = switch_xml_child(x_user, "profile-variables"))) { - switch_caller_profile_t *cp = switch_channel_get_caller_profile(new_channel); - const char* val = NULL; - cp->soft = NULL; - for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { - const char *pvar = switch_xml_attr(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "setting profile var %s = %s\n", pvar, val); - switch_channel_set_profile_var(new_channel, pvar, val); - //switch_caller_profile_set_var(cp, pvar, val); - } - // * TODO * verify onnet/offnet - if((val=switch_caller_get_field_by_name(cp, "Endpoint-Caller-ID-Name"))) { - cp->callee_id_name = val; - cp->orig_caller_id_name = val; - } - if((val=switch_caller_get_field_by_name(cp, "Endpoint-Caller-ID-Number"))) { - cp->callee_id_number = val; - cp->orig_caller_id_number = val; - } - } - switch_core_session_rwunlock(*new_session); - } - - done: - - if (d_dest && d_dest != dest) { - switch_safe_free(d_dest); - } - - if(b_failover_dial && b_failover_dial != failover_dial) { - switch_safe_free(b_failover_dial); - } - - switch_safe_free(dest); - - if (ctx) { - cJSON_Delete(ctx); - } - - if (x_user) { - switch_xml_free(x_user); - } - - if (params) { - switch_event_destroy(¶ms); - } - - if (var_event && var_event_orig != var_event) { - switch_event_destroy(&var_event); - } - - switch_safe_free(user); - switch_safe_free(dup_domain); - return cause; -} - - -/* kazoo endpoint */ - - -switch_io_routines_t kz_endpoint_io_routines = { - /*.outgoing_channel */ kz_endpoint_outgoing_channel -}; - -void add_kz_endpoints(switch_loadable_module_interface_t **module_interface) { - switch_endpoint_interface_t *kz_endpoint_interface; - kz_endpoint_interface = (switch_endpoint_interface_t *) switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); - kz_endpoint_interface->interface_name = "kz"; - kz_endpoint_interface->io_routines = &kz_endpoint_io_routines; -} diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c b/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c deleted file mode 100644 index 3d1f18326b..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c +++ /dev/null @@ -1,750 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * kazoo_event_streams.c -- Event Publisher - * - */ -#include "mod_kazoo.h" - -#define MAX_FRAMING 4 - -/* Blatantly repurposed from switch_eventc */ -static char *my_dup(const char *s) { - size_t len = strlen(s) + 1; - void *new = malloc(len); - switch_assert(new); - - return (char *) memcpy(new, s, len); -} - -#ifndef DUP -#define DUP(str) my_dup(str) -#endif - -static const char* private_headers[] = {"variable_sip_h_", "sip_h_", "P-", "X-"}; - -static int is_private_header(const char *name) { - int i; - for(i=0; i < 4; i++) { - if(!strncmp(name, private_headers[i], strlen(private_headers[i]))) { - return 1; - } - } - return 0; -} - -static int is_kazoo_var(char* header) -{ - int idx = 0; - while(kazoo_globals.kazoo_var_prefixes[idx] != NULL) { - char *prefix = kazoo_globals.kazoo_var_prefixes[idx]; - if(!strncasecmp(header, prefix, strlen(prefix))) { - return 1; - } - idx++; - } - - return 0; -} - -static switch_status_t kazoo_event_dup(switch_event_t **clone, switch_event_t *event, switch_hash_t *filter) { - switch_event_header_t *header; - - if (switch_event_create_subclass(clone, SWITCH_EVENT_CLONE, event->subclass_name) != SWITCH_STATUS_SUCCESS) { - return SWITCH_STATUS_GENERR; - } - - (*clone)->event_id = event->event_id; - (*clone)->event_user_data = event->event_user_data; - (*clone)->bind_user_data = event->bind_user_data; - (*clone)->flags = event->flags; - - for (header = event->headers; header; header = header->next) { - if (event->subclass_name && !strcmp(header->name, "Event-Subclass")) { - continue; - } - - if (!is_kazoo_var(header->name) - && filter - && !switch_core_hash_find(filter, header->name) - && (!kazoo_globals.send_all_headers) - && (!(kazoo_globals.send_all_private_headers && is_private_header(header->name))) - ) - { - continue; - } - - if (header->idx) { - int i; - for (i = 0; i < header->idx; i++) { - switch_event_add_header_string(*clone, SWITCH_STACK_PUSH, header->name, header->array[i]); - } - } else { - switch_event_add_header_string(*clone, SWITCH_STACK_BOTTOM, header->name, header->value); - } - } - - if (event->body) { - (*clone)->body = DUP(event->body); - } - - (*clone)->key = event->key; - - return SWITCH_STATUS_SUCCESS; -} - -static int encode_event_old(switch_event_t *event, ei_x_buff *ebuf) { - switch_event_t *clone = NULL; - - if (kazoo_event_dup(&clone, event, kazoo_globals.event_filter) != SWITCH_STATUS_SUCCESS) { - return 0; - } - - ei_encode_switch_event(ebuf, clone); - - switch_event_destroy(&clone); - - return 1; -} - -static int encode_event_new(switch_event_t *event, ei_x_buff *ebuf) { - kazoo_message_ptr msg = NULL; - ei_event_binding_t *event_binding = (ei_event_binding_t *) event->bind_user_data; - - msg = kazoo_message_create_event(event, event_binding->event, kazoo_globals.events); - - if(msg == NULL) { - return 0; - } - - ei_x_encode_tuple_header(ebuf, 3); - ei_x_encode_atom(ebuf, "event"); - if(kazoo_globals.json_encoding == ERLANG_TUPLE) { - ei_x_encode_atom(ebuf, "json"); - } else { - ei_x_encode_atom(ebuf, "map"); - } - ei_encode_json(ebuf, msg->JObj); - - kazoo_message_destroy(&msg); - - return 1; -} - -/* - * event_handler is duplicated when there are 2+ nodes connected - * with the same bindings - * we should maintain a list of event_streams in event_binding struct - * and build a ref count in the message - * - */ -static void event_handler(switch_event_t *event) { - ei_event_binding_t *event_binding = (ei_event_binding_t *) event->bind_user_data; - ei_event_stream_t *event_stream = event_binding->stream; - ei_x_buff *ebuf = NULL; - int res = 0; - - /* if mod_kazoo or the event stream isn't running dont push a new event */ - if (!switch_test_flag(event_stream, LFLAG_RUNNING) || !switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - return; - } - - kz_event_decode(event); - - switch_malloc(ebuf, sizeof(*ebuf)); - if(ebuf == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate erlang buffer for mod_kazoo message\n"); - return; - } - memset(ebuf, 0, sizeof(*ebuf)); - - if(kazoo_globals.event_stream_preallocate > 0) { - ebuf->buff = malloc(kazoo_globals.event_stream_preallocate); - ebuf->buffsz = kazoo_globals.event_stream_preallocate; - ebuf->index = 0; - if(ebuf->buff == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not pre-allocate memory for mod_kazoo message\n"); - switch_safe_free(ebuf); - return; - } - } else { - ei_x_new(ebuf); - } - - ebuf->index = MAX_FRAMING; - - ei_x_encode_version(ebuf); - - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Target-Node", event_binding->stream->node->peer_nodename); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Switch-Nodename", kazoo_globals.ei_cnode.thisnodename); - - if(event_stream->node->legacy) { - res = encode_event_old(event, ebuf); - } else { - res = encode_event_new(event, ebuf); - } - - switch_event_del_header(event, "Switch-Nodename"); - switch_event_del_header(event, "Target-Node"); - - if(!res) { - ei_x_free(ebuf); - switch_safe_free(ebuf); - return; - } - - if (kazoo_globals.event_stream_preallocate > 0 && ebuf->buffsz > kazoo_globals.event_stream_preallocate) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "increased event stream buffer size to %d\n", ebuf->buffsz); - } - - if (switch_queue_trypush(event_stream->queue, ebuf) != SWITCH_STATUS_SUCCESS) { - /* if we couldn't place the cloned event into the listeners */ - /* event queue make sure we destroy it, real good like */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error placing the event in the listeners queue\n"); - ei_x_free(ebuf); - switch_safe_free(ebuf); - } - -} - -static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void *obj) { - ei_event_stream_t *event_stream = (ei_event_stream_t *) obj; - ei_event_binding_t *event_binding; - switch_sockaddr_t *sa; - uint16_t port; - char ipbuf[48]; - const char *ip_addr; - void *pop; - short event_stream_framing; - short event_stream_keepalive; - short ok = 1; - - switch_atomic_inc(&kazoo_globals.threads); - - switch_assert(event_stream != NULL); - - event_stream_framing = event_stream->event_stream_framing; - event_stream_keepalive = event_stream->event_stream_keepalive; - - /* figure out what socket we just opened */ - switch_socket_addr_get(&sa, SWITCH_FALSE, event_stream->acceptor); - port = switch_sockaddr_get_port(sa); - ip_addr = switch_get_addr(ipbuf, sizeof(ipbuf), sa); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting erlang event stream %p on %s:%u for %s <%d.%d.%d>\n" - ,(void *)event_stream, ip_addr, port, event_stream->pid.node, event_stream->pid.creation - ,event_stream->pid.num, event_stream->pid.serial); - - while (switch_test_flag(event_stream, LFLAG_RUNNING) && switch_test_flag(&kazoo_globals, LFLAG_RUNNING) && ok) { - const switch_pollfd_t *fds; - int32_t numfds; - - /* check if a new connection is pending */ - if (switch_pollset_poll(event_stream->pollset, 0, &numfds, &fds) == SWITCH_STATUS_SUCCESS) { - int32_t i; - for (i = 0; i < numfds; i++) { - switch_socket_t *newsocket; - - /* accept the new client connection */ - if (switch_socket_accept(&newsocket, event_stream->acceptor, event_stream->pool) == SWITCH_STATUS_SUCCESS) { - switch_sockaddr_t *sa; - - if (switch_socket_opt_set(newsocket, SWITCH_SO_NONBLOCK, TRUE)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Couldn't set socket as non-blocking\n"); - } - - if (event_stream_keepalive) { - if (switch_socket_opt_set(newsocket, SWITCH_SO_KEEPALIVE, TRUE)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Couldn't set socket keep-alive\n"); - } - } - - if (switch_socket_opt_set(newsocket, SWITCH_SO_TCP_NODELAY, 1)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Couldn't disable Nagle.\n"); - } - - /* close the current client, if there is one */ - close_socket(&event_stream->socket); - - switch_mutex_lock(event_stream->socket_mutex); - /* start sending to the new client */ - event_stream->socket = newsocket; - - switch_socket_addr_get(&sa, SWITCH_TRUE, newsocket); - event_stream->remote_port = switch_sockaddr_get_port(sa); - switch_get_addr(event_stream->remote_ip, sizeof (event_stream->remote_ip), sa); - - switch_socket_addr_get(&sa, SWITCH_FALSE, newsocket); - event_stream->local_port = switch_sockaddr_get_port(sa); - switch_get_addr(event_stream->local_ip, sizeof (event_stream->local_ip), sa); - - event_stream->connected = SWITCH_TRUE; - event_stream->connected_time = switch_micro_time_now(); - - switch_mutex_unlock(event_stream->socket_mutex); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Erlang event stream %p client %s:%u\n", (void *)event_stream, event_stream->remote_ip, event_stream->remote_port); - } - } - } - - /* if there was an event waiting in our queue send it to the client */ - if (ei_queue_pop(event_stream->queue, &pop, event_stream->queue_timeout) == SWITCH_STATUS_SUCCESS) { - ei_x_buff *ebuf = (ei_x_buff *) pop; - - if (event_stream->socket) { - switch_size_t size = 1, expected = 0; - switch_status_t status = SWITCH_STATUS_SUCCESS; - - if(ebuf->index >= pow(2, 8 * event_stream_framing)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "sending frame size %d with insufficient frame capacity, change event_stream_framing here and tcp_packet_type in ecallmgr\n", ebuf->index); - } else { - if(event_stream_framing) { - int index = ebuf->index - MAX_FRAMING; - char byte; - short i = event_stream_framing; - while (i) { - byte = index >> (8 * --i); - ebuf->buff[MAX_FRAMING - i - 1] = byte; - } - } - expected = size = (switch_size_t)ebuf->index - MAX_FRAMING + event_stream_framing; - if((status = switch_socket_send(event_stream->socket, ebuf->buff + (MAX_FRAMING - event_stream_framing), &size)) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error %d sending event stream\n", status); - ok = 0; - } else if(expected != size) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error sending event stream, sent bytes is different of expected\n"); - ok = 0; - } - } - } - - ei_x_free(ebuf); - switch_safe_free(ebuf); - } - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutting down erlang event stream %p\n", (void *)event_stream); - - /* unbind from the system events */ - event_binding = event_stream->bindings; - while(event_binding != NULL) { - switch_event_unbind(&event_binding->node); - event_binding = event_binding->next; - } - event_stream->bindings = NULL; - - /* clear and destroy any remaining queued events */ - while (switch_queue_trypop(event_stream->queue, &pop) == SWITCH_STATUS_SUCCESS) { - ei_x_buff *ebuf = (ei_x_buff *) pop; - ei_x_free(ebuf); - switch_safe_free(ebuf); - } - - /* remove the acceptor pollset */ - switch_pollset_remove(event_stream->pollset, event_stream->pollfd); - - /* close any open sockets */ - close_socket(&event_stream->acceptor); - - switch_mutex_lock(event_stream->socket_mutex); - event_stream->connected = SWITCH_FALSE; - close_socket(&event_stream->socket); - switch_mutex_unlock(event_stream->socket_mutex); - - switch_mutex_destroy(event_stream->socket_mutex); - - /* clean up the memory */ - switch_core_destroy_memory_pool(&event_stream->pool); - - switch_atomic_dec(&kazoo_globals.threads); - - return NULL; -} - -ei_event_stream_t *new_event_stream(ei_node_t *ei_node, const erlang_pid *from) { - switch_thread_t *thread; - switch_threadattr_t *thd_attr = NULL; - switch_memory_pool_t *pool = NULL; - ei_event_stream_t *event_stream; - ei_event_stream_t **event_streams = &ei_node->event_streams; - - /* create memory pool for this event stream */ - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: How many Alzheimer's patients does it take to screw in a light bulb? To get to the other side.\n"); - return NULL; - } - - /* from the memory pool, allocate the event stream structure */ - if (!(event_stream = switch_core_alloc(pool, sizeof (*event_stream)))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: I may have Alzheimers but at least I dont have Alzheimers.\n"); - goto cleanup; - } - - /* prepare the event stream */ - memset(event_stream, 0, sizeof(*event_stream)); - event_stream->bindings = NULL; - event_stream->pool = pool; - event_stream->connected = SWITCH_FALSE; - event_stream->node = ei_node; - event_stream->event_stream_framing = ei_node->event_stream_framing; - event_stream->event_stream_keepalive = ei_node->event_stream_keepalive; - event_stream->queue_timeout = ei_node->event_stream_queue_timeout; - memcpy(&event_stream->pid, from, sizeof(erlang_pid)); - switch_queue_create(&event_stream->queue, MAX_QUEUE_LEN, pool); - - /* create a socket for accepting the event stream client */ - if (!(event_stream->acceptor = create_socket(pool))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Like car accidents, most hardware problems are due to driver error.\n"); - goto cleanup; - } - - if (switch_socket_opt_set(event_stream->acceptor, SWITCH_SO_NONBLOCK, TRUE)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Hey, it compiles!\n"); - goto cleanup; - } - - /* create a pollset so we can efficiently check for new client connections */ - if (switch_pollset_create(&event_stream->pollset, 1000, pool, 0) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "My software never has bugs. It just develops random features.\n"); - goto cleanup; - } - - switch_socket_create_pollfd(&event_stream->pollfd, event_stream->acceptor, SWITCH_POLLIN | SWITCH_POLLERR, NULL, pool); - if (switch_pollset_add(event_stream->pollset, event_stream->pollfd) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "If you saw a heat wave, would you wave back?\n"); - goto cleanup; - } - - switch_mutex_init(&event_stream->socket_mutex, SWITCH_MUTEX_DEFAULT, pool); - - /* add the new event stream to the link list - * since the event streams link list is only - * accessed from the same thread no locks - * are required */ - if (!*event_streams) { - *event_streams = event_stream; - } else { - event_stream->next = *event_streams; - *event_streams = event_stream; - } - - /* when we start we are running */ - switch_set_flag(event_stream, LFLAG_RUNNING); - - switch_threadattr_create(&thd_attr, event_stream->pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&thread, thd_attr, event_stream_loop, event_stream, event_stream->pool); - - return event_stream; - -cleanup: - - if (event_stream) { - /* remove the acceptor pollset */ - if (event_stream->pollset) { - switch_pollset_remove(event_stream->pollset, event_stream->pollfd); - } - - /* close any open sockets */ - if (event_stream->acceptor) { - close_socket(&event_stream->acceptor); - } - } - - /* clean up the memory */ - switch_core_destroy_memory_pool(&pool); - - return NULL; - -} - -unsigned long get_stream_port(const ei_event_stream_t *event_stream) { - switch_sockaddr_t *sa; - switch_socket_addr_get(&sa, SWITCH_FALSE, event_stream->acceptor); - return (unsigned long) switch_sockaddr_get_port(sa); -} - -ei_event_stream_t *find_event_stream(ei_event_stream_t *event_stream, const erlang_pid *from) { - while (event_stream != NULL) { - if (ei_compare_pids(&event_stream->pid, from) == SWITCH_STATUS_SUCCESS) { - return event_stream; - } - event_stream = event_stream->next; - } - - return NULL; -} - -switch_status_t remove_event_stream(ei_event_stream_t **event_streams, const erlang_pid *from) { - ei_event_stream_t *event_stream, *prev = NULL; - int found = 0; - - /* if there are no event bindings there is nothing to do */ - if (!*event_streams) { - return SWITCH_STATUS_SUCCESS; - } - - /* try to find the event stream for the client process */ - event_stream = *event_streams; - while(event_stream != NULL) { - if (ei_compare_pids(&event_stream->pid, from) == SWITCH_STATUS_SUCCESS) { - found = 1; - break; - } - - prev = event_stream; - event_stream = event_stream->next; - } - - if (found) { - /* if we found an event stream remove it from - * from the link list */ - if (!prev) { - *event_streams = event_stream->next; - } else { - prev->next = event_stream->next; - } - - /* stop the event stream thread */ - switch_clear_flag(event_stream, LFLAG_RUNNING); - } - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t remove_event_streams(ei_event_stream_t **event_streams) { - ei_event_stream_t *event_stream = *event_streams; - - while(event_stream != NULL) { - /* stop the event bindings publisher thread */ - switch_clear_flag(event_stream, LFLAG_RUNNING); - - event_stream = event_stream->next; - } - - *event_streams = NULL; - - return SWITCH_STATUS_SUCCESS; -} - -void bind_event_profile(ei_event_binding_t *event_binding, kazoo_event_ptr event) -{ - switch_event_types_t event_type; - while(event != NULL) { - if (switch_name_event(event->name, &event_type) != SWITCH_STATUS_SUCCESS) { - event_type = SWITCH_EVENT_CUSTOM; - } - if(event_binding->type != SWITCH_EVENT_CUSTOM - && event_binding->type == event_type) { - break; - } - if (event_binding->type == SWITCH_EVENT_CUSTOM - && event_binding->type == event_type - && !strcasecmp(event_binding->subclass_name, event->name)) { - break; - } - event = event->next; - } - event_binding->event = event; - if(event == NULL && (!event_binding->stream->node->legacy)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "event binding to an event without profile in non legacy mode => %s - %s\n",switch_event_name(event_binding->type), event_binding->subclass_name); - } -} - -void bind_event_profiles(kazoo_event_ptr event) -{ - ei_node_t *ei_node = kazoo_globals.ei_nodes; - while(ei_node) { - ei_event_stream_t *event_streams = ei_node->event_streams; - while(event_streams) { - ei_event_binding_t *bindings = event_streams->bindings; - while(bindings) { - bind_event_profile(bindings, event); - bindings = bindings->next; - } - event_streams = event_streams->next; - } - ei_node = ei_node->next; - } -} - -switch_status_t add_event_binding(ei_event_stream_t *event_stream, const char *event_name) { - ei_event_binding_t *event_binding = event_stream->bindings; - switch_event_types_t event_type; - - if(!strcasecmp(event_name, "CUSTOM")) { - return SWITCH_STATUS_SUCCESS; - } - - if (switch_name_event(event_name, &event_type) != SWITCH_STATUS_SUCCESS) { - event_type = SWITCH_EVENT_CUSTOM; - } - - /* check if the event binding already exists, ignore if so */ - while(event_binding != NULL) { - if (event_binding->type == SWITCH_EVENT_CUSTOM) { - if(event_type == SWITCH_EVENT_CUSTOM - && event_name - && event_binding->subclass_name - && !strcasecmp(event_name, event_binding->subclass_name)) { - return SWITCH_STATUS_SUCCESS; - } - } else if (event_binding->type == event_type) { - return SWITCH_STATUS_SUCCESS; - } - event_binding = event_binding->next; - } - - /* from the event stream memory pool, allocate the event binding structure */ - if (!(event_binding = switch_core_alloc(event_stream->pool, sizeof (*event_binding)))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of random-access memory, attempting write-only memory\n"); - return SWITCH_STATUS_FALSE; - } - - /* prepare the event binding struct */ - event_binding->stream = event_stream; - event_binding->type = event_type; - if(event_binding->type == SWITCH_EVENT_CUSTOM) { - event_binding->subclass_name = switch_core_strdup(event_stream->pool, event_name); - } else { - event_binding->subclass_name = SWITCH_EVENT_SUBCLASS_ANY; - } - event_binding->next = NULL; - - bind_event_profile(event_binding, kazoo_globals.events->events); - - - /* bind to the event with a unique ID and capture the event_node pointer */ - switch_uuid_str(event_binding->id, sizeof(event_binding->id)); - if (switch_event_bind_removable(event_binding->id, event_type, event_binding->subclass_name, event_handler, event_binding, &event_binding->node) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to bind to event %s %s!\n" - ,switch_event_name(event_binding->type), event_binding->subclass_name ? event_binding->subclass_name : ""); - return SWITCH_STATUS_GENERR; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding event binding %s to stream %p for %s <%d.%d.%d>: %s %s\n" - ,event_binding->id, (void *)event_stream, event_stream->pid.node, event_stream->pid.creation - ,event_stream->pid.num, event_stream->pid.serial, switch_event_name(event_binding->type) - ,event_binding->subclass_name ? event_binding->subclass_name : ""); - - /* add the new binding to the list */ - if (!event_stream->bindings) { - event_stream->bindings = event_binding; - } else { - event_binding->next = event_stream->bindings; - event_stream->bindings = event_binding; - } - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t remove_event_binding(ei_event_stream_t *event_stream, const switch_event_types_t event_type, const char *subclass_name) { - ei_event_binding_t *event_binding = event_stream->bindings, *prev = NULL; - int found = 0; - - /* if there are no bindings then there is nothing to do */ - if (!event_binding) { - return SWITCH_STATUS_SUCCESS; - } - - /* try to find the event binding specified */ - while(event_binding != NULL) { - if (event_binding->type == SWITCH_EVENT_CUSTOM - && subclass_name - && event_binding->subclass_name - && !strcmp(subclass_name, event_binding->subclass_name)) { - found = 1; - break; - } else if (event_binding->type == event_type) { - found = 1; - break; - } - - prev = event_binding; - event_binding = event_binding->next; - } - - if (found) { - /* if the event binding exists, unbind from the system */ - switch_event_unbind(&event_binding->node); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing event binding %s from %p for %s <%d.%d.%d>: %s %s\n" - ,event_binding->id, (void *)event_stream, event_stream->pid.node, event_stream->pid.creation - ,event_stream->pid.num, event_stream->pid.serial, switch_event_name(event_binding->type) - ,event_binding->subclass_name ? event_binding->subclass_name : ""); - - /* remove the event binding from the list */ - if (!prev) { - event_stream->bindings = event_binding->next; - } else { - prev->next = event_binding->next; - } - } - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t remove_event_bindings(ei_event_stream_t *event_stream) { - ei_event_binding_t *event_binding = event_stream->bindings; - - /* if there are no bindings then there is nothing to do */ - if (!event_binding) { - return SWITCH_STATUS_SUCCESS; - } - - /* try to find the event binding specified */ - while(event_binding != NULL) { - /* if the event binding exists, unbind from the system */ - switch_event_unbind(&event_binding->node); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing event binding %s from %p for %s <%d.%d.%d>: %s %s\n" - ,event_binding->id, (void *)event_stream, event_stream->pid.node, event_stream->pid.creation - ,event_stream->pid.num, event_stream->pid.serial, switch_event_name(event_binding->type) - ,event_binding->subclass_name ? event_binding->subclass_name : ""); - - event_binding = event_binding->next; - } - - event_stream->bindings = NULL; - - return SWITCH_STATUS_SUCCESS; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_fetch_agent.c b/src/mod/event_handlers/mod_kazoo/kazoo_fetch_agent.c deleted file mode 100644 index 5023e39344..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_fetch_agent.c +++ /dev/null @@ -1,803 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * kazoo_fetch.c -- XML fetch request handler - * - */ -#include "mod_kazoo.h" - -static const char *fetch_uuid_sources[] = { - "Fetch-Call-UUID", - "refer-from-channel-id", - "sip_call_id", - NULL -}; - -static char *xml_section_to_string(switch_xml_section_t section) { - switch(section) { - case SWITCH_XML_SECTION_CONFIG: - return "configuration"; - case SWITCH_XML_SECTION_DIRECTORY: - return "directory"; - case SWITCH_XML_SECTION_DIALPLAN: - return "dialplan"; - case SWITCH_XML_SECTION_CHATPLAN: - return "chatplan"; - case SWITCH_XML_SECTION_CHANNELS: - return "channels"; - case SWITCH_XML_SECTION_LANGUAGES: - return "languages"; - default: - return "unknown"; - } -} - -static char *expand_vars(char *xml_str) { - char *var, *val; - char *rp = xml_str; /* read pointer */ - char *ep, *wp, *buff; /* end pointer, write pointer, write buffer */ - - if (!(strstr(xml_str, "$${"))) { - return xml_str; - } - - switch_zmalloc(buff, strlen(xml_str) * 2); - wp = buff; - ep = buff + (strlen(xml_str) * 2) - 1; - - while (*rp && wp < ep) { - if (*rp == '$' && *(rp + 1) == '$' && *(rp + 2) == '{') { - char *e = switch_find_end_paren(rp + 2, '{', '}'); - - if (e) { - rp += 3; - var = rp; - *e++ = '\0'; - rp = e; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "trying to expand %s \n", var); - if ((val = switch_core_get_variable_dup(var))) { - char *p; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "expanded %s to %s\n", var, val); - for (p = val; p && *p && wp <= ep; p++) { - *wp++ = *p; - } - switch_safe_free(val); - } - continue; - } - } - - *wp++ = *rp++; - } - - *wp++ = '\0'; - - switch_safe_free(xml_str); - return buff; -} - -static switch_xml_t fetch_handler(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data) { - switch_xml_t xml = NULL; - switch_uuid_t uuid; - switch_time_t now = 0; - ei_xml_agent_t *agent = (ei_xml_agent_t *) user_data; - ei_xml_client_t *client; - fetch_handler_t *fetch_handler; - xml_fetch_reply_t reply, *pending, *prev = NULL; - switch_event_t *event = params; - kazoo_fetch_profile_ptr profile = agent->profile; - const char *fetch_call_id; - ei_send_msg_t *send_msg = NULL; - int sent = 0; - - now = switch_micro_time_now(); - - if (!switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - return xml; - } - - /* read-lock the agent */ - switch_thread_rwlock_rdlock(agent->lock); - - /* serialize access to current, used to round-robin requests */ - /* TODO: check kazoo_globals for round-robin boolean or loop all clients */ - switch_mutex_lock(agent->current_client_mutex); - if (!agent->current_client) { - client = agent->clients; - } else { - client = agent->current_client; - } - if (client) { - agent->current_client = client->next; - } - switch_mutex_unlock(agent->current_client_mutex); - - /* no client, no work required */ - if (!client || !client->fetch_handlers) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "No %s XML erlang handler currently available\n" - ,section); - switch_thread_rwlock_unlock(agent->lock); - return xml; - } - - /* no profile, no work required */ - if (!profile) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "weird case where client is available but there's no profile for %s. try reloading mod_kazoo.\n" - ,section); - switch_thread_rwlock_unlock(agent->lock); - return xml; - } - - if(event == NULL) { - if (switch_event_create(&event, SWITCH_EVENT_GENERAL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error creating event for fetch handler\n"); - return xml; - } - } - - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Switch-Nodename", kazoo_globals.ei_cnode.thisnodename); - - /* prepare the reply collector */ - switch_uuid_get(&uuid); - switch_uuid_format(reply.uuid_str, &uuid); - reply.next = NULL; - reply.xml_str = NULL; - - if(switch_event_get_header(event, "Unique-ID") == NULL) { - int i; - for(i = 0; fetch_uuid_sources[i] != NULL; i++) { - if((fetch_call_id = switch_event_get_header(event, fetch_uuid_sources[i])) != NULL) { - switch_core_session_t *session = NULL; - if((session = switch_core_session_locate(fetch_call_id)) != NULL) { - switch_channel_t *channel = switch_core_session_get_channel(session); - uint32_t verbose = switch_channel_test_flag(channel, CF_VERBOSE_EVENTS); - switch_channel_set_flag(channel, CF_VERBOSE_EVENTS); - switch_channel_event_set_data(channel, event); - switch_channel_set_flag_value(channel, CF_VERBOSE_EVENTS, verbose); - switch_core_session_rwunlock(session); - break; - } - } - } - } - - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Fetch-UUID", reply.uuid_str); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Fetch-Section", section); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Fetch-Tag", tag_name); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Fetch-Key-Name", key_name); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Fetch-Key-Value", key_value); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Fetch-Timeout", "%u", profile->fetch_timeout); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Fetch-Timestamp-Micro", "%" SWITCH_UINT64_T_FMT, (uint64_t)now); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Kazoo-Version", VERSION); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Kazoo-Bundle", BUNDLE); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Kazoo-Release", RELEASE); - - kz_event_decode(event); - - switch_malloc(send_msg, sizeof(*send_msg)); - - if(client->ei_node->legacy) { - ei_x_new_with_version(&send_msg->buf); - ei_x_encode_tuple_header(&send_msg->buf, 7); - ei_x_encode_atom(&send_msg->buf, "fetch"); - ei_x_encode_atom(&send_msg->buf, section); - _ei_x_encode_string(&send_msg->buf, tag_name ? tag_name : "undefined"); - _ei_x_encode_string(&send_msg->buf, key_name ? key_name : "undefined"); - _ei_x_encode_string(&send_msg->buf, key_value ? key_value : "undefined"); - _ei_x_encode_string(&send_msg->buf, reply.uuid_str); - ei_encode_switch_event_headers(&send_msg->buf, event); - } else { - kazoo_message_ptr msg = kazoo_message_create_fetch(event, profile); - ei_x_new_with_version(&send_msg->buf); - ei_x_encode_tuple_header(&send_msg->buf, 2); - ei_x_encode_atom(&send_msg->buf, "fetch"); - ei_encode_json(&send_msg->buf, msg->JObj); - kazoo_message_destroy(&msg); - } - - /* add our reply placeholder to the replies list */ - switch_mutex_lock(agent->replies_mutex); - if (!agent->replies) { - agent->replies = &reply; - } else { - reply.next = agent->replies; - agent->replies = &reply; - } - switch_mutex_unlock(agent->replies_mutex); - - fetch_handler = client->fetch_handlers; - while (fetch_handler != NULL && sent == 0) { - memcpy(&send_msg->pid, &fetch_handler->pid, sizeof(erlang_pid)); - if (switch_queue_trypush(client->ei_node->send_msgs, send_msg) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to send %s XML request to %s <%d.%d.%d>\n" - ,section - ,fetch_handler->pid.node - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending %s XML request (%s) to %s <%d.%d.%d>\n" - ,section - ,reply.uuid_str - ,fetch_handler->pid.node - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - sent = 1; - } - fetch_handler = fetch_handler->next; - } - - if(!sent) { - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - } - - if(params == NULL) - switch_event_destroy(&event); - - /* wait for a reply (if there isnt already one...amazingly improbable but lets not take shortcuts */ - switch_mutex_lock(agent->replies_mutex); - - switch_thread_rwlock_unlock(agent->lock); - - if (!reply.xml_str) { - switch_time_t timeout; - - timeout = switch_micro_time_now() + 3000000; - while (switch_micro_time_now() < timeout) { - /* unlock the replies list and go to sleep, calculate a three second timeout before we started the loop - * plus 100ms to add a little hysteresis between the timeout and the while loop */ - switch_thread_cond_timedwait(agent->new_reply, agent->replies_mutex, (timeout - switch_micro_time_now() + 100000)); - - /* if we woke up (and therefore have locked replies again) check if we got our reply - * otherwise we either timed-out (the while condition will fail) or one of - * our sibling processes got a reply and we should go back to sleep */ - if (reply.xml_str) { - break; - } - } - } - - /* find our reply placeholder in the linked list and remove it */ - pending = agent->replies; - while (pending != NULL) { - if (pending->uuid_str == reply.uuid_str) { - break; - } - - prev = pending; - pending = pending->next; - } - - if (pending) { - if (!prev) { - agent->replies = reply.next; - } else { - prev->next = reply.next; - } - } - - /* we are done with the replies link-list */ - switch_mutex_unlock(agent->replies_mutex); - - /* after all that did we get what we were after?! */ - if (reply.xml_str) { - /* HELL YA WE DID */ - if (kazoo_globals.expand_headers_on_fetch) { - reply.xml_str = expand_vars(reply.xml_str); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received %s XML (%s) after %dms: %s\n" - ,section - ,reply.uuid_str - ,(unsigned int) (switch_micro_time_now() - now) / 1000 - ,reply.xml_str); - if ((xml = switch_xml_parse_str_dynamic(reply.xml_str, SWITCH_FALSE)) == NULL) { - switch_safe_free(reply.xml_str); - } - } else { - /* facepalm */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Request for %s XML (%s) timed-out after %dms\n" - ,section - ,reply.uuid_str - ,(unsigned int) (switch_micro_time_now() - now) / 1000); - } - - return xml; -} - -void bind_fetch_profile(ei_xml_agent_t *agent, kazoo_config_ptr fetch_handlers) -{ - switch_hash_index_t *hi; - kazoo_fetch_profile_ptr val = NULL, ptr = NULL; - - if (!fetch_handlers) return; - - for (hi = switch_core_hash_first(fetch_handlers->hash); hi; hi = switch_core_hash_next(&hi)) { - switch_core_hash_this(hi, NULL, NULL, (void**) &val); - if (val && val->section == agent->section) { - ptr = val; - break; - } - } - agent->profile = ptr; - switch_safe_free(hi); -} - -void rebind_fetch_profiles(kazoo_config_ptr fetch_handlers) -{ - if(kazoo_globals.config_fetch_binding != NULL) - bind_fetch_profile((ei_xml_agent_t *) switch_xml_get_binding_user_data(kazoo_globals.config_fetch_binding), fetch_handlers); - - if(kazoo_globals.directory_fetch_binding != NULL) - bind_fetch_profile((ei_xml_agent_t *) switch_xml_get_binding_user_data(kazoo_globals.directory_fetch_binding), fetch_handlers); - - if(kazoo_globals.dialplan_fetch_binding != NULL) - bind_fetch_profile((ei_xml_agent_t *) switch_xml_get_binding_user_data(kazoo_globals.dialplan_fetch_binding), fetch_handlers); - - if(kazoo_globals.channels_fetch_binding != NULL) - bind_fetch_profile((ei_xml_agent_t *) switch_xml_get_binding_user_data(kazoo_globals.channels_fetch_binding), fetch_handlers); - - if(kazoo_globals.languages_fetch_binding != NULL) - bind_fetch_profile((ei_xml_agent_t *) switch_xml_get_binding_user_data(kazoo_globals.languages_fetch_binding), fetch_handlers); - - if(kazoo_globals.chatplan_fetch_binding != NULL) - bind_fetch_profile((ei_xml_agent_t *) switch_xml_get_binding_user_data(kazoo_globals.chatplan_fetch_binding), fetch_handlers); -} - -static switch_status_t bind_fetch_agent(switch_xml_section_t section, switch_xml_binding_t **binding) { - switch_memory_pool_t *pool = NULL; - ei_xml_agent_t *agent; - - /* create memory pool for this xml search binging (lives for duration of mod_kazoo runtime) */ - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: They're not people; they're hippies!\n"); - return SWITCH_STATUS_MEMERR; - } - - /* allocate some memory to store the fetch bindings for this section */ - if (!(agent = switch_core_alloc(pool, sizeof (*agent)))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: Oh, Jesus tap-dancing Christ!\n"); - return SWITCH_STATUS_MEMERR; - } - - /* try to bind to the switch */ - if (switch_xml_bind_search_function_ret(fetch_handler, section, agent, binding) != SWITCH_STATUS_SUCCESS) { - switch_core_destroy_memory_pool(&pool); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not bind to FreeSWITCH %s XML requests\n" - ,xml_section_to_string(section)); - return SWITCH_STATUS_GENERR; - } - - agent->pool = pool; - agent->section = section; - switch_thread_rwlock_create(&agent->lock, pool); - agent->clients = NULL; - switch_mutex_init(&agent->current_client_mutex, SWITCH_MUTEX_DEFAULT, pool); - agent->current_client = NULL; - switch_mutex_init(&agent->replies_mutex, SWITCH_MUTEX_DEFAULT, pool); - switch_thread_cond_create(&agent->new_reply, pool); - agent->replies = NULL; - - bind_fetch_profile(agent, kazoo_globals.fetch_handlers); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bound to %s XML requests\n" - ,xml_section_to_string(section)); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t unbind_fetch_agent(switch_xml_binding_t **binding) { - ei_xml_agent_t *agent; - ei_xml_client_t *client; - - if(*binding == NULL) - return SWITCH_STATUS_GENERR; - - /* get a pointer to our user_data */ - agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(*binding); - - /* unbind from the switch */ - switch_xml_unbind_search_function(binding); - - /* LOCK ALL THE THINGS */ - switch_thread_rwlock_wrlock(agent->lock); - switch_mutex_lock(agent->current_client_mutex); - switch_mutex_lock(agent->replies_mutex); - - /* cleanly destroy each client */ - client = agent->clients; - while(client != NULL) { - ei_xml_client_t *tmp_client = client; - fetch_handler_t *fetch_handler; - - fetch_handler = client->fetch_handlers; - while(fetch_handler != NULL) { - fetch_handler_t *tmp_fetch_handler = fetch_handler; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed %s XML handler %s <%d.%d.%d>\n" - ,xml_section_to_string(agent->section) - ,fetch_handler->pid.node - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - - fetch_handler = fetch_handler->next; - switch_safe_free(tmp_fetch_handler); - } - - client = client->next; - switch_safe_free(tmp_client); - } - - /* keep the pointers clean, even if its just for a moment */ - agent->clients = NULL; - agent->current_client = NULL; - - /* release the locks! */ - switch_thread_rwlock_unlock(agent->lock); - switch_mutex_unlock(agent->current_client_mutex); - switch_mutex_unlock(agent->replies_mutex); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unbound from %s XML requests\n" - ,xml_section_to_string(agent->section)); - - /* cleanly destroy the bindings */ - switch_thread_rwlock_destroy(agent->lock); - switch_mutex_destroy(agent->current_client_mutex); - switch_mutex_destroy(agent->replies_mutex); - switch_thread_cond_destroy(agent->new_reply); - switch_core_destroy_memory_pool(&agent->pool); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t remove_xml_client(ei_node_t *ei_node, switch_xml_binding_t *binding) { - ei_xml_agent_t *agent; - ei_xml_client_t *client, *prev = NULL; - int found = 0; - - if(binding == NULL) - return SWITCH_STATUS_GENERR; - - agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(binding); - - /* write-lock the agent */ - switch_thread_rwlock_wrlock(agent->lock); - - client = agent->clients; - while (client != NULL) { - if (client->ei_node == ei_node) { - found = 1; - break; - } - - prev = client; - client = client->next; - } - - if (found) { - fetch_handler_t *fetch_handler; - - if (!prev) { - agent->clients = client->next; - } else { - prev->next = client->next; - } - - /* the mutex lock is not required since we have the write lock - * but hey its fun and safe so do it anyway */ - switch_mutex_lock(agent->current_client_mutex); - if (agent->current_client == client) { - agent->current_client = agent->clients; - } - switch_mutex_unlock(agent->current_client_mutex); - - fetch_handler = client->fetch_handlers; - while(fetch_handler != NULL) { - fetch_handler_t *tmp_fetch_handler = fetch_handler; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed %s XML handler %s <%d.%d.%d>\n" - ,xml_section_to_string(agent->section) - ,fetch_handler->pid.node - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - - fetch_handler = fetch_handler->next; - switch_safe_free(tmp_fetch_handler); - } - - switch_safe_free(client); - } - - switch_thread_rwlock_unlock(agent->lock); - - return SWITCH_STATUS_SUCCESS; -} - -static ei_xml_client_t *add_xml_client(ei_node_t *ei_node, ei_xml_agent_t *agent) { - ei_xml_client_t *client; - - switch_malloc(client, sizeof(*client)); - - client->ei_node = ei_node; - client->fetch_handlers = NULL; - client->next = NULL; - - if (agent->clients) { - client->next = agent->clients; - } - - agent->clients = client; - - return client; -} - -static ei_xml_client_t *find_xml_client(ei_node_t *ei_node, ei_xml_agent_t *agent) { - ei_xml_client_t *client; - - client = agent->clients; - while (client != NULL) { - if (client->ei_node == ei_node) { - return client; - } - - client = client->next; - } - - return NULL; -} - -static switch_status_t remove_fetch_handler(ei_node_t *ei_node, erlang_pid *from, switch_xml_binding_t *binding) { - ei_xml_agent_t *agent; - ei_xml_client_t *client; - fetch_handler_t *fetch_handler, *prev = NULL; - int found = 0; - - agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(binding); - - /* write-lock the agent */ - switch_thread_rwlock_wrlock(agent->lock); - - if (!(client = find_xml_client(ei_node, agent))) { - switch_thread_rwlock_unlock(agent->lock); - return SWITCH_STATUS_SUCCESS; - } - - fetch_handler = client->fetch_handlers; - while (fetch_handler != NULL) { - if (ei_compare_pids(&fetch_handler->pid, from) == SWITCH_STATUS_SUCCESS) { - found = 1; - break; - } - - prev = fetch_handler; - fetch_handler = fetch_handler->next; - } - - if (found) { - if (!prev) { - client->fetch_handlers = fetch_handler->next; - } else { - prev->next = fetch_handler->next; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed %s XML handler %s <%d.%d.%d>\n" - ,xml_section_to_string(agent->section) - ,fetch_handler->pid.node - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - - switch_safe_free(fetch_handler); - } - - switch_thread_rwlock_unlock(agent->lock); - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_api_command_stream(ei_node_t *ei_node, switch_stream_handle_t *stream, switch_xml_binding_t *binding) { - ei_xml_agent_t *agent; - ei_xml_client_t *client; - - if (!binding) { - return SWITCH_STATUS_GENERR; - } - - agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(binding); - - /* read-lock the agent */ - switch_thread_rwlock_rdlock(agent->lock); - client = agent->clients; - while (client != NULL) { - if (client->ei_node == ei_node) { - fetch_handler_t *fetch_handler; - fetch_handler = client->fetch_handlers; - while (fetch_handler != NULL) { - stream->write_function(stream, "XML %s handler <%d.%d.%d>\n" - ,xml_section_to_string(agent->section) - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - fetch_handler = fetch_handler->next; - } - break; - } - - client = client->next; - } - switch_thread_rwlock_unlock(agent->lock); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t bind_fetch_agents() { - bind_fetch_agent(SWITCH_XML_SECTION_CONFIG, &kazoo_globals.config_fetch_binding); - bind_fetch_agent(SWITCH_XML_SECTION_DIRECTORY, &kazoo_globals.directory_fetch_binding); - bind_fetch_agent(SWITCH_XML_SECTION_DIALPLAN, &kazoo_globals.dialplan_fetch_binding); - bind_fetch_agent(SWITCH_XML_SECTION_CHANNELS, &kazoo_globals.channels_fetch_binding); - bind_fetch_agent(SWITCH_XML_SECTION_LANGUAGES, &kazoo_globals.languages_fetch_binding); - bind_fetch_agent(SWITCH_XML_SECTION_CHATPLAN, &kazoo_globals.chatplan_fetch_binding); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t unbind_fetch_agents() { - unbind_fetch_agent(&kazoo_globals.config_fetch_binding); - unbind_fetch_agent(&kazoo_globals.directory_fetch_binding); - unbind_fetch_agent(&kazoo_globals.dialplan_fetch_binding); - unbind_fetch_agent(&kazoo_globals.channels_fetch_binding); - unbind_fetch_agent(&kazoo_globals.languages_fetch_binding); - unbind_fetch_agent(&kazoo_globals.chatplan_fetch_binding); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t remove_xml_clients(ei_node_t *ei_node) { - remove_xml_client(ei_node, kazoo_globals.config_fetch_binding); - remove_xml_client(ei_node, kazoo_globals.directory_fetch_binding); - remove_xml_client(ei_node, kazoo_globals.dialplan_fetch_binding); - remove_xml_client(ei_node, kazoo_globals.channels_fetch_binding); - remove_xml_client(ei_node, kazoo_globals.languages_fetch_binding); - remove_xml_client(ei_node, kazoo_globals.chatplan_fetch_binding); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t add_fetch_handler(ei_node_t *ei_node, erlang_pid *from, switch_xml_binding_t *binding) { - ei_xml_agent_t *agent; - ei_xml_client_t *client; - fetch_handler_t *fetch_handler; - - if(binding == NULL) - return SWITCH_STATUS_GENERR; - - agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(binding); - - /* write-lock the agent */ - switch_thread_rwlock_wrlock(agent->lock); - - if (!(client = find_xml_client(ei_node, agent))) { - client = add_xml_client(ei_node, agent); - } - - fetch_handler = client->fetch_handlers; - while (fetch_handler != NULL) { - if (ei_compare_pids(&fetch_handler->pid, from) == SWITCH_STATUS_SUCCESS) { - switch_thread_rwlock_unlock(agent->lock); - return SWITCH_STATUS_SUCCESS; - } - fetch_handler = fetch_handler->next; - } - - switch_malloc(fetch_handler, sizeof(*fetch_handler)); - - memcpy(&fetch_handler->pid, from, sizeof(erlang_pid));; - - fetch_handler->next = NULL; - if (client->fetch_handlers) { - fetch_handler->next = client->fetch_handlers; - } - - client->fetch_handlers = fetch_handler; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Added %s XML handler %s <%d.%d.%d>\n" - ,xml_section_to_string(agent->section) - ,fetch_handler->pid.node - ,fetch_handler->pid.creation - ,fetch_handler->pid.num - ,fetch_handler->pid.serial); - - switch_thread_rwlock_unlock(agent->lock); - - ei_link(ei_node, ei_self(&kazoo_globals.ei_cnode), from); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t remove_fetch_handlers(ei_node_t *ei_node, erlang_pid *from) { - remove_fetch_handler(ei_node, from, kazoo_globals.config_fetch_binding); - remove_fetch_handler(ei_node, from, kazoo_globals.directory_fetch_binding); - remove_fetch_handler(ei_node, from, kazoo_globals.dialplan_fetch_binding); - remove_fetch_handler(ei_node, from, kazoo_globals.channels_fetch_binding); - remove_fetch_handler(ei_node, from, kazoo_globals.languages_fetch_binding); - remove_fetch_handler(ei_node, from, kazoo_globals.chatplan_fetch_binding); - - return SWITCH_STATUS_SUCCESS; -} - -switch_status_t fetch_reply(char *uuid_str, char *xml_str, switch_xml_binding_t *binding) { - ei_xml_agent_t *agent; - xml_fetch_reply_t *reply; - switch_status_t status = SWITCH_STATUS_NOTFOUND; - - agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(binding); - - switch_mutex_lock(agent->replies_mutex); - reply = agent->replies; - while (reply != NULL) { - if (!strncmp(reply->uuid_str, uuid_str, SWITCH_UUID_FORMATTED_LENGTH)) { - if (!reply->xml_str) { - reply->xml_str = xml_str; - switch_thread_cond_broadcast(agent->new_reply); - status = SWITCH_STATUS_SUCCESS; - } - break; - } - - reply = reply->next; - } - switch_mutex_unlock(agent->replies_mutex); - - return status; -} - -switch_status_t handle_api_command_streams(ei_node_t *ei_node, switch_stream_handle_t *stream) { - handle_api_command_stream(ei_node, stream, kazoo_globals.config_fetch_binding); - handle_api_command_stream(ei_node, stream, kazoo_globals.directory_fetch_binding); - handle_api_command_stream(ei_node, stream, kazoo_globals.dialplan_fetch_binding); - handle_api_command_stream(ei_node, stream, kazoo_globals.channels_fetch_binding); - handle_api_command_stream(ei_node, stream, kazoo_globals.languages_fetch_binding); - handle_api_command_stream(ei_node, stream, kazoo_globals.chatplan_fetch_binding); - - return SWITCH_STATUS_SUCCESS; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_fields.h b/src/mod/event_handlers/mod_kazoo/kazoo_fields.h deleted file mode 100644 index 8d17378768..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_fields.h +++ /dev/null @@ -1,203 +0,0 @@ -/* -* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II -* -* Version: MPL 1.1 -* -* The contents of this file are subject to the Mozilla Public License Version -* 1.1 (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" basis, -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -* for the specific language governing rights and limitations under the -* License. -* -* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* -* The Initial Developer of the Original Code is -* Anthony Minessale II -* Portions created by the Initial Developer are Copyright (C) -* the Initial Developer. All Rights Reserved. -* -* Based on mod_skel by -* Anthony Minessale II -* -* Contributor(s): -* -* Daniel Bryars -* Tim Brown -* Anthony Minessale II -* William King -* Mike Jerris -* -* kazoo.c -- Sends FreeSWITCH events to an AMQP broker -* -*/ - -#ifndef KAZOO_FIELDS_H -#define KAZOO_FIELDS_H - -#include - -#define MAX_LIST_FIELDS 25 - -typedef struct kazoo_log_levels kazoo_loglevels_t; -typedef kazoo_loglevels_t *kazoo_loglevels_ptr; - -struct kazoo_log_levels -{ - switch_log_level_t success_log_level; - switch_log_level_t failed_log_level; - switch_log_level_t warn_log_level; - switch_log_level_t info_log_level; - switch_log_level_t time_log_level; - switch_log_level_t filtered_event_log_level; - switch_log_level_t filtered_field_log_level; - switch_log_level_t trace_log_level; - switch_log_level_t debug_log_level; - switch_log_level_t error_log_level; - switch_log_level_t hashing_log_level; - -}; - -typedef struct kazoo_logging kazoo_logging_t; -typedef kazoo_logging_t *kazoo_logging_ptr; - -struct kazoo_logging -{ - kazoo_loglevels_ptr levels; - const char *profile_name; - const char *event_name; -}; - -typedef struct kazoo_list_s { - char *value[MAX_LIST_FIELDS]; - int size; -} kazoo_list_t; - -typedef enum { - FILTER_COMPARE_REGEX, - FILTER_COMPARE_LIST, - FILTER_COMPARE_VALUE, - FILTER_COMPARE_PREFIX, - FILTER_COMPARE_EXISTS, - FILTER_COMPARE_FIELD - -} kazoo_filter_compare_type; - -typedef enum { - FILTER_EXCLUDE, - FILTER_INCLUDE, - FILTER_ENSURE -} kazoo_filter_type; - -typedef struct kazoo_filter_t { - kazoo_filter_type type; - kazoo_filter_compare_type compare; - char* name; - char* value; - kazoo_list_t list; - struct kazoo_filter_t* next; -} kazoo_filter, *kazoo_filter_ptr; - - -typedef enum { - JSON_NONE, - JSON_STRING, - JSON_NUMBER, - JSON_BOOLEAN, - JSON_OBJECT, - JSON_RAW -} kazoo_json_field_type; - -typedef enum { - FIELD_NONE, - FIELD_COPY, - FIELD_STATIC, - FIELD_FIRST_OF, - FIELD_EXPAND, - FIELD_PREFIX, - FIELD_OBJECT, - FIELD_GROUP, - FIELD_REFERENCE - -} kazoo_field_type; - -typedef struct kazoo_field_t kazoo_field; -typedef kazoo_field *kazoo_field_ptr; - -typedef struct kazoo_fields_t kazoo_fields; -typedef kazoo_fields *kazoo_fields_ptr; - -typedef struct kazoo_definition_t kazoo_definition; -typedef kazoo_definition *kazoo_definition_ptr; - -struct kazoo_field_t { - char* name; - char* value; - char* as; - kazoo_list_t list; - switch_bool_t exclude_prefix; - kazoo_field_type in_type; - kazoo_json_field_type out_type; - int out_type_as_array; - kazoo_filter_ptr filter; - - kazoo_definition_ptr ref; - kazoo_field_ptr next; - kazoo_fields_ptr children; -}; - -struct kazoo_fields_t { - kazoo_field_ptr head; - int verbose; -}; - - -struct kazoo_definition_t { - char* name; - kazoo_field_ptr head; - kazoo_filter_ptr filter; -}; - -struct kazoo_event { - kazoo_event_profile_ptr profile; - char *name; - kazoo_fields_ptr fields; - kazoo_filter_ptr filter; - kazoo_loglevels_ptr logging; - - kazoo_event_t* next; -}; - -struct kazoo_event_profile { - char *name; - kazoo_config_ptr root; - switch_bool_t running; - switch_memory_pool_t *pool; - kazoo_filter_ptr filter; - kazoo_fields_ptr fields; - kazoo_event_ptr events; - - kazoo_loglevels_ptr logging; -}; - -struct kazoo_fetch_profile { - char *name; - kazoo_config_ptr root; - switch_bool_t running; - switch_memory_pool_t *pool; - kazoo_fields_ptr fields; - int fetch_timeout; - switch_mutex_t *fetch_reply_mutex; - switch_hash_t *fetch_reply_hash; - switch_xml_binding_t *fetch_binding; - switch_xml_section_t section; - - kazoo_loglevels_ptr logging; -}; - -#endif /* KAZOO_FIELDS_H */ - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_message.c b/src/mod/event_handlers/mod_kazoo/kazoo_message.c deleted file mode 100644 index 43716a8e02..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_message.c +++ /dev/null @@ -1,488 +0,0 @@ -/* -* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II -* -* Version: MPL 1.1 -* -* The contents of this file are subject to the Mozilla Public License Version -* 1.1 (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" basis, -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -* for the specific language governing rights and limitations under the -* License. -* -* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* -* The Initial Developer of the Original Code is -* Anthony Minessale II -* Portions created by the Initial Developer are Copyright (C) -* the Initial Developer. All Rights Reserved. -* -* Based on mod_skel by -* Anthony Minessale II -* -* Contributor(s): -* -* Daniel Bryars -* Tim Brown -* Anthony Minessale II -* William King -* Mike Jerris -* -* kazoo.c -- Sends FreeSWITCH events to an AMQP broker -* -*/ - -#include "mod_kazoo.h" - -/* deletes then add */ -void kazoo_cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -{ - cJSON_DeleteItemFromObject(object, string); - cJSON_AddItemToObject(object, string, item); -} - -static int inline filter_compare(switch_event_t* evt, kazoo_filter_ptr filter, kazoo_logging_ptr logging) -{ - switch_event_header_t *header; - int hasValue = 0, n; - char *value = NULL, *expr = NULL; - - switch(filter->compare) { - - case FILTER_COMPARE_EXISTS: - hasValue = switch_event_get_header(evt, filter->name) != NULL ? 1 : 0; - switch_log_printf(SWITCH_CHANNEL_LOG, logging->levels->trace_log_level, "profile[%s] event %s checking if %s exists => %s\n", logging->profile_name, logging->event_name, filter->name, hasValue ? "true" : "false"); - break; - - case FILTER_COMPARE_VALUE: - if (*filter->name == '$') { - value = expr = kz_event_expand_headers(evt, filter->name); - } else { - value = switch_event_get_header(evt, filter->name); - } - hasValue = value ? !strcmp(value, filter->value) : 0; - switch_log_printf(SWITCH_CHANNEL_LOG, logging->levels->trace_log_level, "profile[%s] event %s compare value %s to %s => %s == %s => %s\n", logging->profile_name, logging->event_name, filter->name, filter->value, value, filter->value, hasValue ? "true" : "false"); - break; - - case FILTER_COMPARE_FIELD: - if (*filter->name == '$') { - value = expr = kz_event_expand_headers(evt, filter->name); - } else { - value = switch_event_get_header(evt, filter->name); - } - hasValue = value ? !strcmp(value, switch_event_get_header_nil(evt, filter->value)) : 0; - switch_log_printf(SWITCH_CHANNEL_LOG, logging->levels->trace_log_level, "profile[%s] event %s compare field %s to %s => %s == %s => %s\n", logging->profile_name, logging->event_name, filter->name, filter->value, value, switch_event_get_header_nil(evt, filter->value), hasValue ? "true" : "false"); - break; - - case FILTER_COMPARE_PREFIX: - for (header = evt->headers; header; header = header->next) { - if(!strncmp(header->name, filter->value, strlen(filter->value))) { - hasValue = 1; - break; - } - } - break; - - case FILTER_COMPARE_LIST: - if (*filter->name == '$') { - value = expr = kz_event_expand_headers(evt, filter->name); - } else { - value = switch_event_get_header(evt, filter->name); - } - if(value) { - for(n = 0; n < filter->list.size; n++) { - if(!strncmp(value, filter->list.value[n], strlen(filter->list.value[n]))) { - hasValue = 1; - break; - } - } - } - break; - - case FILTER_COMPARE_REGEX: - break; - - default: - break; - } - - switch_safe_free(expr); - - return hasValue; -} - -static kazoo_filter_ptr inline filter_event(switch_event_t* evt, kazoo_filter_ptr filter, kazoo_logging_ptr logging) -{ - while(filter) { - int hasValue = filter_compare(evt, filter, logging); - if(filter->type == FILTER_EXCLUDE) { - if(hasValue) - break; - } else if(filter->type == FILTER_INCLUDE) { - if(!hasValue) - break; - } - filter = filter->next; - } - return filter; -} - -static void kazoo_event_init_json_fields(switch_event_t *event, cJSON *json) -{ - switch_event_header_t *hp; - for (hp = event->headers; hp; hp = hp->next) { - if (strncmp(hp->name, "_json_", 6)) { - if (hp->idx) { - cJSON *a = cJSON_CreateArray(); - int i; - - for(i = 0; i < hp->idx; i++) { - cJSON_AddItemToArray(a, cJSON_CreateString(hp->array[i])); - } - - cJSON_AddItemToObject(json, hp->name, a); - - } else { - cJSON_AddItemToObject(json, hp->name, cJSON_CreateString(hp->value)); - } - } - } -} - -static switch_status_t kazoo_event_init_json(kazoo_fields_ptr fields1, kazoo_fields_ptr fields2, switch_event_t* evt, cJSON** clone) -{ - switch_status_t status = SWITCH_STATUS_SUCCESS; - if( (fields2 && fields2->verbose) - || (fields1 && fields1->verbose) - || ( (!fields2) && (!fields1)) ) { - *clone = cJSON_CreateObject(); - if((*clone) == NULL) { - status = SWITCH_STATUS_GENERR; - } else { - kazoo_event_init_json_fields(evt, *clone); - } - } else { - *clone = cJSON_CreateObject(); - if((*clone) == NULL) { - status = SWITCH_STATUS_GENERR; - } - } - return status; -} - -static cJSON * kazoo_event_json_value(kazoo_json_field_type type, const char *value) { - cJSON *item = NULL; - switch(type) { - case JSON_STRING: - item = cJSON_CreateString(value); - break; - - case JSON_NUMBER: - item = cJSON_CreateNumber(strtod(value, NULL)); - break; - - case JSON_BOOLEAN: - item = cJSON_CreateBool(switch_true(value)); - break; - - case JSON_OBJECT: - item = cJSON_CreateObject(); - break; - - case JSON_RAW: - item = cJSON_Parse(value); - if (!item) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "parse from raw error!\n"); - item = cJSON_CreateRaw(value); - } - break; - - default: - break; - }; - - return item; -} - -static cJSON * kazoo_event_add_json_value(cJSON *dst, kazoo_field_ptr field, const char *as, const char *value) { - cJSON *item = NULL; - if(value || field->out_type == JSON_OBJECT) { - if((item = kazoo_event_json_value(field->out_type, value)) != NULL) { - kazoo_cJSON_AddItemToObject(dst, as, item); - } - } - return item; -} - - -cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_field_ptr field) -{ - switch_event_header_t *header; - char *expanded; - int i, n; - cJSON *item = NULL; - - switch(field->in_type) { - case FIELD_COPY: - if (!strcmp(field->name, "_body")) { - item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, src->body); - } else if((header = switch_event_get_header_ptr(src, field->name)) != NULL) { - if (header->idx) { - item = cJSON_CreateArray(); - - for(i = 0; i < header->idx; i++) { - cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i])); - } - - kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); - } else if (field->out_type_as_array) { - item = cJSON_CreateArray(); - cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->value)); - kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); - } else { - item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, header->value); - } - } - break; - - case FIELD_EXPAND: - expanded = kz_event_expand_headers(src, field->value); - if(expanded != NULL && !zstr(expanded)) { - item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, expanded); - } - - if (expanded != field->value) { - switch_safe_free(expanded); - } - - break; - - case FIELD_FIRST_OF: - - for(n = 0; n < field->list.size; n++) { - if(*field->list.value[n] == '#') { - item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, ++field->list.value[n]); - break; - } else { - header = switch_event_get_header_ptr(src, field->list.value[n]); - if(header) { - if (header->idx) { - item = cJSON_CreateArray(); - - for(i = 0; i < header->idx; i++) { - cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i])); - } - - kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); - } else { - item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, header->value); - } - - break; - } - } - } - - break; - - case FIELD_PREFIX: - - for (header = src->headers; header; header = header->next) { - if(!strncmp(header->name, field->name, strlen(field->name))) { - if (header->idx) { - cJSON *array = cJSON_CreateArray(); - - for(i = 0; i < header->idx; i++) { - cJSON_AddItemToArray(array, kazoo_event_json_value(field->out_type, header->array[i])); - } - - kazoo_cJSON_AddItemToObject(dst, field->exclude_prefix ? header->name+strlen(field->name) : header->name, array); - } else { - kazoo_event_add_json_value(dst, field, field->exclude_prefix ? header->name+strlen(field->name) : header->name, header->value); - } - } - } - - break; - - case FIELD_STATIC: - item = kazoo_event_add_json_value(dst, field, field->name, field->value); - break; - - case FIELD_GROUP: - item = dst; - break; - - default: - break; - } - - return item; -} - -static switch_status_t kazoo_event_add_fields_to_json(kazoo_logging_ptr logging, cJSON *dst, switch_event_t *src, kazoo_field_ptr field) { - - kazoo_filter_ptr filter; - cJSON *item = NULL; - while(field) { - if(field->in_type == FIELD_REFERENCE) { - if(field->ref) { - if((filter = filter_event(src, field->ref->filter, logging)) != NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, logging->levels->filtered_field_log_level, "profile[%s] event %s, referenced field %s filtered by settings %s : %s\n", logging->profile_name, logging->event_name, field->ref->name, filter->name, filter->value); - } else { - kazoo_event_add_fields_to_json(logging, dst, src, field->ref->head); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "profile[%s] event %s, referenced field %s not found\n", logging->profile_name, logging->event_name, field->name); - } - } else { - if((filter = filter_event(src, field->filter, logging)) != NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, logging->levels->filtered_field_log_level, "profile[%s] event %s, field %s filtered by settings %s : %s\n", logging->profile_name, logging->event_name, field->name, filter->name, filter->value); - } else { - item = kazoo_event_add_field_to_json(dst, src, field); - if(field->children && item != NULL) { - if(field->children->verbose && field->out_type == JSON_OBJECT) { - kazoo_event_init_json_fields(src, item); - } - kazoo_event_add_fields_to_json(logging, field->out_type == JSON_OBJECT ? item : dst, src, field->children->head); - } - } - } - - field = field->next; - } - - return SWITCH_STATUS_SUCCESS; -} - -#define EVENT_TIMESTAMP_FIELD "Event-Date-Timestamp" -#define JSON_TIMESTAMP_FIELD "Event-Timestamp" - -static switch_status_t kazoo_event_add_timestamp(switch_event_t* evt, cJSON* JObj) -{ - switch_event_header_t *header; - cJSON *item = NULL; - if((header = switch_event_get_header_ptr(evt, EVENT_TIMESTAMP_FIELD)) != NULL) { - if ((item = kazoo_event_json_value(JSON_NUMBER, header->value)) != NULL) { - kazoo_cJSON_AddItemToObject(JObj, JSON_TIMESTAMP_FIELD, item); - return SWITCH_STATUS_SUCCESS; - } - } - return SWITCH_STATUS_NOTFOUND; -} - -kazoo_message_ptr kazoo_message_create_event(switch_event_t* evt, kazoo_event_ptr event, kazoo_event_profile_ptr profile) -{ - kazoo_message_ptr message; - cJSON *JObj = NULL; - kazoo_filter_ptr filtered; - kazoo_logging_t logging; - - logging.levels = profile->logging; - logging.event_name = evt->subclass_name ? evt->subclass_name : switch_event_get_header_nil(evt, "Event-Name"); - logging.profile_name = profile->name; - - message = malloc(sizeof(kazoo_message_t)); - if(message == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocating memory for serializing event to json\n"); - return NULL; - } - memset(message, 0, sizeof(kazoo_message_t)); - - if(profile->filter) { - // filtering - if((filtered = filter_event(evt, profile->filter, &logging)) != NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, logging.levels->filtered_event_log_level, "profile[%s] event %s filtered by profile settings %s : %s\n", logging.profile_name, logging.event_name, filtered->name, filtered->value); - kazoo_message_destroy(&message); - return NULL; - } - } - - if (event->logging) { - logging.levels = event->logging; - } - - if (event && event->filter) { - if((filtered = filter_event(evt, event->filter, &logging)) != NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, logging.levels->filtered_event_log_level, "profile[%s] event %s filtered by event settings %s : %s\n", logging.profile_name, logging.event_name, filtered->name, filtered->value); - kazoo_message_destroy(&message); - return NULL; - } - } - - kazoo_event_init_json(profile->fields, event ? event->fields : NULL, evt, &JObj); - - kazoo_event_add_timestamp(evt, JObj); - - if(profile->fields) - kazoo_event_add_fields_to_json(&logging, JObj, evt, profile->fields->head); - - if(event && event->fields) - kazoo_event_add_fields_to_json(&logging, JObj, evt, event->fields->head); - - message->JObj = JObj; - - - return message; - - -} - -kazoo_message_ptr kazoo_message_create_fetch(switch_event_t* evt, kazoo_fetch_profile_ptr profile) -{ - kazoo_message_ptr message; - cJSON *JObj = NULL; - kazoo_logging_t logging; - - logging.levels = profile->logging; - logging.event_name = switch_event_get_header_nil(evt, "Event-Name"); - logging.profile_name = profile->name; - - message = malloc(sizeof(kazoo_message_t)); - if(message == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocating memory for serializing event to json\n"); - return NULL; - } - memset(message, 0, sizeof(kazoo_message_t)); - - - kazoo_event_init_json(profile->fields, NULL, evt, &JObj); - - kazoo_event_add_timestamp(evt, JObj); - - if(profile->fields) - kazoo_event_add_fields_to_json(&logging, JObj, evt, profile->fields->head); - - message->JObj = JObj; - - - return message; - - -} - - -void kazoo_message_destroy(kazoo_message_ptr *msg) -{ - if (!msg || !*msg) return; - if((*msg)->JObj != NULL) - cJSON_Delete((*msg)->JObj); - switch_safe_free(*msg); - -} - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_message.h b/src/mod/event_handlers/mod_kazoo/kazoo_message.h deleted file mode 100644 index eade6c4e7b..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_message.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II -* -* Version: MPL 1.1 -* -* The contents of this file are subject to the Mozilla Public License Version -* 1.1 (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" basis, -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -* for the specific language governing rights and limitations under the -* License. -* -* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* -* The Initial Developer of the Original Code is -* Anthony Minessale II -* Portions created by the Initial Developer are Copyright (C) -* the Initial Developer. All Rights Reserved. -* -* Based on mod_skel by -* Anthony Minessale II -* -* Contributor(s): -* -* Daniel Bryars -* Tim Brown -* Anthony Minessale II -* William King -* Mike Jerris -* -* kazoo.c -- Sends FreeSWITCH events to an AMQP broker -* -*/ - -#ifndef KAZOO_MESSAGE_H -#define KAZOO_MESSAGE_H - -#include - -typedef struct { - uint64_t timestamp; - uint64_t start; - uint64_t filter; - uint64_t serialize; - uint64_t print; - uint64_t rk; -} kazoo_message_times_t, *kazoo_message_times_ptr; - -typedef struct { - cJSON *JObj; -} kazoo_message_t, *kazoo_message_ptr; - -void kazoo_cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); -cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_field_ptr field); -kazoo_message_ptr kazoo_message_create_event(switch_event_t* evt, kazoo_event_ptr event, kazoo_event_profile_ptr profile); -kazoo_message_ptr kazoo_message_create_fetch(switch_event_t* evt, kazoo_fetch_profile_ptr profile); - -void kazoo_message_destroy(kazoo_message_ptr *msg); - - -#endif /* KAZOO_MESSAGE_H */ - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_node.c b/src/mod/event_handlers/mod_kazoo/kazoo_node.c deleted file mode 100644 index f75c327023..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_node.c +++ /dev/null @@ -1,1694 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * Andrew Thompson - * Rob Charlton - * Darren Schreiber - * Mike Jerris - * Tamas Cseke - * - * - * handle_msg.c -- handle messages received from erlang nodes - * - */ -#include "mod_kazoo.h" - -struct api_command_struct_s { - char *cmd; - char *arg; - ei_node_t *ei_node; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - erlang_pid pid; - switch_memory_pool_t *pool; -}; -typedef struct api_command_struct_s api_command_struct_t; - -static char *REQUEST_ATOMS[] = { - "noevents", - "exit", - "link", - "nixevent", - "sendevent", - "sendmsg", - "commands", - "command", - "bind", - "getpid", - "version", - "bgapi", - "api", - "event", - "fetch_reply", - "config", - "bgapi4", - "api4", - "json_api" -}; - -typedef enum { - REQUEST_NOEVENTS, - REQUEST_EXIT, - REQUEST_LINK, - REQUEST_NIXEVENT, - REQUEST_SENDEVENT, - REQUEST_SENDMSG, - REQUEST_COMMANDS, - REQUEST_COMMAND, - REQUEST_BIND, - REQUEST_GETPID, - REQUEST_VERSION, - REQUEST_BGAPI, - REQUEST_API, - REQUEST_EVENT, - REQUEST_FETCH_REPLY, - REQUEST_CONFIG, - REQUEST_BGAPI4, - REQUEST_API4, - REQUEST_JSON_API, - REQUEST_MAX -} request_atoms_t; - -static switch_status_t find_request(char *atom, int *request) { - int i; - for (i = 0; i < REQUEST_MAX; i++) { - if(!strncmp(atom, REQUEST_ATOMS[i], MAXATOMLEN)) { - *request = i; - return SWITCH_STATUS_SUCCESS; - } - } - - return SWITCH_STATUS_FALSE; -} - -static void destroy_node_handler(ei_node_t *ei_node) { - int pending = 0; - void *pop; - switch_memory_pool_t *pool = ei_node->pool; - - switch_clear_flag(ei_node, LFLAG_RUNNING); - - /* wait for pending bgapi requests to complete */ - while ((pending = switch_atomic_read(&ei_node->pending_bgapi))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for %d pending bgapi requests to complete\n", pending); - switch_yield(500000); - } - - /* wait for receive handlers to complete */ - while ((pending = switch_atomic_read(&ei_node->receive_handlers))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for %d receive handlers to complete\n", pending); - switch_yield(500000); - } - - switch_mutex_lock(ei_node->event_streams_mutex); - remove_event_streams(&ei_node->event_streams); - switch_mutex_unlock(ei_node->event_streams_mutex); - - remove_xml_clients(ei_node); - - while (switch_queue_trypop(ei_node->received_msgs, &pop) == SWITCH_STATUS_SUCCESS) { - ei_received_msg_t *received_msg = (ei_received_msg_t *) pop; - - ei_x_free(&received_msg->buf); - switch_safe_free(received_msg); - } - - while (switch_queue_trypop(ei_node->send_msgs, &pop) == SWITCH_STATUS_SUCCESS) { - ei_send_msg_t *send_msg = (ei_send_msg_t *) pop; - - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - } - - close_socketfd(&ei_node->nodefd); - - switch_mutex_destroy(ei_node->event_streams_mutex); - - switch_core_destroy_memory_pool(&pool); -} - -static switch_status_t add_to_ei_nodes(ei_node_t *this_ei_node) { - switch_thread_rwlock_wrlock(kazoo_globals.ei_nodes_lock); - - if (!kazoo_globals.ei_nodes) { - kazoo_globals.ei_nodes = this_ei_node; - } else { - this_ei_node->next = kazoo_globals.ei_nodes; - kazoo_globals.ei_nodes = this_ei_node; - } - - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t remove_from_ei_nodes(ei_node_t *this_ei_node) { - ei_node_t *ei_node, *prev = NULL; - int found = 0; - - switch_thread_rwlock_wrlock(kazoo_globals.ei_nodes_lock); - - /* try to find the event bindings list for the requestor */ - ei_node = kazoo_globals.ei_nodes; - while(ei_node != NULL) { - if (ei_node == this_ei_node) { - found = 1; - break; - } - - prev = ei_node; - ei_node = ei_node->next; - } - - if (found) { - if (!prev) { - kazoo_globals.ei_nodes = this_ei_node->next; - } else { - prev->next = ei_node->next; - } - } - - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - - return SWITCH_STATUS_SUCCESS; -} - -void kazoo_event_add_unique_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data) { - if(!switch_event_get_header_ptr(event, header_name)) - switch_event_add_header_string(event, stack, header_name, data); -} - - -SWITCH_DECLARE(switch_status_t) kazoo_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream, char** reply) -{ - switch_api_interface_t *api; - switch_status_t status; - char *arg_used; - char *cmd_used; - int fire_event = 0; - char *arg_expanded = NULL; - switch_event_t* evt; - - switch_assert(stream != NULL); - switch_assert(stream->data != NULL); - switch_assert(stream->write_function != NULL); - - switch_event_create(&evt, SWITCH_EVENT_GENERAL); - arg_expanded = switch_event_expand_headers(evt, arg); - switch_event_destroy(&evt); - - cmd_used = (char *) cmd; - arg_used = arg_expanded; - - if (!stream->param_event) { - switch_event_create(&stream->param_event, SWITCH_EVENT_API); - fire_event = 1; - } - - if (stream->param_event) { - if (cmd_used && *cmd_used) { - switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command", cmd_used); - } - if (arg_used && *arg_used) { - switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command-Argument", arg_used); - } - if (arg_expanded && *arg_expanded) { - switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command-Argument-Expanded", arg_expanded); - } - } - - - if (cmd_used && (api = switch_loadable_module_get_api_interface(cmd_used)) != 0) { - if ((status = api->function(arg_used, session, stream)) != SWITCH_STATUS_SUCCESS) { - kazoo_event_add_unique_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Result", "error"); - kazoo_event_add_unique_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Error", stream->data); - } else { - kazoo_event_add_unique_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Result", "success"); - kazoo_event_add_unique_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Output", stream->data); - } - UNPROTECT_INTERFACE(api); - } else { - status = SWITCH_STATUS_FALSE; - kazoo_event_add_unique_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Result", "error"); - kazoo_event_add_unique_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Error", "invalid command"); - } - - if (stream->param_event && fire_event) { - switch_event_fire(&stream->param_event); - } - - if (cmd_used != cmd) { - switch_safe_free(cmd_used); - } - - if (arg_used != arg_expanded) { - switch_safe_free(arg_used); - } - - if (arg_expanded != arg) { - switch_safe_free(arg_expanded); - } - - return status; -} - -static switch_status_t api_exec_stream(char *cmd, char *arg, switch_stream_handle_t *stream, char **reply) { - switch_status_t status = SWITCH_STATUS_FALSE; - - if (kazoo_api_execute(cmd, arg, NULL, stream, reply) != SWITCH_STATUS_SUCCESS) { - if(stream->data && strlen(stream->data)) { - *reply = strdup(stream->data); - status = SWITCH_STATUS_FALSE; - } else { - *reply = switch_mprintf("%s: Command not found", cmd); - status = SWITCH_STATUS_NOTFOUND; - } - } else if (!stream->data || !strlen(stream->data)) { - *reply = switch_mprintf("%s: Command returned no output", cmd); - status = SWITCH_STATUS_SUCCESS; - } else { - *reply = strdup(stream->data); - status = SWITCH_STATUS_SUCCESS; - } - - return status; -} - -static switch_status_t api_exec(char *cmd, char *arg, char **reply) { - switch_stream_handle_t stream = { 0 }; - switch_status_t status = SWITCH_STATUS_FALSE; - - SWITCH_STANDARD_STREAM(stream); - - status = api_exec_stream(cmd, arg, &stream, reply); - - switch_safe_free(stream.data); - - return status; -} - -static void *SWITCH_THREAD_FUNC bgapi3_exec(switch_thread_t *thread, void *obj) { - api_command_struct_t *acs = (api_command_struct_t *) obj; - switch_memory_pool_t *pool = acs->pool; - char *reply = NULL; - char *cmd = acs->cmd; - char *arg = acs->arg; - ei_node_t *ei_node = acs->ei_node; - ei_send_msg_t *send_msg; - - if(!switch_test_flag(ei_node, LFLAG_RUNNING) || !switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring command while shuting down\n"); - switch_atomic_dec(&ei_node->pending_bgapi); - return NULL; - } - - switch_malloc(send_msg, sizeof(*send_msg)); - memcpy(&send_msg->pid, &acs->pid, sizeof(erlang_pid)); - - ei_x_new_with_version(&send_msg->buf); - - ei_x_encode_tuple_header(&send_msg->buf, 3); - - if (api_exec(cmd, arg, &reply) == SWITCH_STATUS_SUCCESS) { - ei_x_encode_atom(&send_msg->buf, "bgok"); - } else { - ei_x_encode_atom(&send_msg->buf, "bgerror"); - } - - _ei_x_encode_string(&send_msg->buf, acs->uuid_str); - _ei_x_encode_string(&send_msg->buf, reply); - - if (switch_queue_trypush(ei_node->send_msgs, send_msg) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to send bgapi response %s to %s <%d.%d.%d>\n" - ,acs->uuid_str - ,acs->pid.node - ,acs->pid.creation - ,acs->pid.num - ,acs->pid.serial); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - } - - switch_atomic_dec(&ei_node->pending_bgapi); - - switch_safe_free(reply); - switch_safe_free(acs->arg); - switch_core_destroy_memory_pool(&pool); - - return NULL; -} - - -static void *SWITCH_THREAD_FUNC bgapi4_exec(switch_thread_t *thread, void *obj) { - api_command_struct_t *acs = (api_command_struct_t *) obj; - switch_memory_pool_t *pool = acs->pool; - char *reply = NULL; - char *cmd = acs->cmd; - char *arg = acs->arg; - ei_node_t *ei_node = acs->ei_node; - ei_send_msg_t *send_msg; - switch_stream_handle_t stream = { 0 }; - - if(!switch_test_flag(ei_node, LFLAG_RUNNING) || !switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring command while shuting down\n"); - switch_atomic_dec(&ei_node->pending_bgapi); - return NULL; - } - - SWITCH_STANDARD_STREAM(stream); - switch_event_create(&stream.param_event, SWITCH_EVENT_API); - - switch_malloc(send_msg, sizeof(*send_msg)); - memcpy(&send_msg->pid, &acs->pid, sizeof(erlang_pid)); - - ei_x_new_with_version(&send_msg->buf); - ei_x_encode_tuple_header(&send_msg->buf, (stream.param_event ? 4 : 3)); - - if (api_exec_stream(cmd, arg, &stream, &reply) == SWITCH_STATUS_SUCCESS) { - ei_x_encode_atom(&send_msg->buf, "bgok"); - } else { - ei_x_encode_atom(&send_msg->buf, "bgerror"); - } - - _ei_x_encode_string(&send_msg->buf, acs->uuid_str); - _ei_x_encode_string(&send_msg->buf, reply); - - if (stream.param_event) { - ei_encode_switch_event_headers_2(&send_msg->buf, stream.param_event, 0); - } - - if (switch_queue_trypush(ei_node->send_msgs, send_msg) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to send bgapi response %s to %s <%d.%d.%d>\n" - ,acs->uuid_str - ,acs->pid.node - ,acs->pid.creation - ,acs->pid.num - ,acs->pid.serial); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - } - - switch_atomic_dec(&ei_node->pending_bgapi); - - if (stream.param_event) { - switch_event_fire(&stream.param_event); - } - - switch_safe_free(reply); - switch_safe_free(acs->arg); - switch_core_destroy_memory_pool(&pool); - switch_safe_free(stream.data); - - return NULL; -} - -static void log_sendmsg_request(char *uuid, switch_event_t *event) -{ - char *cmd = switch_event_get_header(event, "call-command"); - unsigned long cmd_hash; - switch_ssize_t hlen = -1; - unsigned long CMD_EXECUTE = switch_hashfunc_default("execute", &hlen); - unsigned long CMD_XFEREXT = switch_hashfunc_default("xferext", &hlen); - - if (zstr(cmd)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "log|%s|invalid \n", uuid); - DUMP_EVENT(event); - return; - } - - cmd_hash = switch_hashfunc_default(cmd, &hlen); - - if (cmd_hash == CMD_EXECUTE) { - char *app_name = switch_event_get_header(event, "execute-app-name"); - char *app_arg = switch_event_get_header(event, "execute-app-arg"); - - if(app_name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "log|%s|executing %s %s \n", uuid, app_name, switch_str_nil(app_arg)); - } - } else if (cmd_hash == CMD_XFEREXT) { - switch_event_header_t *hp; - - for (hp = event->headers; hp; hp = hp->next) { - char *app_name; - char *app_arg; - - if (!strcasecmp(hp->name, "application")) { - app_name = strdup(hp->value); - app_arg = strchr(app_name, ' '); - - if (app_arg) { - *app_arg++ = '\0'; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "log|%s|building xferext extension: %s %s\n", uuid, app_name, app_arg); - switch_safe_free(app_name); - } - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "log|%s|transfered call to xferext extension\n", uuid); - } -} - -static switch_status_t build_event(switch_event_t *event, ei_x_buff * buf) { - int propslist_length, arity; - int n=0; - - if(!event) { - return SWITCH_STATUS_FALSE; - } - - if (ei_decode_list_header(buf->buff, &buf->index, &propslist_length)) { - return SWITCH_STATUS_FALSE; - } - - while (!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && n < propslist_length) { - char key[1024]; - char *value; - - if (arity != 2) { - return SWITCH_STATUS_FALSE; - } - - if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(key), key)) { - return SWITCH_STATUS_FALSE; - } - - if (ei_decode_string_or_binary(buf->buff, &buf->index, &value)) { - return SWITCH_STATUS_FALSE; - } - - if (!strcmp(key, "body")) { - switch_safe_free(event->body); - event->body = value; - } else { - if(!strcasecmp(key, "Call-ID")) { - switch_core_session_t *session = NULL; - if(!zstr(value)) { - if ((session = switch_core_session_locate(value)) != NULL) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_event_set_data(channel, event); - switch_core_session_rwunlock(session); - } - } - } - switch_event_add_header_string_nodup(event, SWITCH_STACK_BOTTOM, key, value); - } - n++; - } - ei_skip_term(buf->buff, &buf->index); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t erlang_response_badarg(ei_x_buff * rbuf) { - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_atom(rbuf, "badarg"); - } - - return SWITCH_STATUS_GENERR; -} - -static switch_status_t erlang_response_baduuid(ei_x_buff * rbuf) { - if (rbuf) { - ei_x_format_wo_ver(rbuf, "{~a,~a}", "error", "baduuid"); - } - - return SWITCH_STATUS_NOTFOUND; -} - -static switch_status_t erlang_response_notimplemented(ei_x_buff * rbuf) { - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_atom(rbuf, "not_implemented"); - } - - return SWITCH_STATUS_NOTFOUND; -} - -static switch_status_t erlang_response_ok(ei_x_buff *rbuf) { - if (rbuf) { - ei_x_encode_atom(rbuf, "ok"); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t erlang_response_ok_uuid(ei_x_buff *rbuf, const char * uuid) { - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "ok"); - ei_x_encode_binary(rbuf, uuid, strlen(uuid)); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_noevents(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - ei_event_stream_t *event_stream; - - switch_mutex_lock(ei_node->event_streams_mutex); - if ((event_stream = find_event_stream(ei_node->event_streams, pid))) { - remove_event_bindings(event_stream); - } - switch_mutex_unlock(ei_node->event_streams_mutex); - - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_exit(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - switch_clear_flag(ei_node, LFLAG_RUNNING); - - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_link(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - ei_link(ei_node, ei_self(&kazoo_globals.ei_cnode), pid); - - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_nixevent(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char event_name[MAXATOMLEN + 1]; - switch_event_types_t event_type; - ei_event_stream_t *event_stream; - int custom = 0, length = 0; - int i; - - if (ei_decode_list_header(buf->buff, &buf->index, &length) - || length == 0) { - return erlang_response_badarg(rbuf); - } - - switch_mutex_lock(ei_node->event_streams_mutex); - if (!(event_stream = find_event_stream(ei_node->event_streams, pid))) { - switch_mutex_unlock(ei_node->event_streams_mutex); - return erlang_response_ok(rbuf); - } - - for (i = 1; i <= length; i++) { - if (ei_decode_atom_safe(buf->buff, &buf->index, event_name)) { - switch_mutex_unlock(ei_node->event_streams_mutex); - return erlang_response_badarg(rbuf); - } - - if (custom) { - remove_event_binding(event_stream, SWITCH_EVENT_CUSTOM, event_name); - } else if (switch_name_event(event_name, &event_type) == SWITCH_STATUS_SUCCESS) { - switch (event_type) { - - case SWITCH_EVENT_CUSTOM: - custom++; - break; - - case SWITCH_EVENT_ALL: - { - switch_event_types_t type; - for (type = 0; type < SWITCH_EVENT_ALL; type++) { - if(type != SWITCH_EVENT_CUSTOM) { - remove_event_binding(event_stream, type, NULL); - } - } - break; - } - - default: - remove_event_binding(event_stream, event_type, NULL); - } - } else { - switch_mutex_unlock(ei_node->event_streams_mutex); - return erlang_response_badarg(rbuf); - } - } - switch_mutex_unlock(ei_node->event_streams_mutex); - - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_sendevent(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char event_name[MAXATOMLEN + 1]; - char subclass_name[MAXATOMLEN + 1]; - switch_event_types_t event_type; - switch_event_t *event = NULL; - - if (ei_decode_atom_safe(buf->buff, &buf->index, event_name) - || switch_name_event(event_name, &event_type) != SWITCH_STATUS_SUCCESS) - { - return erlang_response_badarg(rbuf); - } - - if (!strncasecmp(event_name, "CUSTOM", MAXATOMLEN)) { - if(ei_decode_atom(buf->buff, &buf->index, subclass_name)) { - return erlang_response_badarg(rbuf); - } - switch_event_create_subclass(&event, event_type, subclass_name); - } else { - switch_event_create(&event, event_type); - } - - if (build_event(event, buf) == SWITCH_STATUS_SUCCESS) { - switch_event_fire(&event); - return erlang_response_ok(rbuf); - } - - if(event) { - switch_event_destroy(&event); - } - - return erlang_response_badarg(rbuf); -} - -static switch_status_t handle_request_command(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - switch_core_session_t *session; - switch_event_t *event = NULL; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - switch_uuid_t cmd_uuid; - char cmd_uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - - if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str)) { - return erlang_response_badarg(rbuf); - } - - if (zstr_buf(uuid_str) || !(session = switch_core_session_locate(uuid_str))) { - return erlang_response_baduuid(rbuf); - } - - switch_uuid_get(&cmd_uuid); - switch_uuid_format(cmd_uuid_str, &cmd_uuid); - - switch_event_create(&event, SWITCH_EVENT_COMMAND); - if (build_event(event, buf) != SWITCH_STATUS_SUCCESS) { - switch_core_session_rwunlock(session); - return erlang_response_badarg(rbuf); - } - - log_sendmsg_request(uuid_str, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event-uuid", cmd_uuid_str); - - switch_core_session_queue_private_event(session, &event, SWITCH_FALSE); - switch_core_session_rwunlock(session); - - return erlang_response_ok_uuid(rbuf, cmd_uuid_str); -} - -static switch_status_t handle_request_commands(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - switch_core_session_t *session; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - int propslist_length, n; - switch_uuid_t cmd_uuid; - char cmd_uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - - if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str)) { - return erlang_response_badarg(rbuf); - } - - if (zstr_buf(uuid_str) || !(session = switch_core_session_locate(uuid_str))) { - return erlang_response_baduuid(rbuf); - } - - switch_uuid_get(&cmd_uuid); - switch_uuid_format(cmd_uuid_str, &cmd_uuid); - - if (ei_decode_list_header(buf->buff, &buf->index, &propslist_length)) { - switch_core_session_rwunlock(session); - return SWITCH_STATUS_FALSE; - } - - for(n = 0; n < propslist_length; n++) { - switch_event_t *event = NULL; - switch_event_create(&event, SWITCH_EVENT_COMMAND); - if (build_event(event, buf) != SWITCH_STATUS_SUCCESS) { - switch_core_session_rwunlock(session); - return erlang_response_badarg(rbuf); - } - log_sendmsg_request(uuid_str, event); - if(n == (propslist_length - 1)) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event-uuid", cmd_uuid_str); - } else { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event-uuid", "null"); -// switch_event_del_header_val(event, "event-uuid-name", NULL); - } - switch_core_session_queue_private_event(session, &event, SWITCH_FALSE); - } - - switch_core_session_rwunlock(session); - - return erlang_response_ok_uuid(rbuf, cmd_uuid_str); - -} - -static switch_status_t handle_request_sendmsg(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - switch_core_session_t *session; - switch_event_t *event = NULL; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - - if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str)) { - return erlang_response_badarg(rbuf); - } - - if (zstr_buf(uuid_str) || !(session = switch_core_session_locate(uuid_str))) { - return erlang_response_baduuid(rbuf); - } - - switch_event_create(&event, SWITCH_EVENT_SEND_MESSAGE); - if (build_event(event, buf) != SWITCH_STATUS_SUCCESS) { - switch_core_session_rwunlock(session); - return erlang_response_badarg(rbuf); - } - - log_sendmsg_request(uuid_str, event); - - switch_core_session_queue_private_event(session, &event, SWITCH_FALSE); - switch_core_session_rwunlock(session); - - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_config(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - - fetch_config(); - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_bind(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char section_str[MAXATOMLEN + 1]; - switch_xml_section_t section; - - if (ei_decode_atom_safe(buf->buff, &buf->index, section_str) - || !(section = switch_xml_parse_section_string(section_str))) { - return erlang_response_badarg(rbuf); - } - - switch(section) { - case SWITCH_XML_SECTION_CONFIG: - add_fetch_handler(ei_node, pid, kazoo_globals.config_fetch_binding); - if(!kazoo_globals.config_fetched) { - kazoo_globals.config_fetched = 1; - fetch_config(); - } - break; - case SWITCH_XML_SECTION_DIRECTORY: - add_fetch_handler(ei_node, pid, kazoo_globals.directory_fetch_binding); - break; - case SWITCH_XML_SECTION_DIALPLAN: - add_fetch_handler(ei_node, pid, kazoo_globals.dialplan_fetch_binding); - break; - case SWITCH_XML_SECTION_CHANNELS: - add_fetch_handler(ei_node, pid, kazoo_globals.channels_fetch_binding); - break; - case SWITCH_XML_SECTION_LANGUAGES: - add_fetch_handler(ei_node, pid, kazoo_globals.languages_fetch_binding); - break; - case SWITCH_XML_SECTION_CHATPLAN: - add_fetch_handler(ei_node, pid, kazoo_globals.chatplan_fetch_binding); - break; - default: - return erlang_response_badarg(rbuf); - } - - return erlang_response_ok(rbuf); -} - -static switch_status_t handle_request_getpid(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "ok"); - ei_x_encode_pid(rbuf, ei_self(&kazoo_globals.ei_cnode)); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_version(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "ok"); - _ei_x_encode_string(rbuf, VERSION); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_bgapi(switch_thread_start_t func, ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - api_command_struct_t *acs = NULL; - switch_memory_pool_t *pool; - switch_thread_t *thread; - switch_threadattr_t *thd_attr = NULL; - switch_uuid_t uuid; - char cmd[MAXATOMLEN + 1]; - - if (ei_decode_atom_safe(buf->buff, &buf->index, cmd)) { - return erlang_response_badarg(rbuf); - } - - switch_core_new_memory_pool(&pool); - acs = switch_core_alloc(pool, sizeof(*acs)); - - if (ei_decode_string_or_binary(buf->buff, &buf->index, &acs->arg)) { - switch_core_destroy_memory_pool(&pool); - return erlang_response_badarg(rbuf); - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "bgexec: %s(%s)\n", cmd, acs->arg); - - acs->pool = pool; - acs->ei_node = ei_node; - acs->cmd = switch_core_strdup(pool, cmd); - memcpy(&acs->pid, pid, sizeof(erlang_pid)); - - switch_threadattr_create(&thd_attr, acs->pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - - switch_uuid_get(&uuid); - switch_uuid_format(acs->uuid_str, &uuid); - switch_thread_create(&thread, thd_attr, func, acs, acs->pool); - - switch_atomic_inc(&ei_node->pending_bgapi); - - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "ok"); - _ei_x_encode_string(rbuf, acs->uuid_str); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_bgapi3(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - return handle_request_bgapi(bgapi3_exec, ei_node, pid, buf, rbuf); -} - -static switch_status_t handle_request_bgapi4(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - return handle_request_bgapi(bgapi4_exec, ei_node, pid, buf, rbuf); -} - -static switch_status_t handle_request_api4(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char cmd[MAXATOMLEN + 1]; - char *arg; - switch_stream_handle_t stream = { 0 }; - - SWITCH_STANDARD_STREAM(stream); - switch_event_create(&stream.param_event, SWITCH_EVENT_API); - - if (ei_decode_atom_safe(buf->buff, &buf->index, cmd)) { - return erlang_response_badarg(rbuf); - } - - if (ei_decode_string_or_binary(buf->buff, &buf->index, &arg)) { - return erlang_response_badarg(rbuf); - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "exec: %s(%s)\n", cmd, arg); - - if (rbuf) { - char *reply; - switch_status_t status; - - status = api_exec_stream(cmd, arg, &stream, &reply); - - if (status == SWITCH_STATUS_SUCCESS) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "ok"); - } else { - ei_x_encode_tuple_header(rbuf, (stream.param_event ? 3 : 2)); - ei_x_encode_atom(rbuf, "error"); - } - - _ei_x_encode_string(rbuf, reply); - - if (stream.param_event && status != SWITCH_STATUS_SUCCESS) { - ei_encode_switch_event_headers(rbuf, stream.param_event); - } - - switch_safe_free(reply); - } - - if (stream.param_event) { - switch_event_fire(&stream.param_event); - } - - switch_safe_free(arg); - switch_safe_free(stream.data); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_json_api(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) -{ - char *arg; - cJSON *jcmd = NULL; - switch_core_session_t *session = NULL; - const char *uuid = NULL; - char *response = NULL; - const char *parse_end = NULL; - switch_status_t status = SWITCH_STATUS_SUCCESS; - - if (ei_decode_string_or_binary(buf->buff, &buf->index, &arg)) { - return erlang_response_badarg(rbuf); - } - - jcmd = cJSON_ParseWithOpts(arg, &parse_end, 0); - - if (!jcmd) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "json api error: %s\n", parse_end); - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "parse_error"); - _ei_x_encode_string(rbuf, parse_end); - switch_safe_free(arg); - return status; - } - - if ((uuid = cJSON_GetObjectCstr(jcmd, "uuid"))) { - if (!(session = switch_core_session_locate(uuid))) { - cJSON_Delete(jcmd); - switch_safe_free(arg); - return erlang_response_baduuid(rbuf); - } - } - - status = switch_json_api_execute(jcmd, session, NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "json api (%i): %s\n", status , arg); - - response = cJSON_PrintUnformatted(jcmd); - ei_x_encode_tuple_header(rbuf, 2); - if (status == SWITCH_STATUS_SUCCESS) { - ei_x_encode_atom(rbuf, "ok"); - } else { - ei_x_encode_atom(rbuf, "error"); - } - _ei_x_encode_string(rbuf, response); - switch_safe_free(response); - - cJSON_Delete(jcmd); - switch_safe_free(arg); - - if (session) { - switch_core_session_rwunlock(session); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_api(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char cmd[MAXATOMLEN + 1]; - char *arg; - - if (ei_decode_atom_safe(buf->buff, &buf->index, cmd)) { - return erlang_response_badarg(rbuf); - } - - if (ei_decode_string_or_binary(buf->buff, &buf->index, &arg)) { - return erlang_response_badarg(rbuf); - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "exec: %s(%s)\n", cmd, arg); - - if (rbuf) { - char *reply; - - ei_x_encode_tuple_header(rbuf, 2); - - if (api_exec(cmd, arg, &reply) == SWITCH_STATUS_SUCCESS) { - ei_x_encode_atom(rbuf, "ok"); - } else { - ei_x_encode_atom(rbuf, "error"); - } - - _ei_x_encode_string(rbuf, reply); - switch_safe_free(reply); - } - - switch_safe_free(arg); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_event(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char event_name[MAXATOMLEN + 1]; - ei_event_stream_t *event_stream; - int length = 0; - int i; - - if (ei_decode_list_header(buf->buff, &buf->index, &length) || !length) { - return erlang_response_badarg(rbuf); - } - - switch_mutex_lock(ei_node->event_streams_mutex); - if (!(event_stream = find_event_stream(ei_node->event_streams, pid))) { - event_stream = new_event_stream(ei_node, pid); - /* ensure we are notified if the requesting processes dies so we can clean up */ - ei_link(ei_node, ei_self(&kazoo_globals.ei_cnode), pid); - } - - for (i = 1; i <= length; i++) { - if (ei_decode_atom_safe(buf->buff, &buf->index, event_name)) { - switch_mutex_unlock(ei_node->event_streams_mutex); - return erlang_response_badarg(rbuf); - } - add_event_binding(event_stream, event_name); - } - switch_mutex_unlock(ei_node->event_streams_mutex); - - if (rbuf) { - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "ok"); - - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_string(rbuf, ei_node->local_ip); - ei_x_encode_ulong(rbuf, get_stream_port(event_stream)); - } - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t handle_request_fetch_reply(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char section_str[MAXATOMLEN + 1]; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - char *xml_str; - switch_xml_section_t section; - switch_status_t result; - - if (ei_decode_atom_safe(buf->buff, &buf->index, section_str) - || !(section = switch_xml_parse_section_string(section_str))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without a configuration section\n"); - - return erlang_response_badarg(rbuf); - } - - if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str) - || zstr_buf(uuid_str)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without request UUID\n"); - - return erlang_response_badarg(rbuf); - } - - if (ei_decode_string_or_binary(buf->buff, &buf->index, &xml_str)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without XML : %s \n", uuid_str); - - return erlang_response_badarg(rbuf); - } - - if (zstr(xml_str)) { - switch_safe_free(xml_str); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring an empty fetch reply : %s\n", uuid_str); - - return erlang_response_badarg(rbuf); - } - - switch(section) { - case SWITCH_XML_SECTION_CONFIG: - result = fetch_reply(uuid_str, xml_str, kazoo_globals.config_fetch_binding); - break; - case SWITCH_XML_SECTION_DIRECTORY: - result = fetch_reply(uuid_str, xml_str, kazoo_globals.directory_fetch_binding); - break; - case SWITCH_XML_SECTION_DIALPLAN: - result = fetch_reply(uuid_str, xml_str, kazoo_globals.dialplan_fetch_binding); - break; - case SWITCH_XML_SECTION_CHANNELS: - result = fetch_reply(uuid_str, xml_str, kazoo_globals.channels_fetch_binding); - break; - case SWITCH_XML_SECTION_LANGUAGES: - result = fetch_reply(uuid_str, xml_str, kazoo_globals.languages_fetch_binding); - break; - case SWITCH_XML_SECTION_CHATPLAN: - result = fetch_reply(uuid_str, xml_str, kazoo_globals.chatplan_fetch_binding); - break; - default: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s for an unknown configuration section: %s : %s\n", uuid_str, section_str, xml_str); - switch_safe_free(xml_str); - - return erlang_response_badarg(rbuf); - } - - if (result == SWITCH_STATUS_SUCCESS) { - switch_safe_free(xml_str); - - return erlang_response_ok(rbuf); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s is unknown or has expired : %s\n", uuid_str, xml_str); - switch_safe_free(xml_str); - - return erlang_response_baduuid(rbuf); - } -} - -static switch_status_t handle_kazoo_request(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { - char atom[MAXATOMLEN + 1]; - int type, size, arity = 0, request; - - /* ...{_, _}} | ...atom()} = Buf */ - ei_get_type(buf->buff, &buf->index, &type, &size); - - /* is_tuple(Type) */ - if (type == ERL_SMALL_TUPLE_EXT) { - /* ..._, _} = Buf */ - ei_decode_tuple_header(buf->buff, &buf->index, &arity); - } - - if (ei_decode_atom_safe(buf->buff, &buf->index, atom)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received mod_kazoo message that did not contain a command (ensure you are using Kazoo v2.14+).\n"); - return erlang_response_badarg(rbuf); - } - - if (find_request(atom, &request) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received mod_kazoo message for unimplemented feature (ensure you are using Kazoo v2.14+): %s\n", atom); - return erlang_response_badarg(rbuf); - } - - switch(request) { - case REQUEST_NOEVENTS: - return handle_request_noevents(ei_node, pid, buf, rbuf); - case REQUEST_EXIT: - return handle_request_exit(ei_node, pid, buf, rbuf); - case REQUEST_LINK: - return handle_request_link(ei_node, pid, buf, rbuf); - case REQUEST_NIXEVENT: - return handle_request_nixevent(ei_node, pid, buf, rbuf); - case REQUEST_SENDEVENT: - return handle_request_sendevent(ei_node, pid, buf, rbuf); - case REQUEST_SENDMSG: - return handle_request_sendmsg(ei_node, pid, buf, rbuf); - case REQUEST_COMMAND: - return handle_request_command(ei_node, pid, buf, rbuf); - case REQUEST_COMMANDS: - return handle_request_commands(ei_node, pid, buf, rbuf); - case REQUEST_BIND: - return handle_request_bind(ei_node, pid, buf, rbuf); - case REQUEST_GETPID: - return handle_request_getpid(ei_node, pid, buf, rbuf); - case REQUEST_VERSION: - return handle_request_version(ei_node, pid, buf, rbuf); - case REQUEST_BGAPI: - return handle_request_bgapi3(ei_node, pid, buf, rbuf); - case REQUEST_API: - return handle_request_api(ei_node, pid, buf, rbuf); - case REQUEST_EVENT: - return handle_request_event(ei_node, pid, buf, rbuf); - case REQUEST_FETCH_REPLY: - return handle_request_fetch_reply(ei_node, pid, buf, rbuf); - case REQUEST_CONFIG: - return handle_request_config(ei_node, pid, buf, rbuf); - case REQUEST_BGAPI4: - return handle_request_bgapi4(ei_node, pid, buf, rbuf); - case REQUEST_API4: - return handle_request_api4(ei_node, pid, buf, rbuf); - case REQUEST_JSON_API: - return handle_request_json_api(ei_node, pid, buf, rbuf); - default: - return erlang_response_notimplemented(rbuf); - } -} - -static switch_status_t handle_mod_kazoo_request(ei_node_t *ei_node, erlang_msg *msg, ei_x_buff *buf) { - char atom[MAXATOMLEN + 1]; - int version, type, size, arity; - - buf->index = 0; - ei_decode_version(buf->buff, &buf->index, &version); - ei_get_type(buf->buff, &buf->index, &type, &size); - - /* is_tuple(Type) */ - if (type != ERL_SMALL_TUPLE_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang message of an unexpected type (ensure you are using Kazoo v2.14+).\n"); - return SWITCH_STATUS_GENERR; - } - - ei_decode_tuple_header(buf->buff, &buf->index, &arity); - - if (ei_decode_atom_safe(buf->buff, &buf->index, atom)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang message tuple that did not start with an atom (ensure you are using Kazoo v2.14+).\n"); - return SWITCH_STATUS_GENERR; - } - - /* {'$gen_cast', {_, _}} = Buf */ - if (arity == 2 && !strncmp(atom, "$gen_cast", 9)) { - return handle_kazoo_request(ei_node, &msg->from, buf, NULL); - /* {'$gen_call', {_, _}, {_, _}} = Buf */ - } else if (arity == 3 && !strncmp(atom, "$gen_call", 9)) { - switch_status_t status; - ei_send_msg_t *send_msg = NULL; - erlang_ref ref; - - switch_malloc(send_msg, sizeof(*send_msg)); - ei_x_new_with_version(&send_msg->buf); - - /* ...{_, _}, {_, _}} = Buf */ - ei_get_type(buf->buff, &buf->index, &type, &size); - - /* is_tuple(Type) */ - if (type != ERL_SMALL_TUPLE_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang call message of an unexpected type (ensure you are using Kazoo v2.14+).\n"); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - return SWITCH_STATUS_GENERR; - } - - /* ..._, _}, {_, _}} = Buf */ - ei_decode_tuple_header(buf->buff, &buf->index, &arity); - - /* ...pid(), _}, {_, _}} = Buf */ - if (ei_decode_pid(buf->buff, &buf->index, &send_msg->pid)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang call without a reply pid (ensure you are using Kazoo v2.14+).\n"); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - return SWITCH_STATUS_GENERR; - } - - /* ...ref()}, {_, _}} = Buf */ - if (ei_decode_ref(buf->buff, &buf->index, &ref)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang call without a reply tag (ensure you are using Kazoo v2.14+).\n"); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - return SWITCH_STATUS_GENERR; - } - - /* send_msg->buf = {ref(), ... */ - ei_x_encode_tuple_header(&send_msg->buf, 2); - ei_x_encode_ref(&send_msg->buf, &ref); - - status = handle_kazoo_request(ei_node, &msg->from, buf, &send_msg->buf); - - if (switch_queue_trypush(ei_node->send_msgs, send_msg) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error queuing reply\n"); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - } - - return status; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received inappropriate erlang message (ensure you are using Kazoo v2.14+)\n"); - return SWITCH_STATUS_GENERR; - } -} - -/* fake enough of the net_kernel module to be able to respond to net_adm:ping */ -static switch_status_t handle_net_kernel_request(ei_node_t *ei_node, erlang_msg *msg, ei_x_buff *buf) { - int version, size, type, arity; - char atom[MAXATOMLEN + 1]; - ei_send_msg_t *send_msg = NULL; - erlang_ref ref; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received net_kernel message, attempting to reply\n"); - - switch_malloc(send_msg, sizeof(*send_msg)); - ei_x_new_with_version(&send_msg->buf); - - buf->index = 0; - ei_decode_version(buf->buff, &buf->index, &version); - ei_get_type(buf->buff, &buf->index, &type, &size); - - /* is_tuple(Buff) */ - if (type != ERL_SMALL_TUPLE_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received net_kernel message of an unexpected type\n"); - goto error; - } - - ei_decode_tuple_header(buf->buff, &buf->index, &arity); - - /* {_, _, _} = Buf */ - if (arity != 3) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received net_kernel tuple has an unexpected arity\n"); - goto error; - } - - /* {'$gen_call', _, _} = Buf */ - if (ei_decode_atom_safe(buf->buff, &buf->index, atom) || strncmp(atom, "$gen_call", 9)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received net_kernel message tuple does not begin with the atom '$gen_call'\n"); - goto error; - } - - ei_get_type(buf->buff, &buf->index, &type, &size); - - /* {_, Sender, _}=Buff, is_tuple(Sender) */ - if (type != ERL_SMALL_TUPLE_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Second element of the net_kernel tuple is an unexpected type\n"); - goto error; - } - - ei_decode_tuple_header(buf->buff, &buf->index, &arity); - - /* {_, _}=Sender */ - if (arity != 2) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Second element of the net_kernel message has an unexpected arity\n"); - goto error; - } - - /* {Pid, Ref}=Sender */ - if (ei_decode_pid(buf->buff, &buf->index, &send_msg->pid) || ei_decode_ref(buf->buff, &buf->index, &ref)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unable to decode erlang pid or ref of the net_kernel tuple second element\n"); - goto error; - } - - ei_get_type(buf->buff, &buf->index, &type, &size); - - /* {_, _, Request}=Buff, is_tuple(Request) */ - if (type != ERL_SMALL_TUPLE_EXT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Third element of the net_kernel message is an unexpected type\n"); - goto error; - } - - ei_decode_tuple_header(buf->buff, &buf->index, &arity); - - /* {_, _}=Request */ - if (arity != 2) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Third element of the net_kernel message has an unexpected arity\n"); - goto error; - } - - /* {is_auth, _}=Request */ - if (ei_decode_atom_safe(buf->buff, &buf->index, atom) || strncmp(atom, "is_auth", MAXATOMLEN)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "The net_kernel message third element does not begin with the atom 'is_auth'\n"); - goto error; - } - - /* To ! {Tag, Reply} */ - ei_x_encode_tuple_header(&send_msg->buf, 2); - ei_x_encode_ref(&send_msg->buf, &ref); - ei_x_encode_atom(&send_msg->buf, "yes"); - - if (switch_queue_trypush(ei_node->send_msgs, send_msg) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to queue net kernel message\n"); - goto error; - } - - return SWITCH_STATUS_SUCCESS; - -error: - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - return SWITCH_STATUS_GENERR; -} - -static switch_status_t handle_erl_send(ei_node_t *ei_node, erlang_msg *msg, ei_x_buff *buf) { - if (!strncmp(msg->toname, "net_kernel", MAXATOMLEN)) { - return handle_net_kernel_request(ei_node, msg, buf); - } else if (!strncmp(msg->toname, "mod_kazoo", MAXATOMLEN)) { - return handle_mod_kazoo_request(ei_node, msg, buf); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang message to unknown process \"%s\" (ensure you are using Kazoo v2.14+).\n", msg->toname); - return SWITCH_STATUS_GENERR; - } -} - -static switch_status_t handle_erl_msg(ei_node_t *ei_node, erlang_msg *msg, ei_x_buff *buf) { - switch (msg->msgtype) { - case ERL_SEND: - case ERL_REG_SEND: - return handle_erl_send(ei_node, msg, buf); - case ERL_LINK: - /* we received an erlang link request? Should we be linking or are they linking to us and this just informs us? */ - return SWITCH_STATUS_SUCCESS; - case ERL_UNLINK: - /* we received an erlang unlink request? Same question as the ERL_LINK, are we expected to do something? */ - return SWITCH_STATUS_SUCCESS; - case ERL_EXIT: - /* we received a notice that a process we were linked to has exited, clean up any bindings */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received erlang exit notice for %s <%d.%d.%d>\n", msg->from.node, msg->from.creation, msg->from.num, msg->from.serial); - - switch_mutex_lock(ei_node->event_streams_mutex); - remove_event_stream(&ei_node->event_streams, &msg->from); - switch_mutex_unlock(ei_node->event_streams_mutex); - - remove_fetch_handlers(ei_node, &msg->from); - return SWITCH_STATUS_SUCCESS; - case ERL_EXIT2: - /* erlang nodes appear to send both the old and new style exit notices so just ignore these */ - return SWITCH_STATUS_FALSE; - default: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Received unexpected erlang message type %d\n", (int) (msg->msgtype)); - return SWITCH_STATUS_FALSE; - } -} - -static void *SWITCH_THREAD_FUNC receive_handler(switch_thread_t *thread, void *obj) { - ei_node_t *ei_node = (ei_node_t *) obj; - - switch_atomic_inc(&kazoo_globals.threads); - switch_atomic_inc(&ei_node->receive_handlers); - - switch_assert(ei_node != NULL); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting erlang receive handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port); - - while (switch_test_flag(ei_node, LFLAG_RUNNING) && switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - void *pop = NULL; - - if (ei_queue_pop(ei_node->received_msgs, &pop, ei_node->receiver_queue_timeout) == SWITCH_STATUS_SUCCESS) { - ei_received_msg_t *received_msg = (ei_received_msg_t *) pop; - handle_erl_msg(ei_node, &received_msg->msg, &received_msg->buf); - ei_x_free(&received_msg->buf); - switch_safe_free(received_msg); - } - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutdown erlang receive handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port); - - switch_atomic_dec(&ei_node->receive_handlers); - switch_atomic_dec(&kazoo_globals.threads); - - return NULL; -} - -static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj) { - ei_node_t *ei_node = (ei_node_t *) obj; - ei_received_msg_t *received_msg = NULL; - int fault_count = 0; - - switch_atomic_inc(&kazoo_globals.threads); - - switch_assert(ei_node != NULL); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting node request handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port); - - add_to_ei_nodes(ei_node); - - while (switch_test_flag(ei_node, LFLAG_RUNNING) && switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) { - int status; - int send_msg_count = 0; - void *pop = NULL; - - if (!received_msg) { - switch_malloc(received_msg, sizeof(*received_msg)); - /* create a new buf for the erlang message and a rbuf for the reply */ - if(kazoo_globals.receive_msg_preallocate > 0) { - switch_malloc(received_msg->buf.buff, kazoo_globals.receive_msg_preallocate); - received_msg->buf.buffsz = kazoo_globals.receive_msg_preallocate; - received_msg->buf.index = 0; - if(received_msg->buf.buff == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not pre-allocate memory for mod_kazoo message\n"); - goto exit; - } - } else { - ei_x_new(&received_msg->buf); - } - } else { - received_msg->buf.index = 0; - } - - while (++send_msg_count <= kazoo_globals.send_msg_batch - && ei_queue_pop(ei_node->send_msgs, &pop, ei_node->sender_queue_timeout) == SWITCH_STATUS_SUCCESS) { - ei_send_msg_t *send_msg = (ei_send_msg_t *) pop; - ei_helper_send(ei_node, &send_msg->pid, &send_msg->buf); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sent erlang message to %s <%d.%d.%d>\n" - ,send_msg->pid.node - ,send_msg->pid.creation - ,send_msg->pid.num - ,send_msg->pid.serial); - ei_x_free(&send_msg->buf); - switch_safe_free(send_msg); - } - - /* wait for a erlang message, or timeout to check if the module is still running */ - status = ei_xreceive_msg_tmo(ei_node->nodefd, &received_msg->msg, &received_msg->buf, kazoo_globals.ei_receive_timeout); - - switch (status) { - case ERL_TICK: - /* erlang nodes send ticks to eachother to validate they are still reachable, we dont have to do anything here */ - fault_count = 0; - break; - case ERL_MSG: - fault_count = 0; - - if (kazoo_globals.receive_msg_preallocate > 0 && received_msg->buf.buffsz > kazoo_globals.receive_msg_preallocate) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "increased received message buffer size to %d\n", received_msg->buf.buffsz); - } - - if (switch_queue_trypush(ei_node->received_msgs, received_msg) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to push erlang received message from %s <%d.%d.%d> into queue\n", received_msg->msg.from.node, received_msg->msg.from.creation, received_msg->msg.from.num, received_msg->msg.from.serial); - ei_x_free(&received_msg->buf); - switch_safe_free(received_msg); - } - - received_msg = NULL; - break; - case ERL_ERROR: - switch (erl_errno) { - case ETIMEDOUT: - case EAGAIN: - /* if ei_xreceive_msg_tmo just timed out, ignore it and let the while loop check if we are still running */ - /* the erlang lib just wants us to try to receive again, so we will! */ - fault_count = 0; - break; - case EMSGSIZE: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Erlang communication fault with node %p %s (%s:%d): my spoon is too big\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port); - switch_clear_flag(ei_node, LFLAG_RUNNING); - break; - case EIO: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Erlang communication fault with node %p %s (%s:%d): socket closed or I/O error [fault count %d]\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port, ++fault_count); - - if (fault_count >= kazoo_globals.io_fault_tolerance) { - switch_clear_flag(ei_node, LFLAG_RUNNING); - } else { - switch_sleep(kazoo_globals.io_fault_tolerance_sleep); - } - - break; - default: - /* OH NOS! something has gone horribly wrong, shutdown the connection if status set by ei_xreceive_msg_tmo is less than or equal to 0 */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Erlang communication fault with node %p %s (%s:%d): erl_errno=%d errno=%d\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port, erl_errno, errno); - if (status < 0) { - switch_clear_flag(ei_node, LFLAG_RUNNING); - } - break; - } - break; - default: - /* HUH? didnt plan for this, whatevs shutdown the connection if status set by ei_xreceive_msg_tmo is less than or equal to 0 */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected erlang receive status %p %s (%s:%d): %d\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port, status); - if (status < 0) { - switch_clear_flag(ei_node, LFLAG_RUNNING); - } - break; - } - } - - exit: - - if (received_msg) { - ei_x_free(&received_msg->buf); - switch_safe_free(received_msg); - } - - remove_from_ei_nodes(ei_node); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutdown erlang node handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port); - - destroy_node_handler(ei_node); - - switch_atomic_dec(&kazoo_globals.threads); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutdown Complete for erlang node handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port); - - return NULL; -} - -/* Create a thread to wait for messages from an erlang node and process them */ -switch_status_t new_kazoo_node(int nodefd, ErlConnect *conn) { - switch_thread_t *thread; - switch_threadattr_t *thd_attr = NULL; - switch_memory_pool_t *pool = NULL; - switch_sockaddr_t *sa; - ei_node_t *ei_node; - int i = 0; - - /* create memory pool for this erlang node */ - if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: Too bad drinking scotch isn't a paying job or Kenny's dad would be a millionare!\n"); - return SWITCH_STATUS_MEMERR; - } - - /* from the erlang node's memory pool, allocate some memory for the structure */ - if (!(ei_node = switch_core_alloc(pool, sizeof (*ei_node)))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: Stan, don't you know the first law of physics? Anything that's fun costs at least eight dollars.\n"); - return SWITCH_STATUS_MEMERR; - } - - memset(ei_node, 0, sizeof(*ei_node)); - - /* store the location of our pool */ - ei_node->pool = pool; - - /* save the file descriptor that the erlang interface lib uses to communicate with the new node */ - ei_node->nodefd = nodefd; - ei_node->peer_nodename = switch_core_strdup(ei_node->pool, conn->nodename); - ei_node->created_time = switch_micro_time_now(); - ei_node->legacy = kazoo_globals.legacy_events; - ei_node->event_stream_framing = kazoo_globals.event_stream_framing; - ei_node->event_stream_keepalive = kazoo_globals.event_stream_keepalive; - ei_node->event_stream_queue_timeout = kazoo_globals.event_stream_queue_timeout; - ei_node->receiver_queue_timeout = kazoo_globals.node_receiver_queue_timeout; - ei_node->sender_queue_timeout = kazoo_globals.node_sender_queue_timeout; - - /* store the IP and node name we are talking with */ - switch_os_sock_put(&ei_node->socket, (switch_os_socket_t *)&nodefd, pool); - - switch_socket_addr_get(&sa, SWITCH_TRUE, ei_node->socket); - ei_node->remote_port = switch_sockaddr_get_port(sa); - switch_get_addr(ei_node->remote_ip, sizeof (ei_node->remote_ip), sa); - - switch_socket_addr_get(&sa, SWITCH_FALSE, ei_node->socket); - ei_node->local_port = switch_sockaddr_get_port(sa); - switch_get_addr(ei_node->local_ip, sizeof (ei_node->local_ip), sa); - - switch_queue_create(&ei_node->send_msgs, MAX_QUEUE_LEN, pool); - switch_queue_create(&ei_node->received_msgs, MAX_QUEUE_LEN, pool); - - switch_mutex_init(&ei_node->event_streams_mutex, SWITCH_MUTEX_DEFAULT, pool); - - /* when we start we are running */ - switch_set_flag(ei_node, LFLAG_RUNNING); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "New erlang connection from node %s (%s:%d) -> (%s:%d)\n", ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port, ei_node->local_ip, ei_node->local_port); - - for(i = 0; i < kazoo_globals.node_worker_threads; i++) { - switch_threadattr_create(&thd_attr, ei_node->pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&thread, thd_attr, receive_handler, ei_node, ei_node->pool); - } - - switch_threadattr_create(&thd_attr, ei_node->pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&thread, thd_attr, handle_node, ei_node, ei_node->pool); - - return SWITCH_STATUS_SUCCESS; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_tweaks.c b/src/mod/event_handlers/mod_kazoo/kazoo_tweaks.c deleted file mode 100644 index e647871855..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_tweaks.c +++ /dev/null @@ -1,666 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Luis Azedo - * - * mod_hacks.c -- hacks with state handlers - * - */ -#include "mod_kazoo.h" - -static char *TWEAK_NAMES[] = { - "interaction-id", - "export-vars", - "switch-uri", - "replaces-call-id", - "loopback-vars", - "caller-id", - "transfers", - "bridge", - "bridge-replaces-aleg", - "bridge-replaces-call-id", - "bridge-variables", - "restore-caller-id-on-blind-xfer" -}; - -static const char *bridge_variables[] = { - "Call-Control-Queue", - "Call-Control-PID", - "Call-Control-Node", - INTERACTION_VARIABLE, - "ecallmgr_Ecallmgr-Node", - "sip_h_k-cid", - "Switch-URI", - "Switch-URL", - NULL -}; - -static switch_status_t kz_tweaks_signal_bridge_on_hangup(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_event_t *my_event; - - const char *peer_uuid = switch_channel_get_variable(channel, "Bridge-B-Unique-ID"); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "tweak signal bridge on hangup: %s , %s\n", switch_core_session_get_uuid(session), peer_uuid); - - if (switch_event_create(&my_event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session)); - switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid); - switch_channel_event_set_data(channel, my_event); - switch_event_fire(&my_event); - } - - return SWITCH_STATUS_SUCCESS; -} - -static const switch_state_handler_table_t kz_tweaks_signal_bridge_state_handlers = { - /*.on_init */ NULL, - /*.on_routing */ NULL, - /*.on_execute */ NULL, - /*.on_hangup */ kz_tweaks_signal_bridge_on_hangup, - /*.on_exchange_media */ NULL, - /*.on_soft_execute */ NULL, - /*.on_consume_media */ NULL, - /*.on_hibernate */ NULL, - /*.on_reset */ NULL, - /*.on_park */ NULL, - /*.on_reporting */ NULL, - /*.on_destroy */ NULL -}; - -static void kz_tweaks_handle_bridge_variables(switch_event_t *event) -{ - switch_core_session_t *a_session = NULL, *b_session = NULL; - const char *a_leg = switch_event_get_header(event, "Bridge-A-Unique-ID"); - const char *b_leg = switch_event_get_header(event, "Bridge-B-Unique-ID"); - const char *reentry = switch_event_get_header(event, "Bridge-Event-Processed"); - int i; - - if (!kz_test_tweak(KZ_TWEAK_BRIDGE_VARIABLES)) return; - - if(reentry) return; - - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(a_leg), SWITCH_LOG_DEBUG, "tweak bridge event handler: variables : %s , %s\n", a_leg, b_leg); - - if (a_leg && (a_session = switch_core_session_locate(a_leg)) != NULL) { - switch_channel_t *a_channel = switch_core_session_get_channel(a_session); - switch_channel_timetable_t *a_times = switch_channel_get_timetable(a_channel); - if(b_leg && (b_session = switch_core_session_locate(b_leg)) != NULL) { - switch_channel_t *b_channel = switch_core_session_get_channel(b_session); - switch_channel_timetable_t *b_times = switch_channel_get_timetable(b_channel); - if (a_times->created <= b_times->created) { - for(i = 0; bridge_variables[i] != NULL; i++) { - const char *val = switch_channel_get_variable_dup(a_channel, bridge_variables[i], SWITCH_FALSE, -1); - switch_channel_set_variable(b_channel, bridge_variables[i], val); - } - } else { - for(i = 0; bridge_variables[i] != NULL; i++) { - const char *val = switch_channel_get_variable_dup(b_channel, bridge_variables[i], SWITCH_FALSE, -1); - switch_channel_set_variable(a_channel, bridge_variables[i], val); - } - } - switch_core_session_rwunlock(b_session); - } - switch_core_session_rwunlock(a_session); - } else { - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(a_leg), SWITCH_LOG_DEBUG1, "NOT FOUND : %s\n", a_leg); - } -} - -static void kz_tweaks_handle_bridge_replaces_call_id(switch_event_t *event) -{ - switch_event_t *my_event; - - const char *replaced_call_id = switch_event_get_header(event, "variable_sip_replaces_call_id"); - const char *peer_uuid = switch_event_get_header(event, "Unique-ID"); - const char *reentry = switch_event_get_header(event, "Bridge-Event-Processed"); - - if (!kz_test_tweak(KZ_TWEAK_BRIDGE_REPLACES_CALL_ID)) return; - - if(reentry) return; - - if(replaced_call_id) { - switch_core_session_t *call_session = NULL; - const char *call_id = switch_event_get_header(event, "Bridge-B-Unique-ID"); - if (call_id && (call_session = switch_core_session_locate(call_id)) != NULL) { - switch_channel_t *call_channel = switch_core_session_get_channel(call_session); - if (switch_event_create(&my_event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(call_session)); - switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid); - switch_event_add_header_string(my_event, SWITCH_STACK_BOTTOM, "Bridge-Event-Processed", "true"); - switch_channel_event_set_data(call_channel, my_event); - switch_event_fire(&my_event); - } - switch_channel_set_variable(call_channel, "Bridge-B-Unique-ID", peer_uuid); - switch_channel_add_state_handler(call_channel, &kz_tweaks_signal_bridge_state_handlers); - switch_core_session_rwunlock(call_session); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "NOT FOUND : %s\n", call_id); - } - } -} - -static void kz_tweaks_channel_bridge_event_handler(switch_event_t *event) -{ - if (!kz_test_tweak(KZ_TWEAK_BRIDGE)) return; - - kz_tweaks_handle_bridge_replaces_call_id(event); - kz_tweaks_handle_bridge_variables(event); -} - -// TRANSFERS - -static void kz_tweaks_channel_replaced_event_handler(switch_event_t *event) -{ - const char *uuid = switch_event_get_header(event, "Unique-ID"); - const char *replaced_by = switch_event_get_header(event, "att_xfer_replaced_by"); - - if (!kz_test_tweak(KZ_TWEAK_TRANSFERS)) return; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "REPLACED : %s , %s\n", uuid, replaced_by); -} - -static void kz_tweaks_channel_intercepted_event_handler(switch_event_t *event) -{ - const char *uuid = switch_event_get_header(event, "Unique-ID"); - const char *peer_uuid = switch_event_get_header(event, "intercepted_by"); - - if (!kz_test_tweak(KZ_TWEAK_TRANSFERS)) return; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INTERCEPTED : %s => %s\n", uuid, peer_uuid); -} - -static void kz_tweaks_channel_transferor_event_handler(switch_event_t *event) -{ - switch_core_session_t *uuid_session = NULL; - switch_event_t *evt = NULL; - const char *uuid = switch_event_get_header(event, "Unique-ID"); - - const char *orig_call_id = switch_event_get_header(event, "att_xfer_original_call_id"); - const char *dest_peer_uuid = switch_event_get_header(event, "att_xfer_destination_peer_uuid"); - const char *dest_call_id = switch_event_get_header(event, "att_xfer_destination_call_id"); - - const char *file = switch_event_get_header(event, "Event-Calling-File"); - const char *func = switch_event_get_header(event, "Event-Calling-Function"); - const char *line = switch_event_get_header(event, "Event-Calling-Line-Number"); - - if (!kz_test_tweak(KZ_TWEAK_TRANSFERS)) return; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEROR : %s , %s , %s, %s, %s , %s , %s \n", uuid, orig_call_id, dest_peer_uuid, dest_call_id, file, func, line); - if ((uuid_session = switch_core_session_locate(uuid)) != NULL) { - switch_channel_t *uuid_channel = switch_core_session_get_channel(uuid_session); - const char* interaction_id = switch_channel_get_variable_dup(uuid_channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1); - // set to uuid & peer_uuid - if(interaction_id != NULL) { - switch_core_session_t *session = NULL; - if(dest_call_id && (session = switch_core_session_locate(dest_call_id)) != NULL) { - switch_channel_t *channel = switch_core_session_get_channel(session); - const char* prv_interaction_id = switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "LOCATING UUID PRV : %s : %s\n", prv_interaction_id, interaction_id); - switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id); - if (switch_event_create(&evt, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, evt); - switch_event_fire(&evt); - } - switch_core_session_rwunlock(session); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEROR NO UUID SESSION: %s , %s , %s \n", uuid, dest_call_id, dest_peer_uuid); - } - if(dest_peer_uuid && (session = switch_core_session_locate(dest_peer_uuid)) != NULL) { - switch_channel_t *channel = switch_core_session_get_channel(session); - const char* prv_interaction_id = switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "LOCATING PEER UUID PRV : %s : %s\n", prv_interaction_id, interaction_id); - switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id); - if (switch_event_create(&evt, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, evt); - switch_event_fire(&evt); - } - switch_core_session_rwunlock(session); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEROR NO PEER SESSION: %s , %s , %s \n", uuid, dest_call_id, dest_peer_uuid); - } - if(orig_call_id && (session = switch_core_session_locate(orig_call_id)) != NULL) { - switch_channel_t *channel = switch_core_session_get_channel(session); - const char* prv_interaction_id = switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "LOCATING PEER UUID PRV : %s : %s\n", prv_interaction_id, interaction_id); - switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id); - if (switch_event_create(&evt, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, evt); - switch_event_fire(&evt); - } - switch_core_session_rwunlock(session); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEROR NO PEER SESSION: %s , %s , %s \n", uuid, dest_call_id, dest_peer_uuid); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEROR ID = NULL : %s , %s , %s \n", uuid, dest_call_id, dest_peer_uuid); - } - switch_core_session_rwunlock(uuid_session); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SESSION NOT FOUND : %s\n", uuid); - } -} - -static void kz_tweaks_channel_transferee_event_handler(switch_event_t *event) -{ - const char *uuid = switch_event_get_header(event, "Unique-ID"); - const char *replaced_by_uuid = switch_event_get_header(event, "att_xfer_replaced_call_id"); - - if (!kz_test_tweak(KZ_TWEAK_TRANSFERS)) return; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEREE : %s replaced by %s\n", uuid, replaced_by_uuid); -} - -// END TRANSFERS - - -static switch_status_t kz_tweaks_handle_loopback(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_t *a_channel = NULL; - const char * loopback_leg = NULL; - const char * loopback_aleg = NULL; - switch_core_session_t *a_session = NULL; - switch_event_t *event = NULL; - switch_event_header_t *header = NULL; - switch_event_t *to_add = NULL; - switch_event_t *to_remove = NULL; - switch_caller_profile_t *caller; - int n = 0; - - if (!kz_test_tweak(KZ_TWEAK_LOOPBACK_VARS)) { - return SWITCH_STATUS_SUCCESS; - } - - caller = switch_channel_get_caller_profile(channel); - if(strncmp(caller->source, "mod_loopback", 12)) - return SWITCH_STATUS_SUCCESS; - - if((loopback_leg = switch_channel_get_variable(channel, "loopback_leg")) == NULL) - return SWITCH_STATUS_SUCCESS; - - if(strncmp(loopback_leg, "B", 1)) - return SWITCH_STATUS_SUCCESS; - - switch_channel_get_variables(channel, &event); - switch_event_create_plain(&to_add, SWITCH_EVENT_CHANNEL_DATA); - switch_event_create_plain(&to_remove, SWITCH_EVENT_CHANNEL_DATA); - - for(header = event->headers; header; header = header->next) { - if(!strncmp(header->name, "Export-Loopback-", 16)) { - kz_switch_event_add_variable_name_printf(to_add, SWITCH_STACK_BOTTOM, header->value, "%s", header->name+16); - switch_channel_set_variable(channel, header->name, NULL); - n++; - } else if(!strncmp(header->name, "sip_loopback_", 13)) { - kz_switch_event_add_variable_name_printf(to_add, SWITCH_STACK_BOTTOM, header->value, "sip_%s", header->name+13); - } else if(!strncmp(header->name, "ecallmgr_", 9)) { - switch_event_add_header_string(to_remove, SWITCH_STACK_BOTTOM, header->name, header->value); - } - } - if(n) { - for(header = to_remove->headers; header; header = header->next) { - switch_channel_set_variable(channel, header->name, NULL); - } - } - - for(header = to_add->headers; header; header = header->next) { - switch_channel_set_variable(channel, header->name, header->value); - } - - // cleanup leg A - loopback_aleg = switch_channel_get_variable(channel, "other_loopback_leg_uuid"); - if(loopback_aleg != NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found loopback a-leg uuid - %s\n", loopback_aleg); - if ((a_session = switch_core_session_locate(loopback_aleg))) { - a_channel = switch_core_session_get_channel(a_session); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found loopback session a - %s\n", loopback_aleg); - switch_channel_del_variable_prefix(a_channel, "Export-Loopback-"); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Couldn't locate loopback session a - %s\n", loopback_aleg); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Couldn't find loopback a-leg uuid!\n"); - } - - /* - * set Interaction-ID - * if we're not crossing account boundaries - */ - if (kz_test_tweak(KZ_TWEAK_INTERACTION_ID)) { - if (a_channel) { - const char *interaction_id = switch_channel_get_variable_dup(a_channel, INTERACTION_VARIABLE, SWITCH_FALSE, -1); - const char *a_account_id = switch_channel_get_variable_dup(a_channel, "ecallmgr_Account-ID", SWITCH_FALSE, -1); - const char *b_account_id = switch_channel_get_variable_dup(channel, "ecallmgr_Account-ID", SWITCH_FALSE, -1); - if ((!a_account_id) || (!b_account_id) || (!strcmp(a_account_id, b_account_id))) { - switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id); - } - } - } - - if (a_session){ - switch_core_session_rwunlock(a_session); - } - switch_event_destroy(&event); - switch_event_destroy(&to_add); - switch_event_destroy(&to_remove); - - return SWITCH_STATUS_SUCCESS; - -} - -static void kz_tweaks_handle_caller_id(switch_core_session_t *session) -{ - if (kz_test_tweak(KZ_TWEAK_CALLER_ID)) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_caller_profile_t* caller = switch_channel_get_caller_profile(channel); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "CHECKING CALLER-ID\n"); - if (caller && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { - const char* val = NULL; - if((val=switch_caller_get_field_by_name(caller, "Endpoint-Caller-ID-Name"))) { - caller->caller_id_name = val; - caller->orig_caller_id_name = val; - } - if((val=switch_caller_get_field_by_name(caller, "Endpoint-Caller-ID-Number"))) { - caller->caller_id_number = val; - caller->orig_caller_id_number = val; - } - } - } -} - -static switch_status_t kz_tweaks_handle_nightmare_xfer_interaction_id(switch_core_session_t *session) -{ - if (kz_test_tweak(KZ_TWEAK_INTERACTION_ID)) { - switch_core_session_t *replace_session = NULL; - switch_channel_t *channel = switch_core_session_get_channel(session); - const char *replaced_call_id = switch_channel_get_variable(channel, "sip_replaces_call_id"); - const char *core_uuid = switch_channel_get_variable(channel, "sip_h_X-FS-From-Core-UUID"); - const char *partner_uuid = switch_channel_get_variable(channel, "sip_h_X-FS-Refer-Partner-UUID"); - const char *interaction_id = switch_channel_get_variable(channel, "sip_h_X-FS-Call-Interaction-ID"); - if(core_uuid && partner_uuid && replaced_call_id && interaction_id) { - switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "checking nightmare xfer tweak for %s\n", switch_channel_get_uuid(channel)); - if ((replace_session = switch_core_session_locate(replaced_call_id))) { - switch_channel_t *replaced_call_channel = switch_core_session_get_channel(replace_session); - switch_channel_set_variable(replaced_call_channel, INTERACTION_VARIABLE, interaction_id); - switch_core_session_rwunlock(replace_session); - } - if ((replace_session = switch_core_session_locate(partner_uuid))) { - switch_channel_t *replaced_call_channel = switch_core_session_get_channel(replace_session); - switch_channel_set_variable(replaced_call_channel, INTERACTION_VARIABLE, interaction_id); - switch_core_session_rwunlock(replace_session); - } - } - } - - return SWITCH_STATUS_SUCCESS; - -} - -static switch_status_t kz_tweaks_handle_replaces_call_id(switch_core_session_t *session) -{ - if (kz_test_tweak(KZ_TWEAK_REPLACES_CALL_ID)) { - switch_core_session_t *replace_call_session = NULL; - switch_event_t *event; - switch_channel_t *channel = switch_core_session_get_channel(session); - const char *replaced_call_id = switch_channel_get_variable(channel, "sip_replaces_call_id"); - const char *core_uuid = switch_channel_get_variable(channel, "sip_h_X-FS-From-Core-UUID"); - if((!core_uuid) && replaced_call_id) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "checking replaces header tweak for %s\n", replaced_call_id); - if ((replace_call_session = switch_core_session_locate(replaced_call_id))) { - switch_channel_t *replaced_call_channel = switch_core_session_get_channel(replace_call_session); - int i; - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "setting bridge variables from %s to %s\n", replaced_call_id, switch_channel_get_uuid(channel)); - for(i = 0; bridge_variables[i] != NULL; i++) { - const char *val = switch_channel_get_variable_dup(replaced_call_channel, bridge_variables[i], SWITCH_TRUE, -1); - switch_channel_set_variable(channel, bridge_variables[i], val); - } - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - switch_core_session_rwunlock(replace_call_session); - } - } - } - - return SWITCH_STATUS_SUCCESS; - -} - - -static switch_status_t kz_tweaks_handle_switch_uri(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - if (kz_test_tweak(KZ_TWEAK_SWITCH_URI)) { - const char *profile_url = switch_channel_get_variable(channel, "sofia_profile_url"); - if(profile_url) { - int n = strcspn(profile_url, "@"); - switch_channel_set_variable(channel, "Switch-URL", profile_url); - switch_channel_set_variable_printf(channel, "Switch-URI", "sip:%s", n > 0 ? profile_url + n + 1 : profile_url); - } - } - - return SWITCH_STATUS_SUCCESS; - -} - -static char * kz_tweaks_new_interaction_id() -{ - long int first = (switch_micro_time_now() / 1000000) + UNIX_EPOCH_IN_GREGORIAN; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - switch_uuid_t uuid; - switch_uuid_get(&uuid); - switch_uuid_format(uuid_str, &uuid); - uuid_str[8] = '\0'; - return switch_mprintf("%ld-%s", first, uuid_str); -} - -static void kz_tweaks_handle_interaction_id(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - char * val = NULL; - switch_core_session_t *peer_session = NULL; - const char* peer_interaction_id = NULL; - - if (kz_test_tweak(KZ_TWEAK_INTERACTION_ID)) { - val = kz_tweaks_new_interaction_id(); - if (val) { - switch_channel_set_variable(channel, "Original-"INTERACTION_VARIABLE, val); - if(switch_core_session_get_partner(session, &peer_session) == SWITCH_STATUS_SUCCESS) { - switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); - peer_interaction_id = switch_channel_get_variable_dup(peer_channel, INTERACTION_VARIABLE, SWITCH_FALSE, -1); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "PEER_SESSION => %s\n", peer_interaction_id); - if(peer_interaction_id) { - switch_channel_set_variable(channel, INTERACTION_VARIABLE, peer_interaction_id); - } - switch_core_session_rwunlock(peer_session); - } else if (!switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_FALSE, -1)) { - switch_channel_set_variable(channel, INTERACTION_VARIABLE, val); - } - } - - switch_safe_free(val); - } - -} - -static switch_status_t kz_outgoing_channel(switch_core_session_t * session, switch_event_t * event, switch_caller_profile_t * cp, switch_core_session_t * peer_session, switch_originate_flag_t flag) -{ - if (kz_test_tweak(KZ_TWEAK_INTERACTION_ID)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "GOT OUTGOING\n"); - if (peer_session) { - switch_channel_t *channel = switch_core_session_get_channel(session); - const char* interaction_id = switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_FALSE, -1); - switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SESSION && PEER_SESSION => %s\n", interaction_id ); - if (interaction_id) { - switch_channel_set_variable(peer_channel, INTERACTION_VARIABLE, interaction_id); - } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "NO SESSION && PEER_SESSION\n"); - } - } - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t kz_tweaks_register_handle_blind_xfer(switch_core_session_t *session) -{ - if (kz_test_tweak(KZ_TWEAK_RESTORE_CALLER_ID_ON_BLIND_XFER)) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_set_variable(channel, "execute_on_blind_transfer", "kz_restore_caller_id"); - } - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t kz_tweaks_on_init(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "checking tweaks for %s\n", switch_channel_get_uuid(channel)); - switch_channel_set_flag(channel, CF_VERBOSE_EVENTS); - switch_core_event_hook_add_outgoing_channel(session, kz_outgoing_channel); - kz_tweaks_handle_interaction_id(session); - kz_tweaks_handle_switch_uri(session); - kz_tweaks_handle_caller_id(session); - kz_tweaks_handle_nightmare_xfer_interaction_id(session); - kz_tweaks_handle_replaces_call_id(session); - kz_tweaks_handle_loopback(session); - kz_tweaks_register_handle_blind_xfer(session); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_state_handler_table_t kz_tweaks_state_handlers = { - /*.on_init */ kz_tweaks_on_init, - /*.on_routing */ NULL, - /*.on_execute */ NULL, - /*.on_hangup */ NULL, - /*.on_exchange_media */ NULL, - /*.on_soft_execute */ NULL, - /*.on_consume_media */ NULL, - /*.on_hibernate */ NULL, - /*.on_reset */ NULL, - /*.on_park */ NULL, - /*.on_reporting */ NULL, - /*.on_destroy */ NULL -}; - - -static void kz_tweaks_register_state_handlers() -{ -/* - * we may need two handlers - * one with SSH_FLAG_PRE_EXEC - * and another without it - * mod_loopback tweaks needs post-init (SSH_FLAG_PRE_EXEC off) - * - * kz_tweaks_state_handlers.flags = SSH_FLAG_PRE_EXEC; - * - */ - switch_core_add_state_handler(&kz_tweaks_state_handlers); -} - -static void kz_tweaks_unregister_state_handlers() -{ - switch_core_remove_state_handler(&kz_tweaks_state_handlers); -} - -static void kz_tweaks_bind_events() -{ - if (switch_event_bind("kz_tweaks", SWITCH_EVENT_CHANNEL_BRIDGE, SWITCH_EVENT_SUBCLASS_ANY, kz_tweaks_channel_bridge_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind to channel_bridge event!\n"); - } - if (switch_event_bind("kz_tweaks", SWITCH_EVENT_CUSTOM, "sofia::replaced", kz_tweaks_channel_replaced_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind to channel_bridge event!\n"); - } - if (switch_event_bind("kz_tweaks", SWITCH_EVENT_CUSTOM, "sofia::intercepted", kz_tweaks_channel_intercepted_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind to channel_bridge event!\n"); - } - if (switch_event_bind("kz_tweaks", SWITCH_EVENT_CUSTOM, "sofia::transferor", kz_tweaks_channel_transferor_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind to channel_bridge event!\n"); - } - if (switch_event_bind("kz_tweaks", SWITCH_EVENT_CUSTOM, "sofia::transferee", kz_tweaks_channel_transferee_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind to channel_bridge event!\n"); - } -} - -static void kz_tweaks_unbind_events() -{ - switch_event_unbind_callback(kz_tweaks_channel_bridge_event_handler); - switch_event_unbind_callback(kz_tweaks_channel_replaced_event_handler); - switch_event_unbind_callback(kz_tweaks_channel_intercepted_event_handler); - switch_event_unbind_callback(kz_tweaks_channel_transferor_event_handler); - switch_event_unbind_callback(kz_tweaks_channel_transferee_event_handler); -} - -void kz_tweaks_add_core_variables() -{ - switch_core_set_variable("UNIX_EPOCH_IN_GREGORIAN", UNIX_EPOCH_IN_GREGORIAN_STR); -} - -void kz_tweaks_start() -{ - kz_tweaks_add_core_variables(); - kz_tweaks_register_state_handlers(); - kz_tweaks_bind_events(); -} - -void kz_tweaks_stop() -{ - kz_tweaks_unbind_events(); - kz_tweaks_unregister_state_handlers(); -} - -SWITCH_DECLARE(const char *) kz_tweak_name(kz_tweak_t tweak) -{ - return TWEAK_NAMES[tweak]; -} - -SWITCH_DECLARE(switch_status_t) kz_name_tweak(const char *name, kz_tweak_t *type) -{ - kz_tweak_t x; - for (x = 0; x < KZ_TWEAK_MAX; x++) { - if (!strcasecmp(name, TWEAK_NAMES[x])) { - *type = x; - return SWITCH_STATUS_SUCCESS; - } - } - - return SWITCH_STATUS_FALSE; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ - - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_tweaks.h b/src/mod/event_handlers/mod_kazoo/kazoo_tweaks.h deleted file mode 100644 index 11cf5f6561..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_tweaks.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -typedef enum { - KZ_TWEAK_INTERACTION_ID, - KZ_TWEAK_EXPORT_VARS, - KZ_TWEAK_SWITCH_URI, - KZ_TWEAK_REPLACES_CALL_ID, - KZ_TWEAK_LOOPBACK_VARS, - KZ_TWEAK_CALLER_ID, - KZ_TWEAK_TRANSFERS, - KZ_TWEAK_BRIDGE, - KZ_TWEAK_BRIDGE_REPLACES_ALEG, - KZ_TWEAK_BRIDGE_REPLACES_CALL_ID, - KZ_TWEAK_BRIDGE_VARIABLES, - KZ_TWEAK_RESTORE_CALLER_ID_ON_BLIND_XFER, - - /* No new flags below this line */ - KZ_TWEAK_MAX -} kz_tweak_t; - -void kz_tweaks_start(); -void kz_tweaks_stop(); -SWITCH_DECLARE(const char *) kz_tweak_name(kz_tweak_t tweak); -SWITCH_DECLARE(switch_status_t) kz_name_tweak(const char *name, kz_tweak_t *type); - - -#define kz_test_tweak(flag) (kazoo_globals.tweaks[flag] ? 1 : 0) -#define kz_set_tweak(flag) kazoo_globals.tweaks[flag] = 1 -#define kz_clear_tweak(flag) kazoo_globals.tweaks[flag] = 0 - diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_utils.c b/src/mod/event_handlers/mod_kazoo/kazoo_utils.c deleted file mode 100644 index 951707d179..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_utils.c +++ /dev/null @@ -1,700 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * Andrew Thompson - * Rob Charlton - * Karl Anderson - * - * Original from mod_erlang_event. - * ei_helpers.c -- helper functions for ei - * - */ -#include "mod_kazoo.h" - -#define kz_resize(l) {\ -char *dp;\ -olen += (len + l + block);\ -cpos = c - data;\ -if ((dp = realloc(data, olen))) {\ - data = dp;\ - c = data + cpos;\ - memset(c, 0, olen - cpos);\ - }} \ - - -void kz_check_set_profile_var(switch_channel_t *channel, char* var, char *val) -{ - int idx = 0; - while(kazoo_globals.profile_vars_prefixes[idx] != NULL) { - char *prefix = kazoo_globals.profile_vars_prefixes[idx]; - if (!strncasecmp(var, prefix, strlen(prefix))) { - switch_channel_set_profile_var(channel, var + strlen(prefix), val); - - } - idx++; - } -} - -SWITCH_DECLARE(switch_status_t) kz_switch_core_merge_variables(switch_event_t *event) -{ - switch_event_t *global_vars; - switch_status_t status = switch_core_get_variables(&global_vars); - if(status == SWITCH_STATUS_SUCCESS) { - switch_event_merge(event, global_vars); - switch_event_destroy(&global_vars); - } - return status; -} - -SWITCH_DECLARE(switch_status_t) kz_switch_core_base_headers_for_expand(switch_event_t **event) -{ - switch_status_t status = SWITCH_STATUS_GENERR; - *event = NULL; - if(switch_event_create(event, SWITCH_EVENT_GENERAL) == SWITCH_STATUS_SUCCESS) { - status = kz_switch_core_merge_variables(*event); - } - return status; -} - -SWITCH_DECLARE(switch_status_t) kz_expand_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream) -{ - switch_api_interface_t *api; - switch_status_t status; - char *arg_used; - char *cmd_used; - - switch_assert(stream != NULL); - switch_assert(stream->data != NULL); - switch_assert(stream->write_function != NULL); - - cmd_used = switch_strip_whitespace(cmd); - arg_used = switch_strip_whitespace(arg); - - if (cmd_used && (api = switch_loadable_module_get_api_interface(cmd_used)) != 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "executing [%s] => [%s]\n", cmd_used, arg_used); - if ((status = api->function(arg_used, session, stream)) != SWITCH_STATUS_SUCCESS) { - stream->write_function(stream, "COMMAND RETURNED ERROR!\n"); - } - UNPROTECT_INTERFACE(api); - } else { - status = SWITCH_STATUS_FALSE; - stream->write_function(stream, "INVALID COMMAND!\n"); - } - - if (cmd_used != cmd) { - switch_safe_free(cmd_used); - } - - if (arg_used != arg) { - switch_safe_free(arg_used); - } - - return status; -} - - -SWITCH_DECLARE(char *) kz_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur) -{ - char *p, *c = NULL; - char *data, *indup, *endof_indup; - size_t sp = 0, len = 0, olen = 0, vtype = 0, br = 0, cpos, block = 128; - const char *sub_val = NULL; - char *cloned_sub_val = NULL, *expanded_sub_val = NULL; - char *func_val = NULL; - int nv = 0; - char *gvar = NULL, *sb = NULL; - - if (recur > 100) { - return (char *) in; - } - - if (zstr(in)) { - return (char *) in; - } - - nv = switch_string_var_check_const(in) || switch_string_has_escaped_data(in); - - if (!nv) { - return (char *) in; - } - - nv = 0; - olen = strlen(in) + 1; - indup = strdup(in); - switch_assert(indup); - endof_indup = end_of_p(indup) + 1; - - if ((data = malloc(olen))) { - memset(data, 0, olen); - c = data; - for (p = indup; p && p < endof_indup && *p; p++) { - int global = 0; - vtype = 0; - - if (*p == '\\') { - if (*(p + 1) == '$') { - nv = 1; - p++; - if (*(p + 1) == '$') { - p++; - } - } else if (*(p + 1) == '\'') { - p++; - continue; - } else if (*(p + 1) == '\\') { - if (len + 1 >= olen) { - kz_resize(1); - } - - *c++ = *p++; - len++; - continue; - } - } - - if (*p == '$' && !nv) { - if (*(p + 1) == '$') { - p++; - global++; - } - - if (*(p + 1)) { - if (*(p + 1) == '{') { - vtype = global ? 3 : 1; - } else { - nv = 1; - } - } else { - nv = 1; - } - } - - if (nv) { - if (len + 1 >= olen) { - kz_resize(1); - } - - *c++ = *p; - len++; - nv = 0; - continue; - } - - if (vtype) { - char *s = p, *e, *vname, *vval = NULL; - size_t nlen; - - s++; - - if ((vtype == 1 || vtype == 3) && *s == '{') { - br = 1; - s++; - } - - e = s; - vname = s; - while (*e) { - if (br == 1 && *e == '}') { - br = 0; - *e++ = '\0'; - break; - } - - if (br > 0) { - if (e != s && *e == '{') { - br++; - } else if (br > 1 && *e == '}') { - br--; - } - } - - e++; - } - p = e > endof_indup ? endof_indup : e; - - vval = NULL; - for(sb = vname; sb && *sb; sb++) { - if (*sb == ' ') { - vval = sb; - break; - } else if (*sb == '(') { - vval = sb; - br = 1; - break; - } - } - - if (vval) { - e = vval - 1; - *vval++ = '\0'; - - while (*e == ' ') { - *e-- = '\0'; - } - e = vval; - - while (e && *e) { - if (*e == '(') { - br++; - } else if (br > 1 && *e == ')') { - br--; - } else if (br == 1 && *e == ')') { - *e = '\0'; - break; - } - e++; - } - - vtype = 2; - } - - if (vtype == 1 || vtype == 3) { - char *expanded = NULL; - int offset = 0; - int ooffset = 0; - char *ptr; - int idx = -1; - - if ((expanded = kz_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) { - expanded = NULL; - } else { - vname = expanded; - } - if ((ptr = strchr(vname, ':'))) { - *ptr++ = '\0'; - offset = atoi(ptr); - if ((ptr = strchr(ptr, ':'))) { - ptr++; - ooffset = atoi(ptr); - } - } - - if ((ptr = strchr(vname, '[')) && strchr(ptr, ']')) { - *ptr++ = '\0'; - idx = atoi(ptr); - } - - if (vtype == 3 || !(sub_val = switch_event_get_header_idx(event, vname, idx))) { - switch_safe_free(gvar); - if ((gvar = switch_core_get_variable_dup(vname))) { - sub_val = gvar; - } - - if (var_list && !switch_event_check_permission_list(var_list, vname)) { - sub_val = ""; - } - - - if ((expanded_sub_val = kz_event_expand_headers_check(event, sub_val, var_list, api_list, recur+1)) == sub_val) { - expanded_sub_val = NULL; - } else { - sub_val = expanded_sub_val; - } - } - - if (sub_val) { - if (offset || ooffset) { - cloned_sub_val = strdup(sub_val); - switch_assert(cloned_sub_val); - sub_val = cloned_sub_val; - } - - if (offset >= 0) { - sub_val += offset; - } else if ((size_t) abs(offset) <= strlen(sub_val)) { - sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset); - } - - if (ooffset > 0 && (size_t) ooffset < strlen(sub_val)) { - if ((ptr = (char *) sub_val + ooffset)) { - *ptr = '\0'; - } - } - } - - switch_safe_free(expanded); - } else { - char *expanded = NULL; - char *expanded_vname = NULL; - - if ((expanded_vname = kz_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) { - expanded_vname = NULL; - } else { - vname = expanded_vname; - } - - if ((expanded = kz_event_expand_headers_check(event, vval, var_list, api_list, recur+1)) == vval) { - expanded = NULL; - } else { - vval = expanded; - } - - if (!switch_core_test_flag(SCF_API_EXPANSION) || (api_list && !switch_event_check_permission_list(api_list, vname))) { - func_val = NULL; - sub_val = ""; - } else { - switch_stream_handle_t stream = { 0 }; - - SWITCH_STANDARD_STREAM(stream); - stream.param_event = event; - if (kz_expand_api_execute(vname, vval, NULL, &stream) == SWITCH_STATUS_SUCCESS) { - func_val = stream.data; - sub_val = func_val; - } else { - free(stream.data); - } - } - - switch_safe_free(expanded); - switch_safe_free(expanded_vname); - } - if ((nlen = sub_val ? strlen(sub_val) : 0)) { - if (len + nlen >= olen) { - kz_resize(nlen); - } - - len += nlen; - strcat(c, sub_val); - c += nlen; - } - - switch_safe_free(func_val); - switch_safe_free(cloned_sub_val); - switch_safe_free(expanded_sub_val); - sub_val = NULL; - vname = NULL; - br = 0; - } - - if (sp) { - if (len + 1 >= olen) { - kz_resize(1); - } - - *c++ = ' '; - sp = 0; - len++; - } - - if (*p == '$') { - p--; - } else { - if (len + 1 >= olen) { - kz_resize(1); - } - - *c++ = *p; - len++; - } - } - } - free(indup); - switch_safe_free(gvar); - - return data; -} - -SWITCH_DECLARE(char *) kz_event_expand_headers(switch_event_t *event, const char *in) -{ - return kz_event_expand_headers_check(event, in, NULL, NULL, 0); -} - -SWITCH_DECLARE(char *) kz_event_expand_headers_pool(switch_memory_pool_t *pool, switch_event_t *event, char *val) -{ - char *expanded; - char *dup = NULL; - - expanded = kz_event_expand_headers(event, val); - dup = switch_core_strdup(pool, expanded); - - if (expanded != val) { - free(expanded); - } - - return dup; -} - -SWITCH_DECLARE(char *) kz_expand(const char *in, const char *uuid) -{ - switch_event_t *event = NULL; - char *ret = NULL; - kz_switch_core_base_headers_for_expand(&event); - if (uuid != NULL) { - switch_core_session_t *nsession = NULL; - if ((nsession = switch_core_session_locate(uuid))) { - switch_channel_event_set_data(switch_core_session_get_channel(nsession), event); - switch_core_session_rwunlock(nsession); - } - } - ret = kz_event_expand_headers_check(event, in, NULL, NULL, 0); - switch_event_destroy(&event); - return ret; -} - -SWITCH_DECLARE(char *) kz_expand_pool(switch_memory_pool_t *pool, const char *in) -{ - char *expanded; - char *dup = NULL; - - if(!(expanded = kz_expand(in, NULL))) { - return NULL; - } - dup = switch_core_strdup(pool, expanded); - - if (expanded != in) { - switch_safe_free(expanded); - } - - return dup; -} - -char* kz_switch_event_get_first_of(switch_event_t *event, const char *list[]) -{ - switch_event_header_t *header = NULL; - int i = 0; - while(list[i] != NULL) { - if((header = switch_event_get_header_ptr(event, list[i])) != NULL) - break; - i++; - } - if(header != NULL) { - return header->value; - } else { - return "nodomain"; - } -} - -SWITCH_DECLARE(switch_status_t) kz_switch_event_add_variable_name_printf(switch_event_t *event, switch_stack_t stack, const char *val, const char *fmt, ...) -{ - int ret = 0; - char *varname; - va_list ap; - switch_status_t status = SWITCH_STATUS_SUCCESS; - - switch_assert(event != NULL); - - - va_start(ap, fmt); - ret = switch_vasprintf(&varname, fmt, ap); - va_end(ap); - - if (ret == -1) { - return SWITCH_STATUS_MEMERR; - } - - status = switch_event_add_header_string(event, stack, varname, val); - - free(varname); - - return status; -} - -SWITCH_DECLARE(switch_status_t) kz_expand_json_to_event(cJSON *json, switch_event_t *event, char * prefix) -{ - char * fmt = switch_mprintf("%s%s%%s", prefix ? prefix : "", prefix ? "_" : ""); - if (event) { - cJSON *item = NULL; - char *response = NULL; - cJSON_ArrayForEach(item, json) { - if (item->type == cJSON_String) { - response = strdup(item->valuestring); - } else if (item->type == cJSON_Object) { - char * fmt1 = switch_mprintf(fmt, item->string); - kz_expand_json_to_event(item, event, fmt1); - switch_safe_free(fmt1); - continue; - } else { - response = cJSON_PrintUnformatted(item); - } - kz_switch_event_add_variable_name_printf(event, SWITCH_STACK_BOTTOM, response, fmt, item->string); - switch_safe_free(response); - } - } - - switch_safe_free(fmt); - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_DECLARE(switch_xml_t) kz_xml_child(switch_xml_t xml, const char *name) -{ - xml = (xml) ? xml->child : NULL; - while (xml && strcasecmp(name, xml->name)) - xml = xml->sibling; - return xml; -} - -void kz_xml_process(switch_xml_t cfg) -{ - switch_xml_t xml_process; - for (xml_process = kz_xml_child(cfg, "X-PRE-PROCESS"); xml_process; xml_process = xml_process->next) { - const char *cmd = switch_xml_attr(xml_process, "cmd"); - const char *data = switch_xml_attr(xml_process, "data"); - if(cmd != NULL && !strcasecmp(cmd, "set") && data) { - char *name = (char *) data; - char *val = strchr(name, '='); - - if (val) { - char *ve = val++; - while (*val && *val == ' ') { - val++; - } - *ve-- = '\0'; - while (*ve && *ve == ' ') { - *ve-- = '\0'; - } - } - - if (name && val) { - switch_core_set_variable(name, val); - } - } - } - -} - -void kz_event_decode(switch_event_t *event) -{ - switch_event_header_t *hp; - int i; - for (hp = event->headers; hp; hp = hp->next) { - if (strncmp(hp->name, "_json_", 6)) { - if (hp->idx) { - for(i = 0; i < hp->idx; i++) { - switch_url_decode(hp->array[i]); - } - } else { - switch_url_decode(hp->value); - } - } - } -} - -void kz_expand_headers(switch_event_t *resolver, switch_event_t *event) { - switch_event_t *clone = NULL; - switch_event_header_t *header = NULL; - switch_event_create_plain(&clone, event->event_id); - - for(header = event->headers; header; header = header->next) { - char *expanded = kz_event_expand_headers(resolver, header->value); - if (expanded != header->value) { - switch_event_add_header_string(clone, SWITCH_STACK_BOTTOM, header->name, expanded); - switch_safe_free(expanded); - } - } - - /* we don't want to force unique headers - * so we delete and then merge - */ - for(header = clone->headers; header; header = header->next) { - switch_event_del_header(event, header->name); - } - - switch_event_merge(event, clone); - - switch_event_destroy(&clone); -} - -void kz_expand_headers_self(switch_event_t *event) { - kz_expand_headers(event, event); -} - -char * kz_expand_vars(char *xml_str) { - return kz_expand_vars_pool(xml_str, NULL); -} - -char * kz_expand_vars_pool(char *xml_str, switch_memory_pool_t *pool) { - char *var, *val; - char *rp = xml_str; /* read pointer */ - char *ep, *wp, *buff; /* end pointer, write pointer, write buffer */ - - if (!(strstr(xml_str, "$${"))) { - return xml_str; - } - - switch_zmalloc(buff, strlen(xml_str) * 2); - wp = buff; - ep = buff + (strlen(xml_str) * 2) - 1; - - while (*rp && wp < ep) { - if (*rp == '$' && *(rp + 1) == '$' && *(rp + 2) == '{') { - char *e = switch_find_end_paren(rp + 2, '{', '}'); - - if (e) { - rp += 3; - var = rp; - *e++ = '\0'; - rp = e; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "trying to expand %s \n", var); - if ((val = switch_core_get_variable_dup(var))) { - char *p; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "expanded %s to %s\n", var, val); - for (p = val; p && *p && wp <= ep; p++) { - *wp++ = *p; - } - switch_safe_free(val); - } - continue; - } - } - - *wp++ = *rp++; - } - - *wp++ = '\0'; - - if(pool) { - char * ret = switch_core_strdup(pool, buff); - switch_safe_free(buff); - return ret; - } else { - switch_safe_free(xml_str); - return buff; - } - -} - -switch_status_t kz_json_api(const char * command, cJSON *args, cJSON **res) -{ - switch_status_t status = SWITCH_STATUS_SUCCESS; - cJSON *req = cJSON_CreateObject(); - cJSON_AddItemToObject(req, "command", cJSON_CreateString(command)); - cJSON_AddItemToObject(req, "data", args ? args : cJSON_CreateObject()); - status = switch_json_api_execute(req, NULL, res); - cJSON_Delete(req); - return status; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_utils.h b/src/mod/event_handlers/mod_kazoo/kazoo_utils.h deleted file mode 100644 index cb5549c760..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kazoo_utils.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include - -#ifdef __cplusplus -#define KZ_BEGIN_EXTERN_C extern "C" { -#define KZ_END_EXTERN_C } -#else -#define KZ_BEGIN_EXTERN_C -#define KZ_END_EXTERN_C -#endif - -KZ_BEGIN_EXTERN_C - -void kz_check_set_profile_var(switch_channel_t *channel, char* var, char *val); - -SWITCH_DECLARE(switch_status_t) kz_switch_core_merge_variables(switch_event_t *event); - -SWITCH_DECLARE(switch_status_t) kz_switch_core_base_headers_for_expand(switch_event_t **event); - -SWITCH_DECLARE(switch_status_t) kz_expand_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream); - -SWITCH_DECLARE(char *) kz_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur); - -SWITCH_DECLARE(char *) kz_event_expand_headers(switch_event_t *event, const char *in); - -SWITCH_DECLARE(char *) kz_event_expand_headers_pool(switch_memory_pool_t *pool, switch_event_t *event, char *val); - -SWITCH_DECLARE(char *) kz_expand(const char *in, const char *uuid); - -SWITCH_DECLARE(char *) kz_expand_pool(switch_memory_pool_t *pool, const char *in); - -char* kz_switch_event_get_first_of(switch_event_t *event, const char *list[]); - -SWITCH_DECLARE(switch_status_t) kz_switch_event_add_variable_name_printf(switch_event_t *event, switch_stack_t stack, const char *val, const char *fmt, ...); - -SWITCH_DECLARE(switch_xml_t) kz_xml_child(switch_xml_t xml, const char *name); - -void kz_xml_process(switch_xml_t cfg); -void kz_event_decode(switch_event_t *event); - -char * kz_expand_vars(char *xml_str); -void kz_expand_headers(switch_event_t *resolver, switch_event_t *event); -void kz_expand_headers_self(switch_event_t *event); - -char * kz_expand_vars_pool(char *xml_str, switch_memory_pool_t *pool); -switch_status_t kz_json_api(const char * command, cJSON *args, cJSON **res); - -SWITCH_DECLARE(switch_status_t) kz_expand_json_to_event(cJSON *json, switch_event_t *event, char * prefix); - -KZ_END_EXTERN_C diff --git a/src/mod/event_handlers/mod_kazoo/kz_node.c b/src/mod/event_handlers/mod_kazoo/kz_node.c deleted file mode 100644 index 1c50d0586e..0000000000 --- a/src/mod/event_handlers/mod_kazoo/kz_node.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "mod_kazoo.h" - -static int kz_nodes_module_names_array_callback(void *pArg, const char *module_name) -{ - cJSON *json = (cJSON *) pArg; - if(!strstr(module_name, "CORE")) { - cJSON_AddItemToArray(json, cJSON_CreateString(module_name)); - } - return 0; -} - -void kz_nodes_collect_media_role(cJSON *container) -{ - cJSON *retval = NULL; - if(kz_json_api("sofia.status.info", NULL, &retval) == SWITCH_STATUS_SUCCESS) { - if(retval != NULL && (!(retval->type & cJSON_NULL))) { - cJSON_AddItemToObject(container, "Media", cJSON_Duplicate(retval, 1)); - } - } - if(retval) { - cJSON_Delete(retval); - } -} - -void kz_nodes_collect_modules(cJSON *container) -{ - cJSON *modules = cJSON_CreateObject(); - cJSON *loaded = cJSON_CreateArray(); - cJSON *available = cJSON_CreateArray(); - switch_loadable_module_enumerate_available(SWITCH_GLOBAL_dirs.mod_dir, kz_nodes_module_names_array_callback, available); - switch_loadable_module_enumerate_loaded(kz_nodes_module_names_array_callback, loaded); - cJSON_AddItemToObject(modules, "available", available); - cJSON_AddItemToObject(modules, "loaded", loaded); - cJSON_AddItemToObject(container, "Modules", modules); -} - -void kz_nodes_collect_runtime(cJSON *container) -{ - cJSON *retval = NULL; - if(kz_json_api("status", NULL, &retval) == SWITCH_STATUS_SUCCESS) { - if(retval != NULL && (!(retval->type & cJSON_NULL))) { - cJSON *val = cJSON_Duplicate(retval, 1); - cJSON_AddItemToObject(val, "Core-UUID", cJSON_CreateString(switch_core_get_uuid())); - cJSON_AddItemToObject(container, "Runtime-Info", val); - } - } - if(retval) { - cJSON_Delete(retval); - } -} - -void kz_nodes_collect_apps(cJSON *container) -{ - cJSON *apps = cJSON_CreateObject(); - cJSON *app = cJSON_CreateObject(); - cJSON_AddItemToObject(app, "Uptime", cJSON_CreateNumber(switch_core_uptime())); - cJSON_AddItemToObject(apps, "freeswitch", app); - cJSON_AddItemToObject(container, "WhApps", apps); -} - -void kz_nodes_collect_roles(cJSON *container) -{ - cJSON *roles = cJSON_CreateObject(); - cJSON_AddItemToObject(container, "Roles", roles); - kz_nodes_collect_media_role(roles); -} - -cJSON * kz_node_create() -{ - cJSON *node = cJSON_CreateObject(); - - kz_nodes_collect_apps(node); - kz_nodes_collect_runtime(node); - kz_nodes_collect_modules(node); - kz_nodes_collect_roles(node); - - return node; -} - -SWITCH_STANDARD_JSON_API(kz_node_info_json_function) -{ - cJSON * ret = kz_node_create(); - *json_reply = ret; - return SWITCH_STATUS_SUCCESS; -} - -void add_kz_node(switch_loadable_module_interface_t **module_interface) -{ - switch_json_api_interface_t *json_api_interface = NULL; - SWITCH_ADD_JSON_API(json_api_interface, "node.info", "JSON node API", kz_node_info_json_function, ""); -} diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c deleted file mode 100644 index 15b8fb469c..0000000000 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Karl Anderson - * Darren Schreiber - * - * - * mod_kazoo.c -- Socket Controlled Event Handler - * - */ -#include "mod_kazoo.h" - -kz_globals_t kazoo_globals = {0}; - - - -SWITCH_MODULE_DEFINITION(mod_kazoo, mod_kazoo_load, mod_kazoo_shutdown, mod_kazoo_runtime); - -SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load) -{ - kz_erl_init(); - - memset(&kazoo_globals, 0, sizeof(kazoo_globals)); - kazoo_globals.pool = pool; - kz_set_hostname(); - if(kazoo_load_config() != SWITCH_STATUS_SUCCESS) { - // TODO: what would we need to clean up here? - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Improper configuration!\n"); - return SWITCH_STATUS_TERM; - } - - /* connect my internal structure to the blank pointer passed to me */ - *module_interface = switch_loadable_module_create_module_interface(pool, modname); - - switch_thread_rwlock_create(&kazoo_globals.ei_nodes_lock, pool); - - switch_set_flag(&kazoo_globals, LFLAG_RUNNING); - - /* create all XML fetch agents */ - bind_fetch_agents(); - - /* create an api for cli debug commands */ - add_cli_api(module_interface); - - /* add our modified commands */ - add_kz_commands(module_interface); - - /* add our modified dptools */ - add_kz_dptools(module_interface); - - /* add our endpoints */ - add_kz_endpoints(module_interface); - - /* add our kz_node api */ - add_kz_node(module_interface); - - /* add tweaks */ - kz_tweaks_start(); - - /* add our cdr */ - kz_cdr_start(); - - /* indicate that the module should continue to be loaded */ - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown) { - int sanity = 0; - - remove_cli_api(); - - kz_cdr_stop(); - - kz_tweaks_stop(); - - /* stop taking new requests and start shuting down the threads */ - switch_clear_flag(&kazoo_globals, LFLAG_RUNNING); - - /* give everyone time to cleanly shutdown */ - while (switch_atomic_read(&kazoo_globals.threads)) { - switch_yield(100000); - if (++sanity >= 200) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to kill all threads, continuing. This probably wont end well.....good luck!\n"); - break; - } - } - - /* close the connection to epmd and the acceptor */ - close_socketfd(&kazoo_globals.epmdfd); - close_socket(&kazoo_globals.acceptor); - - /* remove all XML fetch agents */ - unbind_fetch_agents(); - - if (kazoo_globals.event_filter) { - switch_core_hash_destroy(&kazoo_globals.event_filter); - } - - switch_thread_rwlock_wrlock(kazoo_globals.ei_nodes_lock); - switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock); - switch_thread_rwlock_destroy(kazoo_globals.ei_nodes_lock); - - /* Close the port we reserved for uPnP/Switch behind firewall, if necessary */ - if (kazoo_globals.nat_map && switch_nat_get_type()) { - switch_nat_del_mapping(kazoo_globals.port, SWITCH_NAT_TCP); - } - - kazoo_destroy_config(); - - /* clean up our allocated preferences */ - switch_safe_free(kazoo_globals.ip); - switch_safe_free(kazoo_globals.ei_cookie); - switch_safe_free(kazoo_globals.ei_nodename); - - kz_erl_shutdown(); - - return SWITCH_STATUS_SUCCESS; -} - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.h b/src/mod/event_handlers/mod_kazoo/mod_kazoo.h deleted file mode 100644 index 37fdd861e7..0000000000 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.h +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_ACL 100 -#define CMD_BUFLEN 1024 * 1000 -#define MAX_QUEUE_LEN 25000 -#define MAX_MISSED 500 -#define MAX_PID_CHARS 255 - -extern const char kz_default_config[]; -extern const int kz_default_config_size; - -#include "kazoo_defs.h" -#include "kazoo_tweaks.h" -#include "kazoo_ei.h" -#include "kazoo_message.h" -#include "kazoo_utils.h" - -typedef enum { - LFLAG_RUNNING = (1 << 0) -} event_flag_t; - - -/* kazoo_commands.c */ -void add_kz_commands(switch_loadable_module_interface_t **module_interface); - -/* kazoo_dptools.c */ -void add_kz_dptools(switch_loadable_module_interface_t **module_interface); - -/* kazoo_api.c */ -void add_cli_api(switch_loadable_module_interface_t **module_interface); -void remove_cli_api(); - -/* kazoo_utils.c */ -/* -SWITCH_DECLARE(switch_status_t) kz_switch_core_merge_variables(switch_event_t *event); -SWITCH_DECLARE(switch_status_t) kz_switch_core_base_headers_for_expand(switch_event_t **event); -void kz_check_set_profile_var(switch_channel_t *channel, char* var, char *val); -char* kz_switch_event_get_first_of(switch_event_t *event, const char *list[]); -SWITCH_DECLARE(switch_status_t) kz_switch_event_add_variable_name_printf(switch_event_t *event, switch_stack_t stack, const char *val, const char *fmt, ...); -void kz_xml_process(switch_xml_t cfg); -void kz_event_decode(switch_event_t *event); -char * kz_expand_vars(char *xml_str); -char * kz_expand_vars_pool(char *xml_str, switch_memory_pool_t *pool); -SWITCH_DECLARE(char *) kz_event_expand_headers(switch_event_t *event, const char *in); -SWITCH_DECLARE(char *) kz_expand(const char *in); -SWITCH_DECLARE(char *) kz_expand_pool(switch_memory_pool_t *pool, const char *in); -switch_status_t kz_json_api(const char * command, cJSON *args, cJSON **res); -*/ - -/* kazoo_endpoints.c */ -void add_kz_endpoints(switch_loadable_module_interface_t **module_interface); - -/* kazoo_cdr.c */ -void kz_cdr_start(); -void kz_cdr_stop(); - -/* kazoo_tweaks.c */ -void kz_tweaks_start(); -void kz_tweaks_stop(); -SWITCH_DECLARE(const char *) kz_tweak_name(kz_tweak_t tweak); -SWITCH_DECLARE(switch_status_t) kz_name_tweak(const char *name, kz_tweak_t *type); - -/* kazoo_node.c */ -void add_kz_node(switch_loadable_module_interface_t **module_interface); - -SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load); -SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown); - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ From 49029c8575891b4f3a637d43214d5df323760171 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Wed, 21 Feb 2024 01:47:45 +0000 Subject: [PATCH 122/123] [mod_sofia] Set missing CF_3PCC flag --- src/mod/endpoints/mod_sofia/sofia.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 311052a619..43bd68b923 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -7992,6 +7992,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_hangup(channel, SWITCH_CAUSE_MANDATORY_IE_MISSING); } else { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOSDP"); + switch_channel_set_flag(channel, CF_3PCC); switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0); switch_core_media_prepare_codecs(session, 1); switch_channel_set_state(channel, CS_HIBERNATE); From d5ad504723a6bf80fbf80b3c35a2e14ab4111582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Had=C5=BEem=20Had=C5=BEi=C4=87?= Date: Thu, 18 Apr 2024 11:06:40 +0200 Subject: [PATCH 123/123] [mod_vlc] Resolve double mutex lock --- src/mod/formats/mod_vlc/mod_vlc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mod/formats/mod_vlc/mod_vlc.c b/src/mod/formats/mod_vlc/mod_vlc.c index af83330d07..6b725515f4 100644 --- a/src/mod/formats/mod_vlc/mod_vlc.c +++ b/src/mod/formats/mod_vlc/mod_vlc.c @@ -1096,7 +1096,8 @@ static switch_status_t vlc_file_read(switch_file_handle_t *handle, void *data, s switch_thread_cond_wait(context->cond, context->cond_mutex); status = libvlc_media_get_state(context->m); } - switch_mutex_lock(context->cond_mutex); + + switch_mutex_unlock(context->cond_mutex); if (context->err == 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "VLC error\n");