aboutsummaryrefslogtreecommitdiffstats
path: root/em-format
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-10-24 22:08:27 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-10-27 21:25:01 +0800
commitc58b70659747967568a536e217b9440424709f92 (patch)
tree1d730d70de24b72ca0b9d200ad25cf28da3cbd05 /em-format
parent4bc632c800acd4d8228224bb628f2de38090f550 (diff)
downloadgsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.tar
gsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.tar.gz
gsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.tar.bz2
gsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.tar.lz
gsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.tar.xz
gsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.tar.zst
gsoc2013-evolution-c58b70659747967568a536e217b9440424709f92.zip
Prefer GQueue (or GNode) over EDList.
Diffstat (limited to 'em-format')
-rw-r--r--em-format/em-format-quote.c12
-rw-r--r--em-format/em-format.c205
-rw-r--r--em-format/em-format.h50
3 files changed, 129 insertions, 138 deletions
diff --git a/em-format/em-format-quote.c b/em-format/em-format-quote.c
index 4bbe977918..c329769976 100644
--- a/em-format/em-format-quote.c
+++ b/em-format/em-format-quote.c
@@ -389,7 +389,7 @@ emfq_format_headers (EMFormatQuote *emfq, CamelStream *stream, CamelMedium *part
EMFormat *emf = (EMFormat *) emfq;
CamelContentType *ct;
const gchar *charset;
- EMFormatHeader *h;
+ GList *link;
if (!part)
return;
@@ -399,10 +399,12 @@ emfq_format_headers (EMFormatQuote *emfq, CamelStream *stream, CamelMedium *part
charset = camel_iconv_charset_name (charset);
/* dump selected headers */
- h = (EMFormatHeader *) emf->header_list.head;
- while (h->next) {
- emfq_format_header (emf, stream, part, h->name, h->flags, charset);
- h = h->next;
+ link = g_queue_peek_head_link (&emf->header_list);
+ while (link != NULL) {
+ EMFormatHeader *h = link->data;
+ emfq_format_header (
+ emf, stream, part, h->name, h->flags, charset);
+ link = g_list_next (link);
}
camel_stream_printf(stream, "<br>\n");
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 9d3cb7c1f9..3308763ee5 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -31,7 +31,6 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include <libedataserver/e-msgport.h>
#include <camel/camel-stream.h>
#include <camel/camel-stream-mem.h>
#include <camel/camel-multipart.h>
@@ -179,7 +178,7 @@ emf_init (EMFormat *emf)
(GDestroyNotify) emf_free_cache);
emf->composer = FALSE;
emf->print = FALSE;
- e_dlist_init(&emf->header_list);
+ g_queue_init (&emf->header_list);
em_format_default_headers(emf);
emf->part_id = g_string_new("");
emf->validity_found = 0;
@@ -392,7 +391,11 @@ em_format_fallback_handler(EMFormat *emf, const gchar *mime_type)
* are resolved by forgetting the old PURI in the global index.
**/
EMFormatPURI *
-em_format_add_puri(EMFormat *emf, gsize size, const gchar *cid, CamelMimePart *part, EMFormatPURIFunc func)
+em_format_add_puri (EMFormat *emf,
+ gsize size,
+ const gchar *cid,
+ CamelMimePart *part,
+ EMFormatPURIFunc func)
{
EMFormatPURI *puri;
const gchar *tmp;
@@ -450,11 +453,11 @@ em_format_add_puri(EMFormat *emf, gsize size, const gchar *cid, CamelMimePart *p
g_return_val_if_fail (emf->pending_uri_level != NULL, NULL);
g_return_val_if_fail (emf->pending_uri_table != NULL, NULL);
- e_dlist_addtail(&emf->pending_uri_level->uri_list, (EDListNode *)puri);
+ g_queue_push_tail (emf->pending_uri_level->data, puri);
if (puri->uri)
- g_hash_table_insert(emf->pending_uri_table, puri->uri, puri);
- g_hash_table_insert(emf->pending_uri_table, puri->cid, puri);
+ g_hash_table_insert (emf->pending_uri_table, puri->uri, puri);
+ g_hash_table_insert (emf->pending_uri_table, puri->cid, puri);
return puri;
}
@@ -470,21 +473,20 @@ em_format_add_puri(EMFormat *emf, gsize size, const gchar *cid, CamelMimePart *p
* the base location.
**/
void
-em_format_push_level(EMFormat *emf)
+em_format_push_level (EMFormat *emf)
{
- struct _EMFormatPURITree *purilist;
-
- d(printf("em_format_push_level\n"));
- purilist = g_malloc0(sizeof(*purilist));
- e_dlist_init(&purilist->children);
- e_dlist_init(&purilist->uri_list);
- purilist->parent = emf->pending_uri_level;
- if (emf->pending_uri_tree == NULL) {
- emf->pending_uri_tree = purilist;
- } else {
- e_dlist_addtail(&emf->pending_uri_level->children, (EDListNode *)purilist);
- }
- emf->pending_uri_level = purilist;
+ GNode *node;
+
+ g_return_if_fail (EM_IS_FORMAT (emf));
+
+ node = g_node_new (g_queue_new ());
+
+ if (emf->pending_uri_tree == NULL)
+ emf->pending_uri_tree = node;
+ else
+ g_node_append (emf->pending_uri_tree, node);
+
+ emf->pending_uri_level = node;
}
/**
@@ -495,9 +497,11 @@ em_format_push_level(EMFormat *emf)
* no PURI values are actually freed.
**/
void
-em_format_pull_level(EMFormat *emf)
+em_format_pull_level (EMFormat *emf)
{
- d(printf("em_format_pull_level\n"));
+ g_return_if_fail (EM_IS_FORMAT (emf));
+ g_return_if_fail (emf->pending_uri_level != NULL);
+
emf->pending_uri_level = emf->pending_uri_level->parent;
}
@@ -512,23 +516,35 @@ em_format_pull_level(EMFormat *emf)
* Return value:
**/
EMFormatPURI *
-em_format_find_visible_puri(EMFormat *emf, const gchar *uri)
+em_format_find_visible_puri (EMFormat *emf,
+ const gchar *uri)
{
- EMFormatPURI *pw;
- struct _EMFormatPURITree *ptree;
+ GNode *node;
+
+ g_return_val_if_fail (EM_IS_FORMAT (emf), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
- d(printf("checking for visible uri '%s'\n", uri));
+ node = emf->pending_uri_level;
- ptree = emf->pending_uri_level;
- while (ptree) {
- pw = (EMFormatPURI *)ptree->uri_list.head;
- while (pw->next) {
- d(printf(" pw->uri = '%s' pw->cid = '%s\n", pw->uri?pw->uri:"", pw->cid));
- if ((pw->uri && !strcmp(pw->uri, uri)) || !strcmp(pw->cid, uri))
+ while (node != NULL) {
+ GQueue *queue = node->data;
+ GList *link;
+
+ link = g_queue_peek_head_link (queue);
+
+ while (link != NULL) {
+ EMFormatPURI *pw = link->data;
+
+ if (g_strcmp0 (pw->uri, uri) == 0)
return pw;
- pw = pw->next;
+
+ if (g_strcmp0 (pw->cid, uri) == 0)
+ return pw;
+
+ link = g_list_next (link);
}
- ptree = ptree->parent;
+
+ node = node->parent;
}
return NULL;
@@ -545,50 +561,36 @@ em_format_find_visible_puri(EMFormat *emf, const gchar *uri)
* Return value:
**/
EMFormatPURI *
-
-em_format_find_puri(EMFormat *emf, const gchar *uri)
+em_format_find_puri (EMFormat *emf,
+ const gchar *uri)
{
- return g_hash_table_lookup(emf->pending_uri_table, uri);
-}
+ g_return_val_if_fail (EM_IS_FORMAT (emf), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
-static void
-emf_clear_puri_node(struct _EMFormatPURITree *node)
-{
- {
- EMFormatPURI *pw, *pn;
-
- /* clear puri's at this level */
- pw = (EMFormatPURI *)node->uri_list.head;
- pn = pw->next;
- while (pn) {
- d(printf ("freeing pw %p format:%p\n", pw, pw->format));
- if (pw->free)
- pw->free(pw);
- g_free(pw->uri);
- g_free(pw->cid);
- g_free(pw->part_id);
- if (pw->part)
- camel_object_unref(pw->part);
- g_free(pw);
- pw = pn;
- pn = pn->next;
- }
- }
+ g_return_val_if_fail (emf->pending_uri_table != NULL, NULL);
- {
- struct _EMFormatPURITree *cw, *cn;
+ return g_hash_table_lookup (emf->pending_uri_table, uri);
+}
- /* clear child nodes */
- cw = (struct _EMFormatPURITree *)node->children.head;
- cn = cw->next;
- while (cn) {
- emf_clear_puri_node(cw);
- cw = cn;
- cn = cn->next;
- }
+static gboolean
+emf_clear_puri_node (GNode *node)
+{
+ GQueue *queue = node->data;
+ EMFormatPURI *pn;
+
+ while ((pn = g_queue_pop_head (queue)) != NULL) {
+ d(printf ("freeing pw %p format:%p\n", pw, pw->format));
+ if (pn->free)
+ pn->free(pn);
+ g_free(pn->uri);
+ g_free(pn->cid);
+ g_free(pn->part_id);
+ if (pn->part)
+ camel_object_unref(pn->part);
+ g_free(pn);
}
- g_free(node);
+ return FALSE;
}
/**
@@ -601,16 +603,24 @@ emf_clear_puri_node(struct _EMFormatPURITree *node)
void
em_format_clear_puri_tree(EMFormat *emf)
{
- d(printf("clearing pending uri's\n"));
+ if (emf->pending_uri_table == NULL)
+ emf->pending_uri_table =
+ g_hash_table_new (g_str_hash, g_str_equal);
+
+ else {
+ g_hash_table_remove_all (emf->pending_uri_table);
+
+ g_node_traverse (
+ emf->pending_uri_tree,
+ G_IN_ORDER, G_TRAVERSE_ALL, -1,
+ (GNodeTraverseFunc) emf_clear_puri_node, NULL);
+ g_node_destroy (emf->pending_uri_tree);
- if (emf->pending_uri_table) {
- g_hash_table_destroy(emf->pending_uri_table);
- emf_clear_puri_node(emf->pending_uri_tree);
- emf->pending_uri_level = NULL;
emf->pending_uri_tree = NULL;
+ emf->pending_uri_level = NULL;
}
- emf->pending_uri_table = g_hash_table_new(g_str_hash, g_str_equal);
- em_format_push_level(emf);
+
+ em_format_push_level (emf);
}
/* use mime_type == NULL to force showing as application/octet-stream */
@@ -719,7 +729,7 @@ emf_format_clone(EMFormat *emf, CamelFolder *folder, const gchar *uid, CamelMime
if (emf != emfsource) {
g_hash_table_remove_all(emf->inline_table);
if (emfsource) {
- struct _EMFormatHeader *h;
+ GList *link;
/* We clone the current state here */
g_hash_table_foreach(emfsource->inline_table, emf_clone_inlines, emf);
@@ -730,8 +740,13 @@ emf_format_clone(EMFormat *emf, CamelFolder *folder, const gchar *uid, CamelMime
emf->default_charset = g_strdup (emfsource->default_charset);
em_format_clear_headers(emf);
- for (h = (struct _EMFormatHeader *)emfsource->header_list.head; h->next; h = h->next)
- em_format_add_header(emf, h->name, h->flags);
+
+ link = g_queue_peek_head_link (&emfsource->header_list);
+ while (link != NULL) {
+ struct _EMFormatHeader *h = link->data;
+ em_format_add_header (emf, h->name, h->flags);
+ link = g_list_next (link);
+ }
}
}
@@ -928,12 +943,12 @@ em_format_set_default_charset(EMFormat *emf, const gchar *charset)
* be shown.
**/
void
-em_format_clear_headers(EMFormat *emf)
+em_format_clear_headers (EMFormat *emf)
{
EMFormatHeader *eh;
- while ((eh = (EMFormatHeader *)e_dlist_remhead(&emf->header_list)))
- g_free(eh);
+ while ((eh = g_queue_pop_head (&emf->header_list)) != NULL)
+ g_free (eh);
}
/* note: also copied in em-mailer-prefs.c */
@@ -988,7 +1003,7 @@ void em_format_add_header(EMFormat *emf, const gchar *name, guint32 flags)
h = g_malloc(sizeof(*h) + strlen(name));
h->flags = flags;
strcpy(h->name, name);
- e_dlist_addtail(&emf->header_list, (EDListNode *)h);
+ g_queue_push_tail (&emf->header_list, h);
}
/**
@@ -1553,8 +1568,7 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
const gchar *start;
gint i, nparts, partidlen, displayid = 0;
gchar *oldpartid;
- struct _EMFormatPURITree *ptree;
- EMFormatPURI *puri, *purin;
+ GList *link;
if (!CAMEL_IS_MULTIPART(mp)) {
em_format_format_source(emf, stream, part);
@@ -1601,6 +1615,8 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
for (i = 0; i < nparts; i++) {
body_part = camel_multipart_get_part(mp, i);
if (body_part != display_part) {
+ EMFormatPURI *puri;
+
/* set the partid since add_puri uses it */
g_string_append_printf(emf->part_id, ".related.%d", i);
puri = em_format_add_puri(emf, sizeof(EMFormatPURI), NULL, body_part, emf_write_related);
@@ -1614,10 +1630,11 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
g_string_truncate(emf->part_id, partidlen);
camel_stream_flush(stream);
- ptree = emf->pending_uri_level;
- puri = (EMFormatPURI *)ptree->uri_list.head;
- purin = puri->next;
- while (purin) {
+ link = g_queue_peek_head_link (emf->pending_uri_level->data);
+
+ while (link->next != NULL) {
+ EMFormatPURI *puri = link->data;
+
if (puri->use_count == 0) {
d(printf("part '%s' '%s' used '%d'\n", puri->uri?puri->uri:"", puri->cid, puri->use_count));
if (puri->func == emf_write_related) {
@@ -1627,8 +1644,8 @@ emf_multipart_related(EMFormat *emf, CamelStream *stream, CamelMimePart *part, c
d(printf("unreferenced uri generated by format code: %s\n", puri->uri?puri->uri:puri->cid));
}
}
- puri = purin;
- purin = purin->next;
+
+ link = g_list_next (link);
}
g_string_printf(emf->part_id, "%s", oldpartid);
diff --git a/em-format/em-format.h b/em-format/em-format.h
index d3a331b6d6..4d8beaa228 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -36,7 +36,6 @@
#include <camel/camel-mime-part.h>
#include <camel/camel-mime-message.h>
#include <camel/camel-cipher-context.h>
-#include <libedataserver/e-msgport.h>
/* Standard GObject macros */
#define EM_TYPE_FORMAT \
@@ -89,7 +88,7 @@ struct _EMFormatHandler {
EMFormatFunc handler;
guint32 flags;
- struct _EMFormatHandler *old;
+ EMFormatHandler *old;
};
/**
@@ -112,8 +111,6 @@ typedef void (*EMFormatPURIFunc)(EMFormat *md, CamelStream *stream, EMFormatPURI
/**
* struct _EMFormatPURI - Pending URI object.
*
- * @next: Double-linked list header.
- * @prev: Double-linked list header.
* @free: May be set by allocator and will be called when no longer needed.
* @format:
* @uri: Calculated URI of the part, if the part has one in its
@@ -133,11 +130,8 @@ typedef void (*EMFormatPURIFunc)(EMFormat *md, CamelStream *stream, EMFormatPURI
* This object may be subclassed as a struct.
**/
struct _EMFormatPURI {
- struct _EMFormatPURI *next;
- struct _EMFormatPURI *prev;
-
- void (*free)(struct _EMFormatPURI *p); /* optional callback for freeing user-fields */
- struct _EMFormat *format;
+ void (*free)(EMFormatPURI *p); /* optional callback for freeing user-fields */
+ EMFormat *format;
gchar *uri; /* will be the location of the part, may be empty */
gchar *cid; /* will always be set, a fake one created if needed */
@@ -149,31 +143,7 @@ struct _EMFormatPURI {
guint use_count; /* used by multipart/related to see if it was accessed */
};
-/**
- * struct _EMFormatPURITree - Pending URI visibility tree.
- *
- * @next: Double-linked list header.
- * @prev: Double-linked list header.
- * @parent: Parent in tree.
- * @uri_list: List of EMFormatPURI objects at this level.
- * @children: Child nodes of EMFormatPURITree.
- *
- * This structure is used internally to form a visibility tree of
- * parts in the current formatting stream. This is to implement the
- * part resolution rules for RFC2387 to implement multipart/related.
- **/
-struct _EMFormatPURITree {
- struct _EMFormatPURITree *next;
- struct _EMFormatPURITree *prev;
- struct _EMFormatPURITree *parent;
-
- EDList uri_list;
- EDList children;
-};
-
struct _EMFormatHeader {
- struct _EMFormatHeader *next, *prev;
-
guint32 flags; /* E_FORMAT_HEADER_* */
gchar name[1];
};
@@ -226,7 +196,7 @@ struct _EMFormat {
GString *part_id; /* current part id prefix, for identifying parts directly */
- EDList header_list; /* if empty, then all */
+ GQueue header_list; /* if empty, then all */
CamelSession *session; /* session, used for authentication when required */
CamelURL *base; /* content-base header or absolute content-location, for any part */
@@ -245,10 +215,12 @@ struct _EMFormat {
/* global lookup table for message */
GHashTable *pending_uri_table;
- /* visibility tree, also stores every puri permanently */
- struct _EMFormatPURITree *pending_uri_tree;
+ /* This structure is used internally to form a visibility tree of
+ * parts in the current formatting stream. This is to implement the
+ * part resolution rules for RFC2387 to implement multipart/related. */
+ GNode *pending_uri_tree;
/* current level to search from */
- struct _EMFormatPURITree *pending_uri_level;
+ GNode *pending_uri_level;
em_format_mode_t mode; /* source/headers/etc */
gchar *charset; /* charset override */
@@ -272,7 +244,7 @@ struct _EMFormatClass {
void (*format_error)(EMFormat *, CamelStream *, const gchar *msg);
/* use for external structured parts */
- void (*format_attachment)(EMFormat *, CamelStream *, CamelMimePart *, const gchar *mime_type, const struct _EMFormatHandler *info);
+ void (*format_attachment)(EMFormat *, CamelStream *, CamelMimePart *, const gchar *mime_type, const EMFormatHandler *info);
/* use for unparsable content */
void (*format_source)(EMFormat *, CamelStream *, CamelMimePart *);
@@ -367,7 +339,7 @@ void em_format_format_attachment (EMFormat *emf,
CamelStream *stream,
CamelMimePart *mime_part,
const gchar *mime_type,
- const struct _EMFormatHandler *info);
+ const EMFormatHandler *info);
void em_format_format_error (EMFormat *emf,
CamelStream *stream,
const gchar *format,