Fixed nickname parsing with WHOIS command to accept formatted
[silc.git] / lib / silcclient / silcclient_entry.h
1 /*
2
3   silcclient_entry.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2006 - 2007 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 /****h* silcclient/Client Library Interface
21  *
22  * DESCRIPTION
23  *
24  * This header file includes the SilcClientEntry, SilcChannelEntry and
25  * SilcServer entry structures and various routines to search, resolve and
26  * handle these structures.
27  *
28  * All entries (SilcClientEntry, SilcChannelEntry and SilcServerEntry) are
29  * reference counted.  If application wishes to save an entry pointer it must
30  * always first acquire a reference.  The reference must be released once the
31  * entry is not needed anymore.  If application wants to read any data from
32  * the entry structure it must first lock the entry.  This protects access to
33  * the entries in multithreaded environment.  If threads are not used, locking
34  * the entries is not needed.  They however still must be referenced even
35  * when threads are not used.
36  *
37  ***/
38
39 #ifndef SILCCLIENT_ENTRY_H
40 #define SILCCLIENT_ENTRY_H
41
42 #ifndef SILCCLIENT_H
43 #error "Do not include this header directly, include silcclient.h instead"
44 #endif
45
46 /****s* silcclient/SilcClientAPI/SilcClientEntry
47  *
48  * NAME
49  *
50  *    typedef struct SilcClientEntryStruct { ... } *SilcClientEntry;
51  *
52  * DESCRIPTION
53  *
54  *    This structure represents a client or a user in the SILC network.
55  *    The local user has this structure also and it can be accessed from
56  *    SilcClientConnection structure.  All other users in the SILC network
57  *    that are accessed using the Client Library routines will have their
58  *    own SilcClientEntry structure.  For example, when finding users by
59  *    their nickname the Client Library returns this structure back to
60  *    the application.  All strings in the structure are UTF-8 encoded.
61  *
62  *    Application may store its own pointer into the context pointer in
63  *    this structure.
64  *
65  * NOTES
66  *
67  *    If application wants to store nickname or any of the other strings
68  *    it should always duplicated them.
69  *
70  *    None of the string arrays are set if the first character is '\0'.
71  *    All string arrays are always zero ('\0') terminated.
72  *
73  *    If application stores the SilcClientEntry it must always take
74  *    a reference of it by calling silc_client_ref_client function.  The
75  *    reference must be released after it is not needed anymore by calling
76  *    silc_client_unref_client function.
77  *
78  * SOURCE
79  */
80 struct SilcClientEntryStruct {
81   char nickname[128 + 1];            /* Nickname */
82   char username[128 + 1];            /* Username */
83   char hostname[256 + 1];            /* Hostname */
84   char server  [256 + 1];            /* SILC server name */
85   char *realname;                    /* Realname (userinfo) */
86   char *nickname_normalized;         /* Normalized nickname */
87
88   SilcClientID id;                   /* The Client ID */
89   SilcUInt32 mode;                   /* User mode in SILC, see SilcUserMode */
90   SilcPublicKey public_key;          /* User's public key, may be NULL */
91   SilcHashTable channels;            /* Channels client has joined */
92   SilcDList attrs;                   /* Requested Attributes (maybe NULL) */
93   unsigned char fingerprint[20];     /* SHA-1 fingerprint of the public key */
94
95   void *context;                     /* Application specific context */
96   SilcClientEntryInternal internal;
97 };
98 /***/
99
100 /****s* silcclient/SilcClientAPI/SilcChannelEntry
101  *
102  * NAME
103  *
104  *    typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry;
105  *
106  * DESCRIPTION
107  *
108  *    This structure represents a channel in the SILC network.  All
109  *    channels that the client are aware of or have joined in will be
110  *    represented as SilcChannelEntry.  The structure includes information
111  *    about the channel.  All strings in the structure are UTF-8 encoded.
112  *
113  *    Application may store its own pointer into the context pointer in
114  *    this structure.
115  *
116  * NOTES
117  *
118  *    If application stores the SilcChannelEntry it must always take
119  *    a reference of it by calling silc_client_ref_channel function.  The
120  *    reference must be released after it is not needed anymore by calling
121  *    silc_client_unref_channel function.
122  *
123  * SOURCE
124  */
125 struct SilcChannelEntryStruct {
126   char *channel_name;                /* Channel name */
127   char *topic;                       /* Current topic, may be NULL */
128   SilcPublicKey founder_key;         /* Founder key, may be NULL */
129   SilcDList channel_pubkeys;         /* Channel public keys, may be NULL */
130   SilcChannelID id;                  /* Channel ID */
131   SilcUInt32 mode;                   /* Channel mode, ChannelModes. */
132   SilcUInt32 user_limit;             /* User limit on channel */
133   SilcHashTable user_list;           /* Joined users.  Key to hash table is
134                                         SilcClientEntry, context is
135                                         SilcChannelUser. */
136
137   void *context;                     /* Application specific context */
138   SilcChannelEntryInternal internal;
139 };
140 /***/
141
142 /****s* silcclient/SilcClientAPI/SilcServerEntry
143  *
144  * NAME
145  *
146  *    typedef struct SilcServerEntryStruct { ... } *SilcServerEntry;
147  *
148  * DESCRIPTION
149  *
150  *    This structure represents a server in the SILC network.  All servers
151  *    that the client is aware of and have for example resolved with
152  *    SILC_COMMAND_INFO command have their on SilcServerEntry structure.
153  *    Server's public key is present only if it has been retrieved using
154  *    SILC_COMMAND_GETKEY command.  All strings in the structure are UTF-8
155  *    encoded.
156  *
157  *    Application may store its own pointer into the context pointer in
158  *    this structure.
159  *
160  * NOTES
161  *
162  *    If application stores the SilcServerEntry it must always take
163  *    a reference of it by calling silc_client_ref_server function.  The
164  *    reference must be released after it is not needed anymore by calling
165  *    silc_client_unref_server function.
166  *
167  * SOURCE
168  */
169 struct SilcServerEntryStruct {
170   /* General information */
171   char *server_name;                 /* Server name */
172   char *server_info;                 /* Server info */
173   SilcServerID id;                   /* Server ID */
174   SilcPublicKey public_key;          /* Server public key, may be NULL */
175
176   void *context;                     /* Application specific context */
177   SilcServerEntryInternal internal;
178 };
179 /***/
180
181 /* SilcClientEntry routines */
182
183 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
184  *
185  * SYNOPSIS
186  *
187  *    typedef void (*SilcGetClientCallback)(SilcClient client,
188  *                                          SilcClientConnection conn,
189  *                                          SilcStatus status,
190  *                                          SilcDList clients,
191  *                                          void *context);
192  *
193  * DESCRIPTION
194  *
195  *    Callback function given to various client search functions.  The
196  *    found entries are allocated into the `clients' list.  The list must
197  *    not be freed by the receiver, the library will free it later.  If the
198  *    `clients' is NULL, no such clients exist in the SILC network, and
199  *    the `status' will include the error.  Each entry in the `clients'
200  *    is SilcClientEntry.
201  *
202  * NOTES
203  *
204  *    If the application stores any of the SilcClientEntry pointers from
205  *    the `clients' list it must reference it with silc_client_ref_client
206  *    function.
207  *
208  *    Application must not free the returned `clients' list.
209  *
210  ***/
211 typedef void (*SilcGetClientCallback)(SilcClient client,
212                                       SilcClientConnection conn,
213                                       SilcStatus status,
214                                       SilcDList clients,
215                                       void *context);
216
217 /****f* silcclient/SilcClientAPI/silc_client_lock_client
218  *
219  * SYNOPSIS
220  *
221  *    void silc_client_lock_client(SilcClientEntry client_entry);
222  *
223  * DESCRIPTION
224  *
225  *    Acquires lock for the client entry indicate by `client_entry'.  When
226  *    application wants to access `client_entry' it must lock the entry
227  *    before reading any data from the `client_entry'.  The lock must be
228  *    unlocked with silc_client_unlock_client.
229  *
230  * NOTES
231  *
232  *    The entry must be unlocked before calling any Client Library API
233  *    functions where the entry is given as argument, unless otherwise stated.
234  *
235  *    The entry should not be locked for long periods of time.  For example,
236  *    it is not appropriate to hold the lock while waiting user interface to
237  *    be drawn.  The appropriate way is to read the data and duplicate it if
238  *    necessary, unlock the entry, then draw on the user interface.
239  *
240  *    This function is not needed if application is not multithreaded.
241  *
242  ***/
243 void silc_client_lock_client(SilcClientEntry client_entry);
244
245 /****f* silcclient/SilcClientAPI/silc_client_unlock_client
246  *
247  * SYNOPSIS
248  *
249  *    void silc_client_unlock_client(SilcClientEntry client_entry);
250  *
251  * DESCRIPTION
252  *
253  *    Releases the lock acquired with silc_client_lock_client.
254  *
255  ***/
256 void silc_client_unlock_client(SilcClientEntry client_entry);
257
258 /****f* silcclient/SilcClientAPI/silc_client_ref_client
259  *
260  * SYNOPSIS
261  *
262  *    SilcClientEntry
263  *    silc_client_ref_client(SilcClient client,
264  *                           SilcClientConnection conn,
265  *                           SilcClientEntry client_entry);
266  *
267  * DESCRIPTION
268  *
269  *    Takes a reference of the client entry indicated by `client_entry'
270  *    The reference must be released by calling silc_client_unref_client
271  *    after it is not needed anymore.  Returns `client_entry'.
272  *
273  ***/
274 SilcClientEntry silc_client_ref_client(SilcClient client,
275                                        SilcClientConnection conn,
276                                        SilcClientEntry client_entry);
277
278 /****f* silcclient/SilcClientAPI/silc_client_unref_client
279  *
280  * SYNOPSIS
281  *
282  *    void silc_client_unref_client(SilcClient client,
283  *                                  SilcClientConnection conn,
284  *                                  SilcClientEntry client_entry);
285  *
286  * DESCRIPTION
287  *
288  *    Releases the client entry reference indicated by `client_entry'.
289  *
290  ***/
291 void silc_client_unref_client(SilcClient client, SilcClientConnection conn,
292                               SilcClientEntry client_entry);
293
294 /****f* silcclient/SilcClientAPI/silc_client_list_free
295  *
296  * SYNOPSIS
297  *
298  *    void silc_client_list_free(SilcClient client,
299  *                               SilcClientConnection conn,
300  *                               SilcDList client_list);
301  *
302  * DESCRIPTION
303  *
304  *    Free's client entry list that has been returned by various library
305  *    routines.
306  *
307  ***/
308 void silc_client_list_free(SilcClient client, SilcClientConnection conn,
309                            SilcDList client_list);
310
311 /****f* silcclient/SilcClientAPI/silc_client_get_clients
312  *
313  * SYNOPSIS
314  *
315  *    SilcUInt16 silc_client_get_clients(SilcClient client,
316  *                                       SilcClientConnection conn,
317  *                                       const char *nickname,
318  *                                       const char *server,
319  *                                       SilcGetClientCallback completion,
320  *                                       void *context);
321  *
322  * DESCRIPTION
323  *
324  *    Finds client entry or entries by the `nickname' and `server'. The
325  *    completion callback will be called when the client entries has been
326  *    found.  After the server returns the client information it is cached
327  *    and can be accesses locally at a later time.  The resolving is done
328  *    with IDENTIFY command.  The `server' may be NULL.  The server
329  *    associated with the nickname may be in the `nickname' (nick@server).
330  *    Returns 0 on error and the command identifier used with the command
331  *    otherwise.
332  *
333  * NOTES
334  *
335  *    This function is always asynchronous and resolves the client
336  *    information from the server.  Thus, if you already know the client
337  *    information then use the silc_client_get_client_by_id function to
338  *    get the client entry since this function may be very slow and should
339  *    be used only to initially get the client entries.
340  *
341  *    This function resolves only the relevant information (user's nickname
342  *    and username).  It does not resolve for example user's real name,
343  *    joined channel list or other information.  To resolve all the details
344  *    use silc_client_get_clients_whois instead.
345  *
346  ***/
347 SilcUInt16 silc_client_get_clients(SilcClient client,
348                                    SilcClientConnection conn,
349                                    const char *nickname,
350                                    const char *server,
351                                    SilcGetClientCallback completion,
352                                    void *context);
353
354 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
355  *
356  * SYNOPSIS
357  *
358  *    SilcUInt16
359  *    silc_client_get_clients_whois(SilcClient client,
360  *                                  SilcClientConnection conn,
361  *                                  const char *nickname,
362  *                                  const char *server,
363  *                                  SilcBuffer attributes,
364  *                                  SilcGetClientCallback completion,
365  *                                  void *context);
366  *
367  * DESCRIPTION
368  *
369  *    Finds client entry or entries by the `nickname' and `server'. The
370  *    completion callback will be called when the client entries has been
371  *    found.  After the server returns the client information it is cached
372  *    and can be accesses locally at a later time.  The resolving is done
373  *    with WHOIS command.  The `server' may be NULL.  The server
374  *    associated with the nickname may be in the `nickname' (nick@server).
375  *    Returns 0 on error and the command identifier used with the command
376  *    otherwise.
377  *
378  *    If the `attributes' is non-NULL then the buffer includes Requested
379  *    Attributes which can be used to fetch very detailed information
380  *    about the user. If it is NULL then only normal WHOIS query is
381  *    made (for more information about attributes see SilcAttribute).
382  *    Caller may create the `attributes' with silc_client_attributes_request
383  *    function.
384  *
385  * NOTES
386  *
387  *    The resolving is done with WHOIS command.  For this reason this
388  *    command may take a long time because it resolves detailed user
389  *    information.
390  *
391  ***/
392 SilcUInt16 silc_client_get_clients_whois(SilcClient client,
393                                          SilcClientConnection conn,
394                                          const char *nickname,
395                                          const char *server,
396                                          SilcBuffer attributes,
397                                          SilcGetClientCallback completion,
398                                          void *context);
399
400 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
401  *
402  * SYNOPSIS
403  *
404  *    SilcDList silc_client_get_clients_local(SilcClient client,
405  *                                            SilcClientConnection conn,
406  *                                            const char *nickname,
407  *                                            SilcBool return_all);
408  *
409  * DESCRIPTION
410  *
411  *    Same as silc_client_get_clients function but does not resolve anything
412  *    from the server.  This checks local cache and returns matching clients
413  *    from the local cache.  If none was found this returns NULL.  The
414  *    `nickname' is the nickname to find and it may be a formatted nickname
415  *    or a base nickname.  If the `return_all' is TRUE this call will return
416  *    all clients matching the `nickname' base.  If it is FALSE this will
417  *    return the exact match if `nickname' is a formatted nickname or the
418  *    first matching nickname if it is not formatted.  The formatted nickname
419  *    must of the format specified in SilcClientParams.  The caller must free
420  *    the returned list by calling silc_client_list_free function.
421  *
422  * NOTES
423  *
424  *    If the application stores any of the SilcClientEntry pointers from
425  *    the returned list it must reference it with silc_client_ref_client
426  *    function.
427  *
428  *    Application must free the returned list with silc_client_list_free
429  *    function.
430  *
431  ***/
432 SilcDList silc_client_get_clients_local(SilcClient client,
433                                         SilcClientConnection conn,
434                                         const char *nickname,
435                                         SilcBool return_all);
436
437 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
438  *
439  * SYNOPSIS
440  *
441  *    void silc_client_get_clients_by_channel(SilcClient client,
442  *                                            SilcClientConnection conn,
443  *                                            SilcChannelEntry channel,
444  *                                            SilcGetClientCallback completion,
445  *                                            void *context);
446  *
447  * DESCRIPTION
448  *
449  *    Gets client entries by the channel indicated by `channel'. Thus,
450  *    it resovles the users currently on that channel. If all users are
451  *    already resolved this returns the users from the channel. If the
452  *    users are resolved only partially this resolves the complete user
453  *    information. If no users are resolved on this channel at all, this
454  *    calls USERS command to resolve all users on the channel. The `completion'
455  *    will be called after the entries are available. When server returns
456  *    the client information it will be cached and can be accessed locally
457  *    at a later time.
458  *
459  *    This function can be used for example in SILC_COMMAND_JOIN command
460  *    reply handling in application to resolve users on that channel.  It
461  *    also can be used after calling silc_client_get_channel_resolve to
462  *    resolve users on that channel.
463  *
464  * NOTES
465  *
466  *    The resolving is done with WHOIS command.  For this reason this
467  *    command may take a long time because it resolves detailed user
468  *    information.
469  *
470  ***/
471 void silc_client_get_clients_by_channel(SilcClient client,
472                                         SilcClientConnection conn,
473                                         SilcChannelEntry channel,
474                                         SilcGetClientCallback completion,
475                                         void *context);
476
477 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
478  *
479  * SYNOPSIS
480  *
481  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
482  *                                                 SilcClientConnection conn,
483  *                                                 SilcClientID *client_id);
484  *
485  * DESCRIPTION
486  *
487  *    Find client entry by the client's ID.  Returns the entry or NULL
488  *    if the entry was not found.  This checks the local cache and does
489  *    not resolve anything from server.
490  *
491  * NOTES
492  *
493  *    The returned SilcClientEntry has been referenced by the library and
494  *    the caller must call silc_client_unref_client after the entry is not
495  *    needed anymore.
496  *
497  ***/
498 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
499                                              SilcClientConnection conn,
500                                              SilcClientID *client_id);
501
502 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
503  *
504  * SYNOPSIS
505  *
506  *    SilcUInt16
507  *    silc_client_get_client_by_id_resolve(SilcClient client,
508  *                                         SilcClientConnection conn,
509  *                                         SilcClientID *client_id,
510  *                                         SilcBuffer attributes,
511  *                                         SilcGetClientCallback completion,
512  *                                         void *context);
513  *
514  * DESCRIPTION
515  *
516  *    Same as silc_client_get_client_by_id but will always resolve the
517  *    information from the server. Use this only if you know that you
518  *    do not have the entry and the only thing you know about the client
519  *    is its ID. When server returns the client information it will be
520  *    cache and can be accessed locally at a later time. The resolving
521  *    is done by sending WHOIS command.
522  *
523  *    Returns command identifier for the resolving.  It can be used to attach
524  *    a pending command to it, if needed.  Returns 0 on error.
525  *
526  *    If the `attributes' is non-NULL then the buffer includes Requested
527  *    Attributes which can be used to fetch very detailed information
528  *    about the user. If it is NULL then only normal WHOIS query is
529  *    made (for more information about attributes see SilcAttribute).
530  *    Caller may create the `attributes' with silc_client_attributes_request
531  *    function.
532  *
533  ***/
534 SilcUInt16
535 silc_client_get_client_by_id_resolve(SilcClient client,
536                                      SilcClientConnection conn,
537                                      SilcClientID *client_id,
538                                      SilcBuffer attributes,
539                                      SilcGetClientCallback completion,
540                                      void *context);
541
542 /* SilcChannelEntry routines */
543
544 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
545  *
546  * SYNOPSIS
547  *
548  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
549  *                                           SilcClientConnection conn,
550  *                                           SilcStatus status,
551  *                                           SilcDList channels,
552  *                                           void *context);
553  *
554  * DESCRIPTION
555  *
556  *    Callback function given to various channel resolving functions.
557  *    The found entries are included in the `channels' list and each entry
558  *    in the list is SilcChannelEntry.  If `channels' is NULL then no such
559  *    channel exist in the network and the `status' will indicate the error.
560  *
561  * NOTES
562  *
563  *    If the application stores any of the SilcChannelEntry pointers from
564  *    the `channels' list it must reference it with silc_client_ref_channel
565  *    function.
566  *
567  *    Application must not free the returned `channels' list.
568  *
569  ***/
570 typedef void (*SilcGetChannelCallback)(SilcClient client,
571                                        SilcClientConnection conn,
572                                        SilcStatus status,
573                                        SilcDList channels,
574                                        void *context);
575
576 /****f* silcclient/SilcClientAPI/silc_client_lock_channel
577  *
578  * SYNOPSIS
579  *
580  *    void silc_client_lock_channel(SilcChannelEntry channel_entry);
581  *
582  * DESCRIPTION
583  *
584  *    Acquires lock for the channel entry indicate by `channel_entry'.  When
585  *    application wants to access `channel_entry' it must lock the entry
586  *    before reading any data from the `channel_entry'.  The lock must be
587  *    unlocked with silc_client_unlock_channel.
588  *
589  * NOTES
590  *
591  *    The entry must be unlocked before calling any Client Library API
592  *    functions where the entry is given as argument, unless otherwise stated.
593  *
594  *    The entry should not be locked for long periods of time.  For example,
595  *    it is not appropriate to hold the lock while waiting user interface to
596  *    be drawn.  The appropriate way is to read the data and duplicate it if
597  *    necessary, unlock the entry, then draw on the user interface.
598  *
599  *    This function is not needed if application is not multithreaded.
600  *
601  ***/
602 void silc_client_lock_channel(SilcChannelEntry channel_entry);
603
604 /****f* silcclient/SilcClientAPI/silc_client_unlock_channel
605  *
606  * SYNOPSIS
607  *
608  *    void silc_client_unlock_channel(SilcChannelEntry channel_entry);
609  *
610  * DESCRIPTION
611  *
612  *    Releases the lock acquired with silc_client_lock_channel.
613  *
614  ***/
615 void silc_client_unlock_channel(SilcChannelEntry channel_entry);
616
617 /****f* silcclient/SilcClientAPI/silc_client_ref_channel
618  *
619  * SYNOPSIS
620  *
621  *    SilcChannelEntry
622  *    silc_client_ref_channel(SilcClient client,
623  *                            SilcClientConnection conn,
624  *                            SilcChannelEntry channel_entry);
625  *
626  * DESCRIPTION
627  *
628  *    Takes a reference of the channel entry indicated by `channel_entry'
629  *    The reference must be released by calling silc_client_unref_channel
630  *    after it is not needed anymore.  Returns `channel_entry'.
631  *
632  ***/
633 SilcChannelEntry silc_client_ref_channel(SilcClient client,
634                                          SilcClientConnection conn,
635                                          SilcChannelEntry channel_entry);
636
637 /****f* silcclient/SilcClientAPI/silc_client_unref_channel
638  *
639  * SYNOPSIS
640  *
641  *    void silc_client_unref_channel(SilcClient client,
642  *                                   SilcClientConnection conn,
643  *                                   SilcChannelEntry channel_entry);
644  *
645  * DESCRIPTION
646  *
647  *    Releases the channel entry reference indicated by `channel_entry'.
648  *
649  ***/
650 void silc_client_unref_channel(SilcClient client, SilcClientConnection conn,
651                                SilcChannelEntry channel_entry);
652
653 /****f* silcclient/SilcClientAPI/silc_client_list_free_channel
654  *
655  * SYNOPSIS
656  *
657  *    void silc_client_list_free_channel(SilcClient client,
658  *                                       SilcClientConnection conn,
659  *                                       SilcDList channel_list);
660  *
661  * DESCRIPTION
662  *
663  *    Free's channel entry list that has been returned by various library
664  *    routines.
665  *
666  ***/
667 void silc_client_list_free_channels(SilcClient client,
668                                     SilcClientConnection conn,
669                                     SilcDList channel_list);
670
671 /****f* silcclient/SilcClientAPI/silc_client_get_channel
672  *
673  * SYNOPSIS
674  *
675  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
676  *                                             SilcClientConnection conn,
677  *                                             char *channel_name);
678  *
679  * DESCRIPTION
680  *
681  *    Finds entry for channel by the channel name. Returns the entry or NULL
682  *    if the entry was not found. It is found only if the client is joined
683  *    to the channel.  Use silc_client_get_channel_resolve or
684  *    silc_client_get_channel_by_id_resolve to resolve channel that client
685  *    is not joined.
686  *
687  * NOTES
688  *
689  *    The returned SilcChannelEntry has been referenced by the library and
690  *    the caller must call silc_client_unref_channel after the entry is not
691  *    needed anymore.
692  *
693  ***/
694 SilcChannelEntry silc_client_get_channel(SilcClient client,
695                                          SilcClientConnection conn,
696                                          char *channel_name);
697
698 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
699  *
700  * SYNOPSIS
701  *
702  *    void silc_client_get_channel_resolve(SilcClient client,
703  *                                         SilcClientConnection conn,
704  *                                         char *channel_name,
705  *                                         SilcGetChannelCallback completion,
706  *                                         void *context);
707  *
708  * DESCRIPTION
709  *
710  *    Resolves entry for channel by the channel name from the server.
711  *    The resolving is done with IDENTIFY command. Note that users on
712  *    the channel are not resolved at the same time. Use for example
713  *    silc_client_get_clients_by_channel to resolve all users on a channel.
714  *
715  ***/
716 void silc_client_get_channel_resolve(SilcClient client,
717                                      SilcClientConnection conn,
718                                      char *channel_name,
719                                      SilcGetChannelCallback completion,
720                                      void *context);
721
722 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
723  *
724  * SYNOPSIS
725  *
726  *    SilcChannelEntry
727  *    silc_client_get_channel_by_id(SilcClient client,
728  *                                  SilcClientConnection conn,
729  *                                  SilcChannelID *channel_id);
730  *
731  * DESCRIPTION
732  *
733  *    Finds channel entry by the channel ID. Returns the entry or NULL
734  *    if the entry was not found.  This checks the local cache and does
735  *    not resolve anything from server.
736  *
737  * NOTES
738  *
739  *    The returned SilcChannelEntry has been referenced by the library and
740  *    the caller must call silc_client_unref_channel after the entry is not
741  *    needed anymore.
742  *
743  ***/
744 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
745                                                SilcClientConnection conn,
746                                                SilcChannelID *channel_id);
747
748 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
749  *
750  * SYNOPSIS
751  *
752  *    SilcUInt16
753  *    silc_client_get_channel_by_id_resolve(SilcClient client,
754  *                                          SilcClientConnection conn,
755  *                                          SilcChannelID *channel_id,
756  *                                          SilcGetClientCallback completion,
757  *                                          void *context);
758  *
759  * DESCRIPTION
760  *
761  *    Resolves the channel information (its name mainly) from the server
762  *    by the `channel_id'. Use this only if you know that you do not have
763  *    the entry cached locally. The resolving is done with IDENTIFY command.
764  *
765  *    Returns command identifier for the resolving.  It can be used to attach
766  *    a pending command to it, if needed.  Returns 0 on error.
767  *
768  *    Note that users on the channel are not resolved at the same time.
769  *    Use for example silc_client_get_clients_by_channel to resolve all
770  *    users on a channel.
771  *
772  ***/
773 SilcUInt16
774 silc_client_get_channel_by_id_resolve(SilcClient client,
775                                       SilcClientConnection conn,
776                                       SilcChannelID *channel_id,
777                                       SilcGetChannelCallback completion,
778                                       void *context);
779
780 /* SilcServerEntry routines */
781
782 /****f* silcclient/SilcClientAPI/SilcGetServerCallback
783  *
784  * SYNOPSIS
785  *
786  *    typedef void (*SilcGetServerCallback)(SilcClient client,
787  *                                          SilcClientConnection conn,
788  *                                          SilcStatus status,
789  *                                          SilcDList servers,
790  *                                          void *context);
791  *
792  * DESCRIPTION
793  *
794  *    Callback function given to various server resolving functions.
795  *    The found entries are included in the `servers' list and each entry
796  *    in the list is SilcServerEntry.  If `server' is NULL then no such
797  *    server exist in the network and the `status' will indicate the error.
798  *
799  * NOTES
800  *
801  *    If the application stores any of the SilcServerEntry pointers from
802  *    the `server' list it must reference it with silc_client_ref_server
803  *    function.
804  *
805  *    Application must not free the returned `server' list.
806  *
807  ***/
808 typedef void (*SilcGetServerCallback)(SilcClient client,
809                                       SilcClientConnection conn,
810                                       SilcStatus status,
811                                       SilcDList servers,
812                                       void *context);
813
814 /****f* silcclient/SilcClientAPI/silc_client_lock_server
815  *
816  * SYNOPSIS
817  *
818  *    void silc_client_lock_server(SilcServerEntry server_entry);
819  *
820  * DESCRIPTION
821  *
822  *    Acquires lock for the server entry indicate by `server_entry'.  When
823  *    application wants to access `server_entry' it must lock the entry
824  *    before reading any data from the `server_entry'.  The lock must be
825  *    unlocked with silc_client_unlock_server.
826  *
827  * NOTES
828  *
829  *    The entry must be unlocked before calling any Client Library API
830  *    functions where the entry is given as argument, unless otherwise stated.
831  *
832  *    The entry should not be locked for long periods of time.  For example,
833  *    it is not appropriate to hold the lock while waiting user interface to
834  *    be drawn.  The appropriate way is to read the data and duplicate it if
835  *    necessary, unlock the entry, then draw on the user interface.
836  *
837  *    This function is not needed if application is not multithreaded.
838  *
839  ***/
840 void silc_client_lock_server(SilcServerEntry server_entry);
841
842 /****f* silcclient/SilcClientAPI/silc_client_unlock_server
843  *
844  * SYNOPSIS
845  *
846  *    void silc_client_unlock_server(SilcServerEntry server_entry);
847  *
848  * DESCRIPTION
849  *
850  *    Releases the lock acquired with silc_client_lock_server.
851  *
852  ***/
853 void silc_client_unlock_server(SilcServerEntry server_entry);
854
855 /****f* silcclient/SilcClientAPI/silc_client_ref_server
856  *
857  * SYNOPSIS
858  *
859  *    SilcServerEntry
860  *    silc_client_ref_server(SilcClient client,
861  *                           SilcClientConnection conn,
862  *                           SilcServerEntry server_entry);
863  *
864  * DESCRIPTION
865  *
866  *    Takes a reference of the server entry indicated by `server_entry'
867  *    The reference must be released by calling silc_client_unref_server
868  *    after it is not needed anymore.  Returns `server_entry'.
869  *
870  ***/
871 SilcServerEntry silc_client_ref_server(SilcClient client,
872                                        SilcClientConnection conn,
873                                        SilcServerEntry server_entry);
874
875 /****f* silcclient/SilcClientAPI/silc_client_unref_server
876  *
877  * SYNOPSIS
878  *
879  *    void silc_client_unref_server(SilcClient client,
880  *                                  SilcClientConnection conn,
881  *                                  SilcServerEntry server_entry);
882  *
883  * DESCRIPTION
884  *
885  *    Releases the server entry reference indicated by `server_entry'.
886  *
887  ***/
888 void silc_client_unref_server(SilcClient client, SilcClientConnection conn,
889                               SilcServerEntry server_entry);
890
891 /****f* silcclient/SilcClientAPI/silc_client_list_free_server
892  *
893  * SYNOPSIS
894  *
895  *    void silc_client_list_free_server(SilcClient client,
896  *                                      SilcClientConnection conn,
897  *                                      SilcDList server_list);
898  *
899  * DESCRIPTION
900  *
901  *    Free's server entry list that has been returned by various library
902  *    routines.
903  *
904  ***/
905 void silc_client_list_free_servers(SilcClient client,
906                                    SilcClientConnection conn,
907                                    SilcDList server_list);
908
909 /****f* silcclient/SilcClientAPI/silc_client_get_server
910  *
911  * SYNOPSIS
912  *
913  *    SilcServerEntry silc_client_get_server(SilcClient client,
914  *                                           SilcClientConnection conn,
915  *                                           char *server_name)
916  *
917  * DESCRIPTION
918  *
919  *    Finds entry for server by the server name. Returns the entry or NULL
920  *    if the entry was not found.
921  *
922  ***/
923 SilcServerEntry silc_client_get_server(SilcClient client,
924                                        SilcClientConnection conn,
925                                        char *server_name);
926
927 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
928  *
929  * SYNOPSIS
930  *
931  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
932  *                                                 SilcClientConnection conn,
933  *                                                 SilcServerID *server_id);
934  *
935  * DESCRIPTION
936  *
937  *    Finds entry for server by the server ID. Returns the entry or NULL
938  *    if the entry was not found.
939  *
940  ***/
941 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
942                                              SilcClientConnection conn,
943                                              SilcServerID *server_id);
944
945 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id_resolve
946  *
947  * SYNOPSIS
948  *
949  *    SilcUInt16
950  *    silc_client_get_server_by_id_resolve(SilcClient client,
951  *                                         SilcClientConnection conn,
952  *                                         SilcServerID *server_id,
953  *                                         SilcGetServerCallback completion,
954  *                                         void *context);
955  *
956  * DESCRIPTION
957  *
958  *    Resolves the server information by the `server_id'.  The resolved
959  *    server is returned into the `completion' callback.
960  *
961  *    Returns command identifier for the resolving.  It can be used to attach
962  *    a pending command to it, if needed.  Returns 0 on error.
963  *
964  ***/
965 SilcUInt16
966 silc_client_get_server_by_id_resolve(SilcClient client,
967                                      SilcClientConnection conn,
968                                      SilcServerID *server_id,
969                                      SilcGetServerCallback completion,
970                                      void *context);
971
972 #endif /* SILCCLIENT_ENTRY_H */