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

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.
2.22    ! vbancrof    6: **     @(#) $Id: HTProt.c,v 2.21 1999/04/04 00:09:14 frystyk Exp $
2.1       frystyk     7: **
                      8: **
                      9: ** HISTORY:
                     10: **     6 July 95  HFN  Spawned off from HTAccess
                     11: */
                     12: 
                     13: /* Library Include files */
2.18      frystyk    14: #include "wwwsys.h"
2.1       frystyk    15: #include "HTUtils.h"
2.5       frystyk    16: #include "HTString.h"
2.1       frystyk    17: #include "HTParse.h"
                     18: #include "HTString.h"
2.15      frystyk    19: #include "HTTrans.h"
2.1       frystyk    20: #include "HTProt.h"                                     /* Implemented here */
                     21: 
                     22: /* Variables and typedefs local to this module */
2.5       frystyk    23: struct _HTProtocol {
2.15      frystyk    24:     char *             name;         /* Name of this protocol access scheme */
                     25:     char *             transport;                  /* Name of the transport */
2.17      frystyk    26:     HTProtocolId       id;                /* Default port for this protocol */
2.11      frystyk    27:     BOOL               preemptive;
2.17      frystyk    28:     HTProtCallback *   client;
                     29:     HTProtCallback *   server;
2.5       frystyk    30: };
                     31: 
2.1       frystyk    32: PRIVATE HTList * protocols = NULL;           /* List of registered protocols */
                     33: 
                     34: /* --------------------------------------------------------------------------*/
                     35: /*                   Management of the HTProtocol structure                 */
                     36: /* --------------------------------------------------------------------------*/
                     37: 
                     38: /*
2.3       frystyk    39: **     Register a Protocol module as an active access method
2.1       frystyk    40: */
2.13      frystyk    41: PUBLIC BOOL HTProtocol_add (const char *               name,
2.15      frystyk    42:                            const char *        transport,
2.17      frystyk    43:                            HTProtocolId        protocolId,
2.11      frystyk    44:                            BOOL                preemptive,
2.17      frystyk    45:                            HTProtCallback *    client,
                     46:                            HTProtCallback *    server)
2.1       frystyk    47: {
2.10      frystyk    48:     if (name && (client || server)) {
2.12      frystyk    49:        HTProtocol *newProt;
2.14      frystyk    50:        if ((newProt=(HTProtocol *) HT_CALLOC(1, sizeof(HTProtocol))) == NULL)
2.12      frystyk    51:            HT_OUTOFMEM("HTProtocol_add");
2.5       frystyk    52:        StrAllocCopy(newProt->name, name);
2.9       frystyk    53:        {
                     54:            char *ptr = newProt->name;
                     55:            while ((*ptr = TOLOWER(*ptr))) ptr++;
                     56:        }
2.15      frystyk    57:        StrAllocCopy(newProt->transport, transport);
                     58:        {
                     59:            char *ptr = newProt->transport;
                     60:            while ((*ptr = TOLOWER(*ptr))) ptr++;
                     61:        }
2.17      frystyk    62:        newProt->id = protocolId;
2.11      frystyk    63:        newProt->preemptive = preemptive;
2.10      frystyk    64:        newProt->client = client;
                     65:        newProt->server = server;
2.5       frystyk    66:        if (!protocols) protocols = HTList_new();
2.22    ! vbancrof   67:        else HTProtocol_delete(name); /* Ensure not listed twice */
2.20      frystyk    68:        HTTRACE(CORE_TRACE, "Protocol.... Adding `%s'\n" _ name);
2.5       frystyk    69:        return HTList_addObject(protocols, (void *) newProt);
                     70:     }
                     71:     return NO;
2.1       frystyk    72: }
                     73: 
2.3       frystyk    74: /*
                     75: **     Deletes a Protocol module as an active access method
                     76: */
2.13      frystyk    77: PUBLIC BOOL HTProtocol_delete (const char * name)
2.3       frystyk    78: {
2.5       frystyk    79:     if (protocols) {
                     80:        HTList *cur = protocols;
                     81:        HTProtocol *pres;
                     82:        while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
                     83:            if (!strcmp(pres->name, name)) {
2.21      frystyk    84:                BOOL status = HTList_removeObject(protocols, (void *) pres);
2.12      frystyk    85:                HT_FREE(pres->name);
2.15      frystyk    86:                HT_FREE(pres->transport);
2.21      frystyk    87:                HT_FREE(pres);
                     88:                return status;
2.5       frystyk    89:            }
                     90:        }
                     91:     }
                     92:     return NO;
                     93: }
                     94: 
                     95: /*
2.10      frystyk    96: **     Returns the client callback function
2.5       frystyk    97: */
2.17      frystyk    98: PUBLIC HTProtCallback * HTProtocol_client (HTProtocol * protocol)
2.5       frystyk    99: {
2.10      frystyk   100:     return protocol ? protocol->client : NULL;
                    101: }
                    102: 
                    103: /*
                    104: **     Returns the server callback function
                    105: */
