summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ReadJob.cc4
-rw-r--r--lib/Regex.cc26
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/ReadJob.cc b/lib/ReadJob.cc
index d5cabca..a29f641 100644
--- a/lib/ReadJob.cc
+++ b/lib/ReadJob.cc
@@ -1,7 +1,7 @@
#include "ReadJob.h"
#include "HttpServ.h"
-ReadJob::ReadJob(Handle * as, Handle * ad) : s(as), d(ad) {
+ReadJob::ReadJob(Handle * as, Handle * ad, const Regex & aregex) : s(as), d(ad), regex(&aregex) {
s->SetNonBlock();
d->SetNonBlock();
WaitFor(s, W4_READING);
@@ -31,7 +31,7 @@ int ReadJob::Do() throw (GeneralException) {
Suspend(TASK_ON_HOLD);
}
current = 0;
- if (buff == "") return TASK_DONE;
+ if (regex->Match(buff)) return TASK_DONE;
}
if (!s->IsClosed()) {
diff --git a/lib/Regex.cc b/lib/Regex.cc
index 2ef2c8e..9b70d68 100644
--- a/lib/Regex.cc
+++ b/lib/Regex.cc
@@ -1 +1,25 @@
-#include "Regex.h" \ No newline at end of file
+#include "Regex.h"
+
+char t[1024];
+
+Regex empty("$^"), any(".*");
+
+Regex::Regex(const String & regex, int cflags, int aeflags) throw (GeneralException) : eflags(aeflags) {
+ int r;
+ if ((r = regcomp(&preg, regex.to_charp(), cflags | REG_NOSUB))) {
+ regerror(r, &preg, t, sizeof(t));
+ throw GeneralException(String("Regex \"") + regex + "\" failed to compile: " + t + "\n");
+ }
+}
+
+Regex::~Regex() {
+ regfree(&preg);
+}
+
+bool Regex::Match(const String & s) const {
+ if (regexec(&preg, s.to_charp(), 0, 0, eflags)) {
+ return false;
+ } else {
+ return true;
+ }
+}