updates.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 25 May 2001 10:07:17 +0000 (10:07 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 25 May 2001 10:07:17 +0000 (10:07 +0000)
apps/irssi/src/silc/core/silc-channels.c
apps/irssi/src/silc/core/silc-channels.h
apps/irssi/src/silc/core/silc-core.c
apps/irssi/src/silc/core/silc-nicklist.h
apps/irssi/src/silc/core/silc-servers.c
apps/irssi/src/silc/core/silc-servers.h

index b1f82f863970d8e14e0c274fb9c42cdfac7b2cc6..9cfe7696fe5face219956f46e6e50afaababcee8 100644 (file)
 /*
- silc-channels.c : irssi
-
-    Copyright (C) 2000-2001 Timo Sirainen
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  silc-channels.c : irssi
+
+  Copyright (C) 2000 - 2001 Timo Sirainen
+                            Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+  
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
 #include "module.h"
+
+#include "net-nonblock.h"
+#include "net-sendbuffer.h"
 #include "signals.h"
+#include "servers.h"
 #include "commands.h"
 #include "levels.h"
+#include "modules.h"
+#include "rawlog.h"
 #include "misc.h"
+#include "settings.h"
+
 #include "channels-setup.h"
-#include "levels.h"
 
+#include "silc-servers.h"
 #include "silc-channels.h"
+#include "silc-queries.h"
 #include "silc-nicklist.h"
+#include "window-item-def.h"
 
 #include "fe-common/core/printtext.h"
 
 SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
                                      const char *name, int automatic)
 {
-       SILC_CHANNEL_REC *rec;
+  SILC_CHANNEL_REC *rec;
 
-       g_return_val_if_fail(server == NULL || IS_SILC_SERVER(server), NULL);
-       g_return_val_if_fail(name != NULL, NULL);
+  g_return_val_if_fail(server == NULL || IS_SILC_SERVER(server), NULL);
+  g_return_val_if_fail(name != NULL, NULL);
 
-       rec = g_new0(SILC_CHANNEL_REC, 1);
-       rec->chat_type = SILC_PROTOCOL;
-       rec->name = g_strdup(name);
-       rec->server = server;
+  rec = g_new0(SILC_CHANNEL_REC, 1);
+  rec->chat_type = SILC_PROTOCOL;
+  rec->name = g_strdup(name);
+  rec->server = server;
 
-       channel_init((CHANNEL_REC *) rec, automatic);
-       return rec;
+  channel_init((CHANNEL_REC *) rec, automatic);
+  return rec;
 }
 
 static void sig_channel_destroyed(SILC_CHANNEL_REC *channel)
 {
-       if (!IS_SILC_CHANNEL(channel))
-                return;
-
-       if (channel->server != NULL && !channel->left && !channel->kicked) {
-               /* destroying channel record without actually
-                  having left the channel yet */
-               silc_command_exec(channel->server, "PART", channel->name);
-       }
+  if (!IS_SILC_CHANNEL(channel))
+    return;
+
+  if (channel->server != NULL && !channel->left && !channel->kicked) {
+    /* destroying channel record without actually
+       having left the channel yet */
+    silc_command_exec(channel->server, "PART", channel->name);
+  }
 }
 
 static void silc_channels_join(SILC_SERVER_REC *server,
                               const char *channels, int automatic)
 {
-       char **list, **tmp, *channel;
-
-       list = g_strsplit(channels, ",", -1);
-       for (tmp = list; *tmp != NULL; tmp++) {
-               channel = **tmp == '#' ? g_strdup(*tmp) :
-                       g_strconcat("#", *tmp, NULL);
-               silc_channel_create(server, channel, FALSE);
-               silc_command_exec(server, "JOIN", channel);
-               g_free(channel);
-       }
-        g_strfreev(list);
+  char **list, **tmp, *channel;
+
+  list = g_strsplit(channels, ",", -1);
+  for (tmp = list; *tmp != NULL; tmp++) {
+    channel = **tmp == '#' ? g_strdup(*tmp) :
+      g_strconcat("#", *tmp, NULL);
+    silc_channel_create(server, channel, FALSE);
+    silc_command_exec(server, "JOIN", channel);
+    g_free(channel);
+  }
+  g_strfreev(list);
 }
 
 static void sig_connected(SILC_SERVER_REC *server)
 {
-       if (IS_SILC_SERVER(server))
-                server->channels_join = (void *) silc_channels_join;
+  if (IS_SILC_SERVER(server))
+    server->channels_join = (void *) silc_channels_join;
 }
 
 SILC_CHANNEL_REC *silc_channel_find_entry(SILC_SERVER_REC *server,
                                          SilcChannelEntry entry)
 {
-       GSList *tmp;
+  GSList *tmp;
 
-       g_return_val_if_fail(IS_SILC_SERVER(server), NULL);
+  g_return_val_if_fail(IS_SILC_SERVER(server), NULL);
 
-       for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
-               SILC_CHANNEL_REC *rec = tmp->data;
+  for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
+    SILC_CHANNEL_REC *rec = tmp->data;
 
-               if (rec->entry == entry)
-                       return rec;
-       }
+    if (rec->entry == entry)
+      return rec;
+  }
 
