1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 ****************************************************************************/
17 /**************************************************************************//**
19 * Implementation of EVEL functions relating to Signaling.
21 ****************************************************************************/
27 #include "evel_throttle.h"
29 /**************************************************************************//**
30 * Create a new Signaling event.
32 * @note The mandatory fields on the Signaling must be supplied to
33 * this factory function and are immutable once set. Optional fields
34 * have explicit setter functions, but again values may only be set
35 * once so that the event has immutable properties.
36 * @param event_name Unique Event Name confirming Domain AsdcModel Description
37 * @param event_id A universal identifier of the event for: troubleshooting correlation, analysis, etc
38 * @param vendor_name The vendor id to encode in the event vnf field.
39 * @param module The module to encode in the event.
40 * @param vnfname The Virtual network function to encode in the event.
41 * @returns pointer to the newly manufactured ::EVENT_SIGNALING. If the event
42 * is not used (i.e. posted) it must be released using
43 * ::evel_free_signaling.
44 * @retval NULL Failed to create the event.
45 *****************************************************************************/
46 EVENT_SIGNALING * evel_new_signaling(const char* ev_name, const char *ev_id,
47 const char * const vendor_name,
48 const char * const correlator,
49 const char * const local_ip_address,
50 const char * const local_port,
51 const char * const remote_ip_address,
52 const char * const remote_port)
54 EVENT_SIGNALING * event = NULL;
58 /***************************************************************************/
59 /* Check preconditions. */
60 /***************************************************************************/
61 assert(vendor_name != NULL);
63 /***************************************************************************/
64 /* Allocate the Signaling event. */
65 /***************************************************************************/
66 event = malloc(sizeof(EVENT_SIGNALING));
69 log_error_state("Out of memory");
72 memset(event, 0, sizeof(EVENT_SIGNALING));
73 EVEL_DEBUG("New Signaling event is at %lp", event);
75 /***************************************************************************/
76 /* Initialize the header & the Signaling fields. */
77 /***************************************************************************/
78 evel_init_header_nameid(&event->header,ev_name,ev_id);
79 event->header.event_domain = EVEL_DOMAIN_SIPSIGNALING;
80 event->major_version = EVEL_SIGNALING_MAJOR_VERSION;
81 event->minor_version = EVEL_SIGNALING_MINOR_VERSION;
82 evel_init_vendor_field(&event->vnfname_field, vendor_name);
83 evel_set_option_string(&event->correlator,correlator,"Init correlator");
84 evel_set_option_string(&event->local_ip_address,local_ip_address,"Init correlator");
85 evel_set_option_string(&event->local_port,local_port,"Init local port");
86 evel_set_option_string(&event->remote_ip_address,remote_ip_address,"Init remote ip");
87 evel_set_option_string(&event->remote_port,remote_port,"Init remote port");
88 evel_init_option_string(&event->compressed_sip);
89 evel_init_option_string(&event->summary_sip);
90 dlist_initialize(&event->additional_info);
98 /**************************************************************************//**
99 * Add an additional value name/value pair to the SIP signaling.
101 * The name and value are null delimited ASCII strings. The library takes
102 * a copy so the caller does not have to preserve values after the function
105 * @param event Pointer to the fault.
106 * @param name ASCIIZ string with the attribute's name. The caller
107 * does not need to preserve the value once the function
109 * @param value ASCIIZ string with the attribute's value. The caller
110 * does not need to preserve the value once the function
112 *****************************************************************************/
113 void evel_signaling_addl_info_add(EVENT_SIGNALING * event, char * name, char * value)
115 FAULT_ADDL_INFO * addl_info = NULL;
118 /***************************************************************************/
119 /* Check preconditions. */
120 /***************************************************************************/
121 assert(event != NULL);
122 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
123 assert(name != NULL);
124 assert(value != NULL);
126 EVEL_DEBUG("Adding name=%s value=%s", name, value);
127 addl_info = malloc(sizeof(SIGNALING_ADDL_FIELD));
128 assert(addl_info != NULL);
129 memset(addl_info, 0, sizeof(SIGNALING_ADDL_FIELD));
130 addl_info->name = strdup(name);
131 addl_info->value = strdup(value);
132 assert(addl_info->name != NULL);
133 assert(addl_info->value != NULL);
135 dlist_push_last(&event->additional_info, addl_info);
141 /**************************************************************************//**
142 * Set the Event Type property of the Signaling event.
144 * @note The property is treated as immutable: it is only valid to call
145 * the setter once. However, we don't assert if the caller tries to
146 * overwrite, just ignoring the update instead.
148 * @param event Pointer to the Signaling event.
149 * @param type The Event Type to be set. ASCIIZ string. The caller
150 * does not need to preserve the value once the function
152 *****************************************************************************/
153 void evel_signaling_type_set(EVENT_SIGNALING * const event,
154 const char * const type)
158 /***************************************************************************/
159 /* Check preconditions and call evel_header_type_set. */
160 /***************************************************************************/
161 assert(event != NULL);
162 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
163 evel_header_type_set(&event->header, type);
168 /**************************************************************************//**
169 * Set the Local Ip Address property of the Signaling event.
171 * @note The property is treated as immutable: it is only valid to call
172 * the setter once. However, we don't assert if the caller tries to
173 * overwrite, just ignoring the update instead.
175 * @param event Pointer to the Signaling event.
176 * @param local_ip_address
177 * The Local Ip Address to be set. ASCIIZ string. The
178 * caller does not need to preserve the value once the
180 *****************************************************************************/
181 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
182 const char * const local_ip_address)
186 /***************************************************************************/
187 /* Check preconditions. */
188 /***************************************************************************/
189 assert(event != NULL);
190 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
191 assert(local_ip_address != NULL);
193 evel_set_option_string(&event->local_ip_address,
200 /**************************************************************************//**
201 * Set the Local Port property of the Signaling event.
203 * @note The property is treated as immutable: it is only valid to call
204 * the setter once. However, we don't assert if the caller tries to
205 * overwrite, just ignoring the update instead.
207 * @param event Pointer to the Signaling event.
208 * @param local_port The Local Port to be set. ASCIIZ string. The caller
209 * does not need to preserve the value once the function
211 *****************************************************************************/
212 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
213 const char * const local_port)
217 /***************************************************************************/
218 /* Check preconditions. */
219 /***************************************************************************/
220 assert(event != NULL);
221 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
222 assert(local_port != NULL);
224 evel_set_option_string(&event->local_port,
231 /**************************************************************************//**
232 * Set the Remote Ip Address property of the Signaling event.
234 * @note The property is treated as immutable: it is only valid to call
235 * the setter once. However, we don't assert if the caller tries to
236 * overwrite, just ignoring the update instead.
238 * @param event Pointer to the Signaling event.
239 * @param remote_ip_address
240 * The Remote Ip Address to be set. ASCIIZ string. The
241 * caller does not need to preserve the value once the
243 *****************************************************************************/
244 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
245 const char * const remote_ip_address)
249 /***************************************************************************/
250 /* Check preconditions. */
251 /***************************************************************************/
252 assert(event != NULL);
253 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
254 assert(remote_ip_address != NULL);
256 evel_set_option_string(&event->remote_ip_address,
258 "Remote Ip Address");
263 /**************************************************************************//**
264 * Set the Remote Port property of the Signaling event.
266 * @note The property is treated as immutable: it is only valid to call
267 * the setter once. However, we don't assert if the caller tries to
268 * overwrite, just ignoring the update instead.
270 * @param event Pointer to the Signaling event.
271 * @param remote_port The Remote Port to be set. ASCIIZ string. The caller
272 * does not need to preserve the value once the function
274 *****************************************************************************/
275 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
276 const char * const remote_port)
280 /***************************************************************************/
281 /* Check preconditions. */
282 /***************************************************************************/
283 assert(event != NULL);
284 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
285 assert(remote_port != NULL);
287 evel_set_option_string(&event->remote_port,
294 /**************************************************************************//**
295 * Set the Vendor module property of the Signaling event.
297 * @note The property is treated as immutable: it is only valid to call
298 * the setter once. However, we don't assert if the caller tries to
299 * overwrite, just ignoring the update instead.
301 * @param event Pointer to the Signaling event.
302 * @param modulename The module name to be set. ASCIIZ string. The caller
303 * does not need to preserve the value once the function
305 *****************************************************************************/
306 void evel_signaling_vnfmodule_name_set(EVENT_SIGNALING * const event,
307 const char * const module_name)
311 /***************************************************************************/
312 /* Check preconditions. */
313 /***************************************************************************/
314 assert(event != NULL);
315 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
316 assert(module_name != NULL);
318 evel_vendor_field_module_set(&event->vnfname_field, module_name);
323 /**************************************************************************//**
324 * Set the Vendor module property of the Signaling event.
326 * @note The property is treated as immutable: it is only valid to call
327 * the setter once. However, we don't assert if the caller tries to
328 * overwrite, just ignoring the update instead.
330 * @param event Pointer to the Signaling event.
331 * @param vnfname The Virtual Network function to be set. ASCIIZ string.
332 * The caller does not need to preserve the value once
333 * the function returns.
334 *****************************************************************************/
335 void evel_signaling_vnfname_set(EVENT_SIGNALING * const event,
336 const char * const vnfname)
340 /***************************************************************************/
341 /* Check preconditions. */
342 /***************************************************************************/
343 assert(event != NULL);
344 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
345 assert(vnfname != NULL);
347 evel_vendor_field_vnfname_set(&event->vnfname_field, vnfname);
352 /**************************************************************************//**
353 * Set the Compressed SIP property of the Signaling event.
355 * @note The property is treated as immutable: it is only valid to call
356 * the setter once. However, we don't assert if the caller tries to
357 * overwrite, just ignoring the update instead.
359 * @param event Pointer to the Signaling event.
360 * @param compressed_sip
361 * The Compressed SIP to be set. ASCIIZ string. The caller
362 * does not need to preserve the value once the function
364 *****************************************************************************/
365 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
366 const char * const compressed_sip)
370 /***************************************************************************/
371 /* Check preconditions. */
372 /***************************************************************************/
373 assert(event != NULL);
374 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
375 assert(compressed_sip != NULL);
377 evel_set_option_string(&event->compressed_sip,
384 /**************************************************************************//**
385 * Set the Summary SIP property of the Signaling event.
387 * @note The property is treated as immutable: it is only valid to call
388 * the setter once. However, we don't assert if the caller tries to
389 * overwrite, just ignoring the update instead.
391 * @param event Pointer to the Signaling event.
392 * @param summary_sip The Summary SIP to be set. ASCIIZ string. The caller
393 * does not need to preserve the value once the function
395 *****************************************************************************/
396 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
397 const char * const summary_sip)
401 /***************************************************************************/
402 /* Check preconditions. */
403 /***************************************************************************/
404 assert(event != NULL);
405 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
406 assert(summary_sip != NULL);
408 evel_set_option_string(&event->summary_sip,
415 /**************************************************************************//**
416 * Set the Correlator property of the Signaling event.
418 * @note The property is treated as immutable: it is only valid to call
419 * the setter once. However, we don't assert if the caller tries to
420 * overwrite, just ignoring the update instead.
422 * @param event Pointer to the Signaling event.
423 * @param correlator The correlator to be set. ASCIIZ string. The caller
424 * does not need to preserve the value once the function
426 *****************************************************************************/
427 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
428 const char * const correlator)
432 /***************************************************************************/
433 /* Check preconditions and call evel_header_type_set. */
434 /***************************************************************************/
435 assert(event != NULL);
436 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
437 evel_set_option_string(&event->correlator,
444 /**************************************************************************//**
445 * Encode the Signaling in JSON according to AT&T's schema for the
448 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
449 * @param event Pointer to the ::EVENT_HEADER to encode.
450 *****************************************************************************/
451 void evel_json_encode_signaling(EVEL_JSON_BUFFER * const jbuf,
452 EVENT_SIGNALING * const event)
454 SIGNALING_ADDL_FIELD * addl_info = NULL;
455 DLIST_ITEM * addl_info_item = NULL;
459 /***************************************************************************/
460 /* Check preconditions. */
461 /***************************************************************************/
462 assert(event != NULL);
463 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
465 evel_json_encode_header(jbuf, &event->header);
466 evel_json_open_named_object(jbuf, "signalingFields");
468 /***************************************************************************/
469 /* Mandatory fields */
470 /***************************************************************************/
472 /***************************************************************************/
473 /* Optional fields */
474 /***************************************************************************/
475 evel_enc_kv_opt_string(jbuf, "compressedSip", &event->compressed_sip);
476 evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
477 evel_enc_kv_opt_string(jbuf, "localIpAddress", &event->local_ip_address);
478 evel_enc_kv_opt_string(jbuf, "localPort", &event->local_port);
479 evel_enc_kv_opt_string(jbuf, "remoteIpAddress", &event->remote_ip_address);
480 evel_enc_kv_opt_string(jbuf, "remotePort", &event->remote_port);
481 evel_enc_version(jbuf, "signalingFieldsVersion", event->major_version,event->minor_version);
482 evel_enc_kv_opt_string(jbuf, "summarySip", &event->summary_sip);
483 evel_json_encode_vendor_field(jbuf, &event->vnfname_field);
486 /***************************************************************************/
487 /* Checkpoint, so that we can wind back if all fields are suppressed. */
488 /***************************************************************************/
489 evel_json_checkpoint(jbuf);
490 if (evel_json_open_opt_named_list(jbuf, "additionalInformation"))
492 bool item_added = false;
494 addl_info_item = dlist_get_first(&event->additional_info);
495 while (addl_info_item != NULL)
497 addl_info = (SIGNALING_ADDL_FIELD*) addl_info_item->item;
498 assert(addl_info != NULL);
500 if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
501 "additionalInformation",
504 evel_json_open_object(jbuf);
505 evel_enc_kv_string(jbuf, "name", addl_info->name);
506 evel_enc_kv_string(jbuf, "value", addl_info->value);
507 evel_json_close_object(jbuf);
510 addl_info_item = dlist_get_next(addl_info_item);
512 evel_json_close_list(jbuf);
514 /*************************************************************************/
515 /* If we've not written anything, rewind to before we opened the list. */
516 /*************************************************************************/
519 evel_json_rewind(jbuf);
523 evel_json_close_object(jbuf);
528 /**************************************************************************//**
529 * Free a Signaling event.
531 * Free off the event supplied. Will free all the contained allocated memory.
533 * @note It does not free the event itself, since that may be part of a larger
535 *****************************************************************************/
536 void evel_free_signaling(EVENT_SIGNALING * const event)
538 SIGNALING_ADDL_FIELD * addl_info = NULL;
541 /***************************************************************************/
542 /* Check preconditions. As an internal API we don't allow freeing NULL */
543 /* events as we do on the public API. */
544 /***************************************************************************/
545 assert(event != NULL);
546 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
548 /***************************************************************************/
549 /* Free all internal strings then the header itself. */
550 /***************************************************************************/
551 addl_info = dlist_pop_last(&event->additional_info);
552 while (addl_info != NULL)
554 EVEL_DEBUG("Freeing Additional Info (%s, %s)",
557 free(addl_info->name);
558 free(addl_info->value);
560 addl_info = dlist_pop_last(&event->additional_info);
563 evel_free_event_vendor_field(&event->vnfname_field);
564 evel_free_option_string(&event->correlator);
565 evel_free_option_string(&event->local_ip_address);
566 evel_free_option_string(&event->local_port);
567 evel_free_option_string(&event->remote_ip_address);
568 evel_free_option_string(&event->remote_port);
569 evel_free_option_string(&event->compressed_sip);
570 evel_free_option_string(&event->summary_sip);
571 evel_free_header(&event->header);