Coverage test fixes and whitespace/doc tweaks.

This commit is contained in:
Jon Siwek 2013-07-22 14:15:35 -05:00
parent ca5abbf13a
commit 325f0c2a3f
4 changed files with 42 additions and 40 deletions

View file

@ -164,9 +164,12 @@ rest_target(${psd} base/protocols/ssl/main.bro)
rest_target(${psd} base/protocols/ssl/mozilla-ca-list.bro)
rest_target(${psd} base/protocols/syslog/consts.bro)
rest_target(${psd} base/protocols/syslog/main.bro)
rest_target(${psd} base/utils/active-http.bro)
rest_target(${psd} base/utils/addrs.bro)
rest_target(${psd} base/utils/conn-ids.bro)
rest_target(${psd} base/utils/dir.bro)
rest_target(${psd} base/utils/directions-and-hosts.bro)
rest_target(${psd} base/utils/exec.bro)
rest_target(${psd} base/utils/files.bro)
rest_target(${psd} base/utils/numbers.bro)
rest_target(${psd} base/utils/paths.bro)

View file

@ -1,21 +1,21 @@
##! A module for performing active HTTP requests and
##! A module for performing active HTTP requests and
##! getting the reply at runtime.
@load ./exec
module ActiveHTTP;
export {
## The default timeout for HTTP requests.
const default_max_time = 1min &redef;
## The default HTTP method/verb to use for requests.
const default_method = "GET" &redef;
type Response: record {
type Response: record {
## Numeric response code from the server.
code: count;
## String response messgae from the server.
## String response message from the server.
msg: string;
## Full body of the response.
body: string &optional;
@ -29,24 +29,24 @@ export {
## The HTTP method/verb to use for the request.
method: string &default=default_method;
## Data to send to the server in the client body. Keep in
## mind that you will probably need to set the $method field
## mind that you will probably need to set the *method* field
## to "POST" or "PUT".
client_data: string &optional;
## Arbitrary headers to pass to the server. Some headers
## Arbitrary headers to pass to the server. Some headers
## will be included by libCurl.
#custom_headers: table[string] of string &optional;
## Timeout for the request.
max_time: interval &default=default_max_time;
## Additional curl command line arguments. Be very careful
## Additional curl command line arguments. Be very careful
## with this option since shell injection could take place
## if careful handling of untrusted data is not applied.
addl_curl_args: string &optional;
};
## Perform an HTTP request according to the :bro:type:`Request` record.
## This is an asynchronous function and must be called within a "when"
## This is an asynchronous function and must be called within a "when"
## statement.
##
##
## req: A record instance representing all options for an HTTP request.
##
## Returns: A record with the full response message.
@ -55,7 +55,7 @@ export {
function request2curl(r: Request, bodyfile: string, headersfile: string): string
{
local cmd = fmt("curl -s -g -o \"%s\" -D \"%s\" -X \"%s\"",
local cmd = fmt("curl -s -g -o \"%s\" -D \"%s\" -X \"%s\"",
str_shell_escape(bodyfile),
str_shell_escape(headersfile),
str_shell_escape(r$method));
@ -91,7 +91,7 @@ function request(req: Request): ActiveHTTP::Response
# If there is no response line then nothing else will work either.
if ( ! (result?$files && headersfile in result$files) )
Reporter::error(fmt("There was a failure when requesting \"%s\" with ActiveHTTP.", req$url));
local headers = result$files[headersfile];
for ( i in headers )
{

View file

@ -1,6 +1,4 @@
##! A module for executing external command line programs.
##! This requires code that is still in topic branches and
##! definitely won't currently work on any released version of Bro.
@load base/frameworks/input
@ -8,15 +6,13 @@ module Exec;
export {
type Command: record {
## The command line to execute.
## Use care to avoid injection attacks!
## The command line to execute. Use care to avoid injection attacks.
## I.e. if the command uses untrusted/variable data, sanitize it.
cmd: string;
## Provide standard in to the program as a
## string.
## Provide standard in to the program as a string.
stdin: string &default="";
## If additional files are required to be read
## in as part of the output of the command they
## can be defined here.
## If additional files are required to be read in as part of the output
## of the command they can be defined here.
read_files: set[string] &optional;
};
@ -27,7 +23,7 @@ export {
signal_exit: bool &default=F;
## Each line of standard out.
stdout: vector of string &optional;
## Each line of standard error.
## Each line of standard error.
stderr: vector of string &optional;
## If additional files were requested to be read in
## the content of the files will be available here.
@ -35,7 +31,7 @@ export {
};
## Function for running command line programs and getting
## output. This is an asynchronous function which is meant
## output. This is an asynchronous function which is meant
## to be run with the `when` statement.
##
## cmd: The command to run. Use care to avoid injection attacks!
@ -56,12 +52,12 @@ redef record Command += {
global results: table[string] of Result = table();
global finished_commands: set[string];
global currently_tracked_files: set[string] = set();
type OneLine: record {
type OneLine: record {
s: string;
is_stderr: bool;
};
type FileLine: record {
type FileLine: record {
s: string;
};
@ -93,7 +89,7 @@ event Exec::file_line(description: Input::EventDescription, tpe: Input::Event, s
local result = results[name];
if ( ! result?$files )
result$files = table();
if ( track_file !in result$files )
result$files[track_file] = vector(s);
else
@ -136,16 +132,16 @@ function run(cmd: Command): Result
}
}
local config_strings: table[string] of string = {
local config_strings: table[string] of string = {
["stdin"] = cmd$stdin,
["read_stderr"] = "1",
};
Input::add_event([$name=cmd$uid,
$source=fmt("%s |", cmd$cmd),
$reader=Input::READER_RAW,
$fields=Exec::OneLine,
$ev=Exec::line,
$want_record=F,
Input::add_event([$name=cmd$uid,
$source=fmt("%s |", cmd$cmd),
$reader=Input::READER_RAW,
$fields=Exec::OneLine,
$ev=Exec::line,
$want_record=F,
$config=config_strings]);
return when ( cmd$uid in finished_commands )
@ -164,4 +160,4 @@ event bro_done()
{
system(fmt("rm \"%s\"", str_shell_escape(fname)));
}
}
}

View file

@ -3,7 +3,7 @@
#empty_field (empty)
#unset_field -
#path loaded_scripts
#open 2013-07-10-21-18-31
#open 2013-07-22-16-01-22
#fields name
#types string
scripts/base/init-bare.bro
@ -90,12 +90,17 @@ scripts/base/init-bare.bro
scripts/base/init-default.bro
scripts/base/utils/site.bro
scripts/base/utils/patterns.bro
scripts/base/utils/active-http.bro
scripts/base/utils/exec.bro
scripts/base/utils/addrs.bro
scripts/base/utils/conn-ids.bro
scripts/base/utils/dir.bro
scripts/base/frameworks/reporter/__load__.bro
scripts/base/frameworks/reporter/main.bro
scripts/base/utils/paths.bro
scripts/base/utils/directions-and-hosts.bro
scripts/base/utils/files.bro
scripts/base/utils/numbers.bro
scripts/base/utils/paths.bro
scripts/base/utils/queue.bro
scripts/base/utils/strings.bro
scripts/base/utils/thresholds.bro
@ -129,8 +134,6 @@ scripts/base/init-default.bro
scripts/base/frameworks/intel/__load__.bro
scripts/base/frameworks/intel/main.bro
scripts/base/frameworks/intel/input.bro
scripts/base/frameworks/reporter/__load__.bro
scripts/base/frameworks/reporter/main.bro
scripts/base/frameworks/sumstats/__load__.bro
scripts/base/frameworks/sumstats/main.bro
scripts/base/frameworks/sumstats/plugins/__load__.bro
@ -195,4 +198,4 @@ scripts/base/init-default.bro
scripts/base/protocols/tunnels/__load__.bro
scripts/base/misc/find-checksum-offloading.bro
scripts/policy/misc/loaded-scripts.bro
#close 2013-07-10-21-18-31
#close 2013-07-22-16-01-22