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