More SILC Server 1.1 porting. Added HTTP statistics access.
[silc.git] / apps / silcd / idlist.c
index 2cdf77fb174cb3c510cf39f49bb7dadb415f204a..8088150e8c1ee1e880ee5ff9d9f9fa4e434d2400 100644 (file)
@@ -35,6 +35,8 @@
 void silc_idlist_add_data(void *entry, SilcIDListData idata)
 {
   SilcIDListData data = entry;
+  data->conn_type = idata->conn_type;
+  data->sconn = idata->sconn;
   data->hash = idata->hash;
   data->public_key = idata->public_key;
   memcpy(data->fingerprint, idata->fingerprint, sizeof(data->fingerprint));
@@ -160,7 +162,8 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
 
 SilcServerEntry
 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
-                               SilcBool registered, SilcIDCacheEntry *ret_entry)
+                               SilcBool registered,
+                               SilcIDCacheEntry *ret_entry)
 {
   SilcIDCacheEntry id_cache = NULL;
   SilcServerEntry server;
@@ -207,7 +210,9 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
     server = id_cache->context;
     sock = server->connection;
 
-    if (sock && silc_socket_stream_get_info(sock, NULL, &host, &ip, NULL)) {
+    if (sock && silc_socket_stream_get_info(
+                           silc_packet_stream_get_stream(sock),
+                           NULL, &host, &ip, NULL)) {
       if (((host && !strcasecmp(host, hostname)) ||
           (ip && !strcasecmp(ip, hostname))) &&
          server->id->port == SILC_SWAB_16(port))
@@ -291,6 +296,16 @@ int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry)
   return FALSE;
 }
 
+/* ID Cache destructor */
+
+void silc_idlist_server_destructor(SilcIDCache cache,
+                                  SilcIDCacheEntry entry,
+                                  void *dest_context,
+                                  void *app_context)
+{
+  silc_free(entry->name);
+}
+
 /******************************************************************************
 
                           Client entry functions
@@ -368,24 +383,11 @@ int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
   SILC_LOG_DEBUG(("Start"));
 
   if (entry) {
-    if (!silc_idcache_del_by_context(id_list->clients, entry, NULL /* XXX */)) {
+    /* Delete client, destructor will free data */
+    if (!silc_idcache_del_by_context(id_list->clients, entry, NULL)) {
       SILC_LOG_DEBUG(("Unknown client, did not delete"));
       return FALSE;
     }
-
-    assert(!silc_hash_table_count(entry->channels));
-
-    silc_free(entry->nickname);
-    silc_free(entry->servername);
-    silc_free(entry->username);
-    silc_free(entry->userinfo);
-    silc_free(entry->id);
-    silc_free(entry->attrs);
-    silc_hash_table_free(entry->channels);
-
-    memset(entry, 'F', sizeof(*entry));
-    silc_free(entry);
-
     return TRUE;
   }
 
@@ -399,15 +401,15 @@ void silc_idlist_client_destructor(SilcIDCache cache,
                                   void *dest_context,
                                   void *app_context)
 {
-  SilcServer server = app_context;
+  SilcServer server = dest_context;
   SilcClientEntry client;
 
   client = (SilcClientEntry)entry->context;
   if (client) {
-    /* Remove this client from the public key hash list */
+    /* Remove client's public key from repository, this will free it too. */
     if (client->data.public_key)
-      silc_hash_table_del_by_context(server->pk_hash,
-                                    client->data.public_key, client);
+      silc_skr_del_public_key(server->repository, client->data.public_key,
+                             client);
 
     assert(!silc_hash_table_count(client->channels));
     silc_free(client->nickname);
@@ -416,8 +418,6 @@ void silc_idlist_client_destructor(SilcIDCache cache,
     silc_free(client->userinfo);
     silc_free(client->id);
     silc_free(client->attrs);
-    if (client->data.public_key)
-      silc_pkcs_public_key_free(client->data.public_key);
     silc_hash_table_free(client->channels);
 
     memset(client, 'A', sizeof(*client));
@@ -634,7 +634,7 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
                                             NULL, NULL, NULL, TRUE);
 
   if (!silc_idcache_add(id_list->channels, channel_namec,
-                       (void *)channel->id, (void *)channel /*XXX, expire */)) {
+                       (void *)channel->id, (void *)channel)) {
     silc_hmac_free(channel->hmac);
     silc_hash_table_free(channel->user_list);
     silc_free(channel);
@@ -645,6 +645,16 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
   return channel;
 }
 
+/* ID Cache destructor */
+
+void silc_idlist_channel_destructor(SilcIDCache cache,
+                                   SilcIDCacheEntry entry,
+                                   void *dest_context,
+                                   void *app_context)
+{
+  silc_free(entry->name);
+}
+
 /* Foreach callbcak to free all users from the channel when deleting a
    channel entry. */