summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-05-04 11:14:14 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-05-04 12:28:25 -0400
commitff5db3334038c4c996f7432363a4032fe60b4f3b (patch)
tree8f6e327f25d946368ec955f4b3a2c9b7d59d03f2
parent14314bd21d31b8502e85111a6dabc6fa09a2f56a (diff)
Extract filename regex creation for reuse
-rw-r--r--telepathy-logger/log-store-xml.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index 3968d07..fb0fa08 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -732,24 +732,14 @@ out:
return exists;
}
-static gboolean
-log_store_xml_exists (TplLogStore *store,
- TpAccount *account,
- TplEntity *target,
- gint type_mask)
+
+static GRegex *
+log_store_xml_create_filename_regex (gint type_mask)
{
- TplLogStoreXml *self = (TplLogStoreXml *) store;
- gchar *dirname;
GString *pattern;
- GRegex *regex;
+ GRegex *regex = NULL;
GError *error = NULL;
- gboolean exists = FALSE;
-
- g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE);
- g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE);
- g_return_val_if_fail (target == NULL || TPL_IS_ENTITY (target), FALSE);
- dirname = log_store_xml_get_dir (self, account, target);
pattern = g_string_new ("");
if (type_mask & TPL_EVENT_MASK_TEXT)
@@ -766,20 +756,46 @@ log_store_xml_exists (TplLogStore *store,
DEBUG ("Pattern is '%s'", pattern->str);
regex = g_regex_new (pattern->str, G_REGEX_OPTIMIZE, 0, &error);
+
if (regex == NULL)
{
DEBUG ("Failed to create regex: %s", error->message);
g_error_free (error);
- goto out;
}
- exists = log_store_xml_exists_in_directory (dirname, regex, type_mask,
- target == NULL);
-
out:
- g_free (dirname);
g_string_free (pattern, TRUE);
- g_regex_unref (regex);
+
+ return regex;
+}
+
+
+static gboolean
+log_store_xml_exists (TplLogStore *store,
+ TpAccount *account,
+ TplEntity *target,
+ gint type_mask)
+{
+ TplLogStoreXml *self = (TplLogStoreXml *) store;
+ gchar *dirname;
+ GRegex *regex;
+ gboolean exists = FALSE;
+
+ g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE);
+ g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE);
+ g_return_val_if_fail (target == NULL || TPL_IS_ENTITY (target), FALSE);
+
+ dirname = log_store_xml_get_dir (self, account, target);
+ regex = log_store_xml_create_filename_regex (type_mask);
+
+ if (regex != NULL)
+ exists = log_store_xml_exists_in_directory (dirname, regex, type_mask,
+ target == NULL);
+
+ g_free (dirname);
+
+ if (regex != NULL)
+ g_regex_unref (regex);
return exists;
}