2.17      frystyk   106: PUBLIC HTProtCallback * HTProtocol_server (HTProtocol * protocol)
2.10      frystyk   107: {
                    108:     return protocol ? protocol->server : NULL;
2.17      frystyk   109: }
                    110: 
                    111: /*
                    112: **     Returns the default port
                    113: */
                    114: PUBLIC HTProtocolId HTProtocol_id (HTProtocol * protocol)
                    115: {
                    116:     return protocol ? protocol->id : 0;
2.5       frystyk   117: }
                    118: 
                    119: /*
2.11      frystyk   120: **     Returns YES if preemptive else NO
2.5       frystyk   121: */
2.11      frystyk   122: PUBLIC BOOL HTProtocol_preemptive (HTProtocol * protocol)
2.5       frystyk   123: {
2.11      frystyk   124:     return protocol ? protocol->preemptive : NO;
2.3       frystyk   125: }
2.1       frystyk   126: 
                    127: /*
                    128: **     Delete the list of registered access methods. This is called from
2.5       frystyk   129: **     within HTLibTerminate. Thanks to Eric Sink, eric@spyglass.com
2.1       frystyk   130: */
2.5       frystyk   131: PUBLIC BOOL HTProtocol_deleteAll (void)
2.1       frystyk   132: {
                    133:     if (protocols) {
2.5       frystyk   134:        HTList *cur = protocols;
                    135:        HTProtocol *pres;
                    136:        while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
2.12      frystyk   137:            HT_FREE(pres->name);
2.15      frystyk   138:            HT_FREE(pres->transport);
2.12      frystyk   139:            HT_FREE(pres);
2.5       frystyk   140:        }
2.1       frystyk   141:        HTList_delete(protocols);
                    142:        protocols = NULL;
2.5       frystyk   143:        return YES;
2.1       frystyk   144:     }
2.5       frystyk   145:     return NO;
2.1       frystyk   146: }
                    147: 
                    148: /*
2.10      frystyk   149: **     Search registered protocols to find suitable protocol object.
                    150: **     Return protocol object or NULL
2.1       frystyk   151: */
2.13      frystyk   152: PUBLIC HTProtocol * HTProtocol_find (HTRequest * request, const char * access)
2.1       frystyk   153: {
2.19      frystyk   154:     if (access) {
2.10      frystyk   155:        HTList * cur = protocols;
                    156:        HTProtocol * pres;
2.9       frystyk   157:        if (cur) {
2.10      frystyk   158:            while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
                    159:                if (!strcmp(pres->name, access)) return pres;
2.1       frystyk   160:            }
                    161:        }
2.19      frystyk   162:        if (request)
                    163:            HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS, (char*) access,
                    164:                               (int) strlen(access), "HTProtocol_find");
2.1       frystyk   165:     }
2.10      frystyk   166:     return NULL;
2.1       frystyk   167: }
2.10      frystyk   168: 
2.15      frystyk   169: /*
                    170: **  Get the transport name of this protocol
                    171: */
                    172: PUBLIC BOOL HTProtocol_setTransport (HTProtocol * protocol,
                    173:                                     const char * transport)
                    174: {
                    175:     if (protocol && transport) {
                    176:        StrAllocCopy(protocol->transport, transport);
                    177:        {
                    178:            char *ptr = protocol->transport;
                    179:            while ((*ptr = TOLOWER(*ptr))) ptr++;
                    180:        }
                    181:        return YES;
                    182:     }
                    183:     return NO;
                    184: }
                    185: 
                    186: PUBLIC const char * HTProtocol_transport (HTProtocol * protocol)
                    187: {
                    188:     return (protocol ? protocol->transport : NULL);
                    189: }
2.1       frystyk   190: 
2.19      frystyk   191: PUBLIC const char * HTProtocol_name (HTProtocol * protocol)
                    192: {
                    193:     return (protocol ? protocol->name : NULL);
                    194: }

Webmaster