- SilcClientConnection conn = (SilcClientConnection)sock->user_data;
- int connecting = FALSE;
- SilcClientID *client_id = silc_id_payload_get_id(idp);
- SilcBuffer sidp;
-
- if (!conn->local_entry)
- connecting = TRUE;
-
- /* Delete old ID from ID cache */
- if (conn->local_id) {
- /* Check whether they are different */
- if (SILC_ID_CLIENT_COMPARE(conn->local_id, client_id)) {
- silc_free(client_id);
- return;
- }
-
- silc_idcache_del_by_context(conn->client_cache, conn->local_entry);
- silc_free(conn->local_id);
- }
-
- /* Save the new ID */
-
- if (conn->local_id_data)
- silc_free(conn->local_id_data);
-
- conn->local_id = client_id;
- conn->local_id_data = silc_id_payload_get_data(idp);
- conn->local_id_data_len = silc_id_payload_get_len(idp);;
-
- if (!conn->local_entry)
- conn->local_entry = silc_calloc(1, sizeof(*conn->local_entry));
-
- conn->local_entry->nickname = strdup(conn->nickname);
- if (!conn->local_entry->username)
- conn->local_entry->username = strdup(client->username);
- if (!conn->local_entry->hostname)
- conn->local_entry->hostname = strdup(client->hostname);
- conn->local_entry->server = strdup(conn->remote_host);
- conn->local_entry->id = conn->local_id;
- conn->local_entry->valid = TRUE;
-
- /* Put it to the ID cache */
- silc_idcache_add(conn->client_cache, strdup(conn->nickname), conn->local_id,
- (void *)conn->local_entry, 0, NULL);
-
- if (connecting) {
- /* Send NICK command if the nickname was set by the application (and is
- not same as the username). */
- if (client->nickname && strcmp(client->nickname, client->username))
- silc_client_command_send(client, conn, SILC_COMMAND_NICK,
- ++conn->cmd_ident, 1, 1,
- client->nickname, strlen(client->nickname));
-
- /* Issue INFO command to fetch the real server name and server information
- and other stuff. */
- silc_client_command_register(client, SILC_COMMAND_INFO, NULL, NULL,
- silc_client_command_reply_info_i, 0,
- ++conn->cmd_ident);
- sidp = silc_id_payload_encode(conn->remote_id, SILC_ID_SERVER);
- silc_client_command_send(client, conn, SILC_COMMAND_INFO,
- conn->cmd_ident, 1, 2, sidp->data, sidp->len);
- silc_buffer_free(sidp);
-
- /* Notify application of successful connection. We do it here now that
- we've received the Client ID and are allowed to send traffic. */
- client->internal->ops->connect(client, conn, TRUE);
- }
-}