config (7721B)
1 #ifndef _CONFIG_ 2 #define _CONFIG_ 3 4 #include "sys/sys" 5 #include "backenddef/backenddef" 6 #include "servertype/servertype" 7 #include "dispatchmode/dispatchmode" 8 #include "error/error" 9 #include "ThreadsAndMutexes/mutex/mutex" 10 #include "backendcheck/backendcheck" 11 12 using namespace std; 13 14 class Config { 15 public: 16 Config (); 17 18 // Init by cmdline 19 void parsecmdline (int ac, char **av); 20 21 // Accessors 22 bool verbose() const { return (verbose_flag); } 23 void verbose (bool v) { verbose_flag = v; } 24 25 bool debug() const { return (debug_flag); } 26 void debug (bool d) { debug_flag = d; } 27 28 unsigned quitafter() const { return (quit_after); } 29 30 Servertype::Type stype() const { return (styp.type()); } 31 void stype(string const &s) { styp.type(s); } 32 string stypestr() const { return (styp.typestr()); } 33 string const &sipaddr() const { return (sip); } 34 int sport() const { return (lport); } 35 36 int backends() const { return (blist.size()); } 37 38 /* PID file */ 39 void pidfile(string const &s); 40 string const &pidfile() { 41 return pid_file; 42 } 43 44 /* Client timeouts */ 45 unsigned client_read_timeout() const { 46 return (c_timeout); 47 } 48 void client_read_timeout (unsigned c) { 49 c_timeout = c; 50 } 51 unsigned client_write_timeout() const { 52 return c_write_timeout; 53 } 54 void client_write_timeout(unsigned c) { 55 c_write_timeout = c; 56 } 57 58 /* Back end timeouts */ 59 unsigned backend_read_timeout() const { 60 return (b_timeout); 61 } 62 void backend_read_timeout (unsigned b) { 63 b_timeout = b; 64 } 65 unsigned backend_write_timeout() const { 66 return b_write_timeout; 67 } 68 void backend_write_timeout(unsigned b) { 69 b_write_timeout = b; 70 } 71 72 unsigned wakeupsec() const { return (wakeup); } 73 void wakeupsec (unsigned w) { wakeup = w; } 74 75 unsigned checkupsec() const { return (checkup); } 76 void checkupsec (unsigned w) { checkup = w; } 77 78 unsigned buffersize() const { return (bufsize); } 79 void buffersize (unsigned b); 80 81 bool foregroundmode() const { return (foreground_mode); } 82 83 bool addxrversion() const { return (add_xr_version); } 84 void addxrversion (bool b); 85 86 bool addxforwardedfor() const { return (add_x_forwarded_for); } 87 void addxforwardedfor (bool b); 88 89 bool stickyhttp() const { return (sticky_http); } 90 void stickyhttp(bool b); 91 92 bool replacehostheader() const { return replace_host_header; } 93 void replacehostheader(bool s) { replace_host_header = s; } 94 95 unsigned maxconn() const { return (max_conn); } 96 void maxconn (unsigned m); 97 98 string const &externalalgorithm() const { 99 return (external_algorithm); 100 } 101 102 bool prefixtimestamp() const { return (prefix_timestamp); } 103 void prefixtimestamp (bool p); 104 105 bool fastclose() const { return (fast_close); } 106 void fastclose (bool f); 107 108 bool usewebinterface() const { return use_webinterface; } 109 string const &webinterfaceip() const { 110 return webinterface_ip; 111 } 112 int webinterfaceport() const { return webinterface_port; } 113 114 void webinterface_auth(string const &s); 115 string webinterface_auth() const { return web_auth; } 116 117 string webinterfacename() const { return webinterface_name; } 118 119 unsigned nserverheaders() const { return (serverheaders.size()); } 120 string const &serverheader (unsigned n) { 121 return (serverheaders[n]); 122 } 123 void addserverheader (string const &s); 124 void removeserverheader (unsigned i); 125 void changeserverheader (unsigned i, string const &s); 126 127 string const &dumpdir() const { return (dump_dir); } 128 void dumpdir (string s) { dump_dir = s; } 129 130 unsigned softmaxconnrate() const { return soft_maxconnrate; } 131 void softmaxconnrate(unsigned n) { soft_maxconnrate = n; } 132 unsigned hardmaxconnrate() const { return hard_maxconnrate; } 133 void hardmaxconnrate(unsigned n) { hard_maxconnrate = n; } 134 unsigned defertime() const { return defer_time; } 135 void defertime(unsigned n) { defer_time = n; } 136 unsigned connrate_time() const { return connrate_timeinterval; } 137 void connrate_time(unsigned n) { connrate_timeinterval = n; } 138 139 unsigned dnscachetimeout() const { return dns_cache_timeout; } 140 void dnscachetimeout(unsigned t) { dns_cache_timeout = t; } 141 142 unsigned nallow() const { return (allowlist.size()); } 143 unsigned ndeny() const { return (denylist.size()); } 144 void addallow (string a); 145 void adddeny (string d); 146 void changeallow(string &a, unsigned index); 147 void changedeny(string &a, unsigned index); 148 void deleteallow(unsigned index); 149 void deletedeny(unsigned index); 150 151 int ipstoretimeout() const { return (ipstore_timeout); } 152 void ipstoretimeout(int t); 153 struct in_addr allow(unsigned n) const { 154 return (allowlist[n]); 155 } 156 struct in_addr deny(unsigned n) const { 157 return (denylist[n]); 158 } 159 160 BackendDef const &backend (int i) const { 161 return (blist[i]); 162 } 163 Dispatchmode::Mode dispatchmode() const { 164 return (dmode.mode()); 165 } 166 string dispatchmodestr() const { 167 return (dmode.modestr()); 168 } 169 bool removereservations() const { 170 return remove_reservations; 171 } 172 void removereservations(bool b) { 173 remove_reservations = b; 174 } 175 176 string const &softmaxconnexcess() const { 177 return soft_maxconn_excess_prog; 178 } 179 void softmaxconnexcess(string const &s) { 180 soft_maxconn_excess_prog = s; 181 } 182 string const &hardmaxconnexcess() const { 183 return hard_maxconn_excess_prog; 184 } 185 void hardmaxconnexcess(string const &s) { 186 hard_maxconn_excess_prog = s; 187 } 188 189 void onstart(string s) { on_start = s; } 190 string const &onstart() const { return on_start; } 191 void onend(string s) { on_end = s; } 192 string const &onend() const { return on_end; } 193 void onfail(string s) { on_fail = s; } 194 string const &onfail() const { return on_fail; } 195 196 /* Restart of program */ 197 void restart(); 198 199 private: 200 void setbackend (string const &s, string const &hostmatch, 201 string const &urlmatch, 202 BackendCheck const &bc); 203 void setwebinterface (string s); 204 void setserver (string s); 205 void setdispatchmode (string s); 206 int setinteger (string s) const; 207 208 static string pid_file; 209 static bool verbose_flag; 210 static int lport; 211 static Servertype styp; 212 static string sip; 213 static vector<BackendDef> blist; 214 static Dispatchmode dmode; 215 static unsigned c_timeout, c_write_timeout; 216 static unsigned b_timeout, b_write_timeout; 217 static unsigned wakeup; 218 static unsigned checkup; 219 static unsigned bufsize; 220 static bool foreground_mode; 221 static bool add_xr_version; 222 static bool debug_flag; 223 static bool add_x_forwarded_for; 224 static bool sticky_http; 225 static bool replace_host_header; 226 static unsigned max_conn; 227 static string external_algorithm; 228 static bool prefix_timestamp; 229 static vector<string> serverheaders; 230 static vector<struct in_addr> allowlist; 231 static vector<struct in_addr> denylist; 232 static bool fast_close; 233 static int ipstore_timeout; 234 static bool use_webinterface; 235 static string webinterface_ip; 236 static int webinterface_port; 237 static string webinterface_name; 238 static string web_auth; 239 static string dump_dir; 240 static unsigned soft_maxconnrate; 241 static unsigned hard_maxconnrate; 242 static unsigned defer_time; 243 static unsigned connrate_timeinterval; 244 static unsigned quit_after; 245 static string soft_maxconn_excess_prog; 246 static string hard_maxconn_excess_prog; 247 static unsigned dns_cache_timeout; 248 static string on_start, on_end, on_fail; 249 static bool remove_reservations; 250 static char **org_argv; 251 }; 252 253 extern Config config; 254 255 #endif