From 6cb32e72eb10254fb607b09cf4690d93ec97044c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 4 Jan 2007 15:17:23 +0000 Subject: [PATCH] * modest-text-utils.[ch], modest-presets.[ch]: - fix some bugs in presets 'get_providers' function - add preconditions to functions (g_return_if_fail etc.) - update documentation - unit tests work now (after next commit) pmo-trunk-r585 --- src/modest-presets.c | 51 ++++++++++++++++++++++++++++------------------- src/modest-presets.h | 10 +++++----- src/modest-text-utils.c | 17 +++++++++++++--- src/modest-text-utils.h | 13 ++++++------ 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/modest-presets.c b/src/modest-presets.c index b17304b..870160e 100644 --- a/src/modest-presets.c +++ b/src/modest-presets.c @@ -40,6 +40,7 @@ #define MODEST_PRESETS_KEY_SECURE_SMTP "SecureSMTP" #define MODEST_PRESETS_KEY_TRUE "true" + ModestPresets* modest_presets_new (const gchar *presetfile) { @@ -70,39 +71,47 @@ modest_presets_new (const gchar *presetfile) } gchar** -modest_presets_get_providers (ModestPresets *self, gint mcc, gboolean include_globals) +modest_presets_get_providers (ModestPresets *self, guint mcc, + gboolean include_globals) { gchar **providers = NULL; gchar **filtered = NULL; + GError *err = NULL; + guint i, j, len; g_return_val_if_fail (self && self->keyfile, NULL); providers = g_key_file_get_groups (self->keyfile, NULL); - + /* return *all* providers? */ - if (mcc < 0 && include_globals) + if (mcc == 0 && include_globals) return providers; - - /* nope: filter them instead */ - filtered = g_new(gchar*, g_strv_length(providers)); - - if (filtered && providers) { - int i = 0, j = 0; - while (providers[i]) { - - int this_mcc; - this_mcc = g_key_file_get_integer (self->keyfile, providers[i], - MODEST_PRESETS_KEY_MCC, - NULL); - if (this_mcc == mcc || (this_mcc == 0 && include_globals)) { - filtered[j++] = providers[i]; - providers[i] = NULL; /* g_strfreev: leave it alone */ - } - ++i; + + /* nope: filter them */ + len = g_strv_length(providers); + filtered = g_new(gchar*, len + 1); + + for (i=0, j=0; i != len; ++i) { + + int this_mcc; + this_mcc = g_key_file_get_integer (self->keyfile, providers[i], + MODEST_PRESETS_KEY_MCC, &err); + if (err) { + g_strfreev (providers); + g_strfreev (filtered); + g_error_free (err); + g_printerr ("modest: error parsing keyfile: %s\n", err->message); + return NULL; + } + + if (this_mcc == mcc || (this_mcc == 0 && include_globals)) { + filtered[j++] = providers[i]; + filtered[j] = NULL; /* the array must be NULL-terminated */ + providers[i] = NULL; /* g_strfreev: leave it alone */ } } - g_strfreev (providers); + g_strfreev (providers); return filtered; } diff --git a/src/modest-presets.h b/src/modest-presets.h index 5f316e1..4afabce 100644 --- a/src/modest-presets.h +++ b/src/modest-presets.h @@ -69,17 +69,17 @@ ModestPresets* modest_presets_new (const gchar *presetfil * modest_presets_get_providers: * @self: a valid ModestPresets instance * @mcc: limit the search to providers with this mcc (Mobile Country Code), - * or <0 to get all - * @include_globals: include providers without MCC (such as GMail, Yahoo) if @mcc != 0? + * or 0 to get all + * @include_globals: include (global) providers without MCC (such as GMail, Yahoo) * - * get a list of providers + * get a list of providers matching certian criteria * * Returns: a newly allocated array of strings, or NULL in case of error * should be freed with g_strvfree * **/ -gchar ** modest_presets_get_providers (ModestPresets *self, gint mcc, - gboolean include_globals); +gchar ** modest_presets_get_providers (ModestPresets *self, guint mcc, + gboolean include_globals); /** * modest_presets_get_server: diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index e7a3209..b66137a 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -117,15 +117,19 @@ modest_text_utils_quote (const gchar *text, { gchar *retval, *cited; - cited = cite (sent_date, from); + g_return_val_if_fail (text, NULL); + g_return_val_if_fail (content_type, NULL); + g_return_val_if_fail (from, NULL); - if (!strcmp (content_type, "text/html")) + cited = cite (sent_date, from); + + if (content_type && strcmp (content_type, "text/html") == 0) /* TODO: extract the of the HTML and pass it to the function */ retval = modest_text_utils_quote_html (text, cited, limit); else retval = modest_text_utils_quote_plain_text (text, cited, limit); - + g_free (cited); return retval; @@ -166,6 +170,13 @@ modest_text_utils_inline (const gchar *text, "

%s"; const gchar *format; + g_return_val_if_fail (text, NULL); + g_return_val_if_fail (content_type, NULL); + g_return_val_if_fail (from, NULL); + g_return_val_if_fail (text, NULL); + g_return_val_if_fail (to, NULL); + g_return_val_if_fail (subject, NULL); + modest_text_utils_strftime (sent_str, 100, "%c", localtime (&sent_date)); if (!strcmp (content_type, "text/html")) diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 3813468..08e57db 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -53,8 +53,9 @@ gchar* modest_text_utils_derived_subject (const gchar *subject, /** * modest_text_utils_quote: - * @text: a string which contains the message to quote - * @from: the sender of the original message + * @text: a non-NULL string which contains the message to quote + * @from: a non-NULL sender of the original message + * @content_type: the non-NULL content type for the quoting, e.g. "text/html" * @sent_date: sent date/time of the original message * @limit: specifies the maximum characters per line in the quoted text * @@ -86,11 +87,11 @@ gchar* modest_text_utils_cite (const gchar *text, /** * modest_text_utils_inlined_text - * @from: the sender of the original message + * @from: the non-NULL sender of the original message * @sent_date: sent date/time of the original message - * @to: sent date/time of the original message - * @subject: sent date/time of the original message - * @text: sent date/time of the original message + * @to: + * @subject: + * @text: * * creates a new string with the "Original message" text prepended to * the text passed as argument and some data of the header -- 1.7.9.5