updates.
[silc.git] / lib / silcclient / silcapi.h
1 /****h* silcclient/silcapi.h
2  *
3  * NAME
4  *
5  * silcapi.h
6  *
7  * COPYRIGHT
8  *
9  * Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
10  *
11  * Copyright (C) 2000 - 2001 Pekka Riikonen
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * DESCRIPTION
24  *
25  * This file defines the SILC Client Library API for the application.  The
26  * client operations are defined first.  These are callback functions that
27  * the application MUST implement since the library may call the functions
28  * at any time.  At the end of file is the API for the application that
29  * it can use from the library.  This is the only file that the application
30  * may include from the SIlC Client Library.
31  *
32  * o SILC Client Operations
33  *
34  *   These functions must be implemented by the application calling the SILC
35  *   client library. The client library can call these functions at any time.
36  *
37  *   To use this structure: define a static SilcClientOperations variable,
38  *   fill it and pass its pointer to silc_client_alloc function.
39  *
40  * o SILC Client Library API
41  *
42  *   This is the API that is published by the SILC Client Library for the
43  *   applications.  These functions are implemented in the SILC Client Library.
44  *   Application may freely call these functions from the library.
45  *
46  * Please, refer to the README file in this directory for the directions
47  * of how to use the SILC Client Library.
48  *
49  ***/
50
51 #ifndef SILCAPI_H
52 #define SILCAPI_H
53
54 #include "clientlibincludes.h"
55
56 /* General definitions */
57
58 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
59  *
60  * NAME
61  *
62  *    typedef enum { ... } SilcKeyAgreementStatus;
63  *
64  * DESCRIPTION
65  *
66  *    Key agreement status types indicating the status of the key
67  *    agreement protocol.  These types are returned to the application 
68  *    in the SilcKeyAgreementCallback callback function.
69  *
70  * SOURCE
71  */
72 typedef enum {
73   SILC_KEY_AGREEMENT_OK,               /* Everything is Ok */
74   SILC_KEY_AGREEMENT_ERROR,            /* Unknown error occurred */
75   SILC_KEY_AGREEMENT_FAILURE,          /* The protocol failed */
76   SILC_KEY_AGREEMENT_TIMEOUT,          /* The protocol timeout */
77 } SilcKeyAgreementStatus;
78 /***/
79
80 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
81  *
82  * SYNOPSIS
83  *
84  *    typedef void (*SilcKeyAgreementCallback)(SilcClient client,
85  *                                             SilcClientConnection conn,
86  *                                             SilcClientEntry client_entry,
87  *                                             SilcKeyAgreementStatus status,
88  *                                             SilcSKEKeyMaterial *key,
89  *                                             void *context);
90  *
91  * DESCRIPTION
92  *
93  *    Key agreement callback that is called after the key agreement protocol
94  *    has been performed. This is called also if error occurred during the
95  *    key agreement protocol. The `key' is the allocated key material and
96  *    the caller is responsible of freeing it. The `key' is NULL if error
97  *    has occurred. The application can freely use the `key' to whatever
98  *    purpose it needs. See lib/silcske/silcske.h for the definition of
99  *    the SilcSKEKeyMaterial structure.
100  *
101  ***/
102 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
103                                          SilcClientConnection conn,
104                                          SilcClientEntry client_entry,
105                                          SilcKeyAgreementStatus status,
106                                          SilcSKEKeyMaterial *key,
107                                          void *context);
108
109 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
110  *
111  * NAME
112  *
113  *    typedef struct { ... } SilcPrivateMessageKeys;
114  *
115  * DESCRIPTION
116  *
117  *    Structure to hold the list of private message keys. The array of this
118  *    structure is returned by the silc_client_list_private_message_keys
119  *    function.
120  *
121  * SOURCE
122  */
123 typedef struct {
124   SilcClientEntry client_entry;       /* The remote client entry */
125   char *cipher;                       /* The cipher name */
126   unsigned char *key;                 /* The original key, If the appliation
127                                          provided it. This is NULL if the
128                                          library generated the key or if
129                                          the SKE key material was used. */
130   uint32 key_len;                     /* The key length */
131 } *SilcPrivateMessageKeys;
132 /***/
133
134
135 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
136  *
137  * SYNOPSIS
138  *
139  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
140  *                                      uint32 passphrase_len,
141  *                                      void *context);
142  *
143  * DESCRIPTION
144  *
145  *    Ask passphrase callback. This is called by the application when the
146  *    library calls `ask_passphrase' client operation.  The callback delivers
147  *    the passphrase to the library.
148  *
149  ***/
150 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
151                                   uint32 passphrase_len,
152                                   void *context);
153
154 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
155  *
156  * SYNOPSIS
157  *
158  *    typedef void (*SilcVerifyPublicKey)(bool success, void *context);
159  *
160  * DESCRIPTION
161  *
162  *    Public key (or certificate) verification callback. This is called
163  *    by the application to indicate that the public key verification was
164  *    either success or failure.
165  *
166  ***/
167 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
168
169 /****d* silcclient/SilcClientAPI/SilcClientMessageType
170  *
171  * NAME
172  *
173  *    typedef enum { ... } SilcClientMessageType;
174  *
175  * DESCRIPTION
176  *
177  *    Different message types for `say' client operation.  The application
178  *    may filter the message sent by the library according this type.
179  *
180  * SOURCE
181  */
182 typedef enum {
183   SILC_CLIENT_MESSAGE_INFO,            /* Informational */
184   SILC_CLIENT_MESSAGE_WARNING,         /* Warning */
185   SILC_CLIENT_MESSAGE_ERROR,           /* Error */
186   SILC_CLIENT_MESSAGE_AUDIT,           /* Auditable */
187 } SilcClientMessageType;
188 /***/
189
190 /****s* silcclient/SilcClientAPI/SilcClientOperations
191  *
192  * NAME
193  *
194  *    typedef struct { ... } SilcClientOperations;
195  *
196  * DESCRIPTION
197  *
198  *    SILC Client Operations. These must be implemented by the application.
199  *    The Client library may call any of these routines at any time.  The
200  *    routines are used to deliver certain information to the application
201  *    or from the application to the client library.
202  *
203  * SOURCE
204  */
205 typedef struct {
206   /* Message sent to the application by library. `conn' associates the
207      message to a specific connection.  `conn', however, may be NULL. 
208      The `type' indicates the type of the message sent by the library.
209      The applicationi can for example filter the message according the
210      type. */
211   void (*say)(SilcClient client, SilcClientConnection conn, 
212               SilcClientMessageType type, char *msg, ...);
213
214   /* Message for a channel. The `sender' is the sender of the message 
215      The `channel' is the channel. */
216   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
217                           SilcClientEntry sender, SilcChannelEntry channel, 
218                           SilcMessageFlags flags, char *msg);
219
220   /* Private message to the client. The `sender' is the sender of the
221      message. */
222   void (*private_message)(SilcClient client, SilcClientConnection conn,
223                           SilcClientEntry sender, SilcMessageFlags flags,
224                           char *msg);
225
226   /* Notify message to the client. The notify arguments are sent in the
227      same order as servers sends them. The arguments are same as received
228      from the server except for ID's.  If ID is received application receives
229      the corresponding entry to the ID. For example, if Client ID is received
230      application receives SilcClientEntry.  Also, if the notify type is
231      for channel the channel entry is sent to application (even if server
232      does not send it because client library gets the channel entry from
233      the Channel ID in the packet's header). */
234   void (*notify)(SilcClient client, SilcClientConnection conn, 
235                  SilcNotifyType type, ...);
236
237   /* Command handler. This function is called always in the command function.
238      If error occurs it will be called as well. `conn' is the associated
239      client connection. `cmd_context' is the command context that was
240      originally sent to the command. `success' is FALSE if error occurred
241      during command. `command' is the command being processed. It must be
242      noted that this is not reply from server. This is merely called just
243      after application has called the command. Just to tell application
244      that the command really was processed. */
245   void (*command)(SilcClient client, SilcClientConnection conn, 
246                   SilcClientCommandContext cmd_context, int success,
247                   SilcCommand command);
248
249   /* Command reply handler. This function is called always in the command reply
250      function. If error occurs it will be called as well. Normal scenario
251      is that it will be called after the received command data has been parsed
252      and processed. The function is used to pass the received command data to
253      the application. 
254      
255      `conn' is the associated client connection. `cmd_payload' is the command
256      payload data received from server and it can be ignored. It is provided
257      if the application would like to re-parse the received command data,
258      however, it must be noted that the data is parsed already by the library
259      thus the payload can be ignored. `success' is FALSE if error occurred.
260      In this case arguments are not sent to the application. The `status' is
261      the command reply status server returned. The `command' is the command
262      reply being processed. The function has variable argument list and each
263      command defines the number and type of arguments it passes to the
264      application (on error they are not sent). */
265   void (*command_reply)(SilcClient client, SilcClientConnection conn,
266                         SilcCommandPayload cmd_payload, int success,
267                         SilcCommand command, SilcCommandStatus status, ...);
268
269   /* Called to indicate that connection was either successfully established
270      or connecting failed.  This is also the first time application receives
271      the SilcClientConnection objecet which it should save somewhere. */
272   void (*connect)(SilcClient client, SilcClientConnection conn, int success);
273
274   /* Called to indicate that connection was disconnected to the server. */
275   void (*disconnect)(SilcClient client, SilcClientConnection conn);
276
277   /* Find authentication method and authentication data by hostname and
278      port. The hostname may be IP address as well. The found authentication
279      method and authentication data is returned to `auth_meth', `auth_data'
280      and `auth_data_len'. The function returns TRUE if authentication method
281      is found and FALSE if not. `conn' may be NULL. */
282   int (*get_auth_method)(SilcClient client, SilcClientConnection conn,
283                          char *hostname, uint16 port,
284                          SilcProtocolAuthMeth *auth_meth,
285                          unsigned char **auth_data,
286                          uint32 *auth_data_len);
287
288   /* Verifies received public key. The `conn_type' indicates which entity
289      (server, client etc.) has sent the public key. If user decides to trust
290      the key may be saved as trusted public key for later use. The 
291      `completion' must be called after the public key has been verified. */
292   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
293                             SilcSocketType conn_type, unsigned char *pk, 
294                             uint32 pk_len, SilcSKEPKType pk_type,
295                             SilcVerifyPublicKey completion, void *context);
296
297   /* Ask (interact, that is) a passphrase from user. The passphrase is
298      returned to the library by calling the `completion' callback with
299      the `context'. */
300   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
301                          SilcAskPassphrase completion, void *context);
302
303   /* Notifies application that failure packet was received.  This is called
304      if there is some protocol active in the client.  The `protocol' is the
305      protocol context.  The `failure' is opaque pointer to the failure
306      indication.  Note, that the `failure' is protocol dependant and
307      application must explicitly cast it to correct type.  Usually `failure'
308      is 32 bit failure type (see protocol specs for all protocol failure
309      types). */
310   void (*failure)(SilcClient client, SilcClientConnection conn, 
311                   SilcProtocol protocol, void *failure);
312
313   /* Asks whether the user would like to perform the key agreement protocol.
314      This is called after we have received an key agreement packet or an
315      reply to our key agreement packet. This returns TRUE if the user wants
316      the library to perform the key agreement protocol and FALSE if it is not
317      desired (application may start it later by calling the function
318      silc_client_perform_key_agreement). If TRUE is returned also the
319      `completion' and `context' arguments must be set by the application. */
320   int (*key_agreement)(SilcClient client, SilcClientConnection conn,
321                        SilcClientEntry client_entry, char *hostname,
322                        int port,
323                        SilcKeyAgreementCallback *completion,
324                        void **context);
325 } SilcClientOperations;
326 /***/
327
328 /****s* silcclient/SilcClientAPI/SilcClientParams
329  *
330  * NAME
331  *
332  *    typedef struct { ... } SilcClientParams;
333  *
334  * DESCRIPTION
335  *
336  *    Client parameters. This can be filled with proper values and
337  *    given as argument to the silc_client_alloc function. The structure
338  *    hold various parameters which affects the function of the client.
339  *
340  * SOURCE
341  */
342 typedef struct {
343   /* Number of maximum tasks the client library's scheduler can handle.
344      If set to zero, the default value will be used (200). For WIN32
345      systems this should be set to 64 as it is the hard limit dictated
346      by the WIN32. */
347   int task_max;
348
349   /* Rekey timeout in seconds. The client will perform rekey in this
350      time interval. If set to zero, the default value will be used. */
351   unsigned int rekey_secs;
352 } SilcClientParams;
353 /***/
354
355
356 /* Initialization functions (client.c) */
357
358 /****f* silcclient/SilcClientAPI/silc_client_alloc
359  *
360  * SYNOPSIS
361  *
362  *    SilcClient silc_client_alloc(SilcClientOperations *ops, 
363  *                                 SilcClientParams *params,
364  *                                 void *application,
365  *                                 const char *silc_version);
366  *
367  * DESCRIPTION
368  *
369  *    Allocates new client object. This has to be done before client may
370  *    work. After calling this one must call silc_client_init to initialize
371  *    the client. The `application' is application specific user data pointer
372  *    and caller must free it. The `silc_version' is the application version
373  *    that will be used to compare against remote host's (usually a server)
374  *    version string.
375  *
376  ***/
377 SilcClient silc_client_alloc(SilcClientOperations *ops, 
378                              SilcClientParams *params,
379                              void *application,
380                              const char *silc_version);
381
382 /****f* silcclient/SilcClientAPI/silc_client_free
383  *
384  * SYNOPSIS
385  *
386  *    void silc_client_free(SilcClient client);
387  *
388  * DESCRIPTION
389  *
390  *    Frees client object and its internals.  The execution of the client
391  *    should be stopped with silc_client_stop function before calling
392  *    this function.
393  *
394  ***/
395 void silc_client_free(SilcClient client);
396
397 /****f* silcclient/SilcClientAPI/silc_client_init
398  *
399  * SYNOPSIS
400  *
401  *    int silc_client_init(SilcClient client);
402  *
403  * DESCRIPTION
404  *
405  *    Initializes the client. This makes all the necessary steps to make
406  *    the client ready to be run. One must call silc_client_run to run the
407  *    client. Returns FALSE if error occurred, TRUE otherwise.
408  *
409  ***/
410 int silc_client_init(SilcClient client);
411
412 /****f* silcclient/SilcClientAPI/silc_client_run
413  *
414  * SYNOPSIS
415  *
416  *    void silc_client_run(SilcClient client);
417  *
418  * DESCRIPTION
419  *
420  *    Runs the client. This starts the scheduler from the utility library.
421  *    When this functions returns the execution of the appliation is over.
422  *
423  ***/
424 void silc_client_run(SilcClient client);
425
426 /****f* silcclient/SilcClientAPI/silc_client_stop
427  *
428  * SYNOPSIS
429  *
430  *    void silc_client_stop(SilcClient client);
431  *
432  * DESCRIPTION
433  *
434  *    Stops the client. This is called to stop the client and thus to stop
435  *    the program.  The client context must be freed with the silc_client_free
436  *    function.
437  *
438  ***/
439 void silc_client_stop(SilcClient client);
440
441
442 /* Connecting functions (client.c) */
443
444 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
445  *
446  * SYNOPSIS
447  *
448  *    int silc_client_connect_to_server(SilcClient client, int port,
449  *                                      char *host, void *context);
450  *
451  * DESCRIPTION
452  *
453  *    Connects to remote server. This is the main routine used to connect
454  *    to SILC server. Returns -1 on error and the created socket otherwise. 
455  *    The `context' is user context that is saved into the SilcClientConnection
456  *    that is created after the connection is created. Note that application
457  *    may handle the connecting process outside the library. If this is the
458  *    case then this function is not used at all. When the connecting is
459  *    done the `connect' client operation is called.
460  *
461  ***/
462 int silc_client_connect_to_server(SilcClient client, int port,
463                                   char *host, void *context);
464
465 /****f* silcclient/SilcClientAPI/silc_client_add_connection
466  *
467  * SYNOPSIS
468  *
469  *    SilcClientConnection silc_client_add_connection(SilcClient client,
470  *                                                    char *hostname,
471  *                                                    int port,
472  *                                                    void *context);
473  *
474  * DESCRIPTION
475  *
476  *    Allocates and adds new connection to the client. This adds the allocated
477  *    connection to the connection table and returns a pointer to it. A client
478  *    can have multiple connections to multiple servers. Every connection must
479  *    be added to the client using this function. User data `context' may
480  *    be sent as argument. This function is normally used only if the 
481  *    application performed the connecting outside the library. The library
482  *    however may use this internally.
483  *
484  ***/
485 SilcClientConnection silc_client_add_connection(SilcClient client,
486                                                 char *hostname,
487                                                 int port,
488                                                 void *context);
489
490 /****f* silcclient/SilcClientAPI/silc_client_del_connection
491  *
492  * SYNOPSIS
493  *
494  *    void silc_client_del_connection(SilcClient client, 
495  *                                    SilcClientConnection conn);
496  *
497  * DESCRIPTION
498  *
499  *    Removes connection from client. Frees all memory. The library
500  *    call this function automatically for all connection contexts.
501  *    The application however may free the connection contexts it has
502  *    allocated.
503  *
504  ***/
505 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
506
507 /****f* silcclient/SilcClientAPI/silc_client_add_socket
508  *
509  * SYNOPSIS
510  *
511  *    void silc_client_add_socket(SilcClient client, 
512  *                                SilcSocketConnection sock);
513  *
514  * DESCRIPTION
515  *
516  *    Adds listener socket to the listener sockets table. This function is
517  *    used to add socket objects that are listeners to the client.  This should
518  *    not be used to add other connection objects.
519  *
520  ***/
521 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
522
523 /****f* silcclient/SilcClientAPI/silc_client_del_socket
524  *
525  * SYNOPSIS
526  *
527  *    void silc_client_del_socket(SilcClient client, 
528  *                                SilcSocketConnection sock);
529  *
530  * DESCRIPTION
531  *
532  *    Deletes listener socket from the listener sockets table.  If the
533  *    application has added a socket with silc_client_add_socket it must
534  *    also free it using this function.
535  *
536  ***/
537 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
538
539 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
540  *
541  * SYNOPSIS
542  *
543  *    int silc_client_start_key_exchange(SilcClient client,
544  *                                       SilcClientConnection conn,
545  *                                       int fd);
546  *
547  * DESCRIPTION
548  *
549  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
550  *    key material between client and server.  This function can be called
551  *    directly if application is performing its own connecting and does not
552  *    use the connecting provided by this library. This function is normally
553  *    used only if the application performed the connecting outside the
554  *    library. The library however may use this internally.
555  *
556  ***/
557 int silc_client_start_key_exchange(SilcClient client,
558                                    SilcClientConnection conn,
559                                    int fd);
560
561 /****f* silcclient/SilcClientAPI/silc_client_close_connection
562  *
563  * SYNOPSIS
564  *
565  *    void silc_client_close_connection(SilcClient client,
566  *                                      SilcSocketConnection sock,
567  *                                      SilcClientConnection conn);
568  *
569  * DESCRIPTION
570  *
571  *    Closes connection to remote end. Free's all allocated data except
572  *    for some information such as nickname etc. that are valid at all time. 
573  *    If the `sock' is NULL then the conn->sock will be used.  If `sock' is
574  *    provided it will be checked whether the sock and `conn->sock' are the
575  *    same (they can be different, ie. a socket can use `conn' as its
576  *    connection but `conn->sock' might be actually a different connection
577  *    than the `sock'). 
578  *
579  ***/
580 void silc_client_close_connection(SilcClient client,
581                                   SilcSocketConnection sock,
582                                   SilcClientConnection conn);
583
584
585 /* Message sending functions (client_channel.c and client_prvmsg.c) */
586
587 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
588  *
589  * SYNOPSIS
590  *
591  *    void silc_client_send_channel_message(SilcClient client, 
592  *                                          SilcClientConnection conn,
593  *                                          SilcChannelEntry channel,
594  *                                          SilcChannelPrivateKey key,
595  *                                          SilcMessageFlags flags,
596  *                                          unsigned char *data, 
597  *                                          uint32 data_len, 
598  *                                          int force_send);
599  *
600  * DESCRIPTION
601  *
602  *    Sends packet to the `channel'. Packet to channel is always encrypted
603  *    differently from "normal" packets. SILC header of the packet is 
604  *    encrypted with the next receiver's key and the rest of the packet is
605  *    encrypted with the channel specific key. Padding and HMAC is computed
606  *    with the next receiver's key. The `data' is the channel message. If
607  *    the `force_send' is TRUE then the packet is sent immediately. 
608  *
609  *    If `key' is provided then that private key is used to encrypt the
610  *    channel message.  If it is not provided, private keys has not been
611  *    set at all, the normal channel key is used automatically.  If private
612  *    keys are set then the first key (the key that was added first as
613  *    private key) is used. 
614  *
615  ***/
616 void silc_client_send_channel_message(SilcClient client, 
617                                       SilcClientConnection conn,
618                                       SilcChannelEntry channel,
619                                       SilcChannelPrivateKey key,
620                                       SilcMessageFlags flags,
621                                       unsigned char *data, 
622                                       uint32 data_len, 
623                                       int force_send);
624
625 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
626  *
627  * SYNOPSIS
628  *
629  *    void silc_client_send_private_message(SilcClient client,
630  *                                          SilcClientConnection conn,
631  *                                          SilcClientEntry client_entry,
632  *                                          SilcMessageFlags flags,
633  *                                          unsigned char *data, 
634  *                                          uint32 data_len, 
635  *                                          int force_send);
636  *
637  * DESCRIPTION
638  *
639  *    Sends private message to remote client. If private message key has
640  *    not been set with this client then the message will be encrypted using
641  *    normal session keys. Private messages are special packets in SILC
642  *    network hence we need this own function for them. This is similar
643  *    to silc_client_packet_send_to_channel except that we send private
644  *    message. The `data' is the private message. If the `force_send' is
645  *    TRUE the packet is sent immediately. 
646  *
647  ***/
648 void silc_client_send_private_message(SilcClient client,
649                                       SilcClientConnection conn,
650                                       SilcClientEntry client_entry,
651                                       SilcMessageFlags flags,
652                                       unsigned char *data, 
653                                       uint32 data_len, 
654                                       int force_send);
655
656
657 /* Client and Channel entry retrieval (idlist.c) */
658
659 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
660  *
661  * SYNOPSIS
662  *
663  *    typedef void (*SilcGetClientCallback)(SilcClient client,
664  *                                          SilcClientConnection conn,
665  *                                          SilcClientEntry *clients,
666  *                                          uint32 clients_count,
667  *                                          void *context);
668  *
669  * DESCRIPTION
670  *
671  *    Callback function given to the silc_client_get_client function. The
672  *    found entries are allocated into the `clients' array. The array must
673  *    not be freed by the receiver, the library will free it later. If the
674  *    `clients' is NULL, no such clients exist in the SILC Network.
675  *
676  ***/
677 typedef void (*SilcGetClientCallback)(SilcClient client,
678                                       SilcClientConnection conn,
679                                       SilcClientEntry *clients,
680                                       uint32 clients_count,
681                                       void *context);
682
683 /****f* silcclient/SilcClientAPI/silc_client_get_clients
684  *
685  * SYNOPSIS
686  *
687  *    void silc_client_get_clients(SilcClient client,
688  *                                 SilcClientConnection conn,
689  *                                 char *nickname,
690  *                                 char *server,
691  *                                 SilcGetClientCallback completion,
692  *                                 void *context);
693  *
694  * DESCRIPTION
695  *
696  *    Finds client entry or entries by the `nickname' and `server'. The 
697  *    completion callback will be called when the client entries has been
698  *    found.
699  *
700  * NOTES
701  *
702  *    NOTE: This function is always asynchronous and resolves the client
703  *    information from the server. Thus, if you already know the client
704  *    information then use the silc_client_get_client_by_id function to
705  *    get the client entry since this function may be very slow and should
706  *    be used only to initially get the client entries. 
707  *
708  ***/
709 void silc_client_get_clients(SilcClient client,
710                              SilcClientConnection conn,
711                              char *nickname,
712                              char *server,
713                              SilcGetClientCallback completion,
714                              void *context);
715
716 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
717  *
718  * SYNOPSIS
719  *
720  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
721  *                                                   SilcClientConnection conn,
722  *                                                   char *nickname,
723  *                                                   char *server,
724  *                                                   uint32 *clients_count);
725  *
726  * DESCRIPTION
727  *
728  *    Same as silc_client_get_clients function but does not resolve anything
729  *    from the server.  This checks local cache and returns all clients from
730  *    the local cache. 
731  *
732  ***/
733 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
734                                                SilcClientConnection conn,
735                                                char *nickname,
736                                                char *server,
737                                                uint32 *clients_count);
738
739 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
740  *
741  * SYNOPSIS
742  *
743  *    void silc_client_get_clients_by_list(SilcClient client,
744  *                                         SilcClientConnection conn,
745  *                                         uint32 list_count,
746  *                                         SilcBuffer client_id_list,
747  *                                         SilcGetClientCallback completion,
748  *                                         void *context);
749  *
750  * DESCRIPTION
751  *
752  *    Gets client entries by the list of client ID's `client_id_list'. This
753  *    always resolves those client ID's it does not know yet from the server
754  *    so this function might take a while. The `client_id_list' is a list
755  *    of ID Payloads added one after other.  JOIN command reply and USERS
756  *    command reply for example returns this sort of list. The `completion'
757  *    will be called after the entries are available. 
758  *
759  ***/
760 void silc_client_get_clients_by_list(SilcClient client,
761                                      SilcClientConnection conn,
762                                      uint32 list_count,
763                                      SilcBuffer client_id_list,
764                                      SilcGetClientCallback completion,
765                                      void *context);
766
767 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
768  *
769  * SYNOPSIS
770  *
771  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
772  *                                                 SilcClientConnection conn,
773  *                                                 SilcClientID *client_id);
774  *
775  * DESCRIPTION
776  *
777  *    Find entry for client by the client's ID. Returns the entry or NULL
778  *    if the entry was not found. 
779  *
780  ***/
781 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
782                                              SilcClientConnection conn,
783                                              SilcClientID *client_id);
784
785 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
786  *
787  * SYNOPSIS
788  *
789  *    void 
790  *    silc_client_get_client_by_id_resolve(SilcClient client,
791  *                                         SilcClientConnection conn,
792  *                                         SilcClientID *client_id,
793  *                                         SilcGetClientCallback completion,
794  *                                         void *context);
795  *
796  * DESCRIPTION
797  *
798  *    Same as silc_client_get_client_by_id but will always resolve the
799  *    information from the server. Use this only if you know that you
800  *    do not have the entry and the only thing you know about the client
801  *    is its ID. 
802  *
803  ***/
804 void silc_client_get_client_by_id_resolve(SilcClient client,
805                                           SilcClientConnection conn,
806                                           SilcClientID *client_id,
807                                           SilcGetClientCallback completion,
808                                           void *context);
809
810 /****f* silcclient/SilcClientAPI/silc_client_del_client
811  *
812  * SYNOPSIS
813  *
814  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
815  *                                SilcClientEntry client_entry)
816  *
817  * DESCRIPTION
818  *
819  *    Removes client from local cache by the client entry indicated by
820  *    the `client_entry'.  Returns TRUE if the deletion were successful.
821  *
822  ***/
823 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
824                             SilcClientEntry client_entry);
825
826 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
827  *
828  * SYNOPSIS
829  *
830  *    typedef void (*SilcGetClientCallback)(SilcClient client,
831  *                                          SilcClientConnection conn,
832  *                                          SilcClientEntry *clients,
833  *                                          uint32 clients_count,
834  *                                          void *context);
835  *
836  * DESCRIPTION
837  *
838  *    Callback function given to the silc_client_get_channel_* functions.
839  *    The found entries are allocated into the `channels' array. The array
840  *    must not be freed by the receiver, the library will free it later.
841  *    If the `channel' is NULL, no such channel exist in the SILC Network.
842  *
843  ***/
844 typedef void (*SilcGetChannelCallback)(SilcClient client,
845                                        SilcClientConnection conn,
846                                        SilcChannelEntry *channels,
847                                        uint32 channels_count,
848                                        void *context);
849
850 /****f* silcclient/SilcClientAPI/silc_client_get_channel
851  *
852  * SYNOPSIS
853  *
854  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
855  *                                             SilcClientConnection conn,
856  *                                             char *channel);
857  *
858  * DESCRIPTION
859  *
860  *    Finds entry for channel by the channel name. Returns the entry or NULL
861  *    if the entry was not found. It is found only if the client is joined
862  *    to the channel. 
863  *
864  ***/
865 SilcChannelEntry silc_client_get_channel(SilcClient client,
866                                          SilcClientConnection conn,
867                                          char *channel);
868
869 /****f* silcclient/SilcClientAPI/silc_client_get_channel
870  *
871  * SYNOPSIS
872  *
873  *    void 
874  *    silc_client_get_channel_by_id_resolve(SilcClient client,
875  *                                          SilcClientConnection conn,
876  *                                          SilcChannelID *channel_id,
877  *                                          SilcGetClientCallback completion,
878  *                                          void *context);
879  *
880  * DESCRIPTION
881  *
882  *    Finds channel entry by the channel name. Returns the entry or NULL
883  *    if it was not found.
884  *
885  ***/
886 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
887                                                SilcClientConnection conn,
888                                                SilcChannelID *channel_id);
889
890 /****f* silcclient/SilcClientAPI/silc_client_get_channel
891  *
892  * SYNOPSIS
893  *
894  *    void 
895  *    silc_client_get_channel_by_id_resolve(SilcClient client,
896  *                                          SilcClientConnection conn,
897  *                                          SilcChannelID *channel_id,
898  *                                          SilcGetClientCallback completion,
899  *                                          void *context);
900  *
901  * DESCRIPTION
902  *
903  *    Resolves the channel information (its name mainly) from the server
904  *    by the `channel_id'. Use this only if you know that you do not have
905  *    the entry cached locally.
906  *
907  ***/
908 void silc_client_get_channel_by_id_resolve(SilcClient client,
909                                            SilcClientConnection conn,
910                                            SilcChannelID *channel_id,
911                                            SilcGetChannelCallback completion,
912                                            void *context);
913
914 /****f* silcclient/SilcClientAPI/silc_client_del_channel
915  *
916  * SYNOPSIS
917  *
918  *    bool silc_client_del_channel(SilcClient client, 
919  *                                 SilcClientConnection conn,
920  *                                 SilcChannelEntry channel)
921  *
922  * DESCRIPTION
923  *
924  *    Removes channel from local cache by the channel entry indicated by
925  *    the `channel'.  Returns TRUE if the deletion were successful.
926  *
927  ***/
928 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
929                              SilcChannelEntry channel);
930
931 /****f* silcclient/SilcClientAPI/silc_client_get_server
932  *
933  * SYNOPSIS
934  *
935  *    SilcServerEntry silc_client_get_server(SilcClient client,
936  *                                           SilcClientConnection conn,
937  *                                           char *server_name)
938  *
939  * DESCRIPTION
940  *
941  *    Finds entry for server by the server name. Returns the entry or NULL
942  *    if the entry was not found.
943  *
944  ***/
945 SilcServerEntry silc_client_get_server(SilcClient client,
946                                        SilcClientConnection conn,
947                                        char *server_name);
948
949 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
950  *
951  * SYNOPSIS
952  *
953  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
954  *                                                 SilcClientConnection conn,
955  *                                                 SilcServerID *server_id);
956  *
957  * DESCRIPTION
958  *
959  *    Finds entry for server by the server ID. Returns the entry or NULL
960  *    if the entry was not found.
961  *
962  ***/
963 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
964                                              SilcClientConnection conn,
965                                              SilcServerID *server_id);
966
967 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
968  *
969  * SYNOPSIS
970  *
971  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
972  *                                SilcServerEntry server);
973  *
974  * DESCRIPTION
975  *
976  *    Removes server from local cache by the server entry indicated by
977  *    the `server'.  Returns TRUE if the deletion were successful.
978  *
979  ***/
980 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
981                             SilcServerEntry server);
982
983 /* Command management (command.c) */
984
985 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
986  *
987  * SYNOPSIS
988  *
989  *    SilcClientCommandContext silc_client_command_alloc();
990  *
991  * DESCRIPTION
992  *
993  *    Allocate Command Context. The context is defined in `command.h' file.
994  *    The context is used by the library commands and applications should use
995  *    it as well. However, application may choose to use some own context
996  *    for its local commands. All library commands, however, must use this
997  *    context. 
998  *
999  ***/
1000 SilcClientCommandContext silc_client_command_alloc();
1001
1002 /****f* silcclient/SilcClientAPI/silc_client_command_free
1003  *
1004  * SYNOPSIS
1005  *
1006  *    void silc_client_command_free(SilcClientCommandContext ctx);
1007  *
1008  * DESCRIPTION
1009  *
1010  *    Free command context and its internals.  If the contex was duplicated
1011  *    with silc_client_command_dup this may not actually free the data, 
1012  *    instead it will decrease the reference counter of the context.  The
1013  *    context will be freed when the reference counter hits zero.
1014  *
1015  ***/
1016 void silc_client_command_free(SilcClientCommandContext ctx);
1017
1018 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1019  *
1020  * SYNOPSIS
1021  *
1022  *    SilcClientCommandContext 
1023  *    silc_client_command_dup(SilcClientCommandContext ctx);
1024  *
1025  * DESCRIPTION
1026  *
1027  *    Duplicate Command Context by adding reference counter. The context won't
1028  *    be free'd untill it hits zero. 
1029  *
1030  ***/
1031 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1032
1033 /****f* silcclient/SilcClientAPI/silc_client_command_find
1034  *
1035  * SYNOPSIS
1036  *
1037  *    SilcClientCommand *silc_client_command_find(const char *name);
1038  *
1039  * DESCRIPTION
1040  *
1041  *    Finds and returns a pointer to the command list. Return NULL if the
1042  *    command is not found. See the `command.[ch]' for the command list. 
1043  *
1044  ***/
1045 SilcClientCommand *silc_client_command_find(const char *name);
1046
1047 /****f* silcclient/SilcClientAPI/silc_client_send_command
1048  *
1049  * SYNOPSIS
1050  *
1051  *    void silc_client_send_command(SilcClient client, 
1052  *                                  SilcClientConnection conn,
1053  *                                  SilcCommand command, uint16 ident,
1054  *                                  uint32 argc, ...);
1055  *
1056  * DESCRIPTION
1057  *
1058  *    Generic function to send any command. The arguments must be sent already
1059  *    encoded into correct form and in correct order. 
1060  *
1061  ***/
1062 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
1063                               SilcCommand command, uint16 ident,
1064                               uint32 argc, ...);
1065
1066 /****f* silcclient/SilcClientAPI/SilcClientPendingDestructor
1067  *
1068  * SYNOPSIS
1069  *
1070  *    typedef void (*SilcClientPendingDestructor)(void *context);
1071  *
1072  * DESCRIPTION
1073  *
1074  *    Pending Command callback destructor. This is called after calling the
1075  *    pending callback or if error occurs while processing the pending command.
1076  *    If error occurs then the callback won't be called at all, and only this
1077  *    destructor is called. The `context' is the context given for the function
1078  *    silc_client_command_pending. 
1079  *
1080  ***/
1081 typedef void (*SilcClientPendingDestructor)(void *context);
1082
1083 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1084  *
1085  * SYNOPSIS
1086  *
1087  *    void silc_client_command_pending(SilcClientConnection conn,
1088  *                                     SilcCommand reply_cmd,
1089  *                                     uint16 ident,
1090  *                                     SilcClientPendingDestructor destructor,
1091  *                                     SilcCommandCb callback,
1092  *                                     void *context);
1093  *
1094  * DESCRIPTION
1095  *
1096  *    Add new pending command to be executed when reply to a command has been
1097  *    received.  The `reply_cmd' is the command that will call the `callback'
1098  *    with `context' when reply has been received.  If `ident is non-zero
1099  *    the `callback' will be executed when received reply with command 
1100  *    identifier `ident'. 
1101  *
1102  ***/
1103 void silc_client_command_pending(SilcClientConnection conn,
1104                                  SilcCommand reply_cmd,
1105                                  uint16 ident,
1106                                  SilcClientPendingDestructor destructor,
1107                                  SilcCommandCb callback,
1108                                  void *context);
1109
1110
1111 /* Private Message key management (client_prvmsg.c) */
1112
1113 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1114  *
1115  * SYNOPSIS
1116  *
1117  *    int silc_client_add_private_message_key(SilcClient client,
1118  *                                            SilcClientConnection conn,
1119  *                                            SilcClientEntry client_entry,
1120  *                                            char *cipher,
1121  *                                            unsigned char *key,
1122  *                                            uint32 key_len,
1123  *                                            bool generate_key,
1124  *                                            bool responder);
1125  *
1126  * DESCRIPTION
1127  *
1128  *    Adds private message key to the client library. The key will be used to
1129  *    encrypt all private message between the client and the remote client
1130  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1131  *    value `generate_key' is TRUE the library will generate random key.
1132  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1133  *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
1134  *    requirements of the SILC protocol are met. The API, however, allows
1135  *    to allocate any cipher.
1136  *
1137  *    If `responder' is TRUE then the sending and receiving keys will be
1138  *    set according the client being the receiver of the private key.  If
1139  *    FALSE the client is being the sender (or negotiator) of the private
1140  *    key.
1141  *
1142  *    It is not necessary to set key for normal private message usage. If the
1143  *    key is not set then the private messages are encrypted using normal
1144  *    session keys. Setting the private key, however, increases the security. 
1145  *
1146  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1147  *    otherwise. 
1148  *
1149  ***/
1150 int silc_client_add_private_message_key(SilcClient client,
1151                                         SilcClientConnection conn,
1152                                         SilcClientEntry client_entry,
1153                                         char *cipher,
1154                                         unsigned char *key,
1155                                         uint32 key_len,
1156                                         bool generate_key,
1157                                         bool responder);
1158
1159 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1160  *
1161  * SYNOPSIS
1162  *
1163  *    int silc_client_add_private_message_key_ske(SilcClient client,
1164  *                                                SilcClientConnection conn,
1165  *                                                SilcClientEntry client_entry,
1166  *                                                char *cipher,
1167  *                                                SilcSKEKeyMaterial *key);
1168  *
1169  * DESCRIPTION
1170  *
1171  *    Same as silc_client_add_private_message_key but takes the key material
1172  *    from the SKE key material structure. This structure is received if
1173  *    the application uses the silc_client_send_key_agreement to negotiate
1174  *    the key material. The `cipher' SHOULD be provided as it is negotiated
1175  *    also in the SKE protocol. 
1176  *
1177  ***/
1178 int silc_client_add_private_message_key_ske(SilcClient client,
1179                                             SilcClientConnection conn,
1180                                             SilcClientEntry client_entry,
1181                                             char *cipher,
1182                                             SilcSKEKeyMaterial *key,
1183                                             bool responder);
1184
1185 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1186  *
1187  * SYNOPSIS
1188  *
1189  *    int silc_client_send_private_message_key(SilcClient client,
1190  *                                             SilcClientConnection conn,
1191  *                                             SilcClientEntry client_entry,
1192  *                                             int force_send);
1193  *
1194  * DESCRIPTION
1195  *
1196  *    Sends private message key payload to the remote client indicated by
1197  *    the `client_entry'. If the `force_send' is TRUE the packet is sent
1198  *    immediately. Returns FALSE if error occurs, TRUE otherwise. The
1199  *    application should call this function after setting the key to the
1200  *    client.
1201  *
1202  *    Note that the key sent using this function is sent to the remote client
1203  *    through the SILC network. The packet is protected using normal session
1204  *    keys. 
1205  *
1206  ***/
1207 int silc_client_send_private_message_key(SilcClient client,
1208                                          SilcClientConnection conn,
1209                                          SilcClientEntry client_entry,
1210                                          int force_send);
1211
1212 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1213  *
1214  * SYNOPSIS
1215  *
1216  *    int silc_client_del_private_message_key(SilcClient client,
1217  *                                            SilcClientConnection conn,
1218  *                                            SilcClientEntry client_entry);
1219  *
1220  * DESCRIPTION
1221  *
1222  *    Removes the private message from the library. The key won't be used
1223  *    after this to protect the private messages with the remote `client_entry'
1224  *    client. Returns FALSE on error, TRUE otherwise. 
1225  *
1226  ***/
1227 int silc_client_del_private_message_key(SilcClient client,
1228                                         SilcClientConnection conn,
1229                                         SilcClientEntry client_entry);
1230
1231 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1232  *
1233  * SYNOPSIS
1234  *
1235  *    SilcPrivateMessageKeys
1236  *    silc_client_list_private_message_keys(SilcClient client,
1237  *                                          SilcClientConnection conn,
1238  *                                          uint32 *key_count);
1239  * 
1240  * DESCRIPTION
1241  *
1242  *    Returns array of set private message keys associated to the connection
1243  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1244  *    count to the `key_count' argument. The array must be freed by the caller
1245  *    by calling the silc_client_free_private_message_keys function. Note: 
1246  *    the keys returned in the array is in raw format. It might not be desired
1247  *    to show the keys as is. The application might choose not to show the keys
1248  *    at all or to show the fingerprints of the keys. 
1249  *
1250  ***/
1251 SilcPrivateMessageKeys
1252 silc_client_list_private_message_keys(SilcClient client,
1253                                       SilcClientConnection conn,
1254                                       uint32 *key_count);
1255
1256 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1257  *
1258  * SYNOPSIS
1259  *
1260  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1261  *                                               uint32 key_count);
1262  * 
1263  * DESCRIPTION
1264  *
1265  *    Frees the SilcPrivateMessageKeys array returned by the function
1266  *    silc_client_list_private_message_keys. 
1267  *
1268  ***/
1269 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1270                                            uint32 key_count);
1271
1272
1273 /* Channel private key management (client_channel.c, 
1274    SilcChannelPrivateKey is defined in idlist.h) */
1275
1276 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1277  *
1278  * SYNOPSIS
1279  *
1280  *    int silc_client_add_channel_private_key(SilcClient client,
1281  *                                            SilcClientConnection conn,
1282  *                                            SilcChannelEntry channel,
1283  *                                            char *cipher,
1284  *                                            char *hmac,
1285  *                                            unsigned char *key,
1286  *                                            uint32 key_len);
1287  * 
1288  * DESCRIPTION
1289  *
1290  *    Adds private key for channel. This may be set only if the channel's mode
1291  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1292  *    mode is not set. When channel has private key then the messages are
1293  *    encrypted using that key. All clients on the channel must also know the
1294  *    key in order to decrypt the messages. However, it is possible to have
1295  *    several private keys per one channel. In this case only some of the
1296  *    clients on the channel may know the one key and only some the other key.
1297  *
1298  *    The private key for channel is optional. If it is not set then the
1299  *    channel messages are encrypted using the channel key generated by the
1300  *    server. However, setting the private key (or keys) for the channel 
1301  *    significantly adds security. If more than one key is set the library
1302  *    will automatically try all keys at the message decryption phase. Note:
1303  *    setting many keys slows down the decryption phase as all keys has to
1304  *    be tried in order to find the correct decryption key. However, setting
1305  *    a few keys does not have big impact to the decryption performace. 
1306  *
1307  * NOTES
1308  *
1309  *    NOTE: This is entirely local setting. The key set using this function
1310  *    is not sent to the network at any phase.
1311  *
1312  *    NOTE: If the key material was originated by the SKE protocol (using
1313  *    silc_client_send_key_agreement) then the `key' MUST be the
1314  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1315  *    currently it is not expected that the SKE key material would be used
1316  *    as channel private key. However, this API allows it. 
1317  *
1318  ***/
1319 int silc_client_add_channel_private_key(SilcClient client,
1320                                         SilcClientConnection conn,
1321                                         SilcChannelEntry channel,
1322                                         char *cipher,
1323                                         char *hmac,
1324                                         unsigned char *key,
1325                                         uint32 key_len);
1326
1327 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1328  *
1329  * SYNOPSIS
1330  *
1331  *    int silc_client_del_channel_private_keys(SilcClient client,
1332  *                                             SilcClientConnection conn,
1333  *                                             SilcChannelEntry channel);
1334  * 
1335  * DESCRIPTION
1336  *
1337  *    Removes all private keys from the `channel'. The old channel key is used
1338  *    after calling this to protect the channel messages. Returns FALSE on
1339  *    on error, TRUE otherwise. 
1340  *
1341  ***/
1342 int silc_client_del_channel_private_keys(SilcClient client,
1343                                          SilcClientConnection conn,
1344                                          SilcChannelEntry channel);
1345
1346 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1347  *
1348  * SYNOPSIS
1349  *
1350  *    int silc_client_del_channel_private_key(SilcClient client,
1351  *                                            SilcClientConnection conn,
1352  *                                            SilcChannelEntry channel,
1353  *                                            SilcChannelPrivateKey key);
1354  * 
1355  * DESCRIPTION
1356  *
1357  *    Removes and frees private key `key' from the channel `channel'. 
1358  *    The `key' is retrieved by calling the function 
1359  *    silc_client_list_channel_private_keys. The key is not used after
1360  *    this. If the key was last private key then the old channel key is
1361  *    used hereafter to protect the channel messages. This returns FALSE
1362  *    on error, TRUE otherwise. 
1363  *
1364  ***/
1365 int silc_client_del_channel_private_key(SilcClient client,
1366                                         SilcClientConnection conn,
1367                                         SilcChannelEntry channel,
1368                                         SilcChannelPrivateKey key);
1369
1370 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1371  *
1372  * SYNOPSIS
1373  *
1374  *    SilcChannelPrivateKey *
1375  *    silc_client_list_channel_private_keys(SilcClient client,
1376  *                                          SilcClientConnection conn,
1377  *                                          SilcChannelEntry channel,
1378  *                                          uint32 *key_count);
1379  *
1380  * DESCRIPTION
1381  *
1382  *    Returns array (pointers) of private keys associated to the `channel'.
1383  *    The caller must free the array by calling the function
1384  *    silc_client_free_channel_private_keys. The pointers in the array may be
1385  *    used to delete the specific key by giving the pointer as argument to the
1386  *    function silc_client_del_channel_private_key. 
1387  *
1388  ***/
1389 SilcChannelPrivateKey *
1390 silc_client_list_channel_private_keys(SilcClient client,
1391                                       SilcClientConnection conn,
1392                                       SilcChannelEntry channel,
1393                                       uint32 *key_count);
1394
1395 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1396  *
1397  * SYNOPSIS
1398  *
1399  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1400  *                                               uint32 key_count);
1401  *
1402  * DESCRIPTION
1403  *
1404  *    Frees the SilcChannelPrivateKey array.
1405  *
1406  ***/
1407 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1408                                            uint32 key_count);
1409
1410
1411 /* Key Agreement routines (client_keyagr.c) */
1412
1413 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1414  *
1415  * SYNOPSIS
1416  *
1417  *    void silc_client_send_key_agreement(SilcClient client,
1418  *                                        SilcClientConnection conn,
1419  *                                        SilcClientEntry client_entry,
1420  *                                        char *hostname,
1421  *                                        int port,
1422  *                                        uint32 timeout_secs,
1423  *                                        SilcKeyAgreementCallback completion,
1424  *                                        void *context);
1425  *
1426  * DESCRIPTION
1427  *
1428  *    Sends key agreement request to the remote client indicated by the
1429  *    `client_entry'. If the caller provides the `hostname' and the `port'
1430  *    arguments then the library will bind the client to that hostname and
1431  *    that port for the key agreement protocol. It also sends the `hostname'
1432  *    and the `port' in the key agreement packet to the remote client. This
1433  *    would indicate that the remote client may initiate the key agreement
1434  *    protocol to the `hostname' on the `port'.  If port is zero then the
1435  *    bound port is undefined (the operating system defines it).
1436  *
1437  *    If the `hostname' and `port' is not provided then empty key agreement
1438  *    packet is sent to the remote client. The remote client may reply with
1439  *    the same packet including its hostname and port. If the library receives
1440  *    the reply from the remote client the `key_agreement' client operation
1441  *    callback will be called to verify whether the user wants to perform the
1442  *    key agreement or not. 
1443  *
1444  * NOTES
1445  *
1446  *    NOTE: If the application provided the `hostname' and the `port' and the 
1447  *    remote side initiates the key agreement protocol it is not verified
1448  *    from the user anymore whether the protocol should be executed or not.
1449  *    By setting the `hostname' and `port' the user gives permission to
1450  *    perform the protocol (we are responder in this case).
1451  *
1452  *    NOTE: If the remote side decides not to initiate the key agreement
1453  *    or decides not to reply with the key agreement packet then we cannot
1454  *    perform the key agreement at all. If the key agreement protocol is
1455  *    performed the `completion' callback with the `context' will be called.
1456  *    If remote side decides to ignore the request the `completion' will be
1457  *    called after the specified timeout, `timeout_secs'. 
1458  *
1459  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
1460  *    will not be called at all since this does nothing more than sending
1461  *    a packet to the remote host.
1462  *
1463  *    NOTE: There can be only one active key agreement for one client entry.
1464  *    Before setting new one, the old one must be finished (it is finished
1465  *    after calling the completion callback) or the function 
1466  *    silc_client_abort_key_agreement must be called. 
1467  *
1468  ***/
1469 void silc_client_send_key_agreement(SilcClient client,
1470                                     SilcClientConnection conn,
1471                                     SilcClientEntry client_entry,
1472                                     char *hostname,
1473                                     int port,
1474                                     uint32 timeout_secs,
1475                                     SilcKeyAgreementCallback completion,
1476                                     void *context);
1477
1478 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1479  *
1480  * SYNOPSIS
1481  *
1482  *    void 
1483  *    silc_client_perform_key_agreement(SilcClient client,
1484  *                                      SilcClientConnection conn,
1485  *                                      SilcClientEntry client_entry,
1486  *                                      char *hostname,
1487  *                                      int port,
1488  *                                      SilcKeyAgreementCallback completion,
1489  *                                      void *context);
1490  *
1491  * DESCRIPTION
1492  *
1493  *    Performs the actual key agreement protocol. Application may use this
1494  *    to initiate the key agreement protocol. This can be called for example
1495  *    after the application has received the `key_agreement' client operation,
1496  *    and did not return TRUE from it.
1497  *
1498  *    The `hostname' is the remote hostname (or IP address) and the `port'
1499  *    is the remote port. The `completion' callback with the `context' will
1500  *    be called after the key agreement protocol.
1501  *
1502  * NOTES
1503  * 
1504  *    NOTE: If the application returns TRUE in the `key_agreement' client
1505  *    operation the library will automatically start the key agreement. In this
1506  *    case the application must not call this function. However, application
1507  *    may choose to just ignore the `key_agreement' client operation (and
1508  *    merely just print information about it on the screen) and call this
1509  *    function when the user whishes to do so (by, for example, giving some
1510  *    specific command). Thus, the API provides both, automatic and manual
1511  *    initiation of the key agreement. Calling this function is the manual
1512  *    initiation and returning TRUE in the `key_agreement' client operation
1513  *    is the automatic initiation. 
1514  *
1515  ***/
1516 void silc_client_perform_key_agreement(SilcClient client,
1517                                        SilcClientConnection conn,
1518                                        SilcClientEntry client_entry,
1519                                        char *hostname,
1520                                        int port,
1521                                        SilcKeyAgreementCallback completion,
1522                                        void *context);
1523
1524 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1525  *
1526  * SYNOPSIS
1527  *
1528  *    void
1529  *    silc_client_perform_key_agreement_fd(SilcClient client,
1530  *                                         SilcClientConnection conn,
1531  *                                         SilcClientEntry client_entry,
1532  *                                         int sock,
1533  *                                         char *hostname,
1534  *                                         SilcKeyAgreementCallback completion,
1535  *                                         void *context);
1536  *
1537  * DESCRIPTION
1538  *
1539  *    Same as above but application has created already the connection to 
1540  *    the remote host. The `sock' is the socket to the remote connection. 
1541  *    Application can use this function if it does not want the client library
1542  *    to create the connection. 
1543  *
1544  ***/
1545 void silc_client_perform_key_agreement_fd(SilcClient client,
1546                                           SilcClientConnection conn,
1547                                           SilcClientEntry client_entry,
1548                                           int sock,
1549                                           char *hostname,
1550                                           SilcKeyAgreementCallback completion,
1551                                           void *context);
1552
1553 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1554  *
1555  * SYNOPSIS
1556  *
1557  *    void silc_client_abort_key_agreement(SilcClient client,
1558  *                                         SilcClientConnection conn,
1559  *                                         SilcClientEntry client_entry);
1560  *
1561  * DESCRIPTION
1562  *
1563  *    This function can be called to unbind the hostname and the port for
1564  *    the key agreement protocol. However, this function has effect only 
1565  *    before the key agreement protocol has been performed. After it has
1566  *    been performed the library will automatically unbind the port. The 
1567  *    `client_entry' is the client to which we sent the key agreement 
1568  *    request. 
1569  *
1570  ***/
1571 void silc_client_abort_key_agreement(SilcClient client,
1572                                      SilcClientConnection conn,
1573                                      SilcClientEntry client_entry);
1574
1575
1576 /* Misc functions */
1577
1578 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1579  *
1580  * SYNOPSIS
1581  *
1582  *    void silc_client_set_away_message(SilcClient client,
1583  *                                      SilcClientConnection conn,
1584  *                                      char *message);
1585  *
1586  * DESCRIPTION
1587  *
1588  *    Sets away `message'.  The away message may be set when the client's
1589  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1590  *    to anyone who sends private message.  The `message' will be sent
1591  *    automatically back to the the client who send private message.  If
1592  *    away message is already set this replaces the old message with the
1593  *    new one.  If `message' is NULL the old away message is removed. 
1594  *    The sender may freely free the memory of the `message'. 
1595  *
1596  ***/
1597 void silc_client_set_away_message(SilcClient client,
1598                                   SilcClientConnection conn,
1599                                   char *message);
1600
1601 #endif