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.
}
/* 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;
{
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;
{
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;
{
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;
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;
-}
/* 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) \
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
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++)
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;
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;