From fffd213c8cba2135afda493d797c41c10354770e Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sat, 12 Apr 2008 11:38:42 +0000 Subject: big svn cleanup --- src/Sockets/tests/http_post.cpp | 107 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/Sockets/tests/http_post.cpp (limited to 'src/Sockets/tests/http_post.cpp') diff --git a/src/Sockets/tests/http_post.cpp b/src/Sockets/tests/http_post.cpp new file mode 100644 index 0000000..3b0b830 --- /dev/null +++ b/src/Sockets/tests/http_post.cpp @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include + + +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() + { + std::string name; + std::string value; + GetForm() -> getfirst(name, value); + while (name.size()) + { +fprintf(stderr, "%s: '%s'\n", name.c_str(), value.c_str()); + GetForm() -> getnext(name, value); + } + 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() + { + Send(""); + 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 l(h); + if (l.Bind(1028)) + { + printf("Bind port 1028 failed\n"); + return -1; + } + h.Add(&l); + ListenSocket l2(h); + if (l2.Bind(8443)) + { + printf("Bind port 8443 failed\n"); + return -1; + } + h.Add(&l2); + HttpPostSocket sock(h, "http://localhost:1028/postdata"); + sock.AddField("name", "value"); + sock.Open(); + h.Add(&sock); + while (h.GetCount()) + { + h.Select(1, 0); + } +} + + -- cgit v1.2.3