Rizin
unix-like reverse engineering framework and cli tools
rz_config.h
Go to the documentation of this file.
1 #ifndef RZ_CONFIG_H
2 #define RZ_CONFIG_H
3 
4 #include "rz_types.h"
5 #include "rz_util.h"
6 #include "rz_util/rz_serialize.h"
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
13 
14 #define CN_BOOL 0x000001
15 #define CN_INT 0x000002
16 // NOTE: removed because this is redundant and it does not add any value
17 // compared to CN_INT. Use that instead for consistency
18 // #define CN_OFFT 0x000004
19 #define CN_STR 0x000008
20 #define CN_RO 0x000010
21 #define CN_RW 0x000020
22 
23 #define NODECB(w, x, y) rz_config_set_cb(cfg, w, x, y)
24 #define NODEICB(w, x, y) rz_config_set_i_cb(cfg, w, x, y)
25 #define SETDESC(x, y) rz_config_node_desc(x, y)
26 #define SETOPTIONS(x, ...) set_options(x, __VA_ARGS__)
27 #define SETI(x, y, z) SETDESC(rz_config_set_i(cfg, x, y), z)
28 #define SETB(x, y, z) SETDESC(rz_config_set_b(cfg, x, y), z)
29 #define SETICB(w, x, y, z) SETDESC(NODEICB(w, x, y), z)
30 #define SETPREF(x, y, z) SETDESC(rz_config_set(cfg, x, y), z)
31 #define SETCB(w, x, y, z) SETDESC(NODECB(w, x, y), z)
32 #define SETBPREF(x, y, z) SETDESC(NODECB(x, y, boolify_var_cb), z)
33 
34 typedef bool (*RzConfigCallback)(void *user, void *data);
35 
36 typedef struct rz_config_node_t {
37  char *name;
38  int flags;
39  char *value;
42  int *cb_ptr_i;
43  char **cb_ptr_s;
46  char *desc;
49 
50 RZ_API const char *rz_config_node_type(RzConfigNode *node);
51 
52 typedef struct rz_config_t {
53  int lock;
54  void *user;
56  RzList /*<RzConfigNode *>*/ *nodes;
57  HtPP *ht;
59 
60 typedef struct rz_config_hold_num_t {
61  char *key;
64 
65 typedef struct rz_config_hold_char_t {
66  char *key;
67  char *value;
69 
70 typedef struct rz_config_hold_t {
72  RzList *list_num; // list of RzConfigHoldNum to hold numeric values
73  RzList *list_char; // list of RzConfigHoldChar to hold char values
75 
76 #ifdef RZ_API
79 
82 
84 
85 RZ_API RzConfig *rz_config_new(void *user);
87 RZ_API void rz_config_free(RzConfig *cfg);
88 RZ_API void rz_config_lock(RzConfig *cfg, int l);
89 RZ_API void rz_config_bump(RzConfig *cfg, const char *key);
90 RZ_API RzConfigNode *rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i);
92 RZ_API RzConfigNode *rz_config_set_cb(RzConfig *cfg, const char *name, const char *value, bool (*callback)(void *user, void *data));
93 RZ_API RzConfigNode *rz_config_set_i_cb(RzConfig *cfg, const char *name, int ivalue, bool (*callback)(void *user, void *data));
94 RZ_API RzConfigNode *rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value);
96 RZ_API bool rz_config_rm(RzConfig *cfg, RZ_NONNULL const char *name);
98 RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name);
99 RZ_API RZ_BORROW const char *rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name);
100 RZ_API const char *rz_config_desc(RzConfig *cfg, RZ_NONNULL const char *name, RZ_NULLABLE const char *desc);
101 RZ_API const char *rz_config_node_desc(RzConfigNode *node, RZ_NULLABLE const char *desc);
107 RZ_API bool rz_config_toggle(RzConfig *cfg, RZ_NONNULL const char *name);
108 RZ_API bool rz_config_readonly(RzConfig *cfg, const char *key);
109 RZ_API bool rz_config_eval(RZ_NONNULL RzConfig *cfg, RZ_NONNULL const char *str);
110 
111 RZ_API bool rz_config_set_setter(RzConfig *cfg, const char *key, RzConfigCallback cb);
112 RZ_API bool rz_config_set_getter(RzConfig *cfg, const char *key, RzConfigCallback cb);
113 
116 
117 static inline bool rz_config_node_is_bool(RzConfigNode *node) {
118  return node->flags & CN_BOOL;
119 }
120 static inline bool rz_config_node_is_int(RzConfigNode *node) {
121  return node->flags & CN_INT;
122 }
123 static inline bool rz_config_node_is_ro(RzConfigNode *node) {
124  return node->flags & CN_RO;
125 }
126 static inline bool rz_config_node_is_str(RzConfigNode *node) {
127  return node->flags & CN_STR;
128 }
129 
130 /* serialize */
131 
134  RZ_NULLABLE const char *const *exclude, RZ_NULLABLE RzSerializeResultInfo *res);
135 #endif
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
const char * desc
Definition: bin_vsf.c:19
static int value
Definition: cmd_api.c:93
#define RZ_API
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static int buf_size
Definition: debug_qnx.c:35
voidpf void * buf
Definition: ioapi.h:138
int n
Definition: mipsasm.c:19
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API RzConfigNode * rz_config_set_cb(RzConfig *cfg, const char *name, const char *value, bool(*callback)(void *user, void *data))
RZ_API void rz_serialize_config_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzConfig *config)
#define CN_BOOL
Definition: rz_config.h:14
RZ_API bool rz_config_unserialize(RZ_NONNULL RzConfig *config, RZ_NONNULL Sdb *db, RZ_NULLABLE char **err)
Definition: config.c:564
RZ_API bool rz_config_eval(RZ_NONNULL RzConfig *cfg, RZ_NONNULL const char *str)
Sets the configuration variable and its value passed as argument.
Definition: config.c:575
static bool rz_config_node_is_bool(RzConfigNode *node)
Definition: rz_config.h:117
struct rz_config_node_t RzConfigNode
RZ_API RzConfigNode * rz_config_set_i_cb(RzConfig *cfg, const char *name, int ivalue, bool(*callback)(void *user, void *data))
static bool rz_config_node_is_int(RzConfigNode *node)
Definition: rz_config.h:120
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API bool rz_config_readonly(RzConfig *cfg, const char *key)
Definition: config.c:481
RZ_API RzConfig * rz_config_clone(RzConfig *cfg)
Definition: config.c:507
RZ_API void rz_config_hold_restore(RzConfigHold *h)
Restore whatever config options were previously saved in h.
Definition: hold.c:132
RZ_LIB_VERSION_HEADER(rz_config)
RZ_API bool rz_config_set_getter(RzConfig *cfg, const char *key, RzConfigCallback cb)
Definition: config.c:53
RZ_API RzConfigHold * rz_config_hold_new(RzConfig *cfg)
Create an opaque object to save/restore some configuration options.
Definition: hold.c:116
RZ_API RZ_BORROW RzConfigNode * rz_config_node_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:48
RZ_API RZ_OWN RzConfigNode * rz_config_node_new(RZ_NONNULL const char *name, RZ_NONNULL const char *value)
Definition: config.c:6
static bool rz_config_node_is_ro(RzConfigNode *node)
Definition: rz_config.h:123
struct rz_config_t RzConfig
RZ_API bool rz_config_hold_s(RzConfigHold *h,...)
Save the current values of a list of config options that have string values.
Definition: hold.c:40
RZ_API bool rz_config_rm(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:392
static bool rz_config_node_is_str(RzConfigNode *node)
Definition: rz_config.h:126
RZ_API const char * rz_config_node_desc(RzConfigNode *node, RZ_NULLABLE const char *desc)
Definition: config.c:383
struct rz_config_hold_char_t RzConfigHoldChar
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API void rz_config_node_free(RZ_NULLABLE void *n)
Definition: config.c:36
RZ_API bool rz_config_add_node(RZ_BORROW RzConfig *cfg, RZ_OWN RzConfigNode *node)
Appends the given node to the config cfg.
Definition: config.c:362
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API const char * rz_config_node_type(RzConfigNode *node)
Definition: config.c:155
RZ_API const char * rz_config_desc(RzConfig *cfg, RZ_NONNULL const char *name, RZ_NULLABLE const char *desc)
Definition: config.c:377
#define CN_STR
Definition: rz_config.h:19
RZ_API RzConfig * rz_config_new(void *user)
Definition: config.c:490
RZ_API bool rz_config_set_setter(RzConfig *cfg, const char *key, RzConfigCallback cb)
Definition: config.c:63
RZ_API bool rz_config_hold_i(RzConfigHold *h,...)
Save the current values of a list of config options that have integer values.
Definition: hold.c:81
RZ_API void rz_config_lock(RzConfig *cfg, int l)
Definition: config.c:476
RZ_API RzConfigNode * rz_config_set_b(RzConfig *cfg, RZ_NONNULL const char *name, bool value)
Definition: config.c:201
RZ_API RZ_OWN RzConfigNode * rz_config_node_clone(RzConfigNode *n)
Definition: config.c:20
struct rz_config_hold_num_t RzConfigHoldNum
RZ_API void rz_config_hold_free(RzConfigHold *h)
Free a RzConfigHold object h.
Definition: hold.c:152
struct rz_config_hold_t RzConfigHold
RZ_API void rz_config_serialize(RZ_NONNULL RzConfig *config, RZ_NONNULL Sdb *db)
Definition: config.c:547
bool(* RzConfigCallback)(void *user, void *data)
Definition: rz_config.h:34
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)
RZ_API void rz_config_bump(RzConfig *cfg, const char *key)
Definition: config.c:539
RZ_API void rz_config_node_value_format_i(char *buf, size_t buf_size, const ut64 i, RZ_NULLABLE RzConfigNode *node)
Definition: config.c:403
RZ_API bool rz_config_toggle(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:97
RZ_API void rz_config_free(RzConfig *cfg)
Definition: config.c:523
#define CN_INT
Definition: rz_config.h:15
#define CN_RO
Definition: rz_config.h:20
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
#define h(i)
Definition: sha256.c:48
Definition: z80asm.h:102
RzList * list_num
Definition: rz_config.h:72
RzList * list_char
Definition: rz_config.h:73
RzConfig * cfg
Definition: rz_config.h:71
RzList * options
Definition: rz_config.h:47
ut64 * cb_ptr_q
Definition: rz_config.h:41
RzConfigCallback setter
Definition: rz_config.h:45
char ** cb_ptr_s
Definition: rz_config.h:43
RzConfigCallback getter
Definition: rz_config.h:44
RzNum * num
Definition: rz_config.h:55
RzList * nodes
Definition: rz_config.h:56
HtPP * ht
Definition: rz_config.h:57
void * user
Definition: rz_config.h:54
Definition: sdb.h:63
#define bool
Definition: sysdefs.h:146
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const char * cb[]
Definition: z80_tab.h:176