From 0b3ff10e1d8d6e70423129fb9a729271f87d1f31 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 16 Feb 2009 17:37:14 +0000 Subject: [PATCH] Simplify the retrieval of script ids. Make get_id a method of struct thread_record. Pass that directly to ScritpResult::set_id. The function process_getScriptId is no longer needed. --- nse_main.cc | 59 +++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/nse_main.cc b/nse_main.cc index 039c0706a..cc6a4cb90 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -35,8 +35,23 @@ struct thread_record { unsigned int registry_idx; // index in the main state registry double runlevel; struct run_record rr; + std::string get_id(); }; +/* Gets the basename of a script filename and removes any ".nse" extension. */ +std::string thread_record::get_id() { + char *abbrev; + + abbrev = path_get_basename(filename.c_str()); + if (abbrev == NULL) + /* On memory error just return the whole filename. */ + return filename; + if (nse_check_extension(SCRIPT_ENGINE_EXTENSION, abbrev)) + abbrev[strlen(abbrev) - strlen(SCRIPT_ENGINE_EXTENSION)] = '\0'; + + return std::string(abbrev); +} + int current_hosts = 0; int errfunc = 0; std::list > torun_scripts; @@ -56,7 +71,6 @@ int process_preparehost(lua_State* L, Target* target, std::listset_id(filename); - } else { - sr->set_id(id); - free(id); - } - - return SCRIPT_ENGINE_SUCCESS; -} - /* try all host and all port rules against the * state of the current target * make a list with run records for the scripts