3
* Implements fieldbucket 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(fieldbucket->objID != ObjID_FIELDBUCKET) { \
43
struct ee_fieldbucket*
44
ee_newFieldbucket(ee_ctx ctx)
46
struct ee_fieldbucket *fieldbucket;
47
if((fieldbucket = malloc(sizeof(struct ee_fieldbucket))) == NULL)
50
fieldbucket->objID = ObjID_FIELDBUCKET;
51
fieldbucket->ctx = ctx;
52
fieldbucket->root = fieldbucket->tail = NULL;
54
done: return fieldbucket;
59
ee_deleteFieldbucket(struct ee_fieldbucket *fieldbucket)
61
struct ee_fieldbucket_listnode *node, *nodeDel;
63
assert(fieldbucket->objID == ObjID_FIELDBUCKET);
64
fieldbucket->objID = ObjID_DELETED;
65
for(node = fieldbucket->root ; node != NULL ; ) {
68
ee_deleteField(nodeDel->field);
75
/* TODO: when in validating mode, check duplicate field entries */
77
ee_addFieldToBucket(struct ee_fieldbucket *fieldb, struct ee_field *field)
80
struct ee_fieldbucket_listnode *node;
81
assert(fieldb != NULL);assert(fieldb->objID == ObjID_FIELDBUCKET);
82
assert(field != NULL);assert(field->objID == ObjID_FIELD);
84
CHKN(node = malloc(sizeof(struct ee_fieldbucket_listnode)));
87
if(fieldb->root == NULL) {
88
fieldb->root = fieldb->tail = node;
90
fieldb->tail->next = node;
99
/* Note: this function currently is quite performance-hungry. We should
100
* replace all this searching by hashtable access some time in the future,
101
* but for now the focus is on getting things done in a simple fashion, and
102
* so the simple list search approach is good enough. But if you try to
103
* optimize, do not optimize the list search but rather introduce the hash
104
* table as second indexing structure! -- rgerhards, 2010-12-01
107
ee_getBucketField(struct ee_fieldbucket *bucket, es_str_t *name)
109
struct ee_fieldbucket_listnode *node;
111
for(node = bucket->root ; node != NULL ; node = node->next) {
112
if(!es_strcmp(name, node->field->name))
116
return((node == NULL) ? NULL : node->field);
121
ee_getNumFieldVals(struct ee_field *field)
123
assert(field != NULL);
124
return(field->nVals);
128
/* TODO: this function currently assumes that the field has a string
129
* representation, which for now is always true. Needs to be changed if
130
* we change the representation!
133
ee_getFieldValueAsStr(struct ee_field *field, unsigned short n)
136
assert(field != NULL);
138
if(n >= field->nVals) {
143
str = es_strdup(field->val->val.str);
145
assert(0); // TODO: implement!