Added Requested Attributes sending and receiving support to
[silc.git] / lib / silcclient / idlist.h
1 /*
2
3   idlist.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 - 2002 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 #ifndef IDLIST_H
21 #define IDLIST_H
22
23 /* Client entry status */
24 typedef enum {
25   SILC_CLIENT_STATUS_NONE       = 0x0000,
26   SILC_CLIENT_STATUS_RESOLVING  = 0x0001,
27 } SilcEntryStatus;
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 struct SilcClientEntryStruct {
34   char *nickname;               /* nickname */
35   char *username;               /* username */
36   char *hostname;               /* hostname */
37   char *server;                 /* SILC server name */
38   char *realname;               /* Realname (userinfo) */
39   SilcUInt32 mode;              /* User mode in SILC */
40   SilcClientID *id;             /* The Client ID */
41   unsigned char *fingerprint;   /* Fingerprint of client's public key */
42   SilcUInt32 fingerprint_len;   /* Length of the fingerprint */
43   SilcCipher send_key;          /* Private message key for sending */
44   SilcCipher receive_key;       /* Private message key for receiving */
45   SilcClientKeyAgreement ke;    /* Current key agreement context or NULL */
46   SilcDList attrs;              /* Requested Attributes (maybe NULL) */
47   SilcEntryStatus status;       /* Status mask */
48   SilcHashTable channels;       /* All channels client has joined */
49   unsigned char *key;           /* Set only if appliation provided the
50                                    key material. NULL if the library 
51                                    generated the key. */
52   SilcUInt32 key_len;           /* Key length */
53   SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
54   bool generated;               /* TRUE if library generated `key' */
55   bool valid;                   /* FALSE if this entry is not valid */
56 };
57
58 /* Client and its mode on a channel */
59 struct SilcChannelUserStruct {
60   SilcClientEntry client;
61   SilcUInt32 mode;
62   SilcChannelEntry channel;
63 };
64
65 /* Channel entry context. This is allocate for every channel client has
66    joined to. This includes for example the channel specific keys */
67 struct SilcChannelEntryStruct {
68   char *channel_name;
69   SilcChannelID *id;
70   SilcUInt32 mode;
71   SilcUInt16 resolve_cmd_ident;
72
73   /* All clients that has joined this channel */
74   SilcHashTable user_list;
75
76   /* Channel keys */
77   SilcCipher channel_key;                    /* The channel key */
78   unsigned char *key;                        /* Raw key data */
79   SilcUInt32 key_len;                        /* Raw key data length */
80   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
81   SilcHmac hmac;                             /* Current HMAC */
82   SilcDList private_keys;                    /* List of private keys or NULL */
83   SilcChannelPrivateKey curr_key;            /* Current private key */
84
85   /* Old channel key is saved for a short period of time when rekey occurs
86      in case if someone is sending messages after the rekey encrypted with
87      the old key, we can still decrypt them. */
88   SilcCipher old_channel_key;
89   SilcHmac old_hmac;
90   SilcTask rekey_task;
91 };
92
93 /* Server entry context. This represents one server. When server information
94    is resolved with INFO command the server info is saved in this context. 
95    Also the connected servers are saved here. */
96 struct SilcServerEntryStruct {
97   char *server_name;
98   char *server_info;
99   SilcServerID *server_id;
100   SilcUInt16 resolve_cmd_ident;
101 };
102
103 /* Prototypes. These are used only by the library. Application should not
104    call these directly. */
105
106 SilcClientEntry
107 silc_client_add_client(SilcClient client, SilcClientConnection conn,
108                        char *nickname, char *username, 
109                        char *userinfo, SilcClientID *id, SilcUInt32 mode);
110 void silc_client_update_client(SilcClient client,
111                                SilcClientConnection conn,
112                                SilcClientEntry client_entry,
113                                const char *nickname,
114                                const char *username,
115                                const char *userinfo,
116                                SilcUInt32 mode);
117 void silc_client_del_client_entry(SilcClient client, 
118                                   SilcClientConnection conn,
119                                   SilcClientEntry client_entry);
120 SilcClientEntry silc_idlist_get_client(SilcClient client,
121                                        SilcClientConnection conn,
122                                        const char *nickname,
123                                        const char *format,
124                                        bool query);
125 SilcChannelEntry silc_client_add_channel(SilcClient client,
126                                          SilcClientConnection conn,
127                                          const char *channel_name,
128                                          SilcUInt32 mode, 
129                                          SilcChannelID *channel_id);
130 SilcServerEntry silc_client_add_server(SilcClient client,
131                                        SilcClientConnection conn,
132                                        const char *server_name,
133                                        const char *server_info,
134                                        SilcServerID *server_id);
135 void silc_client_update_server(SilcClient client,
136                                SilcClientConnection conn,
137                                SilcServerEntry server_entry,
138                                const char *server_name,
139                                const char *server_info);
140 bool silc_client_replace_channel_id(SilcClient client,
141                                     SilcClientConnection conn,
142                                     SilcChannelEntry channel,
143                                     SilcChannelID *new_id);
144 void silc_client_nickname_format(SilcClient client, 
145                                  SilcClientConnection conn,
146                                  SilcClientEntry client_entry);
147
148 #endif