INLINE void ng_sdes_option(struct sdp_ng_flags *out, bencode_item_t *it, unsigned int strip) { str s; if (!bencode_get_str(it, &s)) return; str_shift(&s, strip); if (!str_cmp(&s, "no") || !str_cmp(&s, "off") || !str_cmp(&s, "disabled") || !str_cmp(&s, "disable")) out->sdes_off = 1; else if (!str_cmp(&s, "unencrypted_srtp") || !str_cmp(&s, "UNENCRYPTED_SRTP")) out->sdes_unencrypted_srtp = 1; else if (!str_cmp(&s, "unencrypted_srtcp") || !str_cmp(&s, "UNENCRYPTED_SRTCP")) out->sdes_unencrypted_srtcp = 1; else if (!str_cmp(&s, "unauthenticated_srtp") || !str_cmp(&s, "UNAUTHENTICATED_SRTP")) out->sdes_unauthenticated_srtp = 1; else if (!str_cmp(&s, "encrypted_srtp") || !str_cmp(&s, "ENCRYPTED_SRTP")) out->sdes_encrypted_srtp = 1; else if (!str_cmp(&s, "encrypted_srtcp") || !str_cmp(&s, "ENCRYPTED_SRTCP")) out->sdes_encrypted_srtcp = 1; else if (!str_cmp(&s, "authenticated_srtp") || !str_cmp(&s, "AUTHENTICATED_SRTP")) out->sdes_authenticated_srtp = 1; else ilog(LOG_WARN, "Unknown 'SDES' flag encountered: '"STR_FORMAT"'", STR_FMT(&s)); }
INLINE void str_hyphenate(bencode_item_t *it) { str s; if (!bencode_get_str(it, &s)) return; while (s.len) { str_chr_str(&s, &s, ' '); if (!s.s || !s.len) break; *s.s = '-'; str_shift(&s, 1); } }
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); if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { str_hyphenate(it); if (!bencode_strcmp(it, "trust-address")) out->trust_address = 1; else if (!bencode_strcmp(it, "asymmetric")) out->asymmetric = 1; else if (!bencode_strcmp(it, "strict-source")) out->strict_source = 1; else if (!bencode_strcmp(it, "media-handover")) out->media_handover = 1; else ilog(LOG_WARN, "Unknown flag encountered: '"BENCODE_FORMAT"'", BENCODE_FMT(it)); } } if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { 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)); } } diridx = 0; if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) { for (it = list->child; it && diridx < 2; it = it->sibling) bencode_get_str(it, &out->direction[diridx++]); } list = bencode_dictionary_get_expect(input, "received from", BENCODE_LIST); if (!list) list = bencode_dictionary_get_expect(input, "received-from", BENCODE_LIST); if (list && (it = list->child)) { bencode_get_str(it, &out->received_from_family); bencode_get_str(it->sibling, &out->received_from_address); } if (bencode_dictionary_get_str(input, "ICE", &s)) { if (!str_cmp(&s, "remove")) out->ice_remove = 1; else if (!str_cmp(&s, "force")) out->ice_force = 1; else if (!str_cmp(&s, "force_relay") || !str_cmp(&s, "force-relay")) out->ice_force_relay = 1; else ilog(LOG_WARN, "Unknown 'ICE' flag encountered: '"STR_FORMAT"'", STR_FMT(&s)); } if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { if (!bencode_strcmp(it, "offer")) out->rtcp_mux_offer = 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)); } } bencode_get_alt(input, "transport-protocol", "transport protocol", &out->transport_protocol_str); out->transport_protocol = transport_protocol(&out->transport_protocol_str); bencode_get_alt(input, "media-address", "media address", &out->media_address); if (bencode_get_alt(input, "address-family", "address family", &out->address_family_str)) out->address_family = address_family(&out->address_family_str); out->tos = bencode_dictionary_get_integer(input, "TOS", 256); }
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); if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { if (!bencode_strcmp(it, "trust address")) out->trust_address = 1; else if (!bencode_strcmp(it, "asymmetric")) out->asymmetric = 1; else if (!bencode_strcmp(it, "trust-address")) out->trust_address = 1; else if (!bencode_strcmp(it, "strict source")) out->strict_source = 1; else if (!bencode_strcmp(it, "media handover")) out->media_handover = 1; } } if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { if (!bencode_strcmp(it, "origin")) out->replace_origin = 1; else if (!bencode_strcmp(it, "session connection")) out->replace_sess_conn = 1; else if (!bencode_strcmp(it, "session-connection")) out->replace_sess_conn = 1; } } diridx = 0; if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) { for (it = list->child; it && diridx < 2; it = it->sibling) { if (!bencode_strcmp(it, "internal")) out->directions[diridx++] = DIR_INTERNAL; else if (!bencode_strcmp(it, "external")) out->directions[diridx++] = DIR_EXTERNAL; } } list = bencode_dictionary_get_expect(input, "received from", BENCODE_LIST); if (!list) list = bencode_dictionary_get_expect(input, "received-from", BENCODE_LIST); if (list && (it = list->child)) { bencode_get_str(it, &out->received_from_family); bencode_get_str(it->sibling, &out->received_from_address); } if (bencode_dictionary_get_str(input, "ICE", &s)) { if (!str_cmp(&s, "remove")) out->ice_remove = 1; else if (!str_cmp(&s, "force")) out->ice_force = 1; else if (!str_cmp(&s, "force_relay")) out->ice_force_relay = 1; } if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { if (!bencode_strcmp(it, "offer")) out->rtcp_mux_offer = 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; } } bencode_dictionary_get_str(input, "transport protocol", &out->transport_protocol_str); if (!out->transport_protocol_str.s) bencode_dictionary_get_str(input, "transport-protocol", &out->transport_protocol_str); out->transport_protocol = transport_protocol(&out->transport_protocol_str); bencode_dictionary_get_str(input, "media address", &out->media_address); if (bencode_dictionary_get_str(input, "address family", &out->address_family_str)) out->address_family = address_family(&out->address_family_str); }
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; out->dtls_passive = dtls_passive_def; if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { if (it->type != BENCODE_STRING) continue; str_hyphenate(it); if (!bencode_strcmp(it, "trust-address")) out->trust_address = 1; else if (!bencode_strcmp(it, "SIP-source-address")) out->trust_address = 0; else if (!bencode_strcmp(it, "asymmetric")) out->asymmetric = 1; else if (!bencode_strcmp(it, "strict-source")) out->strict_source = 1; else if (!bencode_strcmp(it, "media-handover")) out->media_handover = 1; else if (!bencode_strcmp(it, "reset")) out->reset = 1; else if (it->iov[1].iov_len >= 5 && !memcmp(it->iov[1].iov_base, "SDES-", 5)) ng_sdes_option(out, it, 5); else ilog(LOG_WARN, "Unknown flag encountered: '"BENCODE_FORMAT"'", BENCODE_FMT(it)); } } if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { 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)); } } diridx = 0; if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) { for (it = list->child; it && diridx < 2; it = it->sibling) bencode_get_str(it, &out->direction[diridx++]); } list = bencode_dictionary_get_expect(input, "received from", BENCODE_LIST); if (!list) list = bencode_dictionary_get_expect(input, "received-from", BENCODE_LIST); if (list && (it = list->child)) { bencode_get_str(it, &out->received_from_family); bencode_get_str(it->sibling, &out->received_from_address); } if (bencode_dictionary_get_str(input, "ICE", &s)) { if (!str_cmp(&s, "remove")) out->ice_remove = 1; else if (!str_cmp(&s, "force")) out->ice_force = 1; else if (!str_cmp(&s, "force_relay") || !str_cmp(&s, "force-relay") || !str_cmp(&s, "force relay")) out->ice_force_relay = 1; else ilog(LOG_WARN, "Unknown 'ICE' flag encountered: '"STR_FORMAT"'", STR_FMT(&s)); } if (bencode_dictionary_get_str(input, "DTLS", &s)) { if (!str_cmp(&s, "passive")) out->dtls_passive = 1; else if (!str_cmp(&s, "no") || !str_cmp(&s, "off") || !str_cmp(&s, "disabled") || !str_cmp(&s, "disable")) out->dtls_off = 1; else ilog(LOG_WARN, "Unknown 'DTLS' flag encountered: '"STR_FORMAT"'", STR_FMT(&s)); } if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) { for (it = list->child; it; it = it->sibling) { if (!bencode_strcmp(it, "offer")) out->rtcp_mux_offer = 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 */ if ((list = bencode_dictionary_get_expect(input, "SDES", BENCODE_LIST))) { 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); out->transport_protocol = transport_protocol(&out->transport_protocol_str); bencode_get_alt(input, "media-address", "media address", &out->media_address); if (bencode_get_alt(input, "address-family", "address family", &out->address_family_str)) out->address_family = address_family(&out->address_family_str); out->tos = bencode_dictionary_get_integer(input, "TOS", 256); }