- // 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);
- }
-}
-
-/* Processes the received new Client ID from server. Old Client ID is
- deleted from cache and new one is added. */
-
-void silc_client_receive_new_id(SilcClient client,
- SilcClientConnection conn,
- SilcIDPayload idp)
-{
- SilcClientConnection conn = (SilcClientConnection)sock->user_data;
- int connecting = FALSE;
- SilcClientID *client_id = silc_id_payload_get_id(idp);
- char *nickname;
-
- 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->internal->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 = conn->nickname;
- if (!conn->local_entry->username)
- conn->local_entry->username = strdup(client->username);
- if (!conn->local_entry->server)
- conn->local_entry->server = strdup(conn->remote_host);
- conn->local_entry->id = conn->local_id;
- conn->local_entry->valid = TRUE;
- if (!conn->local_entry->channels)
- conn->local_entry->channels = silc_hash_table_alloc(1, silc_hash_ptr,
- NULL, NULL,
- NULL, NULL, NULL,
- TRUE);
-
- /* Normalize nickname */
- nickname = silc_identifier_check(conn->nickname, strlen(conn->nickname),
- SILC_STRING_UTF8, 128, NULL);
- if (!nickname)
- return;
-
- /* Put it to the ID cache */
- silc_idcache_add(conn->internal->client_cache, nickname, conn->local_id,
- (void *)conn->local_entry, 0, NULL);
-
-#if 0
- if (connecting) {
- SilcBuffer sidp;
-
- /* Issue IDENTIFY command for itself to get resolved hostname
- correctly from server. */
- silc_client_command_register(client, SILC_COMMAND_IDENTIFY, NULL, NULL,
- silc_client_command_reply_identify_i, 0,
- ++conn->cmd_ident);
- sidp = silc_id_payload_encode(conn->local_entry->id, SILC_ID_CLIENT);
- silc_client_command_send(client, conn, SILC_COMMAND_IDENTIFY,
- conn->cmd_ident, 1, 5, sidp->data, sidp->len);
- silc_buffer_free(sidp);
-
- if (!conn->internal->params.detach_data) {
- /* Send NICK command if the nickname was set by the application (and is
- not same as the username). Send this with little timeout. */
- if (client->nickname &&
- !silc_utf8_strcasecmp(client->nickname, client->username))
- silc_schedule_task_add(client->schedule, 0,
- silc_client_send_auto_nick, conn,
- 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
-
- /* 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->connected(client, conn, SILC_CLIENT_CONN_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);
- } else {
- /* We are resuming session. Start resolving informations from the
- server we need to set the client libary in the state before
- detaching the session. The connect client operation is called
- after this is successfully completed */
- silc_client_resume_session(client, conn, silc_client_resume_session_cb,
- NULL);
- }
- }
-#endif /* 0 */
-}
-
-/* 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);