os: Add CryptoAPI as a choice of SHA1 implementation
[xserver/hramrach.git] / dix / dixutils.c
blob9eb54893a11bc8c8bf5c87224140107c486bc6b0
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27 All Rights Reserved
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 SOFTWARE.
45 ******************************************************************/
49 (c)Copyright 1988,1991 Adobe Systems Incorporated. All rights reserved.
51 Permission to use, copy, modify, distribute, and sublicense this software and its
52 documentation for any purpose and without fee is hereby granted, provided that
53 the above copyright notices appear in all copies and that both those copyright
54 notices and this permission notice appear in supporting documentation and that
55 the name of Adobe Systems Incorporated not be used in advertising or publicity
56 pertaining to distribution of the software without specific, written prior
57 permission. No trademark license to use the Adobe trademarks is hereby
58 granted. If the Adobe trademark "Display PostScript"(tm) is used to describe
59 this software, its functionality or for any other purpose, such use shall be
60 limited to a statement that this software works in conjunction with the Display
61 PostScript system. Proper trademark attribution to reflect Adobe's ownership
62 of the trademark shall be given whenever any such reference to the Display
63 PostScript system is made.
65 ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY
66 PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ADOBE
67 DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
68 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
69 INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE TO YOU
70 OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
71 DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,NEGLIGENCE, STRICT
72 LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
73 PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT PROVIDE ANY TRAINING OR OTHER
74 SUPPORT FOR THE SOFTWARE.
76 Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
77 Incorporated which may be registered in certain jurisdictions.
79 Author: Adobe Systems Incorporated
83 #ifdef HAVE_DIX_CONFIG_H
84 #include <dix-config.h>
85 #endif
87 #include <X11/X.h>
88 #include <X11/Xmd.h>
89 #include "misc.h"
90 #include "windowstr.h"
91 #include "dixstruct.h"
92 #include "pixmapstr.h"
93 #include "gcstruct.h"
94 #include "scrnintstr.h"
95 #define XK_LATIN1
96 #include <X11/keysymdef.h>
97 #include "xace.h"
100 * CompareTimeStamps returns -1, 0, or +1 depending on if the first
101 * argument is less than, equal to or greater than the second argument.
105 CompareTimeStamps(TimeStamp a, TimeStamp b)
107 if (a.months < b.months)
108 return EARLIER;
109 if (a.months > b.months)
110 return LATER;
111 if (a.milliseconds < b.milliseconds)
112 return EARLIER;
113 if (a.milliseconds > b.milliseconds)
114 return LATER;
115 return SAMETIME;
119 * convert client times to server TimeStamps
122 #define HALFMONTH ((unsigned long) 1<<31)
123 TimeStamp
124 ClientTimeToServerTime(CARD32 c)
126 TimeStamp ts;
128 if (c == CurrentTime)
129 return currentTime;
130 ts.months = currentTime.months;
131 ts.milliseconds = c;
132 if (c > currentTime.milliseconds) {
133 if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH)
134 ts.months -= 1;
136 else if (c < currentTime.milliseconds) {
137 if (((unsigned long) currentTime.milliseconds - c) > HALFMONTH)
138 ts.months += 1;
140 return ts;
144 * ISO Latin-1 case conversion routine
146 * this routine always null-terminates the result, so
147 * beware of too-small buffers
150 static unsigned char
151 ISOLatin1ToLower(unsigned char source)
153 unsigned char dest;
155 if ((source >= XK_A) && (source <= XK_Z))
156 dest = source + (XK_a - XK_A);
157 else if ((source >= XK_Agrave) && (source <= XK_Odiaeresis))
158 dest = source + (XK_agrave - XK_Agrave);
159 else if ((source >= XK_Ooblique) && (source <= XK_Thorn))
160 dest = source + (XK_oslash - XK_Ooblique);
161 else
162 dest = source;
163 return dest;
167 CompareISOLatin1Lowered(const unsigned char *s1, int s1len,
168 const unsigned char *s2, int s2len)
170 unsigned char c1, c2;
172 for (;;) {
173 /* note -- compare against zero so that -1 ignores len */
174 c1 = s1len-- ? *s1++ : '\0';
175 c2 = s2len-- ? *s2++ : '\0';
176 if (!c1 ||
177 (c1 != c2 &&
178 (c1 = ISOLatin1ToLower(c1)) != (c2 = ISOLatin1ToLower(c2))))
179 break;
181 return (int) c1 - (int) c2;
185 * dixLookupWindow and dixLookupDrawable:
186 * Look up the window/drawable taking into account the client doing the
187 * lookup, the type of drawable desired, and the type of access desired.
188 * Return Success with *pDraw set if the window/drawable exists and the client
189 * is allowed access, else return an error code with *pDraw set to NULL. The
190 * access mask values are defined in resource.h. The type mask values are
191 * defined in pixmap.h, with zero equivalent to M_DRAWABLE.
194 dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
195 Mask type, Mask access)
197 DrawablePtr pTmp;
198 int rc;
200 *pDraw = NULL;
202 rc = dixLookupResourceByClass((pointer *) &pTmp, id, RC_DRAWABLE, client,
203 access);
205 if (rc != Success)
206 client->errorValue = id;
208 if (rc == BadValue)
209 return BadDrawable;
210 if (rc != Success)
211 return rc;
212 if (!((1 << pTmp->type) & (type ? type : M_DRAWABLE)))
213 return BadMatch;
215 *pDraw = pTmp;
216 return Success;
220 dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access)
222 int rc;
224 rc = dixLookupDrawable((DrawablePtr *) pWin, id, client, M_WINDOW, access);
225 /* dixLookupDrawable returns BadMatch iff id is a valid Drawable
226 but is not a Window. Users of dixLookupWindow expect a BadWindow
227 error in this case; they don't care that it's a valid non-Window XID */
228 if (rc == BadMatch)
229 rc = BadWindow;
230 /* Similarly, users of dixLookupWindow don't want BadDrawable. */
231 if (rc == BadDrawable)
232 rc = BadWindow;
233 return rc;
237 dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access)
239 return dixLookupResourceByType((pointer *) pGC, id, RT_GC, client, access);
243 dixLookupFontable(FontPtr *pFont, XID id, ClientPtr client, Mask access)
245 int rc;
246 GC *pGC;
248 client->errorValue = id; /* EITHER font or gc */
249 rc = dixLookupResourceByType((pointer *) pFont, id, RT_FONT, client,
250 access);
251 if (rc != BadFont)
252 return rc;
253 rc = dixLookupResourceByType((pointer *) &pGC, id, RT_GC, client, access);
254 if (rc == BadGC)
255 return BadFont;
256 if (rc == Success)
257 *pFont = pGC->font;
258 return rc;
262 dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
264 pointer pRes;
265 int rc = BadValue, clientIndex = CLIENT_ID(rid);
267 if (!clientIndex || !clients[clientIndex] || (rid & SERVER_BIT))
268 goto bad;
270 rc = dixLookupResourceByClass(&pRes, rid, RC_ANY, client, DixGetAttrAccess);
271 if (rc != Success)
272 goto bad;
274 rc = XaceHook(XACE_CLIENT_ACCESS, client, clients[clientIndex], access);
275 if (rc != Success)
276 goto bad;
278 *pClient = clients[clientIndex];
279 return Success;
280 bad:
281 if (client)
282 client->errorValue = rid;
283 *pClient = NULL;
284 return rc;
288 AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode,
289 Bool toRoot, Bool map)
291 int numnow;
292 SaveSetElt *pTmp = NULL;
293 int j;
295 numnow = client->numSaved;
296 j = 0;
297 if (numnow) {
298 pTmp = client->saveSet;
299 while ((j < numnow) && (SaveSetWindow(pTmp[j]) != (pointer) pWin))
300 j++;
302 if (mode == SetModeInsert) {
303 if (j < numnow) /* duplicate */
304 return Success;
305 numnow++;
306 pTmp = (SaveSetElt *) realloc(client->saveSet, sizeof(*pTmp) * numnow);
307 if (!pTmp)
308 return BadAlloc;
309 client->saveSet = pTmp;
310 client->numSaved = numnow;
311 SaveSetAssignWindow(client->saveSet[numnow - 1], pWin);
312 SaveSetAssignToRoot(client->saveSet[numnow - 1], toRoot);
313 SaveSetAssignMap(client->saveSet[numnow - 1], map);
314 return Success;
316 else if ((mode == SetModeDelete) && (j < numnow)) {
317 while (j < numnow - 1) {
318 pTmp[j] = pTmp[j + 1];
319 j++;
321 numnow--;
322 if (numnow) {
323 pTmp =
324 (SaveSetElt *) realloc(client->saveSet, sizeof(*pTmp) * numnow);
325 if (pTmp)
326 client->saveSet = pTmp;
328 else {
329 free(client->saveSet);
330 client->saveSet = (SaveSetElt *) NULL;
332 client->numSaved = numnow;
333 return Success;
335 return Success;
338 void
339 DeleteWindowFromAnySaveSet(WindowPtr pWin)
341 int i;
342 ClientPtr client;
344 for (i = 0; i < currentMaxClients; i++) {
345 client = clients[i];
346 if (client && client->numSaved)
347 (void) AlterSaveSetForClient(client, pWin, SetModeDelete, FALSE,
348 TRUE);
352 /* No-op Don't Do Anything : sometimes we need to be able to call a procedure
353 * that doesn't do anything. For example, on screen with only static
354 * colormaps, if someone calls install colormap, it's easier to have a dummy
355 * procedure to call than to check if there's a procedure
357 void
358 NoopDDA(void)
362 typedef struct _BlockHandler {
363 BlockHandlerProcPtr BlockHandler;
364 WakeupHandlerProcPtr WakeupHandler;
365 pointer blockData;
366 Bool deleted;
367 } BlockHandlerRec, *BlockHandlerPtr;
369 static BlockHandlerPtr handlers;
370 static int numHandlers;
371 static int sizeHandlers;
372 static Bool inHandler;
373 static Bool handlerDeleted;
377 * \param pTimeout DIX doesn't want to know how OS represents time
378 * \param pReadMask nor how it represents the det of descriptors
380 void
381 BlockHandler(pointer pTimeout, pointer pReadmask)
383 int i, j;
385 ++inHandler;
386 for (i = 0; i < screenInfo.numScreens; i++)
387 (*screenInfo.screens[i]->BlockHandler) (i,
388 screenInfo.screens[i]->
389 blockData, pTimeout, pReadmask);
390 for (i = 0; i < numHandlers; i++)
391 if (!handlers[i].deleted)
392 (*handlers[i].BlockHandler) (handlers[i].blockData,
393 pTimeout, pReadmask);
394 if (handlerDeleted) {
395 for (i = 0; i < numHandlers;)
396 if (handlers[i].deleted) {
397 for (j = i; j < numHandlers - 1; j++)
398 handlers[j] = handlers[j + 1];
399 numHandlers--;
401 else
402 i++;
403 handlerDeleted = FALSE;
405 --inHandler;
410 * \param result 32 bits of undefined result from the wait
411 * \param pReadmask the resulting descriptor mask
413 void
414 WakeupHandler(int result, pointer pReadmask)
416 int i, j;
418 ++inHandler;
419 for (i = numHandlers - 1; i >= 0; i--)
420 if (!handlers[i].deleted)
421 (*handlers[i].WakeupHandler) (handlers[i].blockData,
422 result, pReadmask);
423 for (i = 0; i < screenInfo.numScreens; i++)
424 (*screenInfo.screens[i]->WakeupHandler) (i,
425 screenInfo.screens[i]->
426 wakeupData, result, pReadmask);
427 if (handlerDeleted) {
428 for (i = 0; i < numHandlers;)
429 if (handlers[i].deleted) {
430 for (j = i; j < numHandlers - 1; j++)
431 handlers[j] = handlers[j + 1];
432 numHandlers--;
434 else
435 i++;
436 handlerDeleted = FALSE;
438 --inHandler;
442 * Reentrant with BlockHandler and WakeupHandler, except wakeup won't
443 * get called until next time
445 Bool
446 RegisterBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
447 WakeupHandlerProcPtr wakeupHandler,
448 pointer blockData)
450 BlockHandlerPtr new;
452 if (numHandlers >= sizeHandlers) {
453 new = (BlockHandlerPtr) realloc(handlers, (numHandlers + 1) *
454 sizeof(BlockHandlerRec));
455 if (!new)
456 return FALSE;
457 handlers = new;
458 sizeHandlers = numHandlers + 1;
460 handlers[numHandlers].BlockHandler = blockHandler;
461 handlers[numHandlers].WakeupHandler = wakeupHandler;
462 handlers[numHandlers].blockData = blockData;
463 handlers[numHandlers].deleted = FALSE;
464 numHandlers = numHandlers + 1;
465 return TRUE;
468 void
469 RemoveBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
470 WakeupHandlerProcPtr wakeupHandler,
471 pointer blockData)
473 int i;
475 for (i = 0; i < numHandlers; i++)
476 if (handlers[i].BlockHandler == blockHandler &&
477 handlers[i].WakeupHandler == wakeupHandler &&
478 handlers[i].blockData == blockData) {
479 if (inHandler) {
480 handlerDeleted = TRUE;
481 handlers[i].deleted = TRUE;
483 else {
484 for (; i < numHandlers - 1; i++)
485 handlers[i] = handlers[i + 1];
486 numHandlers--;
488 break;
492 void
493 InitBlockAndWakeupHandlers(void)
495 free(handlers);
496 handlers = (BlockHandlerPtr) 0;
497 numHandlers = 0;
498 sizeHandlers = 0;
502 * A general work queue. Perform some task before the server
503 * sleeps for input.
506 WorkQueuePtr workQueue;
507 static WorkQueuePtr *workQueueLast = &workQueue;
509 void
510 ProcessWorkQueue(void)
512 WorkQueuePtr q, *p;
514 p = &workQueue;
516 * Scan the work queue once, calling each function. Those
517 * which return TRUE are removed from the queue, otherwise
518 * they will be called again. This must be reentrant with
519 * QueueWorkProc.
521 while ((q = *p)) {
522 if ((*q->function) (q->client, q->closure)) {
523 /* remove q from the list */
524 *p = q->next; /* don't fetch until after func called */
525 free(q);
527 else {
528 p = &q->next; /* don't fetch until after func called */
531 workQueueLast = p;
534 void
535 ProcessWorkQueueZombies(void)
537 WorkQueuePtr q, *p;
539 p = &workQueue;
540 while ((q = *p)) {
541 if (q->client && q->client->clientGone) {
542 (void) (*q->function) (q->client, q->closure);
543 /* remove q from the list */
544 *p = q->next; /* don't fetch until after func called */
545 free(q);
547 else {
548 p = &q->next; /* don't fetch until after func called */
551 workQueueLast = p;
554 Bool
555 QueueWorkProc(Bool (*function)
556 (ClientPtr /* pClient */ , pointer /* closure */ ),
557 ClientPtr client, pointer closure)
559 WorkQueuePtr q;
561 q = malloc(sizeof *q);
562 if (!q)
563 return FALSE;
564 q->function = function;
565 q->client = client;
566 q->closure = closure;
567 q->next = NULL;
568 *workQueueLast = q;
569 workQueueLast = &q->next;
570 return TRUE;
574 * Manage a queue of sleeping clients, awakening them
575 * when requested, by using the OS functions IgnoreClient
576 * and AttendClient. Note that this *ignores* the troubles
577 * with request data interleaving itself with events, but
578 * we'll leave that until a later time.
581 typedef struct _SleepQueue {
582 struct _SleepQueue *next;
583 ClientPtr client;
584 ClientSleepProcPtr function;
585 pointer closure;
586 } SleepQueueRec, *SleepQueuePtr;
588 static SleepQueuePtr sleepQueue = NULL;
590 Bool
591 ClientSleep(ClientPtr client, ClientSleepProcPtr function, pointer closure)
593 SleepQueuePtr q;
595 q = malloc(sizeof *q);
596 if (!q)
597 return FALSE;
599 IgnoreClient(client);
600 q->next = sleepQueue;
601 q->client = client;
602 q->function = function;
603 q->closure = closure;
604 sleepQueue = q;
605 return TRUE;
608 Bool
609 ClientSignal(ClientPtr client)
611 SleepQueuePtr q;
613 for (q = sleepQueue; q; q = q->next)
614 if (q->client == client) {
615 return QueueWorkProc(q->function, q->client, q->closure);
617 return FALSE;
620 void
621 ClientWakeup(ClientPtr client)
623 SleepQueuePtr q, *prev;
625 prev = &sleepQueue;
626 while ((q = *prev)) {
627 if (q->client == client) {
628 *prev = q->next;
629 free(q);
630 if (client->clientGone)
631 /* Oops -- new zombie cleanup code ensures this only
632 * happens from inside CloseDownClient; don't want to
633 * recurse here...
635 /* CloseDownClient(client) */ ;
636 else
637 AttendClient(client);
638 break;
640 prev = &q->next;
644 Bool
645 ClientIsAsleep(ClientPtr client)
647 SleepQueuePtr q;
649 for (q = sleepQueue; q; q = q->next)
650 if (q->client == client)
651 return TRUE;
652 return FALSE;
656 * Generic Callback Manager
659 /* ===== Private Procedures ===== */
661 static int numCallbackListsToCleanup = 0;
662 static CallbackListPtr **listsToCleanup = NULL;
664 static Bool
665 _AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
667 CallbackPtr cbr;
669 cbr = malloc(sizeof(CallbackRec));
670 if (!cbr)
671 return FALSE;
672 cbr->proc = callback;
673 cbr->data = data;
674 cbr->next = (*pcbl)->list;
675 cbr->deleted = FALSE;
676 (*pcbl)->list = cbr;
677 return TRUE;
680 static Bool
681 _DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
683 CallbackListPtr cbl = *pcbl;
684 CallbackPtr cbr, pcbr;
686 for (pcbr = NULL, cbr = cbl->list; cbr != NULL; pcbr = cbr, cbr = cbr->next) {
687 if ((cbr->proc == callback) && (cbr->data == data))
688 break;
690 if (cbr != NULL) {
691 if (cbl->inCallback) {
692 ++(cbl->numDeleted);
693 cbr->deleted = TRUE;
695 else {
696 if (pcbr == NULL)
697 cbl->list = cbr->next;
698 else
699 pcbr->next = cbr->next;
700 free(cbr);
702 return TRUE;
704 return FALSE;
707 void
708 _CallCallbacks(CallbackListPtr *pcbl, pointer call_data)
710 CallbackListPtr cbl = *pcbl;
711 CallbackPtr cbr, pcbr;
713 ++(cbl->inCallback);
714 for (cbr = cbl->list; cbr != NULL; cbr = cbr->next) {
715 (*(cbr->proc)) (pcbl, cbr->data, call_data);
717 --(cbl->inCallback);
719 if (cbl->inCallback)
720 return;
722 /* Was the entire list marked for deletion? */
724 if (cbl->deleted) {
725 DeleteCallbackList(pcbl);
726 return;
729 /* Were some individual callbacks on the list marked for deletion?
730 * If so, do the deletions.
733 if (cbl->numDeleted) {
734 for (pcbr = NULL, cbr = cbl->list; (cbr != NULL) && cbl->numDeleted;) {
735 if (cbr->deleted) {
736 if (pcbr) {
737 cbr = cbr->next;
738 free(pcbr->next);
739 pcbr->next = cbr;
741 else {
742 cbr = cbr->next;
743 free(cbl->list);
744 cbl->list = cbr;
746 cbl->numDeleted--;
748 else { /* this one wasn't deleted */
750 pcbr = cbr;
751 cbr = cbr->next;
757 static void
758 _DeleteCallbackList(CallbackListPtr *pcbl)
760 CallbackListPtr cbl = *pcbl;
761 CallbackPtr cbr, nextcbr;
762 int i;
764 if (cbl->inCallback) {
765 cbl->deleted = TRUE;
766 return;
769 for (i = 0; i < numCallbackListsToCleanup; i++) {
770 if (listsToCleanup[i] == pcbl) {
771 listsToCleanup[i] = NULL;
772 break;
776 for (cbr = cbl->list; cbr != NULL; cbr = nextcbr) {
777 nextcbr = cbr->next;
778 free(cbr);
780 free(cbl);
781 *pcbl = NULL;
784 static Bool
785 CreateCallbackList(CallbackListPtr *pcbl)
787 CallbackListPtr cbl;
788 int i;
790 if (!pcbl)
791 return FALSE;
792 cbl = malloc(sizeof(CallbackListRec));
793 if (!cbl)
794 return FALSE;
795 cbl->inCallback = 0;
796 cbl->deleted = FALSE;
797 cbl->numDeleted = 0;
798 cbl->list = NULL;
799 *pcbl = cbl;
801 for (i = 0; i < numCallbackListsToCleanup; i++) {
802 if (!listsToCleanup[i]) {
803 listsToCleanup[i] = pcbl;
804 return TRUE;
808 listsToCleanup = (CallbackListPtr **) xnfrealloc(listsToCleanup,
809 sizeof(CallbackListPtr *) *
810 (numCallbackListsToCleanup
811 + 1));
812 listsToCleanup[numCallbackListsToCleanup] = pcbl;
813 numCallbackListsToCleanup++;
814 return TRUE;
817 /* ===== Public Procedures ===== */
819 Bool
820 AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
822 if (!pcbl)
823 return FALSE;
824 if (!*pcbl) { /* list hasn't been created yet; go create it */
825 if (!CreateCallbackList(pcbl))
826 return FALSE;
828 return _AddCallback(pcbl, callback, data);
831 Bool
832 DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
834 if (!pcbl || !*pcbl)
835 return FALSE;
836 return _DeleteCallback(pcbl, callback, data);
839 void
840 DeleteCallbackList(CallbackListPtr *pcbl)
842 if (!pcbl || !*pcbl)
843 return;
844 _DeleteCallbackList(pcbl);
847 void
848 InitCallbackManager(void)
850 int i;
852 for (i = 0; i < numCallbackListsToCleanup; i++) {
853 DeleteCallbackList(listsToCleanup[i]);
855 free(listsToCleanup);
857 numCallbackListsToCleanup = 0;
858 listsToCleanup = NULL;