From c9050b110457266488c3b51a38029138da2281aa Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 20 May 2019 17:28:25 +0100 Subject: Added custom pattern detector and extractor from buffer --- buf_misc.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'buf_misc.c') diff --git a/buf_misc.c b/buf_misc.c index d3c540e..386be72 100644 --- a/buf_misc.c +++ b/buf_misc.c @@ -64,7 +64,7 @@ BufLine::BufLine(int size) BufLine::~BufLine() { - + delete buf; } int BufLine::setpattern(char *pattern) @@ -107,6 +107,28 @@ int BufLine::print() return -1; } +/* +RETURN_IF_PATTERN_FOUND(*detect_pattern)(char *INPUT_BUFFER, int INPUT_SIZE) +*/ +int BufLine::pop_pattern(int (*detect_pattern)(char *, int, int*), char **val, int *size) +{ + int detected=0; + + char *buf; + int buf_size = 0; + int data_size = 0; + + this->buf->get_ptr(&buf, &buf_size); + if ((detected = detect_pattern(buf, buf_size, &data_size)) != 1) + { + return -1; + } + + this->buf->popsubstring(data_size, val, size); + + return 0; +} + /* int bbuf_circ_new(bbuf_circ **circ, int size) { -- cgit v1.2.3