diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-09-08 17:07:03 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-09-16 13:00:03 +0200 |
commit | fb00bc1f4b9ede63153cf55ceb38d0fdcb39786c (patch) | |
tree | e95b3f0c70d0fc3a8b00b2c97bf88dae21032c34 /src/plugins/php | |
parent | 24d2ba3338c8467a51ce28eccb05937603e3e6cc (diff) | |
download | weechat-fb00bc1f4b9ede63153cf55ceb38d0fdcb39786c.zip |
scripts: add function hook_url in scripting API
Diffstat (limited to 'src/plugins/php')
-rw-r--r-- | src/plugins/php/weechat-php-api.c | 62 | ||||
-rw-r--r-- | src/plugins/php/weechat-php-api.h | 1 | ||||
-rw-r--r-- | src/plugins/php/weechat-php.c | 1 | ||||
-rw-r--r-- | src/plugins/php/weechat-php.stub.php | 1 | ||||
-rw-r--r-- | src/plugins/php/weechat-php_arginfo.h | 4 | ||||
-rw-r--r-- | src/plugins/php/weechat-php_legacy_arginfo.h | 4 |
6 files changed, 71 insertions, 2 deletions
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 |