You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
5374 lines
160 KiB
5374 lines
160 KiB
/* |
|
* weechat-php-api.c - PHP API functions |
|
* |
|
* Copyright (C) 2006-2017 Adam Saponara <as@php.net> |
|
* Copyright (C) 2017-2021 Sébastien Helleu <flashcode@flashtux.org> |
|
* |
|
* This file is part of WeeChat, the extensible chat client. |
|
* |
|
* WeeChat is free software; you can redistribute it and/or modify |
|
* it under the terms of the GNU General Public License as published by |
|
* the Free Software Foundation; either version 3 of the License, or |
|
* (at your option) any later version. |
|
* |
|
* WeeChat is distributed in the hope that it will be useful, |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
* GNU General Public License for more details. |
|
* |
|
* You should have received a copy of the GNU General Public License |
|
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>. |
|
* |
|
* OpenSSL licensing: |
|
* |
|
* Additional permission under GNU GPL version 3 section 7: |
|
* |
|
* If you modify the Program, or any covered work, by linking or |
|
* combining it with the OpenSSL project's OpenSSL library (or a |
|
* modified version of that library), containing parts covered by the |
|
* terms of the OpenSSL or SSLeay licenses, the licensors of the Program |
|
* grant you additional permission to convey the resulting work. |
|
* Corresponding Source for a non-source form of such a combination |
|
* shall include the source code for the parts of OpenSSL used as well |
|
* as that of the covered work. |
|
*/ |
|
|
|
#include <sapi/embed/php_embed.h> |
|
#include <php.h> |
|
#include <php_ini.h> |
|
#include <ext/standard/info.h> |
|
|
|
#include "../weechat-plugin.h" |
|
#include "../plugin-script.h" |
|
#include "../plugin-script-api.h" |
|
#include "weechat-php.h" |
|
|
|
#define API_FUNC(__name) \ |
|
PHP_FUNCTION(weechat_##__name) |
|
#define API_INIT_FUNC(__init, __name, __ret) \ |
|
char *php_function_name = __name; \ |
|
if (__init \ |
|
&& (!php_current_script || !php_current_script->name)) \ |
|
{ \ |
|
WEECHAT_SCRIPT_MSG_NOT_INIT(PHP_CURRENT_SCRIPT_NAME, \ |
|
php_function_name); \ |
|
__ret; \ |
|
} |
|
#define API_WRONG_ARGS(__ret) \ |
|
{ \ |
|
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PHP_CURRENT_SCRIPT_NAME, \ |
|
php_function_name); \ |
|
__ret; \ |
|
} |
|
#define API_PTR2STR(__pointer) \ |
|
plugin_script_ptr2str (__pointer) |
|
#define API_STR2PTR(__string) \ |
|
plugin_script_str2ptr (weechat_php_plugin, \ |
|
PHP_CURRENT_SCRIPT_NAME, \ |
|
php_function_name, __string) |
|
#define API_RETURN_OK RETURN_LONG((long)1) |
|
#define API_RETURN_ERROR RETURN_LONG((long)0) |
|
#define API_RETURN_EMPTY RETURN_NULL() |
|
#define API_RETURN_STRING(__string) \ |
|
RETURN_STRING((__string) ? (__string) : "") |
|
#define API_RETURN_STRING_FREE(__string) \ |
|
if (__string) \ |
|
{ \ |
|
RETVAL_STRING(__string); \ |
|
free (__string); \ |
|
return; \ |
|
} \ |
|
RETURN_STRING(""); |
|
#define API_RETURN_INT(__int) RETURN_LONG(__int) |
|
#define API_RETURN_LONG(__long) RETURN_LONG(__long) |
|
#define weechat_php_get_function_name(__zfunc, __str) \ |
|
const char *(__str); \ |
|
do \ |
|
{ \ |
|
if (!zend_is_callable (__zfunc, 0, NULL)) \ |
|
{ \ |
|
php_error_docref (NULL, E_WARNING, "Expected callable"); \ |
|
RETURN_FALSE; \ |
|
} \ |
|
(__str) = weechat_php_func_map_add (__zfunc); \ |
|
} \ |
|
while (0) |
|
|
|
static char weechat_php_empty_arg[1] = { '\0' }; |
|
|
|
|
|
/* |
|
* Registers a PHP script. |
|
*/ |
|
|
|
API_FUNC(register) |
|
{ |
|
zend_string *name, *author, *version, *license, *description, *charset; |
|
zval *shutdown_func; |
|
const char *shutdown_func_name; |
|
|
|
API_INIT_FUNC(0, "register", API_RETURN_ERROR); |
|
if (php_registered_script) |
|
{ |
|
/* script already registered */ |
|
weechat_printf (NULL, |
|
weechat_gettext ("%s%s: script \"%s\" already " |
|
"registered (register ignored)"), |
|
weechat_prefix ("error"), PHP_PLUGIN_NAME, |
|
php_registered_script->name); |
|
API_RETURN_ERROR; |
|
} |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSSSzS", |
|
&name, &author, &version, &license, &description, |
|
&shutdown_func, &charset) == FAILURE) |
|
{ |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
} |
|
|
|
php_current_script = NULL; |
|
php_registered_script = NULL; |
|
|
|
if (plugin_script_search (weechat_php_plugin, php_scripts, ZSTR_VAL(name))) |
|
{ |
|
/* another script already exists with same name */ |
|
weechat_printf (NULL, |
|
weechat_gettext ("%s%s: unable to register script " |
|
"\"%s\" (another script already " |
|
"exists with this name)"), |
|
weechat_prefix ("error"), PHP_PLUGIN_NAME, |
|
ZSTR_VAL(name)); |
|
API_RETURN_ERROR; |
|
} |
|
|
|
/* resolve shutdown func */ |
|
shutdown_func_name = NULL; |
|
if (zend_is_callable (shutdown_func, 0, NULL)) |
|
{ |
|
weechat_php_get_function_name (shutdown_func, shutdown_func_name_tmp); |
|
shutdown_func_name = shutdown_func_name_tmp; |
|
} |
|
|
|
/* register script */ |
|
php_current_script = plugin_script_add (weechat_php_plugin, |
|
&php_data, |
|
(php_current_script_filename) ? |
|
php_current_script_filename : "", |
|
ZSTR_VAL(name), |
|
ZSTR_VAL(author), |
|
ZSTR_VAL(version), |
|
ZSTR_VAL(license), |
|
ZSTR_VAL(description), |
|
shutdown_func_name, |
|
ZSTR_VAL(charset)); |
|
if (php_current_script) |
|
{ |
|
php_registered_script = php_current_script; |
|
if ((weechat_php_plugin->debug >= 2) || !php_quiet) |
|
{ |
|
weechat_printf (NULL, |
|
weechat_gettext ("%s: registered script \"%s\", " |
|
"version %s (%s)"), |
|
PHP_PLUGIN_NAME, ZSTR_VAL(name), ZSTR_VAL(version), |
|
ZSTR_VAL(description)); |
|
} |
|
} |
|
else |
|
{ |
|
API_RETURN_ERROR; |
|
} |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
/* |
|
* Generic PHP callback function. |
|
*/ |
|
|
|
static void |
|
weechat_php_cb (const void *pointer, void *data, void **func_argv, |
|
const char *func_types, int func_type, void *rc) |
|
{ |
|
struct t_plugin_script *script; |
|
const char *ptr_function, *ptr_data; |
|
void *ret; |
|
|
|
script = (struct t_plugin_script *)pointer; |
|
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); |
|
|
|
func_argv[0] = ptr_data ? (char *)ptr_data : weechat_php_empty_arg; |
|
|
|
if (!ptr_function || !ptr_function[0]) |
|
{ |
|
goto weechat_php_cb_err; |
|
} |
|
|
|
ret = weechat_php_exec (script, func_type, ptr_function, |
|
func_types, func_argv); |
|
|
|
if (!ret) |
|
{ |
|
goto weechat_php_cb_err; |
|
} |
|
|
|
if (func_type == WEECHAT_SCRIPT_EXEC_INT) |
|
{ |
|
*((int *)rc) = *((int *)ret); |
|
free (ret); |
|
} |
|
else if (func_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) |
|
{ |
|
*((struct t_hashtable **)rc) = (struct t_hashtable *)ret; |
|
} |
|
else |
|
{ |
|
*((char **)rc) = (char *)ret; |
|
} |
|
return; |
|
|
|
weechat_php_cb_err: |
|
if (func_type == WEECHAT_SCRIPT_EXEC_INT) |
|
{ |
|
*((int *)rc) = WEECHAT_RC_ERROR; |
|
} |
|
else if (func_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) |
|
{ |
|
*((struct t_hashtable **)rc) = NULL; |
|
} |
|
else |
|
{ |
|
*((char **)rc) = NULL; |
|
} |
|
} |
|
|
|
/* |
|
* Wrappers for functions in scripting API. |
|
* |
|
* For more info about these functions, look at their implementation in WeeChat |
|
* core. |
|
*/ |
|
|
|
API_FUNC(plugin_get_name) |
|
{ |
|
zend_string *z_plugin; |
|
struct t_weechat_plugin *plugin; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_plugin) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
plugin = API_STR2PTR(ZSTR_VAL(z_plugin)); |
|
|
|
result = weechat_plugin_get_name (plugin); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(charset_set) |
|
{ |
|
zend_string *z_charset; |
|
char *charset; |
|
|
|
API_INIT_FUNC(1, "charset_set", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_charset) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
charset = ZSTR_VAL(z_charset); |
|
|
|
plugin_script_api_charset_set (php_current_script, (const char *)charset); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(iconv_to_internal) |
|
{ |
|
zend_string *z_charset, *z_string; |
|
char *charset, *string, *result; |
|
|
|
API_INIT_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", |
|
&z_charset, &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
charset = ZSTR_VAL(z_charset); |
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_iconv_to_internal ((const char *)charset, |
|
(const char *)string); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(iconv_from_internal) |
|
{ |
|
zend_string *z_charset, *z_string; |
|
char *charset, *string, *result; |
|
|
|
API_INIT_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", |
|
&z_charset, &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
charset = ZSTR_VAL(z_charset); |
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_iconv_from_internal ((const char *)charset, |
|
(const char *)string); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(gettext) |
|
{ |
|
zend_string *z_string; |
|
char *string; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "gettext", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_gettext ((const char *)string); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(ngettext) |
|
{ |
|
zend_string *z_single, *z_plural; |
|
zend_long z_count; |
|
char *single, *plural; |
|
int count; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "ngettext", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSl", |
|
&z_single, &z_plural, &z_count) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
single = ZSTR_VAL(z_single); |
|
plural = ZSTR_VAL(z_plural); |
|
count = (int)z_count; |
|
|
|
result = weechat_ngettext ((const char *)single, |
|
(const char *)plural, |
|
count); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(strlen_screen) |
|
{ |
|
zend_string *z_string; |
|
char *string; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "strlen_screen", API_RETURN_INT(0)); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_strlen_screen ((const char *)string); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_match) |
|
{ |
|
zend_string *z_string, *z_mask; |
|
zend_long z_case_sensitive; |
|
int case_sensitive, result; |
|
char *string, *mask; |
|
|
|
API_INIT_FUNC(1, "string_match", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSl", &z_string, &z_mask, |
|
&z_case_sensitive) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
mask = ZSTR_VAL(z_mask); |
|
case_sensitive = (int)z_case_sensitive; |
|
|
|
result = weechat_string_match ((const char *)string, |
|
(const char *)mask, |
|
case_sensitive); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_match_list) |
|
{ |
|
zend_string *z_string, *z_masks; |
|
zend_long z_case_sensitive; |
|
int case_sensitive, result; |
|
char *string, *masks; |
|
|
|
API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSl", &z_string, &z_masks, |
|
&z_case_sensitive) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
masks = ZSTR_VAL(z_masks); |
|
case_sensitive = (int)z_case_sensitive; |
|
|
|
result = plugin_script_api_string_match_list (weechat_php_plugin, |
|
(const char *)string, |
|
(const char *)masks, |
|
case_sensitive); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_has_highlight) |
|
{ |
|
zend_string *z_string, *z_highlight_words; |
|
char *string, *highlight_words; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_string, |
|
&z_highlight_words) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
highlight_words = ZSTR_VAL(z_highlight_words); |
|
|
|
result = weechat_string_has_highlight ((const char *)string, |
|
(const char *)highlight_words); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_has_highlight_regex) |
|
{ |
|
zend_string *z_string, *z_regex; |
|
char *string, *regex; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_string, |
|
&z_regex) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
regex = ZSTR_VAL(z_regex); |
|
|
|
result = weechat_string_has_highlight_regex ((const char *)string, |
|
(const char *)regex); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_mask_to_regex) |
|
{ |
|
zend_string *z_mask; |
|
char *mask, *result; |
|
|
|
API_INIT_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_mask) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
mask = ZSTR_VAL(z_mask); |
|
|
|
result = weechat_string_mask_to_regex ((const char *)mask); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(string_format_size) |
|
{ |
|
zend_long z_size; |
|
char *result; |
|
|
|
API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "l", &z_size) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
result = weechat_string_format_size ((unsigned long long)z_size); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(string_color_code_size) |
|
{ |
|
zend_string *z_string; |
|
char *string; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "string_color_code_size", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_string_color_code_size ((const char *)string); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_remove_color) |
|
{ |
|
zend_string *z_string, *z_replacement; |
|
char *string, *replacement, *result; |
|
|
|
API_INIT_FUNC(1, "string_remove_color", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_string, |
|
&z_replacement) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
string = ZSTR_VAL(z_string); |
|
replacement = ZSTR_VAL(z_replacement); |
|
|
|
result = weechat_string_remove_color ((const char *)string, |
|
(const char *)replacement); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(string_is_command_char) |
|
{ |
|
zend_string *z_string; |
|
char *string; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_string_is_command_char ((const char *)string); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(string_input_for_buffer) |
|
{ |
|
zend_string *z_string; |
|
char *string; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_string) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
string = ZSTR_VAL(z_string); |
|
|
|
result = weechat_string_input_for_buffer ((const char *)string); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(string_eval_expression) |
|
{ |
|
zend_string *z_expr; |
|
zval *z_pointers, *z_extra_vars, *z_options; |
|
char *expr, *result; |
|
struct t_hashtable *pointers, *extra_vars, *options; |
|
|
|
API_INIT_FUNC(1, "string_eval_expression", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Saaa", &z_expr, &z_pointers, |
|
&z_extra_vars, &z_options) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
expr = ZSTR_VAL(z_expr); |
|
pointers = weechat_php_array_to_hashtable ( |
|
z_pointers, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_POINTER); |
|
extra_vars = weechat_php_array_to_hashtable ( |
|
z_extra_vars, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_STRING); |
|
options = weechat_php_array_to_hashtable ( |
|
z_options, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_STRING); |
|
|
|
result = weechat_string_eval_expression ((const char *)expr, |
|
pointers, |
|
extra_vars, |
|
options); |
|
|
|
if (pointers) |
|
weechat_hashtable_free (pointers); |
|
if (extra_vars) |
|
weechat_hashtable_free (extra_vars); |
|
if (options) |
|
weechat_hashtable_free (options); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(string_eval_path_home) |
|
{ |
|
zend_string *z_path; |
|
zval *z_pointers, *z_extra_vars, *z_options; |
|
char *path, *result; |
|
struct t_hashtable *pointers, *extra_vars, *options; |
|
|
|
API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Saaa", |
|
&z_path, &z_pointers, &z_extra_vars, |
|
&z_options) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
path = ZSTR_VAL(z_path); |
|
pointers = weechat_php_array_to_hashtable ( |
|
z_pointers, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_POINTER); |
|
extra_vars = weechat_php_array_to_hashtable ( |
|
z_extra_vars, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_STRING); |
|
options = weechat_php_array_to_hashtable ( |
|
z_options, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_STRING); |
|
|
|
result = weechat_string_eval_path_home ((const char *)path, |
|
pointers, |
|
extra_vars, |
|
options); |
|
|
|
if (pointers) |
|
weechat_hashtable_free (pointers); |
|
if (extra_vars) |
|
weechat_hashtable_free (extra_vars); |
|
if (options) |
|
weechat_hashtable_free (options); |
|
|
|
API_RETURN_STRING_FREE(result); |
|
} |
|
|
|
API_FUNC(mkdir_home) |
|
{ |
|
zend_string *z_directory; |
|
zend_long z_mode; |
|
char *directory; |
|
int mode; |
|
|
|
API_INIT_FUNC(1, "mkdir_home", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", &z_directory, |
|
&z_mode) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
directory = ZSTR_VAL(z_directory); |
|
mode = (int)z_mode; |
|
|
|
if (weechat_mkdir_home ((const char *)directory, mode)) |
|
API_RETURN_OK; |
|
|
|
API_RETURN_ERROR; |
|
} |
|
|
|
API_FUNC(mkdir) |
|
{ |
|
zend_string *z_directory; |
|
zend_long z_mode; |
|
char *directory; |
|
int mode; |
|
|
|
API_INIT_FUNC(1, "mkdir", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", &z_directory, |
|
&z_mode) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
directory = ZSTR_VAL(z_directory); |
|
mode = (int)z_mode; |
|
|
|
if (weechat_mkdir ((const char *)directory, mode)) |
|
API_RETURN_OK; |
|
|
|
API_RETURN_ERROR; |
|
} |
|
|
|
API_FUNC(mkdir_parents) |
|
{ |
|
zend_string *z_directory; |
|
zend_long z_mode; |
|
char *directory; |
|
int mode; |
|
|
|
API_INIT_FUNC(1, "mkdir_parents", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", &z_directory, |
|
&z_mode) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
directory = ZSTR_VAL(z_directory); |
|
mode = (int)z_mode; |
|
|
|
if (weechat_mkdir_parents ((const char *)directory, mode)) |
|
API_RETURN_OK; |
|
|
|
API_RETURN_ERROR; |
|
} |
|
|
|
API_FUNC(list_new) |
|
{ |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_new", API_RETURN_EMPTY); |
|
if (zend_parse_parameters_none () == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
result = API_PTR2STR(weechat_list_new ()); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_add) |
|
{ |
|
zend_string *z_weelist, *z_data, *z_where, *z_user_data; |
|
struct t_weelist *weelist; |
|
char *data, *where; |
|
void *user_data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_add", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSS", &z_weelist, &z_data, |
|
&z_where, &z_user_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
data = ZSTR_VAL(z_data); |
|
where = ZSTR_VAL(z_where); |
|
user_data = (void *)API_STR2PTR(ZSTR_VAL(z_user_data)); |
|
|
|
result = API_PTR2STR(weechat_list_add (weelist, |
|
(const char *)data, |
|
(const char *)where, |
|
user_data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_search) |
|
{ |
|
zend_string *z_weelist, *z_data; |
|
struct t_weelist *weelist; |
|
char *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_search", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_weelist, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR(weechat_list_search (weelist, (const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_search_pos) |
|
{ |
|
zend_string *z_weelist, *z_data; |
|
struct t_weelist *weelist; |
|
char *data; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_weelist, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(-1)); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = weechat_list_search_pos (weelist, (const char *)data); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(list_casesearch) |
|
{ |
|
zend_string *z_weelist, *z_data; |
|
struct t_weelist *weelist; |
|
char *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_casesearch", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_weelist, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
weechat_list_casesearch (weelist, (const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_casesearch_pos) |
|
{ |
|
zend_string *z_weelist, *z_data; |
|
struct t_weelist *weelist; |
|
char *data; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_weelist, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(-1)); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = weechat_list_casesearch_pos (weelist, (const char *)data); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(list_get) |
|
{ |
|
zend_string *z_weelist; |
|
zend_long z_position; |
|
struct t_weelist *weelist; |
|
int position; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_get", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", &z_weelist, |
|
&z_position) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
position = (int)z_position; |
|
|
|
result = API_PTR2STR(weechat_list_get (weelist, position)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_set) |
|
{ |
|
zend_string *z_item, *z_value; |
|
struct t_weelist_item *item; |
|
char *value; |
|
|
|
API_INIT_FUNC(1, "list_set", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_item, |
|
&z_value) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
item = (struct t_weelist_item *)API_STR2PTR(ZSTR_VAL(z_item)); |
|
value = ZSTR_VAL(z_value); |
|
|
|
weechat_list_set (item, (const char *)value); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(list_next) |
|
{ |
|
zend_string *z_item; |
|
struct t_weelist_item *item; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_next", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_item) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
item = (struct t_weelist_item *)API_STR2PTR(ZSTR_VAL(z_item)); |
|
|
|
result = API_PTR2STR(weechat_list_next (item)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_prev) |
|
{ |
|
zend_string *z_item; |
|
struct t_weelist_item *item; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "list_prev", API_RETURN_EMPTY); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_item) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
item = (struct t_weelist_item *)API_STR2PTR(ZSTR_VAL(z_item)); |
|
|
|
result = API_PTR2STR(weechat_list_prev (item)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_string) |
|
{ |
|
zend_string *z_item; |
|
const char *result; |
|
struct t_weelist_item *item; |
|
|
|
API_INIT_FUNC(1, "list_string", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_item) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
item = (struct t_weelist_item *)API_STR2PTR(ZSTR_VAL(z_item)); |
|
|
|
result = weechat_list_string (item); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(list_size) |
|
{ |
|
zend_string *z_weelist; |
|
struct t_weelist *weelist; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "list_size", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_weelist) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
|
|
result = weechat_list_size (weelist); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(list_remove) |
|
{ |
|
zend_string *z_weelist, *z_item; |
|
struct t_weelist *weelist; |
|
struct t_weelist_item *item; |
|
|
|
API_INIT_FUNC(1, "list_remove", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_weelist, |
|
&z_item) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
item = (struct t_weelist_item *)API_STR2PTR(ZSTR_VAL(z_item)); |
|
|
|
weechat_list_remove (weelist, item); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(list_remove_all) |
|
{ |
|
zend_string *z_weelist; |
|
struct t_weelist *weelist; |
|
|
|
API_INIT_FUNC(1, "list_remove_all", API_RETURN_ERROR); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_weelist) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
|
|
weechat_list_remove_all (weelist); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(list_free) |
|
{ |
|
zend_string *z_weelist; |
|
struct t_weelist *weelist; |
|
|
|
API_INIT_FUNC(1, "list_free", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_weelist) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
weelist = (struct t_weelist *)API_STR2PTR(ZSTR_VAL(z_weelist)); |
|
|
|
weechat_list_free (weelist); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
static int |
|
weechat_php_api_config_reload_cb (const void *pointer, void *data, |
|
struct t_config_file *config_file) |
|
{ |
|
int rc; |
|
void *func_argv[2]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(config_file); |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(config_new) |
|
{ |
|
zend_string *z_name; |
|
zval *z_callback_reload; |
|
zend_string *z_data; |
|
char *name, *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_new", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SzS", &z_name, |
|
&z_callback_reload, &z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
name = ZSTR_VAL(z_name); |
|
weechat_php_get_function_name (z_callback_reload, callback_reload_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_config_new ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)name, |
|
&weechat_php_api_config_reload_cb, |
|
(const char *)callback_reload_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_config_section_read_cb (const void *pointer, void *data, |
|
struct t_config_file *config_file, |
|
struct t_config_section *section, |
|
const char *option_name, |
|
const char *value) |
|
{ |
|
int rc; |
|
void *func_argv[5]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(config_file); |
|
func_argv[2] = (char *)API_PTR2STR(section); |
|
func_argv[3] = option_name ? (char *)option_name : weechat_php_empty_arg; |
|
func_argv[4] = value ? (char *)value : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sssss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
static int |
|
weechat_php_api_config_section_write_cb (const void *pointer, void *data, |
|
struct t_config_file *config_file, |
|
const char *section_name) |
|
{ |
|
int rc; |
|
void *func_argv[3]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(config_file); |
|
func_argv[2] = section_name ? (char *)section_name : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
static int |
|
weechat_php_api_config_section_write_default_cb (const void *pointer, |
|
void *data, |
|
struct t_config_file *config_file, |
|
const char *section_name) |
|
{ |
|
int rc; |
|
void *func_argv[3]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(config_file); |
|
func_argv[2] = section_name ? (char *)section_name : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
static int |
|
weechat_php_api_config_section_create_option_cb (const void *pointer, |
|
void *data, |
|
struct t_config_file *config_file, |
|
struct t_config_section *section, |
|
const char *option_name, |
|
const char *value) |
|
{ |
|
int rc; |
|
void *func_argv[5]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(config_file); |
|
func_argv[2] = (char *)API_PTR2STR(section); |
|
func_argv[3] = option_name ? (char *)option_name : weechat_php_empty_arg; |
|
func_argv[4] = value ? (char *)value : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sssss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
static int |
|
weechat_php_api_config_section_delete_option_cb (const void *pointer, |
|
void *data, |
|
struct t_config_file *config_file, |
|
struct t_config_section *section, |
|
struct t_config_option *option) |
|
{ |
|
int rc; |
|
void *func_argv[4]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(config_file); |
|
func_argv[2] = (char *)API_PTR2STR(section); |
|
func_argv[3] = (char *)API_PTR2STR(option); |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ssss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(config_new_section) |
|
{ |
|
zend_string *z_config_file, *z_name; |
|
zend_long z_user_can_add_options, z_user_can_delete_options; |
|
zval *z_callback_read, *z_callback_write, *z_callback_write_default; |
|
zval *z_callback_create_option, *z_callback_delete_option; |
|
zend_string *z_data_read, *z_data_write, *z_data_write_default; |
|
zend_string *z_data_create_option, *z_data_delete_option; |
|
struct t_config_file *config_file; |
|
char *name; |
|
int user_can_add_options, user_can_delete_options; |
|
char *data_read, *data_write, *data_write_default; |
|
char *data_create_option, *data_delete_option; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_new_section", API_RETURN_EMPTY); |
|
if (zend_parse_parameters ( |
|
ZEND_NUM_ARGS(), "SSllzSzSzSzSzS", &z_config_file, &z_name, |
|
&z_user_can_add_options, &z_user_can_delete_options, |
|
&z_callback_read, &z_data_read, &z_callback_write, &z_data_write, |
|
&z_callback_write_default, &z_data_write_default, |
|
&z_callback_create_option, &z_data_create_option, |
|
&z_callback_delete_option, &z_data_delete_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
name = ZSTR_VAL(z_name); |
|
user_can_add_options = (int)z_user_can_add_options; |
|
user_can_delete_options = (int)z_user_can_delete_options; |
|
weechat_php_get_function_name (z_callback_read, callback_read_name); |
|
data_read = ZSTR_VAL(z_data_read); |
|
weechat_php_get_function_name (z_callback_write, callback_write_name); |
|
data_write = ZSTR_VAL(z_data_write); |
|
weechat_php_get_function_name (z_callback_write_default, |
|
callback_write_default_name); |
|
data_write_default = ZSTR_VAL(z_data_write_default); |
|
weechat_php_get_function_name (z_callback_create_option, |
|
callback_create_option_name); |
|
data_create_option = ZSTR_VAL(z_data_create_option); |
|
weechat_php_get_function_name (z_callback_delete_option, |
|
callback_delete_option_name); |
|
data_delete_option = ZSTR_VAL(z_data_delete_option); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_config_new_section ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
config_file, |
|
(const char *)name, |
|
user_can_add_options, |
|
user_can_delete_options, |
|
&weechat_php_api_config_section_read_cb, |
|
(const char *)callback_read_name, |
|
(const char *)data_read, |
|
&weechat_php_api_config_section_write_cb, |
|
(const char *)callback_write_name, |
|
(const char *)data_write, |
|
&weechat_php_api_config_section_write_default_cb, |
|
(const char *)callback_write_default_name, |
|
(const char *)data_write_default, |
|
&weechat_php_api_config_section_create_option_cb, |
|
(const char *)callback_create_option_name, |
|
(const char *)data_create_option, |
|
&weechat_php_api_config_section_delete_option_cb, |
|
(const char *)callback_delete_option_name, |
|
(const char *)data_delete_option)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_search_section) |
|
{ |
|
zend_string *z_config_file, *z_section_name; |
|
struct t_config_file *config_file; |
|
char *section_name; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_search_section", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_config_file, |
|
&z_section_name) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
section_name = ZSTR_VAL(z_section_name); |
|
|
|
result = API_PTR2STR( |
|
weechat_config_search_section (config_file, |
|
(const char *)section_name)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_config_option_check_value_cb (const void *pointer, |
|
void *data, |
|
struct t_config_option *option, |
|
const char *value) |
|
{ |
|
int rc; |
|
void *func_argv[3]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(option); |
|
func_argv[2] = value ? (char *)value : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
static void |
|
weechat_php_api_config_option_change_cb (const void *pointer, |
|
void *data, |
|
struct t_config_option *option) |
|
{ |
|
int *rc; |
|
void *func_argv[2]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(option); |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
} |
|
|
|
static void |
|
weechat_php_api_config_option_delete_cb (const void *pointer, |
|
void *data, |
|
struct t_config_option *option) |
|
{ |
|
int rc; |
|
void *func_argv[2]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(option); |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
} |
|
|
|
API_FUNC(config_new_option) |
|
{ |
|
zend_string *z_config_file, *z_section, *z_name, *z_type, *z_description; |
|
zend_string *z_string_values, *z_default_value, *z_value; |
|
zend_string *z_data_check_value, *z_data_change, *z_data_delete; |
|
zend_long z_min, z_max, z_null_value_allowed; |
|
zval *z_callback_check_value, *z_callback_change, *z_callback_delete; |
|
struct t_config_file *config_file; |
|
struct t_config_section *section; |
|
char *name, *type, *description, *string_values, *default_value, *value; |
|
char *data_check_value, *data_change, *data_delete; |
|
int min, max, null_value_allowed; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_new_option", API_RETURN_EMPTY); |
|
if (zend_parse_parameters ( |
|
ZEND_NUM_ARGS(), "SSSSSSllSSlzSzSzS", &z_config_file, &z_section, |
|
&z_name, &z_type, &z_description, &z_string_values, &z_min, &z_max, |
|
&z_default_value, &z_value, &z_null_value_allowed, |
|
&z_callback_check_value, &z_data_check_value, &z_callback_change, |
|
&z_data_change, &z_callback_delete, &z_data_delete) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
section = (struct t_config_section *)API_STR2PTR(ZSTR_VAL(z_section)); |
|
name = ZSTR_VAL(z_name); |
|
type = ZSTR_VAL(z_type); |
|
description = ZSTR_VAL(z_description); |
|
string_values = ZSTR_VAL(z_string_values); |
|
min = (int)z_min; |
|
max = (int)z_max; |
|
default_value = ZSTR_VAL(z_default_value); |
|
value = ZSTR_VAL(z_value); |
|
null_value_allowed = (int)z_null_value_allowed; |
|
weechat_php_get_function_name (z_callback_check_value, |
|
callback_check_value_name); |
|
data_check_value = ZSTR_VAL(z_data_check_value); |
|
weechat_php_get_function_name (z_callback_change, callback_change_name); |
|
data_change = ZSTR_VAL(z_data_change); |
|
weechat_php_get_function_name (z_callback_delete, callback_delete_name); |
|
data_delete = ZSTR_VAL(z_data_delete); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_config_new_option ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
config_file, |
|
section, |
|
(const char *)name, |
|
(const char *)type, |
|
(const char *)description, |
|
(const char *)string_values, |
|
min, |
|
max, |
|
(const char *)default_value, |
|
(const char *)value, |
|
null_value_allowed, |
|
&weechat_php_api_config_option_check_value_cb, |
|
(const char *)callback_check_value_name, |
|
(const char *)data_check_value, |
|
&weechat_php_api_config_option_change_cb, |
|
(const char *)callback_change_name, |
|
(const char *)data_change, |
|
&weechat_php_api_config_option_delete_cb, |
|
(const char *)callback_delete_name, |
|
(const char *)data_delete)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_search_option) |
|
{ |
|
zend_string *z_config_file, *z_section, *z_option_name; |
|
struct t_config_file *config_file; |
|
struct t_config_section *section; |
|
char *option_name; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_search_option", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSS", |
|
&z_config_file, &z_section, |
|
&z_option_name) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
section = (struct t_config_section *)API_STR2PTR(ZSTR_VAL(z_section)); |
|
option_name = ZSTR_VAL(z_option_name); |
|
|
|
result = API_PTR2STR( |
|
weechat_config_search_option (config_file, section, |
|
(const char *)option_name)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_string_to_boolean) |
|
{ |
|
zend_string *z_text; |
|
char *text; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_text) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
text = ZSTR_VAL(z_text); |
|
|
|
result = weechat_config_string_to_boolean ((const char *)text); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_reset) |
|
{ |
|
zend_string *z_option; |
|
zend_long z_run_callback; |
|
struct t_config_option *option; |
|
int run_callback, result; |
|
|
|
API_INIT_FUNC(1, "config_option_reset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", |
|
&z_option, &z_run_callback) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
run_callback = (int)z_run_callback; |
|
|
|
result = weechat_config_option_reset (option, run_callback); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_set) |
|
{ |
|
zend_string *z_option, *z_value; |
|
zend_long z_run_callback; |
|
struct t_config_option *option; |
|
char *value; |
|
int run_callback, result; |
|
|
|
API_INIT_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSl", |
|
&z_option, &z_value, |
|
&z_run_callback) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
value = ZSTR_VAL(z_value); |
|
run_callback = (int)z_run_callback; |
|
|
|
result = weechat_config_option_set (option, (const char *)value, |
|
run_callback); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_set_null) |
|
{ |
|
zend_string *z_option; |
|
zend_long z_run_callback; |
|
struct t_config_option *option; |
|
int run_callback, result; |
|
|
|
API_INIT_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", |
|
&z_option, &z_run_callback) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
run_callback = (int)z_run_callback; |
|
|
|
result = weechat_config_option_set_null (option, run_callback); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_unset) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_option_unset (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_rename) |
|
{ |
|
zend_string *z_option, *z_new_name; |
|
struct t_config_option *option; |
|
char *new_name; |
|
|
|
API_INIT_FUNC(1, "config_option_rename", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", |
|
&z_option, &z_new_name) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
new_name = ZSTR_VAL(z_new_name); |
|
|
|
weechat_config_option_rename (option, (const char *)new_name); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_option_is_null) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(1)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_option_is_null (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_default_is_null) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(1)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_option_default_is_null (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_boolean) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_boolean", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_boolean (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_boolean_default) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_boolean_default (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_integer) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_integer", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_integer (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_integer_default) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_integer_default", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_integer_default (option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_string) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_string", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_string (option); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_string_default) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_string_default", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_string_default (option); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_color) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_color", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_color (option); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_color_default) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_color_default", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
result = weechat_config_color_default (option); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_write_option) |
|
{ |
|
zend_string *z_config_file, *z_option; |
|
struct t_config_file *config_file; |
|
struct t_config_option *option; |
|
|
|
API_INIT_FUNC(1, "config_write_option", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_config_file, |
|
&z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
weechat_config_write_option (config_file, option); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_write_line) |
|
{ |
|
zend_string *z_config_file, *z_option_name, *z_value; |
|
struct t_config_file *config_file; |
|
char *option_name, *value; |
|
|
|
API_INIT_FUNC(1, "config_write_line", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSS", &z_config_file, |
|
&z_option_name, &z_value) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
option_name = ZSTR_VAL(z_option_name); |
|
value = ZSTR_VAL(z_value); |
|
|
|
weechat_config_write_line (config_file, |
|
(const char *)option_name, |
|
(const char *)value); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_write) |
|
{ |
|
zend_string *z_config_file; |
|
struct t_config_file *config_file; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_write", API_RETURN_INT(WEECHAT_CONFIG_WRITE_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", |
|
&z_config_file) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_WRITE_ERROR)); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
|
|
result = weechat_config_write (config_file); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_read) |
|
{ |
|
zend_string *z_config_file; |
|
struct t_config_file *config_file; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_read", API_RETURN_INT(WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", |
|
&z_config_file) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
|
|
result = weechat_config_read (config_file); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_reload) |
|
{ |
|
zend_string *z_config_file; |
|
struct t_config_file *config_file; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_reload", API_RETURN_INT(WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", |
|
&z_config_file) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
|
|
result = weechat_config_reload (config_file); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_option_free) |
|
{ |
|
zend_string *z_option; |
|
struct t_config_option *option; |
|
|
|
API_INIT_FUNC(1, "config_option_free", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option)); |
|
|
|
weechat_config_option_free (option); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_section_free_options) |
|
{ |
|
zend_string *z_section; |
|
struct t_config_section *section; |
|
|
|
API_INIT_FUNC(1, "config_section_free_options", API_RETURN_ERROR); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_section) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
section = (struct t_config_section *)API_STR2PTR(ZSTR_VAL(z_section)); |
|
|
|
weechat_config_section_free_options (section); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_section_free) |
|
{ |
|
zend_string *z_section; |
|
struct t_config_section *section; |
|
|
|
API_INIT_FUNC(1, "config_section_free", API_RETURN_ERROR); |
|
|
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_section) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
section = (struct t_config_section *)API_STR2PTR(ZSTR_VAL(z_section)); |
|
|
|
weechat_config_section_free (section); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_free) |
|
{ |
|
zend_string *z_config_file; |
|
struct t_config_file *config_file; |
|
|
|
API_INIT_FUNC(1, "config_free", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", |
|
&z_config_file) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file)); |
|
|
|
weechat_config_free (config_file); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_get) |
|
{ |
|
zend_string *z_option_name; |
|
char *option_name; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_get", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", |
|
&z_option_name) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
option_name = ZSTR_VAL(z_option_name); |
|
|
|
result = API_PTR2STR(weechat_config_get ((const char *)option_name)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_get_plugin) |
|
{ |
|
zend_string *z_option; |
|
char *option; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
option = ZSTR_VAL(z_option); |
|
|
|
result = plugin_script_api_config_get_plugin (weechat_php_plugin, |
|
php_current_script, |
|
(const char *)option); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(config_is_set_plugin) |
|
{ |
|
zend_string *z_option; |
|
char *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
option = ZSTR_VAL(z_option); |
|
|
|
result = plugin_script_api_config_is_set_plugin (weechat_php_plugin, |
|
php_current_script, |
|
(const char *)option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_set_plugin) |
|
{ |
|
zend_string *z_option, *z_value; |
|
char *option, *value; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_option, |
|
&z_value) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); |
|
|
|
option = ZSTR_VAL(z_option); |
|
value = ZSTR_VAL(z_value); |
|
|
|
result = plugin_script_api_config_set_plugin (weechat_php_plugin, |
|
php_current_script, |
|
(const char *)option, |
|
(const char *)value); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(config_set_desc_plugin) |
|
{ |
|
zend_string *z_option, *z_description; |
|
char *option, *description; |
|
|
|
API_INIT_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_option, |
|
&z_description) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
option = ZSTR_VAL(z_option); |
|
description = ZSTR_VAL(z_description); |
|
|
|
plugin_script_api_config_set_desc_plugin (weechat_php_plugin, |
|
php_current_script, |
|
(const char *)option, |
|
(const char *)description); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(config_unset_plugin) |
|
{ |
|
zend_string *z_option; |
|
char *option; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); |
|
|
|
option = ZSTR_VAL(z_option); |
|
|
|
result = plugin_script_api_config_unset_plugin (weechat_php_plugin, |
|
php_current_script, |
|
(const char *)option); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(key_bind) |
|
{ |
|
zend_string *z_context; |
|
zval *z_keys; |
|
char *context; |
|
struct t_hashtable *keys; |
|
int result; |
|
|
|
API_INIT_FUNC(1, "key_bind", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sa", &z_context, |
|
&z_keys) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
context = ZSTR_VAL(z_context); |
|
keys = weechat_php_array_to_hashtable (z_keys, |
|
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, |
|
WEECHAT_HASHTABLE_STRING, |
|
WEECHAT_HASHTABLE_STRING); |
|
|
|
result = weechat_key_bind ((const char *)context, keys); |
|
|
|
if (keys) |
|
weechat_hashtable_free (keys); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(key_unbind) |
|
{ |
|
zend_string *z_context, *z_key; |
|
int result; |
|
char *context, *key; |
|
|
|
API_INIT_FUNC(1, "key_unbind", API_RETURN_INT(0)); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_context, |
|
&z_key) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_INT(0)); |
|
|
|
context = ZSTR_VAL(z_context); |
|
key = ZSTR_VAL(z_key); |
|
|
|
result = weechat_key_unbind ((const char *)context, (const char *)key); |
|
|
|
API_RETURN_INT(result); |
|
} |
|
|
|
API_FUNC(prefix) |
|
{ |
|
zend_string *z_prefix; |
|
char *prefix; |
|
const char *result; |
|
|
|
API_INIT_FUNC(0, "prefix", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_prefix) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
prefix = ZSTR_VAL(z_prefix); |
|
|
|
result = weechat_prefix ((const char *)prefix); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(color) |
|
{ |
|
zend_string *z_color_name; |
|
char *color_name; |
|
const char *result; |
|
|
|
API_INIT_FUNC(0, "color", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_color_name) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
color_name = ZSTR_VAL(z_color_name); |
|
|
|
result = weechat_color ((const char *)color_name); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
API_FUNC(print) |
|
{ |
|
zend_string *z_buffer, *z_message; |
|
struct t_gui_buffer *buffer; |
|
char *message; |
|
|
|
API_INIT_FUNC(0, "print", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_buffer, |
|
&z_message) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer)); |
|
message = ZSTR_VAL(z_message); |
|
|
|
plugin_script_api_printf (weechat_php_plugin, php_current_script, buffer, |
|
"%s", message); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(print_date_tags) |
|
{ |
|
zend_string *z_buffer, *z_tags, *z_message; |
|
zend_long z_date; |
|
struct t_gui_buffer *buffer; |
|
time_t date; |
|
char *tags, *message; |
|
|
|
API_INIT_FUNC(1, "print_date_tags", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SlSS", &z_buffer, &z_date, |
|
&z_tags, &z_message) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer)); |
|
date = (time_t)z_date; |
|
tags = ZSTR_VAL(z_tags); |
|
message = ZSTR_VAL(z_message); |
|
|
|
plugin_script_api_printf_date_tags (weechat_php_plugin, |
|
php_current_script, |
|
buffer, |
|
date, |
|
(const char *)tags, |
|
"%s", |
|
message); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(print_y) |
|
{ |
|
zend_string *z_buffer, *z_message; |
|
zend_long z_y; |
|
struct t_gui_buffer *buffer; |
|
int y; |
|
char *message; |
|
|
|
API_INIT_FUNC(1, "print_y", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SlS", &z_buffer, &z_y, |
|
&z_message) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer)); |
|
y = (int)z_y; |
|
message = ZSTR_VAL(z_message); |
|
|
|
plugin_script_api_printf_y (weechat_php_plugin, |
|
php_current_script, |
|
buffer, |
|
y, |
|
"%s", |
|
message); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
API_FUNC(log_print) |
|
{ |
|
zend_string *z_message; |
|
char *message; |
|
|
|
API_INIT_FUNC(1, "log_print", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_message) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
message = ZSTR_VAL(z_message); |
|
|
|
plugin_script_api_log_printf (weechat_php_plugin, php_current_script, |
|
"%s", message); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_command_cb (const void *pointer, void *data, |
|
struct t_gui_buffer *buffer, |
|
int argc, char **argv, char **argv_eol) |
|
{ |
|
int rc; |
|
void *func_argv[3]; |
|
|
|
/* make C compiler happy */ |
|
(void) argv; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(buffer); |
|
func_argv[2] = (argc > 1) ? argv_eol[1] : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_command) |
|
{ |
|
zend_string *z_command, *z_description, *z_args, *z_args_description; |
|
zend_string *z_completion, *z_data; |
|
zval *z_callback; |
|
char *command, *description, *args, *args_description, *completion, *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_command", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSSSzS", &z_command, |
|
&z_description, &z_args, &z_args_description, |
|
&z_completion, &z_callback, &z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
command = ZSTR_VAL(z_command); |
|
description = ZSTR_VAL(z_description); |
|
args = ZSTR_VAL(z_args); |
|
args_description = ZSTR_VAL(z_args_description); |
|
completion = ZSTR_VAL(z_completion); |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_command ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)command, |
|
(const char *)description, |
|
(const char *)args, |
|
(const char *)args_description, |
|
(const char *)completion, |
|
&weechat_php_api_hook_command_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_completion_cb (const void *pointer, void *data, |
|
const char *completion_item, |
|
struct t_gui_buffer *buffer, |
|
struct t_gui_completion *completion) |
|
{ |
|
int rc; |
|
void *func_argv[4]; |
|
|
|
func_argv[1] = completion_item ? (char *)completion_item : weechat_php_empty_arg; |
|
func_argv[2] = (char *)API_PTR2STR(buffer); |
|
func_argv[3] = (char *)API_PTR2STR(completion); |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ssss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_completion) |
|
{ |
|
zend_string *z_completion, *z_description, *z_data; |
|
zval *z_callback; |
|
char *completion, *description, *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSzS", |
|
&z_completion, &z_description, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
completion = ZSTR_VAL(z_completion); |
|
description = ZSTR_VAL(z_description); |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_completion ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)completion, |
|
(const char *)description, |
|
&weechat_php_api_hook_completion_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
/* |
|
* This function deprecated since WeeChat 2.9, kept for compatibility. |
|
* It is replaced by completion_get_string. |
|
*/ |
|
|
|
API_FUNC(hook_completion_get_string) |
|
{ |
|
zend_string *z_completion, *z_property; |
|
struct t_gui_completion *completion; |
|
char *property; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_completion, |
|
&z_property) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
completion = (struct t_gui_completion *)API_STR2PTR(ZSTR_VAL(z_completion)); |
|
property = ZSTR_VAL(z_property); |
|
|
|
result = weechat_hook_completion_get_string (completion, |
|
(const char *)property); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
/* |
|
* This function deprecated since WeeChat 2.9, kept for compatibility. |
|
* It is replaced by completion_list_add. |
|
*/ |
|
|
|
API_FUNC(hook_completion_list_add) |
|
{ |
|
zend_string *z_completion, *z_word, *z_where; |
|
zend_long z_nick_completion; |
|
struct t_gui_completion *completion; |
|
char *word, *where; |
|
int nick_completion; |
|
|
|
API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSlS", &z_completion, |
|
&z_word, &z_nick_completion, &z_where) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_ERROR); |
|
|
|
completion = (struct t_gui_completion *)API_STR2PTR(ZSTR_VAL(z_completion)); |
|
word = ZSTR_VAL(z_word); |
|
nick_completion = (int)z_nick_completion; |
|
where = ZSTR_VAL(z_where); |
|
|
|
weechat_hook_completion_list_add (completion, |
|
(const char *)word, |
|
nick_completion, |
|
(const char *)where); |
|
|
|
API_RETURN_OK; |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_command_run_cb (const void *pointer, void *data, |
|
struct t_gui_buffer *buffer, |
|
const char *command) |
|
{ |
|
int rc; |
|
void *func_argv[3]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(buffer); |
|
func_argv[2] = command ? (char *)command : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_command_run) |
|
{ |
|
zend_string *z_command, *z_data; |
|
zval *z_callback; |
|
char *command, *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_command_run", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SzS", &z_command, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
command = ZSTR_VAL(z_command); |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_command_run ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)command, |
|
&weechat_php_api_hook_command_run_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_timer_cb (const void *pointer, void *data, |
|
int remaining_calls) |
|
{ |
|
int rc; |
|
void *func_argv[2]; |
|
|
|
func_argv[1] = &remaining_calls; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "si", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_timer) |
|
{ |
|
zend_long z_interval, z_align_second, z_max_calls; |
|
zval *z_callback; |
|
zend_string *z_data; |
|
int interval, align_second, max_calls; |
|
char *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_timer", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "lllzS", &z_interval, |
|
&z_align_second, &z_max_calls, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
interval = (int)z_interval; |
|
align_second = (int)z_align_second; |
|
max_calls = (int)z_max_calls; |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_timer ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
interval, |
|
align_second, |
|
max_calls, |
|
&weechat_php_api_hook_timer_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_fd_cb (const void *pointer, void *data, |
|
int fd) |
|
{ |
|
int rc; |
|
void *func_argv[2]; |
|
|
|
func_argv[1] = &fd; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "si", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_fd) |
|
{ |
|
zend_long z_fd, z_flag_read, z_flag_write, z_flag_exception; |
|
zval *z_callback; |
|
zend_string *z_data; |
|
int fd, flag_read, flag_write, flag_exception; |
|
char *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_fd", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "llllzS", &z_fd, &z_flag_read, |
|
&z_flag_write, &z_flag_exception, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
fd = (int)z_fd; |
|
flag_read = (int)z_flag_read; |
|
flag_write = (int)z_flag_write; |
|
flag_exception = (int)z_flag_exception; |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_fd ( |
|
weechat_php_plugin, |
|
php_current_script, fd, |
|
flag_read, |
|
flag_write, |
|
flag_exception, |
|
&weechat_php_api_hook_fd_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_process_cb (const void *pointer, void *data, |
|
const char *command, int return_code, |
|
const char *out, const char *err) |
|
{ |
|
int rc; |
|
void *func_argv[5]; |
|
|
|
func_argv[1] = command ? (char *)command : weechat_php_empty_arg; |
|
func_argv[2] = &return_code; |
|
func_argv[3] = out ? (char *)out : weechat_php_empty_arg; |
|
func_argv[4] = err ? (char *)err : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ssiss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_process) |
|
{ |
|
zend_string *z_command, *z_data; |
|
zend_long z_timeout; |
|
zval *z_callback; |
|
char *command, *data; |
|
int timeout; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_process", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SlzS", &z_command, &z_timeout, |
|
&z_callback, &z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
command = ZSTR_VAL(z_command); |
|
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_process ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)command, |
|
timeout, |
|
&weechat_php_api_hook_process_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_process_hashtable_cb (const void *pointer, void *data, |
|
const char *command, |
|
int return_code, |
|
const char *out, const char *err) |
|
{ |
|
int rc; |
|
void *func_argv[5]; |
|
|
|
func_argv[1] = command ? (char *)command : weechat_php_empty_arg; |
|
func_argv[2] = &return_code; |
|
func_argv[3] = out ? (char *)out : weechat_php_empty_arg; |
|
func_argv[4] = err ? (char *)err : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ssiss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_process_hashtable) |
|
{ |
|
zend_string *z_command, *z_data; |
|
zval *z_options, *z_callback; |
|
zend_long z_timeout; |
|
char *command, *data; |
|
struct t_hashtable *options; |
|
int timeout; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SalzS", &z_command, |
|
&z_options, &z_timeout, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
command = ZSTR_VAL(z_command); |
|
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_process_hashtable ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)command, |
|
options, |
|
timeout, |
|
&weechat_php_api_hook_process_hashtable_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) |
|
{ |
|
int rc; |
|
void *func_argv[6]; |
|
|
|
func_argv[1] = &status; |
|
func_argv[2] = &gnutls_rc; |
|
func_argv[3] = &sock; |
|
func_argv[4] = error ? (char *)error : weechat_php_empty_arg; |
|
func_argv[5] = ip_address ? (char *)ip_address : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "siiiss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_connect) |
|
{ |
|
zend_string *z_proxy, *z_address, *z_gnutls_sess, *z_gnutls_cb; |
|
zend_string *z_gnutls_priorities, *z_local_hostname, *z_data; |
|
zend_long z_port, z_ipv6, z_retry, z_gnutls_dhkey_size; |
|
zval *z_callback; |
|
char *proxy, *address, *gnutls_priorities, *local_hostname, *data; |
|
int port, ipv6, retry; |
|
void *gnutls_sess, *gnutls_cb; |
|
int gnutls_dhkey_size; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_connect", API_RETURN_EMPTY); |
|
if (zend_parse_parameters ( |
|
ZEND_NUM_ARGS(), "SSlllSSlSSzS", &z_proxy, &z_address, &z_port, |
|
&z_ipv6, &z_retry, &z_gnutls_sess, &z_gnutls_cb, |
|
&z_gnutls_dhkey_size, &z_gnutls_priorities, &z_local_hostname, |
|
&z_callback, &z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
proxy = ZSTR_VAL(z_proxy); |
|
address = ZSTR_VAL(z_address); |
|
port = (int)z_port; |
|
ipv6 = (int)z_ipv6; |
|
retry = (int)z_retry; |
|
gnutls_sess = (void *)API_STR2PTR(ZSTR_VAL(z_gnutls_sess)); |
|
gnutls_cb = (void *)API_STR2PTR(ZSTR_VAL(z_gnutls_cb)); |
|
gnutls_dhkey_size = (int)z_gnutls_dhkey_size; |
|
gnutls_priorities = ZSTR_VAL(z_gnutls_priorities); |
|
local_hostname = ZSTR_VAL(z_local_hostname); |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_connect ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)proxy, |
|
(const char *)address, |
|
port, |
|
ipv6, |
|
retry, |
|
gnutls_sess, |
|
gnutls_cb, |
|
gnutls_dhkey_size, |
|
(const char *)gnutls_priorities, |
|
(const char *)local_hostname, |
|
&weechat_php_api_hook_connect_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
struct t_hashtable * |
|
weechat_php_api_hook_line_cb (const void *pointer, void *data, |
|
struct t_hashtable *line) |
|
{ |
|
struct t_hashtable *rc; |
|
void *func_argv[2]; |
|
|
|
func_argv[1] = line; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "sh", |
|
WEECHAT_SCRIPT_EXEC_HASHTABLE, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_line) |
|
{ |
|
zend_string *z_buffer_type, *z_buffer_name, *z_tags, *z_data; |
|
zval *z_callback; |
|
char *buffer_type, *buffer_name, *tags, *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSzS", |
|
&z_buffer_type, &z_buffer_name, &z_tags, |
|
&z_callback, &z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
weechat_php_get_function_name (z_callback, callback_name); |
|
buffer_type = ZSTR_VAL(z_buffer_type); |
|
buffer_name = ZSTR_VAL(z_buffer_name); |
|
tags = ZSTR_VAL(z_tags); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_line ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
(const char *)buffer_type, |
|
(const char *)buffer_name, |
|
(const char *)tags, |
|
&weechat_php_api_hook_line_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_print_cb (const void *pointer, void *data, |
|
struct t_gui_buffer *buffer, time_t date, |
|
int tags_count, const char **tags, |
|
int displayed, int highlight, |
|
const char *prefix, const char *message) |
|
{ |
|
int rc; |
|
void *func_argv[9]; |
|
|
|
func_argv[1] = (char *)API_PTR2STR(buffer); |
|
func_argv[2] = &date; |
|
func_argv[3] = &tags_count; |
|
func_argv[4] = tags ? (char *)tags : weechat_php_empty_arg; |
|
func_argv[5] = &displayed; |
|
func_argv[6] = &highlight; |
|
func_argv[7] = prefix ? (char *)prefix : weechat_php_empty_arg; |
|
func_argv[8] = message ? (char *)message : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ssiisiiss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_print) |
|
{ |
|
zend_string *z_buffer, *z_tags, *z_message, *z_data; |
|
zend_long z_strip_colors; |
|
zval *z_callback; |
|
struct t_gui_buffer *buffer; |
|
char *tags, *message, *data; |
|
int strip_colors; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_print", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSlzS", &z_buffer, &z_tags, |
|
&z_message, &z_strip_colors, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer)); |
|
tags = ZSTR_VAL(z_tags); |
|
message = ZSTR_VAL(z_message); |
|
strip_colors = (int)z_strip_colors; |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
plugin_script_api_hook_print ( |
|
weechat_php_plugin, |
|
php_current_script, |
|
buffer, |
|
(const char *)tags, |
|
(const char *)message, |
|
strip_colors, |
|
&weechat_php_api_hook_print_cb, |
|
(const char *)callback_name, |
|
(const char *)data)); |
|
|
|
API_RETURN_STRING(result); |
|
} |
|
|
|
static int |
|
weechat_php_api_hook_signal_cb (const void *pointer, void *data, |
|
const char *signal, const char *type_data, |
|
void *signal_data) |
|
{ |
|
int rc; |
|
void *func_argv[4]; |
|
|
|
func_argv[1] = signal ? (char *)signal : weechat_php_empty_arg; |
|
func_argv[2] = type_data ? (char *)type_data : weechat_php_empty_arg; |
|
func_argv[3] = signal_data ? (char *)signal_data : weechat_php_empty_arg; |
|
|
|
weechat_php_cb (pointer, data, func_argv, "ssss", |
|
WEECHAT_SCRIPT_EXEC_INT, &rc); |
|
|
|
return rc; |
|
} |
|
|
|
API_FUNC(hook_signal) |
|
{ |
|
zend_string *z_signal, *z_data; |
|
zval *z_callback; |
|
char *signal, *data; |
|
const char *result; |
|
|
|
API_INIT_FUNC(1, "hook_signal", API_RETURN_EMPTY); |
|
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SzS", &z_signal, &z_callback, |
|
&z_data) == FAILURE) |
|
API_WRONG_ARGS(API_RETURN_EMPTY); |
|
|
|
signal = ZSTR_VAL(z_signal); |
|
weechat_php_get_function_name (z_callback, callback_name); |
|
data = ZSTR_VAL(z_data); |
|
|
|
result = API_PTR2STR( |
|
< |