updates.
[silc.git] / lib / silcclient / client.c
index 2619df2671b66c5d6e6b82c61bb2948f21dbcd41..0d0aeec257e8f5a352f093f45fc837053e38df91 100644 (file)
@@ -1350,7 +1350,6 @@ void silc_client_close_connection_real(SilcClient client,
 
   /* Unregister all tasks */
   silc_schedule_task_del_by_fd(client->schedule, sock->sock);
-  silc_schedule_task_del_by_fd(client->schedule, sock->sock);
 
   /* Close the actual connection */
   silc_net_close_connection(sock->sock);
@@ -1378,6 +1377,7 @@ void silc_client_close_connection_real(SilcClient client,
     /* Free all cache entries */
     SilcIDCacheList list;
     SilcIDCacheEntry entry;
+    SilcClientCommandPending *r;
     bool ret;
 
     if (silc_idcache_get_all(conn->client_cache, &list)) {
@@ -1429,8 +1429,6 @@ void silc_client_close_connection_real(SilcClient client,
       silc_hmac_free(conn->hmac_send);
     if (conn->hmac_receive)
       silc_hmac_free(conn->hmac_receive);
-    if (conn->pending_commands)
-      silc_dlist_uninit(conn->pending_commands);
     if (conn->rekey)
       silc_free(conn->rekey);
 
@@ -1442,6 +1440,12 @@ void silc_client_close_connection_real(SilcClient client,
 
     silc_client_ftp_free_sessions(client, conn);
 
+    silc_dlist_start(conn->pending_commands);
+    while ((r = silc_dlist_get(conn->pending_commands)) != SILC_LIST_END)
+      silc_dlist_del(conn->pending_commands, r);
+    if (conn->pending_commands)
+      silc_dlist_uninit(conn->pending_commands);
+
     memset(conn, 0, sizeof(*conn));
     silc_client_del_connection(client, conn);
   }
@@ -1479,16 +1483,28 @@ SILC_TASK_CALLBACK(silc_client_disconnected_by_server_later)
 
 void silc_client_disconnected_by_server(SilcClient client,
                                        SilcSocketConnection sock,
-                                       SilcBuffer message)
+                                       SilcBuffer packet)
 {
-  char *msg;
+  SilcStatus status;
+  char *message = NULL;
 
   SILC_LOG_DEBUG(("Server disconnected us, sock %d", sock->sock));
 
-  msg = silc_memdup(message->data, message->len);
+  if (packet->len < 1)
+    return;
+
+  status = (SilcStatus)packet->data[0];
+
+  if (packet->len > 1 &&
+      silc_utf8_valid(packet->data + 1, packet->len - 1))
+    message = silc_memdup(packet->data + 1, packet->len - 1);
+
   client->internal->ops->say(client, sock->user_data, 
-                            SILC_CLIENT_MESSAGE_AUDIT, msg);
-  silc_free(msg);
+                            SILC_CLIENT_MESSAGE_AUDIT, 
+                            "Server closed connection: %s (%d) %s",
+                            silc_get_status_message(status), status,
+                            message ? message : "");
+  silc_free(message);
 
   SILC_SET_DISCONNECTED(sock);
 
@@ -1543,15 +1559,17 @@ static void silc_client_resume_session_cb(SilcClient client,
                                 SILC_CLIENT_CONN_SUCCESS_RESUME :
                                 SILC_CLIENT_CONN_ERROR);
 
-  /* Issue INFO command to fetch the real server name and server
-     information and other stuff. */
-  silc_client_command_register(client, SILC_COMMAND_INFO, NULL, NULL,
-                              silc_client_command_reply_info_i, 0, 
-                              ++conn->cmd_ident);
-  sidp = silc_id_payload_encode(conn->remote_id, SILC_ID_SERVER);
-  silc_client_command_send(client, conn, SILC_COMMAND_INFO,
-                          conn->cmd_ident, 1, 2, sidp->data, sidp->len);
-  silc_buffer_free(sidp);
+  if (success) {
+    /* Issue INFO command to fetch the real server name and server
+       information and other stuff. */
+    silc_client_command_register(client, SILC_COMMAND_INFO, NULL, NULL,
+                                silc_client_command_reply_info_i, 0, 
+                                ++conn->cmd_ident);
+    sidp = silc_id_payload_encode(conn->remote_id, SILC_ID_SERVER);
+    silc_client_command_send(client, conn, SILC_COMMAND_INFO,
+                            conn->cmd_ident, 1, 2, sidp->data, sidp->len);
+    silc_buffer_free(sidp);
+  }
 }
 
 /* Processes the received new Client ID from server. Old Client ID is