Compare commits
3 commits
b4841fffaa
...
32f31fe6d6
Author | SHA1 | Date | |
---|---|---|---|
32f31fe6d6 | |||
f3838e775c | |||
|
100d61050f |
5 changed files with 118 additions and 8 deletions
|
@ -21,6 +21,8 @@ are not even initialized to a default value.
|
||||||
- Make `HttpRouter` decode path parts before matching them on regular expressions.
|
- Make `HttpRouter` decode path parts before matching them on regular expressions.
|
||||||
- Fixed a bug in `ArraySort()` that would crash programs if the passed array has no
|
- Fixed a bug in `ArraySort()` that would crash programs if the passed array has no
|
||||||
elements.
|
elements.
|
||||||
|
- Adds `Db[OP]Args` functions that are equivalent to their `Db[OP]` counter parts, but
|
||||||
|
uses an array of string instead of variadic arguments.
|
||||||
|
|
||||||
## v0.4.0
|
## v0.4.0
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,13 @@ extern void DbMaxCacheSet(Db *, size_t);
|
||||||
*/
|
*/
|
||||||
extern DbRef * DbCreate(Db *, size_t,...);
|
extern DbRef * DbCreate(Db *, size_t,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behaves like
|
||||||
|
* .Fn DbCreate ,
|
||||||
|
* but with an array of strings instead of variadic arguments.
|
||||||
|
*/
|
||||||
|
extern DbRef * DbCreateArgs(Db *, Array *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock an existing object in the database. This function will fail
|
* Lock an existing object in the database. This function will fail
|
||||||
* if the object does not exist. It takes a variable number of C
|
* if the object does not exist. It takes a variable number of C
|
||||||
|
@ -129,6 +136,13 @@ extern DbRef * DbCreate(Db *, size_t,...);
|
||||||
*/
|
*/
|
||||||
extern DbRef * DbLock(Db *, size_t,...);
|
extern DbRef * DbLock(Db *, size_t,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behaves like
|
||||||
|
* .Fn DbLock ,
|
||||||
|
* but with an array of strings instead of variadic arguments.
|
||||||
|
*/
|
||||||
|
extern DbRef * DbLockArgs(Db *, Array *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Behaves like
|
* Behaves like
|
||||||
* .Fn DbLock ,
|
* .Fn DbLock ,
|
||||||
|
@ -138,6 +152,13 @@ extern DbRef * DbLock(Db *, size_t,...);
|
||||||
*/
|
*/
|
||||||
extern DbRef * DbLockIntent(Db *, DbHint, size_t,...);
|
extern DbRef * DbLockIntent(Db *, DbHint, size_t,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behaves like
|
||||||
|
* .Fn DbLockIntent ,
|
||||||
|
* but with an array of strings instead of variadic arguments.
|
||||||
|
*/
|
||||||
|
extern DbRef * DbLockIntentArgs(Db *, DbHint, Array *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immediately and permanently remove an object from the database.
|
* Immediately and permanently remove an object from the database.
|
||||||
* This function assumes the object is not locked, otherwise undefined
|
* This function assumes the object is not locked, otherwise undefined
|
||||||
|
@ -145,6 +166,13 @@ extern DbRef * DbLockIntent(Db *, DbHint, size_t,...);
|
||||||
*/
|
*/
|
||||||
extern bool DbDelete(Db *, size_t,...);
|
extern bool DbDelete(Db *, size_t,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behaves like
|
||||||
|
* .Fn DbDelete ,
|
||||||
|
* but with an array of strings instead of variadic arguments.
|
||||||
|
*/
|
||||||
|
extern bool DbDeleteArgs(Db *, Array *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlock an object and return it back to the database. This function
|
* Unlock an object and return it back to the database. This function
|
||||||
* immediately syncs the object to the filesystem. The cache is a
|
* immediately syncs the object to the filesystem. The cache is a
|
||||||
|
@ -162,6 +190,13 @@ extern bool DbUnlock(Db *, DbRef *);
|
||||||
*/
|
*/
|
||||||
extern bool DbExists(Db *, size_t,...);
|
extern bool DbExists(Db *, size_t,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behaves like
|
||||||
|
* .Fn DbExists ,
|
||||||
|
* but with an array of strings instead of variadic arguments.
|
||||||
|
*/
|
||||||
|
extern bool DbExistsArgs(Db *, Array *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all of the objects at a given path. Unlike the other varargs
|
* List all of the objects at a given path. Unlike the other varargs
|
||||||
* functions, this one does not take a path to a specific object; it
|
* functions, this one does not take a path to a specific object; it
|
||||||
|
@ -174,6 +209,13 @@ extern bool DbExists(Db *, size_t,...);
|
||||||
*/
|
*/
|
||||||
extern Array * DbList(Db *, size_t,...);
|
extern Array * DbList(Db *, size_t,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behaves like
|
||||||
|
* .Fn DbList ,
|
||||||
|
* but with an array of strings instead of variadic arguments.
|
||||||
|
*/
|
||||||
|
extern Array * DbListArgs(Db *, Array *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the list returned by
|
* Free the list returned by
|
||||||
* .Fn DbListFree .
|
* .Fn DbListFree .
|
||||||
|
|
75
src/Db/Db.c
75
src/Db/Db.c
|
@ -262,6 +262,16 @@ DbClose(Db * db)
|
||||||
Free(db);
|
Free(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DbRef *
|
||||||
|
DbCreateArgs(Db * db, Array *args)
|
||||||
|
{
|
||||||
|
if (!args || !db || !db->create)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return db->create(db, args);
|
||||||
|
}
|
||||||
DbRef *
|
DbRef *
|
||||||
DbCreate(Db * db, size_t nArgs,...)
|
DbCreate(Db * db, size_t nArgs,...)
|
||||||
{
|
{
|
||||||
|
@ -283,12 +293,22 @@ DbCreate(Db * db, size_t nArgs,...)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db->create(db, args);
|
ret = DbCreateArgs(db, args);
|
||||||
ArrayFree(args);
|
ArrayFree(args);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DbDeleteArgs(Db * db, Array *args)
|
||||||
|
{
|
||||||
|
if (!args || !db || !db->delete)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return db->delete(db, args);
|
||||||
|
}
|
||||||
bool
|
bool
|
||||||
DbDelete(Db * db, size_t nArgs,...)
|
DbDelete(Db * db, size_t nArgs,...)
|
||||||
{
|
{
|
||||||
|
@ -305,12 +325,22 @@ DbDelete(Db * db, size_t nArgs,...)
|
||||||
args = ArrayFromVarArgs(nArgs, ap);
|
args = ArrayFromVarArgs(nArgs, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
ret = db->delete(db, args);
|
ret = DbDeleteArgs(db, args);
|
||||||
|
|
||||||
ArrayFree(args);
|
ArrayFree(args);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DbRef *
|
||||||
|
DbLockArgs(Db * db, Array *args)
|
||||||
|
{
|
||||||
|
if (!args || !db || !db->lockFunc)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return db->lockFunc(db, DB_HINT_WRITE, args);
|
||||||
|
}
|
||||||
DbRef *
|
DbRef *
|
||||||
DbLock(Db * db, size_t nArgs,...)
|
DbLock(Db * db, size_t nArgs,...)
|
||||||
{
|
{
|
||||||
|
@ -318,6 +348,11 @@ DbLock(Db * db, size_t nArgs,...)
|
||||||
Array *args;
|
Array *args;
|
||||||
DbRef *ret;
|
DbRef *ret;
|
||||||
|
|
||||||
|
if (!db)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
va_start(ap, nArgs);
|
va_start(ap, nArgs);
|
||||||
args = ArrayFromVarArgs(nArgs, ap);
|
args = ArrayFromVarArgs(nArgs, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
@ -327,13 +362,22 @@ DbLock(Db * db, size_t nArgs,...)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db->lockFunc(db, DB_HINT_WRITE, args);
|
ret = DbLockArgs(db, args);
|
||||||
|
|
||||||
ArrayFree(args);
|
ArrayFree(args);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DbRef *
|
||||||
|
DbLockIntentArgs(Db * db, DbHint hint, Array *args)
|
||||||
|
{
|
||||||
|
if (!db || !args || !db->lockFunc)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return db->lockFunc(db, hint, args);
|
||||||
|
}
|
||||||
DbRef *
|
DbRef *
|
||||||
DbLockIntent(Db * db, DbHint hint, size_t nArgs,...)
|
DbLockIntent(Db * db, DbHint hint, size_t nArgs,...)
|
||||||
{
|
{
|
||||||
|
@ -350,7 +394,7 @@ DbLockIntent(Db * db, DbHint hint, size_t nArgs,...)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db->lockFunc(db, hint, args);
|
ret = DbLockIntentArgs(db, hint, args);
|
||||||
|
|
||||||
ArrayFree(args);
|
ArrayFree(args);
|
||||||
|
|
||||||
|
@ -368,6 +412,16 @@ DbUnlock(Db * db, DbRef * ref)
|
||||||
return db->unlock(db, ref);
|
return db->unlock(db, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DbExistsArgs(Db * db, Array *args)
|
||||||
|
{
|
||||||
|
if (!args || !db || !db->exists)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return db->exists(db, args);
|
||||||
|
}
|
||||||
bool
|
bool
|
||||||
DbExists(Db * db, size_t nArgs,...)
|
DbExists(Db * db, size_t nArgs,...)
|
||||||
{
|
{
|
||||||
|
@ -388,12 +442,21 @@ DbExists(Db * db, size_t nArgs,...)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db->exists(db, args);
|
ret = DbExistsArgs(db, args);
|
||||||
ArrayFree(args);
|
ArrayFree(args);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array *
|
||||||
|
DbListArgs(Db *db, Array *args)
|
||||||
|
{
|
||||||
|
if (!db || !args || !db->list)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return db->list(db, args);
|
||||||
|
}
|
||||||
Array *
|
Array *
|
||||||
DbList(Db * db, size_t nArgs,...)
|
DbList(Db * db, size_t nArgs,...)
|
||||||
{
|
{
|
||||||
|
@ -410,7 +473,7 @@ DbList(Db * db, size_t nArgs,...)
|
||||||
path = ArrayFromVarArgs(nArgs, ap);
|
path = ArrayFromVarArgs(nArgs, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
result = db->list(db, path);
|
result = DbListArgs(db, path);
|
||||||
|
|
||||||
ArrayFree(path);
|
ArrayFree(path);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -54,7 +54,8 @@ DbDirName(FlatDb * db, Array * args, size_t strip)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *sanitise = StrDuplicate(ArrayGet(args, i));
|
char *sanitise = StrDuplicate(ArrayGet(args, i));
|
||||||
for (j = 0; j < strlen(sanitise); j++)
|
size_t len = strlen(sanitise);
|
||||||
|
for (j = 0; j < len; j++)
|
||||||
{
|
{
|
||||||
sanitise[j] = DbSanitiseChar(sanitise[j]);
|
sanitise[j] = DbSanitiseChar(sanitise[j]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,9 @@ LMDBKeyHead(MDB_val key)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((void *) (end - 1) >= key.mv_data && *(end - 1))
|
/* Doing >= will lead to cases where it is sent straight to the
|
||||||
|
* start. Don't do that. */
|
||||||
|
while ((void *) (end - 1) > key.mv_data && *(end - 1))
|
||||||
{
|
{
|
||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue