Optimized PING command handling a bit.
[silc.git] / apps / silcd / command.c
index 2a354d25f40102476b71705f6e56b46101d89baf..06fbd9fb1f6dbf13ce104fa57c66d025c7f3ccee 100644 (file)
@@ -1545,11 +1545,10 @@ SILC_SERVER_CMD_FUNC(ping)
 {
   SilcServerCommandContext cmd = (SilcServerCommandContext)context;
   SilcServer server = cmd->server;
-  SilcServerID *id;
   SilcUInt32 len;
   unsigned char *tmp;
 
-  SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_INFO, cmd, 1, 2);
+  SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_PING, cmd, 1, 2);
 
   /* Get Server ID */
   tmp = silc_argument_get_arg_type(cmd->args, 1, &len);
@@ -1558,11 +1557,8 @@ SILC_SERVER_CMD_FUNC(ping)
                                          SILC_STATUS_ERR_NO_SERVER_ID, 0);
     goto out;
   }
-  id = silc_id_str2id(tmp, len, SILC_ID_SERVER);
-  if (!id)
-    goto out;
 
-  if (SILC_ID_SERVER_COMPARE(id, server->id)) {
+  if (!memcmp(tmp, server->id_string, server->id_string_len)) {
     /* Send our reply */
     silc_server_command_send_status_reply(cmd, SILC_COMMAND_PING,
                                          SILC_STATUS_OK, 0);
@@ -1572,8 +1568,6 @@ SILC_SERVER_CMD_FUNC(ping)
     goto out;
   }
 
-  silc_free(id);
-
  out:
   silc_server_command_free(cmd);
 }
@@ -1737,6 +1731,25 @@ static void silc_server_command_join_channel(SilcServer server,
       goto out;
     }
 
+    if (auth && auth_len && !client->data.public_key) {
+      if (cmd->pending == 2)
+       goto out;
+
+      /* We must retrieve the detached client's public key by sending
+        GETKEY command. Reprocess this packet after receiving the key */
+      clidp = silc_id_payload_encode(client_id, SILC_ID_CLIENT);
+      silc_server_send_command(server, cmd->sock,
+                              SILC_COMMAND_GETKEY, ++server->cmd_ident,
+                              1, 1, clidp->data, clidp->len);
+      silc_buffer_free(clidp);
+      silc_server_command_pending(server, SILC_COMMAND_GETKEY,
+                                 server->cmd_ident,
+                                 silc_server_command_join, 
+                                 silc_server_command_dup(cmd));
+      cmd->pending = 2;
+      goto out;
+    }
+
     cmd->pending = FALSE;
   }
 
@@ -3436,7 +3449,7 @@ SILC_SERVER_CMD_FUNC(oper)
       silc_server_command_send_status_reply(cmd, SILC_COMMAND_OPER,
                                            SILC_STATUS_ERR_AUTH_FAILED,
                                            0);
-      SILC_LOG_INFO(("OPER authentication failed for username '%s' by"
+      SILC_LOG_INFO(("OPER authentication failed for username '%s' by "
                     "nickname '%s' from %s", username,
                     client->nickname, cmd->sock->hostname));
       goto out;
@@ -3836,7 +3849,7 @@ SILC_SERVER_CMD_FUNC(silcoper)
     if (!admin) {
       silc_server_command_send_status_reply(cmd, SILC_COMMAND_SILCOPER,
                                            SILC_STATUS_ERR_AUTH_FAILED, 0);
-      SILC_LOG_INFO(("SILCOPER authentication failed for username '%s' by"
+      SILC_LOG_INFO(("SILCOPER authentication failed for username '%s' by "
                     "nickname '%s' from %s", username,
                     client->nickname, cmd->sock->hostname));
       goto out;