提交 601e8fe7 authored 作者: gled's avatar gled

woops

上级 dd789b67
BASE=../../../.. BASE=../../..
include $(BASE)/build/modmake.rules include $(BASE)/build/modmake.rules
\ No newline at end of file
...@@ -45,11 +45,13 @@ SWITCH_MODULE_DEFINITION(mod_fgi, mod_fgi_load, mod_fgi_shutdown, NULL); ...@@ -45,11 +45,13 @@ SWITCH_MODULE_DEFINITION(mod_fgi, mod_fgi_load, mod_fgi_shutdown, NULL);
#define FG_READ 0 #define FG_READ 0
#define FG_WRITE 1 #define FG_WRITE 1
#define _MAX_CMD_ARGS 128
static void parse_args(char *buf,int *argc,char *argv[_MAX_CMD_ARGS]); #define MAX(x,y) ((x) > (y) ? (x) : (y))
pid_t fgi_open_process( const char *cmd, int *in, int *out); #define MIN(x,y) ((x) < (y) ? (x) : (y))
static void parse_fgi_args(char *buf,int *argc,char *argv[_MAX_CMD_ARGS]);
pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running) { pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running) {
int p_in[2], p_out[2]; int p_in[2], p_out[2];
pid_t pid; pid_t pid;
...@@ -101,45 +103,39 @@ pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running) ...@@ -101,45 +103,39 @@ pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running)
static switch_status_t find_and_exec_command(char *cmd, int fd_reply) { static switch_status_t find_and_exec_command(char *cmd, int fd_reply) {
char *argv[1024]; char *argv[1024];
int argc = 0; int argc = 0;
int r = -1;
command_binding_t *bind;
pargc =parse_fgi_args(cmd,argv); parse_fgi_args(cmd,&argc,argv);
/* */
bind = find_binding(argv);
if (bind) {
r = bind->handler(eslC,fd,&argc,argv);
}
return r;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t exec_fgi_run() { static switch_status_t exec_fgi_run(char *argv) {
int in,out; int in,out;
pid_t pid; pid_t pid;
int res,nfds; int res=0;
int nfds=0;
fd_set rd; fd_set rd;
char cmd_buf[2048];
int thread_running; int thread_running;
char cmdbuf[_MAX_CMD_ARGS*128];
pid = fgi_open_process(cmd,&in,&out,&thread_running); pid = fgi_open_process(argv,&in,&out,&thread_running);
if ( pid <= 0) if ( pid <= 0)
return SWITCH_STATUS_FAIL; return SWITCH_STATUS_SUCCESS;
while (thread_running) { while (thread_running) {
FD_ZERO(&rd); FD_ZERO(&rd);
FD_SET(in, &rd); FD_SET(in, &rd);
nfds = MAX(nfds,pipes.script[0]); nfds = MAX(nfds,out);
res = select(nfds + 1, &rd, NULL, NULL, NULL); res = select(nfds + 1, &rd, NULL, NULL, NULL);
if (r == -1 ) if (res == -1 )
break; break;
else if (FD_ISSET(out,&rd) ) { /* They have something to say else if (FD_ISSET(out,&rd) ) { /* They have something to say */
r = read(out,&cmdbuf,2047); res = read(out,&cmdbuf,2047);
if (r<0) if (res<0)
goto end; goto end;
else { else {
if ( find_and_exec_command(char *) &cmdbuf,reply_fd) != SWITCH_STATUS_SUCCESS ) if ( find_and_exec_command((char *) &cmdbuf,in) != SWITCH_STATUS_SUCCESS )
goto end; goto end;
} }
} }
...@@ -155,7 +151,7 @@ SWITCH_STANDARD_APP(launch_fgi_thread) { ...@@ -155,7 +151,7 @@ SWITCH_STANDARD_APP(launch_fgi_thread) {
char *argv[6] = { 0 }; char *argv[6] = { 0 };
int argc; int argc;
char *mydata = NULL; char *mydata = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session); // switch_channel_t *channel = switch_core_session_get_channel(session);
if (zstr(data) || !(mydata = switch_core_session_strdup(session, data))) { if (zstr(data) || !(mydata = switch_core_session_strdup(session, data))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID ARGS!\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID ARGS!\n");
...@@ -166,20 +162,18 @@ SWITCH_STANDARD_APP(launch_fgi_thread) { ...@@ -166,20 +162,18 @@ SWITCH_STANDARD_APP(launch_fgi_thread) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID ARGS!\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID ARGS!\n");
return; return;
} }
exec_fgi_run(argc,argv); exec_fgi_run(mydata);
return SWITCH_STATUS_SUCCESS; /* Free up things ? */
} }
SWITCH_MODULE_LOAD_FUNCTION(mod_fgi_load) { SWITCH_MODULE_LOAD_FUNCTION(mod_fgi_load) {
switch_app_interface_t *app_interface; switch_application_interface_t *app_interface;
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello !\n");
SWITCH_ADD_APP(app_interface, "fgi", "Fgi", "launch and give control to an external entity with STDIN/STDOUT", launch_fgi_thread, "fgi <path_to_executable> [<args>]", SAF_NONE);
do_config(SWITCH_FALSE);
SWITCH_ADD_APP(app_interface, "fgi", "Freeswitch Gateway Interface", launch_fgi_thread, "fgi path_to_executable args");
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
...@@ -193,7 +187,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fgi_shutdown) { ...@@ -193,7 +187,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fgi_shutdown) {
} }
static void parse_args(char *buf,int *argc,char *argv[_MAX_CMD_ARGS]) { static void parse_fgi_args(char *buf,int *argc,char *argv[_MAX_CMD_ARGS]) {
char *cur; char *cur;
int x = 0; int x = 0;
int quote = 0; int quote = 0;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论