Browse Source

@msg.body.sdp.line.line_name select call is implemented.

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="].
Miklos Tirpak 17 years ago
parent
commit
54b827f3fd
2 changed files with 70 additions and 0 deletions
  1. 68 0
      select_core.c
  2. 2 0
      select_core.h

+ 68 - 0
select_core.c

@@ -508,6 +508,74 @@ int select_msg_body_sdp(str* res, select_t* sel, struct sip_msg* msg)
 		return -1;
 		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)
 int select_msg_header(str* res, select_t* s, struct sip_msg* msg)
 {
 {
 	/* get all headers */
 	/* get all headers */

+ 2 - 0
select_core.h

@@ -130,6 +130,7 @@ SELECT_F(select_msg_id)
 SELECT_F(select_msg_id_hex)
 SELECT_F(select_msg_id_hex)
 SELECT_F(select_msg_body)
 SELECT_F(select_msg_body)
 SELECT_F(select_msg_body_sdp)
 SELECT_F(select_msg_body_sdp)
+SELECT_F(select_sdp_line)
 SELECT_F(select_msg_header)
 SELECT_F(select_msg_header)
 SELECT_F(select_anyheader)
 SELECT_F(select_anyheader)
 SELECT_F(select_anyheader_params)
 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("body"), select_msg_body, 0},
 	{ select_msg, SEL_PARAM_STR, STR_STATIC_INIT("content"), 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, 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("request"), select_msg_request, 0},
 	{ select_msg, SEL_PARAM_STR, STR_STATIC_INIT("req"), 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},
 	{ select_msg_request, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_msg_request_method, 0},