10
10
11
11
/* system includes */
12
12
#include <sys/types.h>
13
+ #include <stdlib.h>
13
14
#include <string.h>
14
15
#include <assert.h>
15
16
16
17
/* libopendkim includes */
17
- #include "dkim-tables.h"
18
18
#include "dkim-internal.h"
19
19
20
+ /* structures */
21
+ struct dkim_nametable
22
+ {
23
+ const char * tbl_name ; /* name */
24
+ const int tbl_code ; /* code */
25
+ };
26
+
27
+ struct dkim_iter_ctx
28
+ {
29
+ DKIM_NAMETABLE * current ; /* current table entry */
30
+ _Bool is_eot ; /* It is last entry or not */
31
+ };
32
+
20
33
/* lookup tables */
21
- static struct nametable prv_keyparams [] = /* key parameters */
34
+ static struct dkim_nametable prv_keyparams [] = /* key parameters */
22
35
{
23
36
{ "a" , DKIM_KEY_ALGORITHM },
24
37
{ "n" , DKIM_KEY_NOTES },
@@ -28,17 +41,17 @@ static struct nametable prv_keyparams[] = /* key parameters */
28
41
{ "v" , DKIM_KEY_VERSION },
29
42
{ NULL , -1 }
30
43
};
31
- struct nametable * keyparams = prv_keyparams ;
44
+ DKIM_NAMETABLE * dkim_table_keyparams = prv_keyparams ;
32
45
33
- static struct nametable prv_keyflags [] = /* key flags */
46
+ static struct dkim_nametable prv_keyflags [] = /* key flags */
34
47
{
35
48
{ "y" , DKIM_SIGFLAG_TESTKEY },
36
49
{ "s" , DKIM_SIGFLAG_NOSUBDOMAIN },
37
50
{ NULL , -1 }
38
51
};
39
- struct nametable * keyflags = prv_keyflags ;
52
+ DKIM_NAMETABLE * dkim_table_keyflags = prv_keyflags ;
40
53
41
- static struct nametable prv_sigparams [] = /* signature parameters */
54
+ static struct dkim_nametable prv_sigparams [] = /* signature parameters */
42
55
{
43
56
{ "a" , DKIM_PARAM_SIGNALG },
44
57
{ "b" , DKIM_PARAM_SIGNATURE },
@@ -56,49 +69,49 @@ static struct nametable prv_sigparams[] = /* signature parameters */
56
69
{ "z" , DKIM_PARAM_COPIEDHDRS },
57
70
{ NULL , -1 }
58
71
};
59
- struct nametable * sigparams = prv_sigparams ;
72
+ DKIM_NAMETABLE * dkim_table_sigparams = prv_sigparams ;
60
73
61
- static struct nametable prv_algorithms [] = /* signing algorithms */
74
+ static struct dkim_nametable prv_algorithms [] = /* signing algorithms */
62
75
{
63
76
{ "rsa-sha1" , DKIM_SIGN_RSASHA1 },
64
77
{ "rsa-sha256" , DKIM_SIGN_RSASHA256 },
65
78
{ "ed25519-sha256" , DKIM_SIGN_ED25519SHA256 },
66
79
{ NULL , -1 },
67
80
};
68
- struct nametable * algorithms = prv_algorithms ;
81
+ DKIM_NAMETABLE * dkim_table_algorithms = prv_algorithms ;
69
82
70
- static struct nametable prv_canonicalizations [] = /* canonicalizations */
83
+ static struct dkim_nametable prv_canonicalizations [] = /* canonicalizations */
71
84
{
72
85
{ "simple" , DKIM_CANON_SIMPLE },
73
86
{ "relaxed" , DKIM_CANON_RELAXED },
74
87
{ NULL , -1 },
75
88
};
76
- struct nametable * canonicalizations = prv_canonicalizations ;
89
+ DKIM_NAMETABLE * dkim_table_canonicalizations = prv_canonicalizations ;
77
90
78
- static struct nametable prv_hashes [] = /* hashes */
91
+ static struct dkim_nametable prv_hashes [] = /* hashes */
79
92
{
80
93
{ "sha1" , DKIM_HASHTYPE_SHA1 },
81
94
{ "sha256" , DKIM_HASHTYPE_SHA256 },
82
95
{ NULL , -1 },
83
96
};
84
- struct nametable * hashes = prv_hashes ;
97
+ DKIM_NAMETABLE * dkim_table_hashes = prv_hashes ;
85
98
86
- static struct nametable prv_keytypes [] = /* key types */
99
+ static struct dkim_nametable prv_keytypes [] = /* key types */
87
100
{
88
101
{ "rsa" , DKIM_KEYTYPE_RSA },
89
102
{ "ed25519" , DKIM_KEYTYPE_ED25519 },
90
103
{ NULL , -1 },
91
104
};
92
- struct nametable * keytypes = prv_keytypes ;
105
+ DKIM_NAMETABLE * dkim_table_keytypes = prv_keytypes ;
93
106
94
- static struct nametable prv_querytypes [] = /* query types */
107
+ static struct dkim_nametable prv_querytypes [] = /* query types */
95
108
{
96
109
{ "dns" , DKIM_QUERY_DNS },
97
110
{ NULL , -1 },
98
111
};
99
- struct nametable * querytypes = prv_querytypes ;
112
+ DKIM_NAMETABLE * dkim_table_querytypes = prv_querytypes ;
100
113
101
- static struct nametable prv_results [] = /* result codes */
114
+ static struct dkim_nametable prv_results [] = /* result codes */
102
115
{
103
116
{ "Success" , DKIM_STAT_OK },
104
117
{ "Bad signature" , DKIM_STAT_BADSIG },
@@ -116,20 +129,21 @@ static struct nametable prv_results[] = /* result codes */
116
129
{ "Invalid result" , DKIM_STAT_CBINVALID },
117
130
{ "Try again later" , DKIM_STAT_CBTRYAGAIN },
118
131
{ "Multiple DNS replies" , DKIM_STAT_MULTIDNSREPLY },
132
+ { "End of the table" , DKIM_STAT_ITER_EOT },
119
133
{ NULL , -1 },
120
134
};
121
- struct nametable * results = prv_results ;
135
+ DKIM_NAMETABLE * dkim_table_results = prv_results ;
122
136
123
- static struct nametable prv_settypes [] = /* set types */
137
+ static struct dkim_nametable prv_settypes [] = /* set types */
124
138
{
125
139
{ "key" , DKIM_SETTYPE_KEY },
126
140
{ "signature" , DKIM_SETTYPE_SIGNATURE },
127
141
{ "signature reporting" , DKIM_SETTYPE_SIGREPORT },
128
142
{ NULL , -1 },
129
143
};
130
- struct nametable * settypes = prv_settypes ;
144
+ DKIM_NAMETABLE * dkim_table_settypes = prv_settypes ;
131
145
132
- static struct nametable prv_sigerrors [] = /* signature parsing errors */
146
+ static struct dkim_nametable prv_sigerrors [] = /* signature parsing errors */
133
147
{
134
148
{ "no signature error" , DKIM_SIGERROR_OK },
135
149
{ "unsupported signature version" , DKIM_SIGERROR_VERSION },
@@ -182,15 +196,15 @@ static struct nametable prv_sigerrors[] = /* signature parsing errors */
182
196
#endif /* _FFR_CONDITIONAL */
183
197
{ NULL , -1 },
184
198
};
185
- struct nametable * sigerrors = prv_sigerrors ;
199
+ DKIM_NAMETABLE * dkim_table_sigerrors = prv_sigerrors ;
186
200
187
201
#ifdef _FFR_CONDITIONAL
188
- static struct nametable prv_mandatory [] = /* mandatory DKIM tags */
202
+ static struct dkim_nametable prv_mandatory [] = /* mandatory DKIM tags */
189
203
{
190
204
{ "!cd" , 0 },
191
205
{ NULL , -1 },
192
206
};
193
- struct nametable * mandatory = prv_mandatory ;
207
+ DKIM_NAMETABLE * dkim_table_mandatory = prv_mandatory ;
194
208
#endif /* _FFR_CONDITIONAL */
195
209
196
210
/* ===================================================================== */
@@ -207,7 +221,7 @@ struct nametable *mandatory = prv_mandatory;
207
221
*/
208
222
209
223
const char *
210
- dkim_code_to_name (struct nametable * tbl , const int code )
224
+ dkim_code_to_name (DKIM_NAMETABLE * tbl , const int code )
211
225
{
212
226
int c ;
213
227
@@ -235,7 +249,7 @@ dkim_code_to_name(struct nametable *tbl, const int code)
235
249
*/
236
250
237
251
const int
238
- dkim_name_to_code (struct nametable * tbl , const char * name )
252
+ dkim_name_to_code (DKIM_NAMETABLE * tbl , const char * name )
239
253
{
240
254
int c ;
241
255
@@ -250,3 +264,93 @@ dkim_name_to_code(struct nametable *tbl, const char *name)
250
264
return tbl [c ].tbl_code ;
251
265
}
252
266
}
267
+
268
+ /*
269
+ ** DKIM_NAMETABLE_FIRST -- get the first entry of the table and start iteration
270
+ **
271
+ ** Parameters:
272
+ ** tbl -- name table
273
+ ** ctx -- iteration context (returned)
274
+ ** name -- name in the first item in the table (returned)
275
+ ** code -- code in the first item in the table (returned)
276
+ **
277
+ ** Return value:
278
+ ** A DKIM_STAT_OK -- retrieve the first item successfully
279
+ ** A DKIM_STAT_ITER_EOT -- the table has no item.
280
+ ** A DKIM_STAT_NORESOURCE -- cannot allocate memory for the
281
+ ** iteration context
282
+ **
283
+ */
284
+ DKIM_STAT
285
+ dkim_nametable_first (DKIM_NAMETABLE * tbl , DKIM_ITER_CTX * * ctx ,
286
+ const char * * name , int * code )
287
+ {
288
+ * ctx = (DKIM_ITER_CTX * )
289
+ malloc (sizeof (DKIM_ITER_CTX ));
290
+ if (* ctx == NULL )
291
+ {
292
+ return DKIM_STAT_NORESOURCE ;
293
+ }
294
+ if (tbl -> tbl_name == NULL )
295
+ {
296
+ (* ctx )-> current = NULL ;
297
+ (* ctx )-> is_eot = TRUE;
298
+ return DKIM_STAT_ITER_EOT ;
299
+ }
300
+ * name = tbl -> tbl_name ;
301
+ * code = tbl -> tbl_code ;
302
+ (* ctx )-> current = tbl ;
303
+ (* ctx )-> is_eot = (((* ctx )-> current )[1 ].tbl_name == NULL )? TRUE : FALSE;
304
+ return DKIM_STAT_OK ;
305
+ }
306
+
307
+ /*
308
+ ** DKIM_NAMETABLE_NEXT -- get the next entry on the iteration the table
309
+ **
310
+ ** Parameters:
311
+ ** ctx -- iteration context (updated)
312
+ ** name -- name in the first item in the table (returned)
313
+ ** code -- code in the first item in the table (returned)
314
+ **
315
+ ** Return value:
316
+ ** A DKIM_STAT_OK -- retrieve the first item successfully
317
+ ** A DKIM_STAT_ITER_EOT -- the table has no item.
318
+ **
319
+ */
320
+ DKIM_STAT
321
+ dkim_nametable_next (DKIM_ITER_CTX * ctx , const char * * name , int * code )
322
+ {
323
+ if (ctx -> is_eot )
324
+ {
325
+ return DKIM_STAT_ITER_EOT ;
326
+ }
327
+ ctx -> current ++ ;
328
+ * name = ctx -> current -> tbl_name ;
329
+ * code = ctx -> current -> tbl_code ;
330
+ ctx -> is_eot = ((ctx -> current )[1 ].tbl_name == NULL )? TRUE : FALSE;
331
+ return DKIM_STAT_OK ;
332
+ }
333
+
334
+ /*
335
+ ** DKIM_ITER_CTX_FREE -- release resources associated with
336
+ ** a nametable iteration context
337
+ **
338
+ ** Parameters:
339
+ ** ctx -- iteration context
340
+ **
341
+ ** Return value:
342
+ ** DKIM_STAT_OK -- operation was successful
343
+ **
344
+ ** Note: This function is a placeholder to add some operation associated
345
+ ** with future changes of the structure of the tables.
346
+ **
347
+ */
348
+ DKIM_STAT
349
+ dkim_iter_ctx_free (DKIM_ITER_CTX * ctx )
350
+ {
351
+ if (ctx != NULL )
352
+ {
353
+ free ((void * )ctx );
354
+ }
355
+ return DKIM_STAT_OK ;
356
+ }
0 commit comments