90 lines
1.9 KiB
C
90 lines
1.9 KiB
C
/*
|
|
* 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:
|
|
* @self: a #GKeyFile
|
|
* @file: the file name
|
|
*
|
|
* Creates an ini file with the contents of @self.
|
|
**/
|
|
void gvn_key_file_save (GKeyFile * self, const gchar * file)
|
|
{
|
|
gsize len;
|
|
gchar * aux;
|
|
|
|
aux = g_key_file_to_data (self, &len, NULL);
|
|
|
|
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;
|
|
}
|