1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*  Fluent Bit
4  *  ==========
5  *  Copyright (C) 2019-2021 The Fluent Bit Authors
6  *  Copyright (C) 2015-2018 Treasure Data Inc.
7  *
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  */
20 
21 #ifndef FLB_REGEX_H
22 #define FLB_REGEX_H
23 
24 #include <fluent-bit/flb_info.h>
25 
26 #ifdef FLB_HAVE_REGEX
27 
28 #include <fluent-bit/flb_compat.h>
29 
30 #include <stdlib.h>
31 #include <stddef.h>
32 
33 struct flb_regex {
34     void *regex;
35 };
36 
37 struct flb_regex_search {
38     int last_pos;
39     void *region;
40     const char *str;
41     void (*cb_match) (const char *,          /* name  */
42                       const char *, size_t,  /* value */
43                       void *);                  /* caller data */
44     void *data;
45 };
46 
47 int flb_regex_init();
48 struct flb_regex *flb_regex_create(const char *pattern);
49 ssize_t flb_regex_do(struct flb_regex *r, const char *str, size_t slen,
50                      struct flb_regex_search *result);
51 
52 int flb_regex_match(struct flb_regex *r, unsigned char *str, size_t slen);
53 
54 int flb_regex_parse(struct flb_regex *r, struct flb_regex_search *result,
55                     void (*cb_match) (const char *,          /* name  */
56                                       const char *, size_t,  /* value */
57                                       void *),                  /* caller data */
58                     void *data);
59 int flb_regex_destroy(struct flb_regex *r);
60 int flb_regex_results_get(struct flb_regex_search *result, int i,
61                           ptrdiff_t *start, ptrdiff_t *end);
62 void flb_regex_results_release(struct flb_regex_search *result);
63 int flb_regex_results_size(struct flb_regex_search *result);
64 
65 void flb_regex_exit();
66 
67 #endif
68 
69 #endif
70