AT&T ECOMP Vendor Event Listener library  0.1
evel_other.c
Go to the documentation of this file.
1 /**************************************************************************/
35 #include <string.h>
36 #include <assert.h>
37 #include <stdlib.h>
38 
39 #include "evel.h"
40 #include "evel_internal.h"
41 
42 /**************************************************************************/
54 {
55  EVENT_OTHER * other = NULL;
56  EVEL_ENTER();
57 
58  /***************************************************************************/
59  /* Check preconditions. */
60  /***************************************************************************/
61 
62  /***************************************************************************/
63  /* Allocate the Other. */
64  /***************************************************************************/
65  other = malloc(sizeof(EVENT_OTHER));
66  if (other == NULL)
67  {
68  log_error_state("Out of memory");
69  goto exit_label;
70  }
71  memset(other, 0, sizeof(EVENT_OTHER));
72  EVEL_DEBUG("New Other is at %lp", other);
73 
74  /***************************************************************************/
75  /* Initialize the header & the Other fields. Optional string values are */
76  /* uninitialized (NULL). */
77  /***************************************************************************/
78  evel_init_header(&other->header);
81 
82 exit_label:
83  EVEL_EXIT();
84  return other;
85 }
86 
87 /**************************************************************************/
100  const char * const type)
101 {
102  EVEL_ENTER();
103 
104  /***************************************************************************/
105  /* Check preconditions and call evel_header_type_set. */
106  /***************************************************************************/
107  assert(other != NULL);
108  assert(other->header.event_domain == EVEL_DOMAIN_OTHER);
109  evel_header_type_set(&other->header, type);
110 
111  EVEL_EXIT();
112 }
113 
114 /**************************************************************************/
127 void evel_other_field_add(EVENT_OTHER * other, char * name, char * value)
128 {
129  OTHER_FIELD * other_field = NULL;
130  EVEL_ENTER();
131 
132  /***************************************************************************/
133  /* Check preconditions. */
134  /***************************************************************************/
135  assert(other != NULL);
136  assert(other->header.event_domain == EVEL_DOMAIN_OTHER);
137  assert(name != NULL);
138  assert(value != NULL);
139 
140  EVEL_DEBUG("Adding name=%s value=%s", name, value);
141  other_field = malloc(sizeof(OTHER_FIELD));
142  assert(other_field != NULL);
143  memset(other_field, 0, sizeof(OTHER_FIELD));
144  other_field->name = strdup(name);
145  other_field->value = strdup(value);
146  assert(other_field->name != NULL);
147  assert(other_field->value != NULL);
148 
149  dlist_push_last(&other->other_fields, other_field);
150 
151  EVEL_EXIT();
152 }
153 
154 /**************************************************************************/
161  EVENT_OTHER * event)
162 {
163  OTHER_FIELD * other_field = NULL;
164  DLIST_ITEM * other_field_item = NULL;
165 
166  EVEL_ENTER();
167 
168  /***************************************************************************/
169  /* Check preconditions. */
170  /***************************************************************************/
171  assert(event != NULL);
172  assert(event->header.event_domain == EVEL_DOMAIN_OTHER);
173 
174  evel_json_encode_header(jbuf, &event->header);
175  evel_json_open_named_list(jbuf, "otherFields");
176  other_field_item = dlist_get_first(&event->other_fields);
177  while (other_field_item != NULL)
178  {
179  other_field = (OTHER_FIELD *) other_field_item->item;
180  assert(other_field != NULL);
181 
182  evel_json_open_object(jbuf);
183  evel_enc_kv_string(jbuf, "name", other_field->name);
184  evel_enc_kv_string(jbuf, "value", other_field->value);
186  other_field_item = dlist_get_next(other_field_item);
187  }
188  evel_json_close_list(jbuf);
189 
190  EVEL_EXIT();
191 }
192 
193 /**************************************************************************/
202 {
203  OTHER_FIELD * other_field = NULL;
204 
205  EVEL_ENTER();
206 
207  /***************************************************************************/
208  /* Check preconditions. As an internal API we don't allow freeing NULL */
209  /* events as we do on the public API. */
210  /***************************************************************************/
211  assert(event != NULL);
212  assert(event->header.event_domain == EVEL_DOMAIN_OTHER);
213 
214  /***************************************************************************/
215  /* Free all internal strings then the header itself. */
216  /***************************************************************************/
217  other_field = dlist_pop_last(&event->other_fields);
218  while (other_field != NULL)
219  {
220  EVEL_DEBUG("Freeing Other Field (%s, %s)",
221  other_field->name,
222  other_field->value);
223  free(other_field->name);
224  free(other_field->value);
225  free(other_field);
226  other_field = dlist_pop_last(&event->other_fields);
227  }
228  evel_free_header(&event->header);
229 
230  EVEL_EXIT();
231 }
#define EVEL_DEBUG(FMT,...)
Definition: evel.h:3621
EVENT_OTHER * evel_new_other()
Create a new Other event.
Definition: evel_other.c:53
DLIST_ITEM * dlist_get_first(DLIST *list)
Definition: double_list.c:162
void evel_json_open_named_list(EVEL_JSON_BUFFER *jbuf, const char *const key)
Add the key and opening bracket of a named list to a JSON buffer.
void dlist_initialize(DLIST *list)
List initialization.
Definition: double_list.c:55
void evel_other_field_add(EVENT_OTHER *other, char *name, char *value)
Add a field name/value pair to the Other.
Definition: evel_other.c:127
void evel_other_type_set(EVENT_OTHER *other, const char *const type)
Set the Event Type property of the Other.
Definition: evel_other.c:99
void * item
Definition: double_list.h:47
#define EVEL_EXIT()
Definition: evel.h:3631
DLIST other_fields
Definition: evel.h:795
void evel_json_close_list(EVEL_JSON_BUFFER *jbuf)
Add the closing bracket of a list to a JSON buffer.
#define EVEL_ENTER()
Definition: evel.h:3626
Header for EVEL library.
void evel_free_other(EVENT_OTHER *event)
Free an Other.
Definition: evel_other.c:201
Other Field.
Definition: evel.h:803
void evel_enc_kv_string(EVEL_JSON_BUFFER *jbuf, const char *const key, const char *const value)
Encode a string key and string value to a EVEL_JSON_BUFFER.
A Syslog event.
Definition: evel.h:141
void evel_json_close_object(EVEL_JSON_BUFFER *jbuf)
Add the closing bracket of an object to a JSON buffer.
char * value
Definition: evel.h:805
void evel_json_open_object(EVEL_JSON_BUFFER *jbuf)
Add the opening bracket of an object to a JSON buffer.
char * name
Definition: evel.h:804
EVEL_EVENT_DOMAINS event_domain
Definition: evel.h:420
void evel_json_encode_header(EVEL_JSON_BUFFER *jbuf, EVENT_HEADER *event)
Encode the event as a JSON event object according to AT&T&#39;s schema.
Definition: evel_event.c:291
void evel_free_header(EVENT_HEADER *const event)
Free an event header.
Definition: evel_event.c:349
void * dlist_pop_last(DLIST *list)
Definition: double_list.c:73
void dlist_push_last(DLIST *list, void *item)
Definition: double_list.c:132
void log_error_state(char *format,...)
Definition: evel_logging.c:98
Other.
Definition: evel.h:793
DLIST_ITEM * dlist_get_next(DLIST_ITEM *item)
Definition: double_list.c:172
EVENT_HEADER header
Definition: evel.h:794
void evel_header_type_set(EVENT_HEADER *const header, const char *const type)
Set the Event Type property of the event header.
Definition: evel_event.c:164
EVEL internal definitions.
void evel_init_header(EVENT_HEADER *const header)
Initialize a newly created event header.
Definition: evel_event.c:112
void evel_json_encode_other(EVEL_JSON_BUFFER *jbuf, EVENT_OTHER *event)
Encode the Other in JSON according to AT&T&#39;s schema for the event type.
Definition: evel_other.c:160