multiprotocol updates. SILC prints channel and private messages now

using the same message formats as IRC.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@699 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-09-30 22:49:48 +00:00 committed by cras
commit 2b8580c8a7
46 changed files with 667 additions and 687 deletions

View file

@ -75,7 +75,7 @@ static void server_rejoin_channels(IRC_SERVER_REC *server)
while (server->rejoin_channels != NULL) {
char *channel = server->rejoin_channels->data;
irc_channels_join(server, channel, TRUE);
server->channels_join(server, channel, TRUE);
server->rejoin_channels =
g_slist_remove(server->rejoin_channels, channel);
}

View file

@ -56,7 +56,7 @@ static int ignore_check_replies(IGNORE_REC *rec, IRC_SERVER_REC *server,
for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
NICK_REC *nick = tmp->data;
if (irc_nick_match(nick->nick, text))
if (nick_match_msg(SERVER(server), text, nick->nick))
return TRUE;
}
g_slist_free(nicks);
@ -114,7 +114,7 @@ int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host,
/* pattern */
patt_len = 0;
if (rec->pattern != NULL) {
if (rec->pattern != NULL && text != NULL) {
if (!mask_len && !best_mask) {
patt_len = strlen(rec->pattern);
if (patt_len <= best_patt) continue;

View file

@ -20,95 +20,14 @@
#include "module.h"
#include "signals.h"
#include "nicklist.h"
#include "servers.h"
#include "special-vars.h"
#include "servers-setup.h"
#include "channels-setup.h"
#include "irc.h"
#include "irc-chatnets.h"
#include "irc-servers.h"
#include "irc-channels.h"
/* connected to server, autojoin to channels. */
static void event_connected(IRC_SERVER_REC *server)
{
GString *chans;
GSList *tmp;
if (!IS_IRC_SERVER(server) || server->connrec->reconnection)
return;
/* join to the channels marked with autojoin in setup */
chans = g_string_new(NULL);
for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
CHANNEL_SETUP_REC *rec = tmp->data;
if (!rec->autojoin ||
!channel_chatnet_match(rec->chatnet,
server->connrec->chatnet))
continue;
g_string_sprintfa(chans, "%s,", rec->name);
}
if (chans->len > 0) {
g_string_truncate(chans, chans->len-1);
irc_channels_join(server, chans->str, TRUE);
}
g_string_free(chans, TRUE);
}
/* channel wholist received: send the auto send command */
static void channel_wholist(CHANNEL_REC *channel)
{
CHANNEL_SETUP_REC *rec;
NICK_REC *nick;
char **bots, **bot;
g_return_if_fail(IS_CHANNEL(channel));
rec = channels_setup_find(channel->name, channel->server->connrec->chatnet);
if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd)
return;
if (rec->botmasks == NULL || !*rec->botmasks) {
/* just send the command. */
eval_special_string(rec->autosendcmd, "", channel->server, channel);
return;
}
/* find first available bot.. */
bots = g_strsplit(rec->botmasks, " ", -1);
for (bot = bots; *bot != NULL; bot++) {
const char *botnick = *bot;
nick = nicklist_find(channel, isnickflag(*botnick) ?
botnick+1 : botnick);
if (nick == NULL)
continue;
if ((*botnick == '@' && !nick->op) ||
(*botnick == '+' && !nick->voice && !nick->op))
continue;
/* got one! */
eval_special_string(rec->autosendcmd, nick->nick, channel->server, channel);
break;
}
g_strfreev(bots);
}
#include "channels.h"
void irc_channels_setup_init(void)
{
signal_add("event connected", (SIGNAL_FUNC) event_connected);
signal_add("channel wholist", (SIGNAL_FUNC) channel_wholist);
signal_add("channel wholist", (SIGNAL_FUNC) channel_send_autocommands);
}
void irc_channels_setup_deinit(void)
{
signal_remove("event connected", (SIGNAL_FUNC) event_connected);
signal_remove("channel wholist", (SIGNAL_FUNC) channel_wholist);
signal_remove("channel wholist", (SIGNAL_FUNC) channel_send_autocommands);
}

View file

@ -92,7 +92,8 @@ static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
#define get_join_key(key) \
(((key) == NULL || *(key) == '\0') ? "x" : (key))
void irc_channels_join(IRC_SERVER_REC *server, const char *data, int automatic)
static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
int automatic)
{
CHANNEL_SETUP_REC *schannel;
IRC_CHANNEL_REC *chanrec;
@ -191,6 +192,7 @@ static void sig_connected(SERVER_REC *server)
return;
server->channel_find_func = (void *) irc_channel_find_server;
server->channels_join = (void *) irc_channels_join;
}
void irc_channels_init(void)

View file

