/* * 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 . */ #include #include "gvn-misc.h" /** * SECTION: gvn-misc * @Short_description: Miscelaneous utility functions * @Title: Miscelaneous utility functions **/ /** * gvn_object_warning: * @instance: the object instance within which the warning was emitted * @message: (allow-none): a string with the message to show or #NULL * * Prints a more verbose warning message than g_warning(), showing the type of * the object @instance, the file and line from where it's been called and * @message, if any. **/ /** * gvn_key_file_save: * @obj: a #GKeyFile * @file: the file name * * Creates an ini file with the contents of @obj. **/ void gvn_key_file_save (GKeyFile * obj, const gchar * file) { gsize len; gchar * aux; aux = g_key_file_to_data (obj, &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; }