mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The one place where we deviate is header include order since Zeek depends on headers being included in a certain order.
This commit is contained in:
parent
7b8e7ed72c
commit
f5a76c1aed
786 changed files with 131714 additions and 153609 deletions
|
@ -1,80 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#include "zeek/3rdparty/patricia.h"
|
||||
}
|
||||
}
|
||||
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
|
||||
#include "zeek/IPAddr.h"
|
||||
|
||||
namespace zeek
|
||||
{
|
||||
namespace zeek {
|
||||
|
||||
class Val;
|
||||
class SubNetVal;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
|
||||
class PrefixTable
|
||||
{
|
||||
class PrefixTable {
|
||||
private:
|
||||
struct iterator
|
||||
{
|
||||
patricia_node_t* Xstack[PATRICIA_MAXBITS + 1];
|
||||
patricia_node_t** Xsp;
|
||||
patricia_node_t* Xrn;
|
||||
patricia_node_t* Xnode;
|
||||
};
|
||||
struct iterator {
|
||||
patricia_node_t* Xstack[PATRICIA_MAXBITS + 1];
|
||||
patricia_node_t** Xsp;
|
||||
patricia_node_t* Xrn;
|
||||
patricia_node_t* Xnode;
|
||||
};
|
||||
|
||||
public:
|
||||
PrefixTable()
|
||||
{
|
||||
tree = New_Patricia(128);
|
||||
delete_function = nullptr;
|
||||
}
|
||||
~PrefixTable() { Destroy_Patricia(tree, delete_function); }
|
||||
PrefixTable() {
|
||||
tree = New_Patricia(128);
|
||||
delete_function = nullptr;
|
||||
}
|
||||
~PrefixTable() { Destroy_Patricia(tree, delete_function); }
|
||||
|
||||
// Addr in network byte order. If data is zero, acts like a set.
|
||||
// Returns ptr to old data if already existing.
|
||||
// For existing items without data, returns non-nil if found.
|
||||
void* Insert(const IPAddr& addr, int width, void* data = nullptr);
|
||||
// Addr in network byte order. If data is zero, acts like a set.
|
||||
// Returns ptr to old data if already existing.
|
||||
// For existing items without data, returns non-nil if found.
|
||||
void* Insert(const IPAddr& addr, int width, void* data = nullptr);
|
||||
|
||||
// Value may be addr or subnet.
|
||||
void* Insert(const Val* value, void* data = nullptr);
|
||||
// Value may be addr or subnet.
|
||||
void* Insert(const Val* value, void* data = nullptr);
|
||||
|
||||
// Returns nil if not found, pointer to data otherwise.
|
||||
// For items without data, returns non-nil if found.
|
||||
// If exact is false, performs exact rather than longest-prefix match.
|
||||
void* Lookup(const IPAddr& addr, int width, bool exact = false) const;
|
||||
void* Lookup(const Val* value, bool exact = false) const;
|
||||
// Returns nil if not found, pointer to data otherwise.
|
||||
// For items without data, returns non-nil if found.
|
||||
// If exact is false, performs exact rather than longest-prefix match.
|
||||
void* Lookup(const IPAddr& addr, int width, bool exact = false) const;
|
||||
void* Lookup(const Val* value, bool exact = false) const;
|
||||
|
||||
// Returns list of all found matches or empty list otherwise.
|
||||
std::list<std::tuple<IPPrefix, void*>> FindAll(const IPAddr& addr, int width) const;
|
||||
std::list<std::tuple<IPPrefix, void*>> FindAll(const SubNetVal* value) const;
|
||||
// Returns list of all found matches or empty list otherwise.
|
||||
std::list<std::tuple<IPPrefix, void*>> FindAll(const IPAddr& addr, int width) const;
|
||||
std::list<std::tuple<IPPrefix, void*>> FindAll(const SubNetVal* value) const;
|
||||
|
||||
// Returns pointer to data or nil if not found.
|
||||
void* Remove(const IPAddr& addr, int width);
|
||||
void* Remove(const Val* value);
|
||||
// Returns pointer to data or nil if not found.
|
||||
void* Remove(const IPAddr& addr, int width);
|
||||
void* Remove(const Val* value);
|
||||
|
||||
void Clear() { Clear_Patricia(tree, delete_function); }
|
||||
void Clear() { Clear_Patricia(tree, delete_function); }
|
||||
|
||||
// Sets a function to call for each node when table is cleared/destroyed.
|
||||
void SetDeleteFunction(data_fn_t del_fn) { delete_function = del_fn; }
|
||||
// Sets a function to call for each node when table is cleared/destroyed.
|
||||
void SetDeleteFunction(data_fn_t del_fn) { delete_function = del_fn; }
|
||||
|
||||
iterator InitIterator();
|
||||
void* GetNext(iterator* i);
|
||||
iterator InitIterator();
|
||||
void* GetNext(iterator* i);
|
||||
|
||||
private:
|
||||
static prefix_t* MakePrefix(const IPAddr& addr, int width);
|
||||
static IPPrefix PrefixToIPPrefix(prefix_t* p);
|
||||
static prefix_t* MakePrefix(const IPAddr& addr, int width);
|
||||
static IPPrefix PrefixToIPPrefix(prefix_t* p);
|
||||
|
||||
patricia_tree_t* tree;
|
||||
data_fn_t delete_function;
|
||||
};
|
||||
patricia_tree_t* tree;
|
||||
data_fn_t delete_function;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace zeek
|
||||
} // namespace detail
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue