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 vendor_name The vendor id to encode in the event vnf field.
37 * @param module The module to encode in the event.
38 * @param vnfname The Virtual network function to encode in the event.
39 * @returns pointer to the newly manufactured ::EVENT_SIGNALING. If the event
40 * is not used (i.e. posted) it must be released using
41 * ::evel_free_signaling.
42 * @retval NULL Failed to create the event.
43 *****************************************************************************/
44 EVENT_SIGNALING * evel_new_signaling(const char * const vendor_name,
45 const char * const correlator,
46 const char * const local_ip_address,
47 const char * const local_port,
48 const char * const remote_ip_address,
49 const char * const remote_port)
51 EVENT_SIGNALING * event = NULL;
55 /***************************************************************************/
56 /* Check preconditions. */
57 /***************************************************************************/
58 assert(vendor_name != NULL);
60 /***************************************************************************/
61 /* Allocate the Signaling event. */
62 /***************************************************************************/
63 event = malloc(sizeof(EVENT_SIGNALING));
66 log_error_state("Out of memory");
69 memset(event, 0, sizeof(EVENT_SIGNALING));
70 EVEL_DEBUG("New Signaling event is at %lp", event);
72 /***************************************************************************/
73 /* Initialize the header & the Signaling fields. */
74 /***************************************************************************/
75 evel_init_header(&event->header,"SipSignaling");
76 event->header.event_domain = EVEL_DOMAIN_SIPSIGNALING;
77 event->major_version = EVEL_SIGNALING_MAJOR_VERSION;
78 event->minor_version = EVEL_SIGNALING_MINOR_VERSION;
79 evel_init_vendor_field(&event->vnfname_field, vendor_name);
80 evel_set_option_string(&event->correlator,correlator,"Init correlator");
81 evel_set_option_string(&event->local_ip_address,local_ip_address,"Init correlator");
82 evel_set_option_string(&event->local_port,local_port,"Init local port");
83 evel_set_option_string(&event->remote_ip_address,remote_ip_address,"Init remote ip");
84 evel_set_option_string(&event->remote_port,remote_port,"Init remote port");
85 evel_init_option_string(&event->compressed_sip);
86 evel_init_option_string(&event->summary_sip);
87 dlist_initialize(&event->additional_info);
95 /**************************************************************************//**
96 * Add an additional value name/value pair to the SIP signaling.
98 * The name and value are null delimited ASCII strings. The library takes
99 * a copy so the caller does not have to preserve values after the function
102 * @param event Pointer to the fault.
103 * @param name ASCIIZ string with the attribute's name. The caller
104 * does not need to preserve the value once the function
106 * @param value ASCIIZ string with the attribute's value. The caller
107 * does not need to preserve the value once the function
109 *****************************************************************************/
110 void evel_signaling_addl_info_add(EVENT_SIGNALING * event, char * name, char * value)
112 FAULT_ADDL_INFO * addl_info = NULL;
115 /***************************************************************************/
116 /* Check preconditions. */
117 /***************************************************************************/
118 assert(event != NULL);
119 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
120 assert(name != NULL);
121 assert(value != NULL);
123 EVEL_DEBUG("Adding name=%s value=%s", name, value);
124 addl_info = malloc(sizeof(SIGNALING_ADDL_FIELD));
125 assert(addl_info != NULL);
126 memset(addl_info, 0, sizeof(SIGNALING_ADDL_FIELD));
127 addl_info->name = strdup(name);
128 addl_info->value = strdup(value);
129 assert(addl_info->name != NULL);
130 assert(addl_info->value != NULL);
132 dlist_push_last(&event->additional_info, addl_info);
138 /**************************************************************************//**
139 * Set the Event Type property of the Signaling event.
141 * @note The property is treated as immutable: it is only valid to call
142 * the setter once. However, we don't assert if the caller tries to
143 * overwrite, just ignoring the update instead.
145 * @param event Pointer to the Signaling event.
146 * @param type The Event Type to be set. ASCIIZ string. The caller
147 * does not need to preserve the value once the function
149 *****************************************************************************/
150 void evel_signaling_type_set(EVENT_SIGNALING * const event,
151 const char * const type)
155 /***************************************************************************/
156 /* Check preconditions and call evel_header_type_set. */
157 /***************************************************************************/
158 assert(event != NULL);
159 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
160 evel_header_type_set(&event->header, type);
165 /**************************************************************************//**
166 * Set the Local Ip Address property of the Signaling event.
168 * @note The property is treated as immutable: it is only valid to call
169 * the setter once. However, we don't assert if the caller tries to
170 * overwrite, just ignoring the update instead.
172 * @param event Pointer to the Signaling event.
173 * @param local_ip_address
174 * The Local Ip Address to be set. ASCIIZ string. The
175 * caller does not need to preserve the value once the
177 *****************************************************************************/
178 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
179 const char * const local_ip_address)
183 /***************************************************************************/
184 /* Check preconditions. */
185 /***************************************************************************/
186 assert(event != NULL);
187 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
188 assert(local_ip_address != NULL);
190 evel_set_option_string(&event->local_ip_address,
197 /**************************************************************************//**
198 * Set the Local Port property of the Signaling event.
200 * @note The property is treated as immutable: it is only valid to call
201 * the setter once. However, we don't assert if the caller tries to
202 * overwrite, just ignoring the update instead.
204 * @param event Pointer to the Signaling event.
205 * @param local_port The Local Port to be set. ASCIIZ string. The caller
206 * does not need to preserve the value once the function
208 *****************************************************************************/
209 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
210 const char * const local_port)
214 /***************************************************************************/
215 /* Check preconditions. */
216 /***************************************************************************/
217 assert(event != NULL);
218 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
219 assert(local_port != NULL);
221 evel_set_option_string(&event->local_port,
228 /**************************************************************************//**
229 * Set the Remote Ip Address property of the Signaling event.
231 * @note The property is treated as immutable: it is only valid to call
232 * the setter once. However, we don't assert if the caller tries to
233 * overwrite, just ignoring the update instead.
235 * @param event Pointer to the Signaling event.
236 * @param remote_ip_address
237 * The Remote Ip Address to be set. ASCIIZ string. The
238 * caller does not need to preserve the value once the
240 *****************************************************************************/
241 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
242 const char * const remote_ip_address)
246 /***************************************************************************/
247 /* Check preconditions. */
248 /***************************************************************************/
249 assert(event != NULL);
250 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
251 assert(remote_ip_address != NULL);
253 evel_set_option_string(&event->remote_ip_address,
255 "Remote Ip Address");
260 /**************************************************************************//**
261 * Set the Remote Port property of the Signaling event.
263 * @note The property is treated as immutable: it is only valid to call
264 * the setter once. However, we don't assert if the caller tries to
265 * overwrite, just ignoring the update instead.
267 * @param event Pointer to the Signaling event.
268 * @param remote_port The Remote Port to be set. ASCIIZ string. The caller
269 * does not need to preserve the value once the function
271 *****************************************************************************/
272 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
273 const char * const remote_port)
277 /***************************************************************************/
278 /* Check preconditions. */
279 /***************************************************************************/
280 assert(event != NULL);
281 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
282 assert(remote_port != NULL);
284 evel_set_option_string(&event->remote_port,
291 /**************************************************************************//**
292 * Set the Vendor module property of the Signaling event.
294 * @note The property is treated as immutable: it is only valid to call
295 * the setter once. However, we don't assert if the caller tries to
296 * overwrite, just ignoring the update instead.
298 * @param event Pointer to the Signaling event.
299 * @param modulename The module name to be set. ASCIIZ string. The caller
300 * does not need to preserve the value once the function
302 *****************************************************************************/
303 void evel_signaling_vnfmodule_name_set(EVENT_SIGNALING * const event,
304 const char * const module_name)
308 /***************************************************************************/
309 /* Check preconditions. */
310 /***************************************************************************/
311 assert(event != NULL);
312 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
313 assert(module_name != NULL);
315 evel_vendor_field_module_set(&event->vnfname_field, module_name);
320 /**************************************************************************//**
321 * Set the Vendor module property of the Signaling event.
323 * @note The property is treated as immutable: it is only valid to call
324 * the setter once. However, we don't assert if the caller tries to
325 * overwrite, just ignoring the update instead.
327 * @param event Pointer to the Signaling event.
328 * @param vnfname The Virtual Network function to be set. ASCIIZ string.
329 * The caller does not need to preserve the value once
330 * the function returns.
331 *****************************************************************************/
332 void evel_signaling_vnfname_set(EVENT_SIGNALING * const event,
333 const char * const vnfname)
337 /***************************************************************************/
338 /* Check preconditions. */
339 /***************************************************************************/
340 assert(event != NULL);
341 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
342 assert(vnfname != NULL);
344 evel_vendor_field_vnfname_set(&event->vnfname_field, vnfname);
349 /**************************************************************************//**
350 * Set the Compressed SIP property of the Signaling event.
352 * @note The property is treated as immutable: it is only valid to call
353 * the setter once. However, we don't assert if the caller tries to
354 * overwrite, just ignoring the update instead.
356 * @param event Pointer to the Signaling event.
357 * @param compressed_sip
358 * The Compressed SIP to be set. ASCIIZ string. The caller
359 * does not need to preserve the value once the function
361 *****************************************************************************/
362 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
363 const char * const compressed_sip)
367 /***************************************************************************/
368 /* Check preconditions. */
369 /***************************************************************************/
370 assert(event != NULL);
371 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
372 assert(compressed_sip != NULL);
374 evel_set_option_string(&event->compressed_sip,
381 /**************************************************************************//**
382 * Set the Summary SIP property of the Signaling event.
384 * @note The property is treated as immutable: it is only valid to call
385 * the setter once. However, we don't assert if the caller tries to
386 * overwrite, just ignoring the update instead.
388 * @param event Pointer to the Signaling event.
389 * @param summary_sip The Summary SIP to be set. ASCIIZ string. The caller
390 * does not need to preserve the value once the function
392 *****************************************************************************/
393 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
394 const char * const summary_sip)
398 /***************************************************************************/
399 /* Check preconditions. */
400 /***************************************************************************/
401 assert(event != NULL);
402 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
403 assert(summary_sip != NULL);
405 evel_set_option_string(&event->summary_sip,
412 /**************************************************************************//**
413 * Set the Correlator property of the Signaling event.
415 * @note The property is treated as immutable: it is only valid to call
416 * the setter once. However, we don't assert if the caller tries to
417 * overwrite, just ignoring the update instead.
419 * @param event Pointer to the Signaling event.
420 * @param correlator The correlator to be set. ASCIIZ string. The caller
421 * does not need to preserve the value once the function
423 *****************************************************************************/
424 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
425 const char * const correlator)
429 /***************************************************************************/
430 /* Check preconditions and call evel_header_type_set. */
431 /***************************************************************************/
432 assert(event != NULL);
433 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
434 evel_set_option_string(&event->correlator,
441 /**************************************************************************//**
442 * Encode the Signaling in JSON according to AT&T's schema for the
445 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
446 * @param event Pointer to the ::EVENT_HEADER to encode.
447 *****************************************************************************/
448 void evel_json_encode_signaling(EVEL_JSON_BUFFER * const jbuf,
449 EVENT_SIGNALING * const event)
451 SIGNALING_ADDL_FIELD * addl_info = NULL;
452 DLIST_ITEM * addl_info_item = NULL;
456 /***************************************************************************/
457 /* Check preconditions. */
458 /***************************************************************************/
459 assert(event != NULL);
460 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
462 evel_json_encode_header(jbuf, &event->header);
463 evel_json_open_named_object(jbuf, "signalingFields");
465 /***************************************************************************/
466 /* Mandatory fields */
467 /***************************************************************************/
469 /***************************************************************************/
470 /* Optional fields */
471 /***************************************************************************/
472 evel_enc_kv_opt_string(jbuf, "compressedSip", &event->compressed_sip);
473 evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
474 evel_enc_kv_opt_string(jbuf, "localIpAddress", &event->local_ip_address);
475 evel_enc_kv_opt_string(jbuf, "localPort", &event->local_port);
476 evel_enc_kv_opt_string(jbuf, "remoteIpAddress", &event->remote_ip_address);
477 evel_enc_kv_opt_string(jbuf, "remotePort", &event->remote_port);
478 evel_enc_version(jbuf, "signalingFieldsVersion", event->major_version,event->minor_version);
479 evel_enc_kv_opt_string(jbuf, "summarySip", &event->summary_sip);
480 evel_json_encode_vendor_field(jbuf, &event->vnfname_field);
483 /***************************************************************************/
484 /* Checkpoint, so that we can wind back if all fields are suppressed. */
485 /***************************************************************************/
486 evel_json_checkpoint(jbuf);
487 if (evel_json_open_opt_named_list(jbuf, "additionalInformation"))
489 bool item_added = false;
491 addl_info_item = dlist_get_first(&event->additional_info);
492 while (addl_info_item != NULL)
494 addl_info = (SIGNALING_ADDL_FIELD*) addl_info_item->item;
495 assert(addl_info != NULL);
497 if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
498 "additionalInformation",
501 evel_json_open_object(jbuf);
502 evel_enc_kv_string(jbuf, "name", addl_info->name);
503 evel_enc_kv_string(jbuf, "value", addl_info->value);
504 evel_json_close_object(jbuf);
507 addl_info_item = dlist_get_next(addl_info_item);
509 evel_json_close_list(jbuf);
511 /*************************************************************************/
512 /* If we've not written anything, rewind to before we opened the list. */
513 /*************************************************************************/
516 evel_json_rewind(jbuf);
520 evel_json_close_object(jbuf);
525 /**************************************************************************//**
526 * Free a Signaling event.
528 * Free off the event supplied. Will free all the contained allocated memory.
530 * @note It does not free the event itself, since that may be part of a larger
532 *****************************************************************************/
533 void evel_free_signaling(EVENT_SIGNALING * const event)
535 SIGNALING_ADDL_FIELD * addl_info = NULL;
538 /***************************************************************************/
539 /* Check preconditions. As an internal API we don't allow freeing NULL */
540 /* events as we do on the public API. */
541 /***************************************************************************/
542 assert(event != NULL);
543 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
545 /***************************************************************************/
546 /* Free all internal strings then the header itself. */
547 /***************************************************************************/
548 addl_info = dlist_pop_last(&event->additional_info);
549 while (addl_info != NULL)
551 EVEL_DEBUG("Freeing Additional Info (%s, %s)",
554 free(addl_info->name);
555 free(addl_info->value);
557 addl_info = dlist_pop_last(&event->additional_info);
560 evel_free_event_vendor_field(&event->vnfname_field);
561 evel_free_option_string(&event->correlator);
562 evel_free_option_string(&event->local_ip_address);
563 evel_free_option_string(&event->local_port);
564 evel_free_option_string(&event->remote_ip_address);
565 evel_free_option_string(&event->remote_port);
566 evel_free_option_string(&event->compressed_sip);
567 evel_free_option_string(&event->summary_sip);
568 evel_free_header(&event->header);