17 Commits

Author SHA1 Message Date
1ef74e79c3 bump version 2025-11-21 14:05:32 +01:00
6e4d9dfc0f add more tests 2025-11-21 14:01:55 +01:00
314dafa164 fix substring allocation 2025-11-21 14:01:46 +01:00
96b966892c ovector should not be freed because it points into match_data 2025-11-21 12:56:24 +01:00
27a7582d91 fix berkeley db key deletion 2025-11-21 12:38:05 +01:00
e206eef2b8 fix yaml 2025-11-21 12:35:01 +01:00
eb273460c8 add more tests 2025-11-21 12:32:11 +01:00
69cf79fa47 fix packages 2025-11-21 12:23:27 +01:00
26e4fef653 add lip deps 2025-11-21 12:21:58 +01:00
6fbf283df3 fix yaml 2025-11-21 12:20:39 +01:00
6b7a5dedd5 separate test pipeline 2025-11-21 12:17:30 +01:00
a6e08c86c0 build release on tag only 2025-11-21 12:17:20 +01:00
8ea077ba56 use gdbm 2025-11-21 11:59:28 +01:00
be42776399 db-static as well 2025-11-21 11:56:33 +01:00
81792189fb try pcre2-static 2025-11-21 11:52:47 +01:00
7632c617bc make release static 2025-11-21 11:48:53 +01:00
603d702117 fix array allocation and deletion 2025-11-21 11:46:25 +01:00
4 changed files with 87 additions and 24 deletions

View File

@@ -12,12 +12,42 @@ steps:
image: alpine:latest image: alpine:latest
commands: commands:
- apk update - 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 - meson setup --reconfigure build
- ninja -C 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 - 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 - 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
- printf "today:100\nyesterday:500\n" | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
# check if it works
- cat /etc/passwd | build/dbtool -d test.db -s -k today | grep 100
build-gdbm: build-gdbm:
when: when:
@@ -25,9 +55,42 @@ steps:
image: alpine:latest image: alpine:latest
commands: commands:
- apk update - 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 - meson setup --reconfigure build
- ninja -C build - ninja -C build
- rm -f test.db - rm -f test.db
- build/dbtool -d test.db -i -k "test" -v "blah blah blah" - build/dbtool -d test.db -i -k "test" -v "blah blah blah"
- build/dbtool -d test.db -D | grep 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
- printf "today:100\nyesterday:500\n" | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
# check if it works
- cat /etc/passwd | build/dbtool -d test.db -s -k today | grep 100

View File

@@ -6,12 +6,12 @@ labels:
steps: steps:
compile: compile:
when: when:
event: [manual] event: [tag]
image: alpine:latest image: alpine:latest
commands: commands:
- apk update - 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 words-en gdb perl pcre2-static pcre2-dev gdbm gdbm-dev pkgconfig meson ninja
- meson setup --reconfigure --prefer-static build - meson setup --reconfigure --prefer-static -Dcpp_link_args="-static" --buildtype=release build
- ninja -C build - ninja -C build
- file build/dbtool - file build/dbtool
- mv build/dbtool dbtool-linux-amd64 - mv build/dbtool dbtool-linux-amd64
@@ -19,7 +19,7 @@ steps:
release: release:
image: alpine:latest image: alpine:latest
when: when:
event: [manual] event: [tag]
environment: environment:
DEPLOY_TOKEN: DEPLOY_TOKEN:
from_secret: DEPLOY_TOKEN from_secret: DEPLOY_TOKEN

View File

@@ -315,8 +315,7 @@ void Engine::regexp() {
// record end // record end
mode = "key"; mode = "key";
if(config.token != "") { if(config.token != "") {
//char **subs = new char*[2]; string *subs = new string[2];
char *subs[2];
num = pcre2_match(p_pcre, (PCRE2_SPTR)line.c_str(), (PCRE2_SIZE)line.length(), 0, 0, match_data, NULL); num = pcre2_match(p_pcre, (PCRE2_SPTR)line.c_str(), (PCRE2_SIZE)line.length(), 0, 0, match_data, NULL);
@@ -326,19 +325,20 @@ void Engine::regexp() {
cerr << "Token " << config.token << " did not produce sub strings!\n"; cerr << "Token " << config.token << " did not produce sub strings!\n";
else { else {
ovector = pcre2_get_ovector_pointer(match_data); 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];
if (i == 2) { for (int i = 1; i < num; i++) {
break; PCRE2_SPTR substring_start = (PCRE2_SPTR8)constline + ovector[2*i];
} PCRE2_SIZE substring_length = ovector[2*i+1] - ovector[2*i];
subs[i] = substring_start; char *part = (char *)malloc(substring_length+1);
part = strncpy(part, (char *)substring_start, substring_length);
subs[i-1] = part;
free(part);
} }
free(ovector);
if(config.reverse) { if(config.reverse) {
value = subs[0]; value = subs[0];
key = subs[1]; key = subs[1];
@@ -349,8 +349,7 @@ void Engine::regexp() {
} }
} }
//delete(subs); delete[] subs;
line = ""; line = "";
} }
@@ -563,8 +562,9 @@ void Engine::regexp() {
*/ */
void Engine::remove() { void Engine::remove() {
init(); init();
#ifdef HAVE_BERKELEY #ifdef HAVE_BERKELEY
Dbt key((char *)config.key.c_str(), config.key.length() + 1); char *k = (char *)config.key.c_str();
Dbt key(k, strlen(k));
int ret; int ret;
if((ret = db->del(NULL, &key, 0)) != 0) { if((ret = db->del(NULL, &key, 0)) != 0) {
cerr << "Database error" << "(" << strerror(ret) << ")" << endl; cerr << "Database error" << "(" << strerror(ret) << ")" << endl;

View File

@@ -2,7 +2,7 @@ project(
'dbtool', 'dbtool',
'cpp', 'cpp',
license: 'GPL', license: 'GPL',
version: '1.9.1', version: '1.9.2',
meson_version: '>=1.3', meson_version: '>=1.3',
default_options: [ default_options: [
'warning_level=2', 'warning_level=2',