updates.
[silc.git] / lib / silccore / id.h
index a024a25d6a38cfd0be83e72aa6f4963a380d682c..114583bbce62de8919481488e491915bd5800154 100644 (file)
@@ -52,7 +52,7 @@ typedef uint16 SilcIdType;
    ID depends of the length of the IP address.
 */
 typedef struct {
-  unsigned char data[16];      /* IP data */
+  unsigned char data[16];      /* IP data (in MSB first order) */
   uint8 data_len;              /* Length of the data (4 or 16) */
 } SilcIDIP;
 
@@ -97,27 +97,35 @@ 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) \
-  memcmp(id->hash, _hash, CLIENTID_HASH_LEN)
+#define SILC_ID_COMPARE_HASH(id1, id2) \
+  (!memcmp((id1)->hash, (id2)->hash, CLIENTID_HASH_LEN))
 
 /* Prototypes */
 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