Annotation of libwww/Library/src/HTAlert.c, revision 2.54

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.54    ! vbancrof    6: **     @(#) $Id: HTAlert.c,v 2.53 1999/02/22 22:10: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.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();
2.54    ! vbancrof  172:     else HTAlert_delete(cbf); /* Remove duplicates */
2.39      frystyk   173:     return HTAlertCall_add(HTMessages, cbf, opcode);
1.1       timbl     174: }
                    175: 
2.42      frystyk   176: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
                    177: {
                    178:     if (!HTMessages) HTMessages = HTList_new();
                    179:     return HTAlertCall_delete(HTMessages, cbf);
2.52      frystyk   180: }
                    181: 
                    182: PUBLIC BOOL HTAlert_deleteOpcode (HTAlertOpcode opcode)
                    183: {
                    184:     if (!HTMessages) HTMessages = HTList_new();
                    185:     return HTAlertCall_deleteOpcode(HTMessages, opcode);
2.51      frystyk   186: }
                    187: 
                    188: PUBLIC BOOL HTAlert_deleteAll (void)
                    189: {
                    190:     BOOL status = NO;
                    191:     if (HTMessages) {
                    192:        status = HTAlertCall_deleteAll(HTMessages);
                    193:        HTMessages = NULL;
                    194:     }
                    195:     return status;
2.42      frystyk   196: }
                    197: 
2.39      frystyk   198: /*     HTAlert_find
                    199: **     ------------
                    200: **     Finds a global callback function corresponding to the opcode
1.1       timbl     201: */
2.39      frystyk   202: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1       timbl     203: {
2.39      frystyk   204:     return HTAlertCall_find(HTMessages, opcode);
1.1       timbl     205: }
2.8       luotonen  206: 
2.39      frystyk   207: PUBLIC HTAlertPar * HTAlert_newReply (void)
                    208: {
2.44      frystyk   209:     HTAlertPar * me;
                    210:     if ((me = (HTAlertPar  *) HT_CALLOC(1, sizeof(HTAlertPar))) == NULL)
                    211:         HT_OUTOFMEM("HTAlert_newReply");
2.39      frystyk   212:     return me;
                    213: }
2.8       luotonen  214: 
2.39      frystyk   215: /*     HTAlert_deleteReply
                    216: **     -------------------
                    217: **     Delete reply structure but don't touch the replies themselves.
2.8       luotonen  218: */
2.39      frystyk   219: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8       luotonen  220: {
2.48      frystyk   221:     HT_FREE(old);
2.11      luotonen  222: }
                    223: 
2.39      frystyk   224: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
                    225: {
                    226:     return me ? me->message : NULL;
                    227: }
2.11      luotonen  228: 
2.47      frystyk   229: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, const char * message)
2.11      luotonen  230: {
2.39      frystyk   231:     if (me && message) {
                    232:        StrAllocCopy(me->message, message);
                    233:        return YES;
                    234:     }
                    235:     return NO;
2.8       luotonen  236: }
                    237: 
2.43      frystyk   238: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
                    239: {
                    240:     if (me) me->message = message;
                    241:     return YES;
                    242: }
                    243: 
2.39      frystyk   244: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
                    245: {
                    246:     return me ? me->secret : NULL;
                    247: }
2.21      frystyk   248: 
2.47      frystyk   249: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, const char * secret)
2.21      frystyk   250: {
2.39      frystyk   251:     if (me && secret) {
                    252:        StrAllocCopy(me->secret, secret);
                    253:        return YES;
                    254:     }
                    255:     return NO;
                    256: }
2.21      frystyk   257: 
2.39      frystyk   258: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
                    259: {
                    260:     return me ? me->output : NULL;
                    261: }
2.21      frystyk   262: 
2.39      frystyk   263: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
                    264: {
                    265:     if (me) {
                    266:        me->output = output;
                    267:        return YES;
2.21      frystyk   268:     }
2.39      frystyk   269:     return NO;
2.21      frystyk   270: }

Webmaster