1 /**
2  * @file samples.h
3  * @brief Object to process log samples.
4  * @author Rainer Gerhards
5  *
6  * This object handles log samples, and in actual log sample files.
7  * It co-operates with the ptree object to build the actual parser tree.
8  *//*
9  *
10  * liblognorm - a fast samples-based log normalization library
11  * Copyright 2010 by Rainer Gerhards and Adiscon GmbH.
12  *
13  * This file is part of liblognorm.
14  *
15  * This library is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU Lesser General Public
17  * License as published by the Free Software Foundation; either
18  * version 2.1 of the License, or (at your option) any later version.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28  *
29  * A copy of the LGPL v2.1 can be found in the file "COPYING" in this distribution.
30  */
31 #ifndef LIBLOGNORM_V1_SAMPLES_H_INCLUDED
32 #define	LIBLOGNORM_V1_SAMPLES_H_INCLUDED
33 #include <stdio.h>	/* we need es_size_t */
34 #include <libestr.h>
35 
36 
37 /**
38  * A single log sample.
39  */
40 struct ln_v1_samp {
41 	es_str_t *msg;
42 };
43 
44 /**
45  * Reads a sample stored in buffer buf and creates a new ln_v1_samp object
46  * out of it.
47  *
48  * @note
49  * It is the caller's responsibility to delete the newly
50  * created ln_v1_samp object if it is no longer needed.
51  *
52  * @param[ctx] ctx current library context
53  * @param[buf] cstr buffer containing the string contents of the sample
54  * @param[lenBuf] length of the sample contained within buf
55  * @return Newly create object or NULL if an error occured.
56  */
57 struct ln_v1_samp *
58 ln_v1_processSamp(ln_ctx ctx, const char *buf, es_size_t lenBuf);
59 
60 
61 /**
62  * Read a sample from repository (sequentially).
63  *
64  * Reads a sample starting with the current file position and
65  * creates a new ln_v1_samp object out of it.
66  *
67  * @note
68  * It is the caller's responsibility to delete the newly
69  * created ln_v1_samp object if it is no longer needed.
70  *
71  * @param[in] ctx current library context
72  * @param[in] repo repository descriptor
73  * @param[out] isEof must be set to 0 on entry and is switched to 1 if EOF occured.
74  * @return Newly create object or NULL if an error or EOF occured.
75  */
76 struct ln_v1_samp *
77 ln_v1_sampRead(ln_ctx ctx, FILE *repo, int *isEof);
78 
79 
80 /**
81  * Free ln_v1_samp object.
82  */
83 void
84 ln_v1_sampFree(ln_ctx ctx, struct ln_v1_samp *samp);
85 
86 
87 /**
88  * Parse a given sample
89  *
90  * @param[in] ctx current library context
91  * @param[in] rule string (with prefix and suffix '%' markers)
92  * @param[in] offset in rule-string to start at (it should be pointed to
93  *  starting character: '%')
94  * @param[in] temp string buffer(working space),
95  *  externalized for efficiency reasons
96  * @param[out] return code (0 means success)
97  * @return newly created node, which can be added to sample tree.
98  */
99 ln_fieldList_t*
100 ln_v1_parseFieldDescr(ln_ctx ctx, es_str_t *rule, es_size_t *bufOffs,
101 				   es_str_t **str, int* ret);
102 
103 #endif /* #ifndef LIBLOGNORM_V1_SAMPLES_H_INCLUDED */
104