5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2002 Pekka Riikonen
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.
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.
20 /****h* silcclient/Client Library Interface
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.
31 * o SILC Client Operations
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.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
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.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
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;
73 /* General definitions */
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
79 * typedef enum { ... } SilcKeyAgreementStatus;
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.
90 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
91 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
92 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
93 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
94 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
95 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
96 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
97 } SilcKeyAgreementStatus;
100 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
104 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
105 * SilcClientConnection conn,
106 * SilcClientEntry client_entry,
107 * SilcKeyAgreementStatus status,
108 * SilcSKEKeyMaterial *key,
113 * Key agreement callback that is called after the key agreement protocol
114 * has been performed. This is called also if error occurred during the
115 * key agreement protocol. The `key' is the allocated key material and
116 * the caller is responsible of freeing it. The `key' is NULL if error
117 * has occurred. The application can freely use the `key' to whatever
118 * purpose it needs. See lib/silcske/silcske.h for the definition of
119 * the SilcSKEKeyMaterial structure.
122 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
123 SilcClientConnection conn,
124 SilcClientEntry client_entry,
125 SilcKeyAgreementStatus status,
126 SilcSKEKeyMaterial *key,
129 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
133 * typedef struct { ... } SilcPrivateMessageKeys;
137 * Structure to hold the list of private message keys. The array of this
138 * structure is returned by the silc_client_list_private_message_keys
144 SilcClientEntry client_entry; /* The remote client entry */
145 char *cipher; /* The cipher name */
146 unsigned char *key; /* The original key, If the appliation
147 provided it. This is NULL if the
148 library generated the key or if
149 the SKE key material was used. */
150 SilcUInt32 key_len; /* The key length */
151 } *SilcPrivateMessageKeys;
154 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
158 * typedef struct { ... } SilcChannelPrivateKey;
162 * Structure to hold one channel private key. The array of this structure
163 * is returned by silc_client_list_channel_private_keys function.
167 typedef struct SilcChannelPrivateKeyStruct {
168 char *name; /* Application given name */
169 SilcCipher cipher; /* The cipher and key */
170 SilcHmac hmac; /* The HMAC and hmac key */
171 unsigned char *key; /* The key data */
172 SilcUInt32 key_len; /* The key length */
173 } *SilcChannelPrivateKey;
176 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
180 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
181 * SilcUInt32 passphrase_len,
186 * Ask passphrase callback. This is called by the application when the
187 * library calls `ask_passphrase' client operation. The callback delivers
188 * the passphrase to the library. The passphrases in SILC protocol
189 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
190 * encoded, and if it is not then library will attempt to encode it.
193 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
194 SilcUInt32 passphrase_len,
197 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
201 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
205 * Public key (or certificate) verification callback. This is called
206 * by the application to indicate that the public key verification was
207 * either success or failure.
210 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
212 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
216 * typedef void (*SilcGetAuthMeth)(bool success,
217 * SilcProtocolAuthMeth auth_meth,
218 * const unsigned char *auth_data,
219 * SilcUInt32 auth_data_len, void *context);
223 * Authentication method resolving callback. This is called by the
224 * application to return the resolved authentication method. The client
225 * library has called the get_auth_method client operation and given
226 * this function pointer as argument. The `success' will indicate whether
227 * the authentication method could be resolved. The `auth_meth' is the
228 * resolved authentication method. The `auth_data' and the `auth_data_len'
229 * are the resolved authentication data. The `context' is the libary's
230 * context sent to the get_auth_method client operation.
233 typedef void (*SilcGetAuthMeth)(bool success,
234 SilcProtocolAuthMeth auth_meth,
235 const unsigned char *auth_data,
236 SilcUInt32 auth_data_len, void *context);
238 /****d* silcclient/SilcClientAPI/SilcClientMessageType
242 * typedef enum { ... } SilcClientMessageType;
246 * Different message types for `say' client operation. The application
247 * may filter the message sent by the library according this type.
252 SILC_CLIENT_MESSAGE_INFO, /* Informational */
253 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
254 SILC_CLIENT_MESSAGE_ERROR, /* Error */
255 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
256 } SilcClientMessageType;
259 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
263 * typedef enum { ... } SilcClientConnectionStatus
267 * This type is returned to the `connect' client operation to indicate
268 * the status of the created connection. It can indicated if it was
269 * successful or whether an error occurred.
274 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
275 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
276 resumed old detached session */
277 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
278 } SilcClientConnectionStatus;
281 /****s* silcclient/SilcClientAPI/SilcClientOperations
285 * typedef struct { ... } SilcClientOperations;
289 * SILC Client Operations. These must be implemented by the application.
290 * The Client library may call any of these routines at any time. The
291 * routines are used to deliver certain information to the application
292 * or from the application to the client library.
297 /* Message sent to the application by library. `conn' associates the
298 message to a specific connection. `conn', however, may be NULL.
299 The `type' indicates the type of the message sent by the library.
300 The application can for example filter the message according the
302 void (*say)(SilcClient client, SilcClientConnection conn,
303 SilcClientMessageType type, char *msg, ...);
305 /* Message for a channel. The `sender' is the sender of the message
306 The `channel' is the channel. The `message' is the message. Note
307 that `message' maybe NULL. The `flags' indicates message flags
308 and it is used to determine how the message can be interpreted
309 (like it may tell the message is multimedia message). */
310 void (*channel_message)(SilcClient client, SilcClientConnection conn,
311 SilcClientEntry sender, SilcChannelEntry channel,
312 SilcMessageFlags flags,
313 const unsigned char *message,
314 SilcUInt32 message_len);
316 /* Private message to the client. The `sender' is the sender of the
317 message. The message is `message'and maybe NULL. The `flags'
318 indicates message flags and it is used to determine how the message
319 can be interpreted (like it may tell the message is multimedia
321 void (*private_message)(SilcClient client, SilcClientConnection conn,
322 SilcClientEntry sender, SilcMessageFlags flags,
323 const unsigned char *message,
324 SilcUInt32 message_len);
326 /* Notify message to the client. The notify arguments are sent in the
327 same order as servers sends them. The arguments are same as received
328 from the server except for ID's. If ID is received application receives
329 the corresponding entry to the ID. For example, if Client ID is received
330 application receives SilcClientEntry. Also, if the notify type is
331 for channel the channel entry is sent to application (even if server
332 does not send it because client library gets the channel entry from
333 the Channel ID in the packet's header). */
334 void (*notify)(SilcClient client, SilcClientConnection conn,
335 SilcNotifyType type, ...);
337 /* Command handler. This function is called always in the command function.
338 If error occurs it will be called as well. `conn' is the associated
339 client connection. `cmd_context' is the command context that was
340 originally sent to the command. `success' is FALSE if error occurred
341 during command. `command' is the command being processed. It must be
342 noted that this is not reply from server. This is merely called just
343 after application has called the command. Just to tell application
344 that the command really was processed. */
345 void (*command)(SilcClient client, SilcClientConnection conn,
346 SilcClientCommandContext cmd_context, bool success,
347 SilcCommand command, SilcStatus status);
349 /* Command reply handler. This function is called always in the command reply
350 function. If error occurs it will be called as well. Normal scenario
351 is that it will be called after the received command data has been parsed
352 and processed. The function is used to pass the received command data to
355 `conn' is the associated client connection. `cmd_payload' is the command
356 payload data received from server and it can be ignored. It is provided
357 if the application would like to re-parse the received command data,
358 however, it must be noted that the data is parsed already by the library
359 thus the payload can be ignored. `success' is FALSE if error occurred.
360 In this case arguments are not sent to the application. The `status' is
361 the command reply status server returned. The `command' is the command
362 reply being processed. The function has variable argument list and each
363 command defines the number and type of arguments it passes to the
364 application (on error they are not sent).
366 The arguments are sent in the same order as servers sends them. The
367 arguments are same as received from the server except for ID's. If
368 ID is received application receives the corresponding entry to the
369 ID. For example, if Client ID is receives application receives
371 void (*command_reply)(SilcClient client, SilcClientConnection conn,
372 SilcCommandPayload cmd_payload, bool success,
373 SilcCommand command, SilcStatus status, ...);
375 /* Called to indicate that connection was either successfully established
376 or connecting failed. This is also the first time application receives
377 the SilcClientConnection object which it should save somewhere.
378 The `status' indicated whether the connection were successful. If it
379 is error value the application must always call the function
380 silc_client_close_connection. */
381 void (*connect)(SilcClient client, SilcClientConnection conn,
382 SilcClientConnectionStatus status);
384 /* Called to indicate that connection was disconnected to the server.
385 The `status' may tell the reason of the disconnection, and if the
386 `message' is non-NULL it may include the disconnection message
387 received from server. */
388 void (*disconnect)(SilcClient client, SilcClientConnection conn,
389 SilcStatus status, const char *message);
391 /* Find authentication method and authentication data by hostname and
392 port. The hostname may be IP address as well. When the authentication
393 method has been resolved the `completion' callback with the found
394 authentication method and authentication data is called. The `conn'
396 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
397 char *hostname, SilcUInt16 port,
398 SilcGetAuthMeth completion, void *context);
400 /* Verifies received public key. The `conn_type' indicates which entity
401 (server, client etc.) has sent the public key. If user decides to trust
402 the application may save the key as trusted public key for later
403 use. The `completion' must be called after the public key has been
405 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
406 SilcSocketType conn_type, unsigned char *pk,
407 SilcUInt32 pk_len, SilcSKEPKType pk_type,
408 SilcVerifyPublicKey completion, void *context);
410 /* Ask (interact, that is) a passphrase from user. The passphrase is
411 returned to the library by calling the `completion' callback with
412 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
413 if not then the library will attempt to encode. */
414 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
415 SilcAskPassphrase completion, void *context);
417 /* Notifies application that failure packet was received. This is called
418 if there is some protocol active in the client. The `protocol' is the
419 protocol context. The `failure' is opaque pointer to the failure
420 indication. Note, that the `failure' is protocol dependant and
421 application must explicitly cast it to correct type. Usually `failure'
422 is 32 bit failure type (see protocol specs for all protocol failure
424 void (*failure)(SilcClient client, SilcClientConnection conn,
425 SilcProtocol protocol, void *failure);
427 /* Asks whether the user would like to perform the key agreement protocol.
428 This is called after we have received an key agreement packet or an
429 reply to our key agreement packet. This returns TRUE if the user wants
430 the library to perform the key agreement protocol and FALSE if it is not
431 desired (application may start it later by calling the function
432 silc_client_perform_key_agreement). If TRUE is returned also the
433 `completion' and `context' arguments must be set by the application. */
434 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
435 SilcClientEntry client_entry, const char *hostname,
436 SilcUInt16 port, SilcKeyAgreementCallback *completion,
439 /* Notifies application that file transfer protocol session is being
440 requested by the remote client indicated by the `client_entry' from
441 the `hostname' and `port'. The `session_id' is the file transfer
442 session and it can be used to either accept or reject the file
443 transfer request, by calling the silc_client_file_receive or
444 silc_client_file_close, respectively. */
445 void (*ftp)(SilcClient client, SilcClientConnection conn,
446 SilcClientEntry client_entry, SilcUInt32 session_id,
447 const char *hostname, SilcUInt16 port);
449 /* Delivers SILC session detachment data indicated by `detach_data' to the
450 application. If application has issued SILC_COMMAND_DETACH command
451 the client session in the SILC network is not quit. The client remains
452 in the network but is detached. The detachment data may be used later
453 to resume the session in the SILC Network. The appliation is
454 responsible of saving the `detach_data', to for example in a file.
456 The detachment data can be given as argument to the functions
457 silc_client_connect_to_server, or silc_client_add_connection when
458 creating connection to remote server, inside SilcClientConnectionParams
459 structure. If it is provided the client library will attempt to resume
460 the session in the network. After the connection is created
461 successfully, the application is responsible of setting the user
462 interface for user into the same state it was before detaching (showing
463 same channels, channel modes, etc). It can do this by fetching the
464 information (like joined channels) from the client library. */
465 void (*detach)(SilcClient client, SilcClientConnection conn,
466 const unsigned char *detach_data,
467 SilcUInt32 detach_data_len);
468 } SilcClientOperations;
471 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
475 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
476 * char **ret_nickname);
480 * A callback function provided by the application for the library in
481 * SilcClientParams structure. This function parses the formatted
482 * nickname string `nickname' and returns the true nickname to the
483 * `ret_nickname' pointer. The library can call this function at
487 typedef void (*SilcNicknameFormatParse)(const char *nickname,
488 char **ret_nickname);
490 /****s* silcclient/SilcClientAPI/SilcClientParams
494 * typedef struct { ... } SilcClientParams;
498 * Client parameters. This can be filled with proper values and
499 * given as argument to the silc_client_alloc function. The structure
500 * hold various parameters which affects the function of the client.
505 /* Number of maximum tasks the client library's scheduler can handle.
506 If set to zero, the default value will be used (200). For WIN32
507 systems this should be set to 64 as it is the hard limit dictated
511 /* Rekey timeout in seconds. The client will perform rekey in this
512 time interval. If set to zero, the default value will be used. */
513 unsigned int rekey_secs;
515 /* Connection authentication method request timeout. If server does not
516 reply back the current authentication method when we've requested it
517 in this time interval we'll assume the reply will not come at all.
518 If set to zero, the default value (2 seconds) will be used. */
519 unsigned int connauth_request_secs;
521 /* Nickname format string. This can be used to order the client library
522 to save the nicknames in the library in a certain format. Since
523 nicknames are not unique in SILC it is possible to have multiple same
524 nicknames. Using this format string it is possible to order the library
525 to separate the multiple same nicknames from each other. The format
526 types are defined below and they can appear in any order in the format
527 string. If this is NULL then default format is used which is the
528 default nickname without anything else. The string MUST be NULL
531 Following format types are available:
533 %n nickname - the real nickname returned by the server (mandatory)
534 %h hostname - the stripped hostname of the client
535 %H full hostname - the full hostname of the client
536 %s server name - the server name the client is connected
537 %S full server - the full server name the client is connected
538 %a number - ascending number in case there are several
539 same nicknames (fe. nick@host and nick@host2)
541 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
542 "%a!%n@%s" (fe. nick@server, 2!nick@server)
543 "%n@%H" (fe. nick@host.domain.com)
545 By default this format is employed to the nicknames by the libary
546 only when there appears multiple same nicknames. If the library has
547 only one nickname cached the nickname is saved as is and without the
548 defined format. If you want always to save the nickname in the defined
549 format set the boolean field `nickname_force_format' to value TRUE.
551 char nickname_format[32];
553 /* If this is set to TRUE then the `nickname_format' is employed to all
554 saved nicknames even if there are no multiple same nicknames in the
555 cache. By default this is FALSE, which means that the `nickname_format'
556 is employed only if the library will receive a nickname that is
557 already saved in the cache. It is recommended to leave this to FALSE
559 bool nickname_force_format;
561 /* A callback function provided by the application for the library to
562 parse the nickname from the formatted nickname string. Even though
563 the libary formats the nicknames the application knows generally the
564 format better so this function should be provided for the library
565 if the application sets the `nickname_format' field. The library
566 will call this to get the true nickname from the provided formatted
567 nickname string whenever it needs the true nickname. */
568 SilcNicknameFormatParse nickname_parse;
570 /* If this is set to TRUE then the client will ignore all incoming
571 Requested Attributes queries and does not reply anything back. This
572 usually leads into situation where server does not anymore send
573 the queries after seeing that client does not reply anything back.
574 If your application does not support Requested Attributes or you do
575 not want to use them set this to TRUE. See SilcAttribute and
576 silc_client_attribute_add for more information on attributes. */
577 bool ignore_requested_attributes;
583 /* Initialization functions (client.c) */
585 /****f* silcclient/SilcClientAPI/silc_client_alloc
589 * SilcClient silc_client_alloc(SilcClientOperations *ops,
590 * SilcClientParams *params,
592 * const char *silc_version);
596 * Allocates new client object. This has to be done before client may
597 * work. After calling this one must call silc_client_init to initialize
598 * the client. The `application' is application specific user data pointer
599 * and caller must free it. The `silc_version' is the application version
600 * that will be used to compare against remote host's (usually a server)
601 * version string. The `application' context is accessible by the
602 * application by client->application, client being SilcClient.
605 SilcClient silc_client_alloc(SilcClientOperations *ops,
606 SilcClientParams *params,
608 const char *silc_version);
610 /****f* silcclient/SilcClientAPI/silc_client_free
614 * void silc_client_free(SilcClient client);
618 * Frees client object and its internals. The execution of the client
619 * should be stopped with silc_client_stop function before calling
623 void silc_client_free(SilcClient client);
625 /****f* silcclient/SilcClientAPI/silc_client_init
629 * int silc_client_init(SilcClient client);
633 * Initializes the client. This makes all the necessary steps to make
634 * the client ready to be run. One must call silc_client_run to run the
635 * client. Returns FALSE if error occurred, TRUE otherwise.
638 int silc_client_init(SilcClient client);
640 /****f* silcclient/SilcClientAPI/silc_client_run
644 * void silc_client_run(SilcClient client);
648 * Runs the client. This starts the scheduler from the utility library.
649 * When this functions returns the execution of the appliation is over.
652 void silc_client_run(SilcClient client);
654 /****f* silcclient/SilcClientAPI/silc_client_run_one
658 * void silc_client_run_one(SilcClient client);
662 * Runs the client and returns immeadiately. This function is used when
663 * the SILC Client object indicated by the `client' is run under some
664 * other scheduler, or event loop or main loop. On GUI applications,
665 * for example this may be desired to used to run the client under the
666 * GUI application's main loop. Typically the GUI application would
667 * register an idle task that calls this function multiple times in
668 * a second to quickly process the SILC specific data.
671 void silc_client_run_one(SilcClient client);
673 /****f* silcclient/SilcClientAPI/silc_client_stop
677 * void silc_client_stop(SilcClient client);
681 * Stops the client. This is called to stop the client and thus to stop
682 * the program. The client context must be freed with the silc_client_free
686 void silc_client_stop(SilcClient client);
689 /* Connecting functions (client.c) */
691 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
695 * typedef struct { ... } SilcClientConnectionParams;
699 * Client connection parameters. This can be filled by the application
700 * and given as argument to silc_client_connect_to_server or to
701 * silc_client_add_connection.
706 /* The SILC session detachment data that was returned by `detach' client
707 operation when the application detached from the network. Application
708 is responsible of saving the data and giving it as argument here
709 for resuming the session in the SILC network.
711 If this is provided here the client library will attempt to resume
712 the session in the network. After the connection is created
713 successfully, the application is responsible of setting the user
714 interface for user into the same state it was before detaching (showing
715 same channels, channel modes, etc). It can do this by fetching the
716 information (like joined channels) from the client library. */
717 unsigned char *detach_data;
718 SilcUInt32 detach_data_len;
720 } SilcClientConnectionParams;
723 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
727 * int silc_client_connect_to_server(SilcClient client,
728 * SilcClientConnectionParams *params,
729 * int port, char *host, void *context);
733 * Connects to remote server. This is the main routine used to connect
734 * to SILC server. Returns -1 on error and the created socket otherwise.
735 * The `context' is user context that is saved into the SilcClientConnection
736 * that is created after the connection is created. Note that application
737 * may handle the connecting process outside the library. If this is the
738 * case then this function is not used at all. When the connecting is
739 * done the `connect' client operation is called, and the `context' is
740 * accessible with conn->context, conn being SilcClientConnection.
741 * If the `params' is provided they are used by the routine.
744 int silc_client_connect_to_server(SilcClient client,
745 SilcClientConnectionParams *params,
746 int port, char *host, void *context);
748 /****f* silcclient/SilcClientAPI/silc_client_add_connection
753 * SilcClientConnection
754 * silc_client_add_connection(SilcClient client,
755 * SilcClientConnectionParams *params,
756 * char *hostname, int port, void *context);
760 * Allocates and adds new connection to the client. This adds the allocated
761 * connection to the connection table and returns a pointer to it. A client
762 * can have multiple connections to multiple servers. Every connection must
763 * be added to the client using this function. User data `context' may
764 * be sent as argument. If the `params' is provided they are used by
769 * This function is normally used only if the application performed
770 * the connecting outside the library, and did not called the
771 * silc_client_connect_to_server function at all. The library
772 * however may use this internally.
776 silc_client_add_connection(SilcClient client,
777 SilcClientConnectionParams *params,
778 char *hostname, int port, void *context);
780 /****f* silcclient/SilcClientAPI/silc_client_del_connection
784 * void silc_client_del_connection(SilcClient client,
785 * SilcClientConnection conn);
789 * Removes connection from client. Frees all memory. The library
790 * call this function automatically for all connection contexts.
791 * The application however may free the connection contexts it has
795 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
797 /****f* silcclient/SilcClientAPI/silc_client_add_socket
801 * void silc_client_add_socket(SilcClient client,
802 * SilcSocketConnection sock);
806 * Adds listener socket to the listener sockets table. This function is
807 * used to add socket objects that are listeners to the client. This should
808 * not be used to add other connection objects.
811 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
813 /****f* silcclient/SilcClientAPI/silc_client_del_socket
817 * void silc_client_del_socket(SilcClient client,
818 * SilcSocketConnection sock);
822 * Deletes listener socket from the listener sockets table. If the
823 * application has added a socket with silc_client_add_socket it must
824 * also free it using this function.
827 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
829 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
833 * void silc_client_start_key_exchange(SilcClient client,
834 * SilcClientConnection conn,
839 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
840 * key material between client and server. This function can be called
841 * directly if application is performing its own connecting and does not
842 * use the connecting provided by this library. This function is normally
843 * used only if the application performed the connecting outside the
844 * library. The library however may use this internally. After the
845 * key exchange is performed the `connect' client operation is called.
848 void silc_client_start_key_exchange(SilcClient client,
849 SilcClientConnection conn,
852 /****f* silcclient/SilcClientAPI/silc_client_close_connection
856 * void silc_client_close_connection(SilcClient client,
857 * SilcClientConnection conn);
861 * Closes connection to remote end. Free's all allocated data except
862 * for some information such as nickname etc. that are valid at all time.
865 void silc_client_close_connection(SilcClient client,
866 SilcClientConnection conn);
869 /* Message sending functions (client_channel.c and client_prvmsg.c) */
871 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
875 * void silc_client_send_channel_message(SilcClient client,
876 * SilcClientConnection conn,
877 * SilcChannelEntry channel,
878 * SilcChannelPrivateKey key,
879 * SilcMessageFlags flags,
880 * unsigned char *data,
881 * SilcUInt32 data_len,
886 * Sends packet to the `channel'. Packet to channel is always encrypted
887 * differently from "normal" packets. SILC header of the packet is
888 * encrypted with the next receiver's key and the rest of the packet is
889 * encrypted with the channel specific key. Padding and HMAC is computed
890 * with the next receiver's key. The `data' is the channel message. If
891 * the `force_send' is TRUE then the packet is sent immediately.
893 * If `key' is provided then that private key is used to encrypt the
894 * channel message. If it is not provided, private keys has not been
895 * set at all, the normal channel key is used automatically. If private
896 * keys are set then the first key (the key that was added first as
897 * private key) is used.
900 void silc_client_send_channel_message(SilcClient client,
901 SilcClientConnection conn,
902 SilcChannelEntry channel,
903 SilcChannelPrivateKey key,
904 SilcMessageFlags flags,
909 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
913 * void silc_client_send_private_message(SilcClient client,
914 * SilcClientConnection conn,
915 * SilcClientEntry client_entry,
916 * SilcMessageFlags flags,
917 * unsigned char *data,
918 * SilcUInt32 data_len,
923 * Sends private message to remote client. If private message key has
924 * not been set with this client then the message will be encrypted using
925 * normal session keys. Private messages are special packets in SILC
926 * network hence we need this own function for them. This is similar
927 * to silc_client_packet_send_to_channel except that we send private
928 * message. The `data' is the private message. If the `force_send' is
929 * TRUE the packet is sent immediately.
932 void silc_client_send_private_message(SilcClient client,
933 SilcClientConnection conn,
934 SilcClientEntry client_entry,
935 SilcMessageFlags flags,
941 /* Client and Channel entry retrieval (idlist.c) */
943 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
947 * typedef void (*SilcGetClientCallback)(SilcClient client,
948 * SilcClientConnection conn,
949 * SilcClientEntry *clients,
950 * SilcUInt32 clients_count,
955 * Callback function given to the silc_client_get_client function. The
956 * found entries are allocated into the `clients' array. The array must
957 * not be freed by the receiver, the library will free it later. If the
958 * `clients' is NULL, no such clients exist in the SILC Network.
961 typedef void (*SilcGetClientCallback)(SilcClient client,
962 SilcClientConnection conn,
963 SilcClientEntry *clients,
964 SilcUInt32 clients_count,
967 /****f* silcclient/SilcClientAPI/silc_client_get_clients
971 * void silc_client_get_clients(SilcClient client,
972 * SilcClientConnection conn,
973 * const char *nickname,
974 * const char *server,
975 * SilcGetClientCallback completion,
980 * Finds client entry or entries by the `nickname' and `server'. The
981 * completion callback will be called when the client entries has been
982 * found. After the server returns the client information it is cached
983 * and can be accesses locally at a later time.
987 * NOTE: This function is always asynchronous and resolves the client
988 * information from the server. Thus, if you already know the client
989 * information then use the silc_client_get_client_by_id function to
990 * get the client entry since this function may be very slow and should
991 * be used only to initially get the client entries.
994 void silc_client_get_clients(SilcClient client,
995 SilcClientConnection conn,
996 const char *nickname,
998 SilcGetClientCallback completion,
1001 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1005 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1006 * SilcClientConnection conn,
1007 * const char *nickname,
1008 * const char *format,
1009 * SilcUInt32 *clients_count);
1013 * Same as silc_client_get_clients function but does not resolve anything
1014 * from the server. This checks local cache and returns all matching
1015 * clients from the local cache. If none was found this returns NULL.
1016 * The `nickname' is the real nickname of the client, and the `format'
1017 * is the formatted nickname to find exact match from multiple found
1018 * entries. The format must be same as given in the SilcClientParams
1019 * structure to the client library. If the `format' is NULL all found
1020 * clients by `nickname' are returned. The caller must return the
1024 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1025 SilcClientConnection conn,
1026 const char *nickname,
1028 SilcUInt32 *clients_count);
1030 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1034 * void silc_client_get_clients_by_list(SilcClient client,
1035 * SilcClientConnection conn,
1036 * SilcUInt32 list_count,
1037 * SilcBuffer client_id_list,
1038 * SilcGetClientCallback completion,
1043 * Gets client entries by the list of client ID's `client_id_list'. This
1044 * always resolves those client ID's it does not know yet from the server
1045 * so this function might take a while. The `client_id_list' is a list
1046 * of ID Payloads added one after other. JOIN command reply and USERS
1047 * command reply for example returns this sort of list. The `completion'
1048 * will be called after the entries are available. When server returns
1049 * the client information it will be cached and can be accessed locally
1053 void silc_client_get_clients_by_list(SilcClient client,
1054 SilcClientConnection conn,
1055 SilcUInt32 list_count,
1056 SilcBuffer client_id_list,
1057 SilcGetClientCallback completion,
1060 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1064 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1065 * SilcClientConnection conn,
1066 * SilcClientID *client_id);
1070 * Find entry for client by the client's ID. Returns the entry or NULL
1071 * if the entry was not found. This checks the local cache and does
1072 * not resolve anything from server.
1075 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1076 SilcClientConnection conn,
1077 SilcClientID *client_id);
1079 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1084 * silc_client_get_client_by_id_resolve(SilcClient client,
1085 * SilcClientConnection conn,
1086 * SilcClientID *client_id,
1087 * SilcBuffer attributes,
1088 * SilcGetClientCallback completion,
1093 * Same as silc_client_get_client_by_id but will always resolve the
1094 * information from the server. Use this only if you know that you
1095 * do not have the entry and the only thing you know about the client
1096 * is its ID. When server returns the client information it will be
1097 * cache and can be accessed locally at a later time.
1099 * If the `attributes' is non-NULL then the buffer includes Requested
1100 * Attributes which can be used to fetch very detailed information
1101 * about the user. If it is NULL then only normal WHOIS query is
1102 * made (for more information about attributes see SilcAttribute).
1103 * Caller may create the `attributes' with silc_client_attributes_request
1107 void silc_client_get_client_by_id_resolve(SilcClient client,
1108 SilcClientConnection conn,
1109 SilcClientID *client_id,
1110 SilcBuffer attributes,
1111 SilcGetClientCallback completion,
1114 /****f* silcclient/SilcClientAPI/silc_client_del_client
1118 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1119 * SilcClientEntry client_entry)
1123 * Removes client from local cache by the client entry indicated by
1124 * the `client_entry'. Returns TRUE if the deletion were successful.
1127 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1128 SilcClientEntry client_entry);
1130 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1134 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1135 * SilcClientConnection conn,
1136 * SilcChannelEntry *channels,
1137 * SilcUInt32 channels_count,
1142 * Callback function given to the silc_client_get_channel_* functions.
1143 * The found entries are allocated into the `channels' array. The array
1144 * must not be freed by the receiver, the library will free it later.
1145 * If the `channel' is NULL, no such channel exist in the SILC Network.
1148 typedef void (*SilcGetChannelCallback)(SilcClient client,
1149 SilcClientConnection conn,
1150 SilcChannelEntry *channels,
1151 SilcUInt32 channels_count,
1154 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1158 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1159 * SilcClientConnection conn,
1164 * Finds entry for channel by the channel name. Returns the entry or NULL
1165 * if the entry was not found. It is found only if the client is joined
1169 SilcChannelEntry silc_client_get_channel(SilcClient client,
1170 SilcClientConnection conn,
1173 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1178 * silc_client_get_channel_by_id(SilcClient client,
1179 * SilcClientConnection conn,
1180 * SilcChannelID *channel_id);
1184 * Finds channel entry by the channel name. Returns the entry or NULL
1185 * if it was not found.
1188 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1189 SilcClientConnection conn,
1190 SilcChannelID *channel_id);
1192 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1197 * silc_client_get_channel_by_id_resolve(SilcClient client,
1198 * SilcClientConnection conn,
1199 * SilcChannelID *channel_id,
1200 * SilcGetClientCallback completion,
1205 * Resolves the channel information (its name mainly) from the server
1206 * by the `channel_id'. Use this only if you know that you do not have
1207 * the entry cached locally.
1210 void silc_client_get_channel_by_id_resolve(SilcClient client,
1211 SilcClientConnection conn,
1212 SilcChannelID *channel_id,
1213 SilcGetChannelCallback completion,
1216 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1220 * bool silc_client_del_channel(SilcClient client,
1221 * SilcClientConnection conn,
1222 * SilcChannelEntry channel)
1226 * Removes channel from local cache by the channel entry indicated by
1227 * the `channel'. Returns TRUE if the deletion were successful.
1230 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1231 SilcChannelEntry channel);
1233 /****f* silcclient/SilcClientAPI/silc_client_get_server
1237 * SilcServerEntry silc_client_get_server(SilcClient client,
1238 * SilcClientConnection conn,
1239 * char *server_name)
1243 * Finds entry for server by the server name. Returns the entry or NULL
1244 * if the entry was not found.
1247 SilcServerEntry silc_client_get_server(SilcClient client,
1248 SilcClientConnection conn,
1251 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1255 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1256 * SilcClientConnection conn,
1257 * SilcServerID *server_id);
1261 * Finds entry for server by the server ID. Returns the entry or NULL
1262 * if the entry was not found.
1265 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1266 SilcClientConnection conn,
1267 SilcServerID *server_id);
1269 /****f* silcclient/SilcClientAPI/silc_client_del_server
1273 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1274 * SilcServerEntry server);
1278 * Removes server from local cache by the server entry indicated by
1279 * the `server'. Returns TRUE if the deletion were successful.
1282 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1283 SilcServerEntry server);
1285 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1289 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1290 * SilcClientEntry client_entry);
1294 * Returns the ChannelUser entry if the `client_entry' is joined on the
1295 * channel indicated by the `channel'. NULL if client is not joined on
1299 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1300 SilcClientEntry client_entry);
1302 /* Command management (command.c) */
1304 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1308 * SilcClientCommandContext silc_client_command_alloc(void);
1312 * Allocate Command Context. The context is defined in `command.h' file.
1313 * The context is used by the library commands and applications should use
1314 * it as well. However, application may choose to use some own context
1315 * for its local commands. All library commands, however, must use this
1319 SilcClientCommandContext silc_client_command_alloc(void);
1321 /****f* silcclient/SilcClientAPI/silc_client_command_free
1325 * void silc_client_command_free(SilcClientCommandContext ctx);
1329 * Free command context and its internals. If the contex was duplicated
1330 * with silc_client_command_dup this may not actually free the data,
1331 * instead it will decrease the reference counter of the context. The
1332 * context will be freed when the reference counter hits zero.
1335 void silc_client_command_free(SilcClientCommandContext ctx);
1337 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1341 * SilcClientCommandContext
1342 * silc_client_command_dup(SilcClientCommandContext ctx);
1346 * Duplicate Command Context by adding reference counter. The context won't
1347 * be free'd untill it hits zero.
1350 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1352 /****f* silcclient/SilcClientAPI/silc_client_command_find
1356 * SilcClientCommand silc_client_command_find(SilcClient client,
1357 * const char *name);
1361 * Finds and returns a pointer to the command list. Return NULL if the
1362 * command is not found. See the `command.[ch]' for the command list.
1363 * Command names are not case-sensitive.
1366 SilcClientCommand silc_client_command_find(SilcClient client,
1369 /****f* silcclient/SilcClientAPI/silc_client_command_call
1373 * void silc_client_command_call(SilcClientCommand command);
1377 * Calls the command (executes it). Application can call this after
1378 * it has allocated the SilcClientCommandContext with the function
1379 * silc_client_command_alloc and found the command from the client
1380 * library by calling silc_client_command_find. This will execute
1383 * Application can call the command function directly too if it
1384 * wishes to do so. See the command.h for details of the
1385 * SilcClientCommand structure.
1388 void silc_client_command_call(SilcClientCommand command,
1389 SilcClientCommandContext cmd);
1391 /****f* silcclient/SilcClientAPI/silc_client_command_send
1395 * void silc_client_command_send(SilcClient client,
1396 * SilcClientConnection conn,
1397 * SilcCommand command, SilcUInt16 ident,
1398 * SilcUInt32 argc, ...);
1402 * Generic function to send any command. The arguments must be sent already
1403 * encoded into correct form and in correct order. If application wants
1404 * to perform the commands by itself, it can do so and send the data
1405 * directly to the server using this function. If application is using
1406 * the silc_client_command_call, this function is usually not used.
1409 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1410 SilcCommand command, SilcUInt16 ident,
1411 SilcUInt32 argc, ...);
1413 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1417 * void silc_client_command_pending(SilcClientConnection conn,
1418 * SilcCommand reply_cmd,
1420 * SilcCommandCb callback,
1425 * Add new pending command to be executed when reply to a command has been
1426 * received. The `reply_cmd' is the command that will call the `callback'
1427 * with `context' when reply has been received. If `ident' is non-zero
1428 * the `callback' will be executed when received reply with command
1429 * identifier `ident'.
1431 * Note that the application is notified about the received command
1432 * reply through the `command_reply' client operation before calling
1433 * the `callback` pending command callback.
1436 void silc_client_command_pending(SilcClientConnection conn,
1437 SilcCommand reply_cmd,
1439 SilcCommandCb callback,
1443 /* Private Message key management (client_prvmsg.c) */
1445 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1449 * int silc_client_add_private_message_key(SilcClient client,
1450 * SilcClientConnection conn,
1451 * SilcClientEntry client_entry,
1453 * unsigned char *key,
1454 * SilcUInt32 key_len,
1455 * bool generate_key,
1460 * Adds private message key to the client library. The key will be used to
1461 * encrypt all private message between the client and the remote client
1462 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1463 * value `generate_key' is TRUE the library will generate random key.
1464 * The `key' maybe for example pre-shared-key, passphrase or similar.
1465 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1466 * requirements of the SILC protocol are met. The API, however, allows
1467 * to allocate any cipher.
1469 * If `responder' is TRUE then the sending and receiving keys will be
1470 * set according the client being the receiver of the private key. If
1471 * FALSE the client is being the sender (or negotiator) of the private
1474 * It is not necessary to set key for normal private message usage. If the
1475 * key is not set then the private messages are encrypted using normal
1476 * session keys. Setting the private key, however, increases the security.
1478 * Returns FALSE if the key is already set for the `client_entry', TRUE
1482 int silc_client_add_private_message_key(SilcClient client,
1483 SilcClientConnection conn,
1484 SilcClientEntry client_entry,
1491 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1495 * int silc_client_add_private_message_key_ske(SilcClient client,
1496 * SilcClientConnection conn,
1497 * SilcClientEntry client_entry,
1499 * SilcSKEKeyMaterial *key);
1503 * Same as silc_client_add_private_message_key but takes the key material
1504 * from the SKE key material structure. This structure is received if
1505 * the application uses the silc_client_send_key_agreement to negotiate
1506 * the key material. The `cipher' SHOULD be provided as it is negotiated
1507 * also in the SKE protocol.
1510 int silc_client_add_private_message_key_ske(SilcClient client,
1511 SilcClientConnection conn,
1512 SilcClientEntry client_entry,
1514 SilcSKEKeyMaterial *key,
1517 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1521 * int silc_client_del_private_message_key(SilcClient client,
1522 * SilcClientConnection conn,
1523 * SilcClientEntry client_entry);
1527 * Removes the private message from the library. The key won't be used
1528 * after this to protect the private messages with the remote `client_entry'
1529 * client. Returns FALSE on error, TRUE otherwise.
1532 int silc_client_del_private_message_key(SilcClient client,
1533 SilcClientConnection conn,
1534 SilcClientEntry client_entry);
1536 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1540 * SilcPrivateMessageKeys
1541 * silc_client_list_private_message_keys(SilcClient client,
1542 * SilcClientConnection conn,
1543 * SilcUInt32 *key_count);
1547 * Returns array of set private message keys associated to the connection
1548 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1549 * count to the `key_count' argument. The array must be freed by the caller
1550 * by calling the silc_client_free_private_message_keys function. Note:
1551 * the keys returned in the array is in raw format. It might not be desired
1552 * to show the keys as is. The application might choose not to show the keys
1553 * at all or to show the fingerprints of the keys.
1556 SilcPrivateMessageKeys
1557 silc_client_list_private_message_keys(SilcClient client,
1558 SilcClientConnection conn,
1559 SilcUInt32 *key_count);
1561 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1565 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1566 * SilcUInt32 key_count);
1570 * Frees the SilcPrivateMessageKeys array returned by the function
1571 * silc_client_list_private_message_keys.
1574 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1575 SilcUInt32 key_count);
1578 /* Channel private key management (client_channel.c,
1579 SilcChannelPrivateKey is defined in idlist.h) */
1581 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1585 * int silc_client_add_channel_private_key(SilcClient client,
1586 * SilcClientConnection conn,
1587 * SilcChannelEntry channel,
1591 * unsigned char *key,
1592 * SilcUInt32 key_len);
1596 * Adds private key for channel. This may be set only if the channel's mode
1597 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1598 * mode is not set. When channel has private key then the messages are
1599 * encrypted using that key. All clients on the channel must also know the
1600 * key in order to decrypt the messages. However, it is possible to have
1601 * several private keys per one channel. In this case only some of the
1602 * clients on the channel may know the one key and only some the other key.
1603 * The `name' can be application given name for the key.
1605 * The private key for channel is optional. If it is not set then the
1606 * channel messages are encrypted using the channel key generated by the
1607 * server. However, setting the private key (or keys) for the channel
1608 * significantly adds security. If more than one key is set the library
1609 * will automatically try all keys at the message decryption phase. Note:
1610 * setting many keys slows down the decryption phase as all keys has to
1611 * be tried in order to find the correct decryption key. However, setting
1612 * a few keys does not have big impact to the decryption performace.
1616 * NOTE: This is entirely local setting. The key set using this function
1617 * is not sent to the network at any phase.
1619 * NOTE: If the key material was originated by the SKE protocol (using
1620 * silc_client_send_key_agreement) then the `key' MUST be the
1621 * key->send_enc_key as this is dictated by the SILC protocol. However,
1622 * currently it is not expected that the SKE key material would be used
1623 * as channel private key. However, this API allows it.
1626 int silc_client_add_channel_private_key(SilcClient client,
1627 SilcClientConnection conn,
1628 SilcChannelEntry channel,
1633 SilcUInt32 key_len);
1635 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1639 * int silc_client_del_channel_private_keys(SilcClient client,
1640 * SilcClientConnection conn,
1641 * SilcChannelEntry channel);
1645 * Removes all private keys from the `channel'. The old channel key is used
1646 * after calling this to protect the channel messages. Returns FALSE on
1647 * on error, TRUE otherwise.
1650 int silc_client_del_channel_private_keys(SilcClient client,
1651 SilcClientConnection conn,
1652 SilcChannelEntry channel);
1654 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1658 * int silc_client_del_channel_private_key(SilcClient client,
1659 * SilcClientConnection conn,
1660 * SilcChannelEntry channel,
1661 * SilcChannelPrivateKey key);
1665 * Removes and frees private key `key' from the channel `channel'.
1666 * The `key' is retrieved by calling the function
1667 * silc_client_list_channel_private_keys. The key is not used after
1668 * this. If the key was last private key then the old channel key is
1669 * used hereafter to protect the channel messages. This returns FALSE
1670 * on error, TRUE otherwise.
1673 int silc_client_del_channel_private_key(SilcClient client,
1674 SilcClientConnection conn,
1675 SilcChannelEntry channel,
1676 SilcChannelPrivateKey key);
1678 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1682 * SilcChannelPrivateKey *
1683 * silc_client_list_channel_private_keys(SilcClient client,
1684 * SilcClientConnection conn,
1685 * SilcChannelEntry channel,
1686 * SilcUInt32 *key_count);
1690 * Returns array (pointers) of private keys associated to the `channel'.
1691 * The caller must free the array by calling the function
1692 * silc_client_free_channel_private_keys. The pointers in the array may be
1693 * used to delete the specific key by giving the pointer as argument to the
1694 * function silc_client_del_channel_private_key.
1697 SilcChannelPrivateKey *
1698 silc_client_list_channel_private_keys(SilcClient client,
1699 SilcClientConnection conn,
1700 SilcChannelEntry channel,
1701 SilcUInt32 *key_count);
1703 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1707 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1708 * SilcUInt32 key_count);
1712 * Frees the SilcChannelPrivateKey array.
1715 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1716 SilcUInt32 key_count);
1718 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1722 * void silc_client_current_channel_private_key(SilcClient client,
1723 * SilcClientConnection conn,
1724 * SilcChannelEntry channel,
1725 * SilcChannelPrivateKey key);
1729 * Sets the `key' to be used as current channel private key on the
1730 * `channel'. Packet sent after calling this function will be secured
1734 void silc_client_current_channel_private_key(SilcClient client,
1735 SilcClientConnection conn,
1736 SilcChannelEntry channel,
1737 SilcChannelPrivateKey key);
1740 /* Key Agreement routines (client_keyagr.c) */
1742 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1746 * void silc_client_send_key_agreement(SilcClient client,
1747 * SilcClientConnection conn,
1748 * SilcClientEntry client_entry,
1751 * SilcUInt32 timeout_secs,
1752 * SilcKeyAgreementCallback completion,
1757 * Sends key agreement request to the remote client indicated by the
1758 * `client_entry'. If the caller provides the `hostname' and the `port'
1759 * arguments then the library will bind the client to that hostname and
1760 * that port for the key agreement protocol. It also sends the `hostname'
1761 * and the `port' in the key agreement packet to the remote client. This
1762 * would indicate that the remote client may initiate the key agreement
1763 * protocol to the `hostname' on the `port'. If port is zero then the
1764 * bound port is undefined (the operating system defines it).
1766 * If the `hostname' and `port' is not provided then empty key agreement
1767 * packet is sent to the remote client. The remote client may reply with
1768 * the same packet including its hostname and port. If the library receives
1769 * the reply from the remote client the `key_agreement' client operation
1770 * callback will be called to verify whether the user wants to perform the
1771 * key agreement or not.
1775 * NOTE: If the application provided the `hostname' and the `port' and the
1776 * remote side initiates the key agreement protocol it is not verified
1777 * from the user anymore whether the protocol should be executed or not.
1778 * By setting the `hostname' and `port' the user gives permission to
1779 * perform the protocol (we are responder in this case).
1781 * NOTE: If the remote side decides not to initiate the key agreement
1782 * or decides not to reply with the key agreement packet then we cannot
1783 * perform the key agreement at all. If the key agreement protocol is
1784 * performed the `completion' callback with the `context' will be called.
1785 * If remote side decides to ignore the request the `completion' will be
1786 * called after the specified timeout, `timeout_secs'.
1788 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1789 * will not be called at all since this does nothing more than sending
1790 * a packet to the remote host.
1792 * NOTE: There can be only one active key agreement for one client entry.
1793 * Before setting new one, the old one must be finished (it is finished
1794 * after calling the completion callback) or the function
1795 * silc_client_abort_key_agreement must be called.
1798 void silc_client_send_key_agreement(SilcClient client,
1799 SilcClientConnection conn,
1800 SilcClientEntry client_entry,
1801 const char *hostname,
1802 const char *bindhost,
1804 SilcUInt32 timeout_secs,
1805 SilcKeyAgreementCallback completion,
1808 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1813 * silc_client_perform_key_agreement(SilcClient client,
1814 * SilcClientConnection conn,
1815 * SilcClientEntry client_entry,
1818 * SilcKeyAgreementCallback completion,
1823 * Performs the actual key agreement protocol. Application may use this
1824 * to initiate the key agreement protocol. This can be called for example
1825 * after the application has received the `key_agreement' client operation,
1826 * and did not return TRUE from it.
1828 * The `hostname' is the remote hostname (or IP address) and the `port'
1829 * is the remote port. The `completion' callback with the `context' will
1830 * be called after the key agreement protocol.
1834 * NOTE: If the application returns TRUE in the `key_agreement' client
1835 * operation the library will automatically start the key agreement. In this
1836 * case the application must not call this function. However, application
1837 * may choose to just ignore the `key_agreement' client operation (and
1838 * merely just print information about it on the screen) and call this
1839 * function when the user whishes to do so (by, for example, giving some
1840 * specific command). Thus, the API provides both, automatic and manual
1841 * initiation of the key agreement. Calling this function is the manual
1842 * initiation and returning TRUE in the `key_agreement' client operation
1843 * is the automatic initiation.
1846 void silc_client_perform_key_agreement(SilcClient client,
1847 SilcClientConnection conn,
1848 SilcClientEntry client_entry,
1851 SilcKeyAgreementCallback completion,
1854 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1859 * silc_client_perform_key_agreement_fd(SilcClient client,
1860 * SilcClientConnection conn,
1861 * SilcClientEntry client_entry,
1864 * SilcKeyAgreementCallback completion,
1869 * Same as above but application has created already the connection to
1870 * the remote host. The `sock' is the socket to the remote connection.
1871 * Application can use this function if it does not want the client library
1872 * to create the connection.
1875 void silc_client_perform_key_agreement_fd(SilcClient client,
1876 SilcClientConnection conn,
1877 SilcClientEntry client_entry,
1880 SilcKeyAgreementCallback completion,
1883 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1887 * void silc_client_abort_key_agreement(SilcClient client,
1888 * SilcClientConnection conn,
1889 * SilcClientEntry client_entry);
1893 * This function can be called to unbind the hostname and the port for
1894 * the key agreement protocol. However, this function has effect only
1895 * before the key agreement protocol has been performed. After it has
1896 * been performed the library will automatically unbind the port. The
1897 * `client_entry' is the client to which we sent the key agreement
1898 * request. The key agreement completion callback will be called
1899 * with SILC_KEY_AGREEMENT_ABORTED status.
1902 void silc_client_abort_key_agreement(SilcClient client,
1903 SilcClientConnection conn,
1904 SilcClientEntry client_entry);
1907 /* Misc functions */
1909 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1913 * void silc_client_set_away_message(SilcClient client,
1914 * SilcClientConnection conn,
1919 * Sets away `message'. The away message may be set when the client's
1920 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1921 * to anyone who sends private message. The `message' will be sent
1922 * automatically back to the the client who send private message. If
1923 * away message is already set this replaces the old message with the
1924 * new one. If `message' is NULL the old away message is removed.
1925 * The sender may freely free the memory of the `message'.
1928 void silc_client_set_away_message(SilcClient client,
1929 SilcClientConnection conn,
1933 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1937 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1938 * SilcClientConnection conn,
1939 * SilcAuthMethod auth_meth,
1944 * Connection authentication method request callback. This is called
1945 * by the client library after it has received the authentication method
1946 * that the application requested by calling the function
1947 * silc_client_request_authentication_method.
1950 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1951 SilcClientConnection conn,
1952 SilcAuthMethod auth_meth,
1955 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1960 * silc_client_request_authentication_method(SilcClient client,
1961 * SilcClientConnection conn,
1962 * SilcConnectionAuthRequest
1968 * This function can be used to request the current authentication method
1969 * from the server. This may be called when connecting to the server
1970 * and the client library requests the authentication data from the
1971 * application. If the application does not know the current authentication
1972 * method it can request it from the server using this function.
1973 * The `callback' with `context' will be called after the server has
1974 * replied back with the current authentication method.
1978 silc_client_request_authentication_method(SilcClient client,
1979 SilcClientConnection conn,
1980 SilcConnectionAuthRequest callback,
1983 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1987 * typedef enum { ... } SilcClientMonitorStatus;
1991 * File transmission session status types. These will indicate
1992 * the status of the file transmission session.
1997 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1998 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1999 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2000 SILC_CLIENT_FILE_MONITOR_GET,
2001 SILC_CLIENT_FILE_MONITOR_PUT,
2002 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2003 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2004 } SilcClientMonitorStatus;
2007 /****d* silcclient/SilcClientAPI/SilcClientFileError
2011 * typedef enum { ... } SilcClientFileError;
2015 * File transmission error types. These types are returned by
2016 * some of the file transmission functions, and by the monitor
2017 * callback to indicate error.
2022 SILC_CLIENT_FILE_OK,
2023 SILC_CLIENT_FILE_ERROR,
2024 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2025 SILC_CLIENT_FILE_ALREADY_STARTED,
2026 SILC_CLIENT_FILE_NO_SUCH_FILE,
2027 SILC_CLIENT_FILE_PERMISSION_DENIED,
2028 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2029 } SilcClientFileError;
2032 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2036 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2037 * SilcClientConnection conn,
2038 * SilcClientMonitorStatus status,
2039 * SilcClientFileError error,
2040 * SilcUInt64 offset,
2041 * SilcUInt64 filesize,
2042 * SilcClientEntry client_entry,
2043 * SilcUInt32 session_id,
2044 * const char *filepath,
2049 * Monitor callback that is called during the file transmission to
2050 * monitor the transmission process. The `status' indicates the current
2051 * monitoring process. The `error' will indicate the error type
2052 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2053 * currently transmitted amount of total `filesize'. The `client_entry'
2054 * indicates the remote client, and the transmission session ID is the
2055 * `session_id'. The filename being transmitted is indicated by the
2059 typedef void (*SilcClientFileMonitor)(SilcClient client,
2060 SilcClientConnection conn,
2061 SilcClientMonitorStatus status,
2062 SilcClientFileError error,
2064 SilcUInt64 filesize,
2065 SilcClientEntry client_entry,
2066 SilcUInt32 session_id,
2067 const char *filepath,
2070 /****f* silcclient/SilcClientAPI/silc_client_file_send
2074 * SilcClientFileError
2075 * silc_client_file_send(SilcClient client,
2076 * SilcClientConnection conn,
2077 * SilcClientFileMonitor monitor,
2078 * void *monitor_context,
2079 * const char *local_ip,
2080 * SilcUInt32 local_port,
2081 * SilcClientEntry client_entry,
2082 * const char *filepath);
2083 * SilcUInt32 *session_id);
2087 * Sends a file indicated by the `filepath' to the remote client
2088 * indicated by the `client_entry'. This will negotiate a secret key
2089 * with the remote client before actually starting the transmission of
2090 * the file. The `monitor' callback will be called to monitor the
2091 * transmission of the file.
2093 * This returns a file session ID for the file transmission to the
2094 * `session_id' pointer.. It can be used to close the session (and
2095 * abort the file transmission) by calling the silc_client_file_close
2096 * function. The session ID is also returned in the `monitor' callback.
2098 * If the `local_ip' is provided then this will try to bind the
2099 * listener for key exchange protocol to that IP. If `local_port' is
2100 * non-zero that port is used. If `local_ip' is NULL then this will
2101 * automatically attempt to bind it to local IP address of the machine.
2102 * If that fails then this does not bind to any address and port, and
2103 * assume that the remote client will provide the listener for the
2104 * key exchange protocol.
2106 * If error will occur during the file transfer process the error
2107 * status will be returned in the monitor callback. In this case
2108 * the application must call silc_client_file_close to close the
2113 silc_client_file_send(SilcClient client,
2114 SilcClientConnection conn,
2115 SilcClientFileMonitor monitor,
2116 void *monitor_context,
2117 const char *local_ip,
2118 SilcUInt32 local_port,
2119 SilcClientEntry client_entry,
2120 const char *filepath,
2121 SilcUInt32 *session_id);
2123 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2127 * SilcClientFileError
2128 * silc_client_file_receive(SilcClient client,
2129 * SilcClientConnection conn,
2130 * SilcClientFileMonitor monitor,
2131 * void *monitor_context,
2133 * SilcUInt32 session_id);
2137 * Receives a file from a client indicated by the `client_entry'. The
2138 * `session_id' indicates the file transmission session and it has been
2139 * received in the `ftp' client operation function. This will actually
2140 * perform the key agreement protocol with the remote client before
2141 * actually starting the file transmission. The `monitor' callback
2142 * will be called to monitor the transmission. If `path' is non NULL
2143 * the file will be saved into that directory. If NULL the file is
2144 * saved in the current working directory.
2146 * If error will occur during the file transfer process the error
2147 * status will be returned in the monitor callback. In this case
2148 * the application must call silc_client_file_close to close the
2153 silc_client_file_receive(SilcClient client,
2154 SilcClientConnection conn,
2155 SilcClientFileMonitor monitor,
2156 void *monitor_context,
2158 SilcUInt32 session_id);
2160 /****f* silcclient/SilcClientAPI/silc_client_file_close
2164 * SilcClientFileError silc_client_file_close(SilcClient client,
2165 * SilcClientConnection conn,
2166 * SilcUInt32 session_id);
2170 * Closes file transmission session indicated by the `session_id'.
2171 * If file transmission is being conducted it will be aborted
2172 * automatically. This function is also used to close the session
2173 * after successful file transmission. This function can be used
2174 * also to reject incoming file transmission request.
2177 SilcClientFileError silc_client_file_close(SilcClient client,
2178 SilcClientConnection conn,
2179 SilcUInt32 session_id);
2181 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2185 * SilcAttributePayload
2186 * silc_client_attribute_add(SilcClient client,
2187 * SilcClientConnection conn,
2188 * SilcAttribute attribute,
2190 * SilcUInt32 object_size);
2194 * Add new Requsted Attribute for WHOIS command to the client library.
2195 * The `attribute' object indicated by `object' is added and allocated
2196 * SilcAttributePayload is returned. The `object' must be of correct
2197 * type and of correct size. See the SilcAttribute for object types
2198 * for different attributes. You may also get all added attributes
2199 * from the client with silc_client_attributes_get function.
2201 * Requested Attributes are different personal information about the
2202 * user, status information and other information which other users
2203 * may query with WHOIS command. Application may set these so that
2204 * if someone sends WHOIS query these attributes will be replied back
2205 * to the sender. The library always puts the public key to the
2206 * Requested Attributes, but if application wishes to add additional
2207 * public keys (or certificates) it can be done with this interface.
2208 * Library also always computes digital signature of the attributes
2209 * automatically, so application does not need to do that.
2212 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2213 SilcClientConnection conn,
2214 SilcAttribute attribute,
2216 SilcUInt32 object_size);
2218 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2222 * bool silc_client_attribute_del(SilcClient client,
2223 * SilcClientConnection conn,
2224 * SilcAttribute attribute,
2225 * SilcAttributePayload attr);
2229 * Delete a Requested Attribute from the client. If the `attribute'
2230 * is non-zero then all attributes of that type are deleted and the
2231 * `attr' is ignored. If `attr' is non-NULL then that specific
2232 * attribute is deleted and `attribute' is ignored.
2234 * You may get all added attributes with the function
2235 * silc_client_attributes_get and to get the SilcAttributePayload.
2236 * This function Returns TRUE if the attribute was found and deleted.
2239 bool silc_client_attribute_del(SilcClient client,
2240 SilcClientConnection conn,
2241 SilcAttribute attribute,
2242 SilcAttributePayload attr);
2244 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2248 * const SilcHashTable
2249 * silc_client_attributes_get(SilcClient client,
2250 * SilcClientConnection conn);
2254 * Returns pointer to the SilcHashTable which includes all the added
2255 * Requested Attributes. The caller must not free the hash table.
2256 * The caller may use SilcHashTableList and silc_hash_table_list to
2257 * traverse the table. Each entry in the hash table is one added
2258 * SilcAttributePayload. It is possible to delete a attribute
2259 * payload while traversing the table.
2262 const SilcHashTable silc_client_attributes_get(SilcClient client,
2263 SilcClientConnection conn);
2265 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2269 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2273 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2274 * then all attributes are requested. Alternatively, `attribute' and
2275 * all variable arguments can each be requested attribute. In this case
2276 * the last must be set to zero (0) to complete the variable list of
2277 * requested attributes. See SilcAttribute for all attributes.
2278 * You can give the returned buffer as argument to for example
2279 * silc_client_get_client_by_id_resolve function.
2282 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2285 #include "command.h"
2286 #include "command_reply.h"
2288 #include "protocol.h"
2294 #endif /* SILCCLIENT_H */