Commit 4d5c6839 authored by Jaromil's avatar Jaromil
Browse files

remove msgpack global namespace collision

for some yet undetected reason the msgpack library instantiates a
global table 'msgpack' with its own object even without assignation,
so we rename it and nil it in init.lua to avoid collisions.
parent 5030e8f2
......@@ -19,7 +19,7 @@ payload_schema = SCHEMA.Record {
data = read_json(DATA) -- TODO: data_schema validation
keys = read_json(KEYS, keys_schema)
header = unpack( base64(data.header) )
header = msgunpack( base64(data.header) )
dashkey = ECDH.new()
dashkey:private( base64(keys.community_seckey) )
......@@ -32,5 +32,5 @@ payload,ck = decrypt(dashkey,
validate(payload, payload_schema)
-- print("Header:")
-- content(unpack(payload.header) )
print(JSON.encode(unpack(payload.text) ))
-- content(msgunpack(payload.header) )
print(JSON.encode(msgunpack(payload.text) ))
......@@ -51,7 +51,7 @@ header['community_id'] = keys['community_id']
-- zenroom's functions encrypt/decrypt: .checksum .header .iv .text
output = encrypt(devkey,
base64(keys.community_pubkey),
pack(payload), pack(header))
msgpack(payload), msgpack(header))
output = map(output, O.to_base64)
output.zenroom = VERSION
......
......@@ -923,11 +923,11 @@ int luaopen_create(lua_State *L) {
LUALIB_API int luaopen_cmsgpack(lua_State *L) {
luaopen_create(L);
#if LUA_VERSION_NUM < 502
/* Register name globally for 5.1 */
lua_pushvalue(L, -1);
lua_setglobal(L, LUACMSGPACK_NAME);
#endif
// #if LUA_VERSION_NUM < 502
// /* Register name globally for 5.1 */
// lua_pushvalue(L, -1);
// lua_setglobal(L, LUACMSGPACK_NAME);
// #endif
return 1;
}
......@@ -935,7 +935,7 @@ LUALIB_API int luaopen_cmsgpack(lua_State *L) {
LUALIB_API int luaopen_cmsgpack_safe(lua_State *L) {
int i;
luaopen_cmsgpack(L);
luaopen_create(L);
/* Wrap all functions in the safe handler */
for (i = 0; i < (sizeof(cmds)/sizeof(*cmds) - 1); i++) {
......@@ -944,11 +944,11 @@ LUALIB_API int luaopen_cmsgpack_safe(lua_State *L) {
lua_setfield(L, -2, cmds[i].name);
}
#if LUA_VERSION_NUM < 502
/* Register name globally for 5.1 */
lua_pushvalue(L, -1);
lua_setglobal(L, LUACMSGPACK_SAFE_NAME);
#endif
// #if LUA_VERSION_NUM < 502
// /* Register name globally for 5.1 */
// lua_pushvalue(L, -1);
// lua_setglobal(L, LUACMSGPACK_SAFE_NAME);
// #endif
return 1;
}
......
......@@ -1418,11 +1418,11 @@ CJSON_EXPORT int luaopen_cjson(lua_State *l)
{
lua_cjson_new(l);
#ifdef ENABLE_CJSON_GLOBAL
/* Register a global "cjson" table. */
lua_pushvalue(l, -1);
lua_setglobal(l, CJSON_MODNAME);
#endif
// #ifdef ENABLE_CJSON_GLOBAL
// /* Register a global "cjson" table. */
// lua_pushvalue(l, -1);
// lua_setglobal(l, CJSON_MODNAME);
// #endif
/* Return cjson table */
return 1;
......
......@@ -2,6 +2,11 @@
-- zen_load_extensions(L) usually after zen_init()
JSON = require('json')
require('msgpack')
MSG = msgpack
msgpack = nil -- rename default global
SCHEMA = require('schema')
S = SCHEMA -- alias
RNG = require('zenroom_rng')
......@@ -17,7 +22,6 @@ ECP2 = require('ecp2')
BIG = require('zenroom_big')
HASH = require('zenroom_hash')
H = HASH -- alias
MSG = require('msgpack')
-- override type to recognize zenroom's types
luatype = type
......
......@@ -51,14 +51,14 @@ octet.from_base64 = function(s)
end
-- msgpack returning octets
function pack(data)
function msgpack(data)
if (type(data) == "zenroom.octet") then return str(MSG.pack(data:string())) end
-- else
return str(MSG.pack(data))
end
-- msgunpack returning lua's tables or single types
function unpack(data)
function msgunpack(data)
if (type(data) == "table") then error("unpack: argument is already a table") return
elseif(type(data) == "zenroom.octet") then return MSG.unpack(data:string())
elseif(type(data) == "string") then return MSG.unpack(data)
......
......@@ -118,7 +118,7 @@ int zen_exec_extension(lua_State *L, zen_extension_t *p) {
}
int nop(lua_State *L) {
lerror(L,"illegal instruction: required");
lerror(L,"illegal instruction: require");
return 0; }
int zen_require(lua_State *L) {
......@@ -148,10 +148,7 @@ int zen_require(lua_State *L) {
}
}
// require our own C to lua extensions
// if (strcmp(s, "crypto")==0) {
// luaL_requiref(L, s, luaopen_crypto, 1); return 1; }
if(strcasecmp(s, "octet") ==0) {
luaL_requiref(L, s, luaopen_octet, 1); }
// else if(strcmp(s, "rsa") ==0) {
......@@ -174,9 +171,6 @@ int zen_require(lua_State *L) {
luaL_requiref(L, s, lua_cjson_safe_new, 1); }
else if(strcasecmp(s, "msgpack") ==0) {
luaL_requiref(L, s, luaopen_cmsgpack_safe, 1); }
// else if(strcasecmp(s, "cjson_full") ==0) {
// luaL_requiref(L, s, lua_cjson_new, 1); }
else {
// shall we bail out and abort execution here?
warning(L, "required extension not found: %s",s);
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment