1 <big><b>Using SILC Client Library</b></big>
3 <br /> <br /> <br />
7 SILC Client library is a full featured SILC Client protocol implementation.
8 The library has been designed to be complete SILC client without actual
9 user interface. The library provides the API for the appliation which
10 it can use to implement generally whatever user interface it wants. The
11 SILC Client Library recides in the lib/silcclient/ directory. It uses
12 common and core compomnent of SILC protocol from the lib/silccore, SKE
13 from lib/silcske and general utility routines from lib/silcutil.
16 The `silcclient.h' file defines the function prototypes that application
17 must implement in order to be able to create the user interface with the
18 library. The idea is that the application can implement whatever user
19 interface routines in the functions and display the data whatever way
20 it wants. The library is entirely transparent to the user interface and
21 it does not include any user interface specific issues such as window
22 handling or item handling on the screen etc. These does not interest
23 the library. The `silcclient.h' also defines the client libary interface
24 the application can call. The interface includes for example functions
25 for sending channel and private messages, client and channel retrieval
26 and other utility functions.
28 <br /> <br /> <br />
29 <b>Including Library Headers</b>
32 Your application must include the following includes in your sources to
33 get access all SILC Client Library routines:
37 #include "silcincludes.h"<br />
38 #include "silcclient.h"
42 <br /> <br /> <br />
43 <b>Creating Client</b>
46 The client is context or entity based, so several client entitites can
47 be created in the application if needed. However, it should be noted
48 that they are completely independent from each other and can be seen
49 as different applications. Usually only one client entity is needed
53 The client object is SilcClient which is usually allocated in following
57 <tt> SilcClient client = silc_client_alloc(&ops, params, context, silc_version_string);</tt>
60 `ops' is the static structure of client operations that library will call.
61 `context' can be some application specific context that will be saved into
62 the SilcClient object. It is up to the caller to free this context.
63 SilcClient is always passed to the application thus the application
64 specific context can be retrieved from the SilcClient object. See
65 `client.h' file for detailed definition of SilcClient object.
68 The `silc_version_string' is the current protocol version string, and you
69 can get it by including `silcversion.h' header in your source code.
72 `ops' can be defined for example as follows:
76 SilcClientOperations ops = {<br />
77 silc_say,<br />
78 silc_channel_message,<br />
79 silc_private_message,<br />
80 silc_notify,<br />
81 silc_command,<br />
82 silc_command_reply,<br />
83 silc_connect,<br />
84 silc_disconnect,<br />
85 silc_get_auth_method,<br />
86 silc_verify_public_key,<br />
87 silc_ask_passphrase,<br />
88 silc_failure,<br />
89 silc_key_agreement,<br />
94 Please see the `client_ops_example.c' source file in lib/silcclient/
95 directory for predefined structure and stub functions for your
96 convenience. It is provided for programmers so that they can copy
97 it and use it directly in their application.
100 <br /> <br /> <br />
101 <b>Initializing the Client</b>
104 The client must be initialized before running. However, there are also
105 some other tasks that must be done before initializing the client.
106 The following pointers must be set by the application before calling
107 the initializing function:
111 client->username<br />
112 client->hostname<br />
113 client->realname<br />
114 client->pkcs<br />
115 client->public_key<br />
116 client->private_key
120 You may also set client->nickname if you want. If it is set then the
121 library will change the nickname to that one after the client is connected
122 to the server. If not set, then server will initially give the nickname
123 which is same as the username.
126 After setting the pointers one must call:
129 <tt> silc_client_init(client);</tt>
132 which then initializes the client library for the `client'. If the
133 pointers mentioned above are not initialized the silc_client_init will
134 fail. The application should check the return value of the silc_client_init
138 <br /> <br /> <br />
139 <b>Running the Client</b>
142 The client is run by calling silc_client_run. The function will call
143 the scheduler from utility library that will be run until the program is
144 ended. When silc_client_run returns the application is ended. Thus,
145 to run the client, call:
148 <tt> silc_client_run(client);</tt>
151 Usually application may do some other initializations before calling
152 this function. For example before calling this function application
153 should initialize the user interface.
156 <br /> <br /> <br />
157 <b>Running the Client in GUI application</b>
160 Many GUI applications has their own main loop or event loop, which they
161 would like to use or are forced to use by the underlaying system. If you
162 are developing for example GUI application on Unix system, and you are
163 using GTK+ or QT as GUI library you would probably like to use their own
164 main loop. SILC Client can be run under external main loop as well. The
165 interface provides a function silc_client_run_one which will run the
166 client library once, and returns immediately. During that running it can
167 process incoming data and send outgoing data, but it is guaranteed that it
168 will not block the calling process.
171 It is suggested that you would call this function as many times in a
172 second as possible to provide smooth action for the client library. You
173 can use an timeout task, or an idle task provided by your GUI library to
174 accomplish this. After you have initialized the client library with
175 silc_client_init, you should register the timeout task or idle task that
176 will call the silc_client_run_one periodically. In the Toolkit package
177 there is GTK-- GUI example in silcer/ directory. That example calls the
178 silc_client_run_one every 50 milliseconds, and it should be sufficient for
182 For Win32 the silc_client_run can be used instead of using the Windows's
183 own event loop. However, if you would like to use the silc_client_run_one
184 also on Win32 systems it is possible.
187 <br /> <br /> <br />
188 <b>Running Client in GTK--</b>
191 Here is a short example how to run the SILC Client libary under the
192 Gnome/GTK--'s main loop:
196 gint YourClass::silc_scheduler()<br />
198 // Run the SILC client once, and return immediately. This function<br />
199 // is called every 50 milliseconds by the Gnome main loop, to process<br />
200 // SILC stuff. This function will read data, and write data to network,<br />
201 // etc. Makes the client library tick! :)<br />
202 silc_client_run_one(silc_client);<br />
203 return 1;<br />
208 then, during initialization of the SILC Client call:
212 // Setup SILC scheduler as timeout task. This will handle the SILC<br />
213 // client library every 50 milliseconds. It will actually make the<br />
214 // SILC client work on background.<br />
215 Gnome::Main::timeout.connect(slot(this, &YourClass::silc_scheduler), 50);<br />
219 This will call the function silc_scheduler every 50 millisecconds, which
220 on the otherhand will call silc_client_run_one, which will make the SILC
221 Client library work on the background of the GUI application.
224 <br /> <br /> <br />
225 <b>Creating Connection to Server</b>
228 Connection to remote SILC server is done by calling:
231 <tt> silc_client_connect_to_server(client, port, hostname, context);</tt>
234 The function will create the connection asynchronously to the server, ie.
235 the function will return before the actual connection is created. After
236 the connection is created the client->ops->connect operation is called.
239 Generally speaking the connections are associated with windows' on the
240 screen. IRC is usually implemented this way, however it is not the
241 necessary way to associate the client's connections. SilcClientConnection
242 object is provided by the library (and is always passed to the application)
243 that can be used in the application to associate the connection from the
244 library. Application specific context can be saved to the
245 SilcClientConnection object which then can be retrieved in the application,
246 thus perhaps associate the connection with what ever object in
247 application (window or something else).
250 <br /> <br /> <br />
251 <b>Using Own Connecting</b>
254 Application might not want to use silc_client_connect_to_server function
255 if it wants to perform its own connecting for some reason. In this case
256 application must call function silc_client_start_key_exchange after it
257 has created the connection by itself. This function starts the key
258 exhange protocol between the client and server and the library takes care
259 of everything after that.
262 After connection has been created application must call:
266 SilcClientConnection conn;
269 /* Add new connection to client */<br />
270 conn = silc_client_add_connection(client, hostname, port, context);
273 /* Start key exchange and let the library handle everything<br />
274 after this point on. */<br />
275 silc_client_start_key_exchange(client, conn, sock);
279 NOTE: These calls are performed only and only if application did not call
280 silc_client_connect_to_server function, but performed the connecting
284 <br /> <br /> <br />
285 <b>Example Client</b>
288 This section includes an example SILC client implementation in pseudo-like
289 C code. It creates and initializes the client and sets up an imaginary
290 user interface. The user will use the user interface then to create
291 the connections. The SilcClientOperations are expected to be implemented.
295 #include "silcincludes.h"
296 #include "silcclient.h"
300 SilcClientOperations ops = {
302 silc_channel_message,
303 silc_private_message,
309 silc_get_auth_method,
310 silc_verify_public_key,
318 /* Allocate SILC client. The `silc_version_string' is defined
319 in includes/version.h file. */
320 client = silc_client_alloc(&ops, NULL, silc_version_string);
322 /* Register default ciphers, pkcs, hash funtions and hmacs. */
323 silc_cipher_register_default();
324 silc_pkcs_register_default();
325 silc_hash_register_default();
326 silc_hmac_register_default();
328 /* Set the mandatory pointers, read public and private key from
329 files (or somewhere) and return pointers and PKCS context. */
330 client->username = silc_get_username();
331 client->hostname = silc_net_localhost();
332 client->realname = silc_get_real_name();
333 client->pkcs = get_public_and_private_key(&client->public_key,
334 &client->private_key);
336 /* If the keys does not exist, create a key pair since we must
337 provide key pair to the library. */
339 generate_key_new_key_pair(client);
341 /* Iinitialize client */
342 if (!silc_client_init(client))
343 fatal_error("Could not initialize client");
345 /* Initialize user interface. The user interface can be generally
346 initialized at any phase, including before actually allocating
347 and initializing the client, if wished. */
351 /* Start the client. This will start the scheduler. At this phase
352 the user might have the user interface in front of him already.
353 He will use the user interface to create the connection to the
354 server for example. When this function returns the program is
356 silc_client_run(client);
358 /* Client is ended */