summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2004-10-03 16:29:05 +0000
committerSebastien Helleu <flashcode@flashtux.org>2004-10-03 16:29:05 +0000
commit7ef14b95b69a1adf41006939fc42fa101b309003 (patch)
tree0788024a13eaebab7b7e634ae61f2e025044c8c3 /src
parent4e5f1698ba98ca879ddafc2fdef72c295a50e6b3 (diff)
downloadweechat-7ef14b95b69a1adf41006939fc42fa101b309003.zip
Added IRC::command function for Perl scripts
Diffstat (limited to 'src')
-rw-r--r--src/common/command.c2
-rw-r--r--src/irc/irc-channel.c1
-rw-r--r--src/irc/irc-recv.c2
-rw-r--r--src/irc/irc-server.c4
-rw-r--r--src/irc/irc.h3
-rw-r--r--src/plugins/perl/wee-perl.c99
-rw-r--r--src/plugins/perl/wee-perl.h2
-rw-r--r--src/plugins/plugins.c8
-rw-r--r--src/plugins/plugins.h4
9 files changed, 97 insertions, 28 deletions
diff --git a/src/common/command.c b/src/common/command.c
index f9fbd7828..731049ee0 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -540,7 +540,7 @@ exec_weechat_command (t_irc_server *server, char *string)
ptr_args = NULL;
}
- if (!plugin_exec_command (command + 1, ptr_args))
+ if (!plugin_exec_command (command + 1, server->name, ptr_args))
{
argv = explode_string (ptr_args, " ", 0, &argc);
diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c
index 515635cb6..4dbbc4513 100644
--- a/src/irc/irc-channel.c
+++ b/src/irc/irc-channel.c
@@ -31,7 +31,6 @@
#include "irc.h"
-t_irc_channel *current_channel = NULL;
char *channel_modes = "iklmnst";
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index f203a63d2..70ac0118f 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -76,7 +76,7 @@ irc_recv_command (t_irc_server *server, char *entire_line,
if (irc_commands[i].recv_function != NULL)
{
return_code = (int) (irc_commands[i].recv_function) (server, host, arguments);
- plugin_event_msg (irc_commands[i].command_name, entire_line);
+ plugin_event_msg (irc_commands[i].command_name, server->name, entire_line);
return return_code;
}
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index bbb718970..ba5e75808 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -44,7 +44,6 @@
t_irc_server *irc_servers = NULL;
t_irc_server *last_irc_server = NULL;
-t_irc_server *current_irc_server = NULL;
t_irc_message *recv_msgq, *msgq_last_msg;
@@ -686,8 +685,7 @@ server_connect (t_irc_server *server)
server->sock4 = -1;
return 0;
}
-
- current_irc_server = server;
+
return 1;
}
diff --git a/src/irc/irc.h b/src/irc/irc.h
index b90bd7654..15724351f 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -198,9 +198,8 @@ struct t_dcc
};
extern t_irc_command irc_commands[];
-extern t_irc_server *irc_servers, *current_irc_server;
+extern t_irc_server *irc_servers;
extern t_irc_message *recv_msgq, *msgq_last_msg;
-extern t_irc_channel *current_channel;
extern t_dcc *dcc_list;
extern char *dcc_status_string[6];
extern char *channel_modes;
diff --git a/src/plugins/perl/wee-perl.c b/src/plugins/perl/wee-perl.c
index 775b77b9b..67e304dba 100644
--- a/src/plugins/perl/wee-perl.c
+++ b/src/plugins/perl/wee-perl.c
@@ -227,6 +227,55 @@ static XS (XS_IRC_print_infobar)
}
/*
+ * IRC::command: send command to server
+ */
+
+static XS (XS_IRC_command)
+{
+ int integer;
+ char *server, *command, *command2;
+ t_irc_server *ptr_server;
+ dXSARGS;
+
+ /* make gcc happy */
+ (void) cv;
+
+ if (items == 2)
+ {
+ server = SvPV (ST (0), integer);
+ command = SvPV (ST (1), integer);
+ for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
+ {
+ if (strcasecmp (ptr_server->name, server) == 0)
+ break;
+ }
+ if (!ptr_server)
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("Perl error: server not found for IRC::command Perl function\n"));
+ }
+ }
+ else
+ {
+ ptr_server = SERVER(gui_current_window->buffer);
+ command = SvPV (ST (0), integer);
+ }
+
+ if (ptr_server)
+ {
+ command2 = (char *) malloc (strlen (command) + 8);
+ strcpy (command2, command);
+ if (!strstr (command2, "\r\n"))
+ strcat (command2, "\r\n");
+ server_sendf (ptr_server, command2);
+ free (command2);
+ }
+
+ XSRETURN_EMPTY;
+}
+
+/*
* IRC::add_message_handler: add handler for messages (privmsg, ...)
*/
@@ -284,17 +333,37 @@ static XS (XS_IRC_add_command_handler)
static XS (XS_IRC_get_info)
{
- char *arg, *info = NULL;
+ char *arg, *info = NULL, *server;
+ t_irc_server *ptr_server;
int integer;
dXSARGS;
/* make gcc happy */
- (void) items;
(void) cv;
- arg = SvPV (ST (0), integer);
+ if (items == 2)
+ {
+ server = SvPV (ST (0), integer);
+ arg = SvPV (ST (1), integer);
+ for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
+ {
+ if (strcasecmp (ptr_server->name, server) == 0)
+ break;
+ }
+ if (!ptr_server)
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("Perl error: server not found for IRC::get_info Perl function\n"));
+ }
+ }
+ else
+ {
+ ptr_server = SERVER(gui_current_window->buffer);
+ arg = SvPV (ST (0), integer);
+ }
- if (arg)
+ if (ptr_server && arg)
{
if ( (strcasecmp (arg, "0") == 0) || (strcasecmp (arg, "version") == 0) )
@@ -303,7 +372,8 @@ static XS (XS_IRC_get_info)
}
else if ( (strcasecmp (arg, "1") == 0) || (strcasecmp (arg, "nick") == 0) )
{
- info = current_irc_server->nick;
+ if (ptr_server->nick)
+ info = ptr_server->nick;
}
else if ( (strcasecmp (arg, "2") == 0) || (strcasecmp (arg, "channel") == 0) )
{
@@ -312,7 +382,8 @@ static XS (XS_IRC_get_info)
}
else if ( (strcasecmp (arg, "3") == 0) || (strcasecmp (arg, "server") == 0) )
{
- info = current_irc_server->name;
+ if (ptr_server->name)
+ info = ptr_server->name;
}
else if ( (strcasecmp (arg, "4") == 0) || (strcasecmp (arg, "weechatdir") == 0) )
{
@@ -320,7 +391,7 @@ static XS (XS_IRC_get_info)
}
else if ( (strcasecmp (arg, "5") == 0) || (strcasecmp (arg, "away") == 0) )
{
- XST_mIV (0, current_irc_server->is_away);
+ XST_mIV (0, SERVER(gui_current_window->buffer)->is_away);
XSRETURN (1);
return;
}
@@ -346,6 +417,7 @@ xs_init (pTHX)
newXS ("IRC::print", XS_IRC_print, "IRC");
newXS ("IRC::print_with_channel", XS_IRC_print_with_channel, "IRC");
newXS ("IRC::print_infobar", XS_IRC_print_infobar, "IRC");
+ newXS ("IRC::command", XS_IRC_command, "IRC");
newXS ("IRC::add_message_handler", XS_IRC_add_message_handler, "IRC");
newXS ("IRC::add_command_handler", XS_IRC_add_command_handler, "IRC");
newXS ("IRC::get_info", XS_IRC_get_info, "IRC");
@@ -424,9 +496,9 @@ wee_perl_search (char *name)
*/
int
-wee_perl_exec (char *function, char *arguments)
+wee_perl_exec (char *function, char *server, char *arguments)
{
- char *argv[2];
+ char *argv[3];
int count, return_code;
SV *sv;
@@ -435,8 +507,9 @@ wee_perl_exec (char *function, char *arguments)
ENTER;
SAVETMPS;
PUSHMARK(sp);
- argv[0] = arguments;
- argv[1] = NULL;
+ argv[0] = server;
+ argv[1] = arguments;
+ argv[2] = NULL;
count = perl_call_argv (function, G_EVAL | G_SCALAR, argv);
SPAGAIN;
@@ -482,7 +555,7 @@ wee_perl_load (char *filename)
wee_log_printf (_("loading Perl script \"%s\"\n"), filename);
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _("Loading Perl script \"%s\"\n"), filename);
- return wee_perl_exec ("wee_perl_load_eval_file", filename);
+ return wee_perl_exec ("wee_perl_load_eval_file", filename, "");
}
/*
@@ -535,7 +608,7 @@ wee_perl_unload (t_plugin_script *ptr_perl_script)
/* call shutdown callback function */
if (ptr_perl_script->shutdown_func[0])
- wee_perl_exec (ptr_perl_script->shutdown_func, "");
+ wee_perl_exec (ptr_perl_script->shutdown_func, "", "");
wee_perl_script_free (ptr_perl_script);
}
}
diff --git a/src/plugins/perl/wee-perl.h b/src/plugins/perl/wee-perl.h
index 82553ea0e..a4e23a9a0 100644
--- a/src/plugins/perl/wee-perl.h
+++ b/src/plugins/perl/wee-perl.h
@@ -25,7 +25,7 @@
extern void wee_perl_init ();
extern t_plugin_script *wee_perl_search (char *);
-extern int wee_perl_exec (char *, char *);
+extern int wee_perl_exec (char *, char *, char *);
extern int wee_perl_load (char *);
extern void wee_perl_unload (t_plugin_script *);
extern void wee_perl_unload_all ();
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index 74ac3db3d..8b2b53c52 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -273,7 +273,7 @@ plugin_handler_free_all_type (t_plugin_handler **plugin_handlers,
*/
void
-plugin_event_msg (char *irc_command, char *arguments)
+plugin_event_msg (char *irc_command, char *arguments, char *server)
{
#ifdef PLUGINS
t_plugin_handler *ptr_plugin_handler;
@@ -285,7 +285,7 @@ plugin_event_msg (char *irc_command, char *arguments)
{
#ifdef PLUGIN_PERL
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
- wee_perl_exec (ptr_plugin_handler->function_name, arguments);
+ wee_perl_exec (ptr_plugin_handler->function_name, arguments, server);
#endif
}
}
@@ -301,7 +301,7 @@ plugin_event_msg (char *irc_command, char *arguments)
*/
int
-plugin_exec_command (char *user_command, char *arguments)
+plugin_exec_command (char *user_command, char *arguments, char *server)
{
#ifdef PLUGINS
t_plugin_handler *ptr_plugin_handler;
@@ -313,7 +313,7 @@ plugin_exec_command (char *user_command, char *arguments)
{
#ifdef PLUGIN_PERL
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
- wee_perl_exec (ptr_plugin_handler->function_name, arguments);
+ wee_perl_exec (ptr_plugin_handler->function_name, arguments, server);
#endif
/* command executed */
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index db687dcc6..79da1ca3f 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -68,8 +68,8 @@ extern void plugin_handler_add (t_plugin_handler **, t_plugin_handler **,
int, char *, char *);
extern void plugin_handler_free_all_type (t_plugin_handler **,
t_plugin_handler **, int);
-extern void plugin_event_msg (char *, char *);
-extern int plugin_exec_command (char *, /*@null@*/ char *);
+extern void plugin_event_msg (char *, char *, char *);
+extern int plugin_exec_command (char *, /*@null@*/ char *, char *);
extern void plugin_end ();
#endif /* plugins.h */