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