updates. SILC.0.2.2
authorPekka Riikonen <priikone@silcnet.org>
Sun, 6 May 2001 14:41:10 +0000 (14:41 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 6 May 2001 14:41:10 +0000 (14:41 +0000)
CHANGES
apps/silcd/serverid.c
lib/silccore/id.c
lib/silccore/id.h
lib/silccore/idcache.c

diff --git a/CHANGES b/CHANGES
index e41102a9e28fde8f8c6324d4058bd0090a8e2681..d8b576b839105ff71d7761bdef207d06e3a16eca 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,7 +5,6 @@ Sun May  6 13:59:48 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
          This is a step towards IPv6 support.
 
          The silc_id_get_len takes now the ID as an extra argument.
-         Added new function silc_id_compare into lib/silccore/id.[ch].
          The silc_id_id2str, silc_id_str2id and silc_id_dup now supports
          both IPv4 and IPv6 based ID's.
 
index 42a5afe53712bb588b7336c344ba1482404b7263..12cebb6a57ec3d0ebe26ea4dbd73f36c28b651ec 100644 (file)
@@ -44,6 +44,7 @@ void silc_id_create_server_id(int sock, SilcRng rng, SilcServerID **new_id)
   }
 
   /* Create the ID */
+  /* XXX Does not support IPv6 */
   SILC_PUT32_MSB(server.sin_addr.s_addr, (*new_id)->ip.data);
   (*new_id)->ip.data_len = 4;
   (*new_id)->port = server.sin_port;
index 51c95d95fe829d6ddfad10a40ae636b15d85ab7a..ef05bef57c9c8057665ab700972a197f056496e4 100644 (file)
@@ -166,9 +166,7 @@ void *silc_id_dup(void *id, SilcIdType type)
     {
       SilcServerID *server_id = (SilcServerID *)id, *new;
       new = silc_calloc(1, sizeof(*server_id));
-      memcpy(&new->ip, &server_id->ip, sizeof(server_id->ip)); 
-      new->port = server_id->port;
-      new->rnd = server_id->rnd;
+      memcpy(new, server_id, sizeof(*server_id));
       return new;
     }
     break;
@@ -176,9 +174,7 @@ void *silc_id_dup(void *id, SilcIdType type)
     {
       SilcClientID *client_id = (SilcClientID *)id, *new;
       new = silc_calloc(1, sizeof(*client_id));
-      memcpy(&new->ip, &client_id->ip, sizeof(client_id->ip)); 
-      new->rnd = client_id->rnd;
-      memcpy(new->hash, client_id->hash, CLIENTID_HASH_LEN);
+      memcpy(new, client_id, sizeof(*client_id));
       return new;
     }
     break;
@@ -186,9 +182,7 @@ void *silc_id_dup(void *id, SilcIdType type)
     {
       SilcChannelID *channel_id = (SilcChannelID *)id, *new;
       new = silc_calloc(1, sizeof(*channel_id));
-      memcpy(&new->ip, &channel_id->ip, sizeof(channel_id->ip)); 
-      new->port = channel_id->port;
-      new->rnd = channel_id->rnd;
+      memcpy(new, channel_id, sizeof(*channel_id));
       return new;
     }
     break;
@@ -196,49 +190,3 @@ void *silc_id_dup(void *id, SilcIdType type)
 
   return NULL;
 }
