New silcconfig library and server parser. Merged silc-newconfig-final.patch.
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Johnny Mnemonic <johnny@themnemonic.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; 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 SERVERCONFIG_H
22 #define SERVERCONFIG_H
23
24 typedef struct SilcServerConfigSectionCipherStruct {
25   char *name;
26   char *module;
27   uint32 key_length;
28   uint32 block_length;
29   struct SilcServerConfigSectionCipherStruct *next;
30 } SilcServerConfigSectionCipher;
31
32 typedef struct SilcServerConfigSectionHashStruct {
33   char *name;
34   char *module;
35   uint32 block_length;
36   uint32 digest_length;
37   struct SilcServerConfigSectionHashStruct *next;
38 } SilcServerConfigSectionHash;
39
40 typedef struct SilcServerConfigSectionHmacStruct {
41   char *name;
42   char *hash;
43   uint32 mac_length;
44   struct SilcServerConfigSectionHmacStruct *next;
45 } SilcServerConfigSectionHmac;
46
47 typedef struct SilcServerConfigSectionPkcsStruct {
48   char *name;
49   struct SilcServerConfigSectionPkcsStruct *next;
50 } SilcServerConfigSectionPkcs;
51
52 typedef struct SilcServerConfigSectionServerInfoStruct {
53   char *server_name;
54   char *server_ip;
55   uint16 port;
56   char *server_type;    /* E.g. "Test Server" */
57   char *location;       /* geographic location */
58   char *admin;          /* admin full name */
59   char *email;          /* admin's email address */
60   char *user;           /* userid the server should be runned at */
61   char *group;          /* ditto, but about groupid */
62   SilcPublicKey public_key;
63   SilcPrivateKey private_key;
64   char *motd_file;      /* path to text motd file (reading only) */
65   char *pid_file;       /* path to the pid file (for reading and writing) */
66 } SilcServerConfigSectionServerInfo;
67
68 typedef struct SilcServerConfigSectionLoggingStruct {
69   char *file;
70   uint32 maxsize;
71 } SilcServerConfigSectionLogging;
72
73 /* Holds all configured connection classes */
74 /* typedef struct SilcServerConfigSectionClassStruct {
75   uint32 class;
76   uint32 ping_freq;
77   uint32 connect_freq;
78   uint32 max_links;
79   struct SilcServerConfigSectionClassStruct *next;
80 } SilcServerConfigSectionClass; */
81
82 /* Holds all client authentication data from config file */
83 typedef struct SilcServerConfigSectionClientStruct {
84   char *host;
85   SilcAuthMethod auth_meth;
86   void *auth_data;
87   uint32 auth_data_len;
88   uint16 port;
89   uint32 class;
90   struct SilcServerConfigSectionClientStruct *next;
91 } SilcServerConfigSectionClient;
92
93 /* Holds all server's administrators authentication data from config file */
94 typedef struct SilcServerConfigSectionAdminStruct {
95   char *host;
96   char *user;
97   char *nick;
98   SilcAuthMethod auth_meth;
99   void *auth_data;
100   uint32 auth_data_len;
101   struct SilcServerConfigSectionAdminStruct *next;
102 } SilcServerConfigSectionAdmin;
103
104 /* Holds all configured denied connections from config file */
105 typedef struct SilcServerConfigSectionDenyStruct {
106   char *host;
107   uint16 port;
108   char *reason;
109   struct SilcServerConfigSectionDenyStruct *next;
110 } SilcServerConfigSectionDeny;
111
112 /* Holds all configured server connections from config file */
113 typedef struct SilcServerConfigSectionServerStruct {
114   char *host;
115   SilcAuthMethod auth_meth;
116   void *auth_data;
117   uint32 auth_data_len;
118   uint16 port;
119   char *version;
120   uint32 class;
121   bool backup_router;
122   struct SilcServerConfigSectionServerStruct *next;
123 } SilcServerConfigSectionServer;
124
125 /* Holds all configured router connections from config file */
126 typedef struct SilcServerConfigSectionRouterStruct {
127   char *host;
128   SilcAuthMethod auth_meth;
129   void *auth_data;
130   uint32 auth_data_len;
131   uint16 port;
132   char *version;
133   uint32 class;
134   bool initiator;
135   bool backup_router;
136   char *backup_replace_ip;
137   uint16 backup_replace_port;
138   bool backup_local;
139   struct SilcServerConfigSectionRouterStruct *next;
140 } SilcServerConfigSectionRouter;
141
142 /* define the SilcServerConfig object */
143 typedef struct {
144   void *tmp;
145   char *module_path;
146
147   SilcServerConfigSectionCipher *cipher;
148   SilcServerConfigSectionHash *hash;
149   SilcServerConfigSectionHmac *hmac;
150   SilcServerConfigSectionPkcs *pkcs;
151   SilcServerConfigSectionLogging *logging_info;
152   SilcServerConfigSectionLogging *logging_warnings;
153   SilcServerConfigSectionLogging *logging_errors;
154   SilcServerConfigSectionLogging *logging_fatals;
155   SilcServerConfigSectionServerInfo *server_info;
156 /*SilcServerConfigSectionClass *conn_class; */
157   SilcServerConfigSectionClient *clients;
158   SilcServerConfigSectionAdmin *admins;
159   SilcServerConfigSectionDeny *denied;
160   SilcServerConfigSectionServer *servers;
161   SilcServerConfigSectionRouter *routers;
162 } *SilcServerConfig;
163
164 /* Prototypes */
165
166 /* basic config operations */
167 SilcServerConfig silc_server_config_alloc(char *filename);
168 void silc_server_config_destroy(SilcServerConfig config);
169
170 /* algorithm registering and reset functions */
171 bool silc_server_config_register_ciphers(SilcServer server);
172 bool silc_server_config_register_hashfuncs(SilcServer server);
173 bool silc_server_config_register_hmacs(SilcServer server);
174 bool silc_server_config_register_pkcs(SilcServer server);
175 void silc_server_config_setlogfiles(SilcServerConfig config, SilcSchedule sked);
176
177 /* run-time config access functions */
178 SilcServerConfigSectionClient *
179 silc_server_config_find_client(SilcServerConfig config, char *host, int port);
180
181 SilcServerConfigSectionAdmin *
182 silc_server_config_find_admin(SilcServerConfig config,
183                               char *host, char *user, char *nick);
184
185 SilcServerConfigSectionDeny *
186 silc_server_config_find_denied(SilcServerConfig config,
187                                char *host, uint16 port);
188
189 /* Prototypes - OLD */
190 SilcServerConfigSectionServer *
191 silc_server_config_find_server_conn(SilcServerConfig config,
192                                     char *host, int port);
193 SilcServerConfigSectionRouter *
194 silc_server_config_find_router_conn(SilcServerConfig config,
195                                     char *host, int port);
196 bool silc_server_config_is_primary_route(SilcServerConfig config);
197 SilcServerConfigSectionRouter *
198 silc_server_config_get_primary_router(SilcServerConfig config);
199
200 #endif  /* !SERVERCONFIG_H */