2011-06-06 15:55:07 +04:00
|
|
|
/*
|
|
|
|
Provides a serialize/unserialize functionality for INI-like formats.
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2011-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-06-06 15:55:07 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
Written by:
|
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011
|
2011-06-06 15:55:07 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
2011-06-06 15:55:07 +04:00
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
2011-10-15 14:56:47 +04:00
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2011-06-06 15:55:07 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander 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.
|
2011-06-06 15:55:07 +04:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-06-06 15:55:07 +04:00
|
|
|
*/
|
|
|
|
|
2012-08-31 18:05:29 +04:00
|
|
|
/** \file lib/serialize.c
|
2011-06-06 15:55:07 +04:00
|
|
|
* \brief Source: serialize/unserialize functionality for INI-like formats.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
|
|
|
|
#include "lib/serialize.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
#define SRLZ_DELIM_C ':'
|
|
|
|
#define SRLZ_DELIM_S ":"
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2011-06-06 15:55:07 +04:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-06-06 15:55:07 +04:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2015-08-25 15:28:01 +03:00
|
|
|
G_GNUC_PRINTF (2, 3)
|
2024-06-01 21:12:14 +03:00
|
|
|
prepend_error_message (GError **error, const char *format, ...)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
char *prepend_str;
|
|
|
|
char *split_str;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if ((error == NULL) || (*error == NULL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start (ap, format);
|
|
|
|
prepend_str = g_strdup_vprintf (format, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
split_str = g_strdup_printf ("%s: %s", prepend_str, (*error)->message);
|
|
|
|
g_free (prepend_str);
|
|
|
|
g_free ((*error)->message);
|
|
|
|
(*error)->message = split_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
go_to_end_of_serialized_string (const char *non_serialized_data,
|
2024-06-01 21:12:14 +03:00
|
|
|
const char *already_serialized_part, size_t *offset)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
size_t calculated_offset;
|
|
|
|
const char *semi_ptr = strchr (non_serialized_data + 1, SRLZ_DELIM_C);
|
|
|
|
|
|
|
|
calculated_offset = (semi_ptr - non_serialized_data) + 1 + strlen (already_serialized_part);
|
|
|
|
if (calculated_offset >= strlen (non_serialized_data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
non_serialized_data += calculated_offset;
|
|
|
|
*offset += calculated_offset;
|
|
|
|
|
|
|
|
return non_serialized_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize some string object to string
|
|
|
|
*
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
* @param prefix prefix for serialization
|
2011-06-06 15:55:07 +04:00
|
|
|
* @param data data for serialization
|
|
|
|
* @param error contain pointer to object for handle error code and message
|
|
|
|
*
|
|
|
|
* @return serialized data as newly allocated string
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_serialize_str (const char prefix, const char *data, GError **error)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
if (data == NULL)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
g_set_error (error, MC_ERROR, 0, "mc_serialize_str(): Input data is NULL.");
|
2011-06-06 15:55:07 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
lib/serialize.c: cleanup -Wformat-signedness warning.
serialize.c: In function 'mc_serialize_str':
serialize.c:116:34: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
return g_strdup_printf ("%c%zd" SRLZ_DELIM_S "%s", prefix, strlen (data), data);
^
serialize.c:130:19: error: format '%zd' expects argument of type 'signed size_t', but argument 5 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_serialize_str()"
^
serialize.c:175:22: note: in expansion of macro 'FUNC_NAME'
FUNC_NAME
^~~~~~~~~
serialize.c:130:19: error: format '%zd' expects argument of type 'signed size_t', but argument 6 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_serialize_str()"
^
serialize.c:175:22: note: in expansion of macro 'FUNC_NAME'
FUNC_NAME
^~~~~~~~~
serialize.c: In function 'mc_deserialize_config':
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:301:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:313:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:325:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-09-17 15:05:09 +03:00
|
|
|
return g_strdup_printf ("%c%zu" SRLZ_DELIM_S "%s", prefix, strlen (data), data);
|
2011-06-06 15:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Deserialize string to string object
|
|
|
|
*
|
|
|
|
* @param prefix prefix for deserailization
|
|
|
|
* @param data data for deserialization
|
|
|
|
* @param error contain pointer to object for handle error code and message
|
|
|
|
*
|
|
|
|
* @return newly allocated string
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FUNC_NAME "mc_serialize_str()"
|
|
|
|
char *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_deserialize_str (const char prefix, const char *data, GError **error)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
size_t data_len;
|
|
|
|
|
2018-01-26 22:52:22 +03:00
|
|
|
if ((data == NULL) || (*data == '\0'))
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
g_set_error (error, MC_ERROR, 0, FUNC_NAME ": Input data is NULL or empty.");
|
2011-06-06 15:55:07 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*data != prefix)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
g_set_error (error, MC_ERROR, 0, FUNC_NAME ": String prefix doesn't equal to '%c'", prefix);
|
2011-06-06 15:55:07 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
char buffer[BUF_TINY];
|
|
|
|
char *semi_ptr;
|
|
|
|
size_t semi_offset;
|
|
|
|
|
|
|
|
semi_ptr = strchr (data + 1, SRLZ_DELIM_C);
|
|
|
|
if (semi_ptr == NULL)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
g_set_error (error, MC_ERROR, 0,
|
2011-06-06 15:55:07 +04:00
|
|
|
FUNC_NAME ": Length delimiter '%c' doesn't exists", SRLZ_DELIM_C);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
semi_offset = semi_ptr - (data + 1);
|
|
|
|
if (semi_offset >= BUF_TINY)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
g_set_error (error, MC_ERROR, 0, FUNC_NAME ": Too big string length");
|
2011-06-06 15:55:07 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
strncpy (buffer, data + 1, semi_offset);
|
|
|
|
buffer[semi_offset] = '\0';
|
|
|
|
data_len = atol (buffer);
|
|
|
|
data += semi_offset + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data_len > strlen (data))
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
g_set_error (error, MC_ERROR, 0,
|
2011-10-15 14:56:47 +04:00
|
|
|
FUNC_NAME
|
lib/serialize.c: cleanup -Wformat-signedness warning.
serialize.c: In function 'mc_serialize_str':
serialize.c:116:34: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
return g_strdup_printf ("%c%zd" SRLZ_DELIM_S "%s", prefix, strlen (data), data);
^
serialize.c:130:19: error: format '%zd' expects argument of type 'signed size_t', but argument 5 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_serialize_str()"
^
serialize.c:175:22: note: in expansion of macro 'FUNC_NAME'
FUNC_NAME
^~~~~~~~~
serialize.c:130:19: error: format '%zd' expects argument of type 'signed size_t', but argument 6 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_serialize_str()"
^
serialize.c:175:22: note: in expansion of macro 'FUNC_NAME'
FUNC_NAME
^~~~~~~~~
serialize.c: In function 'mc_deserialize_config':
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:301:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:313:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:325:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-09-17 15:05:09 +03:00
|
|
|
": Specified data length (%zu) is greater than actual data length (%zu)",
|
2011-06-06 15:55:07 +04:00
|
|
|
data_len, strlen (data));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return g_strndup (data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Serialize mc_config_t object to string
|
|
|
|
*
|
|
|
|
* @param data data for serialization
|
|
|
|
* @param error contain pointer to object for handle error code and message
|
|
|
|
*
|
|
|
|
* @return serialized data as newly allocated string
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_serialize_config (mc_config_t *data, GError **error)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
gchar **groups, **group_iterator;
|
|
|
|
GString *buffer;
|
|
|
|
|
|
|
|
buffer = g_string_new ("");
|
2014-05-04 12:05:30 +04:00
|
|
|
groups = mc_config_get_groups (data, NULL);
|
2011-06-06 15:55:07 +04:00
|
|
|
|
2014-05-04 12:05:30 +04:00
|
|
|
for (group_iterator = groups; *group_iterator != NULL; group_iterator++)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
char *serialized_str;
|
|
|
|
gchar **params, **param_iterator;
|
|
|
|
|
|
|
|
serialized_str = mc_serialize_str ('g', *group_iterator, error);
|
|
|
|
if (serialized_str == NULL)
|
|
|
|
{
|
|
|
|
g_string_free (buffer, TRUE);
|
|
|
|
g_strfreev (groups);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
g_string_append (buffer, serialized_str);
|
|
|
|
g_free (serialized_str);
|
|
|
|
|
2014-05-04 11:38:25 +04:00
|
|
|
params = mc_config_get_keys (data, *group_iterator, NULL);
|
2011-06-06 15:55:07 +04:00
|
|
|
|
2014-05-04 11:38:25 +04:00
|
|
|
for (param_iterator = params; *param_iterator != NULL; param_iterator++)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
char *value;
|
2014-05-04 11:38:25 +04:00
|
|
|
|
2011-06-06 15:55:07 +04:00
|
|
|
serialized_str = mc_serialize_str ('p', *param_iterator, error);
|
|
|
|
if (serialized_str == NULL)
|
|
|
|
{
|
|
|
|
g_string_free (buffer, TRUE);
|
|
|
|
g_strfreev (params);
|
|
|
|
g_strfreev (groups);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
g_string_append (buffer, serialized_str);
|
|
|
|
g_free (serialized_str);
|
|
|
|
|
|
|
|
value = mc_config_get_string_raw (data, *group_iterator, *param_iterator, "");
|
|
|
|
serialized_str = mc_serialize_str ('v', value, error);
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
if (serialized_str == NULL)
|
|
|
|
{
|
|
|
|
g_string_free (buffer, TRUE);
|
|
|
|
g_strfreev (params);
|
|
|
|
g_strfreev (groups);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (buffer, serialized_str);
|
|
|
|
g_free (serialized_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (params);
|
|
|
|
}
|
2021-05-24 20:41:08 +03:00
|
|
|
|
|
|
|
g_strfreev (groups);
|
|
|
|
|
2011-06-06 15:55:07 +04:00
|
|
|
return g_string_free (buffer, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Deserialize string to mc_config_t object
|
|
|
|
*
|
|
|
|
* @param data data for serialization
|
|
|
|
* @param error contain pointer to object for handle error code and message
|
|
|
|
*
|
|
|
|
* @return newly allocated mc_config_t object
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FUNC_NAME "mc_deserialize_config()"
|
|
|
|
#define prepend_error_and_exit() { \
|
lib/serialize.c: cleanup -Wformat-signedness warning.
serialize.c: In function 'mc_serialize_str':
serialize.c:116:34: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
return g_strdup_printf ("%c%zd" SRLZ_DELIM_S "%s", prefix, strlen (data), data);
^
serialize.c:130:19: error: format '%zd' expects argument of type 'signed size_t', but argument 5 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_serialize_str()"
^
serialize.c:175:22: note: in expansion of macro 'FUNC_NAME'
FUNC_NAME
^~~~~~~~~
serialize.c:130:19: error: format '%zd' expects argument of type 'signed size_t', but argument 6 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_serialize_str()"
^
serialize.c:175:22: note: in expansion of macro 'FUNC_NAME'
FUNC_NAME
^~~~~~~~~
serialize.c: In function 'mc_deserialize_config':
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:301:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:313:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
serialize.c:267:19: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'size_t {aka long unsigned int}' [-Werror=format=]
#define FUNC_NAME "mc_deserialize_config()"
^
serialize.c:269:35: note: in expansion of macro 'FUNC_NAME'
prepend_error_message (error, FUNC_NAME " at %zd", current_position + 1); \
^~~~~~~~~
serialize.c:325:17: note: in expansion of macro 'prepend_error_and_exit'
prepend_error_and_exit ();
^~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-09-17 15:05:09 +03:00
|
|
|
prepend_error_message (error, FUNC_NAME " at %zu", current_position + 1); \
|
2011-06-06 15:55:07 +04:00
|
|
|
mc_config_deinit (ret_data); \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
mc_config_t *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_deserialize_config (const char *data, GError **error)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
char *current_group = NULL, *current_param = NULL, *current_value = NULL;
|
|
|
|
size_t current_position = 0;
|
2012-07-28 14:19:27 +04:00
|
|
|
mc_config_t *ret_data;
|
2011-06-06 15:55:07 +04:00
|
|
|
enum automat_status
|
|
|
|
{
|
|
|
|
WAIT_GROUP,
|
|
|
|
WAIT_PARAM,
|
|
|
|
WAIT_VALUE
|
|
|
|
} current_status = WAIT_GROUP;
|
|
|
|
|
2012-07-28 14:19:27 +04:00
|
|
|
ret_data = mc_config_init (NULL, FALSE);
|
|
|
|
|
2011-06-06 15:55:07 +04:00
|
|
|
while (data != NULL)
|
|
|
|
{
|
|
|
|
if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL))
|
|
|
|
current_status = WAIT_PARAM;
|
|
|
|
|
|
|
|
switch (current_status)
|
|
|
|
{
|
|
|
|
case WAIT_GROUP:
|
|
|
|
g_free (current_group);
|
|
|
|
|
|
|
|
current_group = mc_deserialize_str ('g', data, error);
|
|
|
|
if (current_group == NULL)
|
|
|
|
prepend_error_and_exit ();
|
|
|
|
|
|
|
|
data = go_to_end_of_serialized_string (data, current_group, ¤t_position);
|
|
|
|
current_status = WAIT_PARAM;
|
|
|
|
break;
|
|
|
|
case WAIT_PARAM:
|
|
|
|
g_free (current_param);
|
|
|
|
|
|
|
|
current_param = mc_deserialize_str ('p', data, error);
|
|
|
|
if (current_param == NULL)
|
|
|
|
{
|
|
|
|
g_free (current_group);
|
|
|
|
prepend_error_and_exit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
data = go_to_end_of_serialized_string (data, current_param, ¤t_position);
|
|
|
|
current_status = WAIT_VALUE;
|
|
|
|
break;
|
|
|
|
case WAIT_VALUE:
|
|
|
|
current_value = mc_deserialize_str ('v', data, error);
|
2011-12-09 23:42:08 +04:00
|
|
|
if (current_value == NULL)
|
2011-06-06 15:55:07 +04:00
|
|
|
{
|
|
|
|
g_free (current_group);
|
|
|
|
g_free (current_param);
|
|
|
|
prepend_error_and_exit ();
|
|
|
|
}
|
|
|
|
mc_config_set_string (ret_data, current_group, current_param, current_value);
|
|
|
|
|
|
|
|
data = go_to_end_of_serialized_string (data, current_value, ¤t_position);
|
|
|
|
g_free (current_value);
|
|
|
|
current_status = WAIT_GROUP;
|
|
|
|
break;
|
2015-04-19 13:57:38 +03:00
|
|
|
default:
|
|
|
|
break;
|
2011-06-06 15:55:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (current_group);
|
|
|
|
g_free (current_param);
|
|
|
|
|
|
|
|
return ret_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|