2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "gvn-misc.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION: gvn-misc
|
|
|
|
* @Short_description: Miscelaneous utility functions
|
|
|
|
* @Title: Miscelaneous utility functions
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gvn_key_file_save:
|
2014-07-16 14:12:57 +00:00
|
|
|
* @self: a #GKeyFile
|
2013-10-11 23:07:35 +00:00
|
|
|
* @file: the file name
|
|
|
|
*
|
2014-07-16 14:12:57 +00:00
|
|
|
* Creates an ini file with the contents of @self.
|
2013-10-11 23:07:35 +00:00
|
|
|
**/
|
2014-07-16 14:12:57 +00:00
|
|
|
void gvn_key_file_save (GKeyFile * self, const gchar * file)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
|
|
|
gsize len;
|
|
|
|
gchar * aux;
|
|
|
|
|
2014-07-16 14:12:57 +00:00
|
|
|
aux = g_key_file_to_data (self, &len, NULL);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
g_file_set_contents (file, aux, len, NULL);
|
|
|
|
|
|
|
|
g_free (aux);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gvn_encode:
|
|
|
|
* @string: the string to be encoded.
|
|
|
|
*
|
|
|
|
* Encodes an string using base64.
|
|
|
|
*
|
|
|
|
* Return value: the encoded string.
|
|
|
|
**/
|
|
|
|
gchar * gvn_encode (const gchar * string)
|
|
|
|
{
|
|
|
|
if (string)
|
|
|
|
return g_base64_encode ((guchar *) string, strlen (string));
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gvn_decode:
|
|
|
|
* @string: the string to be decoded.
|
|
|
|
*
|
|
|
|
* Decodes an string using base64.
|
|
|
|
*
|
|
|
|
* Return value: the decoded string.
|
|
|
|
**/
|
|
|
|
gchar * gvn_decode (const gchar * string)
|
|
|
|
{
|
|
|
|
if (string)
|
|
|
|
{
|
|
|
|
gsize len;
|
|
|
|
gchar * base64;
|
|
|
|
gchar * str;
|
|
|
|
|
|
|
|
base64 = (gchar *) g_base64_decode (string, &len);
|
|
|
|
str = g_new (gchar, len + 1);
|
|
|
|
g_memmove (str, base64, len);
|
|
|
|
str[len] = '\0';
|
|
|
|
g_free (base64);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|