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

4.104.114.84.95
Last change on this file since bfb4c547 was bfb4c547, checked in by Joel Sherrill <joel.sherrill@…>, on 03/05/04 at 18:14:27

2004-03-05 Joel Sherrill <joel@…>

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