File:
[Public] /
libwww /
Library /
src /
HTAssoc.c
Revision
2.21:
download - view:
text,
annotated -
select for diffs
Thu Oct 21 09:28:27 1999 UTC (24 years, 7 months ago) by
kahan
Branches:
MAIN
CVS tags:
repeat-requests,
candidate-5-4-1,
before_webdav,
Release-5-4-0,
Release-5-3-1,
HEAD,
Amaya_2_4,
Amaya-6-3,
Amaya-6-1,
Amaya-5-2,
Amaya-4-3-2,
Amaya-4-3-1,
Amaya-4-3,
Amaya-4-1-2,
Amaya-4-1-0,
Amaya-4-0-0,
Amaya-3-2-1,
Amaya-3-2,
Amaya
JK: HTAssoc_removeObject wasn't resetting the current list pointer.
/* HTAssoc.c
** ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS.
**
** (c) COPYRIGHT MIT 1995.
** Please first read the full copyright statement in the file COPYRIGH.
** @(#) $Id: HTAssoc.c,v 2.21 1999/10/21 09:28:27 kahan Exp $
**
** NAMES NOT CASE SENSITIVE, AND ONLY COMMON LENGTH
** IS CHECKED (allows abbreviations; well, length is
** taken from lookup-up name, so if table contains
** a shorter abbrev it is not found).
** AUTHORS:
** AL Ari Luotonen luotonen@dxcern.cern.ch
** HFN Henrik Frystyk frystyk@w3.org
**
** HISTORY:
**
**
** BUGS:
**
**
*/
/* Library include files */
#include "wwwsys.h"
#include "HTUtils.h"
#include "HTString.h"
#include "HTAssoc.h" /* Implemented here */
PUBLIC HTAssocList * HTAssocList_new (void)
{
return HTList_new();
}
PUBLIC BOOL HTAssocList_delete (HTAssocList * list)
{
if (list) {
HTAssocList *cur = list;
HTAssoc *assoc;
while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
HT_FREE(assoc->name);
HT_FREE(assoc->value);
HT_FREE(assoc);
}
return HTList_delete(list);
}
return NO;
}
PUBLIC BOOL HTAssocList_addObject (HTAssocList * list,
const char * name, const char * value)
{
if (list && name) {
HTAssoc * assoc;
if ((assoc = (HTAssoc *) HT_CALLOC(1, sizeof(HTAssoc))) == NULL)
HT_OUTOFMEM("HTAssoc_add");
StrAllocCopy(assoc->name, name);
if (value) StrAllocCopy(assoc->value, value);
return HTList_addObject(list, (void *) assoc);
} else {
HTTRACE(UTIL_TRACE, "HTAssoc_add: ERROR: assoc list NULL!!\n");
}
return NO;
}
PUBLIC BOOL HTAssocList_replaceObject (HTAssocList * list,
const char * name, const char * value)
{
if (list && name) {
HTAssocList * cur = list;
HTAssoc * assoc;
int len = strlen(name);
while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
if (!strncasecomp(assoc->name, name, len)) {
StrAllocCopy(assoc->name, name);
if (value) StrAllocCopy(assoc->value, value);
return YES;
}
}
return HTAssocList_addObject(list, name, value);
}
return NO;
}
PUBLIC char * HTAssocList_findObject (HTAssocList * list, const char * name)
{
if (list && name) {
HTAssocList * cur = list;
HTAssoc * assoc;
int len = strlen(name);
while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
if (!strncasecomp(assoc->name, name, len))
return assoc->value;
}
}
return NULL;
}
PUBLIC char * HTAssocList_findObjectExact (HTAssocList * list, const char * name)
{
if (list && name) {
HTAssocList * cur = list;
HTAssoc * assoc;
while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
if (!strcasecomp(assoc->name, name))
return assoc->value;
}
}
return NULL;
}
PUBLIC char * HTAssocList_findObjectCaseSensitive (HTAssocList * list, const char * name)
{
if (list && name) {
HTAssocList * cur = list;
HTAssoc * assoc;
int len = strlen(name);
while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
if (!strncmp(assoc->name, name, len))
return assoc->value;
}
}
return NULL;
}
PUBLIC char * HTAssocList_findObjectCaseSensitiveExact (HTAssocList * list, const char * name)
{
if (list && name) {
HTAssocList * cur = list;
HTAssoc * assoc;
while ((assoc = (HTAssoc *) HTAssocList_nextObject(cur))) {
if (!strcmp(HTAssoc_name(assoc), name))
return HTAssoc_value(assoc);
}
}
return NULL;
}
/*
** Searches the whole list and removes all elements with this name
*/
PUBLIC BOOL HTAssocList_removeObject (HTAssocList * list, const char * name)
{
BOOL found = NO;
if (list && name) {
HTAssocList * cur = list;
HTAssoc * assoc;
int len = strlen(name);
while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
if (!strncasecomp(assoc->name, name, len)) {
HTList_removeObject(list, assoc);
HT_FREE(assoc);
found = YES;
cur = list;
}
}
}
return found;
}
Webmaster