source: rtems/cpukit/httpd/websuemf.c @ a6b4c0df

4.104.114.84.95
Last change on this file since a6b4c0df was a6b4c0df, checked in by Joel Sherrill <joel.sherrill@…>, on 09/01/00 at 10:57:21

2000-08-30 Joel Sherrill <joel@…>

  • Merged version 2.1 of GoAhead? webserver. This update was submitted by Antti P Miettinen <antti.p.miettinen@…>.
  • 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.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * websuemf.c -- GoAhead Micro Embedded Management Framework
3 *
4 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
5 *
6 * See the file "license.txt" for usage and redistribution license requirements
7 */
8
9/********************************** Description *******************************/
10
11/*
12 *      This modules provides compatibility with the full GoAhead EMF.
13 */
14
15/*********************************** Includes *********************************/
16
17#include        "ejIntrn.h"
18#include        "wsIntrn.h"
19
20/*********************************** Defines **********************************/
21
22/*
23 *      This structure stores scheduled events.
24 */
25typedef struct {
26        void    (*routine)(void *arg, int id);
27        void    *arg;
28        time_t  at;
29        int             schedid;
30} sched_t;
31
32/*********************************** Locals ***********************************/
33
34static sched_t          **sched;
35static int                      schedMax;
36
37/************************************* Code ***********************************/
38/*
39 *      Evaluate a script
40 */
41
42int scriptEval(int engine, char_t *cmd, char_t **result, int chan)
43{
44        int             ejid;
45
46        if (engine == EMF_SCRIPT_EJSCRIPT) {
47                ejid = (int) chan;
48                if (ejEval(ejid, cmd, NULL) ) {
49                        return 0;
50                } else {
51                        return -1;
52                }
53        }
54        return -1;
55}
56
57/******************************************************************************/
58/*
59 * Compare strings, ignoring case:  normal strcmp return codes.
60 *
61 *      WARNING: It is not good form to increment or decrement pointers inside a
62 *      "call" to tolower et al. These can be MACROS, and have undesired side
63 *      effects.
64 */
65
66int strcmpci(char_t *s1, char_t *s2)
67{
68        int             rc;
69
70        a_assert(s1 && s2);
71        if (s1 == NULL || s2 == NULL) {
72                return 0;
73        }
74
75        if (s1 == s2) {
76                return 0;
77        }
78
79        do {
80                rc = gtolower(*s1) - gtolower(*s2);
81                if (*s1 == '\0') {
82                        break;
83                }
84                s1++;
85                s2++;
86        } while (rc == 0);
87        return rc;
88}
89
90/******************************************************************************/
91/*
92 *      This function is called when a scheduled process time has come.
93 */
94
95void TimerProc(int schedid)
96{
97        sched_t *s;
98
99        a_assert(0 <= schedid && schedid < schedMax);
100        s = sched[schedid];
101        a_assert(s);
102
103        (s->routine)(s->arg, s->schedid);
104}
105
106/******************************************************************************/
107/*
108 *      Schedule an event in delay milliseconds time. We will use 1 second
109 *      granularity for webServer.
110 */
111
112int emfSchedCallback(int delay, emfSchedProc *proc, void *arg)
113{
114        sched_t *s;
115        int             schedid;
116
117        if ((schedid = hAllocEntry((void***) &sched, &schedMax,
118                sizeof(sched_t))) < 0) {
119                return -1;
120        }
121        s = sched[schedid];
122        s->routine = proc;
123        s->arg = arg;
124        s->schedid = schedid;
125
126/*
127 *      Round the delay up to seconds.
128 */
129        s->at = ((delay + 500) / 1000) + time(0);
130
131        return schedid;
132}
133
134/******************************************************************************/
135/*
136 *      Reschedule to a new delay.
137 */
138
139void emfReschedCallback(int schedid, int delay)
140{
141        sched_t *s;
142
143        if (sched == NULL || schedid == -1 || schedid >= schedMax ||
144                (s = sched[schedid]) == NULL) {
145                return;
146        }
147        s->at = ((delay + 500) / 1000) + time(0);
148}
149
150/******************************************************************************/
151
152void emfUnschedCallback(int schedid)
153{
154        sched_t *s;
155
156        if (sched == NULL || schedid == -1 || schedid >= schedMax ||
157                (s = sched[schedid]) == NULL) {
158                return;
159        }
160        bfree(B_L, s);
161        schedMax = hFree((void***) &sched, schedid);
162}
163
164/******************************************************************************/
165/*
166 *      Take the tasks off the queue in a round robin fashion.
167 */
168
169void emfSchedProcess()
170{
171        sched_t         *s;
172        int                     schedid;
173        static int      next = 0;       
174
175/*
176 *      If schedMax is 0, there are no tasks scheduled, so just return.
177 */
178        if (schedMax <= 0) {
179                return;
180        }
181
182/*
183 *      If next >= schedMax, the schedule queue was reduced in our absence
184 *      so reset next to 0 to start from the begining of the queue again.
185 */
186        if (next >= schedMax) {
187                next = 0;
188        }
189
190        schedid = next;
191        for (;;) {
192                if ((s = sched[schedid]) != NULL &&     (int)s->at <= (int)time(0)) {
193                        TimerProc(schedid);
194                        next = schedid + 1;
195                        return;
196                }
197                if (++schedid >= schedMax) {
198                        schedid = 0;
199                }
200                if (schedid == next) {
201/*
202 *                      We've gone all the way through the queue without finding
203 *                      anything to do so just return.
204 */
205                        return;
206                }
207        }
208}
209
210/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.