Reformat the world

This commit is contained in:
Tim Wojtulewicz 2021-09-16 15:35:39 -07:00
parent 194cb24547
commit b2f171ec69
714 changed files with 35149 additions and 35203 deletions

View file

@ -14,39 +14,37 @@
#define __STDC_LIMIT_MACROS
#endif
#include <libgen.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <libgen.h>
#include <array>
#include <cinttypes>
#include <cstdint>
#include <memory> // std::unique_ptr
#include <string>
#include <string_view>
#include <array>
#include <vector>
#include <memory> // std::unique_ptr
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#include <sys/time.h>
#include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#ifdef DEBUG
#include <assert.h>
#define ASSERT(x) assert(x)
#define DEBUG_MSG(x...) fprintf(stderr, x)
#define DEBUG_fputs fputs
#define ASSERT(x) assert(x)
#define DEBUG_MSG(x...) fprintf(stderr, x)
#define DEBUG_fputs fputs
#else
@ -74,7 +72,7 @@ extern HeapLeakChecker* heap_checker;
extern "C"
{
#include "zeek/modp_numtoa.h"
#include "zeek/modp_numtoa.h"
}
using bro_int_t = int64_t;
@ -87,13 +85,16 @@ extern char* strcasestr(const char* s, const char* find);
// This is used by the patricia code and so it remains outside of hte namespace.
extern "C" void out_of_memory(const char* where);
namespace zeek {
namespace zeek
{
class ODesc;
class RecordVal;
namespace util {
namespace detail {
namespace util
{
namespace detail
{
std::string extract_ip(const std::string& i);
std::string extract_ip_and_len(const std::string& i, int* len);
@ -106,18 +107,16 @@ extern int expand_escape(const char*& s);
extern const char* fmt_access_time(double time);
extern bool ensure_intermediate_dirs(const char* dirname);
extern bool ensure_dir(const char *dirname);
extern bool ensure_dir(const char* dirname);
extern void hmac_md5(size_t size, const unsigned char* bytes,
unsigned char digest[16]);
extern void hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16]);
// Initializes RNGs for zeek::random_number() and MD5 usage. If load_file is given,
// the seeds (both random & MD5) are loaded from that file. This takes
// precedence over the "use_empty_seeds" argument, which just
// zero-initializes all seed values. If write_file is given, the seeds are
// written to that file.
extern void init_random_seed(const char* load_file, const char* write_file,
bool use_empty_seeds);
extern void init_random_seed(const char* load_file, const char* write_file, bool use_empty_seeds);
// Retrieves the initial seed computed after the very first call to
// init_random_seed(). Repeated calls to init_random_seed() will not affect
@ -195,21 +194,17 @@ extern void add_to_zeek_path(const std::string& dir);
* Wrapper class for functions like dirname(3) or basename(3) that won't
* modify the path argument and may optionally abort execution on error.
*/
class SafePathOp {
class SafePathOp
{
public:
std::string result;
bool error;
protected:
SafePathOp()
: result(), error()
{ }
SafePathOp() : result(), error() { }
void CheckValid(const char* result, const char* path, bool error_aborts);
};
};
/**
* Flatten a script name by replacing '/' path separators with '.'.
@ -218,8 +213,7 @@ protected:
* @param prefix A string to prepend to the flattened script name.
* @return The flattened script name.
*/
std::string flatten_script_name(const std::string& name,
const std::string& prefix = "");
std::string flatten_script_name(const std::string& name, const std::string& prefix = "");
/**
* Return a canonical/shortened path string by removing superfluous elements
@ -286,10 +280,9 @@ double parse_rotate_base_time(const char* rotate_base_time);
// This function is thread-safe.
double calc_next_rotate(double current, double rotate_interval, double base);
} // namespace detail
} // namespace detail
template <class T>
void delete_each(T* t)
template <class T> void delete_each(T* t)
{
typedef typename T::iterator iterator;
for ( iterator it = t->begin(); it != t->end(); ++it )
@ -305,8 +298,7 @@ inline void bytetohex(unsigned char byte, char* hex_out)
std::string get_unescaped_string(const std::string& str);
ODesc* get_escaped_string(ODesc* d, const char* str, size_t len,
bool escape_all);
ODesc* get_escaped_string(ODesc* d, const char* str, size_t len, bool escape_all);
std::string get_escaped_string(const char* str, size_t len, bool escape_all);
inline std::string get_escaped_string(const std::string& str, bool escape_all)
@ -314,9 +306,8 @@ inline std::string get_escaped_string(const std::string& str, bool escape_all)
return get_escaped_string(str.data(), str.length(), escape_all);
}
std::vector<std::string>* tokenize_string(std::string_view input,
std::string_view delim,
std::vector<std::string>* rval = nullptr, int limit = 0);
std::vector<std::string>* tokenize_string(std::string_view input, std::string_view delim,
std::vector<std::string>* rval = nullptr, int limit = 0);
std::vector<std::string_view> tokenize_string(std::string_view input, const char delim) noexcept;
@ -336,11 +327,11 @@ extern void to_upper(char* s);
extern std::string to_upper(const std::string& s);
extern int decode_hex(char ch);
extern unsigned char encode_hex(int h);
template<class T> int atoi_n(int len, const char* s, const char** end, int base, T& result);
extern char* uitoa_n(uint64_t value, char* str, int n, int base, const char* prefix=nullptr);
template <class T> int atoi_n(int len, const char* s, const char** end, int base, T& result);
extern char* uitoa_n(uint64_t value, char* str, int n, int base, const char* prefix = nullptr);
extern const char* strpbrk_n(size_t len, const char* s, const char* charset);
int strstr_n(const int big_len, const unsigned char* big,
const int little_len, const unsigned char* little);
int strstr_n(const int big_len, const unsigned char* big, const int little_len,
const unsigned char* little);
// Replaces all occurences of *o* in *s* with *n*.
extern std::string strreplace(const std::string& s, const std::string& o, const std::string& n);
@ -359,8 +350,7 @@ extern const char* fmt_bytes(const char* data, int len);
// Note: returns a pointer into a shared buffer.
extern const char* vfmt(const char* format, va_list args);
// Note: returns a pointer into a shared buffer.
extern const char* fmt(const char* format, ...)
__attribute__((format (printf, 1, 2)));
extern const char* fmt(const char* format, ...) __attribute__((format(printf, 1, 2)));
// Returns true if path exists and is a directory.
bool is_dir(const std::string& path);
@ -375,27 +365,25 @@ extern const char* zeek_plugin_path();
extern const char* zeek_plugin_activate();
extern std::string zeek_prefixes();
class SafeDirname : public detail::SafePathOp {
class SafeDirname : public detail::SafePathOp
{
public:
explicit SafeDirname(const char* path, bool error_aborts = true);
explicit SafeDirname(const std::string& path, bool error_aborts = true);
private:
void DoFunc(const std::string& path, bool error_aborts = true);
};
};
class SafeBasename : public detail::SafePathOp {
class SafeBasename : public detail::SafePathOp
{
public:
explicit SafeBasename(const char* path, bool error_aborts = true);
explicit SafeBasename(const std::string& path, bool error_aborts = true);
private:
void DoFunc(const std::string& path, bool error_aborts = true);
};
};
std::string implode_string_vector(const std::vector<std::string>& v,
const std::string& delim = "\n");
@ -425,7 +413,7 @@ FILE* open_file(const std::string& path, const std::string& mode = "r");
// (In pseudo-realtime mode this is faked to be the start time of the
// trace plus the time interval Zeek has been running. To avoid this,
// call with real=true).
extern double current_time(bool real=false);
extern double current_time(bool real = false);
// Convert a time represented as a double to a timeval struct.
extern struct timeval double_to_timeval(double t);
@ -438,31 +426,29 @@ extern int time_compare(struct timeval* tv_a, struct timeval* tv_b);
// when the random number generator is seeded to be deterministic. In that
// case, the same sequence of integers is generated per pool.
#define UID_POOL_DEFAULT_INTERNAL 1
#define UID_POOL_DEFAULT_SCRIPT 2
#define UID_POOL_CUSTOM_SCRIPT 10 // First available custom script level pool.
#define UID_POOL_DEFAULT_SCRIPT 2
#define UID_POOL_CUSTOM_SCRIPT 10 // First available custom script level pool.
extern uint64_t calculate_unique_id();
extern uint64_t calculate_unique_id(const size_t pool);
// Use for map's string keys.
struct ltstr {
bool operator()(const char* s1, const char* s2) const
struct ltstr
{
return strcmp(s1, s2) < 0;
}
};
bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; }
};
constexpr size_t pad_size(size_t size)
{
// We emulate glibc here (values measured on Linux i386).
// FIXME: We should better copy the portable value definitions from glibc.
if ( size == 0 )
return 0; // glibc allocated 16 bytes anyway.
return 0; // glibc allocated 16 bytes anyway.
const int pad = 8;
if ( size < 12 )
return 2 * pad;
return ((size+3) / pad + 1) * pad;
return ((size + 3) / pad + 1) * pad;
}
#define padded_sizeof(x) (zeek::util::pad_size(sizeof(x)))
@ -473,8 +459,7 @@ constexpr size_t pad_size(size_t size)
extern bool safe_write(int fd, const char* data, int len);
// Same as safe_write(), but for pwrite().
extern bool safe_pwrite(int fd, const unsigned char* data, size_t len,
size_t offset);
extern bool safe_pwrite(int fd, const unsigned char* data, size_t len, size_t offset);
// Wraps close(2) to emit error messages and abort on unrecoverable errors.
extern void safe_close(int fd);
@ -503,8 +488,8 @@ inline void* safe_malloc(size_t size)
inline char* safe_strncpy(char* dest, const char* src, size_t n)
{
char* result = strncpy(dest, src, n-1);
dest[n-1] = '\0';
char* result = strncpy(dest, src, n - 1);
dest[n - 1] = '\0';
return result;
}
@ -517,10 +502,7 @@ extern void get_memory_usage(uint64_t* total, uint64_t* malloced);
// the actual string values.
struct CompareString
{
bool operator()(char const *a, char const *b) const
{
return strcmp(a, b) < 0;
}
bool operator()(char const* a, char const* b) const { return strcmp(a, b) < 0; }
};
/**
@ -541,8 +523,7 @@ void zeek_strerror_r(int zeek_errno, char* buf, size_t buflen);
* A wrapper function for getenv(). Helps check for existence of
* legacy environment variable names that map to the latest \a name.
*/
[[deprecated("Remove in v5.1. Use getenv() directly.")]]
char* zeekenv(const char* name);
[[deprecated("Remove in v5.1. Use getenv() directly.")]] char* zeekenv(const char* name);
/**
* Escapes bytes in a string that are not valid UTF8 characters with \xYY format. Used
@ -550,7 +531,7 @@ char* zeekenv(const char* name);
* @param val the input string to be escaped
* @return the escaped string
*/
std::string json_escape_utf8(const std::string& val, bool escape_printable_controls=true);
std::string json_escape_utf8(const std::string& val, bool escape_printable_controls = true);
/**
* Escapes bytes in a string that are not valid UTF8 characters with \xYY format. Used
@ -559,7 +540,8 @@ std::string json_escape_utf8(const std::string& val, bool escape_printable_contr
* @param val_size the length of the character data
* @return the escaped string
*/
std::string json_escape_utf8(const char* val, size_t val_size, bool escape_printable_controls=true);
std::string json_escape_utf8(const char* val, size_t val_size,
bool escape_printable_controls = true);
} // namespace util
} // namespace zeek
} // namespace util
} // namespace zeek