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.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
59 /* General definitions */
61 /****s* silcclient/SilcClientAPI/SilcClient
65 * typedef struct SilcClientStruct { ... } *SilcClient
69 * This is the actual SILC Client structure which represents one
70 * SILC Client. It is allocated with the silc_client_alloc function
71 * and given as argument to all SILC Client Library functions. It
72 * is initialized with silc_client_init function, and freed with
73 * silc_client_free function.
77 struct SilcClientStruct {
79 * The following fields are set by application
81 char *nickname; /* Nickname, MAY be set by application */
82 char *username; /* Username, MUST be set by application */
83 char *hostname; /* hostname, MUST be set by application */
84 char *realname; /* Real name, MUST be set be application */
86 SilcPublicKey public_key; /* Public key of user, set by application */
87 SilcPrivateKey private_key; /* Private key of user, set by application */
88 SilcPKCS pkcs; /* PKCS allocated by application */
91 * The following fields are set by the library
94 /* Scheduler, set by library. Application may use this pointer. */
95 SilcSchedule schedule;
97 /* Random Number Generator. Application should use this as its primary
98 random number generator. */
101 /* Application specific user data pointer. Client library does not
102 touch this. This the context sent as argument to silc_client_alloc.
103 Application can use it freely. */
106 /* Generic hash context for application usage */
110 /* Internal data for client library. Application cannot access this
112 SilcClientInternal internal;
116 /****s* silcclient/SilcClientAPI/SilcClientConnection
120 * typedef struct SilcClientConnectionStruct { ... }
121 * *SilcClientConnection
125 * This structure represents a connection. When connection is created
126 * to server this is context is returned to the application in the
127 * "connected" client operation. It includes all the important
128 * data for the session, such as nickname, local and remote IDs, and
133 struct SilcClientConnectionStruct {
137 char *nickname; /* Current nickname */
138 SilcClientEntry local_entry; /* Own Client Entry */
139 SilcClientID *local_id; /* Current Client ID */
140 unsigned char *local_id_data; /* Current Client ID decoded */
141 SilcUInt32 local_id_data_len;
146 char *remote_host; /* Remote host name */
147 int remote_port; /* Remote port */
148 SilcServerID *remote_id; /* Remote Server ID */
149 unsigned char *remote_id_data; /* Remote Server ID decoded */
150 SilcUInt32 remote_id_data_len;
156 /* Current command identifier for a command that was sent last.
157 Application may get the value from this variable to find out the
158 command identifier for last command. */
159 SilcUInt16 cmd_ident;
161 /* User data context. Library does not touch this. Application may
162 freely set and use this pointer for its needs. */
165 /* Pointer back to the SilcClient. Application may use this. */
168 /* Current channel. Application may use and set this pointer if needed. */
169 SilcChannelEntry current_channel;
171 /* Socket connection object for this connection. Application may
172 use this if needed. The sock->user_data is back pointer to this
174 SilcSocketConnection sock;
176 /* Internal data for client library. Application cannot access this
178 SilcClientConnectionInternal internal;
182 /****s* silcclient/SilcClientAPI/SilcClientEntry
186 * typedef struct SilcClientEntryStruct { ... } *SilcClientEntry
190 * This structure represents a client or a user in the SILC network.
191 * The local user has this structure also and it can be accessed from
192 * SilcClientConnection structure. All other users in the SILC network
193 * that are accessed using the Client Library routines will have their
194 * own SilcClientEntry structure. For example, when finding users by
195 * their nickname the Client Library returns this structure back to
200 struct SilcClientEntryStruct {
201 /* General information */
202 char *nickname; /* nickname */
203 char *username; /* username */
204 char *hostname; /* hostname */
205 char *server; /* SILC server name */
206 char *realname; /* Realname (userinfo) */
208 /* Mode, ID and other information */
209 SilcUInt32 mode; /* User mode in SILC, see SilcUserMode */
210 SilcClientID *id; /* The Client ID */
211 SilcDList attrs; /* Requested Attributes (maybe NULL) */
212 unsigned char *fingerprint; /* Fingerprint of client's public key */
213 SilcUInt32 fingerprint_len; /* Length of the fingerprint */
214 SilcPublicKey public_key; /* User's public key, may be NULL */
216 /* Private message keys */
217 SilcCipher send_key; /* Private message key for sending */
218 SilcCipher receive_key; /* Private message key for receiving */
219 SilcHmac hmac_send; /* Private mesage key HMAC for sending */
220 SilcHmac hmac_receive; /* Private mesage key HMAC for receiving */
221 unsigned char *key; /* Set only if application provided the
222 key material. NULL if the library
223 generated the key. */
224 SilcUInt32 key_len; /* Key length */
225 SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
227 /* SilcClientEntry status information */
228 SilcEntryStatus status; /* Status mask */
229 SilcHashTable channels; /* All channels client has joined */
230 SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
231 unsigned int generated : 1; /* TRUE if library generated `key' */
232 unsigned int valid : 1; /* FALSE if this entry is not valid */
233 unsigned int prv_resp : 1; /* TRUE if private message key indicator
234 has been received (responder). */
236 /* Application specific data. Application may set here whatever it wants. */
241 /****s* silcclient/SilcClientAPI/SilcChannelEntry
245 * typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
249 * This structure represents a channel in the SILC network. All
250 * channels that the client are aware of or have joined in will be
251 * represented as SilcChannelEntry. The structure includes information
256 struct SilcChannelEntryStruct {
257 /* General information */
258 char *channel_name; /* Channel name */
259 SilcChannelID *id; /* Channel ID */
260 SilcUInt32 mode; /* Channel mode, ChannelModes. */
261 char *topic; /* Current topic, may be NULL */
262 SilcPublicKey founder_key; /* Founder key, may be NULL */
263 SilcUInt32 user_limit; /* User limit on channel */
265 /* All clients that has joined this channel. The key to the table is the
266 SilcClientEntry and the context is SilcChannelUser context. */
267 SilcHashTable user_list;
270 SilcCipher channel_key; /* The channel key */
271 unsigned char *key; /* Raw key data */
272 SilcUInt32 key_len; /* Raw key data length */
273 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
274 SilcHmac hmac; /* Current HMAC */
276 /* Channel private keys */
277 SilcDList private_keys; /* List of private keys or NULL */
278 SilcChannelPrivateKey curr_key; /* Current private key */
280 /* SilcChannelEntry status information */
281 SilcDList old_channel_keys;
283 SilcUInt16 resolve_cmd_ident; /* Command identifier when
284 resolving this entry */
286 /* Application specific data. Application may set here whatever it wants. */
291 /****s* silcclient/SilcClientAPI/SilcChannelUser
295 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
299 * This structure represents a client that has joined to a channel.
300 * It shows the client and the channel and the client's mode (channel
301 * user mode) on the channel.
305 struct SilcChannelUserStruct {
306 SilcClientEntry client; /* Client joined on channel */
307 SilcUInt32 mode; /* mode, ChannelUserModes */
308 SilcChannelEntry channel; /* The channel user has joined */
310 /* Application specific data. Application may set here whatever it wants. */
315 /****s* silcclient/SilcClientAPI/SilcServerEntry
319 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
323 * This structure represents a server in the SILC network. All servers
324 * that the client is aware of and have for example resolved with
325 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
329 struct SilcServerEntryStruct {
330 /* General information */
331 char *server_name; /* Server name */
332 char *server_info; /* Server info */
333 SilcServerID *server_id; /* Server ID */
334 SilcUInt16 resolve_cmd_ident; /* Command identifier when
335 resolving this entry */
337 /* Application specific data. Application may set here whatever it wants. */
342 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
346 * typedef enum { ... } SilcKeyAgreementStatus;
350 * Key agreement status types indicating the status of the key
351 * agreement protocol. These types are returned to the application
352 * in the SilcKeyAgreementCallback callback function.
357 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
358 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
359 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
360 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
361 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
362 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
363 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
364 } SilcKeyAgreementStatus;
367 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
371 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
372 * SilcClientConnection conn,
373 * SilcClientEntry client_entry,
374 * SilcKeyAgreementStatus status,
375 * SilcSKEKeyMaterial *key,
380 * Key agreement callback that is called after the key agreement protocol
381 * has been performed. This is called also if error occurred during the
382 * key agreement protocol. The `key' is the allocated key material and
383 * the caller is responsible of freeing it. The `key' is NULL if error
384 * has occurred. The application can freely use the `key' to whatever
385 * purpose it needs. See lib/silcske/silcske.h for the definition of
386 * the SilcSKEKeyMaterial structure.
389 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
390 SilcClientConnection conn,
391 SilcClientEntry client_entry,
392 SilcKeyAgreementStatus status,
393 SilcSKEKeyMaterial *key,
396 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
400 * typedef struct { ... } SilcPrivateMessageKeys;
404 * Structure to hold the list of private message keys. The array of this
405 * structure is returned by the silc_client_list_private_message_keys
411 SilcClientEntry client_entry; /* The remote client entry */
412 char *cipher; /* The cipher name */
413 unsigned char *key; /* The original key, If the appliation
414 provided it. This is NULL if the
415 library generated the key or if
416 the SKE key material was used. */
417 SilcUInt32 key_len; /* The key length */
418 } *SilcPrivateMessageKeys;
421 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
425 * typedef struct SilcChannelPrivateKeyStruct { ... }
426 * *SilcChannelPrivateKey;
430 * Structure to hold one channel private key. The array of this structure
431 * is returned by silc_client_list_channel_private_keys function.
435 struct SilcChannelPrivateKeyStruct {
436 char *name; /* Application given name */
437 SilcCipher cipher; /* The cipher and key */
438 SilcHmac hmac; /* The HMAC and hmac key */
439 unsigned char *key; /* The key data */
440 SilcUInt32 key_len; /* The key length */
444 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
448 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
449 * SilcUInt32 passphrase_len,
454 * Ask passphrase callback. This is called by the application when the
455 * library calls `ask_passphrase' client operation. The callback delivers
456 * the passphrase to the library. The passphrases in SILC protocol
457 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
458 * encoded, and if it is not then library will attempt to encode it.
461 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
462 SilcUInt32 passphrase_len,
465 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
469 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
473 * Public key (or certificate) verification callback. This is called
474 * by the application to indicate that the public key verification was
475 * either success or failure.
478 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
480 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
484 * typedef void (*SilcGetAuthMeth)(bool success,
485 * SilcProtocolAuthMeth auth_meth,
486 * const unsigned char *auth_data,
487 * SilcUInt32 auth_data_len, void *context);
491 * Authentication method resolving callback. This is called by the
492 * application to return the resolved authentication method. The client
493 * library has called the get_auth_method client operation and given
494 * this function pointer as argument. The `success' will indicate whether
495 * the authentication method could be resolved. The `auth_meth' is the
496 * resolved authentication method. The `auth_data' and the `auth_data_len'
497 * are the resolved authentication data. The `context' is the libary's
498 * context sent to the get_auth_method client operation.
501 typedef void (*SilcGetAuthMeth)(bool success,
502 SilcProtocolAuthMeth auth_meth,
503 const unsigned char *auth_data,
504 SilcUInt32 auth_data_len, void *context);
506 /****d* silcclient/SilcClientAPI/SilcClientMessageType
510 * typedef enum { ... } SilcClientMessageType;
514 * Different message types for `say' client operation. The application
515 * may filter the message sent by the library according this type.
520 SILC_CLIENT_MESSAGE_INFO, /* Informational */
521 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
522 SILC_CLIENT_MESSAGE_ERROR, /* Error */
523 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
524 } SilcClientMessageType;
527 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
531 * typedef enum { ... } SilcClientConnectionStatus
535 * This type is returned to the `connect' client operation to indicate
536 * the status of the created connection. It can indicate if it was
537 * successful or whether an error occurred.
542 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
543 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
544 resumed old detached session */
545 SILC_CLIENT_CONN_ERROR, /* Unknown error occurred during
547 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
548 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
549 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
550 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
551 } SilcClientConnectionStatus;
554 /****s* silcclient/SilcClientAPI/SilcClientOperations
558 * typedef struct { ... } SilcClientOperations;
562 * SILC Client Operations. These must be implemented by the application.
563 * The Client library may call any of these routines at any time. The
564 * routines are used to deliver certain information to the application
565 * or from the application to the client library.
570 /* Message sent to the application by library. `conn' associates the
571 message to a specific connection. `conn', however, may be NULL.
572 The `type' indicates the type of the message sent by the library.
573 The application can for example filter the message according the
574 type. The variable argument list is arguments to the formatted
575 message that `msg' may be. */
576 void (*say)(SilcClient client, SilcClientConnection conn,
577 SilcClientMessageType type, char *msg, ...);
579 /* Message for a channel. The `sender' is the sender of the message
580 The `channel' is the channel. The `message' is the message. Note
581 that `message' maybe NULL. The `flags' indicates message flags
582 and it is used to determine how the message can be interpreted
583 (like it may tell the message is multimedia message). */
584 void (*channel_message)(SilcClient client, SilcClientConnection conn,
585 SilcClientEntry sender, SilcChannelEntry channel,
586 SilcMessagePayload payload,
587 SilcChannelPrivateKey key, SilcMessageFlags flags,
588 const unsigned char *message,
589 SilcUInt32 message_len);
591 /* Private message to the client. The `sender' is the sender of the
592 message. The message is `message'and maybe NULL. The `flags'
593 indicates message flags and it is used to determine how the message
594 can be interpreted (like it may tell the message is multimedia
596 void (*private_message)(SilcClient client, SilcClientConnection conn,
597 SilcClientEntry sender, SilcMessagePayload payload,
598 SilcMessageFlags flags,
599 const unsigned char *message,
600 SilcUInt32 message_len);
602 /* Notify message to the client. The notify arguments are sent in the
603 same order as servers sends them. The arguments are same as received
604 from the server except for ID's. If ID is received application receives
605 the corresponding entry to the ID. For example, if Client ID is received
606 application receives SilcClientEntry. Also, if the notify type is
607 for channel the channel entry is sent to application (even if server
608 does not send it because client library gets the channel entry from
609 the Channel ID in the packet's header). */
610 void (*notify)(SilcClient client, SilcClientConnection conn,
611 SilcNotifyType type, ...);
613 /* Command handler. This function is called always in the command function.
614 If error occurs it will be called as well. `conn' is the associated
615 client connection. `cmd_context' is the command context that was
616 originally sent to the command. `success' is FALSE if error occurred
617 during command. `command' is the command being processed. It must be
618 noted that this is not reply from server. This is merely called just
619 after application has called the command. Just to tell application
620 that the command really was processed. */
621 void (*command)(SilcClient client, SilcClientConnection conn,
622 SilcClientCommandContext cmd_context, bool success,
623 SilcCommand command, SilcStatus status);
625 /* Command reply handler. This function is called always in the command reply
626 function. If error occurs it will be called as well. Normal scenario
627 is that it will be called after the received command data has been parsed
628 and processed. The function is used to pass the received command data to
631 `conn' is the associated client connection. `cmd_payload' is the command
632 payload data received from server and it can be ignored. It is provided
633 if the application would like to re-parse the received command data,
634 however, it must be noted that the data is parsed already by the library
635 thus the payload can be ignored. `success' is FALSE if error occurred.
636 In this case arguments are not sent to the application. The `status' is
637 the command reply status server returned. The `command' is the command
638 reply being processed. The function has variable argument list and each
639 command defines the number and type of arguments it passes to the
640 application (on error they are not sent).
642 The arguments are sent in the same order as servers sends them. The
643 arguments are same as received from the server except for ID's. If
644 ID is received application receives the corresponding entry to the
645 ID. For example, if Client ID is receives application receives
647 void (*command_reply)(SilcClient client, SilcClientConnection conn,
648 SilcCommandPayload cmd_payload, bool success,
649 SilcCommand command, SilcStatus status, ...);
651 /* Called to indicate that connection was either successfully established
652 or connecting failed. This is also the first time application receives
653 the SilcClientConnection object which it should save somewhere.
654 The `status' indicated whether the connection were successful. If it
655 is error value the application must always call the function
656 silc_client_close_connection. */
657 void (*connected)(SilcClient client, SilcClientConnection conn,
658 SilcClientConnectionStatus status);
660 /* Called to indicate that connection was disconnected to the server.
661 The `status' may tell the reason of the disconnection, and if the
662 `message' is non-NULL it may include the disconnection message
663 received from server. Application must not call the
664 silc_client_close_connection in this callback. The 'conn' is also
665 invalid after this function returns back to library. */
666 void (*disconnected)(SilcClient client, SilcClientConnection conn,
667 SilcStatus status, const char *message);
669 /* Find authentication method and authentication data by hostname and
670 port. The hostname may be IP address as well. When the authentication
671 method has been resolved the `completion' callback with the found
672 authentication method and authentication data is called. The `conn'
674 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
675 char *hostname, SilcUInt16 port,
676 SilcGetAuthMeth completion, void *context);
678 /* Verifies received public key. The `conn_type' indicates which entity
679 (server, client etc.) has sent the public key. If user decides to trust
680 the application may save the key as trusted public key for later
681 use. The `completion' must be called after the public key has been
683 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
684 SilcSocketType conn_type, unsigned char *pk,
685 SilcUInt32 pk_len, SilcSKEPKType pk_type,
686 SilcVerifyPublicKey completion, void *context);
688 /* Ask (interact, that is) a passphrase from user. The passphrase is
689 returned to the library by calling the `completion' callback with
690 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
691 if not then the library will attempt to encode. */
692 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
693 SilcAskPassphrase completion, void *context);
695 /* Notifies application that failure packet was received. This is called
696 if there is some protocol active in the client. The `protocol' is the
697 protocol context. The `failure' is opaque pointer to the failure
698 indication. Note, that the `failure' is protocol dependant and
699 application must explicitly cast it to correct type. Usually `failure'
700 is 32 bit failure type (see protocol specs for all protocol failure
702 void (*failure)(SilcClient client, SilcClientConnection conn,
703 SilcProtocol protocol, void *failure);
705 /* Asks whether the user would like to perform the key agreement protocol.
706 This is called after we have received an key agreement packet or an
707 reply to our key agreement packet. This returns TRUE if the user wants
708 the library to perform the key agreement protocol and FALSE if it is not
709 desired (application may start it later by calling the function
710 silc_client_perform_key_agreement). If TRUE is returned also the
711 `completion' and `context' arguments must be set by the application. */
712 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
713 SilcClientEntry client_entry, const char *hostname,
714 SilcUInt16 port, SilcKeyAgreementCallback *completion,
717 /* Notifies application that file transfer protocol session is being
718 requested by the remote client indicated by the `client_entry' from
719 the `hostname' and `port'. The `session_id' is the file transfer
720 session and it can be used to either accept or reject the file
721 transfer request, by calling the silc_client_file_receive or
722 silc_client_file_close, respectively. */
723 void (*ftp)(SilcClient client, SilcClientConnection conn,
724 SilcClientEntry client_entry, SilcUInt32 session_id,
725 const char *hostname, SilcUInt16 port);
727 /* Delivers SILC session detachment data indicated by `detach_data' to the
728 application. If application has issued SILC_COMMAND_DETACH command
729 the client session in the SILC network is not quit. The client remains
730 in the network but is detached. The detachment data may be used later
731 to resume the session in the SILC Network. The appliation is
732 responsible of saving the `detach_data', to for example in a file.
734 The detachment data can be given as argument to the functions
735 silc_client_connect_to_server, or silc_client_add_connection when
736 creating connection to remote server, inside SilcClientConnectionParams
737 structure. If it is provided the client library will attempt to resume
738 the session in the network. After the connection is created
739 successfully, the application is responsible of setting the user
740 interface for user into the same state it was before detaching (showing
741 same channels, channel modes, etc). It can do this by fetching the
742 information (like joined channels) from the client library. */
743 void (*detach)(SilcClient client, SilcClientConnection conn,
744 const unsigned char *detach_data,
745 SilcUInt32 detach_data_len);
746 } SilcClientOperations;
749 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
753 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
754 * char **ret_nickname);
758 * A callback function provided by the application for the library in
759 * SilcClientParams structure. This function parses the formatted
760 * nickname string `nickname' and returns the true nickname to the
761 * `ret_nickname' pointer. The library can call this function at
765 typedef void (*SilcNicknameFormatParse)(const char *nickname,
766 char **ret_nickname);
768 /****s* silcclient/SilcClientAPI/SilcClientParams
772 * typedef struct { ... } SilcClientParams;
776 * Client parameters. This can be filled with proper values and
777 * given as argument to the silc_client_alloc function. The structure
778 * hold various parameters which affects the function of the client.
783 /* Number of maximum tasks the client library's scheduler can handle.
784 If set to zero, the default value will be used (200). For WIN32
785 systems this should be set to 64 as it is the hard limit dictated
789 /* Rekey timeout in seconds. The client will perform rekey in this
790 time interval. If set to zero, the default value will be used. */
791 unsigned int rekey_secs;
793 /* Connection authentication method request timeout. If server does not
794 reply back the current authentication method when we've requested it
795 in this time interval we'll assume the reply will not come at all.
796 If set to zero, the default value (2 seconds) will be used. */
797 unsigned int connauth_request_secs;
799 /* Nickname format string. This can be used to order the client library
800 to save the nicknames in the library in a certain format. Since
801 nicknames are not unique in SILC it is possible to have multiple same
802 nicknames. Using this format string it is possible to order the library
803 to separate the multiple same nicknames from each other. The format
804 types are defined below and they can appear in any order in the format
805 string. If this is NULL then default format is used which is the
806 default nickname without anything else. The string MUST be NULL
809 Following format types are available:
811 %n nickname - the real nickname returned by the server (mandatory)
812 %h hostname - the stripped hostname of the client
813 %H full hostname - the full hostname of the client
814 %s server name - the server name the client is connected
815 %S full server - the full server name the client is connected
816 %a number - ascending number in case there are several
817 same nicknames (fe. nick@host and nick@host2)
819 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
820 "%a!%n@%s" (fe. nick@server, 2!nick@server)
821 "%n@%H" (fe. nick@host.domain.com)
823 By default this format is employed to the nicknames by the libary
824 only when there appears multiple same nicknames. If the library has
825 only one nickname cached the nickname is saved as is and without the
826 defined format. If you want always to save the nickname in the defined
827 format set the boolean field `nickname_force_format' to value TRUE.
829 char nickname_format[32];
831 /* If this is set to TRUE then the `nickname_format' is employed to all
832 saved nicknames even if there are no multiple same nicknames in the
833 cache. By default this is FALSE, which means that the `nickname_format'
834 is employed only if the library will receive a nickname that is
835 already saved in the cache. It is recommended to leave this to FALSE
837 bool nickname_force_format;
839 /* A callback function provided by the application for the library to
840 parse the nickname from the formatted nickname string. Even though
841 the libary formats the nicknames the application knows generally the
842 format better so this function should be provided for the library
843 if the application sets the `nickname_format' field. The library
844 will call this to get the true nickname from the provided formatted
845 nickname string whenever it needs the true nickname. */
846 SilcNicknameFormatParse nickname_parse;
848 /* If this is set to TRUE then the client will ignore all incoming
849 Requested Attributes queries and does not reply anything back. This
850 usually leads into situation where server does not anymore send
851 the queries after seeing that client does not reply anything back.
852 If your application does not support Requested Attributes or you do
853 not want to use them set this to TRUE. See SilcAttribute and
854 silc_client_attribute_add for more information on attributes. */
855 bool ignore_requested_attributes;
861 /* Initialization functions (client.c) */
863 /****f* silcclient/SilcClientAPI/silc_client_alloc
867 * SilcClient silc_client_alloc(SilcClientOperations *ops,
868 * SilcClientParams *params,
870 * const char *silc_version);
874 * Allocates new client object. This has to be done before client may
875 * work. After calling this one must call silc_client_init to initialize
876 * the client. The `application' is application specific user data pointer
877 * and caller must free it. The `silc_version' is the application version
878 * that will be used to compare against remote host's (usually a server)
879 * version string. The `application' context is accessible by the
880 * application by client->application, client being SilcClient.
883 SilcClient silc_client_alloc(SilcClientOperations *ops,
884 SilcClientParams *params,
886 const char *version_string);
888 /****f* silcclient/SilcClientAPI/silc_client_free
892 * void silc_client_free(SilcClient client);
896 * Frees client object and its internals. The execution of the client
897 * should be stopped with silc_client_stop function before calling
901 void silc_client_free(SilcClient client);
903 /****f* silcclient/SilcClientAPI/silc_client_init
907 * bool silc_client_init(SilcClient client);
911 * Initializes the client. This makes all the necessary steps to make
912 * the client ready to be run. One must call silc_client_run to run the
913 * client. Returns FALSE if error occurred, TRUE otherwise.
916 bool silc_client_init(SilcClient client);
918 /****f* silcclient/SilcClientAPI/silc_client_run
922 * void silc_client_run(SilcClient client);
926 * Runs the client. This starts the scheduler from the utility library.
927 * When this functions returns the execution of the appliation is over.
928 * The client must be initialized before calling this.
931 void silc_client_run(SilcClient client);
933 /****f* silcclient/SilcClientAPI/silc_client_run_one
937 * void silc_client_run_one(SilcClient client);
941 * Runs the client and returns immeadiately. This function is used when
942 * the SILC Client object indicated by the `client' is run under some
943 * other scheduler, or event loop or main loop. On GUI applications,
944 * for example this may be desired to used to run the client under the
945 * GUI application's main loop. Typically the GUI application would
946 * register an idle task that calls this function multiple times in
947 * a second to quickly process the SILC specific data.
950 void silc_client_run_one(SilcClient client);
952 /****f* silcclient/SilcClientAPI/silc_client_stop
956 * void silc_client_stop(SilcClient client);
960 * Stops the client. This is called to stop the client and thus to stop
961 * the program. The client context must be freed with the silc_client_free
965 void silc_client_stop(SilcClient client);
968 /* Connecting functions (client.c) */
970 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
974 * typedef struct { ... } SilcClientConnectionParams;
978 * Client connection parameters. This can be filled by the application
979 * and given as argument to silc_client_connect_to_server or to
980 * silc_client_add_connection.
985 /* The SILC session detachment data that was returned by `detach' client
986 operation when the application detached from the network. Application
987 is responsible of saving the data and giving it as argument here
988 for resuming the session in the SILC network.
990 If this is provided here the client library will attempt to resume
991 the session in the network. After the connection is created
992 successfully, the application is responsible of setting the user
993 interface for user into the same state it was before detaching (showing
994 same channels, channel modes, etc). It can do this by fetching the
995 information (like joined channels) from the client library. */
996 unsigned char *detach_data;
997 SilcUInt32 detach_data_len;
999 } SilcClientConnectionParams;
1002 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
1006 * int silc_client_connect_to_server(SilcClient client,
1007 * SilcClientConnectionParams *params,
1008 * int port, char *host, void *context);
1012 * Connects to remote server. This is the main routine used to connect
1013 * to SILC server. Returns -1 on error and the created socket otherwise.
1014 * The `context' is user context that is saved into the SilcClientConnection
1015 * that is created after the connection is created. Note that application
1016 * may handle the connecting process outside the library. If this is the
1017 * case then this function is not used at all. When the connecting is
1018 * done the `connect' client operation is called, and the `context' is
1019 * accessible with conn->context, conn being SilcClientConnection.
1020 * If the `params' is provided they are used by the routine.
1023 int silc_client_connect_to_server(SilcClient client,
1024 SilcClientConnectionParams *params,
1025 int port, char *host, void *context);
1027 /****f* silcclient/SilcClientAPI/silc_client_add_connection
1032 * SilcClientConnection
1033 * silc_client_add_connection(SilcClient client,
1034 * SilcClientConnectionParams *params,
1035 * char *hostname, int port, void *context);
1039 * Allocates and adds new connection to the client. This adds the allocated
1040 * connection to the connection table and returns a pointer to it. A client
1041 * can have multiple connections to multiple servers. Every connection must
1042 * be added to the client using this function. User data `context' may
1043 * be sent as argument. If the `params' is provided they are used by
1048 * This function is normally used only if the application performed
1049 * the connecting outside the library, and did not called the
1050 * silc_client_connect_to_server function at all. The library
1051 * however may use this internally.
1054 SilcClientConnection
1055 silc_client_add_connection(SilcClient client,
1056 SilcClientConnectionParams *params,
1057 char *hostname, int port, void *context);
1059 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1063 * void silc_client_del_connection(SilcClient client,
1064 * SilcClientConnection conn);
1068 * Removes connection from client. Frees all memory. The library
1069 * call this function automatically for all connection contexts.
1070 * The application however may free the connection contexts it has
1074 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1076 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1080 * void silc_client_add_socket(SilcClient client,
1081 * SilcSocketConnection sock);
1085 * Adds listener socket to the listener sockets table. This function is
1086 * used to add socket objects that are listeners to the client. This should
1087 * not be used to add other connection objects.
1090 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1092 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1096 * void silc_client_del_socket(SilcClient client,
1097 * SilcSocketConnection sock);
1101 * Deletes listener socket from the listener sockets table. If the
1102 * application has added a socket with silc_client_add_socket it must
1103 * also free it using this function.
1106 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1108 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1112 * void silc_client_start_key_exchange(SilcClient client,
1113 * SilcClientConnection conn,
1118 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1119 * key material between client and server. This function can be called
1120 * directly if application is performing its own connecting and does not
1121 * use the connecting provided by this library. This function is normally
1122 * used only if the application performed the connecting outside the
1123 * library. The library however may use this internally. After the
1124 * key exchange is performed the `connect' client operation is called.
1128 * The silc_client_add_connection must be called before calling this
1129 * function to create the SilcClientConnection context for this
1133 void silc_client_start_key_exchange(SilcClient client,
1134 SilcClientConnection conn,
1137 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1141 * void silc_client_close_connection(SilcClient client,
1142 * SilcClientConnection conn);
1146 * Closes connection to remote end. Free's all allocated data except
1147 * for some information such as nickname etc. that are valid at all time.
1148 * Usually application does not need to directly call this, except
1149 * when explicitly closing the connection, or if an error occurs
1150 * during connection to server (see 'connect' client operation for
1151 * more information).
1154 void silc_client_close_connection(SilcClient client,
1155 SilcClientConnection conn);
1158 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1160 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1164 * bool silc_client_send_channel_message(SilcClient client,
1165 * SilcClientConnection conn,
1166 * SilcChannelEntry channel,
1167 * SilcChannelPrivateKey key,
1168 * SilcMessageFlags flags,
1169 * unsigned char *data,
1170 * SilcUInt32 data_len,
1175 * Sends packet to the `channel'. Packet to channel is always encrypted
1176 * differently from "normal" packets. SILC header of the packet is
1177 * encrypted with the next receiver's key and the rest of the packet is
1178 * encrypted with the channel specific key. Padding and HMAC is computed
1179 * with the next receiver's key. The `data' is the channel message. If
1180 * the `force_send' is TRUE then the packet is sent immediately.
1182 * If `key' is provided then that private key is used to encrypt the
1183 * channel message. If it is not provided, private keys has not been
1184 * set at all, the normal channel key is used automatically. If private
1185 * keys are set then the first key (the key that was added first as
1186 * private key) is used.
1188 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1189 * digitally signed with the SILC key pair.
1191 * Returns TRUE if the message was sent, and FALSE if error occurred or
1192 * the sending is not allowed due to channel modes (like sending is
1196 bool silc_client_send_channel_message(SilcClient client,
1197 SilcClientConnection conn,
1198 SilcChannelEntry channel,
1199 SilcChannelPrivateKey key,
1200 SilcMessageFlags flags,
1201 unsigned char *data,
1202 SilcUInt32 data_len,
1205 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1209 * bool silc_client_send_private_message(SilcClient client,
1210 * SilcClientConnection conn,
1211 * SilcClientEntry client_entry,
1212 * SilcMessageFlags flags,
1213 * unsigned char *data,
1214 * SilcUInt32 data_len,
1219 * Sends private message to remote client. If private message key has
1220 * not been set with this client then the message will be encrypted using
1221 * normal session keys. Private messages are special packets in SILC
1222 * network hence we need this own function for them. This is similar
1223 * to silc_client_packet_send_to_channel except that we send private
1224 * message. The `data' is the private message. If the `force_send' is
1225 * TRUE the packet is sent immediately.
1227 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1228 * digitally signed with the SILC key pair.
1230 * Returns TRUE if the message was sent, and FALSE if error occurred.
1233 bool silc_client_send_private_message(SilcClient client,
1234 SilcClientConnection conn,
1235 SilcClientEntry client_entry,
1236 SilcMessageFlags flags,
1237 unsigned char *data,
1238 SilcUInt32 data_len,
1242 /* Client and Channel entry retrieval (idlist.c) */
1244 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1248 * typedef void (*SilcGetClientCallback)(SilcClient client,
1249 * SilcClientConnection conn,
1250 * SilcClientEntry *clients,
1251 * SilcUInt32 clients_count,
1256 * Callback function given to the silc_client_get_client function. The
1257 * found entries are allocated into the `clients' array. The array must
1258 * not be freed by the receiver, the library will free it later. If the
1259 * `clients' is NULL, no such clients exist in the SILC Network.
1262 typedef void (*SilcGetClientCallback)(SilcClient client,
1263 SilcClientConnection conn,
1264 SilcClientEntry *clients,
1265 SilcUInt32 clients_count,
1268 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1272 * void silc_client_get_clients(SilcClient client,
1273 * SilcClientConnection conn,
1274 * const char *nickname,
1275 * const char *server,
1276 * SilcGetClientCallback completion,
1281 * Finds client entry or entries by the `nickname' and `server'. The
1282 * completion callback will be called when the client entries has been
1283 * found. After the server returns the client information it is cached
1284 * and can be accesses locally at a later time. The resolving is done
1285 * with IDENTIFY command. The `server' may be NULL.
1289 * NOTE: This function is always asynchronous and resolves the client
1290 * information from the server. Thus, if you already know the client
1291 * information then use the silc_client_get_client_by_id function to
1292 * get the client entry since this function may be very slow and should
1293 * be used only to initially get the client entries.
1295 * Since this routine resolves with IDENTIFY command only the relevant
1296 * information (user's nickname and username) is resolved. For example,
1297 * user's real name, channel list and others are not resolved. Caller
1298 * can/must resolve those separately if they are needed (for example,
1299 * with silc_client_get_client_by_id_resolve).
1302 void silc_client_get_clients(SilcClient client,
1303 SilcClientConnection conn,
1304 const char *nickname,
1306 SilcGetClientCallback completion,
1309 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
1313 * void silc_client_get_clients_whois(SilcClient client,
1314 * SilcClientConnection conn,
1315 * const char *nickname,
1316 * const char *server,
1317 * SilcBuffer attributes,
1318 * SilcGetClientCallback completion,
1323 * Finds client entry or entries by the `nickname' and `server'. The
1324 * completion callback will be called when the client entries has been
1325 * found. After the server returns the client information it is cached
1326 * and can be accesses locally at a later time. The resolving is done
1327 * with WHOIS command. The `server' may be NULL.
1329 * If the `attributes' is non-NULL then the buffer includes Requested
1330 * Attributes which can be used to fetch very detailed information
1331 * about the user. If it is NULL then only normal WHOIS query is
1332 * made (for more information about attributes see SilcAttribute).
1333 * Caller may create the `attributes' with silc_client_attributes_request
1338 * The resolving is done with WHOIS command. For this reason this
1339 * command may take a long time because it resolves detailed user
1343 void silc_client_get_clients_whois(SilcClient client,
1344 SilcClientConnection conn,
1345 const char *nickname,
1347 SilcBuffer attributes,
1348 SilcGetClientCallback completion,
1351 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1355 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1356 * SilcClientConnection conn,
1357 * const char *nickname,
1358 * const char *format,
1359 * SilcUInt32 *clients_count);
1363 * Same as silc_client_get_clients function but does not resolve anything
1364 * from the server. This checks local cache and returns all matching
1365 * clients from the local cache. If none was found this returns NULL.
1366 * The `nickname' is the real nickname of the client, and the `format'
1367 * is the formatted nickname to find exact match from multiple found
1368 * entries. The format must be same as given in the SilcClientParams
1369 * structure to the client library. If the `format' is NULL all found
1370 * clients by `nickname' are returned. The caller must return the
1374 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1375 SilcClientConnection conn,
1376 const char *nickname,
1378 SilcUInt32 *clients_count);
1380 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1384 * void silc_client_get_clients_by_channel(SilcClient client,
1385 * SilcClientConnection conn,
1386 * SilcChannelEntry channel,
1387 * SilcGetClientCallback completion,
1392 * Gets client entries by the channel indicated by `channel'. Thus,
1393 * it resovles the users currently on that channel. If all users are
1394 * already resolved this returns the users from the channel. If the
1395 * users are resolved only partially this resolves the complete user
1396 * information. If no users are resolved on this channel at all, this
1397 * calls USERS command to resolve all users on the channel. The `completion'
1398 * will be called after the entries are available. When server returns
1399 * the client information it will be cached and can be accessed locally
1402 * This function can be used for example in SILC_COMMAND_JOIN command
1403 * reply handling in application to resolve users on that channel. It
1404 * also can be used after calling silc_client_get_channel_resolve to
1405 * resolve users on that channel.
1409 * The resolving is done with WHOIS command. For this reason this
1410 * command may take a long time because it resolves detailed user
1414 void silc_client_get_clients_by_channel(SilcClient client,
1415 SilcClientConnection conn,
1416 SilcChannelEntry channel,
1417 SilcGetClientCallback completion,
1420 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1424 * void silc_client_get_clients_by_list(SilcClient client,
1425 * SilcClientConnection conn,
1426 * SilcUInt32 list_count,
1427 * SilcBuffer client_id_list,
1428 * SilcGetClientCallback completion,
1433 * Gets client entries by the list of client ID's `client_id_list'. This
1434 * always resolves those client ID's it does not know yet from the server
1435 * so this function might take a while. The `client_id_list' is a list
1436 * of ID Payloads added one after other. JOIN command reply and USERS
1437 * command reply for example returns this sort of list. The `completion'
1438 * will be called after the entries are available. When server returns
1439 * the client information it will be cached and can be accessed locally
1444 * The resolving is done with IDENTIFY command. This means that only
1445 * the relevant information of user (it's nickname and username) is
1446 * resolved. For example, user's real name, channel lists and others
1447 * are not resolved. Caller can/must resolve those separately if they
1448 * are needed (for example, with silc_client_get_client_by_id_resolve).
1451 void silc_client_get_clients_by_list(SilcClient client,
1452 SilcClientConnection conn,
1453 SilcUInt32 list_count,
1454 SilcBuffer client_id_list,
1455 SilcGetClientCallback completion,
1458 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1462 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1463 * SilcClientConnection conn,
1464 * SilcClientID *client_id);
1468 * Find entry for client by the client's ID. Returns the entry or NULL
1469 * if the entry was not found. This checks the local cache and does
1470 * not resolve anything from server.
1473 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1474 SilcClientConnection conn,
1475 SilcClientID *client_id);
1477 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1482 * silc_client_get_client_by_id_resolve(SilcClient client,
1483 * SilcClientConnection conn,
1484 * SilcClientID *client_id,
1485 * SilcBuffer attributes,
1486 * SilcGetClientCallback completion,
1491 * Same as silc_client_get_client_by_id but will always resolve the
1492 * information from the server. Use this only if you know that you
1493 * do not have the entry and the only thing you know about the client
1494 * is its ID. When server returns the client information it will be
1495 * cache and can be accessed locally at a later time. The resolving
1496 * is done by sending WHOIS command.
1498 * If the `attributes' is non-NULL then the buffer includes Requested
1499 * Attributes which can be used to fetch very detailed information
1500 * about the user. If it is NULL then only normal WHOIS query is
1501 * made (for more information about attributes see SilcAttribute).
1502 * Caller may create the `attributes' with silc_client_attributes_request
1506 void silc_client_get_client_by_id_resolve(SilcClient client,
1507 SilcClientConnection conn,
1508 SilcClientID *client_id,
1509 SilcBuffer attributes,
1510 SilcGetClientCallback completion,
1513 /****f* silcclient/SilcClientAPI/silc_client_del_client
1517 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1518 * SilcClientEntry client_entry)
1522 * Removes client from local cache by the client entry indicated by
1523 * the `client_entry'. Returns TRUE if the deletion were successful.
1526 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1527 SilcClientEntry client_entry);
1529 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1533 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1534 * SilcClientConnection conn,
1535 * SilcChannelEntry *channels,
1536 * SilcUInt32 channels_count,
1541 * Callback function given to the silc_client_get_channel_* functions.
1542 * The found entries are allocated into the `channels' array. The array
1543 * must not be freed by the receiver, the library will free it later.
1544 * If the `channel' is NULL, no such channel exist in the SILC Network.
1547 typedef void (*SilcGetChannelCallback)(SilcClient client,
1548 SilcClientConnection conn,
1549 SilcChannelEntry *channels,
1550 SilcUInt32 channels_count,
1553 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1557 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1558 * SilcClientConnection conn,
1559 * char *channel_name);
1563 * Finds entry for channel by the channel name. Returns the entry or NULL
1564 * if the entry was not found. It is found only if the client is joined
1565 * to the channel. Use silc_client_get_channel_resolve or
1566 * silc_client_get_channel_by_id_resolve to resolve channel that client
1570 SilcChannelEntry silc_client_get_channel(SilcClient client,
1571 SilcClientConnection conn,
1572 char *channel_name);
1574 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1578 * void silc_client_get_channel_resolve(SilcClient client,
1579 * SilcClientConnection conn,
1580 * char *channel_name,
1581 * SilcGetChannelCallback completion,
1586 * Resolves entry for channel by the channel name from the server.
1587 * The resolving is done with IDENTIFY command. Note that users on
1588 * the channel are not resolved at the same time. Use for example
1589 * silc_client_get_clients_by_channel to resolve all users on a channel.
1592 void silc_client_get_channel_resolve(SilcClient client,
1593 SilcClientConnection conn,
1595 SilcGetChannelCallback completion,
1598 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1603 * silc_client_get_channel_by_id(SilcClient client,
1604 * SilcClientConnection conn,
1605 * SilcChannelID *channel_id);
1609 * Finds channel entry by the channel ID. Returns the entry or NULL
1610 * if the entry was not found. This checks the local cache and does
1611 * not resolve anything from server.
1614 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1615 SilcClientConnection conn,
1616 SilcChannelID *channel_id);
1618 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1623 * silc_client_get_channel_by_id_resolve(SilcClient client,
1624 * SilcClientConnection conn,
1625 * SilcChannelID *channel_id,
1626 * SilcGetClientCallback completion,
1631 * Resolves the channel information (its name mainly) from the server
1632 * by the `channel_id'. Use this only if you know that you do not have
1633 * the entry cached locally. The resolving is done with IDENTIFY command.
1635 * Note that users on the channel are not resolved at the same time.
1636 * Use for example silc_client_get_clients_by_channel to resolve all
1637 * users on a channel.
1640 void silc_client_get_channel_by_id_resolve(SilcClient client,
1641 SilcClientConnection conn,
1642 SilcChannelID *channel_id,
1643 SilcGetChannelCallback completion,
1646 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1650 * bool silc_client_del_channel(SilcClient client,
1651 * SilcClientConnection conn,
1652 * SilcChannelEntry channel)
1656 * Removes channel from local cache by the channel entry indicated by
1657 * the `channel'. Returns TRUE if the deletion were successful.
1660 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1661 SilcChannelEntry channel);
1663 /****f* silcclient/SilcClientAPI/silc_client_get_server
1667 * SilcServerEntry silc_client_get_server(SilcClient client,
1668 * SilcClientConnection conn,
1669 * char *server_name)
1673 * Finds entry for server by the server name. Returns the entry or NULL
1674 * if the entry was not found.
1677 SilcServerEntry silc_client_get_server(SilcClient client,
1678 SilcClientConnection conn,
1681 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1685 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1686 * SilcClientConnection conn,
1687 * SilcServerID *server_id);
1691 * Finds entry for server by the server ID. Returns the entry or NULL
1692 * if the entry was not found.
1695 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1696 SilcClientConnection conn,
1697 SilcServerID *server_id);
1699 /****f* silcclient/SilcClientAPI/silc_client_del_server
1703 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1704 * SilcServerEntry server);
1708 * Removes server from local cache by the server entry indicated by
1709 * the `server'. Returns TRUE if the deletion were successful.
1712 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1713 SilcServerEntry server);
1715 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1719 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1720 * SilcClientEntry client_entry);
1724 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1725 * channel indicated by the `channel'. NULL if client is not joined on
1729 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1730 SilcClientEntry client_entry);
1732 /* Command management (command.c) */
1734 /****f* silcclient/SilcClientAPI/silc_client_command_call
1738 * bool silc_client_command_call(SilcClient client,
1739 * SilcClientConnection conn,
1740 * const char *command_line, ...);
1744 * Calls and executes the command indicated by the `command_name'.
1745 * The `command_line' is a string which includes the command's name and
1746 * its arguments separated with whitespaces (' '). If `command_line'
1747 * is non-NULL then all variable arguments are ignored by default.
1749 * If `command_line' is NULL, then the variable arguments define the
1750 * command's name and its arguments. The first variable argument must
1751 * be the command name. The variable argument list must be terminated
1754 * Returns FALSE if the command is not known and TRUE after command.
1755 * execution. The "command" client operation is called when the
1756 * command is executed to indicate whether the command executed
1757 * successfully or not.
1759 * The "command_reply" client operation will be called when reply is
1760 * received from the server to the command. Application may also use
1761 * the silc_client_command_pending to attach to the command reply.
1762 * The command identifier for silc_client_command_pending function after
1763 * this function call is conn->cmd_ident, which application may use.
1767 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1769 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1773 * This command executes the commands implemented inside the client
1774 * library. These commands are designed for command line applications,
1775 * but GUI application may call them too if needed. Alternatively
1776 * application may override the library and use silc_client_command_send
1780 bool silc_client_command_call(SilcClient client,
1781 SilcClientConnection conn,
1782 const char *command_line, ...);
1784 /****f* silcclient/SilcClientAPI/silc_client_command_send
1788 * void silc_client_command_send(SilcClient client,
1789 * SilcClientConnection conn,
1790 * SilcCommand command, SilcUInt16 ident,
1791 * SilcUInt32 argc, ...);
1795 * Generic function to send any command. The arguments must be sent already
1796 * encoded into correct form and in correct order. If application wants
1797 * to perform the commands by itself, it can do so and send the data
1798 * directly to the server using this function. If application is using
1799 * the silc_client_command_call, this function is usually not used.
1800 * Note that this overriders the Client Librarys commands and sends
1801 * the command packet directly to server.
1803 * Programmer should get familiar with the SILC protocol commands
1804 * specification when using this function, as the arguments needs to
1805 * be encoded as specified in the protocol.
1807 * The variable arguments are a pair of { type, data, data_length },
1808 * and the `argc' is the number of these pairs.
1812 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1813 * 1, nickname, strlen(nickname));
1816 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1817 SilcCommand command, SilcUInt16 ident,
1818 SilcUInt32 argc, ...);
1820 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1824 * void silc_client_command_pending(SilcClientConnection conn,
1825 * SilcCommand reply_cmd,
1827 * SilcCommandCb callback,
1832 * This function can be used to add pending command callback to be
1833 * called when an command reply is received to an earlier sent command.
1834 * The `reply_cmd' is the command that must be received in order for
1835 * the pending command callback indicated by `callback' to be called.
1836 * The `callback' will deliver the `context' and
1837 * SilcClientCommandReplyContext which includes the internals of the
1840 * The `ident' is a command identifier which was set for the earlier
1841 * sent command. The command reply will include the same identifier
1842 * and pending command callback will be called when the reply is
1843 * received with the same command identifier. It is possible to
1844 * add multiple pending command callbacks for same command and for
1847 * Application may use this function to add its own command reply
1848 * handlers if it wishes not to use the standard `command_reply'
1849 * client operation. However, note that the pending command callback
1850 * does not deliver parsed command reply, but application must parse
1853 * Note also that the application is notified about the received command
1854 * reply through the `command_reply' client operation before calling
1855 * the `callback` pending command callback. That is the normal
1856 * command reply handling, and is called regardless whether pending
1857 * command callbacks are used or not.
1859 * Commands that application calls with silc_client_command_call
1860 * will use a command identifier from conn->cmd_ident variable. After
1861 * calling the silc_client_command_call, the conn->cmd_ident includes
1862 * the command identifier that was used for the command sending.
1866 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1867 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1868 * my_ping_handler, my_ping_context);
1871 void silc_client_command_pending(SilcClientConnection conn,
1872 SilcCommand reply_cmd,
1874 SilcCommandCb callback,
1878 /* Private Message key management (client_prvmsg.c) */
1880 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1884 * bool silc_client_add_private_message_key(SilcClient client,
1885 * SilcClientConnection conn,
1886 * SilcClientEntry client_entry,
1887 * const char *cipher,
1889 * unsigned char *key,
1890 * SilcUInt32 key_len,
1891 * bool generate_key,
1896 * Adds private message key to the client library. The key will be used to
1897 * encrypt all private message between the client and the remote client
1898 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1899 * value `generate_key' is TRUE the library will generate random key.
1900 * The `key' maybe for example pre-shared-key, passphrase or similar.
1901 * The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1902 * that the requirements of the SILC protocol are met. The API, however,
1903 * allows to allocate any cipher and HMAC.
1905 * If `responder' is TRUE then the sending and receiving keys will be
1906 * set according the client being the receiver of the private key. If
1907 * FALSE the client is being the sender (or negotiator) of the private
1910 * It is not necessary to set key for normal private message usage. If the
1911 * key is not set then the private messages are encrypted using normal
1912 * session keys. Setting the private key, however, increases the security.
1914 * Returns FALSE if the key is already set for the `client_entry', TRUE
1918 bool silc_client_add_private_message_key(SilcClient client,
1919 SilcClientConnection conn,
1920 SilcClientEntry client_entry,
1928 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1933 * silc_client_add_private_message_key_ske(SilcClient client,
1934 * SilcClientConnection conn,
1935 * SilcClientEntry client_entry,
1936 * const char *cipher,
1938 * SilcSKEKeyMaterial *key);
1942 * Same as silc_client_add_private_message_key but takes the key material
1943 * from the SKE key material structure. This structure is received if
1944 * the application uses the silc_client_send_key_agreement to negotiate
1945 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1946 * negotiated also in the SKE protocol.
1949 bool silc_client_add_private_message_key_ske(SilcClient client,
1950 SilcClientConnection conn,
1951 SilcClientEntry client_entry,
1954 SilcSKEKeyMaterial *key,
1957 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1961 * bool silc_client_del_private_message_key(SilcClient client,
1962 * SilcClientConnection conn,
1963 * SilcClientEntry client_entry);
1967 * Removes the private message from the library. The key won't be used
1968 * after this to protect the private messages with the remote `client_entry'
1969 * client. Returns FALSE on error, TRUE otherwise.
1972 bool silc_client_del_private_message_key(SilcClient client,
1973 SilcClientConnection conn,
1974 SilcClientEntry client_entry);
1976 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1980 * SilcPrivateMessageKeys
1981 * silc_client_list_private_message_keys(SilcClient client,
1982 * SilcClientConnection conn,
1983 * SilcUInt32 *key_count);
1987 * Returns array of set private message keys associated to the connection
1988 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1989 * count to the `key_count' argument. The array must be freed by the caller
1990 * by calling the silc_client_free_private_message_keys function. Note:
1991 * the keys returned in the array is in raw format. It might not be desired
1992 * to show the keys as is. The application might choose not to show the keys
1993 * at all or to show the fingerprints of the keys.
1996 SilcPrivateMessageKeys
1997 silc_client_list_private_message_keys(SilcClient client,
1998 SilcClientConnection conn,
1999 SilcUInt32 *key_count);
2001 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key_request
2006 * silc_client_send_private_message_key_request(SilcClient client,
2007 * SilcClientConnection conn,
2008 * SilcClientEntry client_entry);
2012 * This function can be used to send an private message key indicator
2013 * request to the remote client indicated by 'client_entry'. This can
2014 * be used when setting a static or pre-shared private message key.
2015 * The sender of this packet is the initiator and must set the 'responder'
2016 * argument in silc_client_add_private_message_key function to FALSE.
2017 * The receiver of this indicator request must set it to TRUE, if the
2018 * receiver decides to set a private message key. By using this
2019 * function applications may automate initiator/responder setting in
2020 * private message key functions, without asking from user which one is
2021 * the initiator and which one is responder.
2025 * The sender of this packet must set the private message key for
2026 * 'client_entry' before calling this function. The 'responder'
2027 * argument MUST be set to FALSE when setting the key.
2031 silc_client_send_private_message_key_request(SilcClient client,
2032 SilcClientConnection conn,
2033 SilcClientEntry client_entry);
2035 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
2039 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2040 * SilcUInt32 key_count);
2044 * Frees the SilcPrivateMessageKeys array returned by the function
2045 * silc_client_list_private_message_keys.
2048 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2049 SilcUInt32 key_count);
2052 /* Channel private key management (client_channel.c,
2053 SilcChannelPrivateKey is defined in idlist.h) */
2055 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
2059 * bool silc_client_add_channel_private_key(SilcClient client,
2060 * SilcClientConnection conn,
2061 * SilcChannelEntry channel,
2065 * unsigned char *key,
2066 * SilcUInt32 key_len,
2067 * SilcChannelPrivateKey *ret_key);
2071 * Adds private key for channel. When channel has private key then the
2072 * messages are encrypted using that key. All clients on the channel
2073 * must also know the key in order to decrypt the messages. However,
2074 * it is possible to have several private keys per one channel. In this
2075 * case only some of the clients on the channel may know the one key
2076 * and only some the other key. The `name' can be application given
2077 * name for the key. This returns the created key to the 'ret_key'
2078 * pointer if it is non-NULL;
2080 * If `cipher' and/or `hmac' is NULL then default values will be used
2081 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
2083 * The private key for channel is optional. If it is not set then the
2084 * channel messages are encrypted using the channel key generated by the
2085 * server. However, setting the private key (or keys) for the channel
2086 * significantly adds security. If more than one key is set the library
2087 * will automatically try all keys at the message decryption phase. Note:
2088 * setting many keys slows down the decryption phase as all keys has to
2089 * be tried in order to find the correct decryption key. However, setting
2090 * a few keys does not have big impact to the decryption performace.
2094 * NOTE: This is entirely local setting. The key set using this function
2095 * is not sent to the network at any phase.
2097 * NOTE: If the key material was originated by the SKE protocol (using
2098 * silc_client_send_key_agreement) then the `key' MUST be the
2099 * key->send_enc_key as this is dictated by the SILC protocol. However,
2100 * currently it is not expected that the SKE key material would be used
2101 * as channel private key. However, this API allows it.
2104 bool silc_client_add_channel_private_key(SilcClient client,
2105 SilcClientConnection conn,
2106 SilcChannelEntry channel,
2112 SilcChannelPrivateKey *ret_key);
2114 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
2118 * bool silc_client_del_channel_private_keys(SilcClient client,
2119 * SilcClientConnection conn,
2120 * SilcChannelEntry channel);
2124 * Removes all private keys from the `channel'. The old channel key is used
2125 * after calling this to protect the channel messages. Returns FALSE on
2126 * on error, TRUE otherwise.
2129 bool silc_client_del_channel_private_keys(SilcClient client,
2130 SilcClientConnection conn,
2131 SilcChannelEntry channel);
2133 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2137 * bool silc_client_del_channel_private_key(SilcClient client,
2138 * SilcClientConnection conn,
2139 * SilcChannelEntry channel,
2140 * SilcChannelPrivateKey key);
2144 * Removes and frees private key `key' from the channel `channel'.
2145 * The `key' is retrieved by calling the function
2146 * silc_client_list_channel_private_keys. The key is not used after
2147 * this. If the key was last private key then the old channel key is
2148 * used hereafter to protect the channel messages. This returns FALSE
2149 * on error, TRUE otherwise.
2152 bool silc_client_del_channel_private_key(SilcClient client,
2153 SilcClientConnection conn,
2154 SilcChannelEntry channel,
2155 SilcChannelPrivateKey key);
2157 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2161 * SilcChannelPrivateKey *
2162 * silc_client_list_channel_private_keys(SilcClient client,
2163 * SilcClientConnection conn,
2164 * SilcChannelEntry channel,
2165 * SilcUInt32 *key_count);
2169 * Returns array (pointers) of private keys associated to the `channel'.
2170 * The caller must free the array by calling the function
2171 * silc_client_free_channel_private_keys. The pointers in the array may be
2172 * used to delete the specific key by giving the pointer as argument to the
2173 * function silc_client_del_channel_private_key.
2176 SilcChannelPrivateKey *
2177 silc_client_list_channel_private_keys(SilcClient client,
2178 SilcClientConnection conn,
2179 SilcChannelEntry channel,
2180 SilcUInt32 *key_count);
2182 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2186 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2187 * SilcUInt32 key_count);
2191 * Frees the SilcChannelPrivateKey array.
2194 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2195 SilcUInt32 key_count);
2197 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2201 * void silc_client_current_channel_private_key(SilcClient client,
2202 * SilcClientConnection conn,
2203 * SilcChannelEntry channel,
2204 * SilcChannelPrivateKey key);
2208 * Sets the `key' to be used as current channel private key on the
2209 * `channel'. Packet sent after calling this function will be secured
2213 void silc_client_current_channel_private_key(SilcClient client,
2214 SilcClientConnection conn,
2215 SilcChannelEntry channel,
2216 SilcChannelPrivateKey key);
2219 /* Key Agreement routines (client_keyagr.c) */
2221 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2225 * void silc_client_send_key_agreement(SilcClient client,
2226 * SilcClientConnection conn,
2227 * SilcClientEntry client_entry,
2230 * SilcUInt32 timeout_secs,
2231 * SilcKeyAgreementCallback completion,
2236 * Sends key agreement request to the remote client indicated by the
2237 * `client_entry'. If the caller provides the `hostname' and the `port'
2238 * arguments then the library will bind the client to that hostname and
2239 * that port for the key agreement protocol. It also sends the `hostname'
2240 * and the `port' in the key agreement packet to the remote client. This
2241 * would indicate that the remote client may initiate the key agreement
2242 * protocol to the `hostname' on the `port'. If port is zero then the
2243 * bound port is undefined (the operating system defines it).
2245 * If the `hostname' and `port' is not provided then empty key agreement
2246 * packet is sent to the remote client. The remote client may reply with
2247 * the same packet including its hostname and port. If the library receives
2248 * the reply from the remote client the `key_agreement' client operation
2249 * callback will be called to verify whether the user wants to perform the
2250 * key agreement or not.
2254 * NOTE: If the application provided the `hostname' and the `port' and the
2255 * remote side initiates the key agreement protocol it is not verified
2256 * from the user anymore whether the protocol should be executed or not.
2257 * By setting the `hostname' and `port' the user gives permission to
2258 * perform the protocol (we are responder in this case).
2260 * NOTE: If the remote side decides not to initiate the key agreement
2261 * or decides not to reply with the key agreement packet then we cannot
2262 * perform the key agreement at all. If the key agreement protocol is
2263 * performed the `completion' callback with the `context' will be called.
2264 * If remote side decides to ignore the request the `completion' will be
2265 * called after the specified timeout, `timeout_secs'.
2267 * NOTE: If the `hostname' and the `port' was not provided the `completion'
2268 * will not be called at all since this does nothing more than sending
2269 * a packet to the remote host.
2271 * NOTE: There can be only one active key agreement for one client entry.
2272 * Before setting new one, the old one must be finished (it is finished
2273 * after calling the completion callback) or the function
2274 * silc_client_abort_key_agreement must be called.
2277 void silc_client_send_key_agreement(SilcClient client,
2278 SilcClientConnection conn,
2279 SilcClientEntry client_entry,
2280 const char *hostname,
2281 const char *bindhost,
2283 SilcUInt32 timeout_secs,
2284 SilcKeyAgreementCallback completion,
2287 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2292 * silc_client_perform_key_agreement(SilcClient client,
2293 * SilcClientConnection conn,
2294 * SilcClientEntry client_entry,
2297 * SilcKeyAgreementCallback completion,
2302 * Performs the actual key agreement protocol. Application may use this
2303 * to initiate the key agreement protocol. This can be called for example
2304 * after the application has received the `key_agreement' client operation,
2305 * and did not return TRUE from it.
2307 * The `hostname' is the remote hostname (or IP address) and the `port'
2308 * is the remote port. The `completion' callback with the `context' will
2309 * be called after the key agreement protocol.
2313 * NOTE: If the application returns TRUE in the `key_agreement' client
2314 * operation the library will automatically start the key agreement. In this
2315 * case the application must not call this function. However, application
2316 * may choose to just ignore the `key_agreement' client operation (and
2317 * merely just print information about it on the screen) and call this
2318 * function when the user whishes to do so (by, for example, giving some
2319 * specific command). Thus, the API provides both, automatic and manual
2320 * initiation of the key agreement. Calling this function is the manual
2321 * initiation and returning TRUE in the `key_agreement' client operation
2322 * is the automatic initiation.
2325 void silc_client_perform_key_agreement(SilcClient client,
2326 SilcClientConnection conn,
2327 SilcClientEntry client_entry,
2330 SilcKeyAgreementCallback completion,
2333 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2338 * silc_client_perform_key_agreement_fd(SilcClient client,
2339 * SilcClientConnection conn,
2340 * SilcClientEntry client_entry,
2343 * SilcKeyAgreementCallback completion,
2348 * Same as above but application has created already the connection to
2349 * the remote host. The `sock' is the socket to the remote connection.
2350 * Application can use this function if it does not want the client library
2351 * to create the connection.
2354 void silc_client_perform_key_agreement_fd(SilcClient client,
2355 SilcClientConnection conn,
2356 SilcClientEntry client_entry,
2359 SilcKeyAgreementCallback completion,
2362 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2366 * void silc_client_abort_key_agreement(SilcClient client,
2367 * SilcClientConnection conn,
2368 * SilcClientEntry client_entry);
2372 * This function can be called to unbind the hostname and the port for
2373 * the key agreement protocol. However, this function has effect only
2374 * before the key agreement protocol has been performed. After it has
2375 * been performed the library will automatically unbind the port. The
2376 * `client_entry' is the client to which we sent the key agreement
2377 * request. The key agreement completion callback will be called
2378 * with SILC_KEY_AGREEMENT_ABORTED status.
2381 void silc_client_abort_key_agreement(SilcClient client,
2382 SilcClientConnection conn,
2383 SilcClientEntry client_entry);
2386 /* Misc functions */
2388 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2392 * void silc_client_set_away_message(SilcClient client,
2393 * SilcClientConnection conn,
2398 * Sets away `message'. The away message may be set when the client's
2399 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2400 * to anyone who sends private message. The `message' will be sent
2401 * automatically back to the the client who send private message. If
2402 * away message is already set this replaces the old message with the
2403 * new one. If `message' is NULL the old away message is removed.
2404 * The sender may freely free the memory of the `message'.
2407 void silc_client_set_away_message(SilcClient client,
2408 SilcClientConnection conn,
2411 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2415 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2416 * SilcClientConnection conn,
2417 * SilcAuthMethod auth_meth,
2422 * Connection authentication method request callback. This is called
2423 * by the client library after it has received the authentication method
2424 * that the application requested by calling the function
2425 * silc_client_request_authentication_method.
2428 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2429 SilcClientConnection conn,
2430 SilcAuthMethod auth_meth,
2433 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2438 * silc_client_request_authentication_method(SilcClient client,
2439 * SilcClientConnection conn,
2440 * SilcConnectionAuthRequest
2446 * This function can be used to request the current authentication method
2447 * from the server. This may be called when connecting to the server
2448 * and the client library requests the authentication data from the
2449 * application. If the application does not know the current authentication
2450 * method it can request it from the server using this function.
2451 * The `callback' with `context' will be called after the server has
2452 * replied back with the current authentication method.
2456 silc_client_request_authentication_method(SilcClient client,
2457 SilcClientConnection conn,
2458 SilcConnectionAuthRequest callback,
2461 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2465 * typedef enum { ... } SilcClientMonitorStatus;
2469 * File transmission session status types. These will indicate
2470 * the status of the file transmission session.
2475 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2476 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2477 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2478 SILC_CLIENT_FILE_MONITOR_GET,
2479 SILC_CLIENT_FILE_MONITOR_PUT,
2480 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2481 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2482 } SilcClientMonitorStatus;
2485 /****d* silcclient/SilcClientAPI/SilcClientFileError
2489 * typedef enum { ... } SilcClientFileError;
2493 * File transmission error types. These types are returned by
2494 * some of the file transmission functions, and by the monitor
2495 * callback to indicate error.
2500 SILC_CLIENT_FILE_OK,
2501 SILC_CLIENT_FILE_ERROR,
2502 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2503 SILC_CLIENT_FILE_ALREADY_STARTED,
2504 SILC_CLIENT_FILE_NO_SUCH_FILE,
2505 SILC_CLIENT_FILE_PERMISSION_DENIED,
2506 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2507 } SilcClientFileError;
2510 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2514 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2515 * SilcClientConnection conn,
2516 * SilcClientMonitorStatus status,
2517 * SilcClientFileError error,
2518 * SilcUInt64 offset,
2519 * SilcUInt64 filesize,
2520 * SilcClientEntry client_entry,
2521 * SilcUInt32 session_id,
2522 * const char *filepath,
2527 * Monitor callback that is called during the file transmission to
2528 * monitor the transmission process. The `status' indicates the current
2529 * monitoring process. The `error' will indicate the error type
2530 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2531 * currently transmitted amount of total `filesize'. The `client_entry'
2532 * indicates the remote client, and the transmission session ID is the
2533 * `session_id'. The filename being transmitted is indicated by the
2537 typedef void (*SilcClientFileMonitor)(SilcClient client,
2538 SilcClientConnection conn,
2539 SilcClientMonitorStatus status,
2540 SilcClientFileError error,
2542 SilcUInt64 filesize,
2543 SilcClientEntry client_entry,
2544 SilcUInt32 session_id,
2545 const char *filepath,
2548 /****f* silcclient/SilcClientAPI/SilcClientFileName
2552 * typedef void (*SilcClientFileName)(const char *filepath,
2557 * Completion callback for the SilcClientFileAskName callback function.
2558 * Application calls this to deliver the filepath and filename where
2559 * the downloaded file is to be saved.
2562 typedef void (*SilcClientFileName)(const char *filepath,
2565 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2569 * typedef void (*SilcClientFileAskName)(SilcClient client,
2570 * SilcClientConnection conn,
2571 * SilcUInt32 session_id,
2572 * const char *remote_filename,
2573 * SilcClientFileName completion,
2574 * void *completion_context,
2579 * File name asking callback, that is called if it is given to the
2580 * silc_client_file_receive and the path given to that as argument was
2581 * NULL. The library calls this to ask the filename and filepath to
2582 * where the file is to be saved. The 'remote_filename' is the file
2583 * that is being downloaded. Application must call the 'completion'
2584 * with 'completion_context' to continue with the file downloading.
2585 * It is not mandatory to provide this to the silc_client_file_receive.
2588 typedef void (*SilcClientFileAskName)(SilcClient client,
2589 SilcClientConnection conn,
2590 SilcUInt32 session_id,
2591 const char *remote_filename,
2592 SilcClientFileName completion,
2593 void *completion_context,
2596 /****f* silcclient/SilcClientAPI/silc_client_file_send
2600 * SilcClientFileError
2601 * silc_client_file_send(SilcClient client,
2602 * SilcClientConnection conn,
2603 * SilcClientFileMonitor monitor,
2604 * void *monitor_context,
2605 * const char *local_ip,
2606 * SilcUInt32 local_port,
2608 * SilcClientEntry client_entry,
2609 * const char *filepath);
2610 * SilcUInt32 *session_id);
2614 * Sends a file indicated by the `filepath' to the remote client
2615 * indicated by the `client_entry'. This will negotiate a secret key
2616 * with the remote client before actually starting the transmission of
2617 * the file. The `monitor' callback will be called to monitor the
2618 * transmission of the file.
2620 * This returns a file session ID for the file transmission to the
2621 * `session_id' pointer. It can be used to close the session (and
2622 * abort the file transmission) by calling the silc_client_file_close
2623 * function. The session ID is also returned in the `monitor' callback.
2625 * If the `local_ip' is provided then this will try to bind the
2626 * listener for key exchange protocol to that IP. If `local_port' is
2627 * non-zero that port is used. If `local_ip' is NULL then this will
2628 * automatically attempt to bind it to local IP address of the machine.
2629 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2630 * ignored and it is expected that the receiver will provide the
2631 * point of contact. This is usefull if the sender is behind NAT.
2633 * If error will occur during the file transfer process the error
2634 * status will be returned in the monitor callback. In this case
2635 * the application must call silc_client_file_close to close the
2640 silc_client_file_send(SilcClient client,
2641 SilcClientConnection conn,
2642 SilcClientFileMonitor monitor,
2643 void *monitor_context,
2644 const char *local_ip,
2645 SilcUInt32 local_port,
2647 SilcClientEntry client_entry,
2648 const char *filepath,
2649 SilcUInt32 *session_id);
2651 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2655 * SilcClientFileError
2656 * silc_client_file_receive(SilcClient client,
2657 * SilcClientConnection conn,
2658 * SilcClientFileMonitor monitor,
2659 * void *monitor_context,
2661 * SilcUInt32 session_id,
2662 * SilcClientFileAskName ask_name,
2663 * void *ask_name_context);
2667 * Receives a file from a client indicated by the `client_entry'. The
2668 * `session_id' indicates the file transmission session and it has been
2669 * received in the `ftp' client operation function. This will actually
2670 * perform the key agreement protocol with the remote client before
2671 * actually starting the file transmission. The `monitor' callback
2672 * will be called to monitor the transmission. If `path' is non-NULL
2673 * the file will be saved into that directory. If NULL the file is
2674 * saved in the current working directory, unless the 'ask_name'
2675 * callback is non-NULL. In this case the callback is called to ask
2676 * the path and filename from application.
2678 * If error will occur during the file transfer process the error
2679 * status will be returned in the monitor callback. In this case
2680 * the application must call silc_client_file_close to close the
2685 silc_client_file_receive(SilcClient client,
2686 SilcClientConnection conn,
2687 SilcClientFileMonitor monitor,
2688 void *monitor_context,
2690 SilcUInt32 session_id,
2691 SilcClientFileAskName ask_name,
2692 void *ask_name_context);
2694 /****f* silcclient/SilcClientAPI/silc_client_file_close
2698 * SilcClientFileError silc_client_file_close(SilcClient client,
2699 * SilcClientConnection conn,
2700 * SilcUInt32 session_id);
2704 * Closes file transmission session indicated by the `session_id'.
2705 * If file transmission is being conducted it will be aborted
2706 * automatically. This function is also used to close the session
2707 * after successful file transmission. This function can be used
2708 * also to reject incoming file transmission request. If the
2709 * session was already started and the monitor callback was set
2710 * the monitor callback will be called with the monitor status
2711 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2714 SilcClientFileError silc_client_file_close(SilcClient client,
2715 SilcClientConnection conn,
2716 SilcUInt32 session_id);
2718 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2722 * SilcAttributePayload
2723 * silc_client_attribute_add(SilcClient client,
2724 * SilcClientConnection conn,
2725 * SilcAttribute attribute,
2727 * SilcUInt32 object_size);
2731 * Add new Requsted Attribute for WHOIS command to the client library.
2732 * The `attribute' object indicated by `object' is added and allocated
2733 * SilcAttributePayload is returned. The `object' must be of correct
2734 * type and of correct size. See the SilcAttribute for object types
2735 * for different attributes. You may also get all added attributes
2736 * from the client with silc_client_attributes_get function.
2738 * Requested Attributes are different personal information about the
2739 * user, status information and other information which other users
2740 * may query with WHOIS command. Application may set these so that
2741 * if someone sends WHOIS query these attributes will be replied back
2742 * to the sender. The library always puts the public key to the
2743 * Requested Attributes, but if application wishes to add additional
2744 * public keys (or certificates) it can be done with this interface.
2745 * Library also always computes digital signature of the attributes
2746 * automatically, so application does not need to do that.
2749 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2750 SilcClientConnection conn,
2751 SilcAttribute attribute,
2753 SilcUInt32 object_size);
2755 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2759 * bool silc_client_attribute_del(SilcClient client,
2760 * SilcClientConnection conn,
2761 * SilcAttribute attribute,
2762 * SilcAttributePayload attr);
2766 * Delete a Requested Attribute from the client. If the `attribute'
2767 * is non-zero then all attributes of that type are deleted and the
2768 * `attr' is ignored. If `attr' is non-NULL then that specific
2769 * attribute is deleted and `attribute' is ignored.
2771 * You may get all added attributes with the function
2772 * silc_client_attributes_get and to get the SilcAttributePayload.
2773 * This function Returns TRUE if the attribute was found and deleted.
2776 bool silc_client_attribute_del(SilcClient client,
2777 SilcClientConnection conn,
2778 SilcAttribute attribute,
2779 SilcAttributePayload attr);
2781 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2785 * const SilcHashTable
2786 * silc_client_attributes_get(SilcClient client,
2787 * SilcClientConnection conn);
2791 * Returns pointer to the SilcHashTable which includes all the added
2792 * Requested Attributes. The caller must not free the hash table.
2793 * The caller may use SilcHashTableList and silc_hash_table_list to
2794 * traverse the table. Each entry in the hash table is one added
2795 * SilcAttributePayload. It is possible to delete a attribute
2796 * payload while traversing the table.
2799 const SilcHashTable silc_client_attributes_get(SilcClient client,
2800 SilcClientConnection conn);
2802 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2806 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2810 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2811 * then all attributes are requested. Alternatively, `attribute' and
2812 * all variable arguments can each be requested attribute. In this case
2813 * the last must be set to zero (0) to complete the variable list of
2814 * requested attributes. See SilcAttribute for all attributes.
2815 * You can give the returned buffer as argument to for example
2816 * silc_client_get_client_by_id_resolve function.
2820 * Request all attributes
2821 * buffer = silc_client_attributes_request(0);
2823 * Request only the following attributes
2824 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2825 * SILC_ATTRIBUTE_SERVICE,
2826 * SILC_ATTRIBUTE_MOOD, 0);
2829 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2831 /* Low level packet sending functions */
2833 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2837 * bool silc_client_send_packet(SilcClient client,
2838 * SilcClientConnection conn,
2839 * SilcPacketType type,
2840 * const unsigned char *data,
2841 * SilcUInt32 data_len);
2845 * This routine can be used by application to send packets directly
2846 * to a connection indicated by `conn'. Usually application does not
2847 * need this routine since the Client Library handles the packet
2848 * sending. The `type' indicates the packet type. If `data' is
2849 * NULL then empty packet is sent. This returns FALSE if packet cannot
2853 bool silc_client_send_packet(SilcClient client,
2854 SilcClientConnection conn,
2855 SilcPacketType type,
2856 const unsigned char *data,
2857 SilcUInt32 data_len);
2859 #include "command.h"
2860 #include "command_reply.h"
2862 #include "protocol.h"
2868 #endif /* SILCCLIENT_H */