Addec multiple channel private key support to Irssi SILC client.
[silc.git] / lib / silcclient / silcclient.h
1 /*
2
3   silcclient.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2000 - 2002 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcclient/Client Library Interface
21  *
22  * DESCRIPTION
23  *
24  * This interface defines the SILC Client Library API for the application.
25  * The client operations are defined first.  These are callback functions that
26  * the application MUST implement since the library may call the functions
27  * at any time.  At the end of file is the API for the application that
28  * it can use from the library.  This is the only file that the application
29  * may include from the SIlC Client Library.
30  *
31  * o SILC Client Operations
32  *
33  *   These functions must be implemented by the application calling the SILC
34  *   client library. The client library can call these functions at any time.
35  *
36  *   To use this structure: define a static SilcClientOperations variable,
37  *   fill it and pass its pointer to silc_client_alloc function.
38  *
39  * o SILC Client Library API
40  *
41  *   This is the API that is published by the SILC Client Library for the
42  *   applications.  These functions are implemented in the SILC Client Library.
43  *   Application may freely call these functions from the library.
44  *
45  * Please, refer to the README file in this directory for the directions
46  * of how to use the SILC Client Library.
47  *
48  ***/
49
50 #ifndef SILCCLIENT_H
51 #define SILCCLIENT_H
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 /* Forward declarations */
58 typedef struct SilcClientStruct *SilcClient;
59 typedef struct SilcClientConnectionStruct *SilcClientConnection;
60 typedef struct SilcClientPingStruct SilcClientPing;
61 typedef struct SilcClientAwayStruct SilcClientAway;
62 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
63 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
64 typedef struct SilcClientEntryStruct *SilcClientEntry;
65 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
66 typedef struct SilcServerEntryStruct *SilcServerEntry;
67 typedef struct SilcClientCommandStruct *SilcClientCommand;
68 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
69 typedef struct SilcClientCommandReplyContextStruct 
70                                            *SilcClientCommandReplyContext;
71 typedef struct SilcChannelUserStruct *SilcChannelUser;
72
73 /* General definitions */
74
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
76  *
77  * NAME
78  *
79  *    typedef enum { ... } SilcKeyAgreementStatus;
80  *
81  * DESCRIPTION
82  *
83  *    Key agreement status types indicating the status of the key
84  *    agreement protocol.  These types are returned to the application 
85  *    in the SilcKeyAgreementCallback callback function.
86  *
87  * SOURCE
88  */
89 typedef enum {
90   SILC_KEY_AGREEMENT_OK,               /* Everything is Ok */
91   SILC_KEY_AGREEMENT_ERROR,            /* Unknown error occurred */
92   SILC_KEY_AGREEMENT_FAILURE,          /* The protocol failed */
93   SILC_KEY_AGREEMENT_TIMEOUT,          /* The protocol timeout */
94   SILC_KEY_AGREEMENT_ABORTED,          /* The protocol aborted */
95 } SilcKeyAgreementStatus;
96 /***/
97
98 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
99  *
100  * SYNOPSIS
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  * DESCRIPTION
110  *
111  *    Key agreement callback that is called after the key agreement protocol
112  *    has been performed. This is called also if error occurred during the
113  *    key agreement protocol. The `key' is the allocated key material and
114  *    the caller is responsible of freeing it. The `key' is NULL if error
115  *    has occurred. The application can freely use the `key' to whatever
116  *    purpose it needs. See lib/silcske/silcske.h for the definition of
117  *    the SilcSKEKeyMaterial structure.
118  *
119  ***/
120 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
121                                          SilcClientConnection conn,
122                                          SilcClientEntry client_entry,
123                                          SilcKeyAgreementStatus status,
124                                          SilcSKEKeyMaterial *key,
125                                          void *context);
126
127 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
128  *
129  * NAME
130  *
131  *    typedef struct { ... } SilcPrivateMessageKeys;
132  *
133  * DESCRIPTION
134  *
135  *    Structure to hold the list of private message keys. The array of this
136  *    structure is returned by the silc_client_list_private_message_keys
137  *    function.
138  *
139  * SOURCE
140  */
141 typedef struct {
142   SilcClientEntry client_entry;       /* The remote client entry */
143   char *cipher;                       /* The cipher name */
144   unsigned char *key;                 /* The original key, If the appliation
145                                          provided it. This is NULL if the
146                                          library generated the key or if
147                                          the SKE key material was used. */
148   SilcUInt32 key_len;                 /* The key length */
149 } *SilcPrivateMessageKeys;
150 /***/
151
152 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
153  *
154  * NAME
155  *
156  *    typedef struct { ... } SilcChannelPrivateKey;
157  *
158  * DESCRIPTION
159  *
160  *    Structure to hold one channel private key. The array of this structure
161  *    is returned by silc_client_list_channel_private_keys function.
162  *
163  * SOURCE
164  */
165 typedef struct SilcChannelPrivateKeyStruct {
166   char *name;                         /* Application given name */
167   SilcCipher cipher;                  /* The cipher and key */
168   SilcHmac hmac;                      /* The HMAC and hmac key */
169   unsigned char *key;                 /* The key data */
170   SilcUInt32 key_len;                 /* The key length */
171 } *SilcChannelPrivateKey;
172 /***/
173
174 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
175  *
176  * SYNOPSIS
177  *
178  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
179  *                                      SilcUInt32 passphrase_len,
180  *                                      void *context);
181  *
182  * DESCRIPTION
183  *
184  *    Ask passphrase callback. This is called by the application when the
185  *    library calls `ask_passphrase' client operation.  The callback delivers
186  *    the passphrase to the library.
187  *
188  ***/
189 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
190                                   SilcUInt32 passphrase_len,
191                                   void *context);
192
193 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
194  *
195  * SYNOPSIS
196  *
197  *    typedef void (*SilcVerifyPublicKey)(bool success, void *context);
198  *
199  * DESCRIPTION
200  *
201  *    Public key (or certificate) verification callback. This is called
202  *    by the application to indicate that the public key verification was
203  *    either success or failure.
204  *
205  ***/
206 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
207
208 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
209  *
210  * SYNOPSIS
211  *
212  *    typedef void (*SilcGetAuthMeth)(bool success, 
213  *                                    SilcProtocolAuthMeth auth_meth,
214  *                                    const unsigned char *auth_data,
215  *                                    SilcUInt32 auth_data_len, void *context);
216  * 
217  * DESCRIPTION
218  *
219  *    Authentication method resolving callback. This is called by the
220  *    application to return the resolved authentication method. The client
221  *    library has called the get_auth_method client operation and given
222  *    this function pointer as argument. The `success' will indicate whether
223  *    the authentication method could be resolved. The `auth_meth' is the
224  *    resolved authentication method. The `auth_data' and the `auth_data_len'
225  *    are the resolved authentication data. The `context' is the libary's
226  *    context sent to the get_auth_method client operation.
227  *
228  ***/
229 typedef void (*SilcGetAuthMeth)(bool success, 
230                                 SilcProtocolAuthMeth auth_meth,
231                                 const unsigned char *auth_data,
232                                 SilcUInt32 auth_data_len, void *context);
233
234 /****d* silcclient/SilcClientAPI/SilcClientMessageType
235  *
236  * NAME
237  *
238  *    typedef enum { ... } SilcClientMessageType;
239  *
240  * DESCRIPTION
241  *
242  *    Different message types for `say' client operation.  The application
243  *    may filter the message sent by the library according this type.
244  *
245  * SOURCE
246  */
247 typedef enum {
248   SILC_CLIENT_MESSAGE_INFO,            /* Informational */
249   SILC_CLIENT_MESSAGE_WARNING,         /* Warning */
250   SILC_CLIENT_MESSAGE_ERROR,           /* Error */
251   SILC_CLIENT_MESSAGE_AUDIT,           /* Auditable */
252 } SilcClientMessageType;
253 /***/
254
255 /****s* silcclient/SilcClientAPI/SilcClientOperations
256  *
257  * NAME
258  *
259  *    typedef struct { ... } SilcClientOperations;
260  *
261  * DESCRIPTION
262  *
263  *    SILC Client Operations. These must be implemented by the application.
264  *    The Client library may call any of these routines at any time.  The
265  *    routines are used to deliver certain information to the application
266  *    or from the application to the client library.
267  *
268  * SOURCE
269  */
270 typedef struct {
271   /* Message sent to the application by library. `conn' associates the
272      message to a specific connection.  `conn', however, may be NULL. 
273      The `type' indicates the type of the message sent by the library.
274      The applicationi can for example filter the message according the
275      type. */
276   void (*say)(SilcClient client, SilcClientConnection conn, 
277               SilcClientMessageType type, char *msg, ...);
278
279   /* Message for a channel. The `sender' is the sender of the message 
280      The `channel' is the channel. The `msg' is the message.  Note that
281      `msg' maybe NULL. */
282   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
283                           SilcClientEntry sender, SilcChannelEntry channel, 
284                           SilcMessageFlags flags, char *msg);
285
286   /* Private message to the client. The `sender' is the sender of the
287      message. */
288   void (*private_message)(SilcClient client, SilcClientConnection conn,
289                           SilcClientEntry sender, SilcMessageFlags flags,
290                           char *msg);
291
292   /* Notify message to the client. The notify arguments are sent in the
293      same order as servers sends them. The arguments are same as received
294      from the server except for ID's.  If ID is received application receives
295      the corresponding entry to the ID. For example, if Client ID is received
296      application receives SilcClientEntry.  Also, if the notify type is
297      for channel the channel entry is sent to application (even if server
298      does not send it because client library gets the channel entry from
299      the Channel ID in the packet's header). */
300   void (*notify)(SilcClient client, SilcClientConnection conn, 
301                  SilcNotifyType type, ...);
302
303   /* Command handler. This function is called always in the command function.
304      If error occurs it will be called as well. `conn' is the associated
305      client connection. `cmd_context' is the command context that was
306      originally sent to the command. `success' is FALSE if error occurred
307      during command. `command' is the command being processed. It must be
308      noted that this is not reply from server. This is merely called just
309      after application has called the command. Just to tell application
310      that the command really was processed. */
311   void (*command)(SilcClient client, SilcClientConnection conn, 
312                   SilcClientCommandContext cmd_context, int success,
313                   SilcCommand command);
314
315   /* Command reply handler. This function is called always in the command reply
316      function. If error occurs it will be called as well. Normal scenario
317      is that it will be called after the received command data has been parsed
318      and processed. The function is used to pass the received command data to
319      the application. 
320      
321      `conn' is the associated client connection. `cmd_payload' is the command
322      payload data received from server and it can be ignored. It is provided
323      if the application would like to re-parse the received command data,
324      however, it must be noted that the data is parsed already by the library
325      thus the payload can be ignored. `success' is FALSE if error occurred.
326      In this case arguments are not sent to the application. The `status' is
327      the command reply status server returned. The `command' is the command
328      reply being processed. The function has variable argument list and each
329      command defines the number and type of arguments it passes to the
330      application (on error they are not sent). */
331   void (*command_reply)(SilcClient client, SilcClientConnection conn,
332                         SilcCommandPayload cmd_payload, int success,
333                         SilcCommand command, SilcCommandStatus status, ...);
334
335   /* Called to indicate that connection was either successfully established
336      or connecting failed.  This is also the first time application receives
337      the SilcClientConnection objecet which it should save somewhere.
338      If the `success' is FALSE the application must always call the function
339      silc_client_close_connection. */
340   void (*connect)(SilcClient client, SilcClientConnection conn, int success);
341
342   /* Called to indicate that connection was disconnected to the server. */
343   void (*disconnect)(SilcClient client, SilcClientConnection conn);
344
345   /* Find authentication method and authentication data by hostname and
346      port. The hostname may be IP address as well. When the authentication
347      method has been resolved the `completion' callback with the found
348      authentication method and authentication data is called. The `conn'
349      may be NULL. */
350   void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
351                           char *hostname, SilcUInt16 port,
352                           SilcGetAuthMeth completion, void *context);
353
354   /* Verifies received public key. The `conn_type' indicates which entity
355      (server, client etc.) has sent the public key. If user decides to trust
356      the key may be saved as trusted public key for later use. The 
357      `completion' must be called after the public key has been verified. */
358   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
359                             SilcSocketType conn_type, unsigned char *pk, 
360                             SilcUInt32 pk_len, SilcSKEPKType pk_type,
361                             SilcVerifyPublicKey completion, void *context);
362
363   /* Ask (interact, that is) a passphrase from user. The passphrase is
364      returned to the library by calling the `completion' callback with
365      the `context'. */
366   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
367                          SilcAskPassphrase completion, void *context);
368
369   /* Notifies application that failure packet was received.  This is called
370      if there is some protocol active in the client.  The `protocol' is the
371      protocol context.  The `failure' is opaque pointer to the failure
372      indication.  Note, that the `failure' is protocol dependant and
373      application must explicitly cast it to correct type.  Usually `failure'
374      is 32 bit failure type (see protocol specs for all protocol failure
375      types). */
376   void (*failure)(SilcClient client, SilcClientConnection conn, 
377                   SilcProtocol protocol, void *failure);
378
379   /* Asks whether the user would like to perform the key agreement protocol.
380      This is called after we have received an key agreement packet or an
381      reply to our key agreement packet. This returns TRUE if the user wants
382      the library to perform the key agreement protocol and FALSE if it is not
383      desired (application may start it later by calling the function
384      silc_client_perform_key_agreement). If TRUE is returned also the
385      `completion' and `context' arguments must be set by the application. */
386   int (*key_agreement)(SilcClient client, SilcClientConnection conn,
387                        SilcClientEntry client_entry, const char *hostname,
388                        SilcUInt16 port, SilcKeyAgreementCallback *completion,
389                        void **context);
390
391   /* Notifies application that file transfer protocol session is being
392      requested by the remote client indicated by the `client_entry' from
393      the `hostname' and `port'. The `session_id' is the file transfer
394      session and it can be used to either accept or reject the file
395      transfer request, by calling the silc_client_file_receive or
396      silc_client_file_close, respectively. */
397   void (*ftp)(SilcClient client, SilcClientConnection conn,
398               SilcClientEntry client_entry, SilcUInt32 session_id,
399               const char *hostname, SilcUInt16 port);
400 } SilcClientOperations;
401 /***/
402
403 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
404  *
405  * SYNOPSIS
406  *
407  *    typedef void (*SilcNicknameFormatParse)(const char *nickname,
408  *                                            char **ret_nickname);
409  *
410  * DESCRIPTION
411  *
412  *    A callback function provided by the application for the library in
413  *    SilcClientParams structure. This function parses the formatted
414  *    nickname string `nickname' and returns the true nickname to the
415  *    `ret_nickname' pointer. The library can call this function at
416  *    any time.
417  *
418  ***/
419 typedef void (*SilcNicknameFormatParse)(const char *nickname,
420                                         char **ret_nickname);
421
422 /****s* silcclient/SilcClientAPI/SilcClientParams
423  *
424  * NAME
425  *
426  *    typedef struct { ... } SilcClientParams;
427  *
428  * DESCRIPTION
429  *
430  *    Client parameters. This can be filled with proper values and
431  *    given as argument to the silc_client_alloc function. The structure
432  *    hold various parameters which affects the function of the client.
433  *
434  * SOURCE
435  */
436 typedef struct {
437   /* Number of maximum tasks the client library's scheduler can handle.
438      If set to zero, the default value will be used (200). For WIN32
439      systems this should be set to 64 as it is the hard limit dictated
440      by the WIN32. */
441   int task_max;
442
443   /* Rekey timeout in seconds. The client will perform rekey in this
444      time interval. If set to zero, the default value will be used. */
445   unsigned int rekey_secs;
446
447   /* Connection authentication method request timeout. If server does not
448      reply back the current authentication method when we've requested it
449      in this time interval we'll assume the reply will not come at all. 
450      If set to zero, the default value (2 seconds) will be used. */
451   unsigned int connauth_request_secs;
452
453   /* Nickname format string. This can be used to order the client library
454      to save the nicknames in the library in a certain format. Since 
455      nicknames are not unique in SILC it is possible to have multiple same
456      nicknames. Using this format string it is possible to order the library
457      to separate the multiple same nicknames from each other. The format
458      types are defined below and they can appear in any order in the format
459      string. If this is NULL then default format is used which is the
460      default nickname without anything else. The string MUST be NULL
461      terminated.
462      
463      Following format types are available:
464      
465      %n  nickname      - the real nickname returned by the server (mandatory)
466      %h  hostname      - the stripped hostname of the client
467      %H  full hostname - the full hostname of the client
468      %s  server name   - the server name the client is connected
469      %S  full server   - the full server name the client is connected
470      %a  number        - ascending number in case there are several
471                          same nicknames (fe. nick@host and nick@host2)
472
473      Example format strings: "%n@%h%a"   (fe. nick@host, nick@host2)
474                              "%a!%n@%s"  (fe. nick@server, 2!nick@server)
475                              "%n@%H"     (fe. nick@host.domain.com)
476
477      By default this format is employed to the nicknames by the libary
478      only when there appears multiple same nicknames. If the library has
479      only one nickname cached the nickname is saved as is and without the
480      defined format. If you want always to save the nickname in the defined
481      format set the boolean field `nickname_force_format' to value TRUE.
482   */
483   char nickname_format[32];
484
485   /* If this is set to TRUE then the `nickname_format' is employed to all
486      saved nicknames even if there are no multiple same nicknames in the 
487      cache. By default this is FALSE, which means that the `nickname_format'
488      is employed only if the library will receive a nickname that is
489      already saved in the cache. It is recommended to leave this to FALSE
490      value. */
491   bool nickname_force_format;
492
493   /* A callback function provided by the application for the library to
494      parse the nickname from the formatted nickname string. Even though
495      the libary formats the nicknames the application knows generally the
496      format better so this function should be provided for the library
497      if the application sets the `nickname_format' field. The library
498      will call this to get the true nickname from the provided formatted
499      nickname string whenever it needs the true nickname. */
500   SilcNicknameFormatParse nickname_parse;
501
502 } SilcClientParams;
503 /***/
504
505
506 /* Initialization functions (client.c) */
507
508 /****f* silcclient/SilcClientAPI/silc_client_alloc
509  *
510  * SYNOPSIS
511  *
512  *    SilcClient silc_client_alloc(SilcClientOperations *ops, 
513  *                                 SilcClientParams *params,
514  *                                 void *application,
515  *                                 const char *silc_version);
516  *
517  * DESCRIPTION
518  *
519  *    Allocates new client object. This has to be done before client may
520  *    work. After calling this one must call silc_client_init to initialize
521  *    the client. The `application' is application specific user data pointer
522  *    and caller must free it. The `silc_version' is the application version
523  *    that will be used to compare against remote host's (usually a server)
524  *    version string.
525  *
526  ***/
527 SilcClient silc_client_alloc(SilcClientOperations *ops, 
528                              SilcClientParams *params,
529                              void *application,
530                              const char *silc_version);
531
532 /****f* silcclient/SilcClientAPI/silc_client_free
533  *
534  * SYNOPSIS
535  *
536  *    void silc_client_free(SilcClient client);
537  *
538  * DESCRIPTION
539  *
540  *    Frees client object and its internals.  The execution of the client
541  *    should be stopped with silc_client_stop function before calling
542  *    this function.
543  *
544  ***/
545 void silc_client_free(SilcClient client);
546
547 /****f* silcclient/SilcClientAPI/silc_client_init
548  *
549  * SYNOPSIS
550  *
551  *    int silc_client_init(SilcClient client);
552  *
553  * DESCRIPTION
554  *
555  *    Initializes the client. This makes all the necessary steps to make
556  *    the client ready to be run. One must call silc_client_run to run the
557  *    client. Returns FALSE if error occurred, TRUE otherwise.
558  *
559  ***/
560 int silc_client_init(SilcClient client);
561
562 /****f* silcclient/SilcClientAPI/silc_client_run
563  *
564  * SYNOPSIS
565  *
566  *    void silc_client_run(SilcClient client);
567  *
568  * DESCRIPTION
569  *
570  *    Runs the client. This starts the scheduler from the utility library.
571  *    When this functions returns the execution of the appliation is over.
572  *
573  ***/
574 void silc_client_run(SilcClient client);
575
576 /****f* silcclient/SilcClientAPI/silc_client_run_one
577  *
578  * SYNOPSIS
579  *
580  *    void silc_client_run_one(SilcClient client);
581  *
582  * DESCRIPTION
583  *
584  *    Runs the client and returns immeadiately. This function is used when
585  *    the SILC Client object indicated by the `client' is run under some
586  *    other scheduler, or event loop or main loop.  On GUI applications,
587  *    for example this may be desired to used to run the client under the
588  *    GUI application's main loop.  Typically the GUI application would
589  *    register an idle task that calls this function multiple times in
590  *    a second to quickly process the SILC specific data.
591  *
592  ***/
593 void silc_client_run_one(SilcClient client);
594
595 /****f* silcclient/SilcClientAPI/silc_client_stop
596  *
597  * SYNOPSIS
598  *
599  *    void silc_client_stop(SilcClient client);
600  *
601  * DESCRIPTION
602  *
603  *    Stops the client. This is called to stop the client and thus to stop
604  *    the program.  The client context must be freed with the silc_client_free
605  *    function.
606  *
607  ***/
608 void silc_client_stop(SilcClient client);
609
610
611 /* Connecting functions (client.c) */
612
613 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
614  *
615  * SYNOPSIS
616  *
617  *    int silc_client_connect_to_server(SilcClient client, int port,
618  *                                      char *host, void *context);
619  *
620  * DESCRIPTION
621  *
622  *    Connects to remote server. This is the main routine used to connect
623  *    to SILC server. Returns -1 on error and the created socket otherwise. 
624  *    The `context' is user context that is saved into the SilcClientConnection
625  *    that is created after the connection is created. Note that application
626  *    may handle the connecting process outside the library. If this is the
627  *    case then this function is not used at all. When the connecting is
628  *    done the `connect' client operation is called.
629  *
630  ***/
631 int silc_client_connect_to_server(SilcClient client, int port,
632                                   char *host, void *context);
633
634 /****f* silcclient/SilcClientAPI/silc_client_add_connection
635  *
636  * SYNOPSIS
637  *
638  *    SilcClientConnection silc_client_add_connection(SilcClient client,
639  *                                                    char *hostname,
640  *                                                    int port,
641  *                                                    void *context);
642  *
643  * DESCRIPTION
644  *
645  *    Allocates and adds new connection to the client. This adds the allocated
646  *    connection to the connection table and returns a pointer to it. A client
647  *    can have multiple connections to multiple servers. Every connection must
648  *    be added to the client using this function. User data `context' may
649  *    be sent as argument. This function is normally used only if the 
650  *    application performed the connecting outside the library. The library
651  *    however may use this internally.
652  *
653  ***/
654 SilcClientConnection silc_client_add_connection(SilcClient client,
655                                                 char *hostname,
656                                                 int port,
657                                                 void *context);
658
659 /****f* silcclient/SilcClientAPI/silc_client_del_connection
660  *
661  * SYNOPSIS
662  *
663  *    void silc_client_del_connection(SilcClient client, 
664  *                                    SilcClientConnection conn);
665  *
666  * DESCRIPTION
667  *
668  *    Removes connection from client. Frees all memory. The library
669  *    call this function automatically for all connection contexts.
670  *    The application however may free the connection contexts it has
671  *    allocated.
672  *
673  ***/
674 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
675
676 /****f* silcclient/SilcClientAPI/silc_client_add_socket
677  *
678  * SYNOPSIS
679  *
680  *    void silc_client_add_socket(SilcClient client, 
681  *                                SilcSocketConnection sock);
682  *
683  * DESCRIPTION
684  *
685  *    Adds listener socket to the listener sockets table. This function is
686  *    used to add socket objects that are listeners to the client.  This should
687  *    not be used to add other connection objects.
688  *
689  ***/
690 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
691
692 /****f* silcclient/SilcClientAPI/silc_client_del_socket
693  *
694  * SYNOPSIS
695  *
696  *    void silc_client_del_socket(SilcClient client, 
697  *                                SilcSocketConnection sock);
698  *
699  * DESCRIPTION
700  *
701  *    Deletes listener socket from the listener sockets table.  If the
702  *    application has added a socket with silc_client_add_socket it must
703  *    also free it using this function.
704  *
705  ***/
706 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
707
708 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
709  *
710  * SYNOPSIS
711  *
712  *    void silc_client_start_key_exchange(SilcClient client,
713  *                                        SilcClientConnection conn,
714  *                                        int fd);
715  *
716  * DESCRIPTION
717  *
718  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
719  *    key material between client and server.  This function can be called
720  *    directly if application is performing its own connecting and does not
721  *    use the connecting provided by this library. This function is normally
722  *    used only if the application performed the connecting outside the
723  *    library. The library however may use this internally.  After the
724  *    key exchange is performed the `connect' client operation is called.
725  *
726  ***/
727 void silc_client_start_key_exchange(SilcClient client,
728                                     SilcClientConnection conn,
729                                     int fd);
730
731 /****f* silcclient/SilcClientAPI/silc_client_close_connection
732  *
733  * SYNOPSIS
734  *
735  *    void silc_client_close_connection(SilcClient client,
736  *                                      SilcSocketConnection sock,
737  *                                      SilcClientConnection conn);
738  *
739  * DESCRIPTION
740  *
741  *    Closes connection to remote end. Free's all allocated data except
742  *    for some information such as nickname etc. that are valid at all time. 
743  *    If the `sock' is NULL then the conn->sock will be used.  If `sock' is
744  *    provided it will be checked whether the sock and `conn->sock' are the
745  *    same (they can be different, ie. a socket can use `conn' as its
746  *    connection but `conn->sock' might be actually a different connection
747  *    than the `sock'). 
748  *
749  ***/
750 void silc_client_close_connection(SilcClient client,
751                                   SilcSocketConnection sock,
752                                   SilcClientConnection conn);
753
754
755 /* Message sending functions (client_channel.c and client_prvmsg.c) */
756
757 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
758  *
759  * SYNOPSIS
760  *
761  *    void silc_client_send_channel_message(SilcClient client, 
762  *                                          SilcClientConnection conn,
763  *                                          SilcChannelEntry channel,
764  *                                          SilcChannelPrivateKey key,
765  *                                          SilcMessageFlags flags,
766  *                                          unsigned char *data, 
767  *                                          SilcUInt32 data_len, 
768  *                                          int force_send);
769  *
770  * DESCRIPTION
771  *
772  *    Sends packet to the `channel'. Packet to channel is always encrypted
773  *    differently from "normal" packets. SILC header of the packet is 
774  *    encrypted with the next receiver's key and the rest of the packet is
775  *    encrypted with the channel specific key. Padding and HMAC is computed
776  *    with the next receiver's key. The `data' is the channel message. If
777  *    the `force_send' is TRUE then the packet is sent immediately. 
778  *
779  *    If `key' is provided then that private key is used to encrypt the
780  *    channel message.  If it is not provided, private keys has not been
781  *    set at all, the normal channel key is used automatically.  If private
782  *    keys are set then the first key (the key that was added first as
783  *    private key) is used. 
784  *
785  ***/
786 void silc_client_send_channel_message(SilcClient client, 
787                                       SilcClientConnection conn,
788                                       SilcChannelEntry channel,
789                                       SilcChannelPrivateKey key,
790                                       SilcMessageFlags flags,
791                                       unsigned char *data, 
792                                       SilcUInt32 data_len, 
793                                       int force_send);
794
795 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
796  *
797  * SYNOPSIS
798  *
799  *    void silc_client_send_private_message(SilcClient client,
800  *                                          SilcClientConnection conn,
801  *                                          SilcClientEntry client_entry,
802  *                                          SilcMessageFlags flags,
803  *                                          unsigned char *data, 
804  *                                          SilcUInt32 data_len, 
805  *                                          int force_send);
806  *
807  * DESCRIPTION
808  *
809  *    Sends private message to remote client. If private message key has
810  *    not been set with this client then the message will be encrypted using
811  *    normal session keys. Private messages are special packets in SILC
812  *    network hence we need this own function for them. This is similar
813  *    to silc_client_packet_send_to_channel except that we send private
814  *    message. The `data' is the private message. If the `force_send' is
815  *    TRUE the packet is sent immediately. 
816  *
817  ***/
818 void silc_client_send_private_message(SilcClient client,
819                                       SilcClientConnection conn,
820                                       SilcClientEntry client_entry,
821                                       SilcMessageFlags flags,
822                                       unsigned char *data, 
823                                       SilcUInt32 data_len, 
824                                       int force_send);
825
826
827 /* Client and Channel entry retrieval (idlist.c) */
828
829 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
830  *
831  * SYNOPSIS
832  *
833  *    typedef void (*SilcGetClientCallback)(SilcClient client,
834  *                                          SilcClientConnection conn,
835  *                                          SilcClientEntry *clients,
836  *                                          SilcUInt32 clients_count,
837  *                                          void *context);
838  *
839  * DESCRIPTION
840  *
841  *    Callback function given to the silc_client_get_client function. The
842  *    found entries are allocated into the `clients' array. The array must
843  *    not be freed by the receiver, the library will free it later. If the
844  *    `clients' is NULL, no such clients exist in the SILC Network.
845  *
846  ***/
847 typedef void (*SilcGetClientCallback)(SilcClient client,
848                                       SilcClientConnection conn,
849                                       SilcClientEntry *clients,
850                                       SilcUInt32 clients_count,
851                                       void *context);
852
853 /****f* silcclient/SilcClientAPI/silc_client_get_clients
854  *
855  * SYNOPSIS
856  *
857  *    void silc_client_get_clients(SilcClient client,
858  *                                 SilcClientConnection conn,
859  *                                 const char *nickname,
860  *                                 const char *server,
861  *                                 SilcGetClientCallback completion,
862  *                                 void *context);
863  *
864  * DESCRIPTION
865  *
866  *    Finds client entry or entries by the `nickname' and `server'. The 
867  *    completion callback will be called when the client entries has been
868  *    found.  After the server returns the client information it is cached
869  *    and can be accesses locally at a later time.
870  *
871  * NOTES
872  *
873  *    NOTE: This function is always asynchronous and resolves the client
874  *    information from the server. Thus, if you already know the client
875  *    information then use the silc_client_get_client_by_id function to
876  *    get the client entry since this function may be very slow and should
877  *    be used only to initially get the client entries. 
878  *
879  ***/
880 void silc_client_get_clients(SilcClient client,
881                              SilcClientConnection conn,
882                              const char *nickname,
883                              const char *server,
884                              SilcGetClientCallback completion,
885                              void *context);
886
887 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
888  *
889  * SYNOPSIS
890  *
891  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
892  *                                                   SilcClientConnection conn,
893  *                                                   const char *nickname,
894  *                                                   const char *format,
895  *                                                   SilcUInt32 *clients_count);
896  *
897  * DESCRIPTION
898  *
899  *    Same as silc_client_get_clients function but does not resolve anything
900  *    from the server. This checks local cache and returns all matching
901  *    clients from the local cache. If none was found this returns NULL.
902  *    The `nickname' is the real nickname of the client, and the `format'
903  *    is the formatted nickname to find exact match from multiple found
904  *    entries. The format must be same as given in the SilcClientParams
905  *    structure to the client library. If the `format' is NULL all found
906  *    clients by `nickname' are returned. The caller must return the
907  *    returned array.
908  *
909  ***/
910 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
911                                                SilcClientConnection conn,
912                                                const char *nickname,
913                                                const char *format,
914                                                SilcUInt32 *clients_count);
915
916 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
917  *
918  * SYNOPSIS
919  *
920  *    void silc_client_get_clients_by_list(SilcClient client,
921  *                                         SilcClientConnection conn,
922  *                                         SilcUInt32 list_count,
923  *                                         SilcBuffer client_id_list,
924  *                                         SilcGetClientCallback completion,
925  *                                         void *context);
926  *
927  * DESCRIPTION
928  *
929  *    Gets client entries by the list of client ID's `client_id_list'. This
930  *    always resolves those client ID's it does not know yet from the server
931  *    so this function might take a while. The `client_id_list' is a list
932  *    of ID Payloads added one after other.  JOIN command reply and USERS
933  *    command reply for example returns this sort of list. The `completion'
934  *    will be called after the entries are available. When server returns
935  *    the client information it will be cached and can be accessed locally
936  *    at a later time.
937  *
938  ***/
939 void silc_client_get_clients_by_list(SilcClient client,
940                                      SilcClientConnection conn,
941                                      SilcUInt32 list_count,
942                                      SilcBuffer client_id_list,
943                                      SilcGetClientCallback completion,
944                                      void *context);
945
946 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
947  *
948  * SYNOPSIS
949  *
950  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
951  *                                                 SilcClientConnection conn,
952  *                                                 SilcClientID *client_id);
953  *
954  * DESCRIPTION
955  *
956  *    Find entry for client by the client's ID. Returns the entry or NULL
957  *    if the entry was not found.  This checks the local cache and does
958  *    not resolve anything from server.
959  *
960  ***/
961 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
962                                              SilcClientConnection conn,
963                                              SilcClientID *client_id);
964
965 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
966  *
967  * SYNOPSIS
968  *
969  *    void 
970  *    silc_client_get_client_by_id_resolve(SilcClient client,
971  *                                         SilcClientConnection conn,
972  *                                         SilcClientID *client_id,
973  *                                         SilcGetClientCallback completion,
974  *                                         void *context);
975  *
976  * DESCRIPTION
977  *
978  *    Same as silc_client_get_client_by_id but will always resolve the
979  *    information from the server. Use this only if you know that you
980  *    do not have the entry and the only thing you know about the client
981  *    is its ID. When server returns the client information it will be
982  *    cache and can be accessed locally at a later time.
983  *
984  ***/
985 void silc_client_get_client_by_id_resolve(SilcClient client,
986                                           SilcClientConnection conn,
987                                           SilcClientID *client_id,
988                                           SilcGetClientCallback completion,
989                                           void *context);
990
991 /****f* silcclient/SilcClientAPI/silc_client_del_client
992  *
993  * SYNOPSIS
994  *
995  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
996  *                                SilcClientEntry client_entry)
997  *
998  * DESCRIPTION
999  *
1000  *    Removes client from local cache by the client entry indicated by
1001  *    the `client_entry'.  Returns TRUE if the deletion were successful.
1002  *
1003  ***/
1004 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1005                             SilcClientEntry client_entry);
1006
1007 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1008  *
1009  * SYNOPSIS
1010  *
1011  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
1012  *                                           SilcClientConnection conn,
1013  *                                           SilcChannelEntry *channels,
1014  *                                           SilcUInt32 channels_count,
1015  *                                           void *context);
1016  *
1017  * DESCRIPTION
1018  *
1019  *    Callback function given to the silc_client_get_channel_* functions.
1020  *    The found entries are allocated into the `channels' array. The array
1021  *    must not be freed by the receiver, the library will free it later.
1022  *    If the `channel' is NULL, no such channel exist in the SILC Network.
1023  *
1024  ***/
1025 typedef void (*SilcGetChannelCallback)(SilcClient client,
1026                                        SilcClientConnection conn,
1027                                        SilcChannelEntry *channels,
1028                                        SilcUInt32 channels_count,
1029                                        void *context);
1030
1031 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1032  *
1033  * SYNOPSIS
1034  *
1035  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
1036  *                                             SilcClientConnection conn,
1037  *                                             char *channel);
1038  *
1039  * DESCRIPTION
1040  *
1041  *    Finds entry for channel by the channel name. Returns the entry or NULL
1042  *    if the entry was not found. It is found only if the client is joined
1043  *    to the channel. 
1044  *
1045  ***/
1046 SilcChannelEntry silc_client_get_channel(SilcClient client,
1047                                          SilcClientConnection conn,
1048                                          char *channel);
1049
1050 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1051  *
1052  * SYNOPSIS
1053  *
1054  *    void 
1055  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1056  *                                          SilcClientConnection conn,
1057  *                                          SilcChannelID *channel_id,
1058  *                                          SilcGetClientCallback completion,
1059  *                                          void *context);
1060  *
1061  * DESCRIPTION
1062  *
1063  *    Finds channel entry by the channel name. Returns the entry or NULL
1064  *    if it was not found.
1065  *
1066  ***/
1067 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1068                                                SilcClientConnection conn,
1069                                                SilcChannelID *channel_id);
1070
1071 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1072  *
1073  * SYNOPSIS
1074  *
1075  *    void 
1076  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1077  *                                          SilcClientConnection conn,
1078  *                                          SilcChannelID *channel_id,
1079  *                                          SilcGetClientCallback completion,
1080  *                                          void *context);
1081  *
1082  * DESCRIPTION
1083  *
1084  *    Resolves the channel information (its name mainly) from the server
1085  *    by the `channel_id'. Use this only if you know that you do not have
1086  *    the entry cached locally.
1087  *
1088  ***/
1089 void silc_client_get_channel_by_id_resolve(SilcClient client,
1090                                            SilcClientConnection conn,
1091                                            SilcChannelID *channel_id,
1092                                            SilcGetChannelCallback completion,
1093                                            void *context);
1094
1095 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1096  *
1097  * SYNOPSIS
1098  *
1099  *    bool silc_client_del_channel(SilcClient client, 
1100  *                                 SilcClientConnection conn,
1101  *                                 SilcChannelEntry channel)
1102  *
1103  * DESCRIPTION
1104  *
1105  *    Removes channel from local cache by the channel entry indicated by
1106  *    the `channel'.  Returns TRUE if the deletion were successful.
1107  *
1108  ***/
1109 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1110                              SilcChannelEntry channel);
1111
1112 /****f* silcclient/SilcClientAPI/silc_client_get_server
1113  *
1114  * SYNOPSIS
1115  *
1116  *    SilcServerEntry silc_client_get_server(SilcClient client,
1117  *                                           SilcClientConnection conn,
1118  *                                           char *server_name)
1119  *
1120  * DESCRIPTION
1121  *
1122  *    Finds entry for server by the server name. Returns the entry or NULL
1123  *    if the entry was not found.
1124  *
1125  ***/
1126 SilcServerEntry silc_client_get_server(SilcClient client,
1127                                        SilcClientConnection conn,
1128                                        char *server_name);
1129
1130 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1131  *
1132  * SYNOPSIS
1133  *
1134  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1135  *                                                 SilcClientConnection conn,
1136  *                                                 SilcServerID *server_id);
1137  *
1138  * DESCRIPTION
1139  *
1140  *    Finds entry for server by the server ID. Returns the entry or NULL
1141  *    if the entry was not found.
1142  *
1143  ***/
1144 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1145                                              SilcClientConnection conn,
1146                                              SilcServerID *server_id);
1147
1148 /****f* silcclient/SilcClientAPI/silc_client_del_server
1149  *
1150  * SYNOPSIS
1151  *
1152  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1153  *                                SilcServerEntry server);
1154  *
1155  * DESCRIPTION
1156  *
1157  *    Removes server from local cache by the server entry indicated by
1158  *    the `server'.  Returns TRUE if the deletion were successful.
1159  *
1160  ***/
1161 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1162                             SilcServerEntry server);
1163
1164 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1165  *
1166  * SYNOPSIS
1167  *
1168  *    SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1169  *                                           SilcClientEntry client_entry);
1170  *
1171  * DESCRIPTION
1172  *
1173  *    Returns the ChannelUser entry if the `client_entry' is joined on the 
1174  *    channel indicated by the `channel'. NULL if client is not joined on
1175  *    the channel. 
1176  *
1177  ***/
1178 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1179                                        SilcClientEntry client_entry);
1180
1181 /* Command management (command.c) */
1182
1183 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1184  *
1185  * SYNOPSIS
1186  *
1187  *    SilcClientCommandContext silc_client_command_alloc(void);
1188  *
1189  * DESCRIPTION
1190  *
1191  *    Allocate Command Context. The context is defined in `command.h' file.
1192  *    The context is used by the library commands and applications should use
1193  *    it as well. However, application may choose to use some own context
1194  *    for its local commands. All library commands, however, must use this
1195  *    context. 
1196  *
1197  ***/
1198 SilcClientCommandContext silc_client_command_alloc(void);
1199
1200 /****f* silcclient/SilcClientAPI/silc_client_command_free
1201  *
1202  * SYNOPSIS
1203  *
1204  *    void silc_client_command_free(SilcClientCommandContext ctx);
1205  *
1206  * DESCRIPTION
1207  *
1208  *    Free command context and its internals.  If the contex was duplicated
1209  *    with silc_client_command_dup this may not actually free the data, 
1210  *    instead it will decrease the reference counter of the context.  The
1211  *    context will be freed when the reference counter hits zero.
1212  *
1213  ***/
1214 void silc_client_command_free(SilcClientCommandContext ctx);
1215
1216 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1217  *
1218  * SYNOPSIS
1219  *
1220  *    SilcClientCommandContext 
1221  *    silc_client_command_dup(SilcClientCommandContext ctx);
1222  *
1223  * DESCRIPTION
1224  *
1225  *    Duplicate Command Context by adding reference counter. The context won't
1226  *    be free'd untill it hits zero. 
1227  *
1228  ***/
1229 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1230
1231 /****f* silcclient/SilcClientAPI/silc_client_command_find
1232  *
1233  * SYNOPSIS
1234  *
1235  *    SilcClientCommand silc_client_command_find(SilcClient client,
1236  *                                               const char *name);
1237  *
1238  * DESCRIPTION
1239  *
1240  *    Finds and returns a pointer to the command list. Return NULL if the
1241  *    command is not found. See the `command.[ch]' for the command list. 
1242  *    Command names are not case-sensitive.
1243  *
1244  ***/
1245 SilcClientCommand silc_client_command_find(SilcClient client,
1246                                            const char *name);
1247
1248 /****f* silcclient/SilcClientAPI/silc_client_command_call
1249  *
1250  * SYNOPSIS
1251  *
1252  *    void silc_client_command_call(SilcClientCommand command);
1253  *
1254  * DESCRIPTION
1255  *
1256  *    Calls the command (executes it).  Application can call this after
1257  *    it has allocated the SilcClientCommandContext with the function
1258  *    silc_client_command_alloc and found the command from the client
1259  *    library by calling silc_client_command_find.  This will execute
1260  *    the command.
1261  *
1262  *    Application can call the command function directly too if it
1263  *    wishes to do so.  See the command.h for details of the
1264  *    SilcClientCommand structure.
1265  *
1266  ***/
1267 void silc_client_command_call(SilcClientCommand command,
1268                               SilcClientCommandContext cmd);
1269
1270 /****f* silcclient/SilcClientAPI/silc_client_command_send
1271  *
1272  * SYNOPSIS
1273  *
1274  *    void silc_client_command_send(SilcClient client, 
1275  *                                  SilcClientConnection conn,
1276  *                                  SilcCommand command, SilcUInt16 ident,
1277  *                                  SilcUInt32 argc, ...);
1278  *
1279  * DESCRIPTION
1280  *
1281  *    Generic function to send any command. The arguments must be sent already
1282  *    encoded into correct form and in correct order. If application wants
1283  *    to perform the commands by itself, it can do so and send the data
1284  *    directly to the server using this function.  If application is using
1285  *    the silc_client_command_call, this function is usually not used.
1286  *
1287  ***/
1288 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1289                               SilcCommand command, SilcUInt16 ident,
1290                               SilcUInt32 argc, ...);
1291
1292 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1293  *
1294  * SYNOPSIS
1295  *
1296  *    void silc_client_command_pending(SilcClientConnection conn,
1297  *                                     SilcCommand reply_cmd,
1298  *                                     SilcUInt16 ident,
1299  *                                     SilcCommandCb callback,
1300  *                                     void *context);
1301  *
1302  * DESCRIPTION
1303  *
1304  *    Add new pending command to be executed when reply to a command has been
1305  *    received.  The `reply_cmd' is the command that will call the `callback'
1306  *    with `context' when reply has been received.  If `ident' is non-zero
1307  *    the `callback' will be executed when received reply with command 
1308  *    identifier `ident'. 
1309  *
1310  *    Note that the application is notified about the received command
1311  *    reply through the `command_reply' client operation before calling
1312  *    the `callback` pending command callback.
1313  *
1314  ***/
1315 void silc_client_command_pending(SilcClientConnection conn,
1316                                  SilcCommand reply_cmd,
1317                                  SilcUInt16 ident,
1318                                  SilcCommandCb callback,
1319                                  void *context);
1320
1321
1322 /* Private Message key management (client_prvmsg.c) */
1323
1324 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1325  *
1326  * SYNOPSIS
1327  *
1328  *    int silc_client_add_private_message_key(SilcClient client,
1329  *                                            SilcClientConnection conn,
1330  *                                            SilcClientEntry client_entry,
1331  *                                            char *cipher,
1332  *                                            unsigned char *key,
1333  *                                            SilcUInt32 key_len,
1334  *                                            bool generate_key,
1335  *                                            bool responder);
1336  *
1337  * DESCRIPTION
1338  *
1339  *    Adds private message key to the client library. The key will be used to
1340  *    encrypt all private message between the client and the remote client
1341  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1342  *    value `generate_key' is TRUE the library will generate random key.
1343  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1344  *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
1345  *    requirements of the SILC protocol are met. The API, however, allows
1346  *    to allocate any cipher.
1347  *
1348  *    If `responder' is TRUE then the sending and receiving keys will be
1349  *    set according the client being the receiver of the private key.  If
1350  *    FALSE the client is being the sender (or negotiator) of the private
1351  *    key.
1352  *
1353  *    It is not necessary to set key for normal private message usage. If the
1354  *    key is not set then the private messages are encrypted using normal
1355  *    session keys. Setting the private key, however, increases the security. 
1356  *
1357  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1358  *    otherwise. 
1359  *
1360  ***/
1361 int silc_client_add_private_message_key(SilcClient client,
1362                                         SilcClientConnection conn,
1363                                         SilcClientEntry client_entry,
1364                                         char *cipher,
1365                                         unsigned char *key,
1366                                         SilcUInt32 key_len,
1367                                         bool generate_key,
1368                                         bool responder);
1369
1370 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1371  *
1372  * SYNOPSIS
1373  *
1374  *    int silc_client_add_private_message_key_ske(SilcClient client,
1375  *                                                SilcClientConnection conn,
1376  *                                                SilcClientEntry client_entry,
1377  *                                                char *cipher,
1378  *                                                SilcSKEKeyMaterial *key);
1379  *
1380  * DESCRIPTION
1381  *
1382  *    Same as silc_client_add_private_message_key but takes the key material
1383  *    from the SKE key material structure. This structure is received if
1384  *    the application uses the silc_client_send_key_agreement to negotiate
1385  *    the key material. The `cipher' SHOULD be provided as it is negotiated
1386  *    also in the SKE protocol. 
1387  *
1388  ***/
1389 int silc_client_add_private_message_key_ske(SilcClient client,
1390                                             SilcClientConnection conn,
1391                                             SilcClientEntry client_entry,
1392                                             char *cipher,
1393                                             SilcSKEKeyMaterial *key,
1394                                             bool responder);
1395
1396 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1397  *
1398  * SYNOPSIS
1399  *
1400  *    int silc_client_send_private_message_key(SilcClient client,
1401  *                                             SilcClientConnection conn,
1402  *                                             SilcClientEntry client_entry,
1403  *                                             int force_send);
1404  *
1405  * DESCRIPTION
1406  *
1407  *    Sends private message key payload to the remote client indicated by
1408  *    the `client_entry'. If the `force_send' is TRUE the packet is sent
1409  *    immediately. Returns FALSE if error occurs, TRUE otherwise. The
1410  *    application should call this function after setting the key to the
1411  *    client.
1412  *
1413  *    Note that the key sent using this function is sent to the remote client
1414  *    through the SILC network. The packet is protected using normal session
1415  *    keys. 
1416  *
1417  ***/
1418 int silc_client_send_private_message_key(SilcClient client,
1419                                          SilcClientConnection conn,
1420                                          SilcClientEntry client_entry,
1421                                          int force_send);
1422
1423 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1424  *
1425  * SYNOPSIS
1426  *
1427  *    int silc_client_del_private_message_key(SilcClient client,
1428  *                                            SilcClientConnection conn,
1429  *                                            SilcClientEntry client_entry);
1430  *
1431  * DESCRIPTION
1432  *
1433  *    Removes the private message from the library. The key won't be used
1434  *    after this to protect the private messages with the remote `client_entry'
1435  *    client. Returns FALSE on error, TRUE otherwise. 
1436  *
1437  ***/
1438 int silc_client_del_private_message_key(SilcClient client,
1439                                         SilcClientConnection conn,
1440                                         SilcClientEntry client_entry);
1441
1442 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1443  *
1444  * SYNOPSIS
1445  *
1446  *    SilcPrivateMessageKeys
1447  *    silc_client_list_private_message_keys(SilcClient client,
1448  *                                          SilcClientConnection conn,
1449  *                                          SilcUInt32 *key_count);
1450  * 
1451  * DESCRIPTION
1452  *
1453  *    Returns array of set private message keys associated to the connection
1454  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1455  *    count to the `key_count' argument. The array must be freed by the caller
1456  *    by calling the silc_client_free_private_message_keys function. Note: 
1457  *    the keys returned in the array is in raw format. It might not be desired
1458  *    to show the keys as is. The application might choose not to show the keys
1459  *    at all or to show the fingerprints of the keys. 
1460  *
1461  ***/
1462 SilcPrivateMessageKeys
1463 silc_client_list_private_message_keys(SilcClient client,
1464                                       SilcClientConnection conn,
1465                                       SilcUInt32 *key_count);
1466
1467 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1468  *
1469  * SYNOPSIS
1470  *
1471  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1472  *                                               SilcUInt32 key_count);
1473  * 
1474  * DESCRIPTION
1475  *
1476  *    Frees the SilcPrivateMessageKeys array returned by the function
1477  *    silc_client_list_private_message_keys. 
1478  *
1479  ***/
1480 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1481                                            SilcUInt32 key_count);
1482
1483
1484 /* Channel private key management (client_channel.c, 
1485    SilcChannelPrivateKey is defined in idlist.h) */
1486
1487 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1488  *
1489  * SYNOPSIS
1490  *
1491  *    int silc_client_add_channel_private_key(SilcClient client,
1492  *                                            SilcClientConnection conn,
1493  *                                            SilcChannelEntry channel,
1494  *                                            const char *name,
1495  *                                            char *cipher,
1496  *                                            char *hmac,
1497  *                                            unsigned char *key,
1498  *                                            SilcUInt32 key_len);
1499  * 
1500  * DESCRIPTION
1501  *
1502  *    Adds private key for channel. This may be set only if the channel's mode
1503  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1504  *    mode is not set. When channel has private key then the messages are
1505  *    encrypted using that key. All clients on the channel must also know the
1506  *    key in order to decrypt the messages. However, it is possible to have
1507  *    several private keys per one channel. In this case only some of the
1508  *    clients on the channel may know the one key and only some the other key.
1509  *    The `name' can be application given name for the key.
1510  *
1511  *    The private key for channel is optional. If it is not set then the
1512  *    channel messages are encrypted using the channel key generated by the
1513  *    server. However, setting the private key (or keys) for the channel 
1514  *    significantly adds security. If more than one key is set the library
1515  *    will automatically try all keys at the message decryption phase. Note:
1516  *    setting many keys slows down the decryption phase as all keys has to
1517  *    be tried in order to find the correct decryption key. However, setting
1518  *    a few keys does not have big impact to the decryption performace. 
1519  *
1520  * NOTES
1521  *
1522  *    NOTE: This is entirely local setting. The key set using this function
1523  *    is not sent to the network at any phase.
1524  *
1525  *    NOTE: If the key material was originated by the SKE protocol (using
1526  *    silc_client_send_key_agreement) then the `key' MUST be the
1527  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1528  *    currently it is not expected that the SKE key material would be used
1529  *    as channel private key. However, this API allows it. 
1530  *
1531  ***/
1532 int silc_client_add_channel_private_key(SilcClient client,
1533                                         SilcClientConnection conn,
1534                                         SilcChannelEntry channel,
1535                                         const char *name,
1536                                         char *cipher,
1537                                         char *hmac,
1538                                         unsigned char *key,
1539                                         SilcUInt32 key_len);
1540
1541 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1542  *
1543  * SYNOPSIS
1544  *
1545  *    int silc_client_del_channel_private_keys(SilcClient client,
1546  *                                             SilcClientConnection conn,
1547  *                                             SilcChannelEntry channel);
1548  * 
1549  * DESCRIPTION
1550  *
1551  *    Removes all private keys from the `channel'. The old channel key is used
1552  *    after calling this to protect the channel messages. Returns FALSE on
1553  *    on error, TRUE otherwise. 
1554  *
1555  ***/
1556 int silc_client_del_channel_private_keys(SilcClient client,
1557                                          SilcClientConnection conn,
1558                                          SilcChannelEntry channel);
1559
1560 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1561  *
1562  * SYNOPSIS
1563  *
1564  *    int silc_client_del_channel_private_key(SilcClient client,
1565  *                                            SilcClientConnection conn,
1566  *                                            SilcChannelEntry channel,
1567  *                                            SilcChannelPrivateKey key);
1568  * 
1569  * DESCRIPTION
1570  *
1571  *    Removes and frees private key `key' from the channel `channel'. 
1572  *    The `key' is retrieved by calling the function 
1573  *    silc_client_list_channel_private_keys. The key is not used after
1574  *    this. If the key was last private key then the old channel key is
1575  *    used hereafter to protect the channel messages. This returns FALSE
1576  *    on error, TRUE otherwise. 
1577  *
1578  ***/
1579 int silc_client_del_channel_private_key(SilcClient client,
1580                                         SilcClientConnection conn,
1581                                         SilcChannelEntry channel,
1582                                         SilcChannelPrivateKey key);
1583
1584 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1585  *
1586  * SYNOPSIS
1587  *
1588  *    SilcChannelPrivateKey *
1589  *    silc_client_list_channel_private_keys(SilcClient client,
1590  *                                          SilcClientConnection conn,
1591  *                                          SilcChannelEntry channel,
1592  *                                          SilcUInt32 *key_count);
1593  *
1594  * DESCRIPTION
1595  *
1596  *    Returns array (pointers) of private keys associated to the `channel'.
1597  *    The caller must free the array by calling the function
1598  *    silc_client_free_channel_private_keys. The pointers in the array may be
1599  *    used to delete the specific key by giving the pointer as argument to the
1600  *    function silc_client_del_channel_private_key. 
1601  *
1602  ***/
1603 SilcChannelPrivateKey *
1604 silc_client_list_channel_private_keys(SilcClient client,
1605                                       SilcClientConnection conn,
1606                                       SilcChannelEntry channel,
1607                                       SilcUInt32 *key_count);
1608
1609 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1610  *
1611  * SYNOPSIS
1612  *
1613  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1614  *                                               SilcUInt32 key_count);
1615  *
1616  * DESCRIPTION
1617  *
1618  *    Frees the SilcChannelPrivateKey array.
1619  *
1620  ***/
1621 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1622                                            SilcUInt32 key_count);
1623
1624 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1625  *
1626  * SYNOPSIS
1627  *
1628  *    void silc_client_current_channel_private_key(SilcClient client,
1629  *                                                 SilcClientConnection conn,
1630  *                                                 SilcChannelEntry channel,
1631  *                                                 SilcChannelPrivateKey key);
1632  *
1633  * DESCRIPTION
1634  *
1635  *    Sets the `key' to be used as current channel private key on the
1636  *    `channel'.  Packet sent after calling this function will be secured
1637  *    with `key'.
1638  *
1639  ***/
1640 void silc_client_current_channel_private_key(SilcClient client,
1641                                              SilcClientConnection conn,
1642                                              SilcChannelEntry channel,
1643                                              SilcChannelPrivateKey key);
1644
1645
1646 /* Key Agreement routines (client_keyagr.c) */
1647
1648 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1649  *
1650  * SYNOPSIS
1651  *
1652  *    void silc_client_send_key_agreement(SilcClient client,
1653  *                                        SilcClientConnection conn,
1654  *                                        SilcClientEntry client_entry,
1655  *                                        char *hostname,
1656  *                                        int port,
1657  *                                        SilcUInt32 timeout_secs,
1658  *                                        SilcKeyAgreementCallback completion,
1659  *                                        void *context);
1660  *
1661  * DESCRIPTION
1662  *
1663  *    Sends key agreement request to the remote client indicated by the
1664  *    `client_entry'. If the caller provides the `hostname' and the `port'
1665  *    arguments then the library will bind the client to that hostname and
1666  *    that port for the key agreement protocol. It also sends the `hostname'
1667  *    and the `port' in the key agreement packet to the remote client. This
1668  *    would indicate that the remote client may initiate the key agreement
1669  *    protocol to the `hostname' on the `port'.  If port is zero then the
1670  *    bound port is undefined (the operating system defines it).
1671  *
1672  *    If the `hostname' and `port' is not provided then empty key agreement
1673  *    packet is sent to the remote client. The remote client may reply with
1674  *    the same packet including its hostname and port. If the library receives
1675  *    the reply from the remote client the `key_agreement' client operation
1676  *    callback will be called to verify whether the user wants to perform the
1677  *    key agreement or not. 
1678  *
1679  * NOTES
1680  *
1681  *    NOTE: If the application provided the `hostname' and the `port' and the 
1682  *    remote side initiates the key agreement protocol it is not verified
1683  *    from the user anymore whether the protocol should be executed or not.
1684  *    By setting the `hostname' and `port' the user gives permission to
1685  *    perform the protocol (we are responder in this case).
1686  *
1687  *    NOTE: If the remote side decides not to initiate the key agreement
1688  *    or decides not to reply with the key agreement packet then we cannot
1689  *    perform the key agreement at all. If the key agreement protocol is
1690  *    performed the `completion' callback with the `context' will be called.
1691  *    If remote side decides to ignore the request the `completion' will be
1692  *    called after the specified timeout, `timeout_secs'. 
1693  *
1694  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
1695  *    will not be called at all since this does nothing more than sending
1696  *    a packet to the remote host.
1697  *
1698  *    NOTE: There can be only one active key agreement for one client entry.
1699  *    Before setting new one, the old one must be finished (it is finished
1700  *    after calling the completion callback) or the function 
1701  *    silc_client_abort_key_agreement must be called. 
1702  *
1703  ***/
1704 void silc_client_send_key_agreement(SilcClient client,
1705                                     SilcClientConnection conn,
1706                                     SilcClientEntry client_entry,
1707                                     const char *hostname,
1708                                     const char *bindhost,
1709                                     int port,
1710                                     SilcUInt32 timeout_secs,
1711                                     SilcKeyAgreementCallback completion,
1712                                     void *context);
1713
1714 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1715  *
1716  * SYNOPSIS
1717  *
1718  *    void 
1719  *    silc_client_perform_key_agreement(SilcClient client,
1720  *                                      SilcClientConnection conn,
1721  *                                      SilcClientEntry client_entry,
1722  *                                      char *hostname,
1723  *                                      int port,
1724  *                                      SilcKeyAgreementCallback completion,
1725  *                                      void *context);
1726  *
1727  * DESCRIPTION
1728  *
1729  *    Performs the actual key agreement protocol. Application may use this
1730  *    to initiate the key agreement protocol. This can be called for example
1731  *    after the application has received the `key_agreement' client operation,
1732  *    and did not return TRUE from it.
1733  *
1734  *    The `hostname' is the remote hostname (or IP address) and the `port'
1735  *    is the remote port. The `completion' callback with the `context' will
1736  *    be called after the key agreement protocol.
1737  *
1738  * NOTES
1739  * 
1740  *    NOTE: If the application returns TRUE in the `key_agreement' client
1741  *    operation the library will automatically start the key agreement. In this
1742  *    case the application must not call this function. However, application
1743  *    may choose to just ignore the `key_agreement' client operation (and
1744  *    merely just print information about it on the screen) and call this
1745  *    function when the user whishes to do so (by, for example, giving some
1746  *    specific command). Thus, the API provides both, automatic and manual
1747  *    initiation of the key agreement. Calling this function is the manual
1748  *    initiation and returning TRUE in the `key_agreement' client operation
1749  *    is the automatic initiation. 
1750  *
1751  ***/
1752 void silc_client_perform_key_agreement(SilcClient client,
1753                                        SilcClientConnection conn,
1754                                        SilcClientEntry client_entry,
1755                                        char *hostname,
1756                                        int port,
1757                                        SilcKeyAgreementCallback completion,
1758                                        void *context);
1759
1760 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1761  *
1762  * SYNOPSIS
1763  *
1764  *    void
1765  *    silc_client_perform_key_agreement_fd(SilcClient client,
1766  *                                         SilcClientConnection conn,
1767  *                                         SilcClientEntry client_entry,
1768  *                                         int sock,
1769  *                                         char *hostname,
1770  *                                         SilcKeyAgreementCallback completion,
1771  *                                         void *context);
1772  *
1773  * DESCRIPTION
1774  *
1775  *    Same as above but application has created already the connection to 
1776  *    the remote host. The `sock' is the socket to the remote connection. 
1777  *    Application can use this function if it does not want the client library
1778  *    to create the connection. 
1779  *
1780  ***/
1781 void silc_client_perform_key_agreement_fd(SilcClient client,
1782                                           SilcClientConnection conn,
1783                                           SilcClientEntry client_entry,
1784                                           int sock,
1785                                           char *hostname,
1786                                           SilcKeyAgreementCallback completion,
1787                                           void *context);
1788
1789 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1790  *
1791  * SYNOPSIS
1792  *
1793  *    void silc_client_abort_key_agreement(SilcClient client,
1794  *                                         SilcClientConnection conn,
1795  *                                         SilcClientEntry client_entry);
1796  *
1797  * DESCRIPTION
1798  *
1799  *    This function can be called to unbind the hostname and the port for
1800  *    the key agreement protocol. However, this function has effect only 
1801  *    before the key agreement protocol has been performed. After it has
1802  *    been performed the library will automatically unbind the port. The 
1803  *    `client_entry' is the client to which we sent the key agreement 
1804  *    request.  The key agreement completion callback will be called
1805  *    with SILC_KEY_AGREEMENT_ABORTED status.
1806  *
1807  ***/
1808 void silc_client_abort_key_agreement(SilcClient client,
1809                                      SilcClientConnection conn,
1810                                      SilcClientEntry client_entry);
1811
1812
1813 /* Misc functions */
1814
1815 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1816  *
1817  * SYNOPSIS
1818  *
1819  *    void silc_client_set_away_message(SilcClient client,
1820  *                                      SilcClientConnection conn,
1821  *                                      char *message);
1822  *
1823  * DESCRIPTION
1824  *
1825  *    Sets away `message'.  The away message may be set when the client's
1826  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1827  *    to anyone who sends private message.  The `message' will be sent
1828  *    automatically back to the the client who send private message.  If
1829  *    away message is already set this replaces the old message with the
1830  *    new one.  If `message' is NULL the old away message is removed. 
1831  *    The sender may freely free the memory of the `message'. 
1832  *
1833  ***/
1834 void silc_client_set_away_message(SilcClient client,
1835                                   SilcClientConnection conn,
1836                                   char *message);
1837
1838
1839 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1840  *
1841  * SYNOPSIS
1842  *
1843  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1844  *                                              SilcClientConnection conn,
1845  *                                              SilcAuthMethod auth_meth,
1846  *                                              void *context);
1847  *
1848  * DESCRIPTION
1849  *
1850  *    Connection authentication method request callback. This is called
1851  *    by the client library after it has received the authentication method
1852  *    that the application requested by calling the function
1853  *    silc_client_request_authentication_method.
1854  *
1855  ***/
1856 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1857                                           SilcClientConnection conn,
1858                                           SilcAuthMethod auth_meth,
1859                                           void *context);
1860
1861 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1862  *
1863  * SYNOPSIS
1864  *
1865  *    void 
1866  *    silc_client_request_authentication_method(SilcClient client,
1867  *                                              SilcClientConnection conn,
1868  *                                              SilcConnectionAuthRequest 
1869  *                                                callback,
1870  *                                              void *context);
1871  *
1872  * DESCRIPTION
1873  *
1874  *    This function can be used to request the current authentication method
1875  *    from the server. This may be called when connecting to the server
1876  *    and the client library requests the authentication data from the
1877  *    application. If the application does not know the current authentication
1878  *    method it can request it from the server using this function.
1879  *    The `callback' with `context' will be called after the server has
1880  *    replied back with the current authentication method.
1881  *
1882  ***/
1883 void 
1884 silc_client_request_authentication_method(SilcClient client,
1885                                           SilcClientConnection conn,
1886                                           SilcConnectionAuthRequest callback,
1887                                           void *context);
1888
1889 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1890  *
1891  * NAME
1892  *
1893  *    typedef enum { ... } SilcClientMonitorStatus;
1894  *
1895  * DESCRIPTION
1896  *
1897  *    File transmission session status types.  These will indicate
1898  *    the status of the file transmission session.
1899  *
1900  * SOURCE
1901  */
1902 typedef enum {
1903   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
1904   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
1905   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
1906   SILC_CLIENT_FILE_MONITOR_GET,
1907   SILC_CLIENT_FILE_MONITOR_PUT,
1908   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
1909   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
1910 } SilcClientMonitorStatus;
1911 /***/
1912
1913 /****d* silcclient/SilcClientAPI/SilcClientFileError
1914  *
1915  * NAME
1916  *
1917  *    typedef enum { ... } SilcClientFileError;
1918  *
1919  * DESCRIPTION
1920  *
1921  *    File transmission error types.  These types are returned by
1922  *    some of the file transmission functions, and by the monitor
1923  *    callback to indicate error.
1924  *
1925  * SOURCE
1926  */
1927 typedef enum {
1928   SILC_CLIENT_FILE_OK,
1929   SILC_CLIENT_FILE_ERROR,
1930   SILC_CLIENT_FILE_UNKNOWN_SESSION,
1931   SILC_CLIENT_FILE_ALREADY_STARTED,
1932   SILC_CLIENT_FILE_NO_SUCH_FILE,
1933   SILC_CLIENT_FILE_PERMISSION_DENIED,
1934   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1935 } SilcClientFileError;
1936 /***/
1937
1938 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1939  *
1940  * SYNOPSIS
1941  *
1942  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
1943  *                                          SilcClientConnection conn,
1944  *                                          SilcClientMonitorStatus status,
1945  *                                          SilcClientFileError error,
1946  *                                          SilcUInt64 offset,
1947  *                                          SilcUInt64 filesize,
1948  *                                          SilcClientEntry client_entry,
1949  *                                          SilcUInt32 session_id,
1950  *                                          const char *filepath,
1951  *                                          void *context);
1952  *
1953  * DESCRIPTION
1954  *
1955  *    Monitor callback that is called during the file transmission to
1956  *    monitor the transmission process.  The `status' indicates the current
1957  *    monitoring process.  The `error' will indicate the error type
1958  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
1959  *    currently transmitted amount of total `filesize'.  The `client_entry'
1960  *    indicates the remote client, and the transmission session ID is the 
1961  *    `session_id'.  The filename being transmitted is indicated by the 
1962  *    `filepath'.
1963  *
1964  ***/
1965 typedef void (*SilcClientFileMonitor)(SilcClient client,
1966                                       SilcClientConnection conn,
1967                                       SilcClientMonitorStatus status,
1968                                       SilcClientFileError error,
1969                                       SilcUInt64 offset,
1970                                       SilcUInt64 filesize,
1971                                       SilcClientEntry client_entry,
1972                                       SilcUInt32 session_id,
1973                                       const char *filepath,
1974                                       void *context);
1975
1976 /****f* silcclient/SilcClientAPI/silc_client_file_send
1977  *
1978  * SYNOPSIS
1979  *
1980  *    SilcClientFileError 
1981  *    silc_client_file_send(SilcClient client,
1982  *                          SilcClientConnection conn,
1983  *                          SilcClientFileMonitor monitor,
1984  *                          void *monitor_context,
1985  *                          const char *local_ip,
1986  *                          SilcUInt32 local_port,
1987  *                          SilcClientEntry client_entry,
1988  *                          const char *filepath);
1989  *                          SilcUInt32 *session_id);
1990  *
1991  * DESCRIPTION
1992  *
1993  *    Sends a file indicated by the `filepath' to the remote client 
1994  *    indicated by the `client_entry'.  This will negotiate a secret key
1995  *    with the remote client before actually starting the transmission of
1996  *    the file.  The `monitor' callback will be called to monitor the
1997  *    transmission of the file.
1998  *
1999  *    This returns a file session ID for the file transmission to the
2000  *    `session_id' pointer..  It can be used to close the session (and
2001  *    abort the file transmission) by calling the silc_client_file_close
2002  *    function.  The session ID is also returned in the `monitor' callback. 
2003  *
2004  *    If the `local_ip' is provided then this will try to bind the 
2005  *    listener for key exchange protocol to that IP.  If `local_port' is
2006  *    non-zero that port is used.  If `local_ip' is NULL then this will
2007  *    automatically attempt to bind it to local IP address of the machine.
2008  *    If that fails then this does not bind to any address and port, and
2009  *    assume that the remote client will provide the listener for the
2010  *    key exchange protocol.
2011  *
2012  *    If error will occur during the file transfer process the error
2013  *    status will be returned in the monitor callback.  In this case
2014  *    the application must call silc_client_file_close to close the
2015  *    session.
2016  *
2017  ***/
2018 SilcClientFileError 
2019 silc_client_file_send(SilcClient client,
2020                       SilcClientConnection conn,
2021                       SilcClientFileMonitor monitor,
2022                       void *monitor_context,
2023                       const char *local_ip,
2024                       SilcUInt32 local_port,
2025                       SilcClientEntry client_entry,
2026                       const char *filepath,
2027                       SilcUInt32 *session_id);
2028
2029 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2030  *
2031  * SYNOPSIS
2032  *
2033  *    SilcClientFileError 
2034  *    silc_client_file_receive(SilcClient client,
2035  *                             SilcClientConnection conn,
2036  *                             SilcClientFileMonitor monitor,
2037  *                             void *monitor_context,
2038  *                             SilcUInt32 session_id);
2039  *
2040  * DESCRIPTION
2041  *
2042  *    Receives a file from a client indicated by the `client_entry'.  The
2043  *    `session_id' indicates the file transmission session and it has been
2044  *    received in the `ftp' client operation function.  This will actually
2045  *    perform the key agreement protocol with the remote client before
2046  *    actually starting the file transmission.  The `monitor' callback
2047  *    will be called to monitor the transmission.
2048  *
2049  *    If error will occur during the file transfer process the error
2050  *    status will be returned in the monitor callback.  In this case
2051  *    the application must call silc_client_file_close to close the
2052  *    session.
2053  *
2054  ***/
2055 SilcClientFileError 
2056 silc_client_file_receive(SilcClient client,
2057                          SilcClientConnection conn,
2058                          SilcClientFileMonitor monitor,
2059                          void *monitor_context,
2060                          SilcUInt32 session_id);
2061
2062 /****f* silcclient/SilcClientAPI/silc_client_file_close
2063  *
2064  * SYNOPSIS
2065  *
2066  *    SilcClientFileError silc_client_file_close(SilcClient client,
2067  *                                               SilcClientConnection conn,
2068  *                                               SilcUInt32 session_id);
2069  *
2070  * DESCRIPTION
2071  *
2072  *    Closes file transmission session indicated by the `session_id'.
2073  *    If file transmission is being conducted it will be aborted
2074  *    automatically. This function is also used to close the session
2075  *    after successful file transmission. This function can be used
2076  *    also to reject incoming file transmission request.
2077  *
2078  ***/
2079 SilcClientFileError silc_client_file_close(SilcClient client,
2080                                            SilcClientConnection conn,
2081                                            SilcUInt32 session_id);
2082
2083 #include "client.h"
2084 #include "command.h"
2085 #include "command_reply.h"
2086 #include "idlist.h"
2087 #include "protocol.h"
2088
2089 #ifdef __cplusplus
2090 }
2091 #endif
2092
2093 #endif /* SILCCLIENT_H */