From 2c5d0444bb11eb2594d30085db510d2b000ac22a Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 13 May 2013 11:44:24 -0400 Subject: Add e_mail_formatter_header_copy(). Duplicates an EMailFormatterHeader struct. --- em-format/e-mail-formatter.c | 60 +++++++++++++++++++++++++++++--------------- em-format/e-mail-formatter.h | 3 ++- 2 files changed, 42 insertions(+), 21 deletions(-) (limited to 'em-format') diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c index 1794231b3d..938cfc6937 100644 --- a/em-format/e-mail-formatter.c +++ b/em-format/e-mail-formatter.c @@ -1474,25 +1474,25 @@ GQueue * e_mail_formatter_dup_headers (EMailFormatter *formatter) { GQueue *header_list; - GList *link; + GList *head, *link; g_return_val_if_fail (E_IS_MAIL_FORMATTER (formatter), NULL); g_mutex_lock (&formatter->priv->property_lock); header_list = g_queue_new (); - for (link = g_queue_peek_head_link ((GQueue *) e_mail_formatter_get_headers (formatter)); - link; - link = g_list_next (link)) { - EMailFormatterHeader *h = link->data, *copy; - if (!h) - continue; + head = g_queue_peek_head_link (formatter->priv->header_list); - copy = e_mail_formatter_header_new (h->name, h->value); - copy->flags = h->flags; + for (link = head; link != NULL; link = g_list_next (link)) { + const EMailFormatterHeader *header = link->data; + EMailFormatterHeader *copy; - g_queue_push_tail (header_list, copy); + /* FIXME Need to guarantee this is never NULL. */ + if (header != NULL) { + copy = e_mail_formatter_header_copy (header); + g_queue_push_tail (header_list, copy); + } } g_mutex_unlock (&formatter->priv->property_lock); @@ -1565,30 +1565,35 @@ e_mail_formatter_add_header (EMailFormatter *formatter, const gchar *value, EMailFormatterHeaderFlags flags) { - EMailFormatterHeader *header; + EMailFormatterHeader header; g_return_if_fail (E_IS_MAIL_FORMATTER (formatter)); g_return_if_fail (name != NULL && *name != '\0'); - header = e_mail_formatter_header_new (name, value); - header->flags = flags; + header.name = (gchar *) name; + header.value = (gchar *) value; + header.flags = flags; - g_mutex_lock (&formatter->priv->property_lock); - g_queue_push_tail (formatter->priv->header_list, header); - g_mutex_unlock (&formatter->priv->property_lock); - - g_signal_emit (formatter, signals[NEED_REDRAW], 0, NULL); + e_mail_formatter_add_header_struct (formatter, &header); } void e_mail_formatter_add_header_struct (EMailFormatter *formatter, const EMailFormatterHeader *header) { + EMailFormatterHeader *copy; + g_return_if_fail (E_IS_MAIL_FORMATTER (formatter)); g_return_if_fail (header != NULL); - e_mail_formatter_add_header ( - formatter, header->name, header->value, header->flags); + g_mutex_lock (&formatter->priv->property_lock); + + copy = e_mail_formatter_header_copy (header); + g_queue_push_tail (formatter->priv->header_list, copy); + + g_mutex_unlock (&formatter->priv->property_lock); + + g_signal_emit (formatter, signals[NEED_REDRAW], 0, NULL); } void @@ -1659,6 +1664,21 @@ e_mail_formatter_header_new (const gchar *name, return header; } +EMailFormatterHeader * +e_mail_formatter_header_copy (const EMailFormatterHeader *header) +{ + EMailFormatterHeader *copy; + + g_return_val_if_fail (header != NULL, NULL); + + copy = g_new0 (EMailFormatterHeader, 1); + copy->name = g_strdup (header->name); + copy->value = g_strdup (header->value); + copy->flags = header->flags; + + return copy; +} + void e_mail_formatter_header_free (EMailFormatterHeader *header) { diff --git a/em-format/e-mail-formatter.h b/em-format/e-mail-formatter.h index ca87246aeb..fcadfaacc2 100644 --- a/em-format/e-mail-formatter.h +++ b/em-format/e-mail-formatter.h @@ -253,7 +253,8 @@ void e_mail_formatter_remove_header_struct EMailFormatterHeader * e_mail_formatter_header_new (const gchar *name, const gchar *value); - +EMailFormatterHeader * + e_mail_formatter_header_copy (const EMailFormatterHeader *header); void e_mail_formatter_header_free (EMailFormatterHeader *header); G_END_DECLS -- cgit v1.2.3