Skip to content

Commit 410c9f6

Browse files
committed
Move SDB into RzUtil
1 parent 5f826df commit 410c9f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+9798
-17
lines changed

librz/include/rz_userconf.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#define HAVE_COPYFILE @HAVE_COPYFILE@
4949
#define HAVE_COPY_FILE_RANGE @HAVE_COPY_FILE_RANGE@
5050
#define HAVE_BACKTRACE @HAVE_BACKTRACE@
51+
#define HAVE_GETPID @HAVE_GETPID@
52+
#define HAVE__GETPID @HAVE__GETPID@
5153

5254
#define HAVE_HEADER_LINUX_ASHMEM_H @HAVE_HEADER_LINUX_ASHMEM_H@
5355
#define HAVE_HEADER_SYS_SHM_H @HAVE_HEADER_SYS_SHM_H@

librz/util/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
subdir('sdb')
12

23
rz_util_sources = [
34
'alloc.c',

librz/util/sdb/.gitignore

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
*._d
2+
*._o
3+
*.[ado]
4+
*.so
5+
pkgconfig/mcsdb.pc
6+
pkgconfig/sdb.pc
7+
test/api/a.out
8+
test/cas
9+
test/f
10+
test/fmt
11+
test/hook
12+
test/hook2
13+
test/reset/db.test
14+
test/reset/test-reset
15+
test/stack
16+
test/stress1
17+
test/verypush
18+
test/.newdb
19+
test/___syncget.db
20+
test/bench-expire
21+
test/chkkey
22+
test/drain
23+
test/dumptwice
24+
test/expire
25+
test/fmtarr
26+
test/merge
27+
test/milset
28+
test/milsetv
29+
test/ns
30+
test/nsabuse
31+
test/siolpain
32+
test/syncget
33+
test/test.db
34+
test/unit/test_hash
35+
test/unit/test_hash.dSYM/
36+
/.tmp
37+
test/.tmp
38+
test/api/array
39+
test/api/refs
40+
test/unit/.tmp
41+
test/unit/test_array
42+
test/unit/test_ls
43+
test/unit/test_sdb
44+
test/unit/test_diff
45+
test/unit/*.dSYM
46+
src/libsdb.so*
47+
src/libsdb.dylib
48+
src/sdb
49+
src/sdb_version.h
50+
memcache/cmds
51+
memcache/cmds.h
52+
memcache/mcsdbc
53+
memcache/mcsdbd
54+
build
55+
compile_commands.json
56+
.ccls-cache

librz/util/sdb/AUTHORS

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Main developer
2+
--------------
3+
4+
5+
Software from others
6+
--------------------
7+
cdb: D. J. Bernstein <[email protected]>
8+
src/ht.c: Jeffrey Crowell <[email protected]>

librz/util/sdb/COPYING

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 pancake
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

librz/util/sdb/README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
SDB (string database)
2+
=====================
3+
4+
sdb is a simple string key/value database based on djb's cdb
5+
disk storage and supports JSON and arrays introspection.
6+
7+
Author
8+
------
9+
10+
11+
Contains
12+
--------
13+
* namespaces (multiple sdb paths)
14+
* atomic database sync (never corrupted)
15+
* commandline frontend for sdb databases
16+
* arrays support (syntax sugar)
17+
* json parser/getter (js0n.c)
18+
19+
Rips
20+
----
21+
* disk storage based on cdb code
22+
* linked lists from rizin api
23+
24+
Compilation
25+
-----------
26+
SDB requires [Meson](https://mesonbuild.com/) and [Ninja](https://ninja-build.org/) buildsystems to be built:
27+
```
28+
meson build
29+
ninja -C build
30+
```
31+
32+
Changes
33+
-------
34+
I have modified cdb code a little to create smaller databases and
35+
be memory leak free in order to use it from a library.
36+
37+
The sdb's cdb database format is 10% smaller than the original
38+
one. This is because keylen and valuelen are encoded in 4 bytes:
39+
1 for the key length and 3 for the value length.
40+
41+
In a test case, a 4.3MB cdb database takes only 3.9MB after this
42+
file format change.
43+
44+
Usage example
45+
-------------
46+
Let's create a database!
47+
```
48+
$ sdb d hello=world
49+
$ sdb d hello
50+
world
51+
```
52+
Using arrays (>=0.6):
53+
```
54+
$ sdb - '[]list=1,2' '[0]list' '[0]list=foo' '[]list' '[+1]list=bar'
55+
1
56+
foo
57+
2
58+
```
59+
Let's play with json:
60+
```
61+
$ sdb d g='{"foo":1,"bar":{"cow":3}}'
62+
$ sdb d g:bar.cow
63+
3
64+
$ sdb - user='{"id":123}' user:id=99 user:id
65+
99
66+
```
67+
Using the commandline without any disk database:
68+
```
69+
$ sdb - foo=bar foo a=3 +a -a
70+
bar
71+
4
72+
3
73+
```
74+
```
75+
$ sdb -
76+
foo=bar
77+
foo
78+
bar
79+
a=3
80+
+a
81+
4
82+
-a
83+
3
84+
```
85+
Remove the database
86+
```
87+
$ rm -f d
88+
```

librz/util/sdb/meson.build

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sdb_incdir = rizin_incdir
2+
3+
subdir('src')
4+
5+
sdb_exe = executable('sdb_native', 'src/main.c',
6+
dependencies: sdb_native_dep,
7+
install: false,
8+
native: true,
9+
implicit_include_directories: false,
10+
)
11+
12+
sdb_gen_cmd = [
13+
sdb_exe,
14+
'@OUTPUT@',
15+
'==',
16+
'@INPUT@'
17+
]

0 commit comments

Comments
 (0)