silcclient: handle command timeout error correctly
[silc.git] / lib / silcclient / command_reply.c
index 910aab545be02edd180c36a8dbc8e3cca64077fb..a3838f4e5b04b869f8eb1c958ebdec50a4050b63 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2007 Pekka Riikonen
+  Copyright (C) 1997 - 2014 Pekka Riikonen
 
   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
@@ -118,6 +118,7 @@ static void silc_client_command_process_error(SilcClientCommandContext cmd,
     client_entry = silc_client_get_client_by_id(client, conn, &id.u.client_id);
     if (client_entry) {
       silc_client_remove_from_channels(client, conn, client_entry);
+      client_entry->internal.valid = FALSE;
       silc_client_del_client(client, conn, client_entry);
       silc_client_unref_client(client, conn, client_entry);
     }
@@ -245,6 +246,7 @@ SILC_FSM_STATE(silc_client_command_reply_timeout)
 
   /* Timeout, reply not received in timely fashion */
   silc_list_del(conn->internal->pending_commands, cmd);
+  cmd->status = SILC_STATUS_OK;
   ERROR_CALLBACK(SILC_STATUS_ERR_TIMEDOUT);
   return SILC_FSM_FINISH;
 }
@@ -737,6 +739,12 @@ SILC_FSM_STATE(silc_client_command_reply_nick)
     goto out;
   }
 
+  /* All auto-generated private message keys must be rekeyed because
+     we changed nick and others may not know about it. */
+  conn->internal->ake_generation++;
+  SILC_LOG_DEBUG(("AKE keys will be rekeyed, generation %u",
+                 conn->internal->ake_generation));
+
   silc_rwlock_unlock(conn->local_entry->internal.lock);
 
   /* Notify application */
@@ -947,6 +955,7 @@ SILC_FSM_STATE(silc_client_command_reply_kill)
   /* Remove the client */
   if (client_entry) {
     silc_client_remove_from_channels(client, conn, client_entry);
+    client_entry->internal.valid = FALSE;
     silc_client_del_client(client, conn, client_entry);
     silc_client_unref_client(client, conn, client_entry);
   }
@@ -1170,6 +1179,17 @@ SILC_FSM_STATE(silc_client_command_reply_join)
     silc_client_ref_channel(client, conn, channel);
   }
 
+  /* Get hmac */
+  hmac = silc_argument_get_arg_type(args, 11, NULL);
+  if (hmac && !silc_hmac_is_supported(hmac)) {
+    if (cmd->verbose)
+      SAY(client, conn, SILC_CLIENT_MESSAGE_COMMAND_ERROR,
+         "Cannot join channel: Unsupported HMAC `%s'", hmac);
+    ERROR_CALLBACK(SILC_STATUS_ERR_UNKNOWN_ALGORITHM);
+    silc_rwlock_unlock(channel->internal.lock);
+    goto out;
+  }
+
   /* Get the list count */
   tmp = silc_argument_get_arg_type(args, 12, &len);
   if (!tmp) {
@@ -1243,19 +1263,6 @@ SILC_FSM_STATE(silc_client_command_reply_join)
     }
   }
 
-  /* Get hmac */
-  hmac = silc_argument_get_arg_type(args, 11, NULL);
-  if (hmac) {
-    if (!silc_hmac_alloc(hmac, NULL, &channel->internal.hmac)) {
-      if (cmd->verbose)
-       SAY(client, conn, SILC_CLIENT_MESSAGE_COMMAND_ERROR,
-           "Cannot join channel: Unsupported HMAC `%s'", hmac);
-      ERROR_CALLBACK(SILC_STATUS_ERR_UNKNOWN_ALGORITHM);
-      silc_rwlock_unlock(channel->internal.lock);
-      goto out;
-    }
-  }
-
   /* Get channel mode */
   tmp = silc_argument_get_arg_type(args, 5, &len);
   if (tmp && len == 4)
@@ -1361,7 +1368,7 @@ SILC_FSM_STATE(silc_client_command_reply_motd)
          line[0] = ' ';
 
        if (cmd->verbose)
-         SAY(client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", line);
+         SAY(client, conn, SILC_CLIENT_MESSAGE_AUDIT, "%s", line);
 
        if (!strlen(cp))
          break;
@@ -2016,7 +2023,7 @@ SILC_FSM_STATE(silc_client_command_reply_getkey)
   SilcServerEntry server_entry;
   unsigned char *tmp;
   SilcUInt32 len;
-  SilcPublicKey public_key;
+  SilcPublicKey public_key = NULL;
   SilcID id;
 
   /* Sanity checks */