Browse code

fixups: generic fixups work now on kamailio pvars

- fix_param() supports now FPARAM_PVS and FPARAM_PVE
(kamailio GPARAM_TYPE_PVS and GPARAM_TYPE_PVE)
- added fparam_free_contents() which frees the contents of a fparam_t

Andrei Pelinescu-Onciul authored on 27/11/2008 00:30:26
Showing 2 changed files
... ...
@@ -1031,6 +1031,7 @@ int fix_param(int type, void** param)
1031 1031
 			if (regcomp(p->v.regex, *param,
1032 1032
 						REG_EXTENDED|REG_ICASE|REG_NEWLINE)) {
1033 1033
 				pkg_free(p->v.regex);
1034
+				p->v.regex=0;
1034 1035
 				ERR("Bad regular expression '%s'\n", (char*)*param);
1035 1036
 				goto error;
1036 1037
 			}
... ...
@@ -1058,7 +1059,7 @@ int fix_param(int type, void** param)
1058 1058
 			if (!name.len || name.s[0] != '@') {
1059 1059
 				/* Not a select identifier */
1060 1060
 				pkg_free(p);
1061
-			return 1;
1061
+				return 1;
1062 1062
 			}
1063 1063
 			if (parse_select(&name.s, &p->v.select) < 0) {
1064 1064
 				ERR("Error while parsing select identifier\n");
... ...
@@ -1071,7 +1072,37 @@ int fix_param(int type, void** param)
1071 1071
 			p->v.subst = subst_parser(&s);
1072 1072
 			if (!p->v.subst) {
1073 1073
 				ERR("Error while parsing regex substitution\n");
1074
-			goto error;
1074
+				goto error;
1075
+			}
1076
+			break;
1077
+		case FPARAM_PVS:
1078
+			name.s = (char*)*param;
1079
+			name.len = strlen(name.s);
1080
+			trim(&name);
1081
+			if (!name.len || name.s[0] != '$'){
1082
+				/* not a pvs identifier */
1083
+				pkg_free(p);
1084
+				return 1;
1085
+			}
1086
+			p->v.pvs=pkg_malloc(sizeof(pv_spec_t));
1087
+			if (p->v.pvs==0){
1088
+				ERR("out of memory while parsing pv_spec_t\n");
1089
+				goto error;
1090
+			}
1091
+			if (pv_parse_spec(&name, p->v.pvs)==0){
1092
+				ERR("unsupported user field indentifier \"%.*s\"\n",
1093
+						name.len, name.s);
1094
+				pkg_free(p->v.pvs);
1095
+				p->v.pvs=0;
1096
+				goto error;
1097
+			}
1098
+			break;
1099
+		case FPARAM_PVE:
1100
+			name.s = (char*)*param;
1101
+			name.len = strlen(name.s);
1102
+			if (pv_parse_format(&name, &p->v.pve)<0){
1103
+				ERR("bad PVE format: \"%.*s\"\n", name.len, name.s);
1104
+				goto error;
1075 1105
 			}
1076 1106
 			break;
1077 1107
 	}
... ...
@@ -1086,6 +1117,63 @@ error:
1086 1086
 }
1087 1087
 
1088 1088
 
1089
+
1090
+/** fparam_t free function.
1091
+ *  Frees the "content" of a fparam, but not the fparam itself.
1092
+ *  Assumes pkg_malloc'ed content.
1093
+ *  @param fp -  fparam to be freed
1094
+ *
1095
+ */
1096
+void fparam_free_contents(fparam_t* fp)
1097
+{
1098
+
1099
+	if (fp==0)
1100
+		return;
1101
+	switch(fp->type) {
1102
+		case FPARAM_UNSPEC:
1103
+		case FPARAM_STRING: /* asciiz string, not str */
1104
+		case FPARAM_INT:
1105
+		case FPARAM_STR:
1106
+			/* nothing to do */
1107
+			return;
1108
+		case FPARAM_REGEX:
1109
+			if (fp->v.regex){
1110
+				regfree(fp->v.regex);
1111
+				pkg_free(fp->v.regex);
1112
+				fp->v.regex=0;
1113
+			}
1114
+			break;
1115
+		case FPARAM_AVP:
1116
+			free_avp_name(&fp->v.avp.flags, &fp->v.avp.name);
1117
+			break;
1118
+		case FPARAM_SELECT:
1119
+			if (fp->v.select){
1120
+				free_select(fp->v.select);
1121
+				fp->v.select=0;
1122
+			}
1123
+			break;
1124
+		case FPARAM_SUBST:
1125
+			if (fp->v.subst){
1126
+				subst_expr_free(fp->v.subst);
1127
+				fp->v.subst=0;
1128
+			}
1129
+			break;
1130
+		case FPARAM_PVS:
1131
+			if (fp->v.pvs){
1132
+				pv_spec_free(fp->v.pvs);
1133
+				fp->v.pvs=0;
1134
+			}
1135
+			break;
1136
+		case FPARAM_PVE:
1137
+			if (fp->v.pve){
1138
+				pv_elem_free_all(fp->v.pve);
1139
+				fp->v.pve=0;
1140
+			}
1141
+			break;
1142
+	}
1143
+}
1144
+
1145
+
1089 1146
 /*
1090 1147
  * Fixup variable string, the parameter can be
1091 1148
  * AVP, SELECT, or ordinary string. AVP and select
... ...
@@ -261,8 +261,8 @@ typedef struct fparam {
261 261
 		avp_ident_t avp;          /* AVP identifier */
262 262
 		select_t* select;         /* select structure */ 
263 263
 		struct subst_expr* subst; /* Regex substitution */
264
-		struct pv_spec_t* pvs;    /* kamailo pseudo-vars */
265
-		struct pv_elem_t* pve;    /* kamailo pseudo-vars */
264
+		pv_spec_t* pvs;    /* kamailo pseudo-vars */
265
+		pv_elem_t* pve;    /* kamailo pseudo-vars in a string */
266 266
 	} v;
267 267
 } fparam_t;
268 268
 
... ...
@@ -417,6 +417,7 @@ int fix_flag( modparam_t type, void* val,
417 417
  * parameter types
418 418
  */
419 419
 int fix_param(int type, void** param);
420
+void fparam_free_contents(fparam_t* fp);
420 421
 
421 422
 /*
422 423
  * Fixup variable string, the parameter can be