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