helper callback for req_parseargs */
| 175 | |
| 176 | /* helper callback for req_parseargs */ |
| 177 | static int req_aprtable2luatable_cb_len(void *l, const char *key, |
| 178 | const char *value, size_t len) |
| 179 | { |
| 180 | int t; |
| 181 | lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */ |
| 182 | /* rstack_dump(L, RRR, "start of cb"); */ |
| 183 | /* L is [table<s,t>, table<s,s>] */ |
| 184 | /* build complex */ |
| 185 | |
| 186 | lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */ |
| 187 | /* rstack_dump(L, RRR, "after getfield"); */ |
| 188 | t = lua_type(L, -1); |
| 189 | switch (t) { |
| 190 | case LUA_TNIL: |
| 191 | case LUA_TNONE:{ |
| 192 | lua_pop(L, 1); /* [table<s,t>, table<s,s>] */ |
| 193 | lua_newtable(L); /* [array, table<s,t>, table<s,s>] */ |
| 194 | lua_pushnumber(L, 1); /* [1, array, table<s,t>, table<s,s>] */ |
| 195 | lua_pushlstring(L, value, len); /* [string, 1, array, table<s,t>, table<s,s>] */ |
| 196 | lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */ |
| 197 | lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */ |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | case LUA_TTABLE:{ |
| 202 | /* [array, table<s,t>, table<s,s>] */ |
| 203 | int size = lua_rawlen(L, -1); |
| 204 | lua_pushnumber(L, size + 1); /* [#, array, table<s,t>, table<s,s>] */ |
| 205 | lua_pushlstring(L, value, len); /* [string, #, array, table<s,t>, table<s,s>] */ |
| 206 | lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */ |
| 207 | lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */ |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* L is [table<s,t>, table<s,s>] */ |
| 213 | /* build simple */ |
| 214 | lua_getfield(L, -2, key); /* [VALUE, table<s,s>, table<s,t>] */ |
| 215 | if (lua_isnoneornil(L, -1)) { /* only set if not already set */ |
| 216 | lua_pop(L, 1); /* [table<s,s>, table<s,t>]] */ |
| 217 | lua_pushlstring(L, value, len); /* [string, table<s,s>, table<s,t>] */ |
| 218 | lua_setfield(L, -3, key); /* [table<s,s>, table<s,t>] */ |
| 219 | } |
| 220 | else { |
| 221 | lua_pop(L, 1); |
| 222 | } |
| 223 | return 1; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | /* |