evolution-3.6.4/em-format/e-mail-extension-registry.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-extension-registry.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-extension-registry.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-extension-registry.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  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 GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #include <glib-object.h>
 20 
 21 #include "e-mail-extension-registry.h"
 22 #include "e-mail-extension.h"
 23 #include "e-mail-format-extensions.h"
 24 #include <libebackend/libebackend.h>
 25 #include <camel/camel.h>
 26 
 27 #include <glib-object.h>
 28 
 29 #include <string.h>
 30 
 31 #define E_MAIL_EXTENSION_REGISTRY_GET_PRIVATE(obj) \
 32 	(G_TYPE_INSTANCE_GET_PRIVATE \
 33 	((obj), E_TYPE_MAIL_EXTENSION_REGISTRY, EMailExtensionRegistryPrivate))
 34 
 35 struct _EMailExtensionRegistryPrivate {
 36 	GHashTable *table;
 37 };
 38 
 39 G_DEFINE_ABSTRACT_TYPE (
 40 	EMailExtensionRegistry,
 41 	e_mail_extension_registry,
 42 	G_TYPE_OBJECT)
 43 
 44 /**
 45  * EMailExtensionRegistry:
 46  *
 47  * The #EMailExtensionRegistry is an abstract class representing a registry
 48  * for #EMailExtension<!-//>s.
 49  *
 50  * #EMailParser and #EMailFormatter both have internally a registry object
 51  * based on the #EMailExtensionRegistry.
 52  *
 53  * One extension can registry itself for more mime-types.
 54  */
 55 
 56 static void
 57 mail_extension_registry_finalize (GObject *object)
 58 {
 59 	EMailExtensionRegistry *reg = E_MAIL_EXTENSION_REGISTRY (object);
 60 
 61 	if (reg->priv->table) {
 62 		g_hash_table_destroy (reg->priv->table);
 63 		reg->priv->table = NULL;
 64 	}
 65 
 66 	/* Chain up to parent's finalize() method. */
 67 	G_OBJECT_CLASS (e_mail_extension_registry_parent_class)->
 68 		finalize (object);
 69 }
 70 
 71 void
 72 e_mail_extension_registry_class_init (EMailExtensionRegistryClass *class)
 73 {
 74 	GObjectClass *object_class;
 75 
 76 	g_type_class_add_private (class, sizeof (EMailExtensionRegistryPrivate));
 77 
 78 	object_class = G_OBJECT_CLASS (class);
 79 	object_class->finalize = mail_extension_registry_finalize;
 80 }
 81 
 82 static void
 83 destroy_queue (GQueue *queue)
 84 {
 85 	g_queue_free_full (queue, g_object_unref);
 86 }
 87 
 88 void
 89 e_mail_extension_registry_init (EMailExtensionRegistry *reg)
 90 {
 91 	reg->priv = E_MAIL_EXTENSION_REGISTRY_GET_PRIVATE (reg);
 92 
 93 	reg->priv->table = g_hash_table_new_full (
 94 		g_str_hash, g_str_equal, NULL, (GDestroyNotify) destroy_queue);
 95 }
 96 
 97 /**
 98  * e_mail_extension_registry_add_extension:
 99  * @reg: An #EMailExtensionRegistry
100  * @extension: An #EMailExtension
101  *
102  * Registrys the @extension as a handler for all mime-types that it is able
103  * to handle.
104  */
105 void
106 e_mail_extension_registry_add_extension (EMailExtensionRegistry *reg,
107                                          EMailExtension *extension)
108 {
109 	gint i;
110 	const gchar **types;
111 
112 	g_return_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg));
113 	g_return_if_fail (E_IS_MAIL_EXTENSION (extension));
114 
115 	/* One reference per extension is enough */
116 	g_object_ref (extension);
117 
118 	types = e_mail_extension_get_mime_types (extension);
119 	for (i = 0; types && types[i]; i++) {
120 		GQueue *queue;
121 
122 		queue = g_hash_table_lookup (reg->priv->table, types[i]);
123 		if (!queue) {
124 			queue = g_queue_new ();
125 			g_queue_push_head (queue, extension);
126 			g_hash_table_insert (reg->priv->table, (gchar *) types[i], queue);
127 		} else {
128 			g_queue_push_head (queue, extension);
129 		}
130 
131 		if (camel_debug ("emformat:registry")) {
132 			printf (
133 				"Added extension '%s' for type '%s'\n",
134 				G_OBJECT_TYPE_NAME (extension), types[i]);
135 		}
136 	}
137 }
138 
139 /**
140  * e_mail_extension_registry_remove_extension:
141  * @reg: An #EMailExtensionRegistry
142  * @extension: An #EMailExtension
143  *
144  * Removes @extension from the registry.
145  */
146 void
147 e_mail_extension_registry_remove_extension (EMailExtensionRegistry *reg,
148                                             EMailExtension *extension)
149 {
150 	gint i;
151 	const gchar **types;
152 
153 	g_return_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg));
154 	g_return_if_fail (E_IS_MAIL_EXTENSION (extension));
155 
156 	types = e_mail_extension_get_mime_types (extension);
157 	for (i = 0; types && types[i]; i++) {
158 		GQueue *queue;
159 
160 		queue = g_hash_table_lookup (reg->priv->table, types[i]);
161 		if (!queue) {
162 			i++;
163 			continue;
164 		}
165 
166 		g_queue_remove (queue, extension);
167 
168 		if (camel_debug ("emformat:registry")) {
169 			printf (
170 				"Removed extension '%s' from type '%s'\n",
171 				G_OBJECT_TYPE_NAME (extension), types[i]);
172 		}
173 	}
174 
175 	g_object_unref (extension);
176 }
177 
178 /**
179  * e_mail_extension_registry_get_for_mime_type:
180  * @reg: An #EMailExtensionRegistry
181  * @mime_type: A string with mime-type to look up
182  *
183  * Tries to lookup list of #EMailExtension<!-//>s that has registryed themselves
184  * as handlers for the @mime_type.
185  *
186  * Return value: Returns #GQueue of #EMailExtension<!-//>s or %NULL when there
187  * are no extension registryed for given @mime_type.
188  */
189 GQueue *
190 e_mail_extension_registry_get_for_mime_type (EMailExtensionRegistry *reg,
191                                              const gchar *mime_type)
192 {
193 	g_return_val_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg), NULL);
194 	g_return_val_if_fail (mime_type && *mime_type, NULL);
195 
196 	return g_hash_table_lookup (reg->priv->table, mime_type);
197 }
198 
199 /**
200  * e_mail_extension_registry_get_fallback:
201  * @reg: An #EMailExtensionRegistry
202  * @mime_type: A string with mime-type whose fallback to look up
203  *
204  * Tries to lookup fallback parsers for given mime type. For instance, for
205  * multipart/alternative, it will try to lookup multipart/ * parser.
206  *
207  * Return Value: Returns #QGueue of #EMailExtension<!-//>>s or %NULL when there
208  * are no extensions registryed for the fallback type.
209  */
210 GQueue *
211 e_mail_extension_registry_get_fallback (EMailExtensionRegistry *reg,
212                                         const gchar *mime_type)
213 {
214 	gchar *s, *type;
215 	gsize len;
216 	GQueue *parsers;
217 
218 	g_return_val_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg), NULL);
219 	g_return_val_if_fail (mime_type && *mime_type, NULL);
220 
221 	s = strchr (mime_type, '/');
222 	if (!s)
223 		return NULL;
224 
225 	len = s - mime_type;
226 
227 	s = g_alloca (len);
228 	strncpy (s, mime_type, len);
229 	type = g_ascii_strdown (s, len);
230 	s = g_strdup_printf ("%s/*", type);
231 
232 	parsers = g_hash_table_lookup (reg->priv->table, s);
233 
234 	g_free (type);
235 	g_free (s);
236 
237 	return parsers;
238 }
239 
240 /******************************************************************************/
241 
242 static void e_mail_parser_extension_registry_extensible_interface_init (EExtensibleInterface *iface);
243 
244 G_DEFINE_TYPE_WITH_CODE (
245 	EMailParserExtensionRegistry,
246 	e_mail_parser_extension_registry,
247 	E_TYPE_MAIL_EXTENSION_REGISTRY,
248 	G_IMPLEMENT_INTERFACE (
249 		E_TYPE_EXTENSIBLE,
250 		e_mail_parser_extension_registry_extensible_interface_init));
251 
252 static void
253 e_mail_parser_extension_registry_init (EMailParserExtensionRegistry *parser_ereg)
254 {
255 }
256 
257 static void
258 e_mail_parser_extension_registry_class_init (EMailParserExtensionRegistryClass *class)
259 {
260 }
261 
262 static void
263 e_mail_parser_extension_registry_extensible_interface_init (EExtensibleInterface *interface)
264 {
265 
266 }
267 
268 /******************************************************************************/
269 
270 static void e_mail_formatter_extension_registry_extensible_interface_init (EExtensibleInterface *iface);
271 
272 G_DEFINE_TYPE_WITH_CODE (
273 	EMailFormatterExtensionRegistry,
274 	e_mail_formatter_extension_registry,
275 	E_TYPE_MAIL_EXTENSION_REGISTRY,
276 	G_IMPLEMENT_INTERFACE (
277 		E_TYPE_EXTENSIBLE,
278 		e_mail_formatter_extension_registry_extensible_interface_init));
279 
280 static void
281 e_mail_formatter_extension_registry_init (EMailFormatterExtensionRegistry *formatter_ereg)
282 {
283 
284 }
285 
286 static void
287 e_mail_formatter_extension_registry_class_init (EMailFormatterExtensionRegistryClass *class)
288 {
289 }
290 
291 static void
292 e_mail_formatter_extension_registry_extensible_interface_init (EExtensibleInterface *interface)
293 {
294 
295 }