Browse code

- avp helper parsing api changes: - added avp_parse_spec() - parses an avp spec. which can be an avp name or an avp global alias - avp_parse_name & lookup_avp_galias have the same prototype now

Andrei Pelinescu-Onciul authored on 17/11/2004 00:37:16
Showing 2 changed files
... ...
@@ -47,7 +47,7 @@
47 47
 #include "usr_avp.h"
48 48
 
49 49
 
50
-
50
+/* usr_avp data bodies */
51 51
 struct str_int_data {
52 52
 	str  name;
53 53
 	int  val;
... ...
@@ -58,6 +58,12 @@ struct str_str_data {
58 58
 	str  val;
59 59
 };
60 60
 
61
+/* avp aliases structs*/
62
+struct avp_spec {
63
+	int type;
64
+	int_str name;
65
+};
66
+
61 67
 struct avp_galias {
62 68
 	str alias;
63 69
 	struct avp_spec  avp;
... ...
@@ -458,15 +464,19 @@ error:
458 458
 }
459 459
 
460 460
 
461
-struct avp_spec *lookup_avp_galias(char *alias, int len)
461
+int lookup_avp_galias(str *alias, int *type, int_str *avp_name)
462 462
 {
463 463
 	struct avp_galias *ga;
464 464
 
465 465
 	for( ga=galiases ; ga ; ga=ga->next )
466
-		if (len==ga->alias.len && (strncasecmp( alias, ga->alias.s, len)==0) )
467
-			return &ga->avp;
466
+		if (alias->len==ga->alias.len &&
467
+		(strncasecmp( alias->s, ga->alias.s, alias->len)==0) ) {
468
+			*type = ga->avp.type;
469
+			*avp_name = ga->avp.name;
470
+			return 0;
471
+		}
468 472
 
469
-	return 0;
473
+	return -1;
470 474
 }
471 475
 
472 476
 
... ...
@@ -477,6 +487,9 @@ int parse_avp_name( str *name, int *type, int_str *avp_name)
477 477
 	unsigned int id;
478 478
 	char c;
479 479
 
480
+	if (name==0 || name->s==0 || name->len==0)
481
+		goto error;
482
+
480 483
 	if (name->len>=2 && name->s[1]==':') {
481 484
 		c = name->s[0];
482 485
 		name->s += 2;
... ...
@@ -514,6 +527,28 @@ error:
514 514
 }
515 515
 
516 516
 
517
+int parse_avp_spec( str *name, int *type, int_str *avp_name)
518
+{
519
+	str alias;
520
+
521
+	if (name==0 || name->s==0 || name->len==0)
522
+		return -1;
523
+
524
+	if (name->s[0]==GALIAS_CHAR_MARKER) {
525
+		/* it's an avp alias */
526
+		if (name->len==1) {
527
+			LOG(L_ERR,"ERROR:parse_avp_spec: empty alias\n");
528
+			return -1;
529
+		}
530
+		alias.s = name->s+1;
531
+		alias.len = name->len-1;
532
+		return lookup_avp_galias( &alias, type, avp_name);
533
+	} else {
534
+		return parse_avp_name( name, type, avp_name);
535
+	}
536
+}
537
+
538
+
517 539
 int add_avp_galias_str(char *alias_definition)
518 540
 {
519 541
 	int_str avp_name;
... ...
@@ -50,25 +50,19 @@ struct usr_avp {
50 50
 };
51 51
 
52 52
 
53
-struct avp_spec {
54
-	int type;
55
-	int_str name;
56
-};
57
-
58
-
59 53
 #define AVP_NAME_STR     (1<<0)
60 54
 #define AVP_VAL_STR      (1<<1)
61 55
 
56
+#define GALIAS_CHAR_MARKER  '$'
57
+
62 58
 /* add functions */
63 59
 int add_avp( unsigned short flags, int_str name, int_str val);
64 60
 
65
-
66 61
 /* search functions */
67 62
 struct usr_avp *search_first_avp( unsigned short name_type, int_str name,
68 63
 															int_str *val );
69 64
 struct usr_avp *search_next_avp( struct usr_avp *avp, int_str *val  );
70 65
 
71
-
72 66
 /* free functions */
73 67
 void reset_avps( );
74 68
 void destroy_avp( struct usr_avp *avp);
... ...
@@ -83,9 +77,10 @@ struct usr_avp** get_avp_list( );
83 83
 
84 84
 /* global alias functions (manipulation and parsing)*/
85 85
 int add_avp_galias_str(char *alias_definition);
86
-struct avp_spec *lookup_avp_galias(char *alias, int len);
86
+int lookup_avp_galias(str *alias, int *type, int_str *avp_name);
87 87
 int add_avp_galias(str *alias, int type, int_str avp_name);
88 88
 int parse_avp_name( str *name, int *type, int_str *avp_name);
89
+int parse_avp_spec( str *name, int *type, int_str *avp_name);
89 90
 
90 91
 #endif
91 92