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 193
 				if (ret<0) {
193 194
 					LOG(L_ERR, "ERROR: do_action: forward: bad_uri "
194 195
 								" dropping packet\n");
195
-					break;
196
+					goto error;
196 197
 				}
197 198
 
198 199
 				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 276
 				LOG(L_CRIT, "BUG: do_action: bad forward() types %d, %d\n",
276 277
 						a->val[0].type, a->val[1].type);
277 278
 				ret=E_BUG;
279
+				goto error;
278 280
 			}
279 281
 			break;
280 282
 		case SEND_T:
... ...
@@ -283,7 +285,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
283 285
 				LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n",
284 286
 						a->val[0].type, a->val[1].type);
285 287
 				ret=E_BUG;
286
-				break;
288
+				goto error;
287 289
 			}
288 290
 			/* init dst */
289 291
 			init_dest_info(&dst);
... ...
@@ -316,7 +318,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
316 318
 #endif
317 319
 			}else{
318 320
 				ret=E_BUG;
319
-				break;
321
+				goto error;
320 322
 			}
321 323
 			proxy_mark((struct proxy_l*)a->val[0].u.data, ret);
322 324
 			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 329
 				LOG(L_CRIT, "BUG: do_action: bad log() types %d, %d\n",
328 330
 						a->val[0].type, a->val[1].type);
329 331
 				ret=E_BUG;
330
-				break;
332
+				goto error;
331 333
 			}
332 334
 			LOG_(DEFAULT_FACILITY, a->val[0].u.number, "<script>: ", "%s", 
333 335
 				 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 342
 				LOG(L_CRIT, "BUG: do_action: bad append_branch_t %d\n",
341 343
 					a->val[0].type );
342 344
 				ret=E_BUG;
343
-				break;
345
+				goto error;
344 346
 			}
345 347
 			ret=append_branch( msg, a->val[0].u.string,
346 348
 					   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 355
 				LOG(L_CRIT, "BUG: do_action: bad len_gt type %d\n",
354 356
 					a->val[0].type );
355 357
 				ret=E_BUG;
356
-				break;
358
+				goto error;
357 359
 			}
358 360
 			/* DBG("XXX: message length %d, max %d\n",
359 361
 				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 370
 				LOG(L_CRIT, "BUG: do_action: bad setflag() type %d\n",
369 371
 					a->val[0].type );
370 372
 				ret=E_BUG;
371
-				break;
373
+				goto error;
372 374
 			}
373 375
 			if (!flag_in_range( a->val[0].u.number )) {
374 376
 				ret=E_CFG;
375
-				break;
377
+				goto error;
376 378
 			}
377 379
 			setflag( msg, a->val[0].u.number );
378 380
 			ret=1;
... ...
@@ -383,11 +385,11 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
383 385
 				LOG(L_CRIT, "BUG: do_action: bad resetflag() type %d\n",
384 386
 					a->val[0].type );
385 387
 				ret=E_BUG;
386
-				break;
388
+				goto error;
387 389
 			}
388 390
 			if (!flag_in_range( a->val[0].u.number )) {
389 391
 				ret=E_CFG;
390
-				break;
392
+				goto error;
391 393
 			}
392 394
 			resetflag( msg, a->val[0].u.number );
393 395
 			ret=1;
... ...
@@ -398,11 +400,11 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
398 400
 				LOG(L_CRIT, "BUG: do_action: bad isflagset() type %d\n",
399 401
 					a->val[0].type );
400 402
 				ret=E_BUG;
401
-				break;
403
+				goto error;
402 404
 			}
403 405
 			if (!flag_in_range( a->val[0].u.number )) {
404 406
 				ret=E_CFG;
405
-				break;
407
+				goto error;
406 408
 			}
407 409
 			ret=isflagset( msg, a->val[0].u.number );
408 410
 			break;
... ...
@@ -452,7 +454,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
452 454
 				LOG(L_CRIT, "BUG: do_action: bad error() types %d, %d\n",
453 455
 						a->val[0].type, a->val[1].type);
454 456
 				ret=E_BUG;
455
-				break;
457
+				goto error;
456 458
 			}
457 459
 			LOG(L_NOTICE, "WARNING: do_action: error(\"%s\", \"%s\") "
458 460
 					"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 465
 				LOG(L_CRIT, "BUG: do_action: bad route() type %d\n",
464 466
 						a->val[0].type);
465 467
 				ret=E_BUG;
466
-				break;
468
+				goto error;
467 469
 			}
468 470
 			if ((a->val[0].u.number>=main_rt.idx)||(a->val[0].u.number<0)){
469 471
 				LOG(L_ERR, "ERROR: invalid routing table number in"
470 472
 							"route(%lu)\n", a->val[0].u.number);
471 473
 				ret=E_CFG;
472
-				break;
474
+				goto error;
473 475
 			}
474 476
 			/*ret=((ret=run_actions(rlist[a->val[0].u.number], msg))<0)?ret:1;*/
