Annotation of libwww/Library/src/HTAssoc.c, revision 2.7
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 "HTAAUtil.h"
26: #include "HTAssoc.h"
27: #include "HTString.h"
28:
29: PUBLIC HTAssocList *HTAssocList_new NOARGS
30: {
31: return HTList_new();
32: }
33:
34:
35: PUBLIC void HTAssocList_delete ARGS1(HTAssocList *, alist)
36: {
37: if (alist) {
38: HTAssocList *cur = alist;
39: HTAssoc *assoc;
40: while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
41: if (assoc->name) free(assoc->name);
42: if (assoc->value) free(assoc->value);
43: free(assoc);
44: }
45: HTList_delete(alist);
46: }
47: }
48:
49:
50: PUBLIC void HTAssocList_add ARGS3(HTAssocList *, alist,
51: CONST char *, name,
52: CONST char *, value)
53: {
54: HTAssoc *assoc;
55:
56: if (alist) {
57: if (!(assoc = (HTAssoc*)malloc(sizeof(HTAssoc))))
58: outofmem(__FILE__, "HTAssoc_add");
59: assoc->name = NULL;
60: assoc->value = NULL;
61:
62: if (name) StrAllocCopy(assoc->name, name);
63: if (value) StrAllocCopy(assoc->value, value);
64: HTList_addObject(alist, (void*)assoc);
65: }
2.7 ! frystyk 66: else if (WWWTRACE) TTYPrint(TDEST, "HTAssoc_add: ERROR: assoc list NULL!!\n");
2.1 luotonen 67: }
68:
69:
70: PUBLIC char *HTAssocList_lookup ARGS2(HTAssocList *, alist,
71: CONST char *, name)
72: {
73: HTAssocList *cur = alist;
74: HTAssoc *assoc;
75:
76: while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
77: if (!strncasecomp(assoc->name, name, strlen(name)))
78: return assoc->value;
79: }
80: return NULL;
81: }
82:
Webmaster