Added silc_server_remove_servers_by_server to remove servers
[silc.git] / apps / silcd / server_util.h
1 /*
2
3   server_util.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2002 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SERVER_UTIL_H
21 #define SERVER_UTIL_H
22
23 /* This function removes all client entries that are originated from
24    `router' and are owned by `entry'.  `router' and `entry' can be same
25    too.  If `server_signoff' is TRUE then SERVER_SIGNOFF notify is 
26    distributed to our local clients. */
27 bool silc_server_remove_clients_by_server(SilcServer server,
28                                           SilcServerEntry router,
29                                           SilcServerEntry entry,
30                                           bool server_signoff);
31
32 /* Updates the clients that are originated from the `from' to be originated
33    from the `to'. If the `resolve_real_server' is TRUE then this will
34    attempt to figure out which clients really are originated from the
35    `from' and which are originated from a server that we have connection
36    to, when we've acting as backup router. If it is FALSE the `to' will
37    be the new source. This function also removes the clients that are
38    *really* originated from `from' if `remove_from' is TRUE. These are
39    clients that the `from' owns, and not just clients that are behind
40    the `from'. If `from' is NULL then all non-local clients are switched
41    to `to'. */
42 void silc_server_update_clients_by_server(SilcServer server, 
43                                           SilcServerEntry from,
44                                           SilcServerEntry to,
45                                           bool resolve_real_server,
46                                           bool remove_from);
47
48 /* Updates servers that are from `from' to be originated from `to'.  This
49    will also update the server's connection to `to's connection. */
50 void silc_server_update_servers_by_server(SilcServer server,
51                                           SilcServerEntry from,
52                                           SilcServerEntry to);
53
54 /* Toggles the enabled/disabled status of local server connections.  Packets
55    can be sent to the servers when `toggle_enabled' is TRUE and will be
56    dropped if `toggle_enabled' is FALSE, after this function is called. */
57 void silc_server_local_servers_toggle_enabled(SilcServer server,
58                                               bool toggle_enabled);
59
60 /* Removes servers that are originated from the `from'.  The server
61    entry is deleted in this function.  If `remove_clients' is TRUE then
62    all clients originated from the server are removed too, and server
63    signoff is sent.  Note that this does not remove the `from'.  This
64    also does not remove locally connected servers. */
65 void silc_server_remove_servers_by_server(SilcServer server,
66                                           SilcServerEntry from,
67                                           bool remove_clients);
68
69 /* Removes channels that are from `from. */
70 void silc_server_remove_channels_by_server(SilcServer server, 
71                                            SilcServerEntry from);
72
73 /* Updates channels that are from `from' to be originated from `to'.  */
74 void silc_server_update_channels_by_server(SilcServer server, 
75                                            SilcServerEntry from,
76                                            SilcServerEntry to);
77
78 /* Checks whether given channel has global users.  If it does this returns
79    TRUE and FALSE if there is only locally connected clients on the channel. */
80 bool silc_server_channel_has_global(SilcChannelEntry channel);
81
82 /* Checks whether given channel has locally connected users.  If it does this
83    returns TRUE and FALSE if there is not one locally connected client. */
84 bool silc_server_channel_has_local(SilcChannelEntry channel);
85
86 /* This function removes the channel and all users on the channel, unless
87    the channel is permanent.  In this case the channel is disabled but all
88    users are removed from the channel.  Returns TRUE if the channel is
89    destroyed totally, and FALSE if it is permanent and remains. */
90 bool silc_server_channel_delete(SilcServer server,
91                                 SilcChannelEntry channel);
92
93 /* Returns TRUE if the given client is on the channel.  FALSE if not. 
94    This works because we assure that the user list on the channel is
95    always in up to date thus we can only check the channel list from 
96    `client' which is faster than checking the user list from `channel'. */
97 bool silc_server_client_on_channel(SilcClientEntry client,
98                                    SilcChannelEntry channel,
99                                    SilcChannelClientEntry *chl);
100
101 /* Checks string for bad characters and returns TRUE if they are found. */
102 bool silc_server_name_bad_chars(const char *name, SilcUInt32 name_len);
103
104 /* Modifies the `nick' if it includes bad characters and returns new
105    allocated nickname that does not include bad characters. */
106 char *silc_server_name_modify_bad(const char *name, SilcUInt32 name_len);
107
108 /* Find number of sockets by IP address indicated by `ip'. Returns 0 if
109    socket connections with the IP address does not exist. */
110 SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip,
111                                          SilcSocketType type);
112
113 /* Find number of sockets by IP address indicated by remote host, indicated
114    by `ip' or `hostname', `port', and `type'.  Returns 0 if socket connections
115    does not exist. If `ip' is provided then `hostname' is ignored. */
116 SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server, 
117                                              const char *ip,
118                                              const char *hostname,
119                                              SilcUInt16 port,
120                                              SilcSocketType type);
121
122 /* Finds locally cached public key by the public key received in the SKE. 
123    If we have it locally cached then we trust it and will use it in the
124    authentication protocol.  Returns the locally cached public key or NULL
125    if we do not find the public key.  */
126 SilcPublicKey silc_server_find_public_key(SilcServer server, 
127                                           SilcHashTable local_public_keys,
128                                           SilcPublicKey remote_public_key);
129
130 /* This returns the first public key from the table of public keys.  This
131    is used only in cases where single public key exists in the table and
132    we want to get a pointer to it.  For public key tables that has multiple
133    keys in it the silc_server_find_public_key must be used. */
134 SilcPublicKey silc_server_get_public_key(SilcServer server,
135                                          SilcHashTable local_public_keys);
136
137 /* Check whether the connection `sock' is allowed to connect to us.  This
138    checks for example whether there is too much connections for this host,
139    and required version for the host etc. */
140 bool silc_server_connection_allowed(SilcServer server, 
141                                     SilcSocketConnection sock,
142                                     SilcSocketType type,
143                                     SilcServerConfigConnParams *global,
144                                     SilcServerConfigConnParams *params,
145                                     SilcSKE ske);
146
147 /* Checks that client has rights to add or remove channel modes. If any
148    of the checks fails FALSE is returned. */
149 bool silc_server_check_cmode_rights(SilcServer server,
150                                     SilcChannelEntry channel,
151                                     SilcChannelClientEntry client,
152                                     SilcUInt32 mode);
153
154 /* Check that the client has rights to change its user mode.  Returns
155    FALSE if setting some mode is not allowed. */
156 bool silc_server_check_umode_rights(SilcServer server,
157                                     SilcClientEntry client,
158                                     SilcUInt32 mode);
159
160 /* This function is used to send the notify packets and motd to the
161    incoming client connection. */
162 void silc_server_send_connect_notifys(SilcServer server,
163                                       SilcSocketConnection sock,
164                                       SilcClientEntry client);
165
166 /* Kill the client indicated by `remote_client' sending KILLED notify
167    to the client, to all channels client has joined and to primary
168    router if needed.  The killed client is also removed from all channels. */
169 void silc_server_kill_client(SilcServer server,
170                              SilcClientEntry remote_client,
171                              const char *comment,
172                              void *killer_id,
173                              SilcIdType killer_id_type);
174
175 /* This function checks whether the `client' nickname is being watched
176    by someone, and notifies the watcher of the notify change of notify
177    type indicated by `notify'. */
178 bool silc_server_check_watcher_list(SilcServer server,
179                                     SilcClientEntry client,
180                                     const char *new_nick,
181                                     SilcNotifyType notify);
182
183 /* Remove the `client' from watcher list. After calling this the `client'
184    is not watching any nicknames. */
185 bool silc_server_del_from_watcher_list(SilcServer server,
186                                        SilcClientEntry client);
187
188 /* Force the client indicated by `chl' to change the channel user mode
189    on channel indicated by `channel' to `forced_mode'. */
190 bool silc_server_force_cumode_change(SilcServer server,
191                                      SilcSocketConnection sock,
192                                      SilcChannelEntry channel,
193                                      SilcChannelClientEntry chl,
194                                      SilcUInt32 forced_mode);
195
196 /* Find active socket connection by the IP address and port indicated by
197    `ip' and `port', and socket connection type of `type'. */
198 SilcSocketConnection
199 silc_server_find_socket_by_host(SilcServer server,
200                                 SilcSocketType type,
201                                 const char *ip, SilcUInt16 port);
202
203 #endif /* SERVER_UTIL_H */