updates.
[silc.git] / apps / irssi / src / silc / core / client_ops.c
index e8386ac52055329107581b5fd1db608119811881..103ccfd6ebfe2cdb2e48013e97709974a8e3e050 100644 (file)
@@ -45,7 +45,7 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                                SilcVerifyPublicKey completion, void *context);
 
 void silc_say(SilcClient client, SilcClientConnection conn,
-                    char *msg, ...)
+             SilcClientMessageType type, char *msg, ...)
 {
   SILC_SERVER_REC *server;
   va_list va;
@@ -86,19 +86,23 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
   
   server = conn == NULL ? NULL : conn->context;
   chanrec = silc_channel_find_entry(server, channel);
+  if (!chanrec)
+    return;
   
   nick = silc_nicklist_find(chanrec, sender);
 
   if (flags & SILC_MESSAGE_FLAG_ACTION)
     printformat_module("fe-common/silc", server, channel->channel_name,
-                      MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_ACTION, msg);
+                      MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_ACTION, 
+                       nick == NULL ? "[<unknown>]" : nick->nick, msg);
   else if (flags & SILC_MESSAGE_FLAG_NOTICE)
     printformat_module("fe-common/silc", server, channel->channel_name,
-                      MSGLEVEL_NOTICES, SILCTXT_CHANNEL_NOTICE, msg);
+                      MSGLEVEL_NOTICES, SILCTXT_CHANNEL_NOTICE, 
+                       nick == NULL ? "[<unknown>]" : nick->nick, msg);
   else
     signal_emit("message public", 6, server, msg,
                nick == NULL ? "[<unknown>]" : nick->nick,
-               nick == NULL ? NULL : nick->host,
+               nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
                chanrec->name, nick);
 }
 
@@ -180,7 +184,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
    or connecting failed.  This is also the first time application receives
    the SilcClientConnection objecet which it should save somewhere. */
 
