mirror of
https://codeberg.org/scip/dbtool.git
synced 2025-12-16 10:50:58 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3dba3473f8 | |||
|
|
3d0ec6bfbc | ||
| b836a4e75d | |||
| a4a3cd470f | |||
|
|
f2137627d7 | ||
| bb967c68c6 | |||
|
|
ab0d3f8268 |
@@ -12,12 +12,50 @@ steps:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2 pcre2-dev db db-dev pkgconfig meson ninja
|
||||
- apk add --no-cache bash build-base gdb perl pcre2 pcre2-dev db db-dev pkgconfig meson ninja
|
||||
- meson setup --reconfigure build
|
||||
- ninja -C build
|
||||
|
||||
test-berkeley:
|
||||
when:
|
||||
event: [push]
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base pcre2 pcre2-dev db db-dev
|
||||
- rm -f test.db
|
||||
- build/dbtool -d test.db -i -k "test" -v "blah blah blah"
|
||||
# insert keys
|
||||
- build/dbtool -d test.db -i -k test -v blah
|
||||
- build/dbtool -d test.db -i -k foo -v bar
|
||||
# look if the appear in the dump
|
||||
- build/dbtool -d test.db -D | grep blah
|
||||
# count 'em
|
||||
- build/dbtool -d test.db -D | wc -l | grep 2
|
||||
# search for key
|
||||
- build/dbtool -d test.db -s -k test
|
||||
# search for key regex
|
||||
- build/dbtool -d test.db -S -k 't$'
|
||||
# remove key
|
||||
- build/dbtool -d test.db -r -k foo
|
||||
# count must match
|
||||
- build/dbtool -d test.db -D | wc -l | grep 1
|
||||
# modify a key
|
||||
- build/dbtool -d test.db -u -k test -v modified
|
||||
# check modified key
|
||||
- build/dbtool -d test.db -s -k test | grep modified
|
||||
# use splitting with regex
|
||||
- echo today:100 | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
|
||||
# check if it works
|
||||
- build/dbtool -d test.db -s -k today | grep 100
|
||||
# use splitting with regex reverse
|
||||
- echo today:cold | build/dbtool -d test.db -R -i -f -t '^([^:]*):([^:]*)'
|
||||
# check if it works
|
||||
- build/dbtool -d test.db -s -k cold | grep today
|
||||
# check encryption
|
||||
- build/dbtool -d test.db -i -k borg -v sevenofnine -p -P foobar
|
||||
- build/dbtool -d test.db -s -k borg -p -P foobar | grep sevenofnine
|
||||
|
||||
|
||||
|
||||
build-gdbm:
|
||||
when:
|
||||
@@ -25,9 +63,49 @@ steps:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2 pcre2-dev gdbm gdbm-dev pkgconfig meson ninja
|
||||
- apk add --no-cache bash build-base perl pcre2 pcre2-dev gdbm gdbm-dev pkgconfig meson ninja
|
||||
- meson setup --reconfigure build
|
||||
- ninja -C build
|
||||
- rm -f test.db
|
||||
- build/dbtool -d test.db -i -k "test" -v "blah blah blah"
|
||||
- build/dbtool -d test.db -D | grep blah
|
||||
|
||||
test-gdbm:
|
||||
when:
|
||||
event: [push]
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base pcre2 pcre2-dev gdbm gdbm-dev
|
||||
- rm -f test.db
|
||||
# insert keys
|
||||
- build/dbtool -d test.db -i -k test -v blah
|
||||
- build/dbtool -d test.db -i -k foo -v bar
|
||||
# look if the appear in the dump
|
||||
- build/dbtool -d test.db -D | grep blah
|
||||
# count 'em
|
||||
- build/dbtool -d test.db -D | wc -l | grep 2
|
||||
# search for key
|
||||
- build/dbtool -d test.db -s -k test
|
||||
# search for key regex
|
||||
- build/dbtool -d test.db -S -k 't$'
|
||||
# remove key
|
||||
- build/dbtool -d test.db -r -k foo
|
||||
# count must match
|
||||
- build/dbtool -d test.db -D | wc -l | grep 1
|
||||
# modify a key
|
||||
- build/dbtool -d test.db -u -k test -v modified
|
||||
# check modified key
|
||||
- build/dbtool -d test.db -s -k test | grep modified
|
||||
# use splitting with regex
|
||||
- echo today:100 | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
|
||||
# check if it works
|
||||
- build/dbtool -d test.db -s -k today | grep 100
|
||||
# use splitting with regex reverse
|
||||
- echo today:cold | build/dbtool -d test.db -R -i -f -t '^([^:]*):([^:]*)'
|
||||
# check if it works
|
||||
- build/dbtool -d test.db -s -k cold | grep today
|
||||
# check encryption
|
||||
- build/dbtool -d test.db -i -k borg -v sevenofnine -p -P foobar
|
||||
- build/dbtool -d test.db -s -k borg -p -P foobar | grep sevenofnine
|
||||
|
||||
|
||||
@@ -50,5 +50,5 @@ fi
|
||||
for file in "$@"; do
|
||||
https --ignore-stdin --check-status -A bearer -a "$DEPLOY_TOKEN" -f POST \
|
||||
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases/$ID/assets" \
|
||||
"name=${file}-${version}" "attachment@${file}"
|
||||
"name=${file}" "attachment@${file}"
|
||||
done
|
||||
|
||||
@@ -6,24 +6,26 @@ labels:
|
||||
steps:
|
||||
compile:
|
||||
when:
|
||||
event: [manual]
|
||||
event: [tag,manual]
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2 pcre2-dev gdbm gdbm-dev pkgconfig meson ninja
|
||||
- meson setup --reconfigure --prefer-static build
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2-static pcre2-dev gdbm gdbm-dev pkgconfig meson ninja git
|
||||
- meson setup --reconfigure --prefer-static -Dcpp_link_args="-static" --buildtype=release build
|
||||
- ninja -C build
|
||||
- meson dist -C build --formats xztar,gztar,zip
|
||||
- file build/dbtool
|
||||
- mv build/dbtool dbtool-linux-amd64
|
||||
- mv build/dbtool dbtool-linux-amd64-$CI_COMMIT_TAG
|
||||
- mv build/meson-dist/* .
|
||||
|
||||
release:
|
||||
image: alpine:latest
|
||||
when:
|
||||
event: [manual]
|
||||
event: [tag,manual]
|
||||
environment:
|
||||
DEPLOY_TOKEN:
|
||||
from_secret: DEPLOY_TOKEN
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash httpie jq git
|
||||
- .woodpecker/release.sh dbtool-linux-amd64
|
||||
- .woodpecker/release.sh dbtool-*
|
||||
|
||||
19
.woodpecker/test.sh
Executable file
19
.woodpecker/test.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
yq '.steps.test-gdbm.commands' < .woodpecker/build.yaml \
|
||||
| grep -- - | grep -v apk | sed 's/^\- //' \
|
||||
| while read COMMAND; do
|
||||
echo "$COMMAND" | bash -e > debug.log 2>&1
|
||||
if test $? -ne 0; then
|
||||
echo "fail - $COMMAND"
|
||||
if test -s debug.log; then
|
||||
cat debug.log
|
||||
else
|
||||
echo exit 1
|
||||
fi
|
||||
else
|
||||
echo "ok - $COMMAND"
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f debug.log
|
||||
22
Makefile
Normal file
22
Makefile
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# convenience wrapper around meson and ninja. Forgive me, I'm old :
|
||||
|
||||
.PHONY: all static install test clean debug
|
||||
all:
|
||||
meson setup --reconfigure build
|
||||
ninja -C build
|
||||
|
||||
install: all
|
||||
sudo ninja -C install
|
||||
|
||||
clean:
|
||||
rm -rf build dbtool*core* dbtool.1 test.db clean
|
||||
|
||||
test:
|
||||
@.woodpecker/test.sh
|
||||
|
||||
debug: all
|
||||
rm -f test.db
|
||||
build/dbtool -d test.db -i -k borg -v sevenofnine -p -P foobar
|
||||
build/dbtool -d test.db -s -k borg -p -P foobar
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[](https://ci.codeberg.org/repos/15585)
|
||||
[](https://codeberg.org/scip/dbtool/blob/master/LICENSE)
|
||||
[](https://codeberg.org/scip/dbtool/raw/branch/main/LICENSE)
|
||||
|
||||
# README for dbtool 1.9.1 (21/11/2025)
|
||||
# README for dbtool 1.9.2 (21/11/2025)
|
||||
|
||||
dbtool can be used to store and retrieve data in a key/value
|
||||
format in a hash database. Perl compatible regular expressions
|
||||
@@ -17,7 +17,7 @@ data and speed.
|
||||
You need either the GNU gdbm library or the Berkeley database
|
||||
system. You can find gdbm at:
|
||||
http://www.gnu.org/software/gdbm/gdbm.html
|
||||
And the berkeley library at: http://www.sleepycat.com.
|
||||
And the berkeley library at: https://libdb.org/.
|
||||
|
||||
You will also need `meson` and `ninja`: https://mesonbuild.com/.
|
||||
|
||||
|
||||
@@ -56,11 +56,8 @@ void cipher::init(const string& phrase) {
|
||||
dig.initDigest();
|
||||
dig.putDigest( (unsigned char *)phrase.c_str(), phrase.length() );
|
||||
__key = dig.stringDigest(); // this is a 32 byte long string, as Rijndael:: expects
|
||||
|
||||
/* convert the key to unsigned char[] */
|
||||
for(int i=0; i<32; i++) {
|
||||
key[i] = __key[i];
|
||||
}
|
||||
|
||||
memcpy(key, __key, 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
cipher.h
1
cipher.h
@@ -61,7 +61,6 @@ class cipher {
|
||||
Rijndael rijn;
|
||||
MD5Digest dig;
|
||||
unsigned char key[32];
|
||||
string blah;
|
||||
const char* error(int num);
|
||||
|
||||
public:
|
||||
|
||||
23
dbtool.cc
23
dbtool.cc
@@ -67,8 +67,8 @@ int main(int argc, char *argv[]) {
|
||||
case 'i':
|
||||
/* insert */
|
||||
if(config.key == "") {
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
}
|
||||
engine.insert();
|
||||
break;
|
||||
@@ -82,32 +82,32 @@ int main(int argc, char *argv[]) {
|
||||
case 's':
|
||||
/* select */
|
||||
if(config.key == "") {
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
}
|
||||
engine.select();
|
||||
break;
|
||||
case 'S':
|
||||
/* regexp select */
|
||||
if(config.key == "") {
|
||||
cerr << pkg << ": key (regexp) required\n";
|
||||
exit(1);
|
||||
cerr << pkg << ": key (regexp) required\n";
|
||||
exit(1);
|
||||
}
|
||||
engine.regexp();
|
||||
break;
|
||||
case 'r':
|
||||
/* remove */
|
||||
if(config.key == "") {
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
}
|
||||
engine.remove();
|
||||
break;
|
||||
case 'u':
|
||||
/* update */
|
||||
if(config.key == "") {
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
cerr << pkg << ": key required\n";
|
||||
exit(1);
|
||||
}
|
||||
engine.update();
|
||||
break;
|
||||
@@ -125,7 +125,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
string readpass() {
|
||||
char *envpass;
|
||||
envpass = getenv(PW_VARNAME);
|
||||
@@ -146,5 +145,3 @@ string readpass() {
|
||||
return password;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
33
engine.cc
33
engine.cc
@@ -315,8 +315,7 @@ void Engine::regexp() {
|
||||
// record end
|
||||
mode = "key";
|
||||
if(config.token != "") {
|
||||
//char **subs = new char*[2];
|
||||
char *subs[2];
|
||||
string *subs = new string[2];
|
||||
|
||||
num = pcre2_match(p_pcre, (PCRE2_SPTR)line.c_str(), (PCRE2_SIZE)line.length(), 0, 0, match_data, NULL);
|
||||
|
||||
@@ -326,19 +325,21 @@ void Engine::regexp() {
|
||||
cerr << "Token " << config.token << " did not produce sub strings!\n";
|
||||
else {
|
||||
ovector = pcre2_get_ovector_pointer(match_data);
|
||||
const char *constline = const_cast<char*>(line.c_str());
|
||||
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
char * substring_start = const_cast<char*>(line.c_str()) + ovector[2*i];
|
||||
for (int i = 1; i < num; i++) {
|
||||
PCRE2_SPTR substring_start = (PCRE2_SPTR8)constline + ovector[2*i];
|
||||
PCRE2_SIZE substring_length = ovector[2*i+1] - ovector[2*i];
|
||||
|
||||
if (i == 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
subs[i] = substring_start;
|
||||
char *part = (char *)malloc(substring_length+1);
|
||||
part = strncpy(part, (char *)substring_start, substring_length);
|
||||
part[substring_length] = '\0';
|
||||
|
||||
subs[i-1] = part;
|
||||
free(part);
|
||||
}
|
||||
|
||||
free(ovector);
|
||||
|
||||
|
||||
if(config.reverse) {
|
||||
value = subs[0];
|
||||
key = subs[1];
|
||||
@@ -349,9 +350,8 @@ void Engine::regexp() {
|
||||
}
|
||||
}
|
||||
|
||||
//delete(subs);
|
||||
delete[] subs;
|
||||
|
||||
|
||||
line = "";
|
||||
}
|
||||
value = encode(value);
|
||||
@@ -563,8 +563,9 @@ void Engine::regexp() {
|
||||
*/
|
||||
void Engine::remove() {
|
||||
init();
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt key((char *)config.key.c_str(), config.key.length() + 1);
|
||||
#ifdef HAVE_BERKELEY
|
||||
char *k = (char *)config.key.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
int ret;
|
||||
if((ret = db->del(NULL, &key, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(ret) << ")" << endl;
|
||||
|
||||
@@ -2,7 +2,7 @@ project(
|
||||
'dbtool',
|
||||
'cpp',
|
||||
license: 'GPL',
|
||||
version: '1.9.1',
|
||||
version: '1.9.3',
|
||||
meson_version: '>=1.3',
|
||||
default_options: [
|
||||
'warning_level=2',
|
||||
|
||||
Reference in New Issue
Block a user