* validate the domain names
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 1 Aug 2007 15:45:03 +0000 (15:45 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 1 Aug 2007 15:45:03 +0000 (15:45 +0000)
  Fixes: NB#64809

pmo-trunk-r2892

src/maemo/modest-account-settings-dialog.c
src/modest-text-utils.c
src/modest-text-utils.h

index 33cd6d0..4001977 100644 (file)
@@ -851,6 +851,9 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
        return GTK_WIDGET (scrollwin);
 }
 
        return GTK_WIDGET (scrollwin);
 }
 
+
+
+       
 static gboolean
 check_data (ModestAccountSettingsDialog *self)
 {
 static gboolean
 check_data (ModestAccountSettingsDialog *self)
 {
@@ -871,8 +874,8 @@ check_data (ModestAccountSettingsDialog *self)
                        return FALSE;
                }
        }
                        return FALSE;
                }
        }
-
-       /* Check that the email address is valud: */
+       
+       /* Check that the email address is valid: */
        const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
        if ((!email_address) || (strlen(email_address) == 0))
                return FALSE;
        const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
        if ((!email_address) || (strlen(email_address) == 0))
                return FALSE;
@@ -888,8 +891,39 @@ check_data (ModestAccountSettingsDialog *self)
                return FALSE;
        }
 
                return FALSE;
        }
 
-       /* Find a suitable authentication method when secure authentication is desired */
+       /* make sure the domain name for the incoming server is valid */
        const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
        const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
+       if ((!hostname) || (strlen(hostname) == 0))
+               return FALSE;
+       if (!modest_text_utils_validate_domain_name (hostname)) {
+               /* Warn the user via a dialog: */
+               /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
+               hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
+                                         
+               /* Return focus to the email address entry: */
+               gtk_widget_grab_focus (self->entry_incomingserver);
+               gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
+               return FALSE;
+       }
+
+       /* make sure the domain name for the outgoing server is valid */
+       const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
+       if ((!hostname2) || (strlen(hostname2) == 0))
+               return FALSE;
+       if (!modest_text_utils_validate_domain_name (hostname2)) {
+               /* Warn the user via a dialog: */
+               /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
+               hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
+                                         
+               /* Return focus to the email address entry: */
+               gtk_widget_grab_focus (self->entry_outgoingserver);
+               gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
+               return FALSE;
+       }
+
+               
+       /* Find a suitable authentication method when secure authentication is desired */
+
        gint port_num = hildon_number_editor_get_value (
                        HILDON_NUMBER_EDITOR (self->entry_incoming_port));
        const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
        gint port_num = hildon_number_editor_get_value (
                        HILDON_NUMBER_EDITOR (self->entry_incoming_port));
        const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
@@ -942,11 +976,10 @@ check_data (ModestAccountSettingsDialog *self)
                        }
                }
        }
                        }
                }
        }
+       
+       
 
 
-       /* TODO: The UI Spec wants us to check that the servernames are valid, 
-        * but does not specify how.
-        */
-        
+       
        return TRUE;
 }
 /*
        return TRUE;
 }
 /*
index 6b67214..f01e706 100644 (file)
@@ -79,7 +79,7 @@ struct _url_match_t {
        { "(file|rtsp|http|ftp|https)://[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]+[-A-Za-z0-9_$%&=?/~#]",\
          NULL, NULL },\
        { "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
        { "(file|rtsp|http|ftp|https)://[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]+[-A-Za-z0-9_$%&=?/~#]",\
          NULL, NULL },\
        { "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
-         NULL, "http://" },\
+                       NULL, "http://" },                              \
        { "ftp\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
          NULL, "ftp://" },\
        { "(voipto|callto|chatto|jabberto|xmpp):[-_a-z@0-9.\\+]+", \
        { "ftp\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
          NULL, "ftp://" },\
        { "(voipto|callto|chatto|jabberto|xmpp):[-_a-z@0-9.\\+]+", \
@@ -1069,6 +1069,32 @@ modest_text_utils_get_display_date (time_t date)
        return g_strdup(date_buf);
 }
 
        return g_strdup(date_buf);
 }
 
+
+gboolean
+modest_text_utils_validate_domain_name (const gchar *domain)
+{
+       gboolean valid = FALSE;
+       regex_t rx;
+       const gchar* domain_regex = "^[a-z0-9]([.]?[a-z0-9-])*[a-z0-9]$";
+
+       if (!domain)
+               return FALSE;
+       
+       /* domain name: all alphanum or '-' or '.',
+        * but beginning/ending in alphanum */  
+       if (regcomp (&rx, domain_regex, REG_ICASE|REG_EXTENDED|REG_NOSUB)) {
+               g_warning ("BUG: error in regexp");
+               return FALSE;
+       }
+       
+       valid = (regexec (&rx, domain, 1, NULL, 0) == 0);
+       regfree (&rx);
+               
+       return valid;
+}
+
+
+
 gboolean
 modest_text_utils_validate_email_address (const gchar *email_address, const gchar **invalid_char_position)
 {
 gboolean
 modest_text_utils_validate_email_address (const gchar *email_address, const gchar **invalid_char_position)
 {
index 401907f..5425d60 100644 (file)
@@ -268,6 +268,17 @@ gchar* modest_text_utils_get_display_date (time_t date);
 gchar * modest_text_utils_get_display_size (guint64 size);
 
 
 gchar * modest_text_utils_get_display_size (guint64 size);
 
 
+
+/**
+ * modest_text_utils_validate_domain_name:
+ * @email_address: a NULL-terminated string
+ * 
+ * validates the domain name passed as argument
+ * 
+ * Returns: TRUE if the domain name is valid, FALSE otherwise
+ **/
+gboolean modest_text_utils_validate_domain_name (const gchar *domain);
+
 /**
  * modest_text_utils_validate_email_address:
  * @email_address: a string
 /**
  * modest_text_utils_validate_email_address:
  * @email_address: a string