From 2f8e6a55e10fa0dee76697d9b18915d1c0c9c525 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 30 Dec 2022 21:32:39 +0100 Subject: [PATCH] MT#56126 Introduce a new helper function for parsing flags New helper func: call_ng_flags_str_q_multi() It parses given flags delimited by a separator, and stores each of them in the given GQueue. By default delimiter is assumed as: ';'. Change-Id: I1e29bf3d852868e2bc4d98b1775f70b38f61054a --- daemon/call_interfaces.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 9dd343542..90a509254 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -59,6 +59,7 @@ static GHashTable *sdp_fragments; INLINE int call_ng_flags_prefix(struct sdp_ng_flags *out, str *s_ori, const char *prefix, void (*cb)(struct sdp_ng_flags *, str *, void *), void *ptr); static void call_ng_flags_str_ht(struct sdp_ng_flags *out, str *s, void *htp); +static void call_ng_flags_str_q_multi(struct sdp_ng_flags *out, str *s, void *qp); static void ng_stats_ssrc(bencode_item_t *dict, struct ssrc_hash *ht); @@ -741,6 +742,9 @@ static void call_ng_flags_esc_str_list(struct sdp_ng_flags *out, str *s, void *q str *s_copy = str_dup_escape(s); g_queue_push_tail((GQueue *) qp, s_copy); } +/** + * Stores flag's value in the given GhashTable. + */ static void call_ng_flags_str_ht(struct sdp_ng_flags *out, str *s, void *htp) { str *s_copy = str_dup_escape(s); GHashTable **ht = htp; @@ -748,6 +752,26 @@ static void call_ng_flags_str_ht(struct sdp_ng_flags *out, str *s, void *htp) { *ht = g_hash_table_new_full(str_case_hash, str_case_equal, free, NULL); g_hash_table_replace(*ht, s_copy, s_copy); } +/** + * Parses one-row flags separated by 'delimiter'. + * Stores parsed flag's values then in the given GQueue. + */ +static void call_ng_flags_str_q_multi(struct sdp_ng_flags *out, str *s, void *qp) { + str *s_copy = str_dup_escape(s); + str token; + GQueue *q = qp; + + if (s_copy->len == 0) + ilog(LOG_DEBUG, "Hm, nothing to parse."); + + while (str_token_sep(&token, s_copy, ';') == 0) + { + str * ret = str_dup(&token); + g_queue_push_tail(q, ret); + } + + free(s_copy); +} #ifdef WITH_TRANSCODING static void call_ng_flags_str_ht_split(struct sdp_ng_flags *out, str *s, void *htp) { GHashTable **ht = htp;