summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-11-08 15:55:43 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-11-08 15:55:43 +0000
commitfd97a959a4a12981eb865626f1b183ad5dee72d2 (patch)
tree25bbddcd1d85f2e5ec7d2509349548f557a715d4
parent916871ec72d163e1f77273ba693cc2fb7e4a73fa (diff)
downloadmailutils-fd97a959a4a12981eb865626f1b183ad5dee72d2.tar.gz
mailutils-fd97a959a4a12981eb865626f1b183ad5dee72d2.tar.bz2
New file. Contains the sieve namespace functions.
-rw-r--r--libsieve/register.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/libsieve/register.c b/libsieve/register.c
new file mode 100644
index 000000000..8f69b0125
--- /dev/null
+++ b/libsieve/register.c
@@ -0,0 +1,127 @@
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
28static list_t test_list;
29static list_t action_list;
30
31static sieve_register_t *
32sieve_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 **)&reg);
43 if (strcmp (reg->name, name) == 0)
44 break;
45 else
46 reg = NULL;
47 }
48 iterator_destroy (&itr);
49 return reg;
50}
51
52sieve_register_t *
53sieve_test_lookup (const char *name)
54{
55 return sieve_lookup (test_list, name);
56}
57
58sieve_register_t *
59sieve_action_lookup (const char *name)
60{
61 return sieve_lookup (action_list, name);
62}
63
64static int
65sieve_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
113int
114sieve_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
121int
122sieve_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}

Return to:

Send suggestions and report system problems to the System administrator.