Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
aoc.c File Reference

generic AOC payload generation encoding and decoding More...

#include "asterisk.h"
#include "asterisk/aoc.h"
#include "asterisk/utils.h"
#include "asterisk/strings.h"
#include "asterisk/_private.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_message_router.h"

Go to the source code of this file.

Data Structures

struct  aoc_event_blob
 
struct  aoc_ie_billing
 
struct  aoc_ie_charging_association
 
struct  aoc_ie_charging_rate
 
struct  aoc_ie_currency
 
struct  aoc_ie_data
 
struct  aoc_ie_unit
 
struct  aoc_pl_ie_hdr
 AOC IE payload header. More...
 
struct  ast_aoc_decoded
 
struct  ast_aoc_encoded
 

Macros

#define AST_AOC_ENCODE_VERSION   1
 
#define AST_AOC_ENCODED_CHARGE_CURRENCY   (2 << 5)
 
#define AST_AOC_ENCODED_CHARGE_FREE   (1 << 5)
 
#define AST_AOC_ENCODED_CHARGE_NA   (0 << 5)
 
#define AST_AOC_ENCODED_CHARGE_SUBTOTAL   (1 << 7)
 
#define AST_AOC_ENCODED_CHARGE_TOTAL   (0 << 7)
 
#define AST_AOC_ENCODED_CHARGE_UNIT   (3 << 5)
 
#define AST_AOC_ENCODED_REQUEST_D   (1 << 3)
 
#define AST_AOC_ENCODED_REQUEST_E   (1 << 4)
 
#define AST_AOC_ENCODED_REQUEST_S   (1 << 2)
 
#define AST_AOC_ENCODED_TYPE_D   (1 << 0)
 
#define AST_AOC_ENCODED_TYPE_E   (2 << 0)
 
#define AST_AOC_ENCODED_TYPE_REQUEST   (0 << 0)
 
#define AST_AOC_ENCODED_TYPE_S   (3 << 0)
 

Enumerations

enum  AOC_IE {
  AOC_IE_CURRENCY = 1, AOC_IE_UNIT = 2, AOC_IE_BILLING = 3, AOC_IE_CHARGING_ASSOCIATION = 4,
  AOC_IE_RATE = 5, AOC_IE_TERMINATION_REQUEST = 6
}
 AOC Payload Information Elements.
 

Functions

static void aoc_amount_str (struct ast_str **msg, const char *prefix, unsigned int amount, enum ast_aoc_currency_multiplier mult)
 
static int aoc_append_ie (struct aoc_ie_data *ied, unsigned short ie_id, const void *data, unsigned short datalen)
 
static const char * aoc_billingid_str (enum ast_aoc_billing_id billing_id)
 
static const char * aoc_charge_type_str (enum ast_aoc_charge_type value)
 
static const char * aoc_charged_item_str (enum ast_aoc_s_charged_item value)
 
