More client library rewrites.
[silc.git] / lib / silcclient / client_resume.c
index 5b984234c7f4fe48bfe60bbaf595612ce57765a9..dbad9c7907c076f45217c186bb76cced5c7a1c3f 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002, 2004 Pekka Riikonen
+  Copyright (C) 2002, 2004, 2006 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
@@ -36,157 +36,6 @@ do {                                                                        \
                         0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);   \
 } while(0)
 
-/* Generates the session detachment data. This data can be used later
-   to resume back to the server. */
-
-SilcBuffer silc_client_get_detach_data(SilcClient client,
-                                      SilcClientConnection conn)
-{
-  SilcBuffer detach;
-  SilcHashTableList htl;
-  SilcChannelUser chu;
-  int ch_count;
-
-  SILC_LOG_DEBUG(("Creating detachment data"));
-
-  ch_count = silc_hash_table_count(conn->local_entry->channels);
-
-  /* Save the nickname, Client ID and user mode in SILC network */
-  detach = silc_buffer_alloc_size(2 + strlen(conn->nickname) +
-                                 2 + conn->local_id_data_len + 4 + 4);
-  silc_buffer_format(detach,
-                    SILC_STR_UI_SHORT(strlen(conn->nickname)),
-                    SILC_STR_UI_XNSTRING(conn->nickname,
-                                         strlen(conn->nickname)),
-                    SILC_STR_UI_SHORT(conn->local_id_data_len),
-                    SILC_STR_UI_XNSTRING(conn->local_id_data,
-                                         conn->local_id_data_len),
-                    SILC_STR_UI_INT(conn->local_entry->mode),
-                    SILC_STR_UI_INT(ch_count),
-                    SILC_STR_END);
-
-  /* Save all joined channels */
-  silc_hash_table_list(conn->local_entry->channels, &htl);
-  while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
-    unsigned char *chid = silc_id_id2str(chu->channel->id, SILC_ID_CHANNEL);
-    SilcUInt16 chid_len = silc_id_get_len(chu->channel->id, SILC_ID_CHANNEL);
-
-    detach = silc_buffer_realloc(detach, detach->truelen + 2 +
-                                strlen(chu->channel->channel_name) +
-                                2 + chid_len + 4);
-    silc_buffer_pull(detach, detach->len);
-    silc_buffer_pull_tail(detach, 2 + strlen(chu->channel->channel_name) +
-                         2 + chid_len + 4);
-    silc_buffer_format(detach,
-                      SILC_STR_UI_SHORT(strlen(chu->channel->channel_name)),
-                      SILC_STR_UI_XNSTRING(chu->channel->channel_name,
-                                          strlen(chu->channel->channel_name)),
-                      SILC_STR_UI_SHORT(chid_len),
-                      SILC_STR_UI_XNSTRING(chid, chid_len),
-                      SILC_STR_UI_INT(chu->channel->mode),
-                      SILC_STR_END);
-    silc_free(chid);
-  }
-  silc_hash_table_list_reset(&htl);
-
-  silc_buffer_push(detach, detach->data - detach->head);
-
-  SILC_LOG_HEXDUMP(("Detach data"), detach->data, detach->len);
-
-  return detach;
-}
-
-/* Processes the detachment data. This creates channels and other
-   stuff according the data found in the the connection parameters.
-   This doesn't actually resolve any detailed information from the
-   server.  To do that call silc_client_resume_session function.
-   This returns the old detached session client ID. */
-
-SilcBool silc_client_process_detach_data(SilcClient client,
-                                    SilcClientConnection conn,
-                                    unsigned char **old_id,
-                                    SilcUInt16 *old_id_len)
-{
-  SilcBufferStruct detach;
-  SilcUInt32 ch_count;
-  int i, len;
-  char *newnick;
-
-  SILC_LOG_DEBUG(("Start"));
-
-  silc_buffer_set(&detach, conn->internal->params.detach_data,
-                 conn->internal->params.detach_data_len);
-
-  SILC_LOG_HEXDUMP(("Detach data"), detach.data, detach.len);
-
-  *old_id = NULL;
-  *old_id_len = 0;
-
-  /* Take the old client ID from the detachment data */
-  len = silc_buffer_unformat(&detach,
-                            SILC_STR_UI16_NSTRING_ALLOC(&newnick,
-                                                        NULL),
-                            SILC_STR_UI16_NSTRING_ALLOC(old_id, old_id_len),
-                            SILC_STR_UI_INT(NULL),
-                            SILC_STR_UI_INT(&ch_count),
-                            SILC_STR_END);
-  if (len == -1)
-    return FALSE;
-  if (!newnick || !(*old_id) || !(*old_id_len))
-    return FALSE;
-
-  silc_free(conn->nickname);
-  conn->nickname = newnick;
-
-  silc_buffer_pull(&detach, len);
-
-  for (i = 0; i < ch_count; i++) {
-    char *channel;
-    unsigned char *chid;
-    SilcUInt16 chid_len;
-    SilcUInt32 ch_mode;
-    SilcChannelID *channel_id;
-    SilcChannelEntry channel_entry;
-
-    len = silc_buffer_unformat(&detach,
-                              SILC_STR_UI16_NSTRING_ALLOC(&channel, NULL),
-                              SILC_STR_UI16_NSTRING(&chid, &chid_len),
-                              SILC_STR_UI_INT(&ch_mode),
-                              SILC_STR_END);
-    if (len == -1)
-      return FALSE;
-
-    /* Add new channel */
-    channel_id = silc_id_str2id(chid, chid_len, SILC_ID_CHANNEL);
-    channel_entry = silc_client_get_channel_by_id(client, conn, channel_id);
-    if (!channel_entry) {
-      channel_entry = silc_client_add_channel(client, conn, channel, ch_mode,
-                                             channel_id);
-    } else {
-      silc_free(channel);
-      silc_free(channel_id);
-    }
-
-    silc_buffer_pull(&detach, len);
-  }
-  silc_buffer_push(&detach, detach.data - detach.head);
-
-  return TRUE;
-}
-
-
-/* Resume session context */
-typedef struct {
-  SilcClient client;
-  SilcClientConnection conn;
-  SilcClientResumeSessionCallback callback;
-  void *context;
-  SilcUInt32 channel_count;
-  SilcUInt32 *cmd_idents;
-  SilcUInt32 cmd_idents_count;
-  SilcBool success;
-} *SilcClientResumeSession;
-
 /* Generic command reply callback. */
 
 SILC_CLIENT_CMD_REPLY_FUNC(resume)