3
* Implements field object methods.
4
*//* Libee - An Event Expression Library inspired by CEE
5
* Copyright 2010 by Rainer Gerhards and Adiscon GmbH.
7
* This file is part of libee.
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
* A copy of the LGPL v2.1 can be found in the file "COPYING" in this distribution.
31
#include "libee/libee.h"
32
#include "libee/internal.h"
34
#define ERR_ABORT {r = 1; goto done; }
37
if(field->objID != ObjID_FIELD) { \
43
ee_newField(ee_ctx ctx)
45
struct ee_field *field;
46
if((field = malloc(sizeof(struct ee_field))) == NULL) goto done;
47
field->objID = ObjID_FIELD;
51
field->valroot = field->valtail = NULL;
58
ee_deleteField(struct ee_field *field)
60
struct ee_valnode *node, *nodeDel;
62
assert(field->objID == ObjID_FIELD);
63
es_deleteStr(field->name);
64
if(field->nVals > 0) {
65
ee_deleteValue(field->val);
67
if(field->nVals > 1) {
68
node = field->valroot;
71
ee_deleteValue(nodeDel->val);
79
ee_newFieldFromNV(ee_ctx __attribute__((unused)) ctx, char *name, struct ee_value *val)
81
struct ee_field *field;
82
assert(val->objID == ObjID_VALUE);
83
if((field = ee_newField(ctx)) == NULL) goto done;
85
if((field->name = es_newStrFromCStr(name, strlen(name))) == NULL) {
98
/* In this version of the method, we simply create a copy of the field name. In
99
* later versions, depending on our state and compliance level, we may use
100
* a pointer to an in-memory representation of the dictionary entity instead.
101
* rgerhards, 2010-10-26
104
ee_nameField(struct ee_field *field, es_str_t *name)
107
assert(field->objID == ObjID_FIELD);
108
if(field->name != NULL) {
112
CHKN(field->name = es_strdup(name));
120
ee_addValueToField(struct ee_field *field, struct ee_value *val)
123
struct ee_valnode *valnode;
124
assert(field != NULL);assert(field->objID== ObjID_FIELD);
125
assert(val != NULL);assert(val->objID == ObjID_VALUE);
127
if(field->nVals == 0) {
130
} else if(field->nVals == LIBEE_CEE_MAX_VALS_PER_FIELD) {
131
r = EE_TOOMANYVALUES;
134
/* we need to add to the list of values */
135
CHKN(valnode = ee_newValnode());
138
if(field->valtail == NULL) {
139
field->valroot = field->valtail = valnode;
141
field->valtail->next = valnode;
142
field->valtail = valnode;