Params: * str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING * str2 - as unsigned int - flags regarding state(less)|(ful) */
| 570 | * str2 - as unsigned int - flags regarding state(less)|(ful) |
| 571 | */ |
| 572 | static int cpl_invoke_script(struct sip_msg* msg, void* type, void* mode) |
| 573 | { |
| 574 | struct cpl_interpreter *cpl_intr; |
| 575 | str username = {0,0}; |
| 576 | str domain = {0,0}; |
| 577 | str loc; |
| 578 | str script; |
| 579 | |
| 580 | /* get the user_name */ |
| 581 | if ( ((unsigned long)type)&CPL_RUN_INCOMING ) { |
| 582 | /* if it's incoming -> get the destination user name */ |
| 583 | if (get_dest_user( msg, &username, &domain)==-1) |
| 584 | goto error0; |
| 585 | } else { |
| 586 | /* if it's outgoing -> get the origin user name */ |
| 587 | if (get_orig_user( msg, &username, &domain)==-1) |
| 588 | goto error0; |
| 589 | } |
| 590 | |
| 591 | /* get the script for this user */ |
| 592 | if (get_user_script(&username, cpl_env.use_domain?&domain:0, |
| 593 | &script, &cpl_bin_col)==-1) |
| 594 | goto error0; |
| 595 | |
| 596 | /* has the user a non-empty script? if not, return normally, allowing the |
| 597 | * script execution to continue */ |
| 598 | if ( !script.s || !script.len ) |
| 599 | return 2; |
| 600 | |
| 601 | /* build a new script interpreter */ |
| 602 | if ( (cpl_intr=new_cpl_interpreter(msg,&script))==0 ) |
| 603 | goto error1; |
| 604 | /* set the flags */ |
| 605 | cpl_intr->flags =(unsigned int)((unsigned long)type)|((unsigned long)mode); |
| 606 | /* build user AOR */ |
| 607 | if (build_user_AOR( &username, &domain, &(cpl_intr->user), 0)!=0 ) |
| 608 | goto error2; |
| 609 | /* for OUTGOING we need also the destination user for init. with him |
| 610 | * the location set */ |
| 611 | if ( ((unsigned long)type)&CPL_RUN_OUTGOING ) { |
| 612 | /* build user initial location -> get the destination user name */ |
| 613 | if (get_dest_user( msg, &username, &domain)==-1) |
| 614 | goto error2; |
| 615 | if (build_user_AOR( &username, &domain, &loc, 1)!=0 ) |
| 616 | goto error2; |
| 617 | if (add_location( &(cpl_intr->loc_set), &loc, 0, 10,CPL_LOC_DUPL)==-1){ |
| 618 | shm_free(loc.s); |
| 619 | goto error2; |
| 620 | } |
| 621 | shm_free(loc.s); |
| 622 | } |
| 623 | |
| 624 | /* run the script */ |
| 625 | switch (cpl_run_script( cpl_intr )) { |
| 626 | case SCRIPT_DEFAULT: |
| 627 | if ( cpl_intr->flags&CPL_DO_NOT_FREE ) |
| 628 | cpl_intr->flags |= CPL_ENDED; |
| 629 | else |
nothing calls this directly
no test coverage detected