The silc_client_connect_to_[server|client] and
[silc.git] / lib / silcclient / silcclient.h
index 2426cb57e5da8798e3c90f9c97c9d2bdeb296143..ee1e0edd039bd308d52cdac1854d0826233010bf 100644 (file)
@@ -83,6 +83,39 @@ typedef enum {
 } SilcClientConnectionStatus;
 /***/
 
+/****f* silcclient/SilcClientAPI/SilcClientRunning
+ *
+ * SYNOPSIS
+ *
+ *    typedef void (*SilcClientRunning)(SilcClient client, void *context);
+ *
+ * DESCRIPTION
+ *
+ *    The callback given as argument to silc_client_init function.  Once
+ *    this is called the client library is running and application may
+ *    start using the Client library API.
+ *
+ ***/
+typedef void (*SilcClientRunning)(SilcClient client, void *context);
+
+/****f* silcclient/SilcClientAPI/SilcClientStopped
+ *
+ * SYNOPSIS
+ *
+ *    typedef void (*SilcClientStopped)(SilcClient client, void *context);
+ *
+ * DESCRIPTION
+ *
+ *    The callback given as argument to silc_client_stop.  Once this is
+ *    called the client library has stopped and can be freed by calling
+ *    silc_client_free.  Note that this won't be called if there are
+ *    active connections in the client.  Connections must first be closed
+ *    by calling silc_client_close_connection or by sending QUIT command to
+ *    the server connection.
+ *
+ ***/
+typedef void (*SilcClientStopped)(SilcClient client, void *context);
+
 /****f* silcclient/SilcClientAPI/SilcClientConnectCallback
  *
  * SYNOPSIS
@@ -594,11 +627,6 @@ typedef struct {
   void (*detach)(SilcClient client, SilcClientConnection conn,
                 const unsigned char *detach_data,
                 SilcUInt32 detach_data_len);
-
-  /* Called when the client library is up and running.  After this callback
-     is called the application may start using the client library APIs. */
-  void (*running)(SilcClient client, void *application);
-
 } SilcClientOperations;
 /***/
 
