updates.
[silc.git] / apps / silcd / server_util.c
index d0488095ef5bc64af9752cb4895796b5dedfe707..c41c8bcfe54f16adf2d894d5f279d2eec677ced0 100644 (file)
@@ -212,8 +212,12 @@ bool silc_server_remove_clients_by_server(SilcServer server,
 
        /* Remove the client entry */
        silc_server_remove_clients_channels(server, NULL, client, channels);
-       client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
-       id_cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
+       if (!server_signoff) {
+         client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
+         id_cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
+       } else {
+         silc_idlist_del_client(server->local_list, client);
+       }
        server->stat.clients--;
        if (server->server_type == SILC_ROUTER)
          server->stat.cell_clients--;
@@ -268,8 +272,12 @@ bool silc_server_remove_clients_by_server(SilcServer server,
 
        /* Remove the client entry */
        silc_server_remove_clients_channels(server, NULL, client, channels);
-       client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
-       id_cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
+       if (!server_signoff) {
+         client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
+         id_cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
+       } else {
+         silc_idlist_del_client(server->global_list, client);
+       }
        server->stat.clients--;
        if (server->server_type == SILC_ROUTER)
          server->stat.cell_clients--;
@@ -371,7 +379,7 @@ silc_server_update_clients_by_real_server(SilcServer server,
            SILC_LOG_DEBUG(("Moving client to local list"));
            silc_idcache_add(server->local_list->clients, client_cache->name,
                             client_cache->id, client_cache->context,
-                            client_cache->expire);
+                            client_cache->expire, NULL);
            silc_idcache_del_by_context(server->global_list->clients, client);
          }
          server_entry = server_entry->router;
@@ -382,7 +390,7 @@ silc_server_update_clients_by_real_server(SilcServer server,
            SILC_LOG_DEBUG(("Moving client to local list"));
            silc_idcache_add(server->local_list->clients, client_cache->name,
                             client_cache->id, client_cache->context,
-                            client_cache->expire);
+                            client_cache->expire, NULL);
            silc_idcache_del_by_context(server->global_list->clients, client);
          }
        }
@@ -418,7 +426,7 @@ silc_server_update_clients_by_real_server(SilcServer server,
            SILC_LOG_DEBUG(("Moving client to global list"));
            silc_idcache_add(server->global_list->clients, client_cache->name,
                             client_cache->id, client_cache->context,
-                            client_cache->expire);
+                            client_cache->expire, NULL);
            silc_idcache_del_by_context(server->local_list->clients, client);
          }
          server_entry = server_entry->router;
@@ -429,7 +437,7 @@ silc_server_update_clients_by_real_server(SilcServer server,
            SILC_LOG_DEBUG(("Moving client to global list"));
            silc_idcache_add(server->global_list->clients, client_cache->name,
                             client_cache->id, client_cache->context,
-                            client_cache->expire);
+                            client_cache->expire, NULL);
            silc_idcache_del_by_context(server->local_list->clients, client);
          }
        }
@@ -622,6 +630,57 @@ void silc_server_update_servers_by_server(SilcServer server,
   }
 }
 
+/* Removes channels that are from `from. */
+
+void silc_server_remove_channels_by_server(SilcServer server, 
+                                          SilcServerEntry from)
+{
+  SilcIDCacheList list = NULL;
+  SilcIDCacheEntry id_cache = NULL;
+  SilcChannelEntry channel = NULL;
+
+  SILC_LOG_DEBUG(("Start"));
+
+  if (silc_idcache_get_all(server->global_list->channels, &list)) {
+    if (silc_idcache_list_first(list, &id_cache)) {
+      while (id_cache) {
+       channel = (SilcChannelEntry)id_cache->context;
+       if (channel->router == from)
+         silc_idlist_del_channel(server->global_list, channel);
+       if (!silc_idcache_list_next(list, &id_cache))
+         break;
+      }
+    }
+    silc_idcache_list_free(list);
+  }
+}
+
+/* Updates channels that are from `from' to be originated from `to'.  */
+
+void silc_server_update_channels_by_server(SilcServer server, 
+                                          SilcServerEntry from,
+                                          SilcServerEntry to)
+{
+  SilcIDCacheList list = NULL;
+  SilcIDCacheEntry id_cache = NULL;
+  SilcChannelEntry channel = NULL;
+
+  SILC_LOG_DEBUG(("Start"));
+
+  if (silc_idcache_get_all(server->global_list->channels, &list)) {
+    if (silc_idcache_list_first(list, &id_cache)) {
+      while (id_cache) {
+       channel = (SilcChannelEntry)id_cache->context;
+       if (channel->router == from)
+         channel->router = to;
+       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. */
 
@@ -672,3 +731,42 @@ bool silc_server_client_on_channel(SilcClientEntry client,
 
   return FALSE;
 }
+
+/* Checks string for bad characters and returns TRUE if they are found. */
+
+bool silc_server_name_bad_chars(const char *name, uint32 name_len)
+{
+  int i;
+
+  for (i = 0; i < name_len; i++) {
+    if (!isascii(name[i]))
+      return TRUE;
+    if (name[i] <= 32) return TRUE;
+    if (name[i] == ' ') return TRUE;
+    if (name[i] == '*') return TRUE;
+    if (name[i] == '?') return TRUE;
+    if (name[i] == ',') return TRUE;
+  }
+
+  return FALSE;
+}
+
+/* Modifies the `name' if it includes bad characters and returns new
+   allocated name that does not include bad characters. */
+
+char *silc_server_name_modify_bad(const char *name, uint32 name_len)
+{
+  int i;
+  char *newname = strdup(name);
+
+  for (i = 0; i < name_len; i++) {
+    if (!isascii(newname[i])) newname[i] = '_';
+    if (newname[i] <= 32) newname[i] = '_';
+    if (newname[i] == ' ') newname[i] = '_';
+    if (newname[i] == '*') newname[i] = '_';
+    if (newname[i] == '?') newname[i] = '_';
+    if (newname[i] == ',') newname[i] = '_';
+  }
+
+  return newname;
+}