-void  silc_connect(SilcClient client, SilcClientConnection conn, int success)
+void silc_connect(SilcClient client, SilcClientConnection conn, int success)
 {
   SILC_SERVER_REC *server = conn->context;
 
@@ -219,6 +223,23 @@ void silc_command(SilcClient client, SilcClientConnection conn,
                  SilcClientCommandContext cmd_context, int success,
                  SilcCommand command)
 {
+  SILC_SERVER_REC *server = conn->context;
+
+  if (!success)
+    return;
+
+  switch(command) {
+  case SILC_COMMAND_INVITE:
+    printformat_module("fe-common/silc", server, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CHANNEL_INVITING,
+                      cmd_context->argv[2], 
+                      (cmd_context->argv[1][0] == '*' ?
+                       (char *)conn->current_channel->channel_name :
+                       (char *)cmd_context->argv[1]));
+    break;
+  default:
+    break;
+  }
 }
 
 /* Client info resolving callback when JOIN command reply is received.
@@ -427,18 +448,24 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     {
       SilcChannelEntry channel;
       char *invite_list;
+      SilcArgumentPayload args;
+      int argc = 0;
       
       if (!success)
        return;
       
       channel = va_arg(vp, SilcChannelEntry);
       invite_list = va_arg(vp, char *);
-      
+
+      args = silc_command_get_args(cmd_payload);
+      if (args)
+       argc = silc_argument_get_arg_num(args);
+
       if (invite_list)
        printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
                           SILCTXT_CHANNEL_INVITE_LIST, channel->channel_name,
                           invite_list);
-      else
+      else if (argc == 3)
        printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
                           SILCTXT_CHANNEL_NO_INVITE_LIST, 
                           channel->channel_name);
@@ -453,6 +480,9 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcBuffer client_id_list;
       uint32 list_count;
 
+      if (!success)
+       return;
+
       channel = va_arg(vp, char *);
       channel_entry = va_arg(vp, SilcChannelEntry);
       modei = va_arg(vp, uint32);
@@ -465,22 +495,19 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       list_count = va_arg(vp, uint32);
       client_id_list = va_arg(vp, SilcBuffer);
 
-      if (!success)
-       return;
-
       chanrec = silc_channel_find(server, channel);
-      if (chanrec != NULL && !success)
-       channel_destroy(CHANNEL(chanrec));
-      else if (chanrec == NULL && success)
+      if (!chanrec)
        chanrec = silc_channel_create(server, channel, TRUE);
-      
+
       if (topic) {
        g_free_not_null(chanrec->topic);
        chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
        signal_emit("channel topic changed", 1, chanrec);
       }
 
-      mode = silc_client_chmode(modei, channel_entry);
+      mode = silc_client_chmode(modei, 
+                               channel_entry->channel_key->cipher->name,
+                               channel_entry->hmac->hmac->name);
       g_free_not_null(chanrec->mode);
       chanrec->mode = g_strdup(mode == NULL ? "" : mode);
       signal_emit("channel mode changed", 1, chanrec);
@@ -557,11 +584,17 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     break;
     
   case SILC_COMMAND_OPER:
+    if (!success)
+      return;
+
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_SERVER_OPER);
     break;
     
   case SILC_COMMAND_SILCOPER:
+    if (!success)
+      return;
+
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_ROUTER_OPER);
     break;
@@ -634,18 +667,24 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       unsigned char *pk;
       uint32 pk_len;
       
+      if (!success)
+       return;
+      
       id_type = va_arg(vp, uint32);
       entry = va_arg(vp, void *);
       public_key = va_arg(vp, SilcPublicKey);
       
       pk = silc_pkcs_public_key_encode(public_key, &pk_len);
       
-      if (id_type == SILC_ID_CLIENT)
-       silc_verify_public_key_internal(client, conn, SILC_SOCKET_TYPE_CLIENT,
-                                       pk, pk_len, SILC_SKE_PK_TYPE_SILC,
-                                       NULL, NULL);
+      silc_verify_public_key_internal(client, conn, 
+                                     (id_type == SILC_ID_CLIENT ?
+                                      SILC_SOCKET_TYPE_CLIENT :
+                                      SILC_SOCKET_TYPE_SERVER),
+                                     pk, pk_len, SILC_SKE_PK_TYPE_SILC,
+                                     NULL, NULL);
       silc_free(pk);
     }
+    break;
     
   case SILC_COMMAND_TOPIC:
     {
@@ -668,9 +707,14 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
        printformat_module("fe-common/silc", server, channel->channel_name,
                           MSGLEVEL_CRAP, SILCTXT_CHANNEL_TOPIC,
                           channel->channel_name, topic);
+      } else {
+       printformat_module("fe-common/silc", server, channel->channel_name,
+                          MSGLEVEL_CRAP, SILCTXT_CHANNEL_TOPIC_NOT_SET,
+                          channel->channel_name);
       }
     }
     break;
+
   }
 
   va_end(vp);
@@ -929,6 +973,8 @@ int silc_get_auth_method(SilcClient client, SilcClientConnection conn,
                         unsigned char **auth_data,
                         uint32 *auth_data_len)
 {
+  bool ret = TRUE;
+  SILC_SERVER_REC *server = conn ? conn->context : NULL;
 
   /* XXX must resolve from configuration whether this connection has
      any specific authentication data */
@@ -937,7 +983,12 @@ int silc_get_auth_method(SilcClient client, SilcClientConnection conn,
   *auth_data = NULL;
   *auth_data_len = 0;
 
-  return TRUE;
+  if (ret == FALSE) {
+    printformat_module("fe-common/silc", server, NULL,
+                      MSGLEVEL_MODES, SILCTXT_AUTH_METH_UNRESOLVED);
+  }
+
+  return ret;
 }
 
 /* Notifies application that failure packet was received.  This is called
@@ -977,6 +1028,9 @@ void silc_failure(SilcClient client, SilcClientConnection conn,
     if (status == SILC_SKE_STATUS_INCORRECT_SIGNATURE)
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP, 
                         SILCTXT_KE_INCORRECT_SIGNATURE);
+    if (status == SILC_SKE_STATUS_INVALID_COOKIE)
+      printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP, 
+                        SILCTXT_KE_INVALID_COOKIE);
   }
 
   if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_CONNECTION_AUTH) {
@@ -1001,7 +1055,7 @@ int silc_key_agreement(SilcClient client, SilcClientConnection conn,
                       SilcKeyAgreementCallback *completion,
                       void **context)
 {
-  char portstr[6];
+  char portstr[12];
 
   /* We will just display the info on the screen and return FALSE and user
      will have to start the key agreement with a command. */