475 477
 			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 484
 				LOG(L_CRIT, "BUG: do_action: bad exec() type %d\n",
483 485
 						a->val[0].type);
484 486
 				ret=E_BUG;
485
-				break;
487
+				goto error;
486 488
 			}
487 489
 			LOG(L_NOTICE, "WARNING: exec(\"%s\") not fully implemented,"
488 490
 						" 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 521
 						LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
520 522
 							a->val[0].type);
521 523
 						ret=E_BUG;
522
-						break;
524
+						goto error;
523 525
 					}
524 526
 				} else if (a->type!=SET_USERPHONE_T) {
525 527
 					if (a->val[0].type!=STRING_ST) {
526 528
 						LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
527 529
 							a->val[0].type);
528 530
 						ret=E_BUG;
529
-						break;
531
+						goto error;
530 532
 					}
531 533
 				}
532 534
 				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 543
 						LOG(L_ERR, "ERROR: do_action: memory allocation"
542 544
 								" failure\n");
543 545
 						ret=E_OUT_OF_MEM;
544
-						break;
546
+						goto error;
545 547
 					}
546 548
 					memcpy(msg->new_uri.s, a->val[0].u.string, len);
547 549
 					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 564
 						LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping"
563 565
 									" packet\n", tmp);
564 566
 						ret=E_UNSPEC;
565
-						break;
567
+						goto error;
566 568
 					}
567 569
 				} else {
568 570
 					uri=msg->parsed_uri;
... ...
@@ -584,7 +586,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
584 586
 				) {
585 587
 					LOG(L_ERR, "ERROR: do_action: port number of a tel: URI cannot be set\n");
586 588
 					ret=E_UNSPEC;
587
-					break;
589
+					goto error;
588 590
 				}
589 591
 
590 592
 				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 594
 					LOG(L_ERR, "ERROR: do_action: memory allocation "
593 595
 								" failure\n");
594 596
 					ret=E_OUT_OF_MEM;
595
-					break;
597
+					goto error;
596 598
 				}
597 599
 				end=new_uri+MAX_URI_SIZE;
598 600
 				crt=new_uri;
... ...
@@ -862,6 +864,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
862 864
 				_last_returned_code = h->last_retcode;
863 865
 			} else {
864 866
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
867
+				goto error;
865 868
 			}
866 869
 			break;
