Art Cancro [Thu, 24 Aug 2023 18:44:37 +0000 (09:44 -0900)]
ctdldump: use the backend API instead of BDB calls
This makes ctdldump backend agnostic, or at least as backend
agnostic as citserver itself is at this point. We will probably
add some calling syntax across the board when we add more
backends, but at least this utility doesn't have to be rewritten
now. This makes me a happy ig. ctdlload will be next.
Art Cancro [Thu, 24 Aug 2023 13:55:33 +0000 (04:55 -0900)]
Makefile: restructured so that backends can be compiled into utilities
database.c has been moved from server/ into server/backends/common.
Makefile now separates server objects from backend objects.
This is all in preparation for ctdldump and ctdlload to link the backend
code instead of calling BDB directly.
Before now, the Berkeley DB back end was supplied the DB_DBT_MALLOC flag
and it became the caller's responsibility to handle any memory allocated
and returned by cdb_fetch() and cdb_next_item(). These heuristics are
not expected to be compatible with new back ends currently in planning.
cdb_fetch() and cdb_next_item() now return data that is to be considered
immutable (don't write to it or you'll segfault). The caller must still
call cdb_free() to free the `struct cdbdata` itself, but the pointers
inside it point to buffers that the back end will reuse.
After a call to cdb_fetch() or cdb_next_item(), the buffers are
guaranteed to be readable until the next call to one of those functions
on the same table.
Art Cancro [Thu, 17 Aug 2023 22:32:56 +0000 (13:32 -0900)]
CtdlFetchMsgList() - treat no-record and zero-messages identically
In both cases, we return 0 to the caller and set the array pointer to NULL.
This simplifies the calling convention and eliminates extra code to check for both conditions
Art Cancro [Wed, 16 Aug 2023 03:14:24 +0000 (18:14 -0900)]
DRY fetch of msglists.
A lot of the calls to cdb_fetch(CDB_MSGLISTS...) follow the same design pattern
and many of them are in need of rework to handle how they free their memory. So
I created a new function CtdlGetMsgList() to do it in a consistent way. Three
callers have been migrated to the new syntax.
Art Cancro [Fri, 11 Aug 2023 15:46:34 +0000 (06:46 -0900)]
Moved cdb_chmod_data() out of the backend API
This function only does file and directory level operations on
the data/ directory and files in it. These operations will be
common across all backends.
Art Cancro [Thu, 10 Aug 2023 14:49:50 +0000 (05:49 -0900)]
Prepared for upcoming change to cdb_next_item() API.
cdb_next_item() is always preceded by a call to cdb_rewind() before the
iteration loop. We're going to remove the cursor from thread-specific
data, and replace it with a void pointer that the caller is responsible
for passing back. This will make the backend drivers easier to build.
Art Cancro [Mon, 7 Aug 2023 14:55:11 +0000 (05:55 -0900)]
Marked code that will require some rework for LMDB.
When BDB returns data, the caller owns the memory and is required to
free it, which we usually do. I marked the places where we take ownership
of memory pointers and then set the BDB ptr to NULL. If we switch to
LMDB, those pointers remain valid forever, so we cannot simply free them
later.
Art Cancro [Tue, 1 Aug 2023 02:32:29 +0000 (17:32 -0900)]
ctdldump/ctdlload: -h now specifies the top-level Citadel directory, just like all the other programs, and defaults to the compiled-in Citadel directory, just like all the other programs
Had a coredump in IMAP Search parsing. Not sure of root cause, but parameter string parsing
of IMAP Search coredumped on ConstStr pointer content access.
When ConstStr are created, pointer is null and length is zero. Some code accesses the pointer
contents without checking length first. Not sure how parameter parsing passed a zero length
parameter, but added length checks before accessing throughout IMAP code to be safe.
While adding checks, found a typo in checking string for end of string in imap_list().
Was using address of character instead of looking for null termination. Corrected.