5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
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 /* User data context. Library does not touch this. Application may
157 freely set and use this pointer for its needs. */
160 /* Pointer back to the SilcClient. Application may use this. */
163 /* Current channel. Application may use and set this pointer if needed. */
164 SilcChannelEntry current_channel;
166 /* Socket connection object for this connection. Application may
167 use this if needed. The sock->user_data is back pointer to this
169 SilcSocketConnection sock;
171 /* Current command identifier, 0 not used */
172 SilcUInt16 cmd_ident;
174 /* Internal data for client library. Application cannot access this
176 SilcClientConnectionInternal internal;
180 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
184 * typedef enum { ... } SilcKeyAgreementStatus;
188 * Key agreement status types indicating the status of the key
189 * agreement protocol. These types are returned to the application
190 * in the SilcKeyAgreementCallback callback function.
195 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
196 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
197 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
198 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
199 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
200 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
201 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
202 } SilcKeyAgreementStatus;
205 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
209 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
210 * SilcClientConnection conn,
211 * SilcClientEntry client_entry,
212 * SilcKeyAgreementStatus status,
213 * SilcSKEKeyMaterial *key,
218 * Key agreement callback that is called after the key agreement protocol
219 * has been performed. This is called also if error occurred during the
220 * key agreement protocol. The `key' is the allocated key material and
221 * the caller is responsible of freeing it. The `key' is NULL if error
222 * has occurred. The application can freely use the `key' to whatever
223 * purpose it needs. See lib/silcske/silcske.h for the definition of
224 * the SilcSKEKeyMaterial structure.
227 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
228 SilcClientConnection conn,
229 SilcClientEntry client_entry,
230 SilcKeyAgreementStatus status,
231 SilcSKEKeyMaterial *key,
234 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
238 * typedef struct { ... } SilcPrivateMessageKeys;
242 * Structure to hold the list of private message keys. The array of this
243 * structure is returned by the silc_client_list_private_message_keys
249 SilcClientEntry client_entry; /* The remote client entry */
250 char *cipher; /* The cipher name */
251 unsigned char *key; /* The original key, If the appliation
252 provided it. This is NULL if the
253 library generated the key or if
254 the SKE key material was used. */
255 SilcUInt32 key_len; /* The key length */
256 } *SilcPrivateMessageKeys;
259 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
263 * typedef struct { ... } SilcChannelPrivateKey;
267 * Structure to hold one channel private key. The array of this structure
268 * is returned by silc_client_list_channel_private_keys function.
272 typedef struct SilcChannelPrivateKeyStruct {
273 char *name; /* Application given name */
274 SilcCipher cipher; /* The cipher and key */
275 SilcHmac hmac; /* The HMAC and hmac key */
276 unsigned char *key; /* The key data */
277 SilcUInt32 key_len; /* The key length */
278 } *SilcChannelPrivateKey;
281 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
285 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
286 * SilcUInt32 passphrase_len,
291 * Ask passphrase callback. This is called by the application when the
292 * library calls `ask_passphrase' client operation. The callback delivers
293 * the passphrase to the library. The passphrases in SILC protocol
294 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
295 * encoded, and if it is not then library will attempt to encode it.
298 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
299 SilcUInt32 passphrase_len,
302 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
306 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
310 * Public key (or certificate) verification callback. This is called
311 * by the application to indicate that the public key verification was
312 * either success or failure.
315 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
317 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
321 * typedef void (*SilcGetAuthMeth)(bool success,
322 * SilcProtocolAuthMeth auth_meth,
323 * const unsigned char *auth_data,
324 * SilcUInt32 auth_data_len, void *context);
328 * Authentication method resolving callback. This is called by the
329 * application to return the resolved authentication method. The client
330 * library has called the get_auth_method client operation and given
331 * this function pointer as argument. The `success' will indicate whether
332 * the authentication method could be resolved. The `auth_meth' is the
333 * resolved authentication method. The `auth_data' and the `auth_data_len'
334 * are the resolved authentication data. The `context' is the libary's
335 * context sent to the get_auth_method client operation.
338 typedef void (*SilcGetAuthMeth)(bool success,
339 SilcProtocolAuthMeth auth_meth,
340 const unsigned char *auth_data,
341 SilcUInt32 auth_data_len, void *context);
343 /****d* silcclient/SilcClientAPI/SilcClientMessageType
347 * typedef enum { ... } SilcClientMessageType;
351 * Different message types for `say' client operation. The application
352 * may filter the message sent by the library according this type.
357 SILC_CLIENT_MESSAGE_INFO, /* Informational */
358 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
359 SILC_CLIENT_MESSAGE_ERROR, /* Error */
360 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
361 } SilcClientMessageType;
364 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
368 * typedef enum { ... } SilcClientConnectionStatus
372 * This type is returned to the `connect' client operation to indicate
373 * the status of the created connection. It can indicated if it was
374 * successful or whether an error occurred.
379 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
380 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
381 resumed old detached session */
382 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
383 } SilcClientConnectionStatus;
386 /****s* silcclient/SilcClientAPI/SilcClientOperations
390 * typedef struct { ... } SilcClientOperations;
394 * SILC Client Operations. These must be implemented by the application.
395 * The Client library may call any of these routines at any time. The
396 * routines are used to deliver certain information to the application
397 * or from the application to the client library.
402 /* Message sent to the application by library. `conn' associates the
403 message to a specific connection. `conn', however, may be NULL.
404 The `type' indicates the type of the message sent by the library.
405 The application can for example filter the message according the
407 void (*say)(SilcClient client, SilcClientConnection conn,
408 SilcClientMessageType type, char *msg, ...);
410 /* Message for a channel. The `sender' is the sender of the message
411 The `channel' is the channel. The `message' is the message. Note
412 that `message' maybe NULL. The `flags' indicates message flags
413 and it is used to determine how the message can be interpreted
414 (like it may tell the message is multimedia message). */
415 void (*channel_message)(SilcClient client, SilcClientConnection conn,
416 SilcClientEntry sender, SilcChannelEntry channel,
417 SilcMessageFlags flags,
418 const unsigned char *message,
419 SilcUInt32 message_len);
421 /* Private message to the client. The `sender' is the sender of the
422 message. The message is `message'and maybe NULL. The `flags'
423 indicates message flags and it is used to determine how the message
424 can be interpreted (like it may tell the message is multimedia
426 void (*private_message)(SilcClient client, SilcClientConnection conn,
427 SilcClientEntry sender, SilcMessageFlags flags,
428 const unsigned char *message,
429 SilcUInt32 message_len);
431 /* Notify message to the client. The notify arguments are sent in the
432 same order as servers sends them. The arguments are same as received
433 from the server except for ID's. If ID is received application receives
434 the corresponding entry to the ID. For example, if Client ID is received
435 application receives SilcClientEntry. Also, if the notify type is
436 for channel the channel entry is sent to application (even if server
437 does not send it because client library gets the channel entry from
438 the Channel ID in the packet's header). */
439 void (*notify)(SilcClient client, SilcClientConnection conn,
440 SilcNotifyType type, ...);
442 /* Command handler. This function is called always in the command function.
443 If error occurs it will be called as well. `conn' is the associated
444 client connection. `cmd_context' is the command context that was
445 originally sent to the command. `success' is FALSE if error occurred
446 during command. `command' is the command being processed. It must be
447 noted that this is not reply from server. This is merely called just
448 after application has called the command. Just to tell application
449 that the command really was processed. */
450 void (*command)(SilcClient client, SilcClientConnection conn,
451 SilcClientCommandContext cmd_context, bool success,
452 SilcCommand command, SilcStatus status);
454 /* Command reply handler. This function is called always in the command reply
455 function. If error occurs it will be called as well. Normal scenario
456 is that it will be called after the received command data has been parsed
457 and processed. The function is used to pass the received command data to
460 `conn' is the associated client connection. `cmd_payload' is the command
461 payload data received from server and it can be ignored. It is provided
462 if the application would like to re-parse the received command data,
463 however, it must be noted that the data is parsed already by the library
464 thus the payload can be ignored. `success' is FALSE if error occurred.
465 In this case arguments are not sent to the application. The `status' is
466 the command reply status server returned. The `command' is the command
467 reply being processed. The function has variable argument list and each
468 command defines the number and type of arguments it passes to the
469 application (on error they are not sent).
471 The arguments are sent in the same order as servers sends them. The
472 arguments are same as received from the server except for ID's. If
473 ID is received application receives the corresponding entry to the
474 ID. For example, if Client ID is receives application receives
476 void (*command_reply)(SilcClient client, SilcClientConnection conn,
477 SilcCommandPayload cmd_payload, bool success,
478 SilcCommand command, SilcStatus status, ...);
480 /* Called to indicate that connection was either successfully established
481 or connecting failed. This is also the first time application receives
482 the SilcClientConnection object which it should save somewhere.
483 The `status' indicated whether the connection were successful. If it
484 is error value the application must always call the function
485 silc_client_close_connection. */
486 void (*connected)(SilcClient client, SilcClientConnection conn,
487 SilcClientConnectionStatus status);
489 /* Called to indicate that connection was disconnected to the server.
490 The `status' may tell the reason of the disconnection, and if the
491 `message' is non-NULL it may include the disconnection message
492 received from server. */
493 void (*disconnected)(SilcClient client, SilcClientConnection conn,
494 SilcStatus status, const char *message);
496 /* Find authentication method and authentication data by hostname and
497 port. The hostname may be IP address as well. When the authentication
498 method has been resolved the `completion' callback with the found
499 authentication method and authentication data is called. The `conn'
501 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
502 char *hostname, SilcUInt16 port,
503 SilcGetAuthMeth completion, void *context);
505 /* Verifies received public key. The `conn_type' indicates which entity
506 (server, client etc.) has sent the public key. If user decides to trust
507 the application may save the key as trusted public key for later
508 use. The `completion' must be called after the public key has been
510 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
511 SilcSocketType conn_type, unsigned char *pk,
512 SilcUInt32 pk_len, SilcSKEPKType pk_type,
513 SilcVerifyPublicKey completion, void *context);
515 /* Ask (interact, that is) a passphrase from user. The passphrase is
516 returned to the library by calling the `completion' callback with
517 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
518 if not then the library will attempt to encode. */
519 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
520 SilcAskPassphrase completion, void *context);
522 /* Notifies application that failure packet was received. This is called
523 if there is some protocol active in the client. The `protocol' is the
524 protocol context. The `failure' is opaque pointer to the failure
525 indication. Note, that the `failure' is protocol dependant and
526 application must explicitly cast it to correct type. Usually `failure'
527 is 32 bit failure type (see protocol specs for all protocol failure
529 void (*failure)(SilcClient client, SilcClientConnection conn,
530 SilcProtocol protocol, void *failure);
532 /* Asks whether the user would like to perform the key agreement protocol.
533 This is called after we have received an key agreement packet or an
534 reply to our key agreement packet. This returns TRUE if the user wants
535 the library to perform the key agreement protocol and FALSE if it is not
536 desired (application may start it later by calling the function
537 silc_client_perform_key_agreement). If TRUE is returned also the
538 `completion' and `context' arguments must be set by the application. */
539 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
540 SilcClientEntry client_entry, const char *hostname,
541 SilcUInt16 port, SilcKeyAgreementCallback *completion,
544 /* Notifies application that file transfer protocol session is being
545 requested by the remote client indicated by the `client_entry' from
546 the `hostname' and `port'. The `session_id' is the file transfer
547 session and it can be used to either accept or reject the file
548 transfer request, by calling the silc_client_file_receive or
549 silc_client_file_close, respectively. */
550 void (*ftp)(SilcClient client, SilcClientConnection conn,
551 SilcClientEntry client_entry, SilcUInt32 session_id,
552 const char *hostname, SilcUInt16 port);
554 /* Delivers SILC session detachment data indicated by `detach_data' to the
555 application. If application has issued SILC_COMMAND_DETACH command
556 the client session in the SILC network is not quit. The client remains
557 in the network but is detached. The detachment data may be used later
558 to resume the session in the SILC Network. The appliation is
559 responsible of saving the `detach_data', to for example in a file.
561 The detachment data can be given as argument to the functions
562 silc_client_connect_to_server, or silc_client_add_connection when
563 creating connection to remote server, inside SilcClientConnectionParams
564 structure. If it is provided the client library will attempt to resume
565 the session in the network. After the connection is created
566 successfully, the application is responsible of setting the user
567 interface for user into the same state it was before detaching (showing
568 same channels, channel modes, etc). It can do this by fetching the
569 information (like joined channels) from the client library. */
570 void (*detach)(SilcClient client, SilcClientConnection conn,
571 const unsigned char *detach_data,
572 SilcUInt32 detach_data_len);
573 } SilcClientOperations;
576 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
580 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
581 * char **ret_nickname);
585 * A callback function provided by the application for the library in
586 * SilcClientParams structure. This function parses the formatted
587 * nickname string `nickname' and returns the true nickname to the
588 * `ret_nickname' pointer. The library can call this function at
592 typedef void (*SilcNicknameFormatParse)(const char *nickname,
593 char **ret_nickname);
595 /****s* silcclient/SilcClientAPI/SilcClientParams
599 * typedef struct { ... } SilcClientParams;
603 * Client parameters. This can be filled with proper values and
604 * given as argument to the silc_client_alloc function. The structure
605 * hold various parameters which affects the function of the client.
610 /* Number of maximum tasks the client library's scheduler can handle.
611 If set to zero, the default value will be used (200). For WIN32
612 systems this should be set to 64 as it is the hard limit dictated
616 /* Rekey timeout in seconds. The client will perform rekey in this
617 time interval. If set to zero, the default value will be used. */
618 unsigned int rekey_secs;
620 /* Connection authentication method request timeout. If server does not
621 reply back the current authentication method when we've requested it
622 in this time interval we'll assume the reply will not come at all.
623 If set to zero, the default value (2 seconds) will be used. */
624 unsigned int connauth_request_secs;
626 /* Nickname format string. This can be used to order the client library
627 to save the nicknames in the library in a certain format. Since
628 nicknames are not unique in SILC it is possible to have multiple same
629 nicknames. Using this format string it is possible to order the library
630 to separate the multiple same nicknames from each other. The format
631 types are defined below and they can appear in any order in the format
632 string. If this is NULL then default format is used which is the
633 default nickname without anything else. The string MUST be NULL
636 Following format types are available:
638 %n nickname - the real nickname returned by the server (mandatory)
639 %h hostname - the stripped hostname of the client
640 %H full hostname - the full hostname of the client
641 %s server name - the server name the client is connected
642 %S full server - the full server name the client is connected
643 %a number - ascending number in case there are several
644 same nicknames (fe. nick@host and nick@host2)
646 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
647 "%a!%n@%s" (fe. nick@server, 2!nick@server)
648 "%n@%H" (fe. nick@host.domain.com)
650 By default this format is employed to the nicknames by the libary
651 only when there appears multiple same nicknames. If the library has
652 only one nickname cached the nickname is saved as is and without the
653 defined format. If you want always to save the nickname in the defined
654 format set the boolean field `nickname_force_format' to value TRUE.
656 char nickname_format[32];
658 /* If this is set to TRUE then the `nickname_format' is employed to all
659 saved nicknames even if there are no multiple same nicknames in the
660 cache. By default this is FALSE, which means that the `nickname_format'
661 is employed only if the library will receive a nickname that is
662 already saved in the cache. It is recommended to leave this to FALSE
664 bool nickname_force_format;
666 /* A callback function provided by the application for the library to
667 parse the nickname from the formatted nickname string. Even though
668 the libary formats the nicknames the application knows generally the
669 format better so this function should be provided for the library
670 if the application sets the `nickname_format' field. The library
671 will call this to get the true nickname from the provided formatted
672 nickname string whenever it needs the true nickname. */
673 SilcNicknameFormatParse nickname_parse;
675 /* If this is set to TRUE then the client will ignore all incoming
676 Requested Attributes queries and does not reply anything back. This
677 usually leads into situation where server does not anymore send
678 the queries after seeing that client does not reply anything back.
679 If your application does not support Requested Attributes or you do
680 not want to use them set this to TRUE. See SilcAttribute and
681 silc_client_attribute_add for more information on attributes. */
682 bool ignore_requested_attributes;
688 /* Initialization functions (client.c) */
690 /****f* silcclient/SilcClientAPI/silc_client_alloc
694 * SilcClient silc_client_alloc(SilcClientOperations *ops,
695 * SilcClientParams *params,
697 * const char *silc_version);
701 * Allocates new client object. This has to be done before client may
702 * work. After calling this one must call silc_client_init to initialize
703 * the client. The `application' is application specific user data pointer
704 * and caller must free it. The `silc_version' is the application version
705 * that will be used to compare against remote host's (usually a server)
706 * version string. The `application' context is accessible by the
707 * application by client->application, client being SilcClient.
710 SilcClient silc_client_alloc(SilcClientOperations *ops,
711 SilcClientParams *params,
713 const char *version_string);
715 /****f* silcclient/SilcClientAPI/silc_client_free
719 * void silc_client_free(SilcClient client);
723 * Frees client object and its internals. The execution of the client
724 * should be stopped with silc_client_stop function before calling
728 void silc_client_free(SilcClient client);
730 /****f* silcclient/SilcClientAPI/silc_client_init
734 * int silc_client_init(SilcClient client);
738 * Initializes the client. This makes all the necessary steps to make
739 * the client ready to be run. One must call silc_client_run to run the
740 * client. Returns FALSE if error occurred, TRUE otherwise.
743 int silc_client_init(SilcClient client);
745 /****f* silcclient/SilcClientAPI/silc_client_run
749 * void silc_client_run(SilcClient client);
753 * Runs the client. This starts the scheduler from the utility library.
754 * When this functions returns the execution of the appliation is over.
755 * The client must be initialized before calling this.
758 void silc_client_run(SilcClient client);
760 /****f* silcclient/SilcClientAPI/silc_client_run_one
764 * void silc_client_run_one(SilcClient client);
768 * Runs the client and returns immeadiately. This function is used when
769 * the SILC Client object indicated by the `client' is run under some
770 * other scheduler, or event loop or main loop. On GUI applications,
771 * for example this may be desired to used to run the client under the
772 * GUI application's main loop. Typically the GUI application would
773 * register an idle task that calls this function multiple times in
774 * a second to quickly process the SILC specific data.
777 void silc_client_run_one(SilcClient client);
779 /****f* silcclient/SilcClientAPI/silc_client_stop
783 * void silc_client_stop(SilcClient client);
787 * Stops the client. This is called to stop the client and thus to stop
788 * the program. The client context must be freed with the silc_client_free
792 void silc_client_stop(SilcClient client);
795 /* Connecting functions (client.c) */
797 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
801 * typedef struct { ... } SilcClientConnectionParams;
805 * Client connection parameters. This can be filled by the application
806 * and given as argument to silc_client_connect_to_server or to
807 * silc_client_add_connection.
812 /* The SILC session detachment data that was returned by `detach' client
813 operation when the application detached from the network. Application
814 is responsible of saving the data and giving it as argument here
815 for resuming the session in the SILC network.
817 If this is provided here the client library will attempt to resume
818 the session in the network. After the connection is created
819 successfully, the application is responsible of setting the user
820 interface for user into the same state it was before detaching (showing
821 same channels, channel modes, etc). It can do this by fetching the
822 information (like joined channels) from the client library. */
823 unsigned char *detach_data;
824 SilcUInt32 detach_data_len;
826 } SilcClientConnectionParams;
829 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
833 * int silc_client_connect_to_server(SilcClient client,
834 * SilcClientConnectionParams *params,
835 * int port, char *host, void *context);
839 * Connects to remote server. This is the main routine used to connect
840 * to SILC server. Returns -1 on error and the created socket otherwise.
841 * The `context' is user context that is saved into the SilcClientConnection
842 * that is created after the connection is created. Note that application
843 * may handle the connecting process outside the library. If this is the
844 * case then this function is not used at all. When the connecting is
845 * done the `connect' client operation is called, and the `context' is
846 * accessible with conn->context, conn being SilcClientConnection.
847 * If the `params' is provided they are used by the routine.
850 int silc_client_connect_to_server(SilcClient client,
851 SilcClientConnectionParams *params,
852 int port, char *host, void *context);
854 /****f* silcclient/SilcClientAPI/silc_client_add_connection
859 * SilcClientConnection
860 * silc_client_add_connection(SilcClient client,
861 * SilcClientConnectionParams *params,
862 * char *hostname, int port, void *context);
866 * Allocates and adds new connection to the client. This adds the allocated
867 * connection to the connection table and returns a pointer to it. A client
868 * can have multiple connections to multiple servers. Every connection must
869 * be added to the client using this function. User data `context' may
870 * be sent as argument. If the `params' is provided they are used by
875 * This function is normally used only if the application performed
876 * the connecting outside the library, and did not called the
877 * silc_client_connect_to_server function at all. The library
878 * however may use this internally.
882 silc_client_add_connection(SilcClient client,
883 SilcClientConnectionParams *params,
884 char *hostname, int port, void *context);
886 /****f* silcclient/SilcClientAPI/silc_client_del_connection
890 * void silc_client_del_connection(SilcClient client,
891 * SilcClientConnection conn);
895 * Removes connection from client. Frees all memory. The library
896 * call this function automatically for all connection contexts.
897 * The application however may free the connection contexts it has
901 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
903 /****f* silcclient/SilcClientAPI/silc_client_add_socket
907 * void silc_client_add_socket(SilcClient client,
908 * SilcSocketConnection sock);
912 * Adds listener socket to the listener sockets table. This function is
913 * used to add socket objects that are listeners to the client. This should
914 * not be used to add other connection objects.
917 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
919 /****f* silcclient/SilcClientAPI/silc_client_del_socket
923 * void silc_client_del_socket(SilcClient client,
924 * SilcSocketConnection sock);
928 * Deletes listener socket from the listener sockets table. If the
929 * application has added a socket with silc_client_add_socket it must
930 * also free it using this function.
933 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
935 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
939 * void silc_client_start_key_exchange(SilcClient client,
940 * SilcClientConnection conn,
945 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
946 * key material between client and server. This function can be called
947 * directly if application is performing its own connecting and does not
948 * use the connecting provided by this library. This function is normally
949 * used only if the application performed the connecting outside the
950 * library. The library however may use this internally. After the
951 * key exchange is performed the `connect' client operation is called.
954 void silc_client_start_key_exchange(SilcClient client,
955 SilcClientConnection conn,
958 /****f* silcclient/SilcClientAPI/silc_client_close_connection
962 * void silc_client_close_connection(SilcClient client,
963 * SilcClientConnection conn);
967 * Closes connection to remote end. Free's all allocated data except
968 * for some information such as nickname etc. that are valid at all time.
971 void silc_client_close_connection(SilcClient client,
972 SilcClientConnection conn);
975 /* Message sending functions (client_channel.c and client_prvmsg.c) */
977 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
981 * void silc_client_send_channel_message(SilcClient client,
982 * SilcClientConnection conn,
983 * SilcChannelEntry channel,
984 * SilcChannelPrivateKey key,
985 * SilcMessageFlags flags,
986 * unsigned char *data,
987 * SilcUInt32 data_len,
992 * Sends packet to the `channel'. Packet to channel is always encrypted
993 * differently from "normal" packets. SILC header of the packet is
994 * encrypted with the next receiver's key and the rest of the packet is
995 * encrypted with the channel specific key. Padding and HMAC is computed
996 * with the next receiver's key. The `data' is the channel message. If
997 * the `force_send' is TRUE then the packet is sent immediately.
999 * If `key' is provided then that private key is used to encrypt the
1000 * channel message. If it is not provided, private keys has not been
1001 * set at all, the normal channel key is used automatically. If private
1002 * keys are set then the first key (the key that was added first as
1003 * private key) is used.
1006 void silc_client_send_channel_message(SilcClient client,
1007 SilcClientConnection conn,
1008 SilcChannelEntry channel,
1009 SilcChannelPrivateKey key,
1010 SilcMessageFlags flags,
1011 unsigned char *data,
1012 SilcUInt32 data_len,
1015 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1019 * void silc_client_send_private_message(SilcClient client,
1020 * SilcClientConnection conn,
1021 * SilcClientEntry client_entry,
1022 * SilcMessageFlags flags,
1023 * unsigned char *data,
1024 * SilcUInt32 data_len,
1029 * Sends private message to remote client. If private message key has
1030 * not been set with this client then the message will be encrypted using
1031 * normal session keys. Private messages are special packets in SILC
1032 * network hence we need this own function for them. This is similar
1033 * to silc_client_packet_send_to_channel except that we send private
1034 * message. The `data' is the private message. If the `force_send' is
1035 * TRUE the packet is sent immediately.
1038 void silc_client_send_private_message(SilcClient client,
1039 SilcClientConnection conn,
1040 SilcClientEntry client_entry,
1041 SilcMessageFlags flags,
1042 unsigned char *data,
1043 SilcUInt32 data_len,
1047 /* Client and Channel entry retrieval (idlist.c) */
1049 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1053 * typedef void (*SilcGetClientCallback)(SilcClient client,
1054 * SilcClientConnection conn,
1055 * SilcClientEntry *clients,
1056 * SilcUInt32 clients_count,
1061 * Callback function given to the silc_client_get_client function. The
1062 * found entries are allocated into the `clients' array. The array must
1063 * not be freed by the receiver, the library will free it later. If the
1064 * `clients' is NULL, no such clients exist in the SILC Network.
1067 typedef void (*SilcGetClientCallback)(SilcClient client,
1068 SilcClientConnection conn,
1069 SilcClientEntry *clients,
1070 SilcUInt32 clients_count,
1073 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1077 * void silc_client_get_clients(SilcClient client,
1078 * SilcClientConnection conn,
1079 * const char *nickname,
1080 * const char *server,
1081 * SilcGetClientCallback completion,
1086 * Finds client entry or entries by the `nickname' and `server'. The
1087 * completion callback will be called when the client entries has been
1088 * found. After the server returns the client information it is cached
1089 * and can be accesses locally at a later time.
1093 * NOTE: This function is always asynchronous and resolves the client
1094 * information from the server. Thus, if you already know the client
1095 * information then use the silc_client_get_client_by_id function to
1096 * get the client entry since this function may be very slow and should
1097 * be used only to initially get the client entries.
1100 void silc_client_get_clients(SilcClient client,
1101 SilcClientConnection conn,
1102 const char *nickname,
1104 SilcGetClientCallback completion,
1107 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1111 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1112 * SilcClientConnection conn,
1113 * const char *nickname,
1114 * const char *format,
1115 * SilcUInt32 *clients_count);
1119 * Same as silc_client_get_clients function but does not resolve anything
1120 * from the server. This checks local cache and returns all matching
1121 * clients from the local cache. If none was found this returns NULL.
1122 * The `nickname' is the real nickname of the client, and the `format'
1123 * is the formatted nickname to find exact match from multiple found
1124 * entries. The format must be same as given in the SilcClientParams
1125 * structure to the client library. If the `format' is NULL all found
1126 * clients by `nickname' are returned. The caller must return the
1130 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1131 SilcClientConnection conn,
1132 const char *nickname,
1134 SilcUInt32 *clients_count);
1136 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1140 * void silc_client_get_clients_by_list(SilcClient client,
1141 * SilcClientConnection conn,
1142 * SilcUInt32 list_count,
1143 * SilcBuffer client_id_list,
1144 * SilcGetClientCallback completion,
1149 * Gets client entries by the list of client ID's `client_id_list'. This
1150 * always resolves those client ID's it does not know yet from the server
1151 * so this function might take a while. The `client_id_list' is a list
1152 * of ID Payloads added one after other. JOIN command reply and USERS
1153 * command reply for example returns this sort of list. The `completion'
1154 * will be called after the entries are available. When server returns
1155 * the client information it will be cached and can be accessed locally
1159 void silc_client_get_clients_by_list(SilcClient client,
1160 SilcClientConnection conn,
1161 SilcUInt32 list_count,
1162 SilcBuffer client_id_list,
1163 SilcGetClientCallback completion,
1166 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1170 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1171 * SilcClientConnection conn,
1172 * SilcClientID *client_id);
1176 * Find entry for client by the client's ID. Returns the entry or NULL
1177 * if the entry was not found. This checks the local cache and does
1178 * not resolve anything from server.
1181 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1182 SilcClientConnection conn,
1183 SilcClientID *client_id);
1185 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1190 * silc_client_get_client_by_id_resolve(SilcClient client,
1191 * SilcClientConnection conn,
1192 * SilcClientID *client_id,
1193 * SilcBuffer attributes,
1194 * SilcGetClientCallback completion,
1199 * Same as silc_client_get_client_by_id but will always resolve the
1200 * information from the server. Use this only if you know that you
1201 * do not have the entry and the only thing you know about the client
1202 * is its ID. When server returns the client information it will be
1203 * cache and can be accessed locally at a later time.
1205 * If the `attributes' is non-NULL then the buffer includes Requested
1206 * Attributes which can be used to fetch very detailed information
1207 * about the user. If it is NULL then only normal WHOIS query is
1208 * made (for more information about attributes see SilcAttribute).
1209 * Caller may create the `attributes' with silc_client_attributes_request
1213 void silc_client_get_client_by_id_resolve(SilcClient client,
1214 SilcClientConnection conn,
1215 SilcClientID *client_id,
1216 SilcBuffer attributes,
1217 SilcGetClientCallback completion,
1220 /****f* silcclient/SilcClientAPI/silc_client_del_client
1224 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1225 * SilcClientEntry client_entry)
1229 * Removes client from local cache by the client entry indicated by
1230 * the `client_entry'. Returns TRUE if the deletion were successful.
1233 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1234 SilcClientEntry client_entry);
1236 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1240 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1241 * SilcClientConnection conn,
1242 * SilcChannelEntry *channels,
1243 * SilcUInt32 channels_count,
1248 * Callback function given to the silc_client_get_channel_* functions.
1249 * The found entries are allocated into the `channels' array. The array
1250 * must not be freed by the receiver, the library will free it later.
1251 * If the `channel' is NULL, no such channel exist in the SILC Network.
1254 typedef void (*SilcGetChannelCallback)(SilcClient client,
1255 SilcClientConnection conn,
1256 SilcChannelEntry *channels,
1257 SilcUInt32 channels_count,
1260 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1264 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1265 * SilcClientConnection conn,
1270 * Finds entry for channel by the channel name. Returns the entry or NULL
1271 * if the entry was not found. It is found only if the client is joined
1275 SilcChannelEntry silc_client_get_channel(SilcClient client,
1276 SilcClientConnection conn,
1279 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1284 * silc_client_get_channel_by_id(SilcClient client,
1285 * SilcClientConnection conn,
1286 * SilcChannelID *channel_id);
1290 * Finds channel entry by the channel name. Returns the entry or NULL
1291 * if it was not found.
1294 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1295 SilcClientConnection conn,
1296 SilcChannelID *channel_id);
1298 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1303 * silc_client_get_channel_by_id_resolve(SilcClient client,
1304 * SilcClientConnection conn,
1305 * SilcChannelID *channel_id,
1306 * SilcGetClientCallback completion,
1311 * Resolves the channel information (its name mainly) from the server
1312 * by the `channel_id'. Use this only if you know that you do not have
1313 * the entry cached locally.
1316 void silc_client_get_channel_by_id_resolve(SilcClient client,
1317 SilcClientConnection conn,
1318 SilcChannelID *channel_id,
1319 SilcGetChannelCallback completion,
1322 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1326 * bool silc_client_del_channel(SilcClient client,
1327 * SilcClientConnection conn,
1328 * SilcChannelEntry channel)
1332 * Removes channel from local cache by the channel entry indicated by
1333 * the `channel'. Returns TRUE if the deletion were successful.
1336 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1337 SilcChannelEntry channel);
1339 /****f* silcclient/SilcClientAPI/silc_client_get_server
1343 * SilcServerEntry silc_client_get_server(SilcClient client,
1344 * SilcClientConnection conn,
1345 * char *server_name)
1349 * Finds entry for server by the server name. Returns the entry or NULL
1350 * if the entry was not found.
1353 SilcServerEntry silc_client_get_server(SilcClient client,
1354 SilcClientConnection conn,
1357 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1361 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1362 * SilcClientConnection conn,
1363 * SilcServerID *server_id);
1367 * Finds entry for server by the server ID. Returns the entry or NULL
1368 * if the entry was not found.
1371 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1372 SilcClientConnection conn,
1373 SilcServerID *server_id);
1375 /****f* silcclient/SilcClientAPI/silc_client_del_server
1379 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1380 * SilcServerEntry server);
1384 * Removes server from local cache by the server entry indicated by
1385 * the `server'. Returns TRUE if the deletion were successful.
1388 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1389 SilcServerEntry server);
1391 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1395 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1396 * SilcClientEntry client_entry);
1400 * Returns the ChannelUser entry if the `client_entry' is joined on the
1401 * channel indicated by the `channel'. NULL if client is not joined on
1405 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1406 SilcClientEntry client_entry);
1408 /* Command management (command.c) */
1410 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1414 * SilcClientCommandContext silc_client_command_alloc(void);
1418 * Allocate Command Context. The context is defined in `command.h' file.
1419 * The context is used by the library commands and applications should use
1420 * it as well. However, application may choose to use some own context
1421 * for its local commands. All library commands, however, must use this
1425 SilcClientCommandContext silc_client_command_alloc(void);
1427 /****f* silcclient/SilcClientAPI/silc_client_command_free
1431 * void silc_client_command_free(SilcClientCommandContext ctx);
1435 * Free command context and its internals. If the contex was duplicated
1436 * with silc_client_command_dup this may not actually free the data,
1437 * instead it will decrease the reference counter of the context. The
1438 * context will be freed when the reference counter hits zero.
1441 void silc_client_command_free(SilcClientCommandContext ctx);
1443 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1447 * SilcClientCommandContext
1448 * silc_client_command_dup(SilcClientCommandContext ctx);
1452 * Duplicate Command Context by adding reference counter. The context won't
1453 * be free'd untill it hits zero.
1456 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1458 /****f* silcclient/SilcClientAPI/silc_client_command_find
1462 * SilcClientCommand silc_client_command_find(SilcClient client,
1463 * const char *name);
1467 * Finds and returns a pointer to the command list. Return NULL if the
1468 * command is not found. See the `command.[ch]' for the command list.
1469 * Command names are not case-sensitive.
1472 SilcClientCommand silc_client_command_find(SilcClient client,
1475 /****f* silcclient/SilcClientAPI/silc_client_command_call
1479 * void silc_client_command_call(SilcClientCommand command);
1483 * Calls the command (executes it). Application can call this after
1484 * it has allocated the SilcClientCommandContext with the function
1485 * silc_client_command_alloc and found the command from the client
1486 * library by calling silc_client_command_find. This will execute
1489 * Application can call the command function directly too if it
1490 * wishes to do so. See the command.h for details of the
1491 * SilcClientCommand structure.
1494 void silc_client_command_call(SilcClientCommand command,
1495 SilcClientCommandContext cmd);
1497 /****f* silcclient/SilcClientAPI/silc_client_command_send
1501 * void silc_client_command_send(SilcClient client,
1502 * SilcClientConnection conn,
1503 * SilcCommand command, SilcUInt16 ident,
1504 * SilcUInt32 argc, ...);
1508 * Generic function to send any command. The arguments must be sent already
1509 * encoded into correct form and in correct order. If application wants
1510 * to perform the commands by itself, it can do so and send the data
1511 * directly to the server using this function. If application is using
1512 * the silc_client_command_call, this function is usually not used.
1514 * The variable arguments are a pair of { type, data, data_length },
1515 * and the `argc' is the number of these pairs.
1519 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1520 * 1, nickname, strlen(nickname));
1523 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1524 SilcCommand command, SilcUInt16 ident,
1525 SilcUInt32 argc, ...);
1527 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1531 * void silc_client_command_pending(SilcClientConnection conn,
1532 * SilcCommand reply_cmd,
1534 * SilcCommandCb callback,
1539 * Add new pending command to be executed when reply to a command has been
1540 * received. The `reply_cmd' is the command that will call the `callback'
1541 * with `context' when reply has been received. If `ident' is non-zero
1542 * the `callback' will be executed when received reply with command
1543 * identifier `ident'.
1545 * Note that the application is notified about the received command
1546 * reply through the `command_reply' client operation before calling
1547 * the `callback` pending command callback.
1550 void silc_client_command_pending(SilcClientConnection conn,
1551 SilcCommand reply_cmd,
1553 SilcCommandCb callback,
1557 /* Private Message key management (client_prvmsg.c) */
1559 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1563 * int silc_client_add_private_message_key(SilcClient client,
1564 * SilcClientConnection conn,
1565 * SilcClientEntry client_entry,
1567 * unsigned char *key,
1568 * SilcUInt32 key_len,
1569 * bool generate_key,
1574 * Adds private message key to the client library. The key will be used to
1575 * encrypt all private message between the client and the remote client
1576 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1577 * value `generate_key' is TRUE the library will generate random key.
1578 * The `key' maybe for example pre-shared-key, passphrase or similar.
1579 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1580 * requirements of the SILC protocol are met. The API, however, allows
1581 * to allocate any cipher.
1583 * If `responder' is TRUE then the sending and receiving keys will be
1584 * set according the client being the receiver of the private key. If
1585 * FALSE the client is being the sender (or negotiator) of the private
1588 * It is not necessary to set key for normal private message usage. If the
1589 * key is not set then the private messages are encrypted using normal
1590 * session keys. Setting the private key, however, increases the security.
1592 * Returns FALSE if the key is already set for the `client_entry', TRUE
1596 int silc_client_add_private_message_key(SilcClient client,
1597 SilcClientConnection conn,
1598 SilcClientEntry client_entry,
1605 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1609 * int silc_client_add_private_message_key_ske(SilcClient client,
1610 * SilcClientConnection conn,
1611 * SilcClientEntry client_entry,
1613 * SilcSKEKeyMaterial *key);
1617 * Same as silc_client_add_private_message_key but takes the key material
1618 * from the SKE key material structure. This structure is received if
1619 * the application uses the silc_client_send_key_agreement to negotiate
1620 * the key material. The `cipher' SHOULD be provided as it is negotiated
1621 * also in the SKE protocol.
1624 int silc_client_add_private_message_key_ske(SilcClient client,
1625 SilcClientConnection conn,
1626 SilcClientEntry client_entry,
1628 SilcSKEKeyMaterial *key,
1631 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1635 * int silc_client_del_private_message_key(SilcClient client,
1636 * SilcClientConnection conn,
1637 * SilcClientEntry client_entry);
1641 * Removes the private message from the library. The key won't be used
1642 * after this to protect the private messages with the remote `client_entry'
1643 * client. Returns FALSE on error, TRUE otherwise.
1646 int silc_client_del_private_message_key(SilcClient client,
1647 SilcClientConnection conn,
1648 SilcClientEntry client_entry);
1650 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1654 * SilcPrivateMessageKeys
1655 * silc_client_list_private_message_keys(SilcClient client,
1656 * SilcClientConnection conn,
1657 * SilcUInt32 *key_count);
1661 * Returns array of set private message keys associated to the connection
1662 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1663 * count to the `key_count' argument. The array must be freed by the caller
1664 * by calling the silc_client_free_private_message_keys function. Note:
1665 * the keys returned in the array is in raw format. It might not be desired
1666 * to show the keys as is. The application might choose not to show the keys
1667 * at all or to show the fingerprints of the keys.
1670 SilcPrivateMessageKeys
1671 silc_client_list_private_message_keys(SilcClient client,
1672 SilcClientConnection conn,
1673 SilcUInt32 *key_count);
1675 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1679 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1680 * SilcUInt32 key_count);
1684 * Frees the SilcPrivateMessageKeys array returned by the function
1685 * silc_client_list_private_message_keys.
1688 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1689 SilcUInt32 key_count);
1692 /* Channel private key management (client_channel.c,
1693 SilcChannelPrivateKey is defined in idlist.h) */
1695 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1699 * int silc_client_add_channel_private_key(SilcClient client,
1700 * SilcClientConnection conn,
1701 * SilcChannelEntry channel,
1705 * unsigned char *key,
1706 * SilcUInt32 key_len);
1710 * Adds private key for channel. This may be set only if the channel's mode
1711 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1712 * mode is not set. When channel has private key then the messages are
1713 * encrypted using that key. All clients on the channel must also know the
1714 * key in order to decrypt the messages. However, it is possible to have
1715 * several private keys per one channel. In this case only some of the
1716 * clients on the channel may know the one key and only some the other key.
1717 * The `name' can be application given name for the key.
1719 * The private key for channel is optional. If it is not set then the
1720 * channel messages are encrypted using the channel key generated by the
1721 * server. However, setting the private key (or keys) for the channel
1722 * significantly adds security. If more than one key is set the library
1723 * will automatically try all keys at the message decryption phase. Note:
1724 * setting many keys slows down the decryption phase as all keys has to
1725 * be tried in order to find the correct decryption key. However, setting
1726 * a few keys does not have big impact to the decryption performace.
1730 * NOTE: This is entirely local setting. The key set using this function
1731 * is not sent to the network at any phase.
1733 * NOTE: If the key material was originated by the SKE protocol (using
1734 * silc_client_send_key_agreement) then the `key' MUST be the
1735 * key->send_enc_key as this is dictated by the SILC protocol. However,
1736 * currently it is not expected that the SKE key material would be used
1737 * as channel private key. However, this API allows it.
1740 int silc_client_add_channel_private_key(SilcClient client,
1741 SilcClientConnection conn,
1742 SilcChannelEntry channel,
1747 SilcUInt32 key_len);
1749 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1753 * int silc_client_del_channel_private_keys(SilcClient client,
1754 * SilcClientConnection conn,
1755 * SilcChannelEntry channel);
1759 * Removes all private keys from the `channel'. The old channel key is used
1760 * after calling this to protect the channel messages. Returns FALSE on
1761 * on error, TRUE otherwise.
1764 int silc_client_del_channel_private_keys(SilcClient client,
1765 SilcClientConnection conn,
1766 SilcChannelEntry channel);
1768 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1772 * int silc_client_del_channel_private_key(SilcClient client,
1773 * SilcClientConnection conn,
1774 * SilcChannelEntry channel,
1775 * SilcChannelPrivateKey key);
1779 * Removes and frees private key `key' from the channel `channel'.
1780 * The `key' is retrieved by calling the function
1781 * silc_client_list_channel_private_keys. The key is not used after
1782 * this. If the key was last private key then the old channel key is
1783 * used hereafter to protect the channel messages. This returns FALSE
1784 * on error, TRUE otherwise.
1787 int silc_client_del_channel_private_key(SilcClient client,
1788 SilcClientConnection conn,
1789 SilcChannelEntry channel,
1790 SilcChannelPrivateKey key);
1792 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1796 * SilcChannelPrivateKey *
1797 * silc_client_list_channel_private_keys(SilcClient client,
1798 * SilcClientConnection conn,
1799 * SilcChannelEntry channel,
1800 * SilcUInt32 *key_count);
1804 * Returns array (pointers) of private keys associated to the `channel'.
1805 * The caller must free the array by calling the function
1806 * silc_client_free_channel_private_keys. The pointers in the array may be
1807 * used to delete the specific key by giving the pointer as argument to the
1808 * function silc_client_del_channel_private_key.
1811 SilcChannelPrivateKey *
1812 silc_client_list_channel_private_keys(SilcClient client,
1813 SilcClientConnection conn,
1814 SilcChannelEntry channel,
1815 SilcUInt32 *key_count);
1817 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1821 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1822 * SilcUInt32 key_count);
1826 * Frees the SilcChannelPrivateKey array.
1829 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1830 SilcUInt32 key_count);
1832 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1836 * void silc_client_current_channel_private_key(SilcClient client,
1837 * SilcClientConnection conn,
1838 * SilcChannelEntry channel,
1839 * SilcChannelPrivateKey key);
1843 * Sets the `key' to be used as current channel private key on the
1844 * `channel'. Packet sent after calling this function will be secured
1848 void silc_client_current_channel_private_key(SilcClient client,
1849 SilcClientConnection conn,
1850 SilcChannelEntry channel,
1851 SilcChannelPrivateKey key);
1854 /* Key Agreement routines (client_keyagr.c) */
1856 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1860 * void silc_client_send_key_agreement(SilcClient client,
1861 * SilcClientConnection conn,
1862 * SilcClientEntry client_entry,
1865 * SilcUInt32 timeout_secs,
1866 * SilcKeyAgreementCallback completion,
1871 * Sends key agreement request to the remote client indicated by the
1872 * `client_entry'. If the caller provides the `hostname' and the `port'
1873 * arguments then the library will bind the client to that hostname and
1874 * that port for the key agreement protocol. It also sends the `hostname'
1875 * and the `port' in the key agreement packet to the remote client. This
1876 * would indicate that the remote client may initiate the key agreement
1877 * protocol to the `hostname' on the `port'. If port is zero then the
1878 * bound port is undefined (the operating system defines it).
1880 * If the `hostname' and `port' is not provided then empty key agreement
1881 * packet is sent to the remote client. The remote client may reply with
1882 * the same packet including its hostname and port. If the library receives
1883 * the reply from the remote client the `key_agreement' client operation
1884 * callback will be called to verify whether the user wants to perform the
1885 * key agreement or not.
1889 * NOTE: If the application provided the `hostname' and the `port' and the
1890 * remote side initiates the key agreement protocol it is not verified
1891 * from the user anymore whether the protocol should be executed or not.
1892 * By setting the `hostname' and `port' the user gives permission to
1893 * perform the protocol (we are responder in this case).
1895 * NOTE: If the remote side decides not to initiate the key agreement
1896 * or decides not to reply with the key agreement packet then we cannot
1897 * perform the key agreement at all. If the key agreement protocol is
1898 * performed the `completion' callback with the `context' will be called.
1899 * If remote side decides to ignore the request the `completion' will be
1900 * called after the specified timeout, `timeout_secs'.
1902 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1903 * will not be called at all since this does nothing more than sending
1904 * a packet to the remote host.
1906 * NOTE: There can be only one active key agreement for one client entry.
1907 * Before setting new one, the old one must be finished (it is finished
1908 * after calling the completion callback) or the function
1909 * silc_client_abort_key_agreement must be called.
1912 void silc_client_send_key_agreement(SilcClient client,
1913 SilcClientConnection conn,
1914 SilcClientEntry client_entry,
1915 const char *hostname,
1916 const char *bindhost,
1918 SilcUInt32 timeout_secs,
1919 SilcKeyAgreementCallback completion,
1922 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1927 * silc_client_perform_key_agreement(SilcClient client,
1928 * SilcClientConnection conn,
1929 * SilcClientEntry client_entry,
1932 * SilcKeyAgreementCallback completion,
1937 * Performs the actual key agreement protocol. Application may use this
1938 * to initiate the key agreement protocol. This can be called for example
1939 * after the application has received the `key_agreement' client operation,
1940 * and did not return TRUE from it.
1942 * The `hostname' is the remote hostname (or IP address) and the `port'
1943 * is the remote port. The `completion' callback with the `context' will
1944 * be called after the key agreement protocol.
1948 * NOTE: If the application returns TRUE in the `key_agreement' client
1949 * operation the library will automatically start the key agreement. In this
1950 * case the application must not call this function. However, application
1951 * may choose to just ignore the `key_agreement' client operation (and
1952 * merely just print information about it on the screen) and call this
1953 * function when the user whishes to do so (by, for example, giving some
1954 * specific command). Thus, the API provides both, automatic and manual
1955 * initiation of the key agreement. Calling this function is the manual
1956 * initiation and returning TRUE in the `key_agreement' client operation
1957 * is the automatic initiation.
1960 void silc_client_perform_key_agreement(SilcClient client,
1961 SilcClientConnection conn,
1962 SilcClientEntry client_entry,
1965 SilcKeyAgreementCallback completion,
1968 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1973 * silc_client_perform_key_agreement_fd(SilcClient client,
1974 * SilcClientConnection conn,
1975 * SilcClientEntry client_entry,
1978 * SilcKeyAgreementCallback completion,
1983 * Same as above but application has created already the connection to
1984 * the remote host. The `sock' is the socket to the remote connection.
1985 * Application can use this function if it does not want the client library
1986 * to create the connection.
1989 void silc_client_perform_key_agreement_fd(SilcClient client,
1990 SilcClientConnection conn,
1991 SilcClientEntry client_entry,
1994 SilcKeyAgreementCallback completion,
1997 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2001 * void silc_client_abort_key_agreement(SilcClient client,
2002 * SilcClientConnection conn,
2003 * SilcClientEntry client_entry);
2007 * This function can be called to unbind the hostname and the port for
2008 * the key agreement protocol. However, this function has effect only
2009 * before the key agreement protocol has been performed. After it has
2010 * been performed the library will automatically unbind the port. The
2011 * `client_entry' is the client to which we sent the key agreement
2012 * request. The key agreement completion callback will be called
2013 * with SILC_KEY_AGREEMENT_ABORTED status.
2016 void silc_client_abort_key_agreement(SilcClient client,
2017 SilcClientConnection conn,
2018 SilcClientEntry client_entry);
2021 /* Misc functions */
2023 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2027 * void silc_client_set_away_message(SilcClient client,
2028 * SilcClientConnection conn,
2033 * Sets away `message'. The away message may be set when the client's
2034 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2035 * to anyone who sends private message. The `message' will be sent
2036 * automatically back to the the client who send private message. If
2037 * away message is already set this replaces the old message with the
2038 * new one. If `message' is NULL the old away message is removed.
2039 * The sender may freely free the memory of the `message'.
2042 void silc_client_set_away_message(SilcClient client,
2043 SilcClientConnection conn,
2046 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2050 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2051 * SilcClientConnection conn,
2052 * SilcAuthMethod auth_meth,
2057 * Connection authentication method request callback. This is called
2058 * by the client library after it has received the authentication method
2059 * that the application requested by calling the function
2060 * silc_client_request_authentication_method.
2063 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2064 SilcClientConnection conn,
2065 SilcAuthMethod auth_meth,
2068 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2073 * silc_client_request_authentication_method(SilcClient client,
2074 * SilcClientConnection conn,
2075 * SilcConnectionAuthRequest
2081 * This function can be used to request the current authentication method
2082 * from the server. This may be called when connecting to the server
2083 * and the client library requests the authentication data from the
2084 * application. If the application does not know the current authentication
2085 * method it can request it from the server using this function.
2086 * The `callback' with `context' will be called after the server has
2087 * replied back with the current authentication method.
2091 silc_client_request_authentication_method(SilcClient client,
2092 SilcClientConnection conn,
2093 SilcConnectionAuthRequest callback,
2096 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2100 * typedef enum { ... } SilcClientMonitorStatus;
2104 * File transmission session status types. These will indicate
2105 * the status of the file transmission session.
2110 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2111 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2112 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2113 SILC_CLIENT_FILE_MONITOR_GET,
2114 SILC_CLIENT_FILE_MONITOR_PUT,
2115 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2116 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2117 } SilcClientMonitorStatus;
2120 /****d* silcclient/SilcClientAPI/SilcClientFileError
2124 * typedef enum { ... } SilcClientFileError;
2128 * File transmission error types. These types are returned by
2129 * some of the file transmission functions, and by the monitor
2130 * callback to indicate error.
2135 SILC_CLIENT_FILE_OK,
2136 SILC_CLIENT_FILE_ERROR,
2137 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2138 SILC_CLIENT_FILE_ALREADY_STARTED,
2139 SILC_CLIENT_FILE_NO_SUCH_FILE,
2140 SILC_CLIENT_FILE_PERMISSION_DENIED,
2141 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2142 } SilcClientFileError;
2145 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2149 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2150 * SilcClientConnection conn,
2151 * SilcClientMonitorStatus status,
2152 * SilcClientFileError error,
2153 * SilcUInt64 offset,
2154 * SilcUInt64 filesize,
2155 * SilcClientEntry client_entry,
2156 * SilcUInt32 session_id,
2157 * const char *filepath,
2162 * Monitor callback that is called during the file transmission to
2163 * monitor the transmission process. The `status' indicates the current
2164 * monitoring process. The `error' will indicate the error type
2165 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2166 * currently transmitted amount of total `filesize'. The `client_entry'
2167 * indicates the remote client, and the transmission session ID is the
2168 * `session_id'. The filename being transmitted is indicated by the
2172 typedef void (*SilcClientFileMonitor)(SilcClient client,
2173 SilcClientConnection conn,
2174 SilcClientMonitorStatus status,
2175 SilcClientFileError error,
2177 SilcUInt64 filesize,
2178 SilcClientEntry client_entry,
2179 SilcUInt32 session_id,
2180 const char *filepath,
2183 /****f* silcclient/SilcClientAPI/silc_client_file_send
2187 * SilcClientFileError
2188 * silc_client_file_send(SilcClient client,
2189 * SilcClientConnection conn,
2190 * SilcClientFileMonitor monitor,
2191 * void *monitor_context,
2192 * const char *local_ip,
2193 * SilcUInt32 local_port,
2194 * SilcClientEntry client_entry,
2195 * const char *filepath);
2196 * SilcUInt32 *session_id);
2200 * Sends a file indicated by the `filepath' to the remote client
2201 * indicated by the `client_entry'. This will negotiate a secret key
2202 * with the remote client before actually starting the transmission of
2203 * the file. The `monitor' callback will be called to monitor the
2204 * transmission of the file.
2206 * This returns a file session ID for the file transmission to the
2207 * `session_id' pointer.. It can be used to close the session (and
2208 * abort the file transmission) by calling the silc_client_file_close
2209 * function. The session ID is also returned in the `monitor' callback.
2211 * If the `local_ip' is provided then this will try to bind the
2212 * listener for key exchange protocol to that IP. If `local_port' is
2213 * non-zero that port is used. If `local_ip' is NULL then this will
2214 * automatically attempt to bind it to local IP address of the machine.
2215 * If that fails then this does not bind to any address and port, and
2216 * assume that the remote client will provide the listener for the
2217 * key exchange protocol.
2219 * If error will occur during the file transfer process the error
2220 * status will be returned in the monitor callback. In this case
2221 * the application must call silc_client_file_close to close the
2226 silc_client_file_send(SilcClient client,
2227 SilcClientConnection conn,
2228 SilcClientFileMonitor monitor,
2229 void *monitor_context,
2230 const char *local_ip,
2231 SilcUInt32 local_port,
2232 SilcClientEntry client_entry,
2233 const char *filepath,
2234 SilcUInt32 *session_id);
2236 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2240 * SilcClientFileError
2241 * silc_client_file_receive(SilcClient client,
2242 * SilcClientConnection conn,
2243 * SilcClientFileMonitor monitor,
2244 * void *monitor_context,
2246 * SilcUInt32 session_id);
2250 * Receives a file from a client indicated by the `client_entry'. The
2251 * `session_id' indicates the file transmission session and it has been
2252 * received in the `ftp' client operation function. This will actually
2253 * perform the key agreement protocol with the remote client before
2254 * actually starting the file transmission. The `monitor' callback
2255 * will be called to monitor the transmission. If `path' is non NULL
2256 * the file will be saved into that directory. If NULL the file is
2257 * saved in the current working directory.
2259 * If error will occur during the file transfer process the error
2260 * status will be returned in the monitor callback. In this case
2261 * the application must call silc_client_file_close to close the
2266 silc_client_file_receive(SilcClient client,
2267 SilcClientConnection conn,
2268 SilcClientFileMonitor monitor,
2269 void *monitor_context,
2271 SilcUInt32 session_id);
2273 /****f* silcclient/SilcClientAPI/silc_client_file_close
2277 * SilcClientFileError silc_client_file_close(SilcClient client,
2278 * SilcClientConnection conn,
2279 * SilcUInt32 session_id);
2283 * Closes file transmission session indicated by the `session_id'.
2284 * If file transmission is being conducted it will be aborted
2285 * automatically. This function is also used to close the session
2286 * after successful file transmission. This function can be used
2287 * also to reject incoming file transmission request.
2290 SilcClientFileError silc_client_file_close(SilcClient client,
2291 SilcClientConnection conn,
2292 SilcUInt32 session_id);
2294 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2298 * SilcAttributePayload
2299 * silc_client_attribute_add(SilcClient client,
2300 * SilcClientConnection conn,
2301 * SilcAttribute attribute,
2303 * SilcUInt32 object_size);
2307 * Add new Requsted Attribute for WHOIS command to the client library.
2308 * The `attribute' object indicated by `object' is added and allocated
2309 * SilcAttributePayload is returned. The `object' must be of correct
2310 * type and of correct size. See the SilcAttribute for object types
2311 * for different attributes. You may also get all added attributes
2312 * from the client with silc_client_attributes_get function.
2314 * Requested Attributes are different personal information about the
2315 * user, status information and other information which other users
2316 * may query with WHOIS command. Application may set these so that
2317 * if someone sends WHOIS query these attributes will be replied back
2318 * to the sender. The library always puts the public key to the
2319 * Requested Attributes, but if application wishes to add additional
2320 * public keys (or certificates) it can be done with this interface.
2321 * Library also always computes digital signature of the attributes
2322 * automatically, so application does not need to do that.
2325 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2326 SilcClientConnection conn,
2327 SilcAttribute attribute,
2329 SilcUInt32 object_size);
2331 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2335 * bool silc_client_attribute_del(SilcClient client,
2336 * SilcClientConnection conn,
2337 * SilcAttribute attribute,
2338 * SilcAttributePayload attr);
2342 * Delete a Requested Attribute from the client. If the `attribute'
2343 * is non-zero then all attributes of that type are deleted and the
2344 * `attr' is ignored. If `attr' is non-NULL then that specific
2345 * attribute is deleted and `attribute' is ignored.
2347 * You may get all added attributes with the function
2348 * silc_client_attributes_get and to get the SilcAttributePayload.
2349 * This function Returns TRUE if the attribute was found and deleted.
2352 bool silc_client_attribute_del(SilcClient client,
2353 SilcClientConnection conn,
2354 SilcAttribute attribute,
2355 SilcAttributePayload attr);
2357 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2361 * const SilcHashTable
2362 * silc_client_attributes_get(SilcClient client,
2363 * SilcClientConnection conn);
2367 * Returns pointer to the SilcHashTable which includes all the added
2368 * Requested Attributes. The caller must not free the hash table.
2369 * The caller may use SilcHashTableList and silc_hash_table_list to
2370 * traverse the table. Each entry in the hash table is one added
2371 * SilcAttributePayload. It is possible to delete a attribute
2372 * payload while traversing the table.
2375 const SilcHashTable silc_client_attributes_get(SilcClient client,
2376 SilcClientConnection conn);
2378 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2382 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2386 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2387 * then all attributes are requested. Alternatively, `attribute' and
2388 * all variable arguments can each be requested attribute. In this case
2389 * the last must be set to zero (0) to complete the variable list of
2390 * requested attributes. See SilcAttribute for all attributes.
2391 * You can give the returned buffer as argument to for example
2392 * silc_client_get_client_by_id_resolve function.
2395 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2397 /* Low level packet sending functions */
2399 /****f* silcclient/SilcClientAPI/silc_client_packet_send
2403 * void silc_client_packet_send(SilcClient client,
2404 * SilcSocketConnection sock,
2405 * SilcPacketType type,
2407 * SilcIdType dst_id_type,
2408 * SilcCipher cipher,
2410 * unsigned char *data,
2411 * SilcUInt32 data_len,
2416 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2417 * then all attributes are requested. Alternatively, `attribute' and
2418 * all variable arguments can each be requested attribute. In this case
2419 * the last must be set to zero (0) to complete the variable list of
2420 * requested attributes. See SilcAttribute for all attributes.
2421 * You can give the returned buffer as argument to for example
2422 * silc_client_get_client_by_id_resolve function.
2425 void silc_client_packet_send(SilcClient client,
2426 SilcSocketConnection sock,
2427 SilcPacketType type,
2429 SilcIdType dst_id_type,
2432 unsigned char *data,
2433 SilcUInt32 data_len,
2436 #include "command.h"
2437 #include "command_reply.h"
2439 #include "protocol.h"
2445 #endif /* SILCCLIENT_H */