Initial code commit for Toolkit 1.1.
[silc.git] / apps / silcd / server.c
index 2c3875a5c12bc8826866dcbfbe418621fddc5a20..92afbb91b5a9b62d115b9c41fc74d7df25f0eaac 100644 (file)
@@ -278,7 +278,7 @@ bool silc_server_init_secondary(SilcServer server)
 
 bool silc_server_init(SilcServer server)
 {
-  int sock;
+  int sock = -1;
   SilcServerID *id;
   SilcServerEntry id_entry;
   SilcIDListPurge purge;
@@ -295,7 +295,7 @@ bool silc_server_init(SilcServer server)
 #ifdef SILC_DEBUG
   /* Set debugging on if configured */
   if (server->config->debug_string) {
-    silc_debug = TRUE;
+    silc_log_debug(TRUE);
     silc_log_set_debug_string(server->config->debug_string);
   }
 #endif /* SILC_DEBUG */
@@ -343,22 +343,22 @@ bool silc_server_init(SilcServer server)
   /* Initialize ID caches */
   server->local_list->clients =
     silc_idcache_alloc(0, SILC_ID_CLIENT, silc_idlist_client_destructor,
-                      FALSE, TRUE);
+                      server, FALSE, TRUE);
   server->local_list->servers =
-    silc_idcache_alloc(0, SILC_ID_SERVER, NULL, FALSE, TRUE);
+    silc_idcache_alloc(0, SILC_ID_SERVER, NULL, NULL, FALSE, TRUE);
   server->local_list->channels =
-    silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL, FALSE, TRUE);
+    silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL, NULL, FALSE, TRUE);
 
   /* These are allocated for normal server as well as these hold some
      global information that the server has fetched from its router. For
      router these are used as they are supposed to be used on router. */
   server->global_list->clients =
     silc_idcache_alloc(0, SILC_ID_CLIENT, silc_idlist_client_destructor,
-                      FALSE, TRUE);
+                      server, FALSE, TRUE);
   server->global_list->servers =
-    silc_idcache_alloc(0, SILC_ID_SERVER, NULL, FALSE, TRUE);
+    silc_idcache_alloc(0, SILC_ID_SERVER, NULL, NULL, FALSE, TRUE);
   server->global_list->channels =
-    silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL, FALSE, TRUE);
+    silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL, NULL, FALSE, TRUE);
 
   /* Init watcher lists */
   server->watcher_list =
@@ -572,7 +572,7 @@ bool silc_server_rehash(SilcServer server)
   SILC_LOG_INFO(("Rehashing server"));
 
   /* Reset the logging system */
-  silc_log_quick = TRUE;
+  silc_log_quick(TRUE);
   silc_log_flush_all();
 
   /* Start the main rehash phase (read again the config file) */
@@ -764,7 +764,7 @@ bool silc_server_rehash(SilcServer server)
 #ifdef SILC_DEBUG
   /* Set debugging on if configured */
   if (server->config->debug_string) {
-    silc_debug = TRUE;
+    silc_log_debug(TRUE);
     silc_log_set_debug_string(server->config->debug_string);
   }
 #endif /* SILC_DEBUG */
@@ -2862,6 +2862,7 @@ void silc_server_packet_parse_type(SilcServer server,
      */
     if (packet->flags & SILC_PACKET_FLAG_LIST)
       break;
+    server->stat.commands_received++;
     silc_server_command_process(server, sock, packet);
     break;
 
@@ -2873,6 +2874,7 @@ void silc_server_packet_parse_type(SilcServer server,
      */
     if (packet->flags & SILC_PACKET_FLAG_LIST)
       break;
+    server->stat.commands_received++;
     silc_server_command_reply(server, sock, packet);
     break;
 
@@ -4127,7 +4129,7 @@ bool silc_server_create_channel_key(SilcServer server,
                                    SilcUInt32 key_len)
 {
   int i;
-  unsigned char channel_key[32], hash[32];
+  unsigned char channel_key[32], hash[SILC_HASH_MAXLEN];
   SilcUInt32 len;
 
   if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY) {
@@ -4210,7 +4212,7 @@ SilcChannelEntry silc_server_save_channel_key(SilcServer server,
 {
   SilcChannelKeyPayload payload = NULL;
   SilcChannelID *id = NULL;
-  unsigned char *tmp, hash[32];
+  unsigned char *tmp, hash[SILC_HASH_MAXLEN];
   SilcUInt32 tmp_len;
   char *cipher;
 
@@ -5079,6 +5081,8 @@ void silc_server_announce_watches(SilcServer server,
     if (!client || !client->id)
       continue;
 
+    server->stat.commands_sent++;
+
     idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
     args = silc_buffer_alloc_size(2);
     silc_buffer_format(args,
@@ -5718,6 +5722,7 @@ SILC_TASK_CALLBACK(silc_server_get_stats)
 
   if (!server->standalone) {
     SILC_LOG_DEBUG(("Retrieving stats from router"));
+    server->stat.commands_sent++;
     idp = silc_id_payload_encode(server->router->id, SILC_ID_SERVER);
     packet = silc_command_payload_encode_va(SILC_COMMAND_STATS,
                                            ++server->cmd_ident, 1,