Browse code

nameaddr support in select framework

if you want to use nameaddr parsing in your select function define as foolows:
{ select_YOUR_FUNCTION_xxx, SEL_PARAM_STR, STR_STATIC_INIT("nameaddr"), select_any_nameaddr, NESTED | CONSUME_NEXT_STR }

Michal Matyska authored on 27/06/2006 11:43:40
Showing 3 changed files
... ...
@@ -248,7 +248,7 @@ int resolve_select(select_t* s)
248 248
 			if (nested < MAX_NESTED_CALLS-1) { /* need space for final function */
249 249
 				s->lvl = nested;
250 250
 				s->f[nested++] = f;
251
-				s->param_offset[nested] = param_idx+1;
251
+				s->param_offset[nested] = param_idx;
252 252
 			} else {
253 253
 				BUG("MAX_NESTED_CALLS too small to resolve select\n");
254 254
 				goto not_found;
... ...
@@ -37,6 +37,7 @@
37 37
 #include "select_buf.h"
38 38
 #include "dprint.h"
39 39
 #include "trim.h"
40
+#include "parser/parser_f.h"
40 41
 #include "parser/hf.h"
41 42
 #include "parser/parse_from.h"
42 43
 #include "parser/parse_to.h"
... ...
@@ -792,3 +793,45 @@ int select_cseq_method(str* res, select_t* s, struct sip_msg* msg)
792 792
 	*res = cs->method;
793 793
 	return 0;
794 794
 }
795
+
796
+ABSTRACT_F(select_any_nameaddr)
797
+
798
+int select_nameaddr_name(str* res, select_t* s, struct sip_msg* msg)
799
+{
800
+	char *p;
801
+	
802
+	p=find_not_quoted(res, '<');
803
+	if (!p) {
804
+		DBG("select_nameaddr_name: no < found, whole string is uri\n");
805
+		res->len=0;
806
+		return 1;
807
+	}
808
+
809
+	res->len=p-res->s;
810
+	while (res->len && SP(res->s[res->len-1])) res->len--;
811
+	return 0;
812
+}
813
+
814
+int select_nameaddr_uri(str* res, select_t* s, struct sip_msg* msg)
815
+{
816
+	char *p;
817
+	
818
+	p=find_not_quoted(res, '<');
819
+	if (!p) {
820
+		DBG("select_nameaddr_uri: no < found, whole string is uri\n");
821
+		return 0;
822
+	}
823
+
824
+	res->len=res->len - (p-res->s) -1;
825
+	res->s=p +1;
826
+	
827
+	p=find_not_quoted(res, '>');
828
+	if (!p) {
829
+		ERR("select_nameaddr_uri: no > found, invalid nameaddr value\n");
830
+		return -1;
831
+	}
832
+
833
+	res->len=p-res->s;
834
+	return 0;
835
+}
836
+
... ...
@@ -73,6 +73,10 @@ SELECT_F(select_via_params_spec)
73 73
 SELECT_F(select_msgheader)
74 74
 SELECT_F(select_anyheader)
75 75
 
76
+SELECT_F(select_any_nameaddr)
77
+SELECT_F(select_nameaddr_name)
78
+SELECT_F(select_nameaddr_uri)
79
+	
76 80
 SELECT_F(select_any_uri)
77 81
 SELECT_F(select_uri_type)
78 82
 SELECT_F(select_uri_user)
... ...
@@ -156,8 +160,13 @@ static select_row_t select_core[] = {
156 156
 	{ select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("num"), select_cseq_num, 0},
157 157
 	{ select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_cseq_method, 0},
158 158
 
159
+	{ select_any_nameaddr, SEL_PARAM_STR, STR_STATIC_INIT("name"), select_nameaddr_name, 0},
160
+	{ select_any_nameaddr, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_nameaddr_uri, 0},
161
+	{ select_nameaddr_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
162
+
159 163
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("msg"), select_msgheader, SEL_PARAM_EXPECTED},
160 164
 	{ select_msgheader, SEL_PARAM_STR, STR_NULL, select_anyheader, OPTIONAL | CONSUME_NEXT_INT | FIXUP_CALL},
165
+	{ select_anyheader, SEL_PARAM_STR, STR_STATIC_INIT("nameaddr"), select_any_nameaddr, NESTED | CONSUME_NEXT_STR},
161 166
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
162 167
 };
163 168