Annotation of libwww/Library/src/HTAlert.c, revision 2.53
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.53 ! frystyk 6: ** @(#) $Id: HTAlert.c,v 2.52 1998/05/19 16:49:21 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.53 ! frystyk 64: HTTRACE(CORE_TRACE, "Alert Call.. Add Alert Handler %p\n" _ (void *) cbf);
2.39 frystyk 65: if (list && cbf) {
2.44 frystyk 66: HTAlert *me;
67: if ((me = (HTAlert *) HT_CALLOC(1, sizeof(HTAlert))) == NULL)
68: HT_OUTOFMEM("HTAlertCall_add");
2.39 frystyk 69: me->cbf = cbf;
70: me->opcode = opcode;
71: return HTList_addObject(list, (void *) me);
72: }
73: return NO;
74: }
75:
76: /* HTAlertCall_delete
77: ** ------------------
78: ** Unregister a call back function from a list
79: */
80: PUBLIC BOOL HTAlertCall_delete (HTList * list, HTAlertCallback *cbf)
81: {
2.53 ! frystyk 82: HTTRACE(CORE_TRACE, "Alert Call.. Delete Alert Handler %p\n" _ (void *) cbf);
2.39 frystyk 83: if (list && cbf) {
84: HTList *cur = list;
85: HTAlert *pres;
86: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
87: if (pres->cbf == cbf) {
88: HTList_removeObject(list, (void *) pres);
2.44 frystyk 89: HT_FREE(pres);
2.39 frystyk 90: return YES;
91: }
92: }
93: }
94: return NO;
95: }
2.28 frystyk 96:
2.52 frystyk 97: /* HTAlertCall_deleteOpcode
98: ** ------------------------
99: ** Unregister all handlers registered for a given opcode.
100: */
101: PUBLIC BOOL HTAlertCall_deleteOpcode (HTList * list, HTAlertOpcode opcode)
102: {
2.53 ! frystyk 103: HTTRACE(CORE_TRACE, "Alert Call.. Delete all handlers with opcode %d\n" _ opcode);
2.52 frystyk 104: if (list) {
105: HTList * cur = list;
106: HTAlert * pres;
107: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
108: if (pres->opcode == opcode) {
109: HTList_removeObject(list, (void *) pres);
110: HT_FREE(pres);
111: cur = list;
112: }
113: }
114: return YES;
115: }
116: return NO;
117: }
118:
2.39 frystyk 119: /* HTAlertCall_deleteAll
120: ** ---------------------
121: ** Unregisters all call back functions
122: */
123: PUBLIC BOOL HTAlertCall_deleteAll (HTList * list)
124: {
2.53 ! frystyk 125: HTTRACE(CORE_TRACE, "Alert Call.. Delete All callback functions\n");
2.39 frystyk 126: if (list) {
127: HTList *cur = list;
128: HTAlert *pres;
129: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
2.44 frystyk 130: HT_FREE(pres);
2.39 frystyk 131: }
132: HTList_delete(list);
133: return YES;
2.28 frystyk 134: }
2.39 frystyk 135: return NO;
136: }
137:
138: /* HTAlertCall_find
139: ** ----------------
140: ** Finds a callback function corresponding to the opcode. If none has
141: ** been registered then NULL is returned.
142: */
143: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
144: {
145: if (list && HTInteractive) {
146: HTAlert * pres;
147: while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
148: if (pres->opcode & opcode)
149: return pres->cbf;
2.28 frystyk 150: }
2.53 ! frystyk 151: HTTRACE(CORE_TRACE, "Alert Call.. No entry found for opcode %d\n" _ opcode);
2.28 frystyk 152: }
2.39 frystyk 153: return NULL;
2.21 frystyk 154: }
155:
2.39 frystyk 156: /*
157: ** Global List of Alert functions. list can be NULL
158: */
159: PUBLIC void HTAlert_setGlobal (HTList * list)
160: {
161: HTMessages = list;
162: }
2.21 frystyk 163:
2.39 frystyk 164: PUBLIC HTList * HTAlert_global (void)
1.1 timbl 165: {
2.39 frystyk 166: return HTMessages;
1.1 timbl 167: }
168:
2.39 frystyk 169: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1 timbl 170: {
2.39 frystyk 171: if (!HTMessages) HTMessages = HTList_new();
172: return HTAlertCall_add(HTMessages, cbf, opcode);
1.1 timbl 173: }
174:
2.42 frystyk 175: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
176: {
177: if (!HTMessages) HTMessages = HTList_new();
178: return HTAlertCall_delete(HTMessages, cbf);
2.52 frystyk 179: }
180:
181: PUBLIC BOOL HTAlert_deleteOpcode (HTAlertOpcode opcode)
182: {
183: if (!HTMessages) HTMessages = HTList_new();
184: return HTAlertCall_deleteOpcode(HTMessages, opcode);
2.51 frystyk 185: }
186:
187: PUBLIC BOOL HTAlert_deleteAll (void)
188: {
189: BOOL status = NO;
190: if (HTMessages) {
191: status = HTAlertCall_deleteAll(HTMessages);
192: HTMessages = NULL;
193: }
194: return status;
2.42 frystyk 195: }
196:
2.39 frystyk 197: /* HTAlert_find
198: ** ------------
199: ** Finds a global callback function corresponding to the opcode
1.1 timbl 200: */
2.39 frystyk 201: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1 timbl 202: {
2.39 frystyk 203: return HTAlertCall_find(HTMessages, opcode);
1.1 timbl 204: }
2.8 luotonen 205:
2.39 frystyk 206: PUBLIC HTAlertPar * HTAlert_newReply (void)
207: {
2.44 frystyk 208: HTAlertPar * me;
209: if ((me = (HTAlertPar *) HT_CALLOC(1, sizeof(HTAlertPar))) == NULL)
210: HT_OUTOFMEM("HTAlert_newReply");
2.39 frystyk 211: return me;
212: }
2.8 luotonen 213:
2.39 frystyk 214: /* HTAlert_deleteReply
215: ** -------------------
216: ** Delete reply structure but don't touch the replies themselves.
2.8 luotonen 217: */
2.39 frystyk 218: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8 luotonen 219: {
2.48 frystyk 220: HT_FREE(old);
2.11 luotonen 221: }
222:
2.39 frystyk 223: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
224: {
225: return me ? me->message : NULL;
226: }
2.11 luotonen 227:
2.47 frystyk 228: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, const char * message)
2.11 luotonen 229: {
2.39 frystyk 230: if (me && message) {
231: StrAllocCopy(me->message, message);
232: return YES;
233: }
234: return NO;
2.8 luotonen 235: }
236:
2.43 frystyk 237: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
238: {
239: if (me) me->message = message;
240: return YES;
241: }
242:
2.39 frystyk 243: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
244: {
245: return me ? me->secret : NULL;
246: }
2.21 frystyk 247:
2.47 frystyk 248: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, const char * secret)
2.21 frystyk 249: {
2.39 frystyk 250: if (me && secret) {
251: StrAllocCopy(me->secret, secret);
252: return YES;
253: }
254: return NO;
255: }
2.21 frystyk 256:
2.39 frystyk 257: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
258: {
259: return me ? me->output : NULL;
260: }
2.21 frystyk 261:
2.39 frystyk 262: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
263: {
264: if (me) {
265: me->output = output;
266: return YES;
2.21 frystyk 267: }
2.39 frystyk 268: return NO;
2.21 frystyk 269: }
Webmaster