updates. New data types.
[silc.git] / lib / silcclient / silcapi.h
index bdef1c76076a424672fccc8b27b6a84597b4a730..17bb058aa6e6614dfd7c6adef1bb5d0b59e8cbad 100644 (file)
 
 /* General definitions */
 
+/* Key agreement status types indicating the status of the protocol. */
+typedef enum {
+  SILC_KEY_AGREEMENT_OK,              /* Everything is Ok */
+  SILC_KEY_AGREEMENT_ERROR,           /* Unknown error occured */
+  SILC_KEY_AGREEMENT_FAILURE,         /* The protocol failed */
+  SILC_KEY_AGREEMENT_TIMEOUT,         /* The protocol timeout */
+} SilcKeyAgreementStatus;
+
 /* Key agreement callback that is called after the key agreement protocol
    has been performed. This is called also if error occured during the
    key agreement protocol. The `key' is the allocated key material and
@@ -47,6 +55,7 @@
 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
                                         SilcClientConnection conn,
                                         SilcClientEntry client_entry,
+                                        SilcKeyAgreementStatus status,
                                         SilcSKEKeyMaterial *key,
                                         void *context);
 
@@ -60,7 +69,7 @@ typedef struct {
                                         provided it. This is NULL if the
                                         library generated the key or if
                                         the SKE key material was used. */
-  unsigned int key_len;                      /* The key length */
+  uint32 key_len;                    /* The key length */
 } *SilcPrivateMessageKeys;
 
 /******************************************************************************
@@ -85,12 +94,13 @@ typedef struct {
      The `channel' is the channel. */
   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
                          SilcClientEntry sender, SilcChannelEntry channel, 
-                         char *msg);
+                         SilcMessageFlags flags, char *msg);
 
   /* Private message to the client. The `sender' is the sender of the
      message. */
   void (*private_message)(SilcClient client, SilcClientConnection conn,
-                         SilcClientEntry sender, char *msg);
+                         SilcClientEntry sender, SilcMessageFlags flags,
+                         char *msg);
 
   /* Notify message to the client. The notify arguments are sent in the
      same order as servers sends them. The arguments are same as received
@@ -149,18 +159,19 @@ typedef struct {
      and `auth_data_len'. The function returns TRUE if authentication method
      is found and FALSE if not. `conn' may be NULL. */
   int (*get_auth_method)(SilcClient client, SilcClientConnection conn,
-                        char *hostname, unsigned short port,
+                        char *hostname, uint16 port,
                         SilcProtocolAuthMeth *auth_meth,
                         unsigned char **auth_data,
-                        unsigned int *auth_data_len);
+                        uint32 *auth_data_len);
 
-  /* Verifies received public key. The public key has been received from
-     a server. If user decides to trust the key may be saved as trusted
-     server key for later use. If user does not trust the key this returns
-     FALSE. If everything is Ok this returns TRUE. */ 
-  int (*verify_server_key)(SilcClient client, SilcClientConnection conn,
-                          unsigned char *pk, unsigned int pk_len,
-                          SilcSKEPKType pk_type);
+  /* Verifies received public key. The `conn_type' indicates which entity
+     (server, client etc.) has sent the public key. If user decides to trust
+     the key may be saved as trusted public key for later use. If user does
+     not trust the key this returns FALSE. If everything is Ok this returns
+     TRUE. */ 
+  int (*verify_public_key)(SilcClient client, SilcClientConnection conn,
+                          SilcSocketType conn_type, unsigned char *pk, 
+                          uint32 pk_len, SilcSKEPKType pk_type);
 
   /* Ask (interact, that is) a passphrase from user. Returns the passphrase
      or NULL on error. */
