More SILC Server 1.1 porting. Added HTTP statistics access.
[silc.git] / apps / silcd / command.c
index ddccf1988aaa6758a1de49ad4fabc0f1aa7abdc7..f5c3824fa0fede2c7f7405a0d4e7427a1fcad8d7 100644 (file)
@@ -271,7 +271,7 @@ void silc_server_command_process(SilcServer server,
     else
       silc_schedule_task_add_timeout(server->schedule,
                                     silc_server_command_process_timeout,
-                                    timeout, 0, 1);
+                                    timeout, 0, 0);
     return;
   }
 
@@ -653,8 +653,8 @@ SILC_SERVER_CMD_FUNC(nick)
 
   /* Truncate over long nicks */
   if (nick_len > 128) {
-    nick[128] = '\0';
     nick_len = 128;
+    nick[nick_len - 1] = '\0';
   }
 
   /* Check for valid nickname string.  This is cached, original is saved
@@ -699,19 +699,13 @@ SILC_SERVER_CMD_FUNC(nick)
 
   oidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
 
-  /* Remove old cache entry */
-  silc_idcache_del_by_context(server->local_list->clients, client, NULL);
-
-  silc_free(client->id);
-  client->id = new_id;
-
+  /* Update client entry */
+  silc_idcache_update_by_context(server->local_list->clients, client,
+                                new_id, nickc, TRUE);
+  silc_free(new_id);
   silc_free(client->nickname);
   client->nickname = strdup(nick);
 
-  /* Update client cache */
-  silc_idcache_add(server->local_list->clients, nickc,
-                  client->id, (void *)client);
-
   nidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
 
   /* Send NICK_CHANGE notify to the client's channels */
@@ -861,6 +855,7 @@ SILC_SERVER_CMD_FUNC(list)
   SilcServerCommandContext cmd = (SilcServerCommandContext)context;
   SilcServer server = cmd->server;
   SilcID id;
+  SilcChannelID *channel_id = NULL;
   SilcChannelEntry *lchannels = NULL, *gchannels = NULL;
   SilcUInt32 lch_count = 0, gch_count = 0;
 
@@ -895,18 +890,15 @@ SILC_SERVER_CMD_FUNC(list)
   }
 
   /* Get Channel ID */
-  if (!silc_argument_get_decoded(cmd->args, 1, SILC_ARGUMENT_ID, &id, NULL)) {
-    silc_server_command_send_status_reply(cmd, SILC_COMMAND_LIST,
-                                         SILC_STATUS_ERR_NO_CHANNEL_ID, 0);
-    goto out;
-  }
+  if (silc_argument_get_decoded(cmd->args, 1, SILC_ARGUMENT_ID, &id, NULL))
+    channel_id = SILC_ID_GET_ID(id);
 
   /* Get the channels from local list */
-  lchannels = silc_idlist_get_channels(server->local_list, SILC_ID_GET_ID(id),
+  lchannels = silc_idlist_get_channels(server->local_list, channel_id,
                                       &lch_count);
 
   /* Get the channels from global list */
-  gchannels = silc_idlist_get_channels(server->global_list, SILC_ID_GET_ID(id),
+  gchannels = silc_idlist_get_channels(server->global_list, channel_id,
                                       &gch_count);
 
   /* Send the reply */
@@ -1733,6 +1725,9 @@ SILC_SERVER_CMD_FUNC(stats)
     goto out;
   }
 
+  SILC_LOG_DEBUG(("id %s", silc_id_render(SILC_ID_GET_ID(id),
+                                         id.type)));
+
   /* The ID must be ours */
   if (!SILC_ID_SERVER_COMPARE(server->id, SILC_ID_GET_ID(id))) {
     tmp = silc_argument_get_arg_type(cmd->args, 1, &tmp_len);
@@ -1844,7 +1839,8 @@ static void silc_server_command_join_channel(SilcServer server,
   if (!channel)
     return;
 
-  silc_socket_stream_get_info(sock, NULL, &hostname, &ip, NULL);
+  silc_socket_stream_get_info(silc_packet_stream_get_stream(sock),
+                             NULL, &hostname, &ip, NULL);
 
   /* Get the client entry */
   if (idata->conn_type == SILC_CONN_CLIENT) {
@@ -3839,7 +3835,8 @@ SILC_SERVER_CMD_FUNC(oper)
 
   SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_OPER, cmd, 1, 2);
 
-  silc_socket_stream_get_info(cmd->sock, NULL, &hostname, &ip, NULL);
+  silc_socket_stream_get_info(silc_packet_stream_get_stream(cmd->sock),
+                             NULL, &hostname, &ip, NULL);
 
   /* Get the username */
   username = silc_argument_get_arg_type(cmd->args, 1, &tmp_len);
@@ -4367,7 +4364,8 @@ SILC_SERVER_CMD_FUNC(silcoper)
 
   SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_SILCOPER, cmd, 1, 2);
 
-  silc_socket_stream_get_info(cmd->sock, NULL, &hostname, &ip, NULL);
+  silc_socket_stream_get_info(silc_packet_stream_get_stream(cmd->sock),
+                             NULL, &hostname, &ip, NULL);
 
   if (server->server_type != SILC_ROUTER) {
     silc_server_command_send_status_reply(cmd, SILC_COMMAND_SILCOPER,
@@ -4594,11 +4592,13 @@ SILC_SERVER_CMD_FUNC(ban)
                       SILC_STR_END);
     silc_hash_table_list(channel->ban_list, &htl);
     while (silc_hash_table_get(&htl, (void *)&type, (void *)&tmp2))
-      list = silc_argument_payload_encode_one(list, tmp2->data, silc_buffer_len(tmp2),
-                                             type);
+      list = silc_argument_payload_encode_one(list, tmp2->data,
+                                             silc_buffer_len(tmp2), type);
     silc_hash_table_list_reset(&htl);
   }
 
+  tmp_id = silc_argument_get_arg_type(cmd->args, 1, &id_len);
+
   /* Send BAN notify type to local servers (but not clients) and to
      network. */
   if (atype && tmp && len2) {
@@ -4608,7 +4608,7 @@ SILC_SERVER_CMD_FUNC(ban)
     if (server->server_type == SILC_ROUTER)
       silc_server_send_notify_to_channel(server, NULL, channel, FALSE, FALSE,
                                          SILC_NOTIFY_TYPE_BAN, 3,
-                                        id, id_len,
+                                        tmp_id, id_len,
                                         atype, 1,
                                         tmp ? blist.data : NULL,
                                         tmp ? silc_buffer_len(&blist) : 0);
@@ -4622,7 +4622,7 @@ SILC_SERVER_CMD_FUNC(ban)
   /* Send the reply back to the client */
   silc_server_send_command_reply(server, cmd->sock, SILC_COMMAND_BAN,
                                 SILC_STATUS_OK, 0, ident, 2,
-                                2, id, id_len,
+                                2, tmp_id, id_len,
                                 3, list ? list->data : NULL,
                                 list ? silc_buffer_len(list) : 0);
   silc_buffer_free(list);