076cbdc664ab91515a726efe317ae4538a614485
[silc.git] / lib / silcclient / silcclient.h
1 /*
2
3   silcclient.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2000 - 2004 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcclient/Client Library Interface
21  *
22  * DESCRIPTION
23  *
24  * This interface defines the SILC Client Library API for the application.
25  * The client operations are defined first.  These are callback functions that
26  * the application MUST implement since the library may call the functions
27  * at any time.  At the end of file is the API for the application that
28  * it can use from the library.  This is the only file that the application
29  * may include from the SIlC Client Library.
30  *
31  * o SILC Client Operations
32  *
33  *   These functions must be implemented by the application calling the SILC
34  *   client library. The client library can call these functions at any time.
35  *
36  *   To use this structure: define a static SilcClientOperations variable,
37  *   fill it and pass its pointer to silc_client_alloc function.
38  *
39  * o SILC Client Library API
40  *
41  *   This is the API that is published by the SILC Client Library for the
42  *   applications.  These functions are implemented in the SILC Client Library.
43  *   Application may freely call these functions from the library.
44  *
45  * Please, refer to the README file in this directory for the directions
46  * of how to use the SILC Client Library.
47  *
48  ***/
49
50 #ifndef SILCCLIENT_H
51 #define SILCCLIENT_H
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 #include "client.h"
58
59 /* General definitions */
60
61 /****s* silcclient/SilcClientAPI/SilcClient
62  *
63  * NAME
64  *
65  *    typedef struct SilcClientStruct { ... } *SilcClient
66  *
67  * DESCRIPTION
68  *
69  *    This is the actual SILC Client structure which represents one
70  *    SILC Client.  It is allocated with the silc_client_alloc function
71  *    and given as argument to all SILC Client Library functions.  It
72  *    is initialized with silc_client_init function, and freed with
73  *    silc_client_free function.
74  *
75  * SOURCE
76  */
77 struct SilcClientStruct {
78   /*
79    * The following fields are set by application
80    */
81   char *nickname;               /* Nickname, MAY be set by application  */
82   char *username;               /* Username, MUST be set by application */
83   char *hostname;               /* hostname, MUST be set by application */
84   char *realname;               /* Real name, MUST be set be application */
85
86   SilcPublicKey public_key;     /* Public key of user, set by application */
87   SilcPrivateKey private_key;   /* Private key of user, set by application */
88   SilcPKCS pkcs;                /* PKCS allocated by application */
89
90   /*
91    * The following fields are set by the library
92    */
93
94   /* Scheduler, set by library.  Application may use this pointer. */
95   SilcSchedule schedule;
96
97   /* Random Number Generator. Application should use this as its primary
98      random number generator. */
99   SilcRng rng;
100
101   /* Application specific user data pointer. Client library does not
102      touch this.  This the context sent as argument to silc_client_alloc.
103      Application can use it freely. */
104   void *application;
105
106   /* Generic hash context for application usage */
107   SilcHash md5hash;
108   SilcHash sha1hash;
109
110   /* Internal data for client library. Application cannot access this
111      data at all. */
112   SilcClientInternal internal;
113 };
114 /***/
115
116 /****s* silcclient/SilcClientAPI/SilcClientConnection
117  *
118  * NAME
119  *
120  *    typedef struct SilcClientConnectionStruct { ... }
121  *                      *SilcClientConnection
122  *
123  * DESCRIPTION
124  *
125  *    This structure represents a connection.  When connection is created
126  *    to server this is context is returned to the application in the
127  *    "connected" client operation.  It includes all the important
128  *    data for the session, such as nickname, local and remote IDs, and
129  *    other information.
130  *
131  * SOURCE
132  */
133 struct SilcClientConnectionStruct {
134   /*
135    * Local data
136    */
137   char *nickname;                 /* Current nickname */
138   SilcClientEntry local_entry;    /* Own Client Entry */
139   SilcClientID *local_id;         /* Current Client ID */
140   unsigned char *local_id_data;   /* Current Client ID decoded */
141   SilcUInt32 local_id_data_len;
142
143   /*
144    * Remote data
145    */
146   char *remote_host;              /* Remote host name */
147   int remote_port;                /* Remote port */
148   SilcServerID *remote_id;        /* Remote Server ID */
149   unsigned char *remote_id_data;  /* Remote Server ID decoded */
150   SilcUInt32 remote_id_data_len;
151
152   /*
153    * Common data
154    */
155
156   /* Current command identifier for a command that was sent last.
157      Application may get the value from this variable to find out the
158      command identifier for last command. */
159   SilcUInt16 cmd_ident;
160
161   /* User data context. Library does not touch this. Application may
162      freely set and use this pointer for its needs. */
163   void *context;
164
165   /* Pointer back to the SilcClient.  Application may use this. */
166   SilcClient client;
167
168   /* Current channel.  Application may use and set this pointer if needed. */
169   SilcChannelEntry current_channel;
170
171   /* Socket connection object for this connection.  Application may
172      use this if needed.  The sock->user_data is back pointer to this
173      structure. */
174   SilcSocketConnection sock;
175
176   /* Internal data for client library. Application cannot access this
177      data at all. */
178   SilcClientConnectionInternal internal;
179 };
180 /***/
181
182 /****s* silcclient/SilcClientAPI/SilcClientEntry
183  *
184  * NAME
185  *
186  *    typedef struct SilcClientEntryStruct { ... } *SilcClientEntry
187  *
188  * DESCRIPTION
189  *
190  *    This structure represents a client or a user in the SILC network.
191  *    The local user has this structure also and it can be accessed from
192  *    SilcClientConnection structure.  All other users in the SILC network
193  *    that are accessed using the Client Library routines will have their
194  *    own SilcClientEntry structure.  For example, when finding users by
195  *    their nickname the Client Library returns this structure back to
196  *    the application.
197  *
198  * SOURCE
199  */
200 struct SilcClientEntryStruct {
201   /* General information */
202   char *nickname;               /* nickname */
203   char *username;               /* username */
204   char *hostname;               /* hostname */
205   char *server;                 /* SILC server name */
206   char *realname;               /* Realname (userinfo) */
207
208   /* Mode, ID and other information */
209   SilcUInt32 mode;              /* User mode in SILC, see SilcUserMode */
210   SilcClientID *id;             /* The Client ID */
211   SilcDList attrs;              /* Requested Attributes (maybe NULL) */
212   unsigned char *fingerprint;   /* Fingerprint of client's public key */
213   SilcUInt32 fingerprint_len;   /* Length of the fingerprint */
214
215   /* Private message keys */
216   SilcCipher send_key;          /* Private message key for sending */
217   SilcCipher receive_key;       /* Private message key for receiving */
218   SilcHmac hmac_send;           /* Private mesage key HMAC for sending */
219   SilcHmac hmac_receive;        /* Private mesage key HMAC for receiving */
220   unsigned char *key;           /* Set only if application provided the
221                                    key material. NULL if the library
222                                    generated the key. */
223   SilcUInt32 key_len;           /* Key length */
224   SilcClientKeyAgreement ke;    /* Current key agreement context or NULL */
225
226   /* SilcClientEntry status information */
227   SilcEntryStatus status;       /* Status mask */
228   SilcHashTable channels;       /* All channels client has joined */
229   SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
230   bool generated;               /* TRUE if library generated `key' */
231   bool valid;                   /* FALSE if this entry is not valid */
232
233   /* Application specific data.  Application may set here whatever it wants. */
234   void *context;
235 };
236 /***/
237
238 /****s* silcclient/SilcClientAPI/SilcChannelEntry
239  *
240  * NAME
241  *
242  *    typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
243  *
244  * DESCRIPTION
245  *
246  *    This structure represents a channel in the SILC network.  All
247  *    channels that the client are aware of or have joined in will be
248  *    represented as SilcChannelEntry.  The structure includes information
249  *    about the channel.
250  *
251  * SOURCE
252  */
253 struct SilcChannelEntryStruct {
254   /* General information */
255   char *channel_name;                        /* Channel name */
256   SilcChannelID *id;                         /* Channel ID */
257   SilcUInt32 mode;                           /* Channel mode, ChannelModes. */
258
259   /* All clients that has joined this channel.  The key to the table is the
260      SilcClientEntry and the context is SilcChannelUser context. */
261   SilcHashTable user_list;
262
263   /* Channel keys */
264   SilcCipher channel_key;                    /* The channel key */
265   unsigned char *key;                        /* Raw key data */
266   SilcUInt32 key_len;                        /* Raw key data length */
267   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
268   SilcHmac hmac;                             /* Current HMAC */
269
270   /* Channel private keys */
271   SilcDList private_keys;                    /* List of private keys or NULL */
272   SilcChannelPrivateKey curr_key;            /* Current private key */
273
274   /* SilcChannelEntry status information */
275   SilcDList old_channel_keys;
276   SilcDList old_hmacs;
277   SilcUInt16 resolve_cmd_ident;              /* Command identifier when
278                                                 resolving this entry */
279
280   /* Application specific data.  Application may set here whatever it wants. */
281   void *context;
282 };
283 /***/
284
285 /****s* silcclient/SilcClientAPI/SilcChannelUser
286  *
287  * NAME
288  *
289  *    typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
290  *
291  * DESCRIPTION
292  *
293  *    This structure represents a client that has joined to a channel.
294  *    It shows the client and the channel and the client's mode (channel
295  *    user mode) on the channel.
296  *
297  * SOURCE
298  */
299 struct SilcChannelUserStruct {
300   SilcClientEntry client;                    /* Client joined on channel */
301   SilcUInt32 mode;                           /* mode, ChannelUserModes */
302   SilcChannelEntry channel;                  /* The channel user has joined */
303
304   /* Application specific data.  Application may set here whatever it wants. */
305   void *context;
306 };
307 /***/
308
309 /****s* silcclient/SilcClientAPI/SilcServerEntry
310  *
311  * NAME
312  *
313  *    typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
314  *
315  * DESCRIPTION
316  *
317  *    This structure represents a server in the SILC network.  All servers
318  *    that the client is aware of and have for example resolved with
319  *    SILC_COMMAND_INFO command have their on SilcServerEntry structure.
320  *
321  * SOURCE
322  */
323 struct SilcServerEntryStruct {
324   /* General information */
325   char *server_name;                         /* Server name */
326   char *server_info;                         /* Server info */
327   SilcServerID *server_id;                   /* Server ID */
328   SilcUInt16 resolve_cmd_ident;              /* Command identifier when
329                                                 resolving this entry */
330
331   /* Application specific data.  Application may set here whatever it wants. */
332   void *context;
333 };
334 /***/
335
336 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
337  *
338  * NAME
339  *
340  *    typedef enum { ... } SilcKeyAgreementStatus;
341  *
342  * DESCRIPTION
343  *
344  *    Key agreement status types indicating the status of the key
345  *    agreement protocol.  These types are returned to the application
346  *    in the SilcKeyAgreementCallback callback function.
347  *
348  * SOURCE
349  */
350 typedef enum {
351   SILC_KEY_AGREEMENT_OK,               /* Everything is Ok */
352   SILC_KEY_AGREEMENT_ERROR,            /* Unknown error occurred */
353   SILC_KEY_AGREEMENT_FAILURE,          /* The protocol failed */
354   SILC_KEY_AGREEMENT_TIMEOUT,          /* The protocol timeout */
355   SILC_KEY_AGREEMENT_ABORTED,          /* The protocol aborted */
356   SILC_KEY_AGREEMENT_ALREADY_STARTED,  /* Already started */
357   SILC_KEY_AGREEMENT_SELF_DENIED,      /* Negotiationg with itself denied */
358 } SilcKeyAgreementStatus;
359 /***/
360
361 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
362  *
363  * SYNOPSIS
364  *
365  *    typedef void (*SilcKeyAgreementCallback)(SilcClient client,
366  *                                             SilcClientConnection conn,
367  *                                             SilcClientEntry client_entry,
368  *                                             SilcKeyAgreementStatus status,
369  *                                             SilcSKEKeyMaterial *key,
370  *                                             void *context);
371  *
372  * DESCRIPTION
373  *
374  *    Key agreement callback that is called after the key agreement protocol
375  *    has been performed. This is called also if error occurred during the
376  *    key agreement protocol. The `key' is the allocated key material and
377  *    the caller is responsible of freeing it. The `key' is NULL if error
378  *    has occurred. The application can freely use the `key' to whatever
379  *    purpose it needs. See lib/silcske/silcske.h for the definition of
380  *    the SilcSKEKeyMaterial structure.
381  *
382  ***/
383 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
384                                          SilcClientConnection conn,
385                                          SilcClientEntry client_entry,
386                                          SilcKeyAgreementStatus status,
387                                          SilcSKEKeyMaterial *key,
388                                          void *context);
389
390 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
391  *
392  * NAME
393  *
394  *    typedef struct { ... } SilcPrivateMessageKeys;
395  *
396  * DESCRIPTION
397  *
398  *    Structure to hold the list of private message keys. The array of this
399  *    structure is returned by the silc_client_list_private_message_keys
400  *    function.
401  *
402  * SOURCE
403  */
404 typedef struct {
405   SilcClientEntry client_entry;       /* The remote client entry */
406   char *cipher;                       /* The cipher name */
407   unsigned char *key;                 /* The original key, If the appliation
408                                          provided it. This is NULL if the
409                                          library generated the key or if
410                                          the SKE key material was used. */
411   SilcUInt32 key_len;                 /* The key length */
412 } *SilcPrivateMessageKeys;
413 /***/
414
415 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
416  *
417  * NAME
418  *
419  *    typedef struct SilcChannelPrivateKeyStruct { ... }
420  *                      *SilcChannelPrivateKey;
421  *
422  * DESCRIPTION
423  *
424  *    Structure to hold one channel private key. The array of this structure
425  *    is returned by silc_client_list_channel_private_keys function.
426  *
427  * SOURCE
428  */
429 struct SilcChannelPrivateKeyStruct {
430   char *name;                         /* Application given name */
431   SilcCipher cipher;                  /* The cipher and key */
432   SilcHmac hmac;                      /* The HMAC and hmac key */
433   unsigned char *key;                 /* The key data */
434   SilcUInt32 key_len;                 /* The key length */
435 };
436 /***/
437
438 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
439  *
440  * SYNOPSIS
441  *
442  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
443  *                                      SilcUInt32 passphrase_len,
444  *                                      void *context);
445  *
446  * DESCRIPTION
447  *
448  *    Ask passphrase callback. This is called by the application when the
449  *    library calls `ask_passphrase' client operation.  The callback delivers
450  *    the passphrase to the library.  The passphrases in SILC protocol
451  *    MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
452  *    encoded, and if it is not then library will attempt to encode it.
453  *
454  ***/
455 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
456                                   SilcUInt32 passphrase_len,
457                                   void *context);
458
459 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
460  *
461  * SYNOPSIS
462  *
463  *    typedef void (*SilcVerifyPublicKey)(bool success, void *context);
464  *
465  * DESCRIPTION
466  *
467  *    Public key (or certificate) verification callback. This is called
468  *    by the application to indicate that the public key verification was
469  *    either success or failure.
470  *
471  ***/
472 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
473
474 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
475  *
476  * SYNOPSIS
477  *
478  *    typedef void (*SilcGetAuthMeth)(bool success,
479  *                                    SilcProtocolAuthMeth auth_meth,
480  *                                    const unsigned char *auth_data,
481  *                                    SilcUInt32 auth_data_len, void *context);
482  *
483  * DESCRIPTION
484  *
485  *    Authentication method resolving callback. This is called by the
486  *    application to return the resolved authentication method. The client
487  *    library has called the get_auth_method client operation and given
488  *    this function pointer as argument. The `success' will indicate whether
489  *    the authentication method could be resolved. The `auth_meth' is the
490  *    resolved authentication method. The `auth_data' and the `auth_data_len'
491  *    are the resolved authentication data. The `context' is the libary's
492  *    context sent to the get_auth_method client operation.
493  *
494  ***/
495 typedef void (*SilcGetAuthMeth)(bool success,
496                                 SilcProtocolAuthMeth auth_meth,
497                                 const unsigned char *auth_data,
498                                 SilcUInt32 auth_data_len, void *context);
499
500 /****d* silcclient/SilcClientAPI/SilcClientMessageType
501  *
502  * NAME
503  *
504  *    typedef enum { ... } SilcClientMessageType;
505  *
506  * DESCRIPTION
507  *
508  *    Different message types for `say' client operation.  The application
509  *    may filter the message sent by the library according this type.
510  *
511  * SOURCE
512  */
513 typedef enum {
514   SILC_CLIENT_MESSAGE_INFO,            /* Informational */
515   SILC_CLIENT_MESSAGE_WARNING,         /* Warning */
516   SILC_CLIENT_MESSAGE_ERROR,           /* Error */
517   SILC_CLIENT_MESSAGE_AUDIT,           /* Auditable */
518 } SilcClientMessageType;
519 /***/
520
521 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
522  *
523  * NAME
524  *
525  *    typedef enum { ... } SilcClientConnectionStatus
526  *
527  * DESCRIPTION
528  *
529  *    This type is returned to the `connect' client operation to indicate
530  *    the status of the created connection.  It can indicate if it was
531  *    successful or whether an error occurred.
532  *
533  * SOURCE
534  */
535 typedef enum {
536   SILC_CLIENT_CONN_SUCCESS,            /* Successfully connected */
537   SILC_CLIENT_CONN_SUCCESS_RESUME,     /* Successfully connected and
538                                           resumed old detached session */
539   SILC_CLIENT_CONN_ERROR,              /* Unknown error occurred during
540                                           connecting */
541   SILC_CLIENT_CONN_ERROR_KE,           /* Key Exchange failed */
542   SILC_CLIENT_CONN_ERROR_AUTH,         /* Authentication failed */
543   SILC_CLIENT_CONN_ERROR_RESUME,       /* Resuming failed */
544   SILC_CLIENT_CONN_ERROR_TIMEOUT,      /* Timeout during connecting */
545 } SilcClientConnectionStatus;
546 /***/
547
548 /****s* silcclient/SilcClientAPI/SilcClientOperations
549  *
550  * NAME
551  *
552  *    typedef struct { ... } SilcClientOperations;
553  *
554  * DESCRIPTION
555  *
556  *    SILC Client Operations. These must be implemented by the application.
557  *    The Client library may call any of these routines at any time.  The
558  *    routines are used to deliver certain information to the application
559  *    or from the application to the client library.
560  *
561  * SOURCE
562  */
563 typedef struct {
564   /* Message sent to the application by library. `conn' associates the
565      message to a specific connection.  `conn', however, may be NULL.
566      The `type' indicates the type of the message sent by the library.
567      The application can for example filter the message according the
568      type.  The variable argument list is arguments to the formatted
569      message that `msg' may be. */
570   void (*say)(SilcClient client, SilcClientConnection conn,
571               SilcClientMessageType type, char *msg, ...);
572
573   /* Message for a channel. The `sender' is the sender of the message
574      The `channel' is the channel. The `message' is the message.  Note
575      that `message' maybe NULL.  The `flags' indicates message flags
576      and it is used to determine how the message can be interpreted
577      (like it may tell the message is multimedia message). */
578   void (*channel_message)(SilcClient client, SilcClientConnection conn,
579                           SilcClientEntry sender, SilcChannelEntry channel,
580                           SilcMessagePayload payload, SilcMessageFlags flags,
581                           const unsigned char *message,
582                           SilcUInt32 message_len);
583
584   /* Private message to the client. The `sender' is the sender of the
585      message. The message is `message'and maybe NULL.  The `flags'
586      indicates message flags  and it is used to determine how the message
587      can be interpreted (like it may tell the message is multimedia
588      message). */
589   void (*private_message)(SilcClient client, SilcClientConnection conn,
590                           SilcClientEntry sender, SilcMessagePayload payload,
591                           SilcMessageFlags flags,
592                           const unsigned char *message,
593                           SilcUInt32 message_len);
594
595   /* Notify message to the client. The notify arguments are sent in the
596      same order as servers sends them. The arguments are same as received
597      from the server except for ID's.  If ID is received application receives
598      the corresponding entry to the ID. For example, if Client ID is received
599      application receives SilcClientEntry.  Also, if the notify type is
600      for channel the channel entry is sent to application (even if server
601      does not send it because client library gets the channel entry from
602      the Channel ID in the packet's header). */
603   void (*notify)(SilcClient client, SilcClientConnection conn,
604                  SilcNotifyType type, ...);
605
606   /* Command handler. This function is called always in the command function.
607      If error occurs it will be called as well. `conn' is the associated
608      client connection. `cmd_context' is the command context that was
609      originally sent to the command. `success' is FALSE if error occurred
610      during command. `command' is the command being processed. It must be
611      noted that this is not reply from server. This is merely called just
612      after application has called the command. Just to tell application
613      that the command really was processed. */
614   void (*command)(SilcClient client, SilcClientConnection conn,
615                   SilcClientCommandContext cmd_context, bool success,
616                   SilcCommand command, SilcStatus status);
617
618   /* Command reply handler. This function is called always in the command reply
619      function. If error occurs it will be called as well. Normal scenario
620      is that it will be called after the received command data has been parsed
621      and processed. The function is used to pass the received command data to
622      the application.
623
624      `conn' is the associated client connection. `cmd_payload' is the command
625      payload data received from server and it can be ignored. It is provided
626      if the application would like to re-parse the received command data,
627      however, it must be noted that the data is parsed already by the library
628      thus the payload can be ignored. `success' is FALSE if error occurred.
629      In this case arguments are not sent to the application. The `status' is
630      the command reply status server returned. The `command' is the command
631      reply being processed. The function has variable argument list and each
632      command defines the number and type of arguments it passes to the
633      application (on error they are not sent).
634
635      The arguments are sent in the same order as servers sends them.  The
636      arguments are same as received from the server except for ID's.  If
637      ID is received application receives the corresponding entry to the
638      ID. For example, if Client ID is receives application receives
639      SilcClientEntry. */
640   void (*command_reply)(SilcClient client, SilcClientConnection conn,
641                         SilcCommandPayload cmd_payload, bool success,
642                         SilcCommand command, SilcStatus status, ...);
643
644   /* Called to indicate that connection was either successfully established
645      or connecting failed.  This is also the first time application receives
646      the SilcClientConnection object which it should save somewhere.
647      The `status' indicated whether the connection were successful.  If it
648      is error value the application must always call the function
649      silc_client_close_connection. */
650   void (*connected)(SilcClient client, SilcClientConnection conn,
651                     SilcClientConnectionStatus status);
652
653   /* Called to indicate that connection was disconnected to the server.
654      The `status' may tell the reason of the disconnection, and if the
655      `message' is non-NULL it may include the disconnection message
656      received from server. */
657   void (*disconnected)(SilcClient client, SilcClientConnection conn,
658                        SilcStatus status, const char *message);
659
660   /* Find authentication method and authentication data by hostname and
661      port. The hostname may be IP address as well. When the authentication
662      method has been resolved the `completion' callback with the found
663      authentication method and authentication data is called. The `conn'
664      may be NULL. */
665   void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
666                           char *hostname, SilcUInt16 port,
667                           SilcGetAuthMeth completion, void *context);
668
669   /* Verifies received public key. The `conn_type' indicates which entity
670      (server, client etc.) has sent the public key. If user decides to trust
671      the application may save the key as trusted public key for later
672      use. The `completion' must be called after the public key has been
673      verified. */
674   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
675                             SilcSocketType conn_type, unsigned char *pk,
676                             SilcUInt32 pk_len, SilcSKEPKType pk_type,
677                             SilcVerifyPublicKey completion, void *context);
678
679   /* Ask (interact, that is) a passphrase from user. The passphrase is
680      returned to the library by calling the `completion' callback with
681      the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
682      if not then the library will attempt to encode. */
683   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
684                          SilcAskPassphrase completion, void *context);
685
686   /* Notifies application that failure packet was received.  This is called
687      if there is some protocol active in the client.  The `protocol' is the
688      protocol context.  The `failure' is opaque pointer to the failure
689      indication.  Note, that the `failure' is protocol dependant and
690      application must explicitly cast it to correct type.  Usually `failure'
691      is 32 bit failure type (see protocol specs for all protocol failure
692      types). */
693   void (*failure)(SilcClient client, SilcClientConnection conn,
694                   SilcProtocol protocol, void *failure);
695
696   /* Asks whether the user would like to perform the key agreement protocol.
697      This is called after we have received an key agreement packet or an
698      reply to our key agreement packet. This returns TRUE if the user wants
699      the library to perform the key agreement protocol and FALSE if it is not
700      desired (application may start it later by calling the function
701      silc_client_perform_key_agreement). If TRUE is returned also the
702      `completion' and `context' arguments must be set by the application. */
703   bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
704                         SilcClientEntry client_entry, const char *hostname,
705                         SilcUInt16 port, SilcKeyAgreementCallback *completion,
706                         void **context);
707
708   /* Notifies application that file transfer protocol session is being
709      requested by the remote client indicated by the `client_entry' from
710      the `hostname' and `port'. The `session_id' is the file transfer
711      session and it can be used to either accept or reject the file
712      transfer request, by calling the silc_client_file_receive or
713      silc_client_file_close, respectively. */
714   void (*ftp)(SilcClient client, SilcClientConnection conn,
715               SilcClientEntry client_entry, SilcUInt32 session_id,
716               const char *hostname, SilcUInt16 port);
717
718   /* Delivers SILC session detachment data indicated by `detach_data' to the
719      application.  If application has issued SILC_COMMAND_DETACH command
720      the client session in the SILC network is not quit.  The client remains
721      in the network but is detached.  The detachment data may be used later
722      to resume the session in the SILC Network.  The appliation is
723      responsible of saving the `detach_data', to for example in a file.
724
725      The detachment data can be given as argument to the functions
726      silc_client_connect_to_server, or silc_client_add_connection when
727      creating connection to remote server, inside SilcClientConnectionParams
728      structure.  If it is provided the client library will attempt to resume
729      the session in the network.  After the connection is created
730      successfully, the application is responsible of setting the user
731      interface for user into the same state it was before detaching (showing
732      same channels, channel modes, etc).  It can do this by fetching the
733      information (like joined channels) from the client library. */
734   void (*detach)(SilcClient client, SilcClientConnection conn,
735                  const unsigned char *detach_data,
736                  SilcUInt32 detach_data_len);
737 } SilcClientOperations;
738 /***/
739
740 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
741  *
742  * SYNOPSIS
743  *
744  *    typedef void (*SilcNicknameFormatParse)(const char *nickname,
745  *                                            char **ret_nickname);
746  *
747  * DESCRIPTION
748  *
749  *    A callback function provided by the application for the library in
750  *    SilcClientParams structure. This function parses the formatted
751  *    nickname string `nickname' and returns the true nickname to the
752  *    `ret_nickname' pointer. The library can call this function at
753  *    any time.
754  *
755  ***/
756 typedef void (*SilcNicknameFormatParse)(const char *nickname,
757                                         char **ret_nickname);
758
759 /****s* silcclient/SilcClientAPI/SilcClientParams
760  *
761  * NAME
762  *
763  *    typedef struct { ... } SilcClientParams;
764  *
765  * DESCRIPTION
766  *
767  *    Client parameters. This can be filled with proper values and
768  *    given as argument to the silc_client_alloc function. The structure
769  *    hold various parameters which affects the function of the client.
770  *
771  * SOURCE
772  */
773 typedef struct {
774   /* Number of maximum tasks the client library's scheduler can handle.
775      If set to zero, the default value will be used (200). For WIN32
776      systems this should be set to 64 as it is the hard limit dictated
777      by the WIN32. */
778   int task_max;
779
780   /* Rekey timeout in seconds. The client will perform rekey in this
781      time interval. If set to zero, the default value will be used. */
782   unsigned int rekey_secs;
783
784   /* Connection authentication method request timeout. If server does not
785      reply back the current authentication method when we've requested it
786      in this time interval we'll assume the reply will not come at all.
787      If set to zero, the default value (2 seconds) will be used. */
788   unsigned int connauth_request_secs;
789
790   /* Nickname format string. This can be used to order the client library
791      to save the nicknames in the library in a certain format. Since
792      nicknames are not unique in SILC it is possible to have multiple same
793      nicknames. Using this format string it is possible to order the library
794      to separate the multiple same nicknames from each other. The format
795      types are defined below and they can appear in any order in the format
796      string. If this is NULL then default format is used which is the
797      default nickname without anything else. The string MUST be NULL
798      terminated.
799
800      Following format types are available:
801
802      %n  nickname      - the real nickname returned by the server (mandatory)
803      %h  hostname      - the stripped hostname of the client
804      %H  full hostname - the full hostname of the client
805      %s  server name   - the server name the client is connected
806      %S  full server   - the full server name the client is connected
807      %a  number        - ascending number in case there are several
808                          same nicknames (fe. nick@host and nick@host2)
809
810      Example format strings: "%n@%h%a"   (fe. nick@host, nick@host2)
811                              "%a!%n@%s"  (fe. nick@server, 2!nick@server)
812                              "%n@%H"     (fe. nick@host.domain.com)
813
814      By default this format is employed to the nicknames by the libary
815      only when there appears multiple same nicknames. If the library has
816      only one nickname cached the nickname is saved as is and without the
817      defined format. If you want always to save the nickname in the defined
818      format set the boolean field `nickname_force_format' to value TRUE.
819   */
820   char nickname_format[32];
821
822   /* If this is set to TRUE then the `nickname_format' is employed to all
823      saved nicknames even if there are no multiple same nicknames in the
824      cache. By default this is FALSE, which means that the `nickname_format'
825      is employed only if the library will receive a nickname that is
826      already saved in the cache. It is recommended to leave this to FALSE
827      value. */
828   bool nickname_force_format;
829
830   /* A callback function provided by the application for the library to
831      parse the nickname from the formatted nickname string. Even though
832      the libary formats the nicknames the application knows generally the
833      format better so this function should be provided for the library
834      if the application sets the `nickname_format' field. The library
835      will call this to get the true nickname from the provided formatted
836      nickname string whenever it needs the true nickname. */
837   SilcNicknameFormatParse nickname_parse;
838
839   /* If this is set to TRUE then the client will ignore all incoming
840      Requested Attributes queries and does not reply anything back.  This
841      usually leads into situation where server does not anymore send
842      the queries after seeing that client does not reply anything back.
843      If your application does not support Requested Attributes or you do
844      not want to use them set this to TRUE.  See SilcAttribute and
845      silc_client_attribute_add for more information on attributes. */
846   bool ignore_requested_attributes;
847
848 } SilcClientParams;
849 /***/
850
851
852 /* Initialization functions (client.c) */
853
854 /****f* silcclient/SilcClientAPI/silc_client_alloc
855  *
856  * SYNOPSIS
857  *
858  *    SilcClient silc_client_alloc(SilcClientOperations *ops,
859  *                                 SilcClientParams *params,
860  *                                 void *application,
861  *                                 const char *silc_version);
862  *
863  * DESCRIPTION
864  *
865  *    Allocates new client object. This has to be done before client may
866  *    work. After calling this one must call silc_client_init to initialize
867  *    the client. The `application' is application specific user data pointer
868  *    and caller must free it. The `silc_version' is the application version
869  *    that will be used to compare against remote host's (usually a server)
870  *    version string.  The `application' context is accessible by the
871  *    application by client->application, client being SilcClient.
872  *
873  ***/
874 SilcClient silc_client_alloc(SilcClientOperations *ops,
875                              SilcClientParams *params,
876                              void *application,
877                              const char *version_string);
878
879 /****f* silcclient/SilcClientAPI/silc_client_free
880  *
881  * SYNOPSIS
882  *
883  *    void silc_client_free(SilcClient client);
884  *
885  * DESCRIPTION
886  *
887  *    Frees client object and its internals.  The execution of the client
888  *    should be stopped with silc_client_stop function before calling
889  *    this function.
890  *
891  ***/
892 void silc_client_free(SilcClient client);
893
894 /****f* silcclient/SilcClientAPI/silc_client_init
895  *
896  * SYNOPSIS
897  *
898  *    bool silc_client_init(SilcClient client);
899  *
900  * DESCRIPTION
901  *
902  *    Initializes the client. This makes all the necessary steps to make
903  *    the client ready to be run. One must call silc_client_run to run the
904  *    client. Returns FALSE if error occurred, TRUE otherwise.
905  *
906  ***/
907 bool silc_client_init(SilcClient client);
908
909 /****f* silcclient/SilcClientAPI/silc_client_run
910  *
911  * SYNOPSIS
912  *
913  *    void silc_client_run(SilcClient client);
914  *
915  * DESCRIPTION
916  *
917  *    Runs the client. This starts the scheduler from the utility library.
918  *    When this functions returns the execution of the appliation is over.
919  *    The client must be initialized before calling this.
920  *
921  ***/
922 void silc_client_run(SilcClient client);
923
924 /****f* silcclient/SilcClientAPI/silc_client_run_one
925  *
926  * SYNOPSIS
927  *
928  *    void silc_client_run_one(SilcClient client);
929  *
930  * DESCRIPTION
931  *
932  *    Runs the client and returns immeadiately. This function is used when
933  *    the SILC Client object indicated by the `client' is run under some
934  *    other scheduler, or event loop or main loop.  On GUI applications,
935  *    for example this may be desired to used to run the client under the
936  *    GUI application's main loop.  Typically the GUI application would
937  *    register an idle task that calls this function multiple times in
938  *    a second to quickly process the SILC specific data.
939  *
940  ***/
941 void silc_client_run_one(SilcClient client);
942
943 /****f* silcclient/SilcClientAPI/silc_client_stop
944  *
945  * SYNOPSIS
946  *
947  *    void silc_client_stop(SilcClient client);
948  *
949  * DESCRIPTION
950  *
951  *    Stops the client. This is called to stop the client and thus to stop
952  *    the program.  The client context must be freed with the silc_client_free
953  *    function.
954  *
955  ***/
956 void silc_client_stop(SilcClient client);
957
958
959 /* Connecting functions (client.c) */
960
961 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
962  *
963  * NAME
964  *
965  *    typedef struct { ... } SilcClientConnectionParams;
966  *
967  * DESCRIPTION
968  *
969  *    Client connection parameters.  This can be filled by the application
970  *    and given as argument to silc_client_connect_to_server or to
971  *    silc_client_add_connection.
972  *
973  * SOURCE
974  */
975 typedef struct {
976   /* The SILC session detachment data that was returned by `detach' client
977      operation when the application detached from the network.  Application
978      is responsible of saving the data and giving it as argument here
979      for resuming the session in the SILC network.
980
981      If this is provided here the client library will attempt to resume
982      the session in the network.  After the connection is created
983      successfully, the application is responsible of setting the user
984      interface for user into the same state it was before detaching (showing
985      same channels, channel modes, etc).  It can do this by fetching the
986      information (like joined channels) from the client library. */
987   unsigned char *detach_data;
988   SilcUInt32 detach_data_len;
989
990 } SilcClientConnectionParams;
991 /***/
992
993 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
994  *
995  * SYNOPSIS
996  *
997  *    int silc_client_connect_to_server(SilcClient client,
998  *                                      SilcClientConnectionParams *params,
999  *                                      int port, char *host, void *context);
1000  *
1001  * DESCRIPTION
1002  *
1003  *    Connects to remote server. This is the main routine used to connect
1004  *    to SILC server. Returns -1 on error and the created socket otherwise.
1005  *    The `context' is user context that is saved into the SilcClientConnection
1006  *    that is created after the connection is created. Note that application
1007  *    may handle the connecting process outside the library. If this is the
1008  *    case then this function is not used at all. When the connecting is
1009  *    done the `connect' client operation is called, and the `context' is
1010  *    accessible with conn->context, conn being SilcClientConnection.
1011  *    If the `params' is provided they are used by the routine.
1012  *
1013  ***/
1014 int silc_client_connect_to_server(SilcClient client,
1015                                   SilcClientConnectionParams *params,
1016                                   int port, char *host, void *context);
1017
1018 /****f* silcclient/SilcClientAPI/silc_client_add_connection
1019  *
1020  * SYNOPSIS
1021  *
1022  *
1023  *    SilcClientConnection
1024  *    silc_client_add_connection(SilcClient client,
1025  *                               SilcClientConnectionParams *params,
1026  *                               char *hostname, int port, void *context);
1027  *
1028  * DESCRIPTION
1029  *
1030  *    Allocates and adds new connection to the client. This adds the allocated
1031  *    connection to the connection table and returns a pointer to it. A client
1032  *    can have multiple connections to multiple servers. Every connection must
1033  *    be added to the client using this function. User data `context' may
1034  *    be sent as argument.  If the `params' is provided they are used by
1035  *    the routine.
1036  *
1037  * NOTES
1038  *
1039  *    This function is normally used only if the application performed
1040  *    the connecting outside the library, and did not called the
1041  *    silc_client_connect_to_server function at all. The library
1042  *    however may use this internally.
1043  *
1044  ***/
1045 SilcClientConnection
1046 silc_client_add_connection(SilcClient client,
1047                            SilcClientConnectionParams *params,
1048                            char *hostname, int port, void *context);
1049
1050 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1051  *
1052  * SYNOPSIS
1053  *
1054  *    void silc_client_del_connection(SilcClient client,
1055  *                                    SilcClientConnection conn);
1056  *
1057  * DESCRIPTION
1058  *
1059  *    Removes connection from client. Frees all memory. The library
1060  *    call this function automatically for all connection contexts.
1061  *    The application however may free the connection contexts it has
1062  *    allocated.
1063  *
1064  ***/
1065 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1066
1067 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1068  *
1069  * SYNOPSIS
1070  *
1071  *    void silc_client_add_socket(SilcClient client,
1072  *                                SilcSocketConnection sock);
1073  *
1074  * DESCRIPTION
1075  *
1076  *    Adds listener socket to the listener sockets table. This function is
1077  *    used to add socket objects that are listeners to the client.  This should
1078  *    not be used to add other connection objects.
1079  *
1080  ***/
1081 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1082
1083 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1084  *
1085  * SYNOPSIS
1086  *
1087  *    void silc_client_del_socket(SilcClient client,
1088  *                                SilcSocketConnection sock);
1089  *
1090  * DESCRIPTION
1091  *
1092  *    Deletes listener socket from the listener sockets table.  If the
1093  *    application has added a socket with silc_client_add_socket it must
1094  *    also free it using this function.
1095  *
1096  ***/
1097 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1098
1099 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1100  *
1101  * SYNOPSIS
1102  *
1103  *    void silc_client_start_key_exchange(SilcClient client,
1104  *                                        SilcClientConnection conn,
1105  *                                        int fd);
1106  *
1107  * DESCRIPTION
1108  *
1109  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1110  *    key material between client and server.  This function can be called
1111  *    directly if application is performing its own connecting and does not
1112  *    use the connecting provided by this library. This function is normally
1113  *    used only if the application performed the connecting outside the
1114  *    library. The library however may use this internally.  After the
1115  *    key exchange is performed the `connect' client operation is called.
1116  *
1117  * NOTES
1118  *
1119  *    The silc_client_add_connection must be called before calling this
1120  *    function to create the SilcClientConnection context for this
1121  *    connection.
1122  *
1123  ***/
1124 void silc_client_start_key_exchange(SilcClient client,
1125                                     SilcClientConnection conn,
1126                                     int fd);
1127
1128 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1129  *
1130  * SYNOPSIS
1131  *
1132  *    void silc_client_close_connection(SilcClient client,
1133  *                                      SilcClientConnection conn);
1134  *
1135  * DESCRIPTION
1136  *
1137  *    Closes connection to remote end. Free's all allocated data except
1138  *    for some information such as nickname etc. that are valid at all time.
1139  *    Usually application does not need to directly call this, except
1140  *    when explicitly closing the connection, or if an error occurs
1141  *    during connection to server (see 'connect' client operation for
1142  *    more information).
1143  *
1144  ***/
1145 void silc_client_close_connection(SilcClient client,
1146                                   SilcClientConnection conn);
1147
1148
1149 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1150
1151 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1152  *
1153  * SYNOPSIS
1154  *
1155  *    bool silc_client_send_channel_message(SilcClient client,
1156  *                                          SilcClientConnection conn,
1157  *                                          SilcChannelEntry channel,
1158  *                                          SilcChannelPrivateKey key,
1159  *                                          SilcMessageFlags flags,
1160  *                                          unsigned char *data,
1161  *                                          SilcUInt32 data_len,
1162  *                                          bool_force_send);
1163  *
1164  * DESCRIPTION
1165  *
1166  *    Sends packet to the `channel'. Packet to channel is always encrypted
1167  *    differently from "normal" packets. SILC header of the packet is
1168  *    encrypted with the next receiver's key and the rest of the packet is
1169  *    encrypted with the channel specific key. Padding and HMAC is computed
1170  *    with the next receiver's key. The `data' is the channel message. If
1171  *    the `force_send' is TRUE then the packet is sent immediately.
1172  *
1173  *    If `key' is provided then that private key is used to encrypt the
1174  *    channel message.  If it is not provided, private keys has not been
1175  *    set at all, the normal channel key is used automatically.  If private
1176  *    keys are set then the first key (the key that was added first as
1177  *    private key) is used.
1178  *
1179  *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1180  *    digitally signed with the SILC key pair.
1181  *
1182  *    Returns TRUE if the message was sent, and FALSE if error occurred or
1183  *    the sending is not allowed due to channel modes (like sending is
1184  *    blocked).
1185  *
1186  ***/
1187 bool silc_client_send_channel_message(SilcClient client,
1188                                       SilcClientConnection conn,
1189                                       SilcChannelEntry channel,
1190                                       SilcChannelPrivateKey key,
1191                                       SilcMessageFlags flags,
1192                                       unsigned char *data,
1193                                       SilcUInt32 data_len,
1194                                       bool force_send);
1195
1196 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1197  *
1198  * SYNOPSIS
1199  *
1200  *    bool silc_client_send_private_message(SilcClient client,
1201  *                                          SilcClientConnection conn,
1202  *                                          SilcClientEntry client_entry,
1203  *                                          SilcMessageFlags flags,
1204  *                                          unsigned char *data,
1205  *                                          SilcUInt32 data_len,
1206  *                                          bool force_send);
1207  *
1208  * DESCRIPTION
1209  *
1210  *    Sends private message to remote client. If private message key has
1211  *    not been set with this client then the message will be encrypted using
1212  *    normal session keys. Private messages are special packets in SILC
1213  *    network hence we need this own function for them. This is similar
1214  *    to silc_client_packet_send_to_channel except that we send private
1215  *    message. The `data' is the private message. If the `force_send' is
1216  *    TRUE the packet is sent immediately.
1217  *
1218  *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1219  *    digitally signed with the SILC key pair.
1220  *
1221  *    Returns TRUE if the message was sent, and FALSE if error occurred.
1222  *
1223  ***/
1224 bool silc_client_send_private_message(SilcClient client,
1225                                       SilcClientConnection conn,
1226                                       SilcClientEntry client_entry,
1227                                       SilcMessageFlags flags,
1228                                       unsigned char *data,
1229                                       SilcUInt32 data_len,
1230                                       bool force_send);
1231
1232
1233 /* Client and Channel entry retrieval (idlist.c) */
1234
1235 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1236  *
1237  * SYNOPSIS
1238  *
1239  *    typedef void (*SilcGetClientCallback)(SilcClient client,
1240  *                                          SilcClientConnection conn,
1241  *                                          SilcClientEntry *clients,
1242  *                                          SilcUInt32 clients_count,
1243  *                                          void *context);
1244  *
1245  * DESCRIPTION
1246  *
1247  *    Callback function given to the silc_client_get_client function. The
1248  *    found entries are allocated into the `clients' array. The array must
1249  *    not be freed by the receiver, the library will free it later. If the
1250  *    `clients' is NULL, no such clients exist in the SILC Network.
1251  *
1252  ***/
1253 typedef void (*SilcGetClientCallback)(SilcClient client,
1254                                       SilcClientConnection conn,
1255                                       SilcClientEntry *clients,
1256                                       SilcUInt32 clients_count,
1257                                       void *context);
1258
1259 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1260  *
1261  * SYNOPSIS
1262  *
1263  *    void silc_client_get_clients(SilcClient client,
1264  *                                 SilcClientConnection conn,
1265  *                                 const char *nickname,
1266  *                                 const char *server,
1267  *                                 SilcGetClientCallback completion,
1268  *                                 void *context);
1269  *
1270  * DESCRIPTION
1271  *
1272  *    Finds client entry or entries by the `nickname' and `server'. The
1273  *    completion callback will be called when the client entries has been
1274  *    found.  After the server returns the client information it is cached
1275  *    and can be accesses locally at a later time.  The resolving is done
1276  *    with IDENTIFY command.  The `server' may be NULL.
1277  *
1278  * NOTES
1279  *
1280  *    NOTE: This function is always asynchronous and resolves the client
1281  *    information from the server. Thus, if you already know the client
1282  *    information then use the silc_client_get_client_by_id function to
1283  *    get the client entry since this function may be very slow and should
1284  *    be used only to initially get the client entries.
1285  *
1286  *    Since this routine resolves with IDENTIFY command only the relevant
1287  *    information (user's nickname and username) is resolved.  For example,
1288  *    user's real name, channel list and others are not resolved.  Caller
1289  *    can/must resolve those separately if they are needed (for example,
1290  *    with silc_client_get_client_by_id_resolve).
1291  *
1292  ***/
1293 void silc_client_get_clients(SilcClient client,
1294                              SilcClientConnection conn,
1295                              const char *nickname,
1296                              const char *server,
1297                              SilcGetClientCallback completion,
1298                              void *context);
1299
1300 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1301  *
1302  * SYNOPSIS
1303  *
1304  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1305  *                                                   SilcClientConnection conn,
1306  *                                                   const char *nickname,
1307  *                                                   const char *format,
1308  *                                                   SilcUInt32 *clients_count);
1309  *
1310  * DESCRIPTION
1311  *
1312  *    Same as silc_client_get_clients function but does not resolve anything
1313  *    from the server. This checks local cache and returns all matching
1314  *    clients from the local cache. If none was found this returns NULL.
1315  *    The `nickname' is the real nickname of the client, and the `format'
1316  *    is the formatted nickname to find exact match from multiple found
1317  *    entries. The format must be same as given in the SilcClientParams
1318  *    structure to the client library. If the `format' is NULL all found
1319  *    clients by `nickname' are returned. The caller must return the
1320  *    returned array.
1321  *
1322  ***/
1323 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1324                                                SilcClientConnection conn,
1325                                                const char *nickname,
1326                                                const char *format,
1327                                                SilcUInt32 *clients_count);
1328
1329 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1330  *
1331  * SYNOPSIS
1332  *
1333  *    void silc_client_get_clients_by_channel(SilcClient client,
1334  *                                            SilcClientConnection conn,
1335  *                                            SilcChannelEntry channel,
1336  *                                            SilcGetClientCallback completion,
1337  *                                            void *context);
1338  *
1339  * DESCRIPTION
1340  *
1341  *    Gets client entries by the channel indicated by `channel'. Thus,
1342  *    it resovles the users currently on that channel. If all users are
1343  *    already resolved this returns the users from the channel. If the
1344  *    users are resolved only partially this resolves the complete user
1345  *    information. If no users are resolved on this channel at all, this
1346  *    calls USERS command to resolve all users on the channel. The `completion'
1347  *    will be called after the entries are available. When server returns
1348  *    the client information it will be cached and can be accessed locally
1349  *    at a later time.
1350  *
1351  *    This function can be used for example in SILC_COMMAND_JOIN command
1352  *    reply handling in application to resolve users on that channel.  It
1353  *    also can be used after calling silc_client_get_channel_resolve to
1354  *    resolve users on that channel.
1355  *
1356  * NOTES
1357  *
1358  *    The resolving is done with WHOIS command. For this reason this
1359  *    command may take a long time because it resolves detailed user
1360  *    information.
1361  *
1362  ***/
1363 void silc_client_get_clients_by_channel(SilcClient client,
1364                                         SilcClientConnection conn,
1365                                         SilcChannelEntry channel,
1366                                         SilcGetClientCallback completion,
1367                                         void *context);
1368
1369 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1370  *
1371  * SYNOPSIS
1372  *
1373  *    void silc_client_get_clients_by_list(SilcClient client,
1374  *                                         SilcClientConnection conn,
1375  *                                         SilcUInt32 list_count,
1376  *                                         SilcBuffer client_id_list,
1377  *                                         SilcGetClientCallback completion,
1378  *                                         void *context);
1379  *
1380  * DESCRIPTION
1381  *
1382  *    Gets client entries by the list of client ID's `client_id_list'. This
1383  *    always resolves those client ID's it does not know yet from the server
1384  *    so this function might take a while. The `client_id_list' is a list
1385  *    of ID Payloads added one after other.  JOIN command reply and USERS
1386  *    command reply for example returns this sort of list. The `completion'
1387  *    will be called after the entries are available. When server returns
1388  *    the client information it will be cached and can be accessed locally
1389  *    at a later time.
1390  *
1391  * NOTES
1392  *
1393  *    The resolving is done with IDENTIFY command. This means that only
1394  *    the relevant information of user (it's nickname and username) is
1395  *    resolved. For example, user's real name, channel lists and others
1396  *    are not resolved. Caller can/must resolve those separately if they
1397  *    are needed (for example, with silc_client_get_client_by_id_resolve).
1398  *
1399  ***/
1400 void silc_client_get_clients_by_list(SilcClient client,
1401                                      SilcClientConnection conn,
1402                                      SilcUInt32 list_count,
1403                                      SilcBuffer client_id_list,
1404                                      SilcGetClientCallback completion,
1405                                      void *context);
1406
1407 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1408  *
1409  * SYNOPSIS
1410  *
1411  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1412  *                                                 SilcClientConnection conn,
1413  *                                                 SilcClientID *client_id);
1414  *
1415  * DESCRIPTION
1416  *
1417  *    Find entry for client by the client's ID. Returns the entry or NULL
1418  *    if the entry was not found.  This checks the local cache and does
1419  *    not resolve anything from server.
1420  *
1421  ***/
1422 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1423                                              SilcClientConnection conn,
1424                                              SilcClientID *client_id);
1425
1426 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1427  *
1428  * SYNOPSIS
1429  *
1430  *    void
1431  *    silc_client_get_client_by_id_resolve(SilcClient client,
1432  *                                         SilcClientConnection conn,
1433  *                                         SilcClientID *client_id,
1434  *                                         SilcBuffer attributes,
1435  *                                         SilcGetClientCallback completion,
1436  *                                         void *context);
1437  *
1438  * DESCRIPTION
1439  *
1440  *    Same as silc_client_get_client_by_id but will always resolve the
1441  *    information from the server. Use this only if you know that you
1442  *    do not have the entry and the only thing you know about the client
1443  *    is its ID. When server returns the client information it will be
1444  *    cache and can be accessed locally at a later time. The resolving
1445  *    is done by sending WHOIS command.
1446  *
1447  *    If the `attributes' is non-NULL then the buffer includes Requested
1448  *    Attributes which can be used to fetch very detailed information
1449  *    about the user. If it is NULL then only normal WHOIS query is
1450  *    made (for more information about attributes see SilcAttribute).
1451  *    Caller may create the `attributes' with silc_client_attributes_request
1452  *    function.
1453  *
1454  ***/
1455 void silc_client_get_client_by_id_resolve(SilcClient client,
1456                                           SilcClientConnection conn,
1457                                           SilcClientID *client_id,
1458                                           SilcBuffer attributes,
1459                                           SilcGetClientCallback completion,
1460                                           void *context);
1461
1462 /****f* silcclient/SilcClientAPI/silc_client_del_client
1463  *
1464  * SYNOPSIS
1465  *
1466  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1467  *                                SilcClientEntry client_entry)
1468  *
1469  * DESCRIPTION
1470  *
1471  *    Removes client from local cache by the client entry indicated by
1472  *    the `client_entry'.  Returns TRUE if the deletion were successful.
1473  *
1474  ***/
1475 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1476                             SilcClientEntry client_entry);
1477
1478 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1479  *
1480  * SYNOPSIS
1481  *
1482  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
1483  *                                           SilcClientConnection conn,
1484  *                                           SilcChannelEntry *channels,
1485  *                                           SilcUInt32 channels_count,
1486  *                                           void *context);
1487  *
1488  * DESCRIPTION
1489  *
1490  *    Callback function given to the silc_client_get_channel_* functions.
1491  *    The found entries are allocated into the `channels' array. The array
1492  *    must not be freed by the receiver, the library will free it later.
1493  *    If the `channel' is NULL, no such channel exist in the SILC Network.
1494  *
1495  ***/
1496 typedef void (*SilcGetChannelCallback)(SilcClient client,
1497                                        SilcClientConnection conn,
1498                                        SilcChannelEntry *channels,
1499                                        SilcUInt32 channels_count,
1500                                        void *context);
1501
1502 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1503  *
1504  * SYNOPSIS
1505  *
1506  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
1507  *                                             SilcClientConnection conn,
1508  *                                             char *channel_name);
1509  *
1510  * DESCRIPTION
1511  *
1512  *    Finds entry for channel by the channel name. Returns the entry or NULL
1513  *    if the entry was not found. It is found only if the client is joined
1514  *    to the channel.  Use silc_client_get_channel_resolve or
1515  *    silc_client_get_channel_by_id_resolve to resolve channel that client
1516  *    is not joined.
1517  *
1518  ***/
1519 SilcChannelEntry silc_client_get_channel(SilcClient client,
1520                                          SilcClientConnection conn,
1521                                          char *channel_name);
1522
1523 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1524  *
1525  * SYNOPSIS
1526  *
1527  *    void silc_client_get_channel_resolve(SilcClient client,
1528  *                                         SilcClientConnection conn,
1529  *                                         char *channel_name,
1530  *                                         SilcGetChannelCallback completion,
1531  *                                         void *context);
1532  *
1533  * DESCRIPTION
1534  *
1535  *    Resolves entry for channel by the channel name from the server.
1536  *    The resolving is done with IDENTIFY command. Note that users on
1537  *    the channel are not resolved at the same time. Use for example
1538  *    silc_client_get_clients_by_channel to resolve all users on a channel.
1539  *
1540  ***/
1541 void silc_client_get_channel_resolve(SilcClient client,
1542                                      SilcClientConnection conn,
1543                                      char *channel_name,
1544                                      SilcGetChannelCallback completion,
1545                                      void *context);
1546
1547 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1548  *
1549  * SYNOPSIS
1550  *
1551  *    SilcChannelEntry
1552  *    silc_client_get_channel_by_id(SilcClient client,
1553  *                                  SilcClientConnection conn,
1554  *                                  SilcChannelID *channel_id);
1555  *
1556  * DESCRIPTION
1557  *
1558  *    Finds channel entry by the channel ID. Returns the entry or NULL
1559  *    if the entry was not found.  This checks the local cache and does
1560  *    not resolve anything from server.
1561  *
1562  ***/
1563 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1564                                                SilcClientConnection conn,
1565                                                SilcChannelID *channel_id);
1566
1567 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1568  *
1569  * SYNOPSIS
1570  *
1571  *    void
1572  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1573  *                                          SilcClientConnection conn,
1574  *                                          SilcChannelID *channel_id,
1575  *                                          SilcGetClientCallback completion,
1576  *                                          void *context);
1577  *
1578  * DESCRIPTION
1579  *
1580  *    Resolves the channel information (its name mainly) from the server
1581  *    by the `channel_id'. Use this only if you know that you do not have
1582  *    the entry cached locally. The resolving is done with IDENTIFY command.
1583  *
1584  *    Note that users on the channel are not resolved at the same time.
1585  *    Use for example silc_client_get_clients_by_channel to resolve all
1586  *    users on a channel.
1587  *
1588  ***/
1589 void silc_client_get_channel_by_id_resolve(SilcClient client,
1590                                            SilcClientConnection conn,
1591                                            SilcChannelID *channel_id,
1592                                            SilcGetChannelCallback completion,
1593                                            void *context);
1594
1595 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1596  *
1597  * SYNOPSIS
1598  *
1599  *    bool silc_client_del_channel(SilcClient client,
1600  *                                 SilcClientConnection conn,
1601  *                                 SilcChannelEntry channel)
1602  *
1603  * DESCRIPTION
1604  *
1605  *    Removes channel from local cache by the channel entry indicated by
1606  *    the `channel'.  Returns TRUE if the deletion were successful.
1607  *
1608  ***/
1609 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1610                              SilcChannelEntry channel);
1611
1612 /****f* silcclient/SilcClientAPI/silc_client_get_server
1613  *
1614  * SYNOPSIS
1615  *
1616  *    SilcServerEntry silc_client_get_server(SilcClient client,
1617  *                                           SilcClientConnection conn,
1618  *                                           char *server_name)
1619  *
1620  * DESCRIPTION
1621  *
1622  *    Finds entry for server by the server name. Returns the entry or NULL
1623  *    if the entry was not found.
1624  *
1625  ***/
1626 SilcServerEntry silc_client_get_server(SilcClient client,
1627                                        SilcClientConnection conn,
1628                                        char *server_name);
1629
1630 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1631  *
1632  * SYNOPSIS
1633  *
1634  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1635  *                                                 SilcClientConnection conn,
1636  *                                                 SilcServerID *server_id);
1637  *
1638  * DESCRIPTION
1639  *
1640  *    Finds entry for server by the server ID. Returns the entry or NULL
1641  *    if the entry was not found.
1642  *
1643  ***/
1644 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1645                                              SilcClientConnection conn,
1646                                              SilcServerID *server_id);
1647
1648 /****f* silcclient/SilcClientAPI/silc_client_del_server
1649  *
1650  * SYNOPSIS
1651  *
1652  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1653  *                                SilcServerEntry server);
1654  *
1655  * DESCRIPTION
1656  *
1657  *    Removes server from local cache by the server entry indicated by
1658  *    the `server'.  Returns TRUE if the deletion were successful.
1659  *
1660  ***/
1661 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1662                             SilcServerEntry server);
1663
1664 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1665  *
1666  * SYNOPSIS
1667  *
1668  *    SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1669  *                                           SilcClientEntry client_entry);
1670  *
1671  * DESCRIPTION
1672  *
1673  *    Returns the SilcChannelUser entry if the `client_entry' is joined on the
1674  *    channel indicated by the `channel'. NULL if client is not joined on
1675  *    the channel.
1676  *
1677  ***/
1678 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1679                                        SilcClientEntry client_entry);
1680
1681 /* Command management (command.c) */
1682
1683 /****f* silcclient/SilcClientAPI/silc_client_command_call
1684  *
1685  * SYNOPSIS
1686  *
1687  *    bool silc_client_command_call(SilcClient client,
1688  *                                  SilcClientConnection conn,
1689  *                                  const char *command_line, ...);
1690  *
1691  * DESCRIPTION
1692  *
1693  *    Calls and executes the command indicated by the `command_name'.
1694  *    The `command_line' is a string which includes the command's name and
1695  *    its arguments separated with whitespaces (' ').  If `command_line'
1696  *    is non-NULL then all variable arguments are ignored by default.
1697  *
1698  *    If `command_line' is NULL, then the variable arguments define the
1699  *    command's name and its arguments.  The first variable argument must
1700  *    be the command name.  The variable argument list must be terminated
1701  *    with NULL.
1702  *
1703  *    Returns FALSE if the command is not known and TRUE after command.
1704  *    execution.  The "command" client operation is called when the
1705  *    command is executed to indicate whether the command executed
1706  *    successfully or not.
1707  *
1708  *    The "command_reply" client operation will be called when reply is
1709  *    received from the server to the command.  Application may also use
1710  *    the silc_client_command_pending to attach to the command reply.
1711  *    The command identifier for silc_client_command_pending function after
1712  *    this function call is conn->cmd_ident, which application may use.
1713  *
1714  * EXAMPLE
1715  *
1716  *    silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1717  *                             NULL);
1718  *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
1719  *
1720  * NOTES
1721  *
1722  *    This command executes the commands implemented inside the client
1723  *    library.  These commands are designed for command line applications,
1724  *    but GUI application may call them too if needed.  Alternatively
1725  *    application may override the library and use silc_client_command_send
1726  *    function instead.
1727  *
1728  ***/
1729 bool silc_client_command_call(SilcClient client,
1730                               SilcClientConnection conn,
1731                               const char *command_line, ...);
1732
1733 /****f* silcclient/SilcClientAPI/silc_client_command_send
1734  *
1735  * SYNOPSIS
1736  *
1737  *    void silc_client_command_send(SilcClient client,
1738  *                                  SilcClientConnection conn,
1739  *                                  SilcCommand command, SilcUInt16 ident,
1740  *                                  SilcUInt32 argc, ...);
1741  *
1742  * DESCRIPTION
1743  *
1744  *    Generic function to send any command. The arguments must be sent already
1745  *    encoded into correct form and in correct order. If application wants
1746  *    to perform the commands by itself, it can do so and send the data
1747  *    directly to the server using this function.  If application is using
1748  *    the silc_client_command_call, this function is usually not used.
1749  *    Note that this overriders the Client Librarys commands and sends
1750  *    the command packet directly to server.
1751  *
1752  *    Programmer should get familiar with the SILC protocol commands
1753  *    specification when using this function, as the arguments needs to
1754  *    be encoded as specified in the protocol.
1755  *
1756  *    The variable arguments are a pair of { type, data, data_length },
1757  *    and the `argc' is the number of these pairs.
1758  *
1759  * EXAMPLE
1760  *
1761  *    silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1762  *                             1, nickname, strlen(nickname));
1763  *
1764  ***/
1765 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1766                               SilcCommand command, SilcUInt16 ident,
1767                               SilcUInt32 argc, ...);
1768
1769 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1770  *
1771  * SYNOPSIS
1772  *
1773  *    void silc_client_command_pending(SilcClientConnection conn,
1774  *                                     SilcCommand reply_cmd,
1775  *                                     SilcUInt16 ident,
1776  *                                     SilcCommandCb callback,
1777  *                                     void *context);
1778  *
1779  * DESCRIPTION
1780  *
1781  *    This function can be used to add pending command callback to be
1782  *    called when an command reply is received to an earlier sent command.
1783  *    The `reply_cmd' is the command that must be received in order for
1784  *    the pending command callback indicated by `callback' to be called.
1785  *    The `callback' will deliver the `context' and
1786  *    SilcClientCommandReplyContext which includes the internals of the
1787  *    command reply.
1788  *
1789  *    The `ident' is a command identifier which was set for the earlier
1790  *    sent command.  The command reply will include the same identifier
1791  *    and pending command callback will be called when the reply is
1792  *    received with the same command identifier.  It is possible to
1793  *    add multiple pending command callbacks for same command and for
1794  *    same identifier.
1795  *
1796  *    Application may use this function to add its own command reply
1797  *    handlers if it wishes not to use the standard `command_reply'
1798  *    client operation.  However, note that the pending command callback
1799  *    does not deliver parsed command reply, but application must parse
1800  *    it itself.
1801  *
1802  *    Note also that the application is notified about the received command
1803  *    reply through the `command_reply' client operation before calling
1804  *    the `callback` pending command callback.  That is the normal
1805  *    command reply handling, and is called regardless whether pending
1806  *    command callbacks are used or not.
1807  *
1808  *    Commands that application calls with silc_client_command_call
1809  *    will use a command identifier from conn->cmd_ident variable.  After
1810  *    calling the silc_client_command_call, the conn->cmd_ident includes
1811  *    the command identifier that was used for the command sending.
1812  *
1813  * EXAMPLE
1814  *
1815  *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
1816  *    silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1817  *                                my_ping_handler, my_ping_context);
1818  *
1819  ***/
1820 void silc_client_command_pending(SilcClientConnection conn,
1821                                  SilcCommand reply_cmd,
1822                                  SilcUInt16 ident,
1823                                  SilcCommandCb callback,
1824                                  void *context);
1825
1826
1827 /* Private Message key management (client_prvmsg.c) */
1828
1829 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1830  *
1831  * SYNOPSIS
1832  *
1833  *    bool silc_client_add_private_message_key(SilcClient client,
1834  *                                             SilcClientConnection conn,
1835  *                                             SilcClientEntry client_entry,
1836  *                                             const char *cipher,
1837  *                                             const char *hmac,
1838  *                                             unsigned char *key,
1839  *                                             SilcUInt32 key_len,
1840  *                                             bool generate_key,
1841  *                                             bool responder);
1842  *
1843  * DESCRIPTION
1844  *
1845  *    Adds private message key to the client library. The key will be used to
1846  *    encrypt all private message between the client and the remote client
1847  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1848  *    value `generate_key' is TRUE the library will generate random key.
1849  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1850  *    The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1851  *    that the requirements of the SILC protocol are met. The API, however,
1852  *    allows to allocate any cipher and HMAC.
1853  *
1854  *    If `responder' is TRUE then the sending and receiving keys will be
1855  *    set according the client being the receiver of the private key.  If
1856  *    FALSE the client is being the sender (or negotiator) of the private
1857  *    key.
1858  *
1859  *    It is not necessary to set key for normal private message usage. If the
1860  *    key is not set then the private messages are encrypted using normal
1861  *    session keys. Setting the private key, however, increases the security.
1862  *
1863  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1864  *    otherwise.
1865  *
1866  ***/
1867 bool silc_client_add_private_message_key(SilcClient client,
1868                                          SilcClientConnection conn,
1869                                          SilcClientEntry client_entry,
1870                                          const char *cipher,
1871                                          const char *hmac,
1872                                          unsigned char *key,
1873                                          SilcUInt32 key_len,
1874                                          bool generate_key,
1875                                          bool responder);
1876
1877 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1878  *
1879  * SYNOPSIS
1880  *
1881  *    bool
1882  *    silc_client_add_private_message_key_ske(SilcClient client,
1883  *                                            SilcClientConnection conn,
1884  *                                            SilcClientEntry client_entry,
1885  *                                            const char *cipher,
1886  *                                            const char *hmac,
1887  *                                            SilcSKEKeyMaterial *key);
1888  *
1889  * DESCRIPTION
1890  *
1891  *    Same as silc_client_add_private_message_key but takes the key material
1892  *    from the SKE key material structure. This structure is received if
1893  *    the application uses the silc_client_send_key_agreement to negotiate
1894  *    the key material. The `cipher' and `hmac' SHOULD be provided as it is
1895  *    negotiated also in the SKE protocol.
1896  *
1897  ***/
1898 bool silc_client_add_private_message_key_ske(SilcClient client,
1899                                              SilcClientConnection conn,
1900                                              SilcClientEntry client_entry,
1901                                              const char *cipher,
1902                                              const char *hmac,
1903                                              SilcSKEKeyMaterial *key,
1904                                              bool responder);
1905
1906 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1907  *
1908  * SYNOPSIS
1909  *
1910  *    bool silc_client_del_private_message_key(SilcClient client,
1911  *                                             SilcClientConnection conn,
1912  *                                             SilcClientEntry client_entry);
1913  *
1914  * DESCRIPTION
1915  *
1916  *    Removes the private message from the library. The key won't be used
1917  *    after this to protect the private messages with the remote `client_entry'
1918  *    client. Returns FALSE on error, TRUE otherwise.
1919  *
1920  ***/
1921 bool silc_client_del_private_message_key(SilcClient client,
1922                                          SilcClientConnection conn,
1923                                          SilcClientEntry client_entry);
1924
1925 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1926  *
1927  * SYNOPSIS
1928  *
1929  *    SilcPrivateMessageKeys
1930  *    silc_client_list_private_message_keys(SilcClient client,
1931  *                                          SilcClientConnection conn,
1932  *                                          SilcUInt32 *key_count);
1933  *
1934  * DESCRIPTION
1935  *
1936  *    Returns array of set private message keys associated to the connection
1937  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1938  *    count to the `key_count' argument. The array must be freed by the caller
1939  *    by calling the silc_client_free_private_message_keys function. Note:
1940  *    the keys returned in the array is in raw format. It might not be desired
1941  *    to show the keys as is. The application might choose not to show the keys
1942  *    at all or to show the fingerprints of the keys.
1943  *
1944  ***/
1945 SilcPrivateMessageKeys
1946 silc_client_list_private_message_keys(SilcClient client,
1947                                       SilcClientConnection conn,
1948                                       SilcUInt32 *key_count);
1949
1950 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1951  *
1952  * SYNOPSIS
1953  *
1954  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1955  *                                               SilcUInt32 key_count);
1956  *
1957  * DESCRIPTION
1958  *
1959  *    Frees the SilcPrivateMessageKeys array returned by the function
1960  *    silc_client_list_private_message_keys.
1961  *
1962  ***/
1963 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1964                                            SilcUInt32 key_count);
1965
1966
1967 /* Channel private key management (client_channel.c,
1968    SilcChannelPrivateKey is defined in idlist.h) */
1969
1970 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1971  *
1972  * SYNOPSIS
1973  *
1974  *    bool silc_client_add_channel_private_key(SilcClient client,
1975  *                                             SilcClientConnection conn,
1976  *                                             SilcChannelEntry channel,
1977  *                                             const char *name,
1978  *                                             char *cipher,
1979  *                                             char *hmac,
1980  *                                             unsigned char *key,
1981  *                                             SilcUInt32 key_len);
1982  *
1983  * DESCRIPTION
1984  *
1985  *    Adds private key for channel. This may be set only if the channel's mode
1986  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1987  *    mode is not set. When channel has private key then the messages are
1988  *    encrypted using that key. All clients on the channel must also know the
1989  *    key in order to decrypt the messages. However, it is possible to have
1990  *    several private keys per one channel. In this case only some of the
1991  *    clients on the channel may know the one key and only some the other key.
1992  *    The `name' can be application given name for the key.
1993  *
1994  *    The private key for channel is optional. If it is not set then the
1995  *    channel messages are encrypted using the channel key generated by the
1996  *    server. However, setting the private key (or keys) for the channel
1997  *    significantly adds security. If more than one key is set the library
1998  *    will automatically try all keys at the message decryption phase. Note:
1999  *    setting many keys slows down the decryption phase as all keys has to
2000  *    be tried in order to find the correct decryption key. However, setting
2001  *    a few keys does not have big impact to the decryption performace.
2002  *
2003  * NOTES
2004  *
2005  *    NOTE: This is entirely local setting. The key set using this function
2006  *    is not sent to the network at any phase.
2007  *
2008  *    NOTE: If the key material was originated by the SKE protocol (using
2009  *    silc_client_send_key_agreement) then the `key' MUST be the
2010  *    key->send_enc_key as this is dictated by the SILC protocol. However,
2011  *    currently it is not expected that the SKE key material would be used
2012  *    as channel private key. However, this API allows it.
2013  *
2014  ***/
2015 bool silc_client_add_channel_private_key(SilcClient client,
2016                                          SilcClientConnection conn,
2017                                          SilcChannelEntry channel,
2018                                          const char *name,
2019                                          char *cipher,
2020                                          char *hmac,
2021                                          unsigned char *key,
2022                                          SilcUInt32 key_len);
2023
2024 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
2025  *
2026  * SYNOPSIS
2027  *
2028  *    bool silc_client_del_channel_private_keys(SilcClient client,
2029  *                                              SilcClientConnection conn,
2030  *                                              SilcChannelEntry channel);
2031  *
2032  * DESCRIPTION
2033  *
2034  *    Removes all private keys from the `channel'. The old channel key is used
2035  *    after calling this to protect the channel messages. Returns FALSE on
2036  *    on error, TRUE otherwise.
2037  *
2038  ***/
2039 bool silc_client_del_channel_private_keys(SilcClient client,
2040                                           SilcClientConnection conn,
2041                                           SilcChannelEntry channel);
2042
2043 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2044  *
2045  * SYNOPSIS
2046  *
2047  *    bool silc_client_del_channel_private_key(SilcClient client,
2048  *                                            SilcClientConnection conn,
2049  *                                            SilcChannelEntry channel,
2050  *                                            SilcChannelPrivateKey key);
2051  *
2052  * DESCRIPTION
2053  *
2054  *    Removes and frees private key `key' from the channel `channel'.
2055  *    The `key' is retrieved by calling the function
2056  *    silc_client_list_channel_private_keys. The key is not used after
2057  *    this. If the key was last private key then the old channel key is
2058  *    used hereafter to protect the channel messages. This returns FALSE
2059  *    on error, TRUE otherwise.
2060  *
2061  ***/
2062 bool silc_client_del_channel_private_key(SilcClient client,
2063                                          SilcClientConnection conn,
2064                                          SilcChannelEntry channel,
2065                                          SilcChannelPrivateKey key);
2066
2067 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2068  *
2069  * SYNOPSIS
2070  *
2071  *    SilcChannelPrivateKey *
2072  *    silc_client_list_channel_private_keys(SilcClient client,
2073  *                                          SilcClientConnection conn,
2074  *                                          SilcChannelEntry channel,
2075  *                                          SilcUInt32 *key_count);
2076  *
2077  * DESCRIPTION
2078  *
2079  *    Returns array (pointers) of private keys associated to the `channel'.
2080  *    The caller must free the array by calling the function
2081  *    silc_client_free_channel_private_keys. The pointers in the array may be
2082  *    used to delete the specific key by giving the pointer as argument to the
2083  *    function silc_client_del_channel_private_key.
2084  *
2085  ***/
2086 SilcChannelPrivateKey *
2087 silc_client_list_channel_private_keys(SilcClient client,
2088                                       SilcClientConnection conn,
2089                                       SilcChannelEntry channel,
2090                                       SilcUInt32 *key_count);
2091
2092 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2093  *
2094  * SYNOPSIS
2095  *
2096  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2097  *                                               SilcUInt32 key_count);
2098  *
2099  * DESCRIPTION
2100  *
2101  *    Frees the SilcChannelPrivateKey array.
2102  *
2103  ***/
2104 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2105                                            SilcUInt32 key_count);
2106
2107 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2108  *
2109  * SYNOPSIS
2110  *
2111  *    void silc_client_current_channel_private_key(SilcClient client,
2112  *                                                 SilcClientConnection conn,
2113  *                                                 SilcChannelEntry channel,
2114  *                                                 SilcChannelPrivateKey key);
2115  *
2116  * DESCRIPTION
2117  *
2118  *    Sets the `key' to be used as current channel private key on the
2119  *    `channel'.  Packet sent after calling this function will be secured
2120  *    with `key'.
2121  *
2122  ***/
2123 void silc_client_current_channel_private_key(SilcClient client,
2124                                              SilcClientConnection conn,
2125                                              SilcChannelEntry channel,
2126                                              SilcChannelPrivateKey key);
2127
2128
2129 /* Key Agreement routines (client_keyagr.c) */
2130
2131 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2132  *
2133  * SYNOPSIS
2134  *
2135  *    void silc_client_send_key_agreement(SilcClient client,
2136  *                                        SilcClientConnection conn,
2137  *                                        SilcClientEntry client_entry,
2138  *                                        char *hostname,
2139  *                                        int port,
2140  *                                        SilcUInt32 timeout_secs,
2141  *                                        SilcKeyAgreementCallback completion,
2142  *                                        void *context);
2143  *
2144  * DESCRIPTION
2145  *
2146  *    Sends key agreement request to the remote client indicated by the
2147  *    `client_entry'. If the caller provides the `hostname' and the `port'
2148  *    arguments then the library will bind the client to that hostname and
2149  *    that port for the key agreement protocol. It also sends the `hostname'
2150  *    and the `port' in the key agreement packet to the remote client. This
2151  *    would indicate that the remote client may initiate the key agreement
2152  *    protocol to the `hostname' on the `port'.  If port is zero then the
2153  *    bound port is undefined (the operating system defines it).
2154  *
2155  *    If the `hostname' and `port' is not provided then empty key agreement
2156  *    packet is sent to the remote client. The remote client may reply with
2157  *    the same packet including its hostname and port. If the library receives
2158  *    the reply from the remote client the `key_agreement' client operation
2159  *    callback will be called to verify whether the user wants to perform the
2160  *    key agreement or not.
2161  *
2162  * NOTES
2163  *
2164  *    NOTE: If the application provided the `hostname' and the `port' and the
2165  *    remote side initiates the key agreement protocol it is not verified
2166  *    from the user anymore whether the protocol should be executed or not.
2167  *    By setting the `hostname' and `port' the user gives permission to
2168  *    perform the protocol (we are responder in this case).
2169  *
2170  *    NOTE: If the remote side decides not to initiate the key agreement
2171  *    or decides not to reply with the key agreement packet then we cannot
2172  *    perform the key agreement at all. If the key agreement protocol is
2173  *    performed the `completion' callback with the `context' will be called.
2174  *    If remote side decides to ignore the request the `completion' will be
2175  *    called after the specified timeout, `timeout_secs'.
2176  *
2177  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
2178  *    will not be called at all since this does nothing more than sending
2179  *    a packet to the remote host.
2180  *
2181  *    NOTE: There can be only one active key agreement for one client entry.
2182  *    Before setting new one, the old one must be finished (it is finished
2183  *    after calling the completion callback) or the function
2184  *    silc_client_abort_key_agreement must be called.
2185  *
2186  ***/
2187 void silc_client_send_key_agreement(SilcClient client,
2188                                     SilcClientConnection conn,
2189                                     SilcClientEntry client_entry,
2190                                     const char *hostname,
2191                                     const char *bindhost,
2192                                     int port,
2193                                     SilcUInt32 timeout_secs,
2194                                     SilcKeyAgreementCallback completion,
2195                                     void *context);
2196
2197 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2198  *
2199  * SYNOPSIS
2200  *
2201  *    void
2202  *    silc_client_perform_key_agreement(SilcClient client,
2203  *                                      SilcClientConnection conn,
2204  *                                      SilcClientEntry client_entry,
2205  *                                      char *hostname,
2206  *                                      int port,
2207  *                                      SilcKeyAgreementCallback completion,
2208  *                                      void *context);
2209  *
2210  * DESCRIPTION
2211  *
2212  *    Performs the actual key agreement protocol. Application may use this
2213  *    to initiate the key agreement protocol. This can be called for example
2214  *    after the application has received the `key_agreement' client operation,
2215  *    and did not return TRUE from it.
2216  *
2217  *    The `hostname' is the remote hostname (or IP address) and the `port'
2218  *    is the remote port. The `completion' callback with the `context' will
2219  *    be called after the key agreement protocol.
2220  *
2221  * NOTES
2222  *
2223  *    NOTE: If the application returns TRUE in the `key_agreement' client
2224  *    operation the library will automatically start the key agreement. In this
2225  *    case the application must not call this function. However, application
2226  *    may choose to just ignore the `key_agreement' client operation (and
2227  *    merely just print information about it on the screen) and call this
2228  *    function when the user whishes to do so (by, for example, giving some
2229  *    specific command). Thus, the API provides both, automatic and manual
2230  *    initiation of the key agreement. Calling this function is the manual
2231  *    initiation and returning TRUE in the `key_agreement' client operation
2232  *    is the automatic initiation.
2233  *
2234  ***/
2235 void silc_client_perform_key_agreement(SilcClient client,
2236                                        SilcClientConnection conn,
2237                                        SilcClientEntry client_entry,
2238                                        char *hostname,
2239                                        int port,
2240                                        SilcKeyAgreementCallback completion,
2241                                        void *context);
2242
2243 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2244  *
2245  * SYNOPSIS
2246  *
2247  *    void
2248  *    silc_client_perform_key_agreement_fd(SilcClient client,
2249  *                                         SilcClientConnection conn,
2250  *                                         SilcClientEntry client_entry,
2251  *                                         int sock,
2252  *                                         char *hostname,
2253  *                                         SilcKeyAgreementCallback completion,
2254  *                                         void *context);
2255  *
2256  * DESCRIPTION
2257  *
2258  *    Same as above but application has created already the connection to
2259  *    the remote host. The `sock' is the socket to the remote connection.
2260  *    Application can use this function if it does not want the client library
2261  *    to create the connection.
2262  *
2263  ***/
2264 void silc_client_perform_key_agreement_fd(SilcClient client,
2265                                           SilcClientConnection conn,
2266                                           SilcClientEntry client_entry,
2267                                           int sock,
2268                                           char *hostname,
2269                                           SilcKeyAgreementCallback completion,
2270                                           void *context);
2271
2272 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2273  *
2274  * SYNOPSIS
2275  *
2276  *    void silc_client_abort_key_agreement(SilcClient client,
2277  *                                         SilcClientConnection conn,
2278  *                                         SilcClientEntry client_entry);
2279  *
2280  * DESCRIPTION
2281  *
2282  *    This function can be called to unbind the hostname and the port for
2283  *    the key agreement protocol. However, this function has effect only
2284  *    before the key agreement protocol has been performed. After it has
2285  *    been performed the library will automatically unbind the port. The
2286  *    `client_entry' is the client to which we sent the key agreement
2287  *    request.  The key agreement completion callback will be called
2288  *    with SILC_KEY_AGREEMENT_ABORTED status.
2289  *
2290  ***/
2291 void silc_client_abort_key_agreement(SilcClient client,
2292                                      SilcClientConnection conn,
2293                                      SilcClientEntry client_entry);
2294
2295
2296 /* Misc functions */
2297
2298 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2299  *
2300  * SYNOPSIS
2301  *
2302  *    void silc_client_set_away_message(SilcClient client,
2303  *                                      SilcClientConnection conn,
2304  *                                      char *message);
2305  *
2306  * DESCRIPTION
2307  *
2308  *    Sets away `message'.  The away message may be set when the client's
2309  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
2310  *    to anyone who sends private message.  The `message' will be sent
2311  *    automatically back to the the client who send private message.  If
2312  *    away message is already set this replaces the old message with the
2313  *    new one.  If `message' is NULL the old away message is removed.
2314  *    The sender may freely free the memory of the `message'.
2315  *
2316  ***/
2317 void silc_client_set_away_message(SilcClient client,
2318                                   SilcClientConnection conn,
2319                                   char *message);
2320
2321 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2322  *
2323  * SYNOPSIS
2324  *
2325  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2326  *                                              SilcClientConnection conn,
2327  *                                              SilcAuthMethod auth_meth,
2328  *                                              void *context);
2329  *
2330  * DESCRIPTION
2331  *
2332  *    Connection authentication method request callback. This is called
2333  *    by the client library after it has received the authentication method
2334  *    that the application requested by calling the function
2335  *    silc_client_request_authentication_method.
2336  *
2337  ***/
2338 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2339                                           SilcClientConnection conn,
2340                                           SilcAuthMethod auth_meth,
2341                                           void *context);
2342
2343 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2344  *
2345  * SYNOPSIS
2346  *
2347  *    void
2348  *    silc_client_request_authentication_method(SilcClient client,
2349  *                                              SilcClientConnection conn,
2350  *                                              SilcConnectionAuthRequest
2351  *                                                callback,
2352  *                                              void *context);
2353  *
2354  * DESCRIPTION
2355  *
2356  *    This function can be used to request the current authentication method
2357  *    from the server. This may be called when connecting to the server
2358  *    and the client library requests the authentication data from the
2359  *    application. If the application does not know the current authentication
2360  *    method it can request it from the server using this function.
2361  *    The `callback' with `context' will be called after the server has
2362  *    replied back with the current authentication method.
2363  *
2364  ***/
2365 void
2366 silc_client_request_authentication_method(SilcClient client,
2367                                           SilcClientConnection conn,
2368                                           SilcConnectionAuthRequest callback,
2369                                           void *context);
2370
2371 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2372  *
2373  * NAME
2374  *
2375  *    typedef enum { ... } SilcClientMonitorStatus;
2376  *
2377  * DESCRIPTION
2378  *
2379  *    File transmission session status types.  These will indicate
2380  *    the status of the file transmission session.
2381  *
2382  * SOURCE
2383  */
2384 typedef enum {
2385   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
2386   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
2387   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
2388   SILC_CLIENT_FILE_MONITOR_GET,
2389   SILC_CLIENT_FILE_MONITOR_PUT,
2390   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
2391   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
2392 } SilcClientMonitorStatus;
2393 /***/
2394
2395 /****d* silcclient/SilcClientAPI/SilcClientFileError
2396  *
2397  * NAME
2398  *
2399  *    typedef enum { ... } SilcClientFileError;
2400  *
2401  * DESCRIPTION
2402  *
2403  *    File transmission error types.  These types are returned by
2404  *    some of the file transmission functions, and by the monitor
2405  *    callback to indicate error.
2406  *
2407  * SOURCE
2408  */
2409 typedef enum {
2410   SILC_CLIENT_FILE_OK,
2411   SILC_CLIENT_FILE_ERROR,
2412   SILC_CLIENT_FILE_UNKNOWN_SESSION,
2413   SILC_CLIENT_FILE_ALREADY_STARTED,
2414   SILC_CLIENT_FILE_NO_SUCH_FILE,
2415   SILC_CLIENT_FILE_PERMISSION_DENIED,
2416   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2417 } SilcClientFileError;
2418 /***/
2419
2420 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2421  *
2422  * SYNOPSIS
2423  *
2424  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
2425  *                                          SilcClientConnection conn,
2426  *                                          SilcClientMonitorStatus status,
2427  *                                          SilcClientFileError error,
2428  *                                          SilcUInt64 offset,
2429  *                                          SilcUInt64 filesize,
2430  *                                          SilcClientEntry client_entry,
2431  *                                          SilcUInt32 session_id,
2432  *                                          const char *filepath,
2433  *                                          void *context);
2434  *
2435  * DESCRIPTION
2436  *
2437  *    Monitor callback that is called during the file transmission to
2438  *    monitor the transmission process.  The `status' indicates the current
2439  *    monitoring process.  The `error' will indicate the error type
2440  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
2441  *    currently transmitted amount of total `filesize'.  The `client_entry'
2442  *    indicates the remote client, and the transmission session ID is the
2443  *    `session_id'.  The filename being transmitted is indicated by the
2444  *    `filepath'.
2445  *
2446  ***/
2447 typedef void (*SilcClientFileMonitor)(SilcClient client,
2448                                       SilcClientConnection conn,
2449                                       SilcClientMonitorStatus status,
2450                                       SilcClientFileError error,
2451                                       SilcUInt64 offset,
2452                                       SilcUInt64 filesize,
2453                                       SilcClientEntry client_entry,
2454                                       SilcUInt32 session_id,
2455                                       const char *filepath,
2456                                       void *context);
2457
2458 /****f* silcclient/SilcClientAPI/silc_client_file_send
2459  *
2460  * SYNOPSIS
2461  *
2462  *    SilcClientFileError
2463  *    silc_client_file_send(SilcClient client,
2464  *                          SilcClientConnection conn,
2465  *                          SilcClientFileMonitor monitor,
2466  *                          void *monitor_context,
2467  *                          const char *local_ip,
2468  *                          SilcUInt32 local_port,
2469  *                          bool do_not_bind,
2470  *                          SilcClientEntry client_entry,
2471  *                          const char *filepath);
2472  *                          SilcUInt32 *session_id);
2473  *
2474  * DESCRIPTION
2475  *
2476  *    Sends a file indicated by the `filepath' to the remote client
2477  *    indicated by the `client_entry'.  This will negotiate a secret key
2478  *    with the remote client before actually starting the transmission of
2479  *    the file.  The `monitor' callback will be called to monitor the
2480  *    transmission of the file.
2481  *
2482  *    This returns a file session ID for the file transmission to the
2483  *    `session_id' pointer.  It can be used to close the session (and
2484  *    abort the file transmission) by calling the silc_client_file_close
2485  *    function.  The session ID is also returned in the `monitor' callback.
2486  *
2487  *    If the `local_ip' is provided then this will try to bind the
2488  *    listener for key exchange protocol to that IP.  If `local_port' is
2489  *    non-zero that port is used.  If `local_ip' is NULL then this will
2490  *    automatically attempt to bind it to local IP address of the machine.
2491  *    If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2492  *    ignored and it is expected that the receiver will provide the
2493  *    point of contact.  This is usefull if the sender is behind NAT.
2494  *
2495  *    If error will occur during the file transfer process the error
2496  *    status will be returned in the monitor callback.  In this case
2497  *    the application must call silc_client_file_close to close the
2498  *    session.
2499  *
2500  ***/
2501 SilcClientFileError
2502 silc_client_file_send(SilcClient client,
2503                       SilcClientConnection conn,
2504                       SilcClientFileMonitor monitor,
2505                       void *monitor_context,
2506                       const char *local_ip,
2507                       SilcUInt32 local_port,
2508                       bool do_not_bind,
2509                       SilcClientEntry client_entry,
2510                       const char *filepath,
2511                       SilcUInt32 *session_id);
2512
2513 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2514  *
2515  * SYNOPSIS
2516  *
2517  *    SilcClientFileError
2518  *    silc_client_file_receive(SilcClient client,
2519  *                             SilcClientConnection conn,
2520  *                             SilcClientFileMonitor monitor,
2521  *                             void *monitor_context,
2522  *                             const char *path,
2523  *                             SilcUInt32 session_id);
2524  *
2525  * DESCRIPTION
2526  *
2527  *    Receives a file from a client indicated by the `client_entry'.  The
2528  *    `session_id' indicates the file transmission session and it has been
2529  *    received in the `ftp' client operation function.  This will actually
2530  *    perform the key agreement protocol with the remote client before
2531  *    actually starting the file transmission.  The `monitor' callback
2532  *    will be called to monitor the transmission.  If `path' is non NULL
2533  *    the file will be saved into that directory.  If NULL the file is
2534  *    saved in the current working directory.
2535  *
2536  *    If error will occur during the file transfer process the error
2537  *    status will be returned in the monitor callback.  In this case
2538  *    the application must call silc_client_file_close to close the
2539  *    session.
2540  *
2541  ***/
2542 SilcClientFileError
2543 silc_client_file_receive(SilcClient client,
2544                          SilcClientConnection conn,
2545                          SilcClientFileMonitor monitor,
2546                          void *monitor_context,
2547                          const char *path,
2548                          SilcUInt32 session_id);
2549
2550 /****f* silcclient/SilcClientAPI/silc_client_file_close
2551  *
2552  * SYNOPSIS
2553  *
2554  *    SilcClientFileError silc_client_file_close(SilcClient client,
2555  *                                               SilcClientConnection conn,
2556  *                                               SilcUInt32 session_id);
2557  *
2558  * DESCRIPTION
2559  *
2560  *    Closes file transmission session indicated by the `session_id'.
2561  *    If file transmission is being conducted it will be aborted
2562  *    automatically. This function is also used to close the session
2563  *    after successful file transmission. This function can be used
2564  *    also to reject incoming file transmission request.
2565  *
2566  ***/
2567 SilcClientFileError silc_client_file_close(SilcClient client,
2568                                            SilcClientConnection conn,
2569                                            SilcUInt32 session_id);
2570
2571 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2572  *
2573  * SYNOPSIS
2574  *
2575  *    SilcAttributePayload
2576  *    silc_client_attribute_add(SilcClient client,
2577  *                              SilcClientConnection conn,
2578  *                              SilcAttribute attribute,
2579  *                              void *object,
2580  *                              SilcUInt32 object_size);
2581  *
2582  * DESCRIPTION
2583  *
2584  *    Add new Requsted Attribute for WHOIS command to the client library.
2585  *    The `attribute' object indicated by `object' is added and allocated
2586  *    SilcAttributePayload is returned.  The `object' must be of correct
2587  *    type and of correct size.  See the SilcAttribute for object types
2588  *    for different attributes.  You may also get all added attributes
2589  *    from the client with silc_client_attributes_get function.
2590  *
2591  *    Requested Attributes are different personal information about the
2592  *    user, status information and other information which other users
2593  *    may query with WHOIS command.  Application may set these so that
2594  *    if someone sends WHOIS query these attributes will be replied back
2595  *    to the sender.  The library always puts the public key to the
2596  *    Requested Attributes, but if application wishes to add additional
2597  *    public keys (or certificates) it can be done with this interface.
2598  *    Library also always computes digital signature of the attributes
2599  *    automatically, so application does not need to do that.
2600  *
2601  ***/
2602 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2603                                                SilcClientConnection conn,
2604                                                SilcAttribute attribute,
2605                                                void *object,
2606                                                SilcUInt32 object_size);
2607
2608 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2609  *
2610  * SYNOPSIS
2611  *
2612  *    bool silc_client_attribute_del(SilcClient client,
2613  *                                   SilcClientConnection conn,
2614  *                                   SilcAttribute attribute,
2615  *                                   SilcAttributePayload attr);
2616  *
2617  * DESCRIPTION
2618  *
2619  *    Delete a Requested Attribute from the client.  If the `attribute'
2620  *    is non-zero then all attributes of that type are deleted and the
2621  *    `attr' is ignored.  If `attr' is non-NULL then that specific
2622  *    attribute is deleted and `attribute' is ignored.
2623  *
2624  *    You may get all added attributes with the function
2625  *    silc_client_attributes_get and to get the SilcAttributePayload.
2626  *    This function Returns TRUE if the attribute was found and deleted.
2627  *
2628  ***/
2629 bool silc_client_attribute_del(SilcClient client,
2630                                SilcClientConnection conn,
2631                                SilcAttribute attribute,
2632                                SilcAttributePayload attr);
2633
2634 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2635  *
2636  * SYNOPSIS
2637  *
2638  *    const SilcHashTable
2639  *    silc_client_attributes_get(SilcClient client,
2640  *                               SilcClientConnection conn);
2641  *
2642  * DESCRIPTION
2643  *
2644  *    Returns pointer to the SilcHashTable which includes all the added
2645  *    Requested Attributes.  The caller must not free the hash table.
2646  *    The caller may use SilcHashTableList and silc_hash_table_list to
2647  *    traverse the table.  Each entry in the hash table is one added
2648  *    SilcAttributePayload.  It is possible to delete a attribute
2649  *    payload while traversing the table.
2650  *
2651  ***/
2652 const SilcHashTable silc_client_attributes_get(SilcClient client,
2653                                                SilcClientConnection conn);
2654
2655 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2656  *
2657  * SYNOPSIS
2658  *
2659  *    SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2660  *
2661  * DESCRIPTION
2662  *
2663  *    Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2664  *    then all attributes are requested.  Alternatively, `attribute' and
2665  *    all variable arguments can each be requested attribute.  In this case
2666  *    the last must be set to zero (0) to complete the variable list of
2667  *    requested attributes.  See SilcAttribute for all attributes.
2668  *    You can give the returned buffer as argument to for example
2669  *    silc_client_get_client_by_id_resolve function.
2670  *
2671  * EXAMPLE
2672  *
2673  *    Request all attributes
2674  *    buffer = silc_client_attributes_request(0);
2675  *
2676  *    Request only the following attributes
2677  *    buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2678  *                                            SILC_ATTRIBUTE_SERVICE,
2679  *                                            SILC_ATTRIBUTE_MOOD, 0);
2680  *
2681  ***/
2682 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2683
2684 /* Low level packet sending functions */
2685
2686 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2687  *
2688  * SYNOPSIS
2689  *
2690  *     bool silc_client_send_packet(SilcClient client,
2691  *                                  SilcClientConnection conn,
2692  *                                  SilcPacketType type,
2693  *                                  const unsigned char *data,
2694  *                                  SilcUInt32 data_len);
2695  *
2696  * DESCRIPTION
2697  *
2698  *    This routine can be used by application to send packets directly
2699  *    to a connection indicated by `conn'.  Usually application does not
2700  *    need this routine since the Client Library handles the packet
2701  *    sending.  The `type' indicates the packet type.  If `data' is
2702  *    NULL then empty packet is sent.  This returns FALSE if packet cannot
2703  *    be sent.
2704  *
2705  ***/
2706 bool silc_client_send_packet(SilcClient client,
2707                              SilcClientConnection conn,
2708                              SilcPacketType type,
2709                              const unsigned char *data,
2710                              SilcUInt32 data_len);
2711
2712 #include "command.h"
2713 #include "command_reply.h"
2714 #include "idlist.h"
2715 #include "protocol.h"
2716
2717 #ifdef __cplusplus
2718 }
2719 #endif
2720
2721 #endif /* SILCCLIENT_H */