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