Browse code

core: print cfg position for action's runtime error

Daniel-Constantin Mierla authored on 26/08/2009 08:50:25
Showing 1 changed files
... ...
@@ -150,6 +150,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
150 150
 						BUG("unexpected subtype %d in DROP_T\n",
151 151
 								a->val[0].type);
152 152
 						ret=0;
153
+						goto error;
153 154
 				}
154 155
 				h->run_flags|=(unsigned int)a->val[1].u.number;
155 156
 			break;
... ...
@@ -192,7 +193,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
192 192
 				if (ret<0) {
193 193
 					LOG(L_ERR, "ERROR: do_action: forward: bad_uri "
194 194
 								" dropping packet\n");
195
-					break;
195
+					goto error;
196 196
 				}
197 197
 
198 198
 				switch (a->val[1].type){
... ...
@@ -275,6 +276,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
275 275
 				LOG(L_CRIT, "BUG: do_action: bad forward() types %d, %d\n",
276 276
 						a->val[0].type, a->val[1].type);
277 277
 				ret=E_BUG;
278
+				goto error;
278 279
 			}
279 280
 			break;
280 281
 		case SEND_T:
... ...
@@ -283,7 +285,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
283 283
 				LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n",
284 284
 						a->val[0].type, a->val[1].type);
285 285
 				ret=E_BUG;
286
-				break;
286
+				goto error;
287 287
 			}
288 288
 			/* init dst */
289 289
 			init_dest_info(&dst);
... ...
@@ -316,7 +318,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
316 316
 #endif
317 317
 			}else{
318 318
 				ret=E_BUG;
319
-				break;
319
+				goto error;
320 320
 			}
321 321
 			proxy_mark((struct proxy_l*)a->val[0].u.data, ret);
322 322
 			if (ret>=0) ret=1;
... ...
@@ -327,7 +329,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
327 327
 				LOG(L_CRIT, "BUG: do_action: bad log() types %d, %d\n",
328 328
 						a->val[0].type, a->val[1].type);
329 329
 				ret=E_BUG;
330
-				break;
330
+				goto error;
331 331
 			}
332 332
 			LOG_(DEFAULT_FACILITY, a->val[0].u.number, "<script>: ", "%s", 
333 333
 				 a->val[1].u.string);
... ...
@@ -340,7 +342,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
340 340
 				LOG(L_CRIT, "BUG: do_action: bad append_branch_t %d\n",
341 341
 					a->val[0].type );
342 342
 				ret=E_BUG;
343
-				break;
343
+				goto error;
344 344
 			}
345 345
 			ret=append_branch( msg, a->val[0].u.string,
346 346
 					   a->val[0].u.string ? strlen(a->val[0].u.string):0,
... ...
@@ -353,7 +355,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
353 353
 				LOG(L_CRIT, "BUG: do_action: bad len_gt type %d\n",
354 354
 					a->val[0].type );
355 355
 				ret=E_BUG;
356
-				break;
356
+				goto error;
357 357
 			}
358 358
 			/* DBG("XXX: message length %d, max %d\n",
359 359
 				msg->len, a->val[0].u.number ); */
... ...
@@ -368,11 +370,11 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
368 368
 				LOG(L_CRIT, "BUG: do_action: bad setflag() type %d\n",
369 369
 					a->val[0].type );
370 370
 				ret=E_BUG;
371
-				break;
371
+				goto error;
372 372
 			}
373 373
 			if (!flag_in_range( a->val[0].u.number )) {
374 374
 				ret=E_CFG;
375
-				break;
375
+				goto error;
376 376
 			}
377 377
 			setflag( msg, a->val[0].u.number );
378 378
 			ret=1;
... ...
@@ -383,11 +385,11 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
383 383
 				LOG(L_CRIT, "BUG: do_action: bad resetflag() type %d\n",
384 384
 					a->val[0].type );
385 385
 				ret=E_BUG;
386
-				break;
386
+				goto error;
387 387
 			}
388 388
 			if (!flag_in_range( a->val[0].u.number )) {
389 389
 				ret=E_CFG;
390
-				break;
390
+				goto error;
391 391
 			}
392 392
 			resetflag( msg, a->val[0].u.number );
393 393
 			ret=1;
... ...
@@ -398,11 +400,11 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
398 398
 				LOG(L_CRIT, "BUG: do_action: bad isflagset() type %d\n",
399 399
 					a->val[0].type );
400 400
 				ret=E_BUG;
401
-				break;
401
+				goto error;
402 402
 			}
