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.
94 * Application may store its own pointer into the context pointer in
99 * If application stores the SilcChannelEntry it must always take
100 * a reference of it by calling silc_client_ref_channel function. The
101 * reference must be released after it is not needed anymore by calling
102 * silc_client_unref_channel function.
106 struct SilcChannelEntryStruct {
107 char *channel_name; /* Channel name */
108 char *topic; /* Current topic, may be NULL */
109 SilcPublicKey founder_key; /* Founder key, may be NULL */
110 SilcDList channel_pubkeys; /* Channel public keys, may be NULL */
111 SilcChannelID id; /* Channel ID */
112 SilcUInt32 mode; /* Channel mode, ChannelModes. */
113 SilcUInt32 user_limit; /* User limit on channel */
114 SilcHashTable user_list; /* Joined users. Key to hash table is
115 SilcClientEntry, context is
118 void *context; /* Application specific context */
119 SilcChannelEntryInternal internal;
123 /****s* silcclient/SilcClientAPI/SilcServerEntry
127 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry;
131 * This structure represents a server in the SILC network. All servers
132 * that the client is aware of and have for example resolved with
133 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
134 * Server's public key is present only if it has been retrieved using
135 * SILC_COMMAND_GETKEY command. All strings in the structure are UTF-8
138 * Application may store its own pointer into the context pointer in
143 * If application stores the SilcServerEntry it must always take
144 * a reference of it by calling silc_client_ref_server function. The
145 * reference must be released after it is not needed anymore by calling
146 * silc_client_unref_server function.
150 struct SilcServerEntryStruct {
151 /* General information */
152 char *server_name; /* Server name */
153 char *server_info; /* Server info */
154 SilcServerID id; /* Server ID */
155 SilcPublicKey public_key; /* Server public key, may be NULL */
157 void *context; /* Application specific context */
158 SilcServerEntryInternal internal;
162 /* SilcClientEntry routines */
164 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
168 * typedef void (*SilcGetClientCallback)(SilcClient client,
169 * SilcClientConnection conn,
176 * Callback function given to various client search functions. The
177 * found entries are allocated into the `clients' list. The list must
178 * not be freed by the receiver, the library will free it later. If the
179 * `clients' is NULL, no such clients exist in the SILC network, and
180 * the `status' will include the error. Each entry in the `clients'
181 * is SilcClientEntry.
185 * If the application stores any of the SilcClientEntry pointers from
186 * the `clients' list it must reference it with silc_client_ref_client
189 * Application must not free the returned `clients' list.
192 typedef void (*SilcGetClientCallback)(SilcClient client,
193 SilcClientConnection conn,
198 /****f* silcclient/SilcClientAPI/silc_client_ref_client
202 * void silc_client_ref_client(SilcClient client,
203 * SilcClientConnection conn,
204 * SilcClientEntry client_entry);
208 * Takes a reference of the client entry indicated by `client_entry'
209 * The reference must be released by calling silc_client_unref_client
210 * after it is not needed anymore.
213 void silc_client_ref_client(SilcClient client, SilcClientConnection conn,
214 SilcClientEntry client_entry);
216 /****f* silcclient/SilcClientAPI/silc_client_unref_client
220 * void silc_client_unref_client(SilcClient client,
221 * SilcClientConnection conn,
222 * SilcClientEntry client_entry);
226 * Releases the client entry reference indicated by `client_entry'.
229 void silc_client_unref_client(SilcClient client, SilcClientConnection conn,
230 SilcClientEntry client_entry);
232 /****f* silcclient/SilcClientAPI/silc_client_list_free
236 * void silc_client_list_free(SilcClient client,
237 * SilcClientConnection conn,
238 * SilcDList client_list);
242 * Free's client entry list that has been returned by various library
246 void silc_client_list_free(SilcClient client, SilcClientConnection conn,
247 SilcDList client_list);
249 /****f* silcclient/SilcClientAPI/silc_client_get_clients
253 * SilcUInt16 silc_client_get_clients(SilcClient client,
254 * SilcClientConnection conn,
255 * const char *nickname,
256 * const char *server,
257 * SilcGetClientCallback completion,
262 * Finds client entry or entries by the `nickname' and `server'. The
263 * completion callback will be called when the client entries has been
264 * found. After the server returns the client information it is cached
265 * and can be accesses locally at a later time. The resolving is done
266 * with IDENTIFY command. The `server' may be NULL. Returns 0 on
267 * error and the command identifier used with the command otherwise.
271 * This function is always asynchronous and resolves the client
272 * information from the server. Thus, if you already know the client
273 * information then use the silc_client_get_client_by_id function to
274 * get the client entry since this function may be very slow and should
275 * be used only to initially get the client entries.
277 * This function resolves only the relevant information (user's nickname
278 * and username). It does not resolve for example user's real name,
279 * joined channel list or other information. To resolve all the details
280 * use silc_client_get_clients_whois instead.
283 SilcUInt16 silc_client_get_clients(SilcClient client,
284 SilcClientConnection conn,
285 const char *nickname,
287 SilcGetClientCallback completion,
290 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
295 * silc_client_get_clients_whois(SilcClient client,
296 * SilcClientConnection conn,
297 * const char *nickname,
298 * const char *server,
299 * SilcBuffer attributes,
300 * SilcGetClientCallback completion,
305 * Finds client entry or entries by the `nickname' and `server'. The
306 * completion callback will be called when the client entries has been
307 * found. After the server returns the client information it is cached
308 * and can be accesses locally at a later time. The resolving is done
309 * with WHOIS command. The `server' may be NULL. Returns 0 on error,
310 * and the command identifier used with the command otherwise.
312 * If the `attributes' is non-NULL then the buffer includes Requested
313 * Attributes which can be used to fetch very detailed information
314 * about the user. If it is NULL then only normal WHOIS query is
315 * made (for more information about attributes see SilcAttribute).
316 * Caller may create the `attributes' with silc_client_attributes_request
321 * The resolving is done with WHOIS command. For this reason this
322 * command may take a long time because it resolves detailed user
326 SilcUInt16 silc_client_get_clients_whois(SilcClient client,
327 SilcClientConnection conn,
328 const char *nickname,
330 SilcBuffer attributes,
331 SilcGetClientCallback completion,
334 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
338 * SilcDList silc_client_get_clients_local(SilcClient client,
339 * SilcClientConnection conn,
340 * const char *nickname,
341 * const char *format);
345 * Same as silc_client_get_clients function but does not resolve anything
346 * from the server. This checks local cache and returns all matching
347 * clients from the local cache. If none was found this returns NULL.
348 * The `nickname' is the real nickname of the client, and the `format'
349 * is the formatted nickname to find exact match from multiple found
350 * entries. The format must be same as given in the SilcClientParams
351 * structure to the client library. If the `format' is NULL all found
352 * clients by `nickname' are returned. The caller must free the
353 * returned list by silc_client_list_free function.
357 * If the application stores any of the SilcClientEntry pointers from
358 * the returned list it must reference it with silc_client_ref_client
361 * Application must free the returned list with silc_client_list_free
365 SilcDList silc_client_get_clients_local(SilcClient client,
366 SilcClientConnection conn,
367 const char *nickname,
370 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
374 * void silc_client_get_clients_by_channel(SilcClient client,
375 * SilcClientConnection conn,
376 * SilcChannelEntry channel,
377 * SilcGetClientCallback completion,
382 * Gets client entries by the channel indicated by `channel'. Thus,
383 * it resovles the users currently on that channel. If all users are
384 * already resolved this returns the users from the channel. If the
385 * users are resolved only partially this resolves the complete user
386 * information. If no users are resolved on this channel at all, this
387 * calls USERS command to resolve all users on the channel. The `completion'
388 * will be called after the entries are available. When server returns
389 * the client information it will be cached and can be accessed locally
392 * This function can be used for example in SILC_COMMAND_JOIN command
393 * reply handling in application to resolve users on that channel. It
394 * also can be used after calling silc_client_get_channel_resolve to
395 * resolve users on that channel.
399 * The resolving is done with WHOIS command. For this reason this
400 * command may take a long time because it resolves detailed user
404 void silc_client_get_clients_by_channel(SilcClient client,
405 SilcClientConnection conn,
406 SilcChannelEntry channel,
407 SilcGetClientCallback completion,
410 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
415 * silc_client_get_clients_by_list(SilcClient client,
416 * SilcClientConnection conn,
417 * SilcUInt32 list_count,
418 * SilcBuffer client_id_list,
419 * SilcGetClientCallback completion,
424 * Gets client entries by the list of client ID's `client_id_list'. This
425 * always resolves those client ID's it doesn't know about from the server.
426 * The `client_id_list' is a list of ID Payloads added one after other.
427 * JOIN command reply and USERS command reply for example returns this sort
428 * of list. The `completion' will be called after the entries are available.
429 * When server returns the client information it will be cached and can be
430 * accessed locally at a later time. The resolving is done with WHOIS
433 * Returns command identifier for the resolving. It can be used to attach
434 * a pending command to it, if needed. Returns 0 when no resolving was
435 * done or wasn't needed (completion is called before this returns).
439 * If even after resolving some Client ID in the `client_id_list' is
440 * unknown it will be ignored and error is not returned.
443 SilcUInt16 silc_client_get_clients_by_list(SilcClient client,
444 SilcClientConnection conn,
445 SilcUInt32 list_count,
446 SilcBuffer client_id_list,
447 SilcGetClientCallback completion,
450 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
454 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
455 * SilcClientConnection conn,
456 * SilcClientID *client_id);
460 * Find client entry by the client's ID. Returns the entry or NULL
461 * if the entry was not found. This checks the local cache and does
462 * not resolve anything from server.
466 * The returned SilcClientEntry has been referenced by the library and
467 * the caller must call silc_client_unref_client after the entry is not
471 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
472 SilcClientConnection conn,
473 SilcClientID *client_id);
475 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
480 * silc_client_get_client_by_id_resolve(SilcClient client,
481 * SilcClientConnection conn,
482 * SilcClientID *client_id,
483 * SilcBuffer attributes,
484 * SilcGetClientCallback completion,
489 * Same as silc_client_get_client_by_id but will always resolve the
490 * information from the server. Use this only if you know that you
491 * do not have the entry and the only thing you know about the client
492 * is its ID. When server returns the client information it will be
493 * cache and can be accessed locally at a later time. The resolving
494 * is done by sending WHOIS command.
496 * Returns command identifier for the resolving. It can be used to attach
497 * a pending command to it, if needed. Returns 0 on error.
499 * If the `attributes' is non-NULL then the buffer includes Requested
500 * Attributes which can be used to fetch very detailed information
501 * about the user. If it is NULL then only normal WHOIS query is
502 * made (for more information about attributes see SilcAttribute).
503 * Caller may create the `attributes' with silc_client_attributes_request
508 silc_client_get_client_by_id_resolve(SilcClient client,
509 SilcClientConnection conn,
510 SilcClientID *client_id,
511 SilcBuffer attributes,
512 SilcGetClientCallback completion,
515 /* SilcChannelEntry routines */
517 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
521 * typedef void (*SilcGetChannelCallback)(SilcClient client,
522 * SilcClientConnection conn,
524 * SilcDList channels,
529 * Callback function given to various channel resolving functions.
530 * The found entries are included in the `channels' list and each entry
531 * in the list is SilcChannelEntry. If `channels' is NULL then no such
532 * channel exist in the network and the `status' will indicate the error.
536 * If the application stores any of the SilcChannelEntry pointers from
537 * the `channels' list it must reference it with silc_client_ref_channel
540 * Application must not free the returned `channels' list.
543 typedef void (*SilcGetChannelCallback)(SilcClient client,
544 SilcClientConnection conn,
549 /****f* silcclient/SilcClientAPI/silc_client_ref_channel
553 * void silc_client_ref_channel(SilcClient client,
554 * SilcClientConnection conn,
555 * SilcChannelEntry channel_entry);
559 * Takes a reference of the channel entry indicated by `channel_entry'
560 * The reference must be released by calling silc_client_unref_channel
561 * after it is not needed anymore.
564 void silc_client_ref_channel(SilcClient client, SilcClientConnection conn,
565 SilcChannelEntry channel_entry);
567 /****f* silcclient/SilcClientAPI/silc_client_unref_channel
571 * void silc_client_unref_channel(SilcClient client,
572 * SilcClientConnection conn,
573 * SilcChannelEntry channel_entry);
577 * Releases the channel entry reference indicated by `channel_entry'.
580 void silc_client_unref_channel(SilcClient client, SilcClientConnection conn,
581 SilcChannelEntry channel_entry);
583 /****f* silcclient/SilcClientAPI/silc_client_list_free_channel
587 * void silc_client_list_free_channel(SilcClient client,
588 * SilcClientConnection conn,
589 * SilcDList channel_list);
593 * Free's channel entry list that has been returned by various library
597 void silc_client_list_free_channels(SilcClient client,
598 SilcClientConnection conn,
599 SilcDList channel_list);
601 /****f* silcclient/SilcClientAPI/silc_client_get_channel
605 * SilcChannelEntry silc_client_get_channel(SilcClient client,
606 * SilcClientConnection conn,
607 * char *channel_name);
611 * Finds entry for channel by the channel name. Returns the entry or NULL
612 * if the entry was not found. It is found only if the client is joined
613 * to the channel. Use silc_client_get_channel_resolve or
614 * silc_client_get_channel_by_id_resolve to resolve channel that client
619 * The returned SilcChannelEntry has been referenced by the library and
620 * the caller must call silc_client_unref_channel after the entry is not
624 SilcChannelEntry silc_client_get_channel(SilcClient client,
625 SilcClientConnection conn,
628 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
632 * void silc_client_get_channel_resolve(SilcClient client,
633 * SilcClientConnection conn,
634 * char *channel_name,
635 * SilcGetChannelCallback completion,
640 * Resolves entry for channel by the channel name from the server.
641 * The resolving is done with IDENTIFY command. Note that users on
642 * the channel are not resolved at the same time. Use for example
643 * silc_client_get_clients_by_channel to resolve all users on a channel.
646 void silc_client_get_channel_resolve(SilcClient client,
647 SilcClientConnection conn,
649 SilcGetChannelCallback completion,
652 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
657 * silc_client_get_channel_by_id(SilcClient client,
658 * SilcClientConnection conn,
659 * SilcChannelID *channel_id);
663 * Finds channel entry by the channel ID. Returns the entry or NULL
664 * if the entry was not found. This checks the local cache and does
665 * not resolve anything from server.
669 * The returned SilcChannelEntry has been referenced by the library and
670 * the caller must call silc_client_unref_channel after the entry is not
674 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
675 SilcClientConnection conn,
676 SilcChannelID *channel_id);
678 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
683 * silc_client_get_channel_by_id_resolve(SilcClient client,
684 * SilcClientConnection conn,
685 * SilcChannelID *channel_id,
686 * SilcGetClientCallback completion,
691 * Resolves the channel information (its name mainly) from the server
692 * by the `channel_id'. Use this only if you know that you do not have
693 * the entry cached locally. The resolving is done with IDENTIFY command.
695 * Returns command identifier for the resolving. It can be used to attach
696 * a pending command to it, if needed. Returns 0 on error.
698 * Note that users on the channel are not resolved at the same time.
699 * Use for example silc_client_get_clients_by_channel to resolve all
700 * users on a channel.
704 silc_client_get_channel_by_id_resolve(SilcClient client,
705 SilcClientConnection conn,
706 SilcChannelID *channel_id,
707 SilcGetChannelCallback completion,
710 /* SilcServerEntry routines */
712 /****f* silcclient/SilcClientAPI/SilcGetServerCallback
716 * typedef void (*SilcGetServerCallback)(SilcClient client,
717 * SilcClientConnection conn,
724 * Callback function given to various server resolving functions.
725 * The found entries are included in the `servers' list and each entry
726 * in the list is SilcServerEntry. If `server' is NULL then no such
727 * server exist in the network and the `status' will indicate the error.
731 * If the application stores any of the SilcServerEntry pointers from
732 * the `server' list it must reference it with silc_client_ref_server
735 * Application must not free the returned `server' list.
738 typedef void (*SilcGetServerCallback)(SilcClient client,
739 SilcClientConnection conn,
744 /****f* silcclient/SilcClientAPI/silc_client_ref_server
748 * void silc_client_ref_server(SilcClient client,
749 * SilcClientConnection conn,
750 * SilcServerEntry server_entry);
754 * Takes a reference of the server entry indicated by `server_entry'
755 * The reference must be released by calling silc_client_unref_server
756 * after it is not needed anymore.
759 void silc_client_ref_server(SilcClient client, SilcClientConnection conn,
760 SilcServerEntry server_entry);
762 /****f* silcclient/SilcClientAPI/silc_client_unref_server
766 * void silc_client_unref_server(SilcClient client,
767 * SilcClientConnection conn,
768 * SilcServerEntry server_entry);
772 * Releases the server entry reference indicated by `server_entry'.
775 void silc_client_unref_server(SilcClient client, SilcClientConnection conn,
776 SilcServerEntry server_entry);
778 /****f* silcclient/SilcClientAPI/silc_client_list_free_server
782 * void silc_client_list_free_server(SilcClient client,
783 * SilcClientConnection conn,
784 * SilcDList server_list);
788 * Free's server entry list that has been returned by various library
792 void silc_client_list_free_servers(SilcClient client,
793 SilcClientConnection conn,
794 SilcDList server_list);
796 /****f* silcclient/SilcClientAPI/silc_client_get_server
800 * SilcServerEntry silc_client_get_server(SilcClient client,
801 * SilcClientConnection conn,
806 * Finds entry for server by the server name. Returns the entry or NULL
807 * if the entry was not found.
810 SilcServerEntry silc_client_get_server(SilcClient client,
811 SilcClientConnection conn,
814 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
818 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
819 * SilcClientConnection conn,
820 * SilcServerID *server_id);
824 * Finds entry for server by the server ID. Returns the entry or NULL
825 * if the entry was not found.
828 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
829 SilcClientConnection conn,
830 SilcServerID *server_id);
832 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id_resolve
837 * silc_client_get_server_by_id_resolve(SilcClient client,
838 * SilcClientConnection conn,
839 * SilcServerID *server_id,
840 * SilcGetServerCallback completion,
845 * Resolves the server information by the `server_id'. The resolved
846 * server is returned into the `completion' callback.
848 * Returns command identifier for the resolving. It can be used to attach
849 * a pending command to it, if needed. Returns 0 on error.
853 silc_client_get_server_by_id_resolve(SilcClient client,
854 SilcClientConnection conn,
855 SilcServerID *server_id,
856 SilcGetServerCallback completion,
859 #endif /* SILCCLIENT_ENTRY_H */