summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-22 13:34:57 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-25 14:03:04 -0400
commitb853620d1a3ff7d60bff034078655f9787bfbf2f (patch)
tree46b5f1f189ccdbc3a891bbdb9337f4c873cf004c
parent0ebe30fabe59e96f551b1c037441cfc144ccc327 (diff)
Make regex matching in file a utility function
-rw-r--r--telepathy-logger/log-store-xml.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index 6bdc9f1..bcd47e9 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -704,6 +704,36 @@ create_date_from_string (const gchar *str)
return date;
}
+
+static gboolean
+log_store_xml_match_in_file (const gchar *filename,
+ GRegex *regex)
+{
+ gboolean retval = FALSE;
+ GMappedFile *file;
+ gsize length;
+ gchar *contents = NULL;
+
+ file = g_mapped_file_new (filename, FALSE, NULL);
+ if (file == NULL)
+ goto out;
+
+ length = g_mapped_file_get_length (file);
+ contents = g_mapped_file_get_contents (file);
+
+ if (length == 0 || contents == NULL)
+ goto out;
+
+ retval = g_regex_match_full (regex, contents, length, 0, 0, NULL, NULL);
+
+out:
+ if (file != NULL)
+ g_mapped_file_unref (file);
+
+ return retval;
+}
+
+
static GList *
log_store_xml_get_dates (TplLogStore *store,
TpAccount *account,
@@ -1252,24 +1282,9 @@ _log_store_xml_search_in_files (TplLogStoreXml *self,
for (l = files; l; l = g_list_next (l))
{
- gchar *filename;
- GMappedFile *file;
- gsize length;
- gchar *contents = NULL;
-
- filename = l->data;
-
- file = g_mapped_file_new (filename, FALSE, NULL);
- if (file == NULL)
- goto fail;
+ gchar *filename = l->data;
- length = g_mapped_file_get_length (file);
- contents = g_mapped_file_get_contents (file);
-
- if (length == 0 || contents == NULL)
- goto fail;
-
- if (g_regex_match_full (regex, contents, length, 0, 0, NULL, NULL))
+ if (log_store_xml_match_in_file (filename, regex))
{
TplLogSearchHit *hit;
@@ -1282,12 +1297,6 @@ _log_store_xml_search_in_files (TplLogStoreXml *self,
g_date_get_month (hit->date), g_date_get_day (hit->date));
}
}
-
-fail:
- if (file != NULL)
- g_mapped_file_unref (file);
-
- g_free (filename);
}
out: