Added preliminary backup router support for standalone routers.
[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 is used to remove all client entries by the server `entry'.
24    This is called when the connection is lost to the server. In this case
25    we must invalidate all the client entries owned by the server `entry'. 
26    If the `server_signoff' is TRUE then the SERVER_SIGNOFF notify is
27    distributed to our local clients. */
28 bool silc_server_remove_clients_by_server(SilcServer server, 
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'. */
41 void silc_server_update_clients_by_server(SilcServer server, 
42                                           SilcServerEntry from,
43                                           SilcServerEntry to,
44                                           bool resolve_real_server,
45                                           bool remove_from);
46
47 /* Updates servers that are from `from' to be originated from `to'.  This
48    will also update the server's connection to `to's connection. If
49    `local_toggle_enabled' is TRUE then local server's connections are
50    enabled, if FALSE they are disabled. */
51 void silc_server_update_servers_by_server(SilcServer server, 
52                                           SilcServerEntry from,
53                                           SilcServerEntry to,
54                                           bool local_toggle_enabled);
55
56 /* Removes channels that are from `from. */
57 void silc_server_remove_channels_by_server(SilcServer server, 
58                                            SilcServerEntry from);
59
60 /* Updates channels that are from `from' to be originated from `to'.  */
61 void silc_server_update_channels_by_server(SilcServer server, 
62                                            SilcServerEntry from,
63                                            SilcServerEntry to);
64
65 /* Checks whether given channel has global users.  If it does this returns
66    TRUE and FALSE if there is only locally connected clients on the channel. */
67 bool silc_server_channel_has_global(SilcChannelEntry channel);
68
69 /* Checks whether given channel has locally connected users.  If it does this
70    returns TRUE and FALSE if there is not one locally connected client. */
71 bool silc_server_channel_has_local(SilcChannelEntry channel);
72
73 /* This function removes the channel and all users on the channel, unless
74    the channel is permanent.  In this case the channel is disabled but all
75    users are removed from the channel.  Returns TRUE if the channel is
76    destroyed totally, and FALSE if it is permanent and remains. */
77 bool silc_server_channel_delete(SilcServer server,
78                                 SilcChannelEntry channel);
79
80 /* Returns TRUE if the given client is on the channel.  FALSE if not. 
81    This works because we assure that the user list on the channel is
82    always in up to date thus we can only check the channel list from 
83    `client' which is faster than checking the user list from `channel'. */
84 bool silc_server_client_on_channel(SilcClientEntry client,
85                                    SilcChannelEntry channel,
86                                    SilcChannelClientEntry *chl);
87
88 /* Checks string for bad characters and returns TRUE if they are found. */
89 bool silc_server_name_bad_chars(const char *name, SilcUInt32 name_len);
90
91 /* Modifies the `nick' if it includes bad characters and returns new
92    allocated nickname that does not include bad characters. */
93 char *silc_server_name_modify_bad(const char *name, SilcUInt32 name_len);
94
95 /* Find number of sockets by IP address indicated by `ip'. Returns 0 if
96    socket connections with the IP address does not exist. */
97 SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip,
98                                          SilcSocketType type);
99
100 /* Find number of sockets by IP address indicated by remote host, indicatd
101    by `ip' or `hostname', `port', and `type'.  Returns 0 if socket connections
102    does not exist. If `ip' is provided then `hostname' is ignored. */
103 SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server, 
104                                              const char *ip,
105                                              const char *hostname,
106                                              SilcUInt16 port,
107                                              SilcSocketType type);
108
109 /* Finds locally cached public key by the public key received in the SKE. 
110    If we have it locally cached then we trust it and will use it in the
111    authentication protocol.  Returns the locally cached public key or NULL
112    if we do not find the public key.  */
113 SilcPublicKey silc_server_find_public_key(SilcServer server, 
114                                           SilcHashTable local_public_keys,
115                                           SilcPublicKey remote_public_key);
116
117 /* This returns the first public key from the table of public keys.  This
118    is used only in cases where single public key exists in the table and
119    we want to get a pointer to it.  For public key tables that has multiple
120    keys in it the silc_server_find_public_key must be used. */
121 SilcPublicKey silc_server_get_public_key(SilcServer server,
122                                          SilcHashTable local_public_keys);
123
124 /* Check whether the connection `sock' is allowed to connect to us.  This
125    checks for example whether there is too much connections for this host,
126    and required version for the host etc. */
127 bool silc_server_connection_allowed(SilcServer server, 
128                                     SilcSocketConnection sock,
129                                     SilcSocketType type,
130                                     SilcServerConfigConnParams *global,
131                                     SilcServerConfigConnParams *params,
132                                     SilcSKE ske);
133
134 /* Checks that client has rights to add or remove channel modes. If any
135    of the checks fails FALSE is returned. */
136 bool silc_server_check_cmode_rights(SilcServer server,
137                                     SilcChannelEntry channel,
138                                     SilcChannelClientEntry client,
139                                     SilcUInt32 mode);
140
141 /* Check that the client has rights to change its user mode.  Returns
142    FALSE if setting some mode is not allowed. */
143 bool silc_server_check_umode_rights(SilcServer server,
144                                     SilcClientEntry client,
145                                     SilcUInt32 mode);
146
147 /* This function is used to send the notify packets and motd to the
148    incoming client connection. */
149 void silc_server_send_connect_notifys(SilcServer server,
150                                       SilcSocketConnection sock,
151                                       SilcClientEntry client);
152
153 /* Kill the client indicated by `remote_client' sending KILLED notify
154    to the client, to all channels client has joined and to primary
155    router if needed.  The killed client is also removed from all channels. */
156 void silc_server_kill_client(SilcServer server,
157                              SilcClientEntry remote_client,
158                              const char *comment,
159                              void *killer_id,
160                              SilcIdType killer_id_type);
161
162 /* This function checks whether the `client' nickname is being watched
163    by someone, and notifies the watcher of the notify change of notify
164    type indicated by `notify'. */
165 bool silc_server_check_watcher_list(SilcServer server,
166                                     SilcClientEntry client,
167                                     const char *new_nick,
168                                     SilcNotifyType notify);
169
170 /* Remove the `client' from watcher list. After calling this the `client'
171    is not watching any nicknames. */
172 bool silc_server_del_from_watcher_list(SilcServer server,
173                                        SilcClientEntry client);
174
175 /* Force the client indicated by `chl' to change the channel user mode
176    on channel indicated by `channel' to `forced_mode'. */
177 bool silc_server_force_cumode_change(SilcServer server,
178                                      SilcSocketConnection sock,
179                                      SilcChannelEntry channel,
180                                      SilcChannelClientEntry chl,
181                                      SilcUInt32 forced_mode);
182
183 #endif /* SERVER_UTIL_H */