Browse code

- support for URI attributes

Jan Janak authored on 04/07/2006 12:46:30
Showing 4 changed files
... ...
@@ -206,6 +206,8 @@ ATTR_MARK   "$"|"%"
206 206
 SELECT_MARK  "@"
207 207
 ATTR_FROM         "f"
208 208
 ATTR_TO           "t"
209
+ATTR_FROMURI      "fr"
210
+ATTR_TOURI       "tr"
209 211
 ATTR_FROMUSER     "fu"
210 212
 ATTR_TOUSER       "tu"
211 213
 ATTR_FROMDOMAIN   "fd"
... ...
@@ -519,6 +521,8 @@ EAT_ABLE	[\ \t\b\r]
519 521
 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR); return ATTR_MARK; }
520 522
 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
521 523
 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
524
+<ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
525
+<ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
522 526
 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
523 527
 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
524 528
 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
... ...
@@ -290,6 +290,8 @@ static struct socket_id* mk_listen_id(char*, int, int);
290 290
 %token SELECT_MARK
291 291
 %token ATTR_FROM
292 292
 %token ATTR_TO
293
+%token ATTR_FROMURI
294
+%token ATTR_TOURI
293 295
 %token ATTR_FROMUSER
294 296
 %token ATTR_TOUSER
295 297
 %token ATTR_FROMDOMAIN
... ...
@@ -1390,6 +1392,8 @@ select_id:
1390 1392
 attr_class_spec:
1391 1393
 	ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
1392 1394
 	| ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
1395
+        | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
1396
+        | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
1393 1397
 	| ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
1394 1398
 	| ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
1395 1399
 	| ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
... ...
@@ -50,7 +50,9 @@
50 50
 #include "usr_avp.h"
51 51
 
52 52
 enum idx {
53
-	IDX_FROM_USER = 0,
53
+	IDX_FROM_URI = 0,
54
+	IDX_TO_URI,
55
+	IDX_FROM_USER,
54 56
 	IDX_TO_USER,
55 57
 	IDX_FROM_DOMAIN,
56 58
 	IDX_TO_DOMAIN,
... ...
@@ -108,7 +110,13 @@ int init_avps(void)
108 110
  */
109 111
 static avp_list_t* select_list(avp_flags_t flags)
110 112
 {
111
-	if (flags & AVP_CLASS_USER) {
113
+	if (flags & AVP_CLASS_URI) {
114
+		if (flags & AVP_TRACK_TO) {
115
+			return crt_list[IDX_TO_URI];
116
+		} else {
117
+			return crt_list[IDX_FROM_URI];
118
+		}
119
+	} else if (flags & AVP_CLASS_USER) {
112 120
 		if (flags & AVP_TRACK_TO) {
113 121
 			return crt_list[IDX_TO_USER];
114 122
 		} else {
... ...
@@ -241,14 +249,15 @@ int add_avp(avp_flags_t flags, avp_name_t name, avp_value_t val)
241 249
 	avp_flags_t avp_class;
242 250
 	avp_list_t* list;
243 251
 
244
-	     /* Add avp to user class if no class has been
252
+	     /* Add avp to uri class if no class has been
245 253
 	      * specified by the caller
246 254
 	      */
247
-	if ((flags & AVP_CLASS_ALL) == 0) flags |= AVP_CLASS_USER;
255
+	if ((flags & AVP_CLASS_ALL) == 0) flags |= AVP_CLASS_URI;
248 256
 	if ((flags & AVP_TRACK_ALL) == 0) flags |= AVP_TRACK_FROM;
249 257
 	list = select_list(flags);
250 258
 
251
-	if (flags & AVP_CLASS_USER) avp_class = AVP_CLASS_USER;
259
+	if (flags & AVP_CLASS_URI) avp_class = AVP_CLASS_URI;
260
+	else if (flags & AVP_CLASS_USER) avp_class = AVP_CLASS_USER;
252 261
 	else if (flags & AVP_CLASS_DOMAIN) avp_class = AVP_CLASS_DOMAIN;
253 262
 	else avp_class = AVP_CLASS_GLOBAL;
254 263
 
... ...
@@ -482,7 +491,10 @@ avp_t *search_next_avp(struct search_state* s, avp_value_t *val )
482 491
 			}
483 492
 		}
484 493
 
485
-		if (s->flags & AVP_CLASS_USER) {
494
+		if (s->flags & AVP_CLASS_URI) {
495
+			s->flags &= ~AVP_CLASS_URI;
496
+			s->avp = *select_list(s->flags);
497
+		} else if (s->flags & AVP_CLASS_USER) {
486 498
 			s->flags &= ~AVP_CLASS_USER;
487 499
 			s->avp = *select_list(s->flags);
488 500
 		} else if (s->flags & AVP_CLASS_DOMAIN) {
... ...
@@ -627,7 +639,15 @@ avp_list_t* set_avp_list( avp_flags_t flags, avp_list_t* list )
627 639
 {
628 640
 	avp_list_t* prev;
629 641
 
630
-	if (flags & AVP_CLASS_USER) {
642
+	if (flags & AVP_CLASS_URI) {
643
+		if (flags & AVP_TRACK_FROM) {
644
+			prev = crt_list[IDX_FROM_URI];
645
+			crt_list[IDX_FROM_URI] = list;
646
+		} else {
647
+			prev = crt_list[IDX_TO_URI];
648
+			crt_list[IDX_TO_URI] = list;
649
+		}
650
+	} else if (flags & AVP_CLASS_USER) {
631 651
 		if (flags & AVP_TRACK_FROM) {
632 652
 			prev = crt_list[IDX_FROM_USER];
633 653
 			crt_list[IDX_FROM_USER] = list;
... ...
@@ -845,6 +865,12 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
845 865
 			case 't':
846 866
 				attr->flags = AVP_TRACK_TO;
847 867
 				break;
868
+			case 0x6672: /* 'fr' */
869
+				attr->flags = AVP_TRACK_FROM | AVP_CLASS_URI;
870
+				break;
871
+			case 0x7472: /* 'tr' */
872
+				attr->flags = AVP_TRACK_TO | AVP_CLASS_URI;
873
+				break;				
848 874
 			case 0x6675: /* 'fu' */
849 875
 				attr->flags = AVP_TRACK_FROM | AVP_CLASS_USER;
850 876
 				break;
... ...
@@ -131,6 +131,7 @@ typedef struct avp_spec {
131 131
 #define AVP_NAME_RE      (1<<2)
132 132
 
133 133
 /* AVP classes */
134
+#define AVP_CLASS_URI    (1<<4)
134 135
 #define AVP_CLASS_USER   (1<<5)
135 136
 #define AVP_CLASS_DOMAIN (1<<6)
136 137
 #define AVP_CLASS_GLOBAL (1<<7)
... ...
@@ -140,7 +141,7 @@ typedef struct avp_spec {
140 141
 #define AVP_TRACK_TO     (1<<9)
141 142
 #define AVP_TRACK_ALL    (AVP_TRACK_FROM|AVP_TRACK_TO)
142 143
 
143
-#define AVP_CLASS_ALL (AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
144
+#define AVP_CLASS_ALL (AVP_CLASS_URI|AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
144 145
 
145 146
 /* AVP name index */
146 147
 #define AVP_INDEX_FORWARD	(1<<10)