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.
140 * When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will
141 * indicate the reason for disconnection. If the `message' is non-NULL
142 * it delivers error or disconnection message.
145 typedef void (*SilcClientConnectCallback)(SilcClient client,
146 SilcClientConnection conn,
147 SilcClientConnectionStatus status,
152 /****s* silcclient/SilcClientAPI/SilcClient
156 * typedef struct SilcClientStruct { ... } *SilcClient
160 * This is the actual SILC Client structure which represents one
161 * SILC Client. It is allocated with the silc_client_alloc function
162 * and given as argument to all SILC Client Library functions. It
163 * is initialized with silc_client_init function, and freed with
164 * silc_client_free function.
166 * This context represents the client. Each connection to remote server
167 * is represented by SilcClientConnection context.
171 struct SilcClientStruct {
172 char *username; /* Username */
173 char *hostname; /* hostname */
174 char *realname; /* Real name */
175 SilcSchedule schedule; /* Client scheduler */
176 SilcRng rng; /* Random number generator */
177 void *application; /* Application specific context, set with
178 silc_client_alloc. */
180 /* Internal data for client library. Application cannot access this. */
181 SilcClientInternal internal;
185 /****s* silcclient/SilcClientAPI/SilcClientConnection
189 * typedef struct SilcClientConnectionStruct { ... }
190 * *SilcClientConnection
194 * This structure represents a connection. It is allocated and freed by
195 * the library. It is returned to application in SilcClientConnectCallback.
196 * It includes all the important data for the session such as local
197 * client entry (which includes current nickname), local and remote IDs,
198 * and other information. All strings in the structure are UTF-8 encoded.
202 struct SilcClientConnectionStruct {
203 SilcClientEntry local_entry; /* Our own Client Entry */
204 SilcClientID *local_id; /* Our current Client ID */
206 char *remote_host; /* Remote host name */
207 int remote_port; /* Remote port */
208 SilcID remote_id; /* Remote ID */
210 SilcChannelEntry current_channel; /* Current joined channel */
211 SilcPublicKey public_key; /* Public key used in this connection */
212 SilcPrivateKey private_key; /* Private key */
213 SilcPacketStream stream; /* Connection to remote host */
214 SilcConnectionType type; /* Connection type */
215 SilcClientConnectCallback callback; /* Connection callback */
216 void *callback_context; /* Connection context */
217 SilcClient client; /* Pointer back to SilcClient */
219 /* Application specific data. Application may set here whatever it wants. */
222 /* Internal data for client library. Application cannot access this. */
223 SilcClientConnectionInternal internal;
227 /****s* silcclient/SilcClientAPI/SilcChannelUser
231 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
235 * This structure represents a client that has joined to a channel.
236 * It shows the client and the channel and the client's mode (channel
237 * user mode) on the channel.
241 struct SilcChannelUserStruct {
242 SilcClientEntry client; /* Client joined on channel */
243 SilcUInt32 mode; /* mode, ChannelUserModes */
244 SilcChannelEntry channel; /* The channel user has joined */
246 /* Application specific data. Application may set here whatever it wants. */
251 /****s* silcclient/SilcClientAPI/SilcClientStats
255 * typedef struct { ... } SilcClientStats;
259 * This structure holds SILC network statistics returned by the
260 * SILC_COMMAND_STATS command reply to the application.
265 SilcUInt32 starttime; /* SILC server start time */
266 SilcUInt32 uptime; /* SILC server uptime*/
267 SilcUInt32 my_clients; /* Number of clients in the server */
268 SilcUInt32 my_channels; /* Number of channel in the server */
269 SilcUInt32 my_server_ops; /* Number of server operators in the server */
270 SilcUInt32 my_router_ops; /* Number of router operators in the router */
271 SilcUInt32 cell_clients; /* Number of clients in the cell */
272 SilcUInt32 cell_channels; /* Number of channels in the cell */
273 SilcUInt32 cell_servers; /* Number of server in the cell */
274 SilcUInt32 clients; /* All clients in SILC network */
275 SilcUInt32 channels; /* All channels in SILC network */
276 SilcUInt32 servers; /* All servers in SILC network */
277 SilcUInt32 routers; /* All routers in SILC network */
278 SilcUInt32 server_ops; /* All server operators in SILC network */
279 SilcUInt32 router_ops; /* All router operators in SILC network */
283 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
287 * typedef enum { ... } SilcKeyAgreementStatus;
291 * Key agreement status types indicating the status of the key
292 * agreement protocol. These types are returned to the application
293 * in the SilcKeyAgreementCallback callback function.
298 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
299 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
300 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
301 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
302 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
303 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
304 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
305 SILC_KEY_AGREEMENT_NO_MEMORY, /* System out of memory */
306 } SilcKeyAgreementStatus;
309 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
313 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
314 * SilcClientConnection conn,
315 * SilcClientEntry client_entry,
316 * SilcKeyAgreementStatus status,
317 * SilcSKEKeyMaterial *key,
322 * Key agreement callback that is called after the key agreement protocol
323 * has been performed. This is called also if error occurred during the
324 * key agreement protocol. The `key' is the allocated key material and
325 * the caller is responsible of freeing it. The `key' is NULL if error
326 * has occurred. The application can freely use the `key' to whatever
327 * purpose it needs. See lib/silcske/silcske.h for the definition of
328 * the SilcSKEKeyMaterial structure.
331 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
332 SilcClientConnection conn,
333 SilcClientEntry client_entry,
334 SilcKeyAgreementStatus status,
335 SilcSKEKeyMaterial key,
338 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
342 * typedef struct { ... } SilcPrivateMessageKeys;
346 * Structure to hold the list of private message keys. The list of these
347 * structures is returned by the silc_client_list_private_message_keys
353 SilcClientEntry client_entry; /* The remote client entry */
354 char *cipher; /* The cipher name */
355 unsigned char *key; /* The original key, If the appliation
356 provided it. This is NULL if
357 the SKE key material was used. */
358 SilcUInt32 key_len; /* The key length */
359 } *SilcPrivateMessageKeys;
362 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
366 * typedef struct SilcChannelPrivateKeyStruct { ... }
367 * *SilcChannelPrivateKey;
371 * Structure to hold one channel private key. The array of this structure
372 * is returned by silc_client_list_channel_private_keys function.
376 struct SilcChannelPrivateKeyStruct {
377 char *name; /* Application given name */
378 SilcCipher cipher; /* The cipher and key */
379 SilcHmac hmac; /* The HMAC and hmac key */
383 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
387 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
388 * SilcUInt32 passphrase_len,
393 * Ask passphrase callback. This is called by the application when the
394 * library calls `ask_passphrase' client operation. The callback delivers
395 * the passphrase to the library. The passphrases in SILC protocol
396 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
397 * encoded, and if it is not then library will attempt to encode it.
400 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
401 SilcUInt32 passphrase_len,
404 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
408 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
412 * Public key (or certificate) verification callback. This is called
413 * by the application to indicate that the public key verification was
414 * either success or failure.
417 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
419 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
423 * typedef void (*SilcGetAuthMeth)(SilcBool success,
424 * SilcAuthMethod auth_meth,
425 * void *auth, SilcUInt32 auth_len,
430 * Authentication data resolving callback. This is called by the
431 * application to return the resolved authentication data. The client
432 * library has called the get_auth_method client operation and given
433 * this function pointer as argument. The `auth_meth' is the selected
434 * authentication method. The `auth_data' and the `auth_data_len'
435 * are the resolved authentication data. The `context' is the libary's
436 * context sent to the get_auth_method client operation.
438 * If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len'
439 * is the passphrase and its length. If it is SILC_AUTH_PUBLIC_KEY the
440 * `auth' must be NULL. The library will use the private key given as
441 * argument to silc_client_connect_to_server, silc_client_connect_to_client
442 * or silc_client_key_exchange. If it is SILC_AUTH_NONE, both `auth' and
443 * `auth_len' are ignored.
446 typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth,
447 void *auth, SilcUInt32 auth_len,
450 /****d* silcclient/SilcClientAPI/SilcClientMessageType
454 * typedef enum { ... } SilcClientMessageType;
458 * Different message types for `say' client operation. The application
459 * may filter the message sent by the library according this type.
464 SILC_CLIENT_MESSAGE_INFO, /* Informational */
465 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
466 SILC_CLIENT_MESSAGE_ERROR, /* Error */
467 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
468 } SilcClientMessageType;
471 /****s* silcclient/SilcClientAPI/SilcClientOperations
475 * typedef struct { ... } SilcClientOperations;
479 * SILC Client Operations. These must be implemented by the application.
480 * The Client library may call any of these routines at any time. The
481 * routines are used to deliver certain information to the application
482 * or from the application to the client library.
487 /* Message sent to the application by library. `conn' associates the
488 message to a specific connection. `conn', however, may be NULL.
489 The `type' indicates the type of the message sent by the library.
490 The application can for example filter the message according the
491 type. The variable argument list is arguments to the formatted
492 message that `msg' may be. */
493 void (*say)(SilcClient client, SilcClientConnection conn,
494 SilcClientMessageType type, char *msg, ...);
496 /* Message for a channel. The `sender' is the sender of the message
497 The `channel' is the channel. The `message' is the message. Note
498 that `message' maybe NULL. The `flags' indicates message flags
499 and it is used to determine how the message can be interpreted
500 (like it may tell the message is multimedia message). */
501 void (*channel_message)(SilcClient client, SilcClientConnection conn,
502 SilcClientEntry sender, SilcChannelEntry channel,
503 SilcMessagePayload payload,
504 SilcChannelPrivateKey key, SilcMessageFlags flags,
505 const unsigned char *message,
506 SilcUInt32 message_len);
508 /* Private message to the client. The `sender' is the sender of the
509 message. The message is `message'and maybe NULL. The `flags'
510 indicates message flags and it is used to determine how the message
511 can be interpreted (like it may tell the message is multimedia
513 void (*private_message)(SilcClient client, SilcClientConnection conn,
514 SilcClientEntry sender, SilcMessagePayload payload,
515 SilcMessageFlags flags, const unsigned char *message,
516 SilcUInt32 message_len);
518 /* Notify message to the client. The notify arguments are sent in the
519 same order as servers sends them. The arguments are same as received
520 from the server except for ID's. If ID is received application receives
521 the corresponding entry to the ID. For example, if Client ID is received
522 application receives SilcClientEntry. Also, if the notify type is
523 for channel the channel entry is sent to application (even if server
524 does not send it because client library gets the channel entry from
525 the Channel ID in the packet's header). */
526 void (*notify)(SilcClient client, SilcClientConnection conn,
527 SilcNotifyType type, ...);
529 /* Command handler. This function is called always after application has
530 called a command. It will be called to indicate that the command
531 was processed. It will also be called if error occurs while processing
532 the command. The `success' indicates whether the command was sent
533 or if error occurred. The `status' indicates the actual error.
534 The `argc' and `argv' are the command line arguments sent to the
535 command by application. Note that, this is not reply to the command
536 from server, this is merely and indication to application that the
537 command was processed. */
538 void (*command)(SilcClient client, SilcClientConnection conn,
539 SilcBool success, SilcCommand command, SilcStatus status,
540 SilcUInt32 argc, unsigned char **argv);
542 /* Command reply handler. This function is called always in the command reply
543 function. If error occurs it will be called as well. Normal scenario
544 is that it will be called after the received command data has been parsed
545 and processed. The function is used to pass the received command data to
548 `conn' is the associated client connection. `cmd_payload' is the command
549 payload data received from server and it can be ignored. It is provided
550 if the application would like to re-parse the received command data,
551 however, it must be noted that the data is parsed already by the library
552 thus the payload can be ignored. `success' is FALSE if error occurred.
553 In this case arguments are not sent to the application. The `status' is
554 the command reply status server returned. The `command' is the command
555 reply being processed. The function has variable argument list and each
556 command defines the number and type of arguments it passes to the
557 application (on error they are not sent).
559 The arguments are sent in the same order as servers sends them. The
560 arguments are same as received from the server except for ID's. If
561 ID is received application receives the corresponding entry to the
562 ID. For example, if Client ID is receives application receives
564 void (*command_reply)(SilcClient client, SilcClientConnection conn,
565 SilcCommand command, SilcStatus status,
566 SilcStatus error, va_list ap);
568 /* Find authentication method and authentication data by hostname and
569 port. The hostname may be IP address as well. The `auth_method' is
570 the authentication method the remote connection requires. It is
571 however possible that remote accepts also some other authentication
572 method. Application should use the method that may have been
573 configured for this connection. If none has been configured it should
574 use the required `auth_method'. If the `auth_method' is
575 SILC_AUTH_NONE, server does not require any authentication or the
576 required authentication method is not known. The `completion'
577 callback must be called to deliver the chosen authentication method
578 and data. The `conn' may be NULL. */
579 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
580 char *hostname, SilcUInt16 port,
581 SilcAuthMethod auth_method,
582 SilcGetAuthMeth completion, void *context);
584 /* Verifies received public key. The `conn_type' indicates which entity
585 (server or client) has sent the public key. If user decides to trust
586 the key the application may save the key as trusted public key for
587 later use. The `completion' must be called after the public key has
589 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
590 SilcConnectionType conn_type,
591 SilcPublicKey public_key,
592 SilcVerifyPublicKey completion, void *context);
594 /* Ask (interact, that is) a passphrase from user. The passphrase is
595 returned to the library by calling the `completion' callback with
596 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
597 if not then the library will attempt to encode. */
598 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
599 SilcAskPassphrase completion, void *context);
601 /* Called to indicate that incoming key agreement request has been
602 received. If the application wants to perform key agreement it may
603 call silc_client_perform_key_agreement to initiate key agreementn or
604 silc_client_send_key_agreement to provide connection point to the
605 remote client in case the `hostname' is NULL. If key agreement is
606 not desired this request can be ignored. The `protocol' is either
607 value 0 for TCP or value 1 for UDP. */
608 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
609 SilcClientEntry client_entry,
610 const char *hostname, SilcUInt16 protocol,
613 /* Notifies application that file transfer protocol session is being
614 requested by the remote client indicated by the `client_entry' from
615 the `hostname' and `port'. The `session_id' is the file transfer
616 session and it can be used to either accept or reject the file
617 transfer request, by calling the silc_client_file_receive or
618 silc_client_file_close, respectively. */
619 void (*ftp)(SilcClient client, SilcClientConnection conn,
620 SilcClientEntry client_entry, SilcUInt32 session_id,
621 const char *hostname, SilcUInt16 port);
622 } SilcClientOperations;
625 /****s* silcclient/SilcClientAPI/SilcClientParams
629 * typedef struct { ... } SilcClientParams;
633 * Client parameters. This can be filled with proper values and
634 * given as argument to the silc_client_alloc function. The structure
635 * hold various parameters which affects the function of the client.
640 /* If this boolean is set to TRUE then the client library will use
641 threads. Any of the callback functions in the SilcClientOperations
642 and other callbacks may be called at any time in a thread. The
643 application may need to employ appropriate concurrency control
644 in the callbacks to protect application specific data. */
647 /* Nickname format string. This can be used to order the client library
648 to save the nicknames in the library in a certain format. Since
649 nicknames are not unique in SILC it is possible to have multiple same
650 nicknames. Using this format string it is possible to order the library
651 to separate the multiple same nicknames from each other. If this is
652 empty then default format is used which is the default nickname
653 without anything else. The string MUST be NULL terminated.
655 Following format types are available:
657 %n nickname - the real nickname returned by the server (mandatory)
658 %h hostname - the stripped hostname of the client
659 %H full hostname - the full hostname of the client
660 %s server name - the server name the client is connected
661 %S full server - the full server name the client is connected
662 %a number - ascending number in case there are several
663 same nicknames (fe. nick@host and nick@host2)
665 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
666 "%a!%n@%s" (fe. nick@server, 2!nick@server)
667 "%n@%H" (fe. nick@host.domain.com)
669 Note that there must always be some separator characters around '%n'
670 format. It is not possible to put format characters before or after
671 '%n' without separators (such ash '@'). Also note that the separator
672 character should be a character that cannot be part of normal nickname.
674 char nickname_format[32];
676 /* If this is set to TRUE then the `nickname_format' is employed to all
677 saved nicknames even if there are no multiple same nicknames in the
678 cache. By default this is FALSE, which means that the `nickname_format'
679 is employed only if the library will receive a nickname that is
680 already saved in the cache. It is recommended to leave this to FALSE
682 SilcBool nickname_force_format;
684 /* If this is set to TRUE, the silcclient library will not register and
685 deregister the cipher, pkcs, hash and hmac algorithms. The application
686 itself will need to handle that. */
687 SilcBool dont_register_crypto_library;
693 /* Initialization functions (client.c) */
695 /****f* silcclient/SilcClientAPI/silc_client_alloc
699 * SilcClient silc_client_alloc(SilcClientOperations *ops,
700 * SilcClientParams *params,
702 * const char *silc_version);
706 * Allocates new client object. This has to be done before client may
707 * work. After calling this one must call silc_client_init to initialize
708 * the client. The `application' is application specific user data pointer
709 * and caller must free it. The `silc_version' is the application version
710 * that will be used to compare against remote host's (usually a server)
711 * version string. The `application' context is accessible by the
712 * application by client->application, client being SilcClient.
715 SilcClient silc_client_alloc(SilcClientOperations *ops,
716 SilcClientParams *params,
718 const char *version_string);
720 /****f* silcclient/SilcClientAPI/silc_client_free
724 * void silc_client_free(SilcClient client);
728 * Frees client object and its internals. The execution of the client
729 * should be stopped with silc_client_stop function before calling
733 void silc_client_free(SilcClient client);
735 /****f* silcclient/SilcClientAPI/silc_client_init
739 * SilcBool silc_client_init(SilcClient client, const char *username,
740 * const char *hostname, const char *realname,
741 * SilcClientRunning running, void *context);
745 * Initializes the client. This makes all the necessary steps to make
746 * the client ready to be run. One must call silc_client_run to run the
747 * client. Returns FALSE if error occurred, TRUE otherwise.
749 * The `username' and `hostname' strings must be given and they must be
750 * UTF-8 encoded. The `username' is the client's username in the
751 * operating system, `hostname' is the client's host name and the
752 * `realname' is the user's real name.
754 * The `running' callback is called after the client is running after
755 * silc_client_run or silc_client_run_one has been called. Application
756 * may start using the Client library API after that. Setting the
757 * callback is optional, but recommended.
760 SilcBool silc_client_init(SilcClient client, const char *username,
761 const char *hostname, const char *realname,
762 SilcClientRunning running, void *context);
764 /****f* silcclient/SilcClientAPI/silc_client_run
768 * void silc_client_run(SilcClient client);
772 * Runs the client. This starts the scheduler from the utility library.
773 * When this functions returns the execution of the application is over.
774 * The client must be initialized before calling this.
777 void silc_client_run(SilcClient client);
779 /****f* silcclient/SilcClientAPI/silc_client_run_one
783 * void silc_client_run_one(SilcClient client);
787 * Runs the client and returns immeadiately. This function is used when
788 * the SILC Client object indicated by the `client' is run under some
789 * other scheduler, or event loop or main loop. On GUI applications,
790 * for example this may be desired to used to run the client under the
791 * GUI application's main loop. Typically the GUI application would
792 * register an idle task that calls this function multiple times in
793 * a second to quickly process the SILC specific data.
796 void silc_client_run_one(SilcClient client);
798 /****f* silcclient/SilcClientAPI/silc_client_stop
802 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
807 * Stops the client. This is called to stop the client and thus to stop
808 * the program. The client context must be freed with the silc_client_free
809 * function. All connections that exist in this client must be closed
810 * before calling this function. Connections can be closed by calling
811 * silc_client_close_connection.
813 * The `stopped' will be called once the client and all connections have
814 * finished. The client may be freed after that. Note that the `stopped'
815 * won't be called before all connections have finished. Setting the
816 * callback is optional.
819 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
822 /* Connecting functions */
824 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
828 * typedef struct { ... } SilcClientConnectionParams;
832 * Client connection parameters. This can be filled by the application
833 * and given as argument to silc_client_connect_to_server,
834 * silc_client_connect_to_client, silc_client_key_exchange or
835 * silc_client_send_key_agreement.
840 /* If this is provided the user's nickname in the network will be the
841 string given here. If it is given, it must be UTF-8 encoded. If this
842 string is not given, the user's username by default is used as nickname.
843 The nickname may later be changed by using NICK command. The maximum
844 length for the nickname string is 128 bytes. */
847 /* If this key repository pointer is non-NULL then public key received in
848 the key exchange protocol will be verified from this repository. If
849 this is not provided then the `verify_public_key' client operation will
850 be called back to application. If the boolean `verify_notfound' is set
851 to TRUE then the `verify_public_key' client operation will be called
852 in case the public key is not found in `repository'. Only public keys
853 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
854 be checked, other keys will be ignored. */
856 SilcBool verify_notfound;
858 /* Authentication data. Application may set here the authentication data
859 and authentication method to be used in connecting. If `auth_set'
860 boolean is TRUE then authentication data is provided by application.
861 If the authentication method is public key authentication then the key
862 pair given as argument when connecting will be used and `auth' field
863 is NULL. If it is passphrase authentication, it can be provided in
864 `auth' and `auth_len' fields. If `auth_set' is FALSE
865 the `get_auth_method' client operation will be called to get the
866 authentication method and data from application. */
868 SilcAuthMethod auth_method;
872 /* If this boolean is set to TRUE then the connection will use UDP instead
873 of TCP. If UDP is set then also the next `local_ip' and `local_port'
877 /* The `local_ip' specifies the local IP address used with the connection.
878 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
879 non-zero it will be used as local port with UDP connection. The remote
880 host will also send packets to the specified address and port. If the
881 `bind_ip' is non-NULL a listener is bound to that address instead of
887 /* If this boolean is set to TRUE then the key exchange is done with
888 perfect forward secrecy. */
891 /* If this boolean is set to TRUE then connection authentication protocol
892 is not performed during connecting. Only key exchange protocol is
893 performed. This usually must be set to TRUE when connecting to another
894 client, but must be FALSE with server connections. */
895 SilcBool no_authentication;
897 /* The SILC session detachment data that was returned in the `command_reply'
898 client operation for SILC_COMMAND_DETACH command. If this is provided
899 here the client library will attempt to resume the session in the network.
900 After the connection is created and the session has been resumed the
901 client will receive SILC_COMMAND_NICK command_reply for the client's
902 nickname in the network and SILC_COMMAND_JOIN command reply for all the
903 channels that the client has joined in the network. It may also receive
904 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
905 unsigned char *detach_data;
906 SilcUInt32 detach_data_len;
908 /* Connection timeout. If non-zero, the connection will timeout unless
909 the SILC connection is completed in the specified amount of time. */
910 SilcUInt32 timeout_secs;
912 /* Rekey timeout in seconds. The client will perform rekey in this
913 time interval. If set to zero, the default value will be used
914 (3600 seconds, 1 hour). */
915 SilcUInt32 rekey_secs;
917 /* If this is set to TRUE then the client will ignore all incoming
918 Requested Attributes queries and does not reply anything back. This
919 usually leads into situation where server does not anymore send
920 the queries after seeing that client does not reply anything back.
921 If your application does not support Requested Attributes or you do
922 not want to use them set this to TRUE. See SilcAttribute and
923 silc_client_attribute_add for more information on attributes. */
924 SilcBool ignore_requested_attributes;
926 } SilcClientConnectionParams;
929 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
934 * silc_client_connect_to_server(SilcClient client,
935 * SilcClientConnectionParams *params,
936 * SilcPublicKey public_key,
937 * SilcPrivateKey private_key,
938 * char *remote_host, int port,
939 * SilcClientConnectCallback callback,
944 * Connects to remote server `remote_host' at port `port'. This function
945 * can be used to create connection to remote SILC server and start
946 * SILC session in the SILC network. The `params' may be provided
947 * to provide various connection parameters. The `public_key' and the
948 * `private_key' is your identity used in this connection. When
949 * authentication method is based on digital signatures, this key pair
950 * will be used. The `callback' with `context' will be called after the
951 * connection has been created. It will also be called later when remote
954 * If application wishes to create the network connection itself, use
955 * the silc_client_key_exchange after creating the connection to start
956 * key exchange and authentication with the server.
958 * Returns SilcAsyncOperation which can be used to cancel the connecting,
959 * or NULL on error. Note that the returned pointer becomes invalid
960 * after the `callback' is called.
964 silc_client_connect_to_server(SilcClient client,
965 SilcClientConnectionParams *params,
966 SilcPublicKey public_key,
967 SilcPrivateKey private_key,
968 char *remote_host, int port,
969 SilcClientConnectCallback callback,
972 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
977 * silc_client_connect_to_client(SilcClient client,
978 * SilcClientConnectionParams *params,
979 * SilcPublicKey public_key,
980 * SilcPrivateKey private_key,
981 * char *remote_host, int port,
982 * SilcClientConnectCallback callback,
987 * Connects to remote client `remote_host' at port `port'. This function
988 * can be used to create peer-to-peer connection to another SILC client,
989 * for example, for direct conferencing, or file transfer or for other
990 * purposes. The `params' may be provided to provide various connection
991 * parameters. The `public_key' and the `private_key' is your identity
992 * used in this connection. The `callback' with `context' will be called
993 * after the connection has been created. It will also be called later
994 * when remote host disconnects.
996 * If application wishes to create the network connection itself, use
997 * the silc_client_key_exchange after creating the connection to start
998 * key exchange with the client.
1000 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1001 * or NULL on error. Note that the returned pointer becomes invalid
1002 * after the `callback' is called.
1006 silc_client_connect_to_client(SilcClient client,
1007 SilcClientConnectionParams *params,
1008 SilcPublicKey public_key,
1009 SilcPrivateKey private_key,
1010 char *remote_host, int port,
1011 SilcClientConnectCallback callback,
1014 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1018 * SilcAsyncOperation
1019 * silc_client_key_exchange(SilcClient client,
1020 * SilcClientConnectionParams *params,
1021 * SilcPublicKey public_key,
1022 * SilcPrivateKey private_key,
1023 * SilcStream stream,
1024 * SilcConnectionType conn_type,
1025 * SilcClientConnectCallback callback,
1030 * Starts key exchange protocol and authentication protocol in the
1031 * connection indicated by `stream'. This function can be be used to
1032 * start SILC session with remote host (usually server) when the caller
1033 * has itself created the connection, instead of calling the function
1034 * silc_client_connect_to_server or silc_client_connect_to_client. If
1035 * one of those functions was used this function must not be called as
1036 * in that case the key exchange is performed automatically.
1038 * Use this function only if you have created the connection by yourself.
1039 * After creating the connection the socket must be wrapped into a
1040 * socket stream. See silcsocketstream.h for more information. Note that
1041 * the `stream' must have valid remote IP address (and optionally also
1042 * hostname) and port set.
1044 * The `params' may be provided to provide various connection parameters.
1045 * The `public_key' and the `private_key' is your identity used in this
1046 * session. The `callback' with `context' will be called after the session
1047 * has been set up. It will also be called later when remote host
1048 * disconnects. The `conn_type' is the type of session this is going to
1051 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1052 * or NULL on error. Note that the returned pointer becomes invalid
1053 * after the `callback' is called.
1059 * // Create remote connection stream. Resolve hostname and IP also.
1060 * sock = create_connection(remote_host, port);
1061 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1062 * stream_create_cb, app);
1064 * // Stream callback delivers our new SilcStream context
1065 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1069 * if (status != SILC_SOCKET_OK)
1072 * // Start key exchange
1073 * silc_client_key_exchange(client, NULL, public_key, private_key,
1074 * stream, SILC_CONN_SERVER, connection_cb, app);
1080 silc_client_key_exchange(SilcClient client,
1081 SilcClientConnectionParams *params,
1082 SilcPublicKey public_key,
1083 SilcPrivateKey private_key,
1085 SilcConnectionType conn_type,
1086 SilcClientConnectCallback callback,
1089 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1093 * void silc_client_close_connection(SilcClient client,
1094 * SilcClientConnection conn);
1098 * Closes the remote connection `conn'. The `conn' will become invalid
1099 * after this call. Usually this function is called only when explicitly
1100 * closing connection for example in case of error, or when the remote
1101 * connection was created by the application or when the remote is client
1102 * connection. Server connections are usually closed by sending QUIT
1103 * command to the server. However, this call may also be used.
1106 void silc_client_close_connection(SilcClient client,
1107 SilcClientConnection conn);
1109 /* Message sending functions */
1111 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1115 * SilcBool silc_client_send_channel_message(SilcClient client,
1116 * SilcClientConnection conn,
1117 * SilcChannelEntry channel,
1118 * SilcChannelPrivateKey key,
1119 * SilcMessageFlags flags,
1121 * unsigned char *data,
1122 * SilcUInt32 data_len);
1126 * Sends packet to the `channel'. Packet to channel is always encrypted
1127 * differently from "normal" packets. SILC header of the packet is
1128 * encrypted with the next receiver's key and the rest of the packet is
1129 * encrypted with the channel specific key. Padding and HMAC is computed
1130 * with the next receiver's key. The `data' is the channel message.
1132 * If `key' is provided then that private key is used to encrypt the
1133 * channel message. If it is not provided, private keys has not been
1134 * set at all, the normal channel key is used automatically. If private
1135 * keys are set then the first key (the key that was added first as
1136 * private key) is used.
1138 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1139 * digitally signed with the SILC key pair. In this case the `hash'
1140 * pointer must be provided as well.
1142 * Returns TRUE if the message was sent, and FALSE if error occurred or
1143 * the sending is not allowed due to channel modes (like sending is
1144 * blocked). This function is thread safe and private messages can be
1145 * sent from multiple threads.
1148 SilcBool silc_client_send_channel_message(SilcClient client,
1149 SilcClientConnection conn,
1150 SilcChannelEntry channel,
1151 SilcChannelPrivateKey key,
1152 SilcMessageFlags flags,
1154 unsigned char *data,
1155 SilcUInt32 data_len);
1157 /* Block process until channel message from `channel' is received */
1159 silc_client_receive_channel_message(SilcClient client,
1160 SilcClientConnection conn,
1161 SilcChannelEntry channel,
1162 SilcClientEntry *return_sender,
1163 SilcMessageFlags *return_flags,
1164 const unsigned char **return_message,
1165 SilcUInt32 *return_message_len);
1167 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1171 * SilcBool silc_client_send_private_message(SilcClient client,
1172 * SilcClientConnection conn,
1173 * SilcClientEntry client_entry,
1174 * SilcMessageFlags flags,
1176 * unsigned char *data,
1177 * SilcUInt32 data_len);
1181 * Sends private message to remote client. If private message key has
1182 * not been set with this client then the message will be encrypted using
1183 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1184 * the message will be digitally signed with the SILC key pair. In this
1185 * case the caller must also provide the `hash' pointer.
1187 * Returns TRUE if the message was sent, and FALSE if error occurred.
1188 * This function is thread safe and private messages can be sent from
1192 SilcBool silc_client_send_private_message(SilcClient client,
1193 SilcClientConnection conn,
1194 SilcClientEntry client_entry,
1195 SilcMessageFlags flags,
1197 unsigned char *data,
1198 SilcUInt32 data_len);
1200 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1204 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1205 * SilcClientEntry client_entry);
1209 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1210 * channel indicated by the `channel'. NULL if client is not joined on
1214 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1215 SilcClientEntry client_entry);
1218 /* Command management */
1220 /****f* silcclient/SilcClientAPI/silc_client_command_call
1224 * SilcUInt16 silc_client_command_call(SilcClient client,
1225 * SilcClientConnection conn,
1226 * const char *command_line, ...);
1230 * Calls and executes the command indicated by the `command_name'.
1231 * The `command_line' is a string which includes the command's name and
1232 * its arguments separated with whitespaces (' '). If `command_line'
1233 * is non-NULL then all variable arguments are ignored by default.
1235 * If `command_line' is NULL, then the variable arguments define the
1236 * command's name and its arguments. The first variable argument must
1237 * be the command name. The variable argument list must be terminated
1240 * Returns FALSE if the command is not known and TRUE after command.
1241 * execution. The "command" client operation is called when the
1242 * command is executed to indicate whether the command executed
1243 * successfully or not.
1245 * The "command_reply" client operation will be called when reply is
1246 * received from the server to the command. Application may also use
1247 * the silc_client_command_pending to attach to the command reply.
1248 * The command identifier for silc_client_command_pending function after
1249 * this function call is conn->cmd_ident, which application may use.
1253 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1255 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1259 * This command executes the commands implemented inside the client
1260 * library. These commands are designed for command line applications,
1261 * but GUI application may call them too if needed. Alternatively
1262 * application may override the library and use silc_client_command_send
1266 SilcUInt16 silc_client_command_call(SilcClient client,
1267 SilcClientConnection conn,
1268 const char *command_line, ...);
1270 /****f* silcclient/SilcClientAPI/SilcClientCommandReply
1274 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1275 * SilcClientConnection conn,
1276 * SilcCommand command,
1277 * SilcStatus status,
1284 * The command reply callback function given as argument to functions
1285 * silc_client_command_send and silc_client_command_pending. This is
1286 * called to deliver the command replies to the caller. Each command
1287 * reply received from the server to the `command' will be delivered
1288 * separately to the caller by calling this callback. The `status' will
1289 * indicate whether there is only one reply or multiple replies. The
1290 * `error' will indicate if an error occurred. The `ap' will include
1291 * command reply arguments. They are the same arguments as for
1292 * `command_reply' client operation in SilcClientOperations.
1294 * If `status' is SILC_STATUS_OK only one reply was received and error
1295 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
1296 * or SILC_STATUS_LIST_END, there are will be two or more replies. The
1297 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
1299 * If FALSE is returned in this function this callback will not be called
1300 * again for `command' even if there are more comand replies. By returning
1301 * FALSE the caller my stop the command reply handling when needed.
1304 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1305 SilcClientConnection conn,
1306 SilcCommand command,
1312 /****f* silcclient/SilcClientAPI/silc_client_command_send
1316 * SilcUInt16 silc_client_command_send(SilcClient client,
1317 * SilcClientConnection conn,
1318 * SilcCommand command,
1319 * SilcClientCommandReply reply,
1320 * void *reply_context,
1321 * SilcUInt32 argc, ...);
1325 * Generic function to send any command. The arguments must be given
1326 * already encoded into correct format and in correct order. If application
1327 * wants to perform the commands by itself, it can do so and send the data
1328 * directly to the server using this function. If application is using
1329 * the silc_client_command_call, this function is usually not used.
1330 * Programmer should get familiar with the SILC protocol commands
1331 * specification when using this function, as the arguments needs to
1332 * be encoded as specified in the protocol.
1334 * The variable arguments are a set of { type, data, data_length },
1335 * and the `argc' is the number of these sets.
1337 * The `reply' callback must be provided, and it is called when the
1338 * command reply is received from the server. Note that, when using this
1339 * function the default `command_reply' client operation will not be
1340 * called, when reply is received.
1342 * Returns command identifier for this sent command. It can be used
1343 * to additionally attach to the command reply using the function
1344 * silc_client_command_pending, if needed. Returns 0 on error,
1348 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1349 * my_whois_command_reply, cmd_ctx,
1350 * 1, 1, nickname, strlen(nickname));
1353 SilcUInt16 silc_client_command_send(SilcClient client,
1354 SilcClientConnection conn,
1355 SilcCommand command,
1356 SilcClientCommandReply reply,
1357 void *reply_context,
1358 SilcUInt32 argc, ...);
1360 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1364 * void silc_client_command_pending(SilcClientConnection conn,
1365 * SilcCommand reply_cmd,
1366 * SilcUInt16 cmd-ident,
1367 * SilcCommandCb callback,
1372 * This function can be used to add pending command callback to be
1373 * called when an command reply is received to an earlier sent command.
1374 * The `reply_cmd' is the command that must be received in order for
1375 * the pending command callback indicated by `callback' to be called.
1376 * The `callback' will deliver the `context' and
1377 * SilcClientCommandReplyContext which includes the internals of the
1380 * The `cmd_ident' is a command identifier which was set for the earlier
1381 * sent command. The command reply will include the same identifier
1382 * and pending command callback will be called when the reply is
1383 * received with the same command identifier. It is possible to
1384 * add multiple pending command callbacks for same command and for
1387 * Application may use this function to add its own command reply
1388 * handlers if it wishes not to use the standard `command_reply'
1389 * client operation. However, note that the pending command callback
1390 * does not deliver parsed command reply, but application must parse
1393 * Note also that the application is notified about the received command
1394 * reply through the `command_reply' client operation before calling
1395 * the `callback` pending command callback. That is the normal
1396 * command reply handling, and is called regardless whether pending
1397 * command callbacks are used or not.
1399 * Commands that application calls with silc_client_command_call
1400 * will use a command identifier from conn->cmd_ident variable. After
1401 * calling the silc_client_command_call, the conn->cmd_ident includes
1402 * the command identifier that was used for the command sending.
1406 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1407 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1408 * my_ping_handler, my_ping_context);
1411 SilcBool silc_client_command_pending(SilcClientConnection conn,
1412 SilcCommand command,
1413 SilcUInt16 cmd_ident,
1414 SilcClientCommandReply reply,
1418 /* Private Message key management */
1420 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1425 * silc_client_add_private_message_key(SilcClient client,
1426 * SilcClientConnection conn,
1427 * SilcClientEntry client_entry,
1428 * const char *cipher,
1430 * unsigned char *key,
1431 * SilcUInt32 key_len);
1435 * Adds a static private message key to the client library. The key
1436 * will be used to encrypt all private message between the client and
1437 * the remote client indicated by the `client_entry'. The `key' can
1438 * be for example a pre-shared-key, passphrase or similar shared secret
1439 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1440 * to assure that the requirements of the SILC protocol are met. The
1441 * API, however, allows to allocate any cipher and HMAC.
1443 * If the private message key is added to client without first receiving
1444 * a request for it from the remote `client_entry' this function will
1445 * send the request to `client_entry'. Note that, the actual key is
1446 * not sent to the network.
1448 * It is not necessary to set key for normal private message usage. If the
1449 * key is not set then the private messages are encrypted using normal
1450 * session keys. Setting the private key, however, increases the security.
1452 * Returns FALSE if the key is already set for the `client_entry', TRUE
1456 SilcBool silc_client_add_private_message_key(SilcClient client,
1457 SilcClientConnection conn,
1458 SilcClientEntry client_entry,
1462 SilcUInt32 key_len);
1464 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1469 * silc_client_add_private_message_key_ske(SilcClient client,
1470 * SilcClientConnection conn,
1471 * SilcClientEntry client_entry,
1472 * const char *cipher,
1474 * SilcSKEKeyMaterial key);
1478 * Same as silc_client_add_private_message_key but takes the key material
1479 * from the SKE key material structure. This structure is received if
1480 * the application uses the silc_client_send_key_agreement to negotiate
1481 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1482 * negotiated also in the SKE protocol.
1485 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1486 SilcClientConnection conn,
1487 SilcClientEntry client_entry,
1490 SilcSKEKeyMaterial key);
1492 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1496 * SilcBool silc_client_del_private_message_key(SilcClient client,
1497 * SilcClientConnection conn,
1498 * SilcClientEntry client_entry);
1502 * Removes the private message from the library. The key won't be used
1503 * after this to protect the private messages with the remote `client_entry'
1504 * client. Returns FALSE on error, TRUE otherwise.
1507 SilcBool silc_client_del_private_message_key(SilcClient client,
1508 SilcClientConnection conn,
1509 SilcClientEntry client_entry);
1511 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1515 * SilcPrivateMessageKeys
1516 * silc_client_list_private_message_keys(SilcClient client,
1517 * SilcClientConnection conn,
1518 * SilcUInt32 *key_count);
1522 * Returns array of set private message keys associated to the connection
1523 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1524 * count to the `key_count' argument. The array must be freed by the caller
1525 * by calling the silc_client_free_private_message_keys function. Note:
1526 * the keys returned in the array is in raw format. It might not be desired
1527 * to show the keys as is. The application might choose not to show the keys
1528 * at all or to show the fingerprints of the keys.
1531 SilcPrivateMessageKeys
1532 silc_client_list_private_message_keys(SilcClient client,
1533 SilcClientConnection conn,
1534 SilcUInt32 *key_count);
1536 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1540 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1541 * SilcUInt32 key_count);
1545 * Frees the SilcPrivateMessageKeys array returned by the function
1546 * silc_client_list_private_message_keys.
1549 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1550 SilcUInt32 key_count);
1553 /* Channel private key management */
1555 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1559 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1560 * SilcClientConnection conn,
1561 * SilcChannelEntry channel,
1565 * unsigned char *key,
1566 * SilcUInt32 key_len,
1567 * SilcChannelPrivateKey *ret_key);
1571 * Adds private key for channel. When channel has private key then the
1572 * messages are encrypted using that key. All clients on the channel
1573 * must also know the key in order to decrypt the messages. However,
1574 * it is possible to have several private keys per one channel. In this
1575 * case only some of the clients on the channel may know the one key
1576 * and only some the other key. The `name' can be application given
1577 * name for the key. This returns the created key to the 'ret_key'
1578 * pointer if it is non-NULL;
1580 * If `cipher' and/or `hmac' is NULL then default values will be used
1581 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1583 * The private key for channel is optional. If it is not set then the
1584 * channel messages are encrypted using the channel key generated by the
1585 * server. However, setting the private key (or keys) for the channel
1586 * significantly adds security. If more than one key is set the library
1587 * will automatically try all keys at the message decryption phase. Note:
1588 * setting many keys slows down the decryption phase as all keys has to
1589 * be tried in order to find the correct decryption key. However, setting
1590 * a few keys does not have big impact to the decryption performace.
1594 * NOTE: This is entirely local setting. The key set using this function
1595 * is not sent to the network at any phase.
1597 * NOTE: If the key material was originated by the SKE protocol (using
1598 * silc_client_send_key_agreement) then the `key' MUST be the
1599 * key->send_enc_key as this is dictated by the SILC protocol. However,
1600 * currently it is not expected that the SKE key material would be used
1601 * as channel private key. However, this API allows it.
1604 SilcBool silc_client_add_channel_private_key(SilcClient client,
1605 SilcClientConnection conn,
1606 SilcChannelEntry channel,
1612 SilcChannelPrivateKey *ret_key);
1614 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1618 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1619 * SilcClientConnection conn,
1620 * SilcChannelEntry channel);
1624 * Removes all private keys from the `channel'. The old channel key is used
1625 * after calling this to protect the channel messages. Returns FALSE on
1626 * on error, TRUE otherwise.
1629 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1630 SilcClientConnection conn,
1631 SilcChannelEntry channel);
1633 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1637 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1638 * SilcClientConnection conn,
1639 * SilcChannelEntry channel,
1640 * SilcChannelPrivateKey key);
1644 * Removes and frees private key `key' from the channel `channel'.
1645 * The `key' is retrieved by calling the function
1646 * silc_client_list_channel_private_keys. The key is not used after
1647 * this. If the key was last private key then the old channel key is
1648 * used hereafter to protect the channel messages. This returns FALSE
1649 * on error, TRUE otherwise.
1652 SilcBool silc_client_del_channel_private_key(SilcClient client,
1653 SilcClientConnection conn,
1654 SilcChannelEntry channel,
1655 SilcChannelPrivateKey key);
1657 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1662 * silc_client_list_channel_private_keys(SilcClient client,
1663 * SilcClientConnection conn,
1664 * SilcChannelEntry channel);
1668 * Returns list of private keys associated to the `channel'. The caller
1669 * must free the returned list with silc_dlist_uninit. The pointers in
1670 * the list may be used to delete the specific key by giving the pointer
1671 * as argument to the function silc_client_del_channel_private_key. Each
1672 * entry in the list is SilcChannelPrivateKey.
1675 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1676 SilcClientConnection conn,
1677 SilcChannelEntry channel);
1679 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1683 * void silc_client_current_channel_private_key(SilcClient client,
1684 * SilcClientConnection conn,
1685 * SilcChannelEntry channel,
1686 * SilcChannelPrivateKey key);
1690 * Sets the `key' to be used as current channel private key on the
1691 * `channel'. Packet sent after calling this function will be secured
1695 void silc_client_current_channel_private_key(SilcClient client,
1696 SilcClientConnection conn,
1697 SilcChannelEntry channel,
1698 SilcChannelPrivateKey key);
1701 /* Key Agreement routines */
1703 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1707 * void silc_client_send_key_agreement(SilcClient client,
1708 * SilcClientConnection conn,
1709 * SilcClientEntry client_entry,
1710 * SilcClientConnectionParams *params,
1711 * SilcPublicKey public_key,
1712 * SilcPrivateKey private_key,
1713 * SilcKeyAgreementCallback completion,
1718 * Sends key agreement request to the remote client indicated by the
1721 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1722 * the caller will provide the connection endpoint for the key agreement
1723 * connection. The `bind_ip' can be used to bind to that IP instead of
1724 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1725 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1726 * and `timeout_secs' fields in `params'. Other fields are ignored.
1727 * If `params' is NULL, then the `client_entry' is expected to provide
1728 * the connection endpoint for us. It is recommended the `timeout_secs'
1729 * is specified in case the remote client does not reply anything to
1732 * The `public_key' and `private_key' is our identity in the key agreement.
1734 * In case we do not provide the connection endpoint, we will receive
1735 * the `key_agreement' client operation when the remote send its own
1736 * key agreement request packet. We may then there start the key
1737 * agreement with silc_client_perform_key_agreement. If we provided the
1738 * the connection endpoint, the client operation will not be called.
1740 * There can be only one active key agreement for `client_entry'. Old
1741 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1745 * // Send key agreement request (we don't provide connection endpoint)
1746 * silc_client_send_key_agreement(client, conn, remote_client,
1747 * NULL, public_key, private_key,
1748 * my_keyagr_completion, my_context);
1750 * // Another example where we provide connection endpoint (TCP).
1751 * SilcClientConnectionParams params;
1752 * memset(¶ms, 0, sizeof(params));
1753 * params.local_ip = local_ip;
1754 * params.local_port = local_port;
1755 * params.timeout_secs = 60;
1756 * silc_client_send_key_agreement(client, conn, remote_client,
1757 * ¶ms, public_key, private_key,
1758 * my_keyagr_completion, my_context);
1761 void silc_client_send_key_agreement(SilcClient client,
1762 SilcClientConnection conn,
1763 SilcClientEntry client_entry,
1764 SilcClientConnectionParams *params,
1765 SilcPublicKey public_key,
1766 SilcPrivateKey private_key,
1767 SilcKeyAgreementCallback completion,
1770 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1775 * silc_client_perform_key_agreement(SilcClient client,
1776 * SilcClientConnection conn,
1777 * SilcClientEntry client_entry,
1778 * SilcClientConnectionParams *params,
1779 * SilcPublicKey public_key,
1780 * SilcPrivateKey private_key,
1781 * char *hostname, int port,
1782 * SilcKeyAgreementCallback completion,
1787 * Performs the key agreement protocol. Application may use this to
1788 * initiate the key agreement protocol. Usually this is called after
1789 * receiving the `key_agreement' client operation.
1791 * The `hostname' is the remote hostname (or IP address) and the `port'
1792 * is the remote port. The `completion' callback with the `context' will
1793 * be called after the key agreement protocol.
1795 * The `params' is connection parameters and it may be used to define
1796 * the key agreement connection related parameters. It may be NULL.
1799 void silc_client_perform_key_agreement(SilcClient client,
1800 SilcClientConnection conn,
1801 SilcClientEntry client_entry,
1802 SilcClientConnectionParams *params,
1803 SilcPublicKey public_key,
1804 SilcPrivateKey private_key,
1805 char *hostname, int port,
1806 SilcKeyAgreementCallback completion,
1809 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1814 * silc_client_perform_key_agreement_stream(
1815 * SilcClient client,
1816 * SilcClientConnection conn,
1817 * SilcClientEntry client_entry,
1818 * SilcClientConnectionParams *params,
1819 * SilcPublicKey public_key,
1820 * SilcPrivateKey private_key,
1821 * SilcStream stream,
1822 * SilcKeyAgreementCallback completion,
1827 * Same as silc_client_perform_key_agreement but the caller has created
1828 * the connection. The `stream' is the created connection.
1832 silc_client_perform_key_agreement_stream(SilcClient client,
1833 SilcClientConnection conn,
1834 SilcClientEntry client_entry,
1835 SilcClientConnectionParams *params,
1836 SilcPublicKey public_key,
1837 SilcPrivateKey private_key,
1839 SilcKeyAgreementCallback completion,
1842 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1846 * void silc_client_abort_key_agreement(SilcClient client,
1847 * SilcClientConnection conn,
1848 * SilcClientEntry client_entry);
1852 * This function can be called to unbind the hostname and the port for
1853 * the key agreement protocol. However, this function has effect only
1854 * before the key agreement protocol has been performed. After it has
1855 * been performed the library will automatically unbind the port. The
1856 * `client_entry' is the client to which we sent the key agreement
1857 * request. The key agreement completion callback will be called
1858 * with SILC_KEY_AGREEMENT_ABORTED status.
1861 void silc_client_abort_key_agreement(SilcClient client,
1862 SilcClientConnection conn,
1863 SilcClientEntry client_entry);
1866 /* Misc functions */
1868 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1872 * void silc_client_set_away_message(SilcClient client,
1873 * SilcClientConnection conn,
1878 * Sets away `message'. The away message may be set when the client's
1879 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1880 * to anyone who sends private message. The `message' will be sent
1881 * automatically back to the the client who send private message. If
1882 * away message is already set this replaces the old message with the
1883 * new one. If `message' is NULL the old away message is removed.
1884 * The sender may freely free the memory of the `message'.
1887 void silc_client_set_away_message(SilcClient client,
1888 SilcClientConnection conn,
1891 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1895 * typedef enum { ... } SilcClientMonitorStatus;
1899 * File transmission session status types. These will indicate
1900 * the status of the file transmission session.
1905 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1906 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1907 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1908 SILC_CLIENT_FILE_MONITOR_GET,
1909 SILC_CLIENT_FILE_MONITOR_PUT,
1910 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1911 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1912 } SilcClientMonitorStatus;
1915 /****d* silcclient/SilcClientAPI/SilcClientFileError
1919 * typedef enum { ... } SilcClientFileError;
1923 * File transmission error types. These types are returned by
1924 * some of the file transmission functions, and by the monitor
1925 * callback to indicate error.
1930 SILC_CLIENT_FILE_OK,
1931 SILC_CLIENT_FILE_ERROR,
1932 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1933 SILC_CLIENT_FILE_ALREADY_STARTED,
1934 SILC_CLIENT_FILE_NO_SUCH_FILE,
1935 SILC_CLIENT_FILE_PERMISSION_DENIED,
1936 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1937 } SilcClientFileError;
1940 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1944 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1945 * SilcClientConnection conn,
1946 * SilcClientMonitorStatus status,
1947 * SilcClientFileError error,
1948 * SilcUInt64 offset,
1949 * SilcUInt64 filesize,
1950 * SilcClientEntry client_entry,
1951 * SilcUInt32 session_id,
1952 * const char *filepath,
1957 * Monitor callback that is called during the file transmission to
1958 * monitor the transmission process. The `status' indicates the current
1959 * monitoring process. The `error' will indicate the error type
1960 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1961 * currently transmitted amount of total `filesize'. The `client_entry'
1962 * indicates the remote client, and the transmission session ID is the
1963 * `session_id'. The filename being transmitted is indicated by the
1967 typedef void (*SilcClientFileMonitor)(SilcClient client,
1968 SilcClientConnection conn,
1969 SilcClientMonitorStatus status,
1970 SilcClientFileError error,
1972 SilcUInt64 filesize,
1973 SilcClientEntry client_entry,
1974 SilcUInt32 session_id,
1975 const char *filepath,
1978 /****f* silcclient/SilcClientAPI/SilcClientFileName
1982 * typedef void (*SilcClientFileName)(const char *filepath,
1987 * Completion callback for the SilcClientFileAskName callback function.
1988 * Application calls this to deliver the filepath and filename where
1989 * the downloaded file is to be saved.
1992 typedef void (*SilcClientFileName)(const char *filepath,
1995 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
1999 * typedef void (*SilcClientFileAskName)(SilcClient client,
2000 * SilcClientConnection conn,
2001 * SilcUInt32 session_id,
2002 * const char *remote_filename,
2003 * SilcClientFileName completion,
2004 * void *completion_context,
2009 * File name asking callback, that is called if it is given to the
2010 * silc_client_file_receive and the path given to that as argument was
2011 * NULL. The library calls this to ask the filename and filepath to
2012 * where the file is to be saved. The 'remote_filename' is the file
2013 * that is being downloaded. Application must call the 'completion'
2014 * with 'completion_context' to continue with the file downloading.
2015 * It is not mandatory to provide this to the silc_client_file_receive.
2018 typedef void (*SilcClientFileAskName)(SilcClient client,
2019 SilcClientConnection conn,
2020 SilcUInt32 session_id,
2021 const char *remote_filename,
2022 SilcClientFileName completion,
2023 void *completion_context,
2026 /****f* silcclient/SilcClientAPI/silc_client_file_send
2030 * SilcClientFileError
2031 * silc_client_file_send(SilcClient client,
2032 * SilcClientConnection conn,
2033 * SilcClientFileMonitor monitor,
2034 * void *monitor_context,
2035 * const char *local_ip,
2036 * SilcUInt32 local_port,
2037 * SilcBool do_not_bind,
2038 * SilcClientEntry client_entry,
2039 * const char *filepath);
2040 * SilcUInt32 *session_id);
2044 * Sends a file indicated by the `filepath' to the remote client
2045 * indicated by the `client_entry'. This will negotiate a secret key
2046 * with the remote client before actually starting the transmission of
2047 * the file. The `monitor' callback will be called to monitor the
2048 * transmission of the file.
2050 * This returns a file session ID for the file transmission to the
2051 * `session_id' pointer. It can be used to close the session (and
2052 * abort the file transmission) by calling the silc_client_file_close
2053 * function. The session ID is also returned in the `monitor' callback.
2055 * If the `local_ip' is provided then this will try to bind the
2056 * listener for key exchange protocol to that IP. If `local_port' is
2057 * non-zero that port is used. If `local_ip' is NULL then this will
2058 * automatically attempt to bind it to local IP address of the machine.
2059 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2060 * ignored and it is expected that the receiver will provide the
2061 * point of contact. This is usefull if the sender is behind NAT.
2063 * If error will occur during the file transfer process the error
2064 * status will be returned in the monitor callback. In this case
2065 * the application must call silc_client_file_close to close the
2070 silc_client_file_send(SilcClient client,
2071 SilcClientEntry client_entry,
2072 SilcClientConnectionParams *params,
2073 SilcPublicKey public_key,
2074 SilcPrivateKey private_key,
2075 SilcClientFileMonitor monitor,
2076 void *monitor_context,
2077 const char *filepath,
2078 SilcUInt32 *session_id);
2080 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2084 * SilcClientFileError
2085 * silc_client_file_receive(SilcClient client,
2086 * SilcClientConnection conn,
2087 * SilcClientFileMonitor monitor,
2088 * void *monitor_context,
2090 * SilcUInt32 session_id,
2091 * SilcClientFileAskName ask_name,
2092 * void *ask_name_context);
2096 * Receives a file from a client indicated by the `client_entry'. The
2097 * `session_id' indicates the file transmission session and it has been
2098 * received in the `ftp' client operation function. This will actually
2099 * perform the key agreement protocol with the remote client before
2100 * actually starting the file transmission. The `monitor' callback
2101 * will be called to monitor the transmission. If `path' is non-NULL
2102 * the file will be saved into that directory. If NULL the file is
2103 * saved in the current working directory, unless the 'ask_name'
2104 * callback is non-NULL. In this case the callback is called to ask
2105 * the path and filename from application.
2107 * If error will occur during the file transfer process the error
2108 * status will be returned in the monitor callback. In this case
2109 * the application must call silc_client_file_close to close the
2114 silc_client_file_receive(SilcClient client,
2115 SilcClientConnection conn,
2116 SilcClientFileMonitor monitor,
2117 void *monitor_context,
2119 SilcUInt32 session_id,
2120 SilcClientFileAskName ask_name,
2121 void *ask_name_context);
2123 /****f* silcclient/SilcClientAPI/silc_client_file_close
2127 * SilcClientFileError silc_client_file_close(SilcClient client,
2128 * SilcClientConnection conn,
2129 * SilcUInt32 session_id);
2133 * Closes file transmission session indicated by the `session_id'.
2134 * If file transmission is being conducted it will be aborted
2135 * automatically. This function is also used to close the session
2136 * after successful file transmission. This function can be used
2137 * also to reject incoming file transmission request. If the
2138 * session was already started and the monitor callback was set
2139 * the monitor callback will be called with the monitor status
2140 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2143 SilcClientFileError silc_client_file_close(SilcClient client,
2144 SilcClientConnection conn,
2145 SilcUInt32 session_id);
2147 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2151 * SilcAttributePayload
2152 * silc_client_attribute_add(SilcClient client,
2153 * SilcClientConnection conn,
2154 * SilcAttribute attribute,
2156 * SilcUInt32 object_size);
2160 * Add new Requsted Attribute for WHOIS command to the client library.
2161 * The `attribute' object indicated by `object' is added and allocated
2162 * SilcAttributePayload is returned. The `object' must be of correct
2163 * type and of correct size. See the SilcAttribute for object types
2164 * for different attributes. You may also get all added attributes
2165 * from the client with silc_client_attributes_get function.
2167 * Requested Attributes are different personal information about the
2168 * user, status information and other information which other users
2169 * may query with WHOIS command. Application may set these so that
2170 * if someone sends WHOIS query these attributes will be replied back
2171 * to the sender. The library always puts the public key to the
2172 * Requested Attributes, but if application wishes to add additional
2173 * public keys (or certificates) it can be done with this interface.
2174 * Library also always computes digital signature of the attributes
2175 * automatically, so application does not need to do that.
2178 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2179 SilcClientConnection conn,
2180 SilcAttribute attribute,
2182 SilcUInt32 object_size);
2184 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2188 * SilcBool silc_client_attribute_del(SilcClient client,
2189 * SilcClientConnection conn,
2190 * SilcAttribute attribute,
2191 * SilcAttributePayload attr);
2195 * Delete a Requested Attribute from the client. If the `attribute'
2196 * is non-zero then all attributes of that type are deleted and the
2197 * `attr' is ignored. If `attr' is non-NULL then that specific
2198 * attribute is deleted and `attribute' is ignored.
2200 * You may get all added attributes with the function
2201 * silc_client_attributes_get and to get the SilcAttributePayload.
2202 * This function Returns TRUE if the attribute was found and deleted.
2205 SilcBool silc_client_attribute_del(SilcClient client,
2206 SilcClientConnection conn,
2207 SilcAttribute attribute,
2208 SilcAttributePayload attr);
2210 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2214 * const SilcHashTable
2215 * silc_client_attributes_get(SilcClient client,
2216 * SilcClientConnection conn);
2220 * Returns pointer to the SilcHashTable which includes all the added
2221 * Requested Attributes. The caller must not free the hash table.
2222 * The caller may use SilcHashTableList and silc_hash_table_list to
2223 * traverse the table. Each entry in the hash table is one added
2224 * SilcAttributePayload. It is possible to delete a attribute
2225 * payload while traversing the table.
2228 SilcHashTable silc_client_attributes_get(SilcClient client,
2229 SilcClientConnection conn);
2231 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2235 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2239 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2240 * then all attributes are requested. Alternatively, `attribute' and
2241 * all variable arguments can each be requested attribute. In this case
2242 * the last must be set to zero (0) to complete the variable list of
2243 * requested attributes. See SilcAttribute for all attributes.
2244 * You can give the returned buffer as argument to for example
2245 * silc_client_get_client_by_id_resolve function.
2249 * Request all attributes
2250 * buffer = silc_client_attributes_request(0);
2252 * Request only the following attributes
2253 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2254 * SILC_ATTRIBUTE_SERVICE,
2255 * SILC_ATTRIBUTE_MOOD, 0);
2258 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2260 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2265 * silc_client_nickname_format(SilcClient client,
2266 * SilcClientConnection conn,
2267 * SilcClientEntry client_entry,
2268 * SilcBool priority);
2272 * Formats the nickname of `client_entry' according to the nickname
2273 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2274 * then the `client_entry' will always get the unformatted nickname.
2275 * If FALSE and there are more than one same nicknames in the client
2276 * the nickname will be formatted.
2278 * This returns NULL on error. Otherwise, the client entry that was
2279 * formatted is returned. If `priority' is FALSE this always returns
2280 * the `client_entry'. If it is TRUE, this may return the client entry
2281 * that was formatted after giving the `client_entry' the unformatted
2284 * Usually application does not need to call this function, as the library
2285 * automatically formats nicknames. However, if application wants to
2286 * for example force the `client_entry' to always have the unformatted
2287 * nickname it may call this function to do so.
2290 SilcClientEntry silc_client_nickname_format(SilcClient client,
2291 SilcClientConnection conn,
2292 SilcClientEntry client_entry,
2299 #endif /* SILCCLIENT_H */