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