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