updates.
[silc.git] / lib / silcclient / silcclient.h
index 2dcb7a58a8aaf9bf9c05b1d984a5f303d1afe741..dd3e5cb1a46a30506b8bfc017ae520e92ca8989c 100644 (file)
@@ -68,7 +68,6 @@ typedef struct SilcClientCommandStruct *SilcClientCommand;
 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
 typedef struct SilcClientCommandReplyContextStruct 
                                            *SilcClientCommandReplyContext;
-typedef struct SilcChannelPrivateKeyStruct *SilcChannelPrivateKey;
 typedef struct SilcChannelUserStruct *SilcChannelUser;
 
 /* General definitions */
@@ -150,6 +149,27 @@ typedef struct {
 } *SilcPrivateMessageKeys;
 /***/
 
+/****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
+ *
+ * NAME
+ *
+ *    typedef struct { ... } SilcChannelPrivateKey;
+ *
+ * DESCRIPTION
+ *
+ *    Structure to hold one channel private key. The array of this structure
+ *    is returned by silc_client_list_channel_private_keys function.
+ *
+ * SOURCE
+ */
+typedef struct SilcChannelPrivateKeyStruct {
+  char *name;                        /* Application given name */
+  SilcCipher cipher;                 /* The cipher and key */
+  SilcHmac hmac;                     /* The HMAC and hmac key */
+  unsigned char *key;                /* The key data */
+  SilcUInt32 key_len;                /* The key length */
+} *SilcChannelPrivateKey;
+/***/
 
 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
  *
@@ -163,7 +183,9 @@ typedef struct {
  *
  *    Ask passphrase callback. This is called by the application when the
  *    library calls `ask_passphrase' client operation.  The callback delivers
- *    the passphrase to the library.
+ *    the passphrase to the library.  The passphrases in SILC protocol
+ *    MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
+ *    encoded, and if it is not then library will attempt to encode it.
  *
  ***/
 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
@@ -261,13 +283,16 @@ typedef struct {
      `msg' maybe NULL. */
   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
                          SilcClientEntry sender, SilcChannelEntry channel, 
-                         SilcMessageFlags flags, char *msg);
+                         SilcMessageFlags flags,
+                         const unsigned char *message,
+                         SilcUInt32 message_len);
 
   /* Private message to the client. The `sender' is the sender of the
      message. */
   void (*private_message)(SilcClient client, SilcClientConnection conn,
                          SilcClientEntry sender, SilcMessageFlags flags,
-                         char *msg);
+                         const unsigned char *message,
+                         SilcUInt32 message_len);
 
   /* Notify message to the client. The notify arguments are sent in the
      same order as servers sends them. The arguments are same as received
@@ -307,14 +332,20 @@ typedef struct {
      the command reply status server returned. The `command' is the command
      reply being processed. The function has variable argument list and each
      command defines the number and type of arguments it passes to the
-     application (on error they are not sent). */
+     application (on error they are not sent).
+
+     The arguments are sent in the same order as servers sends them.  The 
+     arguments are same as received from the server except for ID's.  If 
+     ID is received application receives the corresponding entry to the 
+     ID. For example, if Client ID is receives application receives 
+     SilcClientEntry. */
   void (*command_reply)(SilcClient client, SilcClientConnection conn,
                        SilcCommandPayload cmd_payload, int success,
                        SilcCommand command, SilcCommandStatus status, ...);
 
   /* Called to indicate that connection was either successfully established
      or connecting failed.  This is also the first time application receives
-     the SilcClientConnection objecet which it should save somewhere.
+     the SilcClientConnection object which it should save somewhere.
      If the `success' is FALSE the application must always call the function
      silc_client_close_connection. */
   void (*connect)(SilcClient client, SilcClientConnection conn, int success);
@@ -342,7 +373,8 @@ typedef struct {
 
   /* Ask (interact, that is) a passphrase from user. The passphrase is
      returned to the library by calling the `completion' callback with
-     the `context'. */
+     the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
+     if not then the library will attempt to encode. */
   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
                         SilcAskPassphrase completion, void *context);
 
