New file. Contains the sieve namespace functions.
Showing
1 changed file
with
127 additions
and
0 deletions
libsieve/register.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU Lesser General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <unistd.h> | ||
25 | #include <string.h> | ||
26 | #include <sieve.h> | ||
27 | |||
28 | static list_t test_list; | ||
29 | static list_t action_list; | ||
30 | |||
31 | static sieve_register_t * | ||
32 | sieve_lookup (list_t list, const char *name) | ||
33 | { | ||
34 | iterator_t itr; | ||
35 | sieve_register_t *reg; | ||
36 | |||
37 | if (!list || iterator_create (&itr, list)) | ||
38 | return; | ||
39 | |||
40 | for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr)) | ||
41 | { | ||
42 | iterator_current (itr, (void **)®); | ||
43 | if (strcmp (reg->name, name) == 0) | ||
44 | break; | ||
45 | else | ||
46 | reg = NULL; | ||
47 | } | ||
48 | iterator_destroy (&itr); | ||
49 | return reg; | ||
50 | } | ||
51 | |||
52 | sieve_register_t * | ||
53 | sieve_test_lookup (const char *name) | ||
54 | { | ||
55 | return sieve_lookup (test_list, name); | ||
56 | } | ||
57 | |||
58 | sieve_register_t * | ||
59 | sieve_action_lookup (const char *name) | ||
60 | { | ||
61 | return sieve_lookup (action_list, name); | ||
62 | } | ||
63 | |||
64 | static int | ||
65 | sieve_register (list_t *list, | ||
66 | const char *name, sieve_instr_t instr, | ||
67 | sieve_data_type *arg_types, | ||
68 | sieve_tag_def_t *tags, int required) | ||
69 | { | ||
70 | int n; | ||
71 | sieve_register_t *reg = malloc (sizeof (*reg)); | ||
72 | |||
73 | if (!reg) | ||
74 | return ENOMEM; | ||
75 | reg->name = name; | ||
76 | reg->instr = instr; | ||
77 | |||
78 | if (arg_types) | ||
79 | { | ||
80 | for (n = 0; arg_types[n] != SVT_VOID; n++) | ||
81 | ; | ||
82 | } | ||
83 | else | ||
84 | n = 0; | ||
85 | reg->num_req_args = n; | ||
86 | reg->req_args = arg_types; | ||
87 | |||
88 | if (tags) | ||
89 | { | ||
90 | for (n = 0; tags[n].name != NULL; n++) | ||
91 | ; | ||
92 | } | ||
93 | else | ||
94 | n = 0; | ||
95 | reg->num_tags = n; | ||
96 | reg->tags = tags; | ||
97 | reg->required = required; | ||
98 | |||
99 | if (!*list) | ||
100 | { | ||
101 | int rc = list_create (list); | ||
102 | if (rc) | ||
103 | { | ||
104 | free (reg); | ||
105 | return rc; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | return list_append (*list, reg); | ||
110 | } | ||
111 | |||
112 | |||
113 | int | ||
114 | sieve_register_test (const char *name, sieve_instr_t instr, | ||
115 | sieve_data_type *arg_types, | ||
116 | sieve_tag_def_t *tags, int required) | ||
117 | { | ||
118 | return sieve_register (&test_list, name, instr, arg_types, tags, required); | ||
119 | } | ||
120 | |||
121 | int | ||
122 | sieve_register_action (const char *name, sieve_instr_t instr, | ||
123 | sieve_data_type *arg_types, | ||
124 | sieve_tag_def_t *tags, int required) | ||
125 | { | ||
126 | return sieve_register (&action_list, name, instr, arg_types, tags, required); | ||
127 | } |
-
Please register or sign in to post a comment