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