@@ -377,6 +409,26 @@ typedef struct {
   void (*ftp)(SilcClient client, SilcClientConnection conn,
              SilcClientEntry client_entry, SilcUInt32 session_id,
              const char *hostname, SilcUInt16 port);
+
+  /* Delivers SILC session detachment data indicated by `detach_data' to the
+     application.  If application has issued SILC_COMMAND_DETACH command     
+     the client session in the SILC network is not quit.  The client remains 
+     in the network but is detached.  The detachment data may be used later
+     to resume the session in the SILC Network.  The appliation is   
+     responsible of saving the `detach_data', to for example in a file.
+
+     The detachment data can be given as argument to the functions
+     silc_client_connect_to_server, or silc_client_add_connection when
+     creating connection to remote server, inside SilcClientConnectionParams
+     structure.  If it is provided the client library will attempt to resume
+     the session in the network.  After the connection is created
+     successfully, the application is responsible of setting the user
+     interface for user into the same state it was before detaching (showing
+     same channels, channel modes, etc).  It can do this by fetching the
+     information (like joined channels) from the client library. */
+  void (*detach)(SilcClient client, SilcClientConnection conn,
+                const unsigned char *detach_data,
+                SilcUInt32 detach_data_len);
 } SilcClientOperations;
 /***/
 
@@ -590,12 +642,45 @@ void silc_client_stop(SilcClient client);
 
 /* Connecting functions (client.c) */
 
+/****s* silcclient/SilcClientAPI/SilcClientConnectionParams
+ *
+ * NAME
+ *
+ *    typedef struct { ... } SilcClientConnectionParams;
+ *
+ * DESCRIPTION
+ *
+ *    Client connection parameters.  This can be filled by the application
+ *    and given as argument to silc_client_connect_to_server or to
+ *    silc_client_add_connection.
+ *
+ * SOURCE
+ */
+typedef struct {
+  /* The SILC session detachment data that was returned by `detach' client
+     operation when the application detached from the network.  Application
+     is responsible of saving the data and giving it as argument here
+     for resuming the session in the SILC network.
+
+     If this is provided here the client library will attempt to resume
+     the session in the network.  After the connection is created
+     successfully, the application is responsible of setting the user
+     interface for user into the same state it was before detaching (showing
+     same channels, channel modes, etc).  It can do this by fetching the
+     information (like joined channels) from the client library. */
+  unsigned char *detach_data;
+  SilcUInt32 detach_data_len;
+
+} SilcClientConnectionParams;
+/***/
+
 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
  *
  * SYNOPSIS
  *
- *    int silc_client_connect_to_server(SilcClient client, int port,
- *                                      char *host, void *context);
+ *    int silc_client_connect_to_server(SilcClient client, 
+ *                                      SilcClientConnectionParams *params,
+ *                                      int port, char *host, void *context);
  *
  * DESCRIPTION
  *
@@ -605,20 +690,24 @@ void silc_client_stop(SilcClient client);
  *    that is created after the connection is created. Note that application
  *    may handle the connecting process outside the library. If this is the
  *    case then this function is not used at all. When the connecting is
- *    done the `connect' client operation is called.
+ *    done the `connect' client operation is called, and the `context' is
+ *    accessible with conn->context, conn being SilcClientConnection.
+ *    If the `params' is provided they are used by the routine.
  *
  ***/
-int silc_client_connect_to_server(SilcClient client, int port,
-                                 char *host, void *context);
+int silc_client_connect_to_server(SilcClient client, 
+                                 SilcClientConnectionParams *params,
+                                 int port, char *host, void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_add_connection
  *
  * SYNOPSIS
  *
- *    SilcClientConnection silc_client_add_connection(SilcClient client,
- *                                                    char *hostname,
- *                                                   int port,
- *                                                   void *context);
+ *
+ *    SilcClientConnection
+ *    silc_client_add_connection(SilcClient client,
+ *                               SilcClientConnectionParams *params,
+ *                               char *hostname, int port, void *context);
  *
  * DESCRIPTION
  *
@@ -626,15 +715,21 @@ int silc_client_connect_to_server(SilcClient client, int port,
  *    connection to the connection table and returns a pointer to it. A client
  *    can have multiple connections to multiple servers. Every connection must
  *    be added to the client using this function. User data `context' may
