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 1059
 			if (!name.len || name.s[0] != '@') {
1059 1060
 				/* Not a select identifier */
1060 1061
 				pkg_free(p);
1061
-			return 1;
1062
+				return 1;
1062 1063
 			}
1063 1064
 			if (parse_select(&name.s, &p->v.select) < 0) {
1064 1065
 				ERR("Error while parsing select identifier\n");
... ...
@@ -1071,7 +1072,37 @@ int fix_param(int type, void** param)
1071 1072
 			p->v.subst = subst_parser(&s);
1072 1073
 			if (!p->v.subst) {
1073 1074
 				ERR("Error while parsing regex substitution\n");
1074
-			goto error;
1075
+				goto error;
1076
+			}
1077
+			break;
1078
+		case FPARAM_PVS:
1079
+			name.s = (char*)*param;
1080
+			name.len = strlen(name.s);
1081
+			trim(&name);
1082
+			if (!name.len || name.s[0] != '$'){
1083
+				/* not a pvs identifier */
1084
+				pkg_free(p);
1085
+				return 1;
1086
+			}
1087
+			p->v.pvs=pkg_malloc(sizeof(pv_spec_t));
1088
+			if (p->v.pvs==0){
1089
+				ERR("out of memory while parsing pv_spec_t\n");
1090
+				goto error;
1091
+			}
1092
+			if (pv_parse_spec(&name, p->v.pvs)==0){
1093
+				ERR("unsupported user field indentifier \"%.*s\"\n",
1094
+						name.len, name.s);
1095
+				pkg_free(p->v.pvs);
1096
+				p->v.pvs=0;
1097
+				goto error;
1098
+			}
1099
+			break;
1100
+		case FPARAM_PVE:
1101
+			name.s = (char*)*param;
1102
+			name.len = strlen(name.s);
1103
+			if (pv_parse_format(&name, &p->v.pve)<0){
1104
+				ERR("bad PVE format: \"%.*s\"\n", name.len, name.s);
1105
+				goto error;
1075 1106
 			}
1076 1107
 			break;
1077 1108
 	}
... ...
@@ -1086,6 +1117,63 @@ error:
1086 1117
 }
1087 1118
 
1088 1119
 
1120
+
1121
+/** fparam_t free function.
1122
+ *  Frees the "content" of a fparam, but not the fparam itself.
1123
+ *  Assumes pkg_malloc'ed content.
1124
+ *  @param fp -  fparam to be freed
1125
+ *
1126
+ */
1127
+void fparam_free_contents(fparam_t* fp)
1128
+{
1129
+
1130
+	if (fp==0)
1131
+		return;
1132
+	switch(fp->type) {
1133
+		case FPARAM_UNSPEC:
1134
+		case FPARAM_STRING: /* asciiz string, not str */
1135
+		case FPARAM_INT:
1136
+		case FPARAM_STR:
1137
+			/* nothing to do */
1138
+			return;
1139
+		case FPARAM_REGEX:
1140
+			if (fp->v.regex){
1141
+				regfree(fp->v.regex);
1142
+				pkg_free(fp->v.regex);
1143
+				fp->v.regex=0;
1144
+			}
1145
+			break;
1146
+		case FPARAM_AVP:
1147
+			free_avp_name(&fp->v.avp.flags, &fp->v.avp.name);
1148
+			break;
1149
+		case FPARAM_SELECT:
1150
+			if (fp->v.select){
1151
+				free_select(fp->v.select);
1152
+				fp->v.select=0;
1153
+			}
1154
+			break;
1155
+		case FPARAM_SUBST:
1156
+			if (fp->v.subst){
1157
+				subst_expr_free(fp->v.subst);
1158
+				fp->v.subst=0;
1159
+			}
1160
+			break;
1161
+		case FPARAM_PVS:
1162
+			if (fp->v.pvs){
1163
+				pv_spec_free(fp->v.pvs);
1164
+				fp->v.pvs=0;
1165
+			}
1166
+			break;
1167
+		case FPARAM_PVE:
1168
+			if (fp->v.pve){
1169
+				pv_elem_free_all(fp->v.pve);
1170
+				fp->v.pve=0;
1171
+			}
1172
+			break;
1173
+	}
1174
+}
1175
+
1176
+
1089 1177
 /*
1090 1178
  * Fixup variable string, the parameter can be
1091 1179
  * 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