Annotation of libwww/Library/src/HTAlert.c, revision 2.52
2.18 frystyk 1: /* HTAlert.c
2.39 frystyk 2: ** DIALOG MANAGER
2.18 frystyk 3: **
2.23 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.18 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
2.52 ! frystyk 6: ** @(#) $Id: HTAlert.c,v 2.51 1998/05/04 19:36:10 frystyk Exp $
1.1 timbl 7: **
8: ** REPLACE THIS MODULE with a GUI version in a GUI environment!
9: **
10: ** History:
11: ** Jun 92 Created May 1992 By C.T. Barker
12: ** Feb 93 Simplified, portablised TBL
2.8 luotonen 13: ** Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
2.39 frystyk 14: ** Nov 95 Rewritten using callbacks HFN
1.1 timbl 15: */
16:
2.20 frystyk 17: /* Library include files */
2.29 frystyk 18: #include "WWWLib.h"
2.21 frystyk 19: #include "HTError.h" /* Implemented here */
20: #include "HTAlert.h" /* Implemented here */
1.1 timbl 21:
2.39 frystyk 22: typedef struct _HTAlert {
23: HTAlertCallback * cbf;
24: HTAlertOpcode opcode;
25: } HTAlert;
26:
27: struct _HTAlertPar {
28: char * message;
29: char * secret;
30: void * output;
31: };
2.28 frystyk 32:
2.25 frystyk 33: PRIVATE BOOL HTInteractive=YES; /* Any prompts from the Library? */
1.1 timbl 34:
2.39 frystyk 35: PRIVATE HTList * HTMessages = NULL; /* Global list of alert functions */
36:
2.21 frystyk 37: /* ------------------------------------------------------------------------- */
2.25 frystyk 38:
2.39 frystyk 39: /*
40: ** All messaging can be turned on or off as you like
41: */
42: PUBLIC void HTAlert_setInteractive (BOOL interactive)
2.25 frystyk 43: {
44: HTInteractive = interactive;
45: }
46:
2.39 frystyk 47: PUBLIC BOOL HTAlert_interactive (void)
2.25 frystyk 48: {
49: return HTInteractive;
50: }
2.21 frystyk 51:
2.39 frystyk 52: /* HTAlertCall_add
53: ** ---------------
54: ** Register a call back function that is to be called when generating
55: ** messages, dialog, prompts, progress reports etc.
56: **
57: ** The opcode signifies which call back function to call depending of the
58: ** type of the message. Opcode can be one of the enumerations defined
59: ** by HTAlertOpcode.
60: */
61: PUBLIC BOOL HTAlertCall_add (HTList * list, HTAlertCallback * cbf,
62: HTAlertOpcode opcode)
63: {
2.49 hallam 64: if (CORE_TRACE)
2.52 ! frystyk 65: HTTrace("Alert Call.. Add Alert Handler %p\n", (void *) cbf);
2.39 frystyk 66: if (list && cbf) {
2.44 frystyk 67: HTAlert *me;
68: if ((me = (HTAlert *) HT_CALLOC(1, sizeof(HTAlert))) == NULL)
69: HT_OUTOFMEM("HTAlertCall_add");
2.39 frystyk 70: me->cbf = cbf;
71: me->opcode = opcode;
72: return HTList_addObject(list, (void *) me);
73: }
74: return NO;
75: }
76:
77: /* HTAlertCall_delete
78: ** ------------------
79: ** Unregister a call back function from a list
80: */
81: PUBLIC BOOL HTAlertCall_delete (HTList * list, HTAlertCallback *cbf)
82: {
2.49 hallam 83: if (CORE_TRACE)
2.52 ! frystyk 84: HTTrace("Alert Call.. Delete Alert Handler %p\n", (void *) cbf);
2.39 frystyk 85: if (list && cbf) {
86: HTList *cur = list;
87: HTAlert *pres;
88: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
89: if (pres->cbf == cbf) {
90: HTList_removeObject(list, (void *) pres);
2.44 frystyk 91: HT_FREE(pres);
2.39 frystyk 92: return YES;
93: }
94: }
95: }
96: return NO;
97: }
2.28 frystyk 98:
2.52 ! frystyk 99: /* HTAlertCall_deleteOpcode
! 100: ** ------------------------
! 101: ** Unregister all handlers registered for a given opcode.
! 102: */
! 103: PUBLIC BOOL HTAlertCall_deleteOpcode (HTList * list, HTAlertOpcode opcode)
! 104: {
! 105: if (CORE_TRACE)
! 106: HTTrace("Alert Call.. Delete all handlers with opcode %d\n", opcode);
! 107: if (list) {
! 108: HTList * cur = list;
! 109: HTAlert * pres;
! 110: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
! 111: if (pres->opcode == opcode) {
! 112: HTList_removeObject(list, (void *) pres);
! 113: HT_FREE(pres);
! 114: cur = list;
! 115: }
! 116: }
! 117: return YES;
! 118: }
! 119: return NO;
! 120: }
! 121:
2.39 frystyk 122: /* HTAlertCall_deleteAll
123: ** ---------------------
124: ** Unregisters all call back functions
125: */
126: PUBLIC BOOL HTAlertCall_deleteAll (HTList * list)
127: {
2.49 hallam 128: if (CORE_TRACE)
2.52 ! frystyk 129: HTTrace("Alert Call.. Delete All callback functions\n");
2.39 frystyk 130: if (list) {
131: HTList *cur = list;
132: HTAlert *pres;
133: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
2.44 frystyk 134: HT_FREE(pres);
2.39 frystyk 135: }
136: HTList_delete(list);
137: return YES;
2.28 frystyk 138: }
2.39 frystyk 139: return NO;
140: }
141:
142: /* HTAlertCall_find
143: ** ----------------
144: ** Finds a callback function corresponding to the opcode. If none has
145: ** been registered then NULL is returned.
146: */
147: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
148: {
149: if (list && HTInteractive) {
150: HTAlert * pres;
151: while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
152: if (pres->opcode & opcode)
153: return pres->cbf;
2.28 frystyk 154: }
2.49 hallam 155: if (CORE_TRACE)
2.52 ! frystyk 156: HTTrace("Alert Call.. No entry found for opcode %d\n",opcode);
2.28 frystyk 157: }
2.39 frystyk 158: return NULL;
2.21 frystyk 159: }
160:
2.39 frystyk 161: /*
162: ** Global List of Alert functions. list can be NULL
163: */
164: PUBLIC void HTAlert_setGlobal (HTList * list)
165: {
166: HTMessages = list;
167: }
2.21 frystyk 168:
2.39 frystyk 169: PUBLIC HTList * HTAlert_global (void)
1.1 timbl 170: {
2.39 frystyk 171: return HTMessages;
1.1 timbl 172: }
173:
2.39 frystyk 174: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1 timbl 175: {
2.39 frystyk 176: if (!HTMessages) HTMessages = HTList_new();
177: return HTAlertCall_add(HTMessages, cbf, opcode);
1.1 timbl 178: }
179:
2.42 frystyk 180: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
181: {
182: if (!HTMessages) HTMessages = HTList_new();
183: return HTAlertCall_delete(HTMessages, cbf);
2.52 ! frystyk 184: }
! 185:
! 186: PUBLIC BOOL HTAlert_deleteOpcode (HTAlertOpcode opcode)
! 187: {
! 188: if (!HTMessages) HTMessages = HTList_new();
! 189: return HTAlertCall_deleteOpcode(HTMessages, opcode);
2.51 frystyk 190: }
191:
192: PUBLIC BOOL HTAlert_deleteAll (void)
193: {
194: BOOL status = NO;
195: if (HTMessages) {
196: status = HTAlertCall_deleteAll(HTMessages);
197: HTMessages = NULL;
198: }
199: return status;
2.42 frystyk 200: }
201:
2.39 frystyk 202: /* HTAlert_find
203: ** ------------
204: ** Finds a global callback function corresponding to the opcode
1.1 timbl 205: */
2.39 frystyk 206: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1 timbl 207: {
2.39 frystyk 208: return HTAlertCall_find(HTMessages, opcode);
1.1 timbl 209: }
2.8 luotonen 210:
2.39 frystyk 211: PUBLIC HTAlertPar * HTAlert_newReply (void)
212: {
2.44 frystyk 213: HTAlertPar * me;
214: if ((me = (HTAlertPar *) HT_CALLOC(1, sizeof(HTAlertPar))) == NULL)
215: HT_OUTOFMEM("HTAlert_newReply");
2.39 frystyk 216: return me;
217: }
2.8 luotonen 218:
2.39 frystyk 219: /* HTAlert_deleteReply
220: ** -------------------
221: ** Delete reply structure but don't touch the replies themselves.
2.8 luotonen 222: */
2.39 frystyk 223: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8 luotonen 224: {
2.48 frystyk 225: HT_FREE(old);
2.11 luotonen 226: }
227:
2.39 frystyk 228: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
229: {
230: return me ? me->message : NULL;
231: }
2.11 luotonen 232:
2.47 frystyk 233: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, const char * message)
2.11 luotonen 234: {
2.39 frystyk 235: if (me && message) {
236: StrAllocCopy(me->message, message);
237: return YES;
238: }
239: return NO;
2.8 luotonen 240: }
241:
2.43 frystyk 242: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
243: {
244: if (me) me->message = message;
245: return YES;
246: }
247:
2.39 frystyk 248: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
249: {
250: return me ? me->secret : NULL;
251: }
2.21 frystyk 252:
2.47 frystyk 253: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, const char * secret)
2.21 frystyk 254: {
2.39 frystyk 255: if (me && secret) {
256: StrAllocCopy(me->secret, secret);
257: return YES;
258: }
259: return NO;
260: }
2.21 frystyk 261:
2.39 frystyk 262: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
263: {
264: return me ? me->output : NULL;
265: }
2.21 frystyk 266:
2.39 frystyk 267: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
268: {
269: if (me) {
270: me->output = output;
271: return YES;
2.21 frystyk 272: }
2.39 frystyk 273: return NO;
2.21 frystyk 274: }
Webmaster