Browse code

- support for @event - support for @cseq (@cseq, @cseq.number, @cseq.method) - support for @record_route (@record_route.uri, @record_route.params, ...)

Jan Janak authored on 16/02/2006 14:19:59
Showing 2 changed files
... ...
@@ -42,6 +42,8 @@
42 42
 #include "parser/contact/contact.h"
43 43
 #include "parser/parse_via.h"
44 44
 #include "parser/parse_uri.h"
45
+#include "parser/parse_event.h"
46
+#include "parser/parse_rr.h"
45 47
 
46 48
 #define RETURN0_res(x) {*res=x;return 0;}
47 49
 #define TRIM_RET0_res(x) {*res=x;trim(res);return 0;} 
... ...
@@ -571,3 +573,143 @@ int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
571 573
 	RETURN0_res(uri.params);
572 574
 }
573 575
 
576
+int select_event(str* res, select_t* s, struct sip_msg* msg)
577
+{
578
+	if (!msg->event && parse_headers(msg, HDR_EVENT_F, 0) == -1) {
579
+		ERR("Error while searching Event header field\n");
580
+		return -1;
581
+	}
582
+
583
+	if (!msg->event) {
584
+		DBG("Event header field not found\n");
585
+		return -1;
586
+	}
587
+
588
+	if (parse_event(msg->event) < 0) {
589
+		ERR("Error while parsing Event header field\n");
590
+		return -1;
591
+	}
592
+
593
+	*res = ((event_t*)msg->event->parsed)->text;
594
+	return 0;
595
+}
596
+
597
+
598
+
599
+static int parse_rr_header(struct sip_msg *msg)
600
+{
601
+        if ( !msg->record_route && ( parse_headers(msg,HDR_RECORDROUTE_F,0) == -1)) {
602
+                ERR("bad msg or missing Record-Route header\n");
603
+                return -1;
604
+        }
605
+
606
+	if (!msg->record_route) {
607
+		DBG("No Record-Route header field found\n");
608
+		return -1;
609
+	}
610
+
611
+	return parse_rr(msg->record_route);
612
+}
613
+
614
+#define get_rr(msg) ((rr_t*)(msg->record_route->parsed))
615
+
616
+
617
+int select_rr(str* res, select_t* s, struct sip_msg* msg)
618
+{
619
+	if (parse_rr_header(msg)<0)
620
+		return -1;
621
+	RETURN0_res(msg->record_route->body);
622
+}
623
+
624
+int select_rr_uri(str* res, select_t* s, struct sip_msg* msg)
625
+{
626
+	rr_t* r;
627
+	if (parse_rr_header(msg)<0)
628
+		return -1;
629
+	
630
+	r = get_rr(msg);
631
+	if (!r)
632
+		return 1;
633
+	RETURN0_res(r->nameaddr.uri);
634
+}
635
+
636
+int select_rr_name(str* res, select_t* s, struct sip_msg* msg)
637
+{
638
+	rr_t* r;
639
+	if (parse_rr_header(msg)<0)
640
+		return -1;
641
+	
642
+	r = get_rr(msg);
643
+	if (!r)
644
+		return 1;
645
+	RETURN0_res(r->nameaddr.name);
646
+}
647
+
648
+int select_rr_params(str* res, select_t* s, struct sip_msg* msg)
649
+{
650
+	rr_t* r;
651
+	param_t* p;
652
+	if (parse_rr_header(msg)<0)
653
+		return -1;
654
+	
655
+	r = get_rr(msg);
656
+	if (!r)
657
+		return 1;
658
+	p = r->params;
659
+	while (p) {
660
+		if ((p->name.len==s->params[s->n-1].v.s.len)
661
+		    && !strncasecmp(p->name.s, s->params[s->n-1].v.s.s,p->name.len)) {
662
+			RETURN0_res(p->body)
663
+		}
664
+		p = p->next;
665
+	}
666
+	return 0;
667
+}
668
+
669
+
670
+static inline struct cseq_body* sel_parse_cseq(struct sip_msg* msg)
671
+{
672
+        if (!msg->cseq && (parse_headers(msg, HDR_CSEQ_F, 0) == -1)) {
673
+                ERR("Unable to parse CSeq header\n");
674
+                return 0;
675
+        }
676
+
677
+	if (!msg->cseq) {
678
+		DBG("No CSeqheader field found\n");
679
+		return 0;
680
+	}
681
+
682
+	return get_cseq(msg);
683
+}
684
+
685
+
686
+
687
+int select_cseq(str* res, select_t* s, struct sip_msg* msg)
688
+{
689
+	struct cseq_body* cs;
690
+
691
+	cs = sel_parse_cseq(msg);
692
+	if (!cs) return -1;
693
+	*res = msg->cseq->body;
694
+	return 0;
695
+}
696
+
697
+int select_cseq_num(str* res, select_t* s, struct sip_msg* msg)
698
+{
699
+	struct cseq_body* cs;
700
+
701
+	cs = sel_parse_cseq(msg);
702
+	if (!cs) return -1;
703
+	*res = cs->number;
704
+	return 0;
705
+}
706
+
707
+int select_cseq_method(str* res, select_t* s, struct sip_msg* msg)
708
+{
709
+	struct cseq_body* cs;
710
+
711
+	cs = sel_parse_cseq(msg);
712
+	if (!cs) return -1;
713
+	*res = cs->method;
714
+	return 0;
715
+}
... ...
@@ -80,6 +80,17 @@ SELECT_F(select_uri_host)
80 80
 SELECT_F(select_uri_port)
81 81
 SELECT_F(select_uri_params)
82 82
 
83
+SELECT_F(select_event)
84
+
85
+SELECT_F(select_rr)
86
+SELECT_F(select_rr_uri)
87
+SELECT_F(select_rr_name)
88
+SELECT_F(select_rr_params)
89
+
90
+SELECT_F(select_cseq)
91
+SELECT_F(select_cseq_method)
92
+SELECT_F(select_cseq_num)
93
+
83 94
 static select_row_t select_core[] = {
84 95
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("from"), select_from, 0},
85 96
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("f"), select_from, 0},
... ...
@@ -121,6 +132,7 @@ static select_row_t select_core[] = {
121 132
 	{ select_from_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
122 133
 	{ select_to_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
123 134
 	{ select_contact_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
135
+	{ select_rr_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
124 136
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("type"), select_uri_type, 0},
125 137
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("user"), select_uri_user, 0},
126 138
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("pwd"), select_uri_pwd, 0},
... ...
@@ -129,6 +141,18 @@ static select_row_t select_core[] = {
129 141
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, 0},
130 142
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("msg"), select_msgheader, SEL_PARAM_EXPECTED},
131 143
 	{ select_msgheader, SEL_PARAM_STR, STR_NULL, select_anyheader, OPTIONAL | CONSUME_NEXT_INT},
144
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
145
+
146
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("record_route"), select_rr, 0},
147
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("rr"), select_rr, 0},
148
+	{ select_rr, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_rr_uri, 0},
149
+	{ select_rr, SEL_PARAM_STR, STR_STATIC_INIT("name"), select_rr_name, 0}, 
150
+	{ select_rr, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_rr_params, CONSUME_NEXT_STR},
151
+
152
+        { NULL, SEL_PARAM_STR, STR_STATIC_INIT("cseq"), select_cseq, 0},
153
+        { select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("num"), select_cseq_num, 0},
154
+        { select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_cseq_method, 0},
155
+
132 156
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
133 157
 };
134 158