Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-mime-filter-index.c
1 /*
2  *  Copyright (C) 2000 Ximian Inc.
3  *
4  *  Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "camel-mime-filter-index.h"
22 #include "camel-text-index.h"
23
24 static void camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass);
25 static void camel_mime_filter_index_finalize   (CamelObject *o);
26
27 static CamelMimeFilterClass *camel_mime_filter_index_parent;
28
29 CamelType
30 camel_mime_filter_index_get_type (void)
31 {
32         static CamelType type = CAMEL_INVALID_TYPE;
33         
34         if (type == CAMEL_INVALID_TYPE) {
35                 type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterIndex",
36                                             sizeof (CamelMimeFilterIndex),
37                                             sizeof (CamelMimeFilterIndexClass),
38                                             (CamelObjectClassInitFunc) camel_mime_filter_index_class_init,
39                                             NULL,
40                                             NULL,
41                                             (CamelObjectFinalizeFunc) camel_mime_filter_index_finalize);
42         }
43         
44         return type;
45 }
46
47 static void
48 camel_mime_filter_index_finalize(CamelObject *o)
49 {
50         CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)o;
51
52         if (f->name)
53                 camel_object_unref((CamelObject *)f->name);
54         camel_object_unref((CamelObject *)f->index);
55 }
56
57 static void
58 complete(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
59 {
60         CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)mf;
61
62         if (f->index == NULL || f->name==NULL) {
63                 goto donothing;
64         }
65
66         camel_index_name_add_buffer(f->name, in, len);
67         camel_index_name_add_buffer(f->name, NULL, 0);
68
69 donothing:
70         *out = in;
71         *outlenptr = len;
72         *outprespace = prespace;
73 }
74
75 static void
76 filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
77 {
78         CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)mf;
79
80         if (f->index == NULL || f->name==NULL) {
81                 goto donothing;
82         }
83
84         camel_index_name_add_buffer(f->name, in, len);
85
86 donothing:
87         *out = in;
88         *outlenptr = len;
89         *outprespace = prespace;
90 }
91
92 static void
93 camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass)
94 {
95         CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
96         
97         camel_mime_filter_index_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
98
99         /*filter_class->reset = reset;*/
100         filter_class->filter = filter;
101         filter_class->complete = complete;
102 }
103
104 /**
105  * camel_mime_filter_index_new:
106  *
107  * Create a new #CamelMimeFilterIndex object
108  * 
109  * Returns a new #CamelMimeFilterIndex object
110  **/
111 CamelMimeFilterIndex *
112 camel_mime_filter_index_new (void)
113 {
114         CamelMimeFilterIndex *new = CAMEL_MIME_FILTER_INDEX ( camel_object_new (camel_mime_filter_index_get_type ()));
115         return new;
116 }
117
118
119 /**
120  * camel_mime_filter_index_new_index:
121  * @index: a #CamelIndex object
122  *
123  * Create a new #CamelMimeFilterIndex based on @index.
124  *
125  * Returns a new #CamelMimeFilterIndex object
126  **/
127 CamelMimeFilterIndex *
128 camel_mime_filter_index_new_index (CamelIndex *index)
129 {
130         CamelMimeFilterIndex *new = camel_mime_filter_index_new();
131
132         if (new) {
133                 new->index = index;
134                 if (index)
135                         camel_object_ref (index);
136         }
137         return new;
138 }
139
140 /* Set the match name for any indexed words */
141
142
143 /**
144  * camel_mime_filter_index_set_name:
145  * @filter: a #CamelMimeFilterIndex object
146  * @name: a #CamelIndexName object
147  *
148  * Set the match name for any indexed words.
149  **/
150 void
151 camel_mime_filter_index_set_name (CamelMimeFilterIndex *filter, CamelIndexName *name)
152 {
153         if (filter->name)
154                 camel_object_unref (filter->name);
155         filter->name = name;
156         if (name)
157                 camel_object_ref (name);
158 }
159
160
161 /**
162  * camel_mime_filter_index_set_index:
163  * @filter: a #CamelMimeFilterIndex object
164  * @index: a #CamelIndex object
165  *
166  * Set @index on @filter.
167  **/
168 void
169 camel_mime_filter_index_set_index (CamelMimeFilterIndex *filter, CamelIndex *index)
170 {
171         if (filter->index) {
172                 char *out;
173                 size_t outlen, outspace;
174
175                 camel_mime_filter_complete((CamelMimeFilter *)filter, "", 0, 0, &out, &outlen, &outspace);
176                 camel_object_unref (index);
177         }
178
179         filter->index = index;
180         if (index)
181                 camel_object_ref (index);
182 }