1 /**************************************************************************//**
3 * Implementation of EVEL functions relating to Signaling.
8 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *****************************************************************************/
26 #include "evel_throttle.h"
28 /**************************************************************************//**
29 * Create a new Signaling event.
31 * @note The mandatory fields on the Signaling must be supplied to
32 * this factory function and are immutable once set. Optional fields
33 * have explicit setter functions, but again values may only be set
34 * once so that the event has immutable properties.
35 * @param vendor_id The vendor id to encode in the event instance id.
36 * @param event_id The vendor event id to encode in the event instance id.
37 * @returns pointer to the newly manufactured ::EVENT_SIGNALING. If the event
38 * is not used (i.e. posted) it must be released using
39 * ::evel_free_signaling.
40 * @retval NULL Failed to create the event.
41 *****************************************************************************/
42 EVENT_SIGNALING * evel_new_signaling(const char * const vendor_id,
43 const char * const event_id)
45 EVENT_SIGNALING * event = NULL;
49 /***************************************************************************/
50 /* Check preconditions. */
51 /***************************************************************************/
52 assert(vendor_id != NULL);
53 assert(event_id != NULL);
55 /***************************************************************************/
56 /* Allocate the Signaling event. */
57 /***************************************************************************/
58 event = malloc(sizeof(EVENT_SIGNALING));
61 log_error_state("Out of memory");
64 memset(event, 0, sizeof(EVENT_SIGNALING));
65 EVEL_DEBUG("New Signaling event is at %lp", event);
67 /***************************************************************************/
68 /* Initialize the header & the Signaling fields. */
69 /***************************************************************************/
70 evel_init_header(&event->header);
71 event->header.event_domain = EVEL_DOMAIN_SIGNALING;
72 event->major_version = EVEL_SIGNALING_MAJOR_VERSION;
73 event->minor_version = EVEL_SIGNALING_MINOR_VERSION;
74 evel_init_event_instance_id(&event->instance_id, vendor_id, event_id);
75 evel_init_option_string(&event->correlator);
76 evel_init_option_string(&event->local_ip_address);
77 evel_init_option_string(&event->local_port);
78 evel_init_option_string(&event->remote_ip_address);
79 evel_init_option_string(&event->remote_port);
80 evel_init_option_string(&event->compressed_sip);
81 evel_init_option_string(&event->summary_sip);
89 /**************************************************************************//**
90 * Set the Event Type property of the Signaling event.
92 * @note The property is treated as immutable: it is only valid to call
93 * the setter once. However, we don't assert if the caller tries to
94 * overwrite, just ignoring the update instead.
96 * @param event Pointer to the Signaling event.
97 * @param type The Event Type to be set. ASCIIZ string. The caller
98 * does not need to preserve the value once the function
100 *****************************************************************************/
101 void evel_signaling_type_set(EVENT_SIGNALING * const event,
102 const char * const type)
106 /***************************************************************************/
107 /* Check preconditions and call evel_header_type_set. */
108 /***************************************************************************/
109 assert(event != NULL);
110 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
111 evel_header_type_set(&event->header, type);
116 /**************************************************************************//**
117 * Set the Local Ip Address property of the Signaling event.
119 * @note The property is treated as immutable: it is only valid to call
120 * the setter once. However, we don't assert if the caller tries to
121 * overwrite, just ignoring the update instead.
123 * @param event Pointer to the Signaling event.
124 * @param local_ip_address
125 * The Local Ip Address to be set. ASCIIZ string. The
126 * caller does not need to preserve the value once the
128 *****************************************************************************/
129 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
130 const char * const local_ip_address)
134 /***************************************************************************/
135 /* Check preconditions. */
136 /***************************************************************************/
137 assert(event != NULL);
138 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
139 assert(local_ip_address != NULL);
141 evel_set_option_string(&event->local_ip_address,
148 /**************************************************************************//**
149 * Set the Local Port property of the Signaling event.
151 * @note The property is treated as immutable: it is only valid to call
152 * the setter once. However, we don't assert if the caller tries to
153 * overwrite, just ignoring the update instead.
155 * @param event Pointer to the Signaling event.
156 * @param local_port The Local Port to be set. ASCIIZ string. The caller
157 * does not need to preserve the value once the function
159 *****************************************************************************/
160 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
161 const char * const local_port)
165 /***************************************************************************/
166 /* Check preconditions. */
167 /***************************************************************************/
168 assert(event != NULL);
169 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
170 assert(local_port != NULL);
172 evel_set_option_string(&event->local_port,
179 /**************************************************************************//**
180 * Set the Remote Ip Address property of the Signaling event.
182 * @note The property is treated as immutable: it is only valid to call
183 * the setter once. However, we don't assert if the caller tries to
184 * overwrite, just ignoring the update instead.
186 * @param event Pointer to the Signaling event.
187 * @param remote_ip_address
188 * The Remote Ip Address to be set. ASCIIZ string. The
189 * caller does not need to preserve the value once the
191 *****************************************************************************/
192 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
193 const char * const remote_ip_address)
197 /***************************************************************************/
198 /* Check preconditions. */
199 /***************************************************************************/
200 assert(event != NULL);
201 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
202 assert(remote_ip_address != NULL);
204 evel_set_option_string(&event->remote_ip_address,
206 "Remote Ip Address");
211 /**************************************************************************//**
212 * Set the Remote Port property of the Signaling event.
214 * @note The property is treated as immutable: it is only valid to call
215 * the setter once. However, we don't assert if the caller tries to
216 * overwrite, just ignoring the update instead.
218 * @param event Pointer to the Signaling event.
219 * @param remote_port The Remote Port to be set. ASCIIZ string. The caller
220 * does not need to preserve the value once the function
222 *****************************************************************************/
223 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
224 const char * const remote_port)
228 /***************************************************************************/
229 /* Check preconditions. */
230 /***************************************************************************/
231 assert(event != NULL);
232 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
233 assert(remote_port != NULL);
235 evel_set_option_string(&event->remote_port,
242 /**************************************************************************//**
243 * Set the Compressed SIP property of the Signaling event.
245 * @note The property is treated as immutable: it is only valid to call
246 * the setter once. However, we don't assert if the caller tries to
247 * overwrite, just ignoring the update instead.
249 * @param event Pointer to the Signaling event.
250 * @param compressed_sip
251 * The Compressed SIP to be set. ASCIIZ string. The caller
252 * does not need to preserve the value once the function
254 *****************************************************************************/
255 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
256 const char * const compressed_sip)
260 /***************************************************************************/
261 /* Check preconditions. */
262 /***************************************************************************/
263 assert(event != NULL);
264 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
265 assert(compressed_sip != NULL);
267 evel_set_option_string(&event->compressed_sip,
274 /**************************************************************************//**
275 * Set the Summary SIP property of the Signaling event.
277 * @note The property is treated as immutable: it is only valid to call
278 * the setter once. However, we don't assert if the caller tries to
279 * overwrite, just ignoring the update instead.
281 * @param event Pointer to the Signaling event.
282 * @param summary_sip The Summary SIP to be set. ASCIIZ string. The caller
283 * does not need to preserve the value once the function
285 *****************************************************************************/
286 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
287 const char * const summary_sip)
291 /***************************************************************************/
292 /* Check preconditions. */
293 /***************************************************************************/
294 assert(event != NULL);
295 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
296 assert(summary_sip != NULL);
298 evel_set_option_string(&event->summary_sip,
305 /**************************************************************************//**
306 * Set the Product Id property of the Signaling event.
308 * @note The property is treated as immutable: it is only valid to call
309 * the setter once. However, we don't assert if the caller tries to
310 * overwrite, just ignoring the update instead.
312 * @param event Pointer to the Signaling event.
313 * @param product_id The vendor product id to be set. ASCIIZ string. The
314 * caller does not need to preserve the value once the
316 *****************************************************************************/
317 void evel_signaling_product_id_set(EVENT_SIGNALING * const event,
318 const char * const product_id)
322 /***************************************************************************/
323 /* Check preconditions and call evel_header_type_set. */
324 /***************************************************************************/
325 assert(event != NULL);
326 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
327 evel_set_option_string(&event->instance_id.product_id,
334 /**************************************************************************//**
335 * Set the Subsystem Id property of the Signaling event.
337 * @note The property is treated as immutable: it is only valid to call
338 * the setter once. However, we don't assert if the caller tries to
339 * overwrite, just ignoring the update instead.
341 * @param event Pointer to the Signaling event.
342 * @param subsystem_id The vendor subsystem id to be set. ASCIIZ string. The
343 * caller does not need to preserve the value once the
345 *****************************************************************************/
346 void evel_signaling_subsystem_id_set(EVENT_SIGNALING * const event,
347 const char * const subsystem_id)
351 /***************************************************************************/
352 /* Check preconditions and call evel_header_type_set. */
353 /***************************************************************************/
354 assert(event != NULL);
355 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
356 evel_set_option_string(&event->instance_id.subsystem_id,
363 /**************************************************************************//**
364 * Set the Friendly Name property of the Signaling event.
366 * @note The property is treated as immutable: it is only valid to call
367 * the setter once. However, we don't assert if the caller tries to
368 * overwrite, just ignoring the update instead.
370 * @param event Pointer to the Signaling event.
371 * @param friendly_name The vendor friendly name to be set. ASCIIZ string. The
372 * caller does not need to preserve the value once the
374 *****************************************************************************/
375 void evel_signaling_friendly_name_set(EVENT_SIGNALING * const event,
376 const char * const friendly_name)
380 /***************************************************************************/
381 /* Check preconditions and call evel_header_type_set. */
382 /***************************************************************************/
383 assert(event != NULL);
384 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
385 evel_set_option_string(&event->instance_id.event_friendly_name,
392 /**************************************************************************//**
393 * Set the Correlator property of the Signaling event.
395 * @note The property is treated as immutable: it is only valid to call
396 * the setter once. However, we don't assert if the caller tries to
397 * overwrite, just ignoring the update instead.
399 * @param event Pointer to the Signaling event.
400 * @param correlator The correlator to be set. ASCIIZ string. The caller
401 * does not need to preserve the value once the function
403 *****************************************************************************/
404 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
405 const char * const correlator)
409 /***************************************************************************/
410 /* Check preconditions and call evel_header_type_set. */
411 /***************************************************************************/
412 assert(event != NULL);
413 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
414 evel_set_option_string(&event->correlator,
421 /**************************************************************************//**
422 * Encode the Signaling in JSON according to AT&T's schema for the
425 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
426 * @param event Pointer to the ::EVENT_HEADER to encode.
427 *****************************************************************************/
428 void evel_json_encode_signaling(EVEL_JSON_BUFFER * const jbuf,
429 EVENT_SIGNALING * const event)
433 /***************************************************************************/
434 /* Check preconditions. */
435 /***************************************************************************/
436 assert(event != NULL);
437 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
439 evel_json_encode_header(jbuf, &event->header);
440 evel_json_open_named_object(jbuf, "signalingFields");
442 /***************************************************************************/
443 /* Mandatory fields */
444 /***************************************************************************/
445 evel_json_encode_instance_id(jbuf, &event->instance_id);
446 evel_enc_version(jbuf,
447 "signalingFieldsVersion",
448 event->major_version,
449 event->minor_version);
451 /***************************************************************************/
452 /* Optional fields */
453 /***************************************************************************/
454 evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
455 evel_enc_kv_opt_string(jbuf, "localIpAddress", &event->local_ip_address);
456 evel_enc_kv_opt_string(jbuf, "localPort", &event->local_port);
457 evel_enc_kv_opt_string(jbuf, "remoteIpAddress", &event->remote_ip_address);
458 evel_enc_kv_opt_string(jbuf, "remotePort", &event->remote_port);
459 evel_enc_kv_opt_string(jbuf, "compressedSip", &event->compressed_sip);
460 evel_enc_kv_opt_string(jbuf, "summarySip", &event->summary_sip);
461 evel_json_close_object(jbuf);
466 /**************************************************************************//**
467 * Free a Signaling event.
469 * Free off the event supplied. Will free all the contained allocated memory.
471 * @note It does not free the event itself, since that may be part of a larger
473 *****************************************************************************/
474 void evel_free_signaling(EVENT_SIGNALING * const event)
478 /***************************************************************************/
479 /* Check preconditions. As an internal API we don't allow freeing NULL */
480 /* events as we do on the public API. */
481 /***************************************************************************/
482 assert(event != NULL);
483 assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
485 evel_free_header(&event->header);
486 evel_free_event_instance_id(&event->instance_id);
487 evel_free_option_string(&event->correlator);
488 evel_free_option_string(&event->local_ip_address);
489 evel_free_option_string(&event->local_port);
490 evel_free_option_string(&event->remote_ip_address);
491 evel_free_option_string(&event->remote_port);
492 evel_free_option_string(&event->compressed_sip);
493 evel_free_option_string(&event->summary_sip);