867 870
 		/* 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 883
 				_last_returned_code = h->last_retcode;
881 884
 			} else {
882 885
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
886
+				goto error;
883 887
 			}
884 888
 			break;
885 889
 		case MODULE4_T:
... ...
@@ -896,6 +900,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
896 900
 				_last_returned_code = h->last_retcode;
897 901
 			} else {
898 902
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
903
+				goto error;
899 904
 			}
900 905
 			break;
901 906
 		case MODULE5_T:
... ...
@@ -913,6 +918,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
913 918
 				_last_returned_code = h->last_retcode;
914 919
 			} else {
915 920
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
921
+				goto error;
916 922
 			}
917 923
 			break;
918 924
 		case MODULE6_T:
... ...
@@ -931,6 +937,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
931 937
 				_last_returned_code = h->last_retcode;
932 938
 			} else {
933 939
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
940
+				goto error;
934 941
 			}
935 942
 			break;
936 943
 		case MODULEX_T:
... ...
@@ -945,6 +952,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
945 952
 				_last_returned_code = h->last_retcode;
946 953
 			} else {
947 954
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
955
+				goto error;
948 956
 			}
949 957
 			break;
950 958
 		case EVAL_T:
... ...
@@ -1115,7 +1123,7 @@ match_cleanup:
1115 1123
 								rve->fpos.s_line, rve->fpos.s_col,
1116 1124
 								cfg_get(core, core_cfg, max_while_loops));
1117 1125
 					ret=-1;
1118
-					break;
1126
+					goto error;
1119 1127
 				}
1120 1128
 				if (likely(a->val[1].u.data)){
1121 1129
 					ret=run_actions(h, (struct action*)a->val[1].u.data, msg);
... ...
@@ -1142,7 +1150,7 @@ match_cleanup:
1142 1150
 				LOG(L_CRIT, "BUG: do_action: bad set_advertised_address() "
1143 1151
 						"type %d\n", a->val[0].type);
1144 1152
 				ret=E_BUG;
1145
-				break;
1153
+				goto error;
1146 1154
 			}
1147 1155
 			msg->set_global_address=*((str*)a->val[0].u.data);
1148 1156
 			ret=1; /* continue processing */
... ...
@@ -1152,7 +1160,7 @@ match_cleanup:
1152 1160
 				LOG(L_CRIT, "BUG: do_action: bad set_advertised_port() "
1153 1161
 						"type %d\n", a->val[0].type);
1154 1162
 				ret=E_BUG;
1155
-				break;
1163
+				goto error;
1156 1164
 			}
1157 1165
 			msg->set_global_port=*((str*)a->val[0].u.data);
1158 1166
 			ret=1; /* continue processing */
... ...
@@ -1171,14 +1179,14 @@ match_cleanup:
1171 1179
 					LOG(L_CRIT, "BUG: do_action: bad force_tcp_alias"
1172 1180
 							" port type %d\n", a->val[0].type);
1173 1181
 					ret=E_BUG;
1174
-					break;
1182
+					goto error;
1175 1183
 				}
1176 1184
 
1177 1185
 				if (tcpconn_add_alias(msg->rcv.proto_reserved1, port,
1178 1186
 									msg->rcv.proto)!=0){
1179 1187
 					LOG(L_ERR, " ERROR: receive_msg: tcp alias failed\n");
1180 1188
 					ret=E_UNSPEC;
1181
-					break;
1189
+					goto error;
1182 1190
 				}
1183 1191
 			}
1184 1192
 #endif
... ...
@@ -1189,7 +1197,7 @@ match_cleanup:
1189 1197
 				LOG(L_CRIT, "BUG: do_action: bad force_send_socket argument"
1190 1198
 						" type: %d\n", a->val[0].type);
1191 1199
 				ret=E_BUG;
1192
-				break;
1200
+				goto error;
1193 1201
 			}
1194 1202
 			msg->force_send_socket=(struct socket_info*)a->val[0].u.data;
1195 1203
 			ret=1; /* continue processing */
... ...
@@ -1217,9 +1225,12 @@ skip:
1217 1225
 error_uri:
1218 1226
 	LOG(L_ERR, "ERROR: do_action: set*: uri too long\n");
1219 1227
 	if (new_uri) pkg_free(new_uri);
1228
+	LM_ERR("run action error at: %s:%d\n", (a->cfile)?a->cfile:"", a->cline);
1220 1229
 	return E_UNSPEC;
1221 1230
 error_fwd_uri:
1222 1231
 	/*free_uri(&uri); -- not needed anymore, using msg->parsed_uri*/
1232
+error:
1233
+	LM_ERR("run action error at: %s:%d\n", (a->cfile)?a->cfile:"", a->cline);
1223 1234
 	return ret;
1224 1235
 }
1225 1236