From 3690bce25ee7ca01bb9d36ec253e727c2c10bc9f Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Tue, 15 Nov 2016 12:47:24 +0200 Subject: [PATCH 1/6] test/unit: update unit test 60 - make sipsak use localhost to avoid name lookup error - kill Kamailio by using pid file - do not pass -L to sipsak in order to have proper (CR LF) line ending --- test/unit/60.sh | 17 +++++++++-------- test/unit/include/common | 2 ++ test/unit/include/require.sh | 4 ++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/unit/60.sh b/test/unit/60.sh index c4871362d03..e3f0b0254ba 100755 --- a/test/unit/60.sh +++ b/test/unit/60.sh @@ -20,26 +20,27 @@ . include/common . include/require.sh -CFG=60.cfg +CFGFILE=60.cfg TMPFILE=$(mktemp -t kamailio-test.XXXXXXXXXX) +SIPSAKOPTS="-H localhost -s sip:127.0.0.1 -v" if ! (check_sipsak && check_kamailio && check_module "sdpops"); then exit 0 fi -${BIN} -w . -f ${CFG} > /dev/null +${BIN} -w ${RUN_DIR} -Y ${RUN_DIR} -P ${PIDFILE} -f ${CFGFILE} > /dev/null ret=$? sleep 1 if [ "${ret}" -ne 0 ] ; then echo "start fail" - ${KILL} + kill_kamailio exit ${ret} fi # Borken SDP should give 500 response FILE="60-message-sdp0.sip" -sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE} +sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE} ret=$? if [ "${ret}" -eq 1 ] ; then ret=0 @@ -55,7 +56,7 @@ for i in 1 2 3 4 5 6 7; do TOTALBEFORE=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=X-cap/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${FILE}) OTHERBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f1) - sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE} + sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE} ret=$? if [ "${ret}" -eq 0 ] ; then TOTALAFTER=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=X-cap/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${TMPFILE}) @@ -74,7 +75,7 @@ done # Empty body should get 500 response FILE="60-message-sdp8.sip" -sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE} +sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE} ret=$? if [ "${ret}" -eq 1 ] ; then ret=0 @@ -84,7 +85,7 @@ else exit ${ret} fi -${KILL} - +kill_kamailio +rm ${TMPFILE} exit ${ret} diff --git a/test/unit/include/common b/test/unit/include/common index 245984368fd..ba8aa71632f 100644 --- a/test/unit/include/common +++ b/test/unit/include/common @@ -1,6 +1,7 @@ # all database modules DB_ALL_MOD="acc|alias_db|auth_db|avpops|dialog|dialplan|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist" # root directory relative to tests +RUN_DIR="." SRC_DIR="../.." CTL_DIR="$SRC_DIR/utils/kamctl" CTLRC="$CTL_DIR/kamctlrc" @@ -19,5 +20,6 @@ else fi fi KILL="killall -15 $BNAME" +PIDFILE="${RUN_DIR}/kamailio.pid" # test directory relative to root TEST_DIR="test/unit" diff --git a/test/unit/include/require.sh b/test/unit/include/require.sh index 85cfc8435bf..c7642bbbbb0 100644 --- a/test/unit/include/require.sh +++ b/test/unit/include/require.sh @@ -63,3 +63,7 @@ check_sipsak() { fi; return 0 } + +kill_kamailio() { + kill $(cat ${PIDFILE}) +} From 60703e86eff4849501938b2dcbb85382a9febb9d Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Wed, 16 Nov 2016 13:48:26 +0200 Subject: [PATCH 2/6] modules/sdpops: add optional media parameter to sdp_remove_line_by_prefix() - allows removing lines only within media description --- modules/sdpops/api.h | 2 +- modules/sdpops/doc/sdpops_admin.xml | 2 +- modules/sdpops/sdpops_mod.c | 146 +++++++++++++++++++++------- 3 files changed, 113 insertions(+), 37 deletions(-) diff --git a/modules/sdpops/api.h b/modules/sdpops/api.h index eba0c654891..39e6eab552f 100644 --- a/modules/sdpops/api.h +++ b/modules/sdpops/api.h @@ -41,7 +41,7 @@ typedef struct sdpops_binds { sdp_keep_media_t sdp_keep_codecs_by_name; sdp_remove_media_t sdp_remove_media; sdp_remove_media_t sdp_remove_transport; - sdp_remove_media_t sdp_remove_line_by_prefix; + sdp_remove_media_type_t sdp_remove_line_by_prefix; sdp_remove_media_type_t sdp_remove_codecs_by_id; sdp_remove_media_type_t sdp_remove_codecs_by_name; } sdpops_api_t; diff --git a/modules/sdpops/doc/sdpops_admin.xml b/modules/sdpops/doc/sdpops_admin.xml index 3c27b125c3b..2c14c9bacd2 100644 --- a/modules/sdpops/doc/sdpops_admin.xml +++ b/modules/sdpops/doc/sdpops_admin.xml @@ -126,7 +126,7 @@ sdp_remove_codecs_by_name("PCMU,PCMA,GSM");
- <function moreinfo="none">sdp_remove_line_by_prefix(string)</function> + <function moreinfo="none">sdp_remove_line_by_prefix(string [, mtype])</function> Remove all SDP attribute lines beginning with 'string' diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c index 5813e291407..7d26868f2f5 100644 --- a/modules/sdpops/sdpops_mod.c +++ b/modules/sdpops/sdpops_mod.c @@ -42,7 +42,7 @@ MODULE_VERSION -static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* bar); +static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* media); static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char *media); static int w_sdp_remove_codecs_by_name(sip_msg_t* msg, char* codecs, char *media); static int w_sdp_keep_codecs_by_id(sip_msg_t* msg, char* codecs, char *media); @@ -73,6 +73,8 @@ static int mod_init(void); static cmd_export_t cmds[] = { {"sdp_remove_line_by_prefix", (cmd_function)w_sdp_remove_line_by_prefix, 1, fixup_spve_null, 0, ANY_ROUTE}, + {"sdp_remove_line_by_prefix", (cmd_function)w_sdp_remove_line_by_prefix, + 2, fixup_spve_spve, 0, ANY_ROUTE}, {"sdp_remove_codecs_by_id", (cmd_function)w_sdp_remove_codecs_by_id, 1, fixup_spve_null, 0, ANY_ROUTE}, {"sdp_remove_codecs_by_id", (cmd_function)w_sdp_remove_codecs_by_id, @@ -390,31 +392,7 @@ int sdp_remove_codecs_by_id(sip_msg_t* msg, str* codecs, str* media) return 0; } -/** - * @brief remove all SDP lines that begin with prefix - * @return -1 - error; 0 - no lines found ; 1..N - N lines deleted - */ -int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) -{ - str body = {NULL, 0}; - - if(parse_sdp(msg) != 0) { - LM_ERR("Unable to parse SDP\n"); - return -1; - } - - body.s = ((sdp_info_t*)msg->body)->raw_sdp.s; - body.len = ((sdp_info_t*)msg->body)->raw_sdp.len; - - if (body.s==NULL) { - LM_ERR("failed to get the message body\n"); - return -1; - } - - if (body.len==0) { - LM_DBG("message body has zero length\n"); - return -1; - } +int sdp_remove_line_lump_by_prefix(sip_msg_t* msg, str* body, str* prefix) { char *ptr = NULL; str line = {NULL, 0}; @@ -422,7 +400,7 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) int found = 0; struct lump *anchor = NULL; - ptr = find_sdp_line(body.s, body.s + body.len, prefix->s[0]); + ptr = find_sdp_line(body->s, body->s + body->len, prefix->s[0]); while (ptr) { if (sdp_locate_line(msg, ptr, &line) != 0) @@ -431,9 +409,9 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) return -1; } - if (body.s + body.len < line.s + prefix->len) // check if strncmp would run too far + if (body->s + body->len < line.s + prefix->len) // check if strncmp would run too far { - //LM_DBG("done searching, prefix string >%.*s< (%d) does not fit into remaining buffer space (%ld) \n", prefix->len, prefix->s, prefix->len, body.s + body.len - line.s); + //LM_DBG("done searching, prefix string >%.*s< (%d) does not fit into remaining buffer space (%ld) \n", prefix->len, prefix->s, prefix->len, body->s + body->len - line.s); break; } @@ -465,7 +443,7 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) //LM_DBG("updated remove >%.*s< (%d)\n", remove.len, remove.s, remove.len); } - ptr = find_next_sdp_line(ptr, body.s + body.len, prefix->s[0], NULL); + ptr = find_next_sdp_line(ptr, body->s + body->len, prefix->s[0], NULL); } if (found) { @@ -483,13 +461,102 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) return 0; } +/** + * @brief remove all SDP lines that begin with prefix + * @return -1 - error; 0 - no lines found ; 1..N - N lines deleted + */ +int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix, str* media) +{ + str body = {NULL, 0}; + int sdp_session_num = 0; + int sdp_stream_num = 0; + int found = 0; + + if(parse_sdp(msg) != 0) { + LM_ERR("Unable to parse SDP\n"); + return -1; + } + + body.s = ((sdp_info_t*)msg->body)->raw_sdp.s; + body.len = ((sdp_info_t*)msg->body)->raw_sdp.len; + + if (body.s==NULL) { + LM_ERR("failed to get the message body\n"); + return -1; + } + + if (body.len==0) { + LM_DBG("message body has zero length\n"); + return -1; + } + + if (media->s==NULL || media->len==0 ) { + LM_DBG("media type filter not set\n"); + found = sdp_remove_line_lump_by_prefix(msg, &body, prefix); + } else { + LM_DBG("using media type filter: %.*s\n",media->len, media->s); + + sdp_session_cell_t* sdp_session; + sdp_stream_cell_t* sdp_stream; + + sdp_session_num = 0; + for (;;) { + sdp_session = get_sdp_session(msg, sdp_session_num); + if(!sdp_session) break; + sdp_stream_num = 0; + for (;;) { + sdp_stream = get_sdp_stream(msg, sdp_session_num, sdp_stream_num); + if(!sdp_stream) break; + if( sdp_stream->media.len == media->len && + strncasecmp(sdp_stream->media.s, media->s, media->len) == 0) { + + LM_DBG("range for media type %.*s: %ld - %ld\n", + sdp_stream->media.len, sdp_stream->media.s, + sdp_stream->raw_stream.s - body.s, + sdp_stream->raw_stream.s + sdp_stream->raw_stream.len - body.s + ); + + found += sdp_remove_line_lump_by_prefix(msg,&(sdp_stream->raw_stream),prefix); + + } + sdp_stream_num++; + } + sdp_session_num++; + } + } + return found; +} + + +/* + +int sdp_remove_str_codec_id_attrs(sip_msg_t* msg, sdp_stream_cell_t* sdp_stream, str *rm_codec) + + str aline = {0, 0}; + sdp_payload_attr_t *payload; + struct lump *anchor; + + payload = sdp_stream->payload_attr; + while (payload) { + LM_DBG("a= ... for codec %.*s/%.*s\n", + payload->rtp_payload.len, payload->rtp_payload.s, + payload->rtp_enc.len, payload->rtp_enc.s); + if(rm_codec->len==payload->rtp_payload.len + && strncmp(payload->rtp_payload.s, rm_codec->s, + rm_codec->len)==0) { + if(payload->rtp_enc.s!=NULL) { + if(sdp_locate_line(msg, payload->rtp_enc.s, &aline)==0) +*/ + + /** * removes all SDP lines that begin with script provided prefix * @return -1 - error; 1 - found */ -static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* bar) +static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* media) { - str prfx = {NULL, 0}; + str lprefix = {NULL, 0}; + str lmedia = {NULL, 0}; if(prefix==0) { @@ -497,14 +564,23 @@ static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* bar) return -1; } - if (get_str_fparam(&prfx, msg, (fparam_t*)prefix)) + if (get_str_fparam(&lprefix, msg, (fparam_t*)prefix)) { LM_ERR("unable to determine prefix\n"); return -1; } - LM_DBG("Removing SDP lines with prefix: %.*s\n", prfx.len, prfx.s); - if ( sdp_remove_line_by_prefix(msg, &prfx) < 0) + if (media != NULL) { + if (get_str_fparam(&lmedia, msg, (fparam_t*)media)) + { + LM_ERR("unable to get the media type\n"); + return -1; + } + } + + LM_DBG("Removing SDP lines with prefix: %.*s\n", lprefix.len, lprefix.s); + + if ( sdp_remove_line_by_prefix(msg, &lprefix, &lmedia) < 0) return -1; return 1; } From 8d4c2e419068b034ced89828878c6635d69c8d6f Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Wed, 16 Nov 2016 14:05:13 +0200 Subject: [PATCH 3/6] test/unit: update unit test 60 - Kamailio sdpops manipulates SDP in MESSAGE request - count certain SDP lines before and after sdp_remove_line_by_prefix() - only m=video is to be manipulated - verify by counting prefix line count vs. other lines --- test/unit/60-message-sdp9.sip | 31 +++++++++++++++++++++++++++++++ test/unit/60.cfg | 7 +++++++ test/unit/60.sh | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 test/unit/60-message-sdp9.sip diff --git a/test/unit/60-message-sdp9.sip b/test/unit/60-message-sdp9.sip new file mode 100644 index 00000000000..1e0019a9b0e --- /dev/null +++ b/test/unit/60-message-sdp9.sip @@ -0,0 +1,31 @@ +MESSAGE sip:bob@example.invalid SIP/2.0 +From: sip:alice@example.invalid;tag=45dfdf49 +To: sip:bob@example.invalid +Call-ID: 1172299593a +CSeq: 1 MESSAGE +Content-Type: application/sdp +Max-Forwards: 2 +X-Case: 60-test9 +X-Info: sdpops remove_line_by_prefix test9 - filter video attribute + +v=0 +o=FreeSWITCH 1447318678 1447318679 IN IP4 10.0.0.145 +s=FreeSWITCH +c=IN IP4 10.0.0.145 +t=0 0 +m=audio 28504 RTP/AVP 96 101 +a=rtpmap:96 opus/48000/2 +a=fmtp:96 useinbandfec=1; maxaveragebitrate=14400; maxplaybackrate=8000 +a=rtpmap:101 telephone-event/48000 +a=fmtp:101 0-16 +a=ptime:20 +a=sendrecv +a=rtcp:28505 IN IP4 10.0.0.145 +a=rtcp-fb:101 nack +m=video 21992 RTP/SAVPF 100 +a=rtpmap:100 VP8/90000 +a=rtcp:21992 IN IP4 10.0.0.150 +a=rtcp-fb:100 ccm fir +a=rtcp-fb:100 nack +a=rtcp-fb:100 nack pli + diff --git a/test/unit/60.cfg b/test/unit/60.cfg index 62c0a5b3e46..cd7aa1cb788 100644 --- a/test/unit/60.cfg +++ b/test/unit/60.cfg @@ -26,6 +26,13 @@ route { sl_send_reply(200,"OK"); exit; } + if ($hdr(X-Case) == '60-test9') { + sdp_remove_line_by_prefix("a=rtcp","video"); + msg_apply_changes(); + set_reply_body($rb,"application/sdp"); + sl_send_reply(200,"OK"); + exit; + } sl_send_reply(500,"Unknown test case"); exit; diff --git a/test/unit/60.sh b/test/unit/60.sh index e3f0b0254ba..54d514c2eeb 100755 --- a/test/unit/60.sh +++ b/test/unit/60.sh @@ -85,6 +85,27 @@ else exit ${ret} fi +# Filter only video stream attributes +FILE="60-message-sdp9.sip" +TOTALBEFORE=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=rtcp/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${FILE}) +OTHERBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f1) +PREFIXBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f2) +sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE} +ret=$? +if [ "${ret}" -eq 0 ] ; then + TOTALAFTER=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=rtcp:/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${TMPFILE}) + OTHERAFTER=$(echo ${TOTALBEFORE}|cut -d+ -f1) + PREFIXAFTER=$(echo ${TOTALAFTER}|cut -d+ -f2) + if [ ${PREFIXAFTER} -eq 1 ] && [ ${OTHERBEFORE} -eq ${OTHERAFTER} ]; then + ret=0 + else + ret=1 + echo "found ${PREFIXAFTER} lines with prefix \"a=rtcp\", was expecting 1 (in m=audio)(${FILE})" + fi + else + echo "invalid sipsak return: ${ret}" +fi + kill_kamailio rm ${TMPFILE} exit ${ret} From 18c7eaf11c69eccea195020d4b82f96ddae5dafb Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 17 Nov 2016 00:21:15 +0000 Subject: [PATCH 4/6] modules/app_lua: sdpops API changed --- modules/app_lua/app_lua_exp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c index df8864880d2..81fcd4f1a79 100644 --- a/modules/app_lua/app_lua_exp.c +++ b/modules/app_lua/app_lua_exp.c @@ -2157,7 +2157,7 @@ static int lua_sr_sdpops_remove_transport(lua_State *L) static int lua_sr_sdpops_remove_line_by_prefix(lua_State *L) { int ret; - str media; + str param[2]; sr_lua_env_t *env_L; env_L = sr_lua_env_get(); @@ -2180,10 +2180,12 @@ static int lua_sr_sdpops_remove_line_by_prefix(lua_State *L) return app_lua_return_error(L); } - media.s = (char*)lua_tostring(L, -1); - media.len = strlen(media.s); + param[0].s = (char *) lua_tostring(L, -2); + param[0].len = strlen(param[0].s); + param[1].s = (char *) lua_tostring(L, -1); + param[1].len = strlen(param[1].s); - ret = _lua_sdpopsb.sdp_remove_line_by_prefix(env_L->msg, &media); + ret = _lua_sdpopsb.sdp_remove_line_by_prefix(env_L->msg, ¶m[0], ¶m[1]); return app_lua_return_int(L, ret); } From 0ede53d0872cbd426dcb3542dbca5ca7c00139e2 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Mon, 28 Nov 2016 10:26:08 +0200 Subject: [PATCH 5/6] modules/app_lua: support 1 or 2 parameters with sr.sdpops.sdp_remove_line_by_prefix() --- modules/app_lua/app_lua_exp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c index 81fcd4f1a79..f1b57034ec9 100644 --- a/modules/app_lua/app_lua_exp.c +++ b/modules/app_lua/app_lua_exp.c @@ -2157,7 +2157,8 @@ static int lua_sr_sdpops_remove_transport(lua_State *L) static int lua_sr_sdpops_remove_line_by_prefix(lua_State *L) { int ret; - str param[2]; + str prefix = STR_NULL; + str media = STR_NULL; sr_lua_env_t *env_L; env_L = sr_lua_env_get(); @@ -2174,18 +2175,22 @@ static int lua_sr_sdpops_remove_line_by_prefix(lua_State *L) return app_lua_return_error(L); } - if(lua_gettop(L)!=1) + if(lua_gettop(L)==1) { + prefix.s = (char *) lua_tostring(L, -1); + prefix.len = strlen(prefix.s); + } else if(lua_gettop(L)==2) + { + prefix.s = (char *) lua_tostring(L, -2); + prefix.len = strlen(prefix.s); + media.s = (char *) lua_tostring(L, -1); + media.len = strlen(media.s); + } else { LM_ERR("incorrect number of arguments\n"); return app_lua_return_error(L); } - param[0].s = (char *) lua_tostring(L, -2); - param[0].len = strlen(param[0].s); - param[1].s = (char *) lua_tostring(L, -1); - param[1].len = strlen(param[1].s); - - ret = _lua_sdpopsb.sdp_remove_line_by_prefix(env_L->msg, ¶m[0], ¶m[1]); + ret = _lua_sdpopsb.sdp_remove_line_by_prefix(env_L->msg, &prefix, &media); return app_lua_return_int(L, ret); } From 892ab2737cf931c6bd232439715e80874a7f1d97 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Mon, 28 Nov 2016 10:39:36 +0200 Subject: [PATCH 6/6] test/unit: create unit test 61 - tests Lua exported sdp_remove_line_by_prefix() --- test/unit/61-message-sdp.sip | 29 ++++++++ test/unit/61.cfg | 52 +++++++++++++++ test/unit/61.sh | 124 +++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 test/unit/61-message-sdp.sip create mode 100644 test/unit/61.cfg create mode 100755 test/unit/61.sh diff --git a/test/unit/61-message-sdp.sip b/test/unit/61-message-sdp.sip new file mode 100644 index 00000000000..c6c682b9a79 --- /dev/null +++ b/test/unit/61-message-sdp.sip @@ -0,0 +1,29 @@ +MESSAGE sip:bob@example.invalid SIP/2.0 +From: sip:alice@example.invalid;tag=45dfdf49 +To: sip:bob@example.invalid +Call-ID: 1172299593a +CSeq: 1 MESSAGE +Content-Type: application/sdp +Max-Forwards: 2 +X-Info: test lua sr.sdpops.sdp_remove_line_by_prefix + +v=0 +o=FreeSWITCH 1447318678 1447318679 IN IP4 10.0.0.145 +s=FreeSWITCH +c=IN IP4 10.0.0.145 +t=0 0 +m=audio 28504 RTP/AVP 96 101 +a=rtpmap:96 opus/48000/2 +a=fmtp:96 useinbandfec=1; maxaveragebitrate=14400; maxplaybackrate=8000 +a=rtpmap:101 telephone-event/48000 +a=fmtp:101 0-16 +a=ptime:20 +a=sendrecv +a=rtcp:28505 IN IP4 10.0.0.145 +a=rtcp-fb:101 nack +m=video 21992 RTP/SAVPF 100 +a=rtpmap:100 VP8/90000 +a=rtcp:21992 IN IP4 10.0.0.150 +a=rtcp-fb:100 ccm fir +a=rtcp-fb:100 nack +a=rtcp-fb:100 nack pli diff --git a/test/unit/61.cfg b/test/unit/61.cfg new file mode 100644 index 00000000000..6a7da0a91c6 --- /dev/null +++ b/test/unit/61.cfg @@ -0,0 +1,52 @@ +# ----------- global configuration parameters ------------------------ +debug=2 +fork=yes +log_stderror=no +children=1 +disable_tcp=yes +listen=udp:127.0.0.1:5060 +auto_aliases=no +alias=example.invalid +# ------------------ module loading ---------------------------------- +loadpath "../../modules/" + +loadmodule "sl.so" +loadmodule "pv.so" +loadmodule "textops.so" +loadmodule "textopsx.so" +loadmodule "sdpops.so" +loadmodule "app_lua.so" +modparam("sl", "bind_tm", 0) +modparam("app_lua", "register", "sdpops") + +request_route { + if ( is_present_hf("X-Case") ) { + if ( $hdr(X-Case) == '61-test0') { + if( !lua_dostring("sr.sdpops.sdp_remove_line_by_prefix([[a=rtcp]])") ) { + sl_send_reply(500,"Lua call failed retcode=$retcode ($hdr(X-Case))"); + exit; + } + } else if ( $hdr(X-Case) == '61-test1') { + if( !lua_dostring("sr.sdpops.sdp_remove_line_by_prefix([[a=rtcp]], [[audio]])") ) { + sl_send_reply(500,"Lua call failed retcode=$retcode ($hdr(X-Case))"); + exit; + } + } else if ( $hdr(X-Case) == '61-test2') { + if( !lua_dostring("sr.sdpops.sdp_remove_line_by_prefix([[a=rtcp]], [[video]])") ) { + sl_send_reply(500,"Lua call failed retcode=$retcode ($hdr(X-Case))"); + exit; + } + } else { + sl_send_reply(500,"Unknown test case"); + exit; + } + + msg_apply_changes(); + set_reply_body($rb,"application/sdp"); + sl_send_reply(200,"OK"); + exit; + } + sl_send_reply(500,"X-Case missing"); + exit; +} + diff --git a/test/unit/61.sh b/test/unit/61.sh new file mode 100755 index 00000000000..16288d190af --- /dev/null +++ b/test/unit/61.sh @@ -0,0 +1,124 @@ +#!/bin/sh +# checks sdpops module function sdp_remove_line_by_prefix() via Lua +# +# Copyright (C) 2016 mslehto@iki.fi +# +# This file is part of Kamailio, a free SIP server. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +. include/common +. include/require.sh + +CFGFILE=61.cfg +TMPFILE=$(mktemp -t kamailio-test.XXXXXXXXXX) +SIPSAKOPTS="-H localhost -s sip:127.0.0.1:5060 -v" + +end_test() { + kill_kamailio + rm ${TMPFILE} + exit ${ret} +} + +if ! (check_sipsak && check_kamailio && check_module "sdpops" && check_module "app_lua"); then + exit 0 +fi + +${BIN} -w ${RUN_DIR} -Y ${RUN_DIR} -P ${PIDFILE} -f ${CFGFILE} > /dev/null +ret=$? + +sleep 1 +if [ "${ret}" -ne 0 ] ; then + end_test +fi + +# manipulate whole SDP +FILE="61-message-sdp.sip" +TESTCASE="61-test0" +TOTALBEFORE=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=rtcp/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${FILE}) +OTHERBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f1) +PREFIXBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f2) +sipsak ${SIPSAKOPTS} -f ${FILE} --headers "X-Case: ${TESTCASE}\n" > ${TMPFILE} +ret=$? +if [ "${ret}" -ne 0 ] ; then + echo "sipsak returned ${ret}, aborting" + cat ${TMPFILE} +else + TOTALAFTER=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=rtcp:/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${TMPFILE}) + OTHERAFTER=$(echo ${TOTALAFTER}|cut -d+ -f1) + PREFIXAFTER=$(echo ${TOTALAFTER}|cut -d+ -f2) + if [ ${PREFIXAFTER} -eq 0 ]; then + ret=0 + else + ret=1 + echo "test ${TESTCASE} failed" + echo "found ${PREFIXAFTER} lines with prefix \"a=rtcp\", was expecting 0" + echo "found ${OTHERAFTER} other lines (was ${OTHERBEFORE} before)" + end_test + fi +fi + +# manipulate m=audio only +FILE="61-message-sdp.sip" +TESTCASE="61-test1" +TOTALBEFORE=$(awk '/^m=audio/,/^m=video/ {total++; if ($0 ~ /^a=rtcp/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${FILE}) +OTHERBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f1) +PREFIXBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f2) +sipsak ${SIPSAKOPTS} -f ${FILE} --headers "X-Case: ${TESTCASE}\n" > ${TMPFILE} +ret=$? +if [ "${ret}" -ne 0 ] ; then + echo "sipsak returned ${ret}, aborting" + cat ${TMPFILE} +else + TOTALAFTER=$(awk '/^m=audio/,/^m=video/ {total++; if ($0 ~ /^a=rtcp:/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${TMPFILE}) + OTHERAFTER=$(echo ${TOTALAFTER}|cut -d+ -f1) + PREFIXAFTER=$(echo ${TOTALAFTER}|cut -d+ -f2) + if [ ${PREFIXAFTER} -eq 0 ]; then + ret=0 + else + ret=1 + echo "test ${TESTCASE} failed" + echo "found ${PREFIXAFTER} lines with prefix \"a=rtcp\", was expecting 0" + echo "found ${OTHERAFTER} other lines (was ${OTHERBEFORE} before)" + end_test + fi +fi + +# manipulate m=video only +FILE="61-message-sdp.sip" +TESTCASE="61-test2" +TOTALBEFORE=$(awk '/^m=video/,/^$/ {total++; if ($0 ~ /^a=rtcp/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${FILE}) +OTHERBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f1) +PREFIXBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f2) +sipsak ${SIPSAKOPTS} -f ${FILE} --headers "X-Case: ${TESTCASE}\n" > ${TMPFILE} +ret=$? +if [ "${ret}" -ne 0 ] ; then + echo "sipsak returned ${ret}, aborting" + cat ${TMPFILE} +else + TOTALAFTER=$(awk '/^m=video/,/^$/ {total++; if ($0 ~ /^a=rtcp:/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${TMPFILE}) + OTHERAFTER=$(echo ${TOTALAFTER}|cut -d+ -f1) + PREFIXAFTER=$(echo ${TOTALAFTER}|cut -d+ -f2) + if [ ${PREFIXAFTER} -eq 0 ]; then + ret=0 + else + ret=1 + echo "test ${TESTCASE} failed" + echo "found ${PREFIXAFTER} lines with prefix \"a=rtcp\", was expecting 0" + echo "found ${OTHERAFTER} other lines (was ${OTHERBEFORE} before)" + end_test + fi +fi + +end_test +