Merged from silc_1_0_branch.
[silc.git] / lib / silcclient / silcclient.h
index 2783f4567b5110186b905446c5c9daf0b6eb5d49..d87dff84b92f2054edc34d15498df2fa459195e0 100644 (file)
@@ -215,7 +215,9 @@ struct SilcClientEntryStruct {
   /* Private message keys */
   SilcCipher send_key;         /* Private message key for sending */
   SilcCipher receive_key;      /* Private message key for receiving */
-  unsigned char *key;          /* Set only if appliation provided the
+  SilcHmac hmac_send;          /* Private mesage key HMAC for sending */
+  SilcHmac hmac_receive;       /* Private mesage key HMAC for receiving */
+  unsigned char *key;          /* Set only if application provided the
                                   key material. NULL if the library 
                                   generated the key. */
   SilcUInt32 key_len;          /* Key length */
@@ -289,7 +291,7 @@ struct SilcChannelEntryStruct {
  * SOURCE
  */
 struct SilcServerEntryStruct {
-  /* Generate information */
+  /* General information */
   char *server_name;                        /* Server name */
   char *server_info;                        /* Server info */
   SilcServerID *server_id;                  /* Server ID */
@@ -536,7 +538,7 @@ typedef struct {
      (like it may tell the message is multimedia message). */
   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
                          SilcClientEntry sender, SilcChannelEntry channel, 
-                         SilcMessageFlags flags,
+                         SilcMessagePayload payload, SilcMessageFlags flags,
                          const unsigned char *message,
                          SilcUInt32 message_len);
 
@@ -546,7 +548,8 @@ typedef struct {
      can be interpreted (like it may tell the message is multimedia 
      message). */
   void (*private_message)(SilcClient client, SilcClientConnection conn,
-                         SilcClientEntry sender, SilcMessageFlags flags,
+                         SilcClientEntry sender, SilcMessagePayload payload,
+                         SilcMessageFlags flags,
                          const unsigned char *message,
                          SilcUInt32 message_len);
 
@@ -853,7 +856,7 @@ void silc_client_free(SilcClient client);
  *
  * SYNOPSIS
  *
- *    int silc_client_init(SilcClient client);
+ *    bool silc_client_init(SilcClient client);
  *
  * DESCRIPTION
  *
@@ -862,7 +865,7 @@ void silc_client_free(SilcClient client);
  *    client. Returns FALSE if error occurred, TRUE otherwise.
  *
  ***/
-int silc_client_init(SilcClient client);
+bool silc_client_init(SilcClient client);
 
 /****f* silcclient/SilcClientAPI/silc_client_run
  *
@@ -952,7 +955,7 @@ typedef struct {
  *
  * SYNOPSIS
  *
- *    int silc_client_connect_to_server(SilcClient client, 
+ *    bool silc_client_connect_to_server(SilcClient client, 
  *                                      SilcClientConnectionParams *params,
  *                                      int port, char *host, void *context);
  *
@@ -969,9 +972,9 @@ typedef struct {
  *    If the `params' is provided they are used by the routine.
  *
  ***/
-int silc_client_connect_to_server(SilcClient client, 
-                                 SilcClientConnectionParams *params,
-                                 int port, char *host, void *context);
+bool silc_client_connect_to_server(SilcClient client, 
+                                  SilcClientConnectionParams *params,
+                                  int port, char *host, void *context);
 
 /****f* silcclient/SilcClientAPI/silc_client_add_connection
  *
@@ -1107,7 +1110,7 @@ void silc_client_close_connection(SilcClient client,
  *                                          SilcMessageFlags flags,
  *                                          unsigned char *data, 
  *                                          SilcUInt32 data_len, 
- *                                          int force_send);
+ *                                          bool_force_send);
  *
  * DESCRIPTION
  *
@@ -1124,6 +1127,9 @@ void silc_client_close_connection(SilcClient client,
  *    keys are set then the first key (the key that was added first as
  *    private key) is used. 
  *
+ *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
+ *    digitally signed with the SILC key pair.
+ *
  ***/
 void silc_client_send_channel_message(SilcClient client, 
                                      SilcClientConnection conn,
@@ -1132,7 +1138,7 @@ void silc_client_send_channel_message(SilcClient client,
                                      SilcMessageFlags flags,
                                      unsigned char *data, 
                                      SilcUInt32 data_len, 
-                                     int force_send);
+                                     bool force_send);
 
 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
  *
@@ -1144,7 +1150,7 @@ void silc_client_send_channel_message(SilcClient client,
  *                                          SilcMessageFlags flags,
  *                                          unsigned char *data, 
  *                                          SilcUInt32 data_len, 
- *                                          int force_send);
+ *                                          bool force_send);
  *
  * DESCRIPTION
  *
@@ -1156,6 +1162,9 @@ void silc_client_send_channel_message(SilcClient client,
  *    message. The `data' is the private message. If the `force_send' is
  *    TRUE the packet is sent immediately. 
  *
+ *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
+ *    digitally signed with the SILC key pair.
+ *
  ***/
 void silc_client_send_private_message(SilcClient client,
                                      SilcClientConnection conn,
@@ -1163,7 +1172,7 @@ void silc_client_send_private_message(SilcClient client,
                                      SilcMessageFlags flags,
                                      unsigned char *data, 
                                      SilcUInt32 data_len, 
-                                     int force_send);
+                                     bool force_send);
 
 
 /* Client and Channel entry retrieval (idlist.c) */
@@ -1533,7 +1542,7 @@ SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
  *
  * SYNOPSIS
  *
- *    void silc_client_command_call(SilcClient client,
+ *    bool silc_client_command_call(SilcClient client,
  *                                  SilcClientConnection conn,
  *                                  const char *command_line, ...);
  *
@@ -1619,6 +1628,9 @@ void silc_client_command_send(SilcClient client, SilcClientConnection conn,
  *    called when an command reply is received to an earlier sent command.
  *    The `reply_cmd' is the command that must be received in order for
  *    the pending command callback indicated by `callback' to be called.
+ *    The `callback' will deliver the `context' and 
+ *    SilcClientCommandReplyContext which includes the internals of the 
+ *    command reply.
  *
  *    The `ident' is a command identifier which was set for the earlier
  *    sent command.  The command reply will include the same identifier
@@ -1664,14 +1676,15 @@ void silc_client_command_pending(SilcClientConnection conn,
  *
  * SYNOPSIS
  *
- *    int silc_client_add_private_message_key(SilcClient client,
- *                                            SilcClientConnection conn,
- *                                            SilcClientEntry client_entry,
- *                                            char *cipher,
- *                                            unsigned char *key,
- *                                            SilcUInt32 key_len,
- *                                            bool generate_key,
- *                                            bool responder);
+ *    bool silc_client_add_private_message_key(SilcClient client,
+ *                                             SilcClientConnection conn,
+ *                                             SilcClientEntry client_entry,
+ *                                             const char *cipher,
+ *                                             const char *hmac,
+ *                                             unsigned char *key,
+ *                                             SilcUInt32 key_len,
+ *                                             bool generate_key,
+ *                                             bool responder);
  *
  * DESCRIPTION
  *
@@ -1680,9 +1693,9 @@ void silc_client_command_pending(SilcClientConnection conn,
  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
  *    value `generate_key' is TRUE the library will generate random key.
  *    The `key' maybe for example pre-shared-key, passphrase or similar.
- *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
- *    requirements of the SILC protocol are met. The API, however, allows
- *    to allocate any cipher.
+ *    The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
+ *    that the requirements of the SILC protocol are met. The API, however,
+ *    allows to allocate any cipher and HMAC.
  *
  *    If `responder' is TRUE then the sending and receiving keys will be
  *    set according the client being the receiver of the private key.  If
@@ -1697,48 +1710,52 @@ void silc_client_command_pending(SilcClientConnection conn,
  *    otherwise. 
  *
  ***/
-int silc_client_add_private_message_key(SilcClient client,
-                                       SilcClientConnection conn,
-                                       SilcClientEntry client_entry,
-                                       char *cipher,
-                                       unsigned char *key,
-                                       SilcUInt32 key_len,
-                                       bool generate_key,
-                                       bool responder);
+bool silc_client_add_private_message_key(SilcClient client,
+                                        SilcClientConnection conn,
+                                        SilcClientEntry client_entry,
+                                        const char *cipher,
+                                        const char *hmac,
+                                        unsigned char *key,
+                                        SilcUInt32 key_len,
+                                        bool generate_key,
+                                        bool responder);
 
 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
  *
  * SYNOPSIS
  *
- *    int silc_client_add_private_message_key_ske(SilcClient client,
- *                                                SilcClientConnection conn,
- *                                                SilcClientEntry client_entry,
- *                                                char *cipher,
- *                                                SilcSKEKeyMaterial *key);
+ *    bool
+ *    silc_client_add_private_message_key_ske(SilcClient client,
+ *                                            SilcClientConnection conn,
+ *                                            SilcClientEntry client_entry,
+ *                                            const char *cipher,
+ *                                            const char *hmac,
+ *                                            SilcSKEKeyMaterial *key);
  *
  * DESCRIPTION
  *
  *    Same as silc_client_add_private_message_key but takes the key material
  *    from the SKE key material structure. This structure is received if
  *    the application uses the silc_client_send_key_agreement to negotiate
- *    the key material. The `cipher' SHOULD be provided as it is negotiated
- *    also in the SKE protocol. 
+ *    the key material. The `cipher' and `hmac' SHOULD be provided as it is
+ *    negotiated also in the SKE protocol. 
  *
  ***/
-int silc_client_add_private_message_key_ske(SilcClient client,
-                                           SilcClientConnection conn,
-                                           SilcClientEntry client_entry,
-                                           char *cipher,
-                                           SilcSKEKeyMaterial *key,
-                                           bool responder);
+bool silc_client_add_private_message_key_ske(SilcClient client,
+                                            SilcClientConnection conn,
+                                            SilcClientEntry client_entry,
+                                            const char *cipher,
+                                            const char *hmac,
+                                            SilcSKEKeyMaterial *key,
+                                            bool responder);
 
 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
  *
  * SYNOPSIS
  *
- *    int silc_client_del_private_message_key(SilcClient client,
- *                                            SilcClientConnection conn,
- *                                            SilcClientEntry client_entry);
+ *    bool silc_client_del_private_message_key(SilcClient client,
+ *                                             SilcClientConnection conn,
+ *                                             SilcClientEntry client_entry);
  *
  * DESCRIPTION
  *
@@ -1747,9 +1764,9 @@ int silc_client_add_private_message_key_ske(SilcClient client,
  *    client. Returns FALSE on error, TRUE otherwise. 
  *
  ***/
-int silc_client_del_private_message_key(SilcClient client,
-                                       SilcClientConnection conn,
-                                       SilcClientEntry client_entry);
+bool silc_client_del_private_message_key(SilcClient client,
+                                        SilcClientConnection conn,
+                                        SilcClientEntry client_entry);
 
 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
  *
@@ -1800,14 +1817,14 @@ void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
  *
  * SYNOPSIS
  *
- *    int silc_client_add_channel_private_key(SilcClient client,
- *                                            SilcClientConnection conn,
- *                                            SilcChannelEntry channel,
- *                                            const char *name,
- *                                            char *cipher,
- *                                            char *hmac,
- *                                            unsigned char *key,
- *                                            SilcUInt32 key_len);
+ *    bool silc_client_add_channel_private_key(SilcClient client,
+ *                                             SilcClientConnection conn,
+ *                                             SilcChannelEntry channel,
+ *                                             const char *name,
+ *                                             char *cipher,
+ *                                             char *hmac,
+ *                                             unsigned char *key,
+ *                                             SilcUInt32 key_len);
  * 
  * DESCRIPTION
  *
@@ -1841,22 +1858,22 @@ void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
  *    as channel private key. However, this API allows it. 
  *
  ***/
-int silc_client_add_channel_private_key(SilcClient client,
-                                       SilcClientConnection conn,
-                                       SilcChannelEntry channel,
-                                       const char *name,
-                                       char *cipher,
-                                       char *hmac,
-                                       unsigned char *key,
-                                       SilcUInt32 key_len);
+bool silc_client_add_channel_private_key(SilcClient client,
+                                        SilcClientConnection conn,
+                                        SilcChannelEntry channel,
+                                        const char *name,
+                                        char *cipher,
+                                        char *hmac,
+                                        unsigned char *key,
+                                        SilcUInt32 key_len);
 
 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
  *
  * SYNOPSIS
  *
- *    int silc_client_del_channel_private_keys(SilcClient client,
- *                                             SilcClientConnection conn,
- *                                             SilcChannelEntry channel);
+ *    bool silc_client_del_channel_private_keys(SilcClient client,
+ *                                              SilcClientConnection conn,
+ *                                              SilcChannelEntry channel);
  * 
  * DESCRIPTION
  *
@@ -1865,15 +1882,15 @@ int silc_client_add_channel_private_key(SilcClient client,
  *    on error, TRUE otherwise. 
  *
  ***/
-int silc_client_del_channel_private_keys(SilcClient client,
-                                        SilcClientConnection conn,
-                                        SilcChannelEntry channel);
+bool silc_client_del_channel_private_keys(SilcClient client,
+                                         SilcClientConnection conn,
+                                         SilcChannelEntry channel);
 
 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
  *
  * SYNOPSIS
  *
- *    int silc_client_del_channel_private_key(SilcClient client,
+ *    bool silc_client_del_channel_private_key(SilcClient client,
  *                                            SilcClientConnection conn,
  *                                            SilcChannelEntry channel,
  *                                            SilcChannelPrivateKey key);
@@ -1888,10 +1905,10 @@ int silc_client_del_channel_private_keys(SilcClient client,
  *    on error, TRUE otherwise. 
  *
  ***/
-int silc_client_del_channel_private_key(SilcClient client,
-                                       SilcClientConnection conn,
-                                       SilcChannelEntry channel,
-                                       SilcChannelPrivateKey key);
+bool silc_client_del_channel_private_key(SilcClient client,
+                                        SilcClientConnection conn,
+                                        SilcChannelEntry channel,
+                                        SilcChannelPrivateKey key);
 
 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
  *
@@ -2295,6 +2312,7 @@ typedef void (*SilcClientFileMonitor)(SilcClient client,
  *                          void *monitor_context,
  *                          const char *local_ip,
  *                          SilcUInt32 local_port,
+ *                          bool do_not_bind,
  *                          SilcClientEntry client_entry,
  *                          const char *filepath);
  *                          SilcUInt32 *session_id);
@@ -2308,7 +2326,7 @@ typedef void (*SilcClientFileMonitor)(SilcClient client,
  *    transmission of the file.
  *
  *    This returns a file session ID for the file transmission to the
- *    `session_id' pointer..  It can be used to close the session (and
+ *    `session_id' pointer.  It can be used to close the session (and
  *    abort the file transmission) by calling the silc_client_file_close
  *    function.  The session ID is also returned in the `monitor' callback. 
  *
@@ -2316,9 +2334,9 @@ typedef void (*SilcClientFileMonitor)(SilcClient client,
  *    listener for key exchange protocol to that IP.  If `local_port' is
  *    non-zero that port is used.  If `local_ip' is NULL then this will
  *    automatically attempt to bind it to local IP address of the machine.
- *    If that fails then this does not bind to any address and port, and
- *    assume that the remote client will provide the listener for the
- *    key exchange protocol.
+ *    If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
+ *    ignored and it is expected that the receiver will provide the
+ *    point of contact.  This is usefull if the sender is behind NAT.
  *
  *    If error will occur during the file transfer process the error
  *    status will be returned in the monitor callback.  In this case
@@ -2333,6 +2351,7 @@ silc_client_file_send(SilcClient client,
                      void *monitor_context,
                      const char *local_ip,
                      SilcUInt32 local_port,
+                     bool do_not_bind,
                      SilcClientEntry client_entry,
                      const char *filepath,
                      SilcUInt32 *session_id);