39b4f022d5a0b65d69e73d409d7764e465bef238
[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 } 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 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   bool valid;                   /* FALSE if this entry is not valid */
44   SilcCipher send_key;          /* Private message key for sending */
45   SilcCipher receive_key;       /* Private message key for receiving */
46   unsigned char *key;           /* Set only if appliation provided the
47                                    key material. NULL if the library 
48                                    generated the key. */
49   SilcUInt32 key_len;
50   bool generated;               /* TRUE if library generated the key */
51   SilcClientKeyAgreement ke;    /* Current key agreement context or NULL */
52   SilcClientStatus status;      /* Status mask */
53   SilcHashTable channels;       /* All channels client has joined */
54 };
55
56 /* Client and its mode on a channel */
57 struct SilcChannelUserStruct {
58   SilcClientEntry client;
59   SilcUInt32 mode;
60   SilcChannelEntry channel;
61 };
62
63 /* Channel entry context. This is allocate for every channel client has
64    joined to. This includes for example the channel specific keys */
65 struct SilcChannelEntryStruct {
66   char *channel_name;
67   SilcChannelID *id;
68   SilcUInt32 mode;
69
70   /* All clients that has joined this channel */
71   SilcHashTable user_list;
72
73   /* Channel keys */
74   SilcCipher channel_key;                    /* The channel key */
75   unsigned char *key;                        /* Raw key data */
76   SilcUInt32 key_len;
77   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
78   SilcHmac hmac;                             /* Current HMAC */
79   SilcDList private_keys;                    /* List of private keys or NULL */
80   SilcChannelPrivateKey curr_key;            /* Current private key */
81
82   /* Old channel key is saved for a short period of time when rekey occurs
83      in case if someone is sending messages after the rekey encrypted with
84      the old key, we can still decrypt them. */
85   SilcCipher old_channel_key;
86   SilcHmac old_hmac;
87   SilcTask rekey_task;
88 };
89
90 /* Server entry context. This represents one server. When server information
91    is resolved with INFO command the server info is saved in this context. 
92    Also the connected servers are saved here. */
93 struct SilcServerEntryStruct {
94   char *server_name;
95   char *server_info;
96   SilcServerID *server_id;
97 };
98
99 /* Prototypes. These are used only by the library. Application should not
100    call these directly. */
101
102 SilcClientEntry
103 silc_client_add_client(SilcClient client, SilcClientConnection conn,
104                        char *nickname, char *username, 
105                        char *userinfo, SilcClientID *id, SilcUInt32 mode);
106 void silc_client_update_client(SilcClient client,
107                                SilcClientConnection conn,
108                                SilcClientEntry client_entry,
109                                const char *nickname,
110                                const char *username,
111                                const char *userinfo,
112                                SilcUInt32 mode);
113 void silc_client_del_client_entry(SilcClient client, 
114                                   SilcClientConnection conn,
115                                   SilcClientEntry client_entry);
116 SilcClientEntry silc_idlist_get_client(SilcClient client,
117                                        SilcClientConnection conn,
118                                        const char *nickname,
119                                        const char *format,
120                                        bool query);
121 SilcChannelEntry silc_client_add_channel(SilcClient client,
122                                          SilcClientConnection conn,
123                                          const char *channel_name,
124                                          SilcUInt32 mode, 
125                                          SilcChannelID *channel_id);
126 SilcServerEntry silc_client_add_server(SilcClient client,
127                                        SilcClientConnection conn,
128                                        const char *server_name,
129                                        const char *server_info,
130                                        SilcServerID *server_id);
131 bool silc_client_replace_channel_id(SilcClient client,
132                                     SilcClientConnection conn,
133                                     SilcChannelEntry channel,
134                                     SilcChannelID *new_id);
135 void silc_client_nickname_format(SilcClient client, 
136                                  SilcClientConnection conn,
137                                  SilcClientEntry client_entry);
138
139 #endif