1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

[NSE] Patch to move the call NSE_SELECTED_BY_NAME to nse_main.cc for

improved locality. Other Lua Registry functions called by C were wrapped in
a C API inside nse_main.cc.
This commit is contained in:
batrick
2009-07-14 22:41:25 +00:00
parent ad10a7c672
commit 01c25ab29e
3 changed files with 11 additions and 13 deletions

View File

@@ -28,6 +28,7 @@
#define NSE_BASE "NSE_BASE"
#define NSE_WAITING_TO_RUNNING "NSE_WAITING_TO_RUNNING"
#define NSE_DESTRUCTOR "NSE_DESTRUCTOR"
#define NSE_SELECTED_BY_NAME "NSE_SELECTED_BY_NAME"
#define MAX_FILENAME_LEN 4096
@@ -529,6 +530,12 @@ void nse_base (lua_State *L)
lua_call(L, 0, 1); /* returns base thread */
}
void nse_selectedbyname (lua_State *L)
{
lua_getfield(L, LUA_REGISTRYINDEX, NSE_SELECTED_BY_NAME);
lua_call(L, 0, 1); /* returns boolean, whether script was selected by name */
}
static lua_State *L_NSE = NULL;
void open_nse (void)

View File

@@ -35,6 +35,7 @@ int nse_yield (lua_State *);
void nse_restore (lua_State *, int);
void nse_destructor (lua_State *, char);
void nse_base (lua_State *);
void nse_selectedbyname (lua_State *);
void open_nse (void);
void script_scan (std::vector<Target *> &targets);

View File

@@ -21,9 +21,6 @@ extern "C" {
#include "nse_nmaplib.h"
#include "nse_nsock.h"
/* This is used to index the registry in nse_main.lua. */
#define NSE_SELECTED_BY_NAME "NSE_SELECTED_BY_NAME"
#define SCRIPT_ENGINE_PUSHSTRING_NOTNULL(c_str, str) if(c_str != NULL) {\
lua_pushstring(L, c_str); \
lua_setfield(L, -2, str); \
@@ -524,16 +521,9 @@ static int l_get_verbosity (lua_State *L)
int verbosity;
verbosity = o.verbose;
/* Call the SELECTED_BY_NAME function in nse_main.lua. When a script is
selected by name, we lie to it and say the verbosity is one higher than it
really is. */
lua_getfield(L, LUA_REGISTRYINDEX, NSE_SELECTED_BY_NAME);
if (!lua_isnil(L, -1)) {
lua_call(L, 0, 1);
if (lua_toboolean(L, -1))
verbosity += 1;
}
lua_pop(L, 1);
/* Check if script is selected by name. When a script is selected by name,
we lie to it and say the verbosity is one higher than it really is. */
verbosity += (nse_selectedbyname(L), lua_toboolean(L, -1) ? 1 : 0);
lua_pushnumber(L, verbosity);
return 1;