static char * aoc_cli_debug_enable (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void aoc_create_ie_data (struct ast_aoc_decoded *decoded, struct aoc_ie_data *ied)
 
static void aoc_create_ie_data_charging_rate (const struct ast_aoc_s_entry *entry, struct aoc_ie_charging_rate *ie)
 
static void aoc_d_event (const struct ast_aoc_decoded *decoded, struct ast_str **msg)
 
static struct ast_manager_event_blobaoc_d_to_ami (struct stasis_message *message)
 
struct stasis_message_typeaoc_d_type (void)
 
static void aoc_display_decoded_debug (const struct ast_aoc_decoded *decoded, int decoding, struct ast_channel *chan)
 
static void aoc_e_event (const struct ast_aoc_decoded *decoded, struct ast_str **msg)
 
static struct ast_manager_event_blobaoc_e_to_ami (struct stasis_message *message)
 
struct stasis_message_typeaoc_e_type (void)
 
static void aoc_event_blob_dtor (void *obj)
 
static const char * aoc_multiplier_str (enum ast_aoc_currency_multiplier mult)
 
static int aoc_parse_ie (struct ast_aoc_decoded *decoded, unsigned char *data, unsigned int datalen)
 
static void aoc_parse_ie_charging_rate (struct ast_aoc_decoded *decoded, const struct aoc_ie_charging_rate *ie)
 
static void aoc_publish_blob (struct ast_channel *chan, struct stasis_message_type *msg_type, struct ast_json *blob)
 
static const char * aoc_rate_type_str (enum ast_aoc_s_rate_type value)
 
static void aoc_request_event (const struct ast_aoc_decoded *decoded, struct ast_str **msg)
 
static int aoc_s_add_entry (struct ast_aoc_decoded *decoded, struct ast_aoc_s_entry *entry)
 
static void aoc_s_event (const struct ast_aoc_decoded *decoded, struct ast_str **msg)
 
static struct ast_manager_event_blobaoc_s_to_ami (struct stasis_message *message)
 
struct stasis_message_typeaoc_s_type (void)
 
static const char * aoc_scale_str (enum ast_aoc_time_scale value)
 
static void aoc_shutdown (void)
 
static void aoc_time_str (struct ast_str **msg, const char *prefix, const char *name, unsigned long time, enum ast_aoc_time_scale scale)
 
static struct ast_manager_event_blobaoc_to_ami (struct stasis_message *message, const char *event_name)
 
static const char * aoc_type_of_totaling_str (enum ast_aoc_total_type value)
 
static const char * aoc_volume_unit_str (enum ast_aoc_volume_unit value)
 
static struct ast_jsonassociation_to_json (const struct ast_aoc_decoded *decoded)
 
int ast_aoc_add_unit_entry (struct ast_aoc_decoded *decoded, const unsigned int amount_is_present, const unsigned int amount, const unsigned int type_is_present, const unsigned int type)
 Adds a unit entry into the list of units. More...
 
int ast_aoc_cli_init (void)
 enable aoc cli options
 
struct ast_aoc_decodedast_aoc_create (const enum ast_aoc_type msg_type, const enum ast_aoc_charge_type charge_type, const enum ast_aoc_request requests)
 creates a ast_aoc_decode object of a specific message type More...
 
struct ast_aoc_decodedast_aoc_decode (struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
 decodes an encoded aoc payload. More...
 
int ast_aoc_decoded2str (const struct ast_aoc_decoded *decoded, struct ast_str **msg)
 Convert decoded aoc msg to string representation. More...
 
void * ast_aoc_destroy_decoded (struct ast_aoc_decoded *decoded)
 free an ast_aoc_decoded object
 
void * ast_aoc_destroy_encoded (struct ast_aoc_encoded *encoded)
 free an ast_aoc_encoded object
 
struct ast_aoc_encodedast_aoc_encode (struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
 encodes a decoded aoc structure so it can be passed on the wire More...
 
const struct ast_aoc_charging_associationast_aoc_get_association_info (struct ast_aoc_decoded *decoded)
 get the charging association info for AOC-E messages
 
enum ast_aoc_billing_id ast_aoc_get_billing_id (struct ast_aoc_decoded *decoded)
 get the billing id for AOC-D and AOC-E messages
 
enum ast_aoc_charge_type ast_aoc_get_charge_type (struct ast_aoc_decoded *decoded)
 get the charging type for an AOC-D or AOC-E message
 
unsigned int ast_aoc_get_currency_amount (struct ast_aoc_decoded *decoded)
 get the currency amount for AOC-D and AOC-E messages
 
enum ast_aoc_currency_multiplier ast_aoc_get_currency_multiplier (struct ast_aoc_decoded *decoded)
 get the currency multiplier for AOC-D and AOC-E messages
 
const char * ast_aoc_get_currency_multiplier_decimal (struct ast_aoc_decoded *decoded)
 get the currency multiplier for AOC-D and AOC-E messages in decimal format
 
const char * ast_aoc_get_currency_name (struct ast_aoc_decoded *decoded)
 get the currency name for AOC-D and AOC-E messages
 
enum ast_aoc_type ast_aoc_get_msg_type (struct ast_aoc_decoded *decoded)
 get the message type, AOC-D, AOC-E, or AOC Request
 
enum ast_aoc_request ast_aoc_get_request (struct ast_aoc_decoded *decoded)
 get the types of AOC requested for when message type is AOC Request
 
int ast_aoc_get_termination_request (struct ast_aoc_decoded *decoded)
 get whether or not the AST_AOC_REQUEST message as a termination request. More...
 
enum ast_aoc_total_type ast_aoc_get_total_type (struct ast_aoc_decoded *decoded)
 get the type of total for a AOC-D message
 
unsigned int ast_aoc_get_unit_count (struct ast_aoc_decoded *decoded)
 get the number of unit entries for AOC-D and AOC-E messages
 
const struct ast_aoc_unit_entryast_aoc_get_unit_info (struct ast_aoc_decoded *decoded, unsigned int entry_number)
 get a specific unit entry. More...
 
int ast_aoc_manager_event (const struct ast_aoc_decoded *decoded, struct ast_channel *chan)
 generate AOC manager event for an AOC-S, AOC-D, or AOC-E msg More...
 
int ast_aoc_s_add_rate_duration (struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, unsigned int amount, enum ast_aoc_currency_multiplier multiplier, const char *currency_name, unsigned long time, enum ast_aoc_time_scale time_scale, unsigned long granularity_time, enum ast_aoc_time_scale granularity_time_scale, int step_function)
 Add AOC-S duration rate entry. More...
 
int ast_aoc_s_add_rate_flat (struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, unsigned int amount, enum ast_aoc_currency_multiplier multiplier, const char *currency_name)
 Add AOC-S flat rate entry. More...
 
int ast_aoc_s_add_rate_free (struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, int from_beginning)
 Add AOC-S indicating charge item is free. More...
 
int ast_aoc_s_add_rate_na (struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item)
 Add AOC-S entry indicating charge item is not available. More...
 
int ast_aoc_s_add_rate_special_charge_code (struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, unsigned int code)
 Add AOC-S special rate entry. More...
 
int ast_aoc_s_add_rate_volume (struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, enum ast_aoc_volume_unit volume_unit, unsigned int amount, enum ast_aoc_currency_multiplier multiplier, const char *currency_name)
 Add AOC-S volume rate entry. More...
 
int ast_aoc_s_add_special_arrangement (struct ast_aoc_decoded *decoded, unsigned int code)
 Add AOC-S special arrangement entry. More...
 
unsigned int ast_aoc_s_get_count (struct ast_aoc_decoded *decoded)
 get the number rates associated with an AOC-S message
 
const struct ast_aoc_s_entryast_aoc_s_get_rate_info (struct ast_aoc_decoded *decoded, unsigned int entry_number)
 get a specific AOC-S rate entry. More...
 
int ast_aoc_set_association_id (struct ast_aoc_decoded *decoded, const int id)
 set the charging association id for an AST_AOC_E message More...
 
int ast_aoc_set_association_number (struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
 set the charging association number for an AOC-E message More...
 
int ast_aoc_set_billing_id (struct ast_aoc_decoded *decoded, const enum ast_aoc_billing_id id)
 set the billing id for a AOC-D or AST_AOC_E message More...
 
int ast_aoc_set_currency_info (struct ast_aoc_decoded *decoded, const unsigned int amount, const enum ast_aoc_currency_multiplier multiplier, const char *name)
 Sets the currency values for a AOC-D or AOC-E message. More...
 
int ast_aoc_set_termination_request (struct ast_aoc_decoded *decoded)
 Mark the AST_AOC_REQUEST message as a termination request. More...
 
int ast_aoc_set_total_type (struct ast_aoc_decoded *decoded, const enum ast_aoc_total_type type)
 Sets the type of total for a AOC-D message. More...
 
int ast_aoc_test_encode_decode_match (struct ast_aoc_decoded *decoded)
 test aoc encode decode routines. More...
 
static struct ast_jsoncharge_to_json (const struct ast_aoc_decoded *decoded)
 
static struct ast_jsoncurrency_to_json (const char *name, int cost, enum ast_aoc_currency_multiplier mult)
 
static struct ast_jsond_to_json (const struct ast_aoc_decoded *decoded)
 
static struct ast_jsone_to_json (const struct ast_aoc_decoded *decoded)
 
static struct ast_jsons_to_json (const struct ast_aoc_decoded *decoded)
 
 STASIS_MESSAGE_TYPE_DEFN (aoc_s_type,.to_ami=aoc_s_to_ami)
 
 STASIS_MESSAGE_TYPE_DEFN (aoc_d_type,.to_ami=aoc_d_to_ami)
 
 STASIS_MESSAGE_TYPE_DEFN (aoc_e_type,.to_ami=aoc_e_to_ami)
 
static struct ast_jsonunits_to_json (const struct ast_aoc_decoded *decoded)
 

Variables

static struct ast_cli_entry aoc_cli []
 
static char aoc_debug_enabled = 0
 

Detailed Description

generic AOC payload generation encoding and decoding

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file aoc.c.

Function Documentation

int ast_aoc_add_unit_entry ( struct ast_aoc_decoded decoded,
const unsigned int  amount_is_present,
const unsigned int  amount,
const unsigned int  type_is_present,
const unsigned int  type 
)

Adds a unit entry into the list of units.

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
amount_is_presentset this if the number of units is actually present.
amountnumber of units
type_is_presentset this if the type value is present
typeunit type
Note
If neither the amount nor the type is present, the entry will not be added.
Return values
0success

Definition at line 977 of file aoc.c.

982 {
983  if ((decoded->msg_type == AST_AOC_REQUEST) ||
984  (decoded->unit_count >= ARRAY_LEN(decoded->unit_list))) {
985  return -1;
986  }
987 
988  if (!amount_is_present && !type_is_present) {
989  return -1;
990  }
991 
992  decoded->unit_list[decoded->unit_count].valid_amount = amount_is_present;
993  if (amount_is_present) {
994  decoded->unit_list[decoded->unit_count].amount = amount;
995  } else {
996  decoded->unit_list[decoded->unit_count].amount = 0;
997  }
998 
999  decoded->unit_list[decoded->unit_count].valid_type = type_is_present;
1000  if (type_is_present) {
1001  decoded->unit_list[decoded->unit_count].type = type;
1002  } else {
1003  decoded->unit_list[decoded->unit_count].type = 0;
1004  }
1005  decoded->unit_count++;
1006 
1007  return 0;
1008 }
struct ast_aoc_decoded* ast_aoc_create ( const enum ast_aoc_type  msg_type,
const enum ast_aoc_charge_type  charge_type,
const enum ast_aoc_request  requests 
)

creates a ast_aoc_decode object of a specific message type

Since
1.8
Parameters
msg_typeAOC-D, AOC-E, or AOC Request
charge_typethis is ignored if message type is not AOC-D or AOC-E.
requestsflags. This defines the types of AOC requested. This field should only be set when the message type is AOC Request, the value is ignored otherwise.
Return values
heapallocated ast_aoc_decoded object ptr on success
NULLfailure

Definition at line 276 of file aoc.c.

References ast_calloc.

279 {
280  struct ast_aoc_decoded *decoded = NULL;
281 
282  /* verify input */
283  if (((unsigned int) charge_type > AST_AOC_CHARGE_UNIT) ||
284  ((unsigned int) msg_type > AST_AOC_E) ||
285  ((msg_type == AST_AOC_REQUEST) && !requests)) {
286 
287  ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object, invalid input\n");
288  return NULL;
289  }
290 
291  if (!(decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded)))) {
292  ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
293  return NULL;
294  }
295 
296  decoded->msg_type = msg_type;
297 
298  if (msg_type == AST_AOC_REQUEST) {
299  decoded->request_flag = requests;
300  } else if ((msg_type == AST_AOC_D) || (msg_type == AST_AOC_E)) {
301  decoded->charge_type = charge_type;
302  }
303 
304  return decoded;
305 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
struct ast_aoc_decoded* ast_aoc_decode ( struct ast_aoc_encoded encoded,
size_t  size,
struct ast_channel chan 
)

decodes an encoded aoc payload.

Since
1.8
Parameters
encodedthe encoded payload to decode.
sizetotal size of encoded payload
chanast channel, Optional for DEBUG output purposes
Return values
heapallocated ast_aoc_decoded object ptr on success
NULLfailure

Definition at line 449 of file aoc.c.

References ast_calloc.

Referenced by ast_aoc_test_encode_decode_match(), and wait_for_answer().

450 {
451  struct ast_aoc_decoded *decoded;
452 
453  /* verify our encoded payload is actually large enough to hold all the ies */
454  if ((size - (sizeof(struct ast_aoc_encoded)) != ntohs(encoded->datalen))) {
455  ast_log(LOG_WARNING, "Corrupted aoc encoded object, can not decode\n");
456  return NULL;
457  }
458 
459  if (!(decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded)))) {
460  ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
461  return NULL;
462  }
463 
464  /* decode flags */
465 
466  if ((encoded->flags & AST_AOC_ENCODED_TYPE_S) == AST_AOC_ENCODED_TYPE_S) {
467  decoded->msg_type = AST_AOC_S;
468  } else if (encoded->flags & AST_AOC_ENCODED_TYPE_E) {
469  decoded->msg_type = AST_AOC_E;
470  } else if (encoded->flags & AST_AOC_ENCODED_TYPE_D) {
471  decoded->msg_type = AST_AOC_D;
472  } else {
473  decoded->msg_type = AST_AOC_REQUEST;
474  }
475 
476  if (decoded->msg_type == AST_AOC_REQUEST) {
477  if (encoded->flags & AST_AOC_ENCODED_REQUEST_S) {
478  decoded->request_flag |= AST_AOC_REQUEST_S;
479  }
480  if (encoded->flags & AST_AOC_ENCODED_REQUEST_D) {
481  decoded->request_flag |= AST_AOC_REQUEST_D;
482  }
483  if (encoded->flags & AST_AOC_ENCODED_REQUEST_E) {
484  decoded->request_flag |= AST_AOC_REQUEST_E;
485  }
486  } else if ((decoded->msg_type == AST_AOC_D) || (decoded->msg_type == AST_AOC_E)) {
487  if ((encoded->flags & AST_AOC_ENCODED_CHARGE_UNIT) == AST_AOC_ENCODED_CHARGE_UNIT) {
488  decoded->charge_type = AST_AOC_CHARGE_UNIT;
489  } else if ((encoded->flags & AST_AOC_ENCODED_CHARGE_CURRENCY) == AST_AOC_ENCODED_CHARGE_CURRENCY) {
490  decoded->charge_type = AST_AOC_CHARGE_CURRENCY;
491  } else if ((encoded->flags & AST_AOC_ENCODED_CHARGE_FREE) == AST_AOC_ENCODED_CHARGE_FREE) {
492  decoded->charge_type = AST_AOC_CHARGE_FREE;
493  } else {
494  decoded->charge_type = AST_AOC_CHARGE_NA;
495  }
496 
497  if (encoded->flags & AST_AOC_ENCODED_CHARGE_SUBTOTAL) {
498  decoded->total_type = AST_AOC_SUBTOTAL;
499  }
500  }
501 
502  /* decode information elements */
503  aoc_parse_ie(decoded, encoded->data, ntohs(encoded->datalen));
504 
505  if (aoc_debug_enabled) {
506  aoc_display_decoded_debug(decoded, 1, chan);
507  }
508 
509  return decoded;
510 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
int ast_aoc_decoded2str ( const struct ast_aoc_decoded decoded,
struct ast_str **  msg 
)

Convert decoded aoc msg to string representation.

Since
1.8
Parameters
decodedast_aoc_decoded struct to convert to string
msgdynamic heap allocated ast_str object to store string representation in
Return values
0success
-1failure

Definition at line 1954 of file aoc.c.

References ast_str_append().

1955 {
1956  if (!decoded || !msg) {
1957  return -1;
1958  }
1959 
1960  switch (decoded->msg_type) {
1961  case AST_AOC_S:
1962  ast_str_append(msg, 0, "AOC-S\r\n");
1963  aoc_s_event(decoded, msg);
1964  break;
1965  case AST_AOC_D:
1966  ast_str_append(msg, 0, "AOC-D\r\n");
1967  aoc_d_event(decoded, msg);
1968  break;
1969  case AST_AOC_E:
1970  ast_str_append(msg, 0, "AOC-E\r\n");
1971  aoc_e_event(decoded, msg);
1972  break;
1973  case AST_AOC_REQUEST:
1974  ast_str_append(msg, 0, "AOC-Request\r\n");
1975  aoc_request_event(decoded, msg);
1976  break;
1977  }
1978 
1979  return 0;
1980 }
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
struct ast_aoc_encoded* ast_aoc_encode ( struct ast_aoc_decoded decoded,
size_t *  out_size,
struct ast_channel chan 
)

encodes a decoded aoc structure so it can be passed on the wire

Since
1.8
Parameters
decodedthe decoded struct to be encoded
out_sizeoutput parameter representing size of encoded data
chanast channel, Optional for DEBUG output purposes
Return values
pointerto encoded data
NULLfailure

Definition at line 650 of file aoc.c.

References ast_calloc.

Referenced by ast_aoc_test_encode_decode_match(), and wait_for_answer().

651 {
652  struct aoc_ie_data ied;
653  struct ast_aoc_encoded *encoded = NULL;
654  size_t size = 0;
655 
656  if (!decoded || !out_size) {
657  return NULL;
658  }
659 
660  *out_size = 0;
661 
662  /* create information element buffer before allocating the payload,
663  * by doing this the exact size of the payload + the id data can be
664  * allocated all at once. */
665  aoc_create_ie_data(decoded, &ied);
666 
667  size = sizeof(struct ast_aoc_encoded) + ied.pos;
668 
669  if (!(encoded = ast_calloc(1, size))) {
670  ast_log(LOG_WARNING, "Failed to create ast_aoc_encoded object during decode routine. \n");
671  return NULL;
672  }
673 
674  /* -- Set ie data buffer */
675  if (ied.pos) {
676  /* this is safe because encoded was allocated to fit this perfectly */
677  memcpy(encoded->data, ied.buf, ied.pos);
678  encoded->datalen = htons(ied.pos);
679  }
680 
681  /* --- Set Flags --- */
682  switch (decoded->msg_type) {
683  case AST_AOC_S:
684  encoded->flags = AST_AOC_ENCODED_TYPE_S;
685  break;
686  case AST_AOC_D:
687  encoded->flags = AST_AOC_ENCODED_TYPE_D;
688  break;
689  case AST_AOC_E:
690  encoded->flags = AST_AOC_ENCODED_TYPE_E;
691  break;
692  case AST_AOC_REQUEST:
693  encoded->flags = AST_AOC_ENCODED_TYPE_REQUEST;
694  default:
695  break;
696  }
697 
698  /* if it is type request, set the types requested, else set charge type */
699  if (decoded->msg_type == AST_AOC_REQUEST) {
700  if (decoded->request_flag & AST_AOC_REQUEST_S) {
701  encoded->flags |= AST_AOC_ENCODED_REQUEST_S;
702  }
703  if (decoded->request_flag & AST_AOC_REQUEST_D) {
704  encoded->flags |= AST_AOC_ENCODED_REQUEST_D;
705  }
706  if (decoded->request_flag & AST_AOC_REQUEST_E) {
707  encoded->flags |= AST_AOC_ENCODED_REQUEST_E;
708  }
709  } else if ((decoded->msg_type == AST_AOC_D) || (decoded->msg_type == AST_AOC_E)) {
710  switch (decoded->charge_type) {
711  case AST_AOC_CHARGE_UNIT:
712  encoded->flags |= AST_AOC_ENCODED_CHARGE_UNIT;
713  break;
714  case AST_AOC_CHARGE_CURRENCY:
715  encoded->flags |= AST_AOC_ENCODED_CHARGE_CURRENCY;
716  break;
717  case AST_AOC_CHARGE_FREE:
718  encoded->flags |= AST_AOC_ENCODED_CHARGE_FREE;
719  case AST_AOC_CHARGE_NA:
720  default:
721  encoded->flags |= AST_AOC_ENCODED_CHARGE_NA;
722  break;
723  }
724 
725  if (decoded->total_type == AST_AOC_SUBTOTAL) {
726  encoded->flags |= AST_AOC_ENCODED_CHARGE_SUBTOTAL;
727  }
728  }
729 
730  /* --- Set Version Number --- */
731  encoded->version = AST_AOC_ENCODE_VERSION;
732 
733  /* set the output size */
734  *out_size = size;
735 
736  if (aoc_debug_enabled) {
737  aoc_display_decoded_debug(decoded, 0, chan);
738  }
739 
740  return encoded;
741 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
int ast_aoc_get_termination_request ( struct ast_aoc_decoded decoded)

get whether or not the AST_AOC_REQUEST message as a termination request.

Since
1.8
Note
a termination request indicates that the call has terminated, but that the other side is waiting for a short period of time before hanging up so it can get the final AOC-E message.
Parameters
decodedast_aoc_decoded struct to get values on
Return values
0not a termination request
1is a termination request

Definition at line 1079 of file aoc.c.

1080 {
1081  return decoded->termination_request;
1082 }
const struct ast_aoc_unit_entry* ast_aoc_get_unit_info ( struct ast_aoc_decoded decoded,
unsigned int  entry_number 
)

get a specific unit entry.

Since
1.8
Note
This can be used in conjunction with ast_aoc_get_unit_count to create a unit entry iterator.

Definition at line 1010 of file aoc.c.

1011 {
1012  if (entry_number >= decoded->unit_count) {
1013  return NULL;
1014  }
1015 
1016  return (const struct ast_aoc_unit_entry *) &decoded->unit_list[entry_number];
1017 }
Definition: aoc.h:178
int ast_aoc_manager_event ( const struct ast_aoc_decoded decoded,
struct ast_channel chan 
)

generate AOC manager event for an AOC-S, AOC-D, or AOC-E msg

Precondition
chan is locked

Definition at line 1922 of file aoc.c.

References ast_json_unref().

1923 {
1924  struct ast_json *blob;
1925  struct stasis_message_type *msg_type;
1926 
1927  if (!decoded) {
1928  return -1;
1929  }
1930 
1931  switch (decoded->msg_type) {
1932  case AST_AOC_S:
1933  blob = s_to_json(decoded);
1934  msg_type = aoc_s_type();
1935  break;
1936  case AST_AOC_D:
1937  blob = d_to_json(decoded);
1938  msg_type = aoc_d_type();
1939  break;
1940  case AST_AOC_E:
1941  blob = e_to_json(decoded);
1942  msg_type = aoc_e_type();
1943  break;
1944  default:
1945  /* events for AST_AOC_REQUEST are not generated here */
1946  return 0;
1947  }
1948 
1949  aoc_publish_blob(chan, msg_type, blob);
1950  ast_json_unref(blob);
1951  return 0;
1952 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
Abstract JSON element (object, array, string, int, ...).
int ast_aoc_s_add_rate_duration ( struct ast_aoc_decoded decoded,
enum ast_aoc_s_charged_item  charged_item,
unsigned int  amount,
enum ast_aoc_currency_multiplier  multiplier,
const char *  currency_name,
unsigned long  time,
enum ast_aoc_time_scale  time_scale,
unsigned long  granularity_time,
enum ast_aoc_time_scale  granularity_time_scale,
int  step_function 
)

Add AOC-S duration rate entry.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
charged_itemast_aoc_s_charged_item
amountcurrency amount
multipliercurrency multiplier
currency_nametruncated after 10 characters
time
time_scalefrom ast_aoc_time_scale enum
granularity_time(optional, set to 0 if not present);
granularity_time_scale(optional, set to 0 if not present);
step_functionset to 1 if this is to use a step function, 0 if continuious
Return values
0success
-1failure

Definition at line 770 of file aoc.c.

References ast_copy_string(), ast_aoc_duration_rate::charging_type, ast_aoc_duration_rate::currency_name, ast_aoc_duration_rate::granularity_time, and ast_aoc_s_entry::rate.

780 {
781 
782  struct ast_aoc_s_entry entry = { 0, };
783 
784  entry.charged_item = charged_item;
785  entry.rate_type = AST_AOC_RATE_TYPE_DURATION;
786  entry.rate.duration.amount = amount;
787  entry.rate.duration.multiplier = multiplier;
788  entry.rate.duration.time = time;
789  entry.rate.duration.time_scale = time_scale;
790  entry.rate.duration.granularity_time = granularity_time;
791  entry.rate.duration.granularity_time_scale = granularity_time_scale;
792  entry.rate.duration.charging_type = step_function ? 1 : 0;
793 
794  if (!ast_strlen_zero(currency_name)) {
795  ast_copy_string(entry.rate.duration.currency_name, currency_name, sizeof(entry.rate.duration.currency_name));
796  }
797 
798  return aoc_s_add_entry(decoded, &entry);
799 }
union ast_aoc_s_entry::@180 rate
Charge rate being applied.
Definition: aoc.h:165
uint8_t charging_type
Charging interval type.
Definition: aoc.h:122
uint32_t granularity_time
Definition: aoc.h:107
char currency_name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.h:114
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Definition: search.h:40
int ast_aoc_s_add_rate_flat ( struct ast_aoc_decoded decoded,
enum ast_aoc_s_charged_item  charged_item,
unsigned int  amount,
enum ast_aoc_currency_multiplier  multiplier,
const char *  currency_name 
)

Add AOC-S flat rate entry.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
charged_itemast_aoc_s_charged_item
amountcurrency amount
multipliercurrency multiplier
currency_nametruncated after 10 characters
Return values
0success
-1failure

Definition at line 801 of file aoc.c.

References ast_copy_string(), ast_aoc_flat_rate::currency_name, and ast_aoc_s_entry::rate.

806 {
807  struct ast_aoc_s_entry entry = { 0, };
808 
809  entry.charged_item = charged_item;
810  entry.rate_type = AST_AOC_RATE_TYPE_FLAT;
811  entry.rate.flat.amount = amount;
812  entry.rate.flat.multiplier = multiplier;
813 
814  if (!ast_strlen_zero(currency_name)) {
815  ast_copy_string(entry.rate.flat.currency_name, currency_name, sizeof(entry.rate.flat.currency_name));
816  }
817 
818  return aoc_s_add_entry(decoded, &entry);
819 }
union ast_aoc_s_entry::@180 rate
Charge rate being applied.
Definition: aoc.h:165
char currency_name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.h:142
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Definition: search.h:40
int ast_aoc_s_add_rate_free ( struct ast_aoc_decoded decoded,
enum ast_aoc_s_charged_item  charged_item,
int  from_beginning 
)

Add AOC-S indicating charge item is free.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
charged_itemast_aoc_s_charged_item
from_beginningTRUE if the rate is free from beginning.
Return values
0success
-1failure

Definition at line 857 of file aoc.c.

860 {
861  struct ast_aoc_s_entry entry = { 0, };
862 
863  entry.charged_item = charged_item;
864  entry.rate_type = from_beginning ? AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING : AST_AOC_RATE_TYPE_FREE;
865 
866  return aoc_s_add_entry(decoded, &entry);
867 }
Definition: aoc.h:165
Definition: search.h:40
int ast_aoc_s_add_rate_na ( struct ast_aoc_decoded decoded,
enum ast_aoc_s_charged_item  charged_item 
)

Add AOC-S entry indicating charge item is not available.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
charged_itemast_aoc_s_charged_item
Return values
0success
-1failure

Definition at line 869 of file aoc.c.

871 {
872  struct ast_aoc_s_entry entry = { 0, };
873 
874  entry.charged_item = charged_item;
875  entry.rate_type = AST_AOC_RATE_TYPE_NA;
876 
877  return aoc_s_add_entry(decoded, &entry);
878 }
Definition: aoc.h:165
Definition: search.h:40
int ast_aoc_s_add_rate_special_charge_code ( struct ast_aoc_decoded decoded,
enum ast_aoc_s_charged_item  charged_item,
unsigned int  code 
)

Add AOC-S special rate entry.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
charged_itemast_aoc_s_charged_item
codespecial charging code
Return values
0success
-1failure

Definition at line 844 of file aoc.c.

References ast_aoc_s_entry::rate.

847 {
848  struct ast_aoc_s_entry entry = { 0, };
849 
850  entry.charged_item = charged_item;
851  entry.rate_type = AST_AOC_RATE_TYPE_SPECIAL_CODE;
852  entry.rate.special_code = code;
853 
854  return aoc_s_add_entry(decoded, &entry);
855 }
union ast_aoc_s_entry::@180 rate
Charge rate being applied.
Definition: aoc.h:165
Definition: search.h:40
int ast_aoc_s_add_rate_volume ( struct ast_aoc_decoded decoded,
enum ast_aoc_s_charged_item  charged_item,
enum ast_aoc_volume_unit  volume_unit,
unsigned int  amount,
enum ast_aoc_currency_multiplier  multiplier,
const char *  currency_name 
)

Add AOC-S volume rate entry.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
charged_itemast_aoc_s_charged_item
volume_unitfrom ast_aoc_volume_unit enum
amountcurrency amount
multipliercurrency multiplier
currency_nametruncated after 10 characters
Return values
0success
-1failure

Definition at line 822 of file aoc.c.

References ast_copy_string(), and ast_aoc_s_entry::rate.

828 {
829  struct ast_aoc_s_entry entry = { 0, };
830 
831  entry.charged_item = charged_item;
832  entry.rate_type = AST_AOC_RATE_TYPE_VOLUME;
833  entry.rate.volume.multiplier = multiplier;
834  entry.rate.volume.amount = amount;
835  entry.rate.volume.volume_unit = volume_unit;
836 
837  if (!ast_strlen_zero(currency_name)) {
838  ast_copy_string(entry.rate.volume.currency_name, currency_name, sizeof(entry.rate.volume.currency_name));
839  }
840 
841  return aoc_s_add_entry(decoded, &entry);
842 }
union ast_aoc_s_entry::@180 rate
Charge rate being applied.
Definition: aoc.h:165
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Definition: search.h:40
int ast_aoc_s_add_special_arrangement ( struct ast_aoc_decoded decoded,
unsigned int  code 
)

Add AOC-S special arrangement entry.

Since
1.8
Parameters
decodedaoc decoded object to add entry to
codespecial arrangement code
Return values
0success
-1failure

Definition at line 880 of file aoc.c.

References ast_aoc_s_entry::rate.

882 {
883  struct ast_aoc_s_entry entry = { 0, };
884 
885  entry.charged_item = AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT;
886  entry.rate_type = AST_AOC_RATE_TYPE_SPECIAL_CODE;
887  entry.rate.special_code = code;
888 
889  return aoc_s_add_entry(decoded, &entry);
890 }
union ast_aoc_s_entry::@180 rate
Charge rate being applied.
Definition: aoc.h:165
Definition: search.h:40
const struct ast_aoc_s_entry* ast_aoc_s_get_rate_info ( struct ast_aoc_decoded decoded,
unsigned int  entry_number 
)

get a specific AOC-S rate entry.

Since
1.8
Note
This can be used in conjunction with ast_aoc_s_get_count to create a unit entry iterator.

Definition at line 761 of file aoc.c.

762 {
763  if (entry_number >= decoded->aoc_s_count) {
764  return NULL;
765  }
766 
767  return (const struct ast_aoc_s_entry *) &decoded->aoc_s_entries[entry_number];
768 }
Definition: aoc.h:165
int ast_aoc_set_association_id ( struct ast_aoc_decoded decoded,
const int  id 
)

set the charging association id for an AST_AOC_E message

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
idcharging association identifier
Note
If the association number was set, this will override that value. Only the id OR the number can be set at a time, not both.
Return values
0success

Definition at line 1040 of file aoc.c.

References ast_aoc_charging_association::charging_type.

1041 {
1042  if (decoded->msg_type != AST_AOC_E) {
1043  return -1;
1044  }
1045  memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
1046  decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_ID;
1047  decoded->charging_association.charge.id = id;
1048  return 0;
1049 }
int ast_aoc_set_association_number ( struct ast_aoc_decoded decoded,
const char *  num,
uint8_t  plan 
)

set the charging association number for an AOC-E message

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
numcharging association number
plancharging association number plan and type-of-number fields
Note
If the association id was set, this will override that value. Only the id OR the number can be set at a time, not both.
Return values
0success

Definition at line 1056 of file aoc.c.

References ast_copy_string(), and ast_aoc_charging_association::charging_type.

1057 {
1058  if ((decoded->msg_type != AST_AOC_E) || ast_strlen_zero(num)) {
1059  return -1;
1060  }
1061  memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
1062  decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_NUMBER;
1063  decoded->charging_association.charge.number.plan = plan;
1064  ast_copy_string(decoded->charging_association.charge.number.number, num, sizeof(decoded->charging_association.charge.number.number));
1065 
1066  return 0;
1067 }
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
int ast_aoc_set_billing_id ( struct ast_aoc_decoded decoded,
const enum ast_aoc_billing_id  id 
)

set the billing id for a AOC-D or AST_AOC_E message

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
idbilling id
Return values
0success

Definition at line 1024 of file aoc.c.

1025 {
1026  if ((id >= AST_AOC_BILLING_NUM_ENTRIES) || (id < AST_AOC_BILLING_NA)) {
1027  return -1;
1028  }
1029 
1030  decoded->billing_id = id;
1031 
1032  return 0;
1033 }
int ast_aoc_set_currency_info ( struct ast_aoc_decoded decoded,
const unsigned int  amount,
const enum ast_aoc_currency_multiplier  multiplier,
const char *  name 
)

Sets the currency values for a AOC-D or AOC-E message.

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
amountcurrency amount REQUIRED
multipliercurrency multiplier REQUIRED, 0 or undefined value defaults to AST_AOC_MULT_ONE.
namecurrency name OPTIONAL
Return values
0success

Definition at line 919 of file aoc.c.

References ast_copy_string().

923 {
924 
925  if (!ast_strlen_zero(name)) {
926  ast_copy_string(decoded->currency_name, name, sizeof(decoded->currency_name));
927  }
928 
929  decoded->currency_amount = amount;
930 
931  if (multiplier && (multiplier < AST_AOC_MULT_NUM_ENTRIES)) {
932  decoded->multiplier = multiplier;
933  } else {
934  decoded->multiplier = AST_AOC_MULT_ONE;
935  }
936 
937  return 0;
938 }
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
int ast_aoc_set_termination_request ( struct ast_aoc_decoded decoded)

Mark the AST_AOC_REQUEST message as a termination request.

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
Note
A termination request indicates that the call has terminated, but that the other side is waiting for a short period of time before hanging up so it can get the final AOC-E message.
Return values
0success
-1failure

Definition at line 1069 of file aoc.c.

1070 {
1071  if (decoded->msg_type != AST_AOC_REQUEST) {
1072  return -1;
1073  }
1074  decoded->termination_request = 1;
1075 
1076  return 0;
1077 }
int ast_aoc_set_total_type ( struct ast_aoc_decoded decoded,
const enum ast_aoc_total_type  type 
)

Sets the type of total for a AOC-D message.

Since
1.8
Parameters
decodedast_aoc_decoded struct to set values on
typetotal type: TOTAL or SUBTOTAL
Note
If this value is not set, the default for the message is TOTAL
Return values
0success

Definition at line 907 of file aoc.c.

909 {
910  decoded->total_type = type;
911  return 0;
912 }
int ast_aoc_test_encode_decode_match ( struct ast_aoc_decoded decoded)

test aoc encode decode routines.

Since
1.8
Note
This function verifies that a decoded message matches itself after the encode decode routine.

Definition at line 1330 of file aoc.c.

References ast_aoc_decode(), ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), and ast_aoc_encode().

1331 {
1332  struct ast_aoc_decoded *new_decoded = NULL;
1333  struct ast_aoc_encoded *encoded = NULL;
1334  size_t size;
1335  int res = 0;
1336 
1337  if (!(encoded = ast_aoc_encode(decoded, &size, NULL))) {
1338  return -1;
1339  }
1340 
1341  if (!(new_decoded = ast_aoc_decode(encoded, size, NULL))) {
1342  ast_free(encoded);
1343  return -1;
1344  }
1345 
1346  if (memcmp(new_decoded, decoded, sizeof(struct ast_aoc_decoded))) {
1347  res = -1;
1348  }
1349 
1350  ast_aoc_destroy_decoded(new_decoded);
1351  ast_aoc_destroy_encoded(encoded);
1352  return res;
1353 }
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition: aoc.c:313
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:307
struct ast_aoc_decoded * ast_aoc_decode(struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
decodes an encoded aoc payload.
Definition: aoc.c:449
struct ast_aoc_encoded * ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
encodes a decoded aoc structure so it can be passed on the wire
Definition: aoc.c:650

Variable Documentation

struct ast_cli_entry aoc_cli[]
static
Initial value:
= {
{ .handler = aoc_cli_debug_enable , .summary = "enable cli debugging of AOC messages" ,},
}

Definition at line 2008 of file aoc.c.