- // silc_client_close_connection_real(client, NULL, conn);
-}
-
-/* Called when we receive disconnection packet from server. This
- closes our end properly and displays the reason of the disconnection
- on the screen. */
-
-void silc_client_disconnect(SilcClient client,
- SilcClientConnection conn,
- SilcBuffer packet)
-{
- SilcClientConnection conn;
- SilcStatus status;
- char *message = NULL;
-
- SILC_LOG_DEBUG(("Server disconnected us, sock %d", sock->sock));
-
- if (packet->len < 1)
- return;
-
- status = (SilcStatus)packet->data[0];
-
- if (packet->len > 1 &&
- silc_utf8_valid(packet->data + 1, packet->len - 1))
- message = silc_memdup(packet->data + 1, packet->len - 1);
-
- conn = (SilcClientConnection)sock->user_data;
- if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
- client->internal->ops->disconnected(client, conn, status, message);
-
- silc_free(message);
-
- SILC_SET_DISCONNECTED(sock);
-
- /* Close connection through scheduler. */
- silc_schedule_task_add(client->schedule, sock->sock,
- silc_client_disconnected_by_server_later,
- client, 0, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
-}
-
-/* Received error message from server. Display it on the screen.
- We don't take any action what so ever of the error message. */
-
-void silc_client_error_by_server(SilcClient client,
- SilcClientConnection conn,
- SilcBuffer message)
-{
- char *msg;
-
- msg = silc_memdup(message->data, message->len);
- client->internal->ops->say(client, sock->user_data,
- SILC_CLIENT_MESSAGE_AUDIT, msg);
- silc_free(msg);
-}
-
-/* Auto-nicking callback to send NICK command to server. */
-
-SILC_TASK_CALLBACK(silc_client_send_auto_nick)
-{
- SilcClientConnection conn = (SilcClientConnection)context;
- SilcClient client = conn->client;
- if (client)
- silc_client_command_send(client, conn, SILC_COMMAND_NICK,
- ++conn->cmd_ident, 1, 1,
- client->nickname, strlen(client->nickname));
-}
-
-/* Client session resuming callback. If the session was resumed
- this callback is called after the resuming is completed. This
- will call the `connect' client operation to the application
- since it has not been called yet. */
-
-static void silc_client_resume_session_cb(SilcClient client,
- SilcClientConnection conn,
- SilcBool success,
- void *context)
-{
- SilcBuffer sidp;
-
- /* Notify application that connection is created to server */
- client->internal->ops->connected(client, conn, success ?
- SILC_CLIENT_CONN_SUCCESS_RESUME :
- SILC_CLIENT_CONN_ERROR_RESUME);
-
- if (success) {
- /* 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);
- }
-}
-
-/* Removes a client entry from all channels it has joined. */
-
-void silc_client_remove_from_channels(SilcClient client,
- SilcClientConnection conn,
- SilcClientEntry client_entry)
-{
- SilcHashTableList htl;
- SilcChannelUser chu;
-
- silc_hash_table_list(client_entry->channels, &htl);
- while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
- silc_hash_table_del(chu->client->channels, chu->channel);
- silc_hash_table_del(chu->channel->user_list, chu->client);
- silc_free(chu);
- }
-
- silc_hash_table_list_reset(&htl);
-}
-
-/* Replaces `old' client entries from all channels to `new' client entry.
- This can be called for example when nickname changes and old ID entry
- is replaced from ID cache with the new one. If the old ID entry is only
- updated, then this fucntion needs not to be called. */
-
-void silc_client_replace_from_channels(SilcClient client,
- SilcClientConnection conn,
- SilcClientEntry old,
- SilcClientEntry new)
-{
- SilcHashTableList htl;
- SilcChannelUser chu;
-
- silc_hash_table_list(old->channels, &htl);
- while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
- /* Replace client entry */
- silc_hash_table_del(chu->client->channels, chu->channel);
- silc_hash_table_del(chu->channel->user_list, chu->client);
-
- chu->client = new;
- silc_hash_table_add(chu->channel->user_list, chu->client, chu);
- silc_hash_table_add(chu->client->channels, chu->channel, chu);
- }
- silc_hash_table_list_reset(&htl);
-}
-
-/* Registers failure timeout to process the received failure packet
- with timeout. */
-
-void silc_client_process_failure(SilcClient client,
- SilcClientConnection conn,
- SilcPacketContext *packet)
-{
- SilcUInt32 failure = 0;
-
- if (sock->protocol) {
- if (packet->buffer->len >= 4)
- SILC_GET32_MSB(failure, packet->buffer->data);
-
- /* Notify application */
- client->internal->ops->failure(client, sock->user_data, sock->protocol,
- SILC_32_TO_PTR(failure));
- }
-}
-
-/* A timeout callback for the re-key. We will be the initiator of the
- re-key protocol. */
-
-SILC_TASK_CALLBACK_GLOBAL(silc_client_rekey_callback)
-{
- SilcClientConnection conn = (SilcSocketConnection)context;
- SilcClientConnection conn = (SilcClientConnection)sock->user_data;
- SilcClient client = (SilcClient)conn->internal->rekey->context;
- SilcProtocol protocol;
- SilcClientRekeyInternalContext *proto_ctx;
-
- SILC_LOG_DEBUG(("Start"));
-
- /* If rekey protocol is active already wait for it to finish */
- if (sock->protocol && sock->protocol->protocol &&
- sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_REKEY)
- return;