# HG changeset patch # User jbe # Date 1471819230 -7200 # Node ID 29322b2a1af8f3eae69b3f720e5900ecad58e0da # Parent 832741713761622e4f96c86791f11a6c870a4056 Require "mode" parameter passed to tlsconf function diff -r 832741713761 -r 29322b2a1af8 moonbridge_io.c --- a/moonbridge_io.c Sun Aug 21 16:12:11 2016 +0200 +++ b/moonbridge_io.c Mon Aug 22 00:40:30 2016 +0200 @@ -1681,6 +1681,17 @@ luaL_setmetatable(L, MOONBR_IO_TLSCONF_MT_REGKEY); lua_pushvalue(L, 1); lua_setuservalue(L, -2); +#if LUA_VERSION_NUM >= 503 + if (lua_getfield(L, 1, "mode") == LUA_TSTRING) value = lua_tostring(L, -1); +#else + lua_getfield(L, 1, "mode"); + if (lua_type(L, -1) == LUA_TSTRING) value = lua_tostring(L, -1); +#endif + else value = ""; + if (strcmp(value, "server") && strcmp(value, "client")) { + luaL_argcheck(L, 0, 1, "field \"mode\" must be set to \"server\" or \"client\""); + } + lua_pop(L, 1); moonbr_io_tlsconf_string("CA file", "ca_file", tls_config_set_ca_file); moonbr_io_tlsconf_string("CA path", "ca_path", tls_config_set_ca_path); moonbr_io_tlsconf_binary("CA", "ca_mem", tls_config_set_ca_mem); @@ -1688,9 +1699,17 @@ moonbr_io_tlsconf_binary("certificate", "cert_mem", tls_config_set_cert_mem); moonbr_io_tlsconf_string("key file", "key_file", tls_config_set_key_file); moonbr_io_tlsconf_binary("key", "key_mem", tls_config_set_key_mem); +#if LUA_VERSION_NUM >= 503 + valuetype = lua_getfield(L, 1, "verify_client"); +#else lua_getfield(L, 1, "verify_client"); +#endif if (lua_toboolean(L, -1)) { +#if LUA_VERSION_NUM >= 503 + if (valuetype == LUA_TSTRING) value = lua_tostring(L, -1); +#else if (lua_type(L, -1) == LUA_TSTRING) value = lua_tostring(L, -1); +#endif else value = ""; if (!strcmp(value, "required")) { tls_config_verify_client(tlsconf);