Changed the silc_client_command_call to be simpler for
[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 nameand its arguments.  The variable argument list must
1427  *    be terminated with NULL.
1428  *
1429  *    Returns FALSE if the command is not known and TRUE after command.
1430  *    execution.  The "command" client operation is called when the
1431  *    command is executed to indicate whether the command executed
1432  *    successfully or not.
1433  *
1434  *    The "command_reply" client operation will be called when reply is
1435  *    received from the server to the command.  Application may also use
1436  *    the silc_client_command_pending to attach to the command reply.
1437  *    The command identifier for silc_client_command_pending function after
1438  *    this function call is conn->cmd_ident, which application may use.
1439  *
1440  * EXAMPLE
1441  *
1442  *    silc_client_command_call(client, NULL, "PING", "silc.silcnet.org", NULL);
1443  *    silc_client_command_call(client, "PING silc.silcnet.org");
1444  *
1445  ***/
1446 bool silc_client_command_call(SilcClient client,
1447                               SilcClientConnection conn,
1448                               const char *command_line, ...);
1449
1450 /****f* silcclient/SilcClientAPI/silc_client_command_send
1451  *
1452  * SYNOPSIS
1453  *
1454  *    void silc_client_command_send(SilcClient client, 
1455  *                                  SilcClientConnection conn,
1456  *                                  SilcCommand command, SilcUInt16 ident,
1457  *                                  SilcUInt32 argc, ...);
1458  *
1459  * DESCRIPTION
1460  *
1461  *    Generic function to send any command. The arguments must be sent already
1462  *    encoded into correct form and in correct order. If application wants
1463  *    to perform the commands by itself, it can do so and send the data
1464  *    directly to the server using this function.  If application is using
1465  *    the silc_client_command_call, this function is usually not used.
1466  *
1467  *    The variable arguments are a pair of { type, data, data_length },
1468  *    and the `argc' is the number of these pairs.
1469  *
1470  * EXAMPLE
1471  *
1472  *    silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1473  *                             1, nickname, strlen(nickname));
1474  *
1475  ***/
1476 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1477                               SilcCommand command, SilcUInt16 ident,
1478                               SilcUInt32 argc, ...);
1479
1480 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1481  *
1482  * SYNOPSIS
1483  *
1484  *    void silc_client_command_pending(SilcClientConnection conn,
1485  *                                     SilcCommand reply_cmd,
1486  *                                     SilcUInt16 ident,
1487  *                                     SilcCommandCb callback,
1488  *                                     void *context);
1489  *
1490  * DESCRIPTION
1491  *
1492  *    Add new pending command to be executed when reply to a command has been
1493  *    received.  The `reply_cmd' is the command that will call the `callback'
1494  *    with `context' when reply has been received.  If `ident' is non-zero
1495  *    the `callback' will be executed when received reply with command 
1496  *    identifier `ident'. 
1497  *
1498  *    Note that the application is notified about the received command
1499  *    reply through the `command_reply' client operation before calling
1500  *    the `callback` pending command callback.
1501  *
1502  ***/
1503 void silc_client_command_pending(SilcClientConnection conn,
1504                                  SilcCommand reply_cmd,
1505                                  SilcUInt16 ident,
1506                                  SilcCommandCb callback,
1507                                  void *context);
1508
1509
1510 /* Private Message key management (client_prvmsg.c) */
1511
1512 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1513  *
1514  * SYNOPSIS
1515  *
1516  *    int silc_client_add_private_message_key(SilcClient client,
1517  *                                            SilcClientConnection conn,
1518  *                                            SilcClientEntry client_entry,
1519  *                                            char *cipher,
1520  *                                            unsigned char *key,
1521  *                                            SilcUInt32 key_len,
1522  *                                            bool generate_key,
1523  *                                            bool responder);
1524  *
1525  * DESCRIPTION
1526  *
1527  *    Adds private message key to the client library. The key will be used to
1528  *    encrypt all private message between the client and the remote client
1529  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1530  *    value `generate_key' is TRUE the library will generate random key.
1531  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1532  *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
1533  *    requirements of the SILC protocol are met. The API, however, allows
1534  *    to allocate any cipher.
1535  *
1536  *    If `responder' is TRUE then the sending and receiving keys will be
1537  *    set according the client being the receiver of the private key.  If
1538  *    FALSE the client is being the sender (or negotiator) of the private
1539  *    key.
1540  *
1541  *    It is not necessary to set key for normal private message usage. If the
1542  *    key is not set then the private messages are encrypted using normal
1543  *    session keys. Setting the private key, however, increases the security. 
1544  *
1545  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1546  *    otherwise. 
1547  *
1548  ***/
1549 int silc_client_add_private_message_key(SilcClient client,
1550                                         SilcClientConnection conn,
1551                                         SilcClientEntry client_entry,
1552                                         char *cipher,
1553                                         unsigned char *key,
1554                                         SilcUInt32 key_len,
1555                                         bool generate_key,
1556                                         bool responder);
1557
1558 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1559  *
1560  * SYNOPSIS
1561  *
1562  *    int silc_client_add_private_message_key_ske(SilcClient client,
1563  *                                                SilcClientConnection conn,
1564  *                                                SilcClientEntry client_entry,
1565  *                                                char *cipher,
1566  *                                                SilcSKEKeyMaterial *key);
1567  *
1568  * DESCRIPTION
1569  *
1570  *    Same as silc_client_add_private_message_key but takes the key material
1571  *    from the SKE key material structure. This structure is received if
1572  *    the application uses the silc_client_send_key_agreement to negotiate
1573  *    the key material. The `cipher' SHOULD be provided as it is negotiated
1574  *    also in the SKE protocol. 
1575  *
1576  ***/
1577 int silc_client_add_private_message_key_ske(SilcClient client,
1578                                             SilcClientConnection conn,
1579                                             SilcClientEntry client_entry,
1580                                             char *cipher,
1581                                             SilcSKEKeyMaterial *key,
1582                                             bool responder);
1583
1584 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1585  *
1586  * SYNOPSIS
1587  *
1588  *    int silc_client_del_private_message_key(SilcClient client,
1589  *                                            SilcClientConnection conn,
1590  *                                            SilcClientEntry client_entry);
1591  *
1592  * DESCRIPTION
1593  *
1594  *    Removes the private message from the library. The key won't be used
1595  *    after this to protect the private messages with the remote `client_entry'
1596  *    client. Returns FALSE on error, TRUE otherwise. 
1597  *
1598  ***/
1599 int silc_client_del_private_message_key(SilcClient client,
1600                                         SilcClientConnection conn,
1601                                         SilcClientEntry client_entry);
1602
1603 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1604  *
1605  * SYNOPSIS
1606  *
1607  *    SilcPrivateMessageKeys
1608  *    silc_client_list_private_message_keys(SilcClient client,
1609  *                                          SilcClientConnection conn,
1610  *                                          SilcUInt32 *key_count);
1611  * 
1612  * DESCRIPTION
1613  *
1614  *    Returns array of set private message keys associated to the connection
1615  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1616  *    count to the `key_count' argument. The array must be freed by the caller
1617  *    by calling the silc_client_free_private_message_keys function. Note: 
1618  *    the keys returned in the array is in raw format. It might not be desired
1619  *    to show the keys as is. The application might choose not to show the keys
1620  *    at all or to show the fingerprints of the keys. 
1621  *
1622  ***/
1623 SilcPrivateMessageKeys
1624 silc_client_list_private_message_keys(SilcClient client,
1625                                       SilcClientConnection conn,
1626                                       SilcUInt32 *key_count);
1627
1628 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1629  *
1630  * SYNOPSIS
1631  *
1632  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1633  *                                               SilcUInt32 key_count);
1634  * 
1635  * DESCRIPTION
1636  *
1637  *    Frees the SilcPrivateMessageKeys array returned by the function
1638  *    silc_client_list_private_message_keys. 
1639  *
1640  ***/
1641 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1642                                            SilcUInt32 key_count);
1643
1644
1645 /* Channel private key management (client_channel.c, 
1646    SilcChannelPrivateKey is defined in idlist.h) */
1647
1648 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1649  *
1650  * SYNOPSIS
1651  *
1652  *    int silc_client_add_channel_private_key(SilcClient client,
1653  *                                            SilcClientConnection conn,
1654  *                                            SilcChannelEntry channel,
1655  *                                            const char *name,
1656  *                                            char *cipher,
1657  *                                            char *hmac,
1658  *                                            unsigned char *key,
1659  *                                            SilcUInt32 key_len);
1660  * 
1661  * DESCRIPTION
1662  *
1663  *    Adds private key for channel. This may be set only if the channel's mode
1664  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1665  *    mode is not set. When channel has private key then the messages are
1666  *    encrypted using that key. All clients on the channel must also know the
1667  *    key in order to decrypt the messages. However, it is possible to have
1668  *    several private keys per one channel. In this case only some of the
1669  *    clients on the channel may know the one key and only some the other key.
1670  *    The `name' can be application given name for the key.
1671  *
1672  *    The private key for channel is optional. If it is not set then the
1673  *    channel messages are encrypted using the channel key generated by the
1674  *    server. However, setting the private key (or keys) for the channel 
1675  *    significantly adds security. If more than one key is set the library
1676  *    will automatically try all keys at the message decryption phase. Note:
1677  *    setting many keys slows down the decryption phase as all keys has to
1678  *    be tried in order to find the correct decryption key. However, setting
1679  *    a few keys does not have big impact to the decryption performace. 
1680  *
1681  * NOTES
1682  *
1683  *    NOTE: This is entirely local setting. The key set using this function
1684  *    is not sent to the network at any phase.
1685  *
1686  *    NOTE: If the key material was originated by the SKE protocol (using
1687  *    silc_client_send_key_agreement) then the `key' MUST be the
1688  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1689  *    currently it is not expected that the SKE key material would be used
1690  *    as channel private key. However, this API allows it. 
1691  *
1692  ***/
1693 int silc_client_add_channel_private_key(SilcClient client,
1694                                         SilcClientConnection conn,
1695                                         SilcChannelEntry channel,
1696                                         const char *name,
1697                                         char *cipher,
1698                                         char *hmac,
1699                                         unsigned char *key,
1700                                         SilcUInt32 key_len);
1701
1702 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1703  *
1704  * SYNOPSIS
1705  *
1706  *    int silc_client_del_channel_private_keys(SilcClient client,
1707  *                                             SilcClientConnection conn,
1708  *                                             SilcChannelEntry channel);
1709  * 
1710  * DESCRIPTION
1711  *
1712  *    Removes all private keys from the `channel'. The old channel key is used
1713  *    after calling this to protect the channel messages. Returns FALSE on
1714  *    on error, TRUE otherwise. 
1715  *
1716  ***/
1717 int silc_client_del_channel_private_keys(SilcClient client,
1718                                          SilcClientConnection conn,
1719                                          SilcChannelEntry channel);
1720
1721 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1722  *
1723  * SYNOPSIS
1724  *
1725  *    int silc_client_del_channel_private_key(SilcClient client,
1726  *                                            SilcClientConnection conn,
1727  *                                            SilcChannelEntry channel,
1728  *                                            SilcChannelPrivateKey key);
1729  * 
1730  * DESCRIPTION
1731  *
1732  *    Removes and frees private key `key' from the channel `channel'. 
1733  *    The `key' is retrieved by calling the function 
1734  *    silc_client_list_channel_private_keys. The key is not used after
1735  *    this. If the key was last private key then the old channel key is
1736  *    used hereafter to protect the channel messages. This returns FALSE
1737  *    on error, TRUE otherwise. 
1738  *
1739  ***/
1740 int silc_client_del_channel_private_key(SilcClient client,
1741                                         SilcClientConnection conn,
1742                                         SilcChannelEntry channel,
1743                                         SilcChannelPrivateKey key);
1744
1745 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1746  *
1747  * SYNOPSIS
1748  *
1749  *    SilcChannelPrivateKey *
1750  *    silc_client_list_channel_private_keys(SilcClient client,
1751  *                                          SilcClientConnection conn,
1752  *                                          SilcChannelEntry channel,
1753  *                                          SilcUInt32 *key_count);
1754  *
1755  * DESCRIPTION
1756  *
1757  *    Returns array (pointers) of private keys associated to the `channel'.
1758  *    The caller must free the array by calling the function
1759  *    silc_client_free_channel_private_keys. The pointers in the array may be
1760  *    used to delete the specific key by giving the pointer as argument to the
1761  *    function silc_client_del_channel_private_key. 
1762  *
1763  ***/
1764 SilcChannelPrivateKey *
1765 silc_client_list_channel_private_keys(SilcClient client,
1766                                       SilcClientConnection conn,
1767                                       SilcChannelEntry channel,
1768                                       SilcUInt32 *key_count);
1769
1770 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1771  *
1772  * SYNOPSIS
1773  *
1774  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1775  *                                               SilcUInt32 key_count);
1776  *
1777  * DESCRIPTION
1778  *
1779  *    Frees the SilcChannelPrivateKey array.
1780  *
1781  ***/
1782 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1783                                            SilcUInt32 key_count);
1784
1785 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1786  *
1787  * SYNOPSIS
1788  *
1789  *    void silc_client_current_channel_private_key(SilcClient client,
1790  *                                                 SilcClientConnection conn,
1791  *                                                 SilcChannelEntry channel,
1792  *                                                 SilcChannelPrivateKey key);
1793  *
1794  * DESCRIPTION
1795  *
1796  *    Sets the `key' to be used as current channel private key on the
1797  *    `channel'.  Packet sent after calling this function will be secured
1798  *    with `key'.
1799  *
1800  ***/
1801 void silc_client_current_channel_private_key(SilcClient client,
1802                                              SilcClientConnection conn,
1803                                              SilcChannelEntry channel,
1804                                              SilcChannelPrivateKey key);
1805
1806
1807 /* Key Agreement routines (client_keyagr.c) */
1808
1809 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1810  *
1811  * SYNOPSIS
1812  *
1813  *    void silc_client_send_key_agreement(SilcClient client,
1814  *                                        SilcClientConnection conn,
1815  *                                        SilcClientEntry client_entry,
1816  *                                        char *hostname,
1817  *                                        int port,
1818  *                                        SilcUInt32 timeout_secs,
1819  *                                        SilcKeyAgreementCallback completion,
1820  *                                        void *context);
1821  *
1822  * DESCRIPTION
1823  *
1824  *    Sends key agreement request to the remote client indicated by the
1825  *    `client_entry'. If the caller provides the `hostname' and the `port'
1826  *    arguments then the library will bind the client to that hostname and
1827  *    that port for the key agreement protocol. It also sends the `hostname'
1828  *    and the `port' in the key agreement packet to the remote client. This
1829  *    would indicate that the remote client may initiate the key agreement
1830  *    protocol to the `hostname' on the `port'.  If port is zero then the
1831  *    bound port is undefined (the operating system defines it).
1832  *
1833  *    If the `hostname' and `port' is not provided then empty key agreement
1834  *    packet is sent to the remote client. The remote client may reply with
1835  *    the same packet including its hostname and port. If the library receives
1836  *    the reply from the remote client the `key_agreement' client operation
1837  *    callback will be called to verify whether the user wants to perform the
1838  *    key agreement or not. 
1839  *
1840  * NOTES
1841  *
1842  *    NOTE: If the application provided the `hostname' and the `port' and the 
1843  *    remote side initiates the key agreement protocol it is not verified
1844  *    from the user anymore whether the protocol should be executed or not.
1845  *    By setting the `hostname' and `port' the user gives permission to
1846  *    perform the protocol (we are responder in this case).
1847  *
1848  *    NOTE: If the remote side decides not to initiate the key agreement
1849  *    or decides not to reply with the key agreement packet then we cannot
1850  *    perform the key agreement at all. If the key agreement protocol is
1851  *    performed the `completion' callback with the `context' will be called.
1852  *    If remote side decides to ignore the request the `completion' will be
1853  *    called after the specified timeout, `timeout_secs'. 
1854  *
1855  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
1856  *    will not be called at all since this does nothing more than sending
1857  *    a packet to the remote host.
1858  *
1859  *    NOTE: There can be only one active key agreement for one client entry.
1860  *    Before setting new one, the old one must be finished (it is finished
1861  *    after calling the completion callback) or the function 
1862  *    silc_client_abort_key_agreement must be called. 
1863  *
1864  ***/
1865 void silc_client_send_key_agreement(SilcClient client,
1866                                     SilcClientConnection conn,
1867                                     SilcClientEntry client_entry,
1868                                     const char *hostname,
1869                                     const char *bindhost,
1870                                     int port,
1871                                     SilcUInt32 timeout_secs,
1872                                     SilcKeyAgreementCallback completion,
1873                                     void *context);
1874
1875 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1876  *
1877  * SYNOPSIS
1878  *
1879  *    void 
1880  *    silc_client_perform_key_agreement(SilcClient client,
1881  *                                      SilcClientConnection conn,
1882  *                                      SilcClientEntry client_entry,
1883  *                                      char *hostname,
1884  *                                      int port,
1885  *                                      SilcKeyAgreementCallback completion,
1886  *                                      void *context);
1887  *
1888  * DESCRIPTION
1889  *
1890  *    Performs the actual key agreement protocol. Application may use this
1891  *    to initiate the key agreement protocol. This can be called for example
1892  *    after the application has received the `key_agreement' client operation,
1893  *    and did not return TRUE from it.
1894  *
1895  *    The `hostname' is the remote hostname (or IP address) and the `port'
1896  *    is the remote port. The `completion' callback with the `context' will
1897  *    be called after the key agreement protocol.
1898  *
1899  * NOTES
1900  * 
1901  *    NOTE: If the application returns TRUE in the `key_agreement' client
1902  *    operation the library will automatically start the key agreement. In this
1903  *    case the application must not call this function. However, application
1904  *    may choose to just ignore the `key_agreement' client operation (and
1905  *    merely just print information about it on the screen) and call this
1906  *    function when the user whishes to do so (by, for example, giving some
1907  *    specific command). Thus, the API provides both, automatic and manual
1908  *    initiation of the key agreement. Calling this function is the manual
1909  *    initiation and returning TRUE in the `key_agreement' client operation
1910  *    is the automatic initiation. 
1911  *
1912  ***/
1913 void silc_client_perform_key_agreement(SilcClient client,
1914                                        SilcClientConnection conn,
1915                                        SilcClientEntry client_entry,
1916                                        char *hostname,
1917                                        int port,
1918                                        SilcKeyAgreementCallback completion,
1919                                        void *context);
1920
1921 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1922  *
1923  * SYNOPSIS
1924  *
1925  *    void
1926  *    silc_client_perform_key_agreement_fd(SilcClient client,
1927  *                                         SilcClientConnection conn,
1928  *                                         SilcClientEntry client_entry,
1929  *                                         int sock,
1930  *                                         char *hostname,
1931  *                                         SilcKeyAgreementCallback completion,
1932  *                                         void *context);
1933  *
1934  * DESCRIPTION
1935  *
1936  *    Same as above but application has created already the connection to 
1937  *    the remote host. The `sock' is the socket to the remote connection. 
1938  *    Application can use this function if it does not want the client library
1939  *    to create the connection. 
1940  *
1941  ***/
1942 void silc_client_perform_key_agreement_fd(SilcClient client,
1943                                           SilcClientConnection conn,
1944                                           SilcClientEntry client_entry,
1945                                           int sock,
1946                                           char *hostname,
1947                                           SilcKeyAgreementCallback completion,
1948                                           void *context);
1949
1950 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1951  *
1952  * SYNOPSIS
1953  *
1954  *    void silc_client_abort_key_agreement(SilcClient client,
1955  *                                         SilcClientConnection conn,
1956  *                                         SilcClientEntry client_entry);
1957  *
1958  * DESCRIPTION
1959  *
1960  *    This function can be called to unbind the hostname and the port for
1961  *    the key agreement protocol. However, this function has effect only 
1962  *    before the key agreement protocol has been performed. After it has
1963  *    been performed the library will automatically unbind the port. The 
1964  *    `client_entry' is the client to which we sent the key agreement 
1965  *    request.  The key agreement completion callback will be called
1966  *    with SILC_KEY_AGREEMENT_ABORTED status.
1967  *
1968  ***/
1969 void silc_client_abort_key_agreement(SilcClient client,
1970                                      SilcClientConnection conn,
1971                                      SilcClientEntry client_entry);
1972
1973
1974 /* Misc functions */
1975
1976 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1977  *
1978  * SYNOPSIS
1979  *
1980  *    void silc_client_set_away_message(SilcClient client,
1981  *                                      SilcClientConnection conn,
1982  *                                      char *message);
1983  *
1984  * DESCRIPTION
1985  *
1986  *    Sets away `message'.  The away message may be set when the client's
1987  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1988  *    to anyone who sends private message.  The `message' will be sent
1989  *    automatically back to the the client who send private message.  If
1990  *    away message is already set this replaces the old message with the
1991  *    new one.  If `message' is NULL the old away message is removed. 
1992  *    The sender may freely free the memory of the `message'. 
1993  *
1994  ***/
1995 void silc_client_set_away_message(SilcClient client,
1996                                   SilcClientConnection conn,
1997                                   char *message);
1998
1999 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2000  *
2001  * SYNOPSIS
2002  *
2003  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2004  *                                              SilcClientConnection conn,
2005  *                                              SilcAuthMethod auth_meth,
2006  *                                              void *context);
2007  *
2008  * DESCRIPTION
2009  *
2010  *    Connection authentication method request callback. This is called
2011  *    by the client library after it has received the authentication method
2012  *    that the application requested by calling the function
2013  *    silc_client_request_authentication_method.
2014  *
2015  ***/
2016 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2017                                           SilcClientConnection conn,
2018                                           SilcAuthMethod auth_meth,
2019                                           void *context);
2020
2021 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2022  *
2023  * SYNOPSIS
2024  *
2025  *    void 
2026  *    silc_client_request_authentication_method(SilcClient client,
2027  *                                              SilcClientConnection conn,
2028  *                                              SilcConnectionAuthRequest 
2029  *                                                callback,
2030  *                                              void *context);
2031  *
2032  * DESCRIPTION
2033  *
2034  *    This function can be used to request the current authentication method
2035  *    from the server. This may be called when connecting to the server
2036  *    and the client library requests the authentication data from the
2037  *    application. If the application does not know the current authentication
2038  *    method it can request it from the server using this function.
2039  *    The `callback' with `context' will be called after the server has
2040  *    replied back with the current authentication method.
2041  *
2042  ***/
2043 void 
2044 silc_client_request_authentication_method(SilcClient client,
2045                                           SilcClientConnection conn,
2046                                           SilcConnectionAuthRequest callback,
2047                                           void *context);
2048
2049 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2050  *
2051  * NAME
2052  *
2053  *    typedef enum { ... } SilcClientMonitorStatus;
2054  *
2055  * DESCRIPTION
2056  *
2057  *    File transmission session status types.  These will indicate
2058  *    the status of the file transmission session.
2059  *
2060  * SOURCE
2061  */
2062 typedef enum {
2063   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
2064   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
2065   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
2066   SILC_CLIENT_FILE_MONITOR_GET,
2067   SILC_CLIENT_FILE_MONITOR_PUT,
2068   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
2069   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
2070 } SilcClientMonitorStatus;
2071 /***/
2072
2073 /****d* silcclient/SilcClientAPI/SilcClientFileError
2074  *
2075  * NAME
2076  *
2077  *    typedef enum { ... } SilcClientFileError;
2078  *
2079  * DESCRIPTION
2080  *
2081  *    File transmission error types.  These types are returned by
2082  *    some of the file transmission functions, and by the monitor
2083  *    callback to indicate error.
2084  *
2085  * SOURCE
2086  */
2087 typedef enum {
2088   SILC_CLIENT_FILE_OK,
2089   SILC_CLIENT_FILE_ERROR,
2090   SILC_CLIENT_FILE_UNKNOWN_SESSION,
2091   SILC_CLIENT_FILE_ALREADY_STARTED,
2092   SILC_CLIENT_FILE_NO_SUCH_FILE,
2093   SILC_CLIENT_FILE_PERMISSION_DENIED,
2094   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2095 } SilcClientFileError;
2096 /***/
2097
2098 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2099  *
2100  * SYNOPSIS
2101  *
2102  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
2103  *                                          SilcClientConnection conn,
2104  *                                          SilcClientMonitorStatus status,
2105  *                                          SilcClientFileError error,
2106  *                                          SilcUInt64 offset,
2107  *                                          SilcUInt64 filesize,
2108  *                                          SilcClientEntry client_entry,
2109  *                                          SilcUInt32 session_id,
2110  *                                          const char *filepath,
2111  *                                          void *context);
2112  *
2113  * DESCRIPTION
2114  *
2115  *    Monitor callback that is called during the file transmission to
2116  *    monitor the transmission process.  The `status' indicates the current
2117  *    monitoring process.  The `error' will indicate the error type
2118  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
2119  *    currently transmitted amount of total `filesize'.  The `client_entry'
2120  *    indicates the remote client, and the transmission session ID is the 
2121  *    `session_id'.  The filename being transmitted is indicated by the 
2122  *    `filepath'.
2123  *
2124  ***/
2125 typedef void (*SilcClientFileMonitor)(SilcClient client,
2126                                       SilcClientConnection conn,
2127                                       SilcClientMonitorStatus status,
2128                                       SilcClientFileError error,
2129                                       SilcUInt64 offset,
2130                                       SilcUInt64 filesize,
2131                                       SilcClientEntry client_entry,
2132                                       SilcUInt32 session_id,
2133                                       const char *filepath,
2134                                       void *context);
2135
2136 /****f* silcclient/SilcClientAPI/silc_client_file_send
2137  *
2138  * SYNOPSIS
2139  *
2140  *    SilcClientFileError 
2141  *    silc_client_file_send(SilcClient client,
2142  *                          SilcClientConnection conn,
2143  *                          SilcClientFileMonitor monitor,
2144  *                          void *monitor_context,
2145  *                          const char *local_ip,
2146  *                          SilcUInt32 local_port,
2147  *                          SilcClientEntry client_entry,
2148  *                          const char *filepath);
2149  *                          SilcUInt32 *session_id);
2150  *
2151  * DESCRIPTION
2152  *
2153  *    Sends a file indicated by the `filepath' to the remote client 
2154  *    indicated by the `client_entry'.  This will negotiate a secret key
2155  *    with the remote client before actually starting the transmission of
2156  *    the file.  The `monitor' callback will be called to monitor the
2157  *    transmission of the file.
2158  *
2159  *    This returns a file session ID for the file transmission to the
2160  *    `session_id' pointer..  It can be used to close the session (and
2161  *    abort the file transmission) by calling the silc_client_file_close
2162  *    function.  The session ID is also returned in the `monitor' callback. 
2163  *
2164  *    If the `local_ip' is provided then this will try to bind the 
2165  *    listener for key exchange protocol to that IP.  If `local_port' is
2166  *    non-zero that port is used.  If `local_ip' is NULL then this will
2167  *    automatically attempt to bind it to local IP address of the machine.
2168  *    If that fails then this does not bind to any address and port, and
2169  *    assume that the remote client will provide the listener for the
2170  *    key exchange protocol.
2171  *
2172  *    If error will occur during the file transfer process the error
2173  *    status will be returned in the monitor callback.  In this case
2174  *    the application must call silc_client_file_close to close the
2175  *    session.
2176  *
2177  ***/
2178 SilcClientFileError 
2179 silc_client_file_send(SilcClient client,
2180                       SilcClientConnection conn,
2181                       SilcClientFileMonitor monitor,
2182                       void *monitor_context,
2183                       const char *local_ip,
2184                       SilcUInt32 local_port,
2185                       SilcClientEntry client_entry,
2186                       const char *filepath,
2187                       SilcUInt32 *session_id);
2188
2189 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2190  *
2191  * SYNOPSIS
2192  *
2193  *    SilcClientFileError 
2194  *    silc_client_file_receive(SilcClient client,
2195  *                             SilcClientConnection conn,
2196  *                             SilcClientFileMonitor monitor,
2197  *                             void *monitor_context,
2198  *                             const char *path,
2199  *                             SilcUInt32 session_id);
2200  *
2201  * DESCRIPTION
2202  *
2203  *    Receives a file from a client indicated by the `client_entry'.  The
2204  *    `session_id' indicates the file transmission session and it has been
2205  *    received in the `ftp' client operation function.  This will actually
2206  *    perform the key agreement protocol with the remote client before
2207  *    actually starting the file transmission.  The `monitor' callback
2208  *    will be called to monitor the transmission.  If `path' is non NULL
2209  *    the file will be saved into that directory.  If NULL the file is
2210  *    saved in the current working directory.
2211  *
2212  *    If error will occur during the file transfer process the error
2213  *    status will be returned in the monitor callback.  In this case
2214  *    the application must call silc_client_file_close to close the
2215  *    session.
2216  *
2217  ***/
2218 SilcClientFileError 
2219 silc_client_file_receive(SilcClient client,
2220                          SilcClientConnection conn,
2221                          SilcClientFileMonitor monitor,
2222                          void *monitor_context,
2223                          const char *path,
2224                          SilcUInt32 session_id);
2225
2226 /****f* silcclient/SilcClientAPI/silc_client_file_close
2227  *
2228  * SYNOPSIS
2229  *
2230  *    SilcClientFileError silc_client_file_close(SilcClient client,
2231  *                                               SilcClientConnection conn,
2232  *                                               SilcUInt32 session_id);
2233  *
2234  * DESCRIPTION
2235  *
2236  *    Closes file transmission session indicated by the `session_id'.
2237  *    If file transmission is being conducted it will be aborted
2238  *    automatically. This function is also used to close the session
2239  *    after successful file transmission. This function can be used
2240  *    also to reject incoming file transmission request.
2241  *
2242  ***/
2243 SilcClientFileError silc_client_file_close(SilcClient client,
2244                                            SilcClientConnection conn,
2245                                            SilcUInt32 session_id);
2246
2247 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2248  *
2249  * SYNOPSIS
2250  *
2251  *    SilcAttributePayload
2252  *    silc_client_attribute_add(SilcClient client,
2253  *                              SilcClientConnection conn,
2254  *                              SilcAttribute attribute,
2255  *                              void *object,
2256  *                              SilcUInt32 object_size);
2257  *
2258  * DESCRIPTION
2259  *
2260  *    Add new Requsted Attribute for WHOIS command to the client library.
2261  *    The `attribute' object indicated by `object' is added and allocated
2262  *    SilcAttributePayload is returned.  The `object' must be of correct
2263  *    type and of correct size.  See the SilcAttribute for object types
2264  *    for different attributes.  You may also get all added attributes
2265  *    from the client with silc_client_attributes_get function.
2266  *
2267  *    Requested Attributes are different personal information about the
2268  *    user, status information and other information which other users
2269  *    may query with WHOIS command.  Application may set these so that
2270  *    if someone sends WHOIS query these attributes will be replied back
2271  *    to the sender.  The library always puts the public key to the
2272  *    Requested Attributes, but if application wishes to add additional
2273  *    public keys (or certificates) it can be done with this interface.
2274  *    Library also always computes digital signature of the attributes
2275  *    automatically, so application does not need to do that.
2276  *
2277  ***/
2278 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2279                                                SilcClientConnection conn,
2280                                                SilcAttribute attribute,
2281                                                void *object,
2282                                                SilcUInt32 object_size);
2283
2284 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2285  *
2286  * SYNOPSIS
2287  *
2288  *    bool silc_client_attribute_del(SilcClient client,
2289  *                                   SilcClientConnection conn,
2290  *                                   SilcAttribute attribute,
2291  *                                   SilcAttributePayload attr);
2292  *
2293  * DESCRIPTION
2294  *
2295  *    Delete a Requested Attribute from the client.  If the `attribute'
2296  *    is non-zero then all attributes of that type are deleted and the
2297  *    `attr' is ignored.  If `attr' is non-NULL then that specific
2298  *    attribute is deleted and `attribute' is ignored.
2299  *    
2300  *    You may get all added attributes with the function
2301  *    silc_client_attributes_get and to get the SilcAttributePayload.
2302  *    This function Returns TRUE if the attribute was found and deleted.
2303  *
2304  ***/
2305 bool silc_client_attribute_del(SilcClient client,
2306                                SilcClientConnection conn,
2307                                SilcAttribute attribute,
2308                                SilcAttributePayload attr);
2309
2310 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2311  *
2312  * SYNOPSIS
2313  *
2314  *    const SilcHashTable
2315  *    silc_client_attributes_get(SilcClient client,
2316  *                               SilcClientConnection conn);
2317  *
2318  * DESCRIPTION
2319  *
2320  *    Returns pointer to the SilcHashTable which includes all the added
2321  *    Requested Attributes.  The caller must not free the hash table.
2322  *    The caller may use SilcHashTableList and silc_hash_table_list to
2323  *    traverse the table.  Each entry in the hash table is one added
2324  *    SilcAttributePayload.  It is possible to delete a attribute
2325  *    payload while traversing the table.
2326  *
2327  ***/
2328 const SilcHashTable silc_client_attributes_get(SilcClient client,
2329                                                SilcClientConnection conn);
2330
2331 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2332  *
2333  * SYNOPSIS
2334  *
2335  *    SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2336  *
2337  * DESCRIPTION
2338  *
2339  *    Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2340  *    then all attributes are requested.  Alternatively, `attribute' and
2341  *    all variable arguments can each be requested attribute.  In this case
2342  *    the last must be set to zero (0) to complete the variable list of
2343  *    requested attributes.  See SilcAttribute for all attributes.
2344  *    You can give the returned buffer as argument to for example
2345  *    silc_client_get_client_by_id_resolve function.
2346  *
2347  ***/
2348 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2349
2350 /* Low level packet sending functions */
2351
2352 /****f* silcclient/SilcClientAPI/silc_client_packet_send
2353  *
2354  * SYNOPSIS
2355  *
2356  *    void silc_client_packet_send(SilcClient client, 
2357  *                                 SilcSocketConnection sock,
2358  *                                 SilcPacketType type, 
2359  *                                 void *dst_id,
2360  *                                 SilcIdType dst_id_type,
2361  *                                 SilcCipher cipher,
2362  *                                 SilcHmac hmac,
2363  *                                 unsigned char *data, 
2364  *                                 SilcUInt32 data_len, 
2365  *                                 bool force_send);
2366  *
2367  * DESCRIPTION
2368  *
2369  *    Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2370  *    then all attributes are requested.  Alternatively, `attribute' and
2371  *    all variable arguments can each be requested attribute.  In this case
2372  *    the last must be set to zero (0) to complete the variable list of
2373  *    requested attributes.  See SilcAttribute for all attributes.
2374  *    You can give the returned buffer as argument to for example
2375  *    silc_client_get_client_by_id_resolve function.
2376  *
2377  ***/
2378 void silc_client_packet_send(SilcClient client, 
2379                              SilcSocketConnection sock,
2380                              SilcPacketType type, 
2381                              void *dst_id,
2382                              SilcIdType dst_id_type,
2383                              SilcCipher cipher,
2384                              SilcHmac hmac,
2385                              unsigned char *data, 
2386                              SilcUInt32 data_len, 
2387                              bool force_send);
2388
2389 #include "command.h"
2390 #include "command_reply.h"
2391 #include "idlist.h"
2392 #include "protocol.h"
2393
2394 #ifdef __cplusplus
2395 }
2396 #endif
2397
2398 #endif /* SILCCLIENT_H */