Annotation of libwww/Library/src/HTAssoc.c, revision 2.8
2.2 frystyk 1: /* HTAssoc.c
2: ** ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS.
3: **
2.5 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.2 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
6: **
7: ** NAMES NOT CASE SENSITIVE, AND ONLY COMMON LENGTH
8: ** IS CHECKED (allows abbreviations; well, length is
9: ** taken from lookup-up name, so if table contains
10: ** a shorter abbrev it is not found).
2.1 luotonen 11: ** AUTHORS:
12: ** AL Ari Luotonen luotonen@dxcern.cern.ch
13: **
14: ** HISTORY:
15: **
16: **
17: ** BUGS:
18: **
19: **
20: */
21:
2.4 frystyk 22: /* Library include files */
23: #include "tcp.h"
24: #include "HTUtils.h"
2.1 luotonen 25: #include "HTString.h"
2.8 ! frystyk 26: #include "HTAssoc.h" /* Implemented here */
2.1 luotonen 27:
2.8 ! frystyk 28: PUBLIC HTAssocList *HTAssocList_new (void)
2.1 luotonen 29: {
30: return HTList_new();
31: }
32:
33:
2.8 ! frystyk 34: PUBLIC BOOL HTAssocList_delete (HTAssocList * alist)
2.1 luotonen 35: {
36: if (alist) {
37: HTAssocList *cur = alist;
38: HTAssoc *assoc;
39: while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
40: if (assoc->name) free(assoc->name);
41: if (assoc->value) free(assoc->value);
42: free(assoc);
43: }
2.8 ! frystyk 44: return HTList_delete(alist);
2.1 luotonen 45: }
2.8 ! frystyk 46: return NO;
2.1 luotonen 47: }
48:
49:
2.8 ! frystyk 50: PUBLIC BOOL HTAssocList_add (HTAssocList * alist,
! 51: CONST char * name, CONST char * value)
2.1 luotonen 52: {
53: HTAssoc *assoc;
54: if (alist) {
2.8 ! frystyk 55: if ((assoc = (HTAssoc *) calloc(1, sizeof(HTAssoc))) == NULL)
2.1 luotonen 56: outofmem(__FILE__, "HTAssoc_add");
57: if (name) StrAllocCopy(assoc->name, name);
58: if (value) StrAllocCopy(assoc->value, value);
2.8 ! frystyk 59: return HTList_addObject(alist, (void *) assoc);
! 60: } else {
! 61: if (WWWTRACE)
! 62: TTYPrint(TDEST, "HTAssoc_add: ERROR: assoc list NULL!!\n");
2.1 luotonen 63: }
2.8 ! frystyk 64: return NO;
2.1 luotonen 65: }
66:
67:
2.8 ! frystyk 68: PUBLIC char *HTAssocList_lookup (HTAssocList * alist, CONST char * name)
2.1 luotonen 69: {
70: HTAssocList *cur = alist;
71: HTAssoc *assoc;
2.8 ! frystyk 72: while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
2.1 luotonen 73: if (!strncasecomp(assoc->name, name, strlen(name)))
74: return assoc->value;
75: }
76: return NULL;
77: }
78:
Webmaster