int compare_iptables_table(const char *ipt_save_1, int len_1, const char *ipt_save_2, int len_2, const char *table_name) { char table_1[len_1>0?len_1:1]; char table_2[len_2>0?len_2:1]; int ret = 0; if (!ipt_save_1 || !ipt_save_2 || !table_name || len_1 < 1 || len_2 < 1) { tlog_print(ERROR, "Bad param."); return -1; } if (get_table_string(ipt_save_1, len_1, table_name, table_1) == -1) { tlog_print(INFO, "Table not found in string 1"); return -1; } if (get_table_string(ipt_save_2, len_2, table_name, table_2) == -1) { tlog_print(INFO, "Table not found in string 2"); return -1; } if (strcmp(table_1, table_2) == 0) { // Match ret = 1; } return ret; }
/* * Core function to delete a mailbox. */ static int ifcore_delete(lua_State *lua) { const char *s, *u, *p; int r; if (lua_gettop(lua) != 2) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); luaL_checktype(lua, 2, LUA_TSTRING); lua_pushvalue(lua, 1); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); lua_pop(lua, 1); r = request_delete(s, p, u, lua_tostring(lua, 2)); lua_pop(lua, 2); lua_pushboolean(lua, (r == STATUS_RESPONSE_OK)); return 1; }
/* * Core function to fetch message information (flags, date, size). */ static int ifcore_fetchfast(lua_State *lua) { const char *s, *u, *p; int r; char *flags, *date, *size; flags = date = size = NULL; if (lua_gettop(lua) != 2) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); luaL_checktype(lua, 2, LUA_TSTRING); lua_pushvalue(lua, 1); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); lua_pop(lua, 1); r = request_fetchfast(s, p, u, lua_tostring(lua, 2), &flags, &date, &size); lua_pop(lua, 2); lua_pushboolean(lua, (r == STATUS_RESPONSE_OK)); if (!flags || !date || !size) return 1; lua_pushstring(lua, flags); lua_pushstring(lua, date); lua_pushstring(lua, size); xfree(flags); xfree(date); xfree(size); return 4; }
/* * Core function to list available mailboxes. */ static int ifcore_list(lua_State *lua) { const char *s, *u, *p; int r; char *mboxs, *folders; mboxs = folders = NULL; if (lua_gettop(lua) != 3) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); luaL_checktype(lua, 2, LUA_TSTRING); luaL_checktype(lua, 3, LUA_TSTRING); lua_pushvalue(lua, 1); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); lua_pop(lua, 1); r = request_list(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3), &mboxs, &folders); lua_pop(lua, 3); lua_pushboolean(lua, (r == STATUS_RESPONSE_OK)); if (!mboxs && !folders) return 1; lua_pushstring(lua, mboxs); lua_pushstring(lua, folders); xfree(mboxs); xfree(folders); return 3; }
/* * Core function to append messages to a mailbox. */ static int ifcore_append(lua_State *lua) { const char *s, *u, *p; int r; if (lua_gettop(lua) != 5) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); luaL_checktype(lua, 2, LUA_TSTRING); luaL_checktype(lua, 3, LUA_TSTRING); if (lua_type(lua, 4) != LUA_TNIL) luaL_checktype(lua, 4, LUA_TSTRING); if (lua_type(lua, 5) != LUA_TNIL) luaL_checktype(lua, 5, LUA_TSTRING); lua_pushvalue(lua, 1); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); lua_pop(lua, 1); r = request_append(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3), #if LUA_VERSION_NUM < 502 lua_objlen(lua, 3), #else lua_rawlen(lua, 3), #endif lua_type(lua, 4) == LUA_TSTRING ? lua_tostring(lua, 4) : NULL, lua_type(lua, 5) == LUA_TSTRING ? lua_tostring(lua, 5) : NULL); lua_pop(lua, lua_gettop(lua)); lua_pushboolean(lua, (r == STATUS_RESPONSE_OK)); return 1; }
/* * Core function to fetch message specific part. */ static int ifcore_fetchpart(lua_State *lua) { const char *s, *u, *p; int r; char *part; size_t len; part = NULL; len = 0; if (lua_gettop(lua) != 3) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); luaL_checktype(lua, 2, LUA_TSTRING); luaL_checktype(lua, 3, LUA_TSTRING); lua_pushvalue(lua, 1); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); lua_pop(lua, 1); r = request_fetchpart(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3), &part, &len); lua_pop(lua, 3); lua_pushboolean(lua, (r == STATUS_RESPONSE_OK)); if (!part) return 1; lua_pushlstring(lua, part, len); return 2; }
/* * Core function to login to the server. */ static int ifcore_login(lua_State *lua) { const char *s, *u, *w, *p; int r; if (lua_gettop(lua) != 1) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); if (!(w = get_table_string("password"))) luaL_error(lua, "no password specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); r = request_login(s, p, get_table_string("ssl"), u, w); lua_pop(lua, 1); if (r == STATUS_RESPONSE_NONE) return 0; lua_pushboolean(lua, (r == STATUS_RESPONSE_OK || r == STATUS_RESPONSE_PREAUTH)); return 1; }
/* * Core function to get the status of a mailbox. */ static int ifcore_status(lua_State *lua) { const char *s, *u, *p; int r; unsigned int exists, recent, unseen, uidnext; exists = recent = unseen = uidnext = -1; if (lua_gettop(lua) != 2) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TTABLE); luaL_checktype(lua, 2, LUA_TSTRING); lua_pushvalue(lua, 1); if (!(s = get_table_string("server"))) luaL_error(lua, "no mail server specified"); if (!(u = get_table_string("username"))) luaL_error(lua, "no username specified"); p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl")); lua_pop(lua, 1); r = request_status(s, p, u, lua_tostring(lua, 2), &exists, &recent, &unseen, &uidnext); lua_pop(lua, 2); lua_pushboolean(lua, (r == STATUS_RESPONSE_OK)); lua_pushnumber(lua, (lua_Number) (exists)); lua_pushnumber(lua, (lua_Number) (recent)); lua_pushnumber(lua, (lua_Number) (unseen)); lua_pushnumber(lua, (lua_Number) (uidnext)); return 5; }