3
* Implements event 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.
32
#include "libee/libee.h"
33
#include "libee/internal.h"
34
#include "libee/field.h"
35
#include "libee/value.h"
37
#define ERR_ABORT {r = 1; goto done; }
40
if(event->objID != ObjID_EVENT) { \
47
ee_newEvent(ee_ctx __attribute__((unused)) ctx)
49
struct ee_event *event;
50
if((event = malloc(sizeof(struct ee_event))) == NULL)
53
event->objID = ObjID_EVENT;
64
ee_deleteEvent(struct ee_event *event)
66
assert(event != NULL);assert(event->objID == ObjID_EVENT);
67
if(event->tags != NULL)
68
ee_deleteTagbucket(event->tags);
69
if(event->fields != NULL)
70
ee_deleteFieldbucket(event->fields);
76
ee_addTagToEvent(struct ee_event *event, char *tag)
80
assert(event != NULL);assert(event->objID == ObjID_EVENT);
81
if(event->tags == NULL)
82
if((event->tags = ee_newTagbucket(event->ctx)) == NULL)
85
r = ee_addTagToBucket(event->tags, strdup(tag));
93
ee_addFieldToEvent(struct ee_event *event, struct ee_field *field)
97
assert(event != NULL);assert(event->objID == ObjID_EVENT);
98
if(event->fields == NULL) {
99
CHKN(event->fields = ee_newFieldbucket(event->ctx));
102
r = ee_addFieldToBucket(event->fields, field);
110
ee_addStrFieldToEvent(struct ee_event *event, char *fieldname, es_str_t *value)
113
struct ee_field *field = NULL;
114
struct ee_value *val = NULL;
116
assert(event != NULL);assert(event->objID == ObjID_EVENT);
117
if(event->fields == NULL)
118
if((event->fields = ee_newFieldbucket(event->ctx)) == NULL)
120
//printf("addStrField: %s/%s\n", fieldname, es_str2cstr(value, NULL));
122
if((val = ee_newValue(event->ctx)) == NULL) goto done;
123
if((r = ee_setStrValue(val, value)) != 0) goto done;
124
if((field = ee_newFieldFromNV(event->ctx, fieldname, val)) == NULL) goto done;
125
if((r = ee_addFieldToBucket(event->fields, field)) != 0) goto done;
129
/* central error cleanup */
133
ee_deleteField(field);