1 /*
2  * Copyright (C) 2012 Tommi Maekitalo
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
27  */
28 
29 #ifndef TNT_TNTCONFIG_H
30 #define TNT_TNTCONFIG_H
31 
32 #include <string>
33 #include <vector>
34 #include <map>
35 #include <cxxtools/serializationinfo.h>
36 
37 namespace tnt
38 {
39   static const int SSL_ALL = 0;
40   static const int SSL_NO  = 1;
41   static const int SSL_YES = 2;
42 
43   struct TntConfig
44   {
45 
46     struct Mapping
47     {
48       std::string target;
49       std::string url;
50       std::string vhost;
51       std::string method;
52       std::string pathinfo;
53       int ssl;
54 
55       typedef std::map<std::string, std::string> ArgsType;
56 
57       ArgsType args;
58     };
59 
60     struct Listener
61     {
62       std::string ip;
63       unsigned short port;
64     };
65 
66     struct SslListener : public Listener
67     {
68       std::string certificate;
69       std::string key;
70     };
71 
72     typedef std::vector<Mapping> MappingsType;
73     typedef std::vector<Listener> ListenersType;
74     typedef std::vector<SslListener> SslListenersType;
75     typedef std::vector<std::string> CompPathType;
76     typedef std::map<std::string, std::string> EnvironmentType;
77 
78     MappingsType mappings;
79     ListenersType listeners;
80     SslListenersType ssllisteners;
81     unsigned maxRequestSize;
82     unsigned maxRequestTime;
83     std::string user;
84     std::string group;
85     std::string dir;
86     std::string chrootdir;
87     std::string pidfile;
88     bool daemon;
89     unsigned minThreads;
90     unsigned maxThreads;
91     unsigned long threadStartDelay;
92     unsigned queueSize;
93     CompPathType compPath;
94     unsigned socketBufferSize;
95     unsigned socketReadTimeout;
96     unsigned socketWriteTimeout;
97     unsigned keepAliveTimeout;
98     unsigned keepAliveMax;
99     unsigned sessionTimeout;
100     unsigned listenBacklog;
101     unsigned listenRetry;
102     bool enableCompression;
103     unsigned minCompressSize;
104     std::string mimeDb;
105     unsigned maxUrlMapCache;
106     std::string defaultContentType;
107     std::string accessLog;
108     std::string errorLog;
109     unsigned backgroundTasks;
110     unsigned timerSleep;
111     cxxtools::SerializationInfo config;
112     EnvironmentType environment;
113     std::string documentRoot;
114     std::vector<std::string> includes;
115 
116     TntConfig();
117 
hasValueTntConfig118     bool hasValue(const std::string& key) const
119     { return config.findMember(key) != 0; }
120 
121     static TntConfig& it();
122   };
123 
124   void operator>>= (const cxxtools::SerializationInfo& si, TntConfig::Mapping& mapping);
125   void operator>>= (const cxxtools::SerializationInfo& si, TntConfig::Listener& listener);
126   void operator>>= (const cxxtools::SerializationInfo& si, TntConfig::SslListener& ssllistener);
127   void operator>>= (const cxxtools::SerializationInfo& si, TntConfig& config);
128 }
129 
130 #endif // TNT_TNTCONFIG_H
131 
132