cd4de48926b603611613715a82f3627a8fac912e
[silc.git] / lib / silcclient / idlist.h
1 /*
2
3   idlist.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2001 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; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef IDLIST_H
22 #define IDLIST_H
23
24 typedef enum {
25   SILC_CLIENT_STATUS_NONE       = 0x0000,
26   SILC_CLIENT_STATUS_RESOLVING  = 0x0001,
27 } SilcClientStatus;
28
29 /* Client entry context. When client receives information about new client
30    (it receives its ID, for example, by IDENTIFY request) we create new
31    client entry. This entry also includes the private message keys if
32    they are used. */
33 typedef struct {
34   char *nickname;               /* nickname */
35   char *username;               /* username */
36   char *hostname;               /* hostname */
37   char *server;                 /* SILC server name */
38   char *realname;               /* Realname (userinfo) */
39   uint32 num;
40   uint32 mode;                  /* User mode in SILC */
41   SilcClientID *id;             /* The Client ID */
42   bool valid;                   /* FALSE if this entry is not valid */
43   SilcCipher send_key;          /* Private message key for sending */
44   SilcCipher receive_key;       /* Private message key for receiving */
45   unsigned char *key;           /* Set only if appliation provided the
46                                    key material. NULL if the library 
47                                    generated the key. */
48   uint32 key_len;
49   bool generated;               /* TRUE if library generated the key */
50   SilcClientKeyAgreement ke;    /* Current key agreement context or NULL */
51   SilcClientStatus status;      /* Status mask */
52 } *SilcClientEntry;
53
54 /* Client and its mode on a channel */
55 typedef struct SilcChannelUserStruct {
56   SilcClientEntry client;
57   uint32 mode;
58   struct SilcChannelUserStruct *next;
59 } *SilcChannelUser;
60
61 /* Structure to hold one channel private key. */
62 typedef struct {
63   SilcCipher cipher;                  /* The cipher and key */
64   SilcHmac hmac;                      /* The HMAC and hmac key */
65   unsigned char *key;                 /* The key data */
66   uint32 key_len;                     /* The key length */
67 } *SilcChannelPrivateKey;
68
69 /* Channel entry context. This is allocate for every channel client has
70    joined to. This includes for example the channel specific keys */
71 typedef struct SilcChannelEntryStruct {
72   char *channel_name;
73   SilcChannelID *id;
74   uint32 mode;
75   bool on_channel;
76
77   /* Joined clients */
78   SilcList clients;
79
80   /* Channel keys */
81   SilcCipher channel_key;                    /* The channel key */
82   unsigned char *key;                        /* Raw key data */
83   uint32 key_len;
84   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
85   SilcHmac hmac;                             /* Current HMAC */
86   SilcDList private_keys;                    /* List of private keys or NULL */
87   SilcChannelPrivateKey curr_key;            /* Current private key */
88
89   /* Old channel key is saved for a short period of time when rekey occurs
90      in case if someone is sending messages after the rekey encrypted with
91      the old key, we can still decrypt them. */
92   SilcCipher old_channel_key;
93   SilcHmac old_hmac;
94   SilcTask rekey_task;
95 } *SilcChannelEntry;
96
97 /* Server entry context. This represents one server. When server information
98    is resolved with INFO command the server info is saved in this context. 
99    Also the connected servers are saved here. */
100 typedef struct {
101   char *server_name;
102   char *server_info;
103   SilcServerID *server_id;
104 } *SilcServerEntry;
105
106 /* Prototypes. These are used only by the library. Application should not
107    call these directly. */
108
109 SilcClientEntry
110 silc_client_add_client(SilcClient client, SilcClientConnection conn,
111                        char *nickname, char *username, 
112                        char *userinfo, SilcClientID *id, uint32 mode);
113 void silc_client_update_client(SilcClient client,
114                                SilcClientConnection conn,
115                                SilcClientEntry client_entry,
116                                const char *nickname,
117                                const char *username,
118                                const char *userinfo,
119                                uint32 mode);
120 void silc_client_del_client_entry(SilcClient client, 
121                                   SilcClientEntry client_entry);
122 SilcClientEntry silc_idlist_get_client(SilcClient client,
123                                        SilcClientConnection conn,
124                                        const char *nickname,
125                                        const char *format,
126                                        bool query);
127 SilcChannelEntry silc_idlist_get_channel_by_id(SilcClient client,
128                                                SilcClientConnection conn,
129                                                SilcChannelID *channel_id,
130                                                int query);
131 void silc_client_nickname_format(SilcClient client, 
132                                  SilcClientConnection conn,
133                                  SilcClientEntry client_entry);
134
135 #endif