10 #include <pion/net/WebServer.hpp>
11 #include <pion/net/HTTPRequest.hpp>
12 #include <pion/net/HTTPRequestReader.hpp>
13 #include <pion/net/HTTPResponseWriter.hpp>
14 #include <pion/net/HTTPBasicAuth.hpp>
15 #include <pion/net/HTTPCookieAuth.hpp>
33 m_services.
add(clean_resource, service_ptr);
35 }
catch (std::exception& e) {
38 PION_LOG_INFO(
m_logger,
"Loaded static web service for resource (" << clean_resource <<
")");
48 service_ptr = m_services.
load(clean_resource, service_name);
51 }
catch (std::exception& e) {
54 PION_LOG_INFO(
m_logger,
"Loaded web service plug-in for resource (" << clean_resource <<
"): " << service_name);
58 const std::string& name,
const std::string& value)
67 }
catch (std::exception& e) {
70 PION_LOG_INFO(
m_logger,
"Set web service option for resource ("
71 << resource <<
"): " << name <<
'=' << value);
76 std::string config_file;
81 std::ifstream config_stream;
82 config_stream.open(config_file.c_str(), std::ios::in);
83 if (! config_stream.is_open())
89 PARSE_NEWLINE, PARSE_COMMAND, PARSE_RESOURCE, PARSE_VALUE, PARSE_COMMENT, PARSE_USERNAME
90 } parse_state = PARSE_NEWLINE;
91 std::string command_string;
92 std::string resource_string;
93 std::string username_string;
94 std::string value_string;
95 std::string option_name_string;
96 std::string option_value_string;
97 int c = config_stream.get();
99 while (config_stream) {
100 switch(parse_state) {
105 parse_state = PARSE_COMMENT;
106 }
else if (isalpha(c)) {
108 parse_state = PARSE_COMMAND;
110 command_string += tolower(c);
111 }
else if (c !=
'\r' && c !=
'\n') {
118 if (c ==
' ' || c ==
'\t') {
120 if (command_string==
"path" || command_string==
"auth" || command_string==
"restrict") {
121 value_string.clear();
122 parse_state = PARSE_VALUE;
123 }
else if (command_string==
"service" || command_string==
"option") {
124 resource_string.clear();
125 parse_state = PARSE_RESOURCE;
126 }
else if (command_string==
"user") {
127 username_string.clear();
128 parse_state = PARSE_USERNAME;
132 }
else if (! isalpha(c)) {
137 command_string += tolower(c);
143 if (c ==
' ' || c ==
'\t') {
145 if (! resource_string.empty()) {
147 value_string.clear();
148 parse_state = PARSE_VALUE;
150 }
else if (c ==
'\r' || c ==
'\n') {
155 resource_string += c;
161 if (c ==
' ' || c ==
'\t') {
163 if (! username_string.empty()) {
165 value_string.clear();
166 parse_state = PARSE_VALUE;
168 }
else if (c ==
'\r' || c ==
'\n') {
173 username_string += c;
179 if (c ==
'\r' || c ==
'\n') {
181 if (value_string.empty()) {
184 }
else if (command_string ==
"path") {
187 catch (std::exception& e) {
190 }
else if (command_string ==
"auth") {
193 if (value_string ==
"basic"){
196 else if (value_string ==
"cookie"){
202 }
else if (command_string ==
"restrict") {
206 else if (value_string.empty())
208 auth_ptr->addRestrict(value_string);
209 }
else if (command_string ==
"user") {
213 else if (value_string.empty())
215 auth_ptr->addUser(username_string, value_string);
216 }
else if (command_string ==
"service") {
219 }
else if (command_string ==
"option") {
221 std::string::size_type pos = value_string.find(
'=');
222 if (pos == std::string::npos)
224 option_name_string = value_string.substr(0, pos);
225 option_value_string = value_string.substr(pos + 1);
227 option_value_string);
229 command_string.clear();
230 parse_state = PARSE_NEWLINE;
231 }
else if (c ==
' ' || c ==
'\t') {
233 if (! value_string.empty())
243 if (c ==
'\r' || c ==
'\n')
244 parse_state = PARSE_NEWLINE;
249 c = config_stream.get();