X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcd%2Fserver_util.c;h=8184b2e728162d45bb95597144b88a3c93516830;hb=3b3c092203bf23dfe665739a9916d43415bab056;hp=30c9e157eebaebd1015ec5847fb24b8d2b825213;hpb=afb45ac59c311422e6724e31be2013e46cee908a;p=silc.git diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index 30c9e157..8184b2e7 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -62,9 +62,10 @@ static void silc_server_remove_clients_channels(SilcServer server, if (channel->rekey) silc_schedule_task_del_by_context(server->schedule, channel->rekey); - if (!silc_idlist_del_channel(server->local_list, channel)) - silc_idlist_del_channel(server->global_list, channel); - server->stat.my_channels--; + if (silc_idlist_del_channel(server->local_list, channel)) + server->stat.my_channels--; + else if (silc_idlist_del_channel(server->global_list, channel)) + server->stat.my_channels--; continue; } @@ -108,9 +109,10 @@ static void silc_server_remove_clients_channels(SilcServer server, } /* Remove the channel entry */ - if (!silc_idlist_del_channel(server->local_list, channel)) - silc_idlist_del_channel(server->global_list, channel); - server->stat.my_channels--; + if (silc_idlist_del_channel(server->local_list, channel)) + server->stat.my_channels--; + else if (silc_idlist_del_channel(server->global_list, channel)) + server->stat.my_channels--; continue; } @@ -437,11 +439,12 @@ void silc_server_update_clients_by_server(SilcServer server, SILC_ID_SERVER))); - local = TRUE; - if (silc_idcache_get_all(server->local_list->clients, &list)) { + local = FALSE; + if (silc_idcache_get_all(server->global_list->clients, &list)) { if (silc_idcache_list_first(list, &id_cache)) { while (id_cache) { client = (SilcClientEntry)id_cache->context; + if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) { if (!silc_idcache_list_next(list, &id_cache)) @@ -450,8 +453,11 @@ void silc_server_update_clients_by_server(SilcServer server, continue; } - SILC_LOG_DEBUG(("Client (local) %s", + SILC_LOG_DEBUG(("Client (global) %s", silc_id_render(client->id, SILC_ID_CLIENT))); + if (client->router) + SILC_LOG_DEBUG(("Client->router (global) %s", + silc_id_render(client->router->id, SILC_ID_SERVER))); if (client->router == from) { /* Skip clients that are *really* owned by the `from' */ @@ -469,7 +475,7 @@ void silc_server_update_clients_by_server(SilcServer server, silc_server_update_clients_by_real_server(server, from, client, local, id_cache); if (!client->router) - client->router = from; /* on local list put old from */ + client->router = to; } else { client->router = to; } @@ -482,12 +488,11 @@ void silc_server_update_clients_by_server(SilcServer server, silc_idcache_list_free(list); } - local = FALSE; - if (silc_idcache_get_all(server->global_list->clients, &list)) { + local = TRUE; + if (silc_idcache_get_all(server->local_list->clients, &list)) { if (silc_idcache_list_first(list, &id_cache)) { while (id_cache) { client = (SilcClientEntry)id_cache->context; - if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) { if (!silc_idcache_list_next(list, &id_cache)) @@ -496,8 +501,11 @@ void silc_server_update_clients_by_server(SilcServer server, continue; } - SILC_LOG_DEBUG(("Client (global) %s", + SILC_LOG_DEBUG(("Client (local) %s", silc_id_render(client->id, SILC_ID_CLIENT))); + if (client->router) + SILC_LOG_DEBUG(("Client->router (local) %s", + silc_id_render(client->router->id, SILC_ID_SERVER))); if (client->router == from) { /* Skip clients that are *really* owned by the `from' */ @@ -515,7 +523,7 @@ void silc_server_update_clients_by_server(SilcServer server, silc_server_update_clients_by_real_server(server, from, client, local, id_cache); if (!client->router) - client->router = to; + client->router = from; /* on local list put old from */ } else { client->router = to; } @@ -535,6 +543,50 @@ void silc_server_update_clients_by_server(SilcServer server, silc_server_remove_clients_by_server(server, from, TRUE); } +/* Updates servers that are from `from' to be originated from `to'. This + will also update the server's connection to `to's connection. */ + +void silc_server_update_servers_by_server(SilcServer server, + SilcServerEntry from, + SilcServerEntry to) +{ + SilcIDCacheList list = NULL; + SilcIDCacheEntry id_cache = NULL; + SilcServerEntry server_entry = NULL; + + SILC_LOG_DEBUG(("Start")); + + if (silc_idcache_get_all(server->local_list->servers, &list)) { + if (silc_idcache_list_first(list, &id_cache)) { + while (id_cache) { + server_entry = (SilcServerEntry)id_cache->context; + if (server_entry->router == from) { + server_entry->router = to; + server_entry->connection = to->connection; + } + if (!silc_idcache_list_next(list, &id_cache)) + break; + } + } + silc_idcache_list_free(list); + } + + if (silc_idcache_get_all(server->global_list->servers, &list)) { + if (silc_idcache_list_first(list, &id_cache)) { + while (id_cache) { + server_entry = (SilcServerEntry)id_cache->context; + if (server_entry->router == from) { + server_entry->router = to; + server_entry->connection = to->connection; + } + if (!silc_idcache_list_next(list, &id_cache)) + break; + } + } + silc_idcache_list_free(list); + } +} + /* Checks whether given channel has global users. If it does this returns TRUE and FALSE if there is only locally connected clients on the channel. */