Add License to VES library
[demo.git] / vnfs / VES / code / evel_library / evel_signaling.c
1 /**************************************************************************//**
2  * @file
3  * Implementation of EVEL functions relating to Signaling.
4  *
5  * License
6  * -------
7  *
8  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
9  *
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
14  *
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  *****************************************************************************/
21
22 #include <string.h>
23 #include <assert.h>
24 #include <stdlib.h>
25
26 #include "evel_throttle.h"
27
28 /**************************************************************************//**
29  * Create a new Signaling event.
30  *
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)
44 {
45   EVENT_SIGNALING * event = NULL;
46
47   EVEL_ENTER();
48
49   /***************************************************************************/
50   /* Check preconditions.                                                    */
51   /***************************************************************************/
52   assert(vendor_id != NULL);
53   assert(event_id != NULL);
54
55   /***************************************************************************/
56   /* Allocate the Signaling event.                                           */
57   /***************************************************************************/
58   event = malloc(sizeof(EVENT_SIGNALING));
59   if (event == NULL)
60   {
61     log_error_state("Out of memory");
62     goto exit_label;
63   }
64   memset(event, 0, sizeof(EVENT_SIGNALING));
65   EVEL_DEBUG("New Signaling event is at %lp", event);
66
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);
82
83 exit_label:
84
85   EVEL_EXIT();
86   return event;
87 }
88
89 /**************************************************************************//**
90  * Set the Event Type property of the Signaling event.
91  *
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.
95  *
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
99  *                      returns.
100  *****************************************************************************/
101 void evel_signaling_type_set(EVENT_SIGNALING * const event,
102                              const char * const type)
103 {
104   EVEL_ENTER();
105
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);
112
113   EVEL_EXIT();
114 }
115
116 /**************************************************************************//**
117  * Set the Local Ip Address property of the Signaling event.
118  *
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.
122  *
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
127  *                      function returns.
128  *****************************************************************************/
129 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
130                                          const char * const local_ip_address)
131 {
132   EVEL_ENTER();
133
134   /***************************************************************************/
135   /* Check preconditions.                                                    */
136   /***************************************************************************/
137   assert(event != NULL);
138   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
139   assert(local_ip_address != NULL);
140
141   evel_set_option_string(&event->local_ip_address,
142                          local_ip_address,
143                          "Local Ip Address");
144
145   EVEL_EXIT();
146 }
147
148 /**************************************************************************//**
149  * Set the Local Port property of the Signaling event.
150  *
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.
154  *
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
158  *                      returns.
159  *****************************************************************************/
160 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
161                                    const char * const local_port)
162 {
163   EVEL_ENTER();
164
165   /***************************************************************************/
166   /* Check preconditions.                                                    */
167   /***************************************************************************/
168   assert(event != NULL);
169   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
170   assert(local_port != NULL);
171
172   evel_set_option_string(&event->local_port,
173                          local_port,
174                          "Local Port");
175
176   EVEL_EXIT();
177 }
178
179 /**************************************************************************//**
180  * Set the Remote Ip Address property of the Signaling event.
181  *
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.
185  *
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
190  *                      function returns.
191  *****************************************************************************/
192 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
193                                           const char * const remote_ip_address)
194 {
195   EVEL_ENTER();
196
197   /***************************************************************************/
198   /* Check preconditions.                                                    */
199   /***************************************************************************/
200   assert(event != NULL);
201   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
202   assert(remote_ip_address != NULL);
203
204   evel_set_option_string(&event->remote_ip_address,
205                          remote_ip_address,
206                          "Remote Ip Address");
207
208   EVEL_EXIT();
209 }
210
211 /**************************************************************************//**
212  * Set the Remote Port property of the Signaling event.
213  *
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.
217  *
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
221  *                      returns.
222  *****************************************************************************/
223 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
224                                     const char * const remote_port)
225 {
226   EVEL_ENTER();
227
228   /***************************************************************************/
229   /* Check preconditions.                                                    */
230   /***************************************************************************/
231   assert(event != NULL);
232   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
233   assert(remote_port != NULL);
234
235   evel_set_option_string(&event->remote_port,
236                          remote_port,
237                          "Remote Port");
238
239   EVEL_EXIT();
240 }
241
242 /**************************************************************************//**
243  * Set the Compressed SIP property of the Signaling event.
244  *
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.
248  *
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
253  *                      returns.
254  *****************************************************************************/
255 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
256                                        const char * const compressed_sip)
257 {
258   EVEL_ENTER();
259
260   /***************************************************************************/
261   /* Check preconditions.                                                    */
262   /***************************************************************************/
263   assert(event != NULL);
264   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
265   assert(compressed_sip != NULL);
266
267   evel_set_option_string(&event->compressed_sip,
268                          compressed_sip,
269                          "Compressed SIP");
270
271   EVEL_EXIT();
272 }
273
274 /**************************************************************************//**
275  * Set the Summary SIP property of the Signaling event.
276  *
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.
280  *
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
284  *                      returns.
285  *****************************************************************************/
286 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
287                                     const char * const summary_sip)
288 {
289   EVEL_ENTER();
290
291   /***************************************************************************/
292   /* Check preconditions.                                                    */
293   /***************************************************************************/
294   assert(event != NULL);
295   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
296   assert(summary_sip != NULL);
297
298   evel_set_option_string(&event->summary_sip,
299                          summary_sip,
300                          "Summary SIP");
301
302   EVEL_EXIT();
303 }
304
305 /**************************************************************************//**
306  * Set the Product Id property of the Signaling event.
307  *
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.
311  *
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
315  *                      function returns.
316  *****************************************************************************/
317 void evel_signaling_product_id_set(EVENT_SIGNALING * const event,
318                                    const char * const product_id)
319 {
320   EVEL_ENTER();
321
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,
328                          product_id,
329                          "Product Id");
330
331   EVEL_EXIT();
332 }
333
334 /**************************************************************************//**
335  * Set the Subsystem Id property of the Signaling event.
336  *
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.
340  *
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
344  *                      function returns.
345  *****************************************************************************/
346 void evel_signaling_subsystem_id_set(EVENT_SIGNALING * const event,
347                                      const char * const subsystem_id)
348 {
349   EVEL_ENTER();
350
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,
357                          subsystem_id,
358                          "Subsystem Id");
359
360   EVEL_EXIT();
361 }
362
363 /**************************************************************************//**
364  * Set the Friendly Name property of the Signaling event.
365  *
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.
369  *
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
373  *                      function returns.
374  *****************************************************************************/
375 void evel_signaling_friendly_name_set(EVENT_SIGNALING * const event,
376                                       const char * const friendly_name)
377 {
378   EVEL_ENTER();
379
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,
386                          friendly_name,
387                          "Friendly Name");
388
389   EVEL_EXIT();
390 }
391
392 /**************************************************************************//**
393  * Set the Correlator property of the Signaling event.
394  *
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.
398  *
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
402  *                      returns.
403  *****************************************************************************/
404 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
405                                    const char * const correlator)
406 {
407   EVEL_ENTER();
408
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,
415                          correlator,
416                          "Correlator");
417
418   EVEL_EXIT();
419 }
420
421 /**************************************************************************//**
422  * Encode the Signaling in JSON according to AT&T's schema for the
423  * event type.
424  *
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)
430 {
431   EVEL_ENTER();
432
433   /***************************************************************************/
434   /* Check preconditions.                                                    */
435   /***************************************************************************/
436   assert(event != NULL);
437   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
438
439   evel_json_encode_header(jbuf, &event->header);
440   evel_json_open_named_object(jbuf, "signalingFields");
441
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);
450
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);
462
463   EVEL_EXIT();
464 }
465
466 /**************************************************************************//**
467  * Free a Signaling event.
468  *
469  * Free off the event supplied.  Will free all the contained allocated memory.
470  *
471  * @note It does not free the event itself, since that may be part of a larger
472  * structure.
473  *****************************************************************************/
474 void evel_free_signaling(EVENT_SIGNALING * const event)
475 {
476   EVEL_ENTER();
477
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);
484
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);
494
495   EVEL_EXIT();
496 }