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