typo fixes.
[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 } SilcClientParams;
565 /***/
566
567
568 /* Initialization functions (client.c) */
569
570 /****f* silcclient/SilcClientAPI/silc_client_alloc
571  *
572  * SYNOPSIS
573  *
574  *    SilcClient silc_client_alloc(SilcClientOperations *ops, 
575  *                                 SilcClientParams *params,
576  *                                 void *application,
577  *                                 const char *silc_version);
578  *
579  * DESCRIPTION
580  *
581  *    Allocates new client object. This has to be done before client may
582  *    work. After calling this one must call silc_client_init to initialize
583  *    the client. The `application' is application specific user data pointer
584  *    and caller must free it. The `silc_version' is the application version
585  *    that will be used to compare against remote host's (usually a server)
586  *    version string.  The `application' context is accessible by the
587  *    application by client->application, client being SilcClient.
588  *
589  ***/
590 SilcClient silc_client_alloc(SilcClientOperations *ops, 
591                              SilcClientParams *params,
592                              void *application,
593                              const char *silc_version);
594
595 /****f* silcclient/SilcClientAPI/silc_client_free
596  *
597  * SYNOPSIS
598  *
599  *    void silc_client_free(SilcClient client);
600  *
601  * DESCRIPTION
602  *
603  *    Frees client object and its internals.  The execution of the client
604  *    should be stopped with silc_client_stop function before calling
605  *    this function.
606  *
607  ***/
608 void silc_client_free(SilcClient client);
609
610 /****f* silcclient/SilcClientAPI/silc_client_init
611  *
612  * SYNOPSIS
613  *
614  *    int silc_client_init(SilcClient client);
615  *
616  * DESCRIPTION
617  *
618  *    Initializes the client. This makes all the necessary steps to make
619  *    the client ready to be run. One must call silc_client_run to run the
620  *    client. Returns FALSE if error occurred, TRUE otherwise.
621  *
622  ***/
623 int silc_client_init(SilcClient client);
624
625 /****f* silcclient/SilcClientAPI/silc_client_run
626  *
627  * SYNOPSIS
628  *
629  *    void silc_client_run(SilcClient client);
630  *
631  * DESCRIPTION
632  *
633  *    Runs the client. This starts the scheduler from the utility library.
634  *    When this functions returns the execution of the appliation is over.
635  *
636  ***/
637 void silc_client_run(SilcClient client);
638
639 /****f* silcclient/SilcClientAPI/silc_client_run_one
640  *
641  * SYNOPSIS
642  *
643  *    void silc_client_run_one(SilcClient client);
644  *
645  * DESCRIPTION
646  *
647  *    Runs the client and returns immeadiately. This function is used when
648  *    the SILC Client object indicated by the `client' is run under some
649  *    other scheduler, or event loop or main loop.  On GUI applications,
650  *    for example this may be desired to used to run the client under the
651  *    GUI application's main loop.  Typically the GUI application would
652  *    register an idle task that calls this function multiple times in
653  *    a second to quickly process the SILC specific data.
654  *
655  ***/
656 void silc_client_run_one(SilcClient client);
657
658 /****f* silcclient/SilcClientAPI/silc_client_stop
659  *
660  * SYNOPSIS
661  *
662  *    void silc_client_stop(SilcClient client);
663  *
664  * DESCRIPTION
665  *
666  *    Stops the client. This is called to stop the client and thus to stop
667  *    the program.  The client context must be freed with the silc_client_free
668  *    function.
669  *
670  ***/
671 void silc_client_stop(SilcClient client);
672
673
674 /* Connecting functions (client.c) */
675
676 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
677  *
678  * NAME
679  *
680  *    typedef struct { ... } SilcClientConnectionParams;
681  *
682  * DESCRIPTION
683  *
684  *    Client connection parameters.  This can be filled by the application
685  *    and given as argument to silc_client_connect_to_server or to
686  *    silc_client_add_connection.
687  *
688  * SOURCE
689  */
690 typedef struct {
691   /* The SILC session detachment data that was returned by `detach' client
692      operation when the application detached from the network.  Application
693      is responsible of saving the data and giving it as argument here
694      for resuming the session in the SILC network.
695
696      If this is provided here the client library will attempt to resume
697      the session in the network.  After the connection is created
698      successfully, the application is responsible of setting the user
699      interface for user into the same state it was before detaching (showing
700      same channels, channel modes, etc).  It can do this by fetching the
701      information (like joined channels) from the client library. */
702   unsigned char *detach_data;
703   SilcUInt32 detach_data_len;
704
705 } SilcClientConnectionParams;
706 /***/
707
708 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
709  *
710  * SYNOPSIS
711  *
712  *    int silc_client_connect_to_server(SilcClient client, 
713  *                                      SilcClientConnectionParams *params,
714  *                                      int port, char *host, void *context);
715  *
716  * DESCRIPTION
717  *
718  *    Connects to remote server. This is the main routine used to connect
719  *    to SILC server. Returns -1 on error and the created socket otherwise. 
720  *    The `context' is user context that is saved into the SilcClientConnection
721  *    that is created after the connection is created. Note that application
722  *    may handle the connecting process outside the library. If this is the
723  *    case then this function is not used at all. When the connecting is
724  *    done the `connect' client operation is called, and the `context' is
725  *    accessible with conn->context, conn being SilcClientConnection.
726  *    If the `params' is provided they are used by the routine.
727  *
728  ***/
729 int silc_client_connect_to_server(SilcClient client, 
730                                   SilcClientConnectionParams *params,
731                                   int port, char *host, void *context);
732
733 /****f* silcclient/SilcClientAPI/silc_client_add_connection
734  *
735  * SYNOPSIS
736  *
737  *
738  *    SilcClientConnection
739  *    silc_client_add_connection(SilcClient client,
740  *                               SilcClientConnectionParams *params,
741  *                               char *hostname, int port, void *context);
742  *
743  * DESCRIPTION
744  *
745  *    Allocates and adds new connection to the client. This adds the allocated
746  *    connection to the connection table and returns a pointer to it. A client
747  *    can have multiple connections to multiple servers. Every connection must
748  *    be added to the client using this function. User data `context' may
749  *    be sent as argument.  If the `params' is provided they are used by 
750  *    the routine.
751  *
752  * NOTES
753  *
754  *    This function is normally used only if the application performed 
755  *    the connecting outside the library, and did not called the
756  *    silc_client_connect_to_server function at all. The library
757  *    however may use this internally.
758  *
759  ***/
760 SilcClientConnection
761 silc_client_add_connection(SilcClient client,
762                            SilcClientConnectionParams *params,
763                            char *hostname, int port, void *context);
764
765 /****f* silcclient/SilcClientAPI/silc_client_del_connection
766  *
767  * SYNOPSIS
768  *
769  *    void silc_client_del_connection(SilcClient client, 
770  *                                    SilcClientConnection conn);
771  *
772  * DESCRIPTION
773  *
774  *    Removes connection from client. Frees all memory. The library
775  *    call this function automatically for all connection contexts.
776  *    The application however may free the connection contexts it has
777  *    allocated.
778  *
779  ***/
780 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
781
782 /****f* silcclient/SilcClientAPI/silc_client_add_socket
783  *
784  * SYNOPSIS
785  *
786  *    void silc_client_add_socket(SilcClient client, 
787  *                                SilcSocketConnection sock);
788  *
789  * DESCRIPTION
790  *
791  *    Adds listener socket to the listener sockets table. This function is
792  *    used to add socket objects that are listeners to the client.  This should
793  *    not be used to add other connection objects.
794  *
795  ***/
796 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
797
798 /****f* silcclient/SilcClientAPI/silc_client_del_socket
799  *
800  * SYNOPSIS
801  *
802  *    void silc_client_del_socket(SilcClient client, 
803  *                                SilcSocketConnection sock);
804  *
805  * DESCRIPTION
806  *
807  *    Deletes listener socket from the listener sockets table.  If the
808  *    application has added a socket with silc_client_add_socket it must
809  *    also free it using this function.
810  *
811  ***/
812 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
813
814 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
815  *
816  * SYNOPSIS
817  *
818  *    void silc_client_start_key_exchange(SilcClient client,
819  *                                        SilcClientConnection conn,
820  *                                        int fd);
821  *
822  * DESCRIPTION
823  *
824  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
825  *    key material between client and server.  This function can be called
826  *    directly if application is performing its own connecting and does not
827  *    use the connecting provided by this library. This function is normally
828  *    used only if the application performed the connecting outside the
829  *    library. The library however may use this internally.  After the
830  *    key exchange is performed the `connect' client operation is called.
831  *
832  ***/
833 void silc_client_start_key_exchange(SilcClient client,
834                                     SilcClientConnection conn,
835                                     int fd);
836
837 /****f* silcclient/SilcClientAPI/silc_client_close_connection
838  *
839  * SYNOPSIS
840  *
841  *    void silc_client_close_connection(SilcClient client,
842  *                                      SilcClientConnection conn);
843  *
844  * DESCRIPTION
845  *
846  *    Closes connection to remote end. Free's all allocated data except
847  *    for some information such as nickname etc. that are valid at all time. 
848  *
849  ***/
850 void silc_client_close_connection(SilcClient client,
851                                   SilcClientConnection conn);
852
853
854 /* Message sending functions (client_channel.c and client_prvmsg.c) */
855
856 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
857  *
858  * SYNOPSIS
859  *
860  *    void silc_client_send_channel_message(SilcClient client, 
861  *                                          SilcClientConnection conn,
862  *                                          SilcChannelEntry channel,
863  *                                          SilcChannelPrivateKey key,
864  *                                          SilcMessageFlags flags,
865  *                                          unsigned char *data, 
866  *                                          SilcUInt32 data_len, 
867  *                                          int force_send);
868  *
869  * DESCRIPTION
870  *
871  *    Sends packet to the `channel'. Packet to channel is always encrypted
872  *    differently from "normal" packets. SILC header of the packet is 
873  *    encrypted with the next receiver's key and the rest of the packet is
874  *    encrypted with the channel specific key. Padding and HMAC is computed
875  *    with the next receiver's key. The `data' is the channel message. If
876  *    the `force_send' is TRUE then the packet is sent immediately. 
877  *
878  *    If `key' is provided then that private key is used to encrypt the
879  *    channel message.  If it is not provided, private keys has not been
880  *    set at all, the normal channel key is used automatically.  If private
881  *    keys are set then the first key (the key that was added first as
882  *    private key) is used. 
883  *
884  ***/
885 void silc_client_send_channel_message(SilcClient client, 
886                                       SilcClientConnection conn,
887                                       SilcChannelEntry channel,
888                                       SilcChannelPrivateKey key,
889                                       SilcMessageFlags flags,
890                                       unsigned char *data, 
891                                       SilcUInt32 data_len, 
892                                       int force_send);
893
894 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
895  *
896  * SYNOPSIS
897  *
898  *    void silc_client_send_private_message(SilcClient client,
899  *                                          SilcClientConnection conn,
900  *                                          SilcClientEntry client_entry,
901  *                                          SilcMessageFlags flags,
902  *                                          unsigned char *data, 
903  *                                          SilcUInt32 data_len, 
904  *                                          int force_send);
905  *
906  * DESCRIPTION
907  *
908  *    Sends private message to remote client. If private message key has
909  *    not been set with this client then the message will be encrypted using
910  *    normal session keys. Private messages are special packets in SILC
911  *    network hence we need this own function for them. This is similar
912  *    to silc_client_packet_send_to_channel except that we send private
913  *    message. The `data' is the private message. If the `force_send' is
914  *    TRUE the packet is sent immediately. 
915  *
916  ***/
917 void silc_client_send_private_message(SilcClient client,
918                                       SilcClientConnection conn,
919                                       SilcClientEntry client_entry,
920                                       SilcMessageFlags flags,
921                                       unsigned char *data, 
922                                       SilcUInt32 data_len, 
923                                       int force_send);
924
925
926 /* Client and Channel entry retrieval (idlist.c) */
927
928 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
929  *
930  * SYNOPSIS
931  *
932  *    typedef void (*SilcGetClientCallback)(SilcClient client,
933  *                                          SilcClientConnection conn,
934  *                                          SilcClientEntry *clients,
935  *                                          SilcUInt32 clients_count,
936  *                                          void *context);
937  *
938  * DESCRIPTION
939  *
940  *    Callback function given to the silc_client_get_client function. The
941  *    found entries are allocated into the `clients' array. The array must
942  *    not be freed by the receiver, the library will free it later. If the
943  *    `clients' is NULL, no such clients exist in the SILC Network.
944  *
945  ***/
946 typedef void (*SilcGetClientCallback)(SilcClient client,
947                                       SilcClientConnection conn,
948                                       SilcClientEntry *clients,
949                                       SilcUInt32 clients_count,
950                                       void *context);
951
952 /****f* silcclient/SilcClientAPI/silc_client_get_clients
953  *
954  * SYNOPSIS
955  *
956  *    void silc_client_get_clients(SilcClient client,
957  *                                 SilcClientConnection conn,
958  *                                 const char *nickname,
959  *                                 const char *server,
960  *                                 SilcGetClientCallback completion,
961  *                                 void *context);
962  *
963  * DESCRIPTION
964  *
965  *    Finds client entry or entries by the `nickname' and `server'. The 
966  *    completion callback will be called when the client entries has been
967  *    found.  After the server returns the client information it is cached
968  *    and can be accesses locally at a later time.
969  *
970  * NOTES
971  *
972  *    NOTE: This function is always asynchronous and resolves the client
973  *    information from the server. Thus, if you already know the client
974  *    information then use the silc_client_get_client_by_id function to
975  *    get the client entry since this function may be very slow and should
976  *    be used only to initially get the client entries. 
977  *
978  ***/
979 void silc_client_get_clients(SilcClient client,
980                              SilcClientConnection conn,
981                              const char *nickname,
982                              const char *server,
983                              SilcGetClientCallback completion,
984                              void *context);
985
986 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
987  *
988  * SYNOPSIS
989  *
990  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
991  *                                                   SilcClientConnection conn,
992  *                                                   const char *nickname,
993  *                                                   const char *format,
994  *                                                   SilcUInt32 *clients_count);
995  *
996  * DESCRIPTION
997  *
998  *    Same as silc_client_get_clients function but does not resolve anything
999  *    from the server. This checks local cache and returns all matching
1000  *    clients from the local cache. If none was found this returns NULL.
1001  *    The `nickname' is the real nickname of the client, and the `format'
1002  *    is the formatted nickname to find exact match from multiple found
1003  *    entries. The format must be same as given in the SilcClientParams
1004  *    structure to the client library. If the `format' is NULL all found
1005  *    clients by `nickname' are returned. The caller must return the
1006  *    returned array.
1007  *
1008  ***/
1009 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1010                                                SilcClientConnection conn,
1011                                                const char *nickname,
1012                                                const char *format,
1013                                                SilcUInt32 *clients_count);
1014
1015 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1016  *
1017  * SYNOPSIS
1018  *
1019  *    void silc_client_get_clients_by_list(SilcClient client,
1020  *                                         SilcClientConnection conn,
1021  *                                         SilcUInt32 list_count,
1022  *                                         SilcBuffer client_id_list,
1023  *                                         SilcGetClientCallback completion,
1024  *                                         void *context);
1025  *
1026  * DESCRIPTION
1027  *
1028  *    Gets client entries by the list of client ID's `client_id_list'. This
1029  *    always resolves those client ID's it does not know yet from the server
1030  *    so this function might take a while. The `client_id_list' is a list
1031  *    of ID Payloads added one after other.  JOIN command reply and USERS
1032  *    command reply for example returns this sort of list. The `completion'
1033  *    will be called after the entries are available. When server returns
1034  *    the client information it will be cached and can be accessed locally
1035  *    at a later time.
1036  *
1037  ***/
1038 void silc_client_get_clients_by_list(SilcClient client,
1039                                      SilcClientConnection conn,
1040                                      SilcUInt32 list_count,
1041                                      SilcBuffer client_id_list,
1042                                      SilcGetClientCallback completion,
1043                                      void *context);
1044
1045 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1046  *
1047  * SYNOPSIS
1048  *
1049  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1050  *                                                 SilcClientConnection conn,
1051  *                                                 SilcClientID *client_id);
1052  *
1053  * DESCRIPTION
1054  *
1055  *    Find entry for client by the client's ID. Returns the entry or NULL
1056  *    if the entry was not found.  This checks the local cache and does
1057  *    not resolve anything from server.
1058  *
1059  ***/
1060 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1061                                              SilcClientConnection conn,
1062                                              SilcClientID *client_id);
1063
1064 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1065  *
1066  * SYNOPSIS
1067  *
1068  *    void 
1069  *    silc_client_get_client_by_id_resolve(SilcClient client,
1070  *                                         SilcClientConnection conn,
1071  *                                         SilcClientID *client_id,
1072  *                                         SilcGetClientCallback completion,
1073  *                                         void *context);
1074  *
1075  * DESCRIPTION
1076  *
1077  *    Same as silc_client_get_client_by_id but will always resolve the
1078  *    information from the server. Use this only if you know that you
1079  *    do not have the entry and the only thing you know about the client
1080  *    is its ID. When server returns the client information it will be
1081  *    cache and can be accessed locally at a later time.
1082  *
1083  ***/
1084 void silc_client_get_client_by_id_resolve(SilcClient client,
1085                                           SilcClientConnection conn,
1086                                           SilcClientID *client_id,
1087                                           SilcGetClientCallback completion,
1088                                           void *context);
1089
1090 /****f* silcclient/SilcClientAPI/silc_client_del_client
1091  *
1092  * SYNOPSIS
1093  *
1094  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1095  *                                SilcClientEntry client_entry)
1096  *
1097  * DESCRIPTION
1098  *
1099  *    Removes client from local cache by the client entry indicated by
1100  *    the `client_entry'.  Returns TRUE if the deletion were successful.
1101  *
1102  ***/
1103 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1104                             SilcClientEntry client_entry);
1105
1106 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1107  *
1108  * SYNOPSIS
1109  *
1110  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
1111  *                                           SilcClientConnection conn,
1112  *                                           SilcChannelEntry *channels,
1113  *                                           SilcUInt32 channels_count,
1114  *                                           void *context);
1115  *
1116  * DESCRIPTION
1117  *
1118  *    Callback function given to the silc_client_get_channel_* functions.
1119  *    The found entries are allocated into the `channels' array. The array
1120  *    must not be freed by the receiver, the library will free it later.
1121  *    If the `channel' is NULL, no such channel exist in the SILC Network.
1122  *
1123  ***/
1124 typedef void (*SilcGetChannelCallback)(SilcClient client,
1125                                        SilcClientConnection conn,
1126                                        SilcChannelEntry *channels,
1127                                        SilcUInt32 channels_count,
1128                                        void *context);
1129
1130 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1131  *
1132  * SYNOPSIS
1133  *
1134  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
1135  *                                             SilcClientConnection conn,
1136  *                                             char *channel);
1137  *
1138  * DESCRIPTION
1139  *
1140  *    Finds entry for channel by the channel name. Returns the entry or NULL
1141  *    if the entry was not found. It is found only if the client is joined
1142  *    to the channel. 
1143  *
1144  ***/
1145 SilcChannelEntry silc_client_get_channel(SilcClient client,
1146                                          SilcClientConnection conn,
1147                                          char *channel);
1148
1149 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1150  *
1151  * SYNOPSIS
1152  *
1153  *    SilcChannelEntry
1154  *    silc_client_get_channel_by_id(SilcClient client,
1155  *                                  SilcClientConnection conn,
1156  *                                  SilcChannelID *channel_id);
1157  *
1158  * DESCRIPTION
1159  *
1160  *    Finds channel entry by the channel name. Returns the entry or NULL
1161  *    if it was not found.
1162  *
1163  ***/
1164 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1165                                                SilcClientConnection conn,
1166                                                SilcChannelID *channel_id);
1167
1168 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1169  *
1170  * SYNOPSIS
1171  *
1172  *    void 
1173  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1174  *                                          SilcClientConnection conn,
1175  *                                          SilcChannelID *channel_id,
1176  *                                          SilcGetClientCallback completion,
1177  *                                          void *context);
1178  *
1179  * DESCRIPTION
1180  *
1181  *    Resolves the channel information (its name mainly) from the server
1182  *    by the `channel_id'. Use this only if you know that you do not have
1183  *    the entry cached locally.
1184  *
1185  ***/
1186 void silc_client_get_channel_by_id_resolve(SilcClient client,
1187                                            SilcClientConnection conn,
1188                                            SilcChannelID *channel_id,
1189                                            SilcGetChannelCallback completion,
1190                                            void *context);
1191
1192 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1193  *
1194  * SYNOPSIS
1195  *
1196  *    bool silc_client_del_channel(SilcClient client, 
1197  *                                 SilcClientConnection conn,
1198  *                                 SilcChannelEntry channel)
1199  *
1200  * DESCRIPTION
1201  *
1202  *    Removes channel from local cache by the channel entry indicated by
1203  *    the `channel'.  Returns TRUE if the deletion were successful.
1204  *
1205  ***/
1206 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1207                              SilcChannelEntry channel);
1208
1209 /****f* silcclient/SilcClientAPI/silc_client_get_server
1210  *
1211  * SYNOPSIS
1212  *
1213  *    SilcServerEntry silc_client_get_server(SilcClient client,
1214  *                                           SilcClientConnection conn,
1215  *                                           char *server_name)
1216  *
1217  * DESCRIPTION
1218  *
1219  *    Finds entry for server by the server name. Returns the entry or NULL
1220  *    if the entry was not found.
1221  *
1222  ***/
1223 SilcServerEntry silc_client_get_server(SilcClient client,
1224                                        SilcClientConnection conn,
1225                                        char *server_name);
1226
1227 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1228  *
1229  * SYNOPSIS
1230  *
1231  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1232  *                                                 SilcClientConnection conn,
1233  *                                                 SilcServerID *server_id);
1234  *
1235  * DESCRIPTION
1236  *
1237  *    Finds entry for server by the server ID. Returns the entry or NULL
1238  *    if the entry was not found.
1239  *
1240  ***/
1241 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1242                                              SilcClientConnection conn,
1243                                              SilcServerID *server_id);
1244
1245 /****f* silcclient/SilcClientAPI/silc_client_del_server
1246  *
1247  * SYNOPSIS
1248  *
1249  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1250  *                                SilcServerEntry server);
1251  *
1252  * DESCRIPTION
1253  *
1254  *    Removes server from local cache by the server entry indicated by
1255  *    the `server'.  Returns TRUE if the deletion were successful.
1256  *
1257  ***/
1258 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1259                             SilcServerEntry server);
1260
1261 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1262  *
1263  * SYNOPSIS
1264  *
1265  *    SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1266  *                                           SilcClientEntry client_entry);
1267  *
1268  * DESCRIPTION
1269  *
1270  *    Returns the ChannelUser entry if the `client_entry' is joined on the 
1271  *    channel indicated by the `channel'. NULL if client is not joined on
1272  *    the channel. 
1273  *
1274  ***/
1275 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1276                                        SilcClientEntry client_entry);
1277
1278 /* Command management (command.c) */
1279
1280 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1281  *
1282  * SYNOPSIS
1283  *
1284  *    SilcClientCommandContext silc_client_command_alloc(void);
1285  *
1286  * DESCRIPTION
1287  *
1288  *    Allocate Command Context. The context is defined in `command.h' file.
1289  *    The context is used by the library commands and applications should use
1290  *    it as well. However, application may choose to use some own context
1291  *    for its local commands. All library commands, however, must use this
1292  *    context. 
1293  *
1294  ***/
1295 SilcClientCommandContext silc_client_command_alloc(void);
1296
1297 /****f* silcclient/SilcClientAPI/silc_client_command_free
1298  *
1299  * SYNOPSIS
1300  *
1301  *    void silc_client_command_free(SilcClientCommandContext ctx);
1302  *
1303  * DESCRIPTION
1304  *
1305  *    Free command context and its internals.  If the contex was duplicated
1306  *    with silc_client_command_dup this may not actually free the data, 
1307  *    instead it will decrease the reference counter of the context.  The
1308  *    context will be freed when the reference counter hits zero.
1309  *
1310  ***/
1311 void silc_client_command_free(SilcClientCommandContext ctx);
1312
1313 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1314  *
1315  * SYNOPSIS
1316  *
1317  *    SilcClientCommandContext 
1318  *    silc_client_command_dup(SilcClientCommandContext ctx);
1319  *
1320  * DESCRIPTION
1321  *
1322  *    Duplicate Command Context by adding reference counter. The context won't
1323  *    be free'd untill it hits zero. 
1324  *
1325  ***/
1326 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1327
1328 /****f* silcclient/SilcClientAPI/silc_client_command_find
1329  *
1330  * SYNOPSIS
1331  *
1332  *    SilcClientCommand silc_client_command_find(SilcClient client,
1333  *                                               const char *name);
1334  *
1335  * DESCRIPTION
1336  *
1337  *    Finds and returns a pointer to the command list. Return NULL if the
1338  *    command is not found. See the `command.[ch]' for the command list. 
1339  *    Command names are not case-sensitive.
1340  *
1341  ***/
1342 SilcClientCommand silc_client_command_find(SilcClient client,
1343                                            const char *name);
1344
1345 /****f* silcclient/SilcClientAPI/silc_client_command_call
1346  *
1347  * SYNOPSIS
1348  *
1349  *    void silc_client_command_call(SilcClientCommand command);
1350  *
1351  * DESCRIPTION
1352  *
1353  *    Calls the command (executes it).  Application can call this after
1354  *    it has allocated the SilcClientCommandContext with the function
1355  *    silc_client_command_alloc and found the command from the client
1356  *    library by calling silc_client_command_find.  This will execute
1357  *    the command.
1358  *
1359  *    Application can call the command function directly too if it
1360  *    wishes to do so.  See the command.h for details of the
1361  *    SilcClientCommand structure.
1362  *
1363  ***/
1364 void silc_client_command_call(SilcClientCommand command,
1365                               SilcClientCommandContext cmd);
1366
1367 /****f* silcclient/SilcClientAPI/silc_client_command_send
1368  *
1369  * SYNOPSIS
1370  *
1371  *    void silc_client_command_send(SilcClient client, 
1372  *                                  SilcClientConnection conn,
1373  *                                  SilcCommand command, SilcUInt16 ident,
1374  *                                  SilcUInt32 argc, ...);
1375  *
1376  * DESCRIPTION
1377  *
1378  *    Generic function to send any command. The arguments must be sent already
1379  *    encoded into correct form and in correct order. If application wants
1380  *    to perform the commands by itself, it can do so and send the data
1381  *    directly to the server using this function.  If application is using
1382  *    the silc_client_command_call, this function is usually not used.
1383  *
1384  ***/
1385 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1386                               SilcCommand command, SilcUInt16 ident,
1387                               SilcUInt32 argc, ...);
1388
1389 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1390  *
1391  * SYNOPSIS
1392  *
1393  *    void silc_client_command_pending(SilcClientConnection conn,
1394  *                                     SilcCommand reply_cmd,
1395  *                                     SilcUInt16 ident,
1396  *                                     SilcCommandCb callback,
1397  *                                     void *context);
1398  *
1399  * DESCRIPTION
1400  *
1401  *    Add new pending command to be executed when reply to a command has been
1402  *    received.  The `reply_cmd' is the command that will call the `callback'
1403  *    with `context' when reply has been received.  If `ident' is non-zero
1404  *    the `callback' will be executed when received reply with command 
1405  *    identifier `ident'. 
1406  *
1407  *    Note that the application is notified about the received command
1408  *    reply through the `command_reply' client operation before calling
1409  *    the `callback` pending command callback.
1410  *
1411  ***/
1412 void silc_client_command_pending(SilcClientConnection conn,
1413                                  SilcCommand reply_cmd,
1414                                  SilcUInt16 ident,
1415                                  SilcCommandCb callback,
1416                                  void *context);
1417
1418
1419 /* Private Message key management (client_prvmsg.c) */
1420
1421 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1422  *
1423  * SYNOPSIS
1424  *
1425  *    int silc_client_add_private_message_key(SilcClient client,
1426  *                                            SilcClientConnection conn,
1427  *                                            SilcClientEntry client_entry,
1428  *                                            char *cipher,
1429  *                                            unsigned char *key,
1430  *                                            SilcUInt32 key_len,
1431  *                                            bool generate_key,
1432  *                                            bool responder);
1433  *
1434  * DESCRIPTION
1435  *
1436  *    Adds private message key to the client library. The key will be used to
1437  *    encrypt all private message between the client and the remote client
1438  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1439  *    value `generate_key' is TRUE the library will generate random key.
1440  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1441  *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
1442  *    requirements of the SILC protocol are met. The API, however, allows
1443  *    to allocate any cipher.
1444  *
1445  *    If `responder' is TRUE then the sending and receiving keys will be
1446  *    set according the client being the receiver of the private key.  If
1447  *    FALSE the client is being the sender (or negotiator) of the private
1448  *    key.
1449  *
1450  *    It is not necessary to set key for normal private message usage. If the
1451  *    key is not set then the private messages are encrypted using normal
1452  *    session keys. Setting the private key, however, increases the security. 
1453  *
1454  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1455  *    otherwise. 
1456  *
1457  ***/
1458 int silc_client_add_private_message_key(SilcClient client,
1459                                         SilcClientConnection conn,
1460                                         SilcClientEntry client_entry,
1461                                         char *cipher,
1462                                         unsigned char *key,
1463                                         SilcUInt32 key_len,
1464                                         bool generate_key,
1465                                         bool responder);
1466
1467 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1468  *
1469  * SYNOPSIS
1470  *
1471  *    int silc_client_add_private_message_key_ske(SilcClient client,
1472  *                                                SilcClientConnection conn,
1473  *                                                SilcClientEntry client_entry,
1474  *                                                char *cipher,
1475  *                                                SilcSKEKeyMaterial *key);
1476  *
1477  * DESCRIPTION
1478  *
1479  *    Same as silc_client_add_private_message_key but takes the key material
1480  *    from the SKE key material structure. This structure is received if
1481  *    the application uses the silc_client_send_key_agreement to negotiate
1482  *    the key material. The `cipher' SHOULD be provided as it is negotiated
1483  *    also in the SKE protocol. 
1484  *
1485  ***/
1486 int silc_client_add_private_message_key_ske(SilcClient client,
1487                                             SilcClientConnection conn,
1488                                             SilcClientEntry client_entry,
1489                                             char *cipher,
1490                                             SilcSKEKeyMaterial *key,
1491                                             bool responder);
1492
1493 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1494  *
1495  * SYNOPSIS
1496  *
1497  *    int silc_client_send_private_message_key(SilcClient client,
1498  *                                             SilcClientConnection conn,
1499  *                                             SilcClientEntry client_entry,
1500  *                                             int force_send);
1501  *
1502  * DESCRIPTION
1503  *
1504  *    Sends private message key payload to the remote client indicated by
1505  *    the `client_entry'. If the `force_send' is TRUE the packet is sent
1506  *    immediately. Returns FALSE if error occurs, TRUE otherwise. The
1507  *    application should call this function after setting the key to the
1508  *    client.
1509  *
1510  *    Note that the key sent using this function is sent to the remote client
1511  *    through the SILC network. The packet is protected using normal session
1512  *    keys. 
1513  *
1514  ***/
1515 int silc_client_send_private_message_key(SilcClient client,
1516                                          SilcClientConnection conn,
1517                                          SilcClientEntry client_entry,
1518                                          int force_send);
1519
1520 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1521  *
1522  * SYNOPSIS
1523  *
1524  *    int silc_client_del_private_message_key(SilcClient client,
1525  *                                            SilcClientConnection conn,
1526  *                                            SilcClientEntry client_entry);
1527  *
1528  * DESCRIPTION
1529  *
1530  *    Removes the private message from the library. The key won't be used
1531  *    after this to protect the private messages with the remote `client_entry'
1532  *    client. Returns FALSE on error, TRUE otherwise. 
1533  *
1534  ***/
1535 int silc_client_del_private_message_key(SilcClient client,
1536                                         SilcClientConnection conn,
1537                                         SilcClientEntry client_entry);
1538
1539 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1540  *
1541  * SYNOPSIS
1542  *
1543  *    SilcPrivateMessageKeys
1544  *    silc_client_list_private_message_keys(SilcClient client,
1545  *                                          SilcClientConnection conn,
1546  *                                          SilcUInt32 *key_count);
1547  * 
1548  * DESCRIPTION
1549  *
1550  *    Returns array of set private message keys associated to the connection
1551  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1552  *    count to the `key_count' argument. The array must be freed by the caller
1553  *    by calling the silc_client_free_private_message_keys function. Note: 
1554  *    the keys returned in the array is in raw format. It might not be desired
1555  *    to show the keys as is. The application might choose not to show the keys
1556  *    at all or to show the fingerprints of the keys. 
1557  *
1558  ***/
1559 SilcPrivateMessageKeys
1560 silc_client_list_private_message_keys(SilcClient client,
1561                                       SilcClientConnection conn,
1562                                       SilcUInt32 *key_count);
1563
1564 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1565  *
1566  * SYNOPSIS
1567  *
1568  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1569  *                                               SilcUInt32 key_count);
1570  * 
1571  * DESCRIPTION
1572  *
1573  *    Frees the SilcPrivateMessageKeys array returned by the function
1574  *    silc_client_list_private_message_keys. 
1575  *
1576  ***/
1577 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1578                                            SilcUInt32 key_count);
1579
1580
1581 /* Channel private key management (client_channel.c, 
1582    SilcChannelPrivateKey is defined in idlist.h) */
1583
1584 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1585  *
1586  * SYNOPSIS
1587  *
1588  *    int silc_client_add_channel_private_key(SilcClient client,
1589  *                                            SilcClientConnection conn,
1590  *                                            SilcChannelEntry channel,
1591  *                                            const char *name,
1592  *                                            char *cipher,
1593  *                                            char *hmac,
1594  *                                            unsigned char *key,
1595  *                                            SilcUInt32 key_len);
1596  * 
1597  * DESCRIPTION
1598  *
1599  *    Adds private key for channel. This may be set only if the channel's mode
1600  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1601  *    mode is not set. When channel has private key then the messages are
1602  *    encrypted using that key. All clients on the channel must also know the
1603  *    key in order to decrypt the messages. However, it is possible to have
1604  *    several private keys per one channel. In this case only some of the
1605  *    clients on the channel may know the one key and only some the other key.
1606  *    The `name' can be application given name for the key.
1607  *
1608  *    The private key for channel is optional. If it is not set then the
1609  *    channel messages are encrypted using the channel key generated by the
1610  *    server. However, setting the private key (or keys) for the channel 
1611  *    significantly adds security. If more than one key is set the library
1612  *    will automatically try all keys at the message decryption phase. Note:
1613  *    setting many keys slows down the decryption phase as all keys has to
1614  *    be tried in order to find the correct decryption key. However, setting
1615  *    a few keys does not have big impact to the decryption performace. 
1616  *
1617  * NOTES
1618  *
1619  *    NOTE: This is entirely local setting. The key set using this function
1620  *    is not sent to the network at any phase.
1621  *
1622  *    NOTE: If the key material was originated by the SKE protocol (using
1623  *    silc_client_send_key_agreement) then the `key' MUST be the
1624  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1625  *    currently it is not expected that the SKE key material would be used
1626  *    as channel private key. However, this API allows it. 
1627  *
1628  ***/
1629 int silc_client_add_channel_private_key(SilcClient client,
1630                                         SilcClientConnection conn,
1631                                         SilcChannelEntry channel,
1632                                         const char *name,
1633                                         char *cipher,
1634                                         char *hmac,
1635                                         unsigned char *key,
1636                                         SilcUInt32 key_len);
1637
1638 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1639  *
1640  * SYNOPSIS
1641  *
1642  *    int silc_client_del_channel_private_keys(SilcClient client,
1643  *                                             SilcClientConnection conn,
1644  *                                             SilcChannelEntry channel);
1645  * 
1646  * DESCRIPTION
1647  *
1648  *    Removes all private keys from the `channel'. The old channel key is used
1649  *    after calling this to protect the channel messages. Returns FALSE on
1650  *    on error, TRUE otherwise. 
1651  *
1652  ***/
1653 int silc_client_del_channel_private_keys(SilcClient client,
1654                                          SilcClientConnection conn,
1655                                          SilcChannelEntry channel);
1656
1657 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1658  *
1659  * SYNOPSIS
1660  *
1661  *    int silc_client_del_channel_private_key(SilcClient client,
1662  *                                            SilcClientConnection conn,
1663  *                                            SilcChannelEntry channel,
1664  *                                            SilcChannelPrivateKey key);
1665  * 
1666  * DESCRIPTION
1667  *
1668  *    Removes and frees private key `key' from the channel `channel'. 
1669  *    The `key' is retrieved by calling the function 
1670  *    silc_client_list_channel_private_keys. The key is not used after
1671  *    this. If the key was last private key then the old channel key is
1672  *    used hereafter to protect the channel messages. This returns FALSE
1673  *    on error, TRUE otherwise. 
1674  *
1675  ***/
1676 int silc_client_del_channel_private_key(SilcClient client,
1677                                         SilcClientConnection conn,
1678                                         SilcChannelEntry channel,
1679                                         SilcChannelPrivateKey key);
1680
1681 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1682  *
1683  * SYNOPSIS
1684  *
1685  *    SilcChannelPrivateKey *
1686  *    silc_client_list_channel_private_keys(SilcClient client,
1687  *                                          SilcClientConnection conn,
1688  *                                          SilcChannelEntry channel,
1689  *                                          SilcUInt32 *key_count);
1690  *
1691  * DESCRIPTION
1692  *
1693  *    Returns array (pointers) of private keys associated to the `channel'.
1694  *    The caller must free the array by calling the function
1695  *    silc_client_free_channel_private_keys. The pointers in the array may be
1696  *    used to delete the specific key by giving the pointer as argument to the
1697  *    function silc_client_del_channel_private_key. 
1698  *
1699  ***/
1700 SilcChannelPrivateKey *
1701 silc_client_list_channel_private_keys(SilcClient client,
1702                                       SilcClientConnection conn,
1703                                       SilcChannelEntry channel,
1704                                       SilcUInt32 *key_count);
1705
1706 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1707  *
1708  * SYNOPSIS
1709  *
1710  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1711  *                                               SilcUInt32 key_count);
1712  *
1713  * DESCRIPTION
1714  *
1715  *    Frees the SilcChannelPrivateKey array.
1716  *
1717  ***/
1718 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1719                                            SilcUInt32 key_count);
1720
1721 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1722  *
1723  * SYNOPSIS
1724  *
1725  *    void silc_client_current_channel_private_key(SilcClient client,
1726  *                                                 SilcClientConnection conn,
1727  *                                                 SilcChannelEntry channel,
1728  *                                                 SilcChannelPrivateKey key);
1729  *
1730  * DESCRIPTION
1731  *
1732  *    Sets the `key' to be used as current channel private key on the
1733  *    `channel'.  Packet sent after calling this function will be secured
1734  *    with `key'.
1735  *
1736  ***/
1737 void silc_client_current_channel_private_key(SilcClient client,
1738                                              SilcClientConnection conn,
1739                                              SilcChannelEntry channel,
1740                                              SilcChannelPrivateKey key);
1741
1742
1743 /* Key Agreement routines (client_keyagr.c) */
1744
1745 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1746  *
1747  * SYNOPSIS
1748  *
1749  *    void silc_client_send_key_agreement(SilcClient client,
1750  *                                        SilcClientConnection conn,
1751  *                                        SilcClientEntry client_entry,
1752  *                                        char *hostname,
1753  *                                        int port,
1754  *                                        SilcUInt32 timeout_secs,
1755  *                                        SilcKeyAgreementCallback completion,
1756  *                                        void *context);
1757  *
1758  * DESCRIPTION
1759  *
1760  *    Sends key agreement request to the remote client indicated by the
1761  *    `client_entry'. If the caller provides the `hostname' and the `port'
1762  *    arguments then the library will bind the client to that hostname and
1763  *    that port for the key agreement protocol. It also sends the `hostname'
1764  *    and the `port' in the key agreement packet to the remote client. This
1765  *    would indicate that the remote client may initiate the key agreement
1766  *    protocol to the `hostname' on the `port'.  If port is zero then the
1767  *    bound port is undefined (the operating system defines it).
1768  *
1769  *    If the `hostname' and `port' is not provided then empty key agreement
1770  *    packet is sent to the remote client. The remote client may reply with
1771  *    the same packet including its hostname and port. If the library receives
1772  *    the reply from the remote client the `key_agreement' client operation
1773  *    callback will be called to verify whether the user wants to perform the
1774  *    key agreement or not. 
1775  *
1776  * NOTES
1777  *
1778  *    NOTE: If the application provided the `hostname' and the `port' and the 
1779  *    remote side initiates the key agreement protocol it is not verified
1780  *    from the user anymore whether the protocol should be executed or not.
1781  *    By setting the `hostname' and `port' the user gives permission to
1782  *    perform the protocol (we are responder in this case).
1783  *
1784  *    NOTE: If the remote side decides not to initiate the key agreement
1785  *    or decides not to reply with the key agreement packet then we cannot
1786  *    perform the key agreement at all. If the key agreement protocol is
1787  *    performed the `completion' callback with the `context' will be called.
1788  *    If remote side decides to ignore the request the `completion' will be
1789  *    called after the specified timeout, `timeout_secs'. 
1790  *
1791  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
1792  *    will not be called at all since this does nothing more than sending
1793  *    a packet to the remote host.
1794  *
1795  *    NOTE: There can be only one active key agreement for one client entry.
1796  *    Before setting new one, the old one must be finished (it is finished
1797  *    after calling the completion callback) or the function 
1798  *    silc_client_abort_key_agreement must be called. 
1799  *
1800  ***/
1801 void silc_client_send_key_agreement(SilcClient client,
1802                                     SilcClientConnection conn,
1803                                     SilcClientEntry client_entry,
1804                                     const char *hostname,
1805                                     const char *bindhost,
1806                                     int port,
1807                                     SilcUInt32 timeout_secs,
1808                                     SilcKeyAgreementCallback completion,
1809                                     void *context);
1810
1811 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1812  *
1813  * SYNOPSIS
1814  *
1815  *    void 
1816  *    silc_client_perform_key_agreement(SilcClient client,
1817  *                                      SilcClientConnection conn,
1818  *                                      SilcClientEntry client_entry,
1819  *                                      char *hostname,
1820  *                                      int port,
1821  *                                      SilcKeyAgreementCallback completion,
1822  *                                      void *context);
1823  *
1824  * DESCRIPTION
1825  *
1826  *    Performs the actual key agreement protocol. Application may use this
1827  *    to initiate the key agreement protocol. This can be called for example
1828  *    after the application has received the `key_agreement' client operation,
1829  *    and did not return TRUE from it.
1830  *
1831  *    The `hostname' is the remote hostname (or IP address) and the `port'
1832  *    is the remote port. The `completion' callback with the `context' will
1833  *    be called after the key agreement protocol.
1834  *
1835  * NOTES
1836  * 
1837  *    NOTE: If the application returns TRUE in the `key_agreement' client
1838  *    operation the library will automatically start the key agreement. In this
1839  *    case the application must not call this function. However, application
1840  *    may choose to just ignore the `key_agreement' client operation (and
1841  *    merely just print information about it on the screen) and call this
1842  *    function when the user whishes to do so (by, for example, giving some
1843  *    specific command). Thus, the API provides both, automatic and manual
1844  *    initiation of the key agreement. Calling this function is the manual
1845  *    initiation and returning TRUE in the `key_agreement' client operation
1846  *    is the automatic initiation. 
1847  *
1848  ***/
1849 void silc_client_perform_key_agreement(SilcClient client,
1850                                        SilcClientConnection conn,
1851                                        SilcClientEntry client_entry,
1852                                        char *hostname,
1853                                        int port,
1854                                        SilcKeyAgreementCallback completion,
1855                                        void *context);
1856
1857 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1858  *
1859  * SYNOPSIS
1860  *
1861  *    void
1862  *    silc_client_perform_key_agreement_fd(SilcClient client,
1863  *                                         SilcClientConnection conn,
1864  *                                         SilcClientEntry client_entry,
1865  *                                         int sock,
1866  *                                         char *hostname,
1867  *                                         SilcKeyAgreementCallback completion,
1868  *                                         void *context);
1869  *
1870  * DESCRIPTION
1871  *
1872  *    Same as above but application has created already the connection to 
1873  *    the remote host. The `sock' is the socket to the remote connection. 
1874  *    Application can use this function if it does not want the client library
1875  *    to create the connection. 
1876  *
1877  ***/
1878 void silc_client_perform_key_agreement_fd(SilcClient client,
1879                                           SilcClientConnection conn,
1880                                           SilcClientEntry client_entry,
1881                                           int sock,
1882                                           char *hostname,
1883                                           SilcKeyAgreementCallback completion,
1884                                           void *context);
1885
1886 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1887  *
1888  * SYNOPSIS
1889  *
1890  *    void silc_client_abort_key_agreement(SilcClient client,
1891  *                                         SilcClientConnection conn,
1892  *                                         SilcClientEntry client_entry);
1893  *
1894  * DESCRIPTION
1895  *
1896  *    This function can be called to unbind the hostname and the port for
1897  *    the key agreement protocol. However, this function has effect only 
1898  *    before the key agreement protocol has been performed. After it has
1899  *    been performed the library will automatically unbind the port. The 
1900  *    `client_entry' is the client to which we sent the key agreement 
1901  *    request.  The key agreement completion callback will be called
1902  *    with SILC_KEY_AGREEMENT_ABORTED status.
1903  *
1904  ***/
1905 void silc_client_abort_key_agreement(SilcClient client,
1906                                      SilcClientConnection conn,
1907                                      SilcClientEntry client_entry);
1908
1909
1910 /* Misc functions */
1911
1912 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1913  *
1914  * SYNOPSIS
1915  *
1916  *    void silc_client_set_away_message(SilcClient client,
1917  *                                      SilcClientConnection conn,
1918  *                                      char *message);
1919  *
1920  * DESCRIPTION
1921  *
1922  *    Sets away `message'.  The away message may be set when the client's
1923  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1924  *    to anyone who sends private message.  The `message' will be sent
1925  *    automatically back to the the client who send private message.  If
1926  *    away message is already set this replaces the old message with the
1927  *    new one.  If `message' is NULL the old away message is removed. 
1928  *    The sender may freely free the memory of the `message'. 
1929  *
1930  ***/
1931 void silc_client_set_away_message(SilcClient client,
1932                                   SilcClientConnection conn,
1933                                   char *message);
1934
1935
1936 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1937  *
1938  * SYNOPSIS
1939  *
1940  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1941  *                                              SilcClientConnection conn,
1942  *                                              SilcAuthMethod auth_meth,
1943  *                                              void *context);
1944  *
1945  * DESCRIPTION
1946  *
1947  *    Connection authentication method request callback. This is called
1948  *    by the client library after it has received the authentication method
1949  *    that the application requested by calling the function
1950  *    silc_client_request_authentication_method.
1951  *
1952  ***/
1953 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1954                                           SilcClientConnection conn,
1955                                           SilcAuthMethod auth_meth,
1956                                           void *context);
1957
1958 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1959  *
1960  * SYNOPSIS
1961  *
1962  *    void 
1963  *    silc_client_request_authentication_method(SilcClient client,
1964  *                                              SilcClientConnection conn,
1965  *                                              SilcConnectionAuthRequest 
1966  *                                                callback,
1967  *                                              void *context);
1968  *
1969  * DESCRIPTION
1970  *
1971  *    This function can be used to request the current authentication method
1972  *    from the server. This may be called when connecting to the server
1973  *    and the client library requests the authentication data from the
1974  *    application. If the application does not know the current authentication
1975  *    method it can request it from the server using this function.
1976  *    The `callback' with `context' will be called after the server has
1977  *    replied back with the current authentication method.
1978  *
1979  ***/
1980 void 
1981 silc_client_request_authentication_method(SilcClient client,
1982                                           SilcClientConnection conn,
1983                                           SilcConnectionAuthRequest callback,
1984                                           void *context);
1985
1986 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1987  *
1988  * NAME
1989  *
1990  *    typedef enum { ... } SilcClientMonitorStatus;
1991  *
1992  * DESCRIPTION
1993  *
1994  *    File transmission session status types.  These will indicate
1995  *    the status of the file transmission session.
1996  *
1997  * SOURCE
1998  */
1999 typedef enum {
2000   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
2001   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
2002   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
2003   SILC_CLIENT_FILE_MONITOR_GET,
2004   SILC_CLIENT_FILE_MONITOR_PUT,
2005   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
2006   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
2007 } SilcClientMonitorStatus;
2008 /***/
2009
2010 /****d* silcclient/SilcClientAPI/SilcClientFileError
2011  *
2012  * NAME
2013  *
2014  *    typedef enum { ... } SilcClientFileError;
2015  *
2016  * DESCRIPTION
2017  *
2018  *    File transmission error types.  These types are returned by
2019  *    some of the file transmission functions, and by the monitor
2020  *    callback to indicate error.
2021  *
2022  * SOURCE
2023  */
2024 typedef enum {
2025   SILC_CLIENT_FILE_OK,
2026   SILC_CLIENT_FILE_ERROR,
2027   SILC_CLIENT_FILE_UNKNOWN_SESSION,
2028   SILC_CLIENT_FILE_ALREADY_STARTED,
2029   SILC_CLIENT_FILE_NO_SUCH_FILE,
2030   SILC_CLIENT_FILE_PERMISSION_DENIED,
2031   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2032 } SilcClientFileError;
2033 /***/
2034
2035 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2036  *
2037  * SYNOPSIS
2038  *
2039  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
2040  *                                          SilcClientConnection conn,
2041  *                                          SilcClientMonitorStatus status,
2042  *                                          SilcClientFileError error,
2043  *                                          SilcUInt64 offset,
2044  *                                          SilcUInt64 filesize,
2045  *                                          SilcClientEntry client_entry,
2046  *                                          SilcUInt32 session_id,
2047  *                                          const char *filepath,
2048  *                                          void *context);
2049  *
2050  * DESCRIPTION
2051  *
2052  *    Monitor callback that is called during the file transmission to
2053  *    monitor the transmission process.  The `status' indicates the current
2054  *    monitoring process.  The `error' will indicate the error type
2055  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
2056  *    currently transmitted amount of total `filesize'.  The `client_entry'
2057  *    indicates the remote client, and the transmission session ID is the 
2058  *    `session_id'.  The filename being transmitted is indicated by the 
2059  *    `filepath'.
2060  *
2061  ***/
2062 typedef void (*SilcClientFileMonitor)(SilcClient client,
2063                                       SilcClientConnection conn,
2064                                       SilcClientMonitorStatus status,
2065                                       SilcClientFileError error,
2066                                       SilcUInt64 offset,
2067                                       SilcUInt64 filesize,
2068                                       SilcClientEntry client_entry,
2069                                       SilcUInt32 session_id,
2070                                       const char *filepath,
2071                                       void *context);
2072
2073 /****f* silcclient/SilcClientAPI/silc_client_file_send
2074  *
2075  * SYNOPSIS
2076  *
2077  *    SilcClientFileError 
2078  *    silc_client_file_send(SilcClient client,
2079  *                          SilcClientConnection conn,
2080  *                          SilcClientFileMonitor monitor,
2081  *                          void *monitor_context,
2082  *                          const char *local_ip,
2083  *                          SilcUInt32 local_port,
2084  *                          SilcClientEntry client_entry,
2085  *                          const char *filepath);
2086  *                          SilcUInt32 *session_id);
2087  *
2088  * DESCRIPTION
2089  *
2090  *    Sends a file indicated by the `filepath' to the remote client 
2091  *    indicated by the `client_entry'.  This will negotiate a secret key
2092  *    with the remote client before actually starting the transmission of
2093  *    the file.  The `monitor' callback will be called to monitor the
2094  *    transmission of the file.
2095  *
2096  *    This returns a file session ID for the file transmission to the
2097  *    `session_id' pointer..  It can be used to close the session (and
2098  *    abort the file transmission) by calling the silc_client_file_close
2099  *    function.  The session ID is also returned in the `monitor' callback. 
2100  *
2101  *    If the `local_ip' is provided then this will try to bind the 
2102  *    listener for key exchange protocol to that IP.  If `local_port' is
2103  *    non-zero that port is used.  If `local_ip' is NULL then this will
2104  *    automatically attempt to bind it to local IP address of the machine.
2105  *    If that fails then this does not bind to any address and port, and
2106  *    assume that the remote client will provide the listener for the
2107  *    key exchange protocol.
2108  *
2109  *    If error will occur during the file transfer process the error
2110  *    status will be returned in the monitor callback.  In this case
2111  *    the application must call silc_client_file_close to close the
2112  *    session.
2113  *
2114  ***/
2115 SilcClientFileError 
2116 silc_client_file_send(SilcClient client,
2117                       SilcClientConnection conn,
2118                       SilcClientFileMonitor monitor,
2119                       void *monitor_context,
2120                       const char *local_ip,
2121                       SilcUInt32 local_port,
2122                       SilcClientEntry client_entry,
2123                       const char *filepath,
2124                       SilcUInt32 *session_id);
2125
2126 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2127  *
2128  * SYNOPSIS
2129  *
2130  *    SilcClientFileError 
2131  *    silc_client_file_receive(SilcClient client,
2132  *                             SilcClientConnection conn,
2133  *                             SilcClientFileMonitor monitor,
2134  *                             void *monitor_context,
2135  *                             const char *path,
2136  *                             SilcUInt32 session_id);
2137  *
2138  * DESCRIPTION
2139  *
2140  *    Receives a file from a client indicated by the `client_entry'.  The
2141  *    `session_id' indicates the file transmission session and it has been
2142  *    received in the `ftp' client operation function.  This will actually
2143  *    perform the key agreement protocol with the remote client before
2144  *    actually starting the file transmission.  The `monitor' callback
2145  *    will be called to monitor the transmission.  If `path' is non NULL
2146  *    the file will be saved into that directory.  If NULL the file is
2147  *    saved in the current working directory.
2148  *
2149  *    If error will occur during the file transfer process the error
2150  *    status will be returned in the monitor callback.  In this case
2151  *    the application must call silc_client_file_close to close the
2152  *    session.
2153  *
2154  ***/
2155 SilcClientFileError 
2156 silc_client_file_receive(SilcClient client,
2157                          SilcClientConnection conn,
2158                          SilcClientFileMonitor monitor,
2159                          void *monitor_context,
2160                          const char *path,
2161                          SilcUInt32 session_id);
2162
2163 /****f* silcclient/SilcClientAPI/silc_client_file_close
2164  *
2165  * SYNOPSIS
2166  *
2167  *    SilcClientFileError silc_client_file_close(SilcClient client,
2168  *                                               SilcClientConnection conn,
2169  *                                               SilcUInt32 session_id);
2170  *
2171  * DESCRIPTION
2172  *
2173  *    Closes file transmission session indicated by the `session_id'.
2174  *    If file transmission is being conducted it will be aborted
2175  *    automatically. This function is also used to close the session
2176  *    after successful file transmission. This function can be used
2177  *    also to reject incoming file transmission request.
2178  *
2179  ***/
2180 SilcClientFileError silc_client_file_close(SilcClient client,
2181                                            SilcClientConnection conn,
2182                                            SilcUInt32 session_id);
2183
2184 #include "client.h"
2185 #include "command.h"
2186 #include "command_reply.h"
2187 #include "idlist.h"
2188 #include "protocol.h"
2189
2190 #ifdef __cplusplus
2191 }
2192 #endif
2193
2194 #endif /* SILCCLIENT_H */