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