Annotation of libwww/Library/src/HTProt.c, revision 2.12

2.1       frystyk     1: /*                                                                  HTProt.c
                      2: **     ACCESS SCHEME MANAGER
                      3: **
                      4: **     (c) COPYRIGHT MIT 1995.
                      5: **     Please first read the full copyright statement in the file COPYRIGH.
                      6: **
                      7: **
                      8: ** HISTORY:
                      9: **     6 July 95  HFN  Spawned off from HTAccess
                     10: */
                     11: 
                     12: /* Library Include files */
                     13: #include "tcp.h"
                     14: #include "HTUtils.h"
2.5       frystyk    15: #include "HTString.h"
2.1       frystyk    16: #include "HTParse.h"
                     17: #include "HTString.h"
                     18: #include "HTProt.h"                                     /* Implemented here */
                     19: 
                     20: /* Variables and typedefs local to this module */
2.5       frystyk    21: struct _HTProtocol {
                     22:     char *             name;
2.11      frystyk    23:     BOOL               preemptive;
2.10      frystyk    24:     HTEventCallback *  client;
                     25:     HTEventCallback *  server;
2.5       frystyk    26: };
                     27: 
2.1       frystyk    28: PRIVATE HTList * protocols = NULL;           /* List of registered protocols */
                     29: 
                     30: /* --------------------------------------------------------------------------*/
                     31: /*                   Management of the HTProtocol structure                 */
                     32: /* --------------------------------------------------------------------------*/
                     33: 
                     34: /*
2.3       frystyk    35: **     Register a Protocol module as an active access method
2.1       frystyk    36: */
2.5       frystyk    37: PUBLIC BOOL HTProtocol_add (CONST char *               name,
2.11      frystyk    38:                            BOOL                preemptive,
2.10      frystyk    39:                            HTEventCallback *   client,
                     40:                            HTEventCallback *   server)
2.1       frystyk    41: {
2.10      frystyk    42:     if (name && (client || server)) {
2.12    ! frystyk    43:        HTProtocol *newProt;
        !            44:        if ((newProt = (HTProtocol  *) HT_CALLOC(1, sizeof(HTProtocol))) == NULL)
        !            45:            HT_OUTOFMEM("HTProtocol_add");
2.5       frystyk    46:        StrAllocCopy(newProt->name, name);
2.9       frystyk    47:        {
                     48:            char *ptr = newProt->name;
                     49:            while ((*ptr = TOLOWER(*ptr))) ptr++;
                     50:        }
2.11      frystyk    51:        newProt->preemptive = preemptive;
2.10      frystyk    52:        newProt->client = client;
                     53:        newProt->server = server;
2.5       frystyk    54:        if (!protocols) protocols = HTList_new();
                     55:        return HTList_addObject(protocols, (void *) newProt);
                     56:     }
                     57:     return NO;
2.1       frystyk    58: }
                     59: 
2.3       frystyk    60: /*
                     61: **     Deletes a Protocol module as an active access method
                     62: */
2.5       frystyk    63: PUBLIC BOOL HTProtocol_delete (CONST char * name)
2.3       frystyk    64: {
2.5       frystyk    65:     if (protocols) {
                     66:        HTList *cur = protocols;
                     67:        HTProtocol *pres;
                     68:        while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
                     69:            if (!strcmp(pres->name, name)) {
2.12    ! frystyk    70:                HT_FREE(pres->name);
2.5       frystyk    71:                return HTList_removeObject(protocols, (void *) pres);
                     72:            }
                     73:        }
                     74:     }
                     75:     return NO;
                     76: }
                     77: 
                     78: /*
2.10      frystyk    79: **     Returns the client callback function
2.5       frystyk    80: */
2.10      frystyk    81: PUBLIC HTEventCallback * HTProtocol_client (HTProtocol * protocol)
2.5       frystyk    82: {
2.10      frystyk    83:     return protocol ? protocol->client : NULL;
                     84: }
                     85: 
                     86: /*
                     87: **     Returns the server callback function
                     88: */
                     89: PUBLIC HTEventCallback * HTProtocol_server (HTProtocol * protocol)
                     90: {
                     91:     return protocol ? protocol->server : NULL;
2.5       frystyk    92: }
                     93: 
                     94: /*
2.11      frystyk    95: **     Returns YES if preemptive else NO
2.5       frystyk    96: */
2.11      frystyk    97: PUBLIC BOOL HTProtocol_preemptive (HTProtocol * protocol)
2.5       frystyk    98: {
2.11      frystyk    99:     return protocol ? protocol->preemptive : NO;
2.3       frystyk   100: }
2.1       frystyk   101: 
                    102: /*
                    103: **     Delete the list of registered access methods. This is called from
2.5       frystyk   104: **     within HTLibTerminate. Thanks to Eric Sink, eric@spyglass.com
2.1       frystyk   105: */
2.5       frystyk   106: PUBLIC BOOL HTProtocol_deleteAll (void)
2.1       frystyk   107: {
                    108:     if (protocols) {
2.5       frystyk   109:        HTList *cur = protocols;
                    110:        HTProtocol *pres;
                    111:        while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
2.12    ! frystyk   112:            HT_FREE(pres->name);
        !           113:            HT_FREE(pres);
2.5       frystyk   114:        }
2.1       frystyk   115:        HTList_delete(protocols);
                    116:        protocols = NULL;
2.5       frystyk   117:        return YES;
2.1       frystyk   118:     }
2.5       frystyk   119:     return NO;
2.1       frystyk   120: }
                    121: 
                    122: /*
2.10      frystyk   123: **     Search registered protocols to find suitable protocol object.
                    124: **     Return protocol object or NULL
2.1       frystyk   125: */
2.10      frystyk   126: PUBLIC HTProtocol * HTProtocol_find (HTRequest * request, CONST char * access)
2.1       frystyk   127: {
2.10      frystyk   128:     if (request && access) {
                    129:        HTList * cur = protocols;
                    130:        HTProtocol * pres;
2.9       frystyk   131:        if (cur) {
2.10      frystyk   132:            while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
                    133:                if (!strcmp(pres->name, access)) return pres;
2.1       frystyk   134:            }
                    135:        }
2.10      frystyk   136:        HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS, (char*) access,
                    137:                           (int) strlen(access), "HTProtocol_find");
2.1       frystyk   138:     }
2.10      frystyk   139:     return NULL;
2.1       frystyk   140: }
2.10      frystyk   141: 
2.1       frystyk   142: 

Webmaster