~ubuntu-branches/ubuntu/vivid/libee/vivid

« back to all changes in this revision

Viewing changes to include/libee/field.h

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2010-12-11 12:37:09 UTC
  • Revision ID: james.westby@ubuntu.com-20101211123709-i8v7mpdtzhgjoqn5
Tags: upstream-0.1.0
ImportĀ upstreamĀ versionĀ 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file field.h
 
3
 * @brief The CEE nvfield object.
 
4
 * @class ee_field field.h
 
5
 *
 
6
 *//*
 
7
 *
 
8
 * Libee - An Event Expression Library inspired by CEE
 
9
 * Copyright 2010 by Rainer Gerhards and Adiscon GmbH.
 
10
 *
 
11
 * This file is part of libee.
 
12
 *
 
13
 * This library is free software; you can redistribute it and/or
 
14
 * modify it under the terms of the GNU Lesser General Public
 
15
 * License as published by the Free Software Foundation; either
 
16
 * version 2.1 of the License, or (at your option) any later version.
 
17
 *
 
18
 * This library is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
21
 * Lesser General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU Lesser General Public
 
24
 * License along with this library; if not, write to the Free Software
 
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
26
 *
 
27
 * A copy of the LGPL v2.1 can be found in the file "COPYING" in this distribution.
 
28
 */
 
29
#ifndef LIBEE_FIELD_H_INCLUDED
 
30
#define LIBEE_FIELD_H_INCLUDED
 
31
#include "libee/valnode.h"
 
32
 
 
33
/**
 
34
 * The Field object.
 
35
 *
 
36
 * Note that in CEE terms, this is called a "nvfield". 
 
37
 *
 
38
 * This represents a name-value pair, whereby the name should correspond
 
39
 * to a valid field type. However, depending on compliance level, name
 
40
 * may not point to a valid field. For this reason, we do not require
 
41
 * a pointer to the proper field definition.
 
42
 *
 
43
 * Fields may contain a variable number of values. However, the by far
 
44
 * most common case is exactly one value. To support this effciently, we
 
45
 * store the first value directly within the structure and the 2nd+ in
 
46
 * a linked list.
 
47
 */
 
48
struct ee_field {
 
49
        unsigned objID;         /**< magic number to identify the object */
 
50
        ee_ctx ctx;             /**< associated library context */
 
51
        es_str_t *name;         /**< the field name */
 
52
        unsigned char nVals;    /**< number of values */
 
53
        struct ee_value *val;   /**< value assigned to this field */
 
54
        struct ee_valnode *valroot;     /**< list for 2nd+ values */
 
55
        struct ee_valnode *valtail;     /**< tail of the value list (for fast insert) */
 
56
};
 
57
 
 
58
/**
 
59
 * Constructor for the ee_field object.
 
60
 *
 
61
 * @memberof ee_field
 
62
 * @public
 
63
 *
 
64
 * @param[in] ctx library context
 
65
 *
 
66
 * @return pointer to new object or NULL if an error occured
 
67
 */
 
68
struct ee_field* ee_newField(ee_ctx ctx);
 
69
 
 
70
 
 
71
/**
 
72
 * Constructor an ee_field object from a name value pair.
 
73
 * TODO: is this legacy or do we need it in the future?
 
74
 *
 
75
 * @memberof ee_field
 
76
 * @public
 
77
 *
 
78
 * @param[in] ctx library context
 
79
 * @param[in] name field name
 
80
 * @param[in] val value
 
81
 *
 
82
 * @return new field or NULL if an error occured
 
83
 */
 
84
struct ee_field* ee_newFieldFromNV(ee_ctx ctx, char *name, struct ee_value *val);
 
85
 
 
86
/**
 
87
 * Destructor for the ee_field object.
 
88
 *
 
89
 * @memberof ee_field
 
90
 * @public
 
91
 *
 
92
 * @param[in] field object to be destructed
 
93
 *
 
94
 * @param field The field to be discarded.
 
95
 */
 
96
void ee_deleteField(struct ee_field *field);
 
97
 
 
98
 
 
99
/**
 
100
 * Name a field.
 
101
 * Set the field name. This MUST NOT be called if a field name has
 
102
 * already been established. Note that if the library is in validating mode,
 
103
 * it may check the field name against the dictionary.
 
104
 *
 
105
 * @memberof ee_field
 
106
 * @public
 
107
 *
 
108
 * @param[in] ctx library context
 
109
 * @param[in] str field name
 
110
 *
 
111
 * @return 0 on success, something else otherwise
 
112
 */
 
113
int ee_nameField(struct ee_field *field, es_str_t *name);
 
114
 
 
115
 
 
116
/**
 
117
 * Add a value to a field.
 
118
 * Add the provided value to the list of field values. The value will
 
119
 * be added as the \b last member of the field list (so calling sequence
 
120
 * is important!). In validating mode, the library will check value
 
121
 * cardinality against the dictionary.
 
122
 *
 
123
 * @memberof ee_field
 
124
 * @public
 
125
 *
 
126
 * @param[in] ctx library context
 
127
 * @param[in] val value to add to field
 
128
 *
 
129
 * @return 0 on success, something else otherwise
 
130
 */
 
131
int ee_addValueToField(struct ee_field *field, struct ee_value *val);
 
132
 
 
133
/**
 
134
 * Encode the current field with all its values in syslog format
 
135
 * and append this representation to the provided string.
 
136
 * 
 
137
 * @memberof ee_value
 
138
 * @public
 
139
 *
 
140
 * @param[in] field field to enocde
 
141
 * @param[out]  str string to wich the encoded value is to be added.
 
142
 *                 Must have been allocated by the caller.
 
143
 * @returns 0 on success, something else otherwise
 
144
 */
 
145
int ee_addField_Syslog(struct ee_field *value, es_str_t **str);
 
146
 
 
147
 
 
148
/**
 
149
 * Encode the current field with all its values in XML format
 
150
 * and append this representation to the provided string.
 
151
 * 
 
152
 * @memberof ee_value
 
153
 * @public
 
154
 *
 
155
 * @param[in] field field to enocde
 
156
 * @param[out]  str string to wich the encoded value is to be added.
 
157
 *                 Must have been allocated by the caller.
 
158
 * @returns 0 on success, something else otherwise
 
159
 */
 
160
int ee_addField_XML(struct ee_field *value, es_str_t **str);
 
161
 
 
162
 
 
163
/**
 
164
 * Get the number of values the field has.
 
165
 *
 
166
 * @memberof ee_value
 
167
 * @public
 
168
 *
 
169
 * @param[in] field relevant field
 
170
 * @returns number of values
 
171
 */
 
172
int ee_getNumFieldVals(struct ee_field *field);
 
173
 
 
174
/**
 
175
 * Get a specific value from this field as a string.
 
176
 *
 
177
 * @memberof ee_value
 
178
 * @public
 
179
 *
 
180
 * @param[in] field relevant field
 
181
 * @param[in] n number of the field to return, zero-based (like C arrays)
 
182
 *
 
183
 * @returns string representation of the n-th field value or NULL in
 
184
 *      case of error
 
185
 */
 
186
es_str_t* ee_getFieldValueAsStr(struct ee_field *field, unsigned short n);
 
187
 
 
188
#endif /* #ifndef LIBEE_FIELD_H_INCLUDED */