- *    be sent as argument. This function is normally used only if the 
- *    application performed the connecting outside the library. The library
+ *    be sent as argument.  If the `params' is provided they are used by 
+ *    the routine.
+ *
+ * NOTES
+ *
+ *    This function is normally used only if the application performed 
+ *    the connecting outside the library, and did not called the
+ *    silc_client_connect_to_server function at all. The library
  *    however may use this internally.
  *
  ***/
-SilcClientConnection silc_client_add_connection(SilcClient client,
-                                               char *hostname,
-                                               int port,
-                                               void *context);
+SilcClientConnection
+silc_client_add_connection(SilcClient client,
+                          SilcClientConnectionParams *params,
+                          char *hostname, int port, void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_del_connection
  *
@@ -713,22 +808,15 @@ void silc_client_start_key_exchange(SilcClient client,
  * SYNOPSIS
  *
  *    void silc_client_close_connection(SilcClient client,
- *                                      SilcSocketConnection sock,
  *                                      SilcClientConnection conn);
  *
  * DESCRIPTION
  *
  *    Closes connection to remote end. Free's all allocated data except
  *    for some information such as nickname etc. that are valid at all time. 
- *    If the `sock' is NULL then the conn->sock will be used.  If `sock' is
- *    provided it will be checked whether the sock and `conn->sock' are the
- *    same (they can be different, ie. a socket can use `conn' as its
- *    connection but `conn->sock' might be actually a different connection
- *    than the `sock'). 
  *
  ***/
 void silc_client_close_connection(SilcClient client,
-                                 SilcSocketConnection sock,
                                  SilcClientConnection conn);
 
 
@@ -1471,6 +1559,7 @@ void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
  *    int silc_client_add_channel_private_key(SilcClient client,
  *                                            SilcClientConnection conn,
  *                                            SilcChannelEntry channel,
+ *                                            const char *name,
  *                                            char *cipher,
  *                                            char *hmac,
  *                                            unsigned char *key,
@@ -1485,6 +1574,7 @@ void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
  *    key in order to decrypt the messages. However, it is possible to have
  *    several private keys per one channel. In this case only some of the
  *    clients on the channel may know the one key and only some the other key.
+ *    The `name' can be application given name for the key.
  *
  *    The private key for channel is optional. If it is not set then the
  *    channel messages are encrypted using the channel key generated by the
@@ -1510,6 +1600,7 @@ void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
 int silc_client_add_channel_private_key(SilcClient client,
                                        SilcClientConnection conn,
                                        SilcChannelEntry channel,
+                                       const char *name,
                                        char *cipher,
                                        char *hmac,
                                        unsigned char *key,
@@ -1598,6 +1689,27 @@ silc_client_list_channel_private_keys(SilcClient client,
 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
                                           SilcUInt32 key_count);
 
+/****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_current_channel_private_key(SilcClient client,
+ *                                                 SilcClientConnection conn,
+ *                                                 SilcChannelEntry channel,
+ *                                                 SilcChannelPrivateKey key);
+ *
+ * DESCRIPTION
+ *
+ *    Sets the `key' to be used as current channel private key on the
+ *    `channel'.  Packet sent after calling this function will be secured
+ *    with `key'.
+ *
+ ***/
+void silc_client_current_channel_private_key(SilcClient client,
+                                            SilcClientConnection conn,
+                                            SilcChannelEntry channel,
+                                            SilcChannelPrivateKey key);
+
 
 /* Key Agreement routines (client_keyagr.c) */