2 silc-nicklist.c : irssi
4 Copyright (C) 2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "silc-channels.h"
27 #include "silc-nicklist.h"
29 SILC_NICK_REC *silc_nicklist_insert(SILC_CHANNEL_REC *channel,
30 SilcChannelUser user, int send_massjoin)
34 g_return_val_if_fail(IS_SILC_CHANNEL(channel), NULL);
35 g_return_val_if_fail(user != NULL, NULL);
37 rec = g_new0(SILC_NICK_REC, 1);
38 rec->nick = g_strdup(user->client->nickname);
39 rec->host = g_strdup_printf("%s@%s", user->client->username,
40 user->client->hostname);
41 rec->realname = g_strdup(user->client->realname);
42 rec->silc_user = user;
43 rec->unique_id = user->client;
45 if (user->mode & SILC_CHANNEL_UMODE_CHANOP)
47 if (user->mode & SILC_CHANNEL_UMODE_CHANFO)
49 rec->send_massjoin = send_massjoin;
51 nicklist_insert(CHANNEL(channel), (NICK_REC *) rec);
55 SILC_NICK_REC *silc_nicklist_find(SILC_CHANNEL_REC *channel,
56 SilcClientEntry client)
58 if (!client || !client->nickname)
61 return (SILC_NICK_REC *)nicklist_find_unique(CHANNEL(channel),
62 client->nickname, client);
65 #define isnickchar(a) \
66 (isalnum((int) (a)) || (a) == '`' || (a) == '-' || (a) == '_' || \
67 (a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
68 (a) == '|' || (a) == '\\' || (a) == '^')
70 /* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
71 char *silc_nick_strip(const char *nick)
73 char *stripped, *spos;
75 g_return_val_if_fail(nick != NULL, NULL);
77 spos = stripped = g_strdup(nick);
78 while (isnickchar(*nick)) {
79 if (isalnum((int) *nick))
83 if ((unsigned char) *nick >= 128)
84 *spos++ = *nick; /* just add it so that nicks won't match.. */
90 /* Check is `msg' is meant for `nick'. */
91 int silc_nick_match(const char *nick, const char *msg)
93 char *stripnick, *stripmsg;
96 g_return_val_if_fail(nick != NULL, FALSE);
97 g_return_val_if_fail(msg != NULL, FALSE);
100 if (g_strncasecmp(msg, nick, len) == 0 && !isalnum((int) msg[len]))
103 stripnick = silc_nick_strip(nick);
104 stripmsg = silc_nick_strip(msg);
106 len = strlen(stripnick);
107 ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 &&
108 !isalnum((int) stripmsg[len]) &&
109 (unsigned char) stripmsg[len] < 128;
117 static const char *get_nick_flags(void)
119 static char flags[3] = { '@', '+', '\0' };
123 static void sig_connected(SILC_SERVER_REC *server)
125 if (IS_SILC_SERVER(server))
126 server->get_nick_flags = (void *) get_nick_flags;
129 void silc_change_nick(SILC_SERVER_REC *server, const char *newnick)
131 server_change_nick((SERVER_REC *)server, newnick);
134 void silc_nicklist_init(void)
136 signal_add("server connected", (SIGNAL_FUNC) sig_connected);
139 void silc_nicklist_deinit(void)
141 signal_remove("server connected", (SIGNAL_FUNC) sig_connected);