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