summaryrefslogtreecommitdiffstats
path: root/cpukit/httpd/websuemf.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2000-09-01 10:57:21 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2000-09-01 10:57:21 +0000
commita6b4c0df5f74d1238337f41d1d13f4f168ad01f1 (patch)
treeae171319a76a707e9f3aa638b7c690e40c9f5d5e /cpukit/httpd/websuemf.c
parent2000-08-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de> (diff)
downloadrtems-a6b4c0df5f74d1238337f41d1d13f4f168ad01f1.tar.bz2
2000-08-30 Joel Sherrill <joel@OARcorp.com>
* Merged version 2.1 of GoAhead webserver. This update was submitted by Antti P Miettinen <antti.p.miettinen@nokia.com>. * NOTES, base64.c, ejIntrn.h, emfdb.c, emfdb.h, md5.h, md5c.c, um.c, um.h: New files. * wbase64.c: Removed. * Makefile.am, asp.c, balloc.c, default.c, ej.h, ejlex.c, ejparse.c, form.c, h.c, handler.c, mime.c, misc.c, ringq.c, rom.c, security.c, socket.c, sym.c, uemf.c, uemf.h, url.c, value.c, webcomp.c, webmain.c, webpage.c, webrom.c, webs.c, webs.h, websuemf.c, wsIntrn.h: Modified.
Diffstat (limited to 'cpukit/httpd/websuemf.c')
-rw-r--r--cpukit/httpd/websuemf.c175
1 files changed, 173 insertions, 2 deletions
diff --git a/cpukit/httpd/websuemf.c b/cpukit/httpd/websuemf.c
index 48a30f25d0..2315d9d234 100644
--- a/cpukit/httpd/websuemf.c
+++ b/cpukit/httpd/websuemf.c
@@ -1,7 +1,7 @@
/*
* websuemf.c -- GoAhead Micro Embedded Management Framework
*
- * Copyright (c) Go Ahead Software Inc., 1995-1999. All Rights Reserved.
+ * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
*
* See the file "license.txt" for usage and redistribution license requirements
*/
@@ -14,14 +14,32 @@
/*********************************** Includes *********************************/
+#include "ejIntrn.h"
#include "wsIntrn.h"
+/*********************************** Defines **********************************/
+
+/*
+ * This structure stores scheduled events.
+ */
+typedef struct {
+ void (*routine)(void *arg, int id);
+ void *arg;
+ time_t at;
+ int schedid;
+} sched_t;
+
+/*********************************** Locals ***********************************/
+
+static sched_t **sched;
+static int schedMax;
+
/************************************* Code ***********************************/
/*
* Evaluate a script
*/
-int scriptEval(int engine, char_t* cmd, char_t** result, int chan)
+int scriptEval(int engine, char_t *cmd, char_t **result, int chan)
{
int ejid;
@@ -37,3 +55,156 @@ int scriptEval(int engine, char_t* cmd, char_t** result, int chan)
}
/******************************************************************************/
+/*
+ * Compare strings, ignoring case: normal strcmp return codes.
+ *
+ * WARNING: It is not good form to increment or decrement pointers inside a
+ * "call" to tolower et al. These can be MACROS, and have undesired side
+ * effects.
+ */
+
+int strcmpci(char_t *s1, char_t *s2)
+{
+ int rc;
+
+ a_assert(s1 && s2);
+ if (s1 == NULL || s2 == NULL) {
+ return 0;
+ }
+
+ if (s1 == s2) {
+ return 0;
+ }
+
+ do {
+ rc = gtolower(*s1) - gtolower(*s2);
+ if (*s1 == '\0') {
+ break;
+ }
+ s1++;
+ s2++;
+ } while (rc == 0);
+ return rc;
+}
+
+/******************************************************************************/
+/*
+ * This function is called when a scheduled process time has come.
+ */
+
+void TimerProc(int schedid)
+{
+ sched_t *s;
+
+ a_assert(0 <= schedid && schedid < schedMax);
+ s = sched[schedid];
+ a_assert(s);
+
+ (s->routine)(s->arg, s->schedid);
+}
+
+/******************************************************************************/
+/*
+ * Schedule an event in delay milliseconds time. We will use 1 second
+ * granularity for webServer.
+ */
+
+int emfSchedCallback(int delay, emfSchedProc *proc, void *arg)
+{
+ sched_t *s;
+ int schedid;
+
+ if ((schedid = hAllocEntry((void***) &sched, &schedMax,
+ sizeof(sched_t))) < 0) {
+ return -1;
+ }
+ s = sched[schedid];
+ s->routine = proc;
+ s->arg = arg;
+ s->schedid = schedid;
+
+/*
+ * Round the delay up to seconds.
+ */
+ s->at = ((delay + 500) / 1000) + time(0);
+
+ return schedid;
+}
+
+/******************************************************************************/
+/*
+ * Reschedule to a new delay.
+ */
+
+void emfReschedCallback(int schedid, int delay)
+{
+ sched_t *s;
+
+ if (sched == NULL || schedid == -1 || schedid >= schedMax ||
+ (s = sched[schedid]) == NULL) {
+ return;
+ }
+ s->at = ((delay + 500) / 1000) + time(0);
+}
+
+/******************************************************************************/
+
+void emfUnschedCallback(int schedid)
+{
+ sched_t *s;
+
+ if (sched == NULL || schedid == -1 || schedid >= schedMax ||
+ (s = sched[schedid]) == NULL) {
+ return;
+ }
+ bfree(B_L, s);
+ schedMax = hFree((void***) &sched, schedid);
+}
+
+/******************************************************************************/
+/*
+ * Take the tasks off the queue in a round robin fashion.
+ */
+
+void emfSchedProcess()
+{
+ sched_t *s;
+ int schedid;
+ static int next = 0;
+
+/*
+ * If schedMax is 0, there are no tasks scheduled, so just return.
+ */
+ if (schedMax <= 0) {
+ return;
+ }
+
+/*
+ * If next >= schedMax, the schedule queue was reduced in our absence
+ * so reset next to 0 to start from the begining of the queue again.
+ */
+ if (next >= schedMax) {
+ next = 0;
+ }
+
+ schedid = next;
+ for (;;) {
+ if ((s = sched[schedid]) != NULL && (int)s->at <= (int)time(0)) {
+ TimerProc(schedid);
+ next = schedid + 1;
+ return;
+ }
+ if (++schedid >= schedMax) {
+ schedid = 0;
+ }
+ if (schedid == next) {
+/*
+ * We've gone all the way through the queue without finding
+ * anything to do so just return.
+ */
+ return;
+ }
+ }
+}
+
+/******************************************************************************/