@@ -643,10 +671,6 @@ typedef struct {
      in the callbacks to protect application specific data. */
   SilcBool threads;
 
-  /* Rekey timeout in seconds. The client will perform rekey in this
-     time interval. If set to zero, the default value will be used. */
-  unsigned int rekey_secs;
-
   /* Connection authentication method request timeout. If server does not
      reply back the current authentication method when we've requested it
      in this time interval we'll assume the reply will not come at all.
@@ -767,7 +791,8 @@ void silc_client_free(SilcClient client);
  * SYNOPSIS
  *
  *    SilcBool silc_client_init(SilcClient client, const char *username,
- *                              const char *hostname, const char *realname);
+ *                              const char *hostname, const char *realname,
+ *                              SilcClientRunning running, void *context);
  *
  * DESCRIPTION
  *
@@ -780,9 +805,15 @@ void silc_client_free(SilcClient client);
  *    in the operating system, `hostname' is the client's host name and
  *    the `realname' is the user's real name.
  *
+ *    The `running' callback is called after the client is running after
+ *    silc_client_run or silc_client_run_one has been called.  Application
+ *    may start using the Client library API after that.  Setting the
+ *    callback is optional, but recommended.
+ *
  ***/
 SilcBool silc_client_init(SilcClient client, const char *username,
-                         const char *hostname, const char *realname);
+                         const char *hostname, const char *realname,
+                         SilcClientRunning running, void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_run
  *
@@ -792,7 +823,7 @@ SilcBool silc_client_init(SilcClient client, const char *username,
  *
  * DESCRIPTION
  *
- *    Runs the client. This starts the scheduler from the utility library.
+ *    Runs the client.  This starts the scheduler from the utility library.
  *    When this functions returns the execution of the application is over.
  *    The client must be initialized before calling this.
  *
@@ -818,21 +849,30 @@ void silc_client_run(SilcClient client);
  ***/
 void silc_client_run_one(SilcClient client);
 
+
 /****f* silcclient/SilcClientAPI/silc_client_stop
  *
  * SYNOPSIS
  *
- *    void silc_client_stop(SilcClient client);
+ *    void silc_client_stop(SilcClient client, SilcClientStopped stopped,
+ *                          void *context);
  *
  * DESCRIPTION
  *
  *    Stops the client. This is called to stop the client and thus to stop
  *    the program.  The client context must be freed with the silc_client_free
- *    function.
+ *    function.  All connections that exist in this client must be closed
+ *    before calling this function.  Connections can be closed by calling
+ *    silc_client_close_connection.
+ *
+ *    The `stopped' will be called once the client and all connections have
+ *    finished.  The client may be freed after that.  Note that the `stopped'
+ *    won't be called before all connections have finished.  Setting the
+ *    callback is optional.
  *
  ***/
-void silc_client_stop(SilcClient client);
-
+void silc_client_stop(SilcClient client, SilcClientStopped stopped,
+                     void *context);
 
 /* Connecting functions */
 
@@ -926,6 +966,12 @@ typedef struct {
   /* Connection timeout.  If non-zero, the connection will timeout unless
      the SILC connection is completed in the specified amount of time. */
   SilcUInt32 timeout_secs;
+
+  /* Rekey timeout in seconds.  The client will perform rekey in this
+     time interval.  If set to zero, the default value will be used
+     (3600 seconds, 1 hour). */
+  unsigned int rekey_secs;
+
 } SilcClientConnectionParams;
 /***/
 
@@ -933,7 +979,7 @@ typedef struct {
  *
  * SYNOPSIS
  *
- *    SilcBool
+ *    SilcAsyncOperation
  *    silc_client_connect_to_server(SilcClient client,
  *                                  SilcClientConnectionParams *params,
  *                                  SilcPublicKey public_key,
@@ -957,23 +1003,25 @@ typedef struct {
  *    the silc_client_key_exchange after creating the connection to start
  *    key exchange and authentication with the server.
  *
- *    Returns when connecting is started and FALSE if connection was not
- *    created at all.
+ *    Returns SilcAsyncOperation which can be used to cancel the connecting,
+ *    or NULL on error.  Note that the returned pointer becomes invalid
+ *    after the `callback' is called.
  *
  ***/
-SilcBool silc_client_connect_to_server(SilcClient client,
-                                      SilcClientConnectionParams *params,
-                                      SilcPublicKey public_key,
-                                      SilcPrivateKey private_key,
-                                      char *remote_host, int port,
-                                      SilcClientConnectCallback callback,
-                                      void *context);
+SilcAsyncOperation
+silc_client_connect_to_server(SilcClient client,
+                             SilcClientConnectionParams *params,
+                             SilcPublicKey public_key,
+                             SilcPrivateKey private_key,
+                             char *remote_host, int port,
+                             SilcClientConnectCallback callback,
+                             void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
  *
  * SYNOPSIS
  *
- *    SilcBool
+ *    SilcAsyncOperation
  *    silc_client_connect_to_client(SilcClient client,
  *                                  SilcClientConnectionParams *params,
  *                                  SilcPublicKey public_key,
@@ -996,23 +1044,25 @@ SilcBool silc_client_connect_to_server(SilcClient client,
  *    the silc_client_key_exchange after creating the connection to start
  *    key exchange with the client.
  *
- *    Returns when connecting is started and FALSE if connection was not
- *    created at all.
+ *    Returns SilcAsyncOperation which can be used to cancel the connecting,
+ *    or NULL on error.  Note that the returned pointer becomes invalid
+ *    after the `callback' is called.
  *
  ***/
-SilcBool silc_client_connect_to_client(SilcClient client,
-                                      SilcClientConnectionParams *params,
-                                      SilcPublicKey public_key,
-                                      SilcPrivateKey private_key,
-                                      char *remote_host, int port,
-                                      SilcClientConnectCallback callback,
-                                      void *context);
+SilcAsyncOperation
+silc_client_connect_to_client(SilcClient client,
+                             SilcClientConnectionParams *params,
+                             SilcPublicKey public_key,
+                             SilcPrivateKey private_key,
+                             char *remote_host, int port,
+                             SilcClientConnectCallback callback,
+                             void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
  *
  * SYNOPSIS
  *
- *    SilcBool
+ *    SilcAsyncOperation
  *    silc_client_key_exchange(SilcClient client,
  *                             SilcClientConnectionParams *params,
  *                             SilcPublicKey public_key,
@@ -1045,8 +1095,9 @@ SilcBool silc_client_connect_to_client(SilcClient client,
  *    disconnects.  The `conn_type' is the type of session this is going to
  *    be.
  *
- *    Returns TRUE when key exchange is started and FALSE if it is not started
- *    at all.
+ *    Returns SilcAsyncOperation which can be used to cancel the connecting,
+ *    or NULL on error.  Note that the returned pointer becomes invalid
+ *    after the `callback' is called.
  *
  * EXAMPLE
  *
@@ -1072,14 +1123,15 @@ SilcBool silc_client_connect_to_client(SilcClient client,
  *    }
  *
  ***/
-SilcBool silc_client_key_exchange(SilcClient client,
-                                 SilcClientConnectionParams *params,
-                                 SilcPublicKey public_key,
-                                 SilcPrivateKey private_key,
-                                 SilcStream stream,
-                                 SilcConnectionType conn_type,
-                                 SilcClientConnectCallback callback,
-                                 void *context);
+SilcAsyncOperation
+silc_client_key_exchange(SilcClient client,
+                        SilcClientConnectionParams *params,
+                        SilcPublicKey public_key,
+                        SilcPrivateKey private_key,
+                        SilcStream stream,
+                        SilcConnectionType conn_type,
+                        SilcClientConnectCallback callback,
+                        void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_close_connection
  *