~ubuntu-branches/ubuntu/warty/lynx/warty-security

« back to all changes in this revision

Viewing changes to WWW/Library/Implementation/HTAssoc.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-16 12:14:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040916121410-cz1gu92c4nqfeyrg
Tags: upstream-2.8.5
ImportĀ upstreamĀ versionĀ 2.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* MODULE                                                       HTAssoc.c
 
3
**          ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS.
 
4
**          NAMES NOT CASE SENSITIVE, AND ONLY COMMON LENGTH
 
5
**          IS CHECKED (allows abbreviations; well, length is
 
6
**          taken from lookup-up name, so if table contains
 
7
**          a shorter abbrev it is not found).
 
8
** AUTHORS:
 
9
**      AL      Ari Luotonen    luotonen@dxcern.cern.ch
 
10
**
 
11
** HISTORY:
 
12
**
 
13
**
 
14
** BUGS:
 
15
**
 
16
**
 
17
*/
 
18
 
 
19
#include <HTUtils.h>
 
20
 
 
21
#include <HTAssoc.h>
 
22
 
 
23
#include <LYLeaks.h>
 
24
 
 
25
PUBLIC HTAssocList *HTAssocList_new NOARGS
 
26
{
 
27
    return HTList_new();
 
28
}
 
29
 
 
30
 
 
31
PUBLIC void HTAssocList_delete ARGS1(HTAssocList *, alist)
 
32
{
 
33
    if (alist) {
 
34
        HTAssocList *cur = alist;
 
35
        HTAssoc *assoc;
 
36
        while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
 
37
            FREE(assoc->name);
 
38
            FREE(assoc->value);
 
39
            FREE(assoc);
 
40
        }
 
41
        HTList_delete(alist);
 
42
        alist = NULL;
 
43
    }
 
44
}
 
45
 
 
46
 
 
47
PUBLIC void HTAssocList_add ARGS3(HTAssocList *,        alist,
 
48
                                  CONST char *,         name,
 
49
                                  CONST char *,         value)
 
50
{
 
51
    HTAssoc *assoc;
 
52
 
 
53
    if (alist) {
 
54
        if (!(assoc = (HTAssoc*)malloc(sizeof(HTAssoc))))
 
55
            outofmem(__FILE__, "HTAssoc_add");
 
56
        assoc->name = NULL;
 
57
        assoc->value = NULL;
 
58
 
 
59
        if (name)
 
60
            StrAllocCopy(assoc->name, name);
 
61
        if (value)
 
62
            StrAllocCopy(assoc->value, value);
 
63
        HTList_addObject(alist, (void*)assoc);
 
64
    } else {
 
65
        CTRACE((tfp, "HTAssoc_add: ERROR: assoc list NULL!!\n"));
 
66
    }
 
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