summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <Pixel>2001-10-29 15:44:12 +0000
committerPixel <Pixel>2001-10-29 15:44:12 +0000
commit2e5bed84841f33ff28dd95b77b555720c875a286 (patch)
treede6cbcbf5fa65e90e1888d52a9426373a1638c61 /lib
parent0a6190d0269392e875a479df01b152d47ea4143c (diff)
Beginning task manager
Diffstat (limited to 'lib')
-rw-r--r--lib/Buffer.cc55
-rw-r--r--lib/Confirm.cc2
-rw-r--r--lib/CopyJob.cc0
-rw-r--r--lib/Exceptions.cc22
-rw-r--r--lib/Handle.cc24
-rw-r--r--lib/HttpServ.cc9
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/Task.cc16
8 files changed, 102 insertions, 29 deletions
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
new file mode 100644
index 0000000..164c961
--- /dev/null
+++ b/lib/Buffer.cc
@@ -0,0 +1,55 @@
+#include <string.h>
+#include "Buffer.h"
+#include "General.h"
+#include "config.h"
+
+Buffer::Buffer() : Handle(-1), buffer(NULL), realsiz(0), bufsiz(0), ptr(0) { }
+
+Buffer::~Buffer() {
+ free(buffer);
+}
+
+ssize_t Buffer::write(const void *buf, size_t count) {
+ if (count + realsiz > bufsiz) {
+ int numblocks = (count + realsiz) / realloc_threshold;
+ int remains = (count + realsiz) % realloc_threshold;
+ buffer = (char *) realloc(buffer, bufsiz = ((numblocks + (remains ? 1 : 0)) * realloc_threshold));
+ }
+ memcpy(buffer + realsiz, buf, count);
+ realsiz += count;
+
+ return count;
+}
+
+ssize_t Buffer::read(void *buf, size_t count) {
+ count = MIN(count, realsiz - ptr);
+
+ if (!count) {
+ return 0;
+ }
+
+ memcpy(buf, buffer + ptr, count);
+ ptr += count;
+
+ if (ptr >= realloc_threshold) {
+ int numblocks = (ptr / realloc_threshold) - (bufsiz / realloc_threshold);
+ memmove(buffer, buffer + numblocks * realloc_threshold, numblocks * realloc_threshold);
+ buffer = (char *) realloc(buffer, bufsiz = (numblocks * realloc_threshold));
+ ptr -= numblocks * realloc_threshold;
+ realsiz -= numblocks * realloc_threshold;
+ }
+
+ return count;
+}
+
+bool Buffer::CanRead() {
+ return true;
+}
+
+bool Buffer::CanWrite() {
+ return true;
+}
+
+String Buffer::GetName() {
+ return "Buffer";
+}
diff --git a/lib/Confirm.cc b/lib/Confirm.cc
index 5177f8b..0fbb902 100644
--- a/lib/Confirm.cc
+++ b/lib/Confirm.cc
@@ -9,10 +9,12 @@ void Confirm::Do(Variables * v, Handle * h) {
SendHead(h);
(*h) << msg << "<CENTER><TABLE BORDER=0><tr><td>" << endnl <<
"<FORM METHOD=\"POST\" ACTION=\"/bin/" << (NYes ? NYes->GetURL() : "start") << "\">" << endnl <<
+ "<INPUT TYPE=\"HIDDEN\" VALUE=\"yes\" NAME=\"confirm\">" << endnl <<
"<INPUT TYPE=\"SUBMIT\" VALUE=\" Oui \">" << endnl;
v->Dump(h);
(*h) << "</FORM></td><td>" << endnl <<
"<FORM METHOD=\"POST\" ACTION=\"/bin/" << (NNo ? NNo->GetURL() : "start") << "\">" << endnl <<
+ "<INPUT TYPE=\"HIDDEN\" VALUE=\"no\" NAME=\"confirm\">" << endnl <<
"<INPUT TYPE=\"SUBMIT\" VALUE=\" Non \">" << endnl;
v->Dump(h);
(*h) << "</FORM></td></tr></TABLE></CENTER>" << endnl;
diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/CopyJob.cc
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc
index 0376fee..3989836 100644
--- a/lib/Exceptions.cc
+++ b/lib/Exceptions.cc
@@ -9,24 +9,6 @@
char GeneralException::t[BUFSIZ];
-char * Base::strdup(const char * s) const {
- return xstrdup(s);
-}
-
-void * Base::malloc(ssize_t s) const {
- return xmalloc(s);
-}
-
-
-void * Base::operator new(size_t s) {
- return memset(xmalloc(s), 0, s);
-}
-
-void * Base::operator new(size_t s, void * p) {
- memset(p, 0, s);
- return p;
-}
-
GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) { }
GeneralException::GeneralException() : msg(0) { }
GeneralException::GeneralException(const GeneralException & e) : msg(strdup(e.msg)) { }
@@ -75,10 +57,14 @@ void * xmalloc(ssize_t s) throw (MemoryException) {
throw MemoryException(s);
}
+ memset(r, 0, s);
+
return r;
}
+#ifdef OVER_FREE
#undef free
+#endif
void xfree(void *& p) {
if (p) {
diff --git a/lib/Handle.cc b/lib/Handle.cc
index 4824b43..c3efc55 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -6,11 +6,11 @@
#include "Handle.h"
#include "config.h"
-Handle::Handle(const Handle & nh) : h(dup(nh.h)), closed(false), nonblock(false) { }
+Handle::Handle(const Handle & nh) : h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(false), nonblock(false) { }
Handle::~Handle() {
- if (h != -1) {
- close(h);
+ if (h >= 0) {
+ ::close(h);
}
}
@@ -73,7 +73,7 @@ ssize_t Handle::read(void *buf, size_t count) throw (IOException) {
}
if (!r) {
- close(h);
+ ::close(h);
closed = true;
}
@@ -90,7 +90,9 @@ bool Handle::IsNonBlock(void) {
void Handle::SetNonBlock(void) {
nonblock = true;
- fcntl(h, F_SETFL, O_NONBLOCK);
+ if (h >= 0) {
+ fcntl(h, F_SETFL, O_NONBLOCK);
+ }
}
Handle & operator<<(Handle & h, const String & s) {
@@ -124,3 +126,15 @@ Handle & operator>>(Handle & h, String & s) {
s.set("%s", t);
return h;
}
+
+void Handle::close() {
+ if (IsClosed()) {
+ return;
+ }
+
+ if (h >= 0) {
+ ::close(h);
+ }
+
+ closed = 1;
+}
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index 97152a9..b354f69 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -1,6 +1,7 @@
+#include "Socket.h"
#include "Action.h"
#include "HttpServ.h"
-#include "Socket.h"
+#include "Buffer.h"
#include "config.h"
String endhl = "\r\n", endnl = "\n";
@@ -13,12 +14,11 @@ HttpServ::HttpServ(int port, const String & nname) : name(nname), localport(port
void HttpServ::MainLoop(Action * p) {
while (1) {
- ProcessRequest(p);
+ ProcessRequest(p, Socket(Listener.Accept()));
}
}
-void HttpServ::ProcessRequest(Action * p) {
- Socket s(Listener.Accept());
+void HttpServ::ProcessRequest(Action * p, Socket s) {
String file, domain, t;
Action * f;
int len;
@@ -31,7 +31,6 @@ void HttpServ::ProcessRequest(Action * p) {
bool post = ParseUri(file, domain, s);
-
len = -1;
do {
s >> t;
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 91076a8..1135e12 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -7,6 +7,7 @@ lib_LTLIBRARIES = libBaltisot.la
libBaltisot_la_SOURCES = Exceptions.cc Handle.cc Output.cc String.cc\
Socket.cc Input.cc HttpServ.cc Variables.cc Action.cc Menu.cc Message.cc\
- Form.cc Confirm.cc Table.cc checkargs.c datecalc.c IRC.cc Task.cc
+ Form.cc Confirm.cc Table.cc checkargs.c datecalc.c IRC.cc Task.cc Buffer.cc\
+ Misc.cc
libBaltisot_la_LDFLAGS = -release $(Baltisot_VERSION_INFO)
diff --git a/lib/Task.cc b/lib/Task.cc
index e69de29..79c39e1 100644
--- a/lib/Task.cc
+++ b/lib/Task.cc
@@ -0,0 +1,16 @@
+#include "Task.h"
+
+Task::Task() {}
+Task::~Task() {}
+
+int Task::Do() {
+ return TASK_ON_HOLD;
+}
+
+int Task::Run() {
+ return (state = Do());
+}
+
+int Task::GetState() {
+ return state;
+}