aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-account-settings.c
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2010-10-14 17:55:25 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-10-14 20:32:28 +0800
commit054e1f0bf407756fa8380513d3b1d24930503cce (patch)
tree6a2415154d1b78bc7d13203257cd6279293d249f /libempathy/empathy-account-settings.c
parent1f107665d98cfba8175d47b46ff35dca07d886bc (diff)
downloadgsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.tar
gsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.tar.gz
gsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.tar.bz2
gsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.tar.lz
gsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.tar.xz
gsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.tar.zst
gsoc2013-empathy-054e1f0bf407756fa8380513d3b1d24930503cce.zip
Check format of some user names (#629261)
Diffstat (limited to 'libempathy/empathy-account-settings.c')
-rw-r--r--libempathy/empathy-account-settings.c106
1 files changed, 84 insertions, 22 deletions
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 29ff3f1b7..1e63aede9 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -69,9 +69,15 @@ struct _EmpathyAccountSettingsPriv
gboolean display_name_overridden;
gboolean ready;
+ /* Parameter name (gchar *) -> parameter value (GValue) */
GHashTable *parameters;
+ /* Keys are parameter names from the hash above (gchar *).
+ * Values are regular expresions that should match corresponding parameter
+ * values (GRegex *). Possible regexp patterns are defined in
+ * empathy-account-widget.c */
+ GHashTable *param_regexps;
GArray *unset_parameters;
- GArray *required_params;
+ GList *required_params;
gulong managers_ready_id;
@@ -93,7 +99,12 @@ empathy_account_settings_init (EmpathyAccountSettings *obj)
priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) tp_g_value_slice_free);
+ priv->param_regexps = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) g_regex_unref);
+
priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *));
+
+ priv->required_params = NULL;
}
static void empathy_account_settings_dispose (GObject *object);
@@ -343,6 +354,7 @@ empathy_account_settings_finalize (GObject *object)
{
EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object);
EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+ GList *l;
/* free any data held directly by the object here */
g_free (priv->cm_name);
@@ -352,9 +364,14 @@ empathy_account_settings_finalize (GObject *object)
g_free (priv->icon_name);
if (priv->required_params != NULL)
- g_array_free (priv->required_params, TRUE);
+ {
+ for (l = priv->required_params; l; l = l->next)
+ g_free (l->data);
+ g_list_free (priv->required_params);
+ }
g_hash_table_destroy (priv->parameters);
+ g_hash_table_destroy (priv->param_regexps);
empathy_account_settings_free_unset_parameters (self);
g_array_free (priv->unset_parameters, TRUE);
@@ -407,16 +424,13 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
if (priv->required_params == NULL)
{
TpConnectionManagerParam *cur;
- char *val;
-
- priv->required_params = g_array_new (TRUE, FALSE, sizeof (gchar *));
for (cur = tp_protocol->params; cur->name != NULL; cur++)
{
if (tp_connection_manager_param_is_required (cur))
{
- val = g_strdup (cur->name);
- g_array_append_val (priv->required_params, val);
+ priv->required_params = g_list_append (priv->required_params,
+ g_strdup (cur->name));
}
}
}
@@ -1339,42 +1353,90 @@ empathy_account_settings_has_account (EmpathyAccountSettings *settings,
return (!tp_strdiff (account_path, priv_account_path));
}
+void
+empathy_account_settings_set_regex (EmpathyAccountSettings *settings,
+ const gchar *param,
+ const gchar *pattern)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ GRegex *regex;
+
+ regex = g_regex_new (pattern, 0, 0, NULL);
+ g_hash_table_insert (priv->param_regexps, g_strdup (param), regex);
+}
+
gboolean
-empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
+empathy_account_settings_parameter_is_valid (
+ EmpathyAccountSettings *settings,
+ const gchar *param)
{
EmpathyAccountSettingsPriv *priv;
- guint idx;
- gchar *current;
- gboolean missed = FALSE;
+ const GRegex *regex;
+ const gchar *value;
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
priv = GET_PRIV (settings);
- for (idx = 0; idx < priv->required_params->len; idx++)
+ if (g_list_find_custom (priv->required_params, param, (GCompareFunc) strcmp))
{
- current = g_array_index (priv->required_params, gchar *, idx);
-
/* first, look if it's set in our own parameters */
- if (tp_asv_lookup (priv->parameters, current))
- continue;
+ if (tp_asv_lookup (priv->parameters, param))
+ goto test_regex;
/* if we did not unset the parameter, look if it's in the account */
if (priv->account != NULL &&
- !empathy_account_settings_is_unset (settings, current))
+ !empathy_account_settings_is_unset (settings, param))
{
const GHashTable *account_params;
account_params = tp_account_get_parameters (priv->account);
- if (tp_asv_lookup (account_params, current))
- continue;
+ if (tp_asv_lookup (account_params, param))
+ goto test_regex;
}
- missed = TRUE;
- break;
+ return FALSE;
+ }
+
+test_regex:
+ /* test whether parameter value matches its regex */
+ regex = g_hash_table_lookup (priv->param_regexps, param);
+ if (regex)
+ {
+ value = empathy_account_settings_get_string (settings, param);
+ if (value != NULL && !g_regex_match (regex, value, 0, NULL))
+ return FALSE;
}
- return !missed;
+ return TRUE;
+}
+
+gboolean
+empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
+{
+ EmpathyAccountSettingsPriv *priv;
+ const gchar *param;
+ GHashTableIter iter;
+ GList *l;
+
+ g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
+
+ priv = GET_PRIV (settings);
+
+ for (l = priv->required_params; l; l = l->next)
+ {
+ if (!empathy_account_settings_parameter_is_valid (settings, l->data))
+ return FALSE;
+ }
+
+ g_hash_table_iter_init (&iter, priv->param_regexps);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &param, NULL))
+ {
+ if (!empathy_account_settings_parameter_is_valid (settings, param))
+ return FALSE;
+ }
+
+ return TRUE;
}
const TpConnectionManagerProtocol *