mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 12:56:37 +02:00
scripts: add function hook_url in scripting API
This commit is contained in:
@@ -2536,6 +2536,81 @@ weechat_guile_api_hook_process_hashtable (SCM command, SCM options, SCM timeout,
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_guile_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *) weechat_guile_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
SCM
|
||||
weechat_guile_api_hook_url (SCM url, SCM options, SCM timeout,
|
||||
SCM function, SCM data)
|
||||
{
|
||||
const char *result;
|
||||
SCM return_value;
|
||||
struct t_hashtable *c_options;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
if (!scm_is_string (url) || !scm_list_p (options)
|
||||
|| !scm_is_integer (timeout) || !scm_is_string (function)
|
||||
|| !scm_is_string (data))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
c_options = weechat_guile_alist_to_hashtable (options,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = API_PTR2STR(plugin_script_api_hook_url (weechat_guile_plugin,
|
||||
guile_current_script,
|
||||
API_SCM_TO_STRING(url),
|
||||
c_options,
|
||||
scm_to_int (timeout),
|
||||
&weechat_guile_api_hook_url_cb,
|
||||
API_SCM_TO_STRING(function),
|
||||
API_SCM_TO_STRING(data)));
|
||||
|
||||
if (c_options)
|
||||
weechat_hashtable_free (c_options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_guile_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -5290,6 +5365,7 @@ weechat_guile_api_module_init (void *data)
|
||||
API_DEF_FUNC(hook_fd, 6);
|
||||
API_DEF_FUNC(hook_process, 4);
|
||||
API_DEF_FUNC(hook_process_hashtable, 5);
|
||||
API_DEF_FUNC(hook_url, 5);
|
||||
API_DEF_FUNC(hook_connect, 8);
|
||||
API_DEF_FUNC(hook_line, 5);
|
||||
API_DEF_FUNC(hook_print, 6);
|
||||
|
||||
@@ -2452,6 +2452,82 @@ API_FUNC(hook_process_hashtable)
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_js_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *)weechat_js_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
API_FUNC(hook_url)
|
||||
{
|
||||
struct t_hashtable *options;
|
||||
int timeout;
|
||||
const char *result;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", "shiss", API_RETURN_EMPTY);
|
||||
|
||||
v8::String::Utf8Value url(args[0]);
|
||||
options = weechat_js_object_to_hashtable (
|
||||
args[1]->ToObject(),
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
timeout = args[2]->IntegerValue();
|
||||
v8::String::Utf8Value function(args[3]);
|
||||
v8::String::Utf8Value data(args[4]);
|
||||
|
||||
result = API_PTR2STR(
|
||||
plugin_script_api_hook_url (
|
||||
weechat_js_plugin,
|
||||
js_current_script,
|
||||
*url,
|
||||
options,
|
||||
timeout,
|
||||
&weechat_js_api_hook_url_cb,
|
||||
*function,
|
||||
*data));
|
||||
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_js_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -5233,6 +5309,7 @@ WeechatJsV8::loadLibs()
|
||||
API_DEF_FUNC(hook_fd);
|
||||
API_DEF_FUNC(hook_process);
|
||||
API_DEF_FUNC(hook_process_hashtable);
|
||||
API_DEF_FUNC(hook_url);
|
||||
API_DEF_FUNC(hook_connect);
|
||||
API_DEF_FUNC(hook_line);
|
||||
API_DEF_FUNC(hook_print);
|
||||
|
||||
@@ -2677,6 +2677,82 @@ API_FUNC(hook_process_hashtable)
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_lua_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *) weechat_lua_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
API_FUNC(hook_url)
|
||||
{
|
||||
const char *url, *function, *data;
|
||||
struct t_hashtable *options;
|
||||
int timeout;
|
||||
const char *result;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
if (lua_gettop (L) < 5)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
url = lua_tostring (L, -5);
|
||||
options = weechat_lua_tohashtable (L, -4,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
timeout = lua_tonumber (L, -3);
|
||||
function = lua_tostring (L, -2);
|
||||
data = lua_tostring (L, -1);
|
||||
|
||||
result = API_PTR2STR(plugin_script_api_hook_url (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
url,
|
||||
options,
|
||||
timeout,
|
||||
&weechat_lua_api_hook_url_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_lua_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -5598,6 +5674,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
|
||||
API_DEF_FUNC(hook_fd),
|
||||
API_DEF_FUNC(hook_process),
|
||||
API_DEF_FUNC(hook_process_hashtable),
|
||||
API_DEF_FUNC(hook_url),
|
||||
API_DEF_FUNC(hook_connect),
|
||||
API_DEF_FUNC(hook_line),
|
||||
API_DEF_FUNC(hook_print),
|
||||
|
||||
@@ -2566,6 +2566,81 @@ API_FUNC(hook_process_hashtable)
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_perl_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *) weechat_perl_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
API_FUNC(hook_url)
|
||||
{
|
||||
char *url, *function, *data;
|
||||
const char *result;
|
||||
struct t_hashtable *options;
|
||||
dXSARGS;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
if (items < 5)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
url = SvPV_nolen (ST (0));
|
||||
options = weechat_perl_hash_to_hashtable (ST (1),
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
function = SvPV_nolen (ST (3));
|
||||
data = SvPV_nolen (ST (4));
|
||||
|
||||
result = API_PTR2STR(plugin_script_api_hook_url (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
url,
|
||||
options,
|
||||
SvIV (ST (2)), /* timeout */
|
||||
&weechat_perl_api_hook_url_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_perl_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -5543,6 +5618,7 @@ weechat_perl_api_init (pTHX)
|
||||
API_DEF_FUNC(hook_fd);
|
||||
API_DEF_FUNC(hook_process);
|
||||
API_DEF_FUNC(hook_process_hashtable);
|
||||
API_DEF_FUNC(hook_url);
|
||||
API_DEF_FUNC(hook_connect);
|
||||
API_DEF_FUNC(hook_line);
|
||||
API_DEF_FUNC(hook_print);
|
||||
|
||||
@@ -2685,6 +2685,68 @@ API_FUNC(hook_process_hashtable)
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
static int
|
||||
weechat_php_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
int rc;
|
||||
void *func_argv[4];
|
||||
|
||||
func_argv[1] = url ? (char *)url : weechat_php_empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
weechat_php_cb (pointer, data, func_argv, "sshh",
|
||||
WEECHAT_SCRIPT_EXEC_INT, &rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
API_FUNC(hook_url)
|
||||
{
|
||||
zend_string *z_url, *z_data;
|
||||
zval *z_options, *z_callback;
|
||||
zend_long z_timeout;
|
||||
char *url, *data;
|
||||
struct t_hashtable *options;
|
||||
int timeout;
|
||||
const char *result;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SalzS", &z_url,
|
||||
&z_options, &z_timeout, &z_callback,
|
||||
&z_data) == FAILURE)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
url = ZSTR_VAL(z_url);
|
||||
options = weechat_php_array_to_hashtable (
|
||||
z_options,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
timeout = (int)z_timeout;
|
||||
weechat_php_get_function_name (z_callback, callback_name);
|
||||
data = ZSTR_VAL(z_data);
|
||||
|
||||
result = API_PTR2STR(
|
||||
plugin_script_api_hook_url (
|
||||
weechat_php_plugin,
|
||||
php_current_script,
|
||||
(const char *)url,
|
||||
options,
|
||||
timeout,
|
||||
&weechat_php_api_hook_url_cb,
|
||||
(const char *)callback_name,
|
||||
(const char *)data));
|
||||
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
static int
|
||||
weechat_php_api_hook_connect_cb (const void *pointer, void *data, int status,
|
||||
int gnutls_rc, int sock, const char *error,
|
||||
|
||||
@@ -141,6 +141,7 @@ PHP_FUNCTION(weechat_hook_timer);
|
||||
PHP_FUNCTION(weechat_hook_fd);
|
||||
PHP_FUNCTION(weechat_hook_process);
|
||||
PHP_FUNCTION(weechat_hook_process_hashtable);
|
||||
PHP_FUNCTION(weechat_hook_url);
|
||||
PHP_FUNCTION(weechat_hook_connect);
|
||||
PHP_FUNCTION(weechat_hook_line);
|
||||
PHP_FUNCTION(weechat_hook_print);
|
||||
|
||||
@@ -199,6 +199,7 @@ const zend_function_entry weechat_functions[] = {
|
||||
PHP_FE(weechat_hook_fd, arginfo_weechat_hook_fd)
|
||||
PHP_FE(weechat_hook_process, arginfo_weechat_hook_process)
|
||||
PHP_FE(weechat_hook_process_hashtable, arginfo_weechat_hook_process_hashtable)
|
||||
PHP_FE(weechat_hook_url, arginfo_weechat_hook_url)
|
||||
PHP_FE(weechat_hook_connect, arginfo_weechat_hook_connect)
|
||||
PHP_FE(weechat_hook_line, arginfo_weechat_hook_line)
|
||||
PHP_FE(weechat_hook_print, arginfo_weechat_hook_print)
|
||||
|
||||
@@ -107,6 +107,7 @@ function weechat_hook_timer(int $p0, int $p1, int $p2, mixed $p3, string $p4): s
|
||||
function weechat_hook_fd(int $p0, int $p1, int $p2, int $p3, mixed $p4, string $p5): string {}
|
||||
function weechat_hook_process(string $p0, int $p1, mixed $p2, string $p3): string {}
|
||||
function weechat_hook_process_hashtable(string $p0, array $p1, int $p2, mixed $p3, string $p4): string {}
|
||||
function weechat_hook_url(string $p0, array $p1, int $p2, mixed $p3, string $p4): string {}
|
||||
function weechat_hook_connect(): string {}
|
||||
function weechat_hook_line(string $p0, string $p1, string $p2, mixed $p3, string $p4): string {}
|
||||
function weechat_hook_print(string $p0, string $p1, string $p2, int $p3, mixed $p4, string $p5): string {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: d9a98a051023d3904f6e6f94b776386b3b67a5f6 */
|
||||
* Stub hash: 614392b6be26030a5d7b12437562aec08ad7052c */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_register, 0, 7, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, p0, IS_STRING, 0)
|
||||
@@ -315,6 +315,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_hook_process_hashtable,
|
||||
ZEND_ARG_TYPE_INFO(0, p4, IS_STRING, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_weechat_hook_url arginfo_weechat_hook_process_hashtable
|
||||
|
||||
#define arginfo_weechat_hook_connect arginfo_weechat_list_new
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_hook_line, 0, 5, IS_STRING, 0)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: d9a98a051023d3904f6e6f94b776386b3b67a5f6 */
|
||||
* Stub hash: 614392b6be26030a5d7b12437562aec08ad7052c */
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_weechat_register, 0, 0, 7)
|
||||
ZEND_ARG_INFO(0, p0)
|
||||
@@ -229,6 +229,8 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_weechat_hook_process_hashtable arginfo_weechat_print_y_date_tags
|
||||
|
||||
#define arginfo_weechat_hook_url arginfo_weechat_print_y_date_tags
|
||||
|
||||
#define arginfo_weechat_hook_connect arginfo_weechat_list_new
|
||||
|
||||
#define arginfo_weechat_hook_line arginfo_weechat_print_y_date_tags
|
||||
|
||||
@@ -704,6 +704,50 @@ plugin_script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
|
||||
callback, function, data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hooks a URL.
|
||||
*
|
||||
* Returns pointer to new hook, NULL if error.
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_script_api_hook_url (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
int timeout,
|
||||
int (*callback)(const void *pointer,
|
||||
void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output),
|
||||
const char *function,
|
||||
const char *data)
|
||||
{
|
||||
char *function_and_data;
|
||||
struct t_hook *new_hook;
|
||||
|
||||
if (!script)
|
||||
return NULL;
|
||||
|
||||
function_and_data = plugin_script_build_function_and_data (function, data);
|
||||
|
||||
new_hook = weechat_hook_url (url, options, timeout,
|
||||
callback, script, function_and_data);
|
||||
|
||||
if (new_hook)
|
||||
{
|
||||
weechat_hook_set (new_hook, "subplugin", script->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (function_and_data)
|
||||
free (function_and_data);
|
||||
}
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hooks a connection to a peer (using fork).
|
||||
*
|
||||
|
||||
@@ -203,6 +203,18 @@ extern struct t_hook *plugin_script_api_hook_process (struct t_weechat_plugin *w
|
||||
const char *err),
|
||||
const char *function,
|
||||
const char *data);
|
||||
extern struct t_hook *plugin_script_api_hook_url (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
int timeout,
|
||||
int (*callback)(const void *pointer,
|
||||
void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output),
|
||||
const char *function,
|
||||
const char *data);
|
||||
extern struct t_hook *plugin_script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *proxy,
|
||||
|
||||
@@ -2579,6 +2579,84 @@ API_FUNC(hook_process_hashtable)
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_python_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *) weechat_python_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
API_FUNC(hook_url)
|
||||
{
|
||||
char *url, *function, *data;
|
||||
const char *result;
|
||||
int timeout;
|
||||
struct t_hashtable *options;
|
||||
PyObject *dict;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
url = NULL;
|
||||
dict = NULL;
|
||||
options = NULL;
|
||||
timeout = 0;
|
||||
function = NULL;
|
||||
data = NULL;
|
||||
if (!PyArg_ParseTuple (args, "sOiss", &url, &dict, &timeout, &function,
|
||||
&data))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
options = weechat_python_dict_to_hashtable (dict,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
result = API_PTR2STR(plugin_script_api_hook_url (weechat_python_plugin,
|
||||
python_current_script,
|
||||
url,
|
||||
options,
|
||||
timeout,
|
||||
&weechat_python_api_hook_url_cb,
|
||||
function,
|
||||
data));
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_python_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -5461,6 +5539,7 @@ PyMethodDef weechat_python_funcs[] =
|
||||
API_DEF_FUNC(hook_fd),
|
||||
API_DEF_FUNC(hook_process),
|
||||
API_DEF_FUNC(hook_process_hashtable),
|
||||
API_DEF_FUNC(hook_url),
|
||||
API_DEF_FUNC(hook_connect),
|
||||
API_DEF_FUNC(hook_line),
|
||||
API_DEF_FUNC(hook_print),
|
||||
|
||||
@@ -1362,6 +1362,32 @@ def hook_process_hashtable(command: str, options: Dict[str, str], timeout: int,
|
||||
...
|
||||
|
||||
|
||||
def hook_url(url: str, options: Dict[str, str], timeout: int, callback: str, callback_data: str) -> str:
|
||||
"""`hook_url in WeeChat plugin API reference <https://weechat.org/doc/weechat/api/#_hook_url>`_
|
||||
::
|
||||
|
||||
# example
|
||||
def my_url_cb(data: str, url: str, options: Dict[str, str], output: Dict[str, str]) -> int:
|
||||
weechat.prnt("", "output: %s" % output)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
# example 1: output to a file
|
||||
hook1 = weechat.hook_url("https://weechat.org/",
|
||||
{"file_out": "/tmp/weechat.org.html"},
|
||||
20000, "my_url_cb", "")
|
||||
|
||||
# example 2: custom HTTP headers, output sent to callback
|
||||
options = {
|
||||
"httpheader": "\n".join([
|
||||
"Header1: value1",
|
||||
"Header2: value2",
|
||||
]),
|
||||
}
|
||||
hook2 = weechat.hook_url("http://localhost:8080/", options, 20000, "my_url_cb", "")
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
def hook_connect(proxy: str, address: str, port: int, ipv6: int, retry: int, local_hostname: str,
|
||||
callback: str, callback_data: str) -> str:
|
||||
"""`hook_connect in WeeChat plugin API reference <https://weechat.org/doc/weechat/api/#_hook_connect>`_
|
||||
|
||||
@@ -3152,6 +3152,92 @@ weechat_ruby_api_hook_process_hashtable (VALUE class, VALUE command,
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_ruby_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *) weechat_ruby_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_url (VALUE class, VALUE url,
|
||||
VALUE options, VALUE timeout,
|
||||
VALUE function, VALUE data)
|
||||
{
|
||||
char *c_url, *c_function, *c_data;
|
||||
const char *result;
|
||||
struct t_hashtable *c_options;
|
||||
int c_timeout;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
if (NIL_P (url) || NIL_P (options) || NIL_P (timeout)
|
||||
|| NIL_P (function) || NIL_P (data))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
Check_Type (url, T_STRING);
|
||||
Check_Type (options, T_HASH);
|
||||
CHECK_INTEGER(timeout);
|
||||
Check_Type (function, T_STRING);
|
||||
Check_Type (data, T_STRING);
|
||||
|
||||
c_url = StringValuePtr (url);
|
||||
c_options = weechat_ruby_hash_to_hashtable (options,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
c_timeout = NUM2INT (timeout);
|
||||
c_function = StringValuePtr (function);
|
||||
c_data = StringValuePtr (data);
|
||||
|
||||
result = API_PTR2STR(plugin_script_api_hook_url (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_url,
|
||||
c_options,
|
||||
c_timeout,
|
||||
&weechat_ruby_api_hook_url_cb,
|
||||
c_function,
|
||||
c_data));
|
||||
|
||||
if (c_options)
|
||||
weechat_hashtable_free (c_options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_ruby_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -6764,6 +6850,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
API_DEF_FUNC(hook_fd, 6);
|
||||
API_DEF_FUNC(hook_process, 4);
|
||||
API_DEF_FUNC(hook_process_hashtable, 5);
|
||||
API_DEF_FUNC(hook_url, 5);
|
||||
API_DEF_FUNC(hook_connect, 8);
|
||||
API_DEF_FUNC(hook_line, 5);
|
||||
API_DEF_FUNC(hook_print, 6);
|
||||
|
||||
@@ -2875,6 +2875,85 @@ API_FUNC(hook_process_hashtable)
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_tcl_api_hook_url_cb (const void *pointer, void *data,
|
||||
const char *url,
|
||||
struct t_hashtable *options,
|
||||
struct t_hashtable *output)
|
||||
{
|
||||
struct t_plugin_script *script;
|
||||
void *func_argv[4];
|
||||
char empty_arg[1] = { '\0' };
|
||||
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])
|
||||
{
|
||||
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
|
||||
func_argv[1] = (url) ? (char *)url : empty_arg;
|
||||
func_argv[2] = options;
|
||||
func_argv[3] = output;
|
||||
|
||||
rc = (int *) weechat_tcl_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
ptr_function,
|
||||
"sshh", func_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
API_FUNC(hook_url)
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *url, *function, *data;
|
||||
const char *result;
|
||||
struct t_hashtable *options;
|
||||
int i, timeout;
|
||||
|
||||
API_INIT_FUNC(1, "hook_url", API_RETURN_EMPTY);
|
||||
if (objc < 6)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
if ((Tcl_GetIntFromObj (interp, objv[3], &timeout) != TCL_OK))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
url = Tcl_GetStringFromObj (objv[1], &i);
|
||||
options = weechat_tcl_dict_to_hashtable (interp, objv[2],
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
function = Tcl_GetStringFromObj (objv[4], &i);
|
||||
data = Tcl_GetStringFromObj (objv[5], &i);
|
||||
|
||||
result = API_PTR2STR(plugin_script_api_hook_url (weechat_tcl_plugin,
|
||||
tcl_current_script,
|
||||
url,
|
||||
options,
|
||||
timeout,
|
||||
&weechat_tcl_api_hook_url_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
int
|
||||
weechat_tcl_api_hook_connect_cb (const void *pointer, void *data,
|
||||
int status, int gnutls_rc,
|
||||
@@ -6051,6 +6130,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
|
||||
API_DEF_FUNC(hook_fd);
|
||||
API_DEF_FUNC(hook_process);
|
||||
API_DEF_FUNC(hook_process_hashtable);
|
||||
API_DEF_FUNC(hook_url);
|
||||
API_DEF_FUNC(hook_connect);
|
||||
API_DEF_FUNC(hook_line);
|
||||
API_DEF_FUNC(hook_print);
|
||||
|
||||
Reference in New Issue
Block a user