172 #define AST_AOC_ENCODED_TYPE_REQUEST (0 << 0) 173 #define AST_AOC_ENCODED_TYPE_D (1 << 0) 174 #define AST_AOC_ENCODED_TYPE_E (2 << 0) 175 #define AST_AOC_ENCODED_TYPE_S (3 << 0) 177 #define AST_AOC_ENCODED_REQUEST_S (1 << 2) 178 #define AST_AOC_ENCODED_REQUEST_D (1 << 3) 179 #define AST_AOC_ENCODED_REQUEST_E (1 << 4) 181 #define AST_AOC_ENCODED_CHARGE_NA (0 << 5) 182 #define AST_AOC_ENCODED_CHARGE_FREE (1 << 5) 183 #define AST_AOC_ENCODED_CHARGE_CURRENCY (2 << 5) 184 #define AST_AOC_ENCODED_CHARGE_UNIT (3 << 5) 186 #define AST_AOC_ENCODED_CHARGE_SUBTOTAL (1 << 7) 187 #define AST_AOC_ENCODED_CHARGE_TOTAL (0 << 7) 189 #define AST_AOC_ENCODE_VERSION 1 249 } __attribute__((packed));
255 } __attribute__((packed));
262 } __attribute__((packed));
266 } __attribute__((packed));
270 } __attribute__((packed));
274 } __attribute__((packed));
374 while (datalen >= 2) {
377 if (len > datalen -2) {
378 ast_log(
LOG_ERROR,
"AOC information element length exceeds the total message size\n");
386 memcpy(&ie, data + 2, len);
397 memcpy(&ie, data + 2, len);
406 memcpy(&ie, data + 2, len);
426 memcpy(&ie, data + 2, len);
443 datalen -= (len + 2);
524 if (datalen > ((
int)
sizeof(ied->
buf) - ied->
pos)) {
528 ied->
buf[ied->
pos++] = ie_id;
531 memcpy(ied->
buf + ied->
pos, data, datalen);
622 memset(&ie, 0,
sizeof(ie));
639 memset(&ie, 0,
sizeof(ie));
656 if (!decoded || !out_size) {
670 ast_log(
LOG_WARNING,
"Failed to create ast_aoc_encoded object during decode routine. \n");
677 memcpy(encoded->
data, ied.buf, ied.pos);
678 encoded->
datalen = htons(ied.pos);
774 const char *currency_name,
777 unsigned long granularity_time,
805 const char *currency_name)
827 const char *currency_name)
920 const unsigned int amount,
978 const unsigned int amount_is_present,
979 const unsigned int amount,
980 const unsigned int type_is_present,
981 const unsigned int type)
988 if (!amount_is_present && !type_is_present) {
993 if (amount_is_present) {
1000 if (type_is_present) {
1128 str =
"NotAvailable";
1131 str =
"SpecialArrangement";
1134 str =
"BasicCommunication";
1137 str =
"CallAttempt";
1143 str =
"UserUserInfo";
1146 str =
"SupplementaryService";
1193 str =
"NotAvailable";
1199 str =
"FreeFromBeginning";
1211 str =
"SpecialCode";
1233 str =
"OneHundredthSecond";
1236 str =
"OneTenthSecond";
1264 str =
"NotAvailable";
1305 switch (billing_id) {
1311 return "CreditCard";
1313 return "CallForwardingUnconditional";
1315 return "CallForwardingBusy";
1317 return "CallForwardingNoReply";
1319 return "CallDeflection";
1321 return "CallTransfer";
1323 return "NotAvailable";
1327 return "NotAvailable";
1361 "Usage: 'aoc set debug on' to enable aoc debug, 'aoc set debug off' to disable debug.\n";
1397 ast_str_append(msg, 0,
"%s/%s/Length: %lu\r\n", prefix, name, time);
1416 static const char name[] =
"Amount";
1418 ast_str_append(msg, 0,
"%s/%s/Cost: %u\r\n", prefix, name, amount);
1445 const char *rate_str;
1450 for (idx = 0; idx < decoded->
aoc_s_count; ++idx) {
1451 snprintf(prefix,
sizeof(prefix),
"Rate(%d)", idx);
1462 strcat(prefix,
"/");
1463 strcat(prefix, rate_str);
1471 "StepFunction" :
"ContinuousCharging");
1482 strcat(prefix,
"/");
1483 strcat(prefix, rate_str);
1491 strcat(prefix,
"/");
1492 strcat(prefix, rate_str);
1513 const char *charge_str;
1543 for (idx = 0; idx < decoded->
unit_count; ++idx) {
1544 snprintf(prefix,
sizeof(prefix),
"%s/Item(%d)", charge_str, idx);
1562 const char *charge_str;
1566 charge_str =
"ChargingAssociation";
1570 snprintf(prefix,
sizeof(prefix),
"%s/Number", charge_str);
1606 for (idx = 0; idx < decoded->
unit_count; ++idx) {
1607 snprintf(prefix,
sizeof(prefix),
"%s/Item(%d)", charge_str, idx);
1667 const char *obj_type;
1676 obj_type =
"Currency";
1752 "Currency", currency,
1754 ?
"StepFunction" :
"ContinuousCharging",
1777 "Currency", currency);
1788 "Chargeable", charge_item,
1872 const char *event_name)
1962 if (!decoded || !msg) {
struct stasis_message_type * aoc_s_type(void)
Struct containing info for an AMI event to send out.
#define ast_channel_lock(chan)
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
static void aoc_shutdown(void)
static void aoc_create_ie_data_charging_rate(const struct ast_aoc_s_entry *entry, struct aoc_ie_charging_rate *ie)
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
static void aoc_amount_str(struct ast_str **msg, const char *prefix, unsigned int amount, enum ast_aoc_currency_multiplier mult)
#define AST_AOC_ENCODED_REQUEST_E
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_json * e_to_json(const struct ast_aoc_decoded *decoded)
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
static int aoc_s_add_entry(struct ast_aoc_decoded *decoded, struct ast_aoc_s_entry *entry)
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
String manipulation functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
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.
#define AST_AOC_ENCODED_TYPE_E
static struct ast_json * charge_to_json(const struct ast_aoc_decoded *decoded)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
union ast_aoc_charging_association::@221 charge
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
#define AST_AOC_ENCODED_CHARGE_FREE
enum ast_aoc_currency_multiplier multiplier
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
static struct requests requests
struct ast_aoc_duration_rate duration
static struct ast_json * currency_to_json(const char *name, int cost, enum ast_aoc_currency_multiplier mult)
descriptor for a cli entry.
int ast_aoc_test_encode_decode_match(struct ast_aoc_decoded *decoded)
test aoc encode decode routines.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static void aoc_parse_ie_charging_rate(struct ast_aoc_decoded *decoded, const struct aoc_ie_charging_rate *ie)
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
#define AST_AOC_ENCODED_TYPE_D
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
struct ast_channel_snapshot * ast_channel_snapshot(const struct ast_channel *chan)
#define AST_AOC_ENCODED_CHARGE_CURRENCY
Structure representing a snapshot of channel state.
static void aoc_e_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
static const char * aoc_billingid_str(enum ast_aoc_billing_id billing_id)
struct ast_aoc_charging_association_number number
static struct ast_manager_event_blob * aoc_s_to_ami(struct stasis_message *message)
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
int ast_aoc_decoded2str(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Convert decoded aoc msg to string representation.
struct ast_json * ast_json_stringf(const char *format,...)
Create a JSON string, printf style.
AOC_IE
AOC Payload Information Elements.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct stasis_message_type * aoc_d_type(void)
static void aoc_event_blob_dtor(void *obj)
#define AST_AOC_ENCODED_REQUEST_S
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
#define ao2_alloc_options(data_size, destructor_fn, options)
uint8_t charging_type
Charging interval type.
static const char * aoc_type_of_totaling_str(enum ast_aoc_total_type value)
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.
static struct ast_json * association_to_json(const struct ast_aoc_decoded *decoded)
static const char * aoc_charged_item_str(enum ast_aoc_s_charged_item value)
ast_aoc_currency_multiplier
Defines the currency multiplier for an aoc message.
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
static const char * aoc_volume_unit_str(enum ast_aoc_volume_unit value)
static const char * aoc_multiplier_str(enum ast_aoc_currency_multiplier mult)
enum ast_aoc_billing_id billing_id
int ast_json_is_null(const struct ast_json *value)
Check if value is JSON null.
void ast_cli(int fd, const char *fmt,...)
int ast_aoc_set_termination_request(struct ast_aoc_decoded *decoded)
Mark the AST_AOC_REQUEST message as a termination request.
const char * ast_aoc_get_currency_name(struct ast_aoc_decoded *decoded)
get the currency name for AOC-D and AOC-E messages
#define ast_verb(level,...)
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
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.
int ast_aoc_s_add_special_arrangement(struct ast_aoc_decoded *decoded, unsigned int code)
Add AOC-S special arrangement entry.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
#define ast_strlen_zero(foo)
struct ast_str * ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
Convert a JSON object into an AMI compatible string.
struct ast_json * ast_json_null(void)
Get the JSON null value.
enum ast_aoc_total_type total_type
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.
struct ast_channel_snapshot * snapshot
static void aoc_display_decoded_debug(const struct ast_aoc_decoded *decoded, int decoding, struct ast_channel *chan)
static struct ast_cli_entry aoc_cli[]
static struct ast_manager_event_blob * aoc_d_to_ami(struct stasis_message *message)
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.
static char * aoc_cli_debug_enable(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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
#define AST_AOC_ENCODED_CHARGE_UNIT
Generic Advice of Charge encode and decode routines.
static const char * aoc_rate_type_str(enum ast_aoc_s_rate_type value)
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
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
struct ast_aoc_charging_association charging_association
static void aoc_publish_blob(struct ast_channel *chan, struct stasis_message_type *msg_type, struct ast_json *blob)
#define ao2_ref(o, delta)
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.
struct ast_aoc_flat_rate flat
char currency_name[AOC_CURRENCY_NAME_SIZE]
#define AST_AOC_ENCODED_CHARGE_SUBTOTAL
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
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
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
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
char currency_name[AOC_CURRENCY_NAME_SIZE]
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
static struct ast_json * s_to_json(const struct ast_aoc_decoded *decoded)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
static char aoc_debug_enabled
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
struct ast_aoc_volume_rate volume
#define AST_AOC_ENCODED_TYPE_REQUEST
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
set the charging accociation number for an AOC-E message
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
static struct ast_manager_event_blob * aoc_e_to_ami(struct stasis_message *message)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_aoc_unit_entry unit_list[32]
unsigned int currency_amount
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
STASIS_MESSAGE_TYPE_DEFN(aoc_s_type,.to_ami=aoc_s_to_ami)
#define AST_AOC_ENCODED_REQUEST_D
struct ast_aoc_decoded * ast_aoc_decode(struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
decodes an encoded aoc payload.
static struct ast_json * d_to_json(const struct ast_aoc_decoded *decoded)
uint32_t granularity_time
#define ast_channel_unlock(chan)
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
static struct ast_json * units_to_json(const struct ast_aoc_decoded *decoded)
#define ast_calloc(num, len)
A wrapper for calloc()
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.
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
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
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
static struct ast_manager_event_blob * aoc_to_ami(struct stasis_message *message, const char *event_name)
Prototypes for public functions only of internal interest,.
static const char * aoc_scale_str(enum ast_aoc_time_scale value)
char currency_name[AOC_CURRENCY_NAME_SIZE]
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
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
static void aoc_time_str(struct ast_str **msg, const char *prefix, const char *name, unsigned long time, enum ast_aoc_time_scale scale)
union ast_aoc_s_entry::@220 rate
Charge rate being applied.
int ast_aoc_cli_init(void)
enable aoc cli options
unsigned int ast_aoc_get_currency_amount(struct ast_aoc_decoded *decoded)
get the currency amount for AOC-D and AOC-E messages
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.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
enum ast_aoc_type msg_type
static void aoc_s_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
unsigned int ast_aoc_s_get_count(struct ast_aoc_decoded *decoded)
get the number rates associated with an AOC-S message
Standard Command Line Interface.
struct ast_aoc_charging_association ca
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
#define AST_AOC_ENCODE_VERSION
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
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.
static void aoc_d_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
const char * ast_channel_name(const struct ast_channel *chan)
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
#define AOC_CURRENCY_NAME_SIZE
static void aoc_request_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
ast_aoc_billing_id
Defines the billing id options for an aoc message.
struct stasis_message_type * aoc_e_type(void)
#define AST_AOC_ENCODED_CHARGE_NA
struct ast_aoc_s_entry entry
Abstract JSON element (object, array, string, int, ...).
enum ast_aoc_request request_flag
char name[AOC_CURRENCY_NAME_SIZE]
int ast_aoc_get_termination_request(struct ast_aoc_decoded *decoded)
get whether or not the AST_AOC_REQUEST message as a termination request.
struct ast_aoc_s_entry aoc_s_entries[10]
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.
static void aoc_create_ie_data(struct ast_aoc_decoded *decoded, struct aoc_ie_data *ied)
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.
static int aoc_append_ie(struct aoc_ie_data *ied, unsigned short ie_id, const void *data, unsigned short datalen)
static const char * aoc_charge_type_str(enum ast_aoc_charge_type value)
#define AST_AOC_ENCODED_TYPE_S
enum ast_aoc_charge_type charge_type
static int aoc_parse_ie(struct ast_aoc_decoded *decoded, unsigned char *data, unsigned int datalen)
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
uint16_t granularity_time_scale
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
static char prefix[MAX_PREFIX]
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
char currency_name[AOC_CURRENCY_NAME_SIZE]