- Add new mandatory argument for lookup, set, and transaction_begin.
- Use the username to initialize dict_op_settings passed to lib-dict API
}
/*
- * Iterate a dict at key [-3,+2,e]
+ * Iterate a dict at key [-(3|4),+2,e]
*
* Args:
* 1) userdata: sturct dict *dict
* 2) string: key
* 3) integer: flags
+ * 4*) string: username
*
* Returns:
* Returns a iteration step function and dict iter userdata.
+ * Username will be NULL if not provided in args.
*/
int lua_dict_iterate(lua_State *L)
{
enum dict_iterate_flags flags;
struct lua_dict_iter *iter;
struct dict *dict;
- const char *path;
+ const char *path, *username = NULL;
pool_t pool;
- DLUA_REQUIRE_ARGS(L, 3);
+ DLUA_REQUIRE_ARGS_IN(L, 3, 4);
dict = dlua_check_dict(L, 1);
path = luaL_checkstring(L, 2);
flags = luaL_checkinteger(L, 3);
+ if (lua_gettop(L) >= 4)
+ username = luaL_checkstring(L, 4);
+
+ struct dict_op_settings set = {
+ .username = username,
+ };
/* set up iteration */
pool = pool_alloconly_create("lua dict iter", 128);
iter = p_new(pool, struct lua_dict_iter, 1);
iter->pool = pool;
- iter->iter = dict_iterate_init(dict, NULL, path, flags |
+ iter->iter = dict_iterate_init(dict, &set, path, flags |
DICT_ITERATE_FLAG_ASYNC);
p_array_init(&iter->refs, iter->pool, 32);
iter->L = L;
}
/*
- * Lookup a key in dict [-2,+1,e]
+ * Lookup a key in dict [-(2|3),+1,e]
*
* Args:
* 1) userdata: struct dict *dict
* 2) string: key
+ * 3*) string: username
*
* Returns:
* If key is found, returns a table with values. If key is not found,
* returns nil.
+ * Username will be NULL if not provided in args.
*/
static int lua_dict_lookup(lua_State *L)
{
struct dict *dict;
- const char *key;
+ const char *key, *username = NULL;
- DLUA_REQUIRE_ARGS(L, 2);
+ DLUA_REQUIRE_ARGS_IN(L, 2, 3);
dict = xlua_dict_getptr(L, 1, NULL);
key = luaL_checkstring(L, 2);
+ if (lua_gettop(L) >= 3)
+ username = luaL_checkstring(L, 3);
- dict_lookup_async(dict, NULL, key, lua_dict_lookup_callback, L);
+ struct dict_op_settings set = {
+ .username = username,
+ };
+ dict_lookup_async(dict, &set, key, lua_dict_lookup_callback, L);
return lua_dict_async_continue(L,
lua_yieldk(L, 0, 0, lua_dict_async_continue), 0);
}
/*
- * Start a dict transaction [-1,+1,e]
+ * Start a dict transaction [-(1|2),+1,e]
*
* Args:
* 1) userdata: struct dict *
+ * 2*) string: username
*
* Returns:
* Returns a new transaction object.
+ * Username will be NULL if not provided in args.
*/
int lua_dict_transaction_begin(lua_State *L)
{
struct lua_dict_txn *txn;
struct dict *dict;
+ const char *username = NULL;
pool_t pool;
- DLUA_REQUIRE_ARGS(L, 1);
+ DLUA_REQUIRE_ARGS_IN(L, 1, 2);
dict = dlua_check_dict(L, 1);
+ if (lua_gettop(L) >= 2)
+ username = luaL_checkstring(L, 2);
pool = pool_alloconly_create("lua dict txn", 128);
txn = p_new(pool, struct lua_dict_txn, 1);
txn->pool = pool;
- txn->txn = dict_transaction_begin(dict, NULL);
+
+ struct dict_op_settings set = {
+ .username = username,
+ };
+ txn->txn = dict_transaction_begin(dict, &set);
txn->state = STATE_OPEN;
txn->L = L;