1
0
mirror of https://github.com/lxsang/antd-lua-plugin synced 2024-12-26 17:38:21 +01:00

update API to support binary POST data

This commit is contained in:
DanyLE 2022-08-19 19:59:10 +02:00
parent ae5dbf081e
commit dfb550308d
3 changed files with 33 additions and 4 deletions

View File

@ -4,17 +4,37 @@
// add a length field, and
void lua_new_byte_array(lua_State*L, int n)
{
size_t nbytes = sizeof(byte_array_t) + (n-1)*sizeof(unsigned char);
size_t nbytes = sizeof(byte_array_t) + n*sizeof(unsigned char);
byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes);
a->data = &((char*)a)[sizeof(byte_array_t)];
luaL_getmetatable(L, BYTEARRAY);
lua_setmetatable(L, -2);
a->size = n;
}
void lua_new_light_byte_array(lua_State*L, int n, char* ptr)
{
size_t nbytes = sizeof(byte_array_t);
byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes);
a->size = n;
a->data = ptr;
luaL_getmetatable(L, BYTEARRAY);
lua_setmetatable(L, -2);
}
static int l_new_barray (lua_State *L) {
int n = luaL_checknumber(L, 1);
lua_new_byte_array(L,n);
return 1; /* new userdatum is already on the stack */
}
static int l_new_lightbarray (lua_State *L) {
unsigned char * ptr = lua_touserdata(L,1);
int n = luaL_checknumber(L, 2);
lua_new_light_byte_array(L,n, ptr);
return 1; /* new userdatum is already on the stack */
}
byte_array_t *l_check_barray (lua_State *L,int idx) {
void *ud = luaL_checkudata(L, idx, BYTEARRAY);
luaL_argcheck(L, ud != NULL, idx, "`byte array' expected");
@ -78,6 +98,7 @@ static int l_barray_write(lua_State* L)
}
static const struct luaL_Reg barraylib[] = {
{"unew", l_new_lightbarray},
{"new", l_new_barray},
{"set", l_set_barray},
{"get", l_get_barray},

View File

@ -22,8 +22,15 @@ static void push_dict_to_lua(lua_State* L, dictionary_t d)
if(EQU(as->key,"COOKIE") || EQU(as->key,"REQUEST_HEADER") || EQU(as->key,"REQUEST_DATA") )
push_dict_to_lua(L, (dictionary_t)as->value);
else
{
if(strncmp(as->key,"octet-stream",12) == 0)
{
lua_pushlightuserdata(L, as->value);
}
else
{
lua_pushstring(L,as->value);
}
//printf("VALUE : %s\n",as->value );
}
lua_settable(L, -3);
@ -76,6 +83,7 @@ void* lua_handle(void* data, void* meta)
lua_pushlightuserdata(L, rq->client);
//lua_pushnumber(L,client);
lua_settable(L, -3);
lua_pushstring(L,"request");
push_dict_to_lua(L,rq->request);
lua_settable(L, -3);

View File

@ -20,7 +20,7 @@
// add byte array support
typedef struct{
int size;
unsigned char data[1];
unsigned char * data;
} byte_array_t;
typedef struct{