1 /* 2 3 silcclient.h 4 5 Author: Pekka Riikonen <priikone@silcnet.org> 6 7 Copyright (C) 2000 - 2014 Pekka Riikonen 8 9 The contents of this file are subject to one of the Licenses specified 10 in the COPYING file; You may not use this file except in compliance 11 with the License. 12 13 The software distributed under the License is distributed on an "AS IS" 14 basis, in the hope that it will be useful, but WITHOUT WARRANTY OF ANY 15 KIND, either expressed or implied. See the COPYING file for more 16 information. 17 18 */ 19 20 /****h* silcclient/Client Library Interface 21 * 22 * DESCRIPTION 23 * 24 * This interface defines the SILC Client Library API for the application. 25 * The Client Library is a full featured SILC client without user interface. 26 * A simple interface called SILC Client Operations (SilcClientOperations) 27 * is provided for applications to implmeent the necessary functions to use 28 * the client library. The silcclient.h header file includes client library 29 * API, such as command handling and message sending. The silcclient_entry.h 30 * header file includes entry handling, such as channel and user entry 31 * handling. 32 * 33 * Practically all functions in the Client Library API accepts SilcClient 34 * and SilcClientConnection as their first two argument. The first argument 35 * is the actual SilcClient context and the second is the SilcClientConnection 36 * context of the connection in question. Application may create and handle 37 * multiple connections in one SilcClient. Connections can be created to 38 * servers and other clients. 39 * 40 * The Client Library support multiple threads and is threads safe if used 41 * correctly. Messages can be sent from multiple threads without any 42 * locking. Messages however are always received only in one thread unless 43 * message waiting (see silc_client_private_message_wait as an example) is 44 * used. The threads can be turned on and off by giving a parameter to the 45 * SilcClient. When turned on, each new connection to remote host is always 46 * executed in an own thread. All tasks related to that connection are then 47 * executed in that thread. This means that client operation callbacks for 48 * that connections may be called from threads and application will need to 49 * employ concurrency control if the callbacks need to access shared data 50 * in the application. Messages are also received in that thread. 51 * 52 ***/ 53 54 #ifndef SILCCLIENT_H 55 #define SILCCLIENT_H 56 57 #ifdef __cplusplus 58 extern "C" { 59 #endif 60 61 #include "client.h" 62 #include "silcclient_entry.h" 63 64 /* General definitions */ 65 66 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus 67 * 68 * NAME 69 * 70 * typedef enum { ... } SilcClientConnectionStatus 71 * 72 * DESCRIPTION 73 * 74 * This type is returned to the `connect' client operation to indicate 75 * the status of the created connection. It can indicate if it was 76 * successful or whether an error occurred. 77 * 78 * SOURCE 79 */ 80 typedef enum { 81 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */ 82 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and 83 resumed old detached session */ 84 SILC_CLIENT_CONN_DISCONNECTED, /* Remote host disconnected */ 85 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */ 86 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */ 87 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */ 88 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */ 89 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */ 90 } SilcClientConnectionStatus; 91 /***/ 92 93 /****f* silcclient/SilcClientAPI/SilcClientRunning 94 * 95 * SYNOPSIS 96 * 97 * typedef void (*SilcClientRunning)(SilcClient client, void *context); 98 * 99 * DESCRIPTION 100 * 101 * The callback given as argument to silc_client_init function. Once 102 * this is called the client library is running and application may 103 * start using the Client library API. 104 * 105 ***/ 106 typedef void (*SilcClientRunning)(SilcClient client, void *context); 107 108 /****f* silcclient/SilcClientAPI/SilcClientStopped 109 * 110 * SYNOPSIS 111 * 112 * typedef void (*SilcClientStopped)(SilcClient client, void *context); 113 * 114 * DESCRIPTION 115 * 116 * The callback given as argument to silc_client_stop. Once this is 117 * called the client library has stopped and can be freed by calling 118 * silc_client_free. Note that this won't be called if there are 119 * active connections in the client. Connections must first be closed 120 * by calling silc_client_close_connection or by sending QUIT command to 121 * the server connection. 122 * 123 ***/ 124 typedef void (*SilcClientStopped)(SilcClient client, void *context); 125 126 /****f* silcclient/SilcClientAPI/SilcClientConnectCallback 127 * 128 * SYNOPSIS 129 * 130 * void (*SilcClientConnectCallback)(SilcClient client, 131 * SilcClientConnection conn, 132 * SilcClientConnectionStatus status, 133 * SilcStatus error, 134 * const char *message, 135 * void *context); 136 * 137 * DESCRIPTION 138 * 139 * Connect callbak given as argument to silc_client_connect_to_server, 140 * silc_client_connect_to_client and silc_client_key_exchange functions. 141 * It is called to indicate the status of the connection, indicated 142 * by the `status'. It is called after the connection has been 143 * established to the remote host and when connection is disconnected 144 * by the remote host. The `context' is the context given as argument 145 * to the connecting function. If the `status' is an error the `error' 146 * may indicate more detailed error. If `error' is SILC_STATUS_OK no 147 * detailed error message is available. 148 * 149 * When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will 150 * indicate the reason for disconnection. If the `message' is non-NULL 151 * it delivers error or disconnection message. 152 * 153 * The `conn' is the connection to the remote host. In case error 154 * occurred the `conn' may be NULL, however, in some cases a valid `conn' 155 * is returned even in error. If `conn' is non-NULL the receiver is 156 * responsible of closing the connection with silc_client_close_connection 157 * function, except when SILC_CLINET_CONN_DISCONNECTED or some error 158 * was received. In these cases the library will close the connection. 159 * 160 ***/ 161 typedef void (*SilcClientConnectCallback)(SilcClient client, 162 SilcClientConnection conn, 163 SilcClientConnectionStatus status, 164 SilcStatus error, 165 const char *message, 166 void *context); 167 168 /****s* silcclient/SilcClientAPI/SilcClient 169 * 170 * NAME 171 * 172 * typedef struct SilcClientStruct { ... } *SilcClient 173 * 174 * DESCRIPTION 175 * 176 * This is the actual SILC Client structure which represents one 177 * SILC Client. It is allocated with the silc_client_alloc function 178 * and given as argument to all SILC Client Library functions. It 179 * is initialized with silc_client_init function, and freed with 180 * silc_client_free function. 181 * 182 * This context represents the client. Each connection to remote server 183 * is represented by SilcClientConnection context. 184 * 185 * SOURCE 186 */ 187 struct SilcClientStruct { 188 char *username; /* Username */ 189 char *hostname; /* hostname */ 190 char *realname; /* Real name */ 191 SilcSchedule schedule; /* Client scheduler */ 192 SilcRng rng; /* Random number generator */ 193 void *application; /* Application specific context, set with 194 silc_client_alloc. */ 195 196 /* Internal data for client library. Application cannot access this. */ 197 SilcClientInternal internal; 198 }; 199 /***/ 200 201 /****s* silcclient/SilcClientAPI/SilcClientConnection 202 * 203 * NAME 204 * 205 * typedef struct SilcClientConnectionStruct { ... } 206 * *SilcClientConnection 207 * 208 * DESCRIPTION 209 * 210 * This structure represents a connection. It is allocated and freed by 211 * the library. It is returned to application in SilcClientConnectCallback. 212 * It includes all the important data for the session such as local 213 * client entry (which includes current nickname), local and remote IDs, 214 * and other information. All strings in the structure are UTF-8 encoded. 215 * 216 * SOURCE 217 */ 218 struct SilcClientConnectionStruct { 219 SilcClientEntry local_entry; /* Our own Client Entry */ 220 SilcClientID *local_id; /* Our current Client ID */ 221 222 char *remote_host; /* Remote host name */ 223 int remote_port; /* Remote port */ 224 SilcID remote_id; /* Remote ID */ 225 226 SilcChannelEntry current_channel; /* Current joined channel */ 227 SilcPublicKey public_key; /* Public key used in this connection */ 228 SilcPrivateKey private_key; /* Private key */ 229 SilcPacketStream stream; /* Connection to remote host */ 230 SilcConnectionType type; /* Connection type */ 231 SilcClientConnectCallback callback; /* Connection callback */ 232 void *callback_context; /* Connection context */ 233 SilcClient client; /* Pointer back to SilcClient */ 234 235 /* Current say() or verify_public_key() operation associated context, 236 identifies the client, channel or server the operation is related to. 237 Application can use this information to target the operation better. */ 238 union { 239 SilcClientEntry client_entry; 240 SilcChannelEntry channel_entry; 241 SilcServerEntry server_entry; 242 }; 243 SilcIdType context_type; /* Defines which pointer is set 244 in the union. If SILC_ID_NONE 245 pointer is NULL. */ 246 247 /* Application specific data. Application may set here whatever it wants. */ 248 void *context; 249 250 /* Internal data for client library. Application cannot access this. */ 251 SilcClientConnectionInternal internal; 252 }; 253 /***/ 254 255 /****s* silcclient/SilcClientAPI/SilcChannelUser 256 * 257 * NAME 258 * 259 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser 260 * 261 * DESCRIPTION 262 * 263 * This structure represents a client that has joined to a channel. 264 * It shows the client and the channel and the client's mode (channel 265 * user mode) on the channel. 266 * 267 * SOURCE 268 */ 269 struct SilcChannelUserStruct { 270 SilcClientEntry client; /* Client joined on channel */ 271 SilcUInt32 mode; /* mode, ChannelUserModes */ 272 SilcChannelEntry channel; /* The channel user has joined */ 273 274 /* Application specific data. Application may set here whatever it wants. */ 275 void *context; 276 }; 277 /***/ 278 279 /****s* silcclient/SilcClientAPI/SilcClientStats 280 * 281 * NAME 282 * 283 * typedef struct { ... } SilcClientStats; 284 * 285 * DESCRIPTION 286 * 287 * This structure holds SILC network statistics returned by the 288 * SILC_COMMAND_STATS command reply to the application. 289 * 290 * SOURCE 291 */ 292 typedef struct SilcClientStatsStruct { 293 SilcUInt32 starttime; /* SILC server start time */ 294 SilcUInt32 uptime; /* SILC server uptime*/ 295 SilcUInt32 my_clients; /* Number of clients in the server */ 296 SilcUInt32 my_channels; /* Number of channel in the server */ 297 SilcUInt32 my_server_ops; /* Number of server operators in the server */ 298 SilcUInt32 my_router_ops; /* Number of router operators in the router */ 299 SilcUInt32 cell_clients; /* Number of clients in the cell */ 300 SilcUInt32 cell_channels; /* Number of channels in the cell */ 301 SilcUInt32 cell_servers; /* Number of server in the cell */ 302 SilcUInt32 clients; /* All clients in SILC network */ 303 SilcUInt32 channels; /* All channels in SILC network */ 304 SilcUInt32 servers; /* All servers in SILC network */ 305 SilcUInt32 routers; /* All routers in SILC network */ 306 SilcUInt32 server_ops; /* All server operators in SILC network */ 307 SilcUInt32 router_ops; /* All router operators in SILC network */ 308 } SilcClientStats; 309 /***/ 310 311 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus 312 * 313 * NAME 314 * 315 * typedef enum { ... } SilcKeyAgreementStatus; 316 * 317 * DESCRIPTION 318 * 319 * Key agreement status types indicating the status of the key 320 * agreement protocol. These types are returned to the application 321 * in the SilcKeyAgreementCallback callback function. 322 * 323 * SOURCE 324 */ 325 typedef enum { 326 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */ 327 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */ 328 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */ 329 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */ 330 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */ 331 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */ 332 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */ 333 SILC_KEY_AGREEMENT_NO_MEMORY, /* System out of memory */ 334 } SilcKeyAgreementStatus; 335 /***/ 336 337 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback 338 * 339 * SYNOPSIS 340 * 341 * typedef void (*SilcKeyAgreementCallback)(SilcClient client, 342 * SilcClientConnection conn, 343 * SilcClientEntry client_entry, 344 * SilcKeyAgreementStatus status, 345 * SilcSKEKeyMaterial *key, 346 * void *context); 347 * 348 * DESCRIPTION 349 * 350 * Key agreement callback that is called after the key agreement protocol 351 * has been performed. This is called also if error occurred during the 352 * key agreement protocol. The `key' is the allocated key material and 353 * the caller is responsible of freeing it. The `key' is NULL if error 354 * has occurred. The application can freely use the `key' to whatever 355 * purpose it needs. See lib/silcske/silcske.h for the definition of 356 * the SilcSKEKeyMaterial structure. 357 * 358 ***/ 359 typedef void (*SilcKeyAgreementCallback)(SilcClient client, 360 SilcClientConnection conn, 361 SilcClientEntry client_entry, 362 SilcKeyAgreementStatus status, 363 SilcSKEKeyMaterial key, 364 void *context); 365 366 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys 367 * 368 * NAME 369 * 370 * typedef struct { ... } SilcPrivateMessageKeys; 371 * 372 * DESCRIPTION 373 * 374 * Structure to hold the list of private message keys. The list of these 375 * structures is returned by the silc_client_list_private_message_keys 376 * function. 377 * 378 * SOURCE 379 */ 380 typedef struct SilcPrivateMessageKeysStruct { 381 SilcClientEntry client_entry; /* The remote client entry */ 382 char *cipher; /* The cipher name */ 383 unsigned char *key; /* The original key, If the appliation 384 provided it. This is NULL if 385 the SKE key material was used. */ 386 SilcUInt32 key_len; /* The key length */ 387 } *SilcPrivateMessageKeys; 388 /***/ 389 390 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey 391 * 392 * NAME 393 * 394 * typedef struct SilcChannelPrivateKeyStruct { ... } 395 * *SilcChannelPrivateKey; 396 * 397 * DESCRIPTION 398 * 399 * Structure to hold one channel private key. The array of this structure 400 * is returned by silc_client_list_channel_private_keys function. 401 * 402 * SOURCE 403 */ 404 struct SilcChannelPrivateKeyStruct { 405 char *name; /* Application given name */ 406 SilcCipher send_key; /* The cipher and key */ 407 SilcCipher receive_key; /* The cipher and key */ 408 SilcHmac hmac; /* The HMAC and hmac key */ 409 }; 410 /***/ 411 412 /****f* silcclient/SilcClientAPI/SilcAskPassphrase 413 * 414 * SYNOPSIS 415 * 416 * typedef void (*SilcAskPassphrase)(const unsigned char *passphrase, 417 * SilcUInt32 passphrase_len, 418 * void *context); 419 * 420 * DESCRIPTION 421 * 422 * Ask passphrase callback. This is called by the application when the 423 * library calls `ask_passphrase' client operation. The callback delivers 424 * the passphrase to the library. The passphrases in SILC protocol 425 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8 426 * encoded, and if it is not then library will attempt to encode it. 427 * 428 ***/ 429 typedef void (*SilcAskPassphrase)(const unsigned char *passphrase, 430 SilcUInt32 passphrase_len, 431 void *context); 432 433 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey 434 * 435 * SYNOPSIS 436 * 437 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context); 438 * 439 * DESCRIPTION 440 * 441 * Public key (or certificate) verification callback. This is called 442 * by the application to indicate that the public key verification was 443 * either success or failure. 444 * 445 ***/ 446 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context); 447 448 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth 449 * 450 * SYNOPSIS 451 * 452 * typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth, 453 * const void *auth, SilcUInt32 auth_len, 454 * void *context); 455 * 456 * DESCRIPTION 457 * 458 * Authentication data resolving callback. This is called by the 459 * application to return the resolved authentication data. The client 460 * library has called the get_auth_method client operation and given 461 * this function pointer as argument. The `auth_meth' is the selected 462 * authentication method. The `auth_data' and the `auth_data_len' 463 * are the resolved authentication data. The `context' is the libary's 464 * context sent to the get_auth_method client operation. 465 * 466 * If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len' 467 * is the passphrase and its length. If it is SILC_AUTH_PUBLIC_KEY the 468 * `auth' must be NULL. The library will use the private key given as 469 * argument to silc_client_connect_to_server, silc_client_connect_to_client 470 * or silc_client_key_exchange. If it is SILC_AUTH_NONE, both `auth' and 471 * `auth_len' are ignored. 472 * 473 ***/ 474 typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth, 475 const void *auth, SilcUInt32 auth_len, 476 void *context); 477 478 /****d* silcclient/SilcClientAPI/SilcClientMessageType 479 * 480 * NAME 481 * 482 * typedef enum { ... } SilcClientMessageType; 483 * 484 * DESCRIPTION 485 * 486 * Different message types for `say' client operation. The application 487 * may filter the message sent by the library according this type. 488 * 489 * SOURCE 490 */ 491 typedef enum { 492 SILC_CLIENT_MESSAGE_INFO, /* Informational */ 493 SILC_CLIENT_MESSAGE_WARNING, /* Warning */ 494 SILC_CLIENT_MESSAGE_ERROR, /* Error */ 495 SILC_CLIENT_MESSAGE_COMMAND_ERROR, /* Error during command */ 496 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */ 497 } SilcClientMessageType; 498 /***/ 499 500 /****s* silcclient/SilcClientAPI/SilcClientOperations 501 * 502 * NAME 503 * 504 * typedef struct { ... } SilcClientOperations; 505 * 506 * DESCRIPTION 507 * 508 * SILC Client Operations. These must be implemented by the application. 509 * The Client library may call any of these routines at any time. The 510 * routines are used to deliver certain information to the application 511 * or from the application to the client library. 512 * 513 * SOURCE 514 */ 515 typedef struct SilcClientOperationsStruct { 516 /* Message sent to the application by library. `conn' associates the 517 message to a specific connection. `conn', however, may be NULL. 518 The `type' indicates the type of the message sent by the library. 519 The application can for example filter the message according the 520 type. The variable argument list is arguments to the formatted 521 message `msg'. A SilcClientEntry, SilcChannelEntry or SilcServerEntry 522 can be associated with the message inside the SilcClientConnection 523 by the library, and application may use it to better target the 524 message. */ 525 void (*say)(SilcClient client, SilcClientConnection conn, 526 SilcClientMessageType type, char *msg, ...); 527 528 /* Message for a channel. The `sender' is the sender of the message 529 The `channel' is the channel. The `message' is the message. Note 530 that `message' maybe NULL. The `flags' indicates message flags 531 and it is used to determine how the message can be interpreted 532 (like it may tell the message is multimedia message). The `payload' 533 may be used to retrieve all the details of the message. */ 534 void (*channel_message)(SilcClient client, SilcClientConnection conn, 535 SilcClientEntry sender, SilcChannelEntry channel, 536 SilcMessagePayload payload, 537 SilcChannelPrivateKey key, SilcMessageFlags flags, 538 const unsigned char *message, 539 SilcUInt32 message_len); 540 541 /* Private message to the client. The `sender' is the sender of the 542 message. The message is `message'and maybe NULL. The `flags' 543 indicates message flags and it is used to determine how the message 544 can be interpreted (like it may tell the message is multimedia 545 message). The `payload' may be used to retrieve all the details of 546 the message. */ 547 void (*private_message)(SilcClient client, SilcClientConnection conn, 548 SilcClientEntry sender, SilcMessagePayload payload, 549 SilcMessageFlags flags, const unsigned char *message, 550 SilcUInt32 message_len); 551 552 /* Notify message to the client. The arguments are notify `type' specific. 553 See separate documentation in the Toolkit Reference Manual for the notify 554 arguments. */ 555 void (*notify)(SilcClient client, SilcClientConnection conn, 556 SilcNotifyType type, ...); 557 558 /* Command handler. This function is called always after application has 559 called a command. It will be called to indicate that the command 560 was processed. It will also be called if error occurs while processing 561 the command. The `success' indicates whether the command was sent 562 or if error occurred. The `status' indicates the actual error. 563 The `argc' and `argv' are the command line arguments sent to the 564 command by application. Note that, this is not reply to the command 565 from server, this is merely and indication to application that the 566 command was processed. */ 567 void (*command)(SilcClient client, SilcClientConnection conn, 568 SilcBool success, SilcCommand command, SilcStatus status, 569 SilcUInt32 argc, unsigned char **argv); 570 571 /* Command reply handler. Delivers a reply to command that was sent 572 earlier. The `conn' is the associated client connection. The `command' 573 indicates the command reply type. If the `status' other than 574 SILC_STATUS_OK an error occurred. In this case the `error' will indicate 575 the error. It is possible to receive list of command replies and list 576 of errors. In this case the `status' will indicate it is an list entry 577 (the `status' is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM and/or 578 SILC_STATUS_LIST_END). 579 580 The arguments received in `ap' are command specific. See a separate 581 documentation in the Toolkit Reference Manual for the command reply 582 arguments. */ 583 void (*command_reply)(SilcClient client, SilcClientConnection conn, 584 SilcCommand command, SilcStatus status, 585 SilcStatus error, va_list ap); 586 587 /* Find authentication method and authentication data by hostname and 588 port. The hostname may be IP address as well. The `auth_method' is 589 the authentication method the remote connection requires. It is 590 however possible that remote accepts also some other authentication 591 method. Application should use the method that may have been 592 configured for this connection. If none has been configured it should 593 use the required `auth_method'. If the `auth_method' is 594 SILC_AUTH_NONE, server does not require any authentication or the 595 required authentication method is not known. The `completion' 596 callback must be called to deliver the chosen authentication method 597 and data. The `conn' may be NULL. */ 598 void (*get_auth_method)(SilcClient client, SilcClientConnection conn, 599 char *hostname, SilcUInt16 port, 600 SilcAuthMethod auth_method, 601 SilcGetAuthMeth completion, void *context); 602 603 /* Called to verify received public key. The `conn_type' indicates which 604 entity (server or client) has sent the public key. If user decides to 605 trust the key the application may save the key as trusted public key for 606 later use. The `completion' must be called after the public key has 607 been verified. A SilcClientEntry or SilcServerEntry can be associated 608 with this request inside the SilcClientConnection by the library, and 609 application may use it to better target the verification request. */ 610 void (*verify_public_key)(SilcClient client, SilcClientConnection conn, 611 SilcConnectionType conn_type, 612 SilcPublicKey public_key, 613 SilcVerifyPublicKey completion, void *context); 614 615 /* Ask from end user a passphrase or a password. The passphrase is 616 returned to the library by calling the `completion' callback with 617 the `context'. The returned passphrase SHOULD be in UTF-8 encoded, 618 if not then the library will attempt to encode. */ 619 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn, 620 SilcAskPassphrase completion, void *context); 621 622 /* Called to indicate that incoming key agreement request has been 623 received. If the application wants to perform key agreement it may 624 call silc_client_perform_key_agreement to initiate key agreement or 625 silc_client_send_key_agreement to provide connection point to the 626 remote client in case the `hostname' is NULL. If key agreement is 627 not desired this request can be ignored. The `protocol' is either 628 value 0 for TCP or value 1 for UDP. */ 629 void (*key_agreement)(SilcClient client, SilcClientConnection conn, 630 SilcClientEntry client_entry, 631 const char *hostname, SilcUInt16 protocol, 632 SilcUInt16 port); 633 634 /* Notifies application that file transfer protocol session is being 635 requested by the remote client indicated by the `client_entry' from 636 the `hostname' and `port'. The `session_id' is the file transfer 637 session and it can be used to either accept or reject the file 638 transfer request, by calling the silc_client_file_receive or 639 silc_client_file_close, respectively. */ 640 void (*ftp)(SilcClient client, SilcClientConnection conn, 641 SilcClientEntry client_entry, SilcUInt32 session_id, 642 const char *hostname, SilcUInt16 port); 643 } SilcClientOperations; 644 /***/ 645 646 /****s* silcclient/SilcClientAPI/SilcClientParams 647 * 648 * NAME 649 * 650 * typedef struct { ... } SilcClientParams; 651 * 652 * DESCRIPTION 653 * 654 * Client parameters. This can be filled with proper values and 655 * given as argument to the silc_client_alloc function. The structure 656 * hold various parameters which affects the function of the client. 657 * 658 * SOURCE 659 */ 660 typedef struct SilcClientParamsStruct { 661 /* If this boolean is set to TRUE then the client library will use 662 threads. Any of the callback functions in the SilcClientOperations 663 and other callbacks may be called at any time in a thread. The 664 application may need to employ appropriate concurrency control 665 in the callbacks to protect application specific data. */ 666 SilcBool threads; 667 668 /* Nickname format string. This can be used to order the client library 669 to save the nicknames in the library in a certain format. Since 670 nicknames are not unique in SILC it is possible to have multiple same 671 nicknames. Using this format string it is possible to order the library 672 to separate the multiple same nicknames from each other. If this is 673 empty then default format is used which is the default nickname 674 without anything else. The string MUST be NULL terminated. 675 676 Following format types are available: 677 678 %n nickname - the real nickname returned by the server (mandatory) 679 %a number - ascending number in case there are several 680 same nicknames (fe. nick#2 and nick#3) 681 %h hostname - the stripped hostname of the client 682 %H full hostname - the full hostname of the client 683 684 Example format strings: "%n#%a" (fe. nick#2, nick#3) 685 "%n#%h%a" (fe. nick#host, nick#host2) 686 "%a!%n#%h" (fe. nick#host, 2!nick#host) 687 688 Note that there must always be some separator characters around '%n' 689 format. It is not possible to put format characters before or after 690 '%n' without separators (such ash '#'). Also note that the separator 691 character should be a character that cannot be part of normal nickname. 692 Note that, using '@' as a separator is not recommended as the nickname 693 string may contain it to separate a server name from the nickname (eg. 694 nickname@silcnet.org). 695 */ 696 char nickname_format[32]; 697 698 /* If this is set to TRUE then the `nickname_format' is employed to all 699 saved nicknames even if there are no multiple same nicknames in the 700 cache. By default this is FALSE, which means that the `nickname_format' 701 is employed only if the library will receive a nickname that is 702 already saved in the cache. It is recommended to leave this to FALSE 703 value. */ 704 SilcBool nickname_force_format; 705 706 /* If this is set to TRUE then all nickname strings returned by the library 707 and stored by the library are in the format of 'nickname@server', eg. 708 nickname@silcnet.org. If this is FALSE then the server name of the 709 nickname is available only from the SilcClientEntry structure. When this 710 is TRUE the server name is still parsed to SilcClientEntry. */ 711 SilcBool full_nicknames; 712 713 /* If this is set to TRUE then all channel name strings returned by the 714 library and stored by the library are in the format of 'channel@server', 715 eg. silc@silcnet.org. If this is FALSE then the server name of the 716 channel is available only from the SilcChannelEntry structure. When this 717 is TRUE the server name is still parsed to SilcChannelEntry. Note that, 718 not all SILC server versions return such channel name strings. */ 719 SilcBool full_channel_names; 720 721 /* If this is set to TRUE, the silcclient library will not register and 722 deregister the cipher, pkcs, hash and hmac algorithms. The application 723 itself will need to handle that. */ 724 SilcBool dont_register_crypto_library; 725 726 /* If this is set to TRUE, the silcclient library will not automatically 727 negotiate private message keys using SKE over the SILC network but will 728 use normal session keys to protect private messages. */ 729 SilcBool dont_autoneg_prvmsg_keys; 730 } SilcClientParams; 731 /***/ 732 733 734 /* Initialization functions (client.c) */ 735 736 /****f* silcclient/SilcClientAPI/silc_client_alloc 737 * 738 * SYNOPSIS 739 * 740 * SilcClient silc_client_alloc(SilcClientOperations *ops, 741 * SilcClientParams *params, 742 * void *application, 743 * const char *silc_version); 744 * 745 * DESCRIPTION 746 * 747 * Allocates new client object. This has to be done before client may 748 * work. After calling this one must call silc_client_init to initialize 749 * the client. The `application' is application specific user data pointer 750 * and caller must free it. The `silc_version' is the application version 751 * that will be used to compare against remote host's (usually a server) 752 * version string. The `application' context is accessible by the 753 * application by client->application, client being SilcClient. 754 * 755 ***/ 756 SilcClient silc_client_alloc(SilcClientOperations *ops, 757 SilcClientParams *params, 758 void *application, 759 const char *version_string); 760 761 /****f* silcclient/SilcClientAPI/silc_client_free 762 * 763 * SYNOPSIS 764 * 765 * void silc_client_free(SilcClient client); 766 * 767 * DESCRIPTION 768 * 769 * Frees client object and its internals. The execution of the client 770 * should be stopped with silc_client_stop function before calling 771 * this function. 772 * 773 ***/ 774 void silc_client_free(SilcClient client); 775 776 /****f* silcclient/SilcClientAPI/silc_client_init 777 * 778 * SYNOPSIS 779 * 780 * SilcBool silc_client_init(SilcClient client, const char *username, 781 * const char *hostname, const char *realname, 782 * SilcClientRunning running, void *context); 783 * 784 * DESCRIPTION 785 * 786 * Initializes the client. This makes all the necessary steps to make 787 * the client ready to be run. One must call silc_client_run to run the 788 * client. Returns FALSE if error occurred, TRUE otherwise. 789 * 790 * The `username' and `hostname' strings must be given and they must be 791 * UTF-8 encoded. The `username' is the client's username in the 792 * operating system, `hostname' is the client's host name and the 793 * `realname' is the user's real name. 794 * 795 * The `running' callback with `context' is called after the client is 796 * running after silc_client_run or silc_client_run_one has been called. 797 * Application may start using the Client library API after that. Setting 798 * the callback is optional, but highly recommended. 799 * 800 ***/ 801 SilcBool silc_client_init(SilcClient client, const char *username, 802 const char *hostname, const char *realname, 803 SilcClientRunning running, void *context); 804 805 /****f* silcclient/SilcClientAPI/silc_client_run 806 * 807 * SYNOPSIS 808 * 809 * void silc_client_run(SilcClient client); 810 * 811 * DESCRIPTION 812 * 813 * Runs the client. This starts the scheduler from the utility library. 814 * When this functions returns the execution of the application is over. 815 * The client must be initialized before calling this. 816 * 817 ***/ 818 void silc_client_run(SilcClient client); 819 820 /****f* silcclient/SilcClientAPI/silc_client_run_one 821 * 822 * SYNOPSIS 823 * 824 * void silc_client_run_one(SilcClient client); 825 * 826 * DESCRIPTION 827 * 828 * Runs the client and returns immeadiately. This function is used when 829 * the SILC Client object indicated by the `client' is run under some 830 * other scheduler, or event loop or main loop. On GUI applications, 831 * for example this may be desired to used to run the client under the 832 * GUI application's main loop. Typically the GUI application would 833 * register an idle task that calls this function multiple times in 834 * a second to quickly process the SILC specific data. 835 * 836 ***/ 837 void silc_client_run_one(SilcClient client); 838 839 /****f* silcclient/SilcClientAPI/silc_client_stop 840 * 841 * SYNOPSIS 842 * 843 * void silc_client_stop(SilcClient client, SilcClientStopped stopped, 844 * void *context); 845 * 846 * DESCRIPTION 847 * 848 * Stops the client. This is called to stop the client and thus to stop 849 * the program. The client context must be freed with the silc_client_free 850 * function. All connections that exist in this client must be closed 851 * before calling this function. Connections can be closed by calling 852 * silc_client_close_connection. 853 * 854 * The `stopped' will be called once the client and all connections have 855 * finished. The client may be freed after that. Note that the `stopped' 856 * won't be called before all connections have finished. Setting the 857 * callback is optional. 858 * 859 ***/ 860 void silc_client_stop(SilcClient client, SilcClientStopped stopped, 861 void *context); 862 863 /* Connecting functions */ 864 865 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams 866 * 867 * NAME 868 * 869 * typedef struct { ... } SilcClientConnectionParams; 870 * 871 * DESCRIPTION 872 * 873 * Client connection parameters. This can be filled by the application 874 * and given as argument to silc_client_connect_to_server, 875 * silc_client_connect_to_client, silc_client_key_exchange or 876 * silc_client_send_key_agreement. 877 * 878 * SOURCE 879 */ 880 typedef struct SilcClientConnectionParamsStruct { 881 /* If this is provided the user's nickname in the network will be the 882 string given here. If it is given, it must be UTF-8 encoded. If this 883 string is not given, the user's username by default is used as nickname. 884 The nickname may later be changed by using NICK command. The maximum 885 length for the nickname string is 128 bytes. */ 886 char *nickname; 887 888 /* If this key repository pointer is non-NULL then public key received in 889 the key exchange protocol will be verified from this repository. If 890 this is not provided then the `verify_public_key' client operation will 891 be called back to application. If the boolean `verify_notfound' is set 892 to TRUE then the `verify_public_key' client operation will be called 893 in case the public key is not found in `repository'. Only public keys 894 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will 895 be checked, other keys will be ignored. */ 896 SilcSKR repository; 897 SilcBool verify_notfound; 898 899 /* Authentication data. Application may set here the authentication data 900 and authentication method to be used in connecting. If `auth_set' 901 boolean is TRUE then authentication data is provided by application. 902 If the authentication method is public key authentication then the key 903 pair given as argument when connecting will be used and `auth' field 904 is NULL. If it is passphrase authentication, it can be provided in 905 `auth' and `auth_len' fields. If `auth_set' is FALSE 906 the `get_auth_method' client operation will be called to get the 907 authentication method and data from application. */ 908 SilcBool auth_set; 909 SilcAuthMethod auth_method; 910 void *auth; 911 SilcUInt32 auth_len; 912 913 /* If this boolean is set to TRUE then the connection will use UDP instead 914 of TCP. If UDP is set then also the next `local_ip' and `local_port' 915 must be set. */ 916 SilcBool udp; 917 918 /* The `local_ip' specifies the local IP address used with the connection. 919 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is 920 non-zero it will be used as local port with UDP connection. The remote 921 host will also send packets to the specified address and port. If the 922 `bind_ip' is non-NULL a listener is bound to that address instead of 923 `local_ip'. */ 924 char *local_ip; 925 char *bind_ip; 926 int local_port; 927 928 /* If this boolean is set to TRUE then the key exchange is done with 929 perfect forward secrecy. */ 930 SilcBool pfs; 931 932 /* If this boolean is set to TRUE then connection authentication protocol 933 is not performed during connecting. Only key exchange protocol is 934 performed. This usually must be set to TRUE when connecting to another 935 client, but must be FALSE with server connections. */ 936 SilcBool no_authentication; 937 938 /* The SILC session detachment data that was returned in the `command_reply' 939 client operation for SILC_COMMAND_DETACH command. If this is provided 940 here the client library will attempt to resume the session in the network. 941 After the connection is created and the session has been resumed the 942 client will receive SILC_COMMAND_NICK command_reply for the client's 943 nickname in the network and SILC_COMMAND_JOIN command reply for all the 944 channels that the client has joined in the network. It may also receive 945 SILC_COMMAND_UMODE command reply to set user's mode on the network. */ 946 unsigned char *detach_data; 947 SilcUInt32 detach_data_len; 948 949 /* Connection timeout. If non-zero, the connection will timeout unless 950 the SILC connection is completed in the specified amount of time. */ 951 SilcUInt32 timeout_secs; 952 953 /* Rekey timeout in seconds. The client will perform rekey in this 954 time interval. If set to zero, the default value will be used 955 (3600 seconds, 1 hour). */ 956 SilcUInt32 rekey_secs; 957 958 /* If this is set to TRUE then the client will ignore all incoming 959 Requested Attributes queries and does not reply anything back. This 960 usually leads into situation where server does not anymore send 961 the queries after seeing that client does not reply anything back. 962 If your application does not support Requested Attributes or you do 963 not want to use them set this to TRUE. See SilcAttribute and 964 silc_client_attribute_add for more information on attributes. */ 965 SilcBool ignore_requested_attributes; 966 967 /* User context for SilcClientConnection. If non-NULL this context is 968 set to the 'context' field in SilcClientConnection when the connection 969 context is created. */ 970 void *context; 971 } SilcClientConnectionParams; 972 /***/ 973 974 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server 975 * 976 * SYNOPSIS 977 * 978 * SilcAsyncOperation 979 * silc_client_connect_to_server(SilcClient client, 980 * SilcClientConnectionParams *params, 981 * SilcPublicKey public_key, 982 * SilcPrivateKey private_key, 983 * char *remote_host, int port, 984 * SilcClientConnectCallback callback, 985 * void *context); 986 * 987 * DESCRIPTION 988 * 989 * Connects to remote server `remote_host' at port `port'. This function 990 * can be used to create connection to remote SILC server and start 991 * SILC session in the SILC network. The `params' may be provided 992 * to provide various connection parameters. The `public_key' and the 993 * `private_key' is your identity used in this connection. When 994 * authentication method is based on digital signatures, this key pair 995 * will be used. The `callback' with `context' will be called after the 996 * connection has been created. It will also be called later when remote 997 * host disconnects. 998 * 999 * If application wishes to create the network connection itself, use 1000 * the silc_client_key_exchange after creating the connection to start 1001 * key exchange and authentication with the server. 1002 * 1003 * Returns SilcAsyncOperation which can be used to cancel the connecting, 1004 * or NULL on error. Note that the returned pointer becomes invalid 1005 * after the `callback' is called. 1006 * 1007 ***/ 1008 SilcAsyncOperation 1009 silc_client_connect_to_server(SilcClient client, 1010 SilcClientConnectionParams *params, 1011 SilcPublicKey public_key, 1012 SilcPrivateKey private_key, 1013 char *remote_host, int port, 1014 SilcClientConnectCallback callback, 1015 void *context); 1016 1017 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client 1018 * 1019 * SYNOPSIS 1020 * 1021 * SilcAsyncOperation 1022 * silc_client_connect_to_client(SilcClient client, 1023 * SilcClientConnectionParams *params, 1024 * SilcPublicKey public_key, 1025 * SilcPrivateKey private_key, 1026 * char *remote_host, int port, 1027 * SilcClientConnectCallback callback, 1028 * void *context); 1029 * 1030 * DESCRIPTION 1031 * 1032 * Connects to remote client `remote_host' at port `port'. This function 1033 * can be used to create peer-to-peer connection to another SILC client, 1034 * for example, for direct conferencing, or file transfer or for other 1035 * purposes. The `params' may be provided to provide various connection 1036 * parameters. The `public_key' and the `private_key' is your identity 1037 * used in this connection. The `callback' with `context' will be called 1038 * after the connection has been created. It will also be called later 1039 * when remote host disconnects. 1040 * 1041 * If application wishes to create the network connection itself, use 1042 * the silc_client_key_exchange after creating the connection to start 1043 * key exchange with the client. 1044 * 1045 * Returns SilcAsyncOperation which can be used to cancel the connecting, 1046 * or NULL on error. Note that the returned pointer becomes invalid 1047 * after the `callback' is called. 1048 * 1049 ***/ 1050 SilcAsyncOperation 1051 silc_client_connect_to_client(SilcClient client, 1052 SilcClientConnectionParams *params, 1053 SilcPublicKey public_key, 1054 SilcPrivateKey private_key, 1055 char *remote_host, int port, 1056 SilcClientConnectCallback callback, 1057 void *context); 1058 1059 /****f* silcclient/SilcClientAPI/silc_client_key_exchange 1060 * 1061 * SYNOPSIS 1062 * 1063 * SilcAsyncOperation 1064 * silc_client_key_exchange(SilcClient client, 1065 * SilcClientConnectionParams *params, 1066 * SilcPublicKey public_key, 1067 * SilcPrivateKey private_key, 1068 * SilcStream stream, 1069 * SilcConnectionType conn_type, 1070 * SilcClientConnectCallback callback, 1071 * void *context); 1072 * 1073 * DESCRIPTION 1074 * 1075 * Starts key exchange protocol and authentication protocol in the 1076 * connection indicated by `stream'. This function can be be used to 1077 * start SILC session with remote host (usually server) when the caller 1078 * has itself created the connection, instead of calling the function 1079 * silc_client_connect_to_server or silc_client_connect_to_client. If 1080 * one of those functions was used this function must not be called as 1081 * in that case the key exchange is performed automatically. 1082 * 1083 * Use this function only if you have created the connection by yourself. 1084 * After creating the connection the socket must be wrapped into a 1085 * socket stream. See silcsocketstream.h for more information. Note that 1086 * the `stream' must have valid remote IP address (and optionally also 1087 * hostname) and port set. 1088 * 1089 * The `params' may be provided to provide various connection parameters. 1090 * The `public_key' and the `private_key' is your identity used in this 1091 * session. The `callback' with `context' will be called after the session 1092 * has been set up. It will also be called later when remote host 1093 * disconnects. The `conn_type' is the type of session this is going to 1094 * be. If the remote is SILC server it is SILC_CONN_SERVER or if it is 1095 * SILC client it is SILC_CONN_CLIENT. 1096 * 1097 * Returns SilcAsyncOperation which can be used to cancel the connecting, 1098 * or NULL on error. Note that the returned pointer becomes invalid 1099 * after the `callback' is called. 1100 * 1101 * EXAMPLE 1102 * 1103 * int sock; 1104 * 1105 * // Create remote connection stream. Resolve hostname and IP also. 1106 * sock = create_connection(remote_host, port); 1107 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule, 1108 * stream_create_cb, app); 1109 * 1110 * // Stream callback delivers our new SilcStream context 1111 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream, 1112 * void *context) 1113 * { 1114 * ... 1115 * if (status != SILC_SOCKET_OK) 1116 * error(status); 1117 * 1118 * // Start key exchange 1119 * silc_client_key_exchange(client, NULL, public_key, private_key, 1120 * stream, SILC_CONN_SERVER, connection_cb, app); 1121 * ... 1122 * } 1123 * 1124 ***/ 1125 SilcAsyncOperation 1126 silc_client_key_exchange(SilcClient client, 1127 SilcClientConnectionParams *params, 1128 SilcPublicKey public_key, 1129 SilcPrivateKey private_key, 1130 SilcStream stream, 1131 SilcConnectionType conn_type, 1132 SilcClientConnectCallback callback, 1133 void *context); 1134 1135 /****f* silcclient/SilcClientAPI/silc_client_close_connection 1136 * 1137 * SYNOPSIS 1138 * 1139 * void silc_client_close_connection(SilcClient client, 1140 * SilcClientConnection conn); 1141 * 1142 * DESCRIPTION 1143 * 1144 * Closes the remote connection `conn'. The `conn' will become invalid 1145 * after this call. Usually this function is called only when explicitly 1146 * closing connection for example in case of error, or when the remote 1147 * connection was created by the application or when the remote is client 1148 * connection. Server connections are usually closed by sending QUIT 1149 * command to the server. However, this call may also be used. 1150 * 1151 ***/ 1152 void silc_client_close_connection(SilcClient client, 1153 SilcClientConnection conn); 1154 1155 /* Message sending functions */ 1156 1157 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message 1158 * 1159 * SYNOPSIS 1160 * 1161 * SilcBool silc_client_send_channel_message(SilcClient client, 1162 * SilcClientConnection conn, 1163 * SilcChannelEntry channel, 1164 * SilcChannelPrivateKey key, 1165 * SilcMessageFlags flags, 1166 * SilcHash hash, 1167 * unsigned char *data, 1168 * SilcUInt32 data_len); 1169 * 1170 * DESCRIPTION 1171 * 1172 * Sends encrypted message to the `channel'. The plaintext message is 1173 * the `data' of `data_len' bytes in length. 1174 * 1175 * If `key' is provided then that private channel message key is used to 1176 * encrypt the message. If it is not provided and the `channel' does not 1177 * have SILC_CHANNEL_MODE_PRIVKEY set, the curent channel key is used 1178 * instead. If the mode is set but `key' is NULL the key that was added 1179 * first as private channel message key will be used. 1180 * 1181 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be 1182 * digitally signed with the SILC key pair associated with the `conn'. 1183 * In this case the `hash' pointer must be provided as well. 1184 * 1185 * Returns TRUE if the message was sent, and FALSE if error occurred or 1186 * the sending is not allowed due to channel modes (like sending is 1187 * blocked). This function is thread safe and channel messages can be 1188 * sent from multiple threads. 1189 * 1190 ***/ 1191 SilcBool silc_client_send_channel_message(SilcClient client, 1192 SilcClientConnection conn, 1193 SilcChannelEntry channel, 1194 SilcChannelPrivateKey key, 1195 SilcMessageFlags flags, 1196 SilcHash hash, 1197 unsigned char *data, 1198 SilcUInt32 data_len); 1199 1200 /****f* silcclient/SilcClientAPI/silc_client_send_private_message 1201 * 1202 * SYNOPSIS 1203 * 1204 * SilcBool silc_client_send_private_message(SilcClient client, 1205 * SilcClientConnection conn, 1206 * SilcClientEntry client_entry, 1207 * SilcMessageFlags flags, 1208 * SilcHash hash, 1209 * unsigned char *data, 1210 * SilcUInt32 data_len); 1211 * 1212 * DESCRIPTION 1213 * 1214 * Sends private message to remote client. If private message key has 1215 * not been set with this client then the message will be encrypted using 1216 * the session keys used in `conn' connection. If the `flags' includes 1217 * SILC_MESSAGE_FLAG_SIGNED the message will be digitally signed with the 1218 * SILC key pair associated with `conn'. In this case the caller must also 1219 * provide the `hash' pointer. 1220 * 1221 * Returns TRUE if the message was sent, and FALSE if error occurred. 1222 * This function is thread safe and private messages can be sent from 1223 * multiple threads. 1224 * 1225 ***/ 1226 SilcBool silc_client_send_private_message(SilcClient client, 1227 SilcClientConnection conn, 1228 SilcClientEntry client_entry, 1229 SilcMessageFlags flags, 1230 SilcHash hash, 1231 unsigned char *data, 1232 SilcUInt32 data_len); 1233 1234 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_init 1235 * 1236 * SYNOPSIS 1237 * 1238 * SilcBool 1239 * silc_client_private_message_wait_init(SilcClient client, 1240 * SilcClientConnection conn, 1241 * SilcClientEntry client_entry); 1242 * 1243 * DESCRIPTION 1244 * 1245 * Initializes private message waiting functionality for the client 1246 * indicated by `client_entry'. Once this is called private message 1247 * from remote connection indicated by `conn' for `client_entry' may 1248 * be waiter for, for example in a thread. The function 1249 * silc_client_private_message_wait is used to block the current thread 1250 * until a private message is received from a specified client entry. 1251 * Return FALSE in case an internal error occurred. 1252 * 1253 ***/ 1254 SilcBool silc_client_private_message_wait_init(SilcClient client, 1255 SilcClientConnection conn, 1256 SilcClientEntry client_entry); 1257 1258 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_uninit 1259 * 1260 * SYNOPSIS 1261 * 1262 * void 1263 * silc_client_private_message_wait_uninit(SilcClient client, 1264 * SilcClientConnection conn, 1265 * SilcClientEntry client_entry); 1266 * 1267 * DESCRIPTION 1268 * 1269 * Unintializes private message waiting for client indicated by 1270 * `client_entry'. After this call private message cannot be waited 1271 * anymore and silc_client_private_message_wait will return with FALSE 1272 * value. 1273 * 1274 ***/ 1275 void silc_client_private_message_wait_uninit(SilcClient client, 1276 SilcClientConnection conn, 1277 SilcClientEntry client_entry); 1278 1279 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait 1280 * 1281 * SYNOPSIS 1282 * 1283 * SilcBool 1284 * silc_client_private_message_wait(SilcClient client, 1285 * SilcClientConnection conn, 1286 * SilcClientEntry client_entry, 1287 * SilcMessagePayload *payload); 1288 * 1289 * DESCRIPTION 1290 * 1291 * Blocks current thread or process until a private message has been 1292 * received from the remote client indicated by `client_entry'. Before 1293 * private messages can be waited the silc_client_private_message_wait_init 1294 * must be called. This function can be used from a thread to wait for 1295 * private message from the specified client. Multiple threads can be 1296 * created to wait messages from multiple clients. Any other private 1297 * message received from the connection indicated by `conn' will be 1298 * forwarded to the normal `private_message' client operation callback. 1299 * The private messages from `client_entry' will not be delivered to the 1300 * `private_message' client operation callback. 1301 * 1302 * Returns TRUE and the received private message into `payload'. The caller 1303 * must free the returned SilcMessagePayload. If this function returns 1304 * FALSE the private messages cannot be waited anymore. This happens 1305 * when some other thread calls silc_client_private_message_wait_uninit. 1306 * This returns FALSE also if silc_client_private_message_wait_init has 1307 * not been called. 1308 * 1309 ***/ 1310 SilcBool silc_client_private_message_wait(SilcClient client, 1311 SilcClientConnection conn, 1312 SilcClientEntry client_entry, 1313 SilcMessagePayload *payload); 1314 1315 /****f* silcclient/SilcClientAPI/silc_client_on_channel 1316 * 1317 * SYNOPSIS 1318 * 1319 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel, 1320 * SilcClientEntry client_entry); 1321 * 1322 * DESCRIPTION 1323 * 1324 * Returns the SilcChannelUser entry if the `client_entry' is joined on the 1325 * channel indicated by the `channel'. NULL if client is not joined on 1326 * the channel. 1327 * 1328 ***/ 1329 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel, 1330 SilcClientEntry client_entry); 1331 1332 1333 /* Command management */ 1334 1335 /****f* silcclient/SilcClientAPI/silc_client_command_call 1336 * 1337 * SYNOPSIS 1338 * 1339 * SilcUInt16 silc_client_command_call(SilcClient client, 1340 * SilcClientConnection conn, 1341 * const char *command_line, ...); 1342 * 1343 * DESCRIPTION 1344 * 1345 * Calls and executes the command indicated by the `command_name'. 1346 * The `command_line' is a string which includes the command's name and 1347 * its arguments separated with whitespaces (' '). If `command_line' 1348 * is non-NULL then all variable arguments are ignored by default. 1349 * 1350 * If `command_line' is NULL, then the variable arguments define the 1351 * command's name and its arguments. The first variable argument must 1352 * be the command name. The variable argument list must be terminated 1353 * with NULL. 1354 * 1355 * Returns command identifier for this sent command. It can be used 1356 * to additionally attach to the command reply using the function 1357 * silc_client_command_pending, if needed. Returns 0 on error. 1358 * 1359 * The `command' client operation callback will be called when the 1360 * command is executed to indicate whether or not the command executed 1361 * successfully. 1362 * 1363 * The `command_reply' client operation callbak will be called when reply 1364 * is received from the server to the command. Application may also use 1365 * the silc_client_command_pending to attach to the command reply. 1366 * The command identifier for silc_client_command_pending function after 1367 * this function call is conn->cmd_ident, which application may use. 1368 * 1369 * EXAMPLE 1370 * 1371 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org", 1372 * NULL); 1373 * silc_client_command_call(client, conn, "PING silc.silcnet.org"); 1374 * 1375 * NOTES 1376 * 1377 * This command executes the commands implemented inside the client 1378 * library. These commands are designed for command line applications, 1379 * but GUI application may call them too if needed. Alternatively 1380 * application may override the library and use silc_client_command_send 1381 * function instead. 1382 * 1383 ***/ 1384 SilcUInt16 silc_client_command_call(SilcClient client, 1385 SilcClientConnection conn, 1386 const char *command_line, ...); 1387 1388 /****f* silcclient/SilcClientAPI/SilcClientCommandReply 1389 * 1390 * SYNOPSIS 1391 * 1392 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client, 1393 * SilcClientConnection conn, 1394 * SilcCommand command, 1395 * SilcStatus status, 1396 * SilcStatus error, 1397 * void *context, 1398 * va_list ap); 1399 * 1400 * DESCRIPTION 1401 * 1402 * The command reply callback function given as argument to functions 1403 * silc_client_command_send and silc_client_command_pending. This is 1404 * called to deliver the command replies to the caller. Each command 1405 * reply received from the server to the `command' will be delivered 1406 * separately to the caller by calling this callback. The `status' will 1407 * indicate whether there is only one reply or multiple replies. The 1408 * `error' will indicate if an error occurred. The `ap' will include 1409 * command reply arguments. They are the same arguments as for 1410 * `command_reply' client operation callback in SilcClientOperations. 1411 * 1412 * If `status' is SILC_STATUS_OK only one reply was received and error 1413 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM 1414 * or SILC_STATUS_LIST_END, there are will be two or more replies. The 1415 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END. 1416 * 1417 * If FALSE is returned in this function this callback will not be called 1418 * again for `command' even if there are more comand replies. By returning 1419 * FALSE the caller my stop the command reply handling when needed. 1420 * 1421 ***/ 1422 typedef SilcBool (*SilcClientCommandReply)(SilcClient client, 1423 SilcClientConnection conn, 1424 SilcCommand command, 1425 SilcStatus status, 1426 SilcStatus error, 1427 void *context, 1428 va_list ap); 1429 1430 /****f* silcclient/SilcClientAPI/silc_client_command_send 1431 * 1432 * SYNOPSIS 1433 * 1434 * SilcUInt16 silc_client_command_send(SilcClient client, 1435 * SilcClientConnection conn, 1436 * SilcCommand command, 1437 * SilcClientCommandReply reply, 1438 * void *reply_context, 1439 * SilcUInt32 argc, ...); 1440 * 1441 * DESCRIPTION 1442 * 1443 * Generic function to send any command. The arguments must be given 1444 * already encoded into correct format and in correct order. If application 1445 * wants to perform the commands by itself, it can do so and send the data 1446 * directly to the server using this function. If application is using 1447 * the silc_client_command_call, this function is usually not used. 1448 * Programmer should get familiar with the SILC protocol commands 1449 * specification when using this function, as the arguments needs to 1450 * be encoded as specified in the protocol. 1451 * 1452 * The variable arguments are a set of { type, data, data_length }, 1453 * and the `argc' is the number of these sets. 1454 * 1455 * The `reply' callback must be provided, and it is called when the 1456 * command reply is received from the server. Note that, when using this 1457 * function the default `command_reply' client operation callback will not 1458 * be called when reply is received. 1459 * 1460 * Returns command identifier for this sent command. It can be used 1461 * to additionally attach to the command reply using the function 1462 * silc_client_command_pending, if needed. Returns 0 on error. 1463 * 1464 * EXAMPLE 1465 * 1466 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 1467 * my_whois_command_reply, cmd_ctx, 1468 * 1, 1, nickname, strlen(nickname)); 1469 * 1470 ***/ 1471 SilcUInt16 silc_client_command_send(SilcClient client, 1472 SilcClientConnection conn, 1473 SilcCommand command, 1474 SilcClientCommandReply reply, 1475 void *reply_context, 1476 SilcUInt32 argc, ...); 1477 1478 /****f* silcclient/SilcClientAPI/silc_client_command_pending 1479 * 1480 * SYNOPSIS 1481 * 1482 * void silc_client_command_pending(SilcClientConnection conn, 1483 * SilcCommand command, 1484 * SilcUInt16 cmd_ident, 1485 * SilcClientCommandReply reply, 1486 * void *context); 1487 * 1488 * DESCRIPTION 1489 * 1490 * This function can be used to add pending command callback to be 1491 * called when an command reply is received to an earlier sent command. 1492 * The `command' is the command that must be received in order for 1493 * the pending command callback indicated by `callback' to be called. 1494 * 1495 * The `cmd_ident' is a command identifier which was set for the earlier 1496 * sent command. The command reply will include the same identifier 1497 * and pending command callback will be called when the reply is 1498 * received with the same command identifier. It is possible to 1499 * add multiple pending command callbacks for same command and for 1500 * same identifier. 1501 * 1502 * Application may use this function to add its own command reply 1503 * handlers if it wishes not to use the standard `command_reply' 1504 * client operation. 1505 * 1506 * Note also that the application is notified about the received command 1507 * reply through the `command_reply' client operation before calling 1508 * the `callback` pending command callback. That is the normal 1509 * command reply handling, and is called regardless whether pending 1510 * command callbacks are used or not. 1511 * 1512 * EXAMPLE 1513 * 1514 * SilcUInt16 cmd_ident; 1515 * cmd_ident = silc_client_command_call(client, conn, 1516 * "PING silc.silcnet.org"); 1517 * silc_client_command_pending(conn, SILC_COMMAND_PING, cmd_ident, 1518 * my_ping_handler, my_ping_context); 1519 * 1520 ***/ 1521 SilcBool silc_client_command_pending(SilcClientConnection conn, 1522 SilcCommand command, 1523 SilcUInt16 cmd_ident, 1524 SilcClientCommandReply reply, 1525 void *context); 1526 1527 1528 /* Private Message key management */ 1529 1530 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key 1531 * 1532 * SYNOPSIS 1533 * 1534 * SilcBool 1535 * silc_client_add_private_message_key(SilcClient client, 1536 * SilcClientConnection conn, 1537 * SilcClientEntry client_entry, 1538 * const char *cipher, 1539 * const char *hmac, 1540 * unsigned char *key, 1541 * SilcUInt32 key_len); 1542 * 1543 * DESCRIPTION 1544 * 1545 * Adds a static private message key to the client library. The key 1546 * will be used to encrypt all private message between the client and 1547 * the remote client indicated by the `client_entry'. The `key' can 1548 * be for example a pre-shared-key, passphrase or similar shared secret 1549 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL 1550 * to assure that the requirements of the SILC protocol are met. The 1551 * API, however, allows to allocate any cipher and HMAC. 1552 * 1553 * If the private message key is added to client without first receiving 1554 * a request for it from the remote `client_entry' this function will 1555 * send the request to `client_entry'. Note that, the actual key is 1556 * not sent to the network. 1557 * 1558 * It is not necessary to set key for normal private message usage. If the 1559 * key is not set then the private messages are encrypted using normal 1560 * session keys. Setting the private key, however, increases security. 1561 * 1562 * Returns FALSE if the key is already set for the `client_entry', TRUE 1563 * otherwise. 1564 * 1565 ***/ 1566 SilcBool silc_client_add_private_message_key(SilcClient client, 1567 SilcClientConnection conn, 1568 SilcClientEntry client_entry, 1569 const char *cipher, 1570 const char *hmac, 1571 unsigned char *key, 1572 SilcUInt32 key_len); 1573 1574 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske 1575 * 1576 * SYNOPSIS 1577 * 1578 * SilcBool 1579 * silc_client_add_private_message_key_ske(SilcClient client, 1580 * SilcClientConnection conn, 1581 * SilcClientEntry client_entry, 1582 * const char *cipher, 1583 * const char *hmac, 1584 * SilcSKEKeyMaterial key); 1585 * 1586 * DESCRIPTION 1587 * 1588 * Same as silc_client_add_private_message_key but takes the key material 1589 * from the SKE key material structure. This structure is received if 1590 * the application uses the silc_client_send_key_agreement to negotiate 1591 * the key material. The `cipher' and `hmac' SHOULD be provided as it is 1592 * negotiated also in the SKE protocol. 1593 * 1594 ***/ 1595 SilcBool silc_client_add_private_message_key_ske(SilcClient client, 1596 SilcClientConnection conn, 1597 SilcClientEntry client_entry, 1598 const char *cipher, 1599 const char *hmac, 1600 SilcSKEKeyMaterial key); 1601 1602 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key 1603 * 1604 * SYNOPSIS 1605 * 1606 * SilcBool 1607 * silc_client_del_private_message_key(SilcClient client, 1608 * SilcClientConnection conn, 1609 * SilcClientEntry client_entry); 1610 * 1611 * DESCRIPTION 1612 * 1613 * Removes the private message from the library. The key won't be used 1614 * after this to protect the private messages with the remote `client_entry' 1615 * client. Returns FALSE on error, TRUE otherwise. 1616 * 1617 ***/ 1618 SilcBool silc_client_del_private_message_key(SilcClient client, 1619 SilcClientConnection conn, 1620 SilcClientEntry client_entry); 1621 1622 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys 1623 * 1624 * SYNOPSIS 1625 * 1626 * SilcPrivateMessageKeys 1627 * silc_client_list_private_message_keys(SilcClient client, 1628 * SilcClientConnection conn, 1629 * SilcUInt32 *key_count); 1630 * 1631 * DESCRIPTION 1632 * 1633 * Returns array of set private message keys associated to the connection 1634 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array 1635 * count to the `key_count' argument. The array must be freed by the caller 1636 * by calling the silc_client_free_private_message_keys function. Note: 1637 * the keys returned in the array is in raw format. It might not be desired 1638 * to show the keys as is. The application might choose not to show the keys 1639 * at all or to show the fingerprints of the keys. 1640 * 1641 ***/ 1642 SilcPrivateMessageKeys 1643 silc_client_list_private_message_keys(SilcClient client, 1644 SilcClientConnection conn, 1645 SilcUInt32 *key_count); 1646 1647 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys 1648 * 1649 * SYNOPSIS 1650 * 1651 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys, 1652 * SilcUInt32 key_count); 1653 * 1654 * DESCRIPTION 1655 * 1656 * Frees the SilcPrivateMessageKeys array returned by the function 1657 * silc_client_list_private_message_keys. 1658 * 1659 ***/ 1660 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys, 1661 SilcUInt32 key_count); 1662 1663 /****f* silcclient/SilcClientAPI/silc_client_private_message_key_is_set 1664 * 1665 * SYNOPSIS 1666 * 1667 * SilcBool 1668 * silc_client_private_message_key_is_set(SilcClient client, 1669 * SilcClientConnection conn, 1670 * SilcClientEntry client_entry); 1671 * 1672 * DESCRIPTION 1673 * 1674 * Returns TRUE if the private message key has been set for the client 1675 * entry indicated by `client_entry'. 1676 * 1677 ***/ 1678 SilcBool 1679 silc_client_private_message_key_is_set(SilcClient client, 1680 SilcClientConnection conn, 1681 SilcClientEntry client_entry); 1682 1683 1684 /* Channel private key management */ 1685 1686 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key 1687 * 1688 * SYNOPSIS 1689 * 1690 * SilcBool 1691 * silc_client_add_channel_private_key(SilcClient client, 1692 * SilcClientConnection conn, 1693 * SilcChannelEntry channel, 1694 * const char *name, 1695 * char *cipher, 1696 * char *hmac, 1697 * unsigned char *key, 1698 * SilcUInt32 key_len, 1699 * SilcChannelPrivateKey *ret_key); 1700 * 1701 * DESCRIPTION 1702 * 1703 * Adds private key for channel. When channel has private key then the 1704 * messages are encrypted using that key. All clients on the channel 1705 * must also know the key in order to decrypt the messages. However, 1706 * it is possible to have several private keys per one channel. In this 1707 * case only some of the clients on the channel may know the one key 1708 * and only some the other key. The `name' can be application given 1709 * name for the key. This returns the created key to the 'ret_key' 1710 * pointer if it is non-NULL; 1711 * 1712 * If `cipher' and/or `hmac' is NULL then default values will be used 1713 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac). 1714 * 1715 * The private key for channel is optional. If it is not set then the 1716 * channel messages are encrypted using the channel key generated by the 1717 * server. However, setting the private key (or keys) for the channel 1718 * significantly adds security. If more than one key is set the library 1719 * will automatically try all keys at the message decryption phase. Note: 1720 * setting many keys slows down the decryption phase as all keys has to 1721 * be tried in order to find the correct decryption key. However, setting 1722 * a few keys does not have big impact to the decryption performace. 1723 * 1724 * NOTES 1725 * 1726 * NOTE: This is entirely local setting. The key set using this function 1727 * is not sent to the network at any phase. 1728 * 1729 * NOTE: If the key material was originated by the SKE protocol (using 1730 * silc_client_send_key_agreement) then the `key' MUST be the 1731 * key->send_enc_key as this is dictated by the SILC protocol. However, 1732 * currently it is not expected that the SKE key material would be used 1733 * as channel private key. However, this API allows it. 1734 * 1735 ***/ 1736 SilcBool silc_client_add_channel_private_key(SilcClient client, 1737 SilcClientConnection conn, 1738 SilcChannelEntry channel, 1739 const char *name, 1740 char *cipher, 1741 char *hmac, 1742 unsigned char *key, 1743 SilcUInt32 key_len, 1744 SilcChannelPrivateKey *ret_key); 1745 1746 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys 1747 * 1748 * SYNOPSIS 1749 * 1750 * SilcBool silc_client_del_channel_private_keys(SilcClient client, 1751 * SilcClientConnection conn, 1752 * SilcChannelEntry channel); 1753 * 1754 * DESCRIPTION 1755 * 1756 * Removes all private keys from the `channel'. The old channel key is used 1757 * after calling this to protect the channel messages. Returns FALSE on 1758 * on error, TRUE otherwise. 1759 * 1760 ***/ 1761 SilcBool silc_client_del_channel_private_keys(SilcClient client, 1762 SilcClientConnection conn, 1763 SilcChannelEntry channel); 1764 1765 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key 1766 * 1767 * SYNOPSIS 1768 * 1769 * SilcBool silc_client_del_channel_private_key(SilcClient client, 1770 * SilcClientConnection conn, 1771 * SilcChannelEntry channel, 1772 * SilcChannelPrivateKey key); 1773 * 1774 * DESCRIPTION 1775 * 1776 * Removes and frees private key `key' from the channel `channel'. 1777 * The `key' is retrieved by calling the function 1778 * silc_client_list_channel_private_keys. The key is not used after 1779 * this. If the key was last private key then the old channel key is 1780 * used hereafter to protect the channel messages. This returns FALSE 1781 * on error, TRUE otherwise. 1782 * 1783 ***/ 1784 SilcBool silc_client_del_channel_private_key(SilcClient client, 1785 SilcClientConnection conn, 1786 SilcChannelEntry channel, 1787 SilcChannelPrivateKey key); 1788 1789 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys 1790 * 1791 * SYNOPSIS 1792 * 1793 * SilcDList 1794 * silc_client_list_channel_private_keys(SilcClient client, 1795 * SilcClientConnection conn, 1796 * SilcChannelEntry channel); 1797 * 1798 * DESCRIPTION 1799 * 1800 * Returns list of private keys associated to the `channel'. The caller 1801 * must free the returned list with silc_dlist_uninit. The pointers in 1802 * the list may be used to delete the specific key by giving the pointer 1803 * as argument to the function silc_client_del_channel_private_key. Each 1804 * entry in the list is SilcChannelPrivateKey. 1805 * 1806 ***/ 1807 SilcDList silc_client_list_channel_private_keys(SilcClient client, 1808 SilcClientConnection conn, 1809 SilcChannelEntry channel); 1810 1811 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key 1812 * 1813 * SYNOPSIS 1814 * 1815 * void silc_client_current_channel_private_key(SilcClient client, 1816 * SilcClientConnection conn, 1817 * SilcChannelEntry channel, 1818 * SilcChannelPrivateKey key); 1819 * 1820 * DESCRIPTION 1821 * 1822 * Sets the `key' to be used as current channel private key on the 1823 * `channel'. Packet sent after calling this function will be secured 1824 * with `key'. 1825 * 1826 ***/ 1827 void silc_client_current_channel_private_key(SilcClient client, 1828 SilcClientConnection conn, 1829 SilcChannelEntry channel, 1830 SilcChannelPrivateKey key); 1831 1832 1833 /* Key Agreement routines */ 1834 1835 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement 1836 * 1837 * SYNOPSIS 1838 * 1839 * void silc_client_send_key_agreement(SilcClient client, 1840 * SilcClientConnection conn, 1841 * SilcClientEntry client_entry, 1842 * SilcClientConnectionParams *params, 1843 * SilcPublicKey public_key, 1844 * SilcPrivateKey private_key, 1845 * SilcKeyAgreementCallback completion, 1846 * void *context); 1847 * 1848 * DESCRIPTION 1849 * 1850 * Sends key agreement request to the remote client indicated by the 1851 * `client_entry'. 1852 * 1853 * If `params' is non-NULL and it has the `local_ip' and `local_port' set 1854 * the caller will provide the connection endpoint for the key agreement 1855 * connection. The `bind_ip' can be used to bind to that IP instead of 1856 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP 1857 * instead of TCP. Caller may also set the `repository', `verify_notfound' 1858 * and `timeout_secs' fields in `params'. Other fields are ignored. 1859 * If `params' is NULL, then the `client_entry' is expected to provide 1860 * the connection endpoint for us. It is recommended the `timeout_secs' 1861 * is specified in case the remote client does not reply anything to 1862 * the request. 1863 * 1864 * The `public_key' and `private_key' is our identity in the key agreement. 1865 * 1866 * In case we do not provide the connection endpoint, we will receive 1867 * the `key_agreement' client operation when the remote send its own 1868 * key agreement request packet. We may then there start the key 1869 * agreement with silc_client_perform_key_agreement. If we provided the 1870 * the connection endpoint, the client operation will not be called. 1871 * 1872 * There can be only one active key agreement for `client_entry'. Old 1873 * key agreement may be aborted by calling silc_client_abort_key_agreement. 1874 * 1875 * EXAMPLE 1876 * 1877 * // Send key agreement request (we don't provide connection endpoint) 1878 * silc_client_send_key_agreement(client, conn, remote_client, 1879 * NULL, public_key, private_key, 1880 * my_keyagr_completion, my_context); 1881 * 1882 * // Another example where we provide connection endpoint (TCP). 1883 * SilcClientConnectionParams params; 1884 * memset(¶ms, 0, sizeof(params)); 1885 * params.local_ip = local_ip; 1886 * params.local_port = local_port; 1887 * params.timeout_secs = 60; 1888 * silc_client_send_key_agreement(client, conn, remote_client, 1889 * ¶ms, public_key, private_key, 1890 * my_keyagr_completion, my_context); 1891 * 1892 ***/ 1893 void silc_client_send_key_agreement(SilcClient client, 1894 SilcClientConnection conn, 1895 SilcClientEntry client_entry, 1896 SilcClientConnectionParams *params, 1897 SilcPublicKey public_key, 1898 SilcPrivateKey private_key, 1899 SilcKeyAgreementCallback completion, 1900 void *context); 1901 1902 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement 1903 * 1904 * SYNOPSIS 1905 * 1906 * void 1907 * silc_client_perform_key_agreement(SilcClient client, 1908 * SilcClientConnection conn, 1909 * SilcClientEntry client_entry, 1910 * SilcClientConnectionParams *params, 1911 * SilcPublicKey public_key, 1912 * SilcPrivateKey private_key, 1913 * char *hostname, int port, 1914 * SilcKeyAgreementCallback completion, 1915 * void *context); 1916 * 1917 * DESCRIPTION 1918 * 1919 * Performs the key agreement protocol. Application may use this to 1920 * initiate the key agreement protocol. Usually this is called after 1921 * receiving the `key_agreement' client operation. 1922 * 1923 * The `hostname' is the remote hostname (or IP address) and the `port' 1924 * is the remote port. The `completion' callback with the `context' will 1925 * be called after the key agreement protocol. 1926 * 1927 * The `params' is connection parameters and it may be used to define 1928 * the key agreement connection related parameters. It may be NULL. 1929 * 1930 ***/ 1931 void silc_client_perform_key_agreement(SilcClient client, 1932 SilcClientConnection conn, 1933 SilcClientEntry client_entry, 1934 SilcClientConnectionParams *params, 1935 SilcPublicKey public_key, 1936 SilcPrivateKey private_key, 1937 char *hostname, int port, 1938 SilcKeyAgreementCallback completion, 1939 void *context); 1940 1941 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream 1942 * 1943 * SYNOPSIS 1944 * 1945 * void 1946 * silc_client_perform_key_agreement_stream( 1947 * SilcClient client, 1948 * SilcClientConnection conn, 1949 * SilcClientEntry client_entry, 1950 * SilcClientConnectionParams *params, 1951 * SilcPublicKey public_key, 1952 * SilcPrivateKey private_key, 1953 * SilcStream stream, 1954 * SilcKeyAgreementCallback completion, 1955 * void *context); 1956 * 1957 * DESCRIPTION 1958 * 1959 * Same as silc_client_perform_key_agreement but the caller has created 1960 * the connection to remote client. The `stream' is the created 1961 * connection. 1962 * 1963 ***/ 1964 void 1965 silc_client_perform_key_agreement_stream(SilcClient client, 1966 SilcClientConnection conn, 1967 SilcClientEntry client_entry, 1968 SilcClientConnectionParams *params, 1969 SilcPublicKey public_key, 1970 SilcPrivateKey private_key, 1971 SilcStream stream, 1972 SilcKeyAgreementCallback completion, 1973 void *context); 1974 1975 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement 1976 * 1977 * SYNOPSIS 1978 * 1979 * void silc_client_abort_key_agreement(SilcClient client, 1980 * SilcClientConnection conn, 1981 * SilcClientEntry client_entry); 1982 * 1983 * DESCRIPTION 1984 * 1985 * This function can be called to unbind the hostname and the port for 1986 * the key agreement protocol. However, this function has effect only 1987 * before the key agreement protocol has been performed. After it has 1988 * been performed the library will automatically unbind the port. The 1989 * `client_entry' is the client to which we sent the key agreement 1990 * request. The key agreement completion callback will be called 1991 * with SILC_KEY_AGREEMENT_ABORTED status. 1992 * 1993 ***/ 1994 void silc_client_abort_key_agreement(SilcClient client, 1995 SilcClientConnection conn, 1996 SilcClientEntry client_entry); 1997 1998 1999 /* Misc functions */ 2000 2001 /****f* silcclient/SilcClientAPI/silc_client_set_away_message 2002 * 2003 * SYNOPSIS 2004 * 2005 * SilcBool silc_client_set_away_message(SilcClient client, 2006 * SilcClientConnection conn, 2007 * char *message); 2008 * 2009 * DESCRIPTION 2010 * 2011 * Sets away `message'. The away message may be set when the client's 2012 * mode is changed to SILC_UMODE_GONE and the client whishes to reply 2013 * to anyone who sends private message. The `message' will be sent 2014 * automatically back to the the client who send private message. If 2015 * away message is already set this replaces the old message with the 2016 * new one. If `message' is NULL the old away message is removed. 2017 * The sender may freely free the memory of the `message'. Returns 2018 * FALSE on error. 2019 * 2020 ***/ 2021 SilcBool silc_client_set_away_message(SilcClient client, 2022 SilcClientConnection conn, 2023 char *message); 2024 2025 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus 2026 * 2027 * NAME 2028 * 2029 * typedef enum { ... } SilcClientMonitorStatus; 2030 * 2031 * DESCRIPTION 2032 * 2033 * File transmission session status types. These will indicate 2034 * the status of the file transmission session. 2035 * 2036 * The SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT is called when session 2037 * is key exchange phase. 2038 * 2039 * The SILC_CLIENT_FILE_MONITOR_SEND is called when data is being sent 2040 * to remote client. 2041 * 2042 * The SILC_CLIENT_FILE_MONITOR_RECEIVE is called when data is being 2043 * recieved from remote client. 2044 * 2045 * The SILC_CLIENT_FILE_MONITOR_CLOSED will be called when the user 2046 * issues silc_client_file_close. If needed, it may be ignored in the 2047 * monitor callback. 2048 * 2049 * The SILC_CLIENT_FILE_MONITOR_DISCONNECT will be called if remote 2050 * disconnects the session connection. The silc_client_file_close must 2051 * be called when this status is received. The session is over when 2052 * this is received. 2053 * 2054 * The SILC_CLIENLT_FILE_MONITOR_ERROR is called in case some error 2055 * occured. The SilcClientFileError will indicate more detailed error 2056 * condition. The silc_client_file_close must be called when this status 2057 * is received. The session is over when this is received. 2058 * 2059 * SOURCE 2060 */ 2061 typedef enum { 2062 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */ 2063 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */ 2064 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */ 2065 SILC_CLIENT_FILE_MONITOR_GET, /* Unsupported */ 2066 SILC_CLIENT_FILE_MONITOR_PUT, /* Unsupported */ 2067 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */ 2068 SILC_CLIENT_FILE_MONITOR_DISCONNECT, /* Session disconnected */ 2069 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */ 2070 } SilcClientMonitorStatus; 2071 /***/ 2072 2073 /****d* silcclient/SilcClientAPI/SilcClientFileError 2074 * 2075 * NAME 2076 * 2077 * typedef enum { ... } SilcClientFileError; 2078 * 2079 * DESCRIPTION 2080 * 2081 * File transmission error types. These types are returned by 2082 * some of the file transmission functions, and by the monitor 2083 * callback to indicate error. 2084 * 2085 * SOURCE 2086 */ 2087 typedef enum { 2088 SILC_CLIENT_FILE_OK, 2089 SILC_CLIENT_FILE_ERROR, /* Generic error */ 2090 SILC_CLIENT_FILE_UNKNOWN_SESSION, /* Unknown session ID */ 2091 SILC_CLIENT_FILE_ALREADY_STARTED, /* Session already started */ 2092 SILC_CLIENT_FILE_NO_SUCH_FILE, /* No such file */ 2093 SILC_CLIENT_FILE_PERMISSION_DENIED, /* Permission denied */ 2094 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED, /* Key exchange failed */ 2095 SILC_CLIENT_FILE_CONNECT_FAILED, /* Error during connecting */ 2096 SILC_CLIENT_FILE_TIMEOUT, /* Connecting timedout */ 2097 SILC_CLIENT_FILE_NO_MEMORY, /* System out of memory */ 2098 } SilcClientFileError; 2099 /***/ 2100 2101 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor 2102 * 2103 * SYNOPSIS 2104 * 2105 * typedef void (*SilcClientFileMonitor)(SilcClient client, 2106 * SilcClientConnection conn, 2107 * SilcClientMonitorStatus status, 2108 * SilcClientFileError error, 2109 * SilcUInt64 offset, 2110 * SilcUInt64 filesize, 2111 * SilcClientEntry client_entry, 2112 * SilcUInt32 session_id, 2113 * const char *filepath, 2114 * void *context); 2115 * 2116 * DESCRIPTION 2117 * 2118 * Monitor callback that is called during the file transmission to 2119 * monitor the transmission process. The `status' indicates the current 2120 * monitoring process. The `error' will indicate the error type 2121 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the 2122 * currently transmitted amount of total `filesize'. The `client_entry' 2123 * indicates the remote client, and the transmission session ID is the 2124 * `session_id'. The filename being transmitted is indicated by the 2125 * `filepath'. The `conn' is NULL if the connection to remote client 2126 * does not exist yet. 2127 * 2128 ***/ 2129 typedef void (*SilcClientFileMonitor)(SilcClient client, 2130 SilcClientConnection conn, 2131 SilcClientMonitorStatus status, 2132 SilcClientFileError error, 2133 SilcUInt64 offset, 2134 SilcUInt64 filesize, 2135 SilcClientEntry client_entry, 2136 SilcUInt32 session_id, 2137 const char *filepath, 2138 void *context); 2139 2140 /****f* silcclient/SilcClientAPI/SilcClientFileName 2141 * 2142 * SYNOPSIS 2143 * 2144 * typedef void (*SilcClientFileName)(const char *filepath, 2145 * void *context); 2146 * 2147 * DESCRIPTION 2148 * 2149 * Completion callback for the SilcClientFileAskName callback function. 2150 * Application calls this to deliver the filepath and filename where 2151 * the downloaded file is to be saved. 2152 * 2153 ***/ 2154 typedef void (*SilcClientFileName)(const char *filepath, 2155 void *context); 2156 2157 /****f* silcclient/SilcClientAPI/SilcClientFileAskName 2158 * 2159 * SYNOPSIS 2160 * 2161 * typedef void (*SilcClientFileAskName)(SilcClient client, 2162 * SilcClientConnection conn, 2163 * SilcUInt32 session_id, 2164 * const char *remote_filename, 2165 * SilcClientFileName completion, 2166 * void *completion_context, 2167 * void *context); 2168 * 2169 * DESCRIPTION 2170 * 2171 * File name asking callback that is called if it is given to the 2172 * silc_client_file_receive and the path given to that as argument was 2173 * NULL. The library calls this to ask the filename and filepath to 2174 * where the file is to be saved. The 'remote_filename' is the file 2175 * that is being downloaded. Application must call the 'completion' 2176 * with 'completion_context' to continue with the file downloading. 2177 * It is not mandatory to provide this to the silc_client_file_receive. 2178 * 2179 ***/ 2180 typedef void (*SilcClientFileAskName)(SilcClient client, 2181 SilcClientConnection conn, 2182 SilcUInt32 session_id, 2183 const char *remote_filename, 2184 SilcClientFileName completion, 2185 void *completion_context, 2186 void *context); 2187 2188 /****f* silcclient/SilcClientAPI/silc_client_file_send 2189 * 2190 * SYNOPSIS 2191 * 2192 * SilcClientFileError 2193 * silc_client_file_send(SilcClient client, 2194 * SilcClientConnection conn, 2195 * SilcClientEntry client_entry, 2196 * SilcClientConnectionParams *params, 2197 * SilcPublicKey public_key, 2198 * SilcPrivateKey private_key, 2199 * SilcClientFileMonitor monitor, 2200 * void *monitor_context, 2201 * const char *filepath, 2202 * SilcUInt32 *session_id); 2203 * 2204 * DESCRIPTION 2205 * 2206 * Sends a file indicated by the `filepath' to the remote client 2207 * indicated by the `client_entry'. This will negotiate a secret key 2208 * with the remote client before actually starting the transmission of 2209 * the file. The `monitor' callback will be called to monitor the 2210 * transmission of the file. 2211 * 2212 * This returns a file session ID for the file transmission to the 2213 * `session_id' pointer. It can be used to close the session (and 2214 * abort the file transmission) by calling the silc_client_file_close 2215 * function. The session ID is also returned in the `monitor' callback. 2216 * 2217 * If `params' is non-NULL and it has the `local_ip' and `local_port' set 2218 * the caller will provide the connection endpoint for the key agreement 2219 * connection. The `bind_ip' can be used to bind to that IP instead of 2220 * `local_ip'. Caller may also set the `repository', `verify_notfound' 2221 * and `timeout_secs' fields in `params'. Other fields are ignored. 2222 * If `params' is NULL, then the `client_entry' is expected to provide 2223 * the connection endpoint for us. It is recommended the `timeout_secs' 2224 * is specified in case the remote client does not reply anything to 2225 * the request. 2226 * 2227 * The `public_key' and `private_key' is our identity in the key agreement. 2228 * 2229 * If error will occur during the file transfer process the error status 2230 * will be returned in the monitor callback. In this case the application 2231 * must call silc_client_file_close to close the session. 2232 * 2233 ***/ 2234 SilcClientFileError 2235 silc_client_file_send(SilcClient client, 2236 SilcClientConnection conn, 2237 SilcClientEntry client_entry, 2238 SilcClientConnectionParams *params, 2239 SilcPublicKey public_key, 2240 SilcPrivateKey private_key, 2241 SilcClientFileMonitor monitor, 2242 void *monitor_context, 2243 const char *filepath, 2244 SilcUInt32 *session_id); 2245 2246 /****f* silcclient/SilcClientAPI/silc_client_file_receive 2247 * 2248 * SYNOPSIS 2249 * 2250 * SilcClientFileError 2251 * silc_client_file_receive(SilcClient client, 2252 * SilcClientConnection conn, 2253 * SilcClientConnectionParams *params, 2254 * SilcPublicKey public_key, 2255 * SilcPrivateKey private_key, 2256 * SilcClientFileMonitor monitor, 2257 * void *monitor_context, 2258 * const char *path, 2259 * SilcUInt32 session_id, 2260 * SilcClientFileAskName ask_name, 2261 * void *ask_name_context); 2262 * 2263 * DESCRIPTION 2264 * 2265 * Receives a file from a client indicated by the `client_entry'. The 2266 * `session_id' indicates the file transmission session and it has been 2267 * received in the `ftp' client operation callback. This will actually 2268 * perform the key agreement protocol with the remote client before 2269 * actually starting the file transmission. The `monitor' callback 2270 * will be called to monitor the transmission. If `path' is non-NULL 2271 * the file will be saved into that directory. If NULL the file is 2272 * saved in the current working directory, unless the 'ask_name' 2273 * callback is non-NULL. In this case the callback is called to ask 2274 * the path and filename from application. 2275 * 2276 * The `params' is the connection related parameters. If the remote client 2277 * provided connection point the `params' will be used when creating 2278 * connection to the remote client. If remote client did not provide 2279 * connection point the `params' is used to provide connection point 2280 * locally for the remote client. See silc_client_file_send for more 2281 * information on providing connection point for remote client. 2282 * 2283 * The `public_key' and `private_key' is our identity in the key agreement. 2284 * 2285 * If error will occur during the file transfer process the error status 2286 * will be returned in the monitor callback. In this case the application 2287 * must call silc_client_file_close to close the session. 2288 * 2289 ***/ 2290 SilcClientFileError 2291 silc_client_file_receive(SilcClient client, 2292 SilcClientConnection conn, 2293 SilcClientConnectionParams *params, 2294 SilcPublicKey public_key, 2295 SilcPrivateKey private_key, 2296 SilcClientFileMonitor monitor, 2297 void *monitor_context, 2298 const char *path, 2299 SilcUInt32 session_id, 2300 SilcClientFileAskName ask_name, 2301 void *ask_name_context); 2302 2303 /****f* silcclient/SilcClientAPI/silc_client_file_close 2304 * 2305 * SYNOPSIS 2306 * 2307 * SilcClientFileError silc_client_file_close(SilcClient client, 2308 * SilcClientConnection conn, 2309 * SilcUInt32 session_id); 2310 * 2311 * DESCRIPTION 2312 * 2313 * Closes file transmission session indicated by the `session_id'. 2314 * If file transmission is being conducted it will be aborted 2315 * automatically. This function is also used to close the session 2316 * after successful file transmission. This function can be used 2317 * also to reject incoming file transmission request. If the 2318 * session was already started and the monitor callback was set 2319 * the monitor callback will be called with the monitor status 2320 * SILC_CLIENT_FILE_MONITOR_CLOSED. 2321 * 2322 ***/ 2323 SilcClientFileError silc_client_file_close(SilcClient client, 2324 SilcClientConnection conn, 2325 SilcUInt32 session_id); 2326 2327 /****f* silcclient/SilcClientAPI/silc_client_attribute_add 2328 * 2329 * SYNOPSIS 2330 * 2331 * SilcAttributePayload 2332 * silc_client_attribute_add(SilcClient client, 2333 * SilcClientConnection conn, 2334 * SilcAttribute attribute, 2335 * void *object, 2336 * SilcUInt32 object_size); 2337 * 2338 * DESCRIPTION 2339 * 2340 * Add new Requsted Attribute for WHOIS command to the client library. 2341 * The `attribute' object indicated by `object' is added and allocated 2342 * SilcAttributePayload is returned. The `object' must be of correct 2343 * type and of correct size. See the SilcAttribute for object types 2344 * for different attributes. You may also get all added attributes 2345 * from the client with silc_client_attributes_get function. 2346 * 2347 * Requested Attributes are different personal information about the 2348 * user, status information and other information which other users 2349 * may query with WHOIS command. Application may set these so that 2350 * if someone sends WHOIS query these attributes will be replied back 2351 * to the sender. The library always puts the public key to the 2352 * Requested Attributes, but if application wishes to add additional 2353 * public keys (or certificates) it can be done with this interface. 2354 * Library also always computes digital signature of the attributes 2355 * automatically, so application does not need to do that. 2356 * 2357 ***/ 2358 SilcAttributePayload silc_client_attribute_add(SilcClient client, 2359 SilcClientConnection conn, 2360 SilcAttribute attribute, 2361 void *object, 2362 SilcUInt32 object_size); 2363 2364 /****f* silcclient/SilcClientAPI/silc_client_attribute_del 2365 * 2366 * SYNOPSIS 2367 * 2368 * SilcBool silc_client_attribute_del(SilcClient client, 2369 * SilcClientConnection conn, 2370 * SilcAttribute attribute, 2371 * SilcAttributePayload attr); 2372 * 2373 * DESCRIPTION 2374 * 2375 * Delete a Requested Attribute from the client. If the `attribute' 2376 * is non-zero then all attributes of that type are deleted and the 2377 * `attr' is ignored. If `attr' is non-NULL then that specific 2378 * attribute is deleted and `attribute' is ignored. 2379 * 2380 * You may get all added attributes with the function 2381 * silc_client_attributes_get and to get the SilcAttributePayload. 2382 * This function Returns TRUE if the attribute was found and deleted. 2383 * 2384 ***/ 2385 SilcBool silc_client_attribute_del(SilcClient client, 2386 SilcClientConnection conn, 2387 SilcAttribute attribute, 2388 SilcAttributePayload attr); 2389 2390 /****f* silcclient/SilcClientAPI/silc_client_attributes_get 2391 * 2392 * SYNOPSIS 2393 * 2394 * const SilcHashTable 2395 * silc_client_attributes_get(SilcClient client, 2396 * SilcClientConnection conn); 2397 * 2398 * DESCRIPTION 2399 * 2400 * Returns pointer to the SilcHashTable which includes all the added 2401 * Requested Attributes. The caller must not free the hash table. 2402 * The caller may use SilcHashTableList and silc_hash_table_list to 2403 * traverse the table. Each entry in the hash table is one added 2404 * SilcAttributePayload. It is possible to delete a attribute 2405 * payload while traversing the table. 2406 * 2407 ***/ 2408 SilcHashTable silc_client_attributes_get(SilcClient client, 2409 SilcClientConnection conn); 2410 2411 /****f* silcclient/SilcClientAPI/silc_client_attributes_request 2412 * 2413 * SYNOPSIS 2414 * 2415 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...); 2416 * 2417 * DESCRIPTION 2418 * 2419 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0) 2420 * then all attributes are requested. Alternatively, `attribute' and 2421 * all variable arguments can each be requested attribute. In this case 2422 * the last must be set to zero (0) to complete the variable list of 2423 * requested attributes. See SilcAttribute for all attributes. 2424 * You can give the returned buffer as argument to for example 2425 * silc_client_get_client_by_id_resolve function. 2426 * 2427 * EXAMPLE 2428 * 2429 * Request all attributes 2430 * buffer = silc_client_attributes_request(0); 2431 * 2432 * Request only the following attributes 2433 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO, 2434 * SILC_ATTRIBUTE_SERVICE, 2435 * SILC_ATTRIBUTE_MOOD, 0); 2436 * 2437 ***/ 2438 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...); 2439 2440 /****f* silcclient/SilcClientAPI/silc_client_nickname_format 2441 * 2442 * SYNOPSIS 2443 * 2444 * SilcClientEntry 2445 * silc_client_nickname_format(SilcClient client, 2446 * SilcClientConnection conn, 2447 * SilcClientEntry client_entry, 2448 * SilcBool priority); 2449 * 2450 * DESCRIPTION 2451 * 2452 * Formats the nickname of `client_entry' according to the nickname 2453 * formatting rules set in SilcClientParams. If the `priority' is TRUE 2454 * then the `client_entry' will always get the unformatted nickname. 2455 * If FALSE and there are more than one same nicknames in the client 2456 * the nickname will be formatted. 2457 * 2458 * This returns NULL on error. Otherwise, the client entry that was 2459 * formatted is returned. If `priority' is FALSE this always returns 2460 * the `client_entry'. If it is TRUE, this may return the client entry 2461 * that was formatted after giving the `client_entry' the unformatted 2462 * nickname. 2463 * 2464 * Usually application does not need to call this function, as the library 2465 * automatically formats nicknames. However, if application wants to 2466 * for example force the `client_entry' to always have the unformatted 2467 * nickname it may call this function to do so. 2468 * 2469 ***/ 2470 SilcClientEntry silc_client_nickname_format(SilcClient client, 2471 SilcClientConnection conn, 2472 SilcClientEntry client_entry, 2473 SilcBool priority); 2474 2475 /****f* silcclient/SilcClientAPI/silc_client_nickname_parse 2476 * 2477 * SYNOPSIS 2478 * 2479 * SilcBool silc_client_nickname_parse(SilcClient client, 2480 * SilcClientConnection conn, 2481 * char *nickname, 2482 * char **ret_nick); 2483 * 2484 * DESCRIPTION 2485 * 2486 * Parses the `nickname' according to the format string given in the 2487 * SilcClientParams. Returns the parsed nickname into the `ret_nick'. 2488 * The caller must free the returned pointer. Returns FALSE if error 2489 * occurred during parsing. Returns TRUE if the nickname was parsed, 2490 * it was not formatted or if the format string has not been specified 2491 * in SilcClientParams. 2492 * 2493 ***/ 2494 SilcBool silc_client_nickname_parse(SilcClient client, 2495 SilcClientConnection conn, 2496 char *nickname, 2497 char **ret_nick); 2498 2499 #ifdef __cplusplus 2500 } 2501 #endif 2502 2503 #endif /* SILCCLIENT_H */ 2504