mirror of
https://github.com/irssi/irssi.git
synced 2026-08-20 00:52:30 +02:00
Moved some stuff from irc to core. Added command_bind_proto() function to
bind protocol-specific commands. Added #define command_bind_irc() for easier access. CMD_IRC_SERVER(server) check should be done at the beginning of each command requiring IRC server as active server, it handles it correctly the cases when it is not. Did some other cleanups as well. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1955 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
95b94ed83c
commit
f354fe54c7
70 changed files with 381 additions and 438 deletions
|
|
@ -262,25 +262,25 @@ static void cmd_join(const char *data, SERVER_REC *server)
|
|||
void *free_arg;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
if (!IS_SERVER(server) || !server->connected)
|
||||
cmd_return_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
|
||||
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
|
||||
"join", &optlist, &channels))
|
||||
return;
|
||||
|
||||
/* -<server tag> */
|
||||
server = cmd_options_get_server("join", optlist, server);
|
||||
if (server == NULL || !server->connected)
|
||||
cmd_param_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (g_hash_table_lookup(optlist, "invite"))
|
||||
channels = server->last_invite;
|
||||
else {
|
||||
if (*channels == '\0')
|
||||
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
/* -<server tag> */
|
||||
server = cmd_options_get_server("join", optlist, server);
|
||||
}
|
||||
|
||||
if (server != NULL && channels != NULL)
|
||||
if (channels != NULL)
|
||||
server->channels_join(server, channels, FALSE);
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ int command_have_sub(const char *command)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static COMMAND_MODULE_REC *command_module_get(COMMAND_REC *rec,
|
||||
const char *module)
|
||||
static COMMAND_MODULE_REC *
|
||||
command_module_get(COMMAND_REC *rec, const char *module, int protocol)
|
||||
{
|
||||
COMMAND_MODULE_REC *modrec;
|
||||
|
||||
|
|
@ -122,14 +122,18 @@ static COMMAND_MODULE_REC *command_module_get(COMMAND_REC *rec,
|
|||
if (modrec == NULL) {
|
||||
modrec = g_new0(COMMAND_MODULE_REC, 1);
|
||||
modrec->name = g_strdup(module);
|
||||
modrec->protocol = -1;
|
||||
rec->modules = g_slist_append(rec->modules, modrec);
|
||||
}
|
||||
|
||||
if (protocol != -1)
|
||||
modrec->protocol = protocol;
|
||||
|
||||
return modrec;
|
||||
}
|
||||
|
||||
void command_bind_to(const char *module, int pos, const char *cmd,
|
||||
const char *category, SIGNAL_FUNC func)
|
||||
int protocol, const char *category, SIGNAL_FUNC func)
|
||||
{
|
||||
COMMAND_REC *rec;
|
||||
COMMAND_MODULE_REC *modrec;
|
||||
|
|
@ -145,7 +149,7 @@ void command_bind_to(const char *module, int pos, const char *cmd,
|
|||
rec->category = category == NULL ? NULL : g_strdup(category);
|
||||
commands = g_slist_append(commands, rec);
|
||||
}
|
||||
modrec = command_module_get(rec, module);
|
||||
modrec = command_module_get(rec, module, protocol);
|
||||
|
||||
modrec->signals = g_slist_append(modrec->signals, func);
|
||||
|
||||
|
|
@ -433,7 +437,7 @@ void command_set_options_module(const char *module,
|
|||
|
||||
rec = command_find(cmd);
|
||||
g_return_if_fail(rec != NULL);
|
||||
modrec = command_module_get(rec, module);
|
||||
modrec = command_module_get(rec, module, -1);
|
||||
|
||||
reload = modrec->options != NULL;
|
||||
if (reload) {
|
||||
|
|
@ -769,6 +773,28 @@ void commands_remove_module(const char *module)
|
|||
}
|
||||
}
|
||||
|
||||
static int cmd_protocol_match(COMMAND_REC *cmd, SERVER_REC *server)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = cmd->modules; tmp != NULL; tmp = tmp->next) {
|
||||
COMMAND_MODULE_REC *rec = tmp->data;
|
||||
|
||||
if (rec->protocol == -1) {
|
||||
/* at least one module accepts the command
|
||||
without specific protocol */
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (server != NULL && rec->protocol == server->chat_type) {
|
||||
/* matching protocol found */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define alias_runstack_push(alias) \
|
||||
alias_runstack = g_slist_append(alias_runstack, alias)
|
||||
|
||||
|
|
@ -781,6 +807,7 @@ void commands_remove_module(const char *module)
|
|||
static void parse_command(const char *command, int expand_aliases,
|
||||
SERVER_REC *server, void *item)
|
||||
{
|
||||
COMMAND_REC *rec;
|
||||
const char *alias, *newcmd;
|
||||
char *cmd, *orig, *args, *oldcmd;
|
||||
|
||||
|
|
@ -810,6 +837,17 @@ static void parse_command(const char *command, int expand_aliases,
|
|||
return;
|
||||
}
|
||||
|
||||
rec = command_find(newcmd);
|
||||
if (rec != NULL && !cmd_protocol_match(rec, server)) {
|
||||
g_free(orig);
|
||||
|
||||
signal_emit("error command", 2,
|
||||
GINT_TO_POINTER(server == NULL ?
|
||||
CMDERR_NOT_CONNECTED :
|
||||
CMDERR_ILLEGAL_PROTO));
|
||||
return;
|
||||
}
|
||||
|
||||
cmd = g_strconcat("command ", newcmd, NULL);
|
||||
if (server != NULL)
|
||||
server_redirect_default(SERVER(server), cmd);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
typedef struct {
|
||||
char *name;
|
||||
char *options;
|
||||
int protocol; /* chat protocol required for this command */
|
||||
GSList *signals;
|
||||
} COMMAND_MODULE_REC;
|
||||
|
||||
|
|
@ -26,10 +27,11 @@ enum {
|
|||
|
||||
CMDERR_ERRNO, /* get the error from errno */
|
||||
CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
|
||||
CMDERR_NOT_CONNECTED, /* not connected to IRC server */
|
||||
CMDERR_NOT_CONNECTED, /* not connected to server */
|
||||
CMDERR_NOT_JOINED, /* not joined to any channels in this window */
|
||||
CMDERR_CHAN_NOT_FOUND, /* channel not found */
|
||||
CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
|
||||
CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */
|
||||
CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */
|
||||
};
|
||||
|
||||
|
|
@ -56,10 +58,14 @@ extern char *current_command; /* the command we're right now. */
|
|||
|
||||
/* Bind command to specified function. */
|
||||
void command_bind_to(const char *module, int pos, const char *cmd,
|
||||
const char *category, SIGNAL_FUNC func);
|
||||
#define command_bind(a, b, c) command_bind_to(MODULE_NAME, 1, a, b, c)
|
||||
#define command_bind_first(a, b, c) command_bind_to(MODULE_NAME, 0, a, b, c)
|
||||
#define command_bind_last(a, b, c) command_bind_to(MODULE_NAME, 2, a, b, c)
|
||||
int protocol, const char *category, SIGNAL_FUNC func);
|
||||
#define command_bind(a, b, c) command_bind_to(MODULE_NAME, 1, a, -1, b, c)
|
||||
#define command_bind_first(a, b, c) command_bind_to(MODULE_NAME, 0, a, -1, b, c)
|
||||
#define command_bind_last(a, b, c) command_bind_to(MODULE_NAME, 2, a, -1, b, c)
|
||||
|
||||
#define command_bind_proto(a, b, c, d) command_bind_to(MODULE_NAME, 1, a, b, c, d)
|
||||
#define command_bind_proto_first(a, b, c, d) command_bind_to(MODULE_NAME, 0, a, b, c, d)
|
||||
#define command_bind_proto_last(a, b, c, d) command_bind_to(MODULE_NAME, 2, a, b, c, d)
|
||||
|
||||
void command_unbind(const char *cmd, SIGNAL_FUNC func);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,13 @@
|
|||
#include "rawlog.h"
|
||||
#include "modules.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "misc.h"
|
||||
#include "write-buffer.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "servers.h"
|
||||
|
||||
static int rawlog_lines;
|
||||
static int signal_rawlog;
|
||||
static int log_file_create_mode;
|
||||
|
|
@ -158,6 +161,40 @@ static void read_settings(void)
|
|||
log_file_create_mode = octal2dec(settings_get_int("log_create_mode"));
|
||||
}
|
||||
|
||||
static void cmd_rawlog(const char *data, SERVER_REC *server, void *item)
|
||||
{
|
||||
command_runsub("rawlog", data, server, item);
|
||||
}
|
||||
|
||||
/* SYNTAX: RAWLOG SAVE <file> */
|
||||
static void cmd_rawlog_save(const char *data, SERVER_REC *server)
|
||||
{
|
||||
g_return_if_fail(data != NULL);
|
||||
if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
rawlog_save(server->rawlog, data);
|
||||
}
|
||||
|
||||
/* SYNTAX: RAWLOG OPEN <file> */
|
||||
static void cmd_rawlog_open(const char *data, SERVER_REC *server)
|
||||
{
|
||||
g_return_if_fail(data != NULL);
|
||||
if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
rawlog_open(server->rawlog, data);
|
||||
}
|
||||
|
||||
/* SYNTAX: RAWLOG CLOSE */
|
||||
static void cmd_rawlog_close(const char *data, SERVER_REC *server)
|
||||
{
|
||||
g_return_if_fail(data != NULL);
|
||||
if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
rawlog_close(server->rawlog);
|
||||
}
|
||||
|
||||
void rawlog_init(void)
|
||||
{
|
||||
signal_rawlog = signal_get_uniq_id("rawlog");
|
||||
|
|
@ -166,9 +203,19 @@ void rawlog_init(void)
|
|||
read_settings();
|
||||
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_bind("rawlog", NULL, (SIGNAL_FUNC) cmd_rawlog);
|
||||
command_bind("rawlog save", NULL, (SIGNAL_FUNC) cmd_rawlog_save);
|
||||
command_bind("rawlog open", NULL, (SIGNAL_FUNC) cmd_rawlog_open);
|
||||
command_bind("rawlog close", NULL, (SIGNAL_FUNC) cmd_rawlog_close);
|
||||
}
|
||||
|
||||
void rawlog_deinit(void)
|
||||
{
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_unbind("rawlog", (SIGNAL_FUNC) cmd_rawlog);
|
||||
command_unbind("rawlog save", (SIGNAL_FUNC) cmd_rawlog_save);
|
||||
command_unbind("rawlog open", (SIGNAL_FUNC) cmd_rawlog_open);
|
||||
command_unbind("rawlog close", (SIGNAL_FUNC) cmd_rawlog_close);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue