Commit 8576c199 8576c199ee2aef061f5d7501a002a9f22aad77ae by Sergey Poznyakoff

(sieve_slist_destroy, sieve_value_create): New(sieve_slist_destroy, sieve_value_…

…create): New functions.
1 parent 1b57a009
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 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) 6 the Free Software Foundation; either version 2, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 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 15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 17
...@@ -35,3 +35,53 @@ sieve_alloc (size_t size) ...@@ -35,3 +35,53 @@ sieve_alloc (size_t size)
35 return p; 35 return p;
36 } 36 }
37 37
38 void
39 sieve_slist_destroy (list_t *plist)
40 {
41 iterator_t itr;
42
43 if (!plist || iterator_create (&itr, *plist))
44 return;
45
46 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
47 {
48 char *s;
49 iterator_current (itr, (void **)&s);
50 free (s);
51 }
52 iterator_destroy (&itr);
53 list_destroy (plist);
54 }
55
56 sieve_value_t *
57 sieve_value_create (sieve_data_type type, void *data)
58 {
59 sieve_value_t *val = sieve_alloc (sizeof (*val));
60
61 val->type = type;
62 switch (type)
63 {
64 case SVT_NUMBER:
65 val->v.number = * (long *) data;
66 break;
67
68 case SVT_STRING:
69 val->v.string = data;
70 break;
71
72 case SVT_VALUE_LIST:
73 case SVT_STRING_LIST:
74 val->v.list = data;
75
76 case SVT_TAG:
77 case SVT_IDENT:
78 val->v.string = data;
79 break;
80
81 default:
82 sieve_error ("Invalid data type");
83 abort ();
84 }
85 return val;
86 }
87
......