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