From: Dirk-Jan C. Binnema Date: Wed, 9 Jan 2008 09:06:31 +0000 (+0000) Subject: * add some parameter checks X-Git-Tag: git_migration_finished~1846 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=f409f0b767f36788ce88995246dfeb087797acaa;ds=sidebyside * add some parameter checks pmo-trunk-r3997 --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index c8b0539..afaedef 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -65,21 +65,6 @@ #define HYPERLINKIFY_MAX_LENGTH (1024*50) -/* - * we mark the ampersand with \007 when converting text->html - * because after text->html we do hyperlink detecting, which - * could be screwed up by the ampersand. - * ie. 1<3 ==> 1\007lt;3 - */ -#define MARK_AMP '\007' -#define MARK_AMP_STR "\007" - -/* mark & separately, because they are parts of urls. - * ie. a&b => 1\008amp;b - */ -#define MARK_AMP_URI '\006' -#define MARK_AMP_URI_STR "\006" - /* * we need these regexps to find URLs in plain text e-mails @@ -98,9 +83,34 @@ struct _url_match_t { const gchar* prefix; }; + +/* + * we mark the ampersand with \007 when converting text->html + * because after text->html we do hyperlink detecting, which + * could be screwed up by the ampersand. + * ie. 1<3 ==> 1\007lt;3 + */ +#define MARK_AMP '\007' +#define MARK_AMP_STR "\007" + +/* mark & separately, because they are parts of urls. + * ie. a&b => a\006amp;b, but a>b => a\007gt;b + * + * we need to handle '&' separately, because it can be part of URIs + * (as in href="http://foo.bar?a=1&b=1"), so inside those URIs + * we need to re-replace \006amp; with '&' again, while outside uri's + * it will be '&' + * + * yes, it's messy, but a consequence of doing text->html first, then hyperlinkify + */ +#define MARK_AMP_URI '\006' +#define MARK_AMP_URI_STR "\006" + + /* note: match MARK_AMP_URI_STR as well, because after txt->html, a '&' will look like $(MARK_AMP_URI_STR)"amp;" */ #define MAIL_VIEWER_URL_MATCH_PATTERNS { \ - { "(file|rtsp|http|ftp|https|mms|mmsh|rtsp|rdp|lastfm)://[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]",\ + { "(file|rtsp|http|ftp|https|mms|mmsh|rtsp|rdp|lastfm)://[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR \ + "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]", \ NULL, NULL },\ { "www\\.[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]",\ NULL, "http://" }, \ @@ -221,6 +231,8 @@ forward_cite (const gchar *from, const gchar *to, const gchar *subject) { + g_return_val_if_fail (sent, NULL); + return g_strdup_printf ("%s\n%s %s\n%s %s\n%s %s\n%s %s\n", FORWARD_STRING, FROM_STRING, (from)?from:"", @@ -570,6 +582,8 @@ modest_text_utils_split_addresses_list (const gchar *addresses) const gchar *my_addrs = addresses; const gchar *end; gchar *addr; + + g_return_val_if_fail (addresses, NULL); /* skip any space, ',', ';' at the start */ while (my_addrs && (my_addrs[0] == ' ' || my_addrs[0] == ',' || my_addrs[0] == ';')) @@ -1219,7 +1233,7 @@ modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insens /* if it's not case sensitive */ if (!insensitive) { - /* optimization: short cut if first char is ascii */ + /* optimization: shortcut if first char is ascii */ if (((s1[0] & 0xf0)== 0) && ((s2[0] & 0xf0) == 0)) return s1[0] - s2[0]; diff --git a/src/modest-utils.c b/src/modest-utils.c index a7f09ab..0128966 100644 --- a/src/modest-utils.c +++ b/src/modest-utils.c @@ -79,6 +79,8 @@ modest_utils_file_exists (const gchar *filename) GnomeVFSURI *uri = NULL; gboolean result = FALSE; + g_return_val_if_fail (filename, FALSE); + uri = gnome_vfs_uri_new (filename); if (uri) { result = gnome_vfs_uri_exists (uri); @@ -187,18 +189,18 @@ on_idle_secure_auth_finished (gpointer user_data) } static void -on_camel_account_get_supported_secure_authentication ( - TnyCamelAccount *self, gboolean cancelled, - TnyList *auth_types, GError *err, - gpointer user_data) +on_camel_account_get_supported_secure_authentication (TnyCamelAccount *self, gboolean cancelled, + TnyList *auth_types, GError *err, gpointer user_data) { + g_return_if_fail (TNY_IS_CAMEL_ACCOUNT(self)); + g_return_if_fail (TNY_IS_LIST(auth_types)); + ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data; g_return_if_fail (info); /* Free everything if the actual action was canceled */ - if (info->cancel) - { + if (info->cancel) { /* The operation was canceled and the ownership of the info given to us * so that we could still check the cancel flag. */ g_slice_free (ModestGetSupportedAuthInfo, info); @@ -206,8 +208,7 @@ on_camel_account_get_supported_secure_authentication ( } else { - if (err) - { + if (err) { if (info->error) { g_error_free (info->error); info->error = NULL; @@ -219,10 +220,9 @@ on_camel_account_get_supported_secure_authentication ( if (!auth_types) { g_warning ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__); } - else if (tny_list_get_length(auth_types) == 0) { + else if (tny_list_get_length(auth_types) == 0) g_warning ("DEBUG: %s: auth_types is an empty TnyList.\n", __FUNCTION__); - } else - { + else { ModestPairList* pairs = modest_protocol_info_get_auth_protocol_pair_list (); /* Get the enum value for the strings: */ @@ -262,8 +262,9 @@ on_camel_account_get_supported_secure_authentication ( static void on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data) { - if(response == GTK_RESPONSE_REJECT || response == GTK_RESPONSE_DELETE_EVENT) - { + g_return_if_fail (GTK_IS_WIDGET(dialog)); + + if(response == GTK_RESPONSE_REJECT || response == GTK_RESPONSE_DELETE_EVENT) { ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data; g_return_if_fail(info); /* This gives the ownership of the info to the worker thread. */ @@ -397,6 +398,9 @@ void modest_utils_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog) { + g_return_if_fail (GTK_IS_WINDOW(parent_window)); + g_return_if_fail (GTK_IS_DIALOG(dialog)); + gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window); /* Destroy the dialog when it is closed: */ @@ -438,6 +442,9 @@ modest_list_index (TnyList *list, GObject *object) TnyIterator *iter; gint index = 0; + g_return_val_if_fail (TNY_IS_LIST(list), -1); + g_return_val_if_fail (G_IS_OBJECT(object), -1); + iter = tny_list_create_iterator (list); while (!tny_iterator_is_done (iter)) { GObject *current = tny_iterator_get_current (iter);