conn = silc_calloc(1, sizeof(*conn));
/* Initialize ID caches */
- conn->client_cache = silc_idcache_alloc(0, NULL);
- conn->channel_cache = silc_idcache_alloc(0, NULL);
- conn->server_cache = silc_idcache_alloc(0, NULL);
+ conn->client_cache = silc_idcache_alloc(0, SILC_ID_CLIENT, NULL);
+ conn->channel_cache = silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL);
+ conn->server_cache = silc_idcache_alloc(0, SILC_ID_SERVER, NULL);
conn->client = client;
conn->remote_host = strdup(hostname);
conn->remote_port = port;
if (!client->sockets) {
client->sockets = silc_calloc(1, sizeof(*client->sockets));
- client->sockets[0] = sock;
+ client->sockets[0] = silc_socket_dup(sock);
client->sockets_count = 1;
return;
}
for (i = 0; i < client->sockets_count; i++) {
if (client->sockets[i] == NULL) {
- client->sockets[i] = sock;
+ client->sockets[i] = silc_socket_dup(sock);
return;
}
}
client->sockets = silc_realloc(client->sockets, sizeof(*client->sockets) *
(client->sockets_count + 1));
- client->sockets[client->sockets_count] = sock;
+ client->sockets[client->sockets_count] = silc_socket_dup(sock);
client->sockets_count++;
}
for (i = 0; i < client->sockets_count; i++) {
if (client->sockets[i] == sock) {
+ silc_socket_free(sock);
client->sockets[i] = NULL;
return;
}
protocol as context. */
proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
proto_ctx->client = (void *)client;
- proto_ctx->sock = conn->sock;
+ proto_ctx->sock = silc_socket_dup(conn->sock);
proto_ctx->rng = client->rng;
proto_ctx->responder = FALSE;
proto_ctx->send_packet = silc_client_protocol_ke_send_packet;
if (ctx->dest_id)
silc_free(ctx->dest_id);
ctx->sock->protocol = NULL;
+ silc_socket_free(ctx->sock);
/* Notify application of failure */
client->ops->connect(client, ctx->sock->user_data, FALSE);
if (ctx->dest_id)
silc_free(ctx->dest_id);
conn->sock->protocol = NULL;
+ silc_socket_free(ctx->sock);
/* Notify application of failure */
client->ops->connect(client, ctx->sock->user_data, FALSE);
/* 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 */
silc_free(ctx->auth_data);
if (ctx->ske)
silc_ske_free(ctx->ske);
+ silc_socket_free(ctx->sock);
silc_free(ctx);
conn->sock->protocol = 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 = 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;
connecting = TRUE;
/* Delete old ID from ID cache */
- silc_idcache_del_by_id(conn->client_cache, SILC_ID_CLIENT, conn->local_id);
+ if (conn->local_id) {
+ silc_idcache_del_by_context(conn->client_cache, conn->local_entry);
+ silc_free(conn->local_id);
+ }
/* Save the new ID */
- if (conn->local_id)
- silc_free(conn->local_id);
+
if (conn->local_id_data)
silc_free(conn->local_id_data);
conn->local_entry->id = conn->local_id;
/* Put it to the ID cache */
- silc_idcache_add(conn->client_cache, conn->nickname, strlen(conn->nickname),
- SILC_ID_CLIENT, conn->local_id, (void *)conn->local_entry,
- TRUE, FALSE);
+ silc_idcache_add(conn->client_cache, conn->nickname, conn->local_id,
+ (void *)conn->local_entry, FALSE);
/* Notify application of successful connection. We do it here now that
we've received the Client ID and are allowed to send traffic. */
conn->current_channel = channel;
/* Put it to the ID cache */
- silc_idcache_add(conn->channel_cache, channel_name, strlen(channel_name),
- SILC_ID_CHANNEL, (void *)channel->id, (void *)channel,
- TRUE, FALSE);
+ silc_idcache_add(conn->channel_cache, channel_name, (void *)channel->id,
+ (void *)channel, FALSE);
return channel;
}
SilcChannelEntry channel;
SilcChannelUser chu;
- if (!silc_idcache_find_by_id(conn->channel_cache, SILC_ID_CACHE_ANY,
- SILC_ID_CHANNEL, &list))
+ if (!silc_idcache_get_all(conn->channel_cache, &list))
return;
silc_idcache_list_first(list, &id_cache);
SilcChannelEntry channel;
SilcChannelUser chu;
- if (!silc_idcache_find_by_id(conn->channel_cache, SILC_ID_CACHE_ANY,
- SILC_ID_CHANNEL, &list))
+ if (!silc_idcache_get_all(conn->channel_cache, &list))
return;
silc_idcache_list_first(list, &id_cache);
to the protocol. */
proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
proto_ctx->client = (void *)client;
- proto_ctx->sock = sock;
+ proto_ctx->sock = silc_socket_dup(sock);
proto_ctx->responder = FALSE;
proto_ctx->pfs = conn->rekey->pfs;
silc_packet_context_free(ctx->packet);
if (ctx->ske)
silc_ske_free(ctx->ske);
+ silc_socket_free(ctx->sock);
silc_free(ctx);
return;
}
-#if 0
- /* Take the keys into use */
- if (ctx->pfs == TRUE)
- silc_client_protocol_rekey_generate_pfs(client, ctx);
- else
- silc_client_protocol_rekey_generate(client, ctx);
-#endif
-
/* Cleanup */
silc_protocol_free(protocol);
sock->protocol = NULL;
silc_packet_context_free(ctx->packet);
if (ctx->ske)
silc_ske_free(ctx->ske);
+ silc_socket_free(ctx->sock);
silc_free(ctx);
}