403 403
 			if (!flag_in_range( a->val[0].u.number )) {
404 404
 				ret=E_CFG;
405
-				break;
405
+				goto error;
406 406
 			}
407 407
 			ret=isflagset( msg, a->val[0].u.number );
408 408
 			break;
... ...
@@ -452,7 +454,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
452 452
 				LOG(L_CRIT, "BUG: do_action: bad error() types %d, %d\n",
453 453
 						a->val[0].type, a->val[1].type);
454 454
 				ret=E_BUG;
455
-				break;
455
+				goto error;
456 456
 			}
457 457
 			LOG(L_NOTICE, "WARNING: do_action: error(\"%s\", \"%s\") "
458 458
 					"not implemented yet\n", a->val[0].u.string, a->val[1].u.string);
... ...
@@ -463,13 +465,13 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
463 463
 				LOG(L_CRIT, "BUG: do_action: bad route() type %d\n",
464 464
 						a->val[0].type);
465 465
 				ret=E_BUG;
466
-				break;
466
+				goto error;
467 467
 			}
468 468
 			if ((a->val[0].u.number>=main_rt.idx)||(a->val[0].u.number<0)){
469 469
 				LOG(L_ERR, "ERROR: invalid routing table number in"
470 470
 							"route(%lu)\n", a->val[0].u.number);
471 471
 				ret=E_CFG;
472
-				break;
472
+				goto error;
473 473
 			}
474 474
 			/*ret=((ret=run_actions(rlist[a->val[0].u.number], msg))<0)?ret:1;*/
475 475
 			ret=run_actions(h, main_rt.rlist[a->val[0].u.number], msg);
... ...
@@ -482,7 +484,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
482 482
 				LOG(L_CRIT, "BUG: do_action: bad exec() type %d\n",
483 483
 						a->val[0].type);
484 484
 				ret=E_BUG;
485
-				break;
485
+				goto error;
486 486
 			}
487 487
 			LOG(L_NOTICE, "WARNING: exec(\"%s\") not fully implemented,"
488 488
 						" using dumb version...\n", a->val[0].u.string);
... ...
@@ -519,14 +521,14 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
519 519
 						LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
520 520
 							a->val[0].type);
521 521
 						ret=E_BUG;
522
-						break;
522
+						goto error;
523 523
 					}
524 524
 				} else if (a->type!=SET_USERPHONE_T) {
525 525
 					if (a->val[0].type!=STRING_ST) {
526 526
 						LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
527 527
 							a->val[0].type);
528 528
 						ret=E_BUG;
529
-						break;
529
+						goto error;
530 530
 					}
531 531
 				}
532 532
 				if (a->type==SET_URI_T){
... ...
@@ -541,7 +543,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
541 541
 						LOG(L_ERR, "ERROR: do_action: memory allocation"
542 542
 								" failure\n");
543 543
 						ret=E_OUT_OF_MEM;
544
-						break;
544
+						goto error;
545 545
 					}
546 546
 					memcpy(msg->new_uri.s, a->val[0].u.string, len);
547 547
 					msg->new_uri.s[len]=0;
... ...
@@ -562,7 +564,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
562 562
 						LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping"
563 563
 									" packet\n", tmp);
564 564
 						ret=E_UNSPEC;
565
-						break;
565
+						goto error;
566 566
 					}
567 567
 				} else {
568 568
 					uri=msg->parsed_uri;
... ...
@@ -584,7 +586,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
584 584
 				) {
585 585
 					LOG(L_ERR, "ERROR: do_action: port number of a tel: URI cannot be set\n");
586 586
 					ret=E_UNSPEC;
587
-					break;
587
+					goto error;
588 588
 				}
589 589
 
590 590
 				new_uri=pkg_malloc(MAX_URI_SIZE);
... ...
@@ -592,7 +594,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
592 592
 					LOG(L_ERR, "ERROR: do_action: memory allocation "
593 593
 								" failure\n");
594 594
 					ret=E_OUT_OF_MEM;
595
-					break;
595
+					goto error;
596 596
 				}
597 597
 				end=new_uri+MAX_URI_SIZE;
598 598
 				crt=new_uri;
... ...
@@ -862,6 +864,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
862 862
 				_last_returned_code = h->last_retcode;
863 863
 			} else {
864 864
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
865
+				goto error;
865 866
 			}
866 867
 			break;
