Browse Source

MT#55283 use typed G* for codec-set/except/SDES

Change-Id: Ib64e36db7ccccda83a84d36f716d13906d098946
pull/1776/head
Richard Fuchs 2 years ago
parent
commit
49037aee91
8 changed files with 47 additions and 47 deletions
  1. +3
    -2
      daemon/call.c
  2. +14
    -16
      daemon/call_interfaces.c
  3. +8
    -8
      daemon/codec.c
  4. +4
    -4
      include/call_interfaces.h
  5. +2
    -2
      include/codec.h
  6. +6
    -6
      include/crypto.h
  7. +4
    -0
      lib/str.h
  8. +6
    -9
      t/test-transcode.c

+ 3
- 2
daemon/call.c View File

@ -1856,7 +1856,8 @@ static void __sdes_accept(struct call_media *media, const sdp_ng_flags *flags) {
/* if 'flags->sdes_nonew' is set, don't prune anything, just pass all coming.
* 'flags->sdes_nonew' takes precedence over 'sdes_only' and 'sdes_no'. */
if (flags && (flags->sdes_only || flags->sdes_no) && !flags->sdes_nonew) {
if (flags && (t_hash_table_is_set(flags->sdes_only) || t_hash_table_is_set(flags->sdes_no))
&& !flags->sdes_nonew) {
__auto_type l = media->sdes_in.tail;
while (l) {
struct crypto_params_sdes *offered_cps = l->data;
@ -1878,7 +1879,7 @@ static void __sdes_accept(struct call_media *media, const sdp_ng_flags *flags) {
ilogs(crypto, LOG_DEBUG, "Dropping offered crypto suite '%s' from offer due to %s",
offered_cps->params.crypto_suite->name,
flags->sdes_only ? "not being in SDES-only" : "SDES-no");
t_hash_table_is_set(flags->sdes_only) ? "not being in SDES-only" : "SDES-no");
__auto_type prev = l->prev;
t_queue_delete_link(&media->sdes_in, l);


+ 14
- 16
daemon/call_interfaces.c View File

@ -37,6 +37,8 @@ typedef union {
const struct sdp_attr_helper *attr_helper;
str_q *q;
GHashTable **htp;
str_case_ht *sct;
str_case_value_ht *svt;
void **generic;
} helper_arg __attribute__ ((__transparent_union__));
@ -902,10 +904,10 @@ static void call_ng_flags_esc_str_list(sdp_ng_flags *out, str *s, helper_arg arg
*/
static void call_ng_flags_str_ht(sdp_ng_flags *out, str *s, helper_arg arg) {
str *s_copy = str_dup_escape(s);
GHashTable **ht = arg.htp;
if (!*ht)
*ht = g_hash_table_new_full(str_case_hash, str_case_equal, free, NULL);
g_hash_table_replace(*ht, s_copy, s_copy);
str_case_ht *ht = arg.sct;
if (!t_hash_table_is_set(*ht))
*ht = str_case_ht_new();
t_hash_table_replace(*ht, s_copy, s_copy);
}
/**
* Parses one-row flags separated by 'delimiter'.
@ -929,12 +931,12 @@ static void call_ng_flags_str_q_multi(sdp_ng_flags *out, str *s, helper_arg arg)
}
#ifdef WITH_TRANSCODING
static void call_ng_flags_str_ht_split(sdp_ng_flags *out, str *s, helper_arg arg) {
GHashTable **ht = arg.htp;
if (!*ht)
*ht = g_hash_table_new_full(str_case_hash, str_case_equal, free, free);
str_case_value_ht *ht = arg.svt;
if (!t_hash_table_is_set(*ht))
*ht = str_case_value_ht_new();
str splitter = *s;
while (1) {
g_hash_table_replace(*ht, str_dup_escape(&splitter), str_dup_escape(s));
t_hash_table_replace(*ht, str_dup_escape(&splitter), str_dup_escape(s));
char *c = memrchr(splitter.s, '/', splitter.len);
if (!c)
break;
@ -1868,14 +1870,10 @@ static void ng_sdp_attr_manipulations_free(struct sdp_manipulations * array[__MT
}
void call_ng_free_flags(sdp_ng_flags *flags) {
if (flags->codec_except)
g_hash_table_destroy(flags->codec_except);
if (flags->codec_set)
g_hash_table_destroy(flags->codec_set);
if (flags->sdes_no)
g_hash_table_destroy(flags->sdes_no);
if (flags->sdes_only)
g_hash_table_destroy(flags->sdes_only);
str_case_ht_destroy_ptr(&flags->codec_except);
str_case_value_ht_destroy_ptr(&flags->codec_set);
str_case_ht_destroy_ptr(&flags->sdes_no);
str_case_ht_destroy_ptr(&flags->sdes_only);
if (flags->frequencies)
g_array_free(flags->frequencies, true);


+ 8
- 8
daemon/codec.c View File

@ -4577,9 +4577,9 @@ static void __insert_codec_tracker(GHashTable *all_clockrates, GHashTable *all_s
}
#endif
static int __codec_options_set1(struct call *call, struct rtp_payload_type *pt, const str *enc,
GHashTable *codec_set)
str_case_value_ht codec_set)
{
str *pt_str = g_hash_table_lookup(codec_set, enc);
str *pt_str = t_hash_table_lookup(codec_set, enc);
if (!pt_str)
return 0;
struct rtp_payload_type *pt_parsed = codec_make_payload_type(pt_str, MT_UNKNOWN);
@ -4601,10 +4601,10 @@ static int __codec_options_set1(struct call *call, struct rtp_payload_type *pt,
payload_type_free(pt_parsed);
return 1;
}
static void __codec_options_set(struct call *call, struct rtp_payload_type *pt, GHashTable *codec_set) {
static void __codec_options_set(struct call *call, struct rtp_payload_type *pt, str_case_value_ht codec_set) {
if (!call)
return;
if (!codec_set)
if (!t_hash_table_is_set(codec_set))
return;
if (__codec_options_set1(call, pt, &pt->encoding_with_full_params, codec_set))
return;
@ -5099,7 +5099,7 @@ void __codec_store_populate(struct codec_store *dst, struct codec_store *src, st
codec_store_cleanup(&orig_dst);
}
void codec_store_strip(struct codec_store *cs, str_q *strip, GHashTable *except) {
void codec_store_strip(struct codec_store *cs, str_q *strip, str_case_ht except) {
for (__auto_type l = strip->head; l; l = l->next) {
str *codec = l->data;
if (!str_cmp(codec, "all") || !str_cmp(codec, "full")) {
@ -5113,11 +5113,11 @@ void codec_store_strip(struct codec_store *cs, str_q *strip, GHashTable *except)
while (link) {
__auto_type next = link->next;
struct rtp_payload_type *pt = link->data;
if (except && g_hash_table_lookup(except, &pt->encoding))
if (t_hash_table_is_set(except) && t_hash_table_lookup(except, &pt->encoding))
;
else if (except && g_hash_table_lookup(except, &pt->encoding_with_params))
else if (t_hash_table_is_set(except) && t_hash_table_lookup(except, &pt->encoding_with_params))
;
else if (except && g_hash_table_lookup(except, &pt->encoding_with_full_params))
else if (t_hash_table_is_set(except) && t_hash_table_lookup(except, &pt->encoding_with_full_params))
;
else {
ilogs(codec, LOG_DEBUG, "Stripping codec " STR_FORMAT


+ 4
- 4
include/call_interfaces.h View File

@ -45,17 +45,17 @@ struct sdp_ng_flags {
sockaddr_t xmlrpc_callback;
endpoint_t dtmf_log_dest;
str_q codec_strip;
GHashTable *codec_except;
str_case_ht codec_except;
str_q codec_offer;
str_q codec_transcode;
str_q codec_mask;
str_q codec_accept;
str_q codec_consume;
GHashTable *codec_set;
str_case_value_ht codec_set;
int ptime,
rev_ptime;
GHashTable *sdes_no; /* individual crypto suites which are excluded */
GHashTable *sdes_only; /* individual crypto suites which are only accepted */
str_case_ht sdes_no; /* individual crypto suites which are excluded */
str_case_ht sdes_only; /* individual crypto suites which are only accepted */
str_q sdes_order; /* the order, in which crypto suites are being added to the SDP */
str_q sdes_offerer_pref; /* preferred crypto suites to be selected for the offerer */
str dtls_fingerprint;


+ 2
- 2
include/codec.h View File

@ -112,7 +112,7 @@ void codec_update_all_handlers(struct call_monologue *ml);
void codec_update_all_source_handlers(struct call_monologue *ml, const sdp_ng_flags *flags);
struct codec_store_args {
GHashTable *codec_set;
str_case_value_ht codec_set;
bool answer_only;
bool allow_asymmetric;
struct codec_store *merge_cs;
@ -133,7 +133,7 @@ void __codec_store_populate_reuse(struct codec_store *, struct codec_store *, st
__attribute__((nonnull(1, 2)))
void codec_store_add_raw(struct codec_store *cs, struct rtp_payload_type *pt);
__attribute__((nonnull(1, 2)))
void codec_store_strip(struct codec_store *, str_q *strip, GHashTable *except);
void codec_store_strip(struct codec_store *, str_q *strip, str_case_ht except);
__attribute__((nonnull(1, 2, 3)))
void codec_store_offer(struct codec_store *, str_q *, struct codec_store *);
__attribute__((nonnull(1, 2)))


+ 6
- 6
include/crypto.h View File

@ -231,8 +231,8 @@ INLINE void crypto_params_sdes_queue_copy(sdes_q *dst, const sdes_q *src) {
* Checks whether to apply policies according to: sdes_no / sdes_only
* returns: 1 - to not apply / 0 - to apply
*/
INLINE int crypto_params_sdes_check_limitations(GHashTable * sdes_only,
GHashTable * sdes_no,
INLINE int crypto_params_sdes_check_limitations(str_case_ht sdes_only,
str_case_ht sdes_no,
const struct crypto_suite *cps) {
/* if 'SDES-only-' flag(s) present, then
@ -241,16 +241,16 @@ INLINE int crypto_params_sdes_check_limitations(GHashTable * sdes_only,
* This takes precedence over 'SDES-no-'.
*
* We mustn't check the 'flags->sdes_no' at all, if 'flags->sdes_only' is set. */
if (sdes_only)
if (t_hash_table_is_set(sdes_only))
{
if (!g_hash_table_lookup(sdes_only, &cps->name_str))
if (!t_hash_table_lookup(sdes_only, &cps->name_str))
return 1;
}
/* if 'SDES-no-' flag(s) present, then
* remove SDES-no suites from offered ones */
else if (sdes_no &&
g_hash_table_lookup(sdes_no, &cps->name_str))
else if (t_hash_table_is_set(sdes_no) &&
t_hash_table_lookup(sdes_no, &cps->name_str))
{
return 1;
}


+ 4
- 0
lib/str.h View File

@ -182,6 +182,10 @@ gboolean str_equal(gconstpointer a, gconstpointer b);
guint str_case_hash(gconstpointer s);
gboolean str_case_equal(gconstpointer a, gconstpointer b);
TYPED_GHASHTABLE(str_case_ht, str, str, str_case_hash, str_case_equal, free, NULL)
TYPED_GHASHTABLE(str_case_value_ht, str, str, str_case_hash, str_case_equal, free, free)
/* returns a new str object, duplicates the pointers but doesn't duplicate the contents */
INLINE str *str_slice_dup(const str *);
/* destroy function, frees a slice-alloc'd str */


+ 6
- 9
t/test-transcode.c View File

@ -47,12 +47,9 @@ struct stream_params rtp_types_sp;
#define start() __start(__FILE__, __LINE__)
static void __cleanup(void) {
if (flags.codec_except)
g_hash_table_destroy(flags.codec_except);
if (flags.codec_set)
g_hash_table_destroy(flags.codec_set);
if (flags.sdes_no)
g_hash_table_destroy(flags.sdes_no);
str_case_ht_destroy_ptr(&flags.codec_except);
str_case_value_ht_destroy_ptr(&flags.codec_set);
str_case_ht_destroy_ptr(&flags.sdes_no);
t_queue_clear_full(&flags.codec_offer, str_free);
t_queue_clear_full(&flags.codec_transcode, str_free);
t_queue_clear_full(&flags.codec_strip, str_free);
@ -68,8 +65,8 @@ static void __init(void) {
__cleanup();
codec_store_init(&rtp_types_sp.codecs, NULL);
rtp_types_sp.rtp_endpoint.port = 9;
flags.codec_except = g_hash_table_new_full(str_case_hash, str_case_equal, free, NULL);
flags.codec_set = g_hash_table_new_full(str_case_hash, str_case_equal, free, free);
flags.codec_except = str_case_ht_new();
flags.codec_set = str_case_value_ht_new();
}
static struct packet_stream *ps_new(struct call *c) {
struct packet_stream *ps = malloc(sizeof(*ps));
@ -119,7 +116,7 @@ static void codec_set(char *c) {
str splitter = s;
while (1) {
g_hash_table_replace(flags.codec_set, str_dup(&splitter), str_dup(&s));
t_hash_table_replace(flags.codec_set, str_dup(&splitter), str_dup(&s));
char *cp = memrchr(splitter.s, '/', splitter.len);
if (!cp)
break;


Loading…
Cancel
Save