TT#30403 consolidate NG flags processing functions

Change-Id: Id200b0f064b72d8e60a6a744f764a8bb63655014
pull/445/head
Richard Fuchs 8 years ago
parent 74bae6a9a9
commit b8dbd997e9

@ -526,20 +526,47 @@ INLINE void ng_sdes_option(struct sdp_ng_flags *out, bencode_item_t *it, unsigne
STR_FMT(&s)); STR_FMT(&s));
} }
static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *input) {
bencode_item_t *list, *it;
int diridx;
str s;
ZERO(*out);
out->trust_address = trust_address_def; static void call_ng_flags_list(struct sdp_ng_flags *out, bencode_item_t *input, const char *key,
out->dtls_passive = dtls_passive_def; void (*callback)(struct sdp_ng_flags *out, bencode_item_t *input))
{
if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) { bencode_item_t *list, *it;
for (it = list->child; it; it = it->sibling) { if ((list = bencode_dictionary_get_expect(input, key, BENCODE_LIST))) {
for (it = list->child; it; it = it->sibling)
callback(out, it);
}
}
static void call_ng_flags_sdes(struct sdp_ng_flags *out, bencode_item_t *it) {
ng_sdes_option(out, it, 0);
}
static void call_ng_flags_rtcp_mux(struct sdp_ng_flags *out, bencode_item_t *it) {
if (!bencode_strcmp(it, "offer"))
out->rtcp_mux_offer = 1;
else if (!bencode_strcmp(it, "require"))
out->rtcp_mux_require = 1;
else if (!bencode_strcmp(it, "demux"))
out->rtcp_mux_demux = 1;
else if (!bencode_strcmp(it, "accept"))
out->rtcp_mux_accept = 1;
else if (!bencode_strcmp(it, "reject"))
out->rtcp_mux_reject = 1;
else
ilog(LOG_WARN, "Unknown 'rtcp-mux' flag encountered: '"BENCODE_FORMAT"'",
BENCODE_FMT(it));
}
static void call_ng_flags_replace(struct sdp_ng_flags *out, bencode_item_t *it) {
str_hyphenate(it);
if (!bencode_strcmp(it, "origin"))
out->replace_origin = 1;
else if (!bencode_strcmp(it, "session-connection"))
out->replace_sess_conn = 1;
else
ilog(LOG_WARN, "Unknown 'replace' flag encountered: '"BENCODE_FORMAT"'",
BENCODE_FMT(it));
}
static void call_ng_flags_flags(struct sdp_ng_flags *out, bencode_item_t *it) {
if (it->type != BENCODE_STRING) if (it->type != BENCODE_STRING)
continue; return;
str_hyphenate(it); str_hyphenate(it);
@ -571,20 +598,18 @@ static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *inpu
ilog(LOG_WARN, "Unknown flag encountered: '"BENCODE_FORMAT"'", ilog(LOG_WARN, "Unknown flag encountered: '"BENCODE_FORMAT"'",
BENCODE_FMT(it)); BENCODE_FMT(it));
} }
} static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *input) {
bencode_item_t *list, *it;
int diridx;
str s;
if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) { ZERO(*out);
for (it = list->child; it; it = it->sibling) {
str_hyphenate(it); out->trust_address = trust_address_def;
if (!bencode_strcmp(it, "origin")) out->dtls_passive = dtls_passive_def;
out->replace_origin = 1;
else if (!bencode_strcmp(it, "session-connection")) call_ng_flags_list(out, input, "flags", call_ng_flags_flags);
out->replace_sess_conn = 1; call_ng_flags_list(out, input, "replace", call_ng_flags_replace);
else
ilog(LOG_WARN, "Unknown 'replace' flag encountered: '"BENCODE_FORMAT"'",
BENCODE_FMT(it));
}
}
diridx = 0; diridx = 0;
if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) { if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) {
@ -624,30 +649,10 @@ static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *inpu
STR_FMT(&s)); STR_FMT(&s));
} }
if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) { call_ng_flags_list(out, input, "rtcp-mux", call_ng_flags_rtcp_mux);
for (it = list->child; it; it = it->sibling) {
if (!bencode_strcmp(it, "offer"))
out->rtcp_mux_offer = 1;
else if (!bencode_strcmp(it, "require"))
out->rtcp_mux_require = 1;
else if (!bencode_strcmp(it, "demux"))
out->rtcp_mux_demux = 1;
else if (!bencode_strcmp(it, "accept"))
out->rtcp_mux_accept = 1;
else if (!bencode_strcmp(it, "reject"))
out->rtcp_mux_reject = 1;
else
ilog(LOG_WARN, "Unknown 'rtcp-mux' flag encountered: '"BENCODE_FORMAT"'",
BENCODE_FMT(it));
}
}
/* XXX abstractize the other list walking functions using callbacks */
/* XXX module still needs to support this list */ /* XXX module still needs to support this list */
if ((list = bencode_dictionary_get_expect(input, "SDES", BENCODE_LIST))) { call_ng_flags_list(out, input, "SDES", call_ng_flags_sdes);
for (it = list->child; it; it = it->sibling)
ng_sdes_option(out, it, 0);
}
bencode_get_alt(input, "transport-protocol", "transport protocol", &out->transport_protocol_str); bencode_get_alt(input, "transport-protocol", "transport protocol", &out->transport_protocol_str);
out->transport_protocol = transport_protocol(&out->transport_protocol_str); out->transport_protocol = transport_protocol(&out->transport_protocol_str);

@ -173,6 +173,7 @@ static void control_ng_incoming(struct obj *obj, str *buf, const endpoint_t *sin
g_string_free(log_str, TRUE); g_string_free(log_str, TRUE);
} }
// XXX do the strcmp's only once
errstr = NULL; errstr = NULL;
resultstr = "ok"; resultstr = "ok";
if (!str_cmp(&cmd, "ping")) { if (!str_cmp(&cmd, "ping")) {

Loading…
Cancel
Save