-       return NULL;
+  return NULL;
 }
 
 static void event_join(SILC_SERVER_REC *server, va_list va)
 {
-       SILC_CHANNEL_REC *chanrec;
-       SILC_NICK_REC *nickrec;
-       SilcClientEntry client;
-       SilcChannelEntry channel;
-
-       client = va_arg(va, SilcClientEntry);
-       channel = va_arg(va, SilcChannelEntry);
-
-       if (client == server->conn->local_entry) {
-               /* you joined to channel */
-                chanrec = silc_channel_find(server, channel->channel_name);
-               if (chanrec != NULL && !chanrec->joined)
-                       chanrec->entry = channel;
-       } else {
-               chanrec = silc_channel_find_entry(server, channel);
-               if (chanrec != NULL) {
-                       SilcChannelUser user;
-
-                       silc_list_start(chanrec->entry->clients);
-                       while ((user = silc_list_get(chanrec->entry->clients)) != NULL)
-                               if (user->client == client) {
-                                       nickrec = silc_nicklist_insert(chanrec, user, TRUE);
-                                        break;
-                               }
-               }
+  SILC_CHANNEL_REC *chanrec;
+  SILC_NICK_REC *nickrec;
+  SilcClientEntry client;
+  SilcChannelEntry channel;
+
+  client = va_arg(va, SilcClientEntry);
+  channel = va_arg(va, SilcChannelEntry);
+
+  if (client == server->conn->local_entry) {
+    /* you joined to channel */
+    chanrec = silc_channel_find(server, channel->channel_name);
+    if (chanrec != NULL && !chanrec->joined)
+      chanrec->entry = channel;
+  } else {
+    chanrec = silc_channel_find_entry(server, channel);
+    if (chanrec != NULL) {
+      SilcChannelUser user;
+
+      silc_list_start(chanrec->entry->clients);
+      while ((user = silc_list_get(chanrec->entry->clients)) != NULL)
+       if (user->client == client) {
+         nickrec = silc_nicklist_insert(chanrec, user, TRUE);
+         break;
        }
+    }
+  }
 
-       signal_emit("message join", 4, server, channel->channel_name,
-                   client->nickname,
-                   client->username == NULL ? "" : client->username);
+  signal_emit("message join", 4, server, channel->channel_name,
+             client->nickname,
+             client->username == NULL ? "" : client->username);
 }
 
 static void event_leave(SILC_SERVER_REC *server, va_list va)
 {
-       SILC_CHANNEL_REC *chanrec;
-       SILC_NICK_REC *nickrec;
-       SilcClientEntry client;
-       SilcChannelEntry channel;
-
-       client = va_arg(va, SilcClientEntry);
-       channel = va_arg(va, SilcChannelEntry);
-
-       signal_emit("message part", 5, server, channel->channel_name,
-                   client->nickname, 
-                   client->username == NULL ? "" : client->username, "");
-
-       chanrec = silc_channel_find_entry(server, channel);
-       if (chanrec != NULL) {
-               nickrec = silc_nicklist_find(chanrec, client);
-               if (nickrec != NULL)
-                       nicklist_remove(CHANNEL(chanrec), NICK(nickrec));
-       }
+  SILC_CHANNEL_REC *chanrec;
+  SILC_NICK_REC *nickrec;
+  SilcClientEntry client;
+  SilcChannelEntry channel;
+
+  client = va_arg(va, SilcClientEntry);
+  channel = va_arg(va, SilcChannelEntry);
+
+  signal_emit("message part", 5, server, channel->channel_name,
+             client->nickname, 
+             client->username == NULL ? "" : client->username, "");
+
+  chanrec = silc_channel_find_entry(server, channel);
+  if (chanrec != NULL) {
+    nickrec = silc_nicklist_find(chanrec, client);
+    if (nickrec != NULL)
+      nicklist_remove(CHANNEL(chanrec), NICK(nickrec));
+  }
 }
 
 static void event_signoff(SILC_SERVER_REC *server, va_list va)
 {
-       SilcClientEntry client;
-       GSList *nicks, *tmp;
+  SilcClientEntry client;
+  GSList *nicks, *tmp;
 
-       client = va_arg(va, SilcClientEntry);
+  client = va_arg(va, SilcClientEntry);
 
-       signal_emit("message quit", 4, server, client->nickname,
-                   client->username == NULL ? "" : client->username, "");
+  signal_emit("message quit", 4, server, client->nickname,
+             client->username == NULL ? "" : client->username, "");
 
-       nicks = nicklist_get_same_unique(SERVER(server), client);
-       for (tmp = nicks; tmp != NULL; tmp = tmp->next->next) {
-               CHANNEL_REC *channel = tmp->data;
-               NICK_REC *nickrec = tmp->next->data;
-
-               nicklist_remove(channel, nickrec);
-       }
+  nicks = nicklist_get_same_unique(SERVER(server), client);
+  for (tmp = nicks; tmp != NULL; tmp = tmp->next->next) {
+    CHANNEL_REC *channel = tmp->data;
+    NICK_REC *nickrec = tmp->next->data;
+    
+    nicklist_remove(channel, nickrec);
+  }
 }
 
 static void event_topic(SILC_SERVER_REC *server, va_list va)
 {
-       SILC_CHANNEL_REC *chanrec;
-       SilcClientEntry client;
-       SilcChannelEntry channel;
-       char *topic;
-
-       client = va_arg(va, SilcClientEntry);
-       topic = va_arg(va, char *);
-       channel = va_arg(va, SilcChannelEntry);
-
-       chanrec = silc_channel_find_entry(server, channel);
-       if (chanrec != NULL) {
-               g_free_not_null(chanrec->topic);
-               chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
-               signal_emit("channel topic changed", 1, chanrec);
-       }
-
-       signal_emit("message topic", 5, server, channel->channel_name,
-                   topic, client->nickname, client->username);
+  SILC_CHANNEL_REC *chanrec;
+  SilcClientEntry client;
+  SilcChannelEntry channel;
+  char *topic;
+
+  client = va_arg(va, SilcClientEntry);
+  topic = va_arg(va, char *);
+  channel = va_arg(va, SilcChannelEntry);
+
+  chanrec = silc_channel_find_entry(server, channel);
+  if (chanrec != NULL) {
+    g_free_not_null(chanrec->topic);
+    chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
+    signal_emit("channel topic changed", 1, chanrec);
+  }
+
+  signal_emit("message topic", 5, server, channel->channel_name,
+             topic, client->nickname, client->username);
 }
 
 static void event_invite(SILC_SERVER_REC *server, va_list va)
 {
-       SilcClientEntry client;
-       SilcChannelEntry channel;
-
-       client = va_arg(va, SilcClientEntry);
-       channel = va_arg(va, SilcChannelEntry);
-
-       signal_emit("message invite", 4, server, channel->channel_name,
-                   client->nickname, client->username);
+  SilcClientEntry client;
+  SilcChannelEntry channel;
+  
+  client = va_arg(va, SilcClientEntry);
+  channel = va_arg(va, SilcChannelEntry);
+
+  signal_emit("message invite", 4, server, channel->channel_name,
+             client->nickname, client->username);
 }
 
 static void event_nick(SILC_SERVER_REC *server, va_list va)
 {
-       SilcClientEntry oldclient, newclient;
+  SilcClientEntry oldclient, newclient;
 
-       oldclient = va_arg(va, SilcClientEntry);
-       newclient = va_arg(va, SilcClientEntry);
+  oldclient = va_arg(va, SilcClientEntry);
+  newclient = va_arg(va, SilcClientEntry);
 
-       nicklist_rename_unique(SERVER(server),
-                              oldclient, oldclient->nickname,
-                              newclient, newclient->nickname);
+  nicklist_rename_unique(SERVER(server),
+                        oldclient, oldclient->nickname,
+                        newclient, newclient->nickname);
 
-       signal_emit("message nick", 4, server, newclient->nickname,
-                   oldclient->nickname, newclient->username);
+  signal_emit("message nick", 4, server, newclient->nickname,
+             oldclient->nickname, newclient->username);
 }
 
 static void event_cmode(SILC_SERVER_REC *server, va_list va)
 {
-       SILC_CHANNEL_REC *chanrec;
-       SilcClientEntry client;
-       SilcChannelEntry channel;
-       char *mode;
-
-       client = va_arg(va, SilcClientEntry);
-       mode = silc_client_chmode(va_arg(va, unsigned int));
-       channel = va_arg(va, SilcChannelEntry);
-
-       chanrec = silc_channel_find_entry(server, channel);
-       if (chanrec != NULL) {
-               g_free_not_null(chanrec->mode);
-               chanrec->mode = g_strdup(mode == NULL ? "" : mode);
-               signal_emit("channel mode changed", 1, chanrec);
-       }
-
-       /*signal_emit("message mode", 5, server, chanrec->name,
-                   client->nickname, client->username, mode);*/
-       printtext(server, channel->channel_name, MSGLEVEL_MODES,
-                 "mode/%s [%s] by %s", channel->channel_name, mode,
-                 client->nickname);
-
-       g_free(mode);
+  SILC_CHANNEL_REC *chanrec;
+  SilcClientEntry client;
+  SilcChannelEntry channel;
+  char *mode;
+  uint32 modei;
+
+  client = va_arg(va, SilcClientEntry);
+  modei = va_arg(va, uint32);
+  channel = va_arg(va, SilcChannelEntry);
+  mode = silc_client_chmode(modei, channel);
+  
+  chanrec = silc_channel_find_entry(server, channel);
+  if (chanrec != NULL) {
+    g_free_not_null(chanrec->mode);
+    chanrec->mode = g_strdup(mode == NULL ? "" : mode);
+    signal_emit("channel mode changed", 1, chanrec);
+  }
+  
+  /*signal_emit("message mode", 5, server, chanrec->name,
+    client->nickname, client->username, mode);*/
+  printtext(server, channel->channel_name, MSGLEVEL_MODES,
+           "mode/%s [%s] by %s", channel->channel_name, mode,
+           client->nickname);
+  
+  g_free(mode);
 }
 
 static void event_cumode(SILC_SERVER_REC *server, va_list va)
 {
-       SILC_CHANNEL_REC *chanrec;
-       SilcClientEntry client, destclient;
-       SilcChannelEntry channel;
-        int mode;
-       char *modestr;
-
-       client = va_arg(va, SilcClientEntry);
-       mode = va_arg(va, unsigned int);
-       destclient = va_arg(va, SilcClientEntry);
-       channel = va_arg(va, SilcChannelEntry);
-
-       modestr = silc_client_chumode(mode);
-       chanrec = silc_channel_find_entry(server, channel);
-       if (chanrec != NULL) {
-               SILC_NICK_REC *nick;
-
-               if (destclient == server->conn->local_entry) {
-                       chanrec->chanop =
-                               (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
-               }
-
-               nick = silc_nicklist_find(chanrec, client);
-               if (nick != NULL) {
-                        nick->op = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
-                       signal_emit("nick mode changed", 2, chanrec, nick);
-               }
-       }
+  SILC_CHANNEL_REC *chanrec;
+  SilcClientEntry client, destclient;
+  SilcChannelEntry channel;
+  int mode;
+  char *modestr;
+  
+  client = va_arg(va, SilcClientEntry);
+  mode = va_arg(va, uint32);
+  destclient = va_arg(va, SilcClientEntry);
+  channel = va_arg(va, SilcChannelEntry);
+  
+  modestr = silc_client_chumode(mode);
+  chanrec = silc_channel_find_entry(server, channel);
+  if (chanrec != NULL) {
+    SILC_NICK_REC *nick;
+    
+    if (destclient == server->conn->local_entry) {
+      chanrec->chanop =
+       (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
+    }
+    
+    nick = silc_nicklist_find(chanrec, client);
+    if (nick != NULL) {
+      nick->op = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
+      signal_emit("nick mode changed", 2, chanrec, nick);
+    }
+  }
+  
+  /*signal_emit("message mode", 5, server, chanrec->name,
+    client->nickname, client->username, modestr);*/
+  printtext(server, channel->channel_name, MSGLEVEL_MODES,
+           "mode/%s [%s] by %s", channel->channel_name, modestr,
+           client->nickname);
+  
+  g_free(modestr);
+}
 
-       /*signal_emit("message mode", 5, server, chanrec->name,
-                   client->nickname, client->username, modestr);*/
-       printtext(server, channel->channel_name, MSGLEVEL_MODES,
-                 "mode/%s [%s] by %s", channel->channel_name, modestr,
-                 client->nickname);
+static void event_motd(SILC_SERVER_REC *server, va_list va)
+{
+  char *text = va_arg(va, char *);
 
-       g_free(modestr);
+  if (!settings_get_bool("skip_motd"))
+    printtext_multiline(server, NULL, MSGLEVEL_CRAP, "%s", text);
 }
 
-static void command_part(const char *data, SILC_SERVER_REC *server,
-                        WI_ITEM_REC *item)
+static void event_channel_change(SILC_SERVER_REC *server, va_list va)
 {
-       SILC_CHANNEL_REC *chanrec;
 
-       if (!IS_SILC_SERVER(server) || !server->connected)
-               return;
-
-       if (*data == '\0') {
-               if (!IS_SILC_CHANNEL(item))
-                       cmd_return_error(CMDERR_NOT_JOINED);
-               data = item->name;
-       }
+}
 
-       chanrec = silc_channel_find(server, data);
-       if (chanrec == NULL) cmd_return_error(CMDERR_CHAN_NOT_FOUND);
+static void event_server_signoff(SILC_SERVER_REC *server, va_list va)
+{
 
-       signal_emit("message part", 5, server, chanrec->name,
-                   server->nick, "", "");
+}
 
-       silc_command_exec(server, "LEAVE", chanrec->name);
-       signal_stop();
+static void event_kick(SILC_SERVER_REC *server, va_list va)
+{
 
-       channel_destroy(CHANNEL(chanrec));
 }
 
-void silc_channels_init(void)
+static void event_kill(SILC_SERVER_REC *server, va_list va)
 {
-       signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
-       signal_add("server connected", (SIGNAL_FUNC) sig_connected);
 
-       signal_add("silc event join", (SIGNAL_FUNC) event_join);
-       signal_add("silc event leave", (SIGNAL_FUNC) event_leave);
-       signal_add("silc event signoff", (SIGNAL_FUNC) event_signoff);
-       signal_add("silc event topic", (SIGNAL_FUNC) event_topic);
-       signal_add("silc event invite", (SIGNAL_FUNC) event_invite);
-       signal_add("silc event nick", (SIGNAL_FUNC) event_nick);
-       signal_add("silc event cmode", (SIGNAL_FUNC) event_cmode);
-       signal_add("silc event cumode", (SIGNAL_FUNC) event_cumode);
+}
 
-       command_bind("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
+static void event_ban(SILC_SERVER_REC *server, va_list va)
+{
 
-       silc_nicklist_init();
 }
 
-void silc_channels_deinit(void)
+static void command_part(const char *data, SILC_SERVER_REC *server,
+                        WI_ITEM_REC *item)
 {
-       signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
-       signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
-
-       signal_remove("silc event join", (SIGNAL_FUNC) event_join);
-       signal_remove("silc event leave", (SIGNAL_FUNC) event_leave);
-       signal_remove("silc event signoff", (SIGNAL_FUNC) event_signoff);
-       signal_remove("silc event topic", (SIGNAL_FUNC) event_topic);
-       signal_remove("silc event invite", (SIGNAL_FUNC) event_invite);
-       signal_remove("silc event nick", (SIGNAL_FUNC) event_nick);
-       signal_remove("silc event cmode", (SIGNAL_FUNC) event_cmode);
-       signal_remove("silc event cumode", (SIGNAL_FUNC) event_cumode);
+  SILC_CHANNEL_REC *chanrec;
+  
+  if (!IS_SILC_SERVER(server) || !server->connected)
+    return;
+
+  if (*data == '\0') {
+    if (!IS_SILC_CHANNEL(item))
+      cmd_return_error(CMDERR_NOT_JOINED);
+    data = item->name;
+  }
+
+  chanrec = silc_channel_find(server, data);
+  if (chanrec == NULL) 
+    cmd_return_error(CMDERR_CHAN_NOT_FOUND);
+
+  signal_emit("message part", 5, server, chanrec->name,
+             server->nick, "", "");
+  
+  silc_command_exec(server, "LEAVE", chanrec->name);
+  signal_stop();
+  
+  channel_destroy(CHANNEL(chanrec));
+}
 
-       command_unbind("part", (SIGNAL_FUNC) command_part);
+void silc_channels_init(void)
+{
+  signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
+  signal_add("server connected", (SIGNAL_FUNC) sig_connected);
+
+  signal_add("silc event join", (SIGNAL_FUNC) event_join);
+  signal_add("silc event leave", (SIGNAL_FUNC) event_leave);
+  signal_add("silc event signoff", (SIGNAL_FUNC) event_signoff);
+  signal_add("silc event topic", (SIGNAL_FUNC) event_topic);
+  signal_add("silc event invite", (SIGNAL_FUNC) event_invite);
+  signal_add("silc event nick", (SIGNAL_FUNC) event_nick);
+  signal_add("silc event cmode", (SIGNAL_FUNC) event_cmode);
+  signal_add("silc event cumode", (SIGNAL_FUNC) event_cumode);
+  signal_add("silc event motd", (SIGNAL_FUNC) event_motd);
+  signal_add("silc event channel_change", (SIGNAL_FUNC) event_channel_change);
+  signal_add("silc event server_signoff", (SIGNAL_FUNC) event_server_signoff);
+  signal_add("silc event kick", (SIGNAL_FUNC) event_kick);
+  signal_add("silc event kill", (SIGNAL_FUNC) event_kill);
+  signal_add("silc event ban", (SIGNAL_FUNC) event_ban);
+  
+  command_bind("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
+  
+  silc_nicklist_init();
+}
 
-       silc_nicklist_deinit();
+void silc_channels_deinit(void)
+{
+  signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
+  signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
+
+  signal_remove("silc event join", (SIGNAL_FUNC) event_join);
+  signal_remove("silc event leave", (SIGNAL_FUNC) event_leave);
+  signal_remove("silc event signoff", (SIGNAL_FUNC) event_signoff);
+  signal_remove("silc event topic", (SIGNAL_FUNC) event_topic);
+  signal_remove("silc event invite", (SIGNAL_FUNC) event_invite);
+  signal_remove("silc event nick", (SIGNAL_FUNC) event_nick);
+  signal_remove("silc event cmode", (SIGNAL_FUNC) event_cmode);
+  signal_remove("silc event cumode", (SIGNAL_FUNC) event_cumode);
+  signal_remove("silc event motd", (SIGNAL_FUNC) event_motd);
+  signal_remove("silc event channel_change", 
+               (SIGNAL_FUNC) event_channel_change);
+  signal_remove("silc event server_signoff", 
+               (SIGNAL_FUNC) event_server_signoff);
+  signal_remove("silc event kick", (SIGNAL_FUNC) event_kick);
+  signal_remove("silc event kill", (SIGNAL_FUNC) event_kill);
+  signal_remove("silc event ban", (SIGNAL_FUNC) event_ban);
+  
+  command_unbind("part", (SIGNAL_FUNC) command_part);
+  
+  silc_nicklist_deinit();
 }
index de6db8ba93735c92c86c7fcab4f9bdb502fc65be..8a286b733efe8c5575c07513bb47b9da07397d28 100644 (file)
@@ -8,19 +8,18 @@
 /* Returns SILC_CHANNEL_REC if it's SILC channel, NULL if it isn't. */
 #define SILC_CHANNEL(channel) \
        PROTO_CHECK_CAST(CHANNEL(channel), SILC_CHANNEL_REC, chat_type, "SILC")
-
 #define IS_SILC_CHANNEL(channel) \
        (SILC_CHANNEL(channel) ? TRUE : FALSE)
+#define silc_channel_find(server, name) \
+       SILC_CHANNEL(channel_find(SERVER(server), name))
 
 #define STRUCT_SERVER_REC SILC_SERVER_REC
 typedef struct {
 #include "channel-rec.h"
-
-       GSList *banlist; /* list of bans */
-       GSList *ebanlist; /* list of ban exceptions */
-       GSList *invitelist; /* invite list */
-
-        SilcChannelEntry entry;
+  GSList *banlist;             /* list of bans */
+  GSList *ebanlist;            /* list of ban exceptions */
+  GSList *invitelist;          /* invite list */
+  SilcChannelEntry entry;
 } SILC_CHANNEL_REC;
 
 void silc_channels_init(void);
@@ -29,10 +28,6 @@ void silc_channels_deinit(void);
 /* Create new SILC channel record */
 SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
                                      const char *name, int automatic);
-
-#define silc_channel_find(server, name) \
-       SILC_CHANNEL(channel_find(SERVER(server), name))
-
 SILC_CHANNEL_REC *silc_channel_find_entry(SILC_SERVER_REC *server,
                                          SilcChannelEntry entry);
 
index ddd39e409d7445c44e422904bf306ded90e93532..a2385c75c0661ce9a3a0f2e6cc442b5ab82cf180 100644 (file)
@@ -98,7 +98,7 @@ silc_channel_message(SilcClient client, SilcClientConnection conn,
   
   nick = silc_nicklist_find(chanrec, sender);
   signal_emit("message public", 6, server, msg,
-             nick == NULL ? "(unknown)" : nick->nick,
+             nick == NULL ? "[<unknown>]" : nick->nick,
              nick == NULL ? NULL : nick->host,
              chanrec->name, nick);
 }
@@ -115,7 +115,7 @@ silc_private_message(SilcClient client, SilcClientConnection conn,
   
   server = conn == NULL ? NULL : conn->context;
   signal_emit("message private", 4, server, msg,
-             sender->nickname ? sender->nickname : "(unknown)",
+             sender->nickname ? sender->nickname : "[<unknown>]",
              sender->username ? sender->username : NULL);
 }
 
@@ -140,10 +140,16 @@ static NOTIFY_REC notifies[] = {
   { SILC_NOTIFY_TYPE_LEAVE,            "leave" },
   { SILC_NOTIFY_TYPE_SIGNOFF,          "signoff" },
   { SILC_NOTIFY_TYPE_TOPIC_SET,                "topic" },
-  { SILC_NOTIFY_TYPE_NICK_CHANGE,              "nick" },
+  { SILC_NOTIFY_TYPE_NICK_CHANGE,      "nick" },
   { SILC_NOTIFY_TYPE_CMODE_CHANGE,     "cmode" },
   { SILC_NOTIFY_TYPE_CUMODE_CHANGE,    "cumode" },
-  { SILC_NOTIFY_TYPE_MOTD,             "motd" }
+  { SILC_NOTIFY_TYPE_MOTD,             "motd" },
+  { SILC_NOTIFY_TYPE_CHANNEL_CHANGE,   "channel_change" },
+  { SILC_NOTIFY_TYPE_SERVER_SIGNOFF,   "server_signoff" },
+  { SILC_NOTIFY_TYPE_KICKED,           "kick" },
+  { SILC_NOTIFY_TYPE_KILLED,           "kill" },
+  { SILC_NOTIFY_TYPE_UMODE_CHANGE,      "umode" },
+  { SILC_NOTIFY_TYPE_BAN,               "ban" },
 };
 
 static void silc_notify(SilcClient client, SilcClientConnection conn,
@@ -156,21 +162,18 @@ static void silc_notify(SilcClient client, SilcClientConnection conn,
   va_start(va, type);
   
   if (type == SILC_NOTIFY_TYPE_NONE) {
-    /* some generic notice from server */
-    printtext(server, NULL, MSGLEVEL_CRAP, "%s",
-             (char *) va_arg(va, char *));
+    /* Some generic notice from server */
+    printtext(server, NULL, MSGLEVEL_CRAP, "%s", (char *)va_arg(va, char *));
   } else if (type < MAX_NOTIFY) {
-    /* send signal about the notify event */
+    /* Send signal about the notify event */
     char signal[50];
-    
-    g_snprintf(signal, sizeof(signal), "silc event %s",
-              notifies[type].name);
+    g_snprintf(signal, sizeof(signal), "silc event %s", notifies[type].name);
     signal_emit(signal, 2, server, va);
   } else {
-    /* unknown notify */
-    printtext(server, NULL, MSGLEVEL_CRAP,
-             "Unknown notify %d", type);
+    /* Unknown notify */
+    printtext(server, NULL, MSGLEVEL_CRAP, "Unknown notify type %d", type);
   }
+
   va_end(va);
 }
 
@@ -182,7 +185,7 @@ static void
 silc_connect(SilcClient client, SilcClientConnection conn, int success)
 {
   SILC_SERVER_REC *server = conn->context;
-  
+
   if (success) {
     server->connected = TRUE;
     signal_emit("event connected", 1, server);
@@ -198,12 +201,12 @@ silc_connect(SilcClient client, SilcClientConnection conn, int success)
 static void 
 silc_disconnect(SilcClient client, SilcClientConnection conn)
 {
-       SILC_SERVER_REC *server = conn->context;
+  SILC_SERVER_REC *server = conn->context;
 
-       server->conn->context = NULL;
-       server->conn = NULL;
-       server->connection_lost = TRUE;
-       server_disconnect(SERVER(server));
+  server->conn->context = NULL;
+  server->conn = NULL;
+  server->connection_lost = TRUE;
+  server_disconnect(SERVER(server));
 }
 
 /* Command handler. This function is called always in the command function.
@@ -246,24 +249,188 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
 {
   SILC_SERVER_REC *server = conn->context;
   SILC_CHANNEL_REC *chanrec;
-  va_list va;
+  va_list vp;
 
-  va_start(va, status);
-
-  /*g_snprintf(signal, sizeof(signal), "silc command reply %s",
-    silc_commands[type]);
-    signal_emit(signal, 2, server, va);*/
+  va_start(vp, status);
 
   switch(command) {
+    case SILC_COMMAND_WHOIS:
+      {
+       char buf[1024], *nickname, *username, *realname;
+       int len;
+       uint32 idle, mode;
+       SilcBuffer channels;
+
+       if (status == SILC_STATUS_ERR_NO_SUCH_NICK ||
+           status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
+         char *tmp;
+         tmp = silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
+                                          3, NULL);
+         if (tmp)
+           client->ops->say(client, conn, "%s: %s", tmp,
+                            silc_client_command_status_message(status));
+         else
+           client->ops->say(client, conn, "%s",
+                            silc_client_command_status_message(status));
+         break;
+       }
+
+       if (!success)
+         return;
+
+       (void)va_arg(vp, SilcClientEntry);
+       nickname = va_arg(vp, char *);
+       username = va_arg(vp, char *);
+       realname = va_arg(vp, char *);
+       channels = va_arg(vp, SilcBuffer);
+       mode = va_arg(vp, uint32);
+       idle = va_arg(vp, uint32);
+
+       memset(buf, 0, sizeof(buf));
+
+       if (nickname) {
+         len = strlen(nickname);
+         strncat(buf, nickname, len);
+         strncat(buf, " is ", 4);
+       }
+       
+       if (username) {
+         strncat(buf, username, strlen(username));
+       }
+       
+       if (realname) {
+         strncat(buf, " (", 2);
+         strncat(buf, realname, strlen(realname));
+         strncat(buf, ")", 1);
+       }
+
+       client->ops->say(client, conn, "%s", buf);
+
+       if (channels) {
+         SilcDList list = silc_channel_payload_parse_list(channels);
+         if (list) {
+           SilcChannelPayload entry;
+
+           memset(buf, 0, sizeof(buf));
+           strcat(buf, "on channels: ");
+
+           silc_dlist_start(list);
+           while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
+             char *m = silc_client_chumode_char(silc_channel_get_mode(entry));
+             uint32 name_len;
+             char *name = silc_channel_get_name(entry, &name_len);
+
+             if (m)
+               strncat(buf, m, strlen(m));
+             strncat(buf, name, name_len);
+             strncat(buf, " ", 1);
+             silc_free(m);
+           }
+
+           client->ops->say(client, conn, "%s", buf);
+           silc_channel_payload_list_free(list);
+         }
+       }
+
+       if (mode) {
+         if ((mode & SILC_UMODE_SERVER_OPERATOR) ||
+             (mode & SILC_UMODE_ROUTER_OPERATOR))
+           client->ops->say(client, conn, "%s is %s", nickname,
+                            (mode & SILC_UMODE_SERVER_OPERATOR) ?
+                            "Server Operator" :
+                            (mode & SILC_UMODE_ROUTER_OPERATOR) ?
+                            "SILC Operator" : "[Unknown mode]");
+
+         if (mode & SILC_UMODE_GONE)
+           client->ops->say(client, conn, "%s is gone", nickname);
+       }
+
+       if (idle && nickname)
+         client->ops->say(client, conn, "%s has been idle %d %s",
+                          nickname,
+                          idle > 60 ? (idle / 60) : idle,
+                          idle > 60 ? "minutes" : "seconds");
+      }
+      break;
+
+    case SILC_COMMAND_WHOWAS:
+      {
+       char buf[1024], *nickname, *username, *realname;
+       int len;
+
+       if (status == SILC_STATUS_ERR_NO_SUCH_NICK ||
+           status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
+         char *tmp;
+         tmp = silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
+                                          3, NULL);
+         if (tmp)
+           client->ops->say(client, conn, "%s: %s", tmp,
+                            silc_client_command_status_message(status));
+         else
+           client->ops->say(client, conn, "%s",
+                            silc_client_command_status_message(status));
+         break;
+       }
+
+       if (!success)
+         return;
+
+       (void)va_arg(vp, SilcClientEntry);
+       nickname = va_arg(vp, char *);
+       username = va_arg(vp, char *);
+       realname = va_arg(vp, char *);
+
+       memset(buf, 0, sizeof(buf));
+
+       if (nickname) {
+         len = strlen(nickname);
+         strncat(buf, nickname, len);
+         strncat(buf, " was ", 5);
+       }
+       
+       if (username) {
+         strncat(buf, username, strlen(nickname));
+       }
+       
+       if (realname) {
+         strncat(buf, " (", 2);
+         strncat(buf, realname, strlen(realname));
+         strncat(buf, ")", 1);
+       }
+
+       client->ops->say(client, conn, "%s", buf);
+      }
+      break;
+
+    case SILC_COMMAND_INVITE:
+      {
+       SilcChannelEntry channel;
+       char *invite_list;
+
+       if (!success)
+         return;
+       
+       channel = va_arg(vp, SilcChannelEntry);
+       invite_list = va_arg(vp, char *);
+
+       if (invite_list)
+         silc_say(client, conn, "%s invite list: %s", channel->channel_name,
+                  invite_list);
+       else
+         silc_say(client, conn, "%s invite list not set", 
+                  channel->channel_name);
+      }
+      break;
+
   case SILC_COMMAND_JOIN: 
     {
       char *channel, *mode;
       uint32 modei;
       SilcChannelEntry channel_entry;
       
-      channel = va_arg(va, char *);
-      channel_entry = va_arg(va, SilcChannelEntry);
-      modei = va_arg(va, uint32);
+      channel = va_arg(vp, char *);
+      channel_entry = va_arg(vp, SilcChannelEntry);
+      modei = va_arg(vp, uint32);
       mode = silc_client_chmode(modei, channel_entry);
       
       chanrec = silc_channel_find(server, channel);
@@ -277,9 +444,10 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       signal_emit("channel mode changed", 1, chanrec);
       break;
     }
+
   case SILC_COMMAND_NICK: 
     {
-      SilcClientEntry client = va_arg(va, SilcClientEntry);
+      SilcClientEntry client = va_arg(vp, SilcClientEntry);
       char *old;
       
       old = g_strdup(server->nick);
@@ -293,13 +461,14 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       g_free(old);
       break;
     }
+
   case SILC_COMMAND_USERS: 
     {
       SilcChannelEntry channel;
       SilcChannelUser user;
       NICK_REC *ownnick;
       
-      channel = va_arg(va, SilcChannelEntry);
+      channel = va_arg(vp, SilcChannelEntry);
       chanrec = silc_channel_find_entry(server, channel);
       if (chanrec == NULL)
        break;
@@ -317,7 +486,7 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     }
   }
   
-  va_end(va);
+  va_end(vp);
 }
 
 /* Verifies received public key. If user decides to trust the key it is
index 8d690a2f8cdb560da8ee712d312f18874b236df5..adc82e21cc14b8eb184af8e623be495d2d10d68c 100644 (file)
@@ -5,9 +5,8 @@
 
 typedef struct {
 #include "nick-rec.h"
-       SilcChannelUser silc_user;
-
-       unsigned int founder:1;
+  SilcChannelUser silc_user;
+  unsigned int founder:1;
 } SILC_NICK_REC;
 
 SILC_NICK_REC *silc_nicklist_insert(SILC_CHANNEL_REC *channel,
index 21d562147f662aab3bfc5eea7f50c8f5beebc66b..95de6a5d9ec08a2da4fa6e1cc0e70ab3161eb7d8 100644 (file)
@@ -1,21 +1,22 @@
 /*
- silc-server.c : irssi
-
-    Copyright (C) 2000 Timo Sirainen
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  silc-server.c : irssi
+
+  Copyright (C) 2000 - 2001 Timo Sirainen
+                            Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
 #include "module.h"
@@ -46,14 +47,14 @@ void silc_servers_reconnect_deinit(void);
 static void silc_send_channel(SILC_SERVER_REC *server,
                              char *channel, char *msg)
 {
-        SILC_CHANNEL_REC *rec;
-
-       rec = silc_channel_find(server, channel);
-       if (rec == NULL)
-               return;
-
-       silc_client_send_channel_message(silc_client, server->conn,
-                                         rec->entry, msg, strlen(msg), TRUE);
+  SILC_CHANNEL_REC *rec;
+  
+  rec = silc_channel_find(server, channel);
+  if (rec == NULL)
+    return;
+  
+  silc_client_send_channel_message(silc_client, server->conn, rec->entry, 
+                                  NULL, 0, msg, strlen(msg), TRUE);
 }
 
 typedef struct {
@@ -64,266 +65,263 @@ typedef struct {
 static void silc_send_msg_clients(SilcClient client,
                                  SilcClientConnection conn,
                                  SilcClientEntry *clients,
-                                 unsigned int clients_count,
+                                 uint32 clients_count,
                                  void *context)
 {
-       PRIVMSG_REC *rec = context;
-       SilcClientEntry target;
-
-       if (clients_count == 0) {
-               printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
-                         "Unknown nick: %s", rec->nick);
-       } else {
-               target = clients[0]; /* FIXME: not a good idea :) */
-
-               silc_client_send_private_message(client, conn, target,
-                                                rec->msg, strlen(rec->msg),
-                                                TRUE);
-       }
-
-        g_free(rec->nick);
-        g_free(rec->msg);
-        g_free(rec);
+  PRIVMSG_REC *rec = context;
+  SilcClientEntry target;
+  
+  if (clients_count == 0) {
+    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s", rec->nick);
+  } else {
+    target = clients[0]; /* FIXME: not a good idea :) */
+    
+    silc_client_send_private_message(client, conn, target, 0,
+                                    rec->msg, strlen(rec->msg),
+                                    TRUE);
+  }
+  
+  g_free(rec->nick);
+  g_free(rec->msg);
+  g_free(rec);
 }
 
 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
 {
-       PRIVMSG_REC *rec;
-
-       rec = g_new0(PRIVMSG_REC, 1);
-       rec->nick = g_strdup(nick);
-       rec->msg = g_strdup(msg);
-
-       silc_client_get_clients(silc_client, server->conn,
-                               nick, "", silc_send_msg_clients, rec);
+  PRIVMSG_REC *rec;
+  
+  rec = g_new0(PRIVMSG_REC, 1);
+  rec->nick = g_strdup(nick);
+  rec->msg = g_strdup(msg);
+  
+  silc_client_get_clients(silc_client, server->conn,
+                         nick, "", silc_send_msg_clients, rec);
 }
 
 static int isnickflag_func(char flag)
 {
-       return flag == '@' || flag == '+';
+  return flag == '@' || flag == '+';
 }
 
 static int ischannel_func(const char *data)
 {
-       return *data == '#';
+  return *data == '#';
 }
 
 const char *get_nick_flags(void)
 {
-        return "@\0\0";
+  return "@\0\0";
 }
 
 static void send_message(SILC_SERVER_REC *server, char *target, char *msg)
 {
-       g_return_if_fail(server != NULL);
-       g_return_if_fail(target != NULL);
-       g_return_if_fail(msg != NULL);
-
-       if (*target == '#')
-               silc_send_channel(server, target, msg);
-       else
-               silc_send_msg(server, target, msg);
+  g_return_if_fail(server != NULL);
+  g_return_if_fail(target != NULL);
+  g_return_if_fail(msg != NULL);
+
+  if (*target == '#')
+    silc_send_channel(server, target, msg);
+  else
+    silc_send_msg(server, target, msg);
 }
 
 static void sig_connected(SILC_SERVER_REC *server)
 {
-       SilcClientConnection conn;
-       int fd;
-
-       if (!IS_SILC_SERVER(server))
-               return;
-
-       conn = silc_client_add_connection(silc_client,
-                                         server->connrec->address,
-                                         server->connrec->port,
-                                         server);
-       server->conn = conn;
-
-       fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
-       if (!silc_client_start_key_exchange(silc_client, conn, fd)) {
-                /* some internal error occured */
-               server_disconnect(SERVER(server));
-               signal_stop();
-               return;
-       }
-
-       server->isnickflag = isnickflag_func;
-       server->ischannel = ischannel_func;
-        server->get_nick_flags = get_nick_flags;
-       server->send_message = (void *) send_message;
+  SilcClientConnection conn;
+  int fd;
+
+  if (!IS_SILC_SERVER(server))
+    return;
+
+  conn = silc_client_add_connection(silc_client,
+                                   server->connrec->address,
+                                   server->connrec->port,
+                                   server);
+  server->conn = conn;
+       
+  fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
+  if (!silc_client_start_key_exchange(silc_client, conn, fd)) {
+    /* some internal error occured */
+    server_disconnect(SERVER(server));
+    signal_stop();
+    return;
+  }
+
+  server->isnickflag = isnickflag_func;
+  server->ischannel = ischannel_func;
+  server->get_nick_flags = get_nick_flags;
+  server->send_message = (void *) send_message;
 }
 
 static void sig_disconnected(SILC_SERVER_REC *server)
 {
-       if (!IS_SILC_SERVER(server) || server->conn == NULL)
-               return;
-
-       if (server->conn->sock != NULL) {
-               silc_client_close_connection(silc_client, server->conn);
-
-                /* SILC closes the handle */
-               g_io_channel_unref(net_sendbuffer_handle(server->handle));
-               net_sendbuffer_destroy(server->handle, FALSE);
-                server->handle = NULL;
-       }
+  if (!IS_SILC_SERVER(server) || server->conn == NULL)
+    return;
+  
+  if (server->conn->sock != NULL) {
+    silc_client_close_connection(silc_client, NULL, server->conn);
+    
+    /* SILC closes the handle */
+    g_io_channel_unref(net_sendbuffer_handle(server->handle));
+    net_sendbuffer_destroy(server->handle, FALSE);
+    server->handle = NULL;
+  }
 }
 
 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn)
 {
-       SILC_SERVER_REC *server;
-
-       g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
-       if (conn->address == NULL || *conn->address == '\0') return NULL;
-       if (conn->nick == NULL || *conn->nick == '\0') return NULL;
-
-       server = g_new0(SILC_SERVER_REC, 1);
-       server->chat_type = SILC_PROTOCOL;
-       server->connrec = conn;
-       if (server->connrec->port <= 0) server->connrec->port = 706;
-
-       if (!server_start_connect((SERVER_REC *) server)) {
-                server_connect_free(SERVER_CONNECT(conn));
-               g_free(server);
-               return NULL;
-       }
-
-       return server;
+  SILC_SERVER_REC *server;
+
+  g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
+  if (conn->address == NULL || *conn->address == '\0') 
+    return NULL;
+  if (conn->nick == NULL || *conn->nick == '\0') {
+    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, 
+             "Cannot connect: nickname is not set");
+    return NULL;
+  }
+
+  server = g_new0(SILC_SERVER_REC, 1);
+  server->chat_type = SILC_PROTOCOL;
+  server->connrec = conn;
+  if (server->connrec->port <= 0) 
+    server->connrec->port = 706;
+
+  if (!server_start_connect((SERVER_REC *) server)) {
+    server_connect_free(SERVER_CONNECT(conn));
+    g_free(server);
+    return NULL;
+  }
+
+  return server;
 }
 
