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 #include <stdio.h>
00037
00038 #include "../../parser/msg_parser.h"
00039 #include "../../str.h"
00040 #include "../../sr_module.h"
00041 #include "../../dprint.h"
00042 #include "../../parser/parse_uri.h"
00043
00044 #include "exec.h"
00045 #include "kill.h"
00046 #include "exec_hf.h"
00047
00048 MODULE_VERSION
00049
00050 unsigned int time_to_kill=0;
00051
00052 static int mod_init( void );
00053
00054 inline static int w_exec_dset(struct sip_msg* msg, char* cmd, char* foo);
00055 inline static int w_exec_msg(struct sip_msg* msg, char* cmd, char* foo);
00056
00057 inline static void exec_shutdown();
00058
00059
00060
00061
00062 static cmd_export_t cmds[] = {
00063 {"exec_dset", w_exec_dset, 1, fixup_var_str_1, REQUEST_ROUTE | FAILURE_ROUTE},
00064 {"exec_msg", w_exec_msg, 1, fixup_var_str_1, REQUEST_ROUTE | FAILURE_ROUTE},
00065 {0, 0, 0, 0, 0}
00066 };
00067
00068
00069
00070
00071
00072 static param_export_t params[] = {
00073 {"time_to_kill", PARAM_INT, &time_to_kill},
00074 {"setvars", PARAM_INT, &setvars },
00075 {0, 0, 0}
00076 };
00077
00078
00079 #ifdef STATIC_EXEC
00080 struct module_exports exec_exports = {
00081 #else
00082 struct module_exports exports= {
00083 #endif
00084 "exec",
00085 cmds,
00086 0,
00087 params,
00088 mod_init,
00089 0,
00090 exec_shutdown,
00091 0,
00092 0
00093 };
00094
00095 void exec_shutdown()
00096 {
00097 if (time_to_kill) destroy_kill();
00098 }
00099
00100
00101 static int mod_init( void )
00102 {
00103 fprintf( stderr, "exec - initializing\n");
00104 if (time_to_kill) initialize_kill();
00105 return 0;
00106 }
00107
00108 inline static int w_exec_dset(struct sip_msg* msg, char* p1, char* foo)
00109 {
00110 str cmd;
00111 str *uri;
00112 environment_t *backup;
00113 int ret;
00114
00115 if (get_str_fparam(&cmd, msg, (fparam_t*)p1) < 0) {
00116 ERR("Error while obtaining command name\n");
00117 return -1;
00118 }
00119
00120 backup=0;
00121 if (setvars) {
00122 backup=set_env(msg);
00123 if (!backup) {
00124 LOG(L_ERR, "ERROR: w_exec_msg: no env created\n");
00125 return -1;
00126 }
00127 }
00128
00129 if (msg->new_uri.s && msg->new_uri.len)
00130 uri=&msg->new_uri;
00131 else
00132 uri=&msg->first_line.u.request.uri;
00133
00134 ret=exec_str(msg, &cmd, uri->s, uri->len);
00135 if (setvars) {
00136 unset_env(backup);
00137 }
00138 return ret;
00139 }
00140
00141
00142 inline static int w_exec_msg(struct sip_msg* msg, char* p1, char* foo)
00143 {
00144 str cmd;
00145 environment_t *backup;
00146 int ret;
00147
00148 if (get_str_fparam(&cmd, msg, (fparam_t*)p1) < 0) {
00149 ERR("Error while obtaining command name\n");
00150 return -1;
00151 }
00152
00153 backup=0;
00154 if (setvars) {
00155 backup=set_env(msg);
00156 if (!backup) {
00157 LOG(L_ERR, "ERROR: w_exec_msg: no env created\n");
00158 return -1;
00159 }
00160 }
00161 ret=exec_msg(msg, &cmd);
00162 if (setvars) {
00163 unset_env(backup);
00164 }
00165 return ret;
00166 }