+Sun May 6 13:59:48 EEST 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+ * Added new SilcIDIP structure into the lib/silccore/id.h and
+ replaced the old `ip' fields from all SILC ID's to that type.
+ 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.
+
+ The affected files are lib/silccore/id.[ch] and other files
+ around the tree using these routines.
+
+ * Removed the ID length arguments in server from various
+ silc_server_send_notify_* routines -> they are not needed
+ anymore.
+
Sat May 5 13:56:33 EEST 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
* Fixed memory leak in silc_encode_pem_file in the file
TODO/bugs In SILC Libraries
===========================
- o IPv6 support for ID's and into the code.
+ o silc_server_get_users_on_channel does not support IPv6 based Client
+ ID's.
+
+ o silc_server_route_get and the route code in general supports only
+ IPv4.
+
+ o silcd/serverid.c and its routines supports only IPv4.
o Compression routines are missing. The protocol supports packet
compression thus it must be implemented. SILC Comp API must be
silc_server_send_notify_nick_change(server, server->router->connection,
server->server_type == SILC_SERVER ?
FALSE : TRUE, client->id,
- new_id, SILC_ID_CLIENT_LEN);
+ new_id);
/* Remove old cache entry */
silc_idcache_del_by_id(server->local_list->clients, SILC_ID_CLIENT,
oidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
/* Free old ID */
- if (client->id) {
- memset(client->id, 0, SILC_ID_CLIENT_LEN);
+ if (client->id)
silc_free(client->id);
- }
/* Save the nickname as this client is our local client */
if (client->nickname)
silc_server_send_notify_topic_set(server, server->router->connection,
server->server_type == SILC_ROUTER ?
TRUE : FALSE, channel, client->id,
- SILC_ID_CLIENT_LEN, channel->topic);
+ channel->topic);
idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
silc_server_send_notify_invite(server, server->router->connection,
server->server_type == SILC_ROUTER ?
TRUE : FALSE, channel,
- sender->id, SILC_ID_CLIENT_LEN,
- add, del);
+ sender->id, add, del);
/* Send command reply */
tmp = silc_argument_get_arg_type(cmd->args, 1, &len);
/* Send KILLED notify to primary route */
if (!server->standalone)
silc_server_send_notify_killed(server, server->router->connection, TRUE,
- remote_client->id, SILC_ID_CLIENT_LEN,
- comment);
+ remote_client->id, comment);
/* Send KILLED notify to the client directly */
silc_server_send_notify_killed(server, remote_client->connection ?
remote_client->connection :
remote_client->router->connection, FALSE,
- remote_client->id, SILC_ID_CLIENT_LEN,
- comment);
+ remote_client->id, comment);
/* Remove the client from all channels. This generates new keys to the
channels as well. */
if (!id)
goto out;
- if (!SILC_ID_SERVER_COMPARE(id, server->id)) {
+ if (SILC_ID_SERVER_COMPARE(id, server->id)) {
/* Send our reply */
silc_server_command_send_status_reply(cmd, SILC_COMMAND_PING,
SILC_STATUS_OK);
if (!server->standalone)
silc_server_send_notify_join(server, server->router->connection,
server->server_type == SILC_ROUTER ?
- TRUE : FALSE, channel, client->id,
- SILC_ID_CLIENT_LEN);
+ TRUE : FALSE, channel, client->id);
}
silc_buffer_free(reply);
be same as the client's ID. */
if (cmd->sock->type == SILC_SOCKET_TYPE_CLIENT) {
SilcClientEntry entry = (SilcClientEntry)cmd->sock->user_data;
- if (SILC_ID_CLIENT_COMPARE(entry->id, client_id)) {
+ if (!SILC_ID_CLIENT_COMPARE(entry->id, client_id)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_JOIN,
SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
goto out;
/* Send UMODE change to primary router */
if (!server->standalone)
silc_server_send_notify_umode(server, server->router->connection, TRUE,
- client->id, SILC_ID_CLIENT_LEN,
- client->mode);
+ client->id, client->mode);
/* Send command reply to sender */
packet = silc_command_reply_payload_encode_va(SILC_COMMAND_UMODE,
server->server_type == SILC_ROUTER ?
TRUE : FALSE, channel,
mode_mask, client->id, SILC_ID_CLIENT,
- SILC_ID_CLIENT_LEN,
cipher, hmac);
/* Send command reply to sender */
server->server_type == SILC_ROUTER ?
TRUE : FALSE, channel,
target_mask, client->id,
- SILC_ID_CLIENT, SILC_ID_CLIENT_LEN,
- target_client->id,
- SILC_ID_CLIENT_LEN);
+ SILC_ID_CLIENT,
+ target_client->id);
}
/* Send command reply to sender */
silc_server_send_notify_kicked(server, server->router->connection,
server->server_type == SILC_ROUTER ?
TRUE : FALSE, channel,
- target_client->id, SILC_ID_CLIENT_LEN,
- comment);
+ target_client->id, comment);
if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
/* Re-generate channel key */
/* Send UMODE change to primary router */
if (!server->standalone)
silc_server_send_notify_umode(server, server->router->connection, TRUE,
- client->id, SILC_ID_CLIENT_LEN,
- client->mode);
+ client->id, client->mode);
/* Send reply to the sender */
silc_server_command_send_status_reply(cmd, SILC_COMMAND_OPER,
/* Send UMODE change to primary router */
if (!server->standalone)
silc_server_send_notify_umode(server, server->router->connection, TRUE,
- client->id, SILC_ID_CLIENT_LEN,
- client->mode);
+ client->id, client->mode);
/* Send reply to the sender */
silc_server_command_send_status_reply(cmd, SILC_COMMAND_SILCOPER,
if (!server->standalone)
silc_server_send_notify_leave(server, server->router->connection,
server->server_type == SILC_ROUTER ?
- TRUE : FALSE, channel, id_entry->id,
- SILC_ID_CLIENT_LEN);
+ TRUE : FALSE, channel, id_entry->id);
silc_server_command_send_status_reply(cmd, SILC_COMMAND_LEAVE,
SILC_STATUS_OK);
while (id_cache) {
client = (SilcClientEntry)id_cache->context;
- if (client && !SILC_ID_COMPARE_HASH(client->id, hash))
+ if (client && SILC_ID_COMPARE_HASH(client->id, hash))
break;
id_cache = NULL;
/* If the old ID Cache data was the hash value of the old Client ID
replace it with the hash of new Client ID */
- if (id_cache->data && !SILC_ID_COMPARE_HASH(old_id, id_cache->data)) {
+ if (id_cache->data && SILC_ID_COMPARE_HASH(old_id, id_cache->data)) {
silc_free(id_cache->data);
id_cache->data = silc_calloc(sizeof(new_id->hash), sizeof(unsigned char));
memcpy(id_cache->data, new_id->hash, sizeof(new_id->hash));
silc_server_send_notify_cumode(server, sock, FALSE, channel,
(mode & (~SILC_CHANNEL_UMODE_CHANFO)),
server->id, SILC_ID_SERVER,
- SILC_ID_SERVER_LEN,
- client->id, SILC_ID_CLIENT_LEN);
+ client->id);
silc_free(channel_id);
/* Change the mode back if we changed it */
if (packet->dst_id_type == SILC_ID_SERVER) {
/* For now this must be for us */
- if (SILC_ID_SERVER_COMPARE(packet->dst_id, server->id_string)) {
+ if (memcmp(packet->dst_id, server->id_string, packet->dst_id_len)) {
SILC_LOG_ERROR(("Cannot process command reply to unknown server"));
return;
}
if (packet->src_id_type == SILC_ID_CLIENT) {
silc_list_start(channel->user_list);
while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) {
- if (chl->client && !SILC_ID_CLIENT_COMPARE(chl->client->id, sender)) {
+ if (chl->client && SILC_ID_CLIENT_COMPARE(chl->client->id, sender)) {
sender_entry = chl->client;
break;
}
SilcBuffer reply;
SilcIDListData idata;
char *username = NULL, *realname = NULL, *id_string;
+ uint32 id_len;
int ret;
SILC_LOG_DEBUG(("Creating new client"));
client->username = username;
client->userinfo = realname ? realname : strdup(" ");
client->id = client_id;
+ id_len = silc_id_get_len(client_id, SILC_ID_CLIENT);
/* Update the cache entry */
cache->id = (void *)client_id;
silc_server_send_new_id(server, (SilcSocketConnection)
server->router->connection,
server->server_type == SILC_ROUTER ? TRUE : FALSE,
- client->id, SILC_ID_CLIENT, SILC_ID_CLIENT_LEN);
+ client->id, SILC_ID_CLIENT, id_len);
/* Send the new client ID to the client. */
id_string = silc_id_id2str(client->id, SILC_ID_CLIENT);
- reply = silc_buffer_alloc(2 + 2 + SILC_ID_CLIENT_LEN);
+ reply = silc_buffer_alloc(2 + 2 + id_len);
silc_buffer_pull_tail(reply, SILC_BUFFER_END(reply));
silc_buffer_format(reply,
SILC_STR_UI_SHORT(SILC_ID_CLIENT),
- SILC_STR_UI_SHORT(SILC_ID_CLIENT_LEN),
- SILC_STR_UI_XNSTRING(id_string, SILC_ID_CLIENT_LEN),
+ SILC_STR_UI_SHORT(id_len),
+ SILC_STR_UI_XNSTRING(id_string, id_len),
SILC_STR_END);
silc_server_packet_send(server, sock, SILC_PACKET_NEW_ID, 0,
reply->data, reply->len, FALSE);
server->router->connection != sock)
silc_server_send_new_id(server, server->router->connection,
TRUE, new_server->id, SILC_ID_SERVER,
- SILC_ID_SERVER_LEN);
+ silc_id_get_len(server_id, SILC_ID_SERVER));
if (server->server_type == SILC_ROUTER)
server->stat.cell_servers++;
case SILC_ID_SERVER:
/* If the ID is mine, ignore it. */
- if (!SILC_ID_SERVER_COMPARE(id, server->id)) {
+ if (SILC_ID_SERVER_COMPARE(id, server->id)) {
SILC_LOG_DEBUG(("Ignoring my own ID as new ID"));
break;
}
if (!channel->id)
channel_id = silc_id_dup(channel_id, SILC_ID_CHANNEL);
- if (SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
+ if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
/* They don't match, send CHANNEL_CHANGE notify to the server to
force the ID change. */
SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
silc_server_send_notify_channel_change(server, sock, FALSE,
- channel_id,
- channel->id,
- SILC_ID_CHANNEL_LEN);
+ channel_id, channel->id);
}
/* If the mode is different from what we have then enforce the
SILC_LOG_DEBUG(("Forcing the server to change channel mode"));
silc_server_send_notify_cmode(server, sock, FALSE, channel,
channel->mode, server->id,
- SILC_ID_SERVER, SILC_ID_SERVER_LEN,
+ SILC_ID_SERVER,
channel->cipher, channel->hmac_name);
}
if (dst_id) {
dst_id_data = silc_id_id2str(dst_id, dst_id_type);
- dst_id_len = silc_id_get_len(dst_id_type);
+ dst_id_len = silc_id_get_len(dst_id, dst_id_type);
}
/* Set the packet context pointers */
packetdata.type = type;
packetdata.flags = flags;
packetdata.src_id = silc_id_id2str(server->id, server->id_type);
- packetdata.src_id_len = SILC_ID_SERVER_LEN;
+ packetdata.src_id_len = silc_id_get_len(server->id, server->id_type);
packetdata.src_id_type = server->id_type;
packetdata.dst_id = dst_id_data;
packetdata.dst_id_len = dst_id_len;
if (dst_id) {
dst_id_data = silc_id_id2str(dst_id, dst_id_type);
- dst_id_len = silc_id_get_len(dst_id_type);
+ dst_id_len = silc_id_get_len(dst_id, dst_id_type);
}
if (src_id) {
src_id_data = silc_id_id2str(src_id, src_id_type);
- src_id_len = silc_id_get_len(src_id_type);
+ src_id_len = silc_id_get_len(src_id, src_id_type);
}
/* Set the packet context pointers */
/* If the packet is originated from our primary route we are
not allowed to send the packet. */
id = silc_id_str2id(packet->src_id, packet->src_id_len, packet->src_id_type);
- if (id && SILC_ID_SERVER_COMPARE(id, server->router->id)) {
+ if (id && !SILC_ID_SERVER_COMPARE(id, server->router->id)) {
idata = (SilcIDListData)sock->user_data;
silc_buffer_push(buffer, buffer->data - buffer->head);
packetdata.flags = 0;
packetdata.type = type;
packetdata.src_id = silc_id_id2str(server->id, SILC_ID_SERVER);
- packetdata.src_id_len = SILC_ID_SERVER_LEN;
+ packetdata.src_id_len = silc_id_get_len(server->id, SILC_ID_SERVER);
packetdata.src_id_type = SILC_ID_SERVER;
packetdata.dst_id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
packetdata.dst_id_len = SILC_ID_CHANNEL_LEN;
- packetdata.dst_id_type = SILC_ID_CHANNEL;
+ packetdata.dst_id_type = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
packetdata.src_id_len + packetdata.dst_id_len;
packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen);
packetdata.flags = 0;
packetdata.type = SILC_PACKET_CHANNEL_MESSAGE;
packetdata.src_id = silc_id_id2str(sender, sender_type);
- packetdata.src_id_len = silc_id_get_len(sender_type);
+ packetdata.src_id_len = silc_id_get_len(sender, sender_type);
packetdata.src_id_type = sender_type;
packetdata.dst_id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
packetdata.dst_id_len = SILC_ID_CHANNEL_LEN;
- packetdata.dst_id_type = SILC_ID_CHANNEL;
+ packetdata.dst_id_type = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
packetdata.padlen = SILC_PACKET_PADLEN((SILC_PACKET_HEADER_LEN +
packetdata.src_id_len +
packetdata.dst_id_len));
/* If sender is one on the channel do not send it the packet. */
if (!found && sender_type == SILC_ID_CLIENT &&
- !SILC_ID_CLIENT_COMPARE(client->id, sender)) {
+ SILC_ID_CLIENT_COMPARE(client->id, sender)) {
found = TRUE;
continue;
}
/* Sender maybe server as well so we want to make sure that
we won't send the message to the server it came from. */
- if (!found && !SILC_ID_SERVER_COMPARE(client->router->id, sender)) {
+ if (!found && SILC_ID_SERVER_COMPARE(client->router->id, sender)) {
found = TRUE;
continue;
}
SilcSocketConnection sock,
int broadcast,
SilcChannelID *old_id,
- SilcChannelID *new_id,
- uint32 id_len)
+ SilcChannelID *new_id)
{
SilcBuffer idp1, idp2;
SilcSocketConnection sock,
int broadcast,
SilcClientID *old_id,
- SilcClientID *new_id,
- uint32 id_len)
+ SilcClientID *new_id)
{
SilcBuffer idp1, idp2;
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
- SilcClientID *client_id,
- uint32 client_id_len)
+ SilcClientID *client_id)
{
SilcBuffer idp1, idp2;
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
- SilcClientID *client_id,
- uint32 client_id_len)
+ SilcClientID *client_id)
{
SilcBuffer idp;
SilcChannelEntry channel,
uint32 mode_mask,
void *id, SilcIdType id_type,
- uint32 id_len,
char *cipher, char *hmac)
{
SilcBuffer idp;
SilcChannelEntry channel,
uint32 mode_mask,
void *id, SilcIdType id_type,
- uint32 id_len,
- SilcClientID *target,
- uint32 target_len)
+ SilcClientID *target)
{
SilcBuffer idp1, idp2;
unsigned char mode[4];
SilcSocketConnection sock,
int broadcast,
SilcClientID *client_id,
- uint32 client_id_len,
char *message)
{
SilcBuffer idp;
int broadcast,
SilcChannelEntry channel,
SilcClientID *client_id,
- uint32 client_id_len,
char *topic)
{
SilcBuffer idp;
int broadcast,
SilcChannelEntry channel,
SilcClientID *client_id,
- uint32 client_id_len,
char *comment)
{
SilcBuffer idp;
SilcSocketConnection sock,
int broadcast,
SilcClientID *client_id,
- uint32 client_id_len,
char *comment)
{
SilcBuffer idp;
SilcSocketConnection sock,
int broadcast,
SilcClientID *client_id,
- uint32 client_id_len,
uint32 mode_mask)
{
SilcBuffer idp;
int broadcast,
SilcChannelEntry channel,
SilcClientID *client_id,
- uint32 client_id_len,
char *add, char *del)
{
SilcBuffer idp, idp2;
packetdata.flags = 0;
packetdata.type = SILC_PACKET_NOTIFY;
packetdata.src_id = silc_id_id2str(server->id, SILC_ID_SERVER);
- packetdata.src_id_len = SILC_ID_SERVER_LEN;
+ packetdata.src_id_len = silc_id_get_len(server->id, SILC_ID_SERVER);
packetdata.src_id_type = SILC_ID_SERVER;
silc_list_start(client->channels);
idata = (SilcIDListData)c->router;
packetdata.dst_id = silc_id_id2str(c->router->id, SILC_ID_SERVER);
- packetdata.dst_id_len = SILC_ID_SERVER_LEN;
+ packetdata.dst_id_len = silc_id_get_len(c->router->id, SILC_ID_SERVER);
packetdata.dst_id_type = SILC_ID_SERVER;
packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
packetdata.src_id_len + packetdata.dst_id_len;
idata = (SilcIDListData)c;
packetdata.dst_id = silc_id_id2str(c->id, SILC_ID_CLIENT);
- packetdata.dst_id_len = SILC_ID_CLIENT_LEN;
+ packetdata.dst_id_len = silc_id_get_len(c->id, SILC_ID_CLIENT);
packetdata.dst_id_type = SILC_ID_CLIENT;
packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
packetdata.src_id_len + packetdata.dst_id_len;
/* Encode channel key packet */
tmp_len = strlen(channel->channel_key->cipher->name);
- packet = silc_channel_key_payload_encode(SILC_ID_CHANNEL_LEN, chid, tmp_len,
+ packet = silc_channel_key_payload_encode(silc_id_get_len(channel->id,
+ SILC_ID_CHANNEL),
+ chid, tmp_len,
channel->channel_key->cipher->name,
channel->key_len / 8, channel->key);
SilcSocketConnection sock,
int broadcast,
SilcChannelID *old_id,
- SilcChannelID *new_id,
- uint32 id_len);
+ SilcChannelID *new_id);
void silc_server_send_notify_nick_change(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcClientID *old_id,
- SilcClientID *new_id,
- uint32 id_len);
+ SilcClientID *new_id);
void silc_server_send_notify_join(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
- SilcClientID *client_id,
- uint32 client_id_len);
+ SilcClientID *client_id);
void silc_server_send_notify_leave(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
- SilcClientID *client_id,
- uint32 client_id_len);
+ SilcClientID *client_id);
void silc_server_send_notify_cmode(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
uint32 mode_mask,
void *id, SilcIdType id_type,
- uint32 id_len,
char *cipher, char *hmac);
void silc_server_send_notify_cumode(SilcServer server,
SilcSocketConnection sock,
SilcChannelEntry channel,
uint32 mode_mask,
void *id, SilcIdType id_type,
- uint32 id_len,
- SilcClientID *target,
- uint32 target_len);
+ SilcClientID *target);
void silc_server_send_notify_signoff(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcClientID *client_id,
- uint32 client_id_len,
char *message);
void silc_server_send_notify_topic_set(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
SilcClientID *client_id,
- uint32 client_id_len,
char *topic);
void silc_server_send_notify_kicked(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
SilcClientID *client_id,
- uint32 client_id_len,
char *comment);
void silc_server_send_notify_killed(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcClientID *client_id,
- uint32 client_id_len,
char *comment);
void silc_server_send_notify_umode(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcClientID *client_id,
- uint32 client_id_len,
uint32 mode_mask);
void silc_server_send_notify_ban(SilcServer server,
SilcSocketConnection sock,
int broadcast,
SilcChannelEntry channel,
SilcClientID *client_id,
- uint32 client_id_len,
char *add, char *del);
void silc_server_send_notify_dest(SilcServer server,
SilcSocketConnection sock,
SilcIdType id_type)
{
if (server->server_type == SILC_ROUTER) {
- uint32 dest;
- uint16 port;
+ uint32 dest = 0;
+ uint16 port = 0;
SilcServerEntry router = NULL;
+#if 0
switch(id_type) {
case SILC_ID_CLIENT:
return NULL;
}
+#endif
+
router = silc_server_route_check(dest, port);
if (!router)
return (SilcSocketConnection)server->id_entry->router->connection;
server->id = id;
server->id_string = silc_id_id2str(id, SILC_ID_SERVER);
- server->id_string_len = silc_id_get_len(SILC_ID_SERVER);
+ server->id_string_len = silc_id_get_len(id, SILC_ID_SERVER);
server->id_type = SILC_ID_SERVER;
server->server_name = server->config->server_info->server_name;
SilcBuffer packet;
SilcServerHBContext hb_context;
unsigned char *id_string;
+ uint32 id_len;
SilcIDListData idata;
SILC_LOG_DEBUG(("Start"));
/* Send NEW_SERVER packet to the router. We will become registered
to the SILC network after sending this packet. */
id_string = silc_id_id2str(server->id, SILC_ID_SERVER);
- packet = silc_buffer_alloc(2 + 2 + SILC_ID_SERVER_LEN +
- strlen(server->server_name));
+ id_len = silc_id_get_len(server->id, SILC_ID_SERVER);
+ packet = silc_buffer_alloc(2 + 2 + id_len + strlen(server->server_name));
silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
silc_buffer_format(packet,
- SILC_STR_UI_SHORT(SILC_ID_SERVER_LEN),
- SILC_STR_UI_XNSTRING(id_string, SILC_ID_SERVER_LEN),
+ SILC_STR_UI_SHORT(id_len),
+ SILC_STR_UI_XNSTRING(id_string, id_len),
SILC_STR_UI_SHORT(strlen(server->server_name)),
SILC_STR_UI_XNSTRING(server->server_name,
strlen(server->server_name)),
if (client && client->id) {
void *id = silc_id_str2id(packet->src_id, packet->src_id_len,
packet->src_id_type);
- if (!id || SILC_ID_CLIENT_COMPARE(client->id, id)) {
+ if (!id || !SILC_ID_CLIENT_COMPARE(client->id, id)) {
silc_free(id);
goto out;
}
if (!(packet->flags & SILC_PACKET_FLAG_BROADCAST) &&
packet->dst_id_type == SILC_ID_SERVER &&
sock->type != SILC_SOCKET_TYPE_CLIENT &&
- SILC_ID_SERVER_COMPARE(packet->dst_id, server->id_string)) {
+ memcmp(packet->dst_id, server->id_string, packet->dst_id_len)) {
/* Route the packet to fastest route for the destination ID */
void *id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
if (notify && !server->standalone && server->router)
silc_server_send_notify_signoff(server, server->router->connection,
server->server_type == SILC_SERVER ?
- FALSE : TRUE, client->id,
- SILC_ID_CLIENT_LEN, signoff);
+ FALSE : TRUE, client->id, signoff);
/* Remove client from all channels */
if (notify)
to our primary route. */
if (broadcast && server->standalone == FALSE)
silc_server_send_new_channel(server, server->router->connection, TRUE,
- channel_name, entry->id, SILC_ID_CHANNEL_LEN,
+ channel_name, entry->id,
+ silc_id_get_len(entry->id, SILC_ID_CHANNEL),
entry->mode);
server->stat.my_channels++;
to our primary route. */
if (broadcast && server->standalone == FALSE)
silc_server_send_new_channel(server, server->router->connection, TRUE,
- channel_name, entry->id, SILC_ID_CHANNEL_LEN,
+ channel_name, entry->id,
+ silc_id_get_len(entry->id, SILC_ID_CHANNEL),
entry->mode);
server->stat.my_channels++;
SilcIDCacheEntry id_cache;
SilcChannelEntry channel;
unsigned char *cid;
+ uint32 id_len;
uint16 name_len;
int len;
channel = (SilcChannelEntry)id_cache->context;
cid = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
+ id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
name_len = strlen(channel->channel_name);
- len = 4 + name_len + SILC_ID_CHANNEL_LEN + 4;
+ len = 4 + name_len + id_len + 4;
*channels =
silc_buffer_realloc(*channels,
(*channels ? (*channels)->truelen + len : len));
SILC_STR_UI_SHORT(name_len),
SILC_STR_UI_XNSTRING(channel->channel_name,
name_len),
- SILC_STR_UI_SHORT(SILC_ID_CHANNEL_LEN),
- SILC_STR_UI_XNSTRING(cid, SILC_ID_CHANNEL_LEN),
+ SILC_STR_UI_SHORT(id_len),
+ SILC_STR_UI_XNSTRING(cid, id_len),
SILC_STR_UI_INT(channel->mode),
SILC_STR_END);
silc_buffer_pull(*channels, len);
SilcBuffer idp;
uint32 list_count = 0;
+ /* XXX rewrite - this does not support IPv6 based Client ID's. */
+
client_id_list = silc_buffer_alloc((SILC_ID_CLIENT_LEN + 4) *
silc_list_count(channel->user_list));
client_mode_list = silc_buffer_alloc(4 *
SILC_GET32_MSB(mode, mode_list->data);
silc_buffer_pull(mode_list, 4);
- if (noadd && !SILC_ID_CLIENT_COMPARE(client_id, noadd)) {
+ if (noadd && SILC_ID_CLIENT_COMPARE(client_id, noadd)) {
silc_free(client_id);
continue;
}
SilcChannelEntry channel;
SilcChannelClientEntry chl;
unsigned char *cid;
+ uint32 id_len;
uint16 name_len;
int len;
continue;
cid = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
+ id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
name_len = strlen(channel->channel_name);
- len = 4 + name_len + SILC_ID_CHANNEL_LEN + 4;
+ len = 4 + name_len + id_len + 4;
buffer = silc_buffer_realloc(buffer,
(buffer ? (buffer)->truelen + len : len));
silc_buffer_pull_tail(buffer, ((buffer)->end - (buffer)->data));
SILC_STR_UI_SHORT(name_len),
SILC_STR_UI_XNSTRING(channel->channel_name,
name_len),
- SILC_STR_UI_SHORT(SILC_ID_CHANNEL_LEN),
- SILC_STR_UI_XNSTRING(cid, SILC_ID_CHANNEL_LEN),
+ SILC_STR_UI_SHORT(id_len),
+ SILC_STR_UI_XNSTRING(cid, id_len),
SILC_STR_UI_INT(chl->mode), /* Client's mode */
SILC_STR_END);
silc_buffer_pull(buffer, len);
}
/* Create the ID */
- (*new_id)->ip = server.sin_addr;
+ SILC_PUT32_MSB(server.sin_addr.s_addr, (*new_id)->ip.data);
+ (*new_id)->ip.data_len = 4;
(*new_id)->port = server.sin_port;
(*new_id)->rnd = silc_rng_get_rn16(rng);
silc_hash_make(md5hash, nickname, strlen(nickname), hash);
/* Create the ID */
- (*new_id)->ip.s_addr = server_id->ip.s_addr;
+ memcpy((*new_id)->ip.data, server_id->ip.data, server_id->ip.data_len);
+ (*new_id)->ip.data_len = server_id->ip.data_len;
(*new_id)->rnd = silc_rng_get_byte(rng);
memcpy((*new_id)->hash, hash, CLIENTID_HASH_LEN);
*new_id = silc_calloc(1, sizeof(**new_id));
/* Create the ID */
- (*new_id)->ip.s_addr = router_id->ip.s_addr;
+ memcpy((*new_id)->ip.data, router_id->ip.data, router_id->ip.data_len);
+ (*new_id)->ip.data_len = router_id->ip.data_len;
(*new_id)->port = router_id->port;
(*new_id)->rnd = silc_rng_get_rn16(rng);
/* Save remote ID. */
conn->remote_id = ctx->dest_id;
conn->remote_id_data = silc_id_id2str(ctx->dest_id, SILC_ID_SERVER);
- conn->remote_id_data_len = SILC_ID_SERVER_LEN;
+ conn->remote_id_data_len = silc_id_get_len(ctx->dest_id, SILC_ID_SERVER);
/* Register re-key timeout */
conn->rekey->timeout = 3600; /* XXX hardcoded */
packetdata.flags = 0;
packetdata.type = type;
if (sock->user_data &&
- ((SilcClientConnection)sock->user_data)->local_id_data)
+ ((SilcClientConnection)sock->user_data)->local_id_data) {
packetdata.src_id = ((SilcClientConnection)sock->user_data)->local_id_data;
- else
+ packetdata.src_id_len =
+ silc_id_get_len(((SilcClientConnection)sock->user_data)->local_id,
+ SILC_ID_CLIENT);
+ } else {
packetdata.src_id = silc_calloc(SILC_ID_CLIENT_LEN, sizeof(unsigned char));
- packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+ packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+ }
packetdata.src_id_type = SILC_ID_CLIENT;
if (dst_id) {
packetdata.dst_id = silc_id_id2str(dst_id, dst_id_type);
- packetdata.dst_id_len = silc_id_get_len(dst_id_type);
+ packetdata.dst_id_len = silc_id_get_len(dst_id, dst_id_type);
packetdata.dst_id_type = dst_id_type;
} else {
packetdata.dst_id = NULL;
packetdata.flags = 0;
packetdata.type = type;
if (sock->user_data &&
- ((SilcClientConnection)sock->user_data)->local_id_data)
+ ((SilcClientConnection)sock->user_data)->local_id_data) {
packetdata.src_id = ((SilcClientConnection)sock->user_data)->local_id_data;
- else
+ packetdata.src_id_len =
+ silc_id_get_len(((SilcClientConnection)sock->user_data)->local_id,
+ SILC_ID_CLIENT);
+ } else {
packetdata.src_id = silc_calloc(SILC_ID_CLIENT_LEN, sizeof(unsigned char));
- packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+ packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+ }
packetdata.src_id_type = SILC_ID_CLIENT;
if (dst_id) {
packetdata.dst_id = silc_id_id2str(dst_id, dst_id_type);
- packetdata.dst_id_len = silc_id_get_len(dst_id_type);
+ packetdata.dst_id_len = silc_id_get_len(dst_id, dst_id_type);
packetdata.dst_id_type = dst_id_type;
} else {
packetdata.dst_id = NULL;
packetdata.flags = 0;
packetdata.type = SILC_PACKET_CHANNEL_MESSAGE;
packetdata.src_id = conn->local_id_data;
- packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+ packetdata.src_id_len = silc_id_get_len(conn->local_id, SILC_ID_CLIENT);
packetdata.src_id_type = SILC_ID_CLIENT;
packetdata.dst_id = id_string;
- packetdata.dst_id_len = SILC_ID_CHANNEL_LEN;
+ packetdata.dst_id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
packetdata.dst_id_type = SILC_ID_CHANNEL;
packetdata.truelen = payload->len + SILC_PACKET_HEADER_LEN +
packetdata.src_id_len + packetdata.dst_id_len;
/* Find client entry */
silc_list_start(channel->clients);
while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
- if (!SILC_ID_CLIENT_COMPARE(chu->client->id, client_id)) {
+ if (SILC_ID_CLIENT_COMPARE(chu->client->id, client_id)) {
found = TRUE;
break;
}
goto out;
/* Ignore my ID */
- if (!SILC_ID_CLIENT_COMPARE(client_id, conn->local_id))
+ if (SILC_ID_CLIENT_COMPARE(client_id, conn->local_id))
break;
/* Find old Client entry */
packetdata.flags = SILC_PACKET_FLAG_PRIVMSG_KEY;
packetdata.type = SILC_PACKET_PRIVATE_MESSAGE;
packetdata.src_id = conn->local_id_data;
- packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+ packetdata.src_id_len = silc_id_get_len(conn->local_id, SILC_ID_CLIENT);
packetdata.src_id_type = SILC_ID_CLIENT;
packetdata.dst_id = silc_id_id2str(client_entry->id, SILC_ID_CLIENT);
- packetdata.dst_id_len = SILC_ID_CLIENT_LEN;
+ packetdata.dst_id_len = silc_id_get_len(client_entry->id, SILC_ID_CLIENT);
packetdata.dst_id_type = SILC_ID_CLIENT;
packetdata.truelen = buffer->len + SILC_PACKET_HEADER_LEN +
packetdata.src_id_len + packetdata.dst_id_len;
sender with the set away message. */
if (conn->away && conn->away->away) {
/* If it's me, ignore */
- if (!SILC_ID_CLIENT_COMPARE(remote_id, conn->local_id))
+ if (SILC_ID_CLIENT_COMPARE(remote_id, conn->local_id))
goto out;
/* Send the away message */
/* Send the command */
buffer = silc_command_payload_encode_va(SILC_COMMAND_PING, 0, 1,
1, conn->remote_id_data,
- SILC_ID_SERVER_LEN);
+ silc_id_get_len(conn->remote_id,
+ SILC_ID_SERVER));
silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
0, NULL, NULL, buffer->data, buffer->len, TRUE);
silc_buffer_free(buffer);
}
for (i = 0; i < conn->ping_count; i++) {
- if (!SILC_ID_SERVER_COMPARE(conn->ping[i].dest_id, id)) {
+ if (SILC_ID_SERVER_COMPARE(conn->ping[i].dest_id, id)) {
diff = curtime - conn->ping[i].start_time;
cmd->client->ops->say(cmd->client, conn,
"Ping reply from %s: %d second%s",
Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* $Id$ */
#include "silcincludes.h"
+#include "id.h"
+
+/* ID lengths (in bytes) without the IP address part */
+#define ID_SERVER_LEN_PART 4
+#define ID_CLIENT_LEN_PART CLIENTID_HASH_LEN + 1
+#define ID_CHANNEL_LEN_PART 4
/* Converts ID to string. */
SilcServerID *server_id;
SilcClientID *client_id;
SilcChannelID *channel_id;
+ uint32 id_len = silc_id_get_len(id, type);
switch(type) {
case SILC_ID_SERVER:
server_id = (SilcServerID *)id;
- ret_id = silc_calloc(8, sizeof(unsigned char));
- SILC_PUT32_MSB(server_id->ip.s_addr, ret_id);
+ ret_id = silc_calloc(id_len, sizeof(unsigned char));
+ memcpy(ret_id, server_id->ip.data, server_id->ip.data_len);
SILC_PUT16_MSB(server_id->port, &ret_id[4]);
SILC_PUT16_MSB(server_id->rnd, &ret_id[6]);
return ret_id;
break;
case SILC_ID_CLIENT:
client_id = (SilcClientID *)id;
- ret_id = silc_calloc(16, sizeof(unsigned char));
- SILC_PUT32_MSB(client_id->ip.s_addr, ret_id);
+ ret_id = silc_calloc(id_len, sizeof(unsigned char));
+ memcpy(ret_id, client_id->ip.data, client_id->ip.data_len);
ret_id[4] = client_id->rnd;
memcpy(&ret_id[5], client_id->hash, CLIENTID_HASH_LEN);
return ret_id;
break;
case SILC_ID_CHANNEL:
channel_id = (SilcChannelID *)id;
- ret_id = silc_calloc(8, sizeof(unsigned char));
- SILC_PUT32_MSB(channel_id->ip.s_addr, ret_id);
+ ret_id = silc_calloc(id_len, sizeof(unsigned char));
+ memcpy(ret_id, channel_id->ip.data, channel_id->ip.data_len);
SILC_PUT16_MSB(channel_id->port, &ret_id[4]);
SILC_PUT16_MSB(channel_id->rnd, &ret_id[6]);
return ret_id;
{
SilcServerID *server_id;
- if (id_len != SILC_ID_SERVER_LEN)
+ if (id_len != ID_SERVER_LEN_PART + 4 &&
+ id_len != ID_SERVER_LEN_PART + 16)
return NULL;
server_id = silc_calloc(1, sizeof(*server_id));
- SILC_GET32_MSB(server_id->ip.s_addr, id);
+ memcpy(server_id->ip.data, id, (id_len > ID_SERVER_LEN_PART + 4 ?
+ 16 : 4));
+ server_id->ip.data_len = (id_len > ID_SERVER_LEN_PART + 4 ? 16 : 4);
SILC_GET16_MSB(server_id->port, &id[4]);
SILC_GET16_MSB(server_id->rnd, &id[6]);
return server_id;
{
SilcClientID *client_id;
- if (id_len != SILC_ID_CLIENT_LEN)
+ if (id_len != ID_CLIENT_LEN_PART + 4 &&
+ id_len != ID_CLIENT_LEN_PART + 16)
return NULL;
client_id = silc_calloc(1, sizeof(*client_id));
- SILC_GET32_MSB(client_id->ip.s_addr, id);
+ memcpy(client_id->ip.data, id, (id_len > ID_CLIENT_LEN_PART + 4 ?
+ 16 : 4));
+ client_id->ip.data_len = (id_len > ID_CLIENT_LEN_PART + 4 ? 16 : 4);
client_id->rnd = id[4];
memcpy(client_id->hash, &id[5], CLIENTID_HASH_LEN);
return client_id;
{
SilcChannelID *channel_id;
- if (id_len != SILC_ID_CHANNEL_LEN)
+ if (id_len != ID_CHANNEL_LEN_PART + 4 &&
+ id_len != ID_CHANNEL_LEN_PART + 16)
return NULL;
channel_id = silc_calloc(1, sizeof(*channel_id));
- SILC_GET32_MSB(channel_id->ip.s_addr, id);
+ memcpy(channel_id->ip.data, id, (id_len > ID_CHANNEL_LEN_PART + 4 ?
+ 16 : 4));
+ channel_id->ip.data_len = (id_len > ID_CHANNEL_LEN_PART + 4 ? 16 : 4);
SILC_GET16_MSB(channel_id->port, &id[4]);
SILC_GET16_MSB(channel_id->rnd, &id[6]);
return channel_id;
/* Returns length of the ID */
-uint32 silc_id_get_len(SilcIdType type)
+uint32 silc_id_get_len(void *id, SilcIdType type)
{
switch(type) {
case SILC_ID_SERVER:
- return SILC_ID_SERVER_LEN;
+ {
+ SilcServerID *server_id = (SilcServerID *)id;
+ return ID_SERVER_LEN_PART + server_id->ip.data_len;
+ }
break;
case SILC_ID_CLIENT:
- return SILC_ID_CLIENT_LEN;
+ {
+ SilcClientID *client_id = (SilcClientID *)id;
+ return ID_CLIENT_LEN_PART + client_id->ip.data_len;
+ }
break;
case SILC_ID_CHANNEL:
- return SILC_ID_CHANNEL_LEN;
+ {
+ SilcChannelID *channel_id = (SilcChannelID *)id;
+ return ID_CHANNEL_LEN_PART + channel_id->ip.data_len;
+ }
break;
}
void *silc_id_dup(void *id, SilcIdType type)
{
- int len = silc_id_get_len(type);
- void *new = silc_calloc(1, len);
- memcpy(new, id, len);
- return new;
+ switch(type) {
+ case SILC_ID_SERVER:
+ {
+ 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;
+ return new;
+ }
+ break;
+ case SILC_ID_CLIENT:
+ {
+ 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);
+ return new;
+ }
+ break;
+ case SILC_ID_CHANNEL:
+ {
+ 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;
+ 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;
}
packet sending and reception. However, client never creates these
but it receives the correct ID's from server. Clients, servers and
channels are identified by the these ID's.
-
- Note that these are currently IPv4 specific, although adding IPv6
- support is not a bad task and SILC protocol already supports IPv6.
*/
#ifndef ID_H
#define ID_H
-#define SILC_ID_SERVER_LEN (64 / 8)
-#define SILC_ID_CLIENT_LEN (128 / 8)
-#define SILC_ID_CHANNEL_LEN (64 / 8)
-#define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */
-
-/* SILC ID Types */
+/* The SILC ID Types */
#define SILC_ID_NONE 0
#define SILC_ID_SERVER 1
#define SILC_ID_CLIENT 2
/* Type definition for the ID types. */
typedef uint16 SilcIdType;
+/* The ID Lenghts. These are IPv4 based and should be noted if used directly
+ that these cannot be used with IPv6. */
+#define SILC_ID_SERVER_LEN (64 / 8)
+#define SILC_ID_CLIENT_LEN (128 / 8)
+#define SILC_ID_CHANNEL_LEN (64 / 8)
+
+#define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */
+
+/*
+ SILC ID IP structure.
+
+ Generic IP address structure to indicate either IPv4 or IPv6 address.
+ This structure is used inside all SILC ID's. The true length of the
+ ID depends of the length of the IP address.
+*/
+typedef struct {
+ unsigned char data[16]; /* IP data */
+ uint8 data_len; /* Length of the data (4 or 16) */
+} SilcIDIP;
+
/*
- 64 bit SilcServerID structure:
+ 64 or 160 bit SilcServerID structure:
- 32 bit IP address
+ n bit IP address
16 bit port
16 bit random number
*/
typedef struct {
- struct in_addr ip; /* 32 bit IP */
- uint16 port; /* 16 bit port */
- uint16 rnd; /* 16 bit random number */
+ SilcIDIP ip; /* n bit IP address */
+ uint16 port; /* 16 bit port */
+ uint16 rnd; /* 16 bit random number */
} SilcServerID;
/*
- 128 bit SilcClientID structure:
+ 128 or 224 bit SilcClientID structure:
- 32 bit ServerID IP address [bits 1-32]
+ n bit ServerID IP address [bits 1-32 or bits 1-128]
8 bit random number
88 bit hash value from nickname
*/
typedef struct {
- struct in_addr ip; /* 32 bit IP */
+ SilcIDIP ip; /* n bit IP address */
unsigned char rnd; /* 8 bit random number */
unsigned char hash[CLIENTID_HASH_LEN]; /* 88 bit MD5 hash */
} SilcClientID;
/*
- 64 bit SilcChannel ID structure:
+ 64 or 160 bit SilcChannel ID structure:
- 32 bit Router's ServerID IP address [bits 1-32]
- 16 bit Router's ServerID port [bits 33-48]
+ n bit Router's ServerID IP address [bits 1-32 or bits 1-128]
+ 16 bit Router's ServerID port [bits 33-48 or bits 129-144]
16 bit random number
*/
typedef struct {
- struct in_addr ip; /* 32 bit IP */
- uint16 port; /* 16 bit port */
- uint16 rnd; /* 16 bit random number */
+ SilcIDIP ip; /* n bit IP address */
+ uint16 port; /* 16 bit port */
+ uint16 rnd; /* 16 bit random number */
} SilcChannelID;
/* Macros */
-/* Compares two ID's */
-#define SILC_ID_COMPARE(id1, id2, len) (memcmp(id1, id2, len))
-
-/* Compares Channel ID's */
-#define SILC_ID_CHANNEL_COMPARE(id1, id2) \
- SILC_ID_COMPARE(id1, id2, SILC_ID_CHANNEL_LEN)
-
/* Compares Client ID's */
-#define SILC_ID_CLIENT_COMPARE(id1, id2) \
- SILC_ID_COMPARE(id1, id2, SILC_ID_CLIENT_LEN)
+#define SILC_ID_CLIENT_COMPARE(id1, id2) \
+ silc_id_compare(id1, id2, SILC_ID_CLIENT)
/* Compares Server ID's */
-#define SILC_ID_SERVER_COMPARE(id1, id2) \
- SILC_ID_COMPARE(id1, id2, SILC_ID_SERVER_LEN)
+#define SILC_ID_SERVER_COMPARE(id1, id2) \
+ silc_id_compare(id1, id2, SILC_ID_SERVER)
/* Compares Channel ID's */
-#define SILC_ID_CHANNEL_COMPARE(id1, id2) \
- SILC_ID_COMPARE(id1, id2, SILC_ID_CHANNEL_LEN)
-
-/* Compares IP addresses from the ID's. */
-#define SILC_ID_COMPARE_IP(id1, id2) \
- SILC_ID_COMPARE(id1, id2, 4)
+#define SILC_ID_CHANNEL_COMPARE(id1, id2) \
+ silc_id_compare(id1, id2, SILC_ID_CHANNEL)
/* Compare nickname hash from Client ID */
#define SILC_ID_COMPARE_HASH(id, _hash) \
/* 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(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
int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type,
SilcIDCacheList *ret)
{
- int i, id_len;
+ int i;
SilcIDCacheList list;
if (!cache || !cache->cache || !id)
return FALSE;
- id_len = silc_id_get_len(type);
-
list = silc_idcache_list_alloc();
if (id != SILC_ID_CACHE_ANY) {
for (i = 0; i < cache->cache_count; i++)
- if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len))
+ if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type))
silc_idcache_list_add(list, &(cache->cache[i]));
} else {
for (i = 0; i < cache->cache_count; i++)
int silc_idcache_find_by_id_one(SilcIDCache cache, void *id, SilcIdType type,
SilcIDCacheEntry *ret)
{
- int i, id_len;
+ int i;
if (!cache || !cache->cache || !id)
return FALSE;
- id_len = silc_id_get_len(type);
-
for (i = 0; i < cache->cache_count; i++)
- if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) {
+ if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) {
if (ret)
*ret = &(cache->cache[i]);
return TRUE;
int silc_idcache_del_by_id(SilcIDCache cache, SilcIdType type, void *id)
{
- int i, id_len;
+ int i;
if (!cache || !cache->cache || !id)
return FALSE;
- id_len = silc_id_get_len(type);
-
for (i = 0; i < cache->cache_count; i++)
- if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) {
+ if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) {
cache->cache[i].id = NULL;
cache->cache[i].data = NULL;
cache->cache[i].type = 0;
silc_free(pk);
return NULL;
}
- id_len = silc_id_get_len(type);
+ id_len = silc_id_get_len(id, type);
buf = silc_buffer_alloc(random_len + id_len + pk_len);
silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf));
type == SILC_ID_SERVER ? "Server" : "Channel"));
id_data = silc_id_id2str(id, type);
- len = silc_id_get_len(type);
+ len = silc_id_get_len(id, type);
buffer = silc_buffer_alloc(4 + len);
silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
case SILC_ID_SERVER:
{
SilcServerID *server_id = (SilcServerID *)id;
- strcat(rid, inet_ntoa(server_id->ip));
+ struct in_addr ipv4;
+
+ if (server_id->ip.data_len > 4) {
+
+ } else {
+ SILC_GET32_MSB(ipv4.s_addr, server_id->ip.data);
+ strcat(rid, inet_ntoa(ipv4));
+ }
+
memset(tmp, 0, sizeof(tmp));
snprintf(tmp, sizeof(tmp), ",%d,", ntohs(server_id->port));
strcat(rid, tmp);
case SILC_ID_CLIENT:
{
SilcClientID *client_id = (SilcClientID *)id;
- strcat(rid, inet_ntoa(client_id->ip));
+ struct in_addr ipv4;
+
+ if (client_id->ip.data_len > 4) {
+
+ } else {
+ SILC_GET32_MSB(ipv4.s_addr, client_id->ip.data);
+ strcat(rid, inet_ntoa(ipv4));
+ }
+
memset(tmp, 0, sizeof(tmp));
snprintf(tmp, sizeof(tmp), ",%02x,", client_id->rnd);
strcat(rid, tmp);
case SILC_ID_CHANNEL:
{
SilcChannelID *channel_id = (SilcChannelID *)id;
- strcat(rid, inet_ntoa(channel_id->ip));
+ struct in_addr ipv4;
+
+ if (channel_id->ip.data_len > 4) {
+
+ } else {
+ SILC_GET32_MSB(ipv4.s_addr, channel_id->ip.data);
+ strcat(rid, inet_ntoa(ipv4));
+ }
+
memset(tmp, 0, sizeof(tmp));
snprintf(tmp, sizeof(tmp), ",%d,", ntohs(channel_id->port));
strcat(rid, tmp);
# temporary files (including these prepare* scripts) are removed.
#
-SILC_VERSION=0.2.1
+SILC_VERSION=0.2.2
version=$1
if test "$version" = ""; then