-/* Return a string of all channels in server in
-   server->channels_join() format */
+/* Return a string of all channels in server in server->channels_join() 
+   format */
+
 char *silc_server_get_channels(SILC_SERVER_REC *server)
 {
-       GSList *tmp;
-       GString *chans;
-       char *ret;
-
-       g_return_val_if_fail(server != NULL, FALSE);
-
-       chans = g_string_new(NULL);
-       for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
-               CHANNEL_REC *channel = tmp->data;
-
-               g_string_sprintfa(chans, "%s,", channel->name);
-       }
-
-       if (chans->len > 0)
-               g_string_truncate(chans, chans->len-1);
-
-       ret = chans->str;
-       g_string_free(chans, FALSE);
-
-       return ret;
+  GSList *tmp;
+  GString *chans;
+  char *ret;
+
+  g_return_val_if_fail(server != NULL, FALSE);
+
+  chans = g_string_new(NULL);
+  for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
+    CHANNEL_REC *channel = tmp->data;
+    
+    g_string_sprintfa(chans, "%s,", channel->name);
+  }
+
+  if (chans->len > 0)
+    g_string_truncate(chans, chans->len-1);
+
+  ret = chans->str;
+  g_string_free(chans, FALSE);
+  
+  return ret;
 }
 
 void silc_command_exec(SILC_SERVER_REC *server,
                       const char *command, const char *args)
 {
-       unsigned int argc = 0;
-       unsigned char **argv;
-       unsigned int *argv_lens, *argv_types;
-       char *data, *tmpcmd;
-       SilcClientCommand *cmd;
-       SilcClientCommandContext ctx;
-
-       g_return_if_fail(server != NULL);
-
-       tmpcmd = g_strdup(command); g_strup(tmpcmd);
-       cmd = silc_client_command_find(tmpcmd);
-       g_free(tmpcmd);
-       if (cmd == NULL) return;
-
-       /* Now parse all arguments */
-       data = g_strconcat(command, " ", args, NULL);
-       silc_parse_command_line(data, &argv, &argv_lens,
-                               &argv_types, &argc, cmd->max_args);
-       g_free(data);
-
-       /* Allocate command context. This and its internals must be free'd
-          by the command routine receiving it. */
-       ctx = silc_client_command_alloc();
-       ctx->client = silc_client;
-       ctx->conn = server->conn;
-       ctx->command = cmd;
-       ctx->argc = argc;
-       ctx->argv = argv;
-       ctx->argv_lens = argv_lens;
-       ctx->argv_types = argv_types;
-
-       /* Execute command */
-       (*cmd->cb)(ctx);
+  uint32 argc = 0;
+  unsigned char **argv;
+  uint32 *argv_lens, *argv_types;
+  char *data, *tmpcmd;
+  SilcClientCommand *cmd;
+  SilcClientCommandContext ctx;
+
+  g_return_if_fail(server != NULL);
+
+  tmpcmd = g_strdup(command); g_strup(tmpcmd);
+  cmd = silc_client_command_find(tmpcmd);
+  g_free(tmpcmd);
+  if (cmd == NULL)
+    return;
+
+  /* Now parse all arguments */
+  data = g_strconcat(command, " ", args, NULL);
+  silc_parse_command_line(data, &argv, &argv_lens,
+                         &argv_types, &argc, cmd->max_args);
+  g_free(data);
+
+  /* Allocate command context. This and its internals must be free'd
+     by the command routine receiving it. */
+  ctx = silc_client_command_alloc();
+  ctx->client = silc_client;
+  ctx->conn = server->conn;
+  ctx->command = cmd;
+  ctx->argc = argc;
+  ctx->argv = argv;
+  ctx->argv_lens = argv_lens;
+  ctx->argv_types = argv_types;
+  
+  /* Execute command */
+  (*cmd->cb)(ctx);
 }
 
 static void command_users(const char *data, SILC_SERVER_REC *server,
                          WI_ITEM_REC *item)
 {
-        signal_emit("command names", 3, data, server, item);
+  signal_emit("command names", 3, data, server, item);
 }
 
 static void command_self(const char *data, SILC_SERVER_REC *server)
 {
-       if (!IS_SILC_SERVER(server) || !server->connected)
-               return;
-
-       silc_command_exec(server, current_command, data);
-       signal_stop();
-}
-
-static void event_motd(SILC_SERVER_REC *server, va_list va)
-{
-       char *text = va_arg(va, char *);
+  if (!IS_SILC_SERVER(server) || !server->connected)
+    return;
 
-       if (!settings_get_bool("skip_motd"))
-               printtext_multiline(server, NULL, MSGLEVEL_CRAP, "%s", text);
+  silc_command_exec(server, current_command, data);
+  signal_stop();
 }
 
 static void event_text(const char *line, SILC_SERVER_REC *server,
                       WI_ITEM_REC *item)
 {
-       char *str;
+  char *str;
 
-       g_return_if_fail(line != NULL);
+  g_return_if_fail(line != NULL);
 
-       if (!IS_SILC_ITEM(item))
-               return;
+  if (!IS_SILC_ITEM(item))
+    return;
 
-       str = g_strdup_printf("%s %s", item->name, line);
-       signal_emit("command msg", 3, str, server, item);
-       g_free(str);
+  str = g_strdup_printf("%s %s", item->name, line);
+  signal_emit("command msg", 3, str, server, item);
+  g_free(str);
 
-       signal_stop();
+  signal_stop();
 }
 
 void silc_server_init(void)
 {
-       silc_servers_reconnect_init();
-
-       signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
-        signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
-       signal_add("send text", (SIGNAL_FUNC) event_text);
-       signal_add("silc event motd", (SIGNAL_FUNC) event_motd);
-       command_bind("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
-       command_bind("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
-       command_bind("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
-       command_bind("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
-       command_bind("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
-       command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_users);
-
-       command_set_options("connect", "+silcnet");
+  silc_servers_reconnect_init();
+
+  signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
+  signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
+  signal_add("send text", (SIGNAL_FUNC) event_text);
+  command_bind("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_users);
+
+  command_set_options("connect", "+silcnet");
 }
 
 void silc_server_deinit(void)
 {
-       silc_servers_reconnect_deinit();
-
-        signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
-        signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
-       signal_remove("send text", (SIGNAL_FUNC) event_text);
-       signal_remove("silc event motd", (SIGNAL_FUNC) event_motd);
-       command_unbind("whois", (SIGNAL_FUNC) command_self);
-       command_unbind("nick", (SIGNAL_FUNC) command_self);
-       command_unbind("topic", (SIGNAL_FUNC) command_self);
-       command_unbind("cmode", (SIGNAL_FUNC) command_self);
-       command_unbind("cumode", (SIGNAL_FUNC) command_self);
-       command_unbind("users", (SIGNAL_FUNC) command_users);
+  silc_servers_reconnect_deinit();
+
+  signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
+  signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
+  signal_remove("send text", (SIGNAL_FUNC) event_text);
+  command_unbind("whois", (SIGNAL_FUNC) command_self);
+  command_unbind("nick", (SIGNAL_FUNC) command_self);
+  command_unbind("topic", (SIGNAL_FUNC) command_self);
+  command_unbind("cmode", (SIGNAL_FUNC) command_self);
+  command_unbind("cumode", (SIGNAL_FUNC) command_self);
+  command_unbind("users", (SIGNAL_FUNC) command_users);
 }
index 8ce42c3f8973095ce77c2e4f8651c5f31d86d133..1f9dd7f172821b26e8ee6a07fad012a9ccd77ccf 100644 (file)
@@ -27,32 +27,30 @@ typedef struct {
 #define STRUCT_SERVER_CONNECT_REC SILC_SERVER_CONNECT_REC
 typedef struct {
 #include "server-rec.h"
-       /* Command sending queue */
-       int cmdcount; /* number of commands in `cmdqueue'. Can be more than
-                        there actually is, to make flood control remember
-                        how many messages can be sent before starting the
-                        flood control */
-       int cmd_last_split; /* Last command wasn't sent entirely to server.
-                              First item in `cmdqueue' should be re-sent. */
-       GSList *cmdqueue;
-       GTimeVal last_cmd; /* last time command was sent to server */
-
-       GSList *idles; /* Idle queue - send these commands to server
-                         if there's nothing else to do */
-
-       gpointer chanqueries;
-       SilcClientConnection conn;
+  /* Command sending queue */
+  int cmdcount;                /* number of commands in `cmdqueue'. Can be more than
+                          there actually is, to make flood control remember
+                          how many messages can be sent before starting the
+                          flood control */
+  int cmd_last_split;  /* Last command wasn't sent entirely to server.
+                          First item in `cmdqueue' should be re-sent. */
+  GSList *cmdqueue;
+  GTimeVal last_cmd;   /* last time command was sent to server */
+  
+  GSList *idles;       /* Idle queue - send these commands to server
+                          if there's nothing else to do */
+  
+  gpointer chanqueries;
+  SilcClientConnection conn;
 } SILC_SERVER_REC;
 
 SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn);
 
-/* Return a string of all channels in server in
-   server->channels_join() format */
+/* Return a string of all channels in server in server->channels_join() 
+   format */
 char *silc_server_get_channels(SILC_SERVER_REC *server);
-
 void silc_command_exec(SILC_SERVER_REC *server,
                       const char *command, const char *args);
-
 void silc_server_init(void);
 void silc_server_deinit(void);