Lines Matching refs:L
56 typedef int (*mcp_mut_c)(lua_State *L, int tidx);
57 typedef int (*mcp_mut_i)(lua_State *L, int tidx, int sc, struct mcp_mutator *mut);
124 lua_State *L; member
134 #define mut_step_c(n) static int mcp_mutator_##n##_c(lua_State *L, int tidx)
135 #define mut_step_i(n) static int mcp_mutator_##n##_i(lua_State *L, int tidx, int sc, struct mcp_mut…
143 static void _mut_check_idx(lua_State *L, int tidx) { in _mut_check_idx() argument
144 if (lua_getfield(L, tidx, "idx") != LUA_TNIL) { in _mut_check_idx()
145 luaL_checktype(L, -1, LUA_TNUMBER); in _mut_check_idx()
147 lua_Integer i = lua_tointegerx(L, -1, &isnum); in _mut_check_idx()
149 proxy_lua_ferror(L, "mutator step %d: must provide 'idx' argument as an integer", tidx); in _mut_check_idx()
152 proxy_lua_ferror(L, "mutator step %d: 'idx' argument must be greater than 1", tidx); in _mut_check_idx()
155 proxy_lua_ferror(L, "mutator step %d: must provide 'idx' argument", tidx); in _mut_check_idx()
157 lua_pop(L, 1); in _mut_check_idx()
160 static size_t _mut_check_strlen(lua_State *L, int tidx, const char *n) { in _mut_check_strlen() argument
163 if (lua_getfield(L, tidx, n) != LUA_TNIL) { in _mut_check_strlen()
164 lua_tolstring(L, -1, &len); in _mut_check_strlen()
166 proxy_lua_ferror(L, "mutator step %d: must provide '%s' argument", tidx, n); in _mut_check_strlen()
168 lua_pop(L, 1); in _mut_check_strlen()
173 static void _mut_check_flag(lua_State *L, int tidx) { in _mut_check_flag() argument
174 if (lua_getfield(L, tidx, "flag") != LUA_TNIL) { in _mut_check_flag()
176 const char *flag = lua_tolstring(L, -1, &len); in _mut_check_flag()
178 proxy_lua_ferror(L, "mutator step %d: 'flag' must be a single character", tidx); in _mut_check_flag()
181 proxy_lua_ferror(L, "mutator step %d: 'flag' must be alphanumeric", tidx); in _mut_check_flag()
184 proxy_lua_ferror(L, "mutator step %d: must provide 'flag' argument", tidx); in _mut_check_flag()
186 lua_pop(L, 1); // val or nil in _mut_check_flag()
189 static void _mut_init_flag(lua_State *L, int tidx, struct mcp_mut_flag *c) { in _mut_init_flag() argument
190 if (lua_getfield(L, tidx, "flag") != LUA_TNIL) { in _mut_init_flag()
191 const char *flag = lua_tostring(L, -1); in _mut_init_flag()
195 lua_pop(L, 1); // val or nil in _mut_init_flag()
209 if (lua_getfield(L, tidx, "cmd") != LUA_TNIL) { in mut_step_c()
210 lua_tolstring(L, -1, &len); in mut_step_c()
214 proxy_lua_ferror(L, "mutator step %d: 'cmd' too long", tidx); in mut_step_c()
217 proxy_lua_ferror(L, "mutator step %d: must provide 'cmd' argument", tidx); in mut_step_c()
219 lua_pop(L, 1); in mut_step_c()
229 if (lua_getfield(L, tidx, "cmd") != LUA_TNIL) { in mut_step_i()
230 const char *cmd = lua_tolstring(L, -1, &len); in mut_step_i()
237 lua_pop(L, 1); in mut_step_i()
261 _mut_check_idx(L, tidx); in mut_step_c()
267 if (lua_getfield(L, tidx, "idx") != LUA_TNIL) { in mut_step_i()
268 s->idx = lua_tointeger(L, -1); in mut_step_i()
270 lua_pop(L, 1); in mut_step_i()
278 mcp_request_t *srq = lua_touserdata(run->L, idx); in mut_step_n()
303 _mut_check_idx(L, tidx); in mut_step_c()
310 if (lua_getfield(L, tidx, "idx") != LUA_TNIL) { in mut_step_i()
311 s->idx = lua_tointeger(L, -1); in mut_step_i()
313 lua_pop(L, 1); in mut_step_i()
320 mcp_request_t *srq = lua_touserdata(run->L, idx); in mut_step_n()
338 if (lua_getfield(L, tidx, "str") != LUA_TNIL) { in mut_step_c()
339 lua_tolstring(L, -1, &len); in mut_step_c()
341 proxy_lua_ferror(L, "mutator step %d: 'str' must have nonzero length", tidx); in mut_step_c()
344 proxy_lua_ferror(L, "mutator step %d: must provide 'str' argument", tidx); in mut_step_c()
346 lua_pop(L, 1); // val or nil in mut_step_c()
357 if (lua_getfield(L, tidx, "str") != LUA_TNIL) { in mut_step_i()
358 const char *str = lua_tolstring(L, -1, &len); in mut_step_i()
365 lua_pop(L, 1); // val or nil in mut_step_i()
389 return _mut_check_strlen(L, tidx, "str"); in mut_step_c()
397 if (lua_getfield(L, tidx, "str") != LUA_TNIL) { in mut_step_i()
398 const char *str = lua_tolstring(L, -1, &len); in mut_step_i()
405 lua_pop(L, 1); in mut_step_i()
428 _mut_check_idx(L, tidx); in mut_step_c()
434 if (lua_getfield(L, tidx, "idx") != LUA_TNIL) { in mut_step_i()
435 s->idx = lua_tointeger(L, -1); in mut_step_i()
437 lua_pop(L, 1); in mut_step_i()
445 mcp_resp_t *srs = lua_touserdata(run->L, idx); in mut_step_n()
479 if (lua_getfield(L, tidx, "code") != LUA_TNIL) { in mut_step_c()
480 const char *val = lua_tostring(L, -1); in mut_step_c()
489 … proxy_lua_ferror(L, "mutator step %d: mode must be 'error', server', or 'client'", tidx); in mut_step_c()
494 proxy_lua_ferror(L, "mutator step %d: must provide 'mode' argument", tidx); in mut_step_c()
496 lua_pop(L, 1); in mut_step_c()
498 if (lua_getfield(L, tidx, "msg") != LUA_TNIL) { in mut_step_c()
500 lua_tolstring(L, -1, &len); in mut_step_c()
502 proxy_lua_ferror(L, "mutator step %d: 'msg' must be a nonzero length string", tidx); in mut_step_c()
506 lua_pop(L, 1); in mut_step_c()
518 if (lua_getfield(L, tidx, "code") != LUA_TNIL) { in mut_step_i()
519 const char *val = lua_tostring(L, -1); in mut_step_i()
528 … proxy_lua_ferror(L, "mutator step %d: code must be 'error', server', or 'client'", tidx); in mut_step_i()
538 proxy_lua_ferror(L, "mutator step %d: must provide 'code' argument", tidx); in mut_step_i()
540 lua_pop(L, 1); in mut_step_i()
542 if (lua_getfield(L, tidx, "msg") != LUA_TNIL) { in mut_step_i()
543 const char *str = lua_tolstring(L, -1, &len); in mut_step_i()
551 lua_pop(L, 1); in mut_step_i()
576 _mut_check_flag(L, tidx); in mut_step_c()
579 int vtype = lua_getfield(L, tidx, "val"); in mut_step_c()
582 lua_tolstring(L, -1, &len); in mut_step_c()
584 proxy_lua_ferror(L, "mutator step %d: unsupported type for 'val'", tidx); in mut_step_c()
586 lua_pop(L, 1); in mut_step_c()
596 _mut_init_flag(L, tidx, &c->flag); in mut_step_i()
597 if (lua_getfield(L, tidx, "val") != LUA_TNIL) { in mut_step_i()
598 const char *str = lua_tolstring(L, -1, &len); in mut_step_i()
605 lua_pop(L, 1); in mut_step_i()
636 _mut_check_flag(L, tidx); in mut_step_c()
637 _mut_check_idx(L, tidx); in mut_step_c()
646 _mut_init_flag(L, tidx, c); in mut_step_i()
648 if (lua_getfield(L, tidx, "idx") != LUA_TNIL) { in mut_step_i()
649 s->idx = lua_tointeger(L, -1); in mut_step_i()
651 lua_pop(L, 1); in mut_step_i()
665 mcp_request_t *srq = lua_touserdata(run->L, idx); in mut_step_n()
682 mcp_resp_t *srs = lua_touserdata(run->L, idx); in mut_step_n()
721 _mut_check_idx(L, tidx); in mut_step_c()
724 if (lua_getfield(L, tidx, "arg") == LUA_TSTRING) { in mut_step_c()
725 const char *a = lua_tostring(L, -1); in mut_step_c()
730 … proxy_lua_ferror(L, "mutator step %d: 'arg' must be request, response, string or int", tidx); in mut_step_c()
733 proxy_lua_ferror(L, "mutator step %d: missing 'arg' for input type", tidx); in mut_step_c()
735 lua_pop(L, 1); in mut_step_c()
742 if (lua_getfield(L, tidx, "idx") != LUA_TNIL) { in mut_step_i()
743 s->idx = lua_tointeger(L, -1); in mut_step_i()
745 lua_pop(L, 1); in mut_step_i()
748 if (lua_getfield(L, tidx, "arg") == LUA_TSTRING) { in mut_step_i()
749 const char *a = lua_tostring(L, -1); in mut_step_i()
759 … proxy_lua_ferror(L, "mutator step %d: 'arg' must be request, response, string or int", tidx); in mut_step_i()
762 lua_pop(L, 1); in mut_step_i()
768 lua_State *L = run->L; in mut_step_n() local
781 lua_getmetatable(L, idx); in mut_step_n()
782 lua_getiuservalue(L, 1, MUT_REQ); in mut_step_n()
783 if (lua_rawequal(L, -1, -2) == 0) { in mut_step_n()
787 lua_pop(L, 2); in mut_step_n()
788 srq = lua_touserdata(L, idx); in mut_step_n()
795 lua_getmetatable(L, idx); in mut_step_n()
796 lua_getiuservalue(L, 1, MUT_RES); in mut_step_n()
797 if (lua_rawequal(L, -1, -2) == 0) { in mut_step_n()
801 lua_pop(L, 2); in mut_step_n()
808 if (lua_isstring(L, idx)) { in mut_step_n()
811 run->vbuf = lua_tolstring(L, idx, &run->vlen); in mut_step_n()
817 lua_isnumber(L, idx); in mut_step_n()
859 static enum mcp_mut_steptype mcp_mutator_steptype(lua_State *L) { in mcp_mutator_steptype() argument
860 const char *type = luaL_checkstring(L, -1); in mcp_mutator_steptype()
870 static int mcp_mutator_new(lua_State *L, enum mcp_mut_type type) { in mcp_mutator_new() argument
871 int argc = lua_gettop(L); in mcp_mutator_new()
877 luaL_checktype(L, x, LUA_TTABLE); in mcp_mutator_new()
878 if (lua_getfield(L, x, "t") != LUA_TNIL) { in mcp_mutator_new()
879 enum mcp_mut_steptype st = mcp_mutator_steptype(L); in mcp_mutator_new()
882 proxy_lua_ferror(L, "mutator step %d: step incompatible with mutator type", x); in mcp_mutator_new()
885 proxy_lua_ferror(L, "mutator step %d: unknown step type", x); in mcp_mutator_new()
887 size += e->c(L, x); in mcp_mutator_new()
889 lua_pop(L, 1); // drop 't' or nil in mcp_mutator_new()
896 struct mcp_mutator *mut = lua_newuserdatauv(L, sizeof(*mut) + extsize, 2); in mcp_mutator_new()
901 proxy_lua_error(L, "mutator_new: failed to allocate memory"); in mcp_mutator_new()
903 luaL_setmetatable(L, "mcp.mutator"); in mcp_mutator_new()
908 luaL_getmetatable(L, "mcp.request"); in mcp_mutator_new()
909 lua_setiuservalue(L, -2, MUT_REQ); in mcp_mutator_new()
910 luaL_getmetatable(L, "mcp.response"); in mcp_mutator_new()
911 lua_setiuservalue(L, -2, MUT_RES); in mcp_mutator_new()
917 if (lua_getfield(L, x, "t") != LUA_TNIL) { in mcp_mutator_new()
918 enum mcp_mut_steptype st = mcp_mutator_steptype(L); in mcp_mutator_new()
920 mcp_mut_entries[st].i(L, x, scount, mut); in mcp_mutator_new()
929 lua_pop(L, 1); // drop t or nil in mcp_mutator_new()
934 proxy_lua_error(L, "mutator failed to properly initialize, memory not filled correctly"); in mcp_mutator_new()
992 LIBEVENT_THREAD *t = PROXY_GET_THR(run->L); in mcp_mut_run()
1076 int mcplib_req_mutator_new(lua_State *L) { in mcplib_req_mutator_new() argument
1077 return mcp_mutator_new(L, MUT_REQ); in mcplib_req_mutator_new()
1080 int mcplib_res_mutator_new(lua_State *L) { in mcplib_res_mutator_new() argument
1081 return mcp_mutator_new(L, MUT_RES); in mcplib_res_mutator_new()
1085 int mcplib_mutator_gc(lua_State *L) { in mcplib_mutator_gc() argument
1086 struct mcp_mutator *mut = lua_touserdata(L, 1); in mcplib_mutator_gc()
1117 int mcplib_mutator_call(lua_State *L) { in mcplib_mutator_call() argument
1119 struct mcp_mutator *mut = lua_touserdata(L, 1); in mcplib_mutator_call()
1120 luaL_checktype(L, 2, LUA_TUSERDATA); in mcplib_mutator_call()
1121 if (lua_checkstack(L, mut->rcount + 3) == 0) { in mcplib_mutator_call()
1122 proxy_lua_error(L, "mutator ran out of stack space for results"); in mcplib_mutator_call()
1125 lua_getmetatable(L, 2); // put dest obj arg metatable on stack in mcplib_mutator_call()
1126 lua_getiuservalue(L, 1, mut->type); // put stashed metatable on stack in mcplib_mutator_call()
1127 luaL_argcheck(L, lua_rawequal(L, -1, -2), 2, in mcplib_mutator_call()
1129 lua_pop(L, 2); // toss both metatables in mcplib_mutator_call()
1133 void *arg = lua_touserdata(L, 2); in mcplib_mutator_call()
1135 struct mcp_mut_run run = {L, mut, arg, NULL, NULL, 0}; in mcplib_mutator_call()