updates.
[silc.git] / lib / silcclient / silcclient.h
index 231347173198f1e0509527e17bf0208ee2a2c55e..b9647bdf08bb705e159f6c947a9fc6a3ffb51e27 100644 (file)
@@ -17,7 +17,7 @@
 
 */
 
-/****h* silcclient/SilcClientAPI
+/****h* silcclient/Client Library Interface
  *
  * DESCRIPTION
  *
@@ -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 */
@@ -146,28 +145,51 @@ typedef struct {
                                         provided it. This is NULL if the
                                         library generated the key or if
                                         the SKE key material was used. */
-  uint32 key_len;                    /* The key length */
+  SilcUInt32 key_len;                /* The key length */
 } *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
  *
  * SYNOPSIS
  *
  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
- *                                     uint32 passphrase_len,
+ *                                     SilcUInt32 passphrase_len,
  *                                     void *context);
  *
  * DESCRIPTION
  *
  *    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,
-                                 uint32 passphrase_len,
+                                 SilcUInt32 passphrase_len,
                                  void *context);
 
 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
@@ -192,7 +214,7 @@ typedef void (*SilcVerifyPublicKey)(bool success, void *context);
  *    typedef void (*SilcGetAuthMeth)(bool success, 
  *                                    SilcProtocolAuthMeth auth_meth,
  *                                    const unsigned char *auth_data,
- *                                    uint32 auth_data_len, void *context);
+ *                                    SilcUInt32 auth_data_len, void *context);
  * 
  * DESCRIPTION
  *
@@ -209,7 +231,7 @@ typedef void (*SilcVerifyPublicKey)(bool success, void *context);
 typedef void (*SilcGetAuthMeth)(bool success, 
                                SilcProtocolAuthMeth auth_meth,
                                const unsigned char *auth_data,
-                               uint32 auth_data_len, void *context);
+                               SilcUInt32 auth_data_len, void *context);
 
 /****d* silcclient/SilcClientAPI/SilcClientMessageType
  *
@@ -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,7 +332,13 @@ 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, ...);
@@ -328,7 +359,7 @@ typedef struct {
      authentication method and authentication data is called. The `conn'
      may be NULL. */
   void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
-                         char *hostname, uint16 port,
+                         char *hostname, SilcUInt16 port,
                          SilcGetAuthMeth completion, void *context);
 
   /* Verifies received public key. The `conn_type' indicates which entity
@@ -337,12 +368,13 @@ typedef struct {
      `completion' must be called after the public key has been verified. */
   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
                            SilcSocketType conn_type, unsigned char *pk, 
-                           uint32 pk_len, SilcSKEPKType pk_type,
+                           SilcUInt32 pk_len, SilcSKEPKType pk_type,
                            SilcVerifyPublicKey completion, void *context);
 
   /* 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);
 
@@ -365,7 +397,7 @@ typedef struct {
      `completion' and `context' arguments must be set by the application. */
   int (*key_agreement)(SilcClient client, SilcClientConnection conn,
                       SilcClientEntry client_entry, const char *hostname,
-                      uint16 port, SilcKeyAgreementCallback *completion,
+                      SilcUInt16 port, SilcKeyAgreementCallback *completion,
                       void **context);
 
   /* Notifies application that file transfer protocol session is being
@@ -375,8 +407,8 @@ typedef struct {
      transfer request, by calling the silc_client_file_receive or
      silc_client_file_close, respectively. */
   void (*ftp)(SilcClient client, SilcClientConnection conn,
-             SilcClientEntry client_entry, uint32 session_id,
-             const char *hostname, uint16 port);
+             SilcClientEntry client_entry, SilcUInt32 session_id,
+             const char *hostname, SilcUInt16 port);
 } SilcClientOperations;
 /***/
 
@@ -700,8 +732,8 @@ void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
  *    directly if application is performing its own connecting and does not
  *    use the connecting provided by this library. This function is normally
  *    used only if the application performed the connecting outside the
