Browse code

@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 authored on 22/05/2008 17:04:17
Showing 2 changed files
... ...
@@ -508,6 +508,74 @@ int select_msg_body_sdp(str* res, select_t* sel, struct sip_msg* msg)
508 508
 		return -1;
509 509
 }
510 510
 
511
+int select_sdp_line(str* res, select_t* sel, struct sip_msg* msg)
512
+{
513
+	int	len;
514
+	char	*buf;
515
+	char	*buf_end, *line_end;
516
+	char	line;
517
+
518
+	if (msg == NULL) {
519
+		if (res!=NULL) return -1;
520
+		if (sel->n < 5) return -1;
521
+
522
+		if (sel->params[4].type != SEL_PARAM_STR) {
523
+			ERR("wrong parameter type");
524
+			return -1;
525
+		}
526
+		if ((sel->params[4].v.s.len < 1) ||
527
+			(sel->params[4].v.s.len > 2) ||
528
+			((sel->params[4].v.s.len == 2) && (sel->params[4].v.s.s[1] != '='))
529
+		) {
530
+			ERR("wrong sdp line format: %.*s\n",
531
+				sel->params[4].v.s.len, sel->params[4].v.s.s);
532
+			return -1;
533
+		}
534
+		return 0;
535
+	}
536
+
537
+	/* try to get the body part with application/sdp */
538
+	if (!(buf = get_body_part(msg,
539
+				TYPE_APPLICATION, SUBTYPE_SDP,
540
+				&len))
541
+	)
542
+		return -1;
543
+
544
+	buf_end = buf + len;
545
+	line = *(sel->params[4].v.s.s);
546
+
547
+	while (buf < buf_end) {
548
+		if (*buf == line) {
549
+			/* the requested SDP line is found, return its value */
550
+			buf += 2;
551
+			line_end = buf;
552
+			while ((line_end < buf_end) && (*line_end != '\n'))
553
+				line_end++;
554
+
555
+			if (line_end >= buf_end) {
556
+				ERR("wrong SDP line format\n");
557
+				return -1;
558
+			}
559
+			line_end--;
560
+			if (*line_end == '\r') line_end--;
561
+
562
+			if (line_end < buf) {
563
+				ERR("wrong SDP line format\n");
564
+				return -1;
565
+			}
566
+
567
+			res->s = buf;
568
+			res->len = line_end - buf + 1;
569
+			return 0;
570
+		}
571
+		while ((buf < buf_end) && (*buf != '\n'))
572
+			buf++;
573
+		buf++;
574
+	}
575
+
576
+	return -1;
577
+}
578
+
511 579
 int select_msg_header(str* res, select_t* s, struct sip_msg* msg)
512 580
 {
513 581
 	/* get all headers */
... ...
@@ -130,6 +130,7 @@ SELECT_F(select_msg_id)
130 130
 SELECT_F(select_msg_id_hex)
131 131
 SELECT_F(select_msg_body)
132 132
 SELECT_F(select_msg_body_sdp)
133
+SELECT_F(select_sdp_line)
133 134
 SELECT_F(select_msg_header)
134 135
 SELECT_F(select_anyheader)
135 136
 SELECT_F(select_anyheader_params)
... ...
@@ -318,6 +319,7 @@ static select_row_t select_core[] = {
318 318
 	{ select_msg, SEL_PARAM_STR, STR_STATIC_INIT("body"), select_msg_body, 0},
319 319
 	{ select_msg, SEL_PARAM_STR, STR_STATIC_INIT("content"), select_msg_body, 0},
320 320
 	{ select_msg_body, SEL_PARAM_STR, STR_STATIC_INIT("sdp"), select_msg_body_sdp, 0},
321
+	{ select_msg_body_sdp, SEL_PARAM_STR, STR_STATIC_INIT("line"), select_sdp_line, CONSUME_NEXT_STR | FIXUP_CALL},
321 322
 	{ select_msg, SEL_PARAM_STR, STR_STATIC_INIT("request"), select_msg_request, 0},
322 323
 	{ select_msg, SEL_PARAM_STR, STR_STATIC_INIT("req"), select_msg_request, 0},
323 324
 	{ select_msg_request, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_msg_request_method, 0},