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 519
 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR); return ATTR_MARK; }
520 520
 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
521 521
 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
522
+<ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
523
+<ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
522 524
 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
523 525
 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
524 526
 <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 1390
 attr_class_spec:
1391 1391
 	ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
1392 1392
 	| ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
1393
+        | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
1394
+        | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
1393 1395
 	| ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
1394 1396
 	| ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
1395 1397
 	| 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 108
  */
109 109
 static avp_list_t* select_list(avp_flags_t flags)
110 110
 {
111
-	if (flags & AVP_CLASS_USER) {
111
+	if (flags & AVP_CLASS_URI) {
112
+		if (flags & AVP_TRACK_TO) {
113
+			return crt_list[IDX_TO_URI];
114
+		} else {
115
+			return crt_list[IDX_FROM_URI];
116
+		}
117
+	} else if (flags & AVP_CLASS_USER) {
112 118
 		if (flags & AVP_TRACK_TO) {
113 119
 			return crt_list[IDX_TO_USER];
114 120
 		} else {
... ...
@@ -241,14 +249,15 @@ int add_avp(avp_flags_t flags, avp_name_t name, avp_value_t val)
241 241
 	avp_flags_t avp_class;
242 242
 	avp_list_t* list;
243 243
 
244
-	     /* Add avp to user class if no class has been
244
+	     /* Add avp to uri class if no class has been
245 245
 	      * specified by the caller
246 246
 	      */
247
-	if ((flags & AVP_CLASS_ALL) == 0) flags |= AVP_CLASS_USER;
247
+	if ((flags & AVP_CLASS_ALL) == 0) flags |= AVP_CLASS_URI;
248 248
 	if ((flags & AVP_TRACK_ALL) == 0) flags |= AVP_TRACK_FROM;
249 249
 	list = select_list(flags);
250 250
 
251
-	if (flags & AVP_CLASS_USER) avp_class = AVP_CLASS_USER;
251
+	if (flags & AVP_CLASS_URI) avp_class = AVP_CLASS_URI;
252
+	else if (flags & AVP_CLASS_USER) avp_class = AVP_CLASS_USER;
252 253
 	else if (flags & AVP_CLASS_DOMAIN) avp_class = AVP_CLASS_DOMAIN;
253 254
 	else avp_class = AVP_CLASS_GLOBAL;
254 255
 
... ...
@@ -482,7 +491,10 @@ avp_t *search_next_avp(struct search_state* s, avp_value_t *val )
482 482
 			}
483 483
 		}
484 484
 
485
-		if (s->flags & AVP_CLASS_USER) {
485
+		if (s->flags & AVP_CLASS_URI) {
486
+			s->flags &= ~AVP_CLASS_URI;
487
+			s->avp = *select_list(s->flags);
488
+		} else if (s->flags & AVP_CLASS_USER) {
486 489
 			s->flags &= ~AVP_CLASS_USER;
487 490
 			s->avp = *select_list(s->flags);
488 491
 		} 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 627
 {
628 628
 	avp_list_t* prev;
629 629
 
630
-	if (flags & AVP_CLASS_USER) {
630
+	if (flags & AVP_CLASS_URI) {
631
+		if (flags & AVP_TRACK_FROM) {
632
+			prev = crt_list[IDX_FROM_URI];
633
+			crt_list[IDX_FROM_URI] = list;
634
+		} else {
635
+			prev = crt_list[IDX_TO_URI];
636
+			crt_list[IDX_TO_URI] = list;
637
+		}
638
+	} else if (flags & AVP_CLASS_USER) {
631 639
 		if (flags & AVP_TRACK_FROM) {
632 640
 			prev = crt_list[IDX_FROM_USER];
633 641
 			crt_list[IDX_FROM_USER] = list;
... ...
@@ -845,6 +865,12 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
845 845
 			case 't':
846 846
 				attr->flags = AVP_TRACK_TO;
847 847
 				break;
848
+			case 0x6672: /* 'fr' */
849
+				attr->flags = AVP_TRACK_FROM | AVP_CLASS_URI;
850
+				break;
851
+			case 0x7472: /* 'tr' */
852
+				attr->flags = AVP_TRACK_TO | AVP_CLASS_URI;
853
+				break;				
848 854
 			case 0x6675: /* 'fu' */
849 855
 				attr->flags = AVP_TRACK_FROM | AVP_CLASS_USER;
850 856
 				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 140
 #define AVP_TRACK_TO     (1<<9)
141 141
 #define AVP_TRACK_ALL    (AVP_TRACK_FROM|AVP_TRACK_TO)
142 142
 
143
-#define AVP_CLASS_ALL (AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
143
+#define AVP_CLASS_ALL (AVP_CLASS_URI|AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
144 144
 
145 145
 /* AVP name index */
146 146
 #define AVP_INDEX_FORWARD	(1<<10)