5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
57 /* Forward declarations */
58 typedef struct SilcClientStruct *SilcClient;
59 typedef struct SilcClientConnectionStruct *SilcClientConnection;
60 typedef struct SilcClientPingStruct SilcClientPing;
61 typedef struct SilcClientAwayStruct SilcClientAway;
62 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
63 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
64 typedef struct SilcClientEntryStruct *SilcClientEntry;
65 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
66 typedef struct SilcServerEntryStruct *SilcServerEntry;
67 typedef struct SilcClientCommandStruct *SilcClientCommand;
68 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
69 typedef struct SilcClientCommandReplyContextStruct
70 *SilcClientCommandReplyContext;
71 typedef struct SilcChannelUserStruct *SilcChannelUser;
73 /* General definitions */
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
79 * typedef enum { ... } SilcKeyAgreementStatus;
83 * Key agreement status types indicating the status of the key
84 * agreement protocol. These types are returned to the application
85 * in the SilcKeyAgreementCallback callback function.
90 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
91 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
92 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
93 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
94 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
95 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
96 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
97 } SilcKeyAgreementStatus;
100 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
104 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
105 * SilcClientConnection conn,
106 * SilcClientEntry client_entry,
107 * SilcKeyAgreementStatus status,
108 * SilcSKEKeyMaterial *key,
113 * Key agreement callback that is called after the key agreement protocol
114 * has been performed. This is called also if error occurred during the
115 * key agreement protocol. The `key' is the allocated key material and
116 * the caller is responsible of freeing it. The `key' is NULL if error
117 * has occurred. The application can freely use the `key' to whatever
118 * purpose it needs. See lib/silcske/silcske.h for the definition of
119 * the SilcSKEKeyMaterial structure.
122 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
123 SilcClientConnection conn,
124 SilcClientEntry client_entry,
125 SilcKeyAgreementStatus status,
126 SilcSKEKeyMaterial *key,
129 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
133 * typedef struct { ... } SilcPrivateMessageKeys;
137 * Structure to hold the list of private message keys. The array of this
138 * structure is returned by the silc_client_list_private_message_keys
144 SilcClientEntry client_entry; /* The remote client entry */
145 char *cipher; /* The cipher name */
146 unsigned char *key; /* The original key, If the appliation
147 provided it. This is NULL if the
148 library generated the key or if
149 the SKE key material was used. */
150 SilcUInt32 key_len; /* The key length */
151 } *SilcPrivateMessageKeys;
154 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
158 * typedef struct { ... } SilcChannelPrivateKey;
162 * Structure to hold one channel private key. The array of this structure
163 * is returned by silc_client_list_channel_private_keys function.
167 typedef struct SilcChannelPrivateKeyStruct {
168 char *name; /* Application given name */
169 SilcCipher cipher; /* The cipher and key */
170 SilcHmac hmac; /* The HMAC and hmac key */
171 unsigned char *key; /* The key data */
172 SilcUInt32 key_len; /* The key length */
173 } *SilcChannelPrivateKey;
176 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
180 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
181 * SilcUInt32 passphrase_len,
186 * Ask passphrase callback. This is called by the application when the
187 * library calls `ask_passphrase' client operation. The callback delivers
188 * the passphrase to the library. The passphrases in SILC protocol
189 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
190 * encoded, and if it is not then library will attempt to encode it.
193 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
194 SilcUInt32 passphrase_len,
197 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
201 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
205 * Public key (or certificate) verification callback. This is called
206 * by the application to indicate that the public key verification was
207 * either success or failure.
210 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
212 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
216 * typedef void (*SilcGetAuthMeth)(bool success,
217 * SilcProtocolAuthMeth auth_meth,
218 * const unsigned char *auth_data,
219 * SilcUInt32 auth_data_len, void *context);
223 * Authentication method resolving callback. This is called by the
224 * application to return the resolved authentication method. The client
225 * library has called the get_auth_method client operation and given
226 * this function pointer as argument. The `success' will indicate whether
227 * the authentication method could be resolved. The `auth_meth' is the
228 * resolved authentication method. The `auth_data' and the `auth_data_len'
229 * are the resolved authentication data. The `context' is the libary's
230 * context sent to the get_auth_method client operation.
233 typedef void (*SilcGetAuthMeth)(bool success,
234 SilcProtocolAuthMeth auth_meth,
235 const unsigned char *auth_data,
236 SilcUInt32 auth_data_len, void *context);
238 /****d* silcclient/SilcClientAPI/SilcClientMessageType
242 * typedef enum { ... } SilcClientMessageType;
246 * Different message types for `say' client operation. The application
247 * may filter the message sent by the library according this type.
252 SILC_CLIENT_MESSAGE_INFO, /* Informational */
253 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
254 SILC_CLIENT_MESSAGE_ERROR, /* Error */
255 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
256 } SilcClientMessageType;
259 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
263 * typedef enum { ... } SilcClientConnectionStatus
267 * This type is returned to the `connect' client operation to indicate
268 * the status of the created connection. It can indicated if it was
269 * successful or whether an error occurred.
274 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
275 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
276 resumed old detached session */
277 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
278 } SilcClientConnectionStatus;
281 /****s* silcclient/SilcClientAPI/SilcClientOperations
285 * typedef struct { ... } SilcClientOperations;
289 * SILC Client Operations. These must be implemented by the application.
290 * The Client library may call any of these routines at any time. The
291 * routines are used to deliver certain information to the application
292 * or from the application to the client library.
297 /* Message sent to the application by library. `conn' associates the
298 message to a specific connection. `conn', however, may be NULL.
299 The `type' indicates the type of the message sent by the library.
300 The applicationi can for example filter the message according the
302 void (*say)(SilcClient client, SilcClientConnection conn,
303 SilcClientMessageType type, char *msg, ...);
305 /* Message for a channel. The `sender' is the sender of the message
306 The `channel' is the channel. The `msg' is the message. Note that
308 void (*channel_message)(SilcClient client, SilcClientConnection conn,
309 SilcClientEntry sender, SilcChannelEntry channel,
310 SilcMessageFlags flags,
311 const unsigned char *message,
312 SilcUInt32 message_len);
314 /* Private message to the client. The `sender' is the sender of the
316 void (*private_message)(SilcClient client, SilcClientConnection conn,
317 SilcClientEntry sender, SilcMessageFlags flags,
318 const unsigned char *message,
319 SilcUInt32 message_len);
321 /* Notify message to the client. The notify arguments are sent in the
322 same order as servers sends them. The arguments are same as received
323 from the server except for ID's. If ID is received application receives
324 the corresponding entry to the ID. For example, if Client ID is received
325 application receives SilcClientEntry. Also, if the notify type is
326 for channel the channel entry is sent to application (even if server
327 does not send it because client library gets the channel entry from
328 the Channel ID in the packet's header). */
329 void (*notify)(SilcClient client, SilcClientConnection conn,
330 SilcNotifyType type, ...);
332 /* Command handler. This function is called always in the command function.
333 If error occurs it will be called as well. `conn' is the associated
334 client connection. `cmd_context' is the command context that was
335 originally sent to the command. `success' is FALSE if error occurred
336 during command. `command' is the command being processed. It must be
337 noted that this is not reply from server. This is merely called just
338 after application has called the command. Just to tell application
339 that the command really was processed. */
340 void (*command)(SilcClient client, SilcClientConnection conn,
341 SilcClientCommandContext cmd_context, bool success,
342 SilcCommand command, SilcStatus status);
344 /* Command reply handler. This function is called always in the command reply
345 function. If error occurs it will be called as well. Normal scenario
346 is that it will be called after the received command data has been parsed
347 and processed. The function is used to pass the received command data to
350 `conn' is the associated client connection. `cmd_payload' is the command
351 payload data received from server and it can be ignored. It is provided
352 if the application would like to re-parse the received command data,
353 however, it must be noted that the data is parsed already by the library
354 thus the payload can be ignored. `success' is FALSE if error occurred.
355 In this case arguments are not sent to the application. The `status' is
356 the command reply status server returned. The `command' is the command
357 reply being processed. The function has variable argument list and each
358 command defines the number and type of arguments it passes to the
359 application (on error they are not sent).
361 The arguments are sent in the same order as servers sends them. The
362 arguments are same as received from the server except for ID's. If
363 ID is received application receives the corresponding entry to the
364 ID. For example, if Client ID is receives application receives
366 void (*command_reply)(SilcClient client, SilcClientConnection conn,
367 SilcCommandPayload cmd_payload, bool success,
368 SilcCommand command, SilcStatus status, ...);
370 /* Called to indicate that connection was either successfully established
371 or connecting failed. This is also the first time application receives
372 the SilcClientConnection object which it should save somewhere.
373 The `status' indicated whether the connection were successful. If it
374 is error value the application must always call the function
375 silc_client_close_connection. */
376 void (*connect)(SilcClient client, SilcClientConnection conn,
377 SilcClientConnectionStatus status);
379 /* Called to indicate that connection was disconnected to the server.
380 The `status' may tell the reason of the disconnection, and if the
381 `message' is non-NULL it may include the disconnection message
382 received from server. */
383 void (*disconnect)(SilcClient client, SilcClientConnection conn,
384 SilcStatus status, const char *message);
386 /* Find authentication method and authentication data by hostname and
387 port. The hostname may be IP address as well. When the authentication
388 method has been resolved the `completion' callback with the found
389 authentication method and authentication data is called. The `conn'
391 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
392 char *hostname, SilcUInt16 port,
393 SilcGetAuthMeth completion, void *context);
395 /* Verifies received public key. The `conn_type' indicates which entity
396 (server, client etc.) has sent the public key. If user decides to trust
397 the key may be saved as trusted public key for later use. The
398 `completion' must be called after the public key has been verified. */
399 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
400 SilcSocketType conn_type, unsigned char *pk,
401 SilcUInt32 pk_len, SilcSKEPKType pk_type,
402 SilcVerifyPublicKey completion, void *context);
404 /* Ask (interact, that is) a passphrase from user. The passphrase is
405 returned to the library by calling the `completion' callback with
406 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
407 if not then the library will attempt to encode. */
408 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
409 SilcAskPassphrase completion, void *context);
411 /* Notifies application that failure packet was received. This is called
412 if there is some protocol active in the client. The `protocol' is the
413 protocol context. The `failure' is opaque pointer to the failure
414 indication. Note, that the `failure' is protocol dependant and
415 application must explicitly cast it to correct type. Usually `failure'
416 is 32 bit failure type (see protocol specs for all protocol failure
418 void (*failure)(SilcClient client, SilcClientConnection conn,
419 SilcProtocol protocol, void *failure);
421 /* Asks whether the user would like to perform the key agreement protocol.
422 This is called after we have received an key agreement packet or an
423 reply to our key agreement packet. This returns TRUE if the user wants
424 the library to perform the key agreement protocol and FALSE if it is not
425 desired (application may start it later by calling the function
426 silc_client_perform_key_agreement). If TRUE is returned also the
427 `completion' and `context' arguments must be set by the application. */
428 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
429 SilcClientEntry client_entry, const char *hostname,
430 SilcUInt16 port, SilcKeyAgreementCallback *completion,
433 /* Notifies application that file transfer protocol session is being
434 requested by the remote client indicated by the `client_entry' from
435 the `hostname' and `port'. The `session_id' is the file transfer
436 session and it can be used to either accept or reject the file
437 transfer request, by calling the silc_client_file_receive or
438 silc_client_file_close, respectively. */
439 void (*ftp)(SilcClient client, SilcClientConnection conn,
440 SilcClientEntry client_entry, SilcUInt32 session_id,
441 const char *hostname, SilcUInt16 port);
443 /* Delivers SILC session detachment data indicated by `detach_data' to the
444 application. If application has issued SILC_COMMAND_DETACH command
445 the client session in the SILC network is not quit. The client remains
446 in the network but is detached. The detachment data may be used later
447 to resume the session in the SILC Network. The appliation is
448 responsible of saving the `detach_data', to for example in a file.
450 The detachment data can be given as argument to the functions
451 silc_client_connect_to_server, or silc_client_add_connection when
452 creating connection to remote server, inside SilcClientConnectionParams
453 structure. If it is provided the client library will attempt to resume
454 the session in the network. After the connection is created
455 successfully, the application is responsible of setting the user
456 interface for user into the same state it was before detaching (showing
457 same channels, channel modes, etc). It can do this by fetching the
458 information (like joined channels) from the client library. */
459 void (*detach)(SilcClient client, SilcClientConnection conn,
460 const unsigned char *detach_data,
461 SilcUInt32 detach_data_len);
462 } SilcClientOperations;
465 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
469 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
470 * char **ret_nickname);
474 * A callback function provided by the application for the library in
475 * SilcClientParams structure. This function parses the formatted
476 * nickname string `nickname' and returns the true nickname to the
477 * `ret_nickname' pointer. The library can call this function at
481 typedef void (*SilcNicknameFormatParse)(const char *nickname,
482 char **ret_nickname);
484 /****s* silcclient/SilcClientAPI/SilcClientParams
488 * typedef struct { ... } SilcClientParams;
492 * Client parameters. This can be filled with proper values and
493 * given as argument to the silc_client_alloc function. The structure
494 * hold various parameters which affects the function of the client.
499 /* Number of maximum tasks the client library's scheduler can handle.
500 If set to zero, the default value will be used (200). For WIN32
501 systems this should be set to 64 as it is the hard limit dictated
505 /* Rekey timeout in seconds. The client will perform rekey in this
506 time interval. If set to zero, the default value will be used. */
507 unsigned int rekey_secs;
509 /* Connection authentication method request timeout. If server does not
510 reply back the current authentication method when we've requested it
511 in this time interval we'll assume the reply will not come at all.
512 If set to zero, the default value (2 seconds) will be used. */
513 unsigned int connauth_request_secs;
515 /* Nickname format string. This can be used to order the client library
516 to save the nicknames in the library in a certain format. Since
517 nicknames are not unique in SILC it is possible to have multiple same
518 nicknames. Using this format string it is possible to order the library
519 to separate the multiple same nicknames from each other. The format
520 types are defined below and they can appear in any order in the format
521 string. If this is NULL then default format is used which is the
522 default nickname without anything else. The string MUST be NULL
525 Following format types are available:
527 %n nickname - the real nickname returned by the server (mandatory)
528 %h hostname - the stripped hostname of the client
529 %H full hostname - the full hostname of the client
530 %s server name - the server name the client is connected
531 %S full server - the full server name the client is connected
532 %a number - ascending number in case there are several
533 same nicknames (fe. nick@host and nick@host2)
535 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
536 "%a!%n@%s" (fe. nick@server, 2!nick@server)
537 "%n@%H" (fe. nick@host.domain.com)
539 By default this format is employed to the nicknames by the libary
540 only when there appears multiple same nicknames. If the library has
541 only one nickname cached the nickname is saved as is and without the
542 defined format. If you want always to save the nickname in the defined
543 format set the boolean field `nickname_force_format' to value TRUE.
545 char nickname_format[32];
547 /* If this is set to TRUE then the `nickname_format' is employed to all
548 saved nicknames even if there are no multiple same nicknames in the
549 cache. By default this is FALSE, which means that the `nickname_format'
550 is employed only if the library will receive a nickname that is
551 already saved in the cache. It is recommended to leave this to FALSE
553 bool nickname_force_format;
555 /* A callback function provided by the application for the library to
556 parse the nickname from the formatted nickname string. Even though
557 the libary formats the nicknames the application knows generally the
558 format better so this function should be provided for the library
559 if the application sets the `nickname_format' field. The library
560 will call this to get the true nickname from the provided formatted
561 nickname string whenever it needs the true nickname. */
562 SilcNicknameFormatParse nickname_parse;
564 /* If this is set to TRUE then the client will ignore all incoming
565 Requested Attributes queries and does not reply anything back. This
566 usually leads into situation where server does not anymore send
567 the queries after seeing that client does not reply anything back.
568 If your application does not support Requested Attributes or you do
569 not want to use them set this to TRUE. See SilcAttribute and
570 silc_client_attribute_add for more information on attributes. */
571 bool ignore_requested_attributes;
577 /* Initialization functions (client.c) */
579 /****f* silcclient/SilcClientAPI/silc_client_alloc
583 * SilcClient silc_client_alloc(SilcClientOperations *ops,
584 * SilcClientParams *params,
586 * const char *silc_version);
590 * Allocates new client object. This has to be done before client may
591 * work. After calling this one must call silc_client_init to initialize
592 * the client. The `application' is application specific user data pointer
593 * and caller must free it. The `silc_version' is the application version
594 * that will be used to compare against remote host's (usually a server)
595 * version string. The `application' context is accessible by the
596 * application by client->application, client being SilcClient.
599 SilcClient silc_client_alloc(SilcClientOperations *ops,
600 SilcClientParams *params,
602 const char *silc_version);
604 /****f* silcclient/SilcClientAPI/silc_client_free
608 * void silc_client_free(SilcClient client);
612 * Frees client object and its internals. The execution of the client
613 * should be stopped with silc_client_stop function before calling
617 void silc_client_free(SilcClient client);
619 /****f* silcclient/SilcClientAPI/silc_client_init
623 * int silc_client_init(SilcClient client);
627 * Initializes the client. This makes all the necessary steps to make
628 * the client ready to be run. One must call silc_client_run to run the
629 * client. Returns FALSE if error occurred, TRUE otherwise.
632 int silc_client_init(SilcClient client);
634 /****f* silcclient/SilcClientAPI/silc_client_run
638 * void silc_client_run(SilcClient client);
642 * Runs the client. This starts the scheduler from the utility library.
643 * When this functions returns the execution of the appliation is over.
646 void silc_client_run(SilcClient client);
648 /****f* silcclient/SilcClientAPI/silc_client_run_one
652 * void silc_client_run_one(SilcClient client);
656 * Runs the client and returns immeadiately. This function is used when
657 * the SILC Client object indicated by the `client' is run under some
658 * other scheduler, or event loop or main loop. On GUI applications,
659 * for example this may be desired to used to run the client under the
660 * GUI application's main loop. Typically the GUI application would
661 * register an idle task that calls this function multiple times in
662 * a second to quickly process the SILC specific data.
665 void silc_client_run_one(SilcClient client);
667 /****f* silcclient/SilcClientAPI/silc_client_stop
671 * void silc_client_stop(SilcClient client);
675 * Stops the client. This is called to stop the client and thus to stop
676 * the program. The client context must be freed with the silc_client_free
680 void silc_client_stop(SilcClient client);
683 /* Connecting functions (client.c) */
685 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
689 * typedef struct { ... } SilcClientConnectionParams;
693 * Client connection parameters. This can be filled by the application
694 * and given as argument to silc_client_connect_to_server or to
695 * silc_client_add_connection.
700 /* The SILC session detachment data that was returned by `detach' client
701 operation when the application detached from the network. Application
702 is responsible of saving the data and giving it as argument here
703 for resuming the session in the SILC network.
705 If this is provided here the client library will attempt to resume
706 the session in the network. After the connection is created
707 successfully, the application is responsible of setting the user
708 interface for user into the same state it was before detaching (showing
709 same channels, channel modes, etc). It can do this by fetching the
710 information (like joined channels) from the client library. */
711 unsigned char *detach_data;
712 SilcUInt32 detach_data_len;
714 } SilcClientConnectionParams;
717 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
721 * int silc_client_connect_to_server(SilcClient client,
722 * SilcClientConnectionParams *params,
723 * int port, char *host, void *context);
727 * Connects to remote server. This is the main routine used to connect
728 * to SILC server. Returns -1 on error and the created socket otherwise.
729 * The `context' is user context that is saved into the SilcClientConnection
730 * that is created after the connection is created. Note that application
731 * may handle the connecting process outside the library. If this is the
732 * case then this function is not used at all. When the connecting is
733 * done the `connect' client operation is called, and the `context' is
734 * accessible with conn->context, conn being SilcClientConnection.
735 * If the `params' is provided they are used by the routine.
738 int silc_client_connect_to_server(SilcClient client,
739 SilcClientConnectionParams *params,
740 int port, char *host, void *context);
742 /****f* silcclient/SilcClientAPI/silc_client_add_connection
747 * SilcClientConnection
748 * silc_client_add_connection(SilcClient client,
749 * SilcClientConnectionParams *params,
750 * char *hostname, int port, void *context);
754 * Allocates and adds new connection to the client. This adds the allocated
755 * connection to the connection table and returns a pointer to it. A client
756 * can have multiple connections to multiple servers. Every connection must
757 * be added to the client using this function. User data `context' may
758 * be sent as argument. If the `params' is provided they are used by
763 * This function is normally used only if the application performed
764 * the connecting outside the library, and did not called the
765 * silc_client_connect_to_server function at all. The library
766 * however may use this internally.
770 silc_client_add_connection(SilcClient client,
771 SilcClientConnectionParams *params,
772 char *hostname, int port, void *context);
774 /****f* silcclient/SilcClientAPI/silc_client_del_connection
778 * void silc_client_del_connection(SilcClient client,
779 * SilcClientConnection conn);
783 * Removes connection from client. Frees all memory. The library
784 * call this function automatically for all connection contexts.
785 * The application however may free the connection contexts it has
789 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
791 /****f* silcclient/SilcClientAPI/silc_client_add_socket
795 * void silc_client_add_socket(SilcClient client,
796 * SilcSocketConnection sock);
800 * Adds listener socket to the listener sockets table. This function is
801 * used to add socket objects that are listeners to the client. This should
802 * not be used to add other connection objects.
805 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
807 /****f* silcclient/SilcClientAPI/silc_client_del_socket
811 * void silc_client_del_socket(SilcClient client,
812 * SilcSocketConnection sock);
816 * Deletes listener socket from the listener sockets table. If the
817 * application has added a socket with silc_client_add_socket it must
818 * also free it using this function.
821 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
823 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
827 * void silc_client_start_key_exchange(SilcClient client,
828 * SilcClientConnection conn,
833 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
834 * key material between client and server. This function can be called
835 * directly if application is performing its own connecting and does not
836 * use the connecting provided by this library. This function is normally
837 * used only if the application performed the connecting outside the
838 * library. The library however may use this internally. After the
839 * key exchange is performed the `connect' client operation is called.
842 void silc_client_start_key_exchange(SilcClient client,
843 SilcClientConnection conn,
846 /****f* silcclient/SilcClientAPI/silc_client_close_connection
850 * void silc_client_close_connection(SilcClient client,
851 * SilcClientConnection conn);
855 * Closes connection to remote end. Free's all allocated data except
856 * for some information such as nickname etc. that are valid at all time.
859 void silc_client_close_connection(SilcClient client,
860 SilcClientConnection conn);
863 /* Message sending functions (client_channel.c and client_prvmsg.c) */
865 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
869 * void silc_client_send_channel_message(SilcClient client,
870 * SilcClientConnection conn,
871 * SilcChannelEntry channel,
872 * SilcChannelPrivateKey key,
873 * SilcMessageFlags flags,
874 * unsigned char *data,
875 * SilcUInt32 data_len,
880 * Sends packet to the `channel'. Packet to channel is always encrypted
881 * differently from "normal" packets. SILC header of the packet is
882 * encrypted with the next receiver's key and the rest of the packet is
883 * encrypted with the channel specific key. Padding and HMAC is computed
884 * with the next receiver's key. The `data' is the channel message. If
885 * the `force_send' is TRUE then the packet is sent immediately.
887 * If `key' is provided then that private key is used to encrypt the
888 * channel message. If it is not provided, private keys has not been
889 * set at all, the normal channel key is used automatically. If private
890 * keys are set then the first key (the key that was added first as
891 * private key) is used.
894 void silc_client_send_channel_message(SilcClient client,
895 SilcClientConnection conn,
896 SilcChannelEntry channel,
897 SilcChannelPrivateKey key,
898 SilcMessageFlags flags,
903 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
907 * void silc_client_send_private_message(SilcClient client,
908 * SilcClientConnection conn,
909 * SilcClientEntry client_entry,
910 * SilcMessageFlags flags,
911 * unsigned char *data,
912 * SilcUInt32 data_len,
917 * Sends private message to remote client. If private message key has
918 * not been set with this client then the message will be encrypted using
919 * normal session keys. Private messages are special packets in SILC
920 * network hence we need this own function for them. This is similar
921 * to silc_client_packet_send_to_channel except that we send private
922 * message. The `data' is the private message. If the `force_send' is
923 * TRUE the packet is sent immediately.
926 void silc_client_send_private_message(SilcClient client,
927 SilcClientConnection conn,
928 SilcClientEntry client_entry,
929 SilcMessageFlags flags,
935 /* Client and Channel entry retrieval (idlist.c) */
937 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
941 * typedef void (*SilcGetClientCallback)(SilcClient client,
942 * SilcClientConnection conn,
943 * SilcClientEntry *clients,
944 * SilcUInt32 clients_count,
949 * Callback function given to the silc_client_get_client function. The
950 * found entries are allocated into the `clients' array. The array must
951 * not be freed by the receiver, the library will free it later. If the
952 * `clients' is NULL, no such clients exist in the SILC Network.
955 typedef void (*SilcGetClientCallback)(SilcClient client,
956 SilcClientConnection conn,
957 SilcClientEntry *clients,
958 SilcUInt32 clients_count,
961 /****f* silcclient/SilcClientAPI/silc_client_get_clients
965 * void silc_client_get_clients(SilcClient client,
966 * SilcClientConnection conn,
967 * const char *nickname,
968 * const char *server,
969 * SilcGetClientCallback completion,
974 * Finds client entry or entries by the `nickname' and `server'. The
975 * completion callback will be called when the client entries has been
976 * found. After the server returns the client information it is cached
977 * and can be accesses locally at a later time.
981 * NOTE: This function is always asynchronous and resolves the client
982 * information from the server. Thus, if you already know the client
983 * information then use the silc_client_get_client_by_id function to
984 * get the client entry since this function may be very slow and should
985 * be used only to initially get the client entries.
988 void silc_client_get_clients(SilcClient client,
989 SilcClientConnection conn,
990 const char *nickname,
992 SilcGetClientCallback completion,
995 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
999 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1000 * SilcClientConnection conn,
1001 * const char *nickname,
1002 * const char *format,
1003 * SilcUInt32 *clients_count);
1007 * Same as silc_client_get_clients function but does not resolve anything
1008 * from the server. This checks local cache and returns all matching
1009 * clients from the local cache. If none was found this returns NULL.
1010 * The `nickname' is the real nickname of the client, and the `format'
1011 * is the formatted nickname to find exact match from multiple found
1012 * entries. The format must be same as given in the SilcClientParams
1013 * structure to the client library. If the `format' is NULL all found
1014 * clients by `nickname' are returned. The caller must return the
1018 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1019 SilcClientConnection conn,
1020 const char *nickname,
1022 SilcUInt32 *clients_count);
1024 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1028 * void silc_client_get_clients_by_list(SilcClient client,
1029 * SilcClientConnection conn,
1030 * SilcUInt32 list_count,
1031 * SilcBuffer client_id_list,
1032 * SilcGetClientCallback completion,
1037 * Gets client entries by the list of client ID's `client_id_list'. This
1038 * always resolves those client ID's it does not know yet from the server
1039 * so this function might take a while. The `client_id_list' is a list
1040 * of ID Payloads added one after other. JOIN command reply and USERS
1041 * command reply for example returns this sort of list. The `completion'
1042 * will be called after the entries are available. When server returns
1043 * the client information it will be cached and can be accessed locally
1047 void silc_client_get_clients_by_list(SilcClient client,
1048 SilcClientConnection conn,
1049 SilcUInt32 list_count,
1050 SilcBuffer client_id_list,
1051 SilcGetClientCallback completion,
1054 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1058 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1059 * SilcClientConnection conn,
1060 * SilcClientID *client_id);
1064 * Find entry for client by the client's ID. Returns the entry or NULL
1065 * if the entry was not found. This checks the local cache and does
1066 * not resolve anything from server.
1069 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1070 SilcClientConnection conn,
1071 SilcClientID *client_id);
1073 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1078 * silc_client_get_client_by_id_resolve(SilcClient client,
1079 * SilcClientConnection conn,
1080 * SilcClientID *client_id,
1081 * SilcBuffer attributes,
1082 * SilcGetClientCallback completion,
1087 * Same as silc_client_get_client_by_id but will always resolve the
1088 * information from the server. Use this only if you know that you
1089 * do not have the entry and the only thing you know about the client
1090 * is its ID. When server returns the client information it will be
1091 * cache and can be accessed locally at a later time.
1093 * If the `attributes' is non-NULL then the buffer includes Requested
1094 * Attributes which can be used to fetch very detailed information
1095 * about the user. If it is NULL then only normal WHOIS query is
1096 * made (for more information about attributes see SilcAttribute).
1097 * Caller may create the `attributes' with silc_client_attributes_request
1101 void silc_client_get_client_by_id_resolve(SilcClient client,
1102 SilcClientConnection conn,
1103 SilcClientID *client_id,
1104 SilcBuffer attributes,
1105 SilcGetClientCallback completion,
1108 /****f* silcclient/SilcClientAPI/silc_client_del_client
1112 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1113 * SilcClientEntry client_entry)
1117 * Removes client from local cache by the client entry indicated by
1118 * the `client_entry'. Returns TRUE if the deletion were successful.
1121 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1122 SilcClientEntry client_entry);
1124 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1128 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1129 * SilcClientConnection conn,
1130 * SilcChannelEntry *channels,
1131 * SilcUInt32 channels_count,
1136 * Callback function given to the silc_client_get_channel_* functions.
1137 * The found entries are allocated into the `channels' array. The array
1138 * must not be freed by the receiver, the library will free it later.
1139 * If the `channel' is NULL, no such channel exist in the SILC Network.
1142 typedef void (*SilcGetChannelCallback)(SilcClient client,
1143 SilcClientConnection conn,
1144 SilcChannelEntry *channels,
1145 SilcUInt32 channels_count,
1148 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1152 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1153 * SilcClientConnection conn,
1158 * Finds entry for channel by the channel name. Returns the entry or NULL
1159 * if the entry was not found. It is found only if the client is joined
1163 SilcChannelEntry silc_client_get_channel(SilcClient client,
1164 SilcClientConnection conn,
1167 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1172 * silc_client_get_channel_by_id(SilcClient client,
1173 * SilcClientConnection conn,
1174 * SilcChannelID *channel_id);
1178 * Finds channel entry by the channel name. Returns the entry or NULL
1179 * if it was not found.
1182 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1183 SilcClientConnection conn,
1184 SilcChannelID *channel_id);
1186 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1191 * silc_client_get_channel_by_id_resolve(SilcClient client,
1192 * SilcClientConnection conn,
1193 * SilcChannelID *channel_id,
1194 * SilcGetClientCallback completion,
1199 * Resolves the channel information (its name mainly) from the server
1200 * by the `channel_id'. Use this only if you know that you do not have
1201 * the entry cached locally.
1204 void silc_client_get_channel_by_id_resolve(SilcClient client,
1205 SilcClientConnection conn,
1206 SilcChannelID *channel_id,
1207 SilcGetChannelCallback completion,
1210 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1214 * bool silc_client_del_channel(SilcClient client,
1215 * SilcClientConnection conn,
1216 * SilcChannelEntry channel)
1220 * Removes channel from local cache by the channel entry indicated by
1221 * the `channel'. Returns TRUE if the deletion were successful.
1224 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1225 SilcChannelEntry channel);
1227 /****f* silcclient/SilcClientAPI/silc_client_get_server
1231 * SilcServerEntry silc_client_get_server(SilcClient client,
1232 * SilcClientConnection conn,
1233 * char *server_name)
1237 * Finds entry for server by the server name. Returns the entry or NULL
1238 * if the entry was not found.
1241 SilcServerEntry silc_client_get_server(SilcClient client,
1242 SilcClientConnection conn,
1245 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1249 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1250 * SilcClientConnection conn,
1251 * SilcServerID *server_id);
1255 * Finds entry for server by the server ID. Returns the entry or NULL
1256 * if the entry was not found.
1259 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1260 SilcClientConnection conn,
1261 SilcServerID *server_id);
1263 /****f* silcclient/SilcClientAPI/silc_client_del_server
1267 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1268 * SilcServerEntry server);
1272 * Removes server from local cache by the server entry indicated by
1273 * the `server'. Returns TRUE if the deletion were successful.
1276 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1277 SilcServerEntry server);
1279 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1283 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1284 * SilcClientEntry client_entry);
1288 * Returns the ChannelUser entry if the `client_entry' is joined on the
1289 * channel indicated by the `channel'. NULL if client is not joined on
1293 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1294 SilcClientEntry client_entry);
1296 /* Command management (command.c) */
1298 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1302 * SilcClientCommandContext silc_client_command_alloc(void);
1306 * Allocate Command Context. The context is defined in `command.h' file.
1307 * The context is used by the library commands and applications should use
1308 * it as well. However, application may choose to use some own context
1309 * for its local commands. All library commands, however, must use this
1313 SilcClientCommandContext silc_client_command_alloc(void);
1315 /****f* silcclient/SilcClientAPI/silc_client_command_free
1319 * void silc_client_command_free(SilcClientCommandContext ctx);
1323 * Free command context and its internals. If the contex was duplicated
1324 * with silc_client_command_dup this may not actually free the data,
1325 * instead it will decrease the reference counter of the context. The
1326 * context will be freed when the reference counter hits zero.
1329 void silc_client_command_free(SilcClientCommandContext ctx);
1331 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1335 * SilcClientCommandContext
1336 * silc_client_command_dup(SilcClientCommandContext ctx);
1340 * Duplicate Command Context by adding reference counter. The context won't
1341 * be free'd untill it hits zero.
1344 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1346 /****f* silcclient/SilcClientAPI/silc_client_command_find
1350 * SilcClientCommand silc_client_command_find(SilcClient client,
1351 * const char *name);
1355 * Finds and returns a pointer to the command list. Return NULL if the
1356 * command is not found. See the `command.[ch]' for the command list.
1357 * Command names are not case-sensitive.
1360 SilcClientCommand silc_client_command_find(SilcClient client,
1363 /****f* silcclient/SilcClientAPI/silc_client_command_call
1367 * void silc_client_command_call(SilcClientCommand command);
1371 * Calls the command (executes it). Application can call this after
1372 * it has allocated the SilcClientCommandContext with the function
1373 * silc_client_command_alloc and found the command from the client
1374 * library by calling silc_client_command_find. This will execute
1377 * Application can call the command function directly too if it
1378 * wishes to do so. See the command.h for details of the
1379 * SilcClientCommand structure.
1382 void silc_client_command_call(SilcClientCommand command,
1383 SilcClientCommandContext cmd);
1385 /****f* silcclient/SilcClientAPI/silc_client_command_send
1389 * void silc_client_command_send(SilcClient client,
1390 * SilcClientConnection conn,
1391 * SilcCommand command, SilcUInt16 ident,
1392 * SilcUInt32 argc, ...);
1396 * Generic function to send any command. The arguments must be sent already
1397 * encoded into correct form and in correct order. If application wants
1398 * to perform the commands by itself, it can do so and send the data
1399 * directly to the server using this function. If application is using
1400 * the silc_client_command_call, this function is usually not used.
1403 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1404 SilcCommand command, SilcUInt16 ident,
1405 SilcUInt32 argc, ...);
1407 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1411 * void silc_client_command_pending(SilcClientConnection conn,
1412 * SilcCommand reply_cmd,
1414 * SilcCommandCb callback,
1419 * Add new pending command to be executed when reply to a command has been
1420 * received. The `reply_cmd' is the command that will call the `callback'
1421 * with `context' when reply has been received. If `ident' is non-zero
1422 * the `callback' will be executed when received reply with command
1423 * identifier `ident'.
1425 * Note that the application is notified about the received command
1426 * reply through the `command_reply' client operation before calling
1427 * the `callback` pending command callback.
1430 void silc_client_command_pending(SilcClientConnection conn,
1431 SilcCommand reply_cmd,
1433 SilcCommandCb callback,
1437 /* Private Message key management (client_prvmsg.c) */
1439 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1443 * int silc_client_add_private_message_key(SilcClient client,
1444 * SilcClientConnection conn,
1445 * SilcClientEntry client_entry,
1447 * unsigned char *key,
1448 * SilcUInt32 key_len,
1449 * bool generate_key,
1454 * Adds private message key to the client library. The key will be used to
1455 * encrypt all private message between the client and the remote client
1456 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1457 * value `generate_key' is TRUE the library will generate random key.
1458 * The `key' maybe for example pre-shared-key, passphrase or similar.
1459 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1460 * requirements of the SILC protocol are met. The API, however, allows
1461 * to allocate any cipher.
1463 * If `responder' is TRUE then the sending and receiving keys will be
1464 * set according the client being the receiver of the private key. If
1465 * FALSE the client is being the sender (or negotiator) of the private
1468 * It is not necessary to set key for normal private message usage. If the
1469 * key is not set then the private messages are encrypted using normal
1470 * session keys. Setting the private key, however, increases the security.
1472 * Returns FALSE if the key is already set for the `client_entry', TRUE
1476 int silc_client_add_private_message_key(SilcClient client,
1477 SilcClientConnection conn,
1478 SilcClientEntry client_entry,
1485 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1489 * int silc_client_add_private_message_key_ske(SilcClient client,
1490 * SilcClientConnection conn,
1491 * SilcClientEntry client_entry,
1493 * SilcSKEKeyMaterial *key);
1497 * Same as silc_client_add_private_message_key but takes the key material
1498 * from the SKE key material structure. This structure is received if
1499 * the application uses the silc_client_send_key_agreement to negotiate
1500 * the key material. The `cipher' SHOULD be provided as it is negotiated
1501 * also in the SKE protocol.
1504 int silc_client_add_private_message_key_ske(SilcClient client,
1505 SilcClientConnection conn,
1506 SilcClientEntry client_entry,
1508 SilcSKEKeyMaterial *key,
1511 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1515 * int silc_client_send_private_message_key(SilcClient client,
1516 * SilcClientConnection conn,
1517 * SilcClientEntry client_entry,
1522 * Sends private message key payload to the remote client indicated by
1523 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1524 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1525 * application should call this function after setting the key to the
1528 * Note that the key sent using this function is sent to the remote client
1529 * through the SILC network. The packet is protected using normal session
1533 int silc_client_send_private_message_key(SilcClient client,
1534 SilcClientConnection conn,
1535 SilcClientEntry client_entry,
1538 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1542 * int silc_client_del_private_message_key(SilcClient client,
1543 * SilcClientConnection conn,
1544 * SilcClientEntry client_entry);
1548 * Removes the private message from the library. The key won't be used
1549 * after this to protect the private messages with the remote `client_entry'
1550 * client. Returns FALSE on error, TRUE otherwise.
1553 int silc_client_del_private_message_key(SilcClient client,
1554 SilcClientConnection conn,
1555 SilcClientEntry client_entry);
1557 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1561 * SilcPrivateMessageKeys
1562 * silc_client_list_private_message_keys(SilcClient client,
1563 * SilcClientConnection conn,
1564 * SilcUInt32 *key_count);
1568 * Returns array of set private message keys associated to the connection
1569 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1570 * count to the `key_count' argument. The array must be freed by the caller
1571 * by calling the silc_client_free_private_message_keys function. Note:
1572 * the keys returned in the array is in raw format. It might not be desired
1573 * to show the keys as is. The application might choose not to show the keys
1574 * at all or to show the fingerprints of the keys.
1577 SilcPrivateMessageKeys
1578 silc_client_list_private_message_keys(SilcClient client,
1579 SilcClientConnection conn,
1580 SilcUInt32 *key_count);
1582 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1586 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1587 * SilcUInt32 key_count);
1591 * Frees the SilcPrivateMessageKeys array returned by the function
1592 * silc_client_list_private_message_keys.
1595 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1596 SilcUInt32 key_count);
1599 /* Channel private key management (client_channel.c,
1600 SilcChannelPrivateKey is defined in idlist.h) */
1602 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1606 * int silc_client_add_channel_private_key(SilcClient client,
1607 * SilcClientConnection conn,
1608 * SilcChannelEntry channel,
1612 * unsigned char *key,
1613 * SilcUInt32 key_len);
1617 * Adds private key for channel. This may be set only if the channel's mode
1618 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1619 * mode is not set. When channel has private key then the messages are
1620 * encrypted using that key. All clients on the channel must also know the
1621 * key in order to decrypt the messages. However, it is possible to have
1622 * several private keys per one channel. In this case only some of the
1623 * clients on the channel may know the one key and only some the other key.
1624 * The `name' can be application given name for the key.
1626 * The private key for channel is optional. If it is not set then the
1627 * channel messages are encrypted using the channel key generated by the
1628 * server. However, setting the private key (or keys) for the channel
1629 * significantly adds security. If more than one key is set the library
1630 * will automatically try all keys at the message decryption phase. Note:
1631 * setting many keys slows down the decryption phase as all keys has to
1632 * be tried in order to find the correct decryption key. However, setting
1633 * a few keys does not have big impact to the decryption performace.
1637 * NOTE: This is entirely local setting. The key set using this function
1638 * is not sent to the network at any phase.
1640 * NOTE: If the key material was originated by the SKE protocol (using
1641 * silc_client_send_key_agreement) then the `key' MUST be the
1642 * key->send_enc_key as this is dictated by the SILC protocol. However,
1643 * currently it is not expected that the SKE key material would be used
1644 * as channel private key. However, this API allows it.
1647 int silc_client_add_channel_private_key(SilcClient client,
1648 SilcClientConnection conn,
1649 SilcChannelEntry channel,
1654 SilcUInt32 key_len);
1656 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1660 * int silc_client_del_channel_private_keys(SilcClient client,
1661 * SilcClientConnection conn,
1662 * SilcChannelEntry channel);
1666 * Removes all private keys from the `channel'. The old channel key is used
1667 * after calling this to protect the channel messages. Returns FALSE on
1668 * on error, TRUE otherwise.
1671 int silc_client_del_channel_private_keys(SilcClient client,
1672 SilcClientConnection conn,
1673 SilcChannelEntry channel);
1675 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1679 * int silc_client_del_channel_private_key(SilcClient client,
1680 * SilcClientConnection conn,
1681 * SilcChannelEntry channel,
1682 * SilcChannelPrivateKey key);
1686 * Removes and frees private key `key' from the channel `channel'.
1687 * The `key' is retrieved by calling the function
1688 * silc_client_list_channel_private_keys. The key is not used after
1689 * this. If the key was last private key then the old channel key is
1690 * used hereafter to protect the channel messages. This returns FALSE
1691 * on error, TRUE otherwise.
1694 int silc_client_del_channel_private_key(SilcClient client,
1695 SilcClientConnection conn,
1696 SilcChannelEntry channel,
1697 SilcChannelPrivateKey key);
1699 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1703 * SilcChannelPrivateKey *
1704 * silc_client_list_channel_private_keys(SilcClient client,
1705 * SilcClientConnection conn,
1706 * SilcChannelEntry channel,
1707 * SilcUInt32 *key_count);
1711 * Returns array (pointers) of private keys associated to the `channel'.
1712 * The caller must free the array by calling the function
1713 * silc_client_free_channel_private_keys. The pointers in the array may be
1714 * used to delete the specific key by giving the pointer as argument to the
1715 * function silc_client_del_channel_private_key.
1718 SilcChannelPrivateKey *
1719 silc_client_list_channel_private_keys(SilcClient client,
1720 SilcClientConnection conn,
1721 SilcChannelEntry channel,
1722 SilcUInt32 *key_count);
1724 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1728 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1729 * SilcUInt32 key_count);
1733 * Frees the SilcChannelPrivateKey array.
1736 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1737 SilcUInt32 key_count);
1739 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1743 * void silc_client_current_channel_private_key(SilcClient client,
1744 * SilcClientConnection conn,
1745 * SilcChannelEntry channel,
1746 * SilcChannelPrivateKey key);
1750 * Sets the `key' to be used as current channel private key on the
1751 * `channel'. Packet sent after calling this function will be secured
1755 void silc_client_current_channel_private_key(SilcClient client,
1756 SilcClientConnection conn,
1757 SilcChannelEntry channel,
1758 SilcChannelPrivateKey key);
1761 /* Key Agreement routines (client_keyagr.c) */
1763 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1767 * void silc_client_send_key_agreement(SilcClient client,
1768 * SilcClientConnection conn,
1769 * SilcClientEntry client_entry,
1772 * SilcUInt32 timeout_secs,
1773 * SilcKeyAgreementCallback completion,
1778 * Sends key agreement request to the remote client indicated by the
1779 * `client_entry'. If the caller provides the `hostname' and the `port'
1780 * arguments then the library will bind the client to that hostname and
1781 * that port for the key agreement protocol. It also sends the `hostname'
1782 * and the `port' in the key agreement packet to the remote client. This
1783 * would indicate that the remote client may initiate the key agreement
1784 * protocol to the `hostname' on the `port'. If port is zero then the
1785 * bound port is undefined (the operating system defines it).
1787 * If the `hostname' and `port' is not provided then empty key agreement
1788 * packet is sent to the remote client. The remote client may reply with
1789 * the same packet including its hostname and port. If the library receives
1790 * the reply from the remote client the `key_agreement' client operation
1791 * callback will be called to verify whether the user wants to perform the
1792 * key agreement or not.
1796 * NOTE: If the application provided the `hostname' and the `port' and the
1797 * remote side initiates the key agreement protocol it is not verified
1798 * from the user anymore whether the protocol should be executed or not.
1799 * By setting the `hostname' and `port' the user gives permission to
1800 * perform the protocol (we are responder in this case).
1802 * NOTE: If the remote side decides not to initiate the key agreement
1803 * or decides not to reply with the key agreement packet then we cannot
1804 * perform the key agreement at all. If the key agreement protocol is
1805 * performed the `completion' callback with the `context' will be called.
1806 * If remote side decides to ignore the request the `completion' will be
1807 * called after the specified timeout, `timeout_secs'.
1809 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1810 * will not be called at all since this does nothing more than sending
1811 * a packet to the remote host.
1813 * NOTE: There can be only one active key agreement for one client entry.
1814 * Before setting new one, the old one must be finished (it is finished
1815 * after calling the completion callback) or the function
1816 * silc_client_abort_key_agreement must be called.
1819 void silc_client_send_key_agreement(SilcClient client,
1820 SilcClientConnection conn,
1821 SilcClientEntry client_entry,
1822 const char *hostname,
1823 const char *bindhost,
1825 SilcUInt32 timeout_secs,
1826 SilcKeyAgreementCallback completion,
1829 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1834 * silc_client_perform_key_agreement(SilcClient client,
1835 * SilcClientConnection conn,
1836 * SilcClientEntry client_entry,
1839 * SilcKeyAgreementCallback completion,
1844 * Performs the actual key agreement protocol. Application may use this
1845 * to initiate the key agreement protocol. This can be called for example
1846 * after the application has received the `key_agreement' client operation,
1847 * and did not return TRUE from it.
1849 * The `hostname' is the remote hostname (or IP address) and the `port'
1850 * is the remote port. The `completion' callback with the `context' will
1851 * be called after the key agreement protocol.
1855 * NOTE: If the application returns TRUE in the `key_agreement' client
1856 * operation the library will automatically start the key agreement. In this
1857 * case the application must not call this function. However, application
1858 * may choose to just ignore the `key_agreement' client operation (and
1859 * merely just print information about it on the screen) and call this
1860 * function when the user whishes to do so (by, for example, giving some
1861 * specific command). Thus, the API provides both, automatic and manual
1862 * initiation of the key agreement. Calling this function is the manual
1863 * initiation and returning TRUE in the `key_agreement' client operation
1864 * is the automatic initiation.
1867 void silc_client_perform_key_agreement(SilcClient client,
1868 SilcClientConnection conn,
1869 SilcClientEntry client_entry,
1872 SilcKeyAgreementCallback completion,
1875 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1880 * silc_client_perform_key_agreement_fd(SilcClient client,
1881 * SilcClientConnection conn,
1882 * SilcClientEntry client_entry,
1885 * SilcKeyAgreementCallback completion,
1890 * Same as above but application has created already the connection to
1891 * the remote host. The `sock' is the socket to the remote connection.
1892 * Application can use this function if it does not want the client library
1893 * to create the connection.
1896 void silc_client_perform_key_agreement_fd(SilcClient client,
1897 SilcClientConnection conn,
1898 SilcClientEntry client_entry,
1901 SilcKeyAgreementCallback completion,
1904 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1908 * void silc_client_abort_key_agreement(SilcClient client,
1909 * SilcClientConnection conn,
1910 * SilcClientEntry client_entry);
1914 * This function can be called to unbind the hostname and the port for
1915 * the key agreement protocol. However, this function has effect only
1916 * before the key agreement protocol has been performed. After it has
1917 * been performed the library will automatically unbind the port. The
1918 * `client_entry' is the client to which we sent the key agreement
1919 * request. The key agreement completion callback will be called
1920 * with SILC_KEY_AGREEMENT_ABORTED status.
1923 void silc_client_abort_key_agreement(SilcClient client,
1924 SilcClientConnection conn,
1925 SilcClientEntry client_entry);
1928 /* Misc functions */
1930 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1934 * void silc_client_set_away_message(SilcClient client,
1935 * SilcClientConnection conn,
1940 * Sets away `message'. The away message may be set when the client's
1941 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1942 * to anyone who sends private message. The `message' will be sent
1943 * automatically back to the the client who send private message. If
1944 * away message is already set this replaces the old message with the
1945 * new one. If `message' is NULL the old away message is removed.
1946 * The sender may freely free the memory of the `message'.
1949 void silc_client_set_away_message(SilcClient client,
1950 SilcClientConnection conn,
1954 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1958 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1959 * SilcClientConnection conn,
1960 * SilcAuthMethod auth_meth,
1965 * Connection authentication method request callback. This is called
1966 * by the client library after it has received the authentication method
1967 * that the application requested by calling the function
1968 * silc_client_request_authentication_method.
1971 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1972 SilcClientConnection conn,
1973 SilcAuthMethod auth_meth,
1976 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1981 * silc_client_request_authentication_method(SilcClient client,
1982 * SilcClientConnection conn,
1983 * SilcConnectionAuthRequest
1989 * This function can be used to request the current authentication method
1990 * from the server. This may be called when connecting to the server
1991 * and the client library requests the authentication data from the
1992 * application. If the application does not know the current authentication
1993 * method it can request it from the server using this function.
1994 * The `callback' with `context' will be called after the server has
1995 * replied back with the current authentication method.
1999 silc_client_request_authentication_method(SilcClient client,
2000 SilcClientConnection conn,
2001 SilcConnectionAuthRequest callback,
2004 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2008 * typedef enum { ... } SilcClientMonitorStatus;
2012 * File transmission session status types. These will indicate
2013 * the status of the file transmission session.
2018 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2019 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2020 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2021 SILC_CLIENT_FILE_MONITOR_GET,
2022 SILC_CLIENT_FILE_MONITOR_PUT,
2023 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2024 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2025 } SilcClientMonitorStatus;
2028 /****d* silcclient/SilcClientAPI/SilcClientFileError
2032 * typedef enum { ... } SilcClientFileError;
2036 * File transmission error types. These types are returned by
2037 * some of the file transmission functions, and by the monitor
2038 * callback to indicate error.
2043 SILC_CLIENT_FILE_OK,
2044 SILC_CLIENT_FILE_ERROR,
2045 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2046 SILC_CLIENT_FILE_ALREADY_STARTED,
2047 SILC_CLIENT_FILE_NO_SUCH_FILE,
2048 SILC_CLIENT_FILE_PERMISSION_DENIED,
2049 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2050 } SilcClientFileError;
2053 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2057 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2058 * SilcClientConnection conn,
2059 * SilcClientMonitorStatus status,
2060 * SilcClientFileError error,
2061 * SilcUInt64 offset,
2062 * SilcUInt64 filesize,
2063 * SilcClientEntry client_entry,
2064 * SilcUInt32 session_id,
2065 * const char *filepath,
2070 * Monitor callback that is called during the file transmission to
2071 * monitor the transmission process. The `status' indicates the current
2072 * monitoring process. The `error' will indicate the error type
2073 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2074 * currently transmitted amount of total `filesize'. The `client_entry'
2075 * indicates the remote client, and the transmission session ID is the
2076 * `session_id'. The filename being transmitted is indicated by the
2080 typedef void (*SilcClientFileMonitor)(SilcClient client,
2081 SilcClientConnection conn,
2082 SilcClientMonitorStatus status,
2083 SilcClientFileError error,
2085 SilcUInt64 filesize,
2086 SilcClientEntry client_entry,
2087 SilcUInt32 session_id,
2088 const char *filepath,
2091 /****f* silcclient/SilcClientAPI/silc_client_file_send
2095 * SilcClientFileError
2096 * silc_client_file_send(SilcClient client,
2097 * SilcClientConnection conn,
2098 * SilcClientFileMonitor monitor,
2099 * void *monitor_context,
2100 * const char *local_ip,
2101 * SilcUInt32 local_port,
2102 * SilcClientEntry client_entry,
2103 * const char *filepath);
2104 * SilcUInt32 *session_id);
2108 * Sends a file indicated by the `filepath' to the remote client
2109 * indicated by the `client_entry'. This will negotiate a secret key
2110 * with the remote client before actually starting the transmission of
2111 * the file. The `monitor' callback will be called to monitor the
2112 * transmission of the file.
2114 * This returns a file session ID for the file transmission to the
2115 * `session_id' pointer.. It can be used to close the session (and
2116 * abort the file transmission) by calling the silc_client_file_close
2117 * function. The session ID is also returned in the `monitor' callback.
2119 * If the `local_ip' is provided then this will try to bind the
2120 * listener for key exchange protocol to that IP. If `local_port' is
2121 * non-zero that port is used. If `local_ip' is NULL then this will
2122 * automatically attempt to bind it to local IP address of the machine.
2123 * If that fails then this does not bind to any address and port, and
2124 * assume that the remote client will provide the listener for the
2125 * key exchange protocol.
2127 * If error will occur during the file transfer process the error
2128 * status will be returned in the monitor callback. In this case
2129 * the application must call silc_client_file_close to close the
2134 silc_client_file_send(SilcClient client,
2135 SilcClientConnection conn,
2136 SilcClientFileMonitor monitor,
2137 void *monitor_context,
2138 const char *local_ip,
2139 SilcUInt32 local_port,
2140 SilcClientEntry client_entry,
2141 const char *filepath,
2142 SilcUInt32 *session_id);
2144 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2148 * SilcClientFileError
2149 * silc_client_file_receive(SilcClient client,
2150 * SilcClientConnection conn,
2151 * SilcClientFileMonitor monitor,
2152 * void *monitor_context,
2154 * SilcUInt32 session_id);
2158 * Receives a file from a client indicated by the `client_entry'. The
2159 * `session_id' indicates the file transmission session and it has been
2160 * received in the `ftp' client operation function. This will actually
2161 * perform the key agreement protocol with the remote client before
2162 * actually starting the file transmission. The `monitor' callback
2163 * will be called to monitor the transmission. If `path' is non NULL
2164 * the file will be saved into that directory. If NULL the file is
2165 * saved in the current working directory.
2167 * If error will occur during the file transfer process the error
2168 * status will be returned in the monitor callback. In this case
2169 * the application must call silc_client_file_close to close the
2174 silc_client_file_receive(SilcClient client,
2175 SilcClientConnection conn,
2176 SilcClientFileMonitor monitor,
2177 void *monitor_context,
2179 SilcUInt32 session_id);
2181 /****f* silcclient/SilcClientAPI/silc_client_file_close
2185 * SilcClientFileError silc_client_file_close(SilcClient client,
2186 * SilcClientConnection conn,
2187 * SilcUInt32 session_id);
2191 * Closes file transmission session indicated by the `session_id'.
2192 * If file transmission is being conducted it will be aborted
2193 * automatically. This function is also used to close the session
2194 * after successful file transmission. This function can be used
2195 * also to reject incoming file transmission request.
2198 SilcClientFileError silc_client_file_close(SilcClient client,
2199 SilcClientConnection conn,
2200 SilcUInt32 session_id);
2202 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2206 * SilcAttributePayload
2207 * silc_client_attribute_add(SilcClient client,
2208 * SilcClientConnection conn,
2209 * SilcAttribute attribute,
2211 * SilcUInt32 object_size);
2215 * Add new Requsted Attribute for WHOIS command to the client library.
2216 * The `attribute' object indicated by `object' is added and allocated
2217 * SilcAttributePayload is returned. The `object' must be of correct
2218 * type and of correct size. See the SilcAttribute for object types
2219 * for different attributes. You may also get all added attributes
2220 * from the client with silc_client_attributes_get function.
2222 * Requested Attributes are different personal information about the
2223 * user, status information and other information which other users
2224 * may query with WHOIS command. Application may set these so that
2225 * if someone sends WHOIS query these attributes will be replied back
2226 * to the sender. The library always puts the public key to the
2227 * Requested Attributes, but if application wishes to add additional
2228 * public keys (or certificates) it can be done with this interface.
2229 * Library also always computes digital signature of the attributes
2230 * automatically, so application does not need to do that.
2233 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2234 SilcClientConnection conn,
2235 SilcAttribute attribute,
2237 SilcUInt32 object_size);
2239 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2243 * bool silc_client_attribute_del(SilcClient client,
2244 * SilcClientConnection conn,
2245 * SilcAttribute attribute,
2246 * SilcAttributePayload attr);
2250 * Delete a Requested Attribute from the client. If the `attribute'
2251 * is non-zero then all attributes of that type are deleted and the
2252 * `attr' is ignored. If `attr' is non-NULL then that specific
2253 * attribute is deleted and `attribute' is ignored.
2255 * You may get all added attributes with the function
2256 * silc_client_attributes_get and to get the SilcAttributePayload.
2257 * This function Returns TRUE if the attribute was found and deleted.
2260 bool silc_client_attribute_del(SilcClient client,
2261 SilcClientConnection conn,
2262 SilcAttribute attribute,
2263 SilcAttributePayload attr);
2265 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2269 * const SilcHashTable
2270 * silc_client_attributes_get(SilcClient client,
2271 * SilcClientConnection conn);
2275 * Returns pointer to the SilcHashTable which includes all the added
2276 * Requested Attributes. The caller must not free the hash table.
2277 * The caller may use SilcHashTableList and silc_hash_table_list to
2278 * traverse the table. Each entry in the hash table is one added
2279 * SilcAttributePayload. It is possible to delete a attribute
2280 * payload while traversing the table.
2283 const SilcHashTable silc_client_attributes_get(SilcClient client,
2284 SilcClientConnection conn);
2286 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2290 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2294 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2295 * then all attributes are requested. Alternatively, `attribute' and
2296 * all variable arguments can each be requested attribute. In this case
2297 * the last must be set to zero (0) to complete the variable list of
2298 * requested attributes. See SilcAttribute for all attributes.
2299 * You can give the returned buffer as argument to for example
2300 * silc_client_get_client_by_id_resolve function.
2303 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2306 #include "command.h"
2307 #include "command_reply.h"
2309 #include "protocol.h"
2315 #endif /* SILCCLIENT_H */