diff --git a/modules/rtpproxy-ng/bencode.h b/modules/rtpproxy-ng/bencode.h index 871a805a7..943d37361 100644 --- a/modules/rtpproxy-ng/bencode.h +++ b/modules/rtpproxy-ng/bencode.h @@ -234,6 +234,11 @@ static inline char *bencode_dictionary_get_string(bencode_item_t *dict, const ch * may be NULL. */ static inline char *bencode_dictionary_get_str(bencode_item_t *dict, const char *key, str *str); +/* Looks up the given key in the dictionary and compares the corresponding value to the given + * null-terminated string. Returns 2 if the key isn't found or if the value isn't a string, otherwise + * returns according to strcmp(). */ +static inline int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key, const char *str); + /* Identical to bencode_dictionary_get() but returns the string in a newly allocated buffer (using the * BENCODE_MALLOC function), which remains valid even after bencode_buffer_t is destroyed. */ static inline char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len); @@ -375,5 +380,12 @@ static inline int bencode_strcmp(bencode_item_t *a, const char *b) { return 1; return memcmp(a->iov[1].iov_base, b, len); } +static inline int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key, const char *str) { + bencode_item_t *i; + i = bencode_dictionary_get(dict, key); + if (!i) + return 2; + return bencode_strcmp(i, str); +} #endif diff --git a/modules/rtpproxy-ng/rtpproxy.c b/modules/rtpproxy-ng/rtpproxy.c index 0f9862f98..bd13ffd11 100644 --- a/modules/rtpproxy-ng/rtpproxy.c +++ b/modules/rtpproxy-ng/rtpproxy.c @@ -1093,6 +1093,12 @@ rtpp_test(struct rtpp_node *node, int isdisabled, int force) goto error; } + dict = bencode_decode_expect(&bencbuf, cp, ret, BENCODE_DICTIONARY); + if (!dict || bencode_dictionary_get_strcmp(dict, "result", "pong")) { + LM_ERR("proxy responded with invalid response\n"); + goto error; + } + LM_INFO("rtp proxy <%s> found, support for it %senabled\n", node->rn_url.s, force == 0 ? "re-" : ""); @@ -1853,6 +1859,13 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, int forc LM_ERR("failed to decode bencoded reply from proxy: %.*s\n", ret, cp); goto error; } + if (bencode_dictionary_get_strcmp(dict, "result", "ok")) { + if (!bencode_dictionary_get_str(dict, "error-reason", &newbody)) + LM_ERR("proxy didn't give an \"ok\" response and didn't give an error reason: %.*s\n", ret, cp); + else + LM_ERR("proxy replied with error: %.*s\n", newbody.len, newbody.s); + goto error; + } if (!bencode_dictionary_get_str_dup(dict, "sdp", &newbody)) { LM_ERR("failed to extract sdp body from proxy reply: %.*s\n", ret, cp);