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