@@ -255,6 +266,14 @@ SilcClientConnection silc_client_add_connection(SilcClient client,
 /* Removes connection from client. Frees all memory. */
 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
 
+/* Adds listener socket to the listener sockets table. This function is
+   used to add socket objects that are listeners to the client.  This should
+   not be used to add other connection objects. */
+void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
+
+/* Deletes listener socket from the listener sockets table. */
+void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
+
 /* Start SILC Key Exchange (SKE) protocol to negotiate shared secret
    key material between client and server.  This function can be called
    directly if application is performing its own connecting and does not
@@ -266,8 +285,14 @@ int silc_client_start_key_exchange(SilcClient client,
                                    int fd);
 
 /* Closes connection to remote end. Free's all allocated data except
-   for some information such as nickname etc. that are valid at all time. */
+   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);
 
 
@@ -289,8 +314,9 @@ void silc_client_send_channel_message(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcChannelEntry channel,
                                      SilcChannelPrivateKey key,
+                                     SilcMessageFlags flags,
                                      unsigned char *data, 
-                                     unsigned int data_len, 
+                                     uint32 data_len, 
                                      int force_send);
 
 /* Sends private message to remote client. If private message key has
@@ -303,8 +329,9 @@ void silc_client_send_channel_message(SilcClient client,
 void silc_client_send_private_message(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcClientEntry client_entry,
+                                     SilcMessageFlags flags,
                                      unsigned char *data, 
-                                     unsigned int data_len, 
+                                     uint32 data_len, 
                                      int force_send);
 
 
@@ -317,7 +344,7 @@ void silc_client_send_private_message(SilcClient client,
 typedef void (*SilcGetClientCallback)(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcClientEntry *clients,
-                                     unsigned int clients_count,
+                                     uint32 clients_count,
                                      void *context);
 
 /* Finds client entry or entries by the `nickname' and `server'. The 
@@ -341,7 +368,7 @@ SilcClientEntry *silc_client_get_clients_local(SilcClient client,
                                               SilcClientConnection conn,
                                               char *nickname,
                                               char *server,
-                                              unsigned int *clients_count);
+                                              uint32 *clients_count);
 
 /* Gets client entries by the list of client ID's `client_id_list'. This
    always resolves those client ID's it does not know yet from the server
@@ -351,7 +378,7 @@ SilcClientEntry *silc_client_get_clients_local(SilcClient client,
    will be called after the entries are available. */
 void silc_client_get_clients_by_list(SilcClient client,
                                     SilcClientConnection conn,
-                                    unsigned int list_count,
+                                    uint32 list_count,
                                     SilcBuffer client_id_list,
                                     SilcGetClientCallback completion,
                                     void *context);
@@ -402,8 +429,8 @@ SilcClientCommand *silc_client_command_find(const char *name);
 /* Generic function to send any command. The arguments must be sent already
    encoded into correct form and in correct order. */
 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
-                             SilcCommand command, unsigned short ident,
-                             unsigned int argc, ...);
+                             SilcCommand command, uint16 ident,
+                             uint32 argc, ...);
 
 /* Pending Command callback destructor. This is called after calling the
    pending callback or if error occurs while processing the pending command.
@@ -419,7 +446,7 @@ typedef void (*SilcClientPendingDestructor)(void *context);
    identifier `ident'. */
 void silc_client_command_pending(SilcClientConnection conn,
                                 SilcCommand reply_cmd,
-                                unsigned short ident,
+                                uint16 ident,
                                 SilcClientPendingDestructor destructor,
                                 SilcCommandCb callback,
                                 void *context);
@@ -447,7 +474,7 @@ int silc_client_add_private_message_key(SilcClient client,
                                        SilcClientEntry client_entry,
                                        char *cipher,
                                        unsigned char *key,
-                                       unsigned int key_len,
+                                       uint32 key_len,
                                        int generate_key);
 
 /* Same as above but takes the key material from the SKE key material
@@ -492,12 +519,12 @@ int silc_client_del_private_message_key(SilcClient client,
 SilcPrivateMessageKeys
 silc_client_list_private_message_keys(SilcClient client,
                                      SilcClientConnection conn,
-                                     unsigned int *key_count);
+                                     uint32 *key_count);
 
 /* Frees the SilcPrivateMessageKeys array returned by the function
    silc_client_list_private_message_keys. */
 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
-                                          unsigned int key_count);
+                                          uint32 key_count);
 
 
 /* Channel private key management (client_channel.c, 
@@ -534,7 +561,7 @@ int silc_client_add_channel_private_key(SilcClient client,
                                        char *cipher,
                                        char *hmac,
                                        unsigned char *key,
-                                       unsigned int key_len);
+                                       uint32 key_len);
 
 /* Removes all private keys from the `channel'. The old channel key is used
    after calling this to protect the channel messages. Returns FALSE on
@@ -562,11 +589,11 @@ SilcChannelPrivateKey *
 silc_client_list_channel_private_keys(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcChannelEntry channel,
-                                     unsigned int *key_count);
+                                     uint32 *key_count);
 
 /* Frees the SilcChannelPrivateKey array. */
 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
-                                          unsigned int key_count);
+                                          uint32 key_count);
 
 
 /* Key Agreement routines (client_keyagr.c) */
@@ -609,7 +636,7 @@ void silc_client_send_key_agreement(SilcClient client,
                                    SilcClientEntry client_entry,
                                    char *hostname,
                                    int port,
-                                   unsigned long timeout_secs,
+                                   uint32 timeout_secs,
                                    SilcKeyAgreementCallback completion,
                                    void *context);
 
@@ -648,6 +675,7 @@ void silc_client_perform_key_agreement_fd(SilcClient client,
                                          SilcClientConnection conn,
                                          SilcClientEntry client_entry,
                                          int sock,
+                                         char *hostname,
                                          SilcKeyAgreementCallback completion,
                                          void *context);