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