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 /* 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 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
186 * typedef enum { ... } SilcKeyAgreementStatus;
190 * Key agreement status types indicating the status of the key
191 * agreement protocol. These types are returned to the application
192 * in the SilcKeyAgreementCallback callback function.
197 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
198 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
199 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
200 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
201 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
202 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
203 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
204 } SilcKeyAgreementStatus;
207 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
211 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
212 * SilcClientConnection conn,
213 * SilcClientEntry client_entry,
214 * SilcKeyAgreementStatus status,
215 * SilcSKEKeyMaterial *key,
220 * Key agreement callback that is called after the key agreement protocol
221 * has been performed. This is called also if error occurred during the
222 * key agreement protocol. The `key' is the allocated key material and
223 * the caller is responsible of freeing it. The `key' is NULL if error
224 * has occurred. The application can freely use the `key' to whatever
225 * purpose it needs. See lib/silcske/silcske.h for the definition of
226 * the SilcSKEKeyMaterial structure.
229 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
230 SilcClientConnection conn,
231 SilcClientEntry client_entry,
232 SilcKeyAgreementStatus status,
233 SilcSKEKeyMaterial *key,
236 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
240 * typedef struct { ... } SilcPrivateMessageKeys;
244 * Structure to hold the list of private message keys. The array of this
245 * structure is returned by the silc_client_list_private_message_keys
251 SilcClientEntry client_entry; /* The remote client entry */
252 char *cipher; /* The cipher name */
253 unsigned char *key; /* The original key, If the appliation
254 provided it. This is NULL if the
255 library generated the key or if
256 the SKE key material was used. */
257 SilcUInt32 key_len; /* The key length */
258 } *SilcPrivateMessageKeys;
261 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
265 * typedef struct { ... } SilcChannelPrivateKey;
269 * Structure to hold one channel private key. The array of this structure
270 * is returned by silc_client_list_channel_private_keys function.
274 typedef struct SilcChannelPrivateKeyStruct {
275 char *name; /* Application given name */
276 SilcCipher cipher; /* The cipher and key */
277 SilcHmac hmac; /* The HMAC and hmac key */
278 unsigned char *key; /* The key data */
279 SilcUInt32 key_len; /* The key length */
280 } *SilcChannelPrivateKey;
283 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
287 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
288 * SilcUInt32 passphrase_len,
293 * Ask passphrase callback. This is called by the application when the
294 * library calls `ask_passphrase' client operation. The callback delivers
295 * the passphrase to the library. The passphrases in SILC protocol
296 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
297 * encoded, and if it is not then library will attempt to encode it.
300 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
301 SilcUInt32 passphrase_len,
304 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
308 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
312 * Public key (or certificate) verification callback. This is called
313 * by the application to indicate that the public key verification was
314 * either success or failure.
317 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
319 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
323 * typedef void (*SilcGetAuthMeth)(bool success,
324 * SilcProtocolAuthMeth auth_meth,
325 * const unsigned char *auth_data,
326 * SilcUInt32 auth_data_len, void *context);
330 * Authentication method resolving callback. This is called by the
331 * application to return the resolved authentication method. The client
332 * library has called the get_auth_method client operation and given
333 * this function pointer as argument. The `success' will indicate whether
334 * the authentication method could be resolved. The `auth_meth' is the
335 * resolved authentication method. The `auth_data' and the `auth_data_len'
336 * are the resolved authentication data. The `context' is the libary's
337 * context sent to the get_auth_method client operation.
340 typedef void (*SilcGetAuthMeth)(bool success,
341 SilcProtocolAuthMeth auth_meth,
342 const unsigned char *auth_data,
343 SilcUInt32 auth_data_len, void *context);
345 /****d* silcclient/SilcClientAPI/SilcClientMessageType
349 * typedef enum { ... } SilcClientMessageType;
353 * Different message types for `say' client operation. The application
354 * may filter the message sent by the library according this type.
359 SILC_CLIENT_MESSAGE_INFO, /* Informational */
360 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
361 SILC_CLIENT_MESSAGE_ERROR, /* Error */
362 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
363 } SilcClientMessageType;
366 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
370 * typedef enum { ... } SilcClientConnectionStatus
374 * This type is returned to the `connect' client operation to indicate
375 * the status of the created connection. It can indicated if it was
376 * successful or whether an error occurred.
381 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
382 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
383 resumed old detached session */
384 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
385 } SilcClientConnectionStatus;
388 /****s* silcclient/SilcClientAPI/SilcClientOperations
392 * typedef struct { ... } SilcClientOperations;
396 * SILC Client Operations. These must be implemented by the application.
397 * The Client library may call any of these routines at any time. The
398 * routines are used to deliver certain information to the application
399 * or from the application to the client library.
404 /* Message sent to the application by library. `conn' associates the
405 message to a specific connection. `conn', however, may be NULL.
406 The `type' indicates the type of the message sent by the library.
407 The application can for example filter the message according the
409 void (*say)(SilcClient client, SilcClientConnection conn,
410 SilcClientMessageType type, char *msg, ...);
412 /* Message for a channel. The `sender' is the sender of the message
413 The `channel' is the channel. The `message' is the message. Note
414 that `message' maybe NULL. The `flags' indicates message flags
415 and it is used to determine how the message can be interpreted
416 (like it may tell the message is multimedia message). */
417 void (*channel_message)(SilcClient client, SilcClientConnection conn,
418 SilcClientEntry sender, SilcChannelEntry channel,
419 SilcMessageFlags flags,
420 const unsigned char *message,
421 SilcUInt32 message_len);
423 /* Private message to the client. The `sender' is the sender of the
424 message. The message is `message'and maybe NULL. The `flags'
425 indicates message flags and it is used to determine how the message
426 can be interpreted (like it may tell the message is multimedia
428 void (*private_message)(SilcClient client, SilcClientConnection conn,
429 SilcClientEntry sender, SilcMessageFlags flags,
430 const unsigned char *message,
431 SilcUInt32 message_len);
433 /* Notify message to the client. The notify arguments are sent in the
434 same order as servers sends them. The arguments are same as received
435 from the server except for ID's. If ID is received application receives
436 the corresponding entry to the ID. For example, if Client ID is received
437 application receives SilcClientEntry. Also, if the notify type is
438 for channel the channel entry is sent to application (even if server
439 does not send it because client library gets the channel entry from
440 the Channel ID in the packet's header). */
441 void (*notify)(SilcClient client, SilcClientConnection conn,
442 SilcNotifyType type, ...);
444 /* Command handler. This function is called always in the command function.
445 If error occurs it will be called as well. `conn' is the associated
446 client connection. `cmd_context' is the command context that was
447 originally sent to the command. `success' is FALSE if error occurred
448 during command. `command' is the command being processed. It must be
449 noted that this is not reply from server. This is merely called just
450 after application has called the command. Just to tell application
451 that the command really was processed. */
452 void (*command)(SilcClient client, SilcClientConnection conn,
453 SilcClientCommandContext cmd_context, bool success,
454 SilcCommand command, SilcStatus status);
456 /* Command reply handler. This function is called always in the command reply
457 function. If error occurs it will be called as well. Normal scenario
458 is that it will be called after the received command data has been parsed
459 and processed. The function is used to pass the received command data to
462 `conn' is the associated client connection. `cmd_payload' is the command
463 payload data received from server and it can be ignored. It is provided
464 if the application would like to re-parse the received command data,
465 however, it must be noted that the data is parsed already by the library
466 thus the payload can be ignored. `success' is FALSE if error occurred.
467 In this case arguments are not sent to the application. The `status' is
468 the command reply status server returned. The `command' is the command
469 reply being processed. The function has variable argument list and each
470 command defines the number and type of arguments it passes to the
471 application (on error they are not sent).
473 The arguments are sent in the same order as servers sends them. The
474 arguments are same as received from the server except for ID's. If
475 ID is received application receives the corresponding entry to the
476 ID. For example, if Client ID is receives application receives
478 void (*command_reply)(SilcClient client, SilcClientConnection conn,
479 SilcCommandPayload cmd_payload, bool success,
480 SilcCommand command, SilcStatus status, ...);
482 /* Called to indicate that connection was either successfully established
483 or connecting failed. This is also the first time application receives
484 the SilcClientConnection object which it should save somewhere.
485 The `status' indicated whether the connection were successful. If it
486 is error value the application must always call the function
487 silc_client_close_connection. */
488 void (*connected)(SilcClient client, SilcClientConnection conn,
489 SilcClientConnectionStatus status);
491 /* Called to indicate that connection was disconnected to the server.
492 The `status' may tell the reason of the disconnection, and if the
493 `message' is non-NULL it may include the disconnection message
494 received from server. */
495 void (*disconnected)(SilcClient client, SilcClientConnection conn,
496 SilcStatus status, const char *message);
498 /* Find authentication method and authentication data by hostname and
499 port. The hostname may be IP address as well. When the authentication
500 method has been resolved the `completion' callback with the found
501 authentication method and authentication data is called. The `conn'
503 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
504 char *hostname, SilcUInt16 port,
505 SilcGetAuthMeth completion, void *context);
507 /* Verifies received public key. The `conn_type' indicates which entity
508 (server, client etc.) has sent the public key. If user decides to trust
509 the application may save the key as trusted public key for later
510 use. The `completion' must be called after the public key has been
512 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
513 SilcSocketType conn_type, unsigned char *pk,
514 SilcUInt32 pk_len, SilcSKEPKType pk_type,
515 SilcVerifyPublicKey completion, void *context);
517 /* Ask (interact, that is) a passphrase from user. The passphrase is
518 returned to the library by calling the `completion' callback with
519 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
520 if not then the library will attempt to encode. */
521 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
522 SilcAskPassphrase completion, void *context);
524 /* Notifies application that failure packet was received. This is called
525 if there is some protocol active in the client. The `protocol' is the
526 protocol context. The `failure' is opaque pointer to the failure
527 indication. Note, that the `failure' is protocol dependant and
528 application must explicitly cast it to correct type. Usually `failure'
529 is 32 bit failure type (see protocol specs for all protocol failure
531 void (*failure)(SilcClient client, SilcClientConnection conn,
532 SilcProtocol protocol, void *failure);
534 /* Asks whether the user would like to perform the key agreement protocol.
535 This is called after we have received an key agreement packet or an
536 reply to our key agreement packet. This returns TRUE if the user wants
537 the library to perform the key agreement protocol and FALSE if it is not
538 desired (application may start it later by calling the function
539 silc_client_perform_key_agreement). If TRUE is returned also the
540 `completion' and `context' arguments must be set by the application. */
541 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
542 SilcClientEntry client_entry, const char *hostname,
543 SilcUInt16 port, SilcKeyAgreementCallback *completion,
546 /* Notifies application that file transfer protocol session is being
547 requested by the remote client indicated by the `client_entry' from
548 the `hostname' and `port'. The `session_id' is the file transfer
549 session and it can be used to either accept or reject the file
550 transfer request, by calling the silc_client_file_receive or
551 silc_client_file_close, respectively. */
552 void (*ftp)(SilcClient client, SilcClientConnection conn,
553 SilcClientEntry client_entry, SilcUInt32 session_id,
554 const char *hostname, SilcUInt16 port);
556 /* Delivers SILC session detachment data indicated by `detach_data' to the
557 application. If application has issued SILC_COMMAND_DETACH command
558 the client session in the SILC network is not quit. The client remains
559 in the network but is detached. The detachment data may be used later
560 to resume the session in the SILC Network. The appliation is
561 responsible of saving the `detach_data', to for example in a file.
563 The detachment data can be given as argument to the functions
564 silc_client_connect_to_server, or silc_client_add_connection when
565 creating connection to remote server, inside SilcClientConnectionParams
566 structure. If it is provided the client library will attempt to resume
567 the session in the network. After the connection is created
568 successfully, the application is responsible of setting the user
569 interface for user into the same state it was before detaching (showing
570 same channels, channel modes, etc). It can do this by fetching the
571 information (like joined channels) from the client library. */
572 void (*detach)(SilcClient client, SilcClientConnection conn,
573 const unsigned char *detach_data,
574 SilcUInt32 detach_data_len);
575 } SilcClientOperations;
578 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
582 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
583 * char **ret_nickname);
587 * A callback function provided by the application for the library in
588 * SilcClientParams structure. This function parses the formatted
589 * nickname string `nickname' and returns the true nickname to the
590 * `ret_nickname' pointer. The library can call this function at
594 typedef void (*SilcNicknameFormatParse)(const char *nickname,
595 char **ret_nickname);
597 /****s* silcclient/SilcClientAPI/SilcClientParams
601 * typedef struct { ... } SilcClientParams;
605 * Client parameters. This can be filled with proper values and
606 * given as argument to the silc_client_alloc function. The structure
607 * hold various parameters which affects the function of the client.
612 /* Number of maximum tasks the client library's scheduler can handle.
613 If set to zero, the default value will be used (200). For WIN32
614 systems this should be set to 64 as it is the hard limit dictated
618 /* Rekey timeout in seconds. The client will perform rekey in this
619 time interval. If set to zero, the default value will be used. */
620 unsigned int rekey_secs;
622 /* Connection authentication method request timeout. If server does not
623 reply back the current authentication method when we've requested it
624 in this time interval we'll assume the reply will not come at all.
625 If set to zero, the default value (2 seconds) will be used. */
626 unsigned int connauth_request_secs;
628 /* Nickname format string. This can be used to order the client library
629 to save the nicknames in the library in a certain format. Since
630 nicknames are not unique in SILC it is possible to have multiple same
631 nicknames. Using this format string it is possible to order the library
632 to separate the multiple same nicknames from each other. The format
633 types are defined below and they can appear in any order in the format
634 string. If this is NULL then default format is used which is the
635 default nickname without anything else. The string MUST be NULL
638 Following format types are available:
640 %n nickname - the real nickname returned by the server (mandatory)
641 %h hostname - the stripped hostname of the client
642 %H full hostname - the full hostname of the client
643 %s server name - the server name the client is connected
644 %S full server - the full server name the client is connected
645 %a number - ascending number in case there are several
646 same nicknames (fe. nick@host and nick@host2)
648 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
649 "%a!%n@%s" (fe. nick@server, 2!nick@server)
650 "%n@%H" (fe. nick@host.domain.com)
652 By default this format is employed to the nicknames by the libary
653 only when there appears multiple same nicknames. If the library has
654 only one nickname cached the nickname is saved as is and without the
655 defined format. If you want always to save the nickname in the defined
656 format set the boolean field `nickname_force_format' to value TRUE.
658 char nickname_format[32];
660 /* If this is set to TRUE then the `nickname_format' is employed to all
661 saved nicknames even if there are no multiple same nicknames in the
662 cache. By default this is FALSE, which means that the `nickname_format'
663 is employed only if the library will receive a nickname that is
664 already saved in the cache. It is recommended to leave this to FALSE
666 bool nickname_force_format;
668 /* A callback function provided by the application for the library to
669 parse the nickname from the formatted nickname string. Even though
670 the libary formats the nicknames the application knows generally the
671 format better so this function should be provided for the library
672 if the application sets the `nickname_format' field. The library
673 will call this to get the true nickname from the provided formatted
674 nickname string whenever it needs the true nickname. */
675 SilcNicknameFormatParse nickname_parse;
677 /* If this is set to TRUE then the client will ignore all incoming
678 Requested Attributes queries and does not reply anything back. This
679 usually leads into situation where server does not anymore send
680 the queries after seeing that client does not reply anything back.
681 If your application does not support Requested Attributes or you do
682 not want to use them set this to TRUE. See SilcAttribute and
683 silc_client_attribute_add for more information on attributes. */
684 bool ignore_requested_attributes;
690 /* Initialization functions (client.c) */
692 /****f* silcclient/SilcClientAPI/silc_client_alloc
696 * SilcClient silc_client_alloc(SilcClientOperations *ops,
697 * SilcClientParams *params,
699 * const char *silc_version);
703 * Allocates new client object. This has to be done before client may
704 * work. After calling this one must call silc_client_init to initialize
705 * the client. The `application' is application specific user data pointer
706 * and caller must free it. The `silc_version' is the application version
707 * that will be used to compare against remote host's (usually a server)
708 * version string. The `application' context is accessible by the
709 * application by client->application, client being SilcClient.
712 SilcClient silc_client_alloc(SilcClientOperations *ops,
713 SilcClientParams *params,
715 const char *version_string);
717 /****f* silcclient/SilcClientAPI/silc_client_free
721 * void silc_client_free(SilcClient client);
725 * Frees client object and its internals. The execution of the client
726 * should be stopped with silc_client_stop function before calling
730 void silc_client_free(SilcClient client);
732 /****f* silcclient/SilcClientAPI/silc_client_init
736 * int silc_client_init(SilcClient client);
740 * Initializes the client. This makes all the necessary steps to make
741 * the client ready to be run. One must call silc_client_run to run the
742 * client. Returns FALSE if error occurred, TRUE otherwise.
745 int silc_client_init(SilcClient client);
747 /****f* silcclient/SilcClientAPI/silc_client_run
751 * void silc_client_run(SilcClient client);
755 * Runs the client. This starts the scheduler from the utility library.
756 * When this functions returns the execution of the appliation is over.
757 * The client must be initialized before calling this.
760 void silc_client_run(SilcClient client);
762 /****f* silcclient/SilcClientAPI/silc_client_run_one
766 * void silc_client_run_one(SilcClient client);
770 * Runs the client and returns immeadiately. This function is used when
771 * the SILC Client object indicated by the `client' is run under some
772 * other scheduler, or event loop or main loop. On GUI applications,
773 * for example this may be desired to used to run the client under the
774 * GUI application's main loop. Typically the GUI application would
775 * register an idle task that calls this function multiple times in
776 * a second to quickly process the SILC specific data.
779 void silc_client_run_one(SilcClient client);
781 /****f* silcclient/SilcClientAPI/silc_client_stop
785 * void silc_client_stop(SilcClient client);
789 * Stops the client. This is called to stop the client and thus to stop
790 * the program. The client context must be freed with the silc_client_free
794 void silc_client_stop(SilcClient client);
797 /* Connecting functions (client.c) */
799 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
803 * typedef struct { ... } SilcClientConnectionParams;
807 * Client connection parameters. This can be filled by the application
808 * and given as argument to silc_client_connect_to_server or to
809 * silc_client_add_connection.
814 /* The SILC session detachment data that was returned by `detach' client
815 operation when the application detached from the network. Application
816 is responsible of saving the data and giving it as argument here
817 for resuming the session in the SILC network.
819 If this is provided here the client library will attempt to resume
820 the session in the network. After the connection is created
821 successfully, the application is responsible of setting the user
822 interface for user into the same state it was before detaching (showing
823 same channels, channel modes, etc). It can do this by fetching the
824 information (like joined channels) from the client library. */
825 unsigned char *detach_data;
826 SilcUInt32 detach_data_len;
828 } SilcClientConnectionParams;
831 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
835 * int silc_client_connect_to_server(SilcClient client,
836 * SilcClientConnectionParams *params,
837 * int port, char *host, void *context);
841 * Connects to remote server. This is the main routine used to connect
842 * to SILC server. Returns -1 on error and the created socket otherwise.
843 * The `context' is user context that is saved into the SilcClientConnection
844 * that is created after the connection is created. Note that application
845 * may handle the connecting process outside the library. If this is the
846 * case then this function is not used at all. When the connecting is
847 * done the `connect' client operation is called, and the `context' is
848 * accessible with conn->context, conn being SilcClientConnection.
849 * If the `params' is provided they are used by the routine.
852 int silc_client_connect_to_server(SilcClient client,
853 SilcClientConnectionParams *params,
854 int port, char *host, void *context);
856 /****f* silcclient/SilcClientAPI/silc_client_add_connection
861 * SilcClientConnection
862 * silc_client_add_connection(SilcClient client,
863 * SilcClientConnectionParams *params,
864 * char *hostname, int port, void *context);
868 * Allocates and adds new connection to the client. This adds the allocated
869 * connection to the connection table and returns a pointer to it. A client
870 * can have multiple connections to multiple servers. Every connection must
871 * be added to the client using this function. User data `context' may
872 * be sent as argument. If the `params' is provided they are used by
877 * This function is normally used only if the application performed
878 * the connecting outside the library, and did not called the
879 * silc_client_connect_to_server function at all. The library
880 * however may use this internally.
884 silc_client_add_connection(SilcClient client,
885 SilcClientConnectionParams *params,
886 char *hostname, int port, void *context);
888 /****f* silcclient/SilcClientAPI/silc_client_del_connection
892 * void silc_client_del_connection(SilcClient client,
893 * SilcClientConnection conn);
897 * Removes connection from client. Frees all memory. The library
898 * call this function automatically for all connection contexts.
899 * The application however may free the connection contexts it has
903 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
905 /****f* silcclient/SilcClientAPI/silc_client_add_socket
909 * void silc_client_add_socket(SilcClient client,
910 * SilcSocketConnection sock);
914 * Adds listener socket to the listener sockets table. This function is
915 * used to add socket objects that are listeners to the client. This should
916 * not be used to add other connection objects.
919 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
921 /****f* silcclient/SilcClientAPI/silc_client_del_socket
925 * void silc_client_del_socket(SilcClient client,
926 * SilcSocketConnection sock);
930 * Deletes listener socket from the listener sockets table. If the
931 * application has added a socket with silc_client_add_socket it must
932 * also free it using this function.
935 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
937 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
941 * void silc_client_start_key_exchange(SilcClient client,
942 * SilcClientConnection conn,
947 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
948 * key material between client and server. This function can be called
949 * directly if application is performing its own connecting and does not
950 * use the connecting provided by this library. This function is normally
951 * used only if the application performed the connecting outside the
952 * library. The library however may use this internally. After the
953 * key exchange is performed the `connect' client operation is called.
956 void silc_client_start_key_exchange(SilcClient client,
957 SilcClientConnection conn,
960 /****f* silcclient/SilcClientAPI/silc_client_close_connection
964 * void silc_client_close_connection(SilcClient client,
965 * SilcClientConnection conn);
969 * Closes connection to remote end. Free's all allocated data except
970 * for some information such as nickname etc. that are valid at all time.
973 void silc_client_close_connection(SilcClient client,
974 SilcClientConnection conn);
977 /* Message sending functions (client_channel.c and client_prvmsg.c) */
979 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
983 * void silc_client_send_channel_message(SilcClient client,
984 * SilcClientConnection conn,
985 * SilcChannelEntry channel,
986 * SilcChannelPrivateKey key,
987 * SilcMessageFlags flags,
988 * unsigned char *data,
989 * SilcUInt32 data_len,
994 * Sends packet to the `channel'. Packet to channel is always encrypted
995 * differently from "normal" packets. SILC header of the packet is
996 * encrypted with the next receiver's key and the rest of the packet is
997 * encrypted with the channel specific key. Padding and HMAC is computed
998 * with the next receiver's key. The `data' is the channel message. If
999 * the `force_send' is TRUE then the packet is sent immediately.
1001 * If `key' is provided then that private key is used to encrypt the
1002 * channel message. If it is not provided, private keys has not been
1003 * set at all, the normal channel key is used automatically. If private
1004 * keys are set then the first key (the key that was added first as
1005 * private key) is used.
1008 void silc_client_send_channel_message(SilcClient client,
1009 SilcClientConnection conn,
1010 SilcChannelEntry channel,
1011 SilcChannelPrivateKey key,
1012 SilcMessageFlags flags,
1013 unsigned char *data,
1014 SilcUInt32 data_len,
1017 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1021 * void silc_client_send_private_message(SilcClient client,
1022 * SilcClientConnection conn,
1023 * SilcClientEntry client_entry,
1024 * SilcMessageFlags flags,
1025 * unsigned char *data,
1026 * SilcUInt32 data_len,
1031 * Sends private message to remote client. If private message key has
1032 * not been set with this client then the message will be encrypted using
1033 * normal session keys. Private messages are special packets in SILC
1034 * network hence we need this own function for them. This is similar
1035 * to silc_client_packet_send_to_channel except that we send private
1036 * message. The `data' is the private message. If the `force_send' is
1037 * TRUE the packet is sent immediately.
1040 void silc_client_send_private_message(SilcClient client,
1041 SilcClientConnection conn,
1042 SilcClientEntry client_entry,
1043 SilcMessageFlags flags,
1044 unsigned char *data,
1045 SilcUInt32 data_len,
1049 /* Client and Channel entry retrieval (idlist.c) */
1051 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1055 * typedef void (*SilcGetClientCallback)(SilcClient client,
1056 * SilcClientConnection conn,
1057 * SilcClientEntry *clients,
1058 * SilcUInt32 clients_count,
1063 * Callback function given to the silc_client_get_client function. The
1064 * found entries are allocated into the `clients' array. The array must
1065 * not be freed by the receiver, the library will free it later. If the
1066 * `clients' is NULL, no such clients exist in the SILC Network.
1069 typedef void (*SilcGetClientCallback)(SilcClient client,
1070 SilcClientConnection conn,
1071 SilcClientEntry *clients,
1072 SilcUInt32 clients_count,
1075 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1079 * void silc_client_get_clients(SilcClient client,
1080 * SilcClientConnection conn,
1081 * const char *nickname,
1082 * const char *server,
1083 * SilcGetClientCallback completion,
1088 * Finds client entry or entries by the `nickname' and `server'. The
1089 * completion callback will be called when the client entries has been
1090 * found. After the server returns the client information it is cached
1091 * and can be accesses locally at a later time.
1095 * NOTE: This function is always asynchronous and resolves the client
1096 * information from the server. Thus, if you already know the client
1097 * information then use the silc_client_get_client_by_id function to
1098 * get the client entry since this function may be very slow and should
1099 * be used only to initially get the client entries.
1102 void silc_client_get_clients(SilcClient client,
1103 SilcClientConnection conn,
1104 const char *nickname,
1106 SilcGetClientCallback completion,
1109 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1113 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1114 * SilcClientConnection conn,
1115 * const char *nickname,
1116 * const char *format,
1117 * SilcUInt32 *clients_count);
1121 * Same as silc_client_get_clients function but does not resolve anything
1122 * from the server. This checks local cache and returns all matching
1123 * clients from the local cache. If none was found this returns NULL.
1124 * The `nickname' is the real nickname of the client, and the `format'
1125 * is the formatted nickname to find exact match from multiple found
1126 * entries. The format must be same as given in the SilcClientParams
1127 * structure to the client library. If the `format' is NULL all found
1128 * clients by `nickname' are returned. The caller must return the
1132 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1133 SilcClientConnection conn,
1134 const char *nickname,
1136 SilcUInt32 *clients_count);
1138 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1142 * void silc_client_get_clients_by_list(SilcClient client,
1143 * SilcClientConnection conn,
1144 * SilcUInt32 list_count,
1145 * SilcBuffer client_id_list,
1146 * SilcGetClientCallback completion,
1151 * Gets client entries by the list of client ID's `client_id_list'. This
1152 * always resolves those client ID's it does not know yet from the server
1153 * so this function might take a while. The `client_id_list' is a list
1154 * of ID Payloads added one after other. JOIN command reply and USERS
1155 * command reply for example returns this sort of list. The `completion'
1156 * will be called after the entries are available. When server returns
1157 * the client information it will be cached and can be accessed locally
1161 void silc_client_get_clients_by_list(SilcClient client,
1162 SilcClientConnection conn,
1163 SilcUInt32 list_count,
1164 SilcBuffer client_id_list,
1165 SilcGetClientCallback completion,
1168 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1172 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1173 * SilcClientConnection conn,
1174 * SilcClientID *client_id);
1178 * Find entry for client by the client's ID. Returns the entry or NULL
1179 * if the entry was not found. This checks the local cache and does
1180 * not resolve anything from server.
1183 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1184 SilcClientConnection conn,
1185 SilcClientID *client_id);
1187 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1192 * silc_client_get_client_by_id_resolve(SilcClient client,
1193 * SilcClientConnection conn,
1194 * SilcClientID *client_id,
1195 * SilcBuffer attributes,
1196 * SilcGetClientCallback completion,
1201 * Same as silc_client_get_client_by_id but will always resolve the
1202 * information from the server. Use this only if you know that you
1203 * do not have the entry and the only thing you know about the client
1204 * is its ID. When server returns the client information it will be
1205 * cache and can be accessed locally at a later time.
1207 * If the `attributes' is non-NULL then the buffer includes Requested
1208 * Attributes which can be used to fetch very detailed information
1209 * about the user. If it is NULL then only normal WHOIS query is
1210 * made (for more information about attributes see SilcAttribute).
1211 * Caller may create the `attributes' with silc_client_attributes_request
1215 void silc_client_get_client_by_id_resolve(SilcClient client,
1216 SilcClientConnection conn,
1217 SilcClientID *client_id,
1218 SilcBuffer attributes,
1219 SilcGetClientCallback completion,
1222 /****f* silcclient/SilcClientAPI/silc_client_del_client
1226 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1227 * SilcClientEntry client_entry)
1231 * Removes client from local cache by the client entry indicated by
1232 * the `client_entry'. Returns TRUE if the deletion were successful.
1235 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1236 SilcClientEntry client_entry);
1238 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1242 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1243 * SilcClientConnection conn,
1244 * SilcChannelEntry *channels,
1245 * SilcUInt32 channels_count,
1250 * Callback function given to the silc_client_get_channel_* functions.
1251 * The found entries are allocated into the `channels' array. The array
1252 * must not be freed by the receiver, the library will free it later.
1253 * If the `channel' is NULL, no such channel exist in the SILC Network.
1256 typedef void (*SilcGetChannelCallback)(SilcClient client,
1257 SilcClientConnection conn,
1258 SilcChannelEntry *channels,
1259 SilcUInt32 channels_count,
1262 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1266 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1267 * SilcClientConnection conn,
1272 * Finds entry for channel by the channel name. Returns the entry or NULL
1273 * if the entry was not found. It is found only if the client is joined
1277 SilcChannelEntry silc_client_get_channel(SilcClient client,
1278 SilcClientConnection conn,
1281 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1286 * silc_client_get_channel_by_id(SilcClient client,
1287 * SilcClientConnection conn,
1288 * SilcChannelID *channel_id);
1292 * Finds channel entry by the channel name. Returns the entry or NULL
1293 * if it was not found.
1296 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1297 SilcClientConnection conn,
1298 SilcChannelID *channel_id);
1300 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1305 * silc_client_get_channel_by_id_resolve(SilcClient client,
1306 * SilcClientConnection conn,
1307 * SilcChannelID *channel_id,
1308 * SilcGetClientCallback completion,
1313 * Resolves the channel information (its name mainly) from the server
1314 * by the `channel_id'. Use this only if you know that you do not have
1315 * the entry cached locally.
1318 void silc_client_get_channel_by_id_resolve(SilcClient client,
1319 SilcClientConnection conn,
1320 SilcChannelID *channel_id,
1321 SilcGetChannelCallback completion,
1324 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1328 * bool silc_client_del_channel(SilcClient client,
1329 * SilcClientConnection conn,
1330 * SilcChannelEntry channel)
1334 * Removes channel from local cache by the channel entry indicated by
1335 * the `channel'. Returns TRUE if the deletion were successful.
1338 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1339 SilcChannelEntry channel);
1341 /****f* silcclient/SilcClientAPI/silc_client_get_server
1345 * SilcServerEntry silc_client_get_server(SilcClient client,
1346 * SilcClientConnection conn,
1347 * char *server_name)
1351 * Finds entry for server by the server name. Returns the entry or NULL
1352 * if the entry was not found.
1355 SilcServerEntry silc_client_get_server(SilcClient client,
1356 SilcClientConnection conn,
1359 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1363 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1364 * SilcClientConnection conn,
1365 * SilcServerID *server_id);
1369 * Finds entry for server by the server ID. Returns the entry or NULL
1370 * if the entry was not found.
1373 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1374 SilcClientConnection conn,
1375 SilcServerID *server_id);
1377 /****f* silcclient/SilcClientAPI/silc_client_del_server
1381 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1382 * SilcServerEntry server);
1386 * Removes server from local cache by the server entry indicated by
1387 * the `server'. Returns TRUE if the deletion were successful.
1390 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1391 SilcServerEntry server);
1393 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1397 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1398 * SilcClientEntry client_entry);
1402 * Returns the ChannelUser entry if the `client_entry' is joined on the
1403 * channel indicated by the `channel'. NULL if client is not joined on
1407 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1408 SilcClientEntry client_entry);
1410 /* Command management (command.c) */
1412 /****f* silcclient/SilcClientAPI/silc_client_command_call
1416 * void silc_client_command_call(SilcClient client,
1417 * SilcClientConnection conn,
1418 * const char *command_line, ...);
1422 * Calls and executes the command indicated by the `command_name'.
1423 * The `command_line' is a string which includes the command's name and
1424 * its arguments separated with whitespaces (' '). If `command_line'
1425 * is non-NULL then all variable arguments are ignored by default.
1427 * If `command_line' is NULL, then the variable arguments define the
1428 * command's name and its arguments. The first variable argument must
1429 * be the command name. The variable argument list must be terminated
1432 * Returns FALSE if the command is not known and TRUE after command.
1433 * execution. The "command" client operation is called when the
1434 * command is executed to indicate whether the command executed
1435 * successfully or not.
1437 * The "command_reply" client operation will be called when reply is
1438 * received from the server to the command. Application may also use
1439 * the silc_client_command_pending to attach to the command reply.
1440 * The command identifier for silc_client_command_pending function after
1441 * this function call is conn->cmd_ident, which application may use.
1445 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1447 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1450 bool silc_client_command_call(SilcClient client,
1451 SilcClientConnection conn,
1452 const char *command_line, ...);
1454 /****f* silcclient/SilcClientAPI/silc_client_command_send
1458 * void silc_client_command_send(SilcClient client,
1459 * SilcClientConnection conn,
1460 * SilcCommand command, SilcUInt16 ident,
1461 * SilcUInt32 argc, ...);
1465 * Generic function to send any command. The arguments must be sent already
1466 * encoded into correct form and in correct order. If application wants
1467 * to perform the commands by itself, it can do so and send the data
1468 * directly to the server using this function. If application is using
1469 * the silc_client_command_call, this function is usually not used.
1470 * Note that this overriders the Client Librarys commands and sends
1471 * the command packet directly to server.
1473 * The variable arguments are a pair of { type, data, data_length },
1474 * and the `argc' is the number of these pairs.
1478 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1479 * 1, nickname, strlen(nickname));
1482 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1483 SilcCommand command, SilcUInt16 ident,
1484 SilcUInt32 argc, ...);
1486 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1490 * void silc_client_command_pending(SilcClientConnection conn,
1491 * SilcCommand reply_cmd,
1493 * SilcCommandCb callback,
1498 * This function can be used to add pending command callback to be
1499 * called when an command reply is received to an earlier sent command.
1500 * The `reply_cmd' is the command that must be received in order for
1501 * the pending command callback indicated by `callback' to be called.
1503 * The `ident' is a command identifier which was set for the earlier
1504 * sent command. The command reply will include the same identifier
1505 * and pending command callback will be called when the reply is
1506 * received with the same command identifier. It is possible to
1507 * add multiple pending command callbacks for same command and for
1510 * Application may use this function to add its own command reply
1511 * handlers if it wishes not to use the standard `command_reply'
1512 * client operation. However, note that the pending command callback
1513 * does not deliver parsed command reply, but application must parse
1516 * Note also that the application is notified about the received command
1517 * reply through the `command_reply' client operation before calling
1518 * the `callback` pending command callback. That is the normal
1519 * command reply handling, and is called regardless whether pending
1520 * command callbacks are used or not.
1522 * Commands that application calls with silc_client_command_call
1523 * will use a command identifier from conn->cmd_ident variable. After
1524 * calling the silc_client_command_call, the conn->cmd_ident includes
1525 * the command identifier that was used for the command sending.
1529 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1530 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1531 * my_ping_handler, my_ping_context);
1534 void silc_client_command_pending(SilcClientConnection conn,
1535 SilcCommand reply_cmd,
1537 SilcCommandCb callback,
1541 /* Private Message key management (client_prvmsg.c) */
1543 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1547 * int silc_client_add_private_message_key(SilcClient client,
1548 * SilcClientConnection conn,
1549 * SilcClientEntry client_entry,
1551 * unsigned char *key,
1552 * SilcUInt32 key_len,
1553 * bool generate_key,
1558 * Adds private message key to the client library. The key will be used to
1559 * encrypt all private message between the client and the remote client
1560 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1561 * value `generate_key' is TRUE the library will generate random key.
1562 * The `key' maybe for example pre-shared-key, passphrase or similar.
1563 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1564 * requirements of the SILC protocol are met. The API, however, allows
1565 * to allocate any cipher.
1567 * If `responder' is TRUE then the sending and receiving keys will be
1568 * set according the client being the receiver of the private key. If
1569 * FALSE the client is being the sender (or negotiator) of the private
1572 * It is not necessary to set key for normal private message usage. If the
1573 * key is not set then the private messages are encrypted using normal
1574 * session keys. Setting the private key, however, increases the security.
1576 * Returns FALSE if the key is already set for the `client_entry', TRUE
1580 int silc_client_add_private_message_key(SilcClient client,
1581 SilcClientConnection conn,
1582 SilcClientEntry client_entry,
1589 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1593 * int silc_client_add_private_message_key_ske(SilcClient client,
1594 * SilcClientConnection conn,
1595 * SilcClientEntry client_entry,
1597 * SilcSKEKeyMaterial *key);
1601 * Same as silc_client_add_private_message_key but takes the key material
1602 * from the SKE key material structure. This structure is received if
1603 * the application uses the silc_client_send_key_agreement to negotiate
1604 * the key material. The `cipher' SHOULD be provided as it is negotiated
1605 * also in the SKE protocol.
1608 int silc_client_add_private_message_key_ske(SilcClient client,
1609 SilcClientConnection conn,
1610 SilcClientEntry client_entry,
1612 SilcSKEKeyMaterial *key,
1615 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1619 * int silc_client_del_private_message_key(SilcClient client,
1620 * SilcClientConnection conn,
1621 * SilcClientEntry client_entry);
1625 * Removes the private message from the library. The key won't be used
1626 * after this to protect the private messages with the remote `client_entry'
1627 * client. Returns FALSE on error, TRUE otherwise.
1630 int silc_client_del_private_message_key(SilcClient client,
1631 SilcClientConnection conn,
1632 SilcClientEntry client_entry);
1634 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1638 * SilcPrivateMessageKeys
1639 * silc_client_list_private_message_keys(SilcClient client,
1640 * SilcClientConnection conn,
1641 * SilcUInt32 *key_count);
1645 * Returns array of set private message keys associated to the connection
1646 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1647 * count to the `key_count' argument. The array must be freed by the caller
1648 * by calling the silc_client_free_private_message_keys function. Note:
1649 * the keys returned in the array is in raw format. It might not be desired
1650 * to show the keys as is. The application might choose not to show the keys
1651 * at all or to show the fingerprints of the keys.
1654 SilcPrivateMessageKeys
1655 silc_client_list_private_message_keys(SilcClient client,
1656 SilcClientConnection conn,
1657 SilcUInt32 *key_count);
1659 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1663 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1664 * SilcUInt32 key_count);
1668 * Frees the SilcPrivateMessageKeys array returned by the function
1669 * silc_client_list_private_message_keys.
1672 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1673 SilcUInt32 key_count);
1676 /* Channel private key management (client_channel.c,
1677 SilcChannelPrivateKey is defined in idlist.h) */
1679 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1683 * int silc_client_add_channel_private_key(SilcClient client,
1684 * SilcClientConnection conn,
1685 * SilcChannelEntry channel,
1689 * unsigned char *key,
1690 * SilcUInt32 key_len);
1694 * Adds private key for channel. This may be set only if the channel's mode
1695 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1696 * mode is not set. When channel has private key then the messages are
1697 * encrypted using that key. All clients on the channel must also know the
1698 * key in order to decrypt the messages. However, it is possible to have
1699 * several private keys per one channel. In this case only some of the
1700 * clients on the channel may know the one key and only some the other key.
1701 * The `name' can be application given name for the key.
1703 * The private key for channel is optional. If it is not set then the
1704 * channel messages are encrypted using the channel key generated by the
1705 * server. However, setting the private key (or keys) for the channel
1706 * significantly adds security. If more than one key is set the library
1707 * will automatically try all keys at the message decryption phase. Note:
1708 * setting many keys slows down the decryption phase as all keys has to
1709 * be tried in order to find the correct decryption key. However, setting
1710 * a few keys does not have big impact to the decryption performace.
1714 * NOTE: This is entirely local setting. The key set using this function
1715 * is not sent to the network at any phase.
1717 * NOTE: If the key material was originated by the SKE protocol (using
1718 * silc_client_send_key_agreement) then the `key' MUST be the
1719 * key->send_enc_key as this is dictated by the SILC protocol. However,
1720 * currently it is not expected that the SKE key material would be used
1721 * as channel private key. However, this API allows it.
1724 int silc_client_add_channel_private_key(SilcClient client,
1725 SilcClientConnection conn,
1726 SilcChannelEntry channel,
1731 SilcUInt32 key_len);
1733 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1737 * int silc_client_del_channel_private_keys(SilcClient client,
1738 * SilcClientConnection conn,
1739 * SilcChannelEntry channel);
1743 * Removes all private keys from the `channel'. The old channel key is used
1744 * after calling this to protect the channel messages. Returns FALSE on
1745 * on error, TRUE otherwise.
1748 int silc_client_del_channel_private_keys(SilcClient client,
1749 SilcClientConnection conn,
1750 SilcChannelEntry channel);
1752 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1756 * int silc_client_del_channel_private_key(SilcClient client,
1757 * SilcClientConnection conn,
1758 * SilcChannelEntry channel,
1759 * SilcChannelPrivateKey key);
1763 * Removes and frees private key `key' from the channel `channel'.
1764 * The `key' is retrieved by calling the function
1765 * silc_client_list_channel_private_keys. The key is not used after
1766 * this. If the key was last private key then the old channel key is
1767 * used hereafter to protect the channel messages. This returns FALSE
1768 * on error, TRUE otherwise.
1771 int silc_client_del_channel_private_key(SilcClient client,
1772 SilcClientConnection conn,
1773 SilcChannelEntry channel,
1774 SilcChannelPrivateKey key);
1776 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1780 * SilcChannelPrivateKey *
1781 * silc_client_list_channel_private_keys(SilcClient client,
1782 * SilcClientConnection conn,
1783 * SilcChannelEntry channel,
1784 * SilcUInt32 *key_count);
1788 * Returns array (pointers) of private keys associated to the `channel'.
1789 * The caller must free the array by calling the function
1790 * silc_client_free_channel_private_keys. The pointers in the array may be
1791 * used to delete the specific key by giving the pointer as argument to the
1792 * function silc_client_del_channel_private_key.
1795 SilcChannelPrivateKey *
1796 silc_client_list_channel_private_keys(SilcClient client,
1797 SilcClientConnection conn,
1798 SilcChannelEntry channel,
1799 SilcUInt32 *key_count);
1801 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1805 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1806 * SilcUInt32 key_count);
1810 * Frees the SilcChannelPrivateKey array.
1813 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1814 SilcUInt32 key_count);
1816 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1820 * void silc_client_current_channel_private_key(SilcClient client,
1821 * SilcClientConnection conn,
1822 * SilcChannelEntry channel,
1823 * SilcChannelPrivateKey key);
1827 * Sets the `key' to be used as current channel private key on the
1828 * `channel'. Packet sent after calling this function will be secured
1832 void silc_client_current_channel_private_key(SilcClient client,
1833 SilcClientConnection conn,
1834 SilcChannelEntry channel,
1835 SilcChannelPrivateKey key);
1838 /* Key Agreement routines (client_keyagr.c) */
1840 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1844 * void silc_client_send_key_agreement(SilcClient client,
1845 * SilcClientConnection conn,
1846 * SilcClientEntry client_entry,
1849 * SilcUInt32 timeout_secs,
1850 * SilcKeyAgreementCallback completion,
1855 * Sends key agreement request to the remote client indicated by the
1856 * `client_entry'. If the caller provides the `hostname' and the `port'
1857 * arguments then the library will bind the client to that hostname and
1858 * that port for the key agreement protocol. It also sends the `hostname'
1859 * and the `port' in the key agreement packet to the remote client. This
1860 * would indicate that the remote client may initiate the key agreement
1861 * protocol to the `hostname' on the `port'. If port is zero then the
1862 * bound port is undefined (the operating system defines it).
1864 * If the `hostname' and `port' is not provided then empty key agreement
1865 * packet is sent to the remote client. The remote client may reply with
1866 * the same packet including its hostname and port. If the library receives
1867 * the reply from the remote client the `key_agreement' client operation
1868 * callback will be called to verify whether the user wants to perform the
1869 * key agreement or not.
1873 * NOTE: If the application provided the `hostname' and the `port' and the
1874 * remote side initiates the key agreement protocol it is not verified
1875 * from the user anymore whether the protocol should be executed or not.
1876 * By setting the `hostname' and `port' the user gives permission to
1877 * perform the protocol (we are responder in this case).
1879 * NOTE: If the remote side decides not to initiate the key agreement
1880 * or decides not to reply with the key agreement packet then we cannot
1881 * perform the key agreement at all. If the key agreement protocol is
1882 * performed the `completion' callback with the `context' will be called.
1883 * If remote side decides to ignore the request the `completion' will be
1884 * called after the specified timeout, `timeout_secs'.
1886 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1887 * will not be called at all since this does nothing more than sending
1888 * a packet to the remote host.
1890 * NOTE: There can be only one active key agreement for one client entry.
1891 * Before setting new one, the old one must be finished (it is finished
1892 * after calling the completion callback) or the function
1893 * silc_client_abort_key_agreement must be called.
1896 void silc_client_send_key_agreement(SilcClient client,
1897 SilcClientConnection conn,
1898 SilcClientEntry client_entry,
1899 const char *hostname,
1900 const char *bindhost,
1902 SilcUInt32 timeout_secs,
1903 SilcKeyAgreementCallback completion,
1906 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1911 * silc_client_perform_key_agreement(SilcClient client,
1912 * SilcClientConnection conn,
1913 * SilcClientEntry client_entry,
1916 * SilcKeyAgreementCallback completion,
1921 * Performs the actual key agreement protocol. Application may use this
1922 * to initiate the key agreement protocol. This can be called for example
1923 * after the application has received the `key_agreement' client operation,
1924 * and did not return TRUE from it.
1926 * The `hostname' is the remote hostname (or IP address) and the `port'
1927 * is the remote port. The `completion' callback with the `context' will
1928 * be called after the key agreement protocol.
1932 * NOTE: If the application returns TRUE in the `key_agreement' client
1933 * operation the library will automatically start the key agreement. In this
1934 * case the application must not call this function. However, application
1935 * may choose to just ignore the `key_agreement' client operation (and
1936 * merely just print information about it on the screen) and call this
1937 * function when the user whishes to do so (by, for example, giving some
1938 * specific command). Thus, the API provides both, automatic and manual
1939 * initiation of the key agreement. Calling this function is the manual
1940 * initiation and returning TRUE in the `key_agreement' client operation
1941 * is the automatic initiation.
1944 void silc_client_perform_key_agreement(SilcClient client,
1945 SilcClientConnection conn,
1946 SilcClientEntry client_entry,
1949 SilcKeyAgreementCallback completion,
1952 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1957 * silc_client_perform_key_agreement_fd(SilcClient client,
1958 * SilcClientConnection conn,
1959 * SilcClientEntry client_entry,
1962 * SilcKeyAgreementCallback completion,
1967 * Same as above but application has created already the connection to
1968 * the remote host. The `sock' is the socket to the remote connection.
1969 * Application can use this function if it does not want the client library
1970 * to create the connection.
1973 void silc_client_perform_key_agreement_fd(SilcClient client,
1974 SilcClientConnection conn,
1975 SilcClientEntry client_entry,
1978 SilcKeyAgreementCallback completion,
1981 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1985 * void silc_client_abort_key_agreement(SilcClient client,
1986 * SilcClientConnection conn,
1987 * SilcClientEntry client_entry);
1991 * This function can be called to unbind the hostname and the port for
1992 * the key agreement protocol. However, this function has effect only
1993 * before the key agreement protocol has been performed. After it has
1994 * been performed the library will automatically unbind the port. The
1995 * `client_entry' is the client to which we sent the key agreement
1996 * request. The key agreement completion callback will be called
1997 * with SILC_KEY_AGREEMENT_ABORTED status.
2000 void silc_client_abort_key_agreement(SilcClient client,
2001 SilcClientConnection conn,
2002 SilcClientEntry client_entry);
2005 /* Misc functions */
2007 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2011 * void silc_client_set_away_message(SilcClient client,
2012 * SilcClientConnection conn,
2017 * Sets away `message'. The away message may be set when the client's
2018 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2019 * to anyone who sends private message. The `message' will be sent
2020 * automatically back to the the client who send private message. If
2021 * away message is already set this replaces the old message with the
2022 * new one. If `message' is NULL the old away message is removed.
2023 * The sender may freely free the memory of the `message'.
2026 void silc_client_set_away_message(SilcClient client,
2027 SilcClientConnection conn,
2030 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2034 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2035 * SilcClientConnection conn,
2036 * SilcAuthMethod auth_meth,
2041 * Connection authentication method request callback. This is called
2042 * by the client library after it has received the authentication method
2043 * that the application requested by calling the function
2044 * silc_client_request_authentication_method.
2047 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2048 SilcClientConnection conn,
2049 SilcAuthMethod auth_meth,
2052 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2057 * silc_client_request_authentication_method(SilcClient client,
2058 * SilcClientConnection conn,
2059 * SilcConnectionAuthRequest
2065 * This function can be used to request the current authentication method
2066 * from the server. This may be called when connecting to the server
2067 * and the client library requests the authentication data from the
2068 * application. If the application does not know the current authentication
2069 * method it can request it from the server using this function.
2070 * The `callback' with `context' will be called after the server has
2071 * replied back with the current authentication method.
2075 silc_client_request_authentication_method(SilcClient client,
2076 SilcClientConnection conn,
2077 SilcConnectionAuthRequest callback,
2080 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2084 * typedef enum { ... } SilcClientMonitorStatus;
2088 * File transmission session status types. These will indicate
2089 * the status of the file transmission session.
2094 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2095 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2096 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2097 SILC_CLIENT_FILE_MONITOR_GET,
2098 SILC_CLIENT_FILE_MONITOR_PUT,
2099 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2100 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2101 } SilcClientMonitorStatus;
2104 /****d* silcclient/SilcClientAPI/SilcClientFileError
2108 * typedef enum { ... } SilcClientFileError;
2112 * File transmission error types. These types are returned by
2113 * some of the file transmission functions, and by the monitor
2114 * callback to indicate error.
2119 SILC_CLIENT_FILE_OK,
2120 SILC_CLIENT_FILE_ERROR,
2121 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2122 SILC_CLIENT_FILE_ALREADY_STARTED,
2123 SILC_CLIENT_FILE_NO_SUCH_FILE,
2124 SILC_CLIENT_FILE_PERMISSION_DENIED,
2125 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2126 } SilcClientFileError;
2129 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2133 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2134 * SilcClientConnection conn,
2135 * SilcClientMonitorStatus status,
2136 * SilcClientFileError error,
2137 * SilcUInt64 offset,
2138 * SilcUInt64 filesize,
2139 * SilcClientEntry client_entry,
2140 * SilcUInt32 session_id,
2141 * const char *filepath,
2146 * Monitor callback that is called during the file transmission to
2147 * monitor the transmission process. The `status' indicates the current
2148 * monitoring process. The `error' will indicate the error type
2149 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2150 * currently transmitted amount of total `filesize'. The `client_entry'
2151 * indicates the remote client, and the transmission session ID is the
2152 * `session_id'. The filename being transmitted is indicated by the
2156 typedef void (*SilcClientFileMonitor)(SilcClient client,
2157 SilcClientConnection conn,
2158 SilcClientMonitorStatus status,
2159 SilcClientFileError error,
2161 SilcUInt64 filesize,
2162 SilcClientEntry client_entry,
2163 SilcUInt32 session_id,
2164 const char *filepath,
2167 /****f* silcclient/SilcClientAPI/silc_client_file_send
2171 * SilcClientFileError
2172 * silc_client_file_send(SilcClient client,
2173 * SilcClientConnection conn,
2174 * SilcClientFileMonitor monitor,
2175 * void *monitor_context,
2176 * const char *local_ip,
2177 * SilcUInt32 local_port,
2178 * SilcClientEntry client_entry,
2179 * const char *filepath);
2180 * SilcUInt32 *session_id);
2184 * Sends a file indicated by the `filepath' to the remote client
2185 * indicated by the `client_entry'. This will negotiate a secret key
2186 * with the remote client before actually starting the transmission of
2187 * the file. The `monitor' callback will be called to monitor the
2188 * transmission of the file.
2190 * This returns a file session ID for the file transmission to the
2191 * `session_id' pointer.. It can be used to close the session (and
2192 * abort the file transmission) by calling the silc_client_file_close
2193 * function. The session ID is also returned in the `monitor' callback.
2195 * If the `local_ip' is provided then this will try to bind the
2196 * listener for key exchange protocol to that IP. If `local_port' is
2197 * non-zero that port is used. If `local_ip' is NULL then this will
2198 * automatically attempt to bind it to local IP address of the machine.
2199 * If that fails then this does not bind to any address and port, and
2200 * assume that the remote client will provide the listener for the
2201 * key exchange protocol.
2203 * If error will occur during the file transfer process the error
2204 * status will be returned in the monitor callback. In this case
2205 * the application must call silc_client_file_close to close the
2210 silc_client_file_send(SilcClient client,
2211 SilcClientConnection conn,
2212 SilcClientFileMonitor monitor,
2213 void *monitor_context,
2214 const char *local_ip,
2215 SilcUInt32 local_port,
2216 SilcClientEntry client_entry,
2217 const char *filepath,
2218 SilcUInt32 *session_id);
2220 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2224 * SilcClientFileError
2225 * silc_client_file_receive(SilcClient client,
2226 * SilcClientConnection conn,
2227 * SilcClientFileMonitor monitor,
2228 * void *monitor_context,
2230 * SilcUInt32 session_id);
2234 * Receives a file from a client indicated by the `client_entry'. The
2235 * `session_id' indicates the file transmission session and it has been
2236 * received in the `ftp' client operation function. This will actually
2237 * perform the key agreement protocol with the remote client before
2238 * actually starting the file transmission. The `monitor' callback
2239 * will be called to monitor the transmission. If `path' is non NULL
2240 * the file will be saved into that directory. If NULL the file is
2241 * saved in the current working directory.
2243 * If error will occur during the file transfer process the error
2244 * status will be returned in the monitor callback. In this case
2245 * the application must call silc_client_file_close to close the
2250 silc_client_file_receive(SilcClient client,
2251 SilcClientConnection conn,
2252 SilcClientFileMonitor monitor,
2253 void *monitor_context,
2255 SilcUInt32 session_id);
2257 /****f* silcclient/SilcClientAPI/silc_client_file_close
2261 * SilcClientFileError silc_client_file_close(SilcClient client,
2262 * SilcClientConnection conn,
2263 * SilcUInt32 session_id);
2267 * Closes file transmission session indicated by the `session_id'.
2268 * If file transmission is being conducted it will be aborted
2269 * automatically. This function is also used to close the session
2270 * after successful file transmission. This function can be used
2271 * also to reject incoming file transmission request.
2274 SilcClientFileError silc_client_file_close(SilcClient client,
2275 SilcClientConnection conn,
2276 SilcUInt32 session_id);
2278 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2282 * SilcAttributePayload
2283 * silc_client_attribute_add(SilcClient client,
2284 * SilcClientConnection conn,
2285 * SilcAttribute attribute,
2287 * SilcUInt32 object_size);
2291 * Add new Requsted Attribute for WHOIS command to the client library.
2292 * The `attribute' object indicated by `object' is added and allocated
2293 * SilcAttributePayload is returned. The `object' must be of correct
2294 * type and of correct size. See the SilcAttribute for object types
2295 * for different attributes. You may also get all added attributes
2296 * from the client with silc_client_attributes_get function.
2298 * Requested Attributes are different personal information about the
2299 * user, status information and other information which other users
2300 * may query with WHOIS command. Application may set these so that
2301 * if someone sends WHOIS query these attributes will be replied back
2302 * to the sender. The library always puts the public key to the
2303 * Requested Attributes, but if application wishes to add additional
2304 * public keys (or certificates) it can be done with this interface.
2305 * Library also always computes digital signature of the attributes
2306 * automatically, so application does not need to do that.
2309 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2310 SilcClientConnection conn,
2311 SilcAttribute attribute,
2313 SilcUInt32 object_size);
2315 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2319 * bool silc_client_attribute_del(SilcClient client,
2320 * SilcClientConnection conn,
2321 * SilcAttribute attribute,
2322 * SilcAttributePayload attr);
2326 * Delete a Requested Attribute from the client. If the `attribute'
2327 * is non-zero then all attributes of that type are deleted and the
2328 * `attr' is ignored. If `attr' is non-NULL then that specific
2329 * attribute is deleted and `attribute' is ignored.
2331 * You may get all added attributes with the function
2332 * silc_client_attributes_get and to get the SilcAttributePayload.
2333 * This function Returns TRUE if the attribute was found and deleted.
2336 bool silc_client_attribute_del(SilcClient client,
2337 SilcClientConnection conn,
2338 SilcAttribute attribute,
2339 SilcAttributePayload attr);
2341 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2345 * const SilcHashTable
2346 * silc_client_attributes_get(SilcClient client,
2347 * SilcClientConnection conn);
2351 * Returns pointer to the SilcHashTable which includes all the added
2352 * Requested Attributes. The caller must not free the hash table.
2353 * The caller may use SilcHashTableList and silc_hash_table_list to
2354 * traverse the table. Each entry in the hash table is one added
2355 * SilcAttributePayload. It is possible to delete a attribute
2356 * payload while traversing the table.
2359 const SilcHashTable silc_client_attributes_get(SilcClient client,
2360 SilcClientConnection conn);
2362 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2366 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2370 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2371 * then all attributes are requested. Alternatively, `attribute' and
2372 * all variable arguments can each be requested attribute. In this case
2373 * the last must be set to zero (0) to complete the variable list of
2374 * requested attributes. See SilcAttribute for all attributes.
2375 * You can give the returned buffer as argument to for example
2376 * silc_client_get_client_by_id_resolve function.
2379 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2381 /* Low level packet sending functions */
2383 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2387 * bool silc_client_send_packet(SilcClient client,
2388 * SilcClientConnection conn,
2389 * SilcPacketType type,
2390 * const unsigned char *data,
2391 * SilcUInt32 data_len);
2395 * This routine can be used by application to send packets directly
2396 * to a connection indicated by `conn'. Usually application does not
2397 * need this routine since the Client Library handles the packet
2398 * sending. The `type' indicates the packet type. If `data' is
2399 * NULL then empty packet is sent. This returns FALSE if packet cannot
2403 bool silc_client_send_packet(SilcClient client,
2404 SilcClientConnection conn,
2405 SilcPacketType type,
2406 const unsigned char *data,
2407 SilcUInt32 data_len);
2409 #include "command.h"
2410 #include "command_reply.h"
2412 #include "protocol.h"
2418 #endif /* SILCCLIENT_H */