Browse code

avp: minor fixes & comments

- free_avp_name() for a regexp avp did not use regfree(...)
- changed free_avp_name() prototype to use avp_flags_t for the type
- added comments for parse_avp_ident()

Andrei Pelinescu-Onciul authored on 27/11/2008 00:20:52
Showing 2 changed files
... ...
@@ -838,6 +838,39 @@ int parse_avp_name( str *name, int *type, int_str *avp_name, int *index)
838 838
 	return ret;
839 839
 }
840 840
 
841
+
842
+/** parse an avp indentifier.
843
+ *
844
+ * Parses the following avp indentifier forms:
845
+ *       - "i:<number>"  - old form, deprecated  (e.g. i:42)
846
+ *       - "s:<string>"  - old form, deprecated  (e.g. s:foo)
847
+ *       - "<track>.<name>"                      (e.g.: f.bar)
848
+ *       - "<track>.<name>[<index>]"             (e.g.: f.bar[1])
849
+ *       - "<track><class>.<name>"               (e.g:  tu.bar)
850
+ *       - "<track><class>.<name>[<index>]"      (e.g:  fd.bar[2])
851
+ *       - "<string>"                            (e.g.: foo)
852
+ * Where:
853
+ *          <string> = ascii string
854
+ *          <id>   = ascii string w/o '[', ']', '.' and '/'
855
+ *          <name> = <id> | '/' regex '/'
856
+ *                   (Note: regex use is deprecated)
857
+ *          <track> = 'f' | 't' | 'g'
858
+ *                   (from, to  or global)
859
+ *          <class> = 'r' | 'u' | 'd' 
860
+ *                    (uri, user or domain)
861
+ *          <index> = <number> | '-' <number> | ''
862
+ *                    (the avp index, if missing it means AVP_INDEX_ALL, but
863
+ *                     it's use is deprecated)
864
+ * More examples:
865
+ *       "fr.bar[1]"  - from track, uri class, avp "bar", the value 1.
866
+ *       "tu./^foo/"  - to track,  user class, all avps for which the name
867
+ *                      starts with foo (note RE in avp names are deprecated).
868
+ *        "t.did"     - to track, "did" avp
869
+ *
870
+ * @param name  - avp identifier
871
+ * @param *attr - the result will be stored here
872
+ * @return 0 on success, -1 on error
873
+ */
841 874
 int parse_avp_ident( str *name, avp_ident_t* attr)
842 875
 {
843 876
 	unsigned int id;
... ...
@@ -967,6 +1000,7 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
967 967
 			name->s[name->len-1]=0;
968 968
 			if (regcomp(attr->name.re, name->s+1, REG_EXTENDED|REG_NOSUB|REG_ICASE)) {
969 969
 				pkg_free(attr->name.re);
970
+				attr->name.re=0;
970 971
 				name->s[name->len-1] = '/';
971 972
 				goto error;
972 973
 			}
... ...
@@ -1010,10 +1044,13 @@ int parse_avp_spec( str *name, int *type, int_str *avp_name, int *index)
1010 1010
 	}
1011 1011
 }
1012 1012
 
1013
-void free_avp_name( int *type, int_str *avp_name)
1013
+void free_avp_name(avp_flags_t *type, int_str *avp_name)
1014 1014
 {
1015
-	if ((*type & AVP_NAME_RE) && (avp_name->re))
1015
+	if ((*type & AVP_NAME_RE) && (avp_name->re)){
1016
+		regfree(avp_name->re);
1016 1017
 		pkg_free(avp_name->re);
1018
+		avp_name->re=0;
1019
+	}
1017 1020
 }
1018 1021
 
1019 1022
 int add_avp_galias_str(char *alias_definition)
... ...
@@ -197,7 +197,7 @@ int add_avp_galias(str *alias, int type, int_str avp_name);
197 197
 int parse_avp_ident( str *name, avp_ident_t* attr);
198 198
 int parse_avp_name( str *name, int *type, int_str *avp_name, int *index);
199 199
 int parse_avp_spec( str *name, int *type, int_str *avp_name, int *index);
200
-void free_avp_name( int *type, int_str *avp_name);
200
+void free_avp_name( avp_flags_t *type, int_str *avp_name);
201 201
 
202 202
 /* AVP flags functions */
203 203
 #define MAX_AVPFLAG  ((unsigned int)( sizeof(avp_flags_t) * CHAR_BIT - 1 - AVP_CUSTOM_FLAGS))