Skip to content

Commit

Permalink
Factor out XML script result writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Aug 2, 2012
1 parent 54fa9ec commit 3f415ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 8 additions & 0 deletions nse_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ ScriptResults *get_script_scan_results_obj (void)
return &script_scan_results;
}

void ScriptResult::write_xml() const
{
xml_open_start_tag("script");
xml_attribute("id", "%s", get_id());
xml_attribute("output", "%s", get_output());
xml_close_empty_tag();
}

/* int panic (lua_State *L)
*
* Panic function set via lua_atpanic().
Expand Down
1 change: 1 addition & 0 deletions nse_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ScriptResult
const char *get_output (void) const;
void set_id (const char *);
const char *get_id (void) const;
void write_xml() const;
};

typedef std::list<ScriptResult> ScriptResults;
Expand Down
17 changes: 5 additions & 12 deletions output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,7 @@ void printportoutput(Target *currenths, PortList *plist) {
current->scriptResults.sort(comparescriptids);
for (ssr_iter = current->scriptResults.begin();
ssr_iter != current->scriptResults.end(); ssr_iter++) {
xml_open_start_tag("script");
xml_attribute("id", "%s", ssr_iter->get_id());
xml_attribute("output", "%s", ssr_iter->get_output());
xml_close_empty_tag();
ssr_iter->write_xml();

char *script_output = formatScriptOutput((*ssr_iter));
Tbl->addItem(rowno, 0, true, true, script_output);
Expand Down Expand Up @@ -2198,10 +2195,8 @@ void printscriptresults(ScriptResults *scriptResults, stype scantype) {
for (iter = scriptResults->begin();
iter != scriptResults->end();
iter++) {
xml_open_start_tag("script");
xml_attribute("id", "%s", iter->get_id());
xml_attribute("output", "%s", iter->get_output());
xml_close_empty_tag();
iter->write_xml();

script_output = formatScriptOutput((*iter));
log_write(LOG_PLAIN, "%s\n", script_output);
free(script_output);
Expand All @@ -2222,10 +2217,8 @@ void printhostscriptresults(Target *currenths) {
for (iter = currenths->scriptResults.begin();
iter != currenths->scriptResults.end();
iter++) {
xml_open_start_tag("script");
xml_attribute("id", "%s", iter->get_id());
xml_attribute("output", "%s", iter->get_output());
xml_close_empty_tag();
iter->write_xml();

script_output = formatScriptOutput((*iter));
log_write(LOG_PLAIN, "%s\n", script_output);
free(script_output);
Expand Down

0 comments on commit 3f415ef

Please sign in to comment.