-
-/* Returns TRUE if the `id2' is equal to `id1'. */
-
-bool silc_id_compare(void *id1, void *id2, SilcIdType type)
-{
-  switch(type) {
-  case SILC_ID_SERVER:
-    {
-      SilcServerID *server_id1 = (SilcServerID *)id1;
-      SilcServerID *server_id2 = (SilcServerID *)id2;
-      if (!memcmp(server_id1->ip.data, server_id2->ip.data, 
-                 server_id1->ip.data_len) &&
-         server_id1->port == server_id2->port &&
-         server_id1->rnd == server_id2->rnd)
-       return TRUE;
-      return FALSE;
-    }
-    break;
-  case SILC_ID_CLIENT:
-    {
-      SilcClientID *client_id1 = (SilcClientID *)id1;
-      SilcClientID *client_id2 = (SilcClientID *)id2;
-      if (!memcmp(client_id1->ip.data, client_id2->ip.data, 
-                 client_id1->ip.data_len) &&
-         client_id1->rnd == client_id2->rnd &&
-         !memcmp(client_id1->hash, client_id2->hash, CLIENTID_HASH_LEN))
-       return TRUE;
-      return FALSE;
-    }
-    break;
-  case SILC_ID_CHANNEL:
-    {
-      SilcChannelID *channel_id1 = (SilcChannelID *)id1;
-      SilcChannelID *channel_id2 = (SilcChannelID *)id2;
-      if (!memcmp(channel_id1->ip.data, channel_id2->ip.data, 
-                 channel_id1->ip.data_len) &&
-         channel_id1->port == channel_id2->port &&
-         channel_id1->rnd == channel_id2->rnd)
-       return TRUE;
-      return FALSE;
-    }
-    break;
-  }
-
-  return FALSE;
-}
index a024a25d6a38cfd0be83e72aa6f4963a380d682c..6a1034dffd612204bde3ccdd4e78a260f3d759fd 100644 (file)
@@ -97,17 +97,26 @@ typedef struct {
 
 /* Macros */
 
+/* Compares two ID's. */
+#define SILC_ID_COMPARE(id1, id2, len) (!memcmp(id1, id2, len))
+
 /* Compares Client ID's */
-#define SILC_ID_CLIENT_COMPARE(id1, id2)               \
-  silc_id_compare(id1, id2, SILC_ID_CLIENT)
+#define SILC_ID_CLIENT_COMPARE(id1, id2) \
+  SILC_ID_COMPARE(id1, id2, sizeof(SilcClientID))
 
 /* Compares Server ID's */
-#define SILC_ID_SERVER_COMPARE(id1, id2)               \
-  silc_id_compare(id1, id2, SILC_ID_SERVER)
+#define SILC_ID_SERVER_COMPARE(id1, id2) \
+  SILC_ID_COMPARE(id1, id2, sizeof(SilcServerID))
 
 /* Compares Channel ID's */
-#define SILC_ID_CHANNEL_COMPARE(id1, id2)                      \
-  silc_id_compare(id1, id2, SILC_ID_CHANNEL)
+#define SILC_ID_CHANNEL_COMPARE(id1, id2) \
+  SILC_ID_COMPARE(id1, id2, sizeof(SilcChannelID))
+
+/* Compares two ID's by type */
+#define SILC_ID_COMPARE_TYPE(id1, id2, type)                   \
+  (type == SILC_ID_SERVER ? SILC_ID_SERVER_COMPARE(id1, id2) : \
+   type == SILC_ID_CLIENT ? SILC_ID_CLIENT_COMPARE(id1, id2) : \
+   SILC_ID_CHANNEL_COMPARE(id1, id2))
 
 /* Compare nickname hash from Client ID */
 #define SILC_ID_COMPARE_HASH(id, _hash) \
@@ -118,6 +127,5 @@ unsigned char *silc_id_id2str(void *id, SilcIdType type);
 void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type);
 uint32 silc_id_get_len(void *id, SilcIdType type);
 void *silc_id_dup(void *id, SilcIdType type);
-bool silc_id_compare(void *id1, void *id2, SilcIdType type);
 
 #endif
index 164d15153d979ffac8936ef804d2ee217ef4fd93..c59d4f77531ba9587164c58eb4f6f0707c44befd 100644 (file)
@@ -326,7 +326,8 @@ int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type,
 
   if (id != SILC_ID_CACHE_ANY) {
     for (i = 0; i < cache->cache_count; i++)
-      if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type))
+      if (cache->cache[i].id && SILC_ID_COMPARE_TYPE(cache->cache[i].id, 
+                                                    id, type))
        silc_idcache_list_add(list, &(cache->cache[i]));
   } else {
     for (i = 0; i < cache->cache_count; i++)
@@ -358,7 +359,8 @@ int silc_idcache_find_by_id_one(SilcIDCache cache, void *id, SilcIdType type,
     return FALSE;
 
   for (i = 0; i < cache->cache_count; i++)
-    if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) {
+    if (cache->cache[i].id && SILC_ID_COMPARE_TYPE(cache->cache[i].id, 
+                                                  id, type)) {
       if (ret)
        *ret = &(cache->cache[i]);
       return TRUE;
@@ -483,7 +485,8 @@ int silc_idcache_del_by_id(SilcIDCache cache, SilcIdType type, void *id)
     return FALSE;
 
   for (i = 0; i < cache->cache_count; i++)
-    if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) {
+    if (cache->cache[i].id && SILC_ID_COMPARE_TYPE(cache->cache[i].id, 
+                                                  id, type)) {
       cache->cache[i].id = NULL;
       cache->cache[i].data = NULL;
       cache->cache[i].type = 0;