|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef NW_NVPAIR_H |
|
19 #define NW_NVPAIR_H |
|
20 |
|
21 /* |
|
22 ** Includes |
|
23 */ |
|
24 #include "nwx_defs.h" |
|
25 #include "BrsrStatusCodes.h" |
|
26 |
|
27 #ifdef __cplusplus |
|
28 extern "C" { |
|
29 #endif |
|
30 |
|
31 /* Identifier validation according WMLScript 6.1.6 */ |
|
32 NW_Bool NW_CheckName(const NW_Ucs2* name); |
|
33 |
|
34 /* |
|
35 Description: |
|
36 The NW_NVPair_t abstract data type is for storing name value string |
|
37 pairs. It is implemented to be created and accessed |
|
38 sequencially, and to use as little memory as possible. A typical |
|
39 calling sequence is: |
|
40 |
|
41 |
|
42 Typical calling sequence to create and populate an object: |
|
43 postFields = NW_NVPair_New(); |
|
44 while () { |
|
45 status = NW_NVPair_CalSize(postFields, name, value); |
|
46 } |
|
47 status = NW_NVPair_AllocStorage( postFields ); |
|
48 |
|
49 while () { |
|
50 status = NW_NVPair_Add(postFields, name, value); |
|
51 } |
|
52 |
|
53 (void) NW_NVPair_ResetIter( postFields ); |
|
54 |
|
55 Typical calling sequence to interate through a created object: |
|
56 (void) NW_NVPair_ResetIter( postfields ); |
|
57 |
|
58 status = NW_NVPair_GetNext( postfields, &name, &value ); |
|
59 while ( status == KBrsrSuccess ) { |
|
60 ** code that uses name-value pairs ** |
|
61 status = NW_NVPair_GetNext( postfields, &name, &value ); |
|
62 } |
|
63 if ( status != KBrsrNotFound ) { |
|
64 return status; |
|
65 } |
|
66 */ |
|
67 |
|
68 /* |
|
69 ** Type Declarations |
|
70 */ |
|
71 /* Holds name-value pairs as ucs2 strings. */ |
|
72 typedef struct { |
|
73 NW_Ucs2* iterPtr; /* Used to keep place with iterating over pairs. */ |
|
74 NW_Ucs2* strTable; /* Array of null-terminated ucs2 strings. */ |
|
75 NW_Uint32 size; /* Total # of ucs2 chars of string space. */ |
|
76 } NW_NVPair_t; |
|
77 |
|
78 /* a function type for passing a name value string pair */ |
|
79 typedef TBrowserStatusCode (NW_NVPair_NVFunction_t)(NW_NVPair_t* thisObj, |
|
80 const NW_Ucs2* name, |
|
81 const NW_Ucs2* value); |
|
82 /* |
|
83 ** Preprocessor Macro Definitions |
|
84 */ |
|
85 |
|
86 |
|
87 /* |
|
88 ** Global Function Declarations |
|
89 */ |
|
90 |
|
91 /***************************************************************** |
|
92 |
|
93 Name: NW_NVPair_New |
|
94 |
|
95 Description: Allocates a NW_Pair_t object. |
|
96 |
|
97 Parameters: none |
|
98 |
|
99 Return Value: pointer to newly create object. If fails, NULL. |
|
100 |
|
101 ******************************************************************/ |
|
102 NW_NVPair_t* NW_NVPair_New (void); |
|
103 |
|
104 /***************************************************************** |
|
105 |
|
106 Name: NW_NVPair_Delete |
|
107 |
|
108 Description: |
|
109 Dellocates a NW_Pair_t object. Allows thisObj == NULL. |
|
110 |
|
111 |
|
112 Parameters: |
|
113 thisObj - in: Object to deallocate. |
|
114 |
|
115 Return Value: none |
|
116 |
|
117 ******************************************************************/ |
|
118 void NW_NVPair_Delete (NW_NVPair_t* thisObj); |
|
119 |
|
120 /***************************************************************** |
|
121 |
|
122 Name: NW_NVPair_IsEmpty |
|
123 |
|
124 Description: |
|
125 Returns NW_TRUE if the object is NULL or it does not contain |
|
126 any value-pairs. |
|
127 |
|
128 Parameters: |
|
129 thisObj - in: Object to deallocate. |
|
130 |
|
131 Return Value: |
|
132 NW_TRUE - if object contains 1 or more name-value pairs. |
|
133 NW_FALSE - if object is null or it is empty (no name-value pairs). |
|
134 |
|
135 ******************************************************************/ |
|
136 NW_Bool NW_NVPair_IsEmpty (NW_NVPair_t* thisObj); |
|
137 |
|
138 |
|
139 /***************************************************************** |
|
140 |
|
141 Name: NW_NVPair_CalSize |
|
142 |
|
143 Description: |
|
144 Records the storage requirements for the name-value |
|
145 pair. Counts string plus null-terminater. Used when AddFirst is |
|
146 called to allocate all the necessary storage at once. |
|
147 |
|
148 Parameters: |
|
149 thisObj - in/out: NW_NV_Pair_t object. |
|
150 name - in: name string |
|
151 value - in: value string |
|
152 |
|
153 Requires: |
|
154 (name != NULL) && (name[0] != '\0') |
|
155 thisObj != NULL |
|
156 |
|
157 Return Value: |
|
158 KBrsrSuccess |
|
159 |
|
160 ******************************************************************/ |
|
161 NW_NVPair_NVFunction_t NW_NVPair_CalSize; |
|
162 |
|
163 |
|
164 /***************************************************************** |
|
165 |
|
166 Name: NW_NVPair_AllocStorage |
|
167 |
|
168 Description: |
|
169 This routine allocates the storage to all the name-value pairs |
|
170 this object will hold. |
|
171 |
|
172 Parameters: |
|
173 thisObj - in/out: NW_NV_Pair_t object. |
|
174 |
|
175 Requires: |
|
176 thisObj != NULL |
|
177 thisObj->size >= 3 (minimum to hold 1 name-value pair) |
|
178 |
|
179 Return Value: |
|
180 KBrsrSuccess |
|
181 KBrsrOutOfMemory - unable to allocate storage for name-value |
|
182 pairs. |
|
183 |
|
184 ******************************************************************/ |
|
185 TBrowserStatusCode NW_NVPair_AllocStorage (NW_NVPair_t* thisObj); |
|
186 |
|
187 /***************************************************************** |
|
188 |
|
189 Name: NW_NVPair_Add |
|
190 |
|
191 Description: |
|
192 Adds a name-value pair to the object. Must be called after |
|
193 NW_NVPair_AllocStorage is called to allocate memory. |
|
194 |
|
195 Parameters: |
|
196 thisObj - in/out: NW_NV_Pair_t object. |
|
197 name - in: name string. |
|
198 value - in: value string. |
|
199 |
|
200 Requires: |
|
201 thisObj != NULL |
|
202 (name != NULL) && (name[0] != '\0') |
|
203 |
|
204 Return Value: |
|
205 KBrsrSuccess |
|
206 KBrsrBufferTooSmall - name-value will not fit in allocated |
|
207 storage. |
|
208 |
|
209 ******************************************************************/ |
|
210 NW_NVPair_NVFunction_t NW_NVPair_Add; |
|
211 |
|
212 |
|
213 /***************************************************************** |
|
214 |
|
215 Name: NW_NVPair_ResetIter |
|
216 |
|
217 Description: |
|
218 Sets the iterator for NW_NVPair_GetNext to start at the first |
|
219 name-value pair. Allows thisObj == NULL; |
|
220 |
|
221 Parameters: |
|
222 thisObj - in/out: NW_NV_Pair_t object. |
|
223 |
|
224 Return Value: |
|
225 KBrsrSuccess |
|
226 |
|
227 ******************************************************************/ |
|
228 TBrowserStatusCode NW_NVPair_ResetIter (NW_NVPair_t* thisObj); |
|
229 |
|
230 /***************************************************************** |
|
231 |
|
232 Name: NW_NVPair_GetNext |
|
233 |
|
234 Description: |
|
235 Returns subsequent name-value pair in the order they have been |
|
236 inserted. Returns KBrsrNotFound when no more name-value |
|
237 pairs to return. Allows thisObj == NULL; |
|
238 |
|
239 Parameters: |
|
240 thisObj - in/out: NW_NV_Pair_t object. |
|
241 name - out: name string. |
|
242 value - out: value string. Returns NULL pointer for empty string (""). |
|
243 |
|
244 Return Value: |
|
245 KBrsrSuccess |
|
246 KBrsrNotFound - returned if there is not a name-value |
|
247 pair to return. |
|
248 |
|
249 ******************************************************************/ |
|
250 TBrowserStatusCode NW_NVPair_GetNext (NW_NVPair_t* thisObj, NW_Ucs2** name, |
|
251 NW_Ucs2** value); |
|
252 |
|
253 |
|
254 /* |
|
255 ** Global Variable Declarations |
|
256 */ |
|
257 |
|
258 #ifdef __cplusplus |
|
259 } /* extern "C" */ |
|
260 #endif |
|
261 |
|
262 #endif /* NW_NVPAIR_H */ |
|
263 |
|
264 |