Fixed WATCH notify handling.
[silc.git] / lib / silcclient / client_register.c
index ae5de0011b6243a6a15c5e4b042b6ae4eb0ff1a5..a2380c80b5eee189fb7b59666d4804a2bdd92be0 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2006 Pekka Riikonen
+  Copyright (C) 2006 - 2007 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
@@ -34,20 +34,6 @@ typedef struct {
 
 /************************ Static utility functions **************************/
 
-/* Command callback.  Nothing interesting to do here. */
-
-static SilcBool
-silc_client_register_command_called(SilcClient client,
-                                   SilcClientConnection conn,
-                                   SilcCommand command,
-                                   SilcStatus status,
-                                   SilcStatus error,
-                                   void *context,
-                                   va_list ap)
-{
-  return FALSE;
-}
-
 /* Continues resuming after resolving.  Continue after last reply. */
 
 static SilcBool
@@ -156,9 +142,15 @@ SILC_FSM_STATE(silc_client_st_register)
 {
   SilcClientConnection conn = fsm_context;
   SilcClient client = conn->client;
+  char *nick = NULL;
 
   SILC_LOG_DEBUG(("Register to network"));
 
+  /* From SILC protocol version 1.3, nickname is in NEW_CLIENT packet */
+  if (conn->internal->remote_version >= 13)
+    nick = (conn->internal->params.nickname ?
+           conn->internal->params.nickname : client->username);
+
   /* Send NEW_CLIENT packet to register to network */
   if (!silc_packet_send_va(conn->stream, SILC_PACKET_NEW_CLIENT, 0,
                           SILC_STR_UI_SHORT(strlen(client->username)),
@@ -167,6 +159,8 @@ SILC_FSM_STATE(silc_client_st_register)
                           SILC_STR_UI_SHORT(strlen(client->realname)),
                           SILC_STR_DATA(client->realname,
                                         strlen(client->realname)),
+                          SILC_STR_UI_SHORT(nick ? strlen(nick) : 0),
+                          SILC_STR_DATA(nick, nick ? strlen(nick) : 0),
                           SILC_STR_END)) {
     /** Error sending packet */
     silc_fsm_next(fsm, silc_client_st_register_error);
@@ -217,13 +211,13 @@ SILC_FSM_STATE(silc_client_st_register_complete)
   /* Issue IDENTIFY command for itself to get resolved hostname
      correctly from server. */
   silc_client_command_send(client, conn, SILC_COMMAND_IDENTIFY,
-                          silc_client_register_command_called, NULL,
+                          silc_client_command_called_dummy, NULL,
                           1, 5, silc_buffer_data(conn->internal->local_idp),
                           silc_buffer_len(conn->internal->local_idp));
 
-  /* Call NICK command if the nickname was set by the application (and is
-     not same as the username). */
-  if (conn->internal->params.nickname &&
+  /* With SILC protocol version 1.2 call NICK command if the nickname was
+     set by the application. */
+  if (conn->internal->params.nickname && conn->internal->remote_version < 13 &&
       !silc_utf8_strcasecmp(conn->internal->params.nickname, client->username))
     silc_client_command_call(client, conn, NULL,
                             "NICK", conn->internal->params.nickname, NULL);
@@ -231,7 +225,7 @@ SILC_FSM_STATE(silc_client_st_register_complete)
   /* Issue INFO command to fetch the real server name and server
      information and other stuff. */
   silc_client_command_send(client, conn, SILC_COMMAND_INFO,
-                          silc_client_register_command_called, NULL,
+                          silc_client_command_called_dummy, NULL,
                           1, 2, silc_buffer_data(conn->internal->remote_idp),
                           silc_buffer_len(conn->internal->remote_idp));
 
@@ -251,22 +245,16 @@ SILC_FSM_STATE(silc_client_st_register_complete)
 SILC_FSM_STATE(silc_client_st_register_error)
 {
   SilcClientConnection conn = fsm_context;
-  SilcClient client = conn->client;
 
   SILC_LOG_DEBUG(("Error registering to network"));
 
   /* Signal to close connection */
+  conn->internal->status = SILC_CLIENT_CONN_ERROR;
   if (!conn->internal->disconnected) {
     conn->internal->disconnected = TRUE;
     SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
   }
 
-  /* Call connect callback */
-  if (conn->internal->callback_called)
-    conn->callback(client, conn, SILC_CLIENT_CONN_ERROR, 0, NULL,
-                  conn->callback_context);
-  conn->internal->callback_called = TRUE;
-
   silc_schedule_task_del_by_all(conn->internal->schedule, 0,
                                silc_client_connect_timeout, conn);
 
@@ -392,7 +380,7 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_channels)
   /* Send UMODE command to get our own user mode in the network */
   SILC_LOG_DEBUG(("Resolving user mode"));
   silc_client_command_send(client, conn, SILC_COMMAND_UMODE,
-                          silc_client_register_command_called, NULL,
+                          silc_client_command_called_dummy, NULL,
                           1, 1, silc_buffer_data(conn->internal->local_idp),
                           silc_buffer_len(conn->internal->local_idp));
 
@@ -537,14 +525,14 @@ SILC_FSM_STATE(silc_client_st_resume_completed)
   /* Issue IDENTIFY command for itself to get resolved hostname
      correctly from server. */
   silc_client_command_send(client, conn, SILC_COMMAND_IDENTIFY,
-                          silc_client_register_command_called, NULL,
+                          silc_client_command_called_dummy, NULL,
                           1, 5, silc_buffer_data(conn->internal->local_idp),
                           silc_buffer_len(conn->internal->local_idp));
 
   /* Issue INFO command to fetch the real server name and server
      information and other stuff. */
   silc_client_command_send(client, conn, SILC_COMMAND_INFO,
-                          silc_client_register_command_called, NULL,
+                          silc_client_command_called_dummy, NULL,
                           1, 2, silc_buffer_data(conn->internal->remote_idp),
                           silc_buffer_len(conn->internal->remote_idp));
 
@@ -599,7 +587,6 @@ SILC_FSM_STATE(silc_client_st_resume_completed)
 SILC_FSM_STATE(silc_client_st_resume_error)
 {
   SilcClientConnection conn = fsm_context;
-  SilcClient client = conn->client;
   SilcClientResumeSession resume = state_context;
 
   if (conn->internal->disconnected) {
@@ -613,17 +600,12 @@ SILC_FSM_STATE(silc_client_st_resume_error)
   SILC_LOG_DEBUG(("Error resuming to network"));
 
   /* Signal to close connection */
+  conn->internal->status = SILC_CLIENT_CONN_ERROR;
   if (!conn->internal->disconnected) {
     conn->internal->disconnected = TRUE;
     SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
   }
 
-  /* Call connect callback */
-  if (conn->internal->callback_called)
-    conn->callback(client, conn, SILC_CLIENT_CONN_ERROR, 0, NULL,
-                  conn->callback_context);
-  conn->internal->callback_called = TRUE;
-
   silc_schedule_task_del_by_all(conn->internal->schedule, 0,
                                silc_client_connect_timeout, conn);