5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2006 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #ifndef SILCCLIENT_ENTRY_H
21 #define SILCCLIENT_ENTRY_H
24 #error "Do not include this header directly, include silcclient.h instead"
27 /****s* silcclient/SilcClientAPI/SilcClientEntry
31 * typedef struct SilcClientEntryStruct { ... } *SilcClientEntry;
35 * This structure represents a client or a user in the SILC network.
36 * The local user has this structure also and it can be accessed from
37 * SilcClientConnection structure. All other users in the SILC network
38 * that are accessed using the Client Library routines will have their
39 * own SilcClientEntry structure. For example, when finding users by
40 * their nickname the Client Library returns this structure back to
41 * the application. All strings in the structure are UTF-8 encoded.
43 * Application may store its own pointer into the context pointer in
48 * If application wants to store nickname or any of the other strings
49 * it should always duplicated them.
51 * None of the string arrays are set if the first character is '\0'.
52 * All string arrays are always NULL terminated.
54 * If application stores the SilcClientEntry it must always take
55 * a reference of it by calling silc_client_ref_client function. The
56 * reference must be released after it is not needed anymore by calling
57 * silc_client_unref_client function.
61 struct SilcClientEntryStruct {
62 char nickname[128 + 1]; /* Nickname */
63 char username[128 + 1]; /* Username */
64 char hostname[256 + 1]; /* Hostname */
65 char server [256 + 1]; /* SILC server name */
66 char *realname; /* Realname (userinfo) */
67 char *nickname_normalized; /* Normalized nickname */
69 SilcClientID id; /* The Client ID */
70 SilcUInt32 mode; /* User mode in SILC, see SilcUserMode */
71 SilcPublicKey public_key; /* User's public key, may be NULL */
72 SilcHashTable channels; /* Channels client has joined */
73 SilcDList attrs; /* Requested Attributes (maybe NULL) */
74 unsigned char fingerprint[20]; /* SHA-1 fingerprint of the public key */
76 void *context; /* Application specific context */
77 SilcClientEntryInternal internal;
81 /****s* silcclient/SilcClientAPI/SilcChannelEntry
85 * typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry;
89 * This structure represents a channel in the SILC network. All
90 * channels that the client are aware of or have joined in will be
91 * represented as SilcChannelEntry. The structure includes information
92 * about the channel. All strings in the structure are UTF-8 encoded.
96 struct SilcChannelEntryStruct {
97 /* General information */
98 char *channel_name; /* Channel name */
99 SilcChannelID *id; /* Channel ID */
100 SilcUInt32 mode; /* Channel mode, ChannelModes. */
101 char *topic; /* Current topic, may be NULL */
102 SilcPublicKey founder_key; /* Founder key, may be NULL */
103 SilcUInt32 user_limit; /* User limit on channel */
105 /* All clients that has joined this channel. The key to the table is the
106 SilcClientEntry and the context is SilcChannelUser context. */
107 SilcHashTable user_list;
110 SilcCipher channel_key; /* The channel key */
111 unsigned char *key; /* Raw key data */
112 SilcUInt32 key_len; /* Raw key data length */
113 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
114 SilcHmac hmac; /* Current HMAC */
116 /* Channel private keys */
117 SilcDList private_keys; /* List of private keys or NULL */
118 SilcChannelPrivateKey curr_key; /* Current private key */
120 /* SilcChannelEntry status information */
121 SilcDList old_channel_keys;
123 SilcUInt16 resolve_cmd_ident; /* Command identifier when
124 resolving this entry */
126 /* Application specific data. Application may set here whatever it wants. */
131 /****s* silcclient/SilcClientAPI/SilcServerEntry
135 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
139 * This structure represents a server in the SILC network. All servers
140 * that the client is aware of and have for example resolved with
141 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
142 * All strings in the structure are UTF-8 encoded.
146 struct SilcServerEntryStruct {
147 /* General information */
148 char *server_name; /* Server name */
149 char *server_info; /* Server info */
150 SilcServerID *server_id; /* Server ID */
151 SilcUInt16 resolve_cmd_ident; /* Command identifier when
152 resolving this entry */
154 /* Application specific data. Application may set here whatever it wants. */
159 /* SilcClientEntry routines */
161 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
165 * typedef void (*SilcGetClientCallback)(SilcClient client,
166 * SilcClientConnection conn,
173 * Callback function given to various client search functions. The
174 * found entries are allocated into the `clients' list. The list must
175 * not be freed by the receiver, the library will free it later. If the
176 * `clients' is NULL, no such clients exist in the SILC Network, and
177 * the `status' will include the error.
181 * If the application stores any of the SilcClientEntry pointers from
182 * the `clients' list it must reference it with silc_client_ref_client
185 * Application must not free the returned `clients' list.
188 typedef void (*SilcGetClientCallback)(SilcClient client,
189 SilcClientConnection conn,
194 /****f* silcclient/SilcClientAPI/silc_client_ref_client
198 * void silc_client_ref_client(SilcClient client,
199 * SilcClientConnection conn,
200 * SilcClientEntry client_entry);
204 * Takes a reference of the client entry indicated by `client_entry'
205 * The reference must be released by calling silc_client_unref_client
206 * after it is not needed anymore.
209 void silc_client_ref_client(SilcClient client, SilcClientConnection conn,
210 SilcClientEntry client_entry);
212 /****f* silcclient/SilcClientAPI/silc_client_unref_client
216 * void silc_client_unref_client(SilcClient client,
217 * SilcClientConnection conn,
218 * SilcClientEntry client_entry);
222 * Releases the client entry reference indicated by `client_entry'.
225 void silc_client_unref_client(SilcClient client, SilcClientConnection conn,
226 SilcClientEntry client_entry);
228 /****f* silcclient/SilcClientAPI/silc_client_list_free
232 * void silc_client_list_free(SilcClient client,
233 * SilcClientConnection conn,
234 * SilcDList client_list);
238 * Free's client entry list that has been returned by various library
242 void silc_client_list_free(SilcClient client, SilcClientConnection conn,
243 SilcDList client_list);
245 /****f* silcclient/SilcClientAPI/silc_client_get_clients
249 * SilcUInt16 silc_client_get_clients(SilcClient client,
250 * SilcClientConnection conn,
251 * const char *nickname,
252 * const char *server,
253 * SilcGetClientCallback completion,
258 * Finds client entry or entries by the `nickname' and `server'. The
259 * completion callback will be called when the client entries has been
260 * found. After the server returns the client information it is cached
261 * and can be accesses locally at a later time. The resolving is done
262 * with IDENTIFY command. The `server' may be NULL. Returns 0 on
263 * error and the command identifier used with the command otherwise.
267 * This function is always asynchronous and resolves the client
268 * information from the server. Thus, if you already know the client
269 * information then use the silc_client_get_client_by_id function to
270 * get the client entry since this function may be very slow and should
271 * be used only to initially get the client entries.
273 * This function resolves only the relevant information (user's nickname
274 * and username). It does not resolve for example user's real name,
275 * joined channel list or other information. To resolve all the details
276 * use silc_client_get_clients_whois instead.
279 SilcUInt16 silc_client_get_clients(SilcClient client,
280 SilcClientConnection conn,
281 const char *nickname,
283 SilcGetClientCallback completion,
286 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
291 * silc_client_get_clients_whois(SilcClient client,
292 * SilcClientConnection conn,
293 * const char *nickname,
294 * const char *server,
295 * SilcBuffer attributes,
296 * SilcGetClientCallback completion,
301 * Finds client entry or entries by the `nickname' and `server'. The
302 * completion callback will be called when the client entries has been
303 * found. After the server returns the client information it is cached
304 * and can be accesses locally at a later time. The resolving is done
305 * with WHOIS command. The `server' may be NULL. Returns 0 on error,
306 * and the command identifier used with the command otherwise.
308 * If the `attributes' is non-NULL then the buffer includes Requested
309 * Attributes which can be used to fetch very detailed information
310 * about the user. If it is NULL then only normal WHOIS query is
311 * made (for more information about attributes see SilcAttribute).
312 * Caller may create the `attributes' with silc_client_attributes_request
317 * The resolving is done with WHOIS command. For this reason this
318 * command may take a long time because it resolves detailed user
322 SilcUInt16 silc_client_get_clients_whois(SilcClient client,
323 SilcClientConnection conn,
324 const char *nickname,
326 SilcBuffer attributes,
327 SilcGetClientCallback completion,
330 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
334 * SilcDList silc_client_get_clients_local(SilcClient client,
335 * SilcClientConnection conn,
336 * const char *nickname,
337 * const char *format);
341 * Same as silc_client_get_clients function but does not resolve anything
342 * from the server. This checks local cache and returns all matching
343 * clients from the local cache. If none was found this returns NULL.
344 * The `nickname' is the real nickname of the client, and the `format'
345 * is the formatted nickname to find exact match from multiple found
346 * entries. The format must be same as given in the SilcClientParams
347 * structure to the client library. If the `format' is NULL all found
348 * clients by `nickname' are returned. The caller must free the
349 * returned list by silc_client_list_free function.
353 * If the application stores any of the SilcClientEntry pointers from
354 * the returned list it must reference it with silc_client_ref_client
357 * Application must free the returned list with silc_client_list_free
361 SilcDList silc_client_get_clients_local(SilcClient client,
362 SilcClientConnection conn,
363 const char *nickname,
366 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
370 * void silc_client_get_clients_by_channel(SilcClient client,
371 * SilcClientConnection conn,
372 * SilcChannelEntry channel,
373 * SilcGetClientCallback completion,
378 * Gets client entries by the channel indicated by `channel'. Thus,
379 * it resovles the users currently on that channel. If all users are
380 * already resolved this returns the users from the channel. If the
381 * users are resolved only partially this resolves the complete user
382 * information. If no users are resolved on this channel at all, this
383 * calls USERS command to resolve all users on the channel. The `completion'
384 * will be called after the entries are available. When server returns
385 * the client information it will be cached and can be accessed locally
388 * This function can be used for example in SILC_COMMAND_JOIN command
389 * reply handling in application to resolve users on that channel. It
390 * also can be used after calling silc_client_get_channel_resolve to
391 * resolve users on that channel.
395 * The resolving is done with WHOIS command. For this reason this
396 * command may take a long time because it resolves detailed user
400 void silc_client_get_clients_by_channel(SilcClient client,
401 SilcClientConnection conn,
402 SilcChannelEntry channel,
403 SilcGetClientCallback completion,
406 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
410 * void silc_client_get_clients_by_list(SilcClient client,
411 * SilcClientConnection conn,
412 * SilcUInt32 list_count,
413 * SilcBuffer client_id_list,
414 * SilcGetClientCallback completion,
419 * Gets client entries by the list of client ID's `client_id_list'. This
420 * always resolves those client ID's it doesn't know about from the server.
421 * The `client_id_list' is a list of ID Payloads added one after other.
422 * JOIN command reply and USERS command reply for example returns this sort
423 * of list. The `completion' will be called after the entries are available.
424 * When server returns the client information it will be cached and can be
425 * accessed locally at a later time. The resolving is done with WHOIS
430 * If even after resolving some Client ID in the `client_id_list' is
431 * unknown it will be ignored and error is not returned.
434 void silc_client_get_clients_by_list(SilcClient client,
435 SilcClientConnection conn,
436 SilcUInt32 list_count,
437 SilcBuffer client_id_list,
438 SilcGetClientCallback completion,
441 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
445 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
446 * SilcClientConnection conn,
447 * SilcClientID *client_id);
451 * Find client entry by the client's ID. Returns the entry or NULL
452 * if the entry was not found. This checks the local cache and does
453 * not resolve anything from server.
457 * The returned SilcClientEntry has been referenced by the library and
458 * the caller must call silc_client_unref_client after the entry is not
462 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
463 SilcClientConnection conn,
464 SilcClientID *client_id);
466 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
471 * silc_client_get_client_by_id_resolve(SilcClient client,
472 * SilcClientConnection conn,
473 * SilcClientID *client_id,
474 * SilcBuffer attributes,
475 * SilcGetClientCallback completion,
480 * Same as silc_client_get_client_by_id but will always resolve the
481 * information from the server. Use this only if you know that you
482 * do not have the entry and the only thing you know about the client
483 * is its ID. When server returns the client information it will be
484 * cache and can be accessed locally at a later time. The resolving
485 * is done by sending WHOIS command.
487 * If the `attributes' is non-NULL then the buffer includes Requested
488 * Attributes which can be used to fetch very detailed information
489 * about the user. If it is NULL then only normal WHOIS query is
490 * made (for more information about attributes see SilcAttribute).
491 * Caller may create the `attributes' with silc_client_attributes_request
495 void silc_client_get_client_by_id_resolve(SilcClient client,
496 SilcClientConnection conn,
497 SilcClientID *client_id,
498 SilcBuffer attributes,
499 SilcGetClientCallback completion,
502 /****f* silcclient/SilcClientAPI/silc_client_del_client
506 * SilcBool silc_client_del_client(SilcClient client, SilcClientConnection conn,
507 * SilcClientEntry client_entry)
511 * Removes client from local cache by the client entry indicated by
512 * the `client_entry'. Returns TRUE if the deletion were successful.
515 SilcBool silc_client_del_client(SilcClient client, SilcClientConnection conn,
516 SilcClientEntry client_entry);
519 #endif /* SILCCLIENT_ENTRY_H */