static int ngx_http_lua_ngx_decode_args(lua_State *L) { u_char *buf; u_char *tmp; size_t len = 0; int n; int max; n = lua_gettop(L); if (n != 1 && n != 2) { return luaL_error(L, "expecting 1 or 2 arguments but seen %d", n); } buf = (u_char *) luaL_checklstring(L, 1, &len); if (n == 2) { max = luaL_checkint(L, 2); lua_pop(L, 1); } else { max = NGX_HTTP_LUA_MAX_ARGS; } tmp = lua_newuserdata(L, len); ngx_memcpy(tmp, buf, len); lua_createtable(L, 0, 4); return ngx_http_lua_parse_args(L, tmp, tmp + len, max); }
static int ngx_http_lua_ngx_req_get_uri_args(lua_State *L) { ngx_http_request_t *r; u_char *buf; u_char *last; int retval; int n; int max; n = lua_gettop(L); if (n != 0 && n != 1) { return luaL_error(L, "expecting 0 or 1 arguments but seen %d", n); } if (n == 1) { max = luaL_checkinteger(L, 1); lua_pop(L, 1); } else { max = NGX_HTTP_LUA_MAX_ARGS; } lua_pushlightuserdata(L, &ngx_http_lua_request_key); lua_rawget(L, LUA_GLOBALSINDEX); r = lua_touserdata(L, -1); lua_pop(L, 1); if (r == NULL) { return luaL_error(L, "no request object found"); } ngx_http_lua_check_fake_request(L, r); lua_createtable(L, 0, 4); /* we copy r->args over to buf to simplify * unescaping query arg keys and values */ buf = ngx_palloc(r->pool, r->args.len); if (buf == NULL) { return luaL_error(L, "out of memory"); } ngx_memcpy(buf, r->args.data, r->args.len); last = buf + r->args.len; retval = ngx_http_lua_parse_args(r, L, buf, last, max); ngx_pfree(r->pool, buf); return retval; }
static int ngx_http_lua_ngx_decode_args(lua_State *L) { ngx_http_request_t *r; u_char *buf; u_char *tmp; size_t len = 0; int n; int max; n = lua_gettop(L); if (n != 1 && n != 2) { return luaL_error(L, "expecting 1 or 2 arguments but seen %d", n); } buf = (u_char *) luaL_checklstring(L, 1, &len); if (n == 2) { max = luaL_checkint(L, 2); lua_pop(L, 1); } else { max = NGX_HTTP_LUA_MAX_ARGS; } lua_pushlightuserdata(L, &ngx_http_lua_request_key); lua_rawget(L, LUA_GLOBALSINDEX); r = lua_touserdata(L, -1); lua_pop(L, 1); if (r == NULL) { return luaL_error(L, "no request object found"); } tmp = lua_newuserdata(L, len); ngx_memcpy(tmp, buf, len); lua_createtable(L, 0, 4); return ngx_http_lua_parse_args(r, L, tmp, tmp + len, max); }
int ngx_http_lua_ngx_req_get_uri_args(lua_State *L) { ngx_http_request_t *r; u_char *buf; u_char *last; int retval; if (lua_gettop(L) != 0) { return luaL_error(L, "expecting 0 arguments but seen %d", lua_gettop(L)); } lua_getglobal(L, GLOBALS_SYMBOL_REQUEST); r = lua_touserdata(L, -1); lua_pop(L, 1); if (r == NULL) { return luaL_error(L, "no request object found"); } lua_createtable(L, 0, 4); /* we copy r->args over to buf to simplify * unescaping query arg keys and values */ buf = ngx_palloc(r->pool, r->args.len); if (buf == NULL) { return luaL_error(L, "out of memory"); } ngx_memcpy(buf, r->args.data, r->args.len); last = buf + r->args.len; retval = ngx_http_lua_parse_args(r, L, buf, last); ngx_pfree(r->pool, buf); return retval; }
static int ngx_http_lua_ngx_req_get_post_args(lua_State *L) { ngx_http_request_t *r; u_char *buf; int retval; size_t len; ngx_chain_t *cl; u_char *p; u_char *last; int n; int max; n = lua_gettop(L); if (n != 0 && n != 1) { return luaL_error(L, "expecting 0 or 1 arguments but seen %d", n); } if (n == 1) { max = luaL_checkinteger(L, 1); lua_pop(L, 1); } else { max = NGX_HTTP_LUA_MAX_ARGS; } lua_pushlightuserdata(L, &ngx_http_lua_request_key); lua_rawget(L, LUA_GLOBALSINDEX); r = lua_touserdata(L, -1); lua_pop(L, 1); if (r == NULL) { return luaL_error(L, "no request object found"); } if (r->discard_body) { lua_createtable(L, 0, 4); return 1; } if (r->request_body == NULL) { return luaL_error(L, "no request body found; " "maybe you should turn on lua_need_request_body?"); } if (r->request_body->temp_file) { return luaL_error(L, "requesty body in temp file not supported"); } lua_createtable(L, 0, 4); if (r->request_body->bufs == NULL) { return 1; } /* we copy r->request_body->bufs over to buf to simplify * unescaping query arg keys and values */ len = 0; for (cl = r->request_body->bufs; cl; cl = cl->next) { len += cl->buf->last - cl->buf->pos; } dd("post body length: %d", (int) len); buf = ngx_palloc(r->pool, len); if (buf == NULL) { return luaL_error(L, "out of memory"); } p = buf; for (cl = r->request_body->bufs; cl; cl = cl->next) { p = ngx_copy(p, cl->buf->pos, cl->buf->last - cl->buf->pos); } dd("post body: %.*s", (int) len, buf); last = buf + len; retval = ngx_http_lua_parse_args(r, L, buf, last, max); ngx_pfree(r->pool, buf); return retval; }
int ngx_http_lua_ngx_req_get_post_args(lua_State *L) { ngx_http_request_t *r; u_char *buf; int retval; size_t len; ngx_chain_t *cl; u_char *p; u_char *last; if (lua_gettop(L) != 0) { return luaL_error(L, "expecting 0 arguments but seen %d", lua_gettop(L)); } lua_getglobal(L, GLOBALS_SYMBOL_REQUEST); r = lua_touserdata(L, -1); lua_pop(L, 1); if (r == NULL) { return luaL_error(L, "no request object found"); } if (r->discard_body) { lua_createtable(L, 0, 4); return 1; } if (r->request_body == NULL) { return luaL_error(L, "no request body found; " "maybe you should turn on lua_need_request_body?"); } if (r->request_body->temp_file) { return luaL_error(L, "requesty body in temp file not supported"); } lua_createtable(L, 0, 4); if (r->request_body->bufs == NULL) { return 1; } /* we copy r->request_body->bufs over to buf to simplify * unescaping query arg keys and values */ len = 0; for (cl = r->request_body->bufs; cl; cl = cl->next) { len += cl->buf->last - cl->buf->pos; } dd("post body length: %d", (int) len); buf = ngx_palloc(r->pool, len); if (buf == NULL) { return luaL_error(L, "out of memory"); } p = buf; for (cl = r->request_body->bufs; cl; cl = cl->next) { p = ngx_copy(p, cl->buf->pos, cl->buf->last - cl->buf->pos); } dd("post body: %.*s", (int) len, buf); last = buf + len; retval = ngx_http_lua_parse_args(r, L, buf, last); ngx_pfree(r->pool, buf); return retval; }