[sr-dev] Why was IP type parsing removed from sdp in parser?

Jason Penton jason.penton at gmail.com
Tue Oct 25 14:09:18 CEST 2011


Hi All,

Just curious as to why the parsing of IP type was removed from
extract_mediaip in parser/sdp/sdp_helper_funcs.c. The latest code looks like
below (could I suggest adding the highlighted part?):

p.s. If there are no objections/responses I will commit to master branch.

Cheers
Jason

int extract_mediaip(str *body, str *mediaip, int *pf, char *line)
{
        char *cp, *cp1;
        int len;

        cp1 = NULL;
        for (cp = body->s; (len = body->s + body->len - cp) > 0;) {
                cp1 = (char*)ser_memmem(cp, line, len, 2);
                if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
                        break;
                cp = cp1 + 2;
        }
        if (cp1 == NULL)
                return -1;

        mediaip->s = cp1 + 2;
        mediaip->len = eat_line(mediaip->s, body->s + body->len -
mediaip->s) - mediaip->s;
        trim_len(mediaip->len, mediaip->s, *mediaip);
        if (mediaip->len == 0) {
                LM_ERR("no [%s] line in SDP\n",line);
                return -1;
        }

        /* search reverse for IP[4|6] in c=/o= line */
        cp = (char*)ser_memrmem(mediaip->s, " IP", mediaip->len, 3);
        if (cp == NULL) {
                LM_ERR("no `IP[4|6]' in `%s' field\n",line);
                return -1;
        }

        switch (cp[3]) {
           case '4':
              *pf = AF_INET;
              break;

           case '6':
              *pf = AF_INET6;
              break;
        }

        /* safety checks:
         * - for lenght, at least 6: ' IP[4|6] x...'
         * - white space after
         */
        if(cp + 6 > mediaip->s + mediaip->len && cp[4]!=' ') {
                LM_ERR("invalid content for `%s' line\n",line);
                return -1;
        }
        if(cp[3]!='4' && cp[3]!='6') {
                LM_ERR("invalid addrtype IPx for `%s' line\n",line);
                return -1;
        }
        cp += 5;

        /* next token is the IP address */
        cp = eat_space_end(cp, mediaip->s + mediaip->len);
        len = eat_token_end(cp, mediaip->s + mediaip->len) - cp;
        mediaip->s = cp;
        mediaip->len = len;

        if (mediaip->len == 0) {
                LM_ERR("no `IP[4|6]' address in `%s' field\n",line);
                return -1;
        }

        LM_DBG("located IP address [%.*s] in `%s' field\n",
                        mediaip->len, mediaip->s, line);
        return 1;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20111025/598c791a/attachment.htm>


More information about the sr-dev mailing list