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