1 /**************************************************************************//**
3 * Implementation of EVEL functions relating to Signaling.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement: This product includes
18 * software developed by the AT&T.
19 * 4. Neither the name of AT&T nor the names of its contributors may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *****************************************************************************/
39 #include "evel_throttle.h"
41 /**************************************************************************//**
42 * Create a new Signaling event.
44 * @note The mandatory fields on the Signaling must be supplied to
45 * this factory function and are immutable once set. Optional fields
46 * have explicit setter functions, but again values may only be set
47 * once so that the event has immutable properties.
48 * @param vendor_name The vendor id to encode in the event vnf field.
49 * @param module The module to encode in the event.
50 * @param vnfname The Virtual network function to encode in the event.
51 * @returns pointer to the newly manufactured ::EVENT_SIGNALING. If the event
52 * is not used (i.e. posted) it must be released using
53 * ::evel_free_signaling.
54 * @retval NULL Failed to create the event.
55 *****************************************************************************/
56 EVENT_SIGNALING * evel_new_signaling(const char * const vendor_name,
57 const char * const correlator,
58 const char * const local_ip_address,
59 const char * const local_port,
60 const char * const remote_ip_address,
61 const char * const remote_port)
63 EVENT_SIGNALING * event = NULL;
67 /***************************************************************************/
68 /* Check preconditions. */
69 /***************************************************************************/
70 assert(vendor_name != NULL);
72 /***************************************************************************/
73 /* Allocate the Signaling event. */
74 /***************************************************************************/
75 event = malloc(sizeof(EVENT_SIGNALING));
78 log_error_state("Out of memory");
81 memset(event, 0, sizeof(EVENT_SIGNALING));
82 EVEL_DEBUG("New Signaling event is at %lp", event);
84 /***************************************************************************/
85 /* Initialize the header & the Signaling fields. */
86 /***************************************************************************/
87 evel_init_header(&event->header,"SipSignaling");
88 event->header.event_domain = EVEL_DOMAIN_SIPSIGNALING;
89 event->major_version = EVEL_SIGNALING_MAJOR_VERSION;
90 event->minor_version = EVEL_SIGNALING_MINOR_VERSION;
91 evel_init_vendor_field(&event->vnfname_field, vendor_name);
92 evel_set_option_string(&event->correlator,correlator,"Init correlator");
93 evel_set_option_string(&event->local_ip_address,local_ip_address,"Init correlator");
94 evel_set_option_string(&event->local_port,local_port,"Init local port");
95 evel_set_option_string(&event->remote_ip_address,remote_ip_address,"Init remote ip");
96 evel_set_option_string(&event->remote_port,remote_port,"Init remote port");
97 evel_init_option_string(&event->compressed_sip);
98 evel_init_option_string(&event->summary_sip);
99 dlist_initialize(&event->additional_info);
107 /**************************************************************************//**
108 * Add an additional value name/value pair to the SIP signaling.
110 * The name and value are null delimited ASCII strings. The library takes
111 * a copy so the caller does not have to preserve values after the function
114 * @param event Pointer to the fault.
115 * @param name ASCIIZ string with the attribute's name. The caller
116 * does not need to preserve the value once the function
118 * @param value ASCIIZ string with the attribute's value. The caller
119 * does not need to preserve the value once the function
121 *****************************************************************************/
122 void evel_signaling_addl_info_add(EVENT_SIGNALING * event, char * name, char * value)
124 FAULT_ADDL_INFO * addl_info = NULL;
127 /***************************************************************************/
128 /* Check preconditions. */
129 /***************************************************************************/
130 assert(event != NULL);
131 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
132 assert(name != NULL);
133 assert(value != NULL);
135 EVEL_DEBUG("Adding name=%s value=%s", name, value);
136 addl_info = malloc(sizeof(SIGNALING_ADDL_FIELD));
137 assert(addl_info != NULL);
138 memset(addl_info, 0, sizeof(SIGNALING_ADDL_FIELD));
139 addl_info->name = strdup(name);
140 addl_info->value = strdup(value);
141 assert(addl_info->name != NULL);
142 assert(addl_info->value != NULL);
144 dlist_push_last(&event->additional_info, addl_info);
150 /**************************************************************************//**
151 * Set the Event Type property of the Signaling event.
153 * @note The property is treated as immutable: it is only valid to call
154 * the setter once. However, we don't assert if the caller tries to
155 * overwrite, just ignoring the update instead.
157 * @param event Pointer to the Signaling event.
158 * @param type The Event Type to be set. ASCIIZ string. The caller
159 * does not need to preserve the value once the function
161 *****************************************************************************/
162 void evel_signaling_type_set(EVENT_SIGNALING * const event,
163 const char * const type)
167 /***************************************************************************/
168 /* Check preconditions and call evel_header_type_set. */
169 /***************************************************************************/
170 assert(event != NULL);
171 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
172 evel_header_type_set(&event->header, type);
177 /**************************************************************************//**
178 * Set the Local Ip Address property of the Signaling event.
180 * @note The property is treated as immutable: it is only valid to call
181 * the setter once. However, we don't assert if the caller tries to
182 * overwrite, just ignoring the update instead.
184 * @param event Pointer to the Signaling event.
185 * @param local_ip_address
186 * The Local Ip Address to be set. ASCIIZ string. The
187 * caller does not need to preserve the value once the
189 *****************************************************************************/
190 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
191 const char * const local_ip_address)
195 /***************************************************************************/
196 /* Check preconditions. */
197 /***************************************************************************/
198 assert(event != NULL);
199 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
200 assert(local_ip_address != NULL);
202 evel_set_option_string(&event->local_ip_address,
209 /**************************************************************************//**
210 * Set the Local Port property of the Signaling event.
212 * @note The property is treated as immutable: it is only valid to call
213 * the setter once. However, we don't assert if the caller tries to
214 * overwrite, just ignoring the update instead.
216 * @param event Pointer to the Signaling event.
217 * @param local_port The Local Port to be set. ASCIIZ string. The caller
218 * does not need to preserve the value once the function
220 *****************************************************************************/
221 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
222 const char * const local_port)
226 /***************************************************************************/
227 /* Check preconditions. */
228 /***************************************************************************/
229 assert(event != NULL);
230 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
231 assert(local_port != NULL);
233 evel_set_option_string(&event->local_port,
240 /**************************************************************************//**
241 * Set the Remote Ip Address property of the Signaling event.
243 * @note The property is treated as immutable: it is only valid to call
244 * the setter once. However, we don't assert if the caller tries to
245 * overwrite, just ignoring the update instead.
247 * @param event Pointer to the Signaling event.
248 * @param remote_ip_address
249 * The Remote Ip Address to be set. ASCIIZ string. The
250 * caller does not need to preserve the value once the
252 *****************************************************************************/
253 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
254 const char * const remote_ip_address)
258 /***************************************************************************/
259 /* Check preconditions. */
260 /***************************************************************************/
261 assert(event != NULL);
262 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
263 assert(remote_ip_address != NULL);
265 evel_set_option_string(&event->remote_ip_address,
267 "Remote Ip Address");
272 /**************************************************************************//**
273 * Set the Remote Port property of the Signaling event.
275 * @note The property is treated as immutable: it is only valid to call
276 * the setter once. However, we don't assert if the caller tries to
277 * overwrite, just ignoring the update instead.
279 * @param event Pointer to the Signaling event.
280 * @param remote_port The Remote Port to be set. ASCIIZ string. The caller
281 * does not need to preserve the value once the function
283 *****************************************************************************/
284 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
285 const char * const remote_port)
289 /***************************************************************************/
290 /* Check preconditions. */
291 /***************************************************************************/
292 assert(event != NULL);
293 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
294 assert(remote_port != NULL);
296 evel_set_option_string(&event->remote_port,
303 /**************************************************************************//**
304 * Set the Vendor module property of the Signaling event.
306 * @note The property is treated as immutable: it is only valid to call
307 * the setter once. However, we don't assert if the caller tries to
308 * overwrite, just ignoring the update instead.
310 * @param event Pointer to the Signaling event.
311 * @param modulename The module name to be set. ASCIIZ string. The caller
312 * does not need to preserve the value once the function
314 *****************************************************************************/
315 void evel_signaling_vnfmodule_name_set(EVENT_SIGNALING * const event,
316 const char * const module_name)
320 /***************************************************************************/
321 /* Check preconditions. */
322 /***************************************************************************/
323 assert(event != NULL);
324 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
325 assert(module_name != NULL);
327 evel_vendor_field_module_set(&event->vnfname_field, module_name);
332 /**************************************************************************//**
333 * Set the Vendor module property of the Signaling event.
335 * @note The property is treated as immutable: it is only valid to call
336 * the setter once. However, we don't assert if the caller tries to
337 * overwrite, just ignoring the update instead.
339 * @param event Pointer to the Signaling event.
340 * @param vnfname The Virtual Network function to be set. ASCIIZ string.
341 * The caller does not need to preserve the value once
342 * the function returns.
343 *****************************************************************************/
344 void evel_signaling_vnfname_set(EVENT_SIGNALING * const event,
345 const char * const vnfname)
349 /***************************************************************************/
350 /* Check preconditions. */
351 /***************************************************************************/
352 assert(event != NULL);
353 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
354 assert(vnfname != NULL);
356 evel_vendor_field_vnfname_set(&event->vnfname_field, vnfname);
361 /**************************************************************************//**
362 * Set the Compressed SIP property of the Signaling event.
364 * @note The property is treated as immutable: it is only valid to call
365 * the setter once. However, we don't assert if the caller tries to
366 * overwrite, just ignoring the update instead.
368 * @param event Pointer to the Signaling event.
369 * @param compressed_sip
370 * The Compressed SIP to be set. ASCIIZ string. The caller
371 * does not need to preserve the value once the function
373 *****************************************************************************/
374 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
375 const char * const compressed_sip)
379 /***************************************************************************/
380 /* Check preconditions. */
381 /***************************************************************************/
382 assert(event != NULL);
383 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
384 assert(compressed_sip != NULL);
386 evel_set_option_string(&event->compressed_sip,
393 /**************************************************************************//**
394 * Set the Summary SIP property of the Signaling event.
396 * @note The property is treated as immutable: it is only valid to call
397 * the setter once. However, we don't assert if the caller tries to
398 * overwrite, just ignoring the update instead.
400 * @param event Pointer to the Signaling event.
401 * @param summary_sip The Summary SIP to be set. ASCIIZ string. The caller
402 * does not need to preserve the value once the function
404 *****************************************************************************/
405 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
406 const char * const summary_sip)
410 /***************************************************************************/
411 /* Check preconditions. */
412 /***************************************************************************/
413 assert(event != NULL);
414 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
415 assert(summary_sip != NULL);
417 evel_set_option_string(&event->summary_sip,
424 /**************************************************************************//**
425 * Set the Correlator property of the Signaling event.
427 * @note The property is treated as immutable: it is only valid to call
428 * the setter once. However, we don't assert if the caller tries to
429 * overwrite, just ignoring the update instead.
431 * @param event Pointer to the Signaling event.
432 * @param correlator The correlator to be set. ASCIIZ string. The caller
433 * does not need to preserve the value once the function
435 *****************************************************************************/
436 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
437 const char * const correlator)
441 /***************************************************************************/
442 /* Check preconditions and call evel_header_type_set. */
443 /***************************************************************************/
444 assert(event != NULL);
445 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
446 evel_set_option_string(&event->correlator,
453 /**************************************************************************//**
454 * Encode the Signaling in JSON according to AT&T's schema for the
457 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
458 * @param event Pointer to the ::EVENT_HEADER to encode.
459 *****************************************************************************/
460 void evel_json_encode_signaling(EVEL_JSON_BUFFER * const jbuf,
461 EVENT_SIGNALING * const event)
463 SIGNALING_ADDL_FIELD * addl_info = NULL;
464 DLIST_ITEM * addl_info_item = NULL;
468 /***************************************************************************/
469 /* Check preconditions. */
470 /***************************************************************************/
471 assert(event != NULL);
472 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
474 evel_json_encode_header(jbuf, &event->header);
475 evel_json_open_named_object(jbuf, "signalingFields");
477 /***************************************************************************/
478 /* Mandatory fields */
479 /***************************************************************************/
481 /***************************************************************************/
482 /* Optional fields */
483 /***************************************************************************/
484 evel_enc_kv_opt_string(jbuf, "compressedSip", &event->compressed_sip);
485 evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
486 evel_enc_kv_opt_string(jbuf, "localIpAddress", &event->local_ip_address);
487 evel_enc_kv_opt_string(jbuf, "localPort", &event->local_port);
488 evel_enc_kv_opt_string(jbuf, "remoteIpAddress", &event->remote_ip_address);
489 evel_enc_kv_opt_string(jbuf, "remotePort", &event->remote_port);
490 evel_enc_version(jbuf, "signalingFieldsVersion", event->major_version,event->minor_version);
491 evel_enc_kv_opt_string(jbuf, "summarySip", &event->summary_sip);
492 evel_json_encode_vendor_field(jbuf, &event->vnfname_field);
495 /***************************************************************************/
496 /* Checkpoint, so that we can wind back if all fields are suppressed. */
497 /***************************************************************************/
498 evel_json_checkpoint(jbuf);
499 if (evel_json_open_opt_named_list(jbuf, "additionalInformation"))
501 bool item_added = false;
503 addl_info_item = dlist_get_first(&event->additional_info);
504 while (addl_info_item != NULL)
506 addl_info = (SIGNALING_ADDL_FIELD*) addl_info_item->item;
507 assert(addl_info != NULL);
509 if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
510 "additionalInformation",
513 evel_json_open_object(jbuf);
514 evel_enc_kv_string(jbuf, "name", addl_info->name);
515 evel_enc_kv_string(jbuf, "value", addl_info->value);
516 evel_json_close_object(jbuf);
519 addl_info_item = dlist_get_next(addl_info_item);
521 evel_json_close_list(jbuf);
523 /*************************************************************************/
524 /* If we've not written anything, rewind to before we opened the list. */
525 /*************************************************************************/
528 evel_json_rewind(jbuf);
532 evel_json_close_object(jbuf);
537 /**************************************************************************//**
538 * Free a Signaling event.
540 * Free off the event supplied. Will free all the contained allocated memory.
542 * @note It does not free the event itself, since that may be part of a larger
544 *****************************************************************************/
545 void evel_free_signaling(EVENT_SIGNALING * const event)
547 SIGNALING_ADDL_FIELD * addl_info = NULL;
550 /***************************************************************************/
551 /* Check preconditions. As an internal API we don't allow freeing NULL */
552 /* events as we do on the public API. */
553 /***************************************************************************/
554 assert(event != NULL);
555 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
557 /***************************************************************************/
558 /* Free all internal strings then the header itself. */
559 /***************************************************************************/
560 addl_info = dlist_pop_last(&event->additional_info);
561 while (addl_info != NULL)
563 EVEL_DEBUG("Freeing Additional Info (%s, %s)",
566 free(addl_info->name);
567 free(addl_info->value);
569 addl_info = dlist_pop_last(&event->additional_info);
572 evel_free_event_vendor_field(&event->vnfname_field);
573 evel_free_option_string(&event->correlator);
574 evel_free_option_string(&event->local_ip_address);
575 evel_free_option_string(&event->local_port);
576 evel_free_option_string(&event->remote_ip_address);
577 evel_free_option_string(&event->remote_port);
578 evel_free_option_string(&event->compressed_sip);
579 evel_free_option_string(&event->summary_sip);
580 evel_free_header(&event->header);