[sr-dev] git:master: sdpops: added functions to print sdp and check media type
Carsten Bock
lists at bock.info
Mon Mar 14 09:15:27 CET 2011
Hi Daniel,
nice, new module!
But here is something from my wishlist:
Apart from removing codecs, it would be great to have a function to
remove all codecs but some wanted ones, e.g.:
sdp_limit_codecs("0,8,101");
which would remove all codecs except those with type 0,8 and 101 (if
offered). A function like this should return false, if the codecs are
not present. And, of course, it would be great, if one could limit the
media-types to certain ones: e.g. allow only m=audio, not m=video (or
others)....
That would be my wishlist for this module... (otherwise we/i can add
this later, if i really require this)
Carsten
2011/3/14 Daniel-Constantin Mierla <miconda at gmail.com>:
> Module: sip-router
> Branch: master
> Commit: c889ca572607e4715132b2f3911f795e2bb43bbc
> URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c889ca572607e4715132b2f3911f795e2bb43bbc
>
> Author: Daniel-Constantin Mierla <miconda at gmail.com>
> Committer: Daniel-Constantin Mierla <miconda at gmail.com>
> Date: Sun Mar 13 23:04:18 2011 +0100
>
> sdpops: added functions to print sdp and check media type
>
> - sdp_print(level) - print the parsed sdp structure to the debug 'level'
> (integer representation of log levels). Good for debug purposes
> - sdp_with_media(type) - return true if the sdp has 'media=type'
>
> ---
>
> modules/sdpops/sdpops_mod.c | 103 +++++++++++++++++++++++++++++++++++++++---
> 1 files changed, 95 insertions(+), 8 deletions(-)
>
> diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c
> index bc118ca..e49c968 100644
> --- a/modules/sdpops/sdpops_mod.c
> +++ b/modules/sdpops/sdpops_mod.c
> @@ -38,13 +38,18 @@
> MODULE_VERSION
>
> static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char *bar);
> -static int fixup_sdp_remove_codecs_by_id(void** param, int param_no);
> +static int w_sdp_with_media(sip_msg_t* msg, char* media, char *bar);
> +static int w_sdp_print(sip_msg_t* msg, char* level, char *bar);
>
> static int mod_init(void);
>
> static cmd_export_t cmds[] = {
> {"sdp_remove_codecs_by_id", (cmd_function)w_sdp_remove_codecs_by_id,
> - 1, fixup_sdp_remove_codecs_by_id, 0, ANY_ROUTE},
> + 1, fixup_spve_null, 0, ANY_ROUTE},
> + {"sdp_with_media", (cmd_function)w_sdp_with_media,
> + 1, fixup_spve_null, 0, ANY_ROUTE},
> + {"sdp_print", (cmd_function)w_sdp_print,
> + 1, fixup_igp_null, 0, ANY_ROUTE},
> {0, 0, 0, 0, 0}
> };
>
> @@ -183,8 +188,6 @@ int sdp_remove_codecs_by_id(sip_msg_t* msg, str* codecs)
>
> sdp = (sdp_info_t*)msg->body;
>
> - print_sdp(sdp, L_DBG);
> -
> sdp_session_num = 0;
> for(;;)
> {
> @@ -246,12 +249,96 @@ static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char* bar)
>
>
> /**
> - *
> + * @brief check 'media' matches the value of any 'm=value ...' lines
> + * @return -1 - error; 0 - not found; 1 - found
> */
> -static int fixup_sdp_remove_codecs_by_id(void** param, int param_no)
> +static int sdp_with_media(sip_msg_t *msg, str *media)
> {
> - if (param_no == 1) {
> - return fixup_spve_null(param, 1);
> + sdp_info_t *sdp = NULL;
> + int sdp_session_num;
> + int sdp_stream_num;
> + sdp_session_cell_t* sdp_session;
> + sdp_stream_cell_t* sdp_stream;
> +
> + if(parse_sdp(msg) < 0) {
> + LM_ERR("Unable to parse sdp\n");
> + return -1;
> + }
> +
> + LM_ERR("attempting to search for media type: [%.*s]\n",
> + media->len, media->s);
> +
> + sdp = (sdp_info_t*)msg->body;
> +
> + 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;
> +
> + LM_DBG("stream %d of %d - media [%.*s]\n",
> + sdp_stream_num, sdp_session_num,
> + sdp_stream->media.len, sdp_stream->media.s);
> + if(media->len==sdp_stream->media.len
> + && strncasecmp(sdp_stream->media.s, media->s,
> + media->len)==0)
> + return 1;
> + sdp_stream_num++;
> + }
> + sdp_session_num++;
> }
> +
> return 0;
> }
> +
> +/**
> + *
> + */
> +static int w_sdp_with_media(sip_msg_t* msg, char* media, char *bar)
> +{
> + str lmedia = {0, 0};
> +
> + if(media==0)
> + {
> + LM_ERR("invalid parameters\n");
> + return -1;
> + }
> +
> + if(fixup_get_svalue(msg, (gparam_p)media, &lmedia)!=0)
> + {
> + LM_ERR("unable to get the media value\n");
> + return -1;
> + }
> +
> + if(sdp_with_media(msg, &lmedia)<=0)
> + return -1;
> + return 1;
> +}
> +
> +
> +static int w_sdp_print(sip_msg_t* msg, char* level, char *bar)
> +{
> + sdp_info_t *sdp = NULL;
> + int llevel = L_DBG;
> +
> + if(parse_sdp(msg) < 0) {
> + LM_ERR("Unable to parse sdp\n");
> + return -1;
> + }
> +
> + if(fixup_get_ivalue(msg, (gparam_p)level, &llevel)!=0)
> + {
> + LM_ERR("unable to get the debug level value\n");
> + return -1;
> + }
> +
> + sdp = (sdp_info_t*)msg->body;
> +
> + print_sdp(sdp, llevel);
> + return 1;
> +}
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
--
Carsten Bock
http://www.ng-voice.com
mailto:carsten at ng-voice.com
More information about the sr-dev
mailing list