summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-18 16:44:32 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-18 16:44:32 +0000
commitc44fbbea0488dada04e7183eb7518fa972375bce (patch)
tree1c3d0dcf7e7a30998de69c1202b3a0c7a150dcac
parent52c98d2eb39d00659d051e6e74e0e8a098754163 (diff)
base64.c has gone from being a base64 implementation to a small wrapper around GMappedFile and the glib base64 encoder. Makes more sense in util.c now.
-rw-r--r--aclocal.m44
-rw-r--r--src/Makefile.am1
-rw-r--r--src/base64.c45
-rw-r--r--src/base64.h25
-rw-r--r--src/requests.c4
-rw-r--r--src/util.c19
-rw-r--r--src/util.h1
7 files changed, 24 insertions, 75 deletions
diff --git a/aclocal.m4 b/aclocal.m4
index 4325c07..d110b0e 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -13,8 +13,8 @@
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],,
-[m4_warning([this file was generated for autoconf 2.67.
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],,
+[m4_warning([this file was generated for autoconf 2.68.
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically `autoreconf'.])])
diff --git a/src/Makefile.am b/src/Makefile.am
index 660a59e..fbd1bb0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,7 +33,6 @@ endif
transmission_remote_gtk_SOURCES = main.c \
requests.c \
- base64.c \
json.c \
trg-main-window.c \
util.c \
diff --git a/src/base64.c b/src/base64.c
deleted file mode 100644
index 55002ff..0000000
--- a/src/base64.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * transmission-remote-gtk - A GTK RPC client to Transmission
- * Copyright (C) 2011 Alan Fitton
-
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-#include "base64.h"
-
-gchar *base64encode(const gchar *filename)
-{
- GError *error = NULL;
- GMappedFile *mf = g_mapped_file_new(filename, FALSE, &error);
- gchar *b64out = NULL;
-
- if (error)
- {
- g_error("%s",error->message);
- g_error_free(error);
- } else {
- b64out = g_base64_encode((guchar*)g_mapped_file_get_contents(mf), g_mapped_file_get_length(mf));
- }
-
- g_mapped_file_unref(mf);
-
- return b64out;
-}
diff --git a/src/base64.h b/src/base64.h
deleted file mode 100644
index ab84071..0000000
--- a/src/base64.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * transmission-remote-gtk - A GTK RPC client to Transmission
- * Copyright (C) 2011 Alan Fitton
-
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef BASE64_H_
-#define BASE64_H_
-
-gchar *base64encode(const gchar *filename);
-
-#endif /* BASE64_H_ */
diff --git a/src/requests.c b/src/requests.c
index 5deb94e..1923102 100644
--- a/src/requests.c
+++ b/src/requests.c
@@ -24,9 +24,9 @@
#include <json-glib/json-glib.h>
#include "protocol-constants.h"
-#include "base64.h"
#include "json.h"
#include "torrent.h"
+#include "util.h"
#include "requests.h"
static JsonNode *base_request(gchar * method);
@@ -213,7 +213,7 @@ JsonNode *torrent_add(gchar * filename, gint flags)
{
JsonNode *root = base_request(METHOD_TORRENT_ADD);
JsonObject *args = node_get_arguments(root);
- gchar *encodedFile = base64encode(filename);
+ gchar *encodedFile = trg_base64encode(filename);
if (encodedFile)
json_object_set_string_member(args, PARAM_METAINFO, encodedFile);
json_object_set_boolean_member(args, PARAM_PAUSED, (flags & TORRENT_ADD_FLAG_PAUSED) == TORRENT_ADD_FLAG_PAUSED);
diff --git a/src/util.c b/src/util.c
index e37e728..1bfc20b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -373,3 +373,22 @@ gdouble json_double_to_progress(JsonNode *n)
return 0.0;
}
}
+
+gchar *trg_base64encode(const gchar *filename)
+{
+ GError *error = NULL;
+ GMappedFile *mf = g_mapped_file_new(filename, FALSE, &error);
+ gchar *b64out = NULL;
+
+ if (error)
+ {
+ g_error("%s",error->message);
+ g_error_free(error);
+ } else {
+ b64out = g_base64_encode((guchar*)g_mapped_file_get_contents(mf), g_mapped_file_get_length(mf));
+ }
+
+ g_mapped_file_unref(mf);
+
+ return b64out;
+}
diff --git a/src/util.h b/src/util.h
index 03d8165..76a9719 100644
--- a/src/util.h
+++ b/src/util.h
@@ -66,5 +66,6 @@ int evutil_vsnprintf(char *buf, size_t buflen, const char *format,
void rm_trailing_slashes(gchar *str);
void trg_widget_set_visible(GtkWidget * w, gboolean visible);
gdouble json_double_to_progress(JsonNode *n);
+gchar *trg_base64encode(const gchar *filename);
#endif /* UTIL_H_ */