summaryrefslogtreecommitdiff
path: root/gnu/dist/postfix/src/util/attr.c
blob: 30327454380bd46ba99e938776ac79dad992b54a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*++
/* NAME
/*	attr 3
/* SUMMARY
/*	attribute list manager
/* SYNOPSIS
/*	#include <htable.h>
/*	#include <attr.h>
/*
/*	void	attr_enter(attr, name, value)
/*	HTABLE	*attr;
/*	const char *name;
/*	const char *value;
/*
/*	const char *attr_find(attr, name)
/*	HTABLE	*attr;
/*	const char *name;
/*
/*	void	attr_free(attr)
/*	HTABLE	*attr;
/* DESCRIPTION
/*	This module maintains open attribute lists of string-valued
/*	names and values. The module is built on top of the generic
/*	htable(3) hash table manager.
/*
/*	attr_enter() adds a new attribute or updates an existing one.
/*	Both the name and the value are copied.
/*
/*	attr_find() looks up the named attribute. It returns the
/*	corresponding value if one is found, a null pointer otherwise.
/*
/*	attr_free() destroys the named attribute list and makes its
/*	memory available for reuse.
/* BUGS
/*	This module cannot store null pointer values. If that is a
/*	problem, use the raw hash table management routines instead.
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*--*/

/* System library. */

#include "sys_defs.h"

/* Utility library. */

#include "mymalloc.h"
#include "htable.h"
#include "attr.h"

/* attr_enter - add or replace attribute */

void    attr_enter(HTABLE *attr, const char *name, const char *value)
{
    HTABLE_INFO *ht;

    if ((ht = htable_locate(attr, name)) != 0) {/* replace attribute */
	myfree(ht->value);
	ht->value = mystrdup(value);
    } else {					/* add attribute */
	(void) htable_enter(attr, name, mystrdup(value));
    }
}

/* attr_free - destroy attribute list */

void    attr_free(HTABLE *attr)
{
    htable_free(attr, myfree);
}