------------------ request methods -------------------- */ helper callback for req_parseargs */
| 126 | /* ------------------ request methods -------------------- */ |
| 127 | /* helper callback for req_parseargs */ |
| 128 | static int req_aprtable2luatable_cb(void *l, const char *key, |
| 129 | const char *value) |
| 130 | { |
| 131 | int t; |
| 132 | lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */ |
| 133 | /* rstack_dump(L, RRR, "start of cb"); */ |
| 134 | /* L is [table<s,t>, table<s,s>] */ |
| 135 | /* build complex */ |
| 136 | |
| 137 | lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */ |
| 138 | /* rstack_dump(L, RRR, "after getfield"); */ |
| 139 | t = lua_type(L, -1); |
| 140 | switch (t) { |
| 141 | case LUA_TNIL: |
| 142 | case LUA_TNONE:{ |
| 143 | lua_pop(L, 1); /* [table<s,t>, table<s,s>] */ |
| 144 | lua_newtable(L); /* [array, table<s,t>, table<s,s>] */ |
| 145 | lua_pushnumber(L, 1); /* [1, array, table<s,t>, table<s,s>] */ |
| 146 | lua_pushstring(L, value); /* [string, 1, array, table<s,t>, table<s,s>] */ |
| 147 | lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */ |
| 148 | lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */ |
| 149 | break; |
| 150 | } |
| 151 | case LUA_TTABLE:{ |
| 152 | /* [array, table<s,t>, table<s,s>] */ |
| 153 | int size = lua_rawlen(L, -1); |
| 154 | lua_pushnumber(L, size + 1); /* [#, array, table<s,t>, table<s,s>] */ |
| 155 | lua_pushstring(L, value); /* [string, #, array, table<s,t>, table<s,s>] */ |
| 156 | lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */ |
| 157 | lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */ |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* L is [table<s,t>, table<s,s>] */ |
| 163 | /* build simple */ |
| 164 | lua_getfield(L, -2, key); /* [VALUE, table<s,s>, table<s,t>] */ |
| 165 | if (lua_isnoneornil(L, -1)) { /* only set if not already set */ |
| 166 | lua_pop(L, 1); /* [table<s,s>, table<s,t>]] */ |
| 167 | lua_pushstring(L, value); /* [string, table<s,s>, table<s,t>] */ |
| 168 | lua_setfield(L, -3, key); /* [table<s,s>, table<s,t>] */ |
| 169 | } |
| 170 | else { |
| 171 | lua_pop(L, 1); |
| 172 | } |
| 173 | return 1; |
| 174 | } |
| 175 | |
| 176 | /* helper callback for req_parseargs */ |
| 177 | static int req_aprtable2luatable_cb_len(void *l, const char *key, |