5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
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.
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.
23 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
24 * Importet from internal CVS/Added Log headers.
29 #include "serverincludes.h"
32 /* Adds a new server to the list. The pointer sent as argument is allocated
35 void silc_idlist_add_server(SilcServerList **list,
36 char *server_name, int server_type,
37 SilcServerID *id, SilcServerList *router,
38 SilcCipher send_key, SilcCipher receive_key,
39 SilcPKCS public_key, SilcHmac hmac,
40 SilcServerList **new_idlist)
42 SilcServerList *last, *idlist;
44 SILC_LOG_DEBUG(("Adding new server to id list"));
46 idlist = silc_calloc(1, sizeof(*idlist));
48 SILC_LOG_ERROR(("Could not allocate new server list object"));
53 /* Set the pointers */
54 idlist->server_name = server_name;
55 idlist->server_type = server_type;
57 idlist->router = router;
58 idlist->send_key = send_key;
59 idlist->receive_key = receive_key;
60 idlist->public_key = public_key;
62 idlist->next = idlist;
63 idlist->prev = idlist;
65 /* First on the list? */
72 /* Add it to the list */
75 (*list)->prev = idlist;
76 idlist->next = (*list);
83 /* Adds a new client to the client list. This is called when new client
84 connection is accepted to the server. This adds all the relevant data
85 about the client and session with it to the list. This list is
86 referenced for example when sending message to the client. */
88 void silc_idlist_add_client(SilcClientList **list, char *nickname,
89 char *username, char *userinfo,
90 SilcClientID *id, SilcServerList *router,
91 SilcCipher send_key, SilcCipher receive_key,
92 SilcPKCS public_key, SilcHmac hmac,
93 SilcClientList **new_idlist)
95 SilcClientList *last, *idlist;
97 SILC_LOG_DEBUG(("Adding new client to id list"));
99 idlist = silc_calloc(1, sizeof(*idlist));
100 if (idlist == NULL) {
101 SILC_LOG_ERROR(("Could not allocate new client list object"));
105 /* Set the pointers */
106 idlist->nickname = nickname;
107 idlist->username = username;
108 idlist->userinfo = userinfo;
110 idlist->router = router;
111 idlist->send_key = send_key;
112 idlist->receive_key = receive_key;
113 idlist->public_key = public_key;
115 idlist->next = idlist;
116 idlist->prev = idlist;
118 /* First on the list? */
122 *new_idlist = idlist;
126 /* Add it to the list */
127 last = (*list)->prev;
129 (*list)->prev = idlist;
130 idlist->next = *list;
134 *new_idlist = idlist;
137 /* Free client entry. This free's everything. */
139 void silc_idlist_del_client(SilcClientList **list, SilcClientList *entry)
143 silc_free(entry->nickname);
145 silc_free(entry->username);
147 silc_free(entry->userinfo);
149 silc_free(entry->id);
151 silc_cipher_free(entry->send_key);
152 if (entry->receive_key)
153 silc_cipher_free(entry->receive_key);
154 if (entry->public_key)
155 silc_pkcs_free(entry->public_key);
157 silc_hmac_free(entry->hmac);
158 if (entry->hmac_key) {
159 memset(entry->hmac_key, 0, entry->hmac_key_len);
160 silc_free(entry->hmac_key);
163 /* Last one in list? */
164 if (*list == entry && entry->next == entry) {
170 /* At the start of list? */
171 if (*list == entry && entry->next != entry) {
173 entry->next->prev = entry->prev;
174 entry->prev->next = *list;
179 /* Remove from list */
180 entry->prev->next = entry->next;
181 entry->next->prev = entry->prev;
188 silc_idlist_find_client_by_nickname(SilcClientList *list,
192 SilcClientList *first, *entry;
194 SILC_LOG_DEBUG(("Finding client by nickname"));
199 first = entry = list;
200 if (!strcmp(entry->nickname, nickname)) {
201 SILC_LOG_DEBUG(("Found"));
206 while(entry != first) {
207 if (!strcmp(entry->nickname, nickname)) {
208 SILC_LOG_DEBUG(("Found"));
219 silc_idlist_find_client_by_hash(SilcClientList *list,
220 char *nickname, SilcHash md5hash)
222 SilcClientList *first, *entry;
223 unsigned char hash[16];
225 SILC_LOG_DEBUG(("Finding client by nickname hash"));
230 /* Make hash of the nickname */
231 silc_hash_make(md5hash, nickname, strlen(nickname), hash);
233 first = entry = list;
234 if (entry && !SILC_ID_COMPARE_HASH(entry->id, hash)) {
235 SILC_LOG_DEBUG(("Found"));
240 while(entry != first) {
241 if (entry && !SILC_ID_COMPARE_HASH(entry->id, hash)) {
242 SILC_LOG_DEBUG(("Found"));
253 silc_idlist_find_client_by_id(SilcClientList *list, SilcClientID *id)
255 SilcClientList *first, *entry;
257 SILC_LOG_DEBUG(("Finding client by Client ID"));
262 first = entry = list;
263 if (entry && !SILC_ID_CLIENT_COMPARE(entry->id, id)) {
264 SILC_LOG_DEBUG(("Found"));
269 while(entry != first) {
270 if (entry && !SILC_ID_CLIENT_COMPARE(entry->id, id)) {
271 SILC_LOG_DEBUG(("Found"));
281 /* Adds new channel to the list. */
283 void silc_idlist_add_channel(SilcChannelList **list,
284 char *channel_name, int mode,
285 SilcChannelID *id, SilcServerList *router,
286 SilcCipher channel_key,
287 SilcChannelList **new_idlist)
289 SilcChannelList *last, *idlist;
291 SILC_LOG_DEBUG(("Adding new channel to id list"));
293 idlist = silc_calloc(1, sizeof(*idlist));
294 if (idlist == NULL) {
295 SILC_LOG_ERROR(("Could not allocate new channel list object"));
299 /* Set the pointers */
300 idlist->channel_name = channel_name;
303 idlist->router = router;
304 idlist->channel_key = channel_key;
305 idlist->next = idlist;
306 idlist->prev = idlist;
308 /* First on the list? */
312 *new_idlist = idlist;
316 /* Add it to the list */
317 last = (*list)->prev;
319 (*list)->prev = idlist;
320 idlist->next = (*list);
324 *new_idlist = idlist;
328 silc_idlist_find_channel_by_id(SilcChannelList *list, SilcChannelID *id)
330 SilcChannelList *first, *entry;
332 SILC_LOG_DEBUG(("Finding channel by Channel ID"));
337 first = entry = list;
338 if (entry && !SILC_ID_CHANNEL_COMPARE(entry->id, id)) {
339 SILC_LOG_DEBUG(("Found"));
344 while(entry != first) {
345 if (entry && !SILC_ID_CHANNEL_COMPARE(entry->id, id)) {
346 SILC_LOG_DEBUG(("Found"));
356 /* Free channel entry. This free's everything. */
358 void silc_idlist_del_channel(SilcChannelList **list, SilcChannelList *entry)
361 if (entry->channel_name)
362 silc_free(entry->channel_name);
364 silc_free(entry->id);
366 silc_free(entry->topic);
367 if (entry->channel_key)
368 silc_cipher_free(entry->channel_key);
370 memset(entry->key, 0, entry->key_len);
371 silc_free(entry->key);
373 memset(entry->iv, 0, sizeof(entry->iv));
375 if (entry->user_list_count)
376 silc_free(entry->user_list);
378 /* Last one in list? */
379 if (*list == entry && entry->next == entry) {
385 /* At the start of list? */
386 if (*list == entry && entry->next != entry) {
388 entry->next->prev = entry->prev;
389 entry->prev->next = *list;
394 /* Remove from list */
395 entry->prev->next = entry->next;
396 entry->next->prev = entry->prev;