summaryrefslogtreecommitdiffhomepage
path: root/NetEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-03-29 23:28:05 +0200
committerAki <please@ignore.pl>2022-03-29 23:29:18 +0200
commit27ffda3b67d172afca2cb85387fad27e78719480 (patch)
tree6ca5f6992b54ff34d42125b03522c7227cbaa108 /NetEx
parent20eb9409e1d4d5d26222e62df4a81b0be9cae6f2 (diff)
downloadstarshatter-27ffda3b67d172afca2cb85387fad27e78719480.zip
starshatter-27ffda3b67d172afca2cb85387fad27e78719480.tar.gz
starshatter-27ffda3b67d172afca2cb85387fad27e78719480.tar.bz2
Split Session from HttpServlet
Diffstat (limited to 'NetEx')
-rw-r--r--NetEx/CMakeLists.txt1
-rw-r--r--NetEx/HttpServlet.cpp165
-rw-r--r--NetEx/HttpServlet.h54
-rw-r--r--NetEx/HttpSession.cpp145
-rw-r--r--NetEx/HttpSession.h49
5 files changed, 218 insertions, 196 deletions
diff --git a/NetEx/CMakeLists.txt b/NetEx/CMakeLists.txt
index 84d8b0f..13dadc2 100644
--- a/NetEx/CMakeLists.txt
+++ b/NetEx/CMakeLists.txt
@@ -9,6 +9,7 @@ add_library(
HttpServer.cpp
HttpServlet.cpp
HttpServletExec.cpp
+ HttpSession.cpp
NetAddr.cpp
NetClient.cpp
NetGram.cpp
diff --git a/NetEx/HttpServlet.cpp b/NetEx/HttpServlet.cpp
index eb9f19e..150719c 100644
--- a/NetEx/HttpServlet.cpp
+++ b/NetEx/HttpServlet.cpp
@@ -3,31 +3,31 @@
Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
Copyright (c) 1997-2006, Destroyer Studios LLC.
- AUTHOR: John DiCamillo
+ AUTHOR: John DiCamillo
-
- OVERVIEW
- ========
- Network Server Pump for HTTP Server
+ OVERVIEW
+ ========
+ Network Server Pump for HTTP Server
*/
#include "HttpServlet.h"
-#include "NetLayer.h"
-#include <stdlib.h>
#include <stdio.h>
-#include <ctype.h>
-// +-------------------------------------------------------------------+
+#include "HttpRequest.h"
+#include "HttpResponse.h"
+
+
+HttpServlet::HttpServlet() :
+ session(nullptr)
+{
+}
-HttpServlet::HttpServlet()
- : session(0)
-{ }
HttpServlet::~HttpServlet()
-{ }
+{
+}
-// +--------------------------------------------------------------------+
bool
HttpServlet::Service(HttpRequest& request, HttpResponse& response)
@@ -54,7 +54,6 @@ HttpServlet::Service(HttpRequest& request, HttpResponse& response)
return result;
}
-// +--------------------------------------------------------------------+
bool
HttpServlet::DoGet(HttpRequest& request, HttpResponse& response)
@@ -62,12 +61,14 @@ HttpServlet::DoGet(HttpRequest& request, HttpResponse& response)
return false;
}
+
bool
HttpServlet::DoPost(HttpRequest& request, HttpResponse& response)
{
return DoGet(request, response);
}
+
bool
HttpServlet::DoHead(HttpRequest& request, HttpResponse& response)
{
@@ -84,137 +85,3 @@ HttpServlet::DoHead(HttpRequest& request, HttpResponse& response)
return false;
}
-
-// +--------------------------------------------------------------------+
-// +--------------------------------------------------------------------+
-// +--------------------------------------------------------------------+
-
-HttpSession::HttpSession()
-{
- id = GenerateUniqueID();
- access_time = NetLayer::GetUTC();
-}
-
-HttpSession::~HttpSession()
-{
- attributes.destroy();
-}
-
-// +--------------------------------------------------------------------+
-
-Text
-HttpSession::GetAttribute(const char* name)
-{
- ListIter<HttpParam> iter = attributes;
- while (++iter) {
- HttpParam* p = iter.value();
-
- if (p->name == name)
- return p->value;
- }
-
- return Text();
-}
-
-void
-HttpSession::SetAttribute(const char* name, const char* value)
-{
- ListIter<HttpParam> iter = attributes;
- while (++iter) {
- HttpParam* p = iter.value();
-
- if (p->name == name) {
- p->value = value;
- return;
- }
- }
-
- HttpParam* param = new HttpParam(name, value);
- if (param)
- attributes.append(param);
-}
-
-void
-HttpSession::DelAttribute(const char* name)
-{
- ListIter<HttpParam> iter = attributes;
- while (++iter) {
- HttpParam* p = iter.value();
-
- if (p->name == name) {
- delete iter.removeItem();
- return;
- }
- }
-}
-
-// +--------------------------------------------------------------------+
-
-int
-HttpSession::GetIntAttribute(const char* name)
-{
- ListIter<HttpParam> iter = attributes;
- while (++iter) {
- HttpParam* p = iter.value();
-
- if (p->name == name) {
- int result = ::atoi(p->value.data());
- return result;
- }
- }
-
- return 0;
-}
-
-void
-HttpSession::SetIntAttribute(const char* name, int value)
-{
- char buf[32];
- sprintf(buf, "%d", value);
-
- ListIter<HttpParam> iter = attributes;
- while (++iter) {
- HttpParam* p = iter.value();
-
- if (p->name == name) {
- p->value = buf;
- return;
- }
- }
-
- HttpParam* param = new HttpParam(name, buf);
- if (param)
- attributes.append(param);
-}
-
-void
-HttpSession::DelIntAttribute(const char* name)
-{
- DelAttribute(name);
-}
-
-// +--------------------------------------------------------------------+
-
-Text
-HttpSession::GenerateUniqueID()
-{
- char unique[17];
-
- for (int i = 0; i < 16; i++) {
- char c = rand() % 25 + 'a';
- unique[i] = c;
- }
-
- unique[16] = 0;
- return unique;
-}
-
-// +--------------------------------------------------------------------+
-
-void
-HttpSession::Access()
-{
- access_time = NetLayer::GetUTC();
-}
-
-
diff --git a/NetEx/HttpServlet.h b/NetEx/HttpServlet.h
index aedfb09..eb706ea 100644
--- a/NetEx/HttpServlet.h
+++ b/NetEx/HttpServlet.h
@@ -3,26 +3,21 @@
Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
Copyright (c) 1997-2006, Destroyer Studios LLC.
- AUTHOR: John DiCamillo
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Network Server Pump for HTTP Server
+ OVERVIEW
+ ========
+ Network Server Pump for HTTP Server
*/
-
#ifndef HttpServlet_h
#define HttpServlet_h
-#include "HttpServer.h"
-
-// +-------------------------------------------------------------------+
-
-class HttpServlet;
-class HttpSession;
+#include "HttpRequest.h"
+#include "HttpResponse.h"
+#include "HttpSession.h"
-// +-------------------------------------------------------------------+
class HttpServlet
{
@@ -45,40 +40,5 @@ protected:
HttpSession* session;
};
-// +-------------------------------------------------------------------+
-
-class HttpSession
-{
-public:
- static const char* TYPENAME() { return "HttpSession"; }
-
- HttpSession();
- virtual ~HttpSession();
-
- int operator == (const HttpSession& s) const { return id == s.id; }
-
- Text GenerateUniqueID();
-
- Text GetID() const { return id; }
- void SetID(const char* i) { id = i; }
- int GetLastAccess() const { return access_time;}
- void Access();
-
- List<HttpParam>& GetAttributes() { return attributes; }
-
- Text GetAttribute(const char* name);
- void SetAttribute(const char* name, const char* value);
- void DelAttribute(const char* name);
-
- int GetIntAttribute(const char* name);
- void SetIntAttribute(const char* name, int value);
- void DelIntAttribute(const char* name);
-
-protected:
- Text id;
- int access_time;
- List<HttpParam> attributes;
-};
-
#endif // HttpServlet_h
diff --git a/NetEx/HttpSession.cpp b/NetEx/HttpSession.cpp
new file mode 100644
index 0000000..577b1e3
--- /dev/null
+++ b/NetEx/HttpSession.cpp
@@ -0,0 +1,145 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#include "HttpSession.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "HttpParam.h"
+#include "List.h"
+#include "NetLayer.h"
+#include "Text.h"
+
+
+HttpSession::HttpSession()
+{
+ id = GenerateUniqueID();
+ access_time = NetLayer::GetUTC();
+}
+
+
+HttpSession::~HttpSession()
+{
+ attributes.destroy();
+}
+
+
+Text
+HttpSession::GetAttribute(const char* name)
+{
+ ListIter<HttpParam> iter = attributes;
+ while (++iter) {
+ HttpParam* p = iter.value();
+
+ if (p->name == name)
+ return p->value;
+ }
+
+ return Text();
+}
+
+
+void
+HttpSession::SetAttribute(const char* name, const char* value)
+{
+ ListIter<HttpParam> iter = attributes;
+ while (++iter) {
+ HttpParam* p = iter.value();
+
+ if (p->name == name) {
+ p->value = value;
+ return;
+ }
+ }
+
+ HttpParam* param = new HttpParam(name, value);
+ if (param)
+ attributes.append(param);
+}
+
+
+void
+HttpSession::DelAttribute(const char* name)
+{
+ ListIter<HttpParam> iter = attributes;
+ while (++iter) {
+ HttpParam* p = iter.value();
+
+ if (p->name == name) {
+ delete iter.removeItem();
+ return;
+ }
+ }
+}
+
+
+int
+HttpSession::GetIntAttribute(const char* name)
+{
+ ListIter<HttpParam> iter = attributes;
+ while (++iter) {
+ HttpParam* p = iter.value();
+
+ if (p->name == name) {
+ int result = ::atoi(p->value.data());
+ return result;
+ }
+ }
+
+ return 0;
+}
+
+
+void
+HttpSession::SetIntAttribute(const char* name, int value)
+{
+ char buf[32];
+ sprintf(buf, "%d", value);
+
+ ListIter<HttpParam> iter = attributes;
+ while (++iter) {
+ HttpParam* p = iter.value();
+
+ if (p->name == name) {
+ p->value = buf;
+ return;
+ }
+ }
+
+ HttpParam* param = new HttpParam(name, buf);
+ if (param)
+ attributes.append(param);
+}
+
+
+void
+HttpSession::DelIntAttribute(const char* name)
+{
+ DelAttribute(name);
+}
+
+
+Text
+HttpSession::GenerateUniqueID()
+{
+ char unique[17];
+
+ for (int i = 0; i < 16; i++) {
+ char c = rand() % 25 + 'a';
+ unique[i] = c;
+ }
+
+ unique[16] = 0;
+ return unique;
+}
+
+
+void
+HttpSession::Access()
+{
+ access_time = NetLayer::GetUTC();
+}
diff --git a/NetEx/HttpSession.h b/NetEx/HttpSession.h
new file mode 100644
index 0000000..e8d67f8
--- /dev/null
+++ b/NetEx/HttpSession.h
@@ -0,0 +1,49 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#ifndef HttpSession_h
+#define HttpSession_h
+
+#include "HttpParam.h"
+#include "List.h"
+#include "Text.h"
+
+
+class HttpSession
+{
+public:
+ static const char* TYPENAME() { return "HttpSession"; }
+
+ HttpSession();
+ virtual ~HttpSession();
+
+ int operator == (const HttpSession& s) const { return id == s.id; }
+
+ Text GenerateUniqueID();
+
+ Text GetID() const { return id; }
+ void SetID(const char* i) { id = i; }
+ int GetLastAccess() const { return access_time;}
+ void Access();
+
+ List<HttpParam>& GetAttributes() { return attributes; }
+
+ Text GetAttribute(const char* name);
+ void SetAttribute(const char* name, const char* value);
+ void DelAttribute(const char* name);
+
+ int GetIntAttribute(const char* name);
+ void SetIntAttribute(const char* name, int value);
+ void DelIntAttribute(const char* name);
+
+protected:
+ Text id;
+ int access_time;
+ List<HttpParam> attributes;
+};
+
+
+#endif // HttpSession_h