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