From b694cb09a6345f2f0f646e77cb27e42cfa77c989 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 Oct 2013 22:57:15 +0500 Subject: [PATCH] google changed something in DTLS --- src/include/switch_event.h | 3 +- src/switch_core_cert.c | 1 + src/switch_core_media.c | 18 +++++--- src/switch_event.c | 91 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/src/include/switch_event.h b/src/include/switch_event.h index be60c17cd9..d812602a5b 100644 --- a/src/include/switch_event.h +++ b/src/include/switch_event.h @@ -451,7 +451,8 @@ SWITCH_DECLARE(void) switch_live_array_unlock(switch_live_array_t *la); SWITCH_DECLARE(void) switch_live_array_set_user_data(switch_live_array_t *la, void *user_data); SWITCH_DECLARE(void) switch_live_array_set_command_handler(switch_live_array_t *la, switch_live_array_command_handler_t command_handler); SWITCH_DECLARE(void) switch_live_array_parse_json(cJSON *json, switch_event_channel_id_t channel_id); - +SWITCH_DECLARE(switch_bool_t) switch_live_array_add_alias(switch_live_array_t *la, const char *event_channel, const char *name); +SWITCH_DECLARE(switch_bool_t) switch_live_array_clear_alias(switch_live_array_t *la, const char *event_channel, const char *name); ///\} diff --git a/src/switch_core_cert.c b/src/switch_core_cert.c index 41446c600d..ffba06ade5 100644 --- a/src/switch_core_cert.c +++ b/src/switch_core_cert.c @@ -97,6 +97,7 @@ static const EVP_MD *get_evp_by_name(const char *name) { if (!strcasecmp(name, "md5")) return EVP_md5(); if (!strcasecmp(name, "sha1")) return EVP_sha1(); + if (!strcasecmp(name, "sha-1")) return EVP_sha1(); if (!strcasecmp(name, "sha-256")) return EVP_sha256(); if (!strcasecmp(name, "sha-512")) return EVP_sha512(); diff --git a/src/switch_core_media.c b/src/switch_core_media.c index b412a518f5..38f61fd826 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -2038,7 +2038,11 @@ static void generate_local_fingerprint(switch_media_handle_t *smh, switch_media_ switch_rtp_engine_t *engine = &smh->engines[type]; if (!engine->local_dtls_fingerprint.len) { - engine->local_dtls_fingerprint.type = "sha-256"; + if (engine->remote_dtls_fingerprint.type) { + engine->local_dtls_fingerprint.type = engine->remote_dtls_fingerprint.type; + } else { + engine->local_dtls_fingerprint.type = "sha-256"; + } switch_core_cert_gen_fingerprint(DTLS_SRTP_FNAME, &engine->local_dtls_fingerprint); } } @@ -2118,16 +2122,16 @@ static void check_ice(switch_media_handle_t *smh, switch_media_type_t type, sdp_ switch_set_string(engine->local_dtls_fingerprint.str, p); } - if (strcasecmp(engine->remote_dtls_fingerprint.type, "sha-256")) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "Unsupported fingerprint type.\n"); - engine->local_dtls_fingerprint.type = NULL; - engine->remote_dtls_fingerprint.type = NULL; - } + //if (strcasecmp(engine->remote_dtls_fingerprint.type, "sha-256")) { + // switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "Unsupported fingerprint type.\n"); + //engine->local_dtls_fingerprint.type = NULL; + //engine->remote_dtls_fingerprint.type = NULL; + //} generate_local_fingerprint(smh, type); switch_channel_set_flag(smh->session->channel, CF_DTLS); - + } else if (!engine->remote_ssrc && !strcasecmp(attr->a_name, "ssrc") && attr->a_value) { engine->remote_ssrc = (uint32_t) atol(attr->a_value); diff --git a/src/switch_event.c b/src/switch_event.c index 926b3d85f6..873e3d98dd 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -2963,6 +2963,12 @@ SWITCH_DECLARE(switch_status_t) switch_event_channel_bind(const char *event_chan return status; } +typedef struct alias_node_s { + char *event_channel; + char *name; + struct alias_node_s *next; +} alias_node_t; + typedef struct la_node_s { char *name; cJSON *obj; @@ -2986,8 +2992,31 @@ struct switch_live_array_s { switch_event_channel_id_t channel_id; switch_live_array_command_handler_t command_handler; void *user_data; + alias_node_t *aliases; }; +static switch_status_t la_broadcast(switch_live_array_t *la, cJSON **json) +{ + alias_node_t *np; + + if (la->aliases) { + switch_mutex_lock(la->mutex); + for (np = la->aliases; np; np = np->next) { + cJSON *dup = cJSON_Duplicate(*json, 1); + cJSON *data = cJSON_GetObjectItem(dup, "data"); + + cJSON_ReplaceItemInObject(dup, "eventChannel", cJSON_CreateString(np->event_channel)); + cJSON_ReplaceItemInObject(data, "name", cJSON_CreateString(np->name)); + + switch_event_channel_broadcast(np->event_channel, &dup, __FILE__, la->channel_id); + } + switch_mutex_unlock(la->mutex); + } + + return switch_event_channel_broadcast(la->event_channel, json, __FILE__, la->channel_id); + +} + SWITCH_DECLARE(switch_status_t) switch_live_array_visible(switch_live_array_t *la, switch_bool_t visible, switch_bool_t force) { @@ -3004,7 +3033,7 @@ SWITCH_DECLARE(switch_status_t) switch_live_array_visible(switch_live_array_t *l cJSON_AddItemToObject(data, "action", cJSON_CreateString(visible ? "hide" : "show")); cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(la->serno++)); - switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, la->channel_id); + la_broadcast(la, &msg); la->visible = visible; } @@ -3030,7 +3059,7 @@ SWITCH_DECLARE(switch_status_t) switch_live_array_clear(switch_live_array_t *la) cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(-1)); cJSON_AddItemToObject(data, "data", cJSON_CreateObject()); - switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, la->channel_id); + la_broadcast(la, &msg); while(np) { cur = np; @@ -3146,6 +3175,60 @@ SWITCH_DECLARE(switch_bool_t) switch_live_array_isnew(switch_live_array_t *la) return la->new; } +SWITCH_DECLARE(switch_bool_t) switch_live_array_clear_alias(switch_live_array_t *la, const char *event_channel, const char *name) +{ + alias_node_t *np, *last = NULL; + switch_bool_t r = SWITCH_FALSE; + + switch_mutex_lock(la->mutex); + for (np = la->aliases; np; np = np->next) { + if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) { + r = SWITCH_TRUE; + + if (last) { + last->next = np->next; + } else { + la->aliases = np->next; + } + } else { + last = np; + } + } + switch_mutex_unlock(la->mutex); + + return r; +} + +SWITCH_DECLARE(switch_bool_t) switch_live_array_add_alias(switch_live_array_t *la, const char *event_channel, const char *name) +{ + alias_node_t *node, *np; + switch_bool_t exist = SWITCH_FALSE; + + switch_mutex_lock(la->mutex); + for (np = la->aliases; np && np->next; np = np->next) { + if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) { + exist = SWITCH_TRUE; + break; + } + } + + if (!exist) { + node = switch_core_alloc(la->pool, sizeof(*node)); + node->event_channel = switch_core_strdup(la->pool, event_channel); + node->name = switch_core_strdup(la->pool, name); + if (np) { + np->next = node; + } else { + la->aliases = node; + } + } + + switch_mutex_unlock(la->mutex); + + return !exist; +} + + SWITCH_DECLARE(switch_status_t) switch_live_array_create(const char *event_channel, const char *name, switch_event_channel_id_t channel_id, switch_live_array_t **live_arrayP) { @@ -3259,7 +3342,7 @@ SWITCH_DECLARE(switch_status_t) switch_live_array_del(switch_live_array_t *la, c cJSON_AddItemToObject(data, "data", cur->obj); cur->obj = NULL; - switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, la->channel_id); + la_broadcast(la, &msg); free(cur->name); free(cur); } else { @@ -3360,7 +3443,7 @@ SWITCH_DECLARE(switch_status_t) switch_live_array_add(switch_live_array_t *la, c cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(la->serno++)); cJSON_AddItemToObject(data, "data", cJSON_Duplicate(node->obj, 1)); - switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, la->channel_id); + la_broadcast(la, &msg); switch_mutex_unlock(la->mutex);