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