File:  [Public] / libwww / Library / src / HTProt.c
Revision 2.10: download - view: text, annotated - select for diffs
Mon Nov 27 03:05:12 1995 UTC (28 years, 6 months ago) by frystyk
Branches: MAIN
CVS tags: v4/0C, v4/0B, v4/0, HEAD
alpha 7

/*								     HTProt.c
**	ACCESS SCHEME MANAGER
**
**	(c) COPYRIGHT MIT 1995.
**	Please first read the full copyright statement in the file COPYRIGH.
**
**
** HISTORY:
**	6 July 95  HFN	Spawned off from HTAccess
*/

/* Library Include files */
#include "tcp.h"
#include "HTUtils.h"
#include "HTString.h"
#include "HTParse.h"
#include "HTString.h"
#include "HTProt.h"					 /* Implemented here */

/* Variables and typedefs local to this module */
struct _HTProtocol {
    char *		name;
    BOOL		preemtive;
    HTEventCallback *	client;
    HTEventCallback *	server;
};

PRIVATE HTList * protocols = NULL;           /* List of registered protocols */

/* --------------------------------------------------------------------------*/
/*		      Management of the HTProtocol structure		     */
/* --------------------------------------------------------------------------*/

/*
**	Register a Protocol module as an active access method
*/
PUBLIC BOOL HTProtocol_add (CONST char *       	name,
			    BOOL		preemtive,
			    HTEventCallback *	client,
			    HTEventCallback *	server)
{
    if (name && (client || server)) {
	HTProtocol *newProt = (HTProtocol *) calloc(1, sizeof(HTProtocol));
	if (newProt == NULL) outofmem(__FILE__, "HTProtocol_add");
	StrAllocCopy(newProt->name, name);
	{
	    char *ptr = newProt->name;
	    while ((*ptr = TOLOWER(*ptr))) ptr++;
	}
	newProt->preemtive = preemtive;
	newProt->client = client;
	newProt->server = server;
	if (!protocols) protocols = HTList_new();
	return HTList_addObject(protocols, (void *) newProt);
    }
    return NO;
}

/*
**	Deletes a Protocol module as an active access method
*/
PUBLIC BOOL HTProtocol_delete (CONST char * name)
{
    if (protocols) {
	HTList *cur = protocols;
	HTProtocol *pres;
	while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
	    if (!strcmp(pres->name, name)) {
		FREE(pres->name);
		return HTList_removeObject(protocols, (void *) pres);
	    }
	}
    }
    return NO;
}

/*
**	Returns the client callback function
*/
PUBLIC HTEventCallback * HTProtocol_client (HTProtocol * protocol)
{
    return protocol ? protocol->client : NULL;
}

/*
**	Returns the server callback function
*/
PUBLIC HTEventCallback * HTProtocol_server (HTProtocol * protocol)
{
    return protocol ? protocol->server : NULL;
}

/*
**	Returns YES if preemtive else NO
*/
PUBLIC BOOL HTProtocol_preemtive (HTProtocol * protocol)
{
    return protocol ? protocol->preemtive : NO;
}

/*
**	Delete the list of registered access methods. This is called from
**	within HTLibTerminate. Thanks to Eric Sink, eric@spyglass.com
*/
PUBLIC BOOL HTProtocol_deleteAll (void)
{
    if (protocols) {
	HTList *cur = protocols;
	HTProtocol *pres;
	while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
	    FREE(pres->name);
	    free(pres);
	}
	HTList_delete(protocols);
	protocols = NULL;
	return YES;
    }
    return NO;
}

/*
**	Search registered protocols to find suitable protocol object.
**	Return protocol object or NULL
*/
PUBLIC HTProtocol * HTProtocol_find (HTRequest * request, CONST char * access)
{
    if (request && access) {
	HTList * cur = protocols;
	HTProtocol * pres;
	if (cur) {
	    while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
		if (!strcmp(pres->name, access)) return pres;
	    }
	}
	HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS, (char*) access,
			   (int) strlen(access), "HTProtocol_find");
    }
    return NULL;
}



Webmaster