libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit 5e31f314003bf2e09ee9915a0e34ffe55141efff
parent 00aee106279ae3d7461361f70576e44e551f0634
Author: lash <dev@holbrook.no>
Date:   Thu,  8 May 2025 19:55:15 +0100

Add query and verify tools

Diffstat:
Asrc/example/Makefile | 13+++++++++++++
Asrc/example/query.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/example/verify.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/lq/store.h | 7+++++++
Msrc/store/file.c | 5+++++
5 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/src/example/Makefile b/src/example/Makefile @@ -0,0 +1,13 @@ +OBJS := $(patsubst %.c,%.o,$(wildcard *.c)) +INCLUDES := -I.. -I../aux/include `pkg-config --cflags libtasn1 libgcrypt` +CFLAGS += $(INCLUDES) -Wall -g3 +#LIBS := ../asn1/defs_asn1_tab.o `pkg-config --libs libtasn1 libgcrypt` -L../aux/lib -llash -lhashmap +LIBS := ../asn1/defs_asn1_tab.o `pkg-config --libs libtasn1 libgcrypt` -L.. -L../aux/lib -lqaeda -lhashmap +#LDFLAGS := -lcheck -lsubunit -lm $(LIBS) +#LDFLAGS := -lcheck $(LIBS) +LDFLAGS := $(LIBS) +#COMMONOBJS = ../mem/std.o ../lq/config.o ../lq/err.o ../lq/base.o ../debug.o + +all: + $(CC) $(CFLAGS) query.c -o query_bin $(COMMONOBJS) $(LDFLAGS) -lgcrypt + $(CC) $(CFLAGS) verify.c -o verify_bin $(COMMONOBJS) $(LDFLAGS) -lgcrypt diff --git a/src/example/query.c b/src/example/query.c @@ -0,0 +1,45 @@ +#include <limits.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <lq/store.h> +#include <lq/query.h> +#include <lq/mem.h> +#include <lq/io.h> +#include <lq/err.h> + + +int main(int argc, char **argv) { + int r; + char *p; + char path[PATH_MAX]; + LQStore *store; + LQQuery *query; + + if (argc < 2) { + return 1; + } + + if (argc > 2) { + strcpy(path, *(argv+2)); + } else { + memcpy(path, "./out/", 6); + } + ensuredir(path); + store = lq_store_new(path); + + p = *(argv+1); + query = lq_query_new(LQ_CONTENT_RAW, store, p, strlen(p)); + if (query == NULL) { + return ENOENT; + } + + while(lq_query_next(query) == ERR_OK) { + printf("have\n"); + } + + lq_query_free(query); + lq_store_free(store); + return 0; +} diff --git a/src/example/verify.c b/src/example/verify.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <llog.h> +#include <lq/cert.h> +#include <lq/base.h> +#include "debug.h" + + +int main(int argc, char **argv) { + int f; + int r; + int c; + int l; + char b[LQ_CRYPTO_BUFLEN]; + LQCert *cert; + + lq_init(); + f = open(*(argv+1), O_RDONLY); + if (f < 0) { + lq_finish(); + return 1; + } + + c = 0; + l = LQ_CRYPTO_BUFLEN; + while (1) { + r = read(f, b, l); + if (r < 1) { + break; + } + l -= r; + c += r; + } + close(f); + if (r < 0) { + lq_finish(); + return errno; + } + + r = lq_certificate_deserialize(&cert, NULL, b, c); + if (r) { + debug_logerr(LLOG_ERROR, r, "deserialize err"); + } + + lq_finish(); + return r; +} diff --git a/src/lq/store.h b/src/lq/store.h @@ -66,4 +66,11 @@ struct lq_resolve_t { */ LQStore* lq_store_new(const char *spec); +/** + * \brief Release resources used by the store. + * + * \param[in] The store to operate on. + */ +void lq_store_free(LQStore *store); + #endif // LIBQAEDA_STORE_H_ diff --git a/src/store/file.c b/src/store/file.c @@ -280,3 +280,8 @@ LQStore* lq_store_new(const char *spec) { lq_cpy(store->userdata, spec, l); return store; } + +void lq_store_free(LQStore *store) { + lq_free(store->userdata); + lq_free(store); +}