5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2007 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.
55 #include "silcclient_entry.h"
57 /* General definitions */
59 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
63 * typedef enum { ... } SilcClientConnectionStatus
67 * This type is returned to the `connect' client operation to indicate
68 * the status of the created connection. It can indicate if it was
69 * successful or whether an error occurred.
74 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
75 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
76 resumed old detached session */
77 SILC_CLIENT_CONN_DISCONNECTED, /* Remote host disconnected */
78 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
79 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
80 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
81 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
82 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
83 } SilcClientConnectionStatus;
86 /****f* silcclient/SilcClientAPI/SilcClientRunning
90 * typedef void (*SilcClientRunning)(SilcClient client, void *context);
94 * The callback given as argument to silc_client_init function. Once
95 * this is called the client library is running and application may
96 * start using the Client library API.
99 typedef void (*SilcClientRunning)(SilcClient client, void *context);
101 /****f* silcclient/SilcClientAPI/SilcClientStopped
105 * typedef void (*SilcClientStopped)(SilcClient client, void *context);
109 * The callback given as argument to silc_client_stop. Once this is
110 * called the client library has stopped and can be freed by calling
111 * silc_client_free. Note that this won't be called if there are
112 * active connections in the client. Connections must first be closed
113 * by calling silc_client_close_connection or by sending QUIT command to
114 * the server connection.
117 typedef void (*SilcClientStopped)(SilcClient client, void *context);
119 /****f* silcclient/SilcClientAPI/SilcClientConnectCallback
123 * void (*SilcClientConnectCallback)(SilcClient client,
124 * SilcClientConnection conn,
125 * SilcClientConnectionStatus status,
127 * const char *message,
132 * Connect callbak given as argument to silc_client_connect_to_server,
133 * silc_client_connect_to_client and silc_client_key_exchange functions.
134 * It is called to indicate the status of the connection, indicated
135 * by the `status'. It is called after the connection has been
136 * established to the remote host and when connection is disconnected
137 * by the remote host. The `context' is the context given as argument
138 * to the connecting function. If the `status' is an error the `error'
139 * may indicate more detailed error. If `error' is SILC_STATUS_OK no
140 * detailed error message is available.
142 * When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will
143 * indicate the reason for disconnection. If the `message' is non-NULL
144 * it delivers error or disconnection message.
147 typedef void (*SilcClientConnectCallback)(SilcClient client,
148 SilcClientConnection conn,
149 SilcClientConnectionStatus status,
154 /****s* silcclient/SilcClientAPI/SilcClient
158 * typedef struct SilcClientStruct { ... } *SilcClient
162 * This is the actual SILC Client structure which represents one
163 * SILC Client. It is allocated with the silc_client_alloc function
164 * and given as argument to all SILC Client Library functions. It
165 * is initialized with silc_client_init function, and freed with
166 * silc_client_free function.
168 * This context represents the client. Each connection to remote server
169 * is represented by SilcClientConnection context.
173 struct SilcClientStruct {
174 char *username; /* Username */
175 char *hostname; /* hostname */
176 char *realname; /* Real name */
177 SilcSchedule schedule; /* Client scheduler */
178 SilcRng rng; /* Random number generator */
179 void *application; /* Application specific context, set with
180 silc_client_alloc. */
182 /* Internal data for client library. Application cannot access this. */
183 SilcClientInternal internal;
187 /****s* silcclient/SilcClientAPI/SilcClientConnection
191 * typedef struct SilcClientConnectionStruct { ... }
192 * *SilcClientConnection
196 * This structure represents a connection. It is allocated and freed by
197 * the library. It is returned to application in SilcClientConnectCallback.
198 * It includes all the important data for the session such as local
199 * client entry (which includes current nickname), local and remote IDs,
200 * and other information. All strings in the structure are UTF-8 encoded.
204 struct SilcClientConnectionStruct {
205 SilcClientEntry local_entry; /* Our own Client Entry */
206 SilcClientID *local_id; /* Our current Client ID */
208 char *remote_host; /* Remote host name */
209 int remote_port; /* Remote port */
210 SilcID remote_id; /* Remote ID */
212 SilcChannelEntry current_channel; /* Current joined channel */
213 SilcPublicKey public_key; /* Public key used in this connection */
214 SilcPrivateKey private_key; /* Private key */
215 SilcPacketStream stream; /* Connection to remote host */
216 SilcConnectionType type; /* Connection type */
217 SilcClientConnectCallback callback; /* Connection callback */
218 void *callback_context; /* Connection context */
219 SilcClient client; /* Pointer back to SilcClient */
221 /* Application specific data. Application may set here whatever it wants. */
224 /* Internal data for client library. Application cannot access this. */
225 SilcClientConnectionInternal internal;
229 /****s* silcclient/SilcClientAPI/SilcChannelUser
233 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
237 * This structure represents a client that has joined to a channel.
238 * It shows the client and the channel and the client's mode (channel
239 * user mode) on the channel.
243 struct SilcChannelUserStruct {
244 SilcClientEntry client; /* Client joined on channel */
245 SilcUInt32 mode; /* mode, ChannelUserModes */
246 SilcChannelEntry channel; /* The channel user has joined */
248 /* Application specific data. Application may set here whatever it wants. */
253 /****s* silcclient/SilcClientAPI/SilcClientStats
257 * typedef struct { ... } SilcClientStats;
261 * This structure holds SILC network statistics returned by the
262 * SILC_COMMAND_STATS command reply to the application.
267 SilcUInt32 starttime; /* SILC server start time */
268 SilcUInt32 uptime; /* SILC server uptime*/
269 SilcUInt32 my_clients; /* Number of clients in the server */
270 SilcUInt32 my_channels; /* Number of channel in the server */
271 SilcUInt32 my_server_ops; /* Number of server operators in the server */
272 SilcUInt32 my_router_ops; /* Number of router operators in the router */
273 SilcUInt32 cell_clients; /* Number of clients in the cell */
274 SilcUInt32 cell_channels; /* Number of channels in the cell */
275 SilcUInt32 cell_servers; /* Number of server in the cell */
276 SilcUInt32 clients; /* All clients in SILC network */
277 SilcUInt32 channels; /* All channels in SILC network */
278 SilcUInt32 servers; /* All servers in SILC network */
279 SilcUInt32 routers; /* All routers in SILC network */
280 SilcUInt32 server_ops; /* All server operators in SILC network */
281 SilcUInt32 router_ops; /* All router operators in SILC network */
285 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
289 * typedef enum { ... } SilcKeyAgreementStatus;
293 * Key agreement status types indicating the status of the key
294 * agreement protocol. These types are returned to the application
295 * in the SilcKeyAgreementCallback callback function.
300 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
301 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
302 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
303 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
304 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
305 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
306 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
307 SILC_KEY_AGREEMENT_NO_MEMORY, /* System out of memory */
308 } SilcKeyAgreementStatus;
311 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
315 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
316 * SilcClientConnection conn,
317 * SilcClientEntry client_entry,
318 * SilcKeyAgreementStatus status,
319 * SilcSKEKeyMaterial *key,
324 * Key agreement callback that is called after the key agreement protocol
325 * has been performed. This is called also if error occurred during the
326 * key agreement protocol. The `key' is the allocated key material and
327 * the caller is responsible of freeing it. The `key' is NULL if error
328 * has occurred. The application can freely use the `key' to whatever
329 * purpose it needs. See lib/silcske/silcske.h for the definition of
330 * the SilcSKEKeyMaterial structure.
333 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
334 SilcClientConnection conn,
335 SilcClientEntry client_entry,
336 SilcKeyAgreementStatus status,
337 SilcSKEKeyMaterial key,
340 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
344 * typedef struct { ... } SilcPrivateMessageKeys;
348 * Structure to hold the list of private message keys. The list of these
349 * structures is returned by the silc_client_list_private_message_keys
355 SilcClientEntry client_entry; /* The remote client entry */
356 char *cipher; /* The cipher name */
357 unsigned char *key; /* The original key, If the appliation
358 provided it. This is NULL if
359 the SKE key material was used. */
360 SilcUInt32 key_len; /* The key length */
361 } *SilcPrivateMessageKeys;
364 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
368 * typedef struct SilcChannelPrivateKeyStruct { ... }
369 * *SilcChannelPrivateKey;
373 * Structure to hold one channel private key. The array of this structure
374 * is returned by silc_client_list_channel_private_keys function.
378 struct SilcChannelPrivateKeyStruct {
379 char *name; /* Application given name */
380 SilcCipher cipher; /* The cipher and key */
381 SilcHmac hmac; /* The HMAC and hmac key */
385 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
389 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
390 * SilcUInt32 passphrase_len,
395 * Ask passphrase callback. This is called by the application when the
396 * library calls `ask_passphrase' client operation. The callback delivers
397 * the passphrase to the library. The passphrases in SILC protocol
398 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
399 * encoded, and if it is not then library will attempt to encode it.
402 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
403 SilcUInt32 passphrase_len,
406 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
410 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
414 * Public key (or certificate) verification callback. This is called
415 * by the application to indicate that the public key verification was
416 * either success or failure.
419 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
421 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
425 * typedef void (*SilcGetAuthMeth)(SilcBool success,
426 * SilcAuthMethod auth_meth,
427 * void *auth, SilcUInt32 auth_len,
432 * Authentication data resolving callback. This is called by the
433 * application to return the resolved authentication data. The client
434 * library has called the get_auth_method client operation and given
435 * this function pointer as argument. The `auth_meth' is the selected
436 * authentication method. The `auth_data' and the `auth_data_len'
437 * are the resolved authentication data. The `context' is the libary's
438 * context sent to the get_auth_method client operation.
440 * If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len'
441 * is the passphrase and its length. If it is SILC_AUTH_PUBLIC_KEY the
442 * `auth' must be NULL. The library will use the private key given as
443 * argument to silc_client_connect_to_server, silc_client_connect_to_client
444 * or silc_client_key_exchange. If it is SILC_AUTH_NONE, both `auth' and
445 * `auth_len' are ignored.
448 typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth,
449 void *auth, SilcUInt32 auth_len,
452 /****d* silcclient/SilcClientAPI/SilcClientMessageType
456 * typedef enum { ... } SilcClientMessageType;
460 * Different message types for `say' client operation. The application
461 * may filter the message sent by the library according this type.
466 SILC_CLIENT_MESSAGE_INFO, /* Informational */
467 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
468 SILC_CLIENT_MESSAGE_ERROR, /* Error */
469 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
470 } SilcClientMessageType;
473 /****s* silcclient/SilcClientAPI/SilcClientOperations
477 * typedef struct { ... } SilcClientOperations;
481 * SILC Client Operations. These must be implemented by the application.
482 * The Client library may call any of these routines at any time. The
483 * routines are used to deliver certain information to the application
484 * or from the application to the client library.
489 /* Message sent to the application by library. `conn' associates the
490 message to a specific connection. `conn', however, may be NULL.
491 The `type' indicates the type of the message sent by the library.
492 The application can for example filter the message according the
493 type. The variable argument list is arguments to the formatted
494 message that `msg' may be. */
495 void (*say)(SilcClient client, SilcClientConnection conn,
496 SilcClientMessageType type, char *msg, ...);
498 /* Message for a channel. The `sender' is the sender of the message
499 The `channel' is the channel. The `message' is the message. Note
500 that `message' maybe NULL. The `flags' indicates message flags
501 and it is used to determine how the message can be interpreted
502 (like it may tell the message is multimedia message). */
503 void (*channel_message)(SilcClient client, SilcClientConnection conn,
504 SilcClientEntry sender, SilcChannelEntry channel,
505 SilcMessagePayload payload,
506 SilcChannelPrivateKey key, SilcMessageFlags flags,
507 const unsigned char *message,
508 SilcUInt32 message_len);
510 /* Private message to the client. The `sender' is the sender of the
511 message. The message is `message'and maybe NULL. The `flags'
512 indicates message flags and it is used to determine how the message
513 can be interpreted (like it may tell the message is multimedia
515 void (*private_message)(SilcClient client, SilcClientConnection conn,
516 SilcClientEntry sender, SilcMessagePayload payload,
517 SilcMessageFlags flags, const unsigned char *message,
518 SilcUInt32 message_len);
520 /* Notify message to the client. The notify arguments are sent in the
521 same order as servers sends them. The arguments are same as received
522 from the server except for ID's. If ID is received application receives
523 the corresponding entry to the ID. For example, if Client ID is received
524 application receives SilcClientEntry. Also, if the notify type is
525 for channel the channel entry is sent to application (even if server
526 does not send it because client library gets the channel entry from
527 the Channel ID in the packet's header). */
528 void (*notify)(SilcClient client, SilcClientConnection conn,
529 SilcNotifyType type, ...);
531 /* Command handler. This function is called always after application has
532 called a command. It will be called to indicate that the command
533 was processed. It will also be called if error occurs while processing
534 the command. The `success' indicates whether the command was sent
535 or if error occurred. The `status' indicates the actual error.
536 The `argc' and `argv' are the command line arguments sent to the
537 command by application. Note that, this is not reply to the command
538 from server, this is merely and indication to application that the
539 command was processed. */
540 void (*command)(SilcClient client, SilcClientConnection conn,
541 SilcBool success, SilcCommand command, SilcStatus status,
542 SilcUInt32 argc, unsigned char **argv);
544 /* Command reply handler. This function is called always in the command reply
545 function. If error occurs it will be called as well. Normal scenario
546 is that it will be called after the received command data has been parsed
547 and processed. The function is used to pass the received command data to
550 `conn' is the associated client connection. `cmd_payload' is the command
551 payload data received from server and it can be ignored. It is provided
552 if the application would like to re-parse the received command data,
553 however, it must be noted that the data is parsed already by the library
554 thus the payload can be ignored. `success' is FALSE if error occurred.
555 In this case arguments are not sent to the application. The `status' is
556 the command reply status server returned. The `command' is the command
557 reply being processed. The function has variable argument list and each
558 command defines the number and type of arguments it passes to the
559 application (on error they are not sent).
561 The arguments are sent in the same order as servers sends them. The
562 arguments are same as received from the server except for ID's. If
563 ID is received application receives the corresponding entry to the
564 ID. For example, if Client ID is receives application receives
566 void (*command_reply)(SilcClient client, SilcClientConnection conn,
567 SilcCommand command, SilcStatus status,
568 SilcStatus error, va_list ap);
570 /* Find authentication method and authentication data by hostname and
571 port. The hostname may be IP address as well. The `auth_method' is
572 the authentication method the remote connection requires. It is
573 however possible that remote accepts also some other authentication
574 method. Application should use the method that may have been
575 configured for this connection. If none has been configured it should
576 use the required `auth_method'. If the `auth_method' is
577 SILC_AUTH_NONE, server does not require any authentication or the
578 required authentication method is not known. The `completion'
579 callback must be called to deliver the chosen authentication method
580 and data. The `conn' may be NULL. */
581 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
582 char *hostname, SilcUInt16 port,
583 SilcAuthMethod auth_method,
584 SilcGetAuthMeth completion, void *context);
586 /* Verifies received public key. The `conn_type' indicates which entity
587 (server or client) has sent the public key. If user decides to trust
588 the key the application may save the key as trusted public key for
589 later use. The `completion' must be called after the public key has
591 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
592 SilcConnectionType conn_type,
593 SilcPublicKey public_key,
594 SilcVerifyPublicKey completion, void *context);
596 /* Ask (interact, that is) a passphrase from user. The passphrase is
597 returned to the library by calling the `completion' callback with
598 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
599 if not then the library will attempt to encode. */
600 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
601 SilcAskPassphrase completion, void *context);
603 /* Called to indicate that incoming key agreement request has been
604 received. If the application wants to perform key agreement it may
605 call silc_client_perform_key_agreement to initiate key agreementn or
606 silc_client_send_key_agreement to provide connection point to the
607 remote client in case the `hostname' is NULL. If key agreement is
608 not desired this request can be ignored. The `protocol' is either
609 value 0 for TCP or value 1 for UDP. */
610 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
611 SilcClientEntry client_entry,
612 const char *hostname, SilcUInt16 protocol,
615 /* Notifies application that file transfer protocol session is being
616 requested by the remote client indicated by the `client_entry' from
617 the `hostname' and `port'. The `session_id' is the file transfer
618 session and it can be used to either accept or reject the file
619 transfer request, by calling the silc_client_file_receive or
620 silc_client_file_close, respectively. */
621 void (*ftp)(SilcClient client, SilcClientConnection conn,
622 SilcClientEntry client_entry, SilcUInt32 session_id,
623 const char *hostname, SilcUInt16 port);
624 } SilcClientOperations;
627 /****s* silcclient/SilcClientAPI/SilcClientParams
631 * typedef struct { ... } SilcClientParams;
635 * Client parameters. This can be filled with proper values and
636 * given as argument to the silc_client_alloc function. The structure
637 * hold various parameters which affects the function of the client.
642 /* If this boolean is set to TRUE then the client library will use
643 threads. Any of the callback functions in the SilcClientOperations
644 and other callbacks may be called at any time in a thread. The
645 application may need to employ appropriate concurrency control
646 in the callbacks to protect application specific data. */
649 /* Nickname format string. This can be used to order the client library
650 to save the nicknames in the library in a certain format. Since
651 nicknames are not unique in SILC it is possible to have multiple same
652 nicknames. Using this format string it is possible to order the library
653 to separate the multiple same nicknames from each other. If this is
654 empty then default format is used which is the default nickname
655 without anything else. The string MUST be NULL terminated.
657 Following format types are available:
659 %n nickname - the real nickname returned by the server (mandatory)
660 %h hostname - the stripped hostname of the client
661 %H full hostname - the full hostname of the client
662 %s server name - the server name the client is connected
663 %S full server - the full server name the client is connected
664 %a number - ascending number in case there are several
665 same nicknames (fe. nick@host and nick@host2)
667 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
668 "%a!%n@%s" (fe. nick@server, 2!nick@server)
669 "%n@%H" (fe. nick@host.domain.com)
671 Note that there must always be some separator characters around '%n'
672 format. It is not possible to put format characters before or after
673 '%n' without separators (such ash '@'). Also note that the separator
674 character should be a character that cannot be part of normal nickname.
676 char nickname_format[32];
678 /* If this is set to TRUE then the `nickname_format' is employed to all
679 saved nicknames even if there are no multiple same nicknames in the
680 cache. By default this is FALSE, which means that the `nickname_format'
681 is employed only if the library will receive a nickname that is
682 already saved in the cache. It is recommended to leave this to FALSE
684 SilcBool nickname_force_format;
686 /* If this is set to TRUE, the silcclient library will not register and
687 deregister the cipher, pkcs, hash and hmac algorithms. The application
688 itself will need to handle that. */
689 SilcBool dont_register_crypto_library;
695 /* Initialization functions (client.c) */
697 /****f* silcclient/SilcClientAPI/silc_client_alloc
701 * SilcClient silc_client_alloc(SilcClientOperations *ops,
702 * SilcClientParams *params,
704 * const char *silc_version);
708 * Allocates new client object. This has to be done before client may
709 * work. After calling this one must call silc_client_init to initialize
710 * the client. The `application' is application specific user data pointer
711 * and caller must free it. The `silc_version' is the application version
712 * that will be used to compare against remote host's (usually a server)
713 * version string. The `application' context is accessible by the
714 * application by client->application, client being SilcClient.
717 SilcClient silc_client_alloc(SilcClientOperations *ops,
718 SilcClientParams *params,
720 const char *version_string);
722 /****f* silcclient/SilcClientAPI/silc_client_free
726 * void silc_client_free(SilcClient client);
730 * Frees client object and its internals. The execution of the client
731 * should be stopped with silc_client_stop function before calling
735 void silc_client_free(SilcClient client);
737 /****f* silcclient/SilcClientAPI/silc_client_init
741 * SilcBool silc_client_init(SilcClient client, const char *username,
742 * const char *hostname, const char *realname,
743 * SilcClientRunning running, void *context);
747 * Initializes the client. This makes all the necessary steps to make
748 * the client ready to be run. One must call silc_client_run to run the
749 * client. Returns FALSE if error occurred, TRUE otherwise.
751 * The `username' and `hostname' strings must be given and they must be
752 * UTF-8 encoded. The `username' is the client's username in the
753 * operating system, `hostname' is the client's host name and the
754 * `realname' is the user's real name.
756 * The `running' callback is called after the client is running after
757 * silc_client_run or silc_client_run_one has been called. Application
758 * may start using the Client library API after that. Setting the
759 * callback is optional, but recommended.
762 SilcBool silc_client_init(SilcClient client, const char *username,
763 const char *hostname, const char *realname,
764 SilcClientRunning running, void *context);
766 /****f* silcclient/SilcClientAPI/silc_client_run
770 * void silc_client_run(SilcClient client);
774 * Runs the client. This starts the scheduler from the utility library.
775 * When this functions returns the execution of the application is over.
776 * The client must be initialized before calling this.
779 void silc_client_run(SilcClient client);
781 /****f* silcclient/SilcClientAPI/silc_client_run_one
785 * void silc_client_run_one(SilcClient client);
789 * Runs the client and returns immeadiately. This function is used when
790 * the SILC Client object indicated by the `client' is run under some
791 * other scheduler, or event loop or main loop. On GUI applications,
792 * for example this may be desired to used to run the client under the
793 * GUI application's main loop. Typically the GUI application would
794 * register an idle task that calls this function multiple times in
795 * a second to quickly process the SILC specific data.
798 void silc_client_run_one(SilcClient client);
800 /****f* silcclient/SilcClientAPI/silc_client_stop
804 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
809 * Stops the client. This is called to stop the client and thus to stop
810 * the program. The client context must be freed with the silc_client_free
811 * function. All connections that exist in this client must be closed
812 * before calling this function. Connections can be closed by calling
813 * silc_client_close_connection.
815 * The `stopped' will be called once the client and all connections have
816 * finished. The client may be freed after that. Note that the `stopped'
817 * won't be called before all connections have finished. Setting the
818 * callback is optional.
821 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
824 /* Connecting functions */
826 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
830 * typedef struct { ... } SilcClientConnectionParams;
834 * Client connection parameters. This can be filled by the application
835 * and given as argument to silc_client_connect_to_server,
836 * silc_client_connect_to_client, silc_client_key_exchange or
837 * silc_client_send_key_agreement.
842 /* If this is provided the user's nickname in the network will be the
843 string given here. If it is given, it must be UTF-8 encoded. If this
844 string is not given, the user's username by default is used as nickname.
845 The nickname may later be changed by using NICK command. The maximum
846 length for the nickname string is 128 bytes. */
849 /* If this key repository pointer is non-NULL then public key received in
850 the key exchange protocol will be verified from this repository. If
851 this is not provided then the `verify_public_key' client operation will
852 be called back to application. If the boolean `verify_notfound' is set
853 to TRUE then the `verify_public_key' client operation will be called
854 in case the public key is not found in `repository'. Only public keys
855 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
856 be checked, other keys will be ignored. */
858 SilcBool verify_notfound;
860 /* Authentication data. Application may set here the authentication data
861 and authentication method to be used in connecting. If `auth_set'
862 boolean is TRUE then authentication data is provided by application.
863 If the authentication method is public key authentication then the key
864 pair given as argument when connecting will be used and `auth' field
865 is NULL. If it is passphrase authentication, it can be provided in
866 `auth' and `auth_len' fields. If `auth_set' is FALSE
867 the `get_auth_method' client operation will be called to get the
868 authentication method and data from application. */
870 SilcAuthMethod auth_method;
874 /* If this boolean is set to TRUE then the connection will use UDP instead
875 of TCP. If UDP is set then also the next `local_ip' and `local_port'
879 /* The `local_ip' specifies the local IP address used with the connection.
880 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
881 non-zero it will be used as local port with UDP connection. The remote
882 host will also send packets to the specified address and port. If the
883 `bind_ip' is non-NULL a listener is bound to that address instead of
889 /* If this boolean is set to TRUE then the key exchange is done with
890 perfect forward secrecy. */
893 /* If this boolean is set to TRUE then connection authentication protocol
894 is not performed during connecting. Only key exchange protocol is
895 performed. This usually must be set to TRUE when connecting to another
896 client, but must be FALSE with server connections. */
897 SilcBool no_authentication;
899 /* The SILC session detachment data that was returned in the `command_reply'
900 client operation for SILC_COMMAND_DETACH command. If this is provided
901 here the client library will attempt to resume the session in the network.
902 After the connection is created and the session has been resumed the
903 client will receive SILC_COMMAND_NICK command_reply for the client's
904 nickname in the network and SILC_COMMAND_JOIN command reply for all the
905 channels that the client has joined in the network. It may also receive
906 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
907 unsigned char *detach_data;
908 SilcUInt32 detach_data_len;
910 /* Connection timeout. If non-zero, the connection will timeout unless
911 the SILC connection is completed in the specified amount of time. */
912 SilcUInt32 timeout_secs;
914 /* Rekey timeout in seconds. The client will perform rekey in this
915 time interval. If set to zero, the default value will be used
916 (3600 seconds, 1 hour). */
917 SilcUInt32 rekey_secs;
919 /* If this is set to TRUE then the client will ignore all incoming
920 Requested Attributes queries and does not reply anything back. This
921 usually leads into situation where server does not anymore send
922 the queries after seeing that client does not reply anything back.
923 If your application does not support Requested Attributes or you do
924 not want to use them set this to TRUE. See SilcAttribute and
925 silc_client_attribute_add for more information on attributes. */
926 SilcBool ignore_requested_attributes;
928 } SilcClientConnectionParams;
931 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
936 * silc_client_connect_to_server(SilcClient client,
937 * SilcClientConnectionParams *params,
938 * SilcPublicKey public_key,
939 * SilcPrivateKey private_key,
940 * char *remote_host, int port,
941 * SilcClientConnectCallback callback,
946 * Connects to remote server `remote_host' at port `port'. This function
947 * can be used to create connection to remote SILC server and start
948 * SILC session in the SILC network. The `params' may be provided
949 * to provide various connection parameters. The `public_key' and the
950 * `private_key' is your identity used in this connection. When
951 * authentication method is based on digital signatures, this key pair
952 * will be used. The `callback' with `context' will be called after the
953 * connection has been created. It will also be called later when remote
956 * If application wishes to create the network connection itself, use
957 * the silc_client_key_exchange after creating the connection to start
958 * key exchange and authentication with the server.
960 * Returns SilcAsyncOperation which can be used to cancel the connecting,
961 * or NULL on error. Note that the returned pointer becomes invalid
962 * after the `callback' is called.
966 silc_client_connect_to_server(SilcClient client,
967 SilcClientConnectionParams *params,
968 SilcPublicKey public_key,
969 SilcPrivateKey private_key,
970 char *remote_host, int port,
971 SilcClientConnectCallback callback,
974 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
979 * silc_client_connect_to_client(SilcClient client,
980 * SilcClientConnectionParams *params,
981 * SilcPublicKey public_key,
982 * SilcPrivateKey private_key,
983 * char *remote_host, int port,
984 * SilcClientConnectCallback callback,
989 * Connects to remote client `remote_host' at port `port'. This function
990 * can be used to create peer-to-peer connection to another SILC client,
991 * for example, for direct conferencing, or file transfer or for other
992 * purposes. The `params' may be provided to provide various connection
993 * parameters. The `public_key' and the `private_key' is your identity
994 * used in this connection. The `callback' with `context' will be called
995 * after the connection has been created. It will also be called later
996 * when remote host disconnects.
998 * If application wishes to create the network connection itself, use
999 * the silc_client_key_exchange after creating the connection to start
1000 * key exchange with the client.
1002 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1003 * or NULL on error. Note that the returned pointer becomes invalid
1004 * after the `callback' is called.
1008 silc_client_connect_to_client(SilcClient client,
1009 SilcClientConnectionParams *params,
1010 SilcPublicKey public_key,
1011 SilcPrivateKey private_key,
1012 char *remote_host, int port,
1013 SilcClientConnectCallback callback,
1016 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1020 * SilcAsyncOperation
1021 * silc_client_key_exchange(SilcClient client,
1022 * SilcClientConnectionParams *params,
1023 * SilcPublicKey public_key,
1024 * SilcPrivateKey private_key,
1025 * SilcStream stream,
1026 * SilcConnectionType conn_type,
1027 * SilcClientConnectCallback callback,
1032 * Starts key exchange protocol and authentication protocol in the
1033 * connection indicated by `stream'. This function can be be used to
1034 * start SILC session with remote host (usually server) when the caller
1035 * has itself created the connection, instead of calling the function
1036 * silc_client_connect_to_server or silc_client_connect_to_client. If
1037 * one of those functions was used this function must not be called as
1038 * in that case the key exchange is performed automatically.
1040 * Use this function only if you have created the connection by yourself.
1041 * After creating the connection the socket must be wrapped into a
1042 * socket stream. See silcsocketstream.h for more information. Note that
1043 * the `stream' must have valid remote IP address (and optionally also
1044 * hostname) and port set.
1046 * The `params' may be provided to provide various connection parameters.
1047 * The `public_key' and the `private_key' is your identity used in this
1048 * session. The `callback' with `context' will be called after the session
1049 * has been set up. It will also be called later when remote host
1050 * disconnects. The `conn_type' is the type of session this is going to
1053 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1054 * or NULL on error. Note that the returned pointer becomes invalid
1055 * after the `callback' is called.
1061 * // Create remote connection stream. Resolve hostname and IP also.
1062 * sock = create_connection(remote_host, port);
1063 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1064 * stream_create_cb, app);
1066 * // Stream callback delivers our new SilcStream context
1067 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1071 * if (status != SILC_SOCKET_OK)
1074 * // Start key exchange
1075 * silc_client_key_exchange(client, NULL, public_key, private_key,
1076 * stream, SILC_CONN_SERVER, connection_cb, app);
1082 silc_client_key_exchange(SilcClient client,
1083 SilcClientConnectionParams *params,
1084 SilcPublicKey public_key,
1085 SilcPrivateKey private_key,
1087 SilcConnectionType conn_type,
1088 SilcClientConnectCallback callback,
1091 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1095 * void silc_client_close_connection(SilcClient client,
1096 * SilcClientConnection conn);
1100 * Closes the remote connection `conn'. The `conn' will become invalid
1101 * after this call. Usually this function is called only when explicitly
1102 * closing connection for example in case of error, or when the remote
1103 * connection was created by the application or when the remote is client
1104 * connection. Server connections are usually closed by sending QUIT
1105 * command to the server. However, this call may also be used.
1108 void silc_client_close_connection(SilcClient client,
1109 SilcClientConnection conn);
1111 /* Message sending functions */
1113 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1117 * SilcBool silc_client_send_channel_message(SilcClient client,
1118 * SilcClientConnection conn,
1119 * SilcChannelEntry channel,
1120 * SilcChannelPrivateKey key,
1121 * SilcMessageFlags flags,
1123 * unsigned char *data,
1124 * SilcUInt32 data_len);
1128 * Sends packet to the `channel'. Packet to channel is always encrypted
1129 * differently from "normal" packets. SILC header of the packet is
1130 * encrypted with the next receiver's key and the rest of the packet is
1131 * encrypted with the channel specific key. Padding and HMAC is computed
1132 * with the next receiver's key. The `data' is the channel message.
1134 * If `key' is provided then that private key is used to encrypt the
1135 * channel message. If it is not provided, private keys has not been
1136 * set at all, the normal channel key is used automatically. If private
1137 * keys are set then the first key (the key that was added first as
1138 * private key) is used.
1140 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1141 * digitally signed with the SILC key pair. In this case the `hash'
1142 * pointer must be provided as well.
1144 * Returns TRUE if the message was sent, and FALSE if error occurred or
1145 * the sending is not allowed due to channel modes (like sending is
1146 * blocked). This function is thread safe and private messages can be
1147 * sent from multiple threads.
1150 SilcBool silc_client_send_channel_message(SilcClient client,
1151 SilcClientConnection conn,
1152 SilcChannelEntry channel,
1153 SilcChannelPrivateKey key,
1154 SilcMessageFlags flags,
1156 unsigned char *data,
1157 SilcUInt32 data_len);
1159 /* Block process until channel message from `channel' is received */
1161 silc_client_receive_channel_message(SilcClient client,
1162 SilcClientConnection conn,
1163 SilcChannelEntry channel,
1164 SilcClientEntry *return_sender,
1165 SilcMessageFlags *return_flags,
1166 const unsigned char **return_message,
1167 SilcUInt32 *return_message_len);
1169 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1173 * SilcBool silc_client_send_private_message(SilcClient client,
1174 * SilcClientConnection conn,
1175 * SilcClientEntry client_entry,
1176 * SilcMessageFlags flags,
1178 * unsigned char *data,
1179 * SilcUInt32 data_len);
1183 * Sends private message to remote client. If private message key has
1184 * not been set with this client then the message will be encrypted using
1185 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1186 * the message will be digitally signed with the SILC key pair. In this
1187 * case the caller must also provide the `hash' pointer.
1189 * Returns TRUE if the message was sent, and FALSE if error occurred.
1190 * This function is thread safe and private messages can be sent from
1194 SilcBool silc_client_send_private_message(SilcClient client,
1195 SilcClientConnection conn,
1196 SilcClientEntry client_entry,
1197 SilcMessageFlags flags,
1199 unsigned char *data,
1200 SilcUInt32 data_len);
1202 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1206 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1207 * SilcClientEntry client_entry);
1211 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1212 * channel indicated by the `channel'. NULL if client is not joined on
1216 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1217 SilcClientEntry client_entry);
1220 /* Command management */
1222 /****f* silcclient/SilcClientAPI/silc_client_command_call
1226 * SilcUInt16 silc_client_command_call(SilcClient client,
1227 * SilcClientConnection conn,
1228 * const char *command_line, ...);
1232 * Calls and executes the command indicated by the `command_name'.
1233 * The `command_line' is a string which includes the command's name and
1234 * its arguments separated with whitespaces (' '). If `command_line'
1235 * is non-NULL then all variable arguments are ignored by default.
1237 * If `command_line' is NULL, then the variable arguments define the
1238 * command's name and its arguments. The first variable argument must
1239 * be the command name. The variable argument list must be terminated
1242 * Returns FALSE if the command is not known and TRUE after command.
1243 * execution. The "command" client operation is called when the
1244 * command is executed to indicate whether the command executed
1245 * successfully or not.
1247 * The "command_reply" client operation will be called when reply is
1248 * received from the server to the command. Application may also use
1249 * the silc_client_command_pending to attach to the command reply.
1250 * The command identifier for silc_client_command_pending function after
1251 * this function call is conn->cmd_ident, which application may use.
1255 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1257 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1261 * This command executes the commands implemented inside the client
1262 * library. These commands are designed for command line applications,
1263 * but GUI application may call them too if needed. Alternatively
1264 * application may override the library and use silc_client_command_send
1268 SilcUInt16 silc_client_command_call(SilcClient client,
1269 SilcClientConnection conn,
1270 const char *command_line, ...);
1272 /****f* silcclient/SilcClientAPI/SilcClientCommandReply
1276 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1277 * SilcClientConnection conn,
1278 * SilcCommand command,
1279 * SilcStatus status,
1286 * The command reply callback function given as argument to functions
1287 * silc_client_command_send and silc_client_command_pending. This is
1288 * called to deliver the command replies to the caller. Each command
1289 * reply received from the server to the `command' will be delivered
1290 * separately to the caller by calling this callback. The `status' will
1291 * indicate whether there is only one reply or multiple replies. The
1292 * `error' will indicate if an error occurred. The `ap' will include
1293 * command reply arguments. They are the same arguments as for
1294 * `command_reply' client operation in SilcClientOperations.
1296 * If `status' is SILC_STATUS_OK only one reply was received and error
1297 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
1298 * or SILC_STATUS_LIST_END, there are will be two or more replies. The
1299 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
1301 * If FALSE is returned in this function this callback will not be called
1302 * again for `command' even if there are more comand replies. By returning
1303 * FALSE the caller my stop the command reply handling when needed.
1306 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1307 SilcClientConnection conn,
1308 SilcCommand command,
1314 /****f* silcclient/SilcClientAPI/silc_client_command_send
1318 * SilcUInt16 silc_client_command_send(SilcClient client,
1319 * SilcClientConnection conn,
1320 * SilcCommand command,
1321 * SilcClientCommandReply reply,
1322 * void *reply_context,
1323 * SilcUInt32 argc, ...);
1327 * Generic function to send any command. The arguments must be given
1328 * already encoded into correct format and in correct order. If application
1329 * wants to perform the commands by itself, it can do so and send the data
1330 * directly to the server using this function. If application is using
1331 * the silc_client_command_call, this function is usually not used.
1332 * Programmer should get familiar with the SILC protocol commands
1333 * specification when using this function, as the arguments needs to
1334 * be encoded as specified in the protocol.
1336 * The variable arguments are a set of { type, data, data_length },
1337 * and the `argc' is the number of these sets.
1339 * The `reply' callback must be provided, and it is called when the
1340 * command reply is received from the server. Note that, when using this
1341 * function the default `command_reply' client operation will not be
1342 * called, when reply is received.
1344 * Returns command identifier for this sent command. It can be used
1345 * to additionally attach to the command reply using the function
1346 * silc_client_command_pending, if needed. Returns 0 on error,
1350 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1351 * my_whois_command_reply, cmd_ctx,
1352 * 1, 1, nickname, strlen(nickname));
1355 SilcUInt16 silc_client_command_send(SilcClient client,
1356 SilcClientConnection conn,
1357 SilcCommand command,
1358 SilcClientCommandReply reply,
1359 void *reply_context,
1360 SilcUInt32 argc, ...);
1362 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1366 * void silc_client_command_pending(SilcClientConnection conn,
1367 * SilcCommand reply_cmd,
1368 * SilcUInt16 cmd-ident,
1369 * SilcCommandCb callback,
1374 * This function can be used to add pending command callback to be
1375 * called when an command reply is received to an earlier sent command.
1376 * The `reply_cmd' is the command that must be received in order for
1377 * the pending command callback indicated by `callback' to be called.
1378 * The `callback' will deliver the `context' and
1379 * SilcClientCommandReplyContext which includes the internals of the
1382 * The `cmd_ident' is a command identifier which was set for the earlier
1383 * sent command. The command reply will include the same identifier
1384 * and pending command callback will be called when the reply is
1385 * received with the same command identifier. It is possible to
1386 * add multiple pending command callbacks for same command and for
1389 * Application may use this function to add its own command reply
1390 * handlers if it wishes not to use the standard `command_reply'
1391 * client operation. However, note that the pending command callback
1392 * does not deliver parsed command reply, but application must parse
1395 * Note also that the application is notified about the received command
1396 * reply through the `command_reply' client operation before calling
1397 * the `callback` pending command callback. That is the normal
1398 * command reply handling, and is called regardless whether pending
1399 * command callbacks are used or not.
1401 * Commands that application calls with silc_client_command_call
1402 * will use a command identifier from conn->cmd_ident variable. After
1403 * calling the silc_client_command_call, the conn->cmd_ident includes
1404 * the command identifier that was used for the command sending.
1408 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1409 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1410 * my_ping_handler, my_ping_context);
1413 SilcBool silc_client_command_pending(SilcClientConnection conn,
1414 SilcCommand command,
1415 SilcUInt16 cmd_ident,
1416 SilcClientCommandReply reply,
1420 /* Private Message key management */
1422 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1427 * silc_client_add_private_message_key(SilcClient client,
1428 * SilcClientConnection conn,
1429 * SilcClientEntry client_entry,
1430 * const char *cipher,
1432 * unsigned char *key,
1433 * SilcUInt32 key_len);
1437 * Adds a static private message key to the client library. The key
1438 * will be used to encrypt all private message between the client and
1439 * the remote client indicated by the `client_entry'. The `key' can
1440 * be for example a pre-shared-key, passphrase or similar shared secret
1441 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1442 * to assure that the requirements of the SILC protocol are met. The
1443 * API, however, allows to allocate any cipher and HMAC.
1445 * If the private message key is added to client without first receiving
1446 * a request for it from the remote `client_entry' this function will
1447 * send the request to `client_entry'. Note that, the actual key is
1448 * not sent to the network.
1450 * It is not necessary to set key for normal private message usage. If the
1451 * key is not set then the private messages are encrypted using normal
1452 * session keys. Setting the private key, however, increases the security.
1454 * Returns FALSE if the key is already set for the `client_entry', TRUE
1458 SilcBool silc_client_add_private_message_key(SilcClient client,
1459 SilcClientConnection conn,
1460 SilcClientEntry client_entry,
1464 SilcUInt32 key_len);
1466 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1471 * silc_client_add_private_message_key_ske(SilcClient client,
1472 * SilcClientConnection conn,
1473 * SilcClientEntry client_entry,
1474 * const char *cipher,
1476 * SilcSKEKeyMaterial key);
1480 * Same as silc_client_add_private_message_key but takes the key material
1481 * from the SKE key material structure. This structure is received if
1482 * the application uses the silc_client_send_key_agreement to negotiate
1483 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1484 * negotiated also in the SKE protocol.
1487 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1488 SilcClientConnection conn,
1489 SilcClientEntry client_entry,
1492 SilcSKEKeyMaterial key);
1494 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1498 * SilcBool silc_client_del_private_message_key(SilcClient client,
1499 * SilcClientConnection conn,
1500 * SilcClientEntry client_entry);
1504 * Removes the private message from the library. The key won't be used
1505 * after this to protect the private messages with the remote `client_entry'
1506 * client. Returns FALSE on error, TRUE otherwise.
1509 SilcBool silc_client_del_private_message_key(SilcClient client,
1510 SilcClientConnection conn,
1511 SilcClientEntry client_entry);
1513 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1517 * SilcPrivateMessageKeys
1518 * silc_client_list_private_message_keys(SilcClient client,
1519 * SilcClientConnection conn,
1520 * SilcUInt32 *key_count);
1524 * Returns array of set private message keys associated to the connection
1525 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1526 * count to the `key_count' argument. The array must be freed by the caller
1527 * by calling the silc_client_free_private_message_keys function. Note:
1528 * the keys returned in the array is in raw format. It might not be desired
1529 * to show the keys as is. The application might choose not to show the keys
1530 * at all or to show the fingerprints of the keys.
1533 SilcPrivateMessageKeys
1534 silc_client_list_private_message_keys(SilcClient client,
1535 SilcClientConnection conn,
1536 SilcUInt32 *key_count);
1538 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1542 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1543 * SilcUInt32 key_count);
1547 * Frees the SilcPrivateMessageKeys array returned by the function
1548 * silc_client_list_private_message_keys.
1551 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1552 SilcUInt32 key_count);
1555 /* Channel private key management */
1557 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1561 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1562 * SilcClientConnection conn,
1563 * SilcChannelEntry channel,
1567 * unsigned char *key,
1568 * SilcUInt32 key_len,
1569 * SilcChannelPrivateKey *ret_key);
1573 * Adds private key for channel. When channel has private key then the
1574 * messages are encrypted using that key. All clients on the channel
1575 * must also know the key in order to decrypt the messages. However,
1576 * it is possible to have several private keys per one channel. In this
1577 * case only some of the clients on the channel may know the one key
1578 * and only some the other key. The `name' can be application given
1579 * name for the key. This returns the created key to the 'ret_key'
1580 * pointer if it is non-NULL;
1582 * If `cipher' and/or `hmac' is NULL then default values will be used
1583 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1585 * The private key for channel is optional. If it is not set then the
1586 * channel messages are encrypted using the channel key generated by the
1587 * server. However, setting the private key (or keys) for the channel
1588 * significantly adds security. If more than one key is set the library
1589 * will automatically try all keys at the message decryption phase. Note:
1590 * setting many keys slows down the decryption phase as all keys has to
1591 * be tried in order to find the correct decryption key. However, setting
1592 * a few keys does not have big impact to the decryption performace.
1596 * NOTE: This is entirely local setting. The key set using this function
1597 * is not sent to the network at any phase.
1599 * NOTE: If the key material was originated by the SKE protocol (using
1600 * silc_client_send_key_agreement) then the `key' MUST be the
1601 * key->send_enc_key as this is dictated by the SILC protocol. However,
1602 * currently it is not expected that the SKE key material would be used
1603 * as channel private key. However, this API allows it.
1606 SilcBool silc_client_add_channel_private_key(SilcClient client,
1607 SilcClientConnection conn,
1608 SilcChannelEntry channel,
1614 SilcChannelPrivateKey *ret_key);
1616 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1620 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1621 * SilcClientConnection conn,
1622 * SilcChannelEntry channel);
1626 * Removes all private keys from the `channel'. The old channel key is used
1627 * after calling this to protect the channel messages. Returns FALSE on
1628 * on error, TRUE otherwise.
1631 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1632 SilcClientConnection conn,
1633 SilcChannelEntry channel);
1635 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1639 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1640 * SilcClientConnection conn,
1641 * SilcChannelEntry channel,
1642 * SilcChannelPrivateKey key);
1646 * Removes and frees private key `key' from the channel `channel'.
1647 * The `key' is retrieved by calling the function
1648 * silc_client_list_channel_private_keys. The key is not used after
1649 * this. If the key was last private key then the old channel key is
1650 * used hereafter to protect the channel messages. This returns FALSE
1651 * on error, TRUE otherwise.
1654 SilcBool silc_client_del_channel_private_key(SilcClient client,
1655 SilcClientConnection conn,
1656 SilcChannelEntry channel,
1657 SilcChannelPrivateKey key);
1659 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1664 * silc_client_list_channel_private_keys(SilcClient client,
1665 * SilcClientConnection conn,
1666 * SilcChannelEntry channel);
1670 * Returns list of private keys associated to the `channel'. The caller
1671 * must free the returned list with silc_dlist_uninit. The pointers in
1672 * the list may be used to delete the specific key by giving the pointer
1673 * as argument to the function silc_client_del_channel_private_key. Each
1674 * entry in the list is SilcChannelPrivateKey.
1677 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1678 SilcClientConnection conn,
1679 SilcChannelEntry channel);
1681 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1685 * void silc_client_current_channel_private_key(SilcClient client,
1686 * SilcClientConnection conn,
1687 * SilcChannelEntry channel,
1688 * SilcChannelPrivateKey key);
1692 * Sets the `key' to be used as current channel private key on the
1693 * `channel'. Packet sent after calling this function will be secured
1697 void silc_client_current_channel_private_key(SilcClient client,
1698 SilcClientConnection conn,
1699 SilcChannelEntry channel,
1700 SilcChannelPrivateKey key);
1703 /* Key Agreement routines */
1705 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1709 * void silc_client_send_key_agreement(SilcClient client,
1710 * SilcClientConnection conn,
1711 * SilcClientEntry client_entry,
1712 * SilcClientConnectionParams *params,
1713 * SilcPublicKey public_key,
1714 * SilcPrivateKey private_key,
1715 * SilcKeyAgreementCallback completion,
1720 * Sends key agreement request to the remote client indicated by the
1723 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1724 * the caller will provide the connection endpoint for the key agreement
1725 * connection. The `bind_ip' can be used to bind to that IP instead of
1726 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1727 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1728 * and `timeout_secs' fields in `params'. Other fields are ignored.
1729 * If `params' is NULL, then the `client_entry' is expected to provide
1730 * the connection endpoint for us. It is recommended the `timeout_secs'
1731 * is specified in case the remote client does not reply anything to
1734 * The `public_key' and `private_key' is our identity in the key agreement.
1736 * In case we do not provide the connection endpoint, we will receive
1737 * the `key_agreement' client operation when the remote send its own
1738 * key agreement request packet. We may then there start the key
1739 * agreement with silc_client_perform_key_agreement. If we provided the
1740 * the connection endpoint, the client operation will not be called.
1742 * There can be only one active key agreement for `client_entry'. Old
1743 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1747 * // Send key agreement request (we don't provide connection endpoint)
1748 * silc_client_send_key_agreement(client, conn, remote_client,
1749 * NULL, public_key, private_key,
1750 * my_keyagr_completion, my_context);
1752 * // Another example where we provide connection endpoint (TCP).
1753 * SilcClientConnectionParams params;
1754 * memset(¶ms, 0, sizeof(params));
1755 * params.local_ip = local_ip;
1756 * params.local_port = local_port;
1757 * params.timeout_secs = 60;
1758 * silc_client_send_key_agreement(client, conn, remote_client,
1759 * ¶ms, public_key, private_key,
1760 * my_keyagr_completion, my_context);
1763 void silc_client_send_key_agreement(SilcClient client,
1764 SilcClientConnection conn,
1765 SilcClientEntry client_entry,
1766 SilcClientConnectionParams *params,
1767 SilcPublicKey public_key,
1768 SilcPrivateKey private_key,
1769 SilcKeyAgreementCallback completion,
1772 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1777 * silc_client_perform_key_agreement(SilcClient client,
1778 * SilcClientConnection conn,
1779 * SilcClientEntry client_entry,
1780 * SilcClientConnectionParams *params,
1781 * SilcPublicKey public_key,
1782 * SilcPrivateKey private_key,
1783 * char *hostname, int port,
1784 * SilcKeyAgreementCallback completion,
1789 * Performs the key agreement protocol. Application may use this to
1790 * initiate the key agreement protocol. Usually this is called after
1791 * receiving the `key_agreement' client operation.
1793 * The `hostname' is the remote hostname (or IP address) and the `port'
1794 * is the remote port. The `completion' callback with the `context' will
1795 * be called after the key agreement protocol.
1797 * The `params' is connection parameters and it may be used to define
1798 * the key agreement connection related parameters. It may be NULL.
1801 void silc_client_perform_key_agreement(SilcClient client,
1802 SilcClientConnection conn,
1803 SilcClientEntry client_entry,
1804 SilcClientConnectionParams *params,
1805 SilcPublicKey public_key,
1806 SilcPrivateKey private_key,
1807 char *hostname, int port,
1808 SilcKeyAgreementCallback completion,
1811 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1816 * silc_client_perform_key_agreement_stream(
1817 * SilcClient client,
1818 * SilcClientConnection conn,
1819 * SilcClientEntry client_entry,
1820 * SilcClientConnectionParams *params,
1821 * SilcPublicKey public_key,
1822 * SilcPrivateKey private_key,
1823 * SilcStream stream,
1824 * SilcKeyAgreementCallback completion,
1829 * Same as silc_client_perform_key_agreement but the caller has created
1830 * the connection. The `stream' is the created connection.
1834 silc_client_perform_key_agreement_stream(SilcClient client,
1835 SilcClientConnection conn,
1836 SilcClientEntry client_entry,
1837 SilcClientConnectionParams *params,
1838 SilcPublicKey public_key,
1839 SilcPrivateKey private_key,
1841 SilcKeyAgreementCallback completion,
1844 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1848 * void silc_client_abort_key_agreement(SilcClient client,
1849 * SilcClientConnection conn,
1850 * SilcClientEntry client_entry);
1854 * This function can be called to unbind the hostname and the port for
1855 * the key agreement protocol. However, this function has effect only
1856 * before the key agreement protocol has been performed. After it has
1857 * been performed the library will automatically unbind the port. The
1858 * `client_entry' is the client to which we sent the key agreement
1859 * request. The key agreement completion callback will be called
1860 * with SILC_KEY_AGREEMENT_ABORTED status.
1863 void silc_client_abort_key_agreement(SilcClient client,
1864 SilcClientConnection conn,
1865 SilcClientEntry client_entry);
1868 /* Misc functions */
1870 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1874 * void silc_client_set_away_message(SilcClient client,
1875 * SilcClientConnection conn,
1880 * Sets away `message'. The away message may be set when the client's
1881 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1882 * to anyone who sends private message. The `message' will be sent
1883 * automatically back to the the client who send private message. If
1884 * away message is already set this replaces the old message with the
1885 * new one. If `message' is NULL the old away message is removed.
1886 * The sender may freely free the memory of the `message'.
1889 void silc_client_set_away_message(SilcClient client,
1890 SilcClientConnection conn,
1893 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1897 * typedef enum { ... } SilcClientMonitorStatus;
1901 * File transmission session status types. These will indicate
1902 * the status of the file transmission session.
1907 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1908 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1909 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1910 SILC_CLIENT_FILE_MONITOR_GET,
1911 SILC_CLIENT_FILE_MONITOR_PUT,
1912 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1913 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1914 } SilcClientMonitorStatus;
1917 /****d* silcclient/SilcClientAPI/SilcClientFileError
1921 * typedef enum { ... } SilcClientFileError;
1925 * File transmission error types. These types are returned by
1926 * some of the file transmission functions, and by the monitor
1927 * callback to indicate error.
1932 SILC_CLIENT_FILE_OK,
1933 SILC_CLIENT_FILE_ERROR,
1934 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1935 SILC_CLIENT_FILE_ALREADY_STARTED,
1936 SILC_CLIENT_FILE_NO_SUCH_FILE,
1937 SILC_CLIENT_FILE_PERMISSION_DENIED,
1938 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1939 } SilcClientFileError;
1942 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1946 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1947 * SilcClientConnection conn,
1948 * SilcClientMonitorStatus status,
1949 * SilcClientFileError error,
1950 * SilcUInt64 offset,
1951 * SilcUInt64 filesize,
1952 * SilcClientEntry client_entry,
1953 * SilcUInt32 session_id,
1954 * const char *filepath,
1959 * Monitor callback that is called during the file transmission to
1960 * monitor the transmission process. The `status' indicates the current
1961 * monitoring process. The `error' will indicate the error type
1962 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1963 * currently transmitted amount of total `filesize'. The `client_entry'
1964 * indicates the remote client, and the transmission session ID is the
1965 * `session_id'. The filename being transmitted is indicated by the
1969 typedef void (*SilcClientFileMonitor)(SilcClient client,
1970 SilcClientConnection conn,
1971 SilcClientMonitorStatus status,
1972 SilcClientFileError error,
1974 SilcUInt64 filesize,
1975 SilcClientEntry client_entry,
1976 SilcUInt32 session_id,
1977 const char *filepath,
1980 /****f* silcclient/SilcClientAPI/SilcClientFileName
1984 * typedef void (*SilcClientFileName)(const char *filepath,
1989 * Completion callback for the SilcClientFileAskName callback function.
1990 * Application calls this to deliver the filepath and filename where
1991 * the downloaded file is to be saved.
1994 typedef void (*SilcClientFileName)(const char *filepath,
1997 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2001 * typedef void (*SilcClientFileAskName)(SilcClient client,
2002 * SilcClientConnection conn,
2003 * SilcUInt32 session_id,
2004 * const char *remote_filename,
2005 * SilcClientFileName completion,
2006 * void *completion_context,
2011 * File name asking callback, that is called if it is given to the
2012 * silc_client_file_receive and the path given to that as argument was
2013 * NULL. The library calls this to ask the filename and filepath to
2014 * where the file is to be saved. The 'remote_filename' is the file
2015 * that is being downloaded. Application must call the 'completion'
2016 * with 'completion_context' to continue with the file downloading.
2017 * It is not mandatory to provide this to the silc_client_file_receive.
2020 typedef void (*SilcClientFileAskName)(SilcClient client,
2021 SilcClientConnection conn,
2022 SilcUInt32 session_id,
2023 const char *remote_filename,
2024 SilcClientFileName completion,
2025 void *completion_context,
2028 /****f* silcclient/SilcClientAPI/silc_client_file_send
2032 * SilcClientFileError
2033 * silc_client_file_send(SilcClient client,
2034 * SilcClientConnection conn,
2035 * SilcClientFileMonitor monitor,
2036 * void *monitor_context,
2037 * const char *local_ip,
2038 * SilcUInt32 local_port,
2039 * SilcBool do_not_bind,
2040 * SilcClientEntry client_entry,
2041 * const char *filepath);
2042 * SilcUInt32 *session_id);
2046 * Sends a file indicated by the `filepath' to the remote client
2047 * indicated by the `client_entry'. This will negotiate a secret key
2048 * with the remote client before actually starting the transmission of
2049 * the file. The `monitor' callback will be called to monitor the
2050 * transmission of the file.
2052 * This returns a file session ID for the file transmission to the
2053 * `session_id' pointer. It can be used to close the session (and
2054 * abort the file transmission) by calling the silc_client_file_close
2055 * function. The session ID is also returned in the `monitor' callback.
2057 * If the `local_ip' is provided then this will try to bind the
2058 * listener for key exchange protocol to that IP. If `local_port' is
2059 * non-zero that port is used. If `local_ip' is NULL then this will
2060 * automatically attempt to bind it to local IP address of the machine.
2061 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2062 * ignored and it is expected that the receiver will provide the
2063 * point of contact. This is usefull if the sender is behind NAT.
2065 * If error will occur during the file transfer process the error
2066 * status will be returned in the monitor callback. In this case
2067 * the application must call silc_client_file_close to close the
2072 silc_client_file_send(SilcClient client,
2073 SilcClientEntry client_entry,
2074 SilcClientConnectionParams *params,
2075 SilcPublicKey public_key,
2076 SilcPrivateKey private_key,
2077 SilcClientFileMonitor monitor,
2078 void *monitor_context,
2079 const char *filepath,
2080 SilcUInt32 *session_id);
2082 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2086 * SilcClientFileError
2087 * silc_client_file_receive(SilcClient client,
2088 * SilcClientConnection conn,
2089 * SilcClientFileMonitor monitor,
2090 * void *monitor_context,
2092 * SilcUInt32 session_id,
2093 * SilcClientFileAskName ask_name,
2094 * void *ask_name_context);
2098 * Receives a file from a client indicated by the `client_entry'. The
2099 * `session_id' indicates the file transmission session and it has been
2100 * received in the `ftp' client operation function. This will actually
2101 * perform the key agreement protocol with the remote client before
2102 * actually starting the file transmission. The `monitor' callback
2103 * will be called to monitor the transmission. If `path' is non-NULL
2104 * the file will be saved into that directory. If NULL the file is
2105 * saved in the current working directory, unless the 'ask_name'
2106 * callback is non-NULL. In this case the callback is called to ask
2107 * the path and filename from application.
2109 * If error will occur during the file transfer process the error
2110 * status will be returned in the monitor callback. In this case
2111 * the application must call silc_client_file_close to close the
2116 silc_client_file_receive(SilcClient client,
2117 SilcClientConnection conn,
2118 SilcClientFileMonitor monitor,
2119 void *monitor_context,
2121 SilcUInt32 session_id,
2122 SilcClientFileAskName ask_name,
2123 void *ask_name_context);
2125 /****f* silcclient/SilcClientAPI/silc_client_file_close
2129 * SilcClientFileError silc_client_file_close(SilcClient client,
2130 * SilcClientConnection conn,
2131 * SilcUInt32 session_id);
2135 * Closes file transmission session indicated by the `session_id'.
2136 * If file transmission is being conducted it will be aborted
2137 * automatically. This function is also used to close the session
2138 * after successful file transmission. This function can be used
2139 * also to reject incoming file transmission request. If the
2140 * session was already started and the monitor callback was set
2141 * the monitor callback will be called with the monitor status
2142 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2145 SilcClientFileError silc_client_file_close(SilcClient client,
2146 SilcClientConnection conn,
2147 SilcUInt32 session_id);
2149 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2153 * SilcAttributePayload
2154 * silc_client_attribute_add(SilcClient client,
2155 * SilcClientConnection conn,
2156 * SilcAttribute attribute,
2158 * SilcUInt32 object_size);
2162 * Add new Requsted Attribute for WHOIS command to the client library.
2163 * The `attribute' object indicated by `object' is added and allocated
2164 * SilcAttributePayload is returned. The `object' must be of correct
2165 * type and of correct size. See the SilcAttribute for object types
2166 * for different attributes. You may also get all added attributes
2167 * from the client with silc_client_attributes_get function.
2169 * Requested Attributes are different personal information about the
2170 * user, status information and other information which other users
2171 * may query with WHOIS command. Application may set these so that
2172 * if someone sends WHOIS query these attributes will be replied back
2173 * to the sender. The library always puts the public key to the
2174 * Requested Attributes, but if application wishes to add additional
2175 * public keys (or certificates) it can be done with this interface.
2176 * Library also always computes digital signature of the attributes
2177 * automatically, so application does not need to do that.
2180 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2181 SilcClientConnection conn,
2182 SilcAttribute attribute,
2184 SilcUInt32 object_size);
2186 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2190 * SilcBool silc_client_attribute_del(SilcClient client,
2191 * SilcClientConnection conn,
2192 * SilcAttribute attribute,
2193 * SilcAttributePayload attr);
2197 * Delete a Requested Attribute from the client. If the `attribute'
2198 * is non-zero then all attributes of that type are deleted and the
2199 * `attr' is ignored. If `attr' is non-NULL then that specific
2200 * attribute is deleted and `attribute' is ignored.
2202 * You may get all added attributes with the function
2203 * silc_client_attributes_get and to get the SilcAttributePayload.
2204 * This function Returns TRUE if the attribute was found and deleted.
2207 SilcBool silc_client_attribute_del(SilcClient client,
2208 SilcClientConnection conn,
2209 SilcAttribute attribute,
2210 SilcAttributePayload attr);
2212 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2216 * const SilcHashTable
2217 * silc_client_attributes_get(SilcClient client,
2218 * SilcClientConnection conn);
2222 * Returns pointer to the SilcHashTable which includes all the added
2223 * Requested Attributes. The caller must not free the hash table.
2224 * The caller may use SilcHashTableList and silc_hash_table_list to
2225 * traverse the table. Each entry in the hash table is one added
2226 * SilcAttributePayload. It is possible to delete a attribute
2227 * payload while traversing the table.
2230 SilcHashTable silc_client_attributes_get(SilcClient client,
2231 SilcClientConnection conn);
2233 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2237 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2241 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2242 * then all attributes are requested. Alternatively, `attribute' and
2243 * all variable arguments can each be requested attribute. In this case
2244 * the last must be set to zero (0) to complete the variable list of
2245 * requested attributes. See SilcAttribute for all attributes.
2246 * You can give the returned buffer as argument to for example
2247 * silc_client_get_client_by_id_resolve function.
2251 * Request all attributes
2252 * buffer = silc_client_attributes_request(0);
2254 * Request only the following attributes
2255 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2256 * SILC_ATTRIBUTE_SERVICE,
2257 * SILC_ATTRIBUTE_MOOD, 0);
2260 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2262 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2267 * silc_client_nickname_format(SilcClient client,
2268 * SilcClientConnection conn,
2269 * SilcClientEntry client_entry,
2270 * SilcBool priority);
2274 * Formats the nickname of `client_entry' according to the nickname
2275 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2276 * then the `client_entry' will always get the unformatted nickname.
2277 * If FALSE and there are more than one same nicknames in the client
2278 * the nickname will be formatted.
2280 * This returns NULL on error. Otherwise, the client entry that was
2281 * formatted is returned. If `priority' is FALSE this always returns
2282 * the `client_entry'. If it is TRUE, this may return the client entry
2283 * that was formatted after giving the `client_entry' the unformatted
2286 * Usually application does not need to call this function, as the library
2287 * automatically formats nicknames. However, if application wants to
2288 * for example force the `client_entry' to always have the unformatted
2289 * nickname it may call this function to do so.
2292 SilcClientEntry silc_client_nickname_format(SilcClient client,
2293 SilcClientConnection conn,
2294 SilcClientEntry client_entry,
2301 #endif /* SILCCLIENT_H */