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 571
 	RETURN0_res(uri.params);
572 572
 }
573 573
 
574
+int select_event(str* res, select_t* s, struct sip_msg* msg)
575
+{
576
+	if (!msg->event && parse_headers(msg, HDR_EVENT_F, 0) == -1) {
577
+		ERR("Error while searching Event header field\n");
578
+		return -1;
579
+	}
580
+
581
+	if (!msg->event) {
582
+		DBG("Event header field not found\n");
583
+		return -1;
584
+	}
585
+
586
+	if (parse_event(msg->event) < 0) {
587
+		ERR("Error while parsing Event header field\n");
588
+		return -1;
589
+	}
590
+
591
+	*res = ((event_t*)msg->event->parsed)->text;
592
+	return 0;
593
+}
594
+
595
+
596
+
597
+static int parse_rr_header(struct sip_msg *msg)
598
+{
599
+        if ( !msg->record_route && ( parse_headers(msg,HDR_RECORDROUTE_F,0) == -1)) {
600
+                ERR("bad msg or missing Record-Route header\n");
601
+                return -1;
602
+        }
603
+
604
+	if (!msg->record_route) {
605
+		DBG("No Record-Route header field found\n");
606
+		return -1;
607
+	}
608
+
609
+	return parse_rr(msg->record_route);
610
+}
611
+
612
+#define get_rr(msg) ((rr_t*)(msg->record_route->parsed))
613
+
614
+
615
+int select_rr(str* res, select_t* s, struct sip_msg* msg)
616
+{
617
+	if (parse_rr_header(msg)<0)
618
+		return -1;
619
+	RETURN0_res(msg->record_route->body);
620
+}
621
+
622
+int select_rr_uri(str* res, select_t* s, struct sip_msg* msg)
623
+{
624
+	rr_t* r;
625
+	if (parse_rr_header(msg)<0)
626
+		return -1;
627
+	
628
+	r = get_rr(msg);
629
+	if (!r)
630
+		return 1;
631
+	RETURN0_res(r->nameaddr.uri);
632
+}
633
+
634
+int select_rr_name(str* res, select_t* s, struct sip_msg* msg)
635
+{
636
+	rr_t* r;
637
+	if (parse_rr_header(msg)<0)
638
+		return -1;
639
+	
640
+	r = get_rr(msg);
641
+	if (!r)
642
+		return 1;
643
+	RETURN0_res(r->nameaddr.name);
644
+}
645
+
646
+int select_rr_params(str* res, select_t* s, struct sip_msg* msg)
647
+{
648
+	rr_t* r;
649
+	param_t* p;
650
+	if (parse_rr_header(msg)<0)
651
+		return -1;
652
+	
653
+	r = get_rr(msg);
654
+	if (!r)
655
+		return 1;
656
+	p = r->params;
657
+	while (p) {
658
+		if ((p->name.len==s->params[s->n-1].v.s.len)
659
+		    && !strncasecmp(p->name.s, s->params[s->n-1].v.s.s,p->name.len)) {
660
+			RETURN0_res(p->body)
661
+		}
662
+		p = p->next;
663
+	}
664
+	return 0;
665
+}
666
+
667
+
668
+static inline struct cseq_body* sel_parse_cseq(struct sip_msg* msg)
669
+{
670
+        if (!msg->cseq && (parse_headers(msg, HDR_CSEQ_F, 0) == -1)) {
671
+                ERR("Unable to parse CSeq header\n");
672
+                return 0;
673
+        }
674
+
675
+	if (!msg->cseq) {
676
+		DBG("No CSeqheader field found\n");
677
+		return 0;
678
+	}
679
+
680
+	return get_cseq(msg);
681
+}
682
+
683
+
684
+
685
+int select_cseq(str* res, select_t* s, struct sip_msg* msg)
686
+{
687
+	struct cseq_body* cs;
688
+
689
+	cs = sel_parse_cseq(msg);
690
+	if (!cs) return -1;
691
+	*res = msg->cseq->body;
692
+	return 0;
693
+}
694
+
695
+int select_cseq_num(str* res, select_t* s, struct sip_msg* msg)
696
+{
697
+	struct cseq_body* cs;
698
+
699
+	cs = sel_parse_cseq(msg);
700
+	if (!cs) return -1;
701
+	*res = cs->number;
702
+	return 0;
703
+}
704
+
705
+int select_cseq_method(str* res, select_t* s, struct sip_msg* msg)
706
+{
707
+	struct cseq_body* cs;
708
+
709
+	cs = sel_parse_cseq(msg);
710
+	if (!cs) return -1;
711
+	*res = cs->method;
712
+	return 0;
713
+}
... ...
@@ -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 121
 	{ select_from_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
122 122
 	{ select_to_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
123 123
 	{ select_contact_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
124
+	{ select_rr_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
124 125
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("type"), select_uri_type, 0},
125 126
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("user"), select_uri_user, 0},
126 127
 	{ 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 129
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, 0},
130 130
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("msg"), select_msgheader, SEL_PARAM_EXPECTED},
131 131
 	{ select_msgheader, SEL_PARAM_STR, STR_NULL, select_anyheader, OPTIONAL | CONSUME_NEXT_INT},
132
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
133
+
134
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("record_route"), select_rr, 0},
135
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("rr"), select_rr, 0},
136
+	{ select_rr, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_rr_uri, 0},
137
+	{ select_rr, SEL_PARAM_STR, STR_STATIC_INIT("name"), select_rr_name, 0}, 
138
+	{ select_rr, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_rr_params, CONSUME_NEXT_STR},
139
+
140
+        { NULL, SEL_PARAM_STR, STR_STATIC_INIT("cseq"), select_cseq, 0},
141
+        { select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("num"), select_cseq_num, 0},
142
+        { select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_cseq_method, 0},
143
+
132 144
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
133 145
 };
134 146