[grilo/mocking: 6/8] net: Use g_build_filename() for building capture file name.
- From: Mathias Hasselmann <hasselmm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo/mocking: 6/8] net: Use g_build_filename() for building capture file name.
- Date: Thu, 11 Oct 2012 19:34:27 +0000 (UTC)
commit 42942ff24df0bbfba4ee5c439ab8712cc8c9979f
Author: Mathias Hasselmann <mathias openismus com>
Date: Thu Oct 11 20:55:48 2012 +0200
net: Use g_build_filename() for building capture file name.
libs/net/grl-net-private.c | 36 ++++++++++++++++++++++--------------
libs/net/grl-net-private.h | 2 +-
2 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/libs/net/grl-net-private.c b/libs/net/grl-net-private.c
index a030905..c4d8b0b 100644
--- a/libs/net/grl-net-private.c
+++ b/libs/net/grl-net-private.c
@@ -101,30 +101,38 @@ init_dump_directory ()
capture_dir = NULL;
}
+static char *
+build_request_filename (SoupURI *soup_uri)
+{
+ char *uri = soup_uri_to_string (soup_uri, FALSE);
+ char *escaped_uri = g_uri_escape_string (uri, NULL, FALSE);
+ g_free (uri);
+
+ char *basename = g_strdup_printf ("%s-%"G_GINT64_FORMAT,
+ escaped_uri, g_get_real_time ());
+ g_free (escaped_uri);
+
+ char *filename = g_build_filename (capture_dir, basename, NULL);
+ g_free (basename);
+
+ return filename;
+}
+
void
-dump_data (SoupURI *soup_uri,
+dump_data (SoupURI *uri,
const char *buffer,
const gsize length)
{
- char *uri, *escaped_uri, *file;
- GError *error = NULL;
-
if (!capture_dir)
return;
- uri = soup_uri_to_string (soup_uri, FALSE);
- escaped_uri = g_uri_escape_string (uri, NULL, FALSE);
- g_free (uri);
- file = g_strdup_printf ("%s"G_DIR_SEPARATOR_S"%s-%"G_GINT64_FORMAT,
- capture_dir,
- escaped_uri,
- g_get_real_time ());
- g_free (escaped_uri);
+ char *filename = build_request_filename (uri);
+ GError *error = NULL;
- if (!g_file_set_contents (file, buffer, length, &error)) {
+ if (!g_file_set_contents (filename, buffer, length, &error)) {
GRL_WARNING ("Could not write contents to disk: %s", error->message);
g_error_free (error);
}
- g_free (file);
+ g_free (filename);
}
diff --git a/libs/net/grl-net-private.h b/libs/net/grl-net-private.h
index f1c2212..0a015de 100644
--- a/libs/net/grl-net-private.h
+++ b/libs/net/grl-net-private.h
@@ -81,7 +81,7 @@ void free_op_res (void *op);
void init_dump_directory (void) G_GNUC_INTERNAL;
-void dump_data (SoupURI *soup_uri, const gchar *data, gsize length) G_GNUC_INTERNAL;
+void dump_data (SoupURI *uri, const gchar *data, gsize length) G_GNUC_INTERNAL;
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]