5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2003 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 */
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 */
215 /* Private message keys */
216 SilcCipher send_key; /* Private message key for sending */
217 SilcCipher receive_key; /* Private message key for receiving */
218 SilcHmac hmac_send; /* Private mesage key HMAC for sending */
219 SilcHmac hmac_receive; /* Private mesage key HMAC for receiving */
220 unsigned char *key; /* Set only if application provided the
221 key material. NULL if the library
222 generated the key. */
223 SilcUInt32 key_len; /* Key length */
224 SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
226 /* SilcClientEntry status information */
227 SilcEntryStatus status; /* Status mask */
228 SilcHashTable channels; /* All channels client has joined */
229 SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
230 bool generated; /* TRUE if library generated `key' */
231 bool valid; /* FALSE if this entry is not valid */
235 /****s* silcclient/SilcClientAPI/SilcChannelEntry
239 * typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
243 * This structure represents a channel in the SILC network. All
244 * channels that the client are aware of or have joined in will be
245 * represented as SilcChannelEntry. The structure includes information
250 struct SilcChannelEntryStruct {
251 /* General information */
252 char *channel_name; /* Channel name */
253 SilcChannelID *id; /* Channel ID */
254 SilcUInt32 mode; /* Channel mode */
256 /* All clients that has joined this channel. The key to the table is the
257 SilcClientEntry and the context is SilcChannelUser context. */
258 SilcHashTable user_list;
261 SilcCipher channel_key; /* The channel key */
262 unsigned char *key; /* Raw key data */
263 SilcUInt32 key_len; /* Raw key data length */
264 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
265 SilcHmac hmac; /* Current HMAC */
267 /* Channel private keys */
268 SilcDList private_keys; /* List of private keys or NULL */
269 SilcChannelPrivateKey curr_key; /* Current private key */
271 /* SilcChannelEntry status information */
272 SilcDList old_channel_keys;
274 SilcUInt16 resolve_cmd_ident; /* Command identifier when
275 resolving this entry */
279 /****s* silcclient/SilcClientAPI/SilcServerEntry
283 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
287 * This structure represents a server in the SILC network. All servers
288 * that the client is aware of and have for example resolved with
289 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
293 struct SilcServerEntryStruct {
294 /* General information */
295 char *server_name; /* Server name */
296 char *server_info; /* Server info */
297 SilcServerID *server_id; /* Server ID */
298 SilcUInt16 resolve_cmd_ident; /* Command identifier when
299 resolving this entry */
303 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
307 * typedef enum { ... } SilcKeyAgreementStatus;
311 * Key agreement status types indicating the status of the key
312 * agreement protocol. These types are returned to the application
313 * in the SilcKeyAgreementCallback callback function.
318 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
319 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
320 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
321 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
322 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
323 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
324 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
325 } SilcKeyAgreementStatus;
328 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
332 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
333 * SilcClientConnection conn,
334 * SilcClientEntry client_entry,
335 * SilcKeyAgreementStatus status,
336 * SilcSKEKeyMaterial *key,
341 * Key agreement callback that is called after the key agreement protocol
342 * has been performed. This is called also if error occurred during the
343 * key agreement protocol. The `key' is the allocated key material and
344 * the caller is responsible of freeing it. The `key' is NULL if error
345 * has occurred. The application can freely use the `key' to whatever
346 * purpose it needs. See lib/silcske/silcske.h for the definition of
347 * the SilcSKEKeyMaterial structure.
350 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
351 SilcClientConnection conn,
352 SilcClientEntry client_entry,
353 SilcKeyAgreementStatus status,
354 SilcSKEKeyMaterial *key,
357 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
361 * typedef struct { ... } SilcPrivateMessageKeys;
365 * Structure to hold the list of private message keys. The array of this
366 * structure is returned by the silc_client_list_private_message_keys
372 SilcClientEntry client_entry; /* The remote client entry */
373 char *cipher; /* The cipher name */
374 unsigned char *key; /* The original key, If the appliation
375 provided it. This is NULL if the
376 library generated the key or if
377 the SKE key material was used. */
378 SilcUInt32 key_len; /* The key length */
379 } *SilcPrivateMessageKeys;
382 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
386 * typedef struct SilcChannelPrivateKeyStruct { ... }
387 * *SilcChannelPrivateKey;
391 * Structure to hold one channel private key. The array of this structure
392 * is returned by silc_client_list_channel_private_keys function.
396 struct SilcChannelPrivateKeyStruct {
397 char *name; /* Application given name */
398 SilcCipher cipher; /* The cipher and key */
399 SilcHmac hmac; /* The HMAC and hmac key */
400 unsigned char *key; /* The key data */
401 SilcUInt32 key_len; /* The key length */
405 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
409 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
410 * SilcUInt32 passphrase_len,
415 * Ask passphrase callback. This is called by the application when the
416 * library calls `ask_passphrase' client operation. The callback delivers
417 * the passphrase to the library. The passphrases in SILC protocol
418 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
419 * encoded, and if it is not then library will attempt to encode it.
422 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
423 SilcUInt32 passphrase_len,
426 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
430 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
434 * Public key (or certificate) verification callback. This is called
435 * by the application to indicate that the public key verification was
436 * either success or failure.
439 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
441 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
445 * typedef void (*SilcGetAuthMeth)(bool success,
446 * SilcProtocolAuthMeth auth_meth,
447 * const unsigned char *auth_data,
448 * SilcUInt32 auth_data_len, void *context);
452 * Authentication method resolving callback. This is called by the
453 * application to return the resolved authentication method. The client
454 * library has called the get_auth_method client operation and given
455 * this function pointer as argument. The `success' will indicate whether
456 * the authentication method could be resolved. The `auth_meth' is the
457 * resolved authentication method. The `auth_data' and the `auth_data_len'
458 * are the resolved authentication data. The `context' is the libary's
459 * context sent to the get_auth_method client operation.
462 typedef void (*SilcGetAuthMeth)(bool success,
463 SilcProtocolAuthMeth auth_meth,
464 const unsigned char *auth_data,
465 SilcUInt32 auth_data_len, void *context);
467 /****d* silcclient/SilcClientAPI/SilcClientMessageType
471 * typedef enum { ... } SilcClientMessageType;
475 * Different message types for `say' client operation. The application
476 * may filter the message sent by the library according this type.
481 SILC_CLIENT_MESSAGE_INFO, /* Informational */
482 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
483 SILC_CLIENT_MESSAGE_ERROR, /* Error */
484 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
485 } SilcClientMessageType;
488 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
492 * typedef enum { ... } SilcClientConnectionStatus
496 * This type is returned to the `connect' client operation to indicate
497 * the status of the created connection. It can indicate if it was
498 * successful or whether an error occurred.
503 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
504 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
505 resumed old detached session */
506 SILC_CLIENT_CONN_ERROR, /* Unknown error occurred during
508 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
509 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
510 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
511 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
512 } SilcClientConnectionStatus;
515 /****s* silcclient/SilcClientAPI/SilcClientOperations
519 * typedef struct { ... } SilcClientOperations;
523 * SILC Client Operations. These must be implemented by the application.
524 * The Client library may call any of these routines at any time. The
525 * routines are used to deliver certain information to the application
526 * or from the application to the client library.
531 /* Message sent to the application by library. `conn' associates the
532 message to a specific connection. `conn', however, may be NULL.
533 The `type' indicates the type of the message sent by the library.
534 The application can for example filter the message according the
535 type. The variable argument list is arguments to the formatted
536 message that `msg' may be. */
537 void (*say)(SilcClient client, SilcClientConnection conn,
538 SilcClientMessageType type, char *msg, ...);
540 /* Message for a channel. The `sender' is the sender of the message
541 The `channel' is the channel. The `message' is the message. Note
542 that `message' maybe NULL. The `flags' indicates message flags
543 and it is used to determine how the message can be interpreted
544 (like it may tell the message is multimedia message). */
545 void (*channel_message)(SilcClient client, SilcClientConnection conn,
546 SilcClientEntry sender, SilcChannelEntry channel,
547 SilcMessagePayload payload, SilcMessageFlags flags,
548 const unsigned char *message,
549 SilcUInt32 message_len);
551 /* Private message to the client. The `sender' is the sender of the
552 message. The message is `message'and maybe NULL. The `flags'
553 indicates message flags and it is used to determine how the message
554 can be interpreted (like it may tell the message is multimedia
556 void (*private_message)(SilcClient client, SilcClientConnection conn,
557 SilcClientEntry sender, SilcMessagePayload payload,
558 SilcMessageFlags flags,
559 const unsigned char *message,
560 SilcUInt32 message_len);
562 /* Notify message to the client. The notify arguments are sent in the
563 same order as servers sends them. The arguments are same as received
564 from the server except for ID's. If ID is received application receives
565 the corresponding entry to the ID. For example, if Client ID is received
566 application receives SilcClientEntry. Also, if the notify type is
567 for channel the channel entry is sent to application (even if server
568 does not send it because client library gets the channel entry from
569 the Channel ID in the packet's header). */
570 void (*notify)(SilcClient client, SilcClientConnection conn,
571 SilcNotifyType type, ...);
573 /* Command handler. This function is called always in the command function.
574 If error occurs it will be called as well. `conn' is the associated
575 client connection. `cmd_context' is the command context that was
576 originally sent to the command. `success' is FALSE if error occurred
577 during command. `command' is the command being processed. It must be
578 noted that this is not reply from server. This is merely called just
579 after application has called the command. Just to tell application
580 that the command really was processed. */
581 void (*command)(SilcClient client, SilcClientConnection conn,
582 SilcClientCommandContext cmd_context, bool success,
583 SilcCommand command, SilcStatus status);
585 /* Command reply handler. This function is called always in the command reply
586 function. If error occurs it will be called as well. Normal scenario
587 is that it will be called after the received command data has been parsed
588 and processed. The function is used to pass the received command data to
591 `conn' is the associated client connection. `cmd_payload' is the command
592 payload data received from server and it can be ignored. It is provided
593 if the application would like to re-parse the received command data,
594 however, it must be noted that the data is parsed already by the library
595 thus the payload can be ignored. `success' is FALSE if error occurred.
596 In this case arguments are not sent to the application. The `status' is
597 the command reply status server returned. The `command' is the command
598 reply being processed. The function has variable argument list and each
599 command defines the number and type of arguments it passes to the
600 application (on error they are not sent).
602 The arguments are sent in the same order as servers sends them. The
603 arguments are same as received from the server except for ID's. If
604 ID is received application receives the corresponding entry to the
605 ID. For example, if Client ID is receives application receives
607 void (*command_reply)(SilcClient client, SilcClientConnection conn,
608 SilcCommandPayload cmd_payload, bool success,
609 SilcCommand command, SilcStatus status, ...);
611 /* Called to indicate that connection was either successfully established
612 or connecting failed. This is also the first time application receives
613 the SilcClientConnection object which it should save somewhere.
614 The `status' indicated whether the connection were successful. If it
615 is error value the application must always call the function
616 silc_client_close_connection. */
617 void (*connected)(SilcClient client, SilcClientConnection conn,
618 SilcClientConnectionStatus status);
620 /* Called to indicate that connection was disconnected to the server.
621 The `status' may tell the reason of the disconnection, and if the
622 `message' is non-NULL it may include the disconnection message
623 received from server. */
624 void (*disconnected)(SilcClient client, SilcClientConnection conn,
625 SilcStatus status, const char *message);
627 /* Find authentication method and authentication data by hostname and
628 port. The hostname may be IP address as well. When the authentication
629 method has been resolved the `completion' callback with the found
630 authentication method and authentication data is called. The `conn'
632 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
633 char *hostname, SilcUInt16 port,
634 SilcGetAuthMeth completion, void *context);
636 /* Verifies received public key. The `conn_type' indicates which entity
637 (server, client etc.) has sent the public key. If user decides to trust
638 the application may save the key as trusted public key for later
639 use. The `completion' must be called after the public key has been
641 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
642 SilcSocketType conn_type, unsigned char *pk,
643 SilcUInt32 pk_len, SilcSKEPKType pk_type,
644 SilcVerifyPublicKey completion, void *context);
646 /* Ask (interact, that is) a passphrase from user. The passphrase is
647 returned to the library by calling the `completion' callback with
648 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
649 if not then the library will attempt to encode. */
650 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
651 SilcAskPassphrase completion, void *context);
653 /* Notifies application that failure packet was received. This is called
654 if there is some protocol active in the client. The `protocol' is the
655 protocol context. The `failure' is opaque pointer to the failure
656 indication. Note, that the `failure' is protocol dependant and
657 application must explicitly cast it to correct type. Usually `failure'
658 is 32 bit failure type (see protocol specs for all protocol failure
660 void (*failure)(SilcClient client, SilcClientConnection conn,
661 SilcProtocol protocol, void *failure);
663 /* Asks whether the user would like to perform the key agreement protocol.
664 This is called after we have received an key agreement packet or an
665 reply to our key agreement packet. This returns TRUE if the user wants
666 the library to perform the key agreement protocol and FALSE if it is not
667 desired (application may start it later by calling the function
668 silc_client_perform_key_agreement). If TRUE is returned also the
669 `completion' and `context' arguments must be set by the application. */
670 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
671 SilcClientEntry client_entry, const char *hostname,
672 SilcUInt16 port, SilcKeyAgreementCallback *completion,
675 /* Notifies application that file transfer protocol session is being
676 requested by the remote client indicated by the `client_entry' from
677 the `hostname' and `port'. The `session_id' is the file transfer
678 session and it can be used to either accept or reject the file
679 transfer request, by calling the silc_client_file_receive or
680 silc_client_file_close, respectively. */
681 void (*ftp)(SilcClient client, SilcClientConnection conn,
682 SilcClientEntry client_entry, SilcUInt32 session_id,
683 const char *hostname, SilcUInt16 port);
685 /* Delivers SILC session detachment data indicated by `detach_data' to the
686 application. If application has issued SILC_COMMAND_DETACH command
687 the client session in the SILC network is not quit. The client remains
688 in the network but is detached. The detachment data may be used later
689 to resume the session in the SILC Network. The appliation is
690 responsible of saving the `detach_data', to for example in a file.
692 The detachment data can be given as argument to the functions
693 silc_client_connect_to_server, or silc_client_add_connection when
694 creating connection to remote server, inside SilcClientConnectionParams
695 structure. If it is provided the client library will attempt to resume
696 the session in the network. After the connection is created
697 successfully, the application is responsible of setting the user
698 interface for user into the same state it was before detaching (showing
699 same channels, channel modes, etc). It can do this by fetching the
700 information (like joined channels) from the client library. */
701 void (*detach)(SilcClient client, SilcClientConnection conn,
702 const unsigned char *detach_data,
703 SilcUInt32 detach_data_len);
704 } SilcClientOperations;
707 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
711 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
712 * char **ret_nickname);
716 * A callback function provided by the application for the library in
717 * SilcClientParams structure. This function parses the formatted
718 * nickname string `nickname' and returns the true nickname to the
719 * `ret_nickname' pointer. The library can call this function at
723 typedef void (*SilcNicknameFormatParse)(const char *nickname,
724 char **ret_nickname);
726 /****s* silcclient/SilcClientAPI/SilcClientParams
730 * typedef struct { ... } SilcClientParams;
734 * Client parameters. This can be filled with proper values and
735 * given as argument to the silc_client_alloc function. The structure
736 * hold various parameters which affects the function of the client.
741 /* Number of maximum tasks the client library's scheduler can handle.
742 If set to zero, the default value will be used (200). For WIN32
743 systems this should be set to 64 as it is the hard limit dictated
747 /* Rekey timeout in seconds. The client will perform rekey in this
748 time interval. If set to zero, the default value will be used. */
749 unsigned int rekey_secs;
751 /* Connection authentication method request timeout. If server does not
752 reply back the current authentication method when we've requested it
753 in this time interval we'll assume the reply will not come at all.
754 If set to zero, the default value (2 seconds) will be used. */
755 unsigned int connauth_request_secs;
757 /* Nickname format string. This can be used to order the client library
758 to save the nicknames in the library in a certain format. Since
759 nicknames are not unique in SILC it is possible to have multiple same
760 nicknames. Using this format string it is possible to order the library
761 to separate the multiple same nicknames from each other. The format
762 types are defined below and they can appear in any order in the format
763 string. If this is NULL then default format is used which is the
764 default nickname without anything else. The string MUST be NULL
767 Following format types are available:
769 %n nickname - the real nickname returned by the server (mandatory)
770 %h hostname - the stripped hostname of the client
771 %H full hostname - the full hostname of the client
772 %s server name - the server name the client is connected
773 %S full server - the full server name the client is connected
774 %a number - ascending number in case there are several
775 same nicknames (fe. nick@host and nick@host2)
777 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
778 "%a!%n@%s" (fe. nick@server, 2!nick@server)
779 "%n@%H" (fe. nick@host.domain.com)
781 By default this format is employed to the nicknames by the libary
782 only when there appears multiple same nicknames. If the library has
783 only one nickname cached the nickname is saved as is and without the
784 defined format. If you want always to save the nickname in the defined
785 format set the boolean field `nickname_force_format' to value TRUE.
787 char nickname_format[32];
789 /* If this is set to TRUE then the `nickname_format' is employed to all
790 saved nicknames even if there are no multiple same nicknames in the
791 cache. By default this is FALSE, which means that the `nickname_format'
792 is employed only if the library will receive a nickname that is
793 already saved in the cache. It is recommended to leave this to FALSE
795 bool nickname_force_format;
797 /* A callback function provided by the application for the library to
798 parse the nickname from the formatted nickname string. Even though
799 the libary formats the nicknames the application knows generally the
800 format better so this function should be provided for the library
801 if the application sets the `nickname_format' field. The library
802 will call this to get the true nickname from the provided formatted
803 nickname string whenever it needs the true nickname. */
804 SilcNicknameFormatParse nickname_parse;
806 /* If this is set to TRUE then the client will ignore all incoming
807 Requested Attributes queries and does not reply anything back. This
808 usually leads into situation where server does not anymore send
809 the queries after seeing that client does not reply anything back.
810 If your application does not support Requested Attributes or you do
811 not want to use them set this to TRUE. See SilcAttribute and
812 silc_client_attribute_add for more information on attributes. */
813 bool ignore_requested_attributes;
819 /* Initialization functions (client.c) */
821 /****f* silcclient/SilcClientAPI/silc_client_alloc
825 * SilcClient silc_client_alloc(SilcClientOperations *ops,
826 * SilcClientParams *params,
828 * const char *silc_version);
832 * Allocates new client object. This has to be done before client may
833 * work. After calling this one must call silc_client_init to initialize
834 * the client. The `application' is application specific user data pointer
835 * and caller must free it. The `silc_version' is the application version
836 * that will be used to compare against remote host's (usually a server)
837 * version string. The `application' context is accessible by the
838 * application by client->application, client being SilcClient.
841 SilcClient silc_client_alloc(SilcClientOperations *ops,
842 SilcClientParams *params,
844 const char *version_string);
846 /****f* silcclient/SilcClientAPI/silc_client_free
850 * void silc_client_free(SilcClient client);
854 * Frees client object and its internals. The execution of the client
855 * should be stopped with silc_client_stop function before calling
859 void silc_client_free(SilcClient client);
861 /****f* silcclient/SilcClientAPI/silc_client_init
865 * bool silc_client_init(SilcClient client);
869 * Initializes the client. This makes all the necessary steps to make
870 * the client ready to be run. One must call silc_client_run to run the
871 * client. Returns FALSE if error occurred, TRUE otherwise.
874 bool silc_client_init(SilcClient client);
876 /****f* silcclient/SilcClientAPI/silc_client_run
880 * void silc_client_run(SilcClient client);
884 * Runs the client. This starts the scheduler from the utility library.
885 * When this functions returns the execution of the appliation is over.
886 * The client must be initialized before calling this.
889 void silc_client_run(SilcClient client);
891 /****f* silcclient/SilcClientAPI/silc_client_run_one
895 * void silc_client_run_one(SilcClient client);
899 * Runs the client and returns immeadiately. This function is used when
900 * the SILC Client object indicated by the `client' is run under some
901 * other scheduler, or event loop or main loop. On GUI applications,
902 * for example this may be desired to used to run the client under the
903 * GUI application's main loop. Typically the GUI application would
904 * register an idle task that calls this function multiple times in
905 * a second to quickly process the SILC specific data.
908 void silc_client_run_one(SilcClient client);
910 /****f* silcclient/SilcClientAPI/silc_client_stop
914 * void silc_client_stop(SilcClient client);
918 * Stops the client. This is called to stop the client and thus to stop
919 * the program. The client context must be freed with the silc_client_free
923 void silc_client_stop(SilcClient client);
926 /* Connecting functions (client.c) */
928 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
932 * typedef struct { ... } SilcClientConnectionParams;
936 * Client connection parameters. This can be filled by the application
937 * and given as argument to silc_client_connect_to_server or to
938 * silc_client_add_connection.
943 /* The SILC session detachment data that was returned by `detach' client
944 operation when the application detached from the network. Application
945 is responsible of saving the data and giving it as argument here
946 for resuming the session in the SILC network.
948 If this is provided here the client library will attempt to resume
949 the session in the network. After the connection is created
950 successfully, the application is responsible of setting the user
951 interface for user into the same state it was before detaching (showing
952 same channels, channel modes, etc). It can do this by fetching the
953 information (like joined channels) from the client library. */
954 unsigned char *detach_data;
955 SilcUInt32 detach_data_len;
957 } SilcClientConnectionParams;
960 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
964 * int silc_client_connect_to_server(SilcClient client,
965 * SilcClientConnectionParams *params,
966 * int port, char *host, void *context);
970 * Connects to remote server. This is the main routine used to connect
971 * to SILC server. Returns -1 on error and the created socket otherwise.
972 * The `context' is user context that is saved into the SilcClientConnection
973 * that is created after the connection is created. Note that application
974 * may handle the connecting process outside the library. If this is the
975 * case then this function is not used at all. When the connecting is
976 * done the `connect' client operation is called, and the `context' is
977 * accessible with conn->context, conn being SilcClientConnection.
978 * If the `params' is provided they are used by the routine.
981 int silc_client_connect_to_server(SilcClient client,
982 SilcClientConnectionParams *params,
983 int port, char *host, void *context);
985 /****f* silcclient/SilcClientAPI/silc_client_add_connection
990 * SilcClientConnection
991 * silc_client_add_connection(SilcClient client,
992 * SilcClientConnectionParams *params,
993 * char *hostname, int port, void *context);
997 * Allocates and adds new connection to the client. This adds the allocated
998 * connection to the connection table and returns a pointer to it. A client
999 * can have multiple connections to multiple servers. Every connection must
1000 * be added to the client using this function. User data `context' may
1001 * be sent as argument. If the `params' is provided they are used by
1006 * This function is normally used only if the application performed
1007 * the connecting outside the library, and did not called the
1008 * silc_client_connect_to_server function at all. The library
1009 * however may use this internally.
1012 SilcClientConnection
1013 silc_client_add_connection(SilcClient client,
1014 SilcClientConnectionParams *params,
1015 char *hostname, int port, void *context);
1017 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1021 * void silc_client_del_connection(SilcClient client,
1022 * SilcClientConnection conn);
1026 * Removes connection from client. Frees all memory. The library
1027 * call this function automatically for all connection contexts.
1028 * The application however may free the connection contexts it has
1032 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1034 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1038 * void silc_client_add_socket(SilcClient client,
1039 * SilcSocketConnection sock);
1043 * Adds listener socket to the listener sockets table. This function is
1044 * used to add socket objects that are listeners to the client. This should
1045 * not be used to add other connection objects.
1048 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1050 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1054 * void silc_client_del_socket(SilcClient client,
1055 * SilcSocketConnection sock);
1059 * Deletes listener socket from the listener sockets table. If the
1060 * application has added a socket with silc_client_add_socket it must
1061 * also free it using this function.
1064 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1066 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1070 * void silc_client_start_key_exchange(SilcClient client,
1071 * SilcClientConnection conn,
1076 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1077 * key material between client and server. This function can be called
1078 * directly if application is performing its own connecting and does not
1079 * use the connecting provided by this library. This function is normally
1080 * used only if the application performed the connecting outside the
1081 * library. The library however may use this internally. After the
1082 * key exchange is performed the `connect' client operation is called.
1086 * The silc_client_add_connection must be called before calling this
1087 * function to create the SilcClientConnection context for this
1091 void silc_client_start_key_exchange(SilcClient client,
1092 SilcClientConnection conn,
1095 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1099 * void silc_client_close_connection(SilcClient client,
1100 * SilcClientConnection conn);
1104 * Closes connection to remote end. Free's all allocated data except
1105 * for some information such as nickname etc. that are valid at all time.
1106 * Usually application does not need to directly call this, except
1107 * when explicitly closing the connection, or if an error occurs
1108 * during connection to server (see 'connect' client operation for
1109 * more information).
1112 void silc_client_close_connection(SilcClient client,
1113 SilcClientConnection conn);
1116 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1118 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1122 * bool silc_client_send_channel_message(SilcClient client,
1123 * SilcClientConnection conn,
1124 * SilcChannelEntry channel,
1125 * SilcChannelPrivateKey key,
1126 * SilcMessageFlags flags,
1127 * unsigned char *data,
1128 * SilcUInt32 data_len,
1133 * Sends packet to the `channel'. Packet to channel is always encrypted
1134 * differently from "normal" packets. SILC header of the packet is
1135 * encrypted with the next receiver's key and the rest of the packet is
1136 * encrypted with the channel specific key. Padding and HMAC is computed
1137 * with the next receiver's key. The `data' is the channel message. If
1138 * the `force_send' is TRUE then the packet is sent immediately.
1140 * If `key' is provided then that private key is used to encrypt the
1141 * channel message. If it is not provided, private keys has not been
1142 * set at all, the normal channel key is used automatically. If private
1143 * keys are set then the first key (the key that was added first as
1144 * private key) is used.
1146 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1147 * digitally signed with the SILC key pair.
1149 * Returns TRUE if the message was sent, and FALSE if error occurred or
1150 * the sending is not allowed due to channel modes (like sending is
1154 bool silc_client_send_channel_message(SilcClient client,
1155 SilcClientConnection conn,
1156 SilcChannelEntry channel,
1157 SilcChannelPrivateKey key,
1158 SilcMessageFlags flags,
1159 unsigned char *data,
1160 SilcUInt32 data_len,
1163 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1167 * bool silc_client_send_private_message(SilcClient client,
1168 * SilcClientConnection conn,
1169 * SilcClientEntry client_entry,
1170 * SilcMessageFlags flags,
1171 * unsigned char *data,
1172 * SilcUInt32 data_len,
1177 * Sends private message to remote client. If private message key has
1178 * not been set with this client then the message will be encrypted using
1179 * normal session keys. Private messages are special packets in SILC
1180 * network hence we need this own function for them. This is similar
1181 * to silc_client_packet_send_to_channel except that we send private
1182 * message. The `data' is the private message. If the `force_send' is
1183 * TRUE the packet is sent immediately.
1185 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1186 * digitally signed with the SILC key pair.
1188 * Returns TRUE if the message was sent, and FALSE if error occurred.
1191 bool silc_client_send_private_message(SilcClient client,
1192 SilcClientConnection conn,
1193 SilcClientEntry client_entry,
1194 SilcMessageFlags flags,
1195 unsigned char *data,
1196 SilcUInt32 data_len,
1200 /* Client and Channel entry retrieval (idlist.c) */
1202 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1206 * typedef void (*SilcGetClientCallback)(SilcClient client,
1207 * SilcClientConnection conn,
1208 * SilcClientEntry *clients,
1209 * SilcUInt32 clients_count,
1214 * Callback function given to the silc_client_get_client function. The
1215 * found entries are allocated into the `clients' array. The array must
1216 * not be freed by the receiver, the library will free it later. If the
1217 * `clients' is NULL, no such clients exist in the SILC Network.
1220 typedef void (*SilcGetClientCallback)(SilcClient client,
1221 SilcClientConnection conn,
1222 SilcClientEntry *clients,
1223 SilcUInt32 clients_count,
1226 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1230 * void silc_client_get_clients(SilcClient client,
1231 * SilcClientConnection conn,
1232 * const char *nickname,
1233 * const char *server,
1234 * SilcGetClientCallback completion,
1239 * Finds client entry or entries by the `nickname' and `server'. The
1240 * completion callback will be called when the client entries has been
1241 * found. After the server returns the client information it is cached
1242 * and can be accesses locally at a later time. The resolving is done
1243 * with IDENTIFY command. The `server' may be NULL.
1247 * NOTE: This function is always asynchronous and resolves the client
1248 * information from the server. Thus, if you already know the client
1249 * information then use the silc_client_get_client_by_id function to
1250 * get the client entry since this function may be very slow and should
1251 * be used only to initially get the client entries.
1253 * Since this routine resolves with IDENTIFY command only the relevant
1254 * information (user's nickname and username) is resolved. For example,
1255 * user's real name, channel list and others are not resolved. Caller
1256 * can/must resolve those separately if they are needed (for example,
1257 * with silc_client_get_client_by_id_resolve).
1260 void silc_client_get_clients(SilcClient client,
1261 SilcClientConnection conn,
1262 const char *nickname,
1264 SilcGetClientCallback completion,
1267 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1271 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1272 * SilcClientConnection conn,
1273 * const char *nickname,
1274 * const char *format,
1275 * SilcUInt32 *clients_count);
1279 * Same as silc_client_get_clients function but does not resolve anything
1280 * from the server. This checks local cache and returns all matching
1281 * clients from the local cache. If none was found this returns NULL.
1282 * The `nickname' is the real nickname of the client, and the `format'
1283 * is the formatted nickname to find exact match from multiple found
1284 * entries. The format must be same as given in the SilcClientParams
1285 * structure to the client library. If the `format' is NULL all found
1286 * clients by `nickname' are returned. The caller must return the
1290 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1291 SilcClientConnection conn,
1292 const char *nickname,
1294 SilcUInt32 *clients_count);
1296 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1300 * void silc_client_get_clients_by_channel(SilcClient client,
1301 * SilcClientConnection conn,
1302 * SilcChannelEntry channel,
1303 * SilcGetClientCallback completion,
1308 * Gets client entries by the channel indicated by `channel'. Thus,
1309 * it resovles the users currently on that channel. If all users are
1310 * already resolved this returns the users from the channel. If the
1311 * users are resolved only partially this resolves the complete user
1312 * information. If no users are resolved on this channel at all, this
1313 * calls USERS command to resolve all users on the channel. The `completion'
1314 * will be called after the entries are available. When server returns
1315 * the client information it will be cached and can be accessed locally
1318 * This function can be used for example in SILC_COMMAND_JOIN command
1319 * reply handling in application to resolve users on that channel. It
1320 * also can be used after calling silc_client_get_channel_resolve to
1321 * resolve users on that channel.
1325 * The resolving is done with WHOIS command. For this reason this
1326 * command may take a long time because it resolves detailed user
1330 void silc_client_get_clients_by_channel(SilcClient client,
1331 SilcClientConnection conn,
1332 SilcChannelEntry channel,
1333 SilcGetClientCallback completion,
1336 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1340 * void silc_client_get_clients_by_list(SilcClient client,
1341 * SilcClientConnection conn,
1342 * SilcUInt32 list_count,
1343 * SilcBuffer client_id_list,
1344 * SilcGetClientCallback completion,
1349 * Gets client entries by the list of client ID's `client_id_list'. This
1350 * always resolves those client ID's it does not know yet from the server
1351 * so this function might take a while. The `client_id_list' is a list
1352 * of ID Payloads added one after other. JOIN command reply and USERS
1353 * command reply for example returns this sort of list. The `completion'
1354 * will be called after the entries are available. When server returns
1355 * the client information it will be cached and can be accessed locally
1360 * The resolving is done with IDENTIFY command. This means that only
1361 * the relevant information of user (it's nickname and username) is
1362 * resolved. For example, user's real name, channel lists and others
1363 * are not resolved. Caller can/must resolve those separately if they
1364 * are needed (for example, with silc_client_get_client_by_id_resolve).
1367 void silc_client_get_clients_by_list(SilcClient client,
1368 SilcClientConnection conn,
1369 SilcUInt32 list_count,
1370 SilcBuffer client_id_list,
1371 SilcGetClientCallback completion,
1374 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1378 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1379 * SilcClientConnection conn,
1380 * SilcClientID *client_id);
1384 * Find entry for client by the client's ID. Returns the entry or NULL
1385 * if the entry was not found. This checks the local cache and does
1386 * not resolve anything from server.
1389 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1390 SilcClientConnection conn,
1391 SilcClientID *client_id);
1393 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1398 * silc_client_get_client_by_id_resolve(SilcClient client,
1399 * SilcClientConnection conn,
1400 * SilcClientID *client_id,
1401 * SilcBuffer attributes,
1402 * SilcGetClientCallback completion,
1407 * Same as silc_client_get_client_by_id but will always resolve the
1408 * information from the server. Use this only if you know that you
1409 * do not have the entry and the only thing you know about the client
1410 * is its ID. When server returns the client information it will be
1411 * cache and can be accessed locally at a later time. The resolving
1412 * is done by sending WHOIS command.
1414 * If the `attributes' is non-NULL then the buffer includes Requested
1415 * Attributes which can be used to fetch very detailed information
1416 * about the user. If it is NULL then only normal WHOIS query is
1417 * made (for more information about attributes see SilcAttribute).
1418 * Caller may create the `attributes' with silc_client_attributes_request
1422 void silc_client_get_client_by_id_resolve(SilcClient client,
1423 SilcClientConnection conn,
1424 SilcClientID *client_id,
1425 SilcBuffer attributes,
1426 SilcGetClientCallback completion,
1429 /****f* silcclient/SilcClientAPI/silc_client_del_client
1433 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1434 * SilcClientEntry client_entry)
1438 * Removes client from local cache by the client entry indicated by
1439 * the `client_entry'. Returns TRUE if the deletion were successful.
1442 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1443 SilcClientEntry client_entry);
1445 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1449 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1450 * SilcClientConnection conn,
1451 * SilcChannelEntry *channels,
1452 * SilcUInt32 channels_count,
1457 * Callback function given to the silc_client_get_channel_* functions.
1458 * The found entries are allocated into the `channels' array. The array
1459 * must not be freed by the receiver, the library will free it later.
1460 * If the `channel' is NULL, no such channel exist in the SILC Network.
1463 typedef void (*SilcGetChannelCallback)(SilcClient client,
1464 SilcClientConnection conn,
1465 SilcChannelEntry *channels,
1466 SilcUInt32 channels_count,
1469 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1473 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1474 * SilcClientConnection conn,
1475 * char *channel_name);
1479 * Finds entry for channel by the channel name. Returns the entry or NULL
1480 * if the entry was not found. It is found only if the client is joined
1481 * to the channel. Use silc_client_get_channel_resolve or
1482 * silc_client_get_channel_by_id_resolve to resolve channel that client
1486 SilcChannelEntry silc_client_get_channel(SilcClient client,
1487 SilcClientConnection conn,
1488 char *channel_name);
1490 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1494 * void silc_client_get_channel_resolve(SilcClient client,
1495 * SilcClientConnection conn,
1496 * char *channel_name,
1497 * SilcGetChannelCallback completion,
1502 * Resolves entry for channel by the channel name from the server.
1503 * The resolving is done with IDENTIFY command. Note that users on
1504 * the channel are not resolved at the same time. Use for example
1505 * silc_client_get_clients_by_channel to resolve all users on a channel.
1508 void silc_client_get_channel_resolve(SilcClient client,
1509 SilcClientConnection conn,
1511 SilcGetChannelCallback completion,
1514 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1519 * silc_client_get_channel_by_id(SilcClient client,
1520 * SilcClientConnection conn,
1521 * SilcChannelID *channel_id);
1525 * Finds channel entry by the channel ID. Returns the entry or NULL
1526 * if the entry was not found. This checks the local cache and does
1527 * not resolve anything from server.
1530 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1531 SilcClientConnection conn,
1532 SilcChannelID *channel_id);
1534 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1539 * silc_client_get_channel_by_id_resolve(SilcClient client,
1540 * SilcClientConnection conn,
1541 * SilcChannelID *channel_id,
1542 * SilcGetClientCallback completion,
1547 * Resolves the channel information (its name mainly) from the server
1548 * by the `channel_id'. Use this only if you know that you do not have
1549 * the entry cached locally. The resolving is done with IDENTIFY command.
1551 * Note that users on the channel are not resolved at the same time.
1552 * Use for example silc_client_get_clients_by_channel to resolve all
1553 * users on a channel.
1556 void silc_client_get_channel_by_id_resolve(SilcClient client,
1557 SilcClientConnection conn,
1558 SilcChannelID *channel_id,
1559 SilcGetChannelCallback completion,
1562 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1566 * bool silc_client_del_channel(SilcClient client,
1567 * SilcClientConnection conn,
1568 * SilcChannelEntry channel)
1572 * Removes channel from local cache by the channel entry indicated by
1573 * the `channel'. Returns TRUE if the deletion were successful.
1576 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1577 SilcChannelEntry channel);
1579 /****f* silcclient/SilcClientAPI/silc_client_get_server
1583 * SilcServerEntry silc_client_get_server(SilcClient client,
1584 * SilcClientConnection conn,
1585 * char *server_name)
1589 * Finds entry for server by the server name. Returns the entry or NULL
1590 * if the entry was not found.
1593 SilcServerEntry silc_client_get_server(SilcClient client,
1594 SilcClientConnection conn,
1597 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1601 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1602 * SilcClientConnection conn,
1603 * SilcServerID *server_id);
1607 * Finds entry for server by the server ID. Returns the entry or NULL
1608 * if the entry was not found.
1611 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1612 SilcClientConnection conn,
1613 SilcServerID *server_id);
1615 /****f* silcclient/SilcClientAPI/silc_client_del_server
1619 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1620 * SilcServerEntry server);
1624 * Removes server from local cache by the server entry indicated by
1625 * the `server'. Returns TRUE if the deletion were successful.
1628 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1629 SilcServerEntry server);
1631 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1635 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1636 * SilcClientEntry client_entry);
1640 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1641 * channel indicated by the `channel'. NULL if client is not joined on
1645 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1646 SilcClientEntry client_entry);
1648 /* Command management (command.c) */
1650 /****f* silcclient/SilcClientAPI/silc_client_command_call
1654 * bool silc_client_command_call(SilcClient client,
1655 * SilcClientConnection conn,
1656 * const char *command_line, ...);
1660 * Calls and executes the command indicated by the `command_name'.
1661 * The `command_line' is a string which includes the command's name and
1662 * its arguments separated with whitespaces (' '). If `command_line'
1663 * is non-NULL then all variable arguments are ignored by default.
1665 * If `command_line' is NULL, then the variable arguments define the
1666 * command's name and its arguments. The first variable argument must
1667 * be the command name. The variable argument list must be terminated
1670 * Returns FALSE if the command is not known and TRUE after command.
1671 * execution. The "command" client operation is called when the
1672 * command is executed to indicate whether the command executed
1673 * successfully or not.
1675 * The "command_reply" client operation will be called when reply is
1676 * received from the server to the command. Application may also use
1677 * the silc_client_command_pending to attach to the command reply.
1678 * The command identifier for silc_client_command_pending function after
1679 * this function call is conn->cmd_ident, which application may use.
1683 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1685 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1689 * This command executes the commands implemented inside the client
1690 * library. These commands are designed for command line applications,
1691 * but GUI application may call them too if needed. Alternatively
1692 * application may override the library and use silc_client_command_send
1696 bool silc_client_command_call(SilcClient client,
1697 SilcClientConnection conn,
1698 const char *command_line, ...);
1700 /****f* silcclient/SilcClientAPI/silc_client_command_send
1704 * void silc_client_command_send(SilcClient client,
1705 * SilcClientConnection conn,
1706 * SilcCommand command, SilcUInt16 ident,
1707 * SilcUInt32 argc, ...);
1711 * Generic function to send any command. The arguments must be sent already
1712 * encoded into correct form and in correct order. If application wants
1713 * to perform the commands by itself, it can do so and send the data
1714 * directly to the server using this function. If application is using
1715 * the silc_client_command_call, this function is usually not used.
1716 * Note that this overriders the Client Librarys commands and sends
1717 * the command packet directly to server.
1719 * Programmer should get familiar with the SILC protocol commands
1720 * specification when using this function, as the arguments needs to
1721 * be encoded as specified in the protocol.
1723 * The variable arguments are a pair of { type, data, data_length },
1724 * and the `argc' is the number of these pairs.
1728 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1729 * 1, nickname, strlen(nickname));
1732 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1733 SilcCommand command, SilcUInt16 ident,
1734 SilcUInt32 argc, ...);
1736 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1740 * void silc_client_command_pending(SilcClientConnection conn,
1741 * SilcCommand reply_cmd,
1743 * SilcCommandCb callback,
1748 * This function can be used to add pending command callback to be
1749 * called when an command reply is received to an earlier sent command.
1750 * The `reply_cmd' is the command that must be received in order for
1751 * the pending command callback indicated by `callback' to be called.
1752 * The `callback' will deliver the `context' and
1753 * SilcClientCommandReplyContext which includes the internals of the
1756 * The `ident' is a command identifier which was set for the earlier
1757 * sent command. The command reply will include the same identifier
1758 * and pending command callback will be called when the reply is
1759 * received with the same command identifier. It is possible to
1760 * add multiple pending command callbacks for same command and for
1763 * Application may use this function to add its own command reply
1764 * handlers if it wishes not to use the standard `command_reply'
1765 * client operation. However, note that the pending command callback
1766 * does not deliver parsed command reply, but application must parse
1769 * Note also that the application is notified about the received command
1770 * reply through the `command_reply' client operation before calling
1771 * the `callback` pending command callback. That is the normal
1772 * command reply handling, and is called regardless whether pending
1773 * command callbacks are used or not.
1775 * Commands that application calls with silc_client_command_call
1776 * will use a command identifier from conn->cmd_ident variable. After
1777 * calling the silc_client_command_call, the conn->cmd_ident includes
1778 * the command identifier that was used for the command sending.
1782 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1783 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1784 * my_ping_handler, my_ping_context);
1787 void silc_client_command_pending(SilcClientConnection conn,
1788 SilcCommand reply_cmd,
1790 SilcCommandCb callback,
1794 /* Private Message key management (client_prvmsg.c) */
1796 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1800 * bool silc_client_add_private_message_key(SilcClient client,
1801 * SilcClientConnection conn,
1802 * SilcClientEntry client_entry,
1803 * const char *cipher,
1805 * unsigned char *key,
1806 * SilcUInt32 key_len,
1807 * bool generate_key,
1812 * Adds private message key to the client library. The key will be used to
1813 * encrypt all private message between the client and the remote client
1814 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1815 * value `generate_key' is TRUE the library will generate random key.
1816 * The `key' maybe for example pre-shared-key, passphrase or similar.
1817 * The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1818 * that the requirements of the SILC protocol are met. The API, however,
1819 * allows to allocate any cipher and HMAC.
1821 * If `responder' is TRUE then the sending and receiving keys will be
1822 * set according the client being the receiver of the private key. If
1823 * FALSE the client is being the sender (or negotiator) of the private
1826 * It is not necessary to set key for normal private message usage. If the
1827 * key is not set then the private messages are encrypted using normal
1828 * session keys. Setting the private key, however, increases the security.
1830 * Returns FALSE if the key is already set for the `client_entry', TRUE
1834 bool silc_client_add_private_message_key(SilcClient client,
1835 SilcClientConnection conn,
1836 SilcClientEntry client_entry,
1844 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1849 * silc_client_add_private_message_key_ske(SilcClient client,
1850 * SilcClientConnection conn,
1851 * SilcClientEntry client_entry,
1852 * const char *cipher,
1854 * SilcSKEKeyMaterial *key);
1858 * Same as silc_client_add_private_message_key but takes the key material
1859 * from the SKE key material structure. This structure is received if
1860 * the application uses the silc_client_send_key_agreement to negotiate
1861 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1862 * negotiated also in the SKE protocol.
1865 bool silc_client_add_private_message_key_ske(SilcClient client,
1866 SilcClientConnection conn,
1867 SilcClientEntry client_entry,
1870 SilcSKEKeyMaterial *key,
1873 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1877 * bool silc_client_del_private_message_key(SilcClient client,
1878 * SilcClientConnection conn,
1879 * SilcClientEntry client_entry);
1883 * Removes the private message from the library. The key won't be used
1884 * after this to protect the private messages with the remote `client_entry'
1885 * client. Returns FALSE on error, TRUE otherwise.
1888 bool silc_client_del_private_message_key(SilcClient client,
1889 SilcClientConnection conn,
1890 SilcClientEntry client_entry);
1892 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1896 * SilcPrivateMessageKeys
1897 * silc_client_list_private_message_keys(SilcClient client,
1898 * SilcClientConnection conn,
1899 * SilcUInt32 *key_count);
1903 * Returns array of set private message keys associated to the connection
1904 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1905 * count to the `key_count' argument. The array must be freed by the caller
1906 * by calling the silc_client_free_private_message_keys function. Note:
1907 * the keys returned in the array is in raw format. It might not be desired
1908 * to show the keys as is. The application might choose not to show the keys
1909 * at all or to show the fingerprints of the keys.
1912 SilcPrivateMessageKeys
1913 silc_client_list_private_message_keys(SilcClient client,
1914 SilcClientConnection conn,
1915 SilcUInt32 *key_count);
1917 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1921 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1922 * SilcUInt32 key_count);
1926 * Frees the SilcPrivateMessageKeys array returned by the function
1927 * silc_client_list_private_message_keys.
1930 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1931 SilcUInt32 key_count);
1934 /* Channel private key management (client_channel.c,
1935 SilcChannelPrivateKey is defined in idlist.h) */
1937 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1941 * bool silc_client_add_channel_private_key(SilcClient client,
1942 * SilcClientConnection conn,
1943 * SilcChannelEntry channel,
1947 * unsigned char *key,
1948 * SilcUInt32 key_len);
1952 * Adds private key for channel. This may be set only if the channel's mode
1953 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1954 * mode is not set. When channel has private key then the messages are
1955 * encrypted using that key. All clients on the channel must also know the
1956 * key in order to decrypt the messages. However, it is possible to have
1957 * several private keys per one channel. In this case only some of the
1958 * clients on the channel may know the one key and only some the other key.
1959 * The `name' can be application given name for the key.
1961 * The private key for channel is optional. If it is not set then the
1962 * channel messages are encrypted using the channel key generated by the
1963 * server. However, setting the private key (or keys) for the channel
1964 * significantly adds security. If more than one key is set the library
1965 * will automatically try all keys at the message decryption phase. Note:
1966 * setting many keys slows down the decryption phase as all keys has to
1967 * be tried in order to find the correct decryption key. However, setting
1968 * a few keys does not have big impact to the decryption performace.
1972 * NOTE: This is entirely local setting. The key set using this function
1973 * is not sent to the network at any phase.
1975 * NOTE: If the key material was originated by the SKE protocol (using
1976 * silc_client_send_key_agreement) then the `key' MUST be the
1977 * key->send_enc_key as this is dictated by the SILC protocol. However,
1978 * currently it is not expected that the SKE key material would be used
1979 * as channel private key. However, this API allows it.
1982 bool silc_client_add_channel_private_key(SilcClient client,
1983 SilcClientConnection conn,
1984 SilcChannelEntry channel,
1989 SilcUInt32 key_len);
1991 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1995 * bool silc_client_del_channel_private_keys(SilcClient client,
1996 * SilcClientConnection conn,
1997 * SilcChannelEntry channel);
2001 * Removes all private keys from the `channel'. The old channel key is used
2002 * after calling this to protect the channel messages. Returns FALSE on
2003 * on error, TRUE otherwise.
2006 bool silc_client_del_channel_private_keys(SilcClient client,
2007 SilcClientConnection conn,
2008 SilcChannelEntry channel);
2010 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2014 * bool silc_client_del_channel_private_key(SilcClient client,
2015 * SilcClientConnection conn,
2016 * SilcChannelEntry channel,
2017 * SilcChannelPrivateKey key);
2021 * Removes and frees private key `key' from the channel `channel'.
2022 * The `key' is retrieved by calling the function
2023 * silc_client_list_channel_private_keys. The key is not used after
2024 * this. If the key was last private key then the old channel key is
2025 * used hereafter to protect the channel messages. This returns FALSE
2026 * on error, TRUE otherwise.
2029 bool silc_client_del_channel_private_key(SilcClient client,
2030 SilcClientConnection conn,
2031 SilcChannelEntry channel,
2032 SilcChannelPrivateKey key);
2034 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2038 * SilcChannelPrivateKey *
2039 * silc_client_list_channel_private_keys(SilcClient client,
2040 * SilcClientConnection conn,
2041 * SilcChannelEntry channel,
2042 * SilcUInt32 *key_count);
2046 * Returns array (pointers) of private keys associated to the `channel'.
2047 * The caller must free the array by calling the function
2048 * silc_client_free_channel_private_keys. The pointers in the array may be
2049 * used to delete the specific key by giving the pointer as argument to the
2050 * function silc_client_del_channel_private_key.
2053 SilcChannelPrivateKey *
2054 silc_client_list_channel_private_keys(SilcClient client,
2055 SilcClientConnection conn,
2056 SilcChannelEntry channel,
2057 SilcUInt32 *key_count);
2059 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2063 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2064 * SilcUInt32 key_count);
2068 * Frees the SilcChannelPrivateKey array.
2071 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2072 SilcUInt32 key_count);
2074 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2078 * void silc_client_current_channel_private_key(SilcClient client,
2079 * SilcClientConnection conn,
2080 * SilcChannelEntry channel,
2081 * SilcChannelPrivateKey key);
2085 * Sets the `key' to be used as current channel private key on the
2086 * `channel'. Packet sent after calling this function will be secured
2090 void silc_client_current_channel_private_key(SilcClient client,
2091 SilcClientConnection conn,
2092 SilcChannelEntry channel,
2093 SilcChannelPrivateKey key);
2096 /* Key Agreement routines (client_keyagr.c) */
2098 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2102 * void silc_client_send_key_agreement(SilcClient client,
2103 * SilcClientConnection conn,
2104 * SilcClientEntry client_entry,
2107 * SilcUInt32 timeout_secs,
2108 * SilcKeyAgreementCallback completion,
2113 * Sends key agreement request to the remote client indicated by the
2114 * `client_entry'. If the caller provides the `hostname' and the `port'
2115 * arguments then the library will bind the client to that hostname and
2116 * that port for the key agreement protocol. It also sends the `hostname'
2117 * and the `port' in the key agreement packet to the remote client. This
2118 * would indicate that the remote client may initiate the key agreement
2119 * protocol to the `hostname' on the `port'. If port is zero then the
2120 * bound port is undefined (the operating system defines it).
2122 * If the `hostname' and `port' is not provided then empty key agreement
2123 * packet is sent to the remote client. The remote client may reply with
2124 * the same packet including its hostname and port. If the library receives
2125 * the reply from the remote client the `key_agreement' client operation
2126 * callback will be called to verify whether the user wants to perform the
2127 * key agreement or not.
2131 * NOTE: If the application provided the `hostname' and the `port' and the
2132 * remote side initiates the key agreement protocol it is not verified
2133 * from the user anymore whether the protocol should be executed or not.
2134 * By setting the `hostname' and `port' the user gives permission to
2135 * perform the protocol (we are responder in this case).
2137 * NOTE: If the remote side decides not to initiate the key agreement
2138 * or decides not to reply with the key agreement packet then we cannot
2139 * perform the key agreement at all. If the key agreement protocol is
2140 * performed the `completion' callback with the `context' will be called.
2141 * If remote side decides to ignore the request the `completion' will be
2142 * called after the specified timeout, `timeout_secs'.
2144 * NOTE: If the `hostname' and the `port' was not provided the `completion'
2145 * will not be called at all since this does nothing more than sending
2146 * a packet to the remote host.
2148 * NOTE: There can be only one active key agreement for one client entry.
2149 * Before setting new one, the old one must be finished (it is finished
2150 * after calling the completion callback) or the function
2151 * silc_client_abort_key_agreement must be called.
2154 void silc_client_send_key_agreement(SilcClient client,
2155 SilcClientConnection conn,
2156 SilcClientEntry client_entry,
2157 const char *hostname,
2158 const char *bindhost,
2160 SilcUInt32 timeout_secs,
2161 SilcKeyAgreementCallback completion,
2164 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2169 * silc_client_perform_key_agreement(SilcClient client,
2170 * SilcClientConnection conn,
2171 * SilcClientEntry client_entry,
2174 * SilcKeyAgreementCallback completion,
2179 * Performs the actual key agreement protocol. Application may use this
2180 * to initiate the key agreement protocol. This can be called for example
2181 * after the application has received the `key_agreement' client operation,
2182 * and did not return TRUE from it.
2184 * The `hostname' is the remote hostname (or IP address) and the `port'
2185 * is the remote port. The `completion' callback with the `context' will
2186 * be called after the key agreement protocol.
2190 * NOTE: If the application returns TRUE in the `key_agreement' client
2191 * operation the library will automatically start the key agreement. In this
2192 * case the application must not call this function. However, application
2193 * may choose to just ignore the `key_agreement' client operation (and
2194 * merely just print information about it on the screen) and call this
2195 * function when the user whishes to do so (by, for example, giving some
2196 * specific command). Thus, the API provides both, automatic and manual
2197 * initiation of the key agreement. Calling this function is the manual
2198 * initiation and returning TRUE in the `key_agreement' client operation
2199 * is the automatic initiation.
2202 void silc_client_perform_key_agreement(SilcClient client,
2203 SilcClientConnection conn,
2204 SilcClientEntry client_entry,
2207 SilcKeyAgreementCallback completion,
2210 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2215 * silc_client_perform_key_agreement_fd(SilcClient client,
2216 * SilcClientConnection conn,
2217 * SilcClientEntry client_entry,
2220 * SilcKeyAgreementCallback completion,
2225 * Same as above but application has created already the connection to
2226 * the remote host. The `sock' is the socket to the remote connection.
2227 * Application can use this function if it does not want the client library
2228 * to create the connection.
2231 void silc_client_perform_key_agreement_fd(SilcClient client,
2232 SilcClientConnection conn,
2233 SilcClientEntry client_entry,
2236 SilcKeyAgreementCallback completion,
2239 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2243 * void silc_client_abort_key_agreement(SilcClient client,
2244 * SilcClientConnection conn,
2245 * SilcClientEntry client_entry);
2249 * This function can be called to unbind the hostname and the port for
2250 * the key agreement protocol. However, this function has effect only
2251 * before the key agreement protocol has been performed. After it has
2252 * been performed the library will automatically unbind the port. The
2253 * `client_entry' is the client to which we sent the key agreement
2254 * request. The key agreement completion callback will be called
2255 * with SILC_KEY_AGREEMENT_ABORTED status.
2258 void silc_client_abort_key_agreement(SilcClient client,
2259 SilcClientConnection conn,
2260 SilcClientEntry client_entry);
2263 /* Misc functions */
2265 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2269 * void silc_client_set_away_message(SilcClient client,
2270 * SilcClientConnection conn,
2275 * Sets away `message'. The away message may be set when the client's
2276 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2277 * to anyone who sends private message. The `message' will be sent
2278 * automatically back to the the client who send private message. If
2279 * away message is already set this replaces the old message with the
2280 * new one. If `message' is NULL the old away message is removed.
2281 * The sender may freely free the memory of the `message'.
2284 void silc_client_set_away_message(SilcClient client,
2285 SilcClientConnection conn,
2288 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2292 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2293 * SilcClientConnection conn,
2294 * SilcAuthMethod auth_meth,
2299 * Connection authentication method request callback. This is called
2300 * by the client library after it has received the authentication method
2301 * that the application requested by calling the function
2302 * silc_client_request_authentication_method.
2305 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2306 SilcClientConnection conn,
2307 SilcAuthMethod auth_meth,
2310 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2315 * silc_client_request_authentication_method(SilcClient client,
2316 * SilcClientConnection conn,
2317 * SilcConnectionAuthRequest
2323 * This function can be used to request the current authentication method
2324 * from the server. This may be called when connecting to the server
2325 * and the client library requests the authentication data from the
2326 * application. If the application does not know the current authentication
2327 * method it can request it from the server using this function.
2328 * The `callback' with `context' will be called after the server has
2329 * replied back with the current authentication method.
2333 silc_client_request_authentication_method(SilcClient client,
2334 SilcClientConnection conn,
2335 SilcConnectionAuthRequest callback,
2338 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2342 * typedef enum { ... } SilcClientMonitorStatus;
2346 * File transmission session status types. These will indicate
2347 * the status of the file transmission session.
2352 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2353 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2354 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2355 SILC_CLIENT_FILE_MONITOR_GET,
2356 SILC_CLIENT_FILE_MONITOR_PUT,
2357 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2358 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2359 } SilcClientMonitorStatus;
2362 /****d* silcclient/SilcClientAPI/SilcClientFileError
2366 * typedef enum { ... } SilcClientFileError;
2370 * File transmission error types. These types are returned by
2371 * some of the file transmission functions, and by the monitor
2372 * callback to indicate error.
2377 SILC_CLIENT_FILE_OK,
2378 SILC_CLIENT_FILE_ERROR,
2379 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2380 SILC_CLIENT_FILE_ALREADY_STARTED,
2381 SILC_CLIENT_FILE_NO_SUCH_FILE,
2382 SILC_CLIENT_FILE_PERMISSION_DENIED,
2383 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2384 } SilcClientFileError;
2387 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2391 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2392 * SilcClientConnection conn,
2393 * SilcClientMonitorStatus status,
2394 * SilcClientFileError error,
2395 * SilcUInt64 offset,
2396 * SilcUInt64 filesize,
2397 * SilcClientEntry client_entry,
2398 * SilcUInt32 session_id,
2399 * const char *filepath,
2404 * Monitor callback that is called during the file transmission to
2405 * monitor the transmission process. The `status' indicates the current
2406 * monitoring process. The `error' will indicate the error type
2407 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2408 * currently transmitted amount of total `filesize'. The `client_entry'
2409 * indicates the remote client, and the transmission session ID is the
2410 * `session_id'. The filename being transmitted is indicated by the
2414 typedef void (*SilcClientFileMonitor)(SilcClient client,
2415 SilcClientConnection conn,
2416 SilcClientMonitorStatus status,
2417 SilcClientFileError error,
2419 SilcUInt64 filesize,
2420 SilcClientEntry client_entry,
2421 SilcUInt32 session_id,
2422 const char *filepath,
2425 /****f* silcclient/SilcClientAPI/silc_client_file_send
2429 * SilcClientFileError
2430 * silc_client_file_send(SilcClient client,
2431 * SilcClientConnection conn,
2432 * SilcClientFileMonitor monitor,
2433 * void *monitor_context,
2434 * const char *local_ip,
2435 * SilcUInt32 local_port,
2437 * SilcClientEntry client_entry,
2438 * const char *filepath);
2439 * SilcUInt32 *session_id);
2443 * Sends a file indicated by the `filepath' to the remote client
2444 * indicated by the `client_entry'. This will negotiate a secret key
2445 * with the remote client before actually starting the transmission of
2446 * the file. The `monitor' callback will be called to monitor the
2447 * transmission of the file.
2449 * This returns a file session ID for the file transmission to the
2450 * `session_id' pointer. It can be used to close the session (and
2451 * abort the file transmission) by calling the silc_client_file_close
2452 * function. The session ID is also returned in the `monitor' callback.
2454 * If the `local_ip' is provided then this will try to bind the
2455 * listener for key exchange protocol to that IP. If `local_port' is
2456 * non-zero that port is used. If `local_ip' is NULL then this will
2457 * automatically attempt to bind it to local IP address of the machine.
2458 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2459 * ignored and it is expected that the receiver will provide the
2460 * point of contact. This is usefull if the sender is behind NAT.
2462 * If error will occur during the file transfer process the error
2463 * status will be returned in the monitor callback. In this case
2464 * the application must call silc_client_file_close to close the
2469 silc_client_file_send(SilcClient client,
2470 SilcClientConnection conn,
2471 SilcClientFileMonitor monitor,
2472 void *monitor_context,
2473 const char *local_ip,
2474 SilcUInt32 local_port,
2476 SilcClientEntry client_entry,
2477 const char *filepath,
2478 SilcUInt32 *session_id);
2480 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2484 * SilcClientFileError
2485 * silc_client_file_receive(SilcClient client,
2486 * SilcClientConnection conn,
2487 * SilcClientFileMonitor monitor,
2488 * void *monitor_context,
2490 * SilcUInt32 session_id);
2494 * Receives a file from a client indicated by the `client_entry'. The
2495 * `session_id' indicates the file transmission session and it has been
2496 * received in the `ftp' client operation function. This will actually
2497 * perform the key agreement protocol with the remote client before
2498 * actually starting the file transmission. The `monitor' callback
2499 * will be called to monitor the transmission. If `path' is non NULL
2500 * the file will be saved into that directory. If NULL the file is
2501 * saved in the current working directory.
2503 * If error will occur during the file transfer process the error
2504 * status will be returned in the monitor callback. In this case
2505 * the application must call silc_client_file_close to close the
2510 silc_client_file_receive(SilcClient client,
2511 SilcClientConnection conn,
2512 SilcClientFileMonitor monitor,
2513 void *monitor_context,
2515 SilcUInt32 session_id);
2517 /****f* silcclient/SilcClientAPI/silc_client_file_close
2521 * SilcClientFileError silc_client_file_close(SilcClient client,
2522 * SilcClientConnection conn,
2523 * SilcUInt32 session_id);
2527 * Closes file transmission session indicated by the `session_id'.
2528 * If file transmission is being conducted it will be aborted
2529 * automatically. This function is also used to close the session
2530 * after successful file transmission. This function can be used
2531 * also to reject incoming file transmission request.
2534 SilcClientFileError silc_client_file_close(SilcClient client,
2535 SilcClientConnection conn,
2536 SilcUInt32 session_id);
2538 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2542 * SilcAttributePayload
2543 * silc_client_attribute_add(SilcClient client,
2544 * SilcClientConnection conn,
2545 * SilcAttribute attribute,
2547 * SilcUInt32 object_size);
2551 * Add new Requsted Attribute for WHOIS command to the client library.
2552 * The `attribute' object indicated by `object' is added and allocated
2553 * SilcAttributePayload is returned. The `object' must be of correct
2554 * type and of correct size. See the SilcAttribute for object types
2555 * for different attributes. You may also get all added attributes
2556 * from the client with silc_client_attributes_get function.
2558 * Requested Attributes are different personal information about the
2559 * user, status information and other information which other users
2560 * may query with WHOIS command. Application may set these so that
2561 * if someone sends WHOIS query these attributes will be replied back
2562 * to the sender. The library always puts the public key to the
2563 * Requested Attributes, but if application wishes to add additional
2564 * public keys (or certificates) it can be done with this interface.
2565 * Library also always computes digital signature of the attributes
2566 * automatically, so application does not need to do that.
2569 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2570 SilcClientConnection conn,
2571 SilcAttribute attribute,
2573 SilcUInt32 object_size);
2575 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2579 * bool silc_client_attribute_del(SilcClient client,
2580 * SilcClientConnection conn,
2581 * SilcAttribute attribute,
2582 * SilcAttributePayload attr);
2586 * Delete a Requested Attribute from the client. If the `attribute'
2587 * is non-zero then all attributes of that type are deleted and the
2588 * `attr' is ignored. If `attr' is non-NULL then that specific
2589 * attribute is deleted and `attribute' is ignored.
2591 * You may get all added attributes with the function
2592 * silc_client_attributes_get and to get the SilcAttributePayload.
2593 * This function Returns TRUE if the attribute was found and deleted.
2596 bool silc_client_attribute_del(SilcClient client,
2597 SilcClientConnection conn,
2598 SilcAttribute attribute,
2599 SilcAttributePayload attr);
2601 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2605 * const SilcHashTable
2606 * silc_client_attributes_get(SilcClient client,
2607 * SilcClientConnection conn);
2611 * Returns pointer to the SilcHashTable which includes all the added
2612 * Requested Attributes. The caller must not free the hash table.
2613 * The caller may use SilcHashTableList and silc_hash_table_list to
2614 * traverse the table. Each entry in the hash table is one added
2615 * SilcAttributePayload. It is possible to delete a attribute
2616 * payload while traversing the table.
2619 const SilcHashTable silc_client_attributes_get(SilcClient client,
2620 SilcClientConnection conn);
2622 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2626 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2630 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2631 * then all attributes are requested. Alternatively, `attribute' and
2632 * all variable arguments can each be requested attribute. In this case
2633 * the last must be set to zero (0) to complete the variable list of
2634 * requested attributes. See SilcAttribute for all attributes.
2635 * You can give the returned buffer as argument to for example
2636 * silc_client_get_client_by_id_resolve function.
2640 * Request all attributes
2641 * buffer = silc_client_attributes_request(0);
2643 * Request only the following attributes
2644 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2645 * SILC_ATTRIBUTE_SERVICE,
2646 * SILC_ATTRIBUTE_MOOD, 0);
2649 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2651 /* Low level packet sending functions */
2653 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2657 * bool silc_client_send_packet(SilcClient client,
2658 * SilcClientConnection conn,
2659 * SilcPacketType type,
2660 * const unsigned char *data,
2661 * SilcUInt32 data_len);
2665 * This routine can be used by application to send packets directly
2666 * to a connection indicated by `conn'. Usually application does not
2667 * need this routine since the Client Library handles the packet
2668 * sending. The `type' indicates the packet type. If `data' is
2669 * NULL then empty packet is sent. This returns FALSE if packet cannot
2673 bool silc_client_send_packet(SilcClient client,
2674 SilcClientConnection conn,
2675 SilcPacketType type,
2676 const unsigned char *data,
2677 SilcUInt32 data_len);
2679 #include "command.h"
2680 #include "command_reply.h"
2682 #include "protocol.h"
2688 #endif /* SILCCLIENT_H */