Browse code

modules/dialplan: use pv_cache_get function instead of create pv_spec_t

Victor Seva authored on 20/06/2013 06:32:47
Showing 2 changed files
... ...
@@ -160,14 +160,10 @@ static int mod_init(void)
160 160
 	attrs_column.len    = strlen(attrs_column.s);
161 161
 
162 162
 	if(attr_pvar_s.s) {
163
-		attr_pvar = (pv_spec_t *)shm_malloc(sizeof(pv_spec_t));
164
-		if(!attr_pvar){
165
-			LM_ERR("out of shm memory\n");
166
-			return -1;
167
-		}
168 163
 
169 164
 		attr_pvar_s.len = strlen(attr_pvar_s.s);
170
-		if( (pv_parse_spec(&attr_pvar_s, attr_pvar)==NULL) ||
165
+		attr_pvar = pv_cache_get(&attr_pvar_s);
166
+		if( (attr_pvar==NULL) ||
171 167
 				((attr_pvar->type != PVT_AVP) && (attr_pvar->type!=PVT_SCRIPTVAR))) {
172 168
 			LM_ERR("invalid pvar name\n");
173 169
 			return -1;
... ...
@@ -182,13 +178,15 @@ static int mod_init(void)
182 178
 	memset(default_par2, 0, sizeof(dp_param_t));
183 179
 
184 180
 	default_param_s.len = strlen(default_param_s.s);
185
-	if (pv_parse_spec( &default_param_s, &default_par2->v.sp[0])==NULL) {
181
+	default_par2->v.sp[0] = pv_cache_get(&default_param_s);
182
+	if (default_par2->v.sp[0]==NULL) {
186 183
 		LM_ERR("input pv is invalid\n");
187 184
 		return -1;
188 185
 	}
189 186
 
190 187
 	default_param_s.len = strlen(default_param_s.s);
191
-	if (pv_parse_spec( &default_param_s, &default_par2->v.sp[1])==NULL) {
188
+	default_par2->v.sp[1] = pv_cache_get(&default_param_s);
189
+	if (default_par2->v.sp[1]==NULL) {
192 190
 		LM_ERR("output pv is invalid\n");
193 191
 		return -1;
194 192
 	}
... ...
@@ -242,9 +240,9 @@ static int dp_get_ivalue(struct sip_msg* msg, dp_param_p dp, int *val)
242 240
 		return 0;
243 241
 	}
244 242
 
245
-	LM_DBG("searching %d\n",dp->v.sp[0].type);
243
+	LM_DBG("searching %d\n",dp->v.sp[0]->type);
246 244
 
247
-	if( pv_get_spec_value( msg, &dp->v.sp[0], &value)!=0
245
+	if( pv_get_spec_value( msg, dp->v.sp[0], &value)!=0
248 246
 			|| value.flags&(PV_VAL_NULL|PV_VAL_EMPTY) || !(value.flags&PV_VAL_INT)) {
249 247
 		LM_ERR("no AVP or SCRIPTVAR found (error in scripts)\n");
250 248
 		return -1;
... ...
@@ -254,13 +252,13 @@ static int dp_get_ivalue(struct sip_msg* msg, dp_param_p dp, int *val)
254 252
 }
255 253
 
256 254
 
257
-static int dp_get_svalue(struct sip_msg * msg, pv_spec_t spec, str* val)
255
+static int dp_get_svalue(struct sip_msg * msg, pv_spec_t *spec, str* val)
258 256
 {
259 257
 	pv_value_t value;
260 258
 
261
-	LM_DBG("searching %d \n", spec.type);
259
+	LM_DBG("searching %d \n", spec->type);
262 260
 
263
-	if ( pv_get_spec_value(msg,&spec,&value)!=0 || value.flags&PV_VAL_NULL
261
+	if ( pv_get_spec_value(msg,spec,&value)!=0 || value.flags&PV_VAL_NULL
264 262
 			|| value.flags&PV_VAL_EMPTY || !(value.flags&PV_VAL_STR)){
265 263
 		LM_ERR("no AVP or SCRIPTVAR found (error in scripts)\n");
266 264
 		return -1;
... ...
@@ -280,7 +278,7 @@ static int dp_update(struct sip_msg * msg, pv_spec_t * src, pv_spec_t * dest,
280 278
 	memset(&val, 0, sizeof(pv_value_t));
281 279
 	val.flags = PV_VAL_STR;
282 280
 
283
-	no_change = (dest->type == PVT_NONE) || (!repl->s) || (!repl->len);
281
+	no_change = (dest==NULL) || (dest->type == PVT_NONE) || (!repl->s) || (!repl->len);
284 282
 
285 283
 	if (no_change)
286 284
 		goto set_attr_pvar;
... ...
@@ -358,7 +356,7 @@ static int dp_translate_f(struct sip_msg* msg, char* str1, char* str2)
358 356
 			input.len, input.s, idp->dp_id, output.len, output.s);
359 357
 
360 358
 	/*set the output*/
361
-	if (dp_update(msg, &repl_par->v.sp[0], &repl_par->v.sp[1], 
359
+	if (dp_update(msg, repl_par->v.sp[0], repl_par->v.sp[1],
362 360
 				&output, attrs_par) !=0){
363 361
 		LM_ERR("cannot set the output\n");
364 362
 		return -1;
... ...
@@ -371,10 +369,10 @@ static int dp_translate_f(struct sip_msg* msg, char* str1, char* str2)
371 369
 #define verify_par_type(_par_no, _spec)\
372 370
 	do{\
373 371
 		if( ((_par_no == 1) \
374
-					&& ((_spec).type != PVT_AVP) && ((_spec).type!=PVT_SCRIPTVAR) )\
372
+					&& (_spec->type != PVT_AVP) && (_spec->type!=PVT_SCRIPTVAR) )\
375 373
 				||((_par_no == 2) \
376
-					&& ((_spec).type != PVT_AVP) && ((_spec).type!=PVT_SCRIPTVAR) \
377
-					&& ((_spec).type!=PVT_RURI) && (_spec.type!=PVT_RURI_USERNAME))){\
374
+					&& (_spec->type != PVT_AVP) && (_spec->type!=PVT_SCRIPTVAR) \
375
+					&& (_spec->type!=PVT_RURI) && (_spec->type!=PVT_RURI_USERNAME))){\
378 376
 			\
379 377
 			LM_ERR("Unsupported Parameter TYPE\n");\
380 378
 			return E_UNSPEC;\
... ...
@@ -426,7 +424,8 @@ static int dp_trans_fixup(void ** param, int param_no){
426 424
 			dp_par->v.id = dpid;
427 425
 		}else{
428 426
 			lstr.s = p; lstr.len = strlen(p);
429
-			if (pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
427
+			dp_par->v.sp[0] = pv_cache_get(&lstr);
428
+			if (dp_par->v.sp[0]==NULL)
430 429
 				goto error;
431 430
 
432 431
 			verify_par_type(param_no, dp_par->v.sp[0]);
... ...
@@ -442,16 +441,16 @@ static int dp_trans_fixup(void ** param, int param_no){
442 441
 		}
443 442
 
444 443
 		lstr.s = p; lstr.len = strlen(p);
445
-		if(pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
444
+		dp_par->v.sp[0] = pv_cache_get(&lstr);
445
+		if(dp_par->v.sp[0]==NULL)
446 446
 			goto error;
447 447
 
448 448
 		if (s != 0) {
449 449
 			lstr.s = s; lstr.len = strlen(s);
450
-			if (pv_parse_spec( &lstr, &dp_par->v.sp[1] )==NULL)
450
+			dp_par->v.sp[1] = pv_cache_get(&lstr);
451
+			if (dp_par->v.sp[1]==NULL)
451 452
 				goto error;
452 453
 			verify_par_type(param_no, dp_par->v.sp[1]);
453
-		} else {
454
-			dp_par->v.sp[1].type = PVT_NONE;
455 454
 		}
456 455
 
457 456
 		dp_par->type = DP_VAL_SPEC;
... ...
@@ -83,7 +83,7 @@ typedef struct dp_param{
83 83
 	int type;
84 84
 	union {
85 85
 		int id;
86
-		pv_spec_t sp[2];
86
+		pv_spec_t* sp[2];
87 87
 	} v;
88 88
 }dp_param_t, *dp_param_p;
89 89