diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-04-23 13:59:20 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-04-23 13:59:20 +0200 |
commit | 51c3e0b9ec7ff5720d860168b7a5d60fb69226b8 (patch) | |
tree | 09bda734cf84ba120f9d19e18086c7f9936fa250 /src/plugins | |
parent | ae89d28462f5761bba7ccf647eaa7ed4a51f5fb4 (diff) | |
download | weechat-51c3e0b9ec7ff5720d860168b7a5d60fb69226b8.zip |
api: add support of functions in hook_process
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/guile/weechat-guile-api.c | 23 | ||||
-rw-r--r-- | src/plugins/javascript/weechat-js-api.cpp | 23 | ||||
-rw-r--r-- | src/plugins/lua/weechat-lua-api.c | 23 | ||||
-rw-r--r-- | src/plugins/perl/weechat-perl-api.c | 23 | ||||
-rw-r--r-- | src/plugins/python/weechat-python-api.c | 23 | ||||
-rw-r--r-- | src/plugins/ruby/weechat-ruby-api.c | 23 | ||||
-rw-r--r-- | src/plugins/tcl/weechat-tcl-api.c | 23 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 11 |
8 files changed, 155 insertions, 17 deletions
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index 32676fbd5..acf0f8080 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -2171,14 +2171,33 @@ weechat_guile_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_guile_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index e2cad59f4..4a09b130b 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -2085,14 +2085,33 @@ weechat_js_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_js_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 893424034..ba75aad74 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -2268,14 +2268,33 @@ weechat_lua_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_lua_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 267d1982d..4233f70c6 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -2198,14 +2198,33 @@ weechat_perl_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_perl_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index fc9d05409..23acaba0b 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -2208,14 +2208,33 @@ weechat_python_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_python_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index e3c57e385..9b705afba 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -2682,14 +2682,33 @@ weechat_ruby_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_ruby_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 078afd169..75db35ab3 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -2450,14 +2450,33 @@ weechat_tcl_api_hook_process_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[5]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; int *rc, ret; script = (struct t_plugin_script *)pointer; plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - if (ptr_function && ptr_function[0]) + if (return_code == WEECHAT_HOOK_PROCESS_CHILD) + { + if (strncmp (command, "func:", 5) == 0) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + + result = (char *) weechat_tcl_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + command + 5, + "s", func_argv); + if (result) + { + printf ("%s", result); + free (result); + return 0; + } + } + return 1; + } + else if (ptr_function && ptr_function[0]) { func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; func_argv[1] = (command) ? (char *)command : empty_arg; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 53171b920..ece4de71d 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -57,7 +57,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20160324-01" +#define WEECHAT_PLUGIN_API_VERSION "20160423-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -138,11 +138,16 @@ struct timeval; /* * process return code (for callback): - * if >= 0, then process ended and it's return code of command - * if < 0, then it's running or error + * if >= 0, the process ended and it's return code of command + * if -1, the process is still running + * if -2, the process ended with an error + * if -3, the callback is called in the child process (exec of function) + * (note: the return code -3 is NEVER sent to script plugins, + * it can be used only in C API) */ #define WEECHAT_HOOK_PROCESS_RUNNING -1 #define WEECHAT_HOOK_PROCESS_ERROR -2 +#define WEECHAT_HOOK_PROCESS_CHILD -3 /* connect status for connection hooked */ #define WEECHAT_HOOK_CONNECT_OK 0 |