mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
binpac: Add pre-commit hooks and run clang-format on everything
This commit is contained in:
parent
090ac0a6e0
commit
090325df40
91 changed files with 3086 additions and 3665 deletions
|
@ -2,24 +2,29 @@
|
|||
#define binpac_buffer_h
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "binpac.h"
|
||||
|
||||
namespace binpac {
|
||||
namespace binpac
|
||||
{
|
||||
|
||||
class FlowBuffer {
|
||||
class FlowBuffer
|
||||
{
|
||||
public:
|
||||
struct Policy {
|
||||
struct Policy
|
||||
{
|
||||
int max_capacity;
|
||||
int min_capacity;
|
||||
int contract_threshold;
|
||||
};
|
||||
};
|
||||
|
||||
enum LineBreakStyle {
|
||||
CR_OR_LF, // CR or LF or CRLF
|
||||
STRICT_CRLF, // CR followed by LF
|
||||
CR_LF_NUL, // CR or LF or CR-LF or CR-NUL
|
||||
LINE_BREAKER, // User specified linebreaker
|
||||
};
|
||||
enum LineBreakStyle
|
||||
{
|
||||
CR_OR_LF, // CR or LF or CRLF
|
||||
STRICT_CRLF, // CR followed by LF
|
||||
CR_LF_NUL, // CR or LF or CR-LF or CR-NUL
|
||||
LINE_BREAKER, // User specified linebreaker
|
||||
};
|
||||
|
||||
FlowBuffer(LineBreakStyle linebreak_style = CR_OR_LF);
|
||||
virtual ~FlowBuffer();
|
||||
|
@ -39,13 +44,12 @@ public:
|
|||
void DiscardData();
|
||||
|
||||
// Whether there is enough data for the frame
|
||||
bool ready() const{ return message_complete_ || mode_ == UNKNOWN_MODE; }
|
||||
bool ready() const { return message_complete_ || mode_ == UNKNOWN_MODE; }
|
||||
|
||||
inline const_byteptr begin() const
|
||||
{
|
||||
BINPAC_ASSERT(ready());
|
||||
return ( buffer_n_ == 0 ) ?
|
||||
orig_data_begin_ : buffer_;
|
||||
return (buffer_n_ == 0) ? orig_data_begin_ : buffer_;
|
||||
}
|
||||
|
||||
inline const_byteptr end() const
|
||||
|
@ -64,18 +68,17 @@ public:
|
|||
|
||||
inline int data_length() const
|
||||
{
|
||||
if ( buffer_n_ > 0 )
|
||||
if ( buffer_n_ > 0 )
|
||||
return buffer_n_;
|
||||
|
||||
if ( frame_length_ < 0 ||
|
||||
orig_data_begin_ + frame_length_ > orig_data_end_ )
|
||||
if ( frame_length_ < 0 || orig_data_begin_ + frame_length_ > orig_data_end_ )
|
||||
return orig_data_end_ - orig_data_begin_;
|
||||
else
|
||||
return frame_length_;
|
||||
}
|
||||
|
||||
inline bool data_available() const
|
||||
{
|
||||
{
|
||||
return buffer_n_ > 0 || orig_data_end_ > orig_data_begin_;
|
||||
}
|
||||
|
||||
|
@ -87,22 +90,20 @@ public:
|
|||
void GrowFrame(int new_frame_length);
|
||||
|
||||
int data_seq() const
|
||||
{
|
||||
int data_seq_at_orig_data_begin =
|
||||
data_seq_at_orig_data_end_ -
|
||||
(orig_data_end_ - orig_data_begin_);
|
||||
{
|
||||
int data_seq_at_orig_data_begin = data_seq_at_orig_data_end_ -
|
||||
(orig_data_end_ - orig_data_begin_);
|
||||
if ( buffer_n_ > 0 )
|
||||
return data_seq_at_orig_data_begin;
|
||||
else
|
||||
return data_seq_at_orig_data_begin + data_length();
|
||||
return data_seq_at_orig_data_begin + data_length();
|
||||
}
|
||||
bool eof() const { return eof_; }
|
||||
bool eof() const { return eof_; }
|
||||
void set_eof();
|
||||
|
||||
bool have_pending_request() const { return have_pending_request_; }
|
||||
|
||||
static void init(Policy p)
|
||||
{ policy = p; }
|
||||
static void init(Policy p) { policy = p; }
|
||||
|
||||
protected:
|
||||
// Reset the buffer for a new message
|
||||
|
@ -110,7 +111,7 @@ protected:
|
|||
|
||||
void ClearPreviousData();
|
||||
|
||||
// Expand the buffer to at least <length> bytes. If there
|
||||
// Expand the buffer to at least <length> bytes. If there
|
||||
// are contents in the existing buffer, copy them to the new
|
||||
// buffer.
|
||||
void ExpandBuffer(int length);
|
||||
|
@ -128,8 +129,8 @@ protected:
|
|||
void AppendToBuffer(const_byteptr data, int len);
|
||||
|
||||
// MarkOrCopy{Line,Frame} sets message_complete_ and
|
||||
// marks begin/end pointers if a line/frame is complete,
|
||||
// otherwise it clears message_complete_ and copies all
|
||||
// marks begin/end pointers if a line/frame is complete,
|
||||
// otherwise it clears message_complete_ and copies all
|
||||
// the original data to the buffer.
|
||||
//
|
||||
void MarkOrCopy();
|
||||
|
@ -140,41 +141,43 @@ protected:
|
|||
void MarkOrCopyLine_STRICT_CRLF();
|
||||
void MarkOrCopyLine_LINEBREAK();
|
||||
|
||||
int buffer_n_; // number of bytes in the buffer
|
||||
int buffer_length_; // size of the buffer
|
||||
int buffer_n_; // number of bytes in the buffer
|
||||
int buffer_length_; // size of the buffer
|
||||
unsigned char* buffer_;
|
||||
bool message_complete_;
|
||||
int frame_length_;
|
||||
bool chunked_;
|
||||
bool message_complete_;
|
||||
int frame_length_;
|
||||
bool chunked_;
|
||||
const_byteptr orig_data_begin_, orig_data_end_;
|
||||
|
||||
LineBreakStyle linebreak_style_;
|
||||
LineBreakStyle linebreak_style_default;
|
||||
unsigned char linebreaker_;
|
||||
unsigned char linebreaker_;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
UNKNOWN_MODE,
|
||||
LINE_MODE,
|
||||
FRAME_MODE,
|
||||
} mode_;
|
||||
} mode_;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
CR_OR_LF_0,
|
||||
CR_OR_LF_1,
|
||||
STRICT_CRLF_0,
|
||||
STRICT_CRLF_1,
|
||||
FRAME_0,
|
||||
} state_;
|
||||
} state_;
|
||||
|
||||
int data_seq_at_orig_data_end_;
|
||||
bool eof_;
|
||||
bool have_pending_request_;
|
||||
int data_seq_at_orig_data_end_;
|
||||
bool eof_;
|
||||
bool have_pending_request_;
|
||||
|
||||
static Policy policy;
|
||||
};
|
||||
};
|
||||
|
||||
typedef FlowBuffer *flow_buffer_t;
|
||||
typedef FlowBuffer* flow_buffer_t;
|
||||
|
||||
} // namespace binpac
|
||||
} // namespace binpac
|
||||
|
||||
#endif // binpac_buffer_h
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue