Module: sip-router Branch: master Commit: d28c4043637169c4e90f638102c1f4dfa06716f2 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d28c4043...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Mon Apr 28 12:15:54 2014 +0300
modules/sdpops: added sdp_with_ice() function for checking if sdp contains ICE candidate attribute(s)
---
modules/sdpops/README | 30 ++++++++++++++++++++++++------ modules/sdpops/doc/sdpops_admin.xml | 21 +++++++++++++++++++++ modules/sdpops/sdpops_mod.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 6 deletions(-)
diff --git a/modules/sdpops/README b/modules/sdpops/README index 9ea8e98..ebad4bd 100644 --- a/modules/sdpops/README +++ b/modules/sdpops/README @@ -42,7 +42,8 @@ Daniel-Constantin Mierla 4.14. sdp_print(level) 4.15. sdp_get(avpvar) 4.16. sdp_content() - 4.17. sdp_get_line_startswith(avpvar, string) + 4.17. sdp_with_ice() + 4.18. sdp_get_line_startswith(avpvar, string)
List of Examples
@@ -62,7 +63,8 @@ Daniel-Constantin Mierla 1.14. sdp_print usage 1.15. sdp_get usage 1.16. sdp_content usage - 1.17. sdp_get_line_startswith usage + 1.17. sdp_with_ice usage + 1.18. sdp_get_line_startswith usage
Chapter 1. Admin Guide
@@ -93,7 +95,8 @@ Chapter 1. Admin Guide 4.14. sdp_print(level) 4.15. sdp_get(avpvar) 4.16. sdp_content() - 4.17. sdp_get_line_startswith(avpvar, string) + 4.17. sdp_with_ice() + 4.18. sdp_get_line_startswith(avpvar, string)
1. Overview
@@ -143,7 +146,8 @@ Chapter 1. Admin Guide 4.14. sdp_print(level) 4.15. sdp_get(avpvar) 4.16. sdp_content() - 4.17. sdp_get_line_startswith(avpvar, string) + 4.17. sdp_with_ice() + 4.18. sdp_get_line_startswith(avpvar, string)
4.1. sdp_remove_codecs_by_id(list)
@@ -401,7 +405,21 @@ if(sdp_content()) { } ...
-4.17. sdp_get_line_startswith(avpvar, string) +4.17. sdp_with_ice() + + Return true if the SIP message has SDP body that contains ICE candidate + attribute(s). + + This function can be used from ANY_ROUTE. + + Example 1.17. sdp_with_ice usage +... +if(sdp_with_ice()) { + ... +} +... + +4.18. sdp_get_line_startswith(avpvar, string)
Store the search part of SDP body message with line beginning with 'string' in an AVP. Return 1 if 'string' is found in SDP, -1 on error @@ -409,7 +427,7 @@ if(sdp_content()) {
This function can be used from ANY_ROUTE.
- Example 1.17. sdp_get_line_startswith usage + Example 1.18. sdp_get_line_startswith usage ... if(sdp_get_line_startswith("$avp(mline)", "m=")) { xlog("m-line: $avp(mline)\n"); diff --git a/modules/sdpops/doc/sdpops_admin.xml b/modules/sdpops/doc/sdpops_admin.xml index a688bfa..7373b0b 100644 --- a/modules/sdpops/doc/sdpops_admin.xml +++ b/modules/sdpops/doc/sdpops_admin.xml @@ -460,6 +460,27 @@ if(sdp_content()) { </example> </section> <section> + <title> + <function moreinfo="none">sdp_with_ice()</function> + </title> + <para> + Return true if the SIP message has SDP body that contains ICE candidate attribute(s). + </para> + <para> + This function can be used from ANY_ROUTE. + </para> + <example> + <title><function>sdp_with_ice</function> usage</title> + <programlisting format="linespecific"> +... +if(sdp_with_ice()) { + ... +} +... +</programlisting> + </example> + </section> + <section> <title> <function moreinfo="none">sdp_get_line_startswith(avpvar, string)</function> </title> diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c index 3712311..a8c472f 100644 --- a/modules/sdpops/sdpops_mod.c +++ b/modules/sdpops/sdpops_mod.c @@ -58,6 +58,7 @@ static int w_sdp_remove_transport(sip_msg_t* msg, char* transport, char *bar); static int w_sdp_print(sip_msg_t* msg, char* level, char *bar); static int w_sdp_get(sip_msg_t* msg, char *bar); static int w_sdp_content(sip_msg_t* msg, char* foo, char *bar); +static int w_sdp_with_ice(sip_msg_t* msg, char* foo, char *bar); static int w_sdp_get_line_startswith(sip_msg_t* msg, char *foo, char *bar);
@@ -100,6 +101,8 @@ static cmd_export_t cmds[] = { 1, 0, 0, ANY_ROUTE}, {"sdp_content", (cmd_function)w_sdp_content, 0, 0, 0, ANY_ROUTE}, + {"sdp_with_ice", (cmd_function)w_sdp_with_ice, + 0, 0, 0, ANY_ROUTE}, {"sdp_get_line_startswith", (cmd_function)w_sdp_get_line_startswith, 2, 0, 0, ANY_ROUTE}, {"bind_sdpops", (cmd_function)bind_sdpops, @@ -1424,6 +1427,37 @@ static int w_sdp_content(sip_msg_t* msg, char* foo, char *bar) /** * */ +static int w_sdp_with_ice(sip_msg_t* msg, char* foo, char *bar) +{ + str ice, body; + + ice.s = "a=candidate"; + ice.len = 11; + + body.s = get_body(msg); + if (body.s == NULL) { + LM_DBG("failed to get the message body\n"); + return -1; + } + + body.len = msg->len -(int)(body.s - msg->buf); + if (body.len == 0) { + LM_DBG("message body has length zero\n"); + return -1; + } + + if (ser_memmem(body.s, ice.s, body.len, ice.len) != NULL) { + LM_INFO("found ice attribute\n"); + return 1; + } else { + LM_INFO("did't find ice attribute\n"); + return -1; + } +} + +/** + * + */ static int w_sdp_get_line_startswith(sip_msg_t *msg, char *avp, char *s_line) { sdp_info_t *sdp = NULL;