Rizin
unix-like reverse engineering framework and cli tools
|
#include "sdb.h"
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
#include "sdb_private.h"
Go to the source code of this file.
Classes | |
struct | LoadCtx |
Macros | |
#define | FLUSH |
#define | ESCAPE_LOOP(fd, str, escapes) |
#define | ESCAPE(c, repl, replsz) |
Enumerations | |
enum | LoadState { STATE_NEWLINE , STATE_PATH , STATE_KEY , STATE_VALUE } |
Functions | |
static int | cmp_ns (const void *a, const void *b) |
static void | write_path (int fd, SdbList *path) |
static void | write_key (int fd, const char *k) |
static void | write_value (int fd, const char *v) |
static bool | save_kv_cb (void *user, const char *k, const char *v) |
static bool | text_save (Sdb *s, int fd, bool sort, SdbList *path) |
RZ_API bool | sdb_text_save_fd (Sdb *s, int fd, bool sort) |
RZ_API bool | sdb_text_save (Sdb *s, const char *file, bool sort) |
static void | load_process_line (LoadCtx *ctx) |
static char | unescape_raw_char (char c) |
static void | load_process_single_char (LoadCtx *ctx) |
static bool | load_process_final_line (LoadCtx *ctx) |
static void | load_ctx_fini (LoadCtx *ctx) |
static bool | load_ctx_init (LoadCtx *ctx, Sdb *s, char *buf, size_t sz) |
RZ_API bool | sdb_text_load_buf (Sdb *s, char *buf, size_t sz) |
RZ_API bool | sdb_text_load (Sdb *s, const char *file) |
#define ESCAPE | ( | c, | |
repl, | |||
replsz | |||
) |
#define FLUSH |
enum LoadState |
Plaintext SDB Format
Files are UTF-8 and use '
' line endings. Always.
Lines starting with '/' denote the path of the namespace for the following data:
/some/namespace
The default path is root, just a slash also means root. These paths are always absolute from the root. Characters that must be escaped in a path are: '/', '\', '
', '\r':
/s\/ome/name\nspa\ce
SDB entries are written each as a single k=v line:
somekey=somevalue
To distinguish these from path lines, if there is a leading '/' in the key, it must be escaped (slashes later in the line don't have to be escaped):
\/slashedkey=somevalue
Other than that, at any postion, '\', '
' and '\r' must be escaped:
some\key=some\nvalue
In the key, '=' must also be escaped (not necessary in the value):
some=key=some=value
Example:
/ key=intheroot \/slashedkey=somevalue some\key=some\nvalue some=key=some=value
/subns some=stuff in the sub-namespace
/subns/deeper this=is in /subns/deeper
Definition at line 64 of file text.c.
References a, b, and sdb_ns_t::name.
Referenced by text_save().
|
static |
Definition at line 362 of file text.c.
References ls_free().
Referenced by load_ctx_init(), and sdb_text_load_buf().
Definition at line 366 of file text.c.
References load_ctx_fini(), ls_new(), s, and STATE_NEWLINE.
Referenced by sdb_text_load_buf().
Definition at line 336 of file text.c.
References ls_iter_t::data, free(), load_process_line(), ls_foreach, malloc(), memcpy(), and NULL.
Referenced by sdb_text_load_buf().
|
static |
Definition at line 234 of file text.c.
References k, ls_destroy(), ls_foreach, ls_push, sdb_ns(), sdb_set(), STATE_NEWLINE, STATE_PATH, STATE_VALUE, and v.
Referenced by load_process_final_line(), and load_process_single_char().
|
static |
Definition at line 288 of file text.c.
References c, load_process_line(), ls_push, STATE_KEY, STATE_NEWLINE, STATE_PATH, STATE_VALUE, and unescape_raw_char().
Referenced by sdb_text_load_buf().
Definition at line 139 of file text.c.
References fd, k, v, write_, write_key(), and write_value().
Referenced by text_save().
Definition at line 405 of file text.c.
References calloc(), close, fd, free(), fstat, MAP_PRIVATE, mmap, munmap, O_BINARY, O_RDONLY, PROT_READ, PROT_WRITE, r, read(), s, sdb_text_load_buf(), and x.
Referenced by createdb(), and rz_project_load_file_raw().
Definition at line 386 of file text.c.
References load_ctx_fini(), load_ctx_init(), load_process_final_line(), load_process_single_char(), s, and STATE_NEWLINE.
Referenced by createdb(), and sdb_text_load().
Definition at line 189 of file text.c.
References fd, ls_free(), ls_new(), path, r, s, and text_save().
Referenced by sdb_text_save().
Definition at line 148 of file text.c.
References cmp_ns(), fd, ls_clone(), ls_foreach, ls_free(), ls_pop(), ls_push, ls_sort(), sdb_ns_t::name, path, s, save_kv_cb(), sdb_ns_t::sdb, sdb_foreach(), sdb_foreach_list(), sdbkv_key(), sdbkv_value(), write_, and write_path().
Referenced by sdb_text_save_fd().
|
inlinestatic |
Definition at line 117 of file text.c.
References ESCAPE, ESCAPE_LOOP, fd, k, and write_.
Referenced by save_kv_cb().
Definition at line 98 of file text.c.
References ESCAPE, ESCAPE_LOOP, fd, ls_foreach, path, and write_.
Referenced by text_save().
Definition at line 129 of file text.c.
References ESCAPE, ESCAPE_LOOP, fd, and v.
Referenced by save_kv_cb().