diff options
| author | Thomas Schmucker <ts@its1.de> | 2026-09-21 09:28:52 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2026-09-21 09:28:52 +0200 |
| commit | 2ac83ca7e7fc75c51e550720ed89dfe4097b1df4 (patch) | |
| tree | 9991e74559a2dbfd0aa607815c6a2e397acc450f | |
| parent | 204472f3341dfccbd9c9ef753ea90de9d4c817b8 (diff) | |
| download | use-fastcgi-2ac83ca7e7fc75c51e550720ed89dfe4097b1df4.tar.gz use-fastcgi-2ac83ca7e7fc75c51e550720ed89dfe4097b1df4.tar.bz2 use-fastcgi-2ac83ca7e7fc75c51e550720ed89dfe4097b1df4.zip | |
neue Funktion: escape_html()
| -rw-r--r-- | server.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
| @@ -25,8 +25,8 @@ struct Configuration { | |||
| 25 | 25 | ||
| 26 | struct RequestError : runtime_error { | 26 | struct 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 }; | |||
| 37 | atomic_bool reload{ false }; | 37 | atomic_bool reload{ false }; |
| 38 | 38 | ||
| 39 | void | 39 | void |
| 40 | handler(int signal) | 40 | signal_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 | ||
| 75 | void | 75 | void |
| 76 | handle_request(char** env, const Configuration&, string_view body, ostream& out) | 76 | escape_html(string_view str, ostream& out) |
| 77 | { | ||
| 78 | for ( auto chr: str ) { | ||
| 79 | switch ( chr ) { | ||
| 80 | case '<': | ||
| 81 | out << "<"; | ||
| 82 | break; | ||
| 83 | case '>': | ||
| 84 | out << ">"; | ||
| 85 | break; | ||
| 86 | case '&': | ||
| 87 | out << "&"; | ||
| 88 | break; | ||
| 89 | case '\"': | ||
| 90 | out << """; | ||
| 91 | break; | ||
| 92 | default: | ||
| 93 | out << chr; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | void | ||
| 99 | handle_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 | } |
