1 /*
2 
3   					W3C Sample Code Library libwww Association Pairs
4 
5 
6 !
7   Association List For Storing Name-Value Pairs
8 !
9 */
10 
11 /*
12 **	(c) COPYRIGHT MIT 1995.
13 **	Please first read the full copyright statement in the file COPYRIGH.
14 */
15 
16 /*
17 
18 This Assoctiation List class is closely related to the
19 HTList Class as it simply is a list of a specific
20 list element containing a characters based name/value pair. Lookups from
21 association list can be case sensitive and or prefix based.
22 
23 This module is implemented by HTAssoc.c, and it is
24 a part of the  W3C Sample Code
25 Library.
26 */
27 
28 #ifndef HTASSOC_H
29 #define HTASSOC_H
30 
31 #include "HTList.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef HTList HTAssocList;
38 
39 typedef struct {
40     char * name;
41     char * value;
42 } HTAssoc;
43 
44 /*
45 .
46   Creation and Deletetion Methods
47 .
48 
49 These methods create and deletes and association list
50 */
51 
52 extern HTAssocList * HTAssocList_new (void);
53 extern BOOL 	     HTAssocList_delete (HTAssocList * alist);
54 
55 /*
56 .
57   Add an Element to a List
58 .
59 
60 We have two methods for adding new elements - you can either add unconditionally
61 or replace any existing element with the same name but a new value.
62 In replacing an element, the search is case insensitive
63 prefix match! A new list element is added to the beginning of the
64 list so that it is the first element just after the head element.
65 */
66 
67 extern BOOL HTAssocList_addObject (
68 	HTAssocList *	alist,
69 	const char *	name,
70 	const char *	value);
71 
72 extern BOOL HTAssocList_replaceObject (
73 	HTAssocList *	list,
74 	const char * 	name,
75 	const char *	value);
76 
77 /*
78 .
79   Remove an Element from a List
80 .
81 
82 Remove the element with the given name from the list. Search is
83 case insensitive prefix match!
84 */
85 
86 extern BOOL HTAssocList_removeObject (
87 	HTAssocList * 	list,
88 	const char * 	name);
89 
90 /*
91 .
92   Search for Element in a list
93 .
94 
95 We have a small set of methods for searching a specific element within a
96 list.
97 (
98   Case Insensitive, Prefix Match
99 )
100 
101 In many situations, the values of associations are case insensitive - use
102 this method to search the list using case insensitive comparison. Also, you
103 can search for matching prefixes and not the whole string, for example
104 "foo" matches "football"
105 */
106 
107 extern char * HTAssocList_findObject (
108 	HTAssocList *	alist,
109 	const char *	name);
110 
111 /*
112 (
113   Case Insensitive, Exact Match
114 )
115 
116 In case you want case insensitive, exact match
117 */
118 
119 extern char * HTAssocList_findObjectExact (
120 	HTAssocList *	alist,
121 	const char *	name);
122 
123 /*
124 (
125   Case Sensitive, Prefix Match
126 )
127 
128 In case you want case sensitive, prefix match
129 */
130 
131 extern char * HTAssocList_findObjectCaseSensitive (
132 	HTAssocList *	list,
133 	const char *	name);
134 
135 /*
136 (
137   Case Sensitive, Exact Match
138 )
139 
140 And finally if you want case sensitive, exact match
141 */
142 
143 extern char * HTAssocList_findObjectCaseSensitiveExact (
144 	HTAssocList *	list,
145 	const char * 	name);
146 
147 /*
148 .
149   Get Name and Values
150 .
151 
152 Use this to get the name and value of a assoc object
153 */
154 
155 #define HTAssoc_name(me)	((me) ? (me)->name : NULL)
156 #define HTAssoc_value(me)	((me) ? (me)->value : NULL)
157 
158 /*
159 .
160   Traverse list
161 .
162 
163 Fast macro to traverse the list. Call it first with copy of list header:
164 it returns the first object and increments the passed list pointer. Call
165 it with the same variable until it returns NULL.
166 */
167 
168 #define	HTAssocList_nextObject(me) \
169 	((me) && ((me) = (me)->next) ? (me)->object : NULL)
170 
171 /*
172 */
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif /* not HTASSOC_H */
179 
180 /*
181 
182 
183 
184   @(#) $Id$
185 
186 */
187