summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/guile/weechat-guile-api.c76
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp77
-rw-r--r--src/plugins/lua/weechat-lua-api.c77
-rw-r--r--src/plugins/perl/weechat-perl-api.c76
-rw-r--r--src/plugins/php/weechat-php-api.c62
-rw-r--r--src/plugins/php/weechat-php-api.h1
-rw-r--r--src/plugins/php/weechat-php.c1
-rw-r--r--src/plugins/php/weechat-php.stub.php1
-rw-r--r--src/plugins/php/weechat-php_arginfo.h4
-rw-r--r--src/plugins/php/weechat-php_legacy_arginfo.h4
-rw-r--r--src/plugins/plugin-script-api.c44
-rw-r--r--src/plugins/plugin-script-api.h12
-rw-r--r--src/plugins/python/weechat-python-api.c79
-rw-r--r--src/plugins/python/weechat.pyi26
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c87
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c80
16 files changed, 705 insertions, 2 deletions
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index fc1b8ad52..55f8ce7ec 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -2537,6 +2537,81 @@ weechat_guile_api_hook_process_hashtable (SCM command, SCM options, SCM timeout,
}
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,
int sock, const char *error,
@@ -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);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index df916b95d..0475672e3 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -2453,6 +2453,82 @@ API_FUNC(hook_process_hashtable)
}
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,
int sock, const char *error,
@@ -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);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index dfe38116f..749ce5acf 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -2678,6 +2678,82 @@ API_FUNC(hook_process_hashtable)
}
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,
int sock, const char *error,
@@ -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),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index c8119f12b..0e28070eb 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -2567,6 +2567,81 @@ API_FUNC(hook_process_hashtable)
}
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,
int sock, const char *error,
@@ -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);
diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c
index 32835d23c..fbd1ce5db 100644
--- a/src/plugins/php/weechat-php-api.c
+++ b/src/plugins/php/weechat-php-api.c
@@ -2686,6 +2686,68 @@ API_FUNC(hook_process_hashtable)
}
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,
const char *ip_address)
diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h
index 348ac94da..d223b6f56 100644
--- a/src/plugins/php/weechat-php-api.h
+++ b/src/plugins/php/weechat-php-api.h
@@ -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);
diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c
index ae7293528..5d83482e5 100644
--- a/src/plugins/php/weechat-php.c
+++ b/src/plugins/php/weechat-php.c
@@ -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)
diff --git a/src/plugins/php/weechat-php.stub.php b/src/plugins/php/weechat-php.stub.php
index b9297f8aa..9343075af 100644
--- a/src/plugins/php/weechat-php.stub.php
+++ b/src/plugins/php/weechat-php.stub.php
@@ -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 {}
diff --git a/src/plugins/php/weechat-php_arginfo.h b/src/plugins/php/weechat-php_arginfo.h
index df6d3a5bf..e2b345a3e 100644
--- a/src/plugins/php/weechat-php_arginfo.h
+++ b/src/plugins/php/weechat-php_arginfo.h
@@ -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)
diff --git a/src/plugins/php/weechat-php_legacy_arginfo.h b/src/plugins/php/weechat-php_legacy_arginfo.h
index 951f9f11a..de2cb031e 100644
--- a/src/plugins/php/weechat-php_legacy_arginfo.h
+++ b/src/plugins/php/weechat-php_legacy_arginfo.h
@@ -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
diff --git a/src/plugins/plugin-script-api.c b/src/plugins/plugin-script-api.c
index c85244840..85ee30430 100644
--- a/src/plugins/plugin-script-api.c
+++ b/src/plugins/plugin-script-api.c
@@ -705,6 +705,50 @@ plugin_script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
}
/*
+ * 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).
*
* Returns pointer to new hook, NULL if error.
diff --git a/src/plugins/plugin-script-api.h b/src/plugins/plugin-script-api.h
index 44cf8c179..a69b3435a 100644
--- a/src/plugins/plugin-script-api.h
+++ b/src/plugins/plugin-script-api.h
@@ -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,
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index 9ffac5b3b..2cb87d55f 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -2580,6 +2580,84 @@ API_FUNC(hook_process_hashtable)
}
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,
int sock, const char *error,
@@ -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),
diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi
index c21438aa9..db2b5ceae 100644
--- a/src/plugins/python/weechat.pyi
+++ b/src/plugins/python/weechat.pyi
@@ -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>`_
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 873aa86c1..9716dc5be 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -3153,6 +3153,92 @@ weechat_ruby_api_hook_process_hashtable (VALUE class, VALUE command,
}
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,
int sock, const char *error,
@@ -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);
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index a0b2a70c7..9414ad27b 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -2876,6 +2876,85 @@ API_FUNC(hook_process_hashtable)
}
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,
int sock, const char *error,
@@ -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);