summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/server.cpp b/server.cpp
index 344f0bc..5e67b5f 100644
--- a/server.cpp
+++ b/server.cpp
@@ -25,8 +25,8 @@ struct Configuration {
25 25
26struct RequestError : runtime_error { 26struct RequestError : runtime_error {
27 RequestError(int status, const string& meldung) 27 RequestError(int status, const string& meldung)
28 : runtime_error(meldung) 28 : runtime_error(meldung)
29 , status(status) 29 , status(status)
30 { 30 {
31 } 31 }
32 32
@@ -37,7 +37,7 @@ atomic_bool quit{ false };
37atomic_bool reload{ false }; 37atomic_bool reload{ false };
38 38
39void 39void
40handler(int signal) 40signal_handler(int signal)
41{ 41{
42 if ( signal == SIGINT || signal == SIGTERM ) { 42 if ( signal == SIGINT || signal == SIGTERM ) {
43 quit = true; 43 quit = true;
@@ -52,7 +52,7 @@ init_signal_handler()
52{ 52{
53 struct sigaction sa; 53 struct sigaction sa;
54 memset(&sa, 0, sizeof sa); 54 memset(&sa, 0, sizeof sa);
55 sa.sa_handler = handler; 55 sa.sa_handler = signal_handler;
56 sa.sa_flags = 0; 56 sa.sa_flags = 0;
57 sigemptyset(&sa.sa_mask); 57 sigemptyset(&sa.sa_mask);
58 58
@@ -73,7 +73,30 @@ load_configuration(Configuration& configuration)
73} 73}
74 74
75void 75void
76handle_request(char** env, const Configuration&, string_view body, ostream& out) 76escape_html(string_view str, ostream& out)
77{
78 for ( auto chr: str ) {
79 switch ( chr ) {
80 case '<':
81 out << "&lt;";
82 break;
83 case '>':
84 out << "&gt;";
85 break;
86 case '&':
87 out << "&amp;";
88 break;
89 case '\"':
90 out << "&quot;";
91 break;
92 default:
93 out << chr;
94 }
95 }
96}
97
98void
99handle_request(char* env[], const Configuration&, string_view body, ostream& out)
77{ 100{
78 const char* methode = FCGX_GetParam("REQUEST_METHOD", env); 101 const char* methode = FCGX_GetParam("REQUEST_METHOD", env);
79 102
@@ -82,8 +105,10 @@ handle_request(char** env, const Configuration&, string_view body, ostream& out)
82 out << "<p>Methode: " << (methode ? methode : "?") << ", Body: " << body.size() << " Bytes</p>"; 105 out << "<p>Methode: " << (methode ? methode : "?") << ", Body: " << body.size() << " Bytes</p>";
83 106
84 out << "<pre>"; 107 out << "<pre>";
85 for (int i=0; env[i] != NULL; ++i) { 108 for ( int i = 0; env[i] != NULL; ++i ) {
86 out << env[i] << '\n'; 109 // Request-Daten dürfen nicht ungefiltert als HTML ausgegeben werden.
110 escape_html(env[i], out);
111 out << '\n';
87 } 112 }
88 out << "</pre>"; 113 out << "</pre>";
89} 114}