5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2004 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.
56 /* General definitions */
58 /****s* silcclient/SilcClientAPI/SilcClient
62 * typedef struct SilcClientStruct { ... } *SilcClient
66 * This is the actual SILC Client structure which represents one
67 * SILC Client. It is allocated with the silc_client_alloc function
68 * and given as argument to all SILC Client Library functions. It
69 * is initialized with silc_client_init function, and freed with
70 * silc_client_free function.
74 struct SilcClientStruct {
76 * The following fields are set by application
78 char *nickname; /* Nickname, MAY be set by application */
79 char *username; /* Username, MUST be set by application */
80 char *hostname; /* hostname, MUST be set by application */
81 char *realname; /* Real name, MUST be set be application */
83 SilcPublicKey public_key; /* Public key of user, set by application */
84 SilcPrivateKey private_key; /* Private key of user, set by application */
85 SilcPKCS pkcs; /* PKCS allocated by application */
88 * The following fields are set by the library
91 /* Scheduler, set by library. Application may use this pointer. */
92 SilcSchedule schedule;
94 /* Random Number Generator. Application should use this as its primary
95 random number generator. */
98 /* Application specific user data pointer. Client library does not
99 touch this. This the context sent as argument to silc_client_alloc.
100 Application can use it freely. */
103 /* Generic hash context for application usage */
107 /* Internal data for client library. Application cannot access this
109 SilcClientInternal internal;
113 /****s* silcclient/SilcClientAPI/SilcClientConnection
117 * typedef struct SilcClientConnectionStruct { ... }
118 * *SilcClientConnection
122 * This structure represents a connection. When connection is created
123 * to server this is context is returned to the application in the
124 * "connected" client operation. It includes all the important
125 * data for the session, such as nickname, local and remote IDs, and
130 struct SilcClientConnectionStruct {
134 char *nickname; /* Current nickname */
135 SilcClientEntry local_entry; /* Own Client Entry */
136 SilcClientID *local_id; /* Current Client ID */
137 unsigned char *local_id_data; /* Current Client ID decoded */
138 SilcUInt32 local_id_data_len;
143 char *remote_host; /* Remote host name */
144 int remote_port; /* Remote port */
145 SilcServerID *remote_id; /* Remote Server ID */
146 unsigned char *remote_id_data; /* Remote Server ID decoded */
147 SilcUInt32 remote_id_data_len;
153 /* Current command identifier for a command that was sent last.
154 Application may get the value from this variable to find out the
155 command identifier for last command. */
156 SilcUInt16 cmd_ident;
158 /* User data context. Library does not touch this. Application may
159 freely set and use this pointer for its needs. */
162 /* Pointer back to the SilcClient. Application may use this. */
165 /* Current channel. Application may use and set this pointer if needed. */
166 SilcChannelEntry current_channel;
168 /* Socket connection object for this connection. Application may
169 use this if needed. The sock->user_data is back pointer to this
171 SilcSocketConnection sock;
173 /* Internal data for client library. Application cannot access this
175 SilcClientConnectionInternal internal;
179 /****s* silcclient/SilcClientAPI/SilcClientEntry
183 * typedef struct SilcClientEntryStruct { ... } *SilcClientEntry
187 * This structure represents a client or a user in the SILC network.
188 * The local user has this structure also and it can be accessed from
189 * SilcClientConnection structure. All other users in the SILC network
190 * that are accessed using the Client Library routines will have their
191 * own SilcClientEntry structure. For example, when finding users by
192 * their nickname the Client Library returns this structure back to
197 struct SilcClientEntryStruct {
198 /* General information */
199 char *nickname; /* nickname */
200 char *username; /* username */
201 char *hostname; /* hostname */
202 char *server; /* SILC server name */
203 char *realname; /* Realname (userinfo) */
205 /* Mode, ID and other information */
206 SilcUInt32 mode; /* User mode in SILC, see SilcUserMode */
207 SilcClientID *id; /* The Client ID */
208 SilcDList attrs; /* Requested Attributes (maybe NULL) */
209 unsigned char *fingerprint; /* Fingerprint of client's public key */
210 SilcUInt32 fingerprint_len; /* Length of the fingerprint */
211 SilcPublicKey public_key; /* User's public key, may be NULL */
213 /* Private message keys */
214 SilcCipher send_key; /* Private message key for sending */
215 SilcCipher receive_key; /* Private message key for receiving */
216 SilcHmac hmac_send; /* Private mesage key HMAC for sending */
217 SilcHmac hmac_receive; /* Private mesage key HMAC for receiving */
218 unsigned char *key; /* Set only if application provided the
219 key material. NULL if the library
220 generated the key. */
221 SilcUInt32 key_len; /* Key length */
222 SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
224 /* SilcClientEntry status information */
225 SilcEntryStatus status; /* Status mask */
226 SilcHashTable channels; /* All channels client has joined */
227 SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
228 unsigned int generated : 1; /* TRUE if library generated `key' */
229 unsigned int valid : 1; /* FALSE if this entry is not valid */
230 unsigned int prv_resp : 1; /* TRUE if private message key indicator
231 has been received (responder). */
233 /* Application specific data. Application may set here whatever it wants. */
238 /****s* silcclient/SilcClientAPI/SilcChannelEntry
242 * typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
246 * This structure represents a channel in the SILC network. All
247 * channels that the client are aware of or have joined in will be
248 * represented as SilcChannelEntry. The structure includes information
253 struct SilcChannelEntryStruct {
254 /* General information */
255 char *channel_name; /* Channel name */
256 SilcChannelID *id; /* Channel ID */
257 SilcUInt32 mode; /* Channel mode, ChannelModes. */
258 char *topic; /* Current topic, may be NULL */
259 SilcPublicKey founder_key; /* Founder key, may be NULL */
260 SilcUInt32 user_limit; /* User limit on channel */
262 /* All clients that has joined this channel. The key to the table is the
263 SilcClientEntry and the context is SilcChannelUser context. */
264 SilcHashTable user_list;
267 SilcCipher channel_key; /* The channel key */
268 unsigned char *key; /* Raw key data */
269 SilcUInt32 key_len; /* Raw key data length */
270 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
271 SilcHmac hmac; /* Current HMAC */
273 /* Channel private keys */
274 SilcDList private_keys; /* List of private keys or NULL */
275 SilcChannelPrivateKey curr_key; /* Current private key */
277 /* SilcChannelEntry status information */
278 SilcDList old_channel_keys;
280 SilcUInt16 resolve_cmd_ident; /* Command identifier when
281 resolving this entry */
283 /* Application specific data. Application may set here whatever it wants. */
288 /****s* silcclient/SilcClientAPI/SilcChannelUser
292 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
296 * This structure represents a client that has joined to a channel.
297 * It shows the client and the channel and the client's mode (channel
298 * user mode) on the channel.
302 struct SilcChannelUserStruct {
303 SilcClientEntry client; /* Client joined on channel */
304 SilcUInt32 mode; /* mode, ChannelUserModes */
305 SilcChannelEntry channel; /* The channel user has joined */
307 /* Application specific data. Application may set here whatever it wants. */
312 /****s* silcclient/SilcClientAPI/SilcServerEntry
316 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
320 * This structure represents a server in the SILC network. All servers
321 * that the client is aware of and have for example resolved with
322 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
326 struct SilcServerEntryStruct {
327 /* General information */
328 char *server_name; /* Server name */
329 char *server_info; /* Server info */
330 SilcServerID *server_id; /* Server ID */
331 SilcUInt16 resolve_cmd_ident; /* Command identifier when
332 resolving this entry */
334 /* Application specific data. Application may set here whatever it wants. */
339 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
343 * typedef enum { ... } SilcKeyAgreementStatus;
347 * Key agreement status types indicating the status of the key
348 * agreement protocol. These types are returned to the application
349 * in the SilcKeyAgreementCallback callback function.
354 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
355 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
356 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
357 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
358 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
359 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
360 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
361 } SilcKeyAgreementStatus;
364 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
368 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
369 * SilcClientConnection conn,
370 * SilcClientEntry client_entry,
371 * SilcKeyAgreementStatus status,
372 * SilcSKEKeyMaterial *key,
377 * Key agreement callback that is called after the key agreement protocol
378 * has been performed. This is called also if error occurred during the
379 * key agreement protocol. The `key' is the allocated key material and
380 * the caller is responsible of freeing it. The `key' is NULL if error
381 * has occurred. The application can freely use the `key' to whatever
382 * purpose it needs. See lib/silcske/silcske.h for the definition of
383 * the SilcSKEKeyMaterial structure.
386 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
387 SilcClientConnection conn,
388 SilcClientEntry client_entry,
389 SilcKeyAgreementStatus status,
390 SilcSKEKeyMaterial *key,
393 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
397 * typedef struct { ... } SilcPrivateMessageKeys;
401 * Structure to hold the list of private message keys. The array of this
402 * structure is returned by the silc_client_list_private_message_keys
408 SilcClientEntry client_entry; /* The remote client entry */
409 char *cipher; /* The cipher name */
410 unsigned char *key; /* The original key, If the appliation
411 provided it. This is NULL if the
412 library generated the key or if
413 the SKE key material was used. */
414 SilcUInt32 key_len; /* The key length */
415 } *SilcPrivateMessageKeys;
418 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
422 * typedef struct SilcChannelPrivateKeyStruct { ... }
423 * *SilcChannelPrivateKey;
427 * Structure to hold one channel private key. The array of this structure
428 * is returned by silc_client_list_channel_private_keys function.
432 struct SilcChannelPrivateKeyStruct {
433 char *name; /* Application given name */
434 SilcCipher cipher; /* The cipher and key */
435 SilcHmac hmac; /* The HMAC and hmac key */
436 unsigned char *key; /* The key data */
437 SilcUInt32 key_len; /* The key length */
441 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
445 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
446 * SilcUInt32 passphrase_len,
451 * Ask passphrase callback. This is called by the application when the
452 * library calls `ask_passphrase' client operation. The callback delivers
453 * the passphrase to the library. The passphrases in SILC protocol
454 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
455 * encoded, and if it is not then library will attempt to encode it.
458 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
459 SilcUInt32 passphrase_len,
462 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
466 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
470 * Public key (or certificate) verification callback. This is called
471 * by the application to indicate that the public key verification was
472 * either success or failure.
475 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
477 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
481 * typedef void (*SilcGetAuthMeth)(bool success,
482 * SilcProtocolAuthMeth auth_meth,
483 * const unsigned char *auth_data,
484 * SilcUInt32 auth_data_len, void *context);
488 * Authentication method resolving callback. This is called by the
489 * application to return the resolved authentication method. The client
490 * library has called the get_auth_method client operation and given
491 * this function pointer as argument. The `success' will indicate whether
492 * the authentication method could be resolved. The `auth_meth' is the
493 * resolved authentication method. The `auth_data' and the `auth_data_len'
494 * are the resolved authentication data. The `context' is the libary's
495 * context sent to the get_auth_method client operation.
498 typedef void (*SilcGetAuthMeth)(bool success,
499 SilcProtocolAuthMeth auth_meth,
500 const unsigned char *auth_data,
501 SilcUInt32 auth_data_len, void *context);
503 /****d* silcclient/SilcClientAPI/SilcClientMessageType
507 * typedef enum { ... } SilcClientMessageType;
511 * Different message types for `say' client operation. The application
512 * may filter the message sent by the library according this type.
517 SILC_CLIENT_MESSAGE_INFO, /* Informational */
518 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
519 SILC_CLIENT_MESSAGE_ERROR, /* Error */
520 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
521 } SilcClientMessageType;
524 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
528 * typedef enum { ... } SilcClientConnectionStatus
532 * This type is returned to the `connect' client operation to indicate
533 * the status of the created connection. It can indicate if it was
534 * successful or whether an error occurred.
539 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
540 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
541 resumed old detached session */
542 SILC_CLIENT_CONN_ERROR, /* Unknown error occurred during
544 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
545 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
546 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
547 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
548 } SilcClientConnectionStatus;
551 /****s* silcclient/SilcClientAPI/SilcClientOperations
555 * typedef struct { ... } SilcClientOperations;
559 * SILC Client Operations. These must be implemented by the application.
560 * The Client library may call any of these routines at any time. The
561 * routines are used to deliver certain information to the application
562 * or from the application to the client library.
567 /* Message sent to the application by library. `conn' associates the
568 message to a specific connection. `conn', however, may be NULL.
569 The `type' indicates the type of the message sent by the library.
570 The application can for example filter the message according the
571 type. The variable argument list is arguments to the formatted
572 message that `msg' may be. */
573 void (*say)(SilcClient client, SilcClientConnection conn,
574 SilcClientMessageType type, char *msg, ...);
576 /* Message for a channel. The `sender' is the sender of the message
577 The `channel' is the channel. The `message' is the message. Note
578 that `message' maybe NULL. The `flags' indicates message flags
579 and it is used to determine how the message can be interpreted
580 (like it may tell the message is multimedia message). */
581 void (*channel_message)(SilcClient client, SilcClientConnection conn,
582 SilcClientEntry sender, SilcChannelEntry channel,
583 SilcMessagePayload payload,
584 SilcChannelPrivateKey key, SilcMessageFlags flags,
585 const unsigned char *message,
586 SilcUInt32 message_len);
588 /* Private message to the client. The `sender' is the sender of the
589 message. The message is `message'and maybe NULL. The `flags'
590 indicates message flags and it is used to determine how the message
591 can be interpreted (like it may tell the message is multimedia
593 void (*private_message)(SilcClient client, SilcClientConnection conn,
594 SilcClientEntry sender, SilcMessagePayload payload,
595 SilcMessageFlags flags,
596 const unsigned char *message,
597 SilcUInt32 message_len);
599 /* Notify message to the client. The notify arguments are sent in the
600 same order as servers sends them. The arguments are same as received
601 from the server except for ID's. If ID is received application receives
602 the corresponding entry to the ID. For example, if Client ID is received
603 application receives SilcClientEntry. Also, if the notify type is
604 for channel the channel entry is sent to application (even if server
605 does not send it because client library gets the channel entry from
606 the Channel ID in the packet's header). */
607 void (*notify)(SilcClient client, SilcClientConnection conn,
608 SilcNotifyType type, ...);
610 /* Command handler. This function is called always in the command function.
611 If error occurs it will be called as well. `conn' is the associated
612 client connection. `cmd_context' is the command context that was
613 originally sent to the command. `success' is FALSE if error occurred
614 during command. `command' is the command being processed. It must be
615 noted that this is not reply from server. This is merely called just
616 after application has called the command. Just to tell application
617 that the command really was processed. */
618 void (*command)(SilcClient client, SilcClientConnection conn,
619 SilcClientCommandContext cmd_context, bool success,
620 SilcCommand command, SilcStatus status);
622 /* Command reply handler. This function is called always in the command reply
623 function. If error occurs it will be called as well. Normal scenario
624 is that it will be called after the received command data has been parsed
625 and processed. The function is used to pass the received command data to
628 `conn' is the associated client connection. `cmd_payload' is the command
629 payload data received from server and it can be ignored. It is provided
630 if the application would like to re-parse the received command data,
631 however, it must be noted that the data is parsed already by the library
632 thus the payload can be ignored. `success' is FALSE if error occurred.
633 In this case arguments are not sent to the application. The `status' is
634 the command reply status server returned. The `command' is the command
635 reply being processed. The function has variable argument list and each
636 command defines the number and type of arguments it passes to the
637 application (on error they are not sent).
639 The arguments are sent in the same order as servers sends them. The
640 arguments are same as received from the server except for ID's. If
641 ID is received application receives the corresponding entry to the
642 ID. For example, if Client ID is receives application receives
644 void (*command_reply)(SilcClient client, SilcClientConnection conn,
645 SilcCommandPayload cmd_payload, bool success,
646 SilcCommand command, SilcStatus status, ...);
648 /* Called to indicate that connection was either successfully established
649 or connecting failed. This is also the first time application receives
650 the SilcClientConnection object which it should save somewhere.
651 The `status' indicated whether the connection were successful. If it
652 is error value the application must always call the function
653 silc_client_close_connection. */
654 void (*connected)(SilcClient client, SilcClientConnection conn,
655 SilcClientConnectionStatus status);
657 /* Called to indicate that connection was disconnected to the server.
658 The `status' may tell the reason of the disconnection, and if the
659 `message' is non-NULL it may include the disconnection message
660 received from server. Application must not call the
661 silc_client_close_connection in this callback. The 'conn' is also
662 invalid after this function returns back to library. */
663 void (*disconnected)(SilcClient client, SilcClientConnection conn,
664 SilcStatus status, const char *message);
666 /* Find authentication method and authentication data by hostname and
667 port. The hostname may be IP address as well. When the authentication
668 method has been resolved the `completion' callback with the found
669 authentication method and authentication data is called. The `conn'
671 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
672 char *hostname, SilcUInt16 port,
673 SilcGetAuthMeth completion, void *context);
675 /* Verifies received public key. The `conn_type' indicates which entity
676 (server, client etc.) has sent the public key. If user decides to trust
677 the application may save the key as trusted public key for later
678 use. The `completion' must be called after the public key has been
680 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
681 SilcSocketType conn_type, unsigned char *pk,
682 SilcUInt32 pk_len, SilcSKEPKType pk_type,
683 SilcVerifyPublicKey completion, void *context);
685 /* Ask (interact, that is) a passphrase from user. The passphrase is
686 returned to the library by calling the `completion' callback with
687 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
688 if not then the library will attempt to encode. */
689 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
690 SilcAskPassphrase completion, void *context);
692 /* Notifies application that failure packet was received. This is called
693 if there is some protocol active in the client. The `protocol' is the
694 protocol context. The `failure' is opaque pointer to the failure
695 indication. Note, that the `failure' is protocol dependant and
696 application must explicitly cast it to correct type. Usually `failure'
697 is 32 bit failure type (see protocol specs for all protocol failure
699 void (*failure)(SilcClient client, SilcClientConnection conn,
700 SilcProtocol protocol, void *failure);
702 /* Asks whether the user would like to perform the key agreement protocol.
703 This is called after we have received an key agreement packet or an
704 reply to our key agreement packet. This returns TRUE if the user wants
705 the library to perform the key agreement protocol and FALSE if it is not
706 desired (application may start it later by calling the function
707 silc_client_perform_key_agreement). If TRUE is returned also the
708 `completion' and `context' arguments must be set by the application. */
709 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
710 SilcClientEntry client_entry, const char *hostname,
711 SilcUInt16 port, SilcKeyAgreementCallback *completion,
714 /* Notifies application that file transfer protocol session is being
715 requested by the remote client indicated by the `client_entry' from
716 the `hostname' and `port'. The `session_id' is the file transfer
717 session and it can be used to either accept or reject the file
718 transfer request, by calling the silc_client_file_receive or
719 silc_client_file_close, respectively. */
720 void (*ftp)(SilcClient client, SilcClientConnection conn,
721 SilcClientEntry client_entry, SilcUInt32 session_id,
722 const char *hostname, SilcUInt16 port);
724 /* Delivers SILC session detachment data indicated by `detach_data' to the
725 application. If application has issued SILC_COMMAND_DETACH command
726 the client session in the SILC network is not quit. The client remains
727 in the network but is detached. The detachment data may be used later
728 to resume the session in the SILC Network. The appliation is
729 responsible of saving the `detach_data', to for example in a file.
731 The detachment data can be given as argument to the functions
732 silc_client_connect_to_server, or silc_client_add_connection when
733 creating connection to remote server, inside SilcClientConnectionParams
734 structure. If it is provided the client library will attempt to resume
735 the session in the network. After the connection is created
736 successfully, the application is responsible of setting the user
737 interface for user into the same state it was before detaching (showing
738 same channels, channel modes, etc). It can do this by fetching the
739 information (like joined channels) from the client library. */
740 void (*detach)(SilcClient client, SilcClientConnection conn,
741 const unsigned char *detach_data,
742 SilcUInt32 detach_data_len);
743 } SilcClientOperations;
746 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
750 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
751 * char **ret_nickname);
755 * A callback function provided by the application for the library in
756 * SilcClientParams structure. This function parses the formatted
757 * nickname string `nickname' and returns the true nickname to the
758 * `ret_nickname' pointer. The library can call this function at
762 typedef void (*SilcNicknameFormatParse)(const char *nickname,
763 char **ret_nickname);
765 /****s* silcclient/SilcClientAPI/SilcClientParams
769 * typedef struct { ... } SilcClientParams;
773 * Client parameters. This can be filled with proper values and
774 * given as argument to the silc_client_alloc function. The structure
775 * hold various parameters which affects the function of the client.
780 /* Number of maximum tasks the client library's scheduler can handle.
781 If set to zero, the default value will be used (200). For WIN32
782 systems this should be set to 64 as it is the hard limit dictated
786 /* Rekey timeout in seconds. The client will perform rekey in this
787 time interval. If set to zero, the default value will be used. */
788 unsigned int rekey_secs;
790 /* Connection authentication method request timeout. If server does not
791 reply back the current authentication method when we've requested it
792 in this time interval we'll assume the reply will not come at all.
793 If set to zero, the default value (2 seconds) will be used. */
794 unsigned int connauth_request_secs;
796 /* Nickname format string. This can be used to order the client library
797 to save the nicknames in the library in a certain format. Since
798 nicknames are not unique in SILC it is possible to have multiple same
799 nicknames. Using this format string it is possible to order the library
800 to separate the multiple same nicknames from each other. The format
801 types are defined below and they can appear in any order in the format
802 string. If this is NULL then default format is used which is the
803 default nickname without anything else. The string MUST be NULL
806 Following format types are available:
808 %n nickname - the real nickname returned by the server (mandatory)
809 %h hostname - the stripped hostname of the client
810 %H full hostname - the full hostname of the client
811 %s server name - the server name the client is connected
812 %S full server - the full server name the client is connected
813 %a number - ascending number in case there are several
814 same nicknames (fe. nick@host and nick@host2)
816 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
817 "%a!%n@%s" (fe. nick@server, 2!nick@server)
818 "%n@%H" (fe. nick@host.domain.com)
820 By default this format is employed to the nicknames by the libary
821 only when there appears multiple same nicknames. If the library has
822 only one nickname cached the nickname is saved as is and without the
823 defined format. If you want always to save the nickname in the defined
824 format set the boolean field `nickname_force_format' to value TRUE.
826 char nickname_format[32];
828 /* If this is set to TRUE then the `nickname_format' is employed to all
829 saved nicknames even if there are no multiple same nicknames in the
830 cache. By default this is FALSE, which means that the `nickname_format'
831 is employed only if the library will receive a nickname that is
832 already saved in the cache. It is recommended to leave this to FALSE
834 bool nickname_force_format;
836 /* A callback function provided by the application for the library to
837 parse the nickname from the formatted nickname string. Even though
838 the libary formats the nicknames the application knows generally the
839 format better so this function should be provided for the library
840 if the application sets the `nickname_format' field. The library
841 will call this to get the true nickname from the provided formatted
842 nickname string whenever it needs the true nickname. */
843 SilcNicknameFormatParse nickname_parse;
845 /* If this is set to TRUE then the client will ignore all incoming
846 Requested Attributes queries and does not reply anything back. This
847 usually leads into situation where server does not anymore send
848 the queries after seeing that client does not reply anything back.
849 If your application does not support Requested Attributes or you do
850 not want to use them set this to TRUE. See SilcAttribute and
851 silc_client_attribute_add for more information on attributes. */
852 bool ignore_requested_attributes;
854 /* If this is set to TRUE, the silcclient library will not register and
855 deregister the cipher, pkcs, hash and hmac algorithms. The application
856 itself will need to handle that. */
857 bool dont_register_crypto_library;
863 /* Initialization functions (client.c) */
865 /****f* silcclient/SilcClientAPI/silc_client_alloc
869 * SilcClient silc_client_alloc(SilcClientOperations *ops,
870 * SilcClientParams *params,
872 * const char *silc_version);
876 * Allocates new client object. This has to be done before client may
877 * work. After calling this one must call silc_client_init to initialize
878 * the client. The `application' is application specific user data pointer
879 * and caller must free it. The `silc_version' is the application version
880 * that will be used to compare against remote host's (usually a server)
881 * version string. The `application' context is accessible by the
882 * application by client->application, client being SilcClient.
885 SilcClient silc_client_alloc(SilcClientOperations *ops,
886 SilcClientParams *params,
888 const char *version_string);
890 /****f* silcclient/SilcClientAPI/silc_client_free
894 * void silc_client_free(SilcClient client);
898 * Frees client object and its internals. The execution of the client
899 * should be stopped with silc_client_stop function before calling
903 void silc_client_free(SilcClient client);
905 /****f* silcclient/SilcClientAPI/silc_client_init
909 * bool silc_client_init(SilcClient client);
913 * Initializes the client. This makes all the necessary steps to make
914 * the client ready to be run. One must call silc_client_run to run the
915 * client. Returns FALSE if error occurred, TRUE otherwise.
918 bool silc_client_init(SilcClient client);
920 /****f* silcclient/SilcClientAPI/silc_client_run
924 * void silc_client_run(SilcClient client);
928 * Runs the client. This starts the scheduler from the utility library.
929 * When this functions returns the execution of the appliation is over.
930 * The client must be initialized before calling this.
933 void silc_client_run(SilcClient client);
935 /****f* silcclient/SilcClientAPI/silc_client_run_one
939 * void silc_client_run_one(SilcClient client);
943 * Runs the client and returns immeadiately. This function is used when
944 * the SILC Client object indicated by the `client' is run under some
945 * other scheduler, or event loop or main loop. On GUI applications,
946 * for example this may be desired to used to run the client under the
947 * GUI application's main loop. Typically the GUI application would
948 * register an idle task that calls this function multiple times in
949 * a second to quickly process the SILC specific data.
952 void silc_client_run_one(SilcClient client);
954 /****f* silcclient/SilcClientAPI/silc_client_stop
958 * void silc_client_stop(SilcClient client);
962 * Stops the client. This is called to stop the client and thus to stop
963 * the program. The client context must be freed with the silc_client_free
967 void silc_client_stop(SilcClient client);
970 /* Connecting functions (client.c) */
972 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
976 * typedef struct { ... } SilcClientConnectionParams;
980 * Client connection parameters. This can be filled by the application
981 * and given as argument to silc_client_connect_to_server or to
982 * silc_client_add_connection.
987 /* The SILC session detachment data that was returned by `detach' client
988 operation when the application detached from the network. Application
989 is responsible of saving the data and giving it as argument here
990 for resuming the session in the SILC network.
992 If this is provided here the client library will attempt to resume
993 the session in the network. After the connection is created
994 successfully, the application is responsible of setting the user
995 interface for user into the same state it was before detaching (showing
996 same channels, channel modes, etc). It can do this by fetching the
997 information (like joined channels) from the client library. */
998 unsigned char *detach_data;
999 SilcUInt32 detach_data_len;
1001 } SilcClientConnectionParams;
1004 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
1008 * int silc_client_connect_to_server(SilcClient client,
1009 * SilcClientConnectionParams *params,
1010 * int port, char *host, void *context);
1014 * Connects to remote server. This is the main routine used to connect
1015 * to SILC server. Returns -1 on error and the created socket otherwise.
1016 * The `context' is user context that is saved into the SilcClientConnection
1017 * that is created after the connection is created. Note that application
1018 * may handle the connecting process outside the library. If this is the
1019 * case then this function is not used at all. When the connecting is
1020 * done the `connect' client operation is called, and the `context' is
1021 * accessible with conn->context, conn being SilcClientConnection.
1022 * If the `params' is provided they are used by the routine.
1025 int silc_client_connect_to_server(SilcClient client,
1026 SilcClientConnectionParams *params,
1027 int port, char *host, void *context);
1029 /****f* silcclient/SilcClientAPI/silc_client_add_connection
1034 * SilcClientConnection
1035 * silc_client_add_connection(SilcClient client,
1036 * SilcClientConnectionParams *params,
1037 * char *hostname, int port, void *context);
1041 * Allocates and adds new connection to the client. This adds the allocated
1042 * connection to the connection table and returns a pointer to it. A client
1043 * can have multiple connections to multiple servers. Every connection must
1044 * be added to the client using this function. User data `context' may
1045 * be sent as argument. If the `params' is provided they are used by
1050 * This function is normally used only if the application performed
1051 * the connecting outside the library, and did not called the
1052 * silc_client_connect_to_server function at all. The library
1053 * however may use this internally.
1056 SilcClientConnection
1057 silc_client_add_connection(SilcClient client,
1058 SilcClientConnectionParams *params,
1059 char *hostname, int port, void *context);
1061 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1065 * void silc_client_del_connection(SilcClient client,
1066 * SilcClientConnection conn);
1070 * Removes connection from client. Frees all memory. The library
1071 * call this function automatically for all connection contexts.
1072 * The application however may free the connection contexts it has
1076 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1078 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1082 * void silc_client_add_socket(SilcClient client,
1083 * SilcSocketConnection sock);
1087 * Adds listener socket to the listener sockets table. This function is
1088 * used to add socket objects that are listeners to the client. This should
1089 * not be used to add other connection objects.
1092 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1094 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1098 * void silc_client_del_socket(SilcClient client,
1099 * SilcSocketConnection sock);
1103 * Deletes listener socket from the listener sockets table. If the
1104 * application has added a socket with silc_client_add_socket it must
1105 * also free it using this function.
1108 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1110 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1114 * void silc_client_start_key_exchange(SilcClient client,
1115 * SilcClientConnection conn,
1120 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1121 * key material between client and server. This function can be called
1122 * directly if application is performing its own connecting and does not
1123 * use the connecting provided by this library. This function is normally
1124 * used only if the application performed the connecting outside the
1125 * library. The library however may use this internally. After the
1126 * key exchange is performed the `connect' client operation is called.
1130 * The silc_client_add_connection must be called before calling this
1131 * function to create the SilcClientConnection context for this
1135 void silc_client_start_key_exchange(SilcClient client,
1136 SilcClientConnection conn,
1139 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1143 * void silc_client_close_connection(SilcClient client,
1144 * SilcClientConnection conn);
1148 * Closes connection to remote end. Free's all allocated data except
1149 * for some information such as nickname etc. that are valid at all time.
1150 * Usually application does not need to directly call this, except
1151 * when explicitly closing the connection, or if an error occurs
1152 * during connection to server (see 'connect' client operation for
1153 * more information).
1156 void silc_client_close_connection(SilcClient client,
1157 SilcClientConnection conn);
1160 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1162 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1166 * bool silc_client_send_channel_message(SilcClient client,
1167 * SilcClientConnection conn,
1168 * SilcChannelEntry channel,
1169 * SilcChannelPrivateKey key,
1170 * SilcMessageFlags flags,
1171 * unsigned char *data,
1172 * SilcUInt32 data_len,
1177 * Sends packet to the `channel'. Packet to channel is always encrypted
1178 * differently from "normal" packets. SILC header of the packet is
1179 * encrypted with the next receiver's key and the rest of the packet is
1180 * encrypted with the channel specific key. Padding and HMAC is computed
1181 * with the next receiver's key. The `data' is the channel message. If
1182 * the `force_send' is TRUE then the packet is sent immediately.
1184 * If `key' is provided then that private key is used to encrypt the
1185 * channel message. If it is not provided, private keys has not been
1186 * set at all, the normal channel key is used automatically. If private
1187 * keys are set then the first key (the key that was added first as
1188 * private key) is used.
1190 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1191 * digitally signed with the SILC key pair.
1193 * Returns TRUE if the message was sent, and FALSE if error occurred or
1194 * the sending is not allowed due to channel modes (like sending is
1198 bool silc_client_send_channel_message(SilcClient client,
1199 SilcClientConnection conn,
1200 SilcChannelEntry channel,
1201 SilcChannelPrivateKey key,
1202 SilcMessageFlags flags,
1203 unsigned char *data,
1204 SilcUInt32 data_len,
1207 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1211 * bool silc_client_send_private_message(SilcClient client,
1212 * SilcClientConnection conn,
1213 * SilcClientEntry client_entry,
1214 * SilcMessageFlags flags,
1215 * unsigned char *data,
1216 * SilcUInt32 data_len,
1221 * Sends private message to remote client. If private message key has
1222 * not been set with this client then the message will be encrypted using
1223 * normal session keys. Private messages are special packets in SILC
1224 * network hence we need this own function for them. This is similar
1225 * to silc_client_packet_send_to_channel except that we send private
1226 * message. The `data' is the private message. If the `force_send' is
1227 * TRUE the packet is sent immediately.
1229 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1230 * digitally signed with the SILC key pair.
1232 * Returns TRUE if the message was sent, and FALSE if error occurred.
1235 bool silc_client_send_private_message(SilcClient client,
1236 SilcClientConnection conn,
1237 SilcClientEntry client_entry,
1238 SilcMessageFlags flags,
1239 unsigned char *data,
1240 SilcUInt32 data_len,
1244 /* Client and Channel entry retrieval (idlist.c) */
1246 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1250 * typedef void (*SilcGetClientCallback)(SilcClient client,
1251 * SilcClientConnection conn,
1252 * SilcClientEntry *clients,
1253 * SilcUInt32 clients_count,
1258 * Callback function given to the silc_client_get_client function. The
1259 * found entries are allocated into the `clients' array. The array must
1260 * not be freed by the receiver, the library will free it later. If the
1261 * `clients' is NULL, no such clients exist in the SILC Network.
1264 typedef void (*SilcGetClientCallback)(SilcClient client,
1265 SilcClientConnection conn,
1266 SilcClientEntry *clients,
1267 SilcUInt32 clients_count,
1270 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1274 * void silc_client_get_clients(SilcClient client,
1275 * SilcClientConnection conn,
1276 * const char *nickname,
1277 * const char *server,
1278 * SilcGetClientCallback completion,
1283 * Finds client entry or entries by the `nickname' and `server'. The
1284 * completion callback will be called when the client entries has been
1285 * found. After the server returns the client information it is cached
1286 * and can be accesses locally at a later time. The resolving is done
1287 * with IDENTIFY command. The `server' may be NULL.
1291 * NOTE: This function is always asynchronous and resolves the client
1292 * information from the server. Thus, if you already know the client
1293 * information then use the silc_client_get_client_by_id function to
1294 * get the client entry since this function may be very slow and should
1295 * be used only to initially get the client entries.
1297 * Since this routine resolves with IDENTIFY command only the relevant
1298 * information (user's nickname and username) is resolved. For example,
1299 * user's real name, channel list and others are not resolved. Caller
1300 * can/must resolve those separately if they are needed (for example,
1301 * with silc_client_get_client_by_id_resolve).
1304 void silc_client_get_clients(SilcClient client,
1305 SilcClientConnection conn,
1306 const char *nickname,
1308 SilcGetClientCallback completion,
1311 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
1315 * void silc_client_get_clients_whois(SilcClient client,
1316 * SilcClientConnection conn,
1317 * const char *nickname,
1318 * const char *server,
1319 * SilcBuffer attributes,
1320 * SilcGetClientCallback completion,
1325 * Finds client entry or entries by the `nickname' and `server'. The
1326 * completion callback will be called when the client entries has been
1327 * found. After the server returns the client information it is cached
1328 * and can be accesses locally at a later time. The resolving is done
1329 * with WHOIS command. The `server' may be NULL.
1331 * If the `attributes' is non-NULL then the buffer includes Requested
1332 * Attributes which can be used to fetch very detailed information
1333 * about the user. If it is NULL then only normal WHOIS query is
1334 * made (for more information about attributes see SilcAttribute).
1335 * Caller may create the `attributes' with silc_client_attributes_request
1340 * The resolving is done with WHOIS command. For this reason this
1341 * command may take a long time because it resolves detailed user
1345 void silc_client_get_clients_whois(SilcClient client,
1346 SilcClientConnection conn,
1347 const char *nickname,
1349 SilcBuffer attributes,
1350 SilcGetClientCallback completion,
1353 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1357 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1358 * SilcClientConnection conn,
1359 * const char *nickname,
1360 * const char *format,
1361 * SilcUInt32 *clients_count);
1365 * Same as silc_client_get_clients function but does not resolve anything
1366 * from the server. This checks local cache and returns all matching
1367 * clients from the local cache. If none was found this returns NULL.
1368 * The `nickname' is the real nickname of the client, and the `format'
1369 * is the formatted nickname to find exact match from multiple found
1370 * entries. The format must be same as given in the SilcClientParams
1371 * structure to the client library. If the `format' is NULL all found
1372 * clients by `nickname' are returned. The caller must return the
1376 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1377 SilcClientConnection conn,
1378 const char *nickname,
1380 SilcUInt32 *clients_count);
1382 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1386 * void silc_client_get_clients_by_channel(SilcClient client,
1387 * SilcClientConnection conn,
1388 * SilcChannelEntry channel,
1389 * SilcGetClientCallback completion,
1394 * Gets client entries by the channel indicated by `channel'. Thus,
1395 * it resovles the users currently on that channel. If all users are
1396 * already resolved this returns the users from the channel. If the
1397 * users are resolved only partially this resolves the complete user
1398 * information. If no users are resolved on this channel at all, this
1399 * calls USERS command to resolve all users on the channel. The `completion'
1400 * will be called after the entries are available. When server returns
1401 * the client information it will be cached and can be accessed locally
1404 * This function can be used for example in SILC_COMMAND_JOIN command
1405 * reply handling in application to resolve users on that channel. It
1406 * also can be used after calling silc_client_get_channel_resolve to
1407 * resolve users on that channel.
1411 * The resolving is done with WHOIS command. For this reason this
1412 * command may take a long time because it resolves detailed user
1416 void silc_client_get_clients_by_channel(SilcClient client,
1417 SilcClientConnection conn,
1418 SilcChannelEntry channel,
1419 SilcGetClientCallback completion,
1422 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1426 * void silc_client_get_clients_by_list(SilcClient client,
1427 * SilcClientConnection conn,
1428 * SilcUInt32 list_count,
1429 * SilcBuffer client_id_list,
1430 * SilcGetClientCallback completion,
1435 * Gets client entries by the list of client ID's `client_id_list'. This
1436 * always resolves those client ID's it does not know yet from the server
1437 * so this function might take a while. The `client_id_list' is a list
1438 * of ID Payloads added one after other. JOIN command reply and USERS
1439 * command reply for example returns this sort of list. The `completion'
1440 * will be called after the entries are available. When server returns
1441 * the client information it will be cached and can be accessed locally
1446 * The resolving is done with IDENTIFY command. This means that only
1447 * the relevant information of user (it's nickname and username) is
1448 * resolved. For example, user's real name, channel lists and others
1449 * are not resolved. Caller can/must resolve those separately if they
1450 * are needed (for example, with silc_client_get_client_by_id_resolve).
1453 void silc_client_get_clients_by_list(SilcClient client,
1454 SilcClientConnection conn,
1455 SilcUInt32 list_count,
1456 SilcBuffer client_id_list,
1457 SilcGetClientCallback completion,
1460 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1464 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1465 * SilcClientConnection conn,
1466 * SilcClientID *client_id);
1470 * Find entry for client by the client's ID. Returns the entry or NULL
1471 * if the entry was not found. This checks the local cache and does
1472 * not resolve anything from server.
1475 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1476 SilcClientConnection conn,
1477 SilcClientID *client_id);
1479 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1484 * silc_client_get_client_by_id_resolve(SilcClient client,
1485 * SilcClientConnection conn,
1486 * SilcClientID *client_id,
1487 * SilcBuffer attributes,
1488 * SilcGetClientCallback completion,
1493 * Same as silc_client_get_client_by_id but will always resolve the
1494 * information from the server. Use this only if you know that you
1495 * do not have the entry and the only thing you know about the client
1496 * is its ID. When server returns the client information it will be
1497 * cache and can be accessed locally at a later time. The resolving
1498 * is done by sending WHOIS command.
1500 * If the `attributes' is non-NULL then the buffer includes Requested
1501 * Attributes which can be used to fetch very detailed information
1502 * about the user. If it is NULL then only normal WHOIS query is
1503 * made (for more information about attributes see SilcAttribute).
1504 * Caller may create the `attributes' with silc_client_attributes_request
1508 void silc_client_get_client_by_id_resolve(SilcClient client,
1509 SilcClientConnection conn,
1510 SilcClientID *client_id,
1511 SilcBuffer attributes,
1512 SilcGetClientCallback completion,
1515 /****f* silcclient/SilcClientAPI/silc_client_del_client
1519 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1520 * SilcClientEntry client_entry)
1524 * Removes client from local cache by the client entry indicated by
1525 * the `client_entry'. Returns TRUE if the deletion were successful.
1528 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1529 SilcClientEntry client_entry);
1531 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1535 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1536 * SilcClientConnection conn,
1537 * SilcChannelEntry *channels,
1538 * SilcUInt32 channels_count,
1543 * Callback function given to the silc_client_get_channel_* functions.
1544 * The found entries are allocated into the `channels' array. The array
1545 * must not be freed by the receiver, the library will free it later.
1546 * If the `channel' is NULL, no such channel exist in the SILC Network.
1549 typedef void (*SilcGetChannelCallback)(SilcClient client,
1550 SilcClientConnection conn,
1551 SilcChannelEntry *channels,
1552 SilcUInt32 channels_count,
1555 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1559 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1560 * SilcClientConnection conn,
1561 * char *channel_name);
1565 * Finds entry for channel by the channel name. Returns the entry or NULL
1566 * if the entry was not found. It is found only if the client is joined
1567 * to the channel. Use silc_client_get_channel_resolve or
1568 * silc_client_get_channel_by_id_resolve to resolve channel that client
1572 SilcChannelEntry silc_client_get_channel(SilcClient client,
1573 SilcClientConnection conn,
1574 char *channel_name);
1576 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1580 * void silc_client_get_channel_resolve(SilcClient client,
1581 * SilcClientConnection conn,
1582 * char *channel_name,
1583 * SilcGetChannelCallback completion,
1588 * Resolves entry for channel by the channel name from the server.
1589 * The resolving is done with IDENTIFY command. Note that users on
1590 * the channel are not resolved at the same time. Use for example
1591 * silc_client_get_clients_by_channel to resolve all users on a channel.
1594 void silc_client_get_channel_resolve(SilcClient client,
1595 SilcClientConnection conn,
1597 SilcGetChannelCallback completion,
1600 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1605 * silc_client_get_channel_by_id(SilcClient client,
1606 * SilcClientConnection conn,
1607 * SilcChannelID *channel_id);
1611 * Finds channel entry by the channel ID. Returns the entry or NULL
1612 * if the entry was not found. This checks the local cache and does
1613 * not resolve anything from server.
1616 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1617 SilcClientConnection conn,
1618 SilcChannelID *channel_id);
1620 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1625 * silc_client_get_channel_by_id_resolve(SilcClient client,
1626 * SilcClientConnection conn,
1627 * SilcChannelID *channel_id,
1628 * SilcGetClientCallback completion,
1633 * Resolves the channel information (its name mainly) from the server
1634 * by the `channel_id'. Use this only if you know that you do not have
1635 * the entry cached locally. The resolving is done with IDENTIFY command.
1637 * Note that users on the channel are not resolved at the same time.
1638 * Use for example silc_client_get_clients_by_channel to resolve all
1639 * users on a channel.
1642 void silc_client_get_channel_by_id_resolve(SilcClient client,
1643 SilcClientConnection conn,
1644 SilcChannelID *channel_id,
1645 SilcGetChannelCallback completion,
1648 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1652 * bool silc_client_del_channel(SilcClient client,
1653 * SilcClientConnection conn,
1654 * SilcChannelEntry channel)
1658 * Removes channel from local cache by the channel entry indicated by
1659 * the `channel'. Returns TRUE if the deletion were successful.
1662 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1663 SilcChannelEntry channel);
1665 /****f* silcclient/SilcClientAPI/silc_client_get_server
1669 * SilcServerEntry silc_client_get_server(SilcClient client,
1670 * SilcClientConnection conn,
1671 * char *server_name)
1675 * Finds entry for server by the server name. Returns the entry or NULL
1676 * if the entry was not found.
1679 SilcServerEntry silc_client_get_server(SilcClient client,
1680 SilcClientConnection conn,
1683 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1687 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1688 * SilcClientConnection conn,
1689 * SilcServerID *server_id);
1693 * Finds entry for server by the server ID. Returns the entry or NULL
1694 * if the entry was not found.
1697 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1698 SilcClientConnection conn,
1699 SilcServerID *server_id);
1701 /****f* silcclient/SilcClientAPI/silc_client_del_server
1705 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1706 * SilcServerEntry server);
1710 * Removes server from local cache by the server entry indicated by
1711 * the `server'. Returns TRUE if the deletion were successful.
1714 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1715 SilcServerEntry server);
1717 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1721 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1722 * SilcClientEntry client_entry);
1726 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1727 * channel indicated by the `channel'. NULL if client is not joined on
1731 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1732 SilcClientEntry client_entry);
1734 /* Command management (command.c) */
1736 /****f* silcclient/SilcClientAPI/silc_client_command_call
1740 * bool silc_client_command_call(SilcClient client,
1741 * SilcClientConnection conn,
1742 * const char *command_line, ...);
1746 * Calls and executes the command indicated by the `command_name'.
1747 * The `command_line' is a string which includes the command's name and
1748 * its arguments separated with whitespaces (' '). If `command_line'
1749 * is non-NULL then all variable arguments are ignored by default.
1751 * If `command_line' is NULL, then the variable arguments define the
1752 * command's name and its arguments. The first variable argument must
1753 * be the command name. The variable argument list must be terminated
1756 * Returns FALSE if the command is not known and TRUE after command.
1757 * execution. The "command" client operation is called when the
1758 * command is executed to indicate whether the command executed
1759 * successfully or not.
1761 * The "command_reply" client operation will be called when reply is
1762 * received from the server to the command. Application may also use
1763 * the silc_client_command_pending to attach to the command reply.
1764 * The command identifier for silc_client_command_pending function after
1765 * this function call is conn->cmd_ident, which application may use.
1769 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1771 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1775 * This command executes the commands implemented inside the client
1776 * library. These commands are designed for command line applications,
1777 * but GUI application may call them too if needed. Alternatively
1778 * application may override the library and use silc_client_command_send
1782 bool silc_client_command_call(SilcClient client,
1783 SilcClientConnection conn,
1784 const char *command_line, ...);
1786 /****f* silcclient/SilcClientAPI/silc_client_command_send
1790 * void silc_client_command_send(SilcClient client,
1791 * SilcClientConnection conn,
1792 * SilcCommand command, SilcUInt16 ident,
1793 * SilcUInt32 argc, ...);
1797 * Generic function to send any command. The arguments must be sent already
1798 * encoded into correct form and in correct order. If application wants
1799 * to perform the commands by itself, it can do so and send the data
1800 * directly to the server using this function. If application is using
1801 * the silc_client_command_call, this function is usually not used.
1802 * Note that this overriders the Client Librarys commands and sends
1803 * the command packet directly to server.
1805 * Programmer should get familiar with the SILC protocol commands
1806 * specification when using this function, as the arguments needs to
1807 * be encoded as specified in the protocol.
1809 * The variable arguments are a pair of { type, data, data_length },
1810 * and the `argc' is the number of these pairs.
1814 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1815 * 1, nickname, strlen(nickname));
1818 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1819 SilcCommand command, SilcUInt16 ident,
1820 SilcUInt32 argc, ...);
1822 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1826 * void silc_client_command_pending(SilcClientConnection conn,
1827 * SilcCommand reply_cmd,
1829 * SilcCommandCb callback,
1834 * This function can be used to add pending command callback to be
1835 * called when an command reply is received to an earlier sent command.
1836 * The `reply_cmd' is the command that must be received in order for
1837 * the pending command callback indicated by `callback' to be called.
1838 * The `callback' will deliver the `context' and
1839 * SilcClientCommandReplyContext which includes the internals of the
1842 * The `ident' is a command identifier which was set for the earlier
1843 * sent command. The command reply will include the same identifier
1844 * and pending command callback will be called when the reply is
1845 * received with the same command identifier. It is possible to
1846 * add multiple pending command callbacks for same command and for
1849 * Application may use this function to add its own command reply
1850 * handlers if it wishes not to use the standard `command_reply'
1851 * client operation. However, note that the pending command callback
1852 * does not deliver parsed command reply, but application must parse
1855 * Note also that the application is notified about the received command
1856 * reply through the `command_reply' client operation before calling
1857 * the `callback` pending command callback. That is the normal
1858 * command reply handling, and is called regardless whether pending
1859 * command callbacks are used or not.
1861 * Commands that application calls with silc_client_command_call
1862 * will use a command identifier from conn->cmd_ident variable. After
1863 * calling the silc_client_command_call, the conn->cmd_ident includes
1864 * the command identifier that was used for the command sending.
1868 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1869 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1870 * my_ping_handler, my_ping_context);
1873 void silc_client_command_pending(SilcClientConnection conn,
1874 SilcCommand reply_cmd,
1876 SilcCommandCb callback,
1880 /* Private Message key management (client_prvmsg.c) */
1882 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1886 * bool silc_client_add_private_message_key(SilcClient client,
1887 * SilcClientConnection conn,
1888 * SilcClientEntry client_entry,
1889 * const char *cipher,
1891 * unsigned char *key,
1892 * SilcUInt32 key_len,
1893 * bool generate_key,
1898 * Adds private message key to the client library. The key will be used to
1899 * encrypt all private message between the client and the remote client
1900 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1901 * value `generate_key' is TRUE the library will generate random key.
1902 * The `key' maybe for example pre-shared-key, passphrase or similar.
1903 * The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1904 * that the requirements of the SILC protocol are met. The API, however,
1905 * allows to allocate any cipher and HMAC.
1907 * If `responder' is TRUE then the sending and receiving keys will be
1908 * set according the client being the receiver of the private key. If
1909 * FALSE the client is being the sender (or negotiator) of the private
1912 * It is not necessary to set key for normal private message usage. If the
1913 * key is not set then the private messages are encrypted using normal
1914 * session keys. Setting the private key, however, increases the security.
1916 * Returns FALSE if the key is already set for the `client_entry', TRUE
1920 bool silc_client_add_private_message_key(SilcClient client,
1921 SilcClientConnection conn,
1922 SilcClientEntry client_entry,
1930 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1935 * silc_client_add_private_message_key_ske(SilcClient client,
1936 * SilcClientConnection conn,
1937 * SilcClientEntry client_entry,
1938 * const char *cipher,
1940 * SilcSKEKeyMaterial *key);
1944 * Same as silc_client_add_private_message_key but takes the key material
1945 * from the SKE key material structure. This structure is received if
1946 * the application uses the silc_client_send_key_agreement to negotiate
1947 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1948 * negotiated also in the SKE protocol.
1951 bool silc_client_add_private_message_key_ske(SilcClient client,
1952 SilcClientConnection conn,
1953 SilcClientEntry client_entry,
1956 SilcSKEKeyMaterial *key,
1959 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1963 * bool silc_client_del_private_message_key(SilcClient client,
1964 * SilcClientConnection conn,
1965 * SilcClientEntry client_entry);
1969 * Removes the private message from the library. The key won't be used
1970 * after this to protect the private messages with the remote `client_entry'
1971 * client. Returns FALSE on error, TRUE otherwise.
1974 bool silc_client_del_private_message_key(SilcClient client,
1975 SilcClientConnection conn,
1976 SilcClientEntry client_entry);
1978 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1982 * SilcPrivateMessageKeys
1983 * silc_client_list_private_message_keys(SilcClient client,
1984 * SilcClientConnection conn,
1985 * SilcUInt32 *key_count);
1989 * Returns array of set private message keys associated to the connection
1990 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1991 * count to the `key_count' argument. The array must be freed by the caller
1992 * by calling the silc_client_free_private_message_keys function. Note:
1993 * the keys returned in the array is in raw format. It might not be desired
1994 * to show the keys as is. The application might choose not to show the keys
1995 * at all or to show the fingerprints of the keys.
1998 SilcPrivateMessageKeys
1999 silc_client_list_private_message_keys(SilcClient client,
2000 SilcClientConnection conn,
2001 SilcUInt32 *key_count);
2003 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key_request
2008 * silc_client_send_private_message_key_request(SilcClient client,
2009 * SilcClientConnection conn,
2010 * SilcClientEntry client_entry);
2014 * This function can be used to send an private message key indicator
2015 * request to the remote client indicated by 'client_entry'. This can
2016 * be used when setting a static or pre-shared private message key.
2017 * The sender of this packet is the initiator and must set the 'responder'
2018 * argument in silc_client_add_private_message_key function to FALSE.
2019 * The receiver of this indicator request must set it to TRUE, if the
2020 * receiver decides to set a private message key. By using this
2021 * function applications may automate initiator/responder setting in
2022 * private message key functions, without asking from user which one is
2023 * the initiator and which one is responder.
2027 * The sender of this packet must set the private message key for
2028 * 'client_entry' before calling this function. The 'responder'
2029 * argument MUST be set to FALSE when setting the key.
2033 silc_client_send_private_message_key_request(SilcClient client,
2034 SilcClientConnection conn,
2035 SilcClientEntry client_entry);
2037 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
2041 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2042 * SilcUInt32 key_count);
2046 * Frees the SilcPrivateMessageKeys array returned by the function
2047 * silc_client_list_private_message_keys.
2050 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2051 SilcUInt32 key_count);
2054 /* Channel private key management (client_channel.c,
2055 SilcChannelPrivateKey is defined in idlist.h) */
2057 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
2061 * bool silc_client_add_channel_private_key(SilcClient client,
2062 * SilcClientConnection conn,
2063 * SilcChannelEntry channel,
2067 * unsigned char *key,
2068 * SilcUInt32 key_len,
2069 * SilcChannelPrivateKey *ret_key);
2073 * Adds private key for channel. When channel has private key then the
2074 * messages are encrypted using that key. All clients on the channel
2075 * must also know the key in order to decrypt the messages. However,
2076 * it is possible to have several private keys per one channel. In this
2077 * case only some of the clients on the channel may know the one key
2078 * and only some the other key. The `name' can be application given
2079 * name for the key. This returns the created key to the 'ret_key'
2080 * pointer if it is non-NULL;
2082 * If `cipher' and/or `hmac' is NULL then default values will be used
2083 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
2085 * The private key for channel is optional. If it is not set then the
2086 * channel messages are encrypted using the channel key generated by the
2087 * server. However, setting the private key (or keys) for the channel
2088 * significantly adds security. If more than one key is set the library
2089 * will automatically try all keys at the message decryption phase. Note:
2090 * setting many keys slows down the decryption phase as all keys has to
2091 * be tried in order to find the correct decryption key. However, setting
2092 * a few keys does not have big impact to the decryption performace.
2096 * NOTE: This is entirely local setting. The key set using this function
2097 * is not sent to the network at any phase.
2099 * NOTE: If the key material was originated by the SKE protocol (using
2100 * silc_client_send_key_agreement) then the `key' MUST be the
2101 * key->send_enc_key as this is dictated by the SILC protocol. However,
2102 * currently it is not expected that the SKE key material would be used
2103 * as channel private key. However, this API allows it.
2106 bool silc_client_add_channel_private_key(SilcClient client,
2107 SilcClientConnection conn,
2108 SilcChannelEntry channel,
2114 SilcChannelPrivateKey *ret_key);
2116 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
2120 * bool silc_client_del_channel_private_keys(SilcClient client,
2121 * SilcClientConnection conn,
2122 * SilcChannelEntry channel);
2126 * Removes all private keys from the `channel'. The old channel key is used
2127 * after calling this to protect the channel messages. Returns FALSE on
2128 * on error, TRUE otherwise.
2131 bool silc_client_del_channel_private_keys(SilcClient client,
2132 SilcClientConnection conn,
2133 SilcChannelEntry channel);
2135 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2139 * bool silc_client_del_channel_private_key(SilcClient client,
2140 * SilcClientConnection conn,
2141 * SilcChannelEntry channel,
2142 * SilcChannelPrivateKey key);
2146 * Removes and frees private key `key' from the channel `channel'.
2147 * The `key' is retrieved by calling the function
2148 * silc_client_list_channel_private_keys. The key is not used after
2149 * this. If the key was last private key then the old channel key is
2150 * used hereafter to protect the channel messages. This returns FALSE
2151 * on error, TRUE otherwise.
2154 bool silc_client_del_channel_private_key(SilcClient client,
2155 SilcClientConnection conn,
2156 SilcChannelEntry channel,
2157 SilcChannelPrivateKey key);
2159 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2163 * SilcChannelPrivateKey *
2164 * silc_client_list_channel_private_keys(SilcClient client,
2165 * SilcClientConnection conn,
2166 * SilcChannelEntry channel,
2167 * SilcUInt32 *key_count);
2171 * Returns array (pointers) of private keys associated to the `channel'.
2172 * The caller must free the array by calling the function
2173 * silc_client_free_channel_private_keys. The pointers in the array may be
2174 * used to delete the specific key by giving the pointer as argument to the
2175 * function silc_client_del_channel_private_key.
2178 SilcChannelPrivateKey *
2179 silc_client_list_channel_private_keys(SilcClient client,
2180 SilcClientConnection conn,
2181 SilcChannelEntry channel,
2182 SilcUInt32 *key_count);
2184 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2188 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2189 * SilcUInt32 key_count);
2193 * Frees the SilcChannelPrivateKey array.
2196 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2197 SilcUInt32 key_count);
2199 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2203 * void silc_client_current_channel_private_key(SilcClient client,
2204 * SilcClientConnection conn,
2205 * SilcChannelEntry channel,
2206 * SilcChannelPrivateKey key);
2210 * Sets the `key' to be used as current channel private key on the
2211 * `channel'. Packet sent after calling this function will be secured
2215 void silc_client_current_channel_private_key(SilcClient client,
2216 SilcClientConnection conn,
2217 SilcChannelEntry channel,
2218 SilcChannelPrivateKey key);
2221 /* Key Agreement routines (client_keyagr.c) */
2223 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2227 * void silc_client_send_key_agreement(SilcClient client,
2228 * SilcClientConnection conn,
2229 * SilcClientEntry client_entry,
2232 * SilcUInt32 timeout_secs,
2233 * SilcKeyAgreementCallback completion,
2238 * Sends key agreement request to the remote client indicated by the
2239 * `client_entry'. If the caller provides the `hostname' and the `port'
2240 * arguments then the library will bind the client to that hostname and
2241 * that port for the key agreement protocol. It also sends the `hostname'
2242 * and the `port' in the key agreement packet to the remote client. This
2243 * would indicate that the remote client may initiate the key agreement
2244 * protocol to the `hostname' on the `port'. If port is zero then the
2245 * bound port is undefined (the operating system defines it).
2247 * If the `hostname' and `port' is not provided then empty key agreement
2248 * packet is sent to the remote client. The remote client may reply with
2249 * the same packet including its hostname and port. If the library receives
2250 * the reply from the remote client the `key_agreement' client operation
2251 * callback will be called to verify whether the user wants to perform the
2252 * key agreement or not.
2256 * NOTE: If the application provided the `hostname' and the `port' and the
2257 * remote side initiates the key agreement protocol it is not verified
2258 * from the user anymore whether the protocol should be executed or not.
2259 * By setting the `hostname' and `port' the user gives permission to
2260 * perform the protocol (we are responder in this case).
2262 * NOTE: If the remote side decides not to initiate the key agreement
2263 * or decides not to reply with the key agreement packet then we cannot
2264 * perform the key agreement at all. If the key agreement protocol is
2265 * performed the `completion' callback with the `context' will be called.
2266 * If remote side decides to ignore the request the `completion' will be
2267 * called after the specified timeout, `timeout_secs'.
2269 * NOTE: If the `hostname' and the `port' was not provided the `completion'
2270 * will not be called at all since this does nothing more than sending
2271 * a packet to the remote host.
2273 * NOTE: There can be only one active key agreement for one client entry.
2274 * Before setting new one, the old one must be finished (it is finished
2275 * after calling the completion callback) or the function
2276 * silc_client_abort_key_agreement must be called.
2279 void silc_client_send_key_agreement(SilcClient client,
2280 SilcClientConnection conn,
2281 SilcClientEntry client_entry,
2282 const char *hostname,
2283 const char *bindhost,
2285 SilcUInt32 timeout_secs,
2286 SilcKeyAgreementCallback completion,
2289 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2294 * silc_client_perform_key_agreement(SilcClient client,
2295 * SilcClientConnection conn,
2296 * SilcClientEntry client_entry,
2299 * SilcKeyAgreementCallback completion,
2304 * Performs the actual key agreement protocol. Application may use this
2305 * to initiate the key agreement protocol. This can be called for example
2306 * after the application has received the `key_agreement' client operation,
2307 * and did not return TRUE from it.
2309 * The `hostname' is the remote hostname (or IP address) and the `port'
2310 * is the remote port. The `completion' callback with the `context' will
2311 * be called after the key agreement protocol.
2315 * NOTE: If the application returns TRUE in the `key_agreement' client
2316 * operation the library will automatically start the key agreement. In this
2317 * case the application must not call this function. However, application
2318 * may choose to just ignore the `key_agreement' client operation (and
2319 * merely just print information about it on the screen) and call this
2320 * function when the user whishes to do so (by, for example, giving some
2321 * specific command). Thus, the API provides both, automatic and manual
2322 * initiation of the key agreement. Calling this function is the manual
2323 * initiation and returning TRUE in the `key_agreement' client operation
2324 * is the automatic initiation.
2327 void silc_client_perform_key_agreement(SilcClient client,
2328 SilcClientConnection conn,
2329 SilcClientEntry client_entry,
2332 SilcKeyAgreementCallback completion,
2335 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2340 * silc_client_perform_key_agreement_fd(SilcClient client,
2341 * SilcClientConnection conn,
2342 * SilcClientEntry client_entry,
2345 * SilcKeyAgreementCallback completion,
2350 * Same as above but application has created already the connection to
2351 * the remote host. The `sock' is the socket to the remote connection.
2352 * Application can use this function if it does not want the client library
2353 * to create the connection.
2356 void silc_client_perform_key_agreement_fd(SilcClient client,
2357 SilcClientConnection conn,
2358 SilcClientEntry client_entry,
2361 SilcKeyAgreementCallback completion,
2364 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2368 * void silc_client_abort_key_agreement(SilcClient client,
2369 * SilcClientConnection conn,
2370 * SilcClientEntry client_entry);
2374 * This function can be called to unbind the hostname and the port for
2375 * the key agreement protocol. However, this function has effect only
2376 * before the key agreement protocol has been performed. After it has
2377 * been performed the library will automatically unbind the port. The
2378 * `client_entry' is the client to which we sent the key agreement
2379 * request. The key agreement completion callback will be called
2380 * with SILC_KEY_AGREEMENT_ABORTED status.
2383 void silc_client_abort_key_agreement(SilcClient client,
2384 SilcClientConnection conn,
2385 SilcClientEntry client_entry);
2388 /* Misc functions */
2390 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2394 * void silc_client_set_away_message(SilcClient client,
2395 * SilcClientConnection conn,
2400 * Sets away `message'. The away message may be set when the client's
2401 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2402 * to anyone who sends private message. The `message' will be sent
2403 * automatically back to the the client who send private message. If
2404 * away message is already set this replaces the old message with the
2405 * new one. If `message' is NULL the old away message is removed.
2406 * The sender may freely free the memory of the `message'.
2409 void silc_client_set_away_message(SilcClient client,
2410 SilcClientConnection conn,
2413 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2417 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2418 * SilcClientConnection conn,
2419 * SilcAuthMethod auth_meth,
2424 * Connection authentication method request callback. This is called
2425 * by the client library after it has received the authentication method
2426 * that the application requested by calling the function
2427 * silc_client_request_authentication_method.
2430 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2431 SilcClientConnection conn,
2432 SilcAuthMethod auth_meth,
2435 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2440 * silc_client_request_authentication_method(SilcClient client,
2441 * SilcClientConnection conn,
2442 * SilcConnectionAuthRequest
2448 * This function can be used to request the current authentication method
2449 * from the server. This may be called when connecting to the server
2450 * and the client library requests the authentication data from the
2451 * application. If the application does not know the current authentication
2452 * method it can request it from the server using this function.
2453 * The `callback' with `context' will be called after the server has
2454 * replied back with the current authentication method.
2458 silc_client_request_authentication_method(SilcClient client,
2459 SilcClientConnection conn,
2460 SilcConnectionAuthRequest callback,
2463 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2467 * typedef enum { ... } SilcClientMonitorStatus;
2471 * File transmission session status types. These will indicate
2472 * the status of the file transmission session.
2477 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2478 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2479 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2480 SILC_CLIENT_FILE_MONITOR_GET,
2481 SILC_CLIENT_FILE_MONITOR_PUT,
2482 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2483 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2484 } SilcClientMonitorStatus;
2487 /****d* silcclient/SilcClientAPI/SilcClientFileError
2491 * typedef enum { ... } SilcClientFileError;
2495 * File transmission error types. These types are returned by
2496 * some of the file transmission functions, and by the monitor
2497 * callback to indicate error.
2502 SILC_CLIENT_FILE_OK,
2503 SILC_CLIENT_FILE_ERROR,
2504 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2505 SILC_CLIENT_FILE_ALREADY_STARTED,
2506 SILC_CLIENT_FILE_NO_SUCH_FILE,
2507 SILC_CLIENT_FILE_PERMISSION_DENIED,
2508 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2509 } SilcClientFileError;
2512 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2516 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2517 * SilcClientConnection conn,
2518 * SilcClientMonitorStatus status,
2519 * SilcClientFileError error,
2520 * SilcUInt64 offset,
2521 * SilcUInt64 filesize,
2522 * SilcClientEntry client_entry,
2523 * SilcUInt32 session_id,
2524 * const char *filepath,
2529 * Monitor callback that is called during the file transmission to
2530 * monitor the transmission process. The `status' indicates the current
2531 * monitoring process. The `error' will indicate the error type
2532 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2533 * currently transmitted amount of total `filesize'. The `client_entry'
2534 * indicates the remote client, and the transmission session ID is the
2535 * `session_id'. The filename being transmitted is indicated by the
2539 typedef void (*SilcClientFileMonitor)(SilcClient client,
2540 SilcClientConnection conn,
2541 SilcClientMonitorStatus status,
2542 SilcClientFileError error,
2544 SilcUInt64 filesize,
2545 SilcClientEntry client_entry,
2546 SilcUInt32 session_id,
2547 const char *filepath,
2550 /****f* silcclient/SilcClientAPI/SilcClientFileName
2554 * typedef void (*SilcClientFileName)(const char *filepath,
2559 * Completion callback for the SilcClientFileAskName callback function.
2560 * Application calls this to deliver the filepath and filename where
2561 * the downloaded file is to be saved.
2564 typedef void (*SilcClientFileName)(const char *filepath,
2567 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2571 * typedef void (*SilcClientFileAskName)(SilcClient client,
2572 * SilcClientConnection conn,
2573 * SilcUInt32 session_id,
2574 * const char *remote_filename,
2575 * SilcClientFileName completion,
2576 * void *completion_context,
2581 * File name asking callback, that is called if it is given to the
2582 * silc_client_file_receive and the path given to that as argument was
2583 * NULL. The library calls this to ask the filename and filepath to
2584 * where the file is to be saved. The 'remote_filename' is the file
2585 * that is being downloaded. Application must call the 'completion'
2586 * with 'completion_context' to continue with the file downloading.
2587 * It is not mandatory to provide this to the silc_client_file_receive.
2590 typedef void (*SilcClientFileAskName)(SilcClient client,
2591 SilcClientConnection conn,
2592 SilcUInt32 session_id,
2593 const char *remote_filename,
2594 SilcClientFileName completion,
2595 void *completion_context,
2598 /****f* silcclient/SilcClientAPI/silc_client_file_send
2602 * SilcClientFileError
2603 * silc_client_file_send(SilcClient client,
2604 * SilcClientConnection conn,
2605 * SilcClientFileMonitor monitor,
2606 * void *monitor_context,
2607 * const char *local_ip,
2608 * SilcUInt32 local_port,
2610 * SilcClientEntry client_entry,
2611 * const char *filepath);
2612 * SilcUInt32 *session_id);
2616 * Sends a file indicated by the `filepath' to the remote client
2617 * indicated by the `client_entry'. This will negotiate a secret key
2618 * with the remote client before actually starting the transmission of
2619 * the file. The `monitor' callback will be called to monitor the
2620 * transmission of the file.
2622 * This returns a file session ID for the file transmission to the
2623 * `session_id' pointer. It can be used to close the session (and
2624 * abort the file transmission) by calling the silc_client_file_close
2625 * function. The session ID is also returned in the `monitor' callback.
2627 * If the `local_ip' is provided then this will try to bind the
2628 * listener for key exchange protocol to that IP. If `local_port' is
2629 * non-zero that port is used. If `local_ip' is NULL then this will
2630 * automatically attempt to bind it to local IP address of the machine.
2631 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2632 * ignored and it is expected that the receiver will provide the
2633 * point of contact. This is usefull if the sender is behind NAT.
2635 * If error will occur during the file transfer process the error
2636 * status will be returned in the monitor callback. In this case
2637 * the application must call silc_client_file_close to close the
2642 silc_client_file_send(SilcClient client,
2643 SilcClientConnection conn,
2644 SilcClientFileMonitor monitor,
2645 void *monitor_context,
2646 const char *local_ip,
2647 SilcUInt32 local_port,
2649 SilcClientEntry client_entry,
2650 const char *filepath,
2651 SilcUInt32 *session_id);
2653 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2657 * SilcClientFileError
2658 * silc_client_file_receive(SilcClient client,
2659 * SilcClientConnection conn,
2660 * SilcClientFileMonitor monitor,
2661 * void *monitor_context,
2663 * SilcUInt32 session_id,
2664 * SilcClientFileAskName ask_name,
2665 * void *ask_name_context);
2669 * Receives a file from a client indicated by the `client_entry'. The
2670 * `session_id' indicates the file transmission session and it has been
2671 * received in the `ftp' client operation function. This will actually
2672 * perform the key agreement protocol with the remote client before
2673 * actually starting the file transmission. The `monitor' callback
2674 * will be called to monitor the transmission. If `path' is non-NULL
2675 * the file will be saved into that directory. If NULL the file is
2676 * saved in the current working directory, unless the 'ask_name'
2677 * callback is non-NULL. In this case the callback is called to ask
2678 * the path and filename from application.
2680 * If error will occur during the file transfer process the error
2681 * status will be returned in the monitor callback. In this case
2682 * the application must call silc_client_file_close to close the
2687 silc_client_file_receive(SilcClient client,
2688 SilcClientConnection conn,
2689 SilcClientFileMonitor monitor,
2690 void *monitor_context,
2692 SilcUInt32 session_id,
2693 SilcClientFileAskName ask_name,
2694 void *ask_name_context);
2696 /****f* silcclient/SilcClientAPI/silc_client_file_close
2700 * SilcClientFileError silc_client_file_close(SilcClient client,
2701 * SilcClientConnection conn,
2702 * SilcUInt32 session_id);
2706 * Closes file transmission session indicated by the `session_id'.
2707 * If file transmission is being conducted it will be aborted
2708 * automatically. This function is also used to close the session
2709 * after successful file transmission. This function can be used
2710 * also to reject incoming file transmission request. If the
2711 * session was already started and the monitor callback was set
2712 * the monitor callback will be called with the monitor status
2713 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2716 SilcClientFileError silc_client_file_close(SilcClient client,
2717 SilcClientConnection conn,
2718 SilcUInt32 session_id);
2720 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2724 * SilcAttributePayload
2725 * silc_client_attribute_add(SilcClient client,
2726 * SilcClientConnection conn,
2727 * SilcAttribute attribute,
2729 * SilcUInt32 object_size);
2733 * Add new Requsted Attribute for WHOIS command to the client library.
2734 * The `attribute' object indicated by `object' is added and allocated
2735 * SilcAttributePayload is returned. The `object' must be of correct
2736 * type and of correct size. See the SilcAttribute for object types
2737 * for different attributes. You may also get all added attributes
2738 * from the client with silc_client_attributes_get function.
2740 * Requested Attributes are different personal information about the
2741 * user, status information and other information which other users
2742 * may query with WHOIS command. Application may set these so that
2743 * if someone sends WHOIS query these attributes will be replied back
2744 * to the sender. The library always puts the public key to the
2745 * Requested Attributes, but if application wishes to add additional
2746 * public keys (or certificates) it can be done with this interface.
2747 * Library also always computes digital signature of the attributes
2748 * automatically, so application does not need to do that.
2751 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2752 SilcClientConnection conn,
2753 SilcAttribute attribute,
2755 SilcUInt32 object_size);
2757 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2761 * bool silc_client_attribute_del(SilcClient client,
2762 * SilcClientConnection conn,
2763 * SilcAttribute attribute,
2764 * SilcAttributePayload attr);
2768 * Delete a Requested Attribute from the client. If the `attribute'
2769 * is non-zero then all attributes of that type are deleted and the
2770 * `attr' is ignored. If `attr' is non-NULL then that specific
2771 * attribute is deleted and `attribute' is ignored.
2773 * You may get all added attributes with the function
2774 * silc_client_attributes_get and to get the SilcAttributePayload.
2775 * This function Returns TRUE if the attribute was found and deleted.
2778 bool silc_client_attribute_del(SilcClient client,
2779 SilcClientConnection conn,
2780 SilcAttribute attribute,
2781 SilcAttributePayload attr);
2783 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2787 * const SilcHashTable
2788 * silc_client_attributes_get(SilcClient client,
2789 * SilcClientConnection conn);
2793 * Returns pointer to the SilcHashTable which includes all the added
2794 * Requested Attributes. The caller must not free the hash table.
2795 * The caller may use SilcHashTableList and silc_hash_table_list to
2796 * traverse the table. Each entry in the hash table is one added
2797 * SilcAttributePayload. It is possible to delete a attribute
2798 * payload while traversing the table.
2801 const SilcHashTable silc_client_attributes_get(SilcClient client,
2802 SilcClientConnection conn);
2804 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2808 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2812 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2813 * then all attributes are requested. Alternatively, `attribute' and
2814 * all variable arguments can each be requested attribute. In this case
2815 * the last must be set to zero (0) to complete the variable list of
2816 * requested attributes. See SilcAttribute for all attributes.
2817 * You can give the returned buffer as argument to for example
2818 * silc_client_get_client_by_id_resolve function.
2822 * Request all attributes
2823 * buffer = silc_client_attributes_request(0);
2825 * Request only the following attributes
2826 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2827 * SILC_ATTRIBUTE_SERVICE,
2828 * SILC_ATTRIBUTE_MOOD, 0);
2831 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2833 /* Low level packet sending functions */
2835 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2839 * bool silc_client_send_packet(SilcClient client,
2840 * SilcClientConnection conn,
2841 * SilcPacketType type,
2842 * const unsigned char *data,
2843 * SilcUInt32 data_len);
2847 * This routine can be used by application to send packets directly
2848 * to a connection indicated by `conn'. Usually application does not
2849 * need this routine since the Client Library handles the packet
2850 * sending. The `type' indicates the packet type. If `data' is
2851 * NULL then empty packet is sent. This returns FALSE if packet cannot
2855 bool silc_client_send_packet(SilcClient client,
2856 SilcClientConnection conn,
2857 SilcPacketType type,
2858 const unsigned char *data,
2859 SilcUInt32 data_len);
2861 #include "command.h"
2862 #include "command_reply.h"
2864 #include "protocol.h"
2870 #endif /* SILCCLIENT_H */