diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index fe3029a3e..bd38dbc74 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -601,6 +601,8 @@ INLINE void ng_sdp_attr_manipulations(struct sdp_manipulations_common ** sm_ptr, bencode_item_t *command_action = it->sibling ? it->sibling : NULL; enum media_type media; str media_type; + GQueue * q_ptr = NULL; + GHashTable ** ht = NULL; if (!command_action) /* if no action, makes no sense to continue */ continue; @@ -624,29 +626,30 @@ INLINE void ng_sdp_attr_manipulations(struct sdp_manipulations_common ** sm_ptr, if (!bencode_get_str(it_c, &command_type)) continue; - GQueue * q_ptr = NULL; - switch (__csh_lookup(&command_type)) { /* CMD_ADD / CMD_SUBST commands */ case CSH_LOOKUP("substitute"):; - struct sdp_substitute_attr * subst_command = NULL; switch (media) { case MT_UNKNOWN: - q_ptr = &(*sm_ptr)->subst_commands_glob; + ht = &(*sm_ptr)->subst_commands_glob; break; case MT_AUDIO: - q_ptr = &(*sm_ptr)->subst_commands_audio; + ht = &(*sm_ptr)->subst_commands_audio; break; case MT_VIDEO: - q_ptr = &(*sm_ptr)->subst_commands_video; + ht = &(*sm_ptr)->subst_commands_video; break; default: - ilog(LOG_WARN, "SDP manipulations: unspported SDP section targeted."); + ilog(LOG_WARN, "SDP manipulations: unsupported SDP section targeted."); continue; } + /* a table can already be allocated by similar commands in previous iterations */ + if (!*ht) + *ht = g_hash_table_new_full(str_case_hash, str_case_equal, free, free); + for (bencode_item_t *it_v = command_value->child; it_v; it_v = it_v->sibling) { str from; @@ -666,11 +669,7 @@ INLINE void ng_sdp_attr_manipulations(struct sdp_manipulations_common ** sm_ptr, continue; } - subst_command = g_slice_alloc0(sizeof(*subst_command)); - subst_command->value_a = s_copy_from; - subst_command->value_b = s_copy_to; - - g_queue_push_tail(q_ptr, subst_command); + g_hash_table_replace(*ht, s_copy_from, s_copy_to); } break; @@ -704,8 +703,6 @@ INLINE void ng_sdp_attr_manipulations(struct sdp_manipulations_common ** sm_ptr, /* CMD_REM commands */ case CSH_LOOKUP("remove"):; - GHashTable ** ht = NULL; - switch (media) { case MT_UNKNOWN: ht = &(*sm_ptr)->rem_commands_glob; @@ -1817,20 +1814,7 @@ static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *inpu call_ng_dict_iter(out, input, call_ng_main_flags); } -static void free_subst_attr(void *p) { - struct sdp_substitute_attr *attr = p; - if (attr->value_a) - free(attr->value_a); - if (attr->value_b) - free(attr->value_b); - g_slice_free1(sizeof(*attr), attr); -} - static void ng_sdp_attr_manipulations_free(struct sdp_manipulations_common * sdp_manipulations) { - GQueue *cpq_subst_glob = &sdp_manipulations->subst_commands_glob; - GQueue *cpq_subst_audio = &sdp_manipulations->subst_commands_audio; - GQueue *cpq_subst_video = &sdp_manipulations->subst_commands_video; - if (sdp_manipulations->rem_commands_glob) g_hash_table_destroy(sdp_manipulations->rem_commands_glob); if (sdp_manipulations->rem_commands_audio) @@ -1838,17 +1822,17 @@ static void ng_sdp_attr_manipulations_free(struct sdp_manipulations_common * sdp if (sdp_manipulations->rem_commands_video) g_hash_table_destroy(sdp_manipulations->rem_commands_video); + if (sdp_manipulations->subst_commands_glob) + g_hash_table_destroy(sdp_manipulations->subst_commands_glob); + if (sdp_manipulations->subst_commands_audio) + g_hash_table_destroy(sdp_manipulations->subst_commands_audio); + if (sdp_manipulations->subst_commands_video) + g_hash_table_destroy(sdp_manipulations->subst_commands_video); + g_queue_clear_full(&sdp_manipulations->add_commands_glob, free); g_queue_clear_full(&sdp_manipulations->add_commands_audio, free); g_queue_clear_full(&sdp_manipulations->add_commands_video, free); - if (cpq_subst_glob && cpq_subst_glob->head) - g_queue_clear_full(cpq_subst_glob, free_subst_attr); - if (cpq_subst_audio && cpq_subst_audio->head) - g_queue_clear_full(cpq_subst_audio, free_subst_attr); - if (cpq_subst_video && cpq_subst_video->head) - g_queue_clear_full(cpq_subst_video, free_subst_attr); - g_slice_free1(sizeof(*sdp_manipulations), sdp_manipulations); } diff --git a/daemon/sdp.c b/daemon/sdp.c index 5f5b50b4b..21f2a4cb3 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -291,15 +291,6 @@ static void attr_free(void *p); static void attr_insert(struct sdp_attributes *attrs, struct sdp_attribute *attr); INLINE void chopper_append_c(struct sdp_chopper *c, const char *s); -/** - * Helper, which compares a substitute command for SDP manipulations. - */ -static int sdp_manipulate_subst_cmp(gconstpointer a, gconstpointer b) { - const struct sdp_substitute_attr * subst = a; - const struct sdp_substitute_attr * subst_lookup = b; - return str_cmp_str(subst->value_a, subst_lookup->value_a); -} - /** * Checks whether a given type of SDP manipulation exists for a given session level. */ @@ -320,32 +311,32 @@ static int sdp_manipulate_check(enum command_type command_type, } GQueue * q_ptr = NULL; + GHashTable * ht = NULL; switch (command_type) { case CMD_SUBST:; - q_ptr = NULL; + ht = NULL; if (!attr_name || !attr_name->len) break; - struct sdp_substitute_attr fictitious = {attr_name, NULL}; switch (media_type) { case MT_AUDIO: - q_ptr = &sdp_manipulations->subst_commands_audio; + ht = sdp_manipulations->subst_commands_audio; break; case MT_VIDEO: - q_ptr = &sdp_manipulations->subst_commands_video; + ht = sdp_manipulations->subst_commands_video; break; default: /* MT_UNKNOWN */ - q_ptr = &sdp_manipulations->subst_commands_glob; + ht = sdp_manipulations->subst_commands_glob; } - if (q_ptr && q_ptr->head && - g_queue_find_custom(q_ptr, &fictitious, sdp_manipulate_subst_cmp)) + + str * l = g_hash_table_lookup(ht, attr_name); + if (l) return 1; break; case CMD_ADD:; - q_ptr = NULL; switch (media_type) { case MT_AUDIO: q_ptr = &sdp_manipulations->add_commands_audio; @@ -361,7 +352,7 @@ static int sdp_manipulate_check(enum command_type command_type, break; case CMD_REM:; - GHashTable *ht = NULL; + ht = NULL; if (!attr_name || !attr_name->len) break; @@ -424,28 +415,26 @@ static void sdp_manipulations_subst(struct sdp_chopper *chop, struct sdp_manipulations_common * sdp_manipulations, enum media_type media_type, str * attr_name) { - GQueue * q_ptr = NULL; + GHashTable * ht = NULL; + switch (media_type) { case MT_AUDIO: - q_ptr = &sdp_manipulations->subst_commands_audio; + ht = sdp_manipulations->subst_commands_audio; break; case MT_VIDEO: - q_ptr = &sdp_manipulations->subst_commands_video; + ht = sdp_manipulations->subst_commands_video; break; default: /* MT_UNKNOWN */ - q_ptr = &sdp_manipulations->subst_commands_glob; + ht = sdp_manipulations->subst_commands_glob; } - for (GList *l = q_ptr->head; l; l = l->next) - { - struct sdp_substitute_attr * attr_value = l->data; + str * cmd_subst_value = g_hash_table_lookup(ht, attr_name); + if (!cmd_subst_value) + return; - if (!str_cmp_str(attr_name, attr_value->value_a)) { - chopper_append_c(chop, "a="); - chopper_append_c(chop, attr_value->value_b->s); - chopper_append_c(chop, "\r\n"); - } - } + chopper_append_c(chop, "a="); + chopper_append_c(chop, cmd_subst_value->s); + chopper_append_c(chop, "\r\n"); } static void append_attr_to_gstring(GString *s, char * name, const str * value, diff --git a/include/sdp.h b/include/sdp.h index 731a57a67..7dbe97f69 100644 --- a/include/sdp.h +++ b/include/sdp.h @@ -13,12 +13,6 @@ enum command_type { CMD_SUBST, }; -/* */ -struct sdp_substitute_attr { - str * value_a; /* from */ - str * value_b; /* to */ -}; - /* A structure for SDP arbitrary manipulations on all levels of SDP: * session (global), media (audio/video). Works only on `a=` lines. */ @@ -31,9 +25,9 @@ struct sdp_manipulations_common { GHashTable * rem_commands_audio; GHashTable * rem_commands_video; - GQueue subst_commands_glob; - GQueue subst_commands_audio; - GQueue subst_commands_video; + GHashTable * subst_commands_glob; + GHashTable * subst_commands_audio; + GHashTable * subst_commands_video; }; struct ice_candidate;