"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib-dict/dict-lua.c" between
dovecot-2.3.16.tar.gz and dovecot-2.3.17.tar.gz

About: Dovecot is an IMAP and POP3 server, written with security primarily in mind.

dict-lua.c  (dovecot-2.3.16):dict-lua.c  (dovecot-2.3.17)
skipping to change at line 30 skipping to change at line 30
{ {
} }
DLUA_WRAP_C_DATA(dict, struct dict, lua_dict_unref, lua_dict_methods); DLUA_WRAP_C_DATA(dict, struct dict, lua_dict_unref, lua_dict_methods);
static int lua_dict_async_continue(lua_State *L, static int lua_dict_async_continue(lua_State *L,
int status ATTR_UNUSED, int status ATTR_UNUSED,
lua_KContext ctx ATTR_UNUSED) lua_KContext ctx ATTR_UNUSED)
{ {
/* /*
* lua_dict_*_callback() already pushed the result table or error * lua_dict_*_callback() already pushed the result table/nil or error
* string. We simply need to return/error out. * string. We simply need to return/error out.
*/ */
if (lua_istable(L, -1)) if (lua_istable(L, -1) || lua_isnil(L, -1))
return 1; return 1;
else else
return lua_error(L); return lua_error(L);
} }
static void lua_dict_lookup_callback(const struct dict_lookup_result *result, static void lua_dict_lookup_callback(const struct dict_lookup_result *result,
lua_State *L) lua_State *L)
{ {
if (result->ret < 0) { if (result->ret < 0) {
lua_pushstring(L, result->error); lua_pushstring(L, result->error);
} else if (result->ret == 0) {
lua_pushnil(L);
} else { } else {
unsigned int i; unsigned int i;
lua_newtable(L); lua_newtable(L);
for (i = 0; i < str_array_length(result->values); i++) { for (i = 0; i < str_array_length(result->values); i++) {
lua_pushstring(L, result->values[i]); lua_pushstring(L, result->values[i]);
lua_seti(L, -2, i + 1); lua_seti(L, -2, i + 1);
} }
} }
dlua_pcall_yieldable_resume(L, 1); dlua_pcall_yieldable_resume(L, 1);
} }
/* /*
* Lookup a key in dict [-2,+1,e] * Lookup a key in dict [-(2|3),+1,e]
* *
* Args: * Args:
* 1) userdata: struct dict *dict * 1) userdata: struct dict *dict
* 2) string: key * 2) string: key
* 3*) string: username
* *
* Returns: * Returns:
* If key is found, returns a table with values. If key is not found, * If key is found, returns a table with values. If key is not found,
* returns nil. * returns nil.
* Username will be NULL if not provided in args.
*/ */
static int lua_dict_lookup(lua_State *L) static int lua_dict_lookup(lua_State *L)
{ {
struct dict *dict; 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); dict = xlua_dict_getptr(L, 1, NULL);
key = luaL_checkstring(L, 2); key = luaL_checkstring(L, 2);
if (lua_gettop(L) >= 3)
username = luaL_checkstring(L, 3);
dict_lookup_async(dict, 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, return lua_dict_async_continue(L,
lua_yieldk(L, 0, 0, lua_dict_async_continue), 0); lua_yieldk(L, 0, 0, lua_dict_async_continue), 0);
} }
void dlua_push_dict(lua_State *L, struct dict *dict) void dlua_push_dict(lua_State *L, struct dict *dict)
{ {
xlua_pushdict(L, dict, FALSE); xlua_pushdict(L, dict, FALSE);
} }
 End of changes. 10 change blocks. 
6 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)