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