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