diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-09-18 16:44:32 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-09-18 16:44:32 +0000 |
commit | c44fbbea0488dada04e7183eb7518fa972375bce (patch) | |
tree | 1c3d0dcf7e7a30998de69c1202b3a0c7a150dcac /src | |
parent | 52c98d2eb39d00659d051e6e74e0e8a098754163 (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.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/base64.c | 45 | ||||
-rw-r--r-- | src/base64.h | 25 | ||||
-rw-r--r-- | src/requests.c | 4 | ||||
-rw-r--r-- | src/util.c | 19 | ||||
-rw-r--r-- | src/util.h | 1 |
6 files changed, 22 insertions, 73 deletions
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); @@ -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; +} @@ -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_ */ |