X509_ATTRIBUTE* openssl_new_xattribute(lua_State*L, X509_ATTRIBUTE** a, int idx, const char* eprefix) { int arttype; size_t len = 0; int nid; const char* data = NULL; lua_getfield(L, idx, "object"); nid = openssl_get_nid(L, -1); if (nid == NID_undef) { if (eprefix) { luaL_error(L, "%s field object is invalid value", eprefix); } else luaL_argcheck(L, nid != NID_undef, idx, "field object is invalid value"); } lua_pop(L, 1); lua_getfield(L, idx, "type"); arttype = luaL_checkint(L, -1); if (arttype == V_ASN1_UNDEF || arttype == 0) { if (eprefix) { luaL_error(L, "%s field type is not invalid value", eprefix); } else luaL_argcheck(L, nid != NID_undef, idx, "field type is not invalid value"); } lua_pop(L, 1); lua_getfield(L, idx, "value"); if (lua_isstring(L, -1)) { data = lua_tolstring(L, -1, &len); } else if (auxiliar_isgroup(L, "openssl.asn1group", -1)) { ASN1_STRING* value = CHECK_GROUP(-1, ASN1_STRING, "openssl.asn1group"); if (ASN1_STRING_type(value) != arttype) { if (eprefix) luaL_error(L, "%s field value not match type", eprefix); else luaL_argcheck(L, ASN1_STRING_type(value) == arttype, idx, "field value not match type"); } data = (const char *)ASN1_STRING_data(value); len = ASN1_STRING_length(value); } else { if (eprefix) { luaL_error(L, "%s filed value only accept string or asn1_string", eprefix); } else luaL_argerror(L, idx, "filed value only accept string or asn1_string"); } lua_pop(L, 1); if (data) return X509_ATTRIBUTE_create_by_NID(a, nid, arttype, data, len); return 0; }
int luaopen_normalize(lua_State *L) { luaL_openlib(L, "normalize", normalize, 0); lua_getfield(L, -1, "normalize"); lua_setglobal(L, "normalize"); return(0); }
/* ** Read the options specified in the ini file. ** */ void CMeasureScript::ReadOptions(CConfigParser& parser, const WCHAR* section) { CMeasure::ReadOptions(parser, section); std::wstring file = parser.ReadString(section, L"ScriptFile", L""); if (!file.empty()) { if (m_MeterWindow) { m_MeterWindow->MakePathAbsolute(file); } std::string scriptFile = ConvertToAscii(file.c_str()); if (!m_Initialized || strcmp(scriptFile.c_str(), m_ScriptFile.c_str()) != 0) { DeleteLuaScript(); lua_State* L = LuaManager::GetState(); m_ScriptFile = scriptFile; m_LuaScript = new LuaScript(m_ScriptFile.c_str()); if (m_LuaScript->IsInitialized()) { m_HasInitializeFunction = m_LuaScript->IsFunction(g_InitializeFunctionName); m_HasUpdateFunction = m_LuaScript->IsFunction(g_UpdateFunctionName); m_HasGetStringFunction = m_LuaScript->IsFunction(g_GetStringFunctionName); // For backwards compatbility if (m_HasGetStringFunction) { LogWithArgs(LOG_WARNING, L"Script: Using deprecated GetStringValue() in [%s]", m_Name.c_str()); } lua_rawgeti(L, LUA_GLOBALSINDEX, m_LuaScript->GetRef()); *(CMeterWindow**)lua_newuserdata(L, sizeof(CMeterWindow*)) = m_MeterWindow; lua_getglobal(L, "CMeterWindow"); lua_setmetatable(L, -2); lua_setfield(L, -2, "SKIN"); *(CMeasure**)lua_newuserdata(L, sizeof(CMeasure*)) = this; lua_getglobal(L, "CMeasure"); lua_setmetatable(L, -2); lua_setfield(L, -2, "SELF"); // For backwards compatibility lua_getfield(L, -1, "PROPERTIES"); if (lua_isnil(L, -1) == 0) { lua_pushnil(L); // Look in the table for values to read from the section while (lua_next(L, -2)) { lua_pop(L, 1); const char* strKey = lua_tostring(L, -1); std::wstring wstrKey = ConvertToWide(strKey); const std::wstring& wstrValue = parser.ReadString(section, wstrKey.c_str(), L""); if (!wstrValue.empty()) { std::string strStrVal = ConvertToAscii(wstrValue.c_str()); const char* strValue = strStrVal.c_str(); lua_pushstring(L, strValue); lua_setfield(L, -3, strKey); } } } // Pop PROPERTIES table and our table lua_pop(L, 2); } else { DeleteLuaScript(); } } } else { LogWithArgs(LOG_ERROR, L"Script: File not valid in [%s]", m_Name.c_str()); DeleteLuaScript(); } }
/* WSLUA_ATTRIBUTE CaptureInfo_hosts WO Sets resolved ip-to-hostname information. The value set must be a Lua table of two key-ed names: `ipv4_addresses` and `ipv6_addresses`. The value of each of these names are themselves array tables, of key-ed tables, such that the inner table has a key `addr` set to the raw 4-byte or 16-byte IP address Lua string and a `name` set to the resolved name. For example, if the capture file identifies one resolved IPv4 address of 1.2.3.4 to `foo.com`, then you must set `CaptureInfo.hosts` to a table of: @code { ipv4_addresses = { { addr = "\01\02\03\04", name = "foo.com" } } } @endcode Note that either the `ipv4_addresses` or the `ipv6_addresses` table, or both, may be empty or nil. */ static int CaptureInfo_set_hosts(lua_State* L) { CaptureInfo fi = checkCaptureInfo(L,1); wtap *wth = fi->wth; const char *addr = NULL; const char *name = NULL; size_t addr_len = 0; size_t name_len = 0; guint32 v4_addr = 0; struct e_in6_addr v6_addr = { {0} }; if (!wth->add_new_ipv4 || !wth->add_new_ipv6) { return luaL_error(L, "CaptureInfo wtap has no IPv4 or IPv6 name resolution"); } if (!lua_istable(L,-1)) { return luaL_error(L, "CaptureInfo.host must be set to a table"); } /* get the ipv4_addresses table */ lua_getfield(L, -1, "ipv4_addresses"); if (lua_istable(L,-1)) { /* now walk the table */ lua_pushnil(L); /* first key */ while (lua_next(L, -2) != 0) { /* 'key' (at index -2) and 'value' (at index -1) */ if (!lua_istable(L,-1)) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses table does not contain a table"); } lua_getfield(L, -1, "addr"); if (!lua_isstring(L,-1)) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses table's table does not contain an 'addr' field"); } addr = luaL_checklstring(L,-1,&addr_len); if (addr_len != 4) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses 'addr' value is not 4 bytes long"); } memcpy(&v4_addr, addr, 4); lua_getfield(L, -1, "name"); if (!lua_isstring(L,-1)) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses table's table does not contain an 'addr' field"); } name = luaL_checklstring(L,-1,&name_len); wth->add_new_ipv4(v4_addr, name); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); } } /* wasn't a table, or it was and we walked it; either way pop it */ lua_pop(L,1); /* get the ipv6_addresses table */ lua_getfield(L, -1, "ip6_addresses"); if (lua_istable(L,-1)) { /* now walk the table */ lua_pushnil(L); /* first key */ while (lua_next(L, -2) != 0) { /* 'key' (at index -2) and 'value' (at index -1) */ if (!lua_istable(L,-1)) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses table does not contain a table"); } lua_getfield(L, -1, "addr"); if (!lua_isstring(L,-1)) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses table's table does not contain an 'addr' field"); } addr = luaL_checklstring(L,-1,&addr_len); if (addr_len != 16) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses 'addr' value is not 16 bytes long"); } memcpy(&v6_addr, addr, 16); lua_getfield(L, -1, "name"); if (!lua_isstring(L,-1)) { lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses table's table does not contain an 'addr' field"); } name = luaL_checklstring(L,-1,&name_len); wth->add_new_ipv6((const void *)(&v6_addr), name); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); } } /* wasn't a table, or it was and we walked it; either way pop it */ lua_pop(L,1); return 0; }
static int stream_readL(lua_State *L) { struct stream *stream; u8_t buf[1024]; u8_t *buf_ptr, *body_ptr; size_t header_len; ssize_t n; /* * 1: Stream (self) * 2: Playback (self) */ stream = lua_touserdata(L, 1); /* shortcut, just read to streambuf */ if (stream->num_crlf == 4) { n = streambuf_feed_fd(stream->fd, L); if (n == 0) { /* closed */ lua_pushboolean(L, FALSE); return 1; } if (n == -ENOSPC) { lua_pushinteger(L, 0); return 1; } if (n < 0) { CLOSESOCKET(stream->fd); lua_pushnil(L); lua_pushstring(L, strerror(n)); return 2; } lua_pushinteger(L, n); return 1; } /* read buffer, but we must not overflow the stream fifo */ n = streambuf_get_freebytes(); if (n > (ssize_t)sizeof(buf)) { n = sizeof(buf); } n = recv(stream->fd, buf, sizeof(buf), 0); /* socket closed */ if (n == 0) { lua_pushboolean(L, FALSE); return 1; } /* socket error */ if (n < 0) { // XXXX do we need to handle timeout here? CLOSESOCKET(stream->fd); lua_pushnil(L); lua_pushstring(L, strerror(SOCKETERROR)); return 2; } buf_ptr = buf; /* read http header */ if (stream->num_crlf < 4) { stream->body = realloc(stream->body, stream->body_len + n); body_ptr = stream->body + stream->body_len; stream->body_len += n; while (n) { *body_ptr++ = *buf_ptr; if (*buf_ptr == '\n' || *buf_ptr == '\r') { stream->num_crlf++; } else { stream->num_crlf = 0; } buf_ptr++; n--; if (stream->num_crlf == 4) { header_len = body_ptr - stream->body; //LOG_DEBUG(log_audio_decode, "headers %d %*s\n", header_len, header_len, stream->body); /* Send headers to SqueezeCenter */ lua_getfield(L, 2, "_streamHttpHeaders"); lua_pushvalue(L, 2); lua_pushlstring(L, (char *)stream->body, header_len); lua_call(L, 2, 0); /* do not free the header here - leave it to disconnect - * so that it can be used by the proxy code */ /* Send headers to proxy clients */ proxy_chunk(stream->body, header_len, L); break; } } } /* we need to loop when playing sound effects, so we need to remember where the stream starts */ streambuf_lptr = streambuf_fifo.wptr; /* feed remaining buffer */ streambuf_feedL(buf_ptr, n, L); lua_pushboolean(L, TRUE); return 1; }
void pprint(lua_State *L, struct luadebug_user *user, int index, bool full, const char *hide) { int h; LUA_STACK_MARK(L); lua_getglobal(L, "haka"); lua_getfield(L, -1, "debug"); h = lua_gettop(L); if (user) { lua_getfield(L, h, "__printwrapper"); lua_pushcfunction(L, lua_user_print); lua_pushlightuserdata(L, user); if (lua_pcall(L, 2, 1, 0)) { user->print(user, CLEAR RED "error: %s\n" CLEAR, lua_tostring(L, -1)); lua_settop(L, h-2); LUA_STACK_CHECK(L, 0); return; } } lua_getfield(L, h, "pprint"); /* obj */ if (index < 0) { lua_pushvalue(L, h-1+index); } else { lua_pushvalue(L, index); } /* indent */ lua_pushstring(L, " \t"); /* depth */ if (!full) { lua_pushnumber(L, 1); } else { lua_pushnil(L); } /* hide */ if (hide) { lua_getfield(L, h, "hide_underscore"); } else { lua_pushnil(L); } /* out */ if (user) { lua_pushvalue(L, h+1); } else { lua_pushnil(L); } if (lua_pcall(L, 5, 0, 0)) { user->print(user, CLEAR RED "error: %s\n" CLEAR, lua_tostring(L, -1)); lua_pop(L, 1); } lua_settop(L, h-2); LUA_STACK_CHECK(L, 0); }