Asterisk - The Open Source Telephony Project
21.4.1
|
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 |
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_blob * | aoc_d_to_ami (struct stasis_message *message) |
struct stasis_message_type * | aoc_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_blob * | aoc_e_to_ami (struct stasis_message *message) |
struct stasis_message_type * | aoc_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_blob * | aoc_s_to_ami (struct stasis_message *message) |
struct stasis_message_type * | aoc_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_blob * | aoc_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_json * | association_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_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 More... | |
struct ast_aoc_decoded * | ast_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_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 More... | |
const struct ast_aoc_charging_association * | ast_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_entry * | ast_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_entry * | ast_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_json * | charge_to_json (const struct ast_aoc_decoded *decoded) |
static struct ast_json * | currency_to_json (const char *name, int cost, enum ast_aoc_currency_multiplier mult) |
static struct ast_json * | d_to_json (const struct ast_aoc_decoded *decoded) |
static struct ast_json * | e_to_json (const struct ast_aoc_decoded *decoded) |
static struct ast_json * | s_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_json * | units_to_json (const struct ast_aoc_decoded *decoded) |
Variables | |
static struct ast_cli_entry | aoc_cli [] |
static char | aoc_debug_enabled = 0 |
generic AOC payload generation encoding and decoding
Definition in file aoc.c.
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.
decoded | ast_aoc_decoded struct to set values on |
amount_is_present | set this if the number of units is actually present. |
amount | number of units |
type_is_present | set this if the type value is present |
type | unit type |
0 | success |
Definition at line 977 of file aoc.c.
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
msg_type | AOC-D, AOC-E, or AOC Request |
charge_type | this is ignored if message type is not AOC-D or AOC-E. |
requests | flags. 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. |
heap | allocated ast_aoc_decoded object ptr on success |
NULL | failure |
Definition at line 276 of file aoc.c.
References ast_calloc.
struct ast_aoc_decoded* ast_aoc_decode | ( | struct ast_aoc_encoded * | encoded, |
size_t | size, | ||
struct ast_channel * | chan | ||
) |
decodes an encoded aoc payload.
encoded | the encoded payload to decode. |
size | total size of encoded payload |
chan | ast channel, Optional for DEBUG output purposes |
heap | allocated ast_aoc_decoded object ptr on success |
NULL | failure |
Definition at line 449 of file aoc.c.
References ast_calloc.
Referenced by ast_aoc_test_encode_decode_match(), and wait_for_answer().
int ast_aoc_decoded2str | ( | const struct ast_aoc_decoded * | decoded, |
struct ast_str ** | msg | ||
) |
Convert decoded aoc msg to string representation.
decoded | ast_aoc_decoded struct to convert to string |
msg | dynamic heap allocated ast_str object to store string representation in |
0 | success |
-1 | failure |
Definition at line 1954 of file aoc.c.
References ast_str_append().
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
decoded | the decoded struct to be encoded |
out_size | output parameter representing size of encoded data |
chan | ast channel, Optional for DEBUG output purposes |
pointer | to encoded data |
NULL | failure |
Definition at line 650 of file aoc.c.
References ast_calloc.
Referenced by ast_aoc_test_encode_decode_match(), and wait_for_answer().
int ast_aoc_get_termination_request | ( | struct ast_aoc_decoded * | decoded | ) |
get whether or not the AST_AOC_REQUEST message as a termination request.
decoded | ast_aoc_decoded struct to get values on |
0 | not a termination request |
1 | is a termination request |
const struct ast_aoc_unit_entry* ast_aoc_get_unit_info | ( | struct ast_aoc_decoded * | decoded, |
unsigned int | entry_number | ||
) |
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
Definition at line 1922 of file aoc.c.
References ast_json_unref().
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.
decoded | aoc decoded object to add entry to |
charged_item | ast_aoc_s_charged_item |
amount | currency amount |
multiplier | currency multiplier |
currency_name | truncated after 10 characters |
time | |
time_scale | from 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_function | set to 1 if this is to use a step function, 0 if continuious |
0 | success |
-1 | failure |
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.
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.
decoded | aoc decoded object to add entry to |
charged_item | ast_aoc_s_charged_item |
amount | currency amount |
multiplier | currency multiplier |
currency_name | truncated after 10 characters |
0 | success |
-1 | failure |
Definition at line 801 of file aoc.c.
References ast_copy_string(), ast_aoc_flat_rate::currency_name, and ast_aoc_s_entry::rate.
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.
decoded | aoc decoded object to add entry to |
charged_item | ast_aoc_s_charged_item |
from_beginning | TRUE if the rate is free from beginning. |
0 | success |
-1 | failure |
Definition at line 857 of file aoc.c.
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.
decoded | aoc decoded object to add entry to |
charged_item | ast_aoc_s_charged_item |
0 | success |
-1 | failure |
Definition at line 869 of file aoc.c.
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.
decoded | aoc decoded object to add entry to |
charged_item | ast_aoc_s_charged_item |
code | special charging code |
0 | success |
-1 | failure |
Definition at line 844 of file aoc.c.
References ast_aoc_s_entry::rate.
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.
decoded | aoc decoded object to add entry to |
charged_item | ast_aoc_s_charged_item |
volume_unit | from ast_aoc_volume_unit enum |
amount | currency amount |
multiplier | currency multiplier |
currency_name | truncated after 10 characters |
0 | success |
-1 | failure |
Definition at line 822 of file aoc.c.
References ast_copy_string(), and ast_aoc_s_entry::rate.
int ast_aoc_s_add_special_arrangement | ( | struct ast_aoc_decoded * | decoded, |
unsigned int | code | ||
) |
Add AOC-S special arrangement entry.
decoded | aoc decoded object to add entry to |
code | special arrangement code |
0 | success |
-1 | failure |
Definition at line 880 of file aoc.c.
References ast_aoc_s_entry::rate.
const struct ast_aoc_s_entry* ast_aoc_s_get_rate_info | ( | struct ast_aoc_decoded * | decoded, |
unsigned int | entry_number | ||
) |
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
decoded | ast_aoc_decoded struct to set values on |
id | charging association identifier |
0 | success |
Definition at line 1040 of file aoc.c.
References ast_aoc_charging_association::charging_type.
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
decoded | ast_aoc_decoded struct to set values on |
num | charging association number |
plan | charging association number plan and type-of-number fields |
0 | success |
Definition at line 1056 of file aoc.c.
References ast_copy_string(), and ast_aoc_charging_association::charging_type.
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
decoded | ast_aoc_decoded struct to set values on |
id | billing id |
0 | success |
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.
decoded | ast_aoc_decoded struct to set values on |
amount | currency amount REQUIRED |
multiplier | currency multiplier REQUIRED, 0 or undefined value defaults to AST_AOC_MULT_ONE. |
name | currency name OPTIONAL |
0 | success |
Definition at line 919 of file aoc.c.
References ast_copy_string().
int ast_aoc_set_termination_request | ( | struct ast_aoc_decoded * | decoded | ) |
Mark the AST_AOC_REQUEST message as a termination request.
decoded | ast_aoc_decoded struct to set values on |
0 | success |
-1 | failure |
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.
decoded | ast_aoc_decoded struct to set values on |
type | total type: TOTAL or SUBTOTAL |
0 | success |
int ast_aoc_test_encode_decode_match | ( | struct ast_aoc_decoded * | decoded | ) |
test aoc encode decode routines.
Definition at line 1330 of file aoc.c.
References ast_aoc_decode(), ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), and ast_aoc_encode().
|
static |