00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "action.h"
00052 #include "config.h"
00053 #include "error.h"
00054 #include "dprint.h"
00055 #include "proxy.h"
00056 #include "forward.h"
00057 #include "udp_server.h"
00058 #include "route.h"
00059 #include "parser/msg_parser.h"
00060 #include "parser/parse_uri.h"
00061 #include "ut.h"
00062 #include "sr_module.h"
00063 #include "mem/mem.h"
00064 #include "globals.h"
00065 #include "dset.h"
00066 #include "flags.h"
00067 #include "errinfo.h"
00068 #include "blacklists.h"
00069 #ifdef USE_TCP
00070 #include "tcp_server.h"
00071 #endif
00072
00073 #include <sys/types.h>
00074 #include <sys/socket.h>
00075 #include <netdb.h>
00076 #include <stdlib.h>
00077 #include <netinet/in.h>
00078 #include <arpa/inet.h>
00079 #include <string.h>
00080
00081 #ifdef DEBUG_DMALLOC
00082 #include <dmalloc.h>
00083 #endif
00084
00085 int action_flags = 0;
00086 int return_code = 0;
00087 int max_while_loops = 100;
00088
00089 static int rec_lev=0;
00090
00091 extern err_info_t _oser_err_info;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 static inline int run_actions(struct action* a, struct sip_msg* msg)
00102 {
00103 int ret;
00104
00105 rec_lev++;
00106 if (rec_lev>ROUTE_MAX_REC_LEV){
00107 LM_ERR("too many recursive routing table lookups (%d) giving up!\n",
00108 rec_lev);
00109 ret=E_UNSPEC;
00110 goto error;
00111 }
00112
00113 if (a==0){
00114 LM_WARN("null action list (rec_level=%d)\n",
00115 rec_lev);
00116 ret=1;
00117 goto error;
00118 }
00119
00120 ret=run_action_list(a, msg);
00121
00122
00123 if(action_flags&ACT_FL_RETURN)
00124 action_flags &= ~ACT_FL_RETURN;
00125
00126 rec_lev--;
00127 return ret;
00128
00129 error:
00130 rec_lev--;
00131 return ret;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 int run_action_list(struct action* a, struct sip_msg* msg)
00141 {
00142 int ret=E_UNSPEC;
00143 struct action* t;
00144 for (t=a; t!=0; t=t->next){
00145 ret=do_action(t, msg);
00146
00147 if(ret==0)
00148 action_flags |= ACT_FL_EXIT;
00149 #ifndef USE_LOCAL_ROUTE
00150 if(error_rlist!=NULL && !is_route_type(ERROR_ROUTE)
00151 && !is_route_type(ONREPLY_ROUTE)
00152 #else
00153 if(error_rlist!=NULL &&
00154 (route_type&(ERROR_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE))==0
00155 #endif
00156 && _oser_err_info.eclass!=0)
00157
00158 {
00159 LM_DBG("jumping to error route\n");
00160 set_route_type( ERROR_ROUTE );
00161 run_actions(error_rlist, msg);
00162
00163 if(!(action_flags&ACT_FL_EXIT))
00164 init_err_info();
00165 }
00166
00167 if((action_flags&ACT_FL_RETURN) || (action_flags&ACT_FL_EXIT))
00168 break;
00169 }
00170 return ret;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 int run_top_route(struct action* a, struct sip_msg* msg)
00180 {
00181 int bk_action_flags;
00182 int bk_rec_lev;
00183 int ret;
00184
00185 bk_action_flags = action_flags;
00186 bk_rec_lev = rec_lev;
00187
00188 action_flags = 0;
00189 rec_lev = 0;
00190 init_err_info();
00191 reset_bl_markers();
00192
00193 resetsflag( (unsigned int)-1 );
00194
00195 run_actions(a, msg);
00196 ret = action_flags;
00197
00198 action_flags = bk_action_flags;
00199 rec_lev = bk_rec_lev;
00200
00201 return ret;
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 int do_assign(struct sip_msg* msg, struct action* a)
00212 {
00213 int ret;
00214 pv_value_t val;
00215 pv_spec_p dspec;
00216
00217 ret = -1;
00218 dspec = (pv_spec_p)a->elem[0].u.data;
00219 if(!pv_is_w(dspec))
00220 {
00221 LM_ERR("read only PV in left expression\n");
00222 goto error;
00223 }
00224
00225 memset(&val, 0, sizeof(pv_value_t));
00226 if(a->elem[1].type != NULLV_ST)
00227 {
00228 ret = eval_expr((struct expr*)a->elem[1].u.data, msg, &val);
00229 if(!((val.flags&PV_VAL_STR)||(val.flags&PV_VAL_INT))) {
00230 LM_ERR("no value in right expression\n");
00231 goto error;
00232 }
00233 }
00234
00235 switch ((unsigned char)a->type){
00236 case EQ_T:
00237 case COLONEQ_T:
00238 case PLUSEQ_T:
00239 case MINUSEQ_T:
00240 case DIVEQ_T:
00241 case MULTEQ_T:
00242 case MODULOEQ_T:
00243 case BANDEQ_T:
00244 case BOREQ_T:
00245 case BXOREQ_T:
00246 if(a->elem[1].type == NULLV_ST)
00247 {
00248 if(pv_set_spec_value(msg, dspec, (int)a->type, 0)<0)
00249 {
00250 LM_ERR("setting PV failed\n");
00251 goto error;
00252 }
00253 } else {
00254 if(pv_set_spec_value(msg, dspec, (int)a->type, &val)<0)
00255 {
00256 LM_ERR("setting PV failed\n");
00257 goto error;
00258 }
00259 }
00260 ret = 1;
00261 break;
00262 default:
00263 LM_ALERT("BUG -> unknown op type %d\n", a->type);
00264 goto error;
00265 }
00266
00267 pv_value_destroy(&val);
00268 return ret;
00269
00270 error:
00271 LM_ERR("error at line: %d\n", a->line);
00272 pv_value_destroy(&val);
00273 return -1;
00274 }
00275
00276
00277
00278
00279
00280
00281
00282 int do_action(struct action* a, struct sip_msg* msg)
00283 {
00284 int ret;
00285 int v;
00286 union sockaddr_union* to;
00287 struct proxy_l* p;
00288 char* tmp;
00289 char *new_uri, *end, *crt;
00290 int len;
00291 int user;
00292 struct sip_uri uri, next_hop;
00293 struct sip_uri *u;
00294 unsigned short port;
00295 int cmatch;
00296 struct action *aitem;
00297 struct action *adefault;
00298 pv_spec_t *spec;
00299 pv_elem_p model;
00300 pv_value_t val;
00301
00302
00303
00304
00305
00306 prev_ser_error=ser_error;
00307 ser_error=E_UNSPEC;
00308
00309 ret=E_BUG;
00310 switch ((unsigned char)a->type){
00311 case DROP_T:
00312 action_flags |= ACT_FL_DROP;
00313 case EXIT_T:
00314 ret=0;
00315 action_flags |= ACT_FL_EXIT;
00316 break;
00317 case RETURN_T:
00318 if (a->elem[0].type == SCRIPTVAR_ST)
00319 {
00320 spec = (pv_spec_t*)a->elem[0].u.data;
00321 if(pv_get_spec_value(msg, spec, &val)!=0
00322 || (val.flags&PV_VAL_NULL))
00323 {
00324 ret=-1;
00325 } else {
00326 if(!(val.flags&PV_VAL_INT))
00327 ret = 1;
00328 else
00329 ret = val.ri;
00330 }
00331 pv_value_destroy(&val);
00332 } else {
00333 ret=a->elem[0].u.number;
00334 }
00335 action_flags |= ACT_FL_RETURN;
00336 break;
00337 case FORWARD_T:
00338 if (a->elem[0].type==NOSUBTYPE){
00339
00340 if (msg->dst_uri.len) {
00341 ret = parse_uri(msg->dst_uri.s, msg->dst_uri.len,
00342 &next_hop);
00343 u = &next_hop;
00344 } else {
00345 ret = parse_sip_msg_uri(msg);
00346 u = &msg->parsed_uri;
00347 }
00348 if (ret<0) {
00349 LM_ERR("forward: bad_uri dropping packet\n");
00350 break;
00351 }
00352
00353 p=mk_proxy(&u->host, u->port_no, u->proto,
00354 (u->type==SIPS_URI_T)?1:0 );
00355 if (p==0){
00356 LM_ERR("bad host name in uri, dropping packet\n");
00357 ret=E_BAD_ADDRESS;
00358 goto error_fwd_uri;
00359 }
00360 ret=forward_request(msg, p);
00361 free_proxy(p);
00362 pkg_free(p);
00363 if (ret==0) ret=1;
00364 }else if ((a->elem[0].type==PROXY_ST)) {
00365 ret=forward_request(msg,(struct proxy_l*)a->elem[0].u.data);
00366 if (ret==0) ret=1;
00367 }else{
00368 LM_ALERT("BUG in forward() types %d, %d\n",
00369 a->elem[0].type, a->elem[1].type);
00370 ret=E_BUG;
00371 }
00372 break;
00373 case SEND_T:
00374 if (a->elem[0].type!= PROXY_ST){
00375 LM_ALERT("BUG in send() type %d\n", a->elem[0].type);
00376 ret=E_BUG;
00377 break;
00378 }
00379 to=(union sockaddr_union*)
00380 pkg_malloc(sizeof(union sockaddr_union));
00381 if (to==0){
00382 LM_ERR("memory allocation failure\n");
00383 ret=E_OUT_OF_MEM;
00384 break;
00385 }
00386
00387 p=(struct proxy_l*)a->elem[0].u.data;
00388
00389 ret=hostent2su(to, &p->host, p->addr_idx,
00390 (p->port)?p->port:SIP_PORT );
00391 if (ret==0){
00392 ret = msg_send(0, p->proto, to, 0,
00393 msg->buf, msg->len);
00394 if (ret!=0 && p->host.h_addr_list[p->addr_idx+1])
00395 p->addr_idx++;
00396 }
00397 pkg_free(to);
00398 if (ret==0)
00399 ret=1;
00400 break;
00401 case LOG_T:
00402 if ((a->elem[0].type!=NUMBER_ST)|(a->elem[1].type!=STRING_ST)){
00403 LM_ALERT("BUG in log() types %d, %d\n",
00404 a->elem[0].type, a->elem[1].type);
00405 ret=E_BUG;
00406 break;
00407 }
00408 LM_GEN1(a->elem[0].u.number, "%s", a->elem[1].u.string);
00409 ret=1;
00410 break;
00411 case APPEND_BRANCH_T:
00412
00413 if ((a->elem[0].type!=STRING_ST)) {
00414 LM_ALERT("BUG in append_branch %d\n",
00415 a->elem[0].type );
00416 ret=E_BUG;
00417 break;
00418 }
00419 if (a->elem[0].u.s.s==NULL) {
00420 ret = append_branch(msg, 0, &msg->dst_uri, &msg->path_vec,
00421 a->elem[1].u.number, getb0flags(), msg->force_send_socket);
00422
00423 msg->force_send_socket = 0;
00424 setb0flags(0);
00425 if(msg->dst_uri.s!=0)
00426 pkg_free(msg->dst_uri.s);
00427 msg->dst_uri.s = 0;
00428 msg->dst_uri.len = 0;
00429 if(msg->path_vec.s!=0)
00430 pkg_free(msg->path_vec.s);
00431 msg->path_vec.s = 0;
00432 msg->path_vec.len = 0;
00433 } else {
00434 ret = append_branch(msg, &a->elem[0].u.s, &msg->dst_uri,
00435 &msg->path_vec, a->elem[1].u.number, getb0flags(),
00436 msg->force_send_socket);
00437 }
00438 break;
00439 case LEN_GT_T:
00440 if (a->elem[0].type!=NUMBER_ST) {
00441 LM_ALERT("BUG in len_gt type %d\n",
00442 a->elem[0].type );
00443 ret=E_BUG;
00444 break;
00445 }
00446 ret = (msg->len >= (unsigned int)a->elem[0].u.number) ? 1 : -1;
00447 break;
00448 case SET_DEBUG_T:
00449 if (a->elem[0].type==NUMBER_ST)
00450 set_proc_debug_level(a->elem[0].u.number);
00451 else
00452 reset_proc_debug_level();
00453 ret = 1;
00454 break;
00455 case SETFLAG_T:
00456 ret = setflag( msg, a->elem[0].u.number );
00457 break;
00458 case RESETFLAG_T:
00459 ret = resetflag( msg, a->elem[0].u.number );
00460 break;
00461 case ISFLAGSET_T:
00462 ret = isflagset( msg, a->elem[0].u.number );
00463 break;
00464 case SETSFLAG_T:
00465 ret = setsflag( a->elem[0].u.number );
00466 break;
00467 case RESETSFLAG_T:
00468 ret = resetsflag( a->elem[0].u.number );
00469 break;
00470 case ISSFLAGSET_T:
00471 ret = issflagset( a->elem[0].u.number );
00472 break;
00473 case SETBFLAG_T:
00474 ret = setbflag( a->elem[0].u.number, a->elem[1].u.number );
00475 break;
00476 case RESETBFLAG_T:
00477 ret = resetbflag( a->elem[0].u.number, a->elem[1].u.number );
00478 break;
00479 case ISBFLAGSET_T:
00480 ret = isbflagset( a->elem[0].u.number, a->elem[1].u.number );
00481 break;
00482 case ERROR_T:
00483 if ((a->elem[0].type!=STRING_ST)|(a->elem[1].type!=STRING_ST)){
00484 LM_ALERT("BUG in error() types %d, %d\n",
00485 a->elem[0].type, a->elem[1].type);
00486 ret=E_BUG;
00487 break;
00488 }
00489 LM_ERR("error(\"%s\", \"%s\") not implemented yet\n",
00490 a->elem[0].u.string, a->elem[1].u.string);
00491 ret=1;
00492 break;
00493 case ROUTE_T:
00494 if (a->elem[0].type!=NUMBER_ST){
00495 LM_ALERT("BUG in route() type %d\n",
00496 a->elem[0].type);
00497 ret=E_BUG;
00498 break;
00499 }
00500 if ((a->elem[0].u.number>RT_NO)||(a->elem[0].u.number<0)){
00501 LM_ALERT("BUG - invalid routing table number in"
00502 "route(%lu)\n", a->elem[0].u.number);
00503 ret=E_CFG;
00504 break;
00505 }
00506 return_code=run_actions(rlist[a->elem[0].u.number], msg);
00507 ret=return_code;
00508 break;
00509 case REVERT_URI_T:
00510 if (msg->new_uri.s) {
00511 pkg_free(msg->new_uri.s);
00512 msg->new_uri.len=0;
00513 msg->new_uri.s=0;
00514 msg->parsed_uri_ok=0;
00515 };
00516 ret=1;
00517 break;
00518 case SET_HOST_T:
00519 case SET_HOSTPORT_T:
00520 case SET_HOSTALL_T:
00521 case SET_USER_T:
00522 case SET_USERPASS_T:
00523 case SET_PORT_T:
00524 case SET_URI_T:
00525 case PREFIX_T:
00526 case STRIP_T:
00527 case STRIP_TAIL_T:
00528 user=0;
00529 if (a->type==STRIP_T || a->type==STRIP_TAIL_T) {
00530 if (a->elem[0].type!=NUMBER_ST) {
00531 LM_ALERT("BUG in set*() type %d\n",
00532 a->elem[0].type);
00533 break;
00534 }
00535 } else if (a->elem[0].type!=STRING_ST){
00536 LM_ALERT("BUG in set*() type %d\n",
00537 a->elem[0].type);
00538 ret=E_BUG;
00539 break;
00540 }
00541 if (a->type==SET_URI_T){
00542 if (msg->new_uri.s) {
00543 pkg_free(msg->new_uri.s);
00544 msg->new_uri.len=0;
00545 }
00546 msg->parsed_uri_ok=0;
00547 len=strlen(a->elem[0].u.string);
00548 msg->new_uri.s=pkg_malloc(len+1);
00549 if (msg->new_uri.s==0){
00550 LM_ERR("memory allocation failure\n");
00551 ret=E_OUT_OF_MEM;
00552 break;
00553 }
00554 memcpy(msg->new_uri.s, a->elem[0].u.string, len);
00555 msg->new_uri.s[len]=0;
00556 msg->new_uri.len=len;
00557
00558 ret=1;
00559 break;
00560 }
00561 if (msg->new_uri.s) {
00562 tmp=msg->new_uri.s;
00563 len=msg->new_uri.len;
00564 }else{
00565 tmp=msg->first_line.u.request.uri.s;
00566 len=msg->first_line.u.request.uri.len;
00567 }
00568 if (parse_uri(tmp, len, &uri)<0){
00569 LM_ERR("bad uri <%s>, dropping packet\n", tmp);
00570 ret=E_UNSPEC;
00571 break;
00572 }
00573
00574 new_uri=pkg_malloc(MAX_URI_SIZE);
00575 if (new_uri==0){
00576 LM_ERR("memory allocation failure\n");
00577 ret=E_OUT_OF_MEM;
00578 break;
00579 }
00580 end=new_uri+MAX_URI_SIZE;
00581 crt=new_uri;
00582
00583 len=strlen("sip:"); if(crt+len>end) goto error_uri;
00584 memcpy(crt,"sip:",len);crt+=len;
00585
00586 if (a->type==PREFIX_T) {
00587 tmp=a->elem[0].u.string;
00588 len=strlen(tmp); if(crt+len>end) goto error_uri;
00589 memcpy(crt,tmp,len);crt+=len;
00590
00591
00592 user=1;
00593 }
00594
00595 if ((a->type==SET_USER_T)||(a->type==SET_USERPASS_T)) {
00596 tmp=a->elem[0].u.string;
00597 len=strlen(tmp);
00598 } else if (a->type==STRIP_T) {
00599 if (a->elem[0].u.number>uri.user.len) {
00600 LM_WARN("too long strip asked; "
00601 " deleting username: %lu of <%.*s>\n",
00602 a->elem[0].u.number, uri.user.len, uri.user.s);
00603 len=0;
00604 } else if (a->elem[0].u.number==uri.user.len) {
00605 len=0;
00606 } else {
00607 tmp=uri.user.s + a->elem[0].u.number;
00608 len=uri.user.len - a->elem[0].u.number;
00609 }
00610 } else if (a->type==STRIP_TAIL_T) {
00611 if (a->elem[0].u.number>uri.user.len) {
00612 LM_WARN("too long strip_tail asked;"
00613 " deleting username: %lu of <%.*s>\n",
00614 a->elem[0].u.number, uri.user.len, uri.user.s);
00615 len=0;
00616 } else if (a->elem[0].u.number==uri.user.len) {
00617 len=0;
00618 } else {
00619 tmp=uri.user.s;
00620 len=uri.user.len - a->elem[0].u.number;
00621 }
00622 } else {
00623 tmp=uri.user.s;
00624 len=uri.user.len;
00625 }
00626
00627 if (len){
00628 if(crt+len>end) goto error_uri;
00629 memcpy(crt,tmp,len);crt+=len;
00630 user=1;
00631 }
00632
00633 if (a->type==SET_USERPASS_T) tmp=0;
00634 else tmp=uri.passwd.s;
00635
00636 if (tmp){
00637 len=uri.passwd.len; if(crt+len+1>end) goto error_uri;
00638 *crt=':'; crt++;
00639 memcpy(crt,tmp,len);crt+=len;
00640 }
00641
00642 if (user || tmp){
00643 if(crt+1>end) goto error_uri;
00644 *crt='@'; crt++;
00645 }
00646 if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)
00647 || (a->type==SET_HOSTALL_T)) {
00648 tmp=a->elem[0].u.string;
00649 if (tmp) len = strlen(tmp);
00650 else len=0;
00651 } else {
00652 tmp=uri.host.s;
00653 len = uri.host.len;
00654 }
00655 if (tmp){
00656 if(crt+len>end) goto error_uri;
00657 memcpy(crt,tmp,len);crt+=len;
00658 }
00659 if(a->type==SET_HOSTALL_T)
00660 goto done_seturi;
00661
00662
00663 if (a->type==SET_HOSTPORT_T) tmp=0;
00664 else if (a->type==SET_PORT_T) {
00665 tmp=a->elem[0].u.string;
00666 if (tmp) len = strlen(tmp);
00667 else len = 0;
00668 } else {
00669 tmp=uri.port.s;
00670 len = uri.port.len;
00671 }
00672 if (tmp && len>0){
00673 if(crt+len+1>end) goto error_uri;
00674 *crt=':'; crt++;
00675 memcpy(crt,tmp,len);crt+=len;
00676 }
00677
00678 tmp=uri.params.s;
00679 if (tmp){
00680 len=uri.params.len; if(crt+len+1>end) goto error_uri;
00681 *crt=';'; crt++;
00682 memcpy(crt,tmp,len);crt+=len;
00683 }
00684
00685 tmp=uri.headers.s;
00686 if (tmp){
00687 len=uri.headers.len; if(crt+len+1>end) goto error_uri;
00688 *crt='?'; crt++;
00689 memcpy(crt,tmp,len);crt+=len;
00690 }
00691 done_seturi:
00692 *crt=0;
00693
00694 if (msg->new_uri.s) pkg_free(msg->new_uri.s);
00695 msg->new_uri.s=new_uri;
00696 msg->new_uri.len=crt-new_uri;
00697 msg->parsed_uri_ok=0;
00698 ret=1;
00699 break;
00700 case SET_DSTURI_T:
00701
00702 if (a->elem[0].type!=STRING_ST){
00703 LM_ALERT("BUG in setdsturi() type %d\n",
00704 a->elem[0].type);
00705 ret=E_BUG;
00706 break;
00707 }
00708 if(set_dst_uri(msg, &a->elem[0].u.s)!=0)
00709 ret = -1;
00710 else
00711 ret = 1;
00712 break;
00713 case RESET_DSTURI_T:
00714 if(msg->dst_uri.s!=0)
00715 pkg_free(msg->dst_uri.s);
00716 msg->dst_uri.s = 0;
00717 msg->dst_uri.len = 0;
00718 ret = 1;
00719 break;
00720 case ISDSTURISET_T:
00721 if(msg->dst_uri.s==0 || msg->dst_uri.len<=0)
00722 ret = -1;
00723 else
00724 ret = 1;
00725 break;
00726 case IF_T:
00727
00728 if ((a->elem[0].type==EXPR_ST)&&a->elem[0].u.data){
00729 v=eval_expr((struct expr*)a->elem[0].u.data, msg, 0);
00730
00731 if (v<0 || (action_flags&ACT_FL_RETURN)
00732 || (action_flags&ACT_FL_EXIT) ){
00733 if (v==EXPR_DROP || (action_flags&ACT_FL_RETURN)
00734 || (action_flags&ACT_FL_EXIT) ){
00735 ret=0;
00736 return_code = 0;
00737 break;
00738 }else{
00739 LM_WARN("error in expression (l=%d)\n", a->line);
00740 }
00741 }
00742
00743 ret=1;
00744 if (v>0) {
00745 if ((a->elem[1].type==ACTIONS_ST)&&a->elem[1].u.data){
00746 ret=run_action_list(
00747 (struct action*)a->elem[1].u.data,msg );
00748 return_code = ret;
00749 } else return_code = v;
00750 }else{
00751 if ((a->elem[2].type==ACTIONS_ST)&&a->elem[2].u.data){
00752 ret=run_action_list(
00753 (struct action*)a->elem[2].u.data,msg);
00754 return_code = ret;
00755 } else return_code = v;
00756 }
00757 }
00758 break;
00759 case WHILE_T:
00760
00761 if ((a->elem[0].type==EXPR_ST)&&a->elem[0].u.data){
00762 len = 0;
00763 while(1)
00764 {
00765 if(len++ >= max_while_loops)
00766 {
00767 LM_INFO("max while loops are encountered\n");
00768 break;
00769 }
00770 v=eval_expr((struct expr*)a->elem[0].u.data, msg, 0);
00771
00772 if (v<0 || (action_flags&ACT_FL_RETURN)
00773 || (action_flags&ACT_FL_EXIT) ){
00774 if (v==EXPR_DROP || (action_flags&ACT_FL_RETURN)
00775 || (action_flags&ACT_FL_EXIT) ){
00776 ret=0;
00777 return_code = 0;
00778 break;
00779 }else{
00780 LM_WARN("error in expression (l=%d)\n",
00781 a->line);
00782 }
00783 }
00784
00785 ret=1;
00786 if (v>0) {
00787 if ((a->elem[1].type==ACTIONS_ST)
00788 &&a->elem[1].u.data){
00789 ret=run_action_list(
00790 (struct action*)a->elem[1].u.data,msg );
00791 return_code = ret;
00792 } else {
00793
00794 return_code = v;
00795 break;
00796 }
00797 } else {
00798
00799 return_code = v;
00800 break;
00801 }
00802 }
00803 }
00804 break;
00805 case SWITCH_T:
00806 if (a->elem[0].type!=SCRIPTVAR_ST){
00807 LM_ALERT("BUG in switch() type %d\n",
00808 a->elem[0].type);
00809 ret=E_BUG;
00810 break;
00811 }
00812 spec = (pv_spec_t*)a->elem[0].u.data;
00813 if(pv_get_spec_value(msg, spec, &val)!=0)
00814 {
00815 LM_ALERT("BUG - no value in switch()\n");
00816 ret=E_BUG;
00817 break;
00818 }
00819
00820 if(a->elem[1].type!=ACTIONS_ST) {
00821 LM_ALERT("BUG in switch() actions\n");
00822 ret=E_BUG;
00823 break;
00824 }
00825 return_code=1;
00826 adefault = NULL;
00827 aitem = (struct action*)a->elem[1].u.data;
00828 cmatch=0;
00829 while(aitem)
00830 {
00831 if((unsigned char)aitem->type==DEFAULT_T)
00832 adefault=aitem;
00833 if(cmatch==0)
00834 {
00835 if(aitem->elem[0].type==STRING_ST)
00836 {
00837 if(val.flags&PV_VAL_STR
00838 && val.rs.len==aitem->elem[0].u.s.len
00839 && strncasecmp(val.rs.s, aitem->elem[0].u.s.s,
00840 val.rs.len)==0)
00841 cmatch = 1;
00842 } else {
00843 if(val.flags&PV_VAL_INT &&
00844 val.ri==aitem->elem[0].u.number)
00845 cmatch = 1;
00846 }
00847 }
00848 if(cmatch==1)
00849 {
00850 if(aitem->elem[1].u.data)
00851 {
00852 return_code=run_action_list(
00853 (struct action*)aitem->elem[1].u.data, msg);
00854 if ((action_flags&ACT_FL_RETURN) ||
00855 (action_flags&ACT_FL_EXIT))
00856 break;
00857 }
00858 if(aitem->elem[2].u.number==1)
00859 break;
00860 }
00861 aitem = aitem->next;
00862 }
00863 if((cmatch==0) && (adefault!=NULL))
00864 {
00865 LM_DBG("switch: running default statement\n");
00866 if(adefault->elem[0].u.data)
00867 return_code=run_action_list(
00868 (struct action*)adefault->elem[0].u.data, msg);
00869 }
00870 ret=return_code;
00871 break;
00872 case MODULE_T:
00873 if ( (a->elem[0].type==CMD_ST) && a->elem[0].u.data ) {
00874 ret=((cmd_export_t*)(a->elem[0].u.data))->function(msg,
00875 (char*)a->elem[1].u.data, (char*)a->elem[2].u.data,
00876 (char*)a->elem[3].u.data, (char*)a->elem[4].u.data,
00877 (char*)a->elem[5].u.data, (char*)a->elem[6].u.data);
00878 }else{
00879 LM_ALERT("BUG in module call\n");
00880 }
00881 break;
00882 case FORCE_RPORT_T:
00883 msg->msg_flags|=FL_FORCE_RPORT;
00884 ret=1;
00885 break;
00886 case FORCE_LOCAL_RPORT_T:
00887 msg->msg_flags|=FL_FORCE_LOCAL_RPORT;
00888 ret=1;
00889 break;
00890 case SET_ADV_ADDR_T:
00891 if (a->elem[0].type!=STR_ST){
00892 LM_ALERT("BUG in set_advertised_address() "
00893 "type %d\n", a->elem[0].type);
00894 ret=E_BUG;
00895 break;
00896 }
00897 msg->set_global_address=*((str*)a->elem[0].u.data);
00898 ret=1;
00899 break;
00900 case SET_ADV_PORT_T:
00901 if (a->elem[0].type!=STR_ST){
00902 LM_ALERT("BUG in set_advertised_port() "
00903 "type %d\n", a->elem[0].type);
00904 ret=E_BUG;
00905 break;
00906 }
00907 msg->set_global_port=*((str*)a->elem[0].u.data);
00908 ret=1;
00909 break;
00910 #ifdef USE_TCP
00911 case FORCE_TCP_ALIAS_T:
00912 if ( msg->rcv.proto==PROTO_TCP
00913 #ifdef USE_TLS
00914 || msg->rcv.proto==PROTO_TLS
00915 #endif
00916 ){
00917
00918 if (a->elem[0].type==NOSUBTYPE) port=msg->via1->port;
00919 else if (a->elem[0].type==NUMBER_ST)
00920 port=(int)a->elem[0].u.number;
00921 else{
00922 LM_ALERT("BUG in force_tcp_alias"
00923 " port type %d\n", a->elem[0].type);
00924 ret=E_BUG;
00925 break;
00926 }
00927
00928 if (tcpconn_add_alias(msg->rcv.proto_reserved1, port,
00929 msg->rcv.proto)!=0){
00930 LM_ERR("tcp alias failed\n");
00931 ret=E_UNSPEC;
00932 break;
00933 }
00934 }
00935 #endif
00936 ret=1;
00937 break;
00938 case FORCE_SEND_SOCKET_T:
00939 if (a->elem[0].type!=SOCKETINFO_ST){
00940 LM_ALERT("BUG in force_send_socket argument"
00941 " type: %d\n", a->elem[0].type);
00942 ret=E_BUG;
00943 break;
00944 }
00945 msg->force_send_socket=(struct socket_info*)a->elem[0].u.data;
00946 ret=1;
00947 break;
00948 case EQ_T:
00949 case COLONEQ_T:
00950 case PLUSEQ_T:
00951 case MINUSEQ_T:
00952 case DIVEQ_T:
00953 case MULTEQ_T:
00954 case MODULOEQ_T:
00955 case BANDEQ_T:
00956 case BOREQ_T:
00957 case BXOREQ_T:
00958 ret = do_assign(msg, a);
00959 break;
00960 case USE_BLACKLIST_T:
00961 mark_for_search((struct bl_head*)a->elem[0].u.data, 1);
00962 break;
00963 case UNUSE_BLACKLIST_T:
00964 mark_for_search((struct bl_head*)a->elem[0].u.data, 0);
00965 break;
00966 case PV_PRINTF_T:
00967 ret = -1;
00968 spec = (pv_spec_p)a->elem[0].u.data;
00969 if(!pv_is_w(spec))
00970 {
00971 LM_ERR("read only PV in first parameter of pv_printf\n");
00972 goto error;
00973 }
00974
00975 model = (pv_elem_p)a->elem[1].u.data;
00976
00977 memset(&val, 0, sizeof(pv_value_t));
00978 if(pv_printf_s(msg, model, &val.rs)!=0)
00979 {
00980 LM_ERR("cannot eval second parameter\n");
00981 goto error;
00982 }
00983 val.flags = PV_VAL_STR;
00984 if(spec->setf(msg, &spec->pvp, EQ_T, &val)<0)
00985 {
00986 LM_ERR("setting PV failed\n");
00987 goto error;
00988 }
00989
00990 ret = 1;
00991 break;
00992 default:
00993 LM_ALERT("BUG - unknown type %d\n", a->type);
00994 goto error;
00995 }
00996
00997 if((unsigned char)a->type!=IF_T && (unsigned char)a->type!=ROUTE_T)
00998 return_code = ret;
00999
01000 return ret;
01001
01002 error:
01003 LM_ERR("error at line: %d\n", a->line);
01004 return ret;
01005
01006 error_uri:
01007 LM_ERR("set*: uri too long\n");
01008 if (new_uri) pkg_free(new_uri);
01009 return E_UNSPEC;
01010 error_fwd_uri:
01011 return ret;
01012 }