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

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.19    ! frystyk     6: **     @(#) $Id: HTProt.c,v 2.18 1998/05/04 19:37: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.16      frystyk    67:        if (CORE_TRACE) HTTrace("Protocol.... Adding `%s'\n", name);
2.5       frystyk    68:        return HTList_addObject(protocols, (void *) newProt);
                     69:     }
                     70:     return NO;
2.1       frystyk    71: }
                     72: 
2.3       frystyk    73: /*
                     74: **     Deletes a Protocol module as an active access method
                     75: */
2.13      frystyk    76: PUBLIC BOOL HTProtocol_delete (const char * name)
2.3       frystyk    77: {
2.5       frystyk    78:     if (protocols) {
                     79:        HTList *cur = protocols;
                     80:        HTProtocol *pres;
                     81:        while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
                     82:            if (!strcmp(pres->name, name)) {
2.12      frystyk    83:                HT_FREE(pres->name);
2.15      frystyk    84:                HT_FREE(pres->transport);
2.5       frystyk    85:                return HTList_removeObject(protocols, (void *) pres);
                     86:            }
                     87:        }
                     88:     }
                     89:     return NO;
                     90: }
                     91: 
                     92: /*
2.10      frystyk    93: **     Returns the client callback function
2.5       frystyk    94: */
2.17      frystyk    95: PUBLIC HTProtCallback * HTProtocol_client (HTProtocol * protocol)
2.5       frystyk    96: {
2.10      frystyk    97:     return protocol ? protocol->client : NULL;
                     98: }
                     99: 
                    100: /*
                    101: **     Returns the server callback function
                    102: */
2.17      frystyk   103: PUBLIC HTProtCallback * HTProtocol_server (HTProtocol * protocol)
2.10      frystyk   104: {
                    105:     return protocol ? protocol->server : NULL;
2.17      frystyk   106: }
                    107: 
                    108: /*
                    109: **     Returns the default port
                    110: */
                    111: PUBLIC HTProtocolId HTProtocol_id (HTProtocol * protocol)
                    112: {
                    113:     return protocol ? protocol->id : 0;
2.5       frystyk   114: }
                    115: 
                    116: /*
2.11      frystyk   117: **     Returns YES if preemptive else NO
2.5       frystyk   118: */
2.11      frystyk   119: PUBLIC BOOL HTProtocol_preemptive (HTProtocol * protocol)
2.5       frystyk   120: {
2.11      frystyk   121:     return protocol ? protocol->preemptive : NO;
2.3       frystyk   122: }
2.1       frystyk   123: 
                    124: /*
                    125: **     Delete the list of registered access methods. This is called from
2.5       frystyk   126: **     within HTLibTerminate. Thanks to Eric Sink, eric@spyglass.com
2.1       frystyk   127: */
2.5       frystyk   128: PUBLIC BOOL HTProtocol_deleteAll (void)
2.1       frystyk   129: {
                    130:     if (protocols) {
2.5       frystyk   131:        HTList *cur = protocols;
                    132:        HTProtocol *pres;
                    133:        while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
2.12      frystyk   134:            HT_FREE(pres->name);
2.15      frystyk   135:            HT_FREE(pres->transport);
2.12      frystyk   136:            HT_FREE(pres);
2.5       frystyk   137:        }
2.1       frystyk   138:        HTList_delete(protocols);
                    139:        protocols = NULL;
2.5       frystyk   140:        return YES;
2.1       frystyk   141:     }
2.5       frystyk   142:     return NO;
2.1       frystyk   143: }
                    144: 
                    145: /*
2.10      frystyk   146: **     Search registered protocols to find suitable protocol object.
                    147: **     Return protocol object or NULL
2.1       frystyk   148: */
2.13      frystyk   149: PUBLIC HTProtocol * HTProtocol_find (HTRequest * request, const char * access)
2.1       frystyk   150: {
2.19    ! frystyk   151:     if (access) {
2.10      frystyk   152:        HTList * cur = protocols;
                    153:        HTProtocol * pres;
2.9       frystyk   154:        if (cur) {
2.10      frystyk   155:            while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
                    156:                if (!strcmp(pres->name, access)) return pres;
2.1       frystyk   157:            }
                    158:        }
2.19    ! frystyk   159:        if (request)
        !           160:            HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS, (char*) access,
        !           161:                               (int) strlen(access), "HTProtocol_find");
2.1       frystyk   162:     }
2.10      frystyk   163:     return NULL;
2.1       frystyk   164: }
2.10      frystyk   165: 
2.15      frystyk   166: /*
                    167: **  Get the transport name of this protocol
                    168: */
                    169: PUBLIC BOOL HTProtocol_setTransport (HTProtocol * protocol,
                    170:                                     const char * transport)
                    171: {
                    172:     if (protocol && transport) {
                    173:        StrAllocCopy(protocol->transport, transport);
                    174:        {
                    175:            char *ptr = protocol->transport;
                    176:            while ((*ptr = TOLOWER(*ptr))) ptr++;
                    177:        }
                    178:        return YES;
                    179:     }
                    180:     return NO;
                    181: }
                    182: 
                    183: PUBLIC const char * HTProtocol_transport (HTProtocol * protocol)
                    184: {
                    185:     return (protocol ? protocol->transport : NULL);
                    186: }
2.1       frystyk   187: 
2.19    ! frystyk   188: PUBLIC const char * HTProtocol_name (HTProtocol * protocol)
        !           189: {
        !           190:     return (protocol ? protocol->name : NULL);
        !           191: }

Webmaster