@msg.body.sdp.line.line_name select call is implemented.
authorMiklos Tirpak <miklos@iptel.org>
Thu, 22 May 2008 17:04:17 +0000 (17:04 +0000)
committerMiklos Tirpak <miklos@iptel.org>
Thu, 22 May 2008 17:04:17 +0000 (17:04 +0000)
The select call returns the first value of line_name from the
SDP body, for example @msg.body.sdp.line.o,
or @msg.body.sdp.line["o="].

select_core.c
select_core.h

index 7774f7f..e37d70b 100644 (file)
@@ -508,6 +508,74 @@ int select_msg_body_sdp(str* res, select_t* sel, struct sip_msg* msg)
                return -1;
 }
 
+int select_sdp_line(str* res, select_t* sel, struct sip_msg* msg)
+{
+       int     len;
+       char    *buf;
+       char    *buf_end, *line_end;
+       char    line;
+
+       if (msg == NULL) {
+               if (res!=NULL) return -1;
+               if (sel->n < 5) return -1;
+
+               if (sel->params[4].type != SEL_PARAM_STR) {
+                       ERR("wrong parameter type");
+                       return -1;
+               }
+               if ((sel->params[4].v.s.len < 1) ||
+                       (sel->params[4].v.s.len > 2) ||
+                       ((sel->params[4].v.s.len == 2) && (sel->params[4].v.s.s[1] != '='))
+               ) {
+                       ERR("wrong sdp line format: %.*s\n",
+                               sel->params[4].v.s.len, sel->params[4].v.s.s);
+                       return -1;
+               }
+               return 0;
+       }
+
+       /* try to get the body part with application/sdp */
+       if (!(buf = get_body_part(msg,
+                               TYPE_APPLICATION, SUBTYPE_SDP,
+                               &len))
+       )
+               return -1;
+
+       buf_end = buf + len;
+       line = *(sel->params[4].v.s.s);
+
+       while (buf < buf_end) {
+               if (*buf == line) {
+                       /* the requested SDP line is found, return its value */
+                       buf += 2;
+                       line_end = buf;
+                       while ((line_end < buf_end) && (*line_end != '\n'))
+                               line_end++;
+
+                       if (line_end >= buf_end) {
+                               ERR("wrong SDP line format\n");
+                               return -1;
+                       }
+                       line_end--;
+                       if (*line_end == '\r') line_end--;
+
+                       if (line_end < buf) {
+                               ERR("wrong SDP line format\n");
+                               return -1;
+                       }
+
+                       res->s = buf;
+                       res->len = line_end - buf + 1;
+                       return 0;
+               }
+               while ((buf < buf_end) && (*buf != '\n'))
+                       buf++;
+               buf++;
+       }
+
+       return -1;
+}
+
 int select_msg_header(str* res, select_t* s, struct sip_msg* msg)
 {
        /* get all headers */
index 05d3028..50178d5 100644 (file)
@@ -130,6 +130,7 @@ SELECT_F(select_msg_id)
 SELECT_F(select_msg_id_hex)
 SELECT_F(select_msg_body)
 SELECT_F(select_msg_body_sdp)
+SELECT_F(select_sdp_line)
 SELECT_F(select_msg_header)
 SELECT_F(select_anyheader)
 SELECT_F(select_anyheader_params)
@@ -318,6 +319,7 @@ static select_row_t select_core[] = {
        { select_msg, SEL_PARAM_STR, STR_STATIC_INIT("body"), select_msg_body, 0},
        { select_msg, SEL_PARAM_STR, STR_STATIC_INIT("content"), select_msg_body, 0},
        { select_msg_body, SEL_PARAM_STR, STR_STATIC_INIT("sdp"), select_msg_body_sdp, 0},
+       { select_msg_body_sdp, SEL_PARAM_STR, STR_STATIC_INIT("line"), select_sdp_line, CONSUME_NEXT_STR | FIXUP_CALL},
        { select_msg, SEL_PARAM_STR, STR_STATIC_INIT("request"), select_msg_request, 0},
        { select_msg, SEL_PARAM_STR, STR_STATIC_INIT("req"), select_msg_request, 0},
        { select_msg_request, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_msg_request_method, 0},