updates
[silc.git] / apps / silcd / server.h
1 /*
2
3   server.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 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; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef SERVER_H
22 #define SERVER_H
23
24 /* Forward declaration for SILC Server object. The actual object is
25    defined in internal header file for server routines. I want to keep
26    the object private hence this declaration. */
27 typedef struct SilcServerStruct *SilcServer;
28
29 #define SILC_SERVER_MAX_CONNECTIONS 10000
30
31 /* General definitions */
32
33 /* Server and router. Used internally by the code. */
34 #define SILC_SERVER 0
35 #define SILC_ROUTER 1
36
37 /* Connection retry timeout. We implement exponential backoff algorithm
38    in connection retry. The interval of timeuot grows when retry count
39    grows. */
40 #define SILC_SERVER_RETRY_COUNT        4         /* Max retry count */
41 #define SILC_SERVER_RETRY_MULTIPLIER   7 / 4     /* Interval growth */
42 #define SILC_SERVER_RETRY_RANDOMIZER   2         /* timeout += rnd % 2 */
43 #define SILC_SERVER_RETRY_INTERVAL_MIN 10        /* Min retry timeout */
44 #define SILC_SERVER_RETRY_INTERVAL_MAX 600       /* Max generated timeout */
45
46 /* 
47    Silc Server Params.
48
49    Structure to hold various default parameters for server that can be
50    given before running the server. 
51
52 */
53 typedef struct {
54   unsigned int retry_count;
55   unsigned long retry_interval_min;
56   unsigned long retry_interval_min_usec;
57   unsigned long retry_interval_max;
58   unsigned int retry_keep_trying;
59
60   unsigned long protocol_timeout;
61   unsigned long protocol_timeout_usec;
62 } *SilcServerParams;
63
64 /* Macros */
65
66 /* This macro is used to send notify messages with formatted string. The
67    string is formatted with arguments and the formatted string is sent as
68    argument. */
69 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt)                    \
70 do {                                                                        \
71   char *__fmt__ = silc_format fmt;                                          \
72   silc_server_send_notify(server, sock, type, 1, __fmt__, strlen(__fmt__)); \
73   silc_free(__fmt__);                                                       \
74 } while(0);
75
76 /* Prototypes */
77 int silc_server_alloc(SilcServer *new_server);
78 void silc_server_free(SilcServer server);
79 int silc_server_init(SilcServer server);
80 void silc_server_run(SilcServer server);
81 void silc_server_stop(SilcServer server);
82 void silc_server_packet_parse(SilcPacketParserContext *parser_context);
83 void silc_server_packet_parse_type(SilcServer server, 
84                                    SilcSocketConnection sock,
85                                    SilcPacketContext *packet);
86 void silc_server_packet_send(SilcServer server,
87                              SilcSocketConnection sock, 
88                              SilcPacketType type, 
89                              SilcPacketFlags flags,
90                              unsigned char *data, 
91                              unsigned int data_len,
92                              int force_send);
93 void silc_server_packet_send_dest(SilcServer server,
94                                   SilcSocketConnection sock, 
95                                   SilcPacketType type, 
96                                   SilcPacketFlags flags,
97                                   void *dst_id,
98                                   SilcIdType dst_id_type,
99                                   unsigned char *data, 
100                                   unsigned int data_len,
101                                   int force_send);
102 void silc_server_packet_forward(SilcServer server,
103                                 SilcSocketConnection sock,
104                                 unsigned char *data, unsigned int data_len,
105                                 int force_send);
106 void silc_server_packet_broadcast(SilcServer server,
107                                   SilcSocketConnection sock,
108                                   SilcPacketContext *packet);
109 void silc_server_packet_send_to_channel(SilcServer server,
110                                         SilcChannelEntry channel,
111                                         SilcPacketType type,
112                                         unsigned char *data,
113                                         unsigned int data_len,
114                                         int force_send);
115 void silc_server_packet_relay_to_channel(SilcServer server,
116                                          SilcSocketConnection sender_sock,
117                                          SilcChannelEntry channel,
118                                          void *sender, 
119                                          SilcIdType sender_type,
120                                          unsigned char *data,
121                                          unsigned int data_len,
122                                          int force_send);
123 void silc_server_packet_send_local_channel(SilcServer server,
124                                            SilcChannelEntry channel,
125                                            SilcPacketType type,
126                                            SilcPacketFlags flags,
127                                            unsigned char *data,
128                                            unsigned int data_len,
129                                            int force_send);
130 void silc_server_packet_relay_command_reply(SilcServer server,
131                                             SilcSocketConnection sock,
132                                             SilcPacketContext *packet);
133 void silc_server_close_connection(SilcServer server,
134                                   SilcSocketConnection sock);
135 void silc_server_free_sock_user_data(SilcServer server, 
136                                      SilcSocketConnection sock);
137 void silc_server_remove_from_channels(SilcServer server, 
138                                       SilcSocketConnection sock,
139                                       SilcClientEntry client);
140 int silc_server_remove_from_one_channel(SilcServer server, 
141                                         SilcSocketConnection sock,
142                                         SilcChannelEntry channel,
143                                         SilcClientEntry client,
144                                         int notify);
145 int silc_server_client_on_channel(SilcClientEntry client,
146                                   SilcChannelEntry channel);
147 void silc_server_disconnect_remote(SilcServer server,
148                                    SilcSocketConnection sock,
149                                    const char *fmt, ...);
150 void silc_server_private_message(SilcServer server,
151                                  SilcSocketConnection sock,
152                                  SilcPacketContext *packet);
153 void silc_server_channel_message(SilcServer server,
154                                  SilcSocketConnection sock,
155                                  SilcPacketContext *packet);
156 void silc_server_channel_key(SilcServer server,
157                              SilcSocketConnection sock,
158                              SilcPacketContext *packet);
159 void silc_server_send_motd(SilcServer server,
160                            SilcSocketConnection sock);
161 void silc_server_send_error(SilcServer server,
162                             SilcSocketConnection sock,
163                             const char *fmt, ...);
164 void silc_server_send_notify(SilcServer server,
165                              SilcSocketConnection sock,
166                              SilcNotifyType type,
167                              unsigned int argc, ...);
168 void silc_server_send_notify_dest(SilcServer server,
169                                   SilcSocketConnection sock,
170                                   void *dest_id,
171                                   SilcIdType dest_id_type,
172                                   SilcNotifyType type,
173                                   unsigned int argc, ...);
174 void silc_server_send_notify_to_channel(SilcServer server,
175                                         SilcChannelEntry channel,
176                                         SilcNotifyType type,
177                                         unsigned int argc, ...);
178 void silc_server_send_notify_on_channels(SilcServer server,
179                                          SilcClientEntry client,
180                                          SilcNotifyType type,
181                                          unsigned int argc, ...);
182 void silc_server_send_new_id(SilcServer server,
183                              SilcSocketConnection sock,
184                              int broadcast,
185                              void *id, SilcIdType id_type, 
186                              unsigned int id_len);
187 void silc_server_send_replace_id(SilcServer server,
188                                  SilcSocketConnection sock,
189                                  int broadcast,
190                                  void *old_id, SilcIdType old_id_type,
191                                  unsigned int old_id_len,
192                                  void *new_id, SilcIdType new_id_type,
193                                  unsigned int new_id_len);
194 void silc_server_send_remove_channel_user(SilcServer server,
195                                           SilcSocketConnection sock,
196                                           int broadcast,
197                                           void *client_id, void *channel_id);
198 void silc_server_replace_id(SilcServer server,
199                             SilcSocketConnection sock,
200                             SilcPacketContext *packet);
201 SilcChannelEntry silc_server_new_channel(SilcServer server, 
202                                          SilcServerID *router_id,
203                                          char *cipher, char *channel_name);
204 SilcClientEntry silc_server_new_client(SilcServer server,
205                                        SilcSocketConnection sock,
206                                        SilcPacketContext *packet);
207 SilcServerEntry silc_server_new_server(SilcServer server,
208                                        SilcSocketConnection sock,
209                                        SilcPacketContext *packet);
210 void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
211                         SilcPacketContext *packet);
212 void silc_server_remove_channel_user(SilcServer server,
213                                      SilcSocketConnection sock,
214                                      SilcPacketContext *packet);
215
216 #endif