00001
00004 #ifndef _GROK_H_
00005 #define _GROK_H_
00006
00007 #include <pcre.h>
00008 #include <tcutil.h>
00009 #include <stdlib.h>
00010 #include <stdbool.h>
00011 #include <stdint.h>
00012 #include <db.h>
00013 #include <string.h>
00014
00015
00016
00017
00018
00019 typedef struct grok grok_t;
00020
00021 typedef struct grok_pattern {
00022 const char *name;
00023 char *regexp;
00024 } grok_pattern_t;
00025
00026 struct grok {
00028 const char *pattern;
00029
00031 int pattern_len;
00032
00034 char *full_pattern;
00035
00037 int full_pattern_len;
00038
00040 TCTREE *patterns;
00041
00042 pcre *re;
00043 int *pcre_capture_vector;
00044 int pcre_num_captures;
00045
00046
00047 TCTREE *captures_by_id;
00048 TCTREE *captures_by_name;
00049 TCTREE *captures_by_subname;
00050 TCTREE *captures_by_capture_number;
00051 int max_capture_num;
00052
00054 const char *pcre_errptr;
00055 int pcre_erroffset;
00056 int pcre_errno;
00057
00058 unsigned int logmask;
00059 unsigned int logdepth;
00060 char *errstr;
00061 };
00062
00063 extern int g_grok_global_initialized;
00064 extern pcre *g_pattern_re;
00065 extern int g_pattern_num_captures;
00066 extern int g_cap_name;
00067 extern int g_cap_pattern;
00068 extern int g_cap_subname;
00069 extern int g_cap_predicate;
00070
00071
00072
00073
00074 #define PATTERN_REGEX \
00075 "(?!<\\\\)%{" \
00076 "(?<name>" \
00077 "(?<pattern>[A-z0-9]+)" \
00078 "(?::(?<subname>[A-z0-9]+))?" \
00079 ")" \
00080 "\\s*(?<predicate>" \
00081 "(?:" \
00082 "(?P<curly>\\{(?:(?>[^{}]+|(?>\\\\[{}])+)|(?P>curly))*\\})" \
00083 "|" \
00084 "(?:[^{}]+|\\\\[{}])+" \
00085 ")+" \
00086 ")?" \
00087 "}"
00088
00090 #define GROK_OK 0
00091
00094 #define GROK_ERROR_FILE_NOT_ACCESSIBLE 1
00095
00099 #define GROK_ERROR_PATTERN_NOT_FOUND 2
00100
00101 #define GROK_ERROR_UNEXPECTED_READ_SIZE 3
00102
00104 #define GROK_ERROR_COMPILE_FAILED 4
00105
00108 #define GROK_ERROR_UNINITIALIZED 5
00109
00112 #define GROK_ERROR_PCRE_ERROR 6
00113
00115 #define GROK_ERROR_NOMATCH 7
00116
00117 #define CAPTURE_ID_LEN 4
00118 #define CAPTURE_FORMAT "%04x"
00119
00120 #include "grok_logging.h"
00121
00122 #ifndef GROK_TEST_NO_PATTERNS
00123 #include "grok_pattern.h"
00124 #endif
00125
00126 #ifndef GROK_TEST_NO_CAPTURE
00127 #include "grok_capture.h"
00128 #endif
00129
00130 #include "grok_match.h"
00131 #include "grok_discover.h"
00132 #include "grok_version.h"
00133
00155 grok_t *grok_new();
00156
00163 void grok_init(grok_t *grok);
00164
00173 void grok_clone(grok_t *dst, const grok_t *src);
00174
00185 void grok_free(grok_t *grok);
00186
00189 void grok_free_clone(const grok_t *grok);
00190
00196 const char *grok_version();
00197
00208 int grok_compile(grok_t *grok, const char *pattern);
00209
00217 int grok_compilen(grok_t *grok, const char *pattern, int length);
00218
00226 int grok_exec(const grok_t *grok, const char *text, grok_match_t *gm);
00227
00231 int grok_execn(const grok_t *grok, const char *text, int textlen, grok_match_t *gm);
00232
00233 int grok_match_get_named_substring(const grok_match_t *gm, const char *name,
00234 const char **substr, int *len);
00235
00236
00237 #endif