@ -35,8 +35,4 @@ IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server,
#define irc_channel_find(server, name) \
IRC_CHANNEL(channel_find(SERVER(server), name))
/* Join to channels. `data' contains channels and channel keys */
void irc_channels_join(IRC_SERVER_REC *server,
const char *data, int automatic);
#endif

View file

@ -153,42 +153,6 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server,
cmd_params_free(free_arg);
}
/* SYNTAX: MSG [-<server tag>] <targets> <message> */
static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
GHashTable *optlist;
char *target, *msg;
void *free_arg;
int free_ret;
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"msg", &optlist, &target, &msg))
return;
if (*target == '\0' || *msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
server = IRC_SERVER(cmd_options_get_server("msg", optlist, SERVER(server)));
if (!IS_IRC_SERVER(server) || !server->connected)
cmd_param_error(CMDERR_NOT_CONNECTED);
free_ret = FALSE;
if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0)
target = parse_special(&target, SERVER(server), item, NULL, &free_ret, NULL);
else if (strcmp(target, "*") == 0 &&
(IS_IRC_CHANNEL(item) || IS_IRC_QUERY(item)))
target = item->name;
if (target != NULL) {
g_string_sprintf(tmpstr, "PRIVMSG %s :%s", target, msg);
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
}
if (free_ret && target != NULL) g_free(target);
cmd_params_free(free_arg);
}
/* SYNTAX: NOTICE <targets> <message> */
static void cmd_notice(const char *data, IRC_SERVER_REC *server)
{
@ -254,33 +218,6 @@ static void cmd_nctcp(const char *data, IRC_SERVER_REC *server)
cmd_params_free(free_arg);
}
/* SYNTAX: JOIN [-invite] [-<server tag>] <channels> [<keys>] */
static void cmd_join(const char *data, IRC_SERVER_REC *server)
{
GHashTable *optlist;
char *channels;
void *free_arg;
g_return_if_fail(data != NULL);
if (!IS_IRC_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;
if (g_hash_table_lookup(optlist, "invite")) {
if (server->last_invite != NULL)
irc_channels_join(server, server->last_invite, FALSE);
} else {
/* -<server tag> */
server = IRC_SERVER(cmd_options_get_server("join", optlist, SERVER(server)));
if (server != NULL) irc_channels_join(server, channels, FALSE);
}
cmd_params_free(free_arg);
}
/* SYNTAX: PART [<channels>] [<message>] */
static void cmd_part(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
@ -946,11 +883,9 @@ void irc_commands_init(void)
signal_add("server connected", (SIGNAL_FUNC) sig_connected);
command_bind("server", NULL, (SIGNAL_FUNC) cmd_server);
command_bind("connect", NULL, (SIGNAL_FUNC) cmd_connect);
command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg);
command_bind("notice", NULL, (SIGNAL_FUNC) cmd_notice);
command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp);
command_bind("nctcp", NULL, (SIGNAL_FUNC) cmd_nctcp);
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
command_bind("part", NULL, (SIGNAL_FUNC) cmd_part);
command_bind("kick", NULL, (SIGNAL_FUNC) cmd_kick);
command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic);
@ -1036,7 +971,6 @@ void irc_commands_init(void)
command_set_options("topic", "delete");
command_set_options("list", "yes");
command_set_options("away", "one all");
command_set_options("join", "invite");
}
void irc_commands_deinit(void)
@ -1046,11 +980,9 @@ void irc_commands_deinit(void)
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
command_unbind("server", (SIGNAL_FUNC) cmd_server);
command_unbind("connect", (SIGNAL_FUNC) cmd_connect);
command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
command_unbind("notice", (SIGNAL_FUNC) cmd_notice);
command_unbind("ctcp", (SIGNAL_FUNC) cmd_ctcp);
command_unbind("nctcp", (SIGNAL_FUNC) cmd_nctcp);
command_unbind("join", (SIGNAL_FUNC) cmd_join);
command_unbind("part", (SIGNAL_FUNC) cmd_part);
command_unbind("kick", (SIGNAL_FUNC) cmd_kick);
command_unbind("topic", (SIGNAL_FUNC) cmd_topic);

View file

