diff options
author | Othmar Gsenger <otti@anytun.org> | 2008-04-12 11:38:42 +0000 |
---|---|---|
committer | Othmar Gsenger <otti@anytun.org> | 2008-04-12 11:38:42 +0000 |
commit | fffd213c8cba2135afda493d797c41c10354770e (patch) | |
tree | bb5eea1b12871d8c3fed0e687d83be3e504d11b2 /Sockets/tests/httpd.cpp | |
parent | svn cleanup (diff) |
big svn cleanup
Diffstat (limited to 'Sockets/tests/httpd.cpp')
-rw-r--r-- | Sockets/tests/httpd.cpp | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/Sockets/tests/httpd.cpp b/Sockets/tests/httpd.cpp deleted file mode 100644 index e1106a0..0000000 --- a/Sockets/tests/httpd.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include <HttpdSocket.h> -#include <SocketHandler.h> -#include <ListenSocket.h> -#include <StdoutLog.h> - - -class sSocket : public HttpdSocket -{ -public: - sSocket(ISocketHandler& h) : HttpdSocket(h) { - } - - void Init() - { - if (GetParent() -> GetPort() == 443 || GetParent() -> GetPort() == 8443) - { -#ifdef HAVE_OPENSSL - EnableSSL(); -#else - fprintf(stderr, "SSL not available\n"); -#endif - } - } - - void Exec() - { - CreateHeader(); - GenerateDocument(); - } - - void CreateHeader() - { - SetStatus("200"); - SetStatusText("OK"); -fprintf(stderr, "Uri: '%s'\n", GetUri().c_str()); - { - size_t x = 0; - for (size_t i = 0; i < GetUri().size(); i++) - if (GetUri()[i] == '.') - x = i; - std::string ext = GetUri().substr(x + 1); - if (ext == "gif" || ext == "jpg" || ext == "png") - AddResponseHeader("Content-type", "image/" + ext); - else - AddResponseHeader("Content-type", "text/" + ext); - } - AddResponseHeader("Connection", "close"); - SendResponse(); - } - - void GenerateDocument() - { - std::string fn = GetUri().substr(1); - FILE *fil = fopen(fn.c_str(), "rb"); - if (fil) - { - char slask[1000]; - int n = fread(slask,1,1000,fil); - while (n > 0) - { - SendBuf(slask, n); - n = fread(slask,1,1000,fil); - } - fclose(fil); - } - else - { - SetStatus("404"); - SetStatusText("Not Found"); - } - SetCloseAndDelete(); - } - -#ifdef HAVE_OPENSSL - void InitSSLServer() - { - InitializeContext("httpd", "comb.pem", "", SSLv23_method()); - } -#endif - -}; - - -int main(int argc, char *argv[]) -{ - std::string host = argc > 1 ? argv[1] : "www.alhem.net"; - StdoutLog log; - SocketHandler h(&log); - ListenSocket<sSocket> l(h); - if (l.Bind(1028)) - { - printf("Bind port 1028 failed\n"); - return -1; - } - h.Add(&l); - ListenSocket<sSocket> l2(h); - if (l2.Bind(8443)) - { - printf("Bind port 8443 failed\n"); - return -1; - } - h.Add(&l2); - while (h.GetCount()) - { - h.Select(1, 0); - } -} - - |