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