867 868
 		/* instead of using the parameter number, we use different names
... ...
@@ -880,6 +883,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
880 880
 				_last_returned_code = h->last_retcode;
881 881
 			} else {
882 882
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
883
+				goto error;
883 884
 			}
884 885
 			break;
885 886
 		case MODULE4_T:
... ...
@@ -896,6 +900,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
896 896
 				_last_returned_code = h->last_retcode;
897 897
 			} else {
898 898
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
899
+				goto error;
899 900
 			}
900 901
 			break;
901 902
 		case MODULE5_T:
... ...
@@ -913,6 +918,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
913 913
 				_last_returned_code = h->last_retcode;
914 914
 			} else {
915 915
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
916
+				goto error;
916 917
 			}
917 918
 			break;
918 919
 		case MODULE6_T:
... ...
@@ -931,6 +937,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
931 931
 				_last_returned_code = h->last_retcode;
932 932
 			} else {
933 933
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
934
+				goto error;
934 935
 			}
935 936
 			break;
936 937
 		case MODULEX_T:
... ...
@@ -945,6 +952,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
945 945
 				_last_returned_code = h->last_retcode;
946 946
 			} else {
947 947
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
948
+				goto error;
948 949
 			}
949 950
 			break;
950 951
 		case EVAL_T:
... ...
@@ -1115,7 +1123,7 @@ match_cleanup:
1115 1115
 								rve->fpos.s_line, rve->fpos.s_col,
1116 1116
 								cfg_get(core, core_cfg, max_while_loops));
1117 1117
 					ret=-1;
1118
-					break;
1118
+					goto error;
1119 1119
 				}
1120 1120
 				if (likely(a->val[1].u.data)){
1121 1121
 					ret=run_actions(h, (struct action*)a->val[1].u.data, msg);
... ...
@@ -1142,7 +1150,7 @@ match_cleanup:
1142 1142
 				LOG(L_CRIT, "BUG: do_action: bad set_advertised_address() "
1143 1143
 						"type %d\n", a->val[0].type);
1144 1144
 				ret=E_BUG;
1145
-				break;
1145
+				goto error;
1146 1146
 			}
1147 1147
 			msg->set_global_address=*((str*)a->val[0].u.data);
1148 1148
 			ret=1; /* continue processing */
... ...
@@ -1152,7 +1160,7 @@ match_cleanup:
1152 1152
 				LOG(L_CRIT, "BUG: do_action: bad set_advertised_port() "
1153 1153
 						"type %d\n", a->val[0].type);
1154 1154
 				ret=E_BUG;
1155
-				break;
1155
+				goto error;
1156 1156
 			}
1157 1157
 			msg->set_global_port=*((str*)a->val[0].u.data);
1158 1158
 			ret=1; /* continue processing */
... ...
@@ -1171,14 +1179,14 @@ match_cleanup:
1171 1171
 					LOG(L_CRIT, "BUG: do_action: bad force_tcp_alias"
1172 1172
 							" port type %d\n", a->val[0].type);
1173 1173
 					ret=E_BUG;
1174
-					break;
1174
+					goto error;
1175 1175
 				}
1176 1176
 
1177 1177
 				if (tcpconn_add_alias(msg->rcv.proto_reserved1, port,
1178 1178
 									msg->rcv.proto)!=0){
1179 1179
 					LOG(L_ERR, " ERROR: receive_msg: tcp alias failed\n");
1180 1180
 					ret=E_UNSPEC;
1181
-					break;
1181
+					goto error;
1182 1182
 				}
1183 1183
 			}
1184 1184
 #endif
... ...
@@ -1189,7 +1197,7 @@ match_cleanup:
1189 1189
 				LOG(L_CRIT, "BUG: do_action: bad force_send_socket argument"
1190 1190
 						" type: %d\n", a->val[0].type);
1191 1191
 				ret=E_BUG;
1192
-				break;
1192
+				goto error;
1193 1193
 			}
1194 1194
 			msg->force_send_socket=(struct socket_info*)a->val[0].u.data;
1195 1195
 			ret=1; /* continue processing */
... ...
@@ -1217,9 +1225,12 @@ skip:
1217 1217
 error_uri:
1218 1218
 	LOG(L_ERR, "ERROR: do_action: set*: uri too long\n");
1219 1219
 	if (new_uri) pkg_free(new_uri);
1220
+	LM_ERR("run action error at: %s:%d\n", (a->cfile)?a->cfile:"", a->cline);
1220 1221
 	return E_UNSPEC;
1221 1222
 error_fwd_uri:
1222 1223
 	/*free_uri(&uri); -- not needed anymore, using msg->parsed_uri*/
1224
+error:
1225
+	LM_ERR("run action error at: %s:%d\n", (a->cfile)?a->cfile:"", a->cline);
1223 1226
 	return ret;
1224 1227
 }
1225 1228