- *    library. The library however may use this internally. Returns FALSE
- *    if the key exchange could not be started.
+ *    library. The library however may use this internally.  After the
+ *    key exchange is performed the `connect' client operation is called.
  *
  ***/
 void silc_client_start_key_exchange(SilcClient client,
@@ -744,7 +776,7 @@ void silc_client_close_connection(SilcClient client,
  *                                          SilcChannelPrivateKey key,
  *                                          SilcMessageFlags flags,
  *                                          unsigned char *data, 
- *                                          uint32 data_len, 
+ *                                          SilcUInt32 data_len, 
  *                                          int force_send);
  *
  * DESCRIPTION
@@ -769,7 +801,7 @@ void silc_client_send_channel_message(SilcClient client,
                                      SilcChannelPrivateKey key,
                                      SilcMessageFlags flags,
                                      unsigned char *data, 
-                                     uint32 data_len, 
+                                     SilcUInt32 data_len, 
                                      int force_send);
 
 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
@@ -781,7 +813,7 @@ void silc_client_send_channel_message(SilcClient client,
  *                                          SilcClientEntry client_entry,
  *                                          SilcMessageFlags flags,
  *                                          unsigned char *data, 
- *                                          uint32 data_len, 
+ *                                          SilcUInt32 data_len, 
  *                                          int force_send);
  *
  * DESCRIPTION
@@ -800,7 +832,7 @@ void silc_client_send_private_message(SilcClient client,
                                      SilcClientEntry client_entry,
                                      SilcMessageFlags flags,
                                      unsigned char *data, 
-                                     uint32 data_len, 
+                                     SilcUInt32 data_len, 
                                      int force_send);
 
 
@@ -813,7 +845,7 @@ void silc_client_send_private_message(SilcClient client,
  *    typedef void (*SilcGetClientCallback)(SilcClient client,
  *                                          SilcClientConnection conn,
  *                                          SilcClientEntry *clients,
- *                                          uint32 clients_count,
+ *                                          SilcUInt32 clients_count,
  *                                          void *context);
  *
  * DESCRIPTION
@@ -827,7 +859,7 @@ void silc_client_send_private_message(SilcClient client,
 typedef void (*SilcGetClientCallback)(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcClientEntry *clients,
-                                     uint32 clients_count,
+                                     SilcUInt32 clients_count,
                                      void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_get_clients
@@ -872,7 +904,7 @@ void silc_client_get_clients(SilcClient client,
  *                                                   SilcClientConnection conn,
  *                                                   const char *nickname,
  *                                                   const char *format,
- *                                                   uint32 *clients_count);
+ *                                                   SilcUInt32 *clients_count);
  *
  * DESCRIPTION
  *
@@ -891,7 +923,7 @@ SilcClientEntry *silc_client_get_clients_local(SilcClient client,
                                               SilcClientConnection conn,
                                               const char *nickname,
                                               const char *format,
-                                              uint32 *clients_count);
+                                              SilcUInt32 *clients_count);
 
 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
  *
@@ -899,7 +931,7 @@ SilcClientEntry *silc_client_get_clients_local(SilcClient client,
  *
  *    void silc_client_get_clients_by_list(SilcClient client,
  *                                         SilcClientConnection conn,
- *                                         uint32 list_count,
+ *                                         SilcUInt32 list_count,
  *                                         SilcBuffer client_id_list,
  *                                         SilcGetClientCallback completion,
  *                                         void *context);
@@ -918,7 +950,7 @@ SilcClientEntry *silc_client_get_clients_local(SilcClient client,
  ***/
 void silc_client_get_clients_by_list(SilcClient client,
                                     SilcClientConnection conn,
-                                    uint32 list_count,
+                                    SilcUInt32 list_count,
                                     SilcBuffer client_id_list,
                                     SilcGetClientCallback completion,
                                     void *context);
@@ -991,7 +1023,7 @@ bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
  *                                           SilcClientConnection conn,
  *                                           SilcChannelEntry *channels,
- *                                           uint32 channels_count,
+ *                                           SilcUInt32 channels_count,
  *                                           void *context);
  *
  * DESCRIPTION
@@ -1005,7 +1037,7 @@ bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
 typedef void (*SilcGetChannelCallback)(SilcClient client,
                                       SilcClientConnection conn,
                                       SilcChannelEntry *channels,
-                                      uint32 channels_count,
+                                      SilcUInt32 channels_count,
                                       void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_get_channel
@@ -1253,8 +1285,8 @@ void silc_client_command_call(SilcClientCommand command,
  *
  *    void silc_client_command_send(SilcClient client, 
  *                                  SilcClientConnection conn,
- *                                  SilcCommand command, uint16 ident,
- *                                  uint32 argc, ...);
+ *                                  SilcCommand command, SilcUInt16 ident,
+ *                                  SilcUInt32 argc, ...);
  *
  * DESCRIPTION
  *
@@ -1266,8 +1298,8 @@ void silc_client_command_call(SilcClientCommand command,
  *
  ***/
 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
-                             SilcCommand command, uint16 ident,
-                             uint32 argc, ...);
+                             SilcCommand command, SilcUInt16 ident,
+                             SilcUInt32 argc, ...);
 
 /****f* silcclient/SilcClientAPI/silc_client_command_pending
  *
@@ -1275,7 +1307,7 @@ void silc_client_command_send(SilcClient client, SilcClientConnection conn,
  *
  *    void silc_client_command_pending(SilcClientConnection conn,
  *                                     SilcCommand reply_cmd,
- *                                     uint16 ident,
+ *                                     SilcUInt16 ident,
  *                                     SilcCommandCb callback,
  *                                     void *context);
  *
@@ -1294,7 +1326,7 @@ void silc_client_command_send(SilcClient client, SilcClientConnection conn,
  ***/
 void silc_client_command_pending(SilcClientConnection conn,
                                 SilcCommand reply_cmd,
-                                uint16 ident,
+                                SilcUInt16 ident,
                                 SilcCommandCb callback,
                                 void *context);
 
@@ -1310,7 +1342,7 @@ void silc_client_command_pending(SilcClientConnection conn,
  *                                            SilcClientEntry client_entry,
  *                                            char *cipher,
  *                                            unsigned char *key,
- *                                            uint32 key_len,
+ *                                            SilcUInt32 key_len,
  *                                            bool generate_key,
  *                                            bool responder);
  *
@@ -1343,7 +1375,7 @@ int silc_client_add_private_message_key(SilcClient client,
                                        SilcClientEntry client_entry,
                                        char *cipher,
                                        unsigned char *key,
-                                       uint32 key_len,
+                                       SilcUInt32 key_len,
                                        bool generate_key,
                                        bool responder);
 
@@ -1426,7 +1458,7 @@ int silc_client_del_private_message_key(SilcClient client,
  *    SilcPrivateMessageKeys
  *    silc_client_list_private_message_keys(SilcClient client,
  *                                          SilcClientConnection conn,
- *                                          uint32 *key_count);
+ *                                          SilcUInt32 *key_count);
  * 
  * DESCRIPTION
  *
@@ -1442,14 +1474,14 @@ int silc_client_del_private_message_key(SilcClient client,
 SilcPrivateMessageKeys
 silc_client_list_private_message_keys(SilcClient client,
                                      SilcClientConnection conn,
-                                     uint32 *key_count);
+                                     SilcUInt32 *key_count);
 
 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
  *
  * SYNOPSIS
  *
  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
- *                                               uint32 key_count);
+ *                                               SilcUInt32 key_count);
  * 
  * DESCRIPTION
  *
@@ -1458,7 +1490,7 @@ silc_client_list_private_message_keys(SilcClient client,
  *
  ***/
 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
-                                          uint32 key_count);
+                                          SilcUInt32 key_count);
 
 
 /* Channel private key management (client_channel.c, 
@@ -1471,10 +1503,11 @@ 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,
- *                                            uint32 key_len);
+ *                                            SilcUInt32 key_len);
  * 
  * DESCRIPTION
  *
@@ -1485,6 +1518,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,10 +1544,11 @@ 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,
-                                       uint32 key_len);
+                                       SilcUInt32 key_len);
 
 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
  *
@@ -1566,7 +1601,7 @@ int silc_client_del_channel_private_key(SilcClient client,
  *    silc_client_list_channel_private_keys(SilcClient client,
  *                                          SilcClientConnection conn,
  *                                          SilcChannelEntry channel,
- *                                          uint32 *key_count);
+ *                                          SilcUInt32 *key_count);
  *
  * DESCRIPTION
  *
@@ -1581,14 +1616,14 @@ SilcChannelPrivateKey *
 silc_client_list_channel_private_keys(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcChannelEntry channel,
-                                     uint32 *key_count);
+                                     SilcUInt32 *key_count);
 
 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
  *
  * SYNOPSIS
  *
  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
- *                                               uint32 key_count);
+ *                                               SilcUInt32 key_count);
  *
  * DESCRIPTION
  *
@@ -1596,7 +1631,28 @@ silc_client_list_channel_private_keys(SilcClient client,
  *
  ***/
 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
-                                          uint32 key_count);
+                                          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) */
@@ -1610,7 +1666,7 @@ void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
  *                                        SilcClientEntry client_entry,
  *                                        char *hostname,
  *                                        int port,
- *                                        uint32 timeout_secs,
+ *                                        SilcUInt32 timeout_secs,
  *                                        SilcKeyAgreementCallback completion,
  *                                        void *context);
  *
@@ -1663,7 +1719,7 @@ void silc_client_send_key_agreement(SilcClient client,
                                    const char *hostname,
                                    const char *bindhost,
                                    int port,
-                                   uint32 timeout_secs,
+                                   SilcUInt32 timeout_secs,
                                    SilcKeyAgreementCallback completion,
                                    void *context);
 
@@ -1899,10 +1955,10 @@ typedef enum {
  *                                          SilcClientConnection conn,
  *                                          SilcClientMonitorStatus status,
  *                                          SilcClientFileError error,
- *                                          uint64 offset,
- *                                          uint64 filesize,
+ *                                          SilcUInt64 offset,
+ *                                          SilcUInt64 filesize,
  *                                          SilcClientEntry client_entry,
- *                                          uint32 session_id,
+ *                                          SilcUInt32 session_id,
  *                                          const char *filepath,
  *                                          void *context);
  *
@@ -1922,10 +1978,10 @@ typedef void (*SilcClientFileMonitor)(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcClientMonitorStatus status,
                                      SilcClientFileError error,
-                                     uint64 offset,
-                                     uint64 filesize,
+                                     SilcUInt64 offset,
+                                     SilcUInt64 filesize,
                                      SilcClientEntry client_entry,
-                                     uint32 session_id,
+                                     SilcUInt32 session_id,
                                      const char *filepath,
                                      void *context);
 
@@ -1939,10 +1995,10 @@ typedef void (*SilcClientFileMonitor)(SilcClient client,
  *                          SilcClientFileMonitor monitor,
  *                          void *monitor_context,
  *                          const char *local_ip,
- *                          uint32 local_port,
+ *                          SilcUInt32 local_port,
  *                          SilcClientEntry client_entry,
  *                          const char *filepath);
- *                          uint32 *session_id);
+ *                          SilcUInt32 *session_id);
  *
  * DESCRIPTION
  *
@@ -1977,10 +2033,10 @@ silc_client_file_send(SilcClient client,
                      SilcClientFileMonitor monitor,
                      void *monitor_context,
                      const char *local_ip,
-                     uint32 local_port,
+                     SilcUInt32 local_port,
                      SilcClientEntry client_entry,
                      const char *filepath,
-                     uint32 *session_id);
+                     SilcUInt32 *session_id);
 
 /****f* silcclient/SilcClientAPI/silc_client_file_receive
  *
@@ -1991,7 +2047,7 @@ silc_client_file_send(SilcClient client,
  *                             SilcClientConnection conn,
  *                             SilcClientFileMonitor monitor,
  *                             void *monitor_context,
- *                             uint32 session_id);
+ *                             SilcUInt32 session_id);
  *
  * DESCRIPTION
  *
@@ -2013,7 +2069,7 @@ silc_client_file_receive(SilcClient client,
                         SilcClientConnection conn,
                         SilcClientFileMonitor monitor,
                         void *monitor_context,
-                        uint32 session_id);
+                        SilcUInt32 session_id);
 
 /****f* silcclient/SilcClientAPI/silc_client_file_close
  *
@@ -2021,7 +2077,7 @@ silc_client_file_receive(SilcClient client,
  *
  *    SilcClientFileError silc_client_file_close(SilcClient client,
  *                                               SilcClientConnection conn,
- *                                               uint32 session_id);
+ *                                               SilcUInt32 session_id);
  *
  * DESCRIPTION
  *
@@ -2034,7 +2090,7 @@ silc_client_file_receive(SilcClient client,
  ***/
 SilcClientFileError silc_client_file_close(SilcClient client,
                                           SilcClientConnection conn,
-                                          uint32 session_id);
+                                          SilcUInt32 session_id);
 
 #include "client.h"
 #include "command.h"