1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

core: add URL transfer (using libcurl), add function hook_process_hashtable in plugin API, add support of URL in hook_process/hook_process_hashtable (task #10247)

This commit is contained in:
Sebastien Helleu
2012-01-16 19:52:08 +01:00
parent ca07f58406
commit b91c231096
52 changed files with 2049 additions and 56 deletions
+40
View File
@@ -2667,6 +2667,45 @@ weechat_lua_api_hook_process (lua_State *L)
API_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_process_hashtable: hook a process with options in
* a hashtable
*/
static int
weechat_lua_api_hook_process_hashtable (lua_State *L)
{
const char *command, *function, *data;
struct t_hashtable *options;
int timeout;
char *result;
API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY);
if (lua_gettop (lua_current_interpreter) < 5)
API_WRONG_ARGS(API_RETURN_EMPTY);
command = lua_tostring (lua_current_interpreter, -5);
options = weechat_lua_tohashtable (lua_current_interpreter, -4,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
timeout = lua_tonumber (lua_current_interpreter, -3);
function = lua_tostring (lua_current_interpreter, -2);
data = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (script_api_hook_process_hashtable (weechat_lua_plugin,
lua_current_script,
command,
options,
timeout,
&weechat_lua_api_hook_process_cb,
function,
data));
if (options)
weechat_hashtable_free (options);
API_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_connect_cb: callback for connect hooked
*/
@@ -6207,6 +6246,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(hook_timer),
API_DEF_FUNC(hook_fd),
API_DEF_FUNC(hook_process),
API_DEF_FUNC(hook_process_hashtable),
API_DEF_FUNC(hook_connect),
API_DEF_FUNC(hook_print),
API_DEF_FUNC(hook_signal),
@@ -2505,6 +2505,41 @@ XS (XS_weechat_api_hook_process)
API_RETURN_STRING_FREE(result);
}
/*
* weechat::hook_process_hashtable: hook a process with options in a hashtable
*/
XS (XS_weechat_api_hook_process_hashtable)
{
char *command, *function, *data, *result;
struct t_hashtable *options;
dXSARGS;
API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY);
if (items < 5)
API_WRONG_ARGS(API_RETURN_EMPTY);
command = SvPV_nolen (ST (0));
options = weechat_perl_hash_to_hashtable (ST (1),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
function = SvPV_nolen (ST (3));
data = SvPV_nolen (ST (4));
result = script_ptr2str (script_api_hook_process_hashtable (weechat_perl_plugin,
perl_current_script,
command,
options,
SvIV (ST (2)), /* timeout */
&weechat_perl_api_hook_process_cb,
function,
data));
if (options)
weechat_hashtable_free (options);
API_RETURN_STRING_FREE(result);
}
/*
* weechat_perl_api_hook_connect_cb: callback for connect hooked
*/
@@ -5565,6 +5600,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(hook_timer);
API_DEF_FUNC(hook_fd);
API_DEF_FUNC(hook_process);
API_DEF_FUNC(hook_process_hashtable);
API_DEF_FUNC(hook_connect);
API_DEF_FUNC(hook_print);
API_DEF_FUNC(hook_signal);
@@ -2608,6 +2608,46 @@ weechat_python_api_hook_process (PyObject *self, PyObject *args)
API_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_process_hashtable: hook a process with options in
* a hashtable
*/
static PyObject *
weechat_python_api_hook_process_hashtable (PyObject *self, PyObject *args)
{
char *command, *function, *data, *result;
int timeout;
struct t_hashtable *options;
PyObject *dict, *return_value;
API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY);
command = NULL;
options = NULL;
timeout = 0;
function = NULL;
data = NULL;
if (!PyArg_ParseTuple (args, "sOiss", &command, &dict, &timeout, &function,
&data))
API_WRONG_ARGS(API_RETURN_EMPTY);
options = weechat_python_dict_to_hashtable (dict,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
result = script_ptr2str (script_api_hook_process_hashtable (weechat_python_plugin,
python_current_script,
command,
options,
timeout,
&weechat_python_api_hook_process_cb,
function,
data));
if (options)
weechat_hashtable_free (options);
API_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_connect_cb: callback for connect hooked
*/
@@ -5733,6 +5773,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(hook_timer),
API_DEF_FUNC(hook_fd),
API_DEF_FUNC(hook_process),
API_DEF_FUNC(hook_process_hashtable),
API_DEF_FUNC(hook_connect),
API_DEF_FUNC(hook_print),
API_DEF_FUNC(hook_signal),
@@ -2988,6 +2988,54 @@ weechat_ruby_api_hook_process (VALUE class, VALUE command, VALUE timeout,
API_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_process_hashtable: hook a process with options in
* a hashtable
*/
static VALUE
weechat_ruby_api_hook_process_hashtable (VALUE class, VALUE command,
VALUE options, VALUE timeout,
VALUE function, VALUE data)
{
char *c_command, *c_function, *c_data, *result;
struct t_hashtable *c_options;
int c_timeout;
VALUE return_value;
API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY);
if (NIL_P (command) || NIL_P (options) || NIL_P (timeout)
|| NIL_P (function) || NIL_P (data))
API_WRONG_ARGS(API_RETURN_EMPTY);
Check_Type (command, T_STRING);
Check_Type (options, T_HASH);
Check_Type (timeout, T_FIXNUM);
Check_Type (function, T_STRING);
Check_Type (data, T_STRING);
c_command = StringValuePtr (command);
c_options = weechat_ruby_hash_to_hashtable (options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
c_timeout = FIX2INT (timeout);
c_function = StringValuePtr (function);
c_data = StringValuePtr (data);
result = script_ptr2str (script_api_hook_process_hashtable (weechat_ruby_plugin,
ruby_current_script,
c_command,
c_options,
c_timeout,
&weechat_ruby_api_hook_process_cb,
c_function,
c_data));
if (c_options)
weechat_hashtable_free (c_options);
API_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_connect_cb: callback for connect hooked
*/
@@ -6638,6 +6686,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(hook_timer, 5);
API_DEF_FUNC(hook_fd, 6);
API_DEF_FUNC(hook_process, 4);
API_DEF_FUNC(hook_process_hashtable, 5);
API_DEF_FUNC(hook_connect, 8);
API_DEF_FUNC(hook_print, 6);
API_DEF_FUNC(hook_signal, 3);
+47 -23
View File
@@ -859,7 +859,50 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
}
/*
* script_api_hook_connect: hook a connection
* script_api_hook_process_hashtable: hook a process
* return new hook, NULL if error
*/
struct t_hook *
script_api_hook_process_hashtable (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
struct t_hashtable *options,
int timeout,
int (*callback)(void *data,
const char *command,
int return_code,
const char *out,
const char *err),
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
script_callback_init (new_script_callback, script, function, data);
script_callback_add (script, new_script_callback);
new_hook = weechat_hook_process_hashtable (command, options, timeout,
callback, new_script_callback);
if (!new_hook)
{
script_callback_remove (script, new_script_callback);
return NULL;
}
new_script_callback->hook = new_hook;
return new_hook;
}
/*
* script_api_hook_process: hook a process
* return new hook, NULL if error
*/
@@ -876,28 +919,9 @@ script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
script_callback_init (new_script_callback, script, function, data);
script_callback_add (script, new_script_callback);
new_hook = weechat_hook_process (command, timeout, callback,
new_script_callback);
if (!new_hook)
{
script_callback_remove (script, new_script_callback);
return NULL;
}
new_script_callback->hook = new_hook;
return new_hook;
return script_api_hook_process_hashtable (weechat_plugin, script, command,
NULL, timeout,
callback, function, data);
}
/*
+12
View File
@@ -152,6 +152,18 @@ extern struct t_hook *script_api_hook_fd (struct t_weechat_plugin *weechat_plugi
int (*callback)(void *data, int fd),
const char *function,
const char *data);
extern struct t_hook *script_api_hook_process_hashtable (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
struct t_hashtable *options,
int timeout,
int (*callback)(void *data,
const char *command,
int return_code,
const char *out,
const char *err),
const char *function,
const char *data);
extern struct t_hook *script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
+44
View File
@@ -2933,6 +2933,49 @@ weechat_tcl_api_hook_process (ClientData clientData, Tcl_Interp *interp,
API_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_hook_process_hashtable: hook a process with options in
* a hashtable
*/
static int
weechat_tcl_api_hook_process_hashtable (ClientData clientData,
Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
char *command, *function, *data, *result;
struct t_hashtable *options;
int i, timeout;
API_FUNC(1, "hook_process_hashtable", 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);
command = Tcl_GetStringFromObj (objv[1], &i);
options = weechat_tcl_dict_to_hashtable (interp, objv[2],
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
function = Tcl_GetStringFromObj (objv[4], &i);
data = Tcl_GetStringFromObj (objv[5], &i);
result = script_ptr2str (script_api_hook_process_hashtable (weechat_tcl_plugin,
tcl_current_script,
command,
options,
timeout,
&weechat_tcl_api_hook_process_cb,
function,
data));
if (options)
weechat_hashtable_free (options);
API_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_hook_connect_cb: callback for connect hooked
*/
@@ -6380,6 +6423,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(hook_timer);
API_DEF_FUNC(hook_fd);
API_DEF_FUNC(hook_process);
API_DEF_FUNC(hook_process_hashtable);
API_DEF_FUNC(hook_connect);
API_DEF_FUNC(hook_print);
API_DEF_FUNC(hook_signal);