Merge remote-tracking branch 'origin/master' into topic/robin/pktsrc

Conflicts:
	configure
	src/CMakeLists.txt
	src/Net.cc
	src/PacketSort.cc
	src/PacketSort.h
	src/RemoteSerializer.cc
	src/Sessions.cc
	src/Sessions.h
This commit is contained in:
Robin Sommer 2014-08-22 15:38:24 -07:00
commit bf6dd2e9ca
794 changed files with 119018 additions and 91558 deletions

View file

@ -121,31 +121,41 @@ std::string get_unescaped_string(const std::string& arg_str)
* Takes a string, escapes characters into equivalent hex codes (\x##), and
* returns a string containing all escaped values.
*
* @param d an ODesc object to store the escaped hex version of the string,
* if null one will be allocated and returned from the function.
* @param str string to escape
* @param escape_all If true, all characters are escaped. If false, only
* characters are escaped that are either whitespace or not printable in
* ASCII.
* @return A std::string containing a list of escaped hex values of the form
* \x## */
std::string get_escaped_string(const std::string& str, bool escape_all)
* @return A ODesc object containing a list of escaped hex values of the form
* \x##, which may be newly allocated if \a d was a null pointer. */
ODesc* get_escaped_string(ODesc* d, const char* str, size_t len,
bool escape_all)
{
char tbuf[16];
string esc = "";
if ( ! d )
d = new ODesc();
for ( size_t i = 0; i < str.length(); ++i )
for ( size_t i = 0; i < len; ++i )
{
char c = str[i];
if ( escape_all || isspace(c) || ! isascii(c) || ! isprint(c) )
{
snprintf(tbuf, sizeof(tbuf), "\\x%02x", str[i]);
esc += tbuf;
char hex[4] = {'\\', 'x', '0', '0' };
bytetohex(c, hex + 2);
d->AddRaw(hex, 4);
}
else
esc += c;
d->AddRaw(&c, 1);
}
return esc;
return d;
}
std::string get_escaped_string(const char* str, size_t len, bool escape_all)
{
ODesc d;
return get_escaped_string(&d, str, len, escape_all)->Description();
}
char* copy_string(const char* s)
@ -559,7 +569,7 @@ const char* fmt(const char* format, ...)
static unsigned int buf_len = 1024;
if ( ! buf )
buf = (char*) malloc(buf_len);
buf = (char*) safe_malloc(buf_len);
va_list al;
va_start(al, format);
@ -569,7 +579,7 @@ const char* fmt(const char* format, ...)
if ( (unsigned int) n >= buf_len )
{ // Not enough room, grow the buffer.
buf_len = n + 32;
buf = (char*) realloc(buf, buf_len);
buf = (char*) safe_realloc(buf, buf_len);
// Is it portable to restart?
va_start(al, format);
@ -965,16 +975,6 @@ extern void add_to_bro_path(const string& dir)
bro_path_value += string(":") + dir;
}
const char* bro_magic_path()
{
const char* path = getenv("BROMAGIC");
if ( ! path )
path = BRO_MAGIC_INSTALL_PATH;
return path;
}
const char* bro_plugin_path()
{
const char* path = getenv("BRO_PLUGIN_PATH");
@ -985,6 +985,16 @@ const char* bro_plugin_path()
return path;
}
const char* bro_plugin_activate()
{
const char* names = getenv("BRO_PLUGIN_ACTIVATE");
if ( ! names )
names = "";
return names;
}
string bro_prefixes()
{
string rval;
@ -1619,7 +1629,6 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
unsigned int ret_total;
#ifdef HAVE_MALLINFO
// For memory, getrusage() gives bogus results on Linux. Grmpf.
struct mallinfo mi = mallinfo();
if ( malloced )
@ -1630,7 +1639,7 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
struct rusage r;
getrusage(RUSAGE_SELF, &r);
// At least on FreeBSD it's in KB.
// In KB.
ret_total = r.ru_maxrss * 1024;
if ( total )
@ -1706,45 +1715,6 @@ void operator delete[](void* v)
#endif
void bro_init_magic(magic_t* cookie_ptr, int flags)
{
if ( ! cookie_ptr || *cookie_ptr )
return;
*cookie_ptr = magic_open(flags);
// Always use Bro's custom magic database.
const char* database = bro_magic_path();
if ( ! *cookie_ptr )
{
const char* err = magic_error(*cookie_ptr);
reporter->InternalError("can't init libmagic: %s",
err ? err : "unknown");
}
else if ( magic_load(*cookie_ptr, database) < 0 )
{
const char* err = magic_error(*cookie_ptr);
reporter->InternalError("can't load magic file %s: %s", database,
err ? err : "unknown");
magic_close(*cookie_ptr);
*cookie_ptr = 0;
}
}
const char* bro_magic_buffer(magic_t cookie, const void* buffer, size_t length)
{
const char* rval = magic_buffer(cookie, buffer, length);
if ( ! rval )
{
const char* err = magic_error(cookie);
reporter->Error("magic_buffer error: %s", err ? err : "unknown");
}
return rval;
}
std::string canonify_name(const std::string& name)
{
unsigned int len = name.size();