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