| 684 | |
| 685 | |
| 686 | static inline int do_script_action(struct sip_msg *msg, int action) |
| 687 | { |
| 688 | str body = {0,0}; |
| 689 | str bin = {0,0}; |
| 690 | str log = {0,0}; |
| 691 | str username = {0,0}; |
| 692 | str domain = {0,0}; |
| 693 | |
| 694 | if ( get_body(msg, &body)!=0 ) { |
| 695 | LM_ERR("failed to look for body!\n"); |
| 696 | goto error; |
| 697 | } |
| 698 | |
| 699 | /* get the user name */ |
| 700 | if (get_dest_user( msg, &username, &domain)==-1) |
| 701 | goto error; |
| 702 | |
| 703 | /* we have the script and the user */ |
| 704 | switch (action) { |
| 705 | case STORE_SCRIPT : |
| 706 | /* check the len -> it must not be 0 */ |
| 707 | if (body.len==0) { |
| 708 | LM_ERR("0 content-len found for store\n"); |
| 709 | goto error_1; |
| 710 | } |
| 711 | /* now compile the script and place it into database */ |
| 712 | /* get the binary coding for the XML file */ |
| 713 | if ( encodeCPL( &body, &bin, &log)!=1) { |
| 714 | cpl_err = &bad_cpl; |
| 715 | goto error_1; |
| 716 | } |
| 717 | |
| 718 | /* write both the XML and binary formats into database */ |
| 719 | if (write_to_db( &username, cpl_env.use_domain?&domain:0, |
| 720 | &body,&bin)!=1) { |
| 721 | cpl_err = &intern_err; |
| 722 | goto error_1; |
| 723 | } |
| 724 | break; |
| 725 | case REMOVE_SCRIPT: |
| 726 | /* check the len -> it must be 0 */ |
| 727 | if (body.len!=0) { |
| 728 | LM_ERR("non-0 content-len found for remove\n"); |
| 729 | goto error_1; |
| 730 | } |
| 731 | /* remove the script for the user */ |
| 732 | if (rmv_from_db( &username, cpl_env.use_domain?&domain:0)!=1) { |
| 733 | cpl_err = &intern_err; |
| 734 | goto error_1; |
| 735 | } |
| 736 | break; |
| 737 | } |
| 738 | |
| 739 | if (log.s) pkg_free( log.s ); |
| 740 | return 0; |
| 741 | error_1: |
| 742 | if (log.s) pkg_free( log.s ); |
| 743 | error: |
no test coverage detected