@ -51,7 +51,14 @@ void irc_channels_setup_deinit(void);
void irc_core_init(void)
{
chat_protocol_register("IRC", "Internet Relay Chat", "ircnet");
CHAT_PROTOCOL_REC *rec;
rec = g_new0(CHAT_PROTOCOL_REC, 1);
rec->name = "IRC";
rec->fullname = "Internet Relay Chat";
rec->chatnet = "ircnet";
chat_protocol_register(rec);
irc_chatnets_init();
irc_servers_init();

View file

@ -34,9 +34,6 @@
(a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
(a) == '|' || (a) == '\\' || (a) == '^')
#define isalnumhigh(a) \
(isalnum(a) || (unsigned char) (a) >= 128)
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
char *irc_nick_strip(const char *nick)
{
@ -56,45 +53,6 @@ char *irc_nick_strip(const char *nick)
return stripped;
}
/* Check is `msg' is meant for `nick'. */
int irc_nick_match(const char *nick, const char *msg)
{
int len;
g_return_val_if_fail(nick != NULL, FALSE);
g_return_val_if_fail(msg != NULL, FALSE);
/* first check for identical match */
len = strlen(nick);
if (g_strncasecmp(msg, nick, len) == 0 && !isalnumhigh((int) msg[len]))
return TRUE;
/* check if it matches for alphanumeric parts of nick */
while (*nick != '\0' && *msg != '\0') {
if (*nick == *msg) {
/* total match */
msg++;
} else if (isalnum(*msg) && !isalnum(*nick)) {
/* some strange char in your nick, pass it */
} else
break;
nick++;
}
if (isalnumhigh(*msg)) {
/* message continues with another alphanumeric character,
it isn't for us. */
return FALSE;
}
/* remove all the non-alphanumeric characters at the end of
the nick and check if message matched that far. */
while (*nick != '\0' && !isalnum(*nick)) nick++;
return *nick == '\0';
}
static void event_names_list(const char *data, SERVER_REC *server)
{
CHANNEL_REC *chanrec;
@ -378,6 +336,17 @@ static void sig_usermode(SERVER_REC *server)
nicklist_update_flags(server, server->nick, server->usermode_away, -1);
}
static const char *get_nick_flags(void)
{
return "@+%";
}
static void sig_connected(IRC_SERVER_REC *server)
{
if (IS_IRC_SERVER(server))
server->get_nick_flags = (void *) get_nick_flags;
}
void irc_nicklist_init(void)
{
signal_add("event nick", (SIGNAL_FUNC) event_nick);
@ -395,6 +364,7 @@ void irc_nicklist_init(void)
signal_add("event 302", (SIGNAL_FUNC) event_userhost);
signal_add("userhost event", (SIGNAL_FUNC) event_userhost);
signal_add("user mode changed", (SIGNAL_FUNC) sig_usermode);
signal_add("server connected", (SIGNAL_FUNC) sig_connected);
}
void irc_nicklist_deinit(void)
@ -414,4 +384,5 @@ void irc_nicklist_deinit(void)
signal_remove("event 302", (SIGNAL_FUNC) event_userhost);
signal_remove("userhost event", (SIGNAL_FUNC) event_userhost);
signal_remove("user mode changed", (SIGNAL_FUNC) sig_usermode);
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
}

View file

@ -9,7 +9,4 @@ void irc_nicklist_deinit(void);
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
char *irc_nick_strip(const char *nick);
/* Check if `msg' is meant for `nick'. */
int irc_nick_match(const char *nick, const char *msg);
#endif

View file

@ -90,11 +90,9 @@ static int sig_set_user_mode(IRC_SERVER_REC *server)
static void sig_connected(IRC_SERVER_REC *server)
{
if (!server->connrec->reconnection)
if (!IS_IRC_SERVER(server) || !server->connrec->reconnection)
return;
if (server->connrec->channels != NULL)
irc_channels_join(server, server->connrec->channels, TRUE);
if (server->connrec->away_reason != NULL)
signal_emit("command away", 2, server->connrec->away_reason, server, NULL);
if (server->connrec->usermode != NULL) {

View file

@ -61,6 +61,30 @@ static void sig_server_connect_free(IRC_SERVER_CONNECT_REC *conn)
g_free_not_null(conn->alternate_nick);
}
static int isnickflag_func(char flag)
{
return isnickflag(flag);
}
static int ischannel_func(char flag)
{
return ischannel(flag);
}
static void send_message(IRC_SERVER_REC *server, const char *target,
const char *msg)
{
char *str;
g_return_if_fail(server != NULL);
g_return_if_fail(target != NULL);
g_return_if_fail(msg != NULL);
str = g_strdup_printf("PRIVMSG %s :%s", target, msg);
irc_send_cmd_split(server, str, 2, server->max_msgs_in_cmd);
g_free(str);
}
static void server_init(IRC_SERVER_REC *server)
{
IRC_SERVER_CONNECT_REC *conn;
@ -100,6 +124,9 @@ static void server_init(IRC_SERVER_REC *server)
address, conn->realname);
server->cmdcount = 0;
server->isnickflag = isnickflag_func;
server->ischannel = ischannel_func;
server->send_message = (void *) send_message;
}
IRC_SERVER_REC *irc_server_connect(IRC_SERVER_CONNECT_REC *conn)

View file

@ -37,7 +37,6 @@ typedef struct {
char *real_address; /* address the irc server gives */
char *usermode; /* The whole mode string .. */
char *userhost; /* /USERHOST <nick> - set when joined to first channel */
char *last_invite; /* channel where you were last invited */
int whois_coming:1; /* Mostly just to display away message right.. */
int whois_found:1; /* Did WHOIS return any entries? */