Rizin
unix-like reverse engineering framework and cli tools
serialize_config.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2020 Florian Märkl <info@florianmaerkl.de>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_util/rz_serialize.h>
5 #include <rz_config.h>
6 
7 /*
8  *
9  * RzConfig isn't completely serialized, only the values.
10  *
11  * SDB Format:
12  *
13  * /
14  * <name>=<value>
15  * ...
16  *
17  */
18 
21  RzConfigNode *node;
22  rz_list_foreach (config->nodes, iter, node) {
23  sdb_set(db, node->name, node->value, 0);
24  }
25 }
26 
27 typedef struct load_config_ctx_t {
29  HtPP *exclude;
31 
32 static bool load_config_cb(void *user, const char *k, const char *v) {
33  LoadConfigCtx *ctx = user;
34  if (ctx->exclude && ht_pp_find_kv(ctx->exclude, k, NULL)) {
35  return true;
36  }
37  RzConfigNode *node = rz_config_node_get(ctx->config, k);
38  if (!node) {
39  return 1;
40  }
41  rz_config_set(ctx->config, k, v);
42  return 1;
43 }
44 
49  RZ_NULLABLE const char *const *exclude, RZ_NULLABLE RzSerializeResultInfo *res) {
51  if (exclude) {
52  ctx.exclude = ht_pp_new(NULL, NULL, NULL);
53  if (!ctx.exclude) {
54  return false;
55  }
56  for (; *exclude; exclude++) {
57  ht_pp_insert(ctx.exclude, *exclude, NULL);
58  }
59  }
61  ht_pp_free(ctx.exclude);
62  return true;
63 }
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RZ_BORROW RzConfigNode * rz_config_node_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:48
#define RZ_API
#define NULL
Definition: cris-opc.c:27
struct config_s config
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_NONNULL
Definition: rz_types.h:64
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RZ_API bool sdb_foreach(Sdb *s, SdbForeachCallback cb, void *user)
Definition: sdb.c:758
static bool load_config_cb(void *user, const char *k, const char *v)
RZ_API void rz_serialize_config_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzConfig *config)
struct load_config_ctx_t LoadConfigCtx
RZ_API bool rz_serialize_config_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzConfig *config, RZ_NULLABLE const char *const *exclude, RZ_NULLABLE RzSerializeResultInfo *res)
Definition: sdb.h:63