Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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"
Include dependency graph for aoc.c:

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. More...
 

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 More...
 
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 More...
 
void * ast_aoc_destroy_encoded (struct ast_aoc_encoded *encoded)
 free an ast_aoc_encoded object More...
 
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 More...
 
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 More...
 
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 More...
 
unsigned int ast_aoc_get_currency_amount (struct ast_aoc_decoded *decoded)
 get the currency amount for AOC-D and AOC-E messages More...
 
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 More...
 
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 More...
 
const char * ast_aoc_get_currency_name (struct ast_aoc_decoded *decoded)
 get the currency name for AOC-D and AOC-E messages More...
 
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 More...
 
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 More...
 
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 More...
 
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 More...
 
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 More...
 
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_d_type,.to_ami=aoc_d_to_ami)
 
 STASIS_MESSAGE_TYPE_DEFN (aoc_e_type,.to_ami=aoc_e_to_ami)
 
 STASIS_MESSAGE_TYPE_DEFN (aoc_s_type,.to_ami=aoc_s_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.

Macro Definition Documentation

◆ AST_AOC_ENCODE_VERSION

#define AST_AOC_ENCODE_VERSION   1

Definition at line 198 of file aoc.c.

◆ AST_AOC_ENCODED_CHARGE_CURRENCY

#define AST_AOC_ENCODED_CHARGE_CURRENCY   (2 << 5)

Definition at line 192 of file aoc.c.

◆ AST_AOC_ENCODED_CHARGE_FREE

#define AST_AOC_ENCODED_CHARGE_FREE   (1 << 5)

Definition at line 191 of file aoc.c.

◆ AST_AOC_ENCODED_CHARGE_NA

#define AST_AOC_ENCODED_CHARGE_NA   (0 << 5)

Definition at line 190 of file aoc.c.

◆ AST_AOC_ENCODED_CHARGE_SUBTOTAL

#define AST_AOC_ENCODED_CHARGE_SUBTOTAL   (1 << 7)

Definition at line 195 of file aoc.c.

◆ AST_AOC_ENCODED_CHARGE_TOTAL

#define AST_AOC_ENCODED_CHARGE_TOTAL   (0 << 7)

Definition at line 196 of file aoc.c.

◆ AST_AOC_ENCODED_CHARGE_UNIT

#define AST_AOC_ENCODED_CHARGE_UNIT   (3 << 5)

Definition at line 193 of file aoc.c.

◆ AST_AOC_ENCODED_REQUEST_D

#define AST_AOC_ENCODED_REQUEST_D   (1 << 3)

Definition at line 187 of file aoc.c.

◆ AST_AOC_ENCODED_REQUEST_E

#define AST_AOC_ENCODED_REQUEST_E   (1 << 4)

Definition at line 188 of file aoc.c.

◆ AST_AOC_ENCODED_REQUEST_S

#define AST_AOC_ENCODED_REQUEST_S   (1 << 2)

Definition at line 186 of file aoc.c.

◆ AST_AOC_ENCODED_TYPE_D

#define AST_AOC_ENCODED_TYPE_D   (1 << 0)

Definition at line 182 of file aoc.c.

◆ AST_AOC_ENCODED_TYPE_E

#define AST_AOC_ENCODED_TYPE_E   (2 << 0)

Definition at line 183 of file aoc.c.

◆ AST_AOC_ENCODED_TYPE_REQUEST

#define AST_AOC_ENCODED_TYPE_REQUEST   (0 << 0)

Definition at line 181 of file aoc.c.

◆ AST_AOC_ENCODED_TYPE_S

#define AST_AOC_ENCODED_TYPE_S   (3 << 0)

Definition at line 184 of file aoc.c.

Enumeration Type Documentation

◆ AOC_IE

enum AOC_IE

AOC Payload Information Elements.

Enumerator
AOC_IE_CURRENCY 
AOC_IE_UNIT 
AOC_IE_BILLING 
AOC_IE_CHARGING_ASSOCIATION 
AOC_IE_RATE 
AOC_IE_TERMINATION_REQUEST 

Definition at line 244 of file aoc.c.

244 {
245 AOC_IE_CURRENCY = 1,
246 AOC_IE_UNIT = 2,
247 AOC_IE_BILLING = 3,
249 AOC_IE_RATE = 5,
251};
@ AOC_IE_UNIT
Definition: aoc.c:246
@ AOC_IE_RATE
Definition: aoc.c:249
@ AOC_IE_TERMINATION_REQUEST
Definition: aoc.c:250
@ AOC_IE_CHARGING_ASSOCIATION
Definition: aoc.c:248
@ AOC_IE_BILLING
Definition: aoc.c:247
@ AOC_IE_CURRENCY
Definition: aoc.c:245

Function Documentation

◆ aoc_amount_str()

static void aoc_amount_str ( struct ast_str **  msg,
const char *  prefix,
unsigned int  amount,
enum ast_aoc_currency_multiplier  mult 
)
static

Definition at line 1419 of file aoc.c.

1420{
1421 static const char name[] = "Amount";
1422
1423 ast_str_append(msg, 0, "%s/%s/Cost: %u\r\n", prefix, name, amount);
1424 ast_str_append(msg, 0, "%s/%s/Multiplier: %s\r\n", prefix, name,
1425 aoc_multiplier_str(mult));
1426}
static const char * aoc_multiplier_str(enum ast_aoc_currency_multiplier mult)
Definition: aoc.c:1289
static const char name[]
Definition: format_mp3.c:68
static char prefix[MAX_PREFIX]
Definition: http.c:144
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

References aoc_multiplier_str(), ast_str_append(), name, and prefix.

Referenced by aoc_d_event(), aoc_e_event(), and aoc_s_event().

◆ aoc_append_ie()

static int aoc_append_ie ( struct aoc_ie_data ied,
unsigned short  ie_id,
const void *  data,
unsigned short  datalen 
)
static

Definition at line 531 of file aoc.c.

532{
533 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
534 ast_log(LOG_WARNING, "Failure to append AOC information element, out of space \n");
535 return -1;
536 }
537 ied->buf[ied->pos++] = ie_id;
538 ied->buf[ied->pos++] = datalen;
539 if (datalen) {
540 memcpy(ied->buf + ied->pos, data, datalen);
541 ied->pos += datalen;
542 }
543 return 0;
544}
#define ast_log
Definition: astobj2.c:42
#define LOG_WARNING
int pos
Definition: aoc.c:523
unsigned char buf[1024]
Definition: aoc.c:522

References ast_log, aoc_ie_data::buf, LOG_WARNING, and aoc_ie_data::pos.

Referenced by aoc_create_ie_data().

◆ aoc_billingid_str()

static const char * aoc_billingid_str ( enum ast_aoc_billing_id  billing_id)
static

Definition at line 1312 of file aoc.c.

1313{
1314 switch (billing_id) {
1316 return "Normal";
1318 return "Reverse";
1320 return "CreditCard";
1322 return "CallForwardingUnconditional";
1324 return "CallForwardingBusy";
1326 return "CallForwardingNoReply";
1328 return "CallDeflection";
1330 return "CallTransfer";
1331 case AST_AOC_BILLING_NA:
1332 return "NotAvailable";
1334 break;
1335 }
1336 return "NotAvailable";
1337}
@ AST_AOC_BILLING_NUM_ENTRIES
Definition: aoc.h:59
@ AST_AOC_BILLING_CALL_FWD_BUSY
Definition: aoc.h:55
@ AST_AOC_BILLING_CALL_FWD_NO_REPLY
Definition: aoc.h:56
@ AST_AOC_BILLING_NORMAL
Definition: aoc.h:51
@ AST_AOC_BILLING_CALL_DEFLECTION
Definition: aoc.h:57
@ AST_AOC_BILLING_CREDIT_CARD
Definition: aoc.h:53
@ AST_AOC_BILLING_CALL_TRANSFER
Definition: aoc.h:58
@ AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL
Definition: aoc.h:54
@ AST_AOC_BILLING_REVERSE_CHARGE
Definition: aoc.h:52
@ AST_AOC_BILLING_NA
Definition: aoc.h:50

References AST_AOC_BILLING_CALL_DEFLECTION, AST_AOC_BILLING_CALL_FWD_BUSY, AST_AOC_BILLING_CALL_FWD_NO_REPLY, AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL, AST_AOC_BILLING_CALL_TRANSFER, AST_AOC_BILLING_CREDIT_CARD, AST_AOC_BILLING_NA, AST_AOC_BILLING_NORMAL, AST_AOC_BILLING_NUM_ENTRIES, and AST_AOC_BILLING_REVERSE_CHARGE.

Referenced by aoc_d_event(), aoc_e_event(), and charge_to_json().

◆ aoc_charge_type_str()

static const char * aoc_charge_type_str ( enum ast_aoc_charge_type  value)
static

Definition at line 1266 of file aoc.c.

1267{
1268 const char *str;
1269
1270 switch (value) {
1271 default:
1272 case AST_AOC_CHARGE_NA:
1273 str = "NotAvailable";
1274 break;
1276 str = "Free";
1277 break;
1279 str = "Currency";
1280 break;
1282 str = "Units";
1283 break;
1284 }
1285
1286 return str;
1287}
@ AST_AOC_CHARGE_CURRENCY
Definition: aoc.h:72
@ AST_AOC_CHARGE_FREE
Definition: aoc.h:71
@ AST_AOC_CHARGE_UNIT
Definition: aoc.h:73
@ AST_AOC_CHARGE_NA
Definition: aoc.h:70
const char * str
Definition: app_jack.c:150
int value
Definition: syslog.c:37

References AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_NA, AST_AOC_CHARGE_UNIT, str, and value.

Referenced by aoc_d_event(), aoc_e_event(), and charge_to_json().

◆ aoc_charged_item_str()

static const char * aoc_charged_item_str ( enum ast_aoc_s_charged_item  value)
static

Definition at line 1130 of file aoc.c.

1131{
1132 const char *str;
1133
1134 switch (value) {
1135 default:
1137 str = "NotAvailable";
1138 break;
1140 str = "SpecialArrangement";
1141 break;
1143 str = "BasicCommunication";
1144 break;
1146 str = "CallAttempt";
1147 break;
1149 str = "CallSetup";
1150 break;
1152 str = "UserUserInfo";
1153 break;
1155 str = "SupplementaryService";
1156 break;
1157 }
1158 return str;
1159}
@ AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION
Definition: aoc.h:148
@ AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT
Definition: aoc.h:147
@ AST_AOC_CHARGED_ITEM_NA
Definition: aoc.h:146
@ AST_AOC_CHARGED_ITEM_USER_USER_INFO
Definition: aoc.h:151
@ AST_AOC_CHARGED_ITEM_CALL_SETUP
Definition: aoc.h:150
@ AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE
Definition: aoc.h:152
@ AST_AOC_CHARGED_ITEM_CALL_ATTEMPT
Definition: aoc.h:149

References AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION, AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, AST_AOC_CHARGED_ITEM_CALL_SETUP, AST_AOC_CHARGED_ITEM_NA, AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT, AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE, AST_AOC_CHARGED_ITEM_USER_USER_INFO, str, and value.

Referenced by aoc_s_event(), and s_to_json().

◆ aoc_cli_debug_enable()

static char * aoc_cli_debug_enable ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1364 of file aoc.c.

1365{
1366 switch (cmd) {
1367 case CLI_INIT:
1368 e->command = "aoc set debug";
1369 e->usage =
1370 "Usage: 'aoc set debug on' to enable aoc debug, 'aoc set debug off' to disable debug.\n";
1371 return NULL;
1372 case CLI_GENERATE:
1373 return NULL;
1374 case CLI_HANDLER:
1375 if (a->argc != 4) {
1376 return CLI_SHOWUSAGE;
1377 } else if(ast_true(a->argv[3])) {
1378 ast_cli(a->fd, "aoc debug enabled\n");
1380 } else if (ast_false(a->argv[3])) {
1381 ast_cli(a->fd, "aoc debug disabled\n");
1383 } else {
1384 return CLI_SHOWUSAGE;
1385 }
1386 }
1387
1388 return CLI_SUCCESS;
1389}
static char aoc_debug_enabled
Definition: aoc.c:201
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
@ CLI_HANDLER
Definition: cli.h:154
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define NULL
Definition: resample.c:96
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition: utils.c:2216
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
static struct test_val a

References a, aoc_debug_enabled, ast_cli(), ast_false(), ast_true(), CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.

◆ aoc_create_ie_data()

static void aoc_create_ie_data ( struct ast_aoc_decoded decoded,
struct aoc_ie_data ied 
)
static

Definition at line 592 of file aoc.c.

593{
594 ied->pos = 0;
595
596 if (decoded->currency_amount) {
597 struct aoc_ie_currency ie = {
598 .amount = htonl(decoded->currency_amount),
599 .multiplier = decoded->multiplier, /* only one byte */
600 .name = { 0, },
601 };
602
603 if (!ast_strlen_zero(decoded->currency_name)) {
604 ast_copy_string(ie.name, decoded->currency_name, sizeof(ie.name));
605 }
606
607 aoc_append_ie(ied, AOC_IE_CURRENCY, (const void *) &ie, sizeof(ie));
608 }
609
610 if (decoded->unit_count) {
611 struct aoc_ie_unit ie = { 0 };
612 int i;
613
614 for (i = 0; i < decoded->unit_count; i++) {
615 ie.valid_amount = decoded->unit_list[i].valid_amount; /* only one byte */
616 ie.amount = htonl(decoded->unit_list[i].amount);
617 ie.valid_type = decoded->unit_list[i].valid_type; /* only one byte */
618 ie.type = decoded->unit_list[i].type; /* only one byte */
619 aoc_append_ie(ied, AOC_IE_UNIT, (const void *) &ie, sizeof(ie));
620 }
621 }
622
623 if (decoded->billing_id) {
624 struct aoc_ie_billing ie;
625 ie.id = decoded->billing_id; /* only one byte */
626 aoc_append_ie(ied, AOC_IE_BILLING, (const void *) &ie, sizeof(ie));
627 }
628
631 memset(&ie, 0, sizeof(ie));
632 ie.ca.charging_type = decoded->charging_association.charging_type; /* only one byte */
634 ie.ca.charge.number.plan = decoded->charging_association.charge.number.plan; /* only one byte */
635 ast_copy_string(ie.ca.charge.number.number,
637 sizeof(ie.ca.charge.number.number));
639 ie.ca.charge.id = htonl(decoded->charging_association.charge.id);
640 }
641 aoc_append_ie(ied, AOC_IE_CHARGING_ASSOCIATION, (const void *) &ie, sizeof(ie));
642 }
643
644 if (decoded->aoc_s_count) {
645 struct aoc_ie_charging_rate ie;
646 int i;
647 for (i = 0; i < decoded->aoc_s_count; i++) {
648 memset(&ie, 0, sizeof(ie));
650 aoc_append_ie(ied, AOC_IE_RATE, (const void *) &ie, sizeof(ie));
651 }
652 }
653
654 if (decoded->termination_request) {
656 }
657}
static void aoc_create_ie_data_charging_rate(const struct ast_aoc_s_entry *entry, struct aoc_ie_charging_rate *ie)
Definition: aoc.c:546
static int aoc_append_ie(struct aoc_ie_data *ied, unsigned short ie_id, const void *data, unsigned short datalen)
Definition: aoc.c:531
@ AST_AOC_CHARGING_ASSOCIATION_NA
Definition: aoc.h:186
@ AST_AOC_CHARGING_ASSOCIATION_ID
Definition: aoc.h:188
@ AST_AOC_CHARGING_ASSOCIATION_NUMBER
Definition: aoc.h:187
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
uint32_t amount
Definition: aoc.c:261
char name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.c:263
uint32_t amount
Definition: aoc.c:267
uint8_t type
Definition: aoc.c:270
uint8_t valid_amount
Definition: aoc.c:269
uint8_t valid_type
Definition: aoc.c:268
union ast_aoc_charging_association::@183 charge
struct ast_aoc_charging_association_number number
Definition: aoc.h:197
enum ast_aoc_currency_multiplier multiplier
Definition: aoc.c:221
unsigned int currency_amount
Definition: aoc.c:222
struct ast_aoc_unit_entry unit_list[32]
Definition: aoc.c:227
char currency_name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.c:223
enum ast_aoc_billing_id billing_id
Definition: aoc.c:230
int unit_count
Definition: aoc.c:226
struct ast_aoc_s_entry aoc_s_entries[10]
Definition: aoc.c:237
struct ast_aoc_charging_association charging_association
Definition: aoc.c:233
char termination_request
Definition: aoc.c:240
int aoc_s_count
Definition: aoc.c:236
unsigned int amount
Definition: aoc.h:180
unsigned int type
Definition: aoc.h:182
char valid_type
Definition: aoc.h:181
char valid_amount
Definition: aoc.h:179

References ast_aoc_unit_entry::amount, aoc_ie_currency::amount, aoc_ie_unit::amount, aoc_append_ie(), aoc_create_ie_data_charging_rate(), AOC_IE_BILLING, AOC_IE_CHARGING_ASSOCIATION, AOC_IE_CURRENCY, AOC_IE_RATE, AOC_IE_TERMINATION_REQUEST, AOC_IE_UNIT, ast_aoc_decoded::aoc_s_count, ast_aoc_decoded::aoc_s_entries, AST_AOC_CHARGING_ASSOCIATION_ID, AST_AOC_CHARGING_ASSOCIATION_NA, AST_AOC_CHARGING_ASSOCIATION_NUMBER, ast_copy_string(), ast_strlen_zero(), ast_aoc_decoded::billing_id, aoc_ie_charging_association::ca, ast_aoc_charging_association::charge, ast_aoc_decoded::charging_association, ast_aoc_charging_association::charging_type, ast_aoc_decoded::currency_amount, ast_aoc_decoded::currency_name, ast_aoc_charging_association::id, aoc_ie_billing::id, ast_aoc_decoded::multiplier, aoc_ie_currency::name, NULL, ast_aoc_charging_association_number::number, ast_aoc_charging_association::number, ast_aoc_charging_association_number::plan, aoc_ie_data::pos, ast_aoc_decoded::termination_request, ast_aoc_unit_entry::type, aoc_ie_unit::type, ast_aoc_decoded::unit_count, ast_aoc_decoded::unit_list, ast_aoc_unit_entry::valid_amount, aoc_ie_unit::valid_amount, ast_aoc_unit_entry::valid_type, and aoc_ie_unit::valid_type.

Referenced by ast_aoc_encode().

◆ aoc_create_ie_data_charging_rate()

static void aoc_create_ie_data_charging_rate ( const struct ast_aoc_s_entry entry,
struct aoc_ie_charging_rate ie 
)
static

Definition at line 546 of file aoc.c.

547{
548 ie->entry.charged_item = htons(entry->charged_item);
549 ie->entry.rate_type = htons(entry->rate_type);
550
551 switch (entry->rate_type) {
554 ie->entry.rate.duration.amount = htonl(entry->rate.duration.amount);
555 ie->entry.rate.duration.time = htonl(entry->rate.duration.time);
559 ie->entry.rate.duration.charging_type = entry->rate.duration.charging_type; /* only one byte */
560
564 sizeof(ie->entry.rate.duration.currency_name));
565 }
566 break;
568 ie->entry.rate.flat.multiplier = htons(entry->rate.flat.multiplier);
569 ie->entry.rate.flat.amount = htonl(entry->rate.flat.amount);
570 if (!ast_strlen_zero(entry->rate.flat.currency_name)) {
572 entry->rate.flat.currency_name,
573 sizeof(ie->entry.rate.flat.currency_name));
574 }
575 break;
577 ie->entry.rate.volume.multiplier = htons(entry->rate.volume.multiplier);
578 ie->entry.rate.volume.amount = htonl(entry->rate.volume.amount);
579 ie->entry.rate.volume.volume_unit = htons(entry->rate.volume.volume_unit);
583 sizeof(ie->entry.rate.volume.currency_name));
584 }
585 break;
587 ie->entry.rate.special_code = htons(entry->rate.special_code);
588 break;
589 }
590
591}
@ AST_AOC_RATE_TYPE_VOLUME
Definition: aoc.h:161
@ AST_AOC_RATE_TYPE_SPECIAL_CODE
Definition: aoc.h:162
@ AST_AOC_RATE_TYPE_DURATION
Definition: aoc.h:159
@ AST_AOC_RATE_TYPE_FLAT
Definition: aoc.h:160
struct ast_aoc_s_entry entry
Definition: aoc.c:282
uint32_t amount
Definition: aoc.h:104
char currency_name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.h:114
uint16_t multiplier
Definition: aoc.h:109
uint16_t granularity_time_scale
Definition: aoc.h:111
uint8_t charging_type
Charging interval type.
Definition: aoc.h:122
uint16_t time_scale
Definition: aoc.h:110
uint32_t granularity_time
Definition: aoc.h:107
uint32_t time
Definition: aoc.h:105
uint32_t amount
Definition: aoc.h:139
char currency_name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.h:142
uint16_t multiplier
Definition: aoc.h:140
struct ast_aoc_flat_rate flat
Definition: aoc.h:172
uint16_t special_code
Definition: aoc.h:174
uint16_t charged_item
Definition: aoc.h:166
union ast_aoc_s_entry::@182 rate
Charge rate being applied.
struct ast_aoc_volume_rate volume
Definition: aoc.h:173
struct ast_aoc_duration_rate duration
Definition: aoc.h:171
uint16_t rate_type
Definition: aoc.h:167
uint32_t amount
Definition: aoc.h:132
char currency_name[AOC_CURRENCY_NAME_SIZE]
Definition: aoc.h:135
uint16_t multiplier
Definition: aoc.h:133
uint16_t volume_unit
Definition: aoc.h:134

References ast_aoc_duration_rate::amount, ast_aoc_volume_rate::amount, ast_aoc_flat_rate::amount, AST_AOC_RATE_TYPE_DURATION, AST_AOC_RATE_TYPE_FLAT, AST_AOC_RATE_TYPE_SPECIAL_CODE, AST_AOC_RATE_TYPE_VOLUME, ast_copy_string(), ast_strlen_zero(), ast_aoc_s_entry::charged_item, ast_aoc_duration_rate::charging_type, ast_aoc_duration_rate::currency_name, ast_aoc_volume_rate::currency_name, ast_aoc_flat_rate::currency_name, ast_aoc_s_entry::duration, aoc_ie_charging_rate::entry, ast_aoc_s_entry::flat, ast_aoc_duration_rate::granularity_time, ast_aoc_duration_rate::granularity_time_scale, ast_aoc_duration_rate::multiplier, ast_aoc_volume_rate::multiplier, ast_aoc_flat_rate::multiplier, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, ast_aoc_s_entry::special_code, ast_aoc_duration_rate::time, ast_aoc_duration_rate::time_scale, ast_aoc_s_entry::volume, and ast_aoc_volume_rate::volume_unit.

Referenced by aoc_create_ie_data().

◆ aoc_d_event()

static void aoc_d_event ( const struct ast_aoc_decoded decoded,
struct ast_str **  msg 
)
static

Definition at line 1516 of file aoc.c.

1517{
1518 const char *charge_str;
1519 int idx;
1520 char prefix[32];
1521
1522 charge_str = aoc_charge_type_str(decoded->charge_type);
1523 ast_str_append(msg, 0, "Type: %s\r\n", charge_str);
1524
1525 switch (decoded->charge_type) {
1528 ast_str_append(msg, 0, "BillingID: %s\r\n",
1529 aoc_billingid_str(decoded->billing_id));
1530 ast_str_append(msg, 0, "TypeOfCharging: %s\r\n",
1532 break;
1533 default:
1534 break;
1535 }
1536
1537 switch (decoded->charge_type) {
1539 ast_str_append(msg, 0, "%s: %s\r\n", charge_str,
1540 decoded->currency_name);
1541 aoc_amount_str(msg, charge_str,
1542 decoded->currency_amount,
1543 decoded->multiplier);
1544 break;
1546 ast_str_append(msg, 0, "%s/NumberItems: %d\r\n", charge_str,
1547 decoded->unit_count);
1548 for (idx = 0; idx < decoded->unit_count; ++idx) {
1549 snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, idx);
1550 if (decoded->unit_list[idx].valid_amount) {
1551 ast_str_append(msg, 0, "%s/NumberOf: %u\r\n", prefix,
1552 decoded->unit_list[idx].amount);
1553 }
1554 if (decoded->unit_list[idx].valid_type) {
1555 ast_str_append(msg, 0, "%s/TypeOf: %u\r\n", prefix,
1556 decoded->unit_list[idx].type);
1557 }
1558 }
1559 break;
1560 default:
1561 break;
1562 }
1563}
static const char * aoc_charge_type_str(enum ast_aoc_charge_type value)
Definition: aoc.c:1266
static const char * aoc_type_of_totaling_str(enum ast_aoc_total_type value)
Definition: aoc.c:1170
static const char * aoc_billingid_str(enum ast_aoc_billing_id billing_id)
Definition: aoc.c:1312
static void aoc_amount_str(struct ast_str **msg, const char *prefix, unsigned int amount, enum ast_aoc_currency_multiplier mult)
Definition: aoc.c:1419
enum ast_aoc_total_type total_type
Definition: aoc.c:218
enum ast_aoc_charge_type charge_type
Definition: aoc.c:216

References ast_aoc_unit_entry::amount, aoc_amount_str(), aoc_billingid_str(), aoc_charge_type_str(), aoc_type_of_totaling_str(), AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_UNIT, ast_str_append(), ast_aoc_decoded::billing_id, ast_aoc_decoded::charge_type, ast_aoc_decoded::currency_amount, ast_aoc_decoded::currency_name, ast_aoc_decoded::multiplier, prefix, ast_aoc_decoded::total_type, ast_aoc_unit_entry::type, ast_aoc_decoded::unit_count, ast_aoc_decoded::unit_list, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by ast_aoc_decoded2str().

◆ aoc_d_to_ami()

static struct ast_manager_event_blob * aoc_d_to_ami ( struct stasis_message message)
static

Definition at line 1905 of file aoc.c.

1906{
1907 return aoc_to_ami(message, "AOC-D");
1908}
static struct ast_manager_event_blob * aoc_to_ami(struct stasis_message *message, const char *event_name)
Definition: aoc.c:1874

References aoc_to_ami().

◆ aoc_d_type()

struct stasis_message_type * aoc_d_type ( void  )

◆ aoc_display_decoded_debug()

static void aoc_display_decoded_debug ( const struct ast_aoc_decoded decoded,
int  decoding,
struct ast_channel chan 
)
static

Definition at line 1991 of file aoc.c.

1992{
1993 struct ast_str *msg;
1994
1995 if (!decoded || !(msg = ast_str_create(1024))) {
1996 return;
1997 }
1998
1999 if (decoding) {
2000 ast_str_append(&msg, 0, "---- DECODED AOC MSG ----\r\n");
2001 } else {
2002 ast_str_append(&msg, 0, "---- ENCODED AOC MSG ----\r\n");
2003 }
2004 if (chan) {
2005 ast_str_append(&msg, 0, "CHANNEL: %s\r\n", ast_channel_name(chan));
2006 }
2007
2008 if (ast_aoc_decoded2str(decoded, &msg)) {
2009 ast_free(msg);
2010 return;
2011 }
2012
2013 ast_verb(1, "%s\r\n", ast_str_buffer(msg));
2014 ast_free(msg);
2015}
int ast_aoc_decoded2str(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Convert decoded aoc msg to string representation.
Definition: aoc.c:1963
#define ast_free(a)
Definition: astmm.h:180
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_verb(level,...)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
Support for dynamic strings.
Definition: strings.h:623

References ast_aoc_decoded2str(), ast_channel_name(), ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, and ast_verb.

Referenced by ast_aoc_decode(), and ast_aoc_encode().

◆ aoc_e_event()

static void aoc_e_event ( const struct ast_aoc_decoded decoded,
struct ast_str **  msg 
)
static

Definition at line 1565 of file aoc.c.

1566{
1567 const char *charge_str;
1568 int idx;
1569 char prefix[32];
1570
1571 charge_str = "ChargingAssociation";
1572
1573 switch (decoded->charging_association.charging_type) {
1575 snprintf(prefix, sizeof(prefix), "%s/Number", charge_str);
1576 ast_str_append(msg, 0, "%s: %s\r\n", prefix,
1578 ast_str_append(msg, 0, "%s/Plan: %d\r\n", prefix,
1580 break;
1582 ast_str_append(msg, 0, "%s/ID: %d\r\n", charge_str, decoded->charging_association.charge.id);
1583 break;
1585 default:
1586 break;
1587 }
1588
1589 charge_str = aoc_charge_type_str(decoded->charge_type);
1590 ast_str_append(msg, 0, "Type: %s\r\n", charge_str);
1591 switch (decoded->charge_type) {
1594 ast_str_append(msg, 0, "BillingID: %s\r\n",
1595 aoc_billingid_str(decoded->billing_id));
1596 break;
1597 default:
1598 break;
1599 }
1600 switch (decoded->charge_type) {
1602 ast_str_append(msg, 0, "%s: %s\r\n", charge_str,
1603 decoded->currency_name);
1604 aoc_amount_str(msg, charge_str,
1605 decoded->currency_amount,
1606 decoded->multiplier);
1607 break;
1609 ast_str_append(msg, 0, "%s/NumberItems: %d\r\n", charge_str,
1610 decoded->unit_count);
1611 for (idx = 0; idx < decoded->unit_count; ++idx) {
1612 snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, idx);
1613 if (decoded->unit_list[idx].valid_amount) {
1614 ast_str_append(msg, 0, "%s/NumberOf: %u\r\n", prefix,
1615 decoded->unit_list[idx].amount);
1616 }
1617 if (decoded->unit_list[idx].valid_type) {
1618 ast_str_append(msg, 0, "%s/TypeOf: %u\r\n", prefix,
1619 decoded->unit_list[idx].type);
1620 }
1621 }
1622 break;
1623 default:
1624 break;
1625 }
1626}

References ast_aoc_unit_entry::amount, aoc_amount_str(), aoc_billingid_str(), aoc_charge_type_str(), AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_UNIT, AST_AOC_CHARGING_ASSOCIATION_ID, AST_AOC_CHARGING_ASSOCIATION_NA, AST_AOC_CHARGING_ASSOCIATION_NUMBER, ast_str_append(), ast_aoc_decoded::billing_id, ast_aoc_charging_association::charge, ast_aoc_decoded::charge_type, ast_aoc_decoded::charging_association, ast_aoc_charging_association::charging_type, ast_aoc_decoded::currency_amount, ast_aoc_decoded::currency_name, ast_aoc_charging_association::id, ast_aoc_decoded::multiplier, ast_aoc_charging_association_number::number, ast_aoc_charging_association::number, ast_aoc_charging_association_number::plan, prefix, ast_aoc_unit_entry::type, ast_aoc_decoded::unit_count, ast_aoc_decoded::unit_list, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by ast_aoc_decoded2str().

◆ aoc_e_to_ami()

static struct ast_manager_event_blob * aoc_e_to_ami ( struct stasis_message message)
static

Definition at line 1910 of file aoc.c.

1911{
1912 return aoc_to_ami(message, "AOC-E");
1913}

References aoc_to_ami().

◆ aoc_e_type()

struct stasis_message_type * aoc_e_type ( void  )

◆ aoc_event_blob_dtor()

static void aoc_event_blob_dtor ( void *  obj)
static

Definition at line 1821 of file aoc.c.

1822{
1823 struct aoc_event_blob *aoc_event = obj;
1824
1825 ao2_cleanup(aoc_event->snapshot);
1826 ast_json_unref(aoc_event->blob);
1827}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_channel_snapshot * snapshot
Definition: aoc.c:1816
struct ast_json * blob
Definition: aoc.c:1818

References ao2_cleanup, ast_json_unref(), aoc_event_blob::blob, and aoc_event_blob::snapshot.

Referenced by aoc_publish_blob().

◆ aoc_multiplier_str()

static const char * aoc_multiplier_str ( enum ast_aoc_currency_multiplier  mult)
static

Definition at line 1289 of file aoc.c.

1290{
1291 switch (mult) {
1293 return "1/1000";
1295 return "1/100";
1297 return "1/10";
1298 case AST_AOC_MULT_ONE:
1299 return "1";
1300 case AST_AOC_MULT_TEN:
1301 return "10";
1303 return "100";
1305 return "1000";
1307 break;
1308 }
1309 return "1";
1310}
@ AST_AOC_MULT_TEN
Definition: aoc.h:39
@ AST_AOC_MULT_ONEHUNDREDTH
Definition: aoc.h:36
@ AST_AOC_MULT_HUNDRED
Definition: aoc.h:40
@ AST_AOC_MULT_NUM_ENTRIES
Definition: aoc.h:42
@ AST_AOC_MULT_ONETENTH
Definition: aoc.h:37
@ AST_AOC_MULT_ONETHOUSANDTH
Definition: aoc.h:35
@ AST_AOC_MULT_THOUSAND
Definition: aoc.h:41
@ AST_AOC_MULT_ONE
Definition: aoc.h:38

References AST_AOC_MULT_HUNDRED, AST_AOC_MULT_NUM_ENTRIES, AST_AOC_MULT_ONE, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETENTH, AST_AOC_MULT_ONETHOUSANDTH, AST_AOC_MULT_TEN, and AST_AOC_MULT_THOUSAND.

Referenced by aoc_amount_str(), and currency_to_json().

◆ aoc_parse_ie()

static int aoc_parse_ie ( struct ast_aoc_decoded decoded,
unsigned char *  data,
unsigned int  datalen 
)
static

Definition at line 378 of file aoc.c.

379{
380 enum AOC_IE ie_id;
381 unsigned int len;
382
383 while (datalen >= 2) {
384 ie_id = data[0];
385 len = data[1];
386 if (len > datalen -2) {
387 ast_log(LOG_ERROR, "AOC information element length exceeds the total message size\n");
388 return -1;
389 }
390
391 switch(ie_id) {
392 case AOC_IE_CURRENCY:
393 if (len == sizeof(struct aoc_ie_currency)) {
394 struct aoc_ie_currency ie;
395 memcpy(&ie, data + 2, len);
396 decoded->currency_amount = ntohl(ie.amount);
397 decoded->multiplier = ie.multiplier; /* only one byte */
398 memcpy(decoded->currency_name, ie.name, sizeof(decoded->currency_name));
399 } else {
400 ast_log(LOG_WARNING, "Received invalid currency ie\n");
401 }
402 break;
403 case AOC_IE_UNIT:
404 if (len == sizeof(struct aoc_ie_unit)) {
405 struct aoc_ie_unit ie;
406 memcpy(&ie, data + 2, len);
407 ast_aoc_add_unit_entry(decoded, ie.valid_amount, ntohl(ie.amount), ie.valid_type, ie.type);
408 } else {
409 ast_log(LOG_WARNING, "Received invalid unit ie\n");
410 }
411 break;
412 case AOC_IE_BILLING:
413 if (len == sizeof(struct aoc_ie_billing)) {
414 struct aoc_ie_billing ie;
415 memcpy(&ie, data + 2, len);
416 decoded->billing_id = ie.id; /* only one byte */
417 } else {
418 ast_log(LOG_WARNING, "Received invalid billing ie\n");
419 }
420 break;
422 if (len == sizeof(struct aoc_ie_charging_association)) {
423 memcpy(&decoded->charging_association, data + 2, sizeof(decoded->charging_association));
424 /* everything in the charging_association struct is a single byte except for the id */
426 decoded->charging_association.charge.id = ntohl(decoded->charging_association.charge.id);
427 }
428 } else {
429 ast_log(LOG_WARNING, "Received invalid charging association ie\n");
430 }
431 break;
432 case AOC_IE_RATE:
433 if (len == sizeof(struct aoc_ie_charging_rate)) {
434 struct aoc_ie_charging_rate ie;
435 memcpy(&ie, data + 2, len);
436 aoc_parse_ie_charging_rate(decoded, &ie);
437 } else {
438 ast_log(LOG_WARNING, "Received invalid charging rate ie\n");
439 }
440 break;
442 if (len == 0) {
443 decoded->termination_request = 1;
444 } else {
445 ast_log(LOG_WARNING, "Received invalid termination request ie\n");
446 }
447 break;
448 default:
449 ast_log(LOG_WARNING, "Unknown AOC Information Element, ignoring.\n");
450 }
451
452 datalen -= (len + 2);
453 data += (len + 2);
454 }
455 return 0;
456}
AOC_IE
AOC Payload Information Elements.
Definition: aoc.c:244
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.
Definition: aoc.c:986
static void aoc_parse_ie_charging_rate(struct ast_aoc_decoded *decoded, const struct aoc_ie_charging_rate *ie)
Definition: aoc.c:328
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_ERROR

References aoc_ie_currency::amount, aoc_ie_unit::amount, AOC_IE_BILLING, AOC_IE_CHARGING_ASSOCIATION, AOC_IE_CURRENCY, AOC_IE_RATE, AOC_IE_TERMINATION_REQUEST, AOC_IE_UNIT, aoc_parse_ie_charging_rate(), ast_aoc_add_unit_entry(), AST_AOC_CHARGING_ASSOCIATION_ID, ast_log, ast_aoc_decoded::billing_id, ast_aoc_charging_association::charge, ast_aoc_decoded::charging_association, ast_aoc_charging_association::charging_type, ast_aoc_decoded::currency_amount, ast_aoc_decoded::currency_name, ast_aoc_charging_association::id, aoc_ie_billing::id, len(), LOG_ERROR, LOG_WARNING, ast_aoc_decoded::multiplier, aoc_ie_currency::multiplier, aoc_ie_currency::name, ast_aoc_decoded::termination_request, aoc_ie_unit::type, aoc_ie_unit::valid_amount, and aoc_ie_unit::valid_type.

Referenced by ast_aoc_decode().

◆ aoc_parse_ie_charging_rate()

static void aoc_parse_ie_charging_rate ( struct ast_aoc_decoded decoded,
const struct aoc_ie_charging_rate ie 
)
static

Definition at line 328 of file aoc.c.

329{
330 struct ast_aoc_s_entry entry = { 0, };
331
332 entry.charged_item = ntohs(ie->entry.charged_item);
333 entry.rate_type = ntohs(ie->entry.rate_type);
334
335 switch (entry.rate_type) {
338 entry.rate.duration.amount = ntohl(ie->entry.rate.duration.amount);
339 entry.rate.duration.time = ntohl(ie->entry.rate.duration.time);
343 entry.rate.duration.charging_type = ie->entry.rate.duration.charging_type; /* only one byte */
344
348 sizeof(entry.rate.duration.currency_name));
349 }
350 break;
352 entry.rate.flat.multiplier = ntohs(ie->entry.rate.flat.multiplier);
353 entry.rate.flat.amount = ntohl(ie->entry.rate.flat.amount);
357 sizeof(entry.rate.flat.currency_name));
358 }
359 break;
361 entry.rate.volume.multiplier = ntohs(ie->entry.rate.volume.multiplier);
362 entry.rate.volume.amount = ntohl(ie->entry.rate.volume.amount);
367 sizeof(entry.rate.volume.currency_name));
368 }
369 break;
371 entry.rate.special_code = ntohs(ie->entry.rate.special_code);
372 break;
373 }
374
375 aoc_s_add_entry(decoded, &entry);
376}
static int aoc_s_add_entry(struct ast_aoc_decoded *decoded, struct ast_aoc_s_entry *entry)
Definition: aoc.c:752
Definition: aoc.h:165

References ast_aoc_duration_rate::amount, ast_aoc_volume_rate::amount, ast_aoc_flat_rate::amount, aoc_s_add_entry(), AST_AOC_RATE_TYPE_DURATION, AST_AOC_RATE_TYPE_FLAT, AST_AOC_RATE_TYPE_SPECIAL_CODE, AST_AOC_RATE_TYPE_VOLUME, ast_copy_string(), ast_strlen_zero(), ast_aoc_s_entry::charged_item, ast_aoc_duration_rate::charging_type, ast_aoc_duration_rate::currency_name, ast_aoc_volume_rate::currency_name, ast_aoc_flat_rate::currency_name, ast_aoc_s_entry::duration, aoc_ie_charging_rate::entry, ast_aoc_s_entry::flat, ast_aoc_duration_rate::granularity_time, ast_aoc_duration_rate::granularity_time_scale, ast_aoc_duration_rate::multiplier, ast_aoc_volume_rate::multiplier, ast_aoc_flat_rate::multiplier, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, ast_aoc_s_entry::special_code, ast_aoc_duration_rate::time, ast_aoc_duration_rate::time_scale, ast_aoc_s_entry::volume, and ast_aoc_volume_rate::volume_unit.

Referenced by aoc_parse_ie().

◆ aoc_publish_blob()

static void aoc_publish_blob ( struct ast_channel chan,
struct stasis_message_type msg_type,
struct ast_json blob 
)
static

Definition at line 1838 of file aoc.c.

1839{
1840 struct stasis_message *msg;
1841 struct aoc_event_blob *aoc_event;
1842
1843 if (!blob || ast_json_is_null(blob)) {
1844 /* No AOC blob information? Nothing to send an event about. */
1845 return;
1846 }
1847
1848 aoc_event = ao2_alloc_options(sizeof(*aoc_event), aoc_event_blob_dtor,
1850 if (!aoc_event) {
1851 return;
1852 }
1853
1854 if (chan) {
1855 ast_channel_lock(chan);
1856 aoc_event->snapshot = ao2_bump(ast_channel_snapshot(chan));
1857 ast_channel_unlock(chan);
1858 if (!aoc_event->snapshot) {
1859 ao2_ref(aoc_event, -1);
1860 return;
1861 }
1862 }
1863 aoc_event->blob = ast_json_ref(blob);
1864
1865 msg = stasis_message_create(msg_type, aoc_event);
1866 ao2_ref(aoc_event, -1);
1867
1868 if (msg) {
1870 ao2_ref(msg, -1);
1871 }
1872}
static void aoc_event_blob_dtor(void *obj)
Definition: aoc.c:1821
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
#define ast_channel_lock(chan)
Definition: channel.h:2970
struct ast_channel_snapshot * ast_channel_snapshot(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2971
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:454
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int ast_json_is_null(const struct ast_json *value)
Check if value is JSON null.
Definition: json.c:273
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1538

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_ref, aoc_event_blob_dtor(), ast_channel_lock, ast_channel_snapshot(), ast_channel_unlock, ast_json_is_null(), ast_json_ref(), ast_manager_get_topic(), aoc_event_blob::blob, aoc_event_blob::snapshot, stasis_message_create(), and stasis_publish().

Referenced by ast_aoc_manager_event().

◆ aoc_rate_type_str()

static const char * aoc_rate_type_str ( enum ast_aoc_s_rate_type  value)
static

Definition at line 1195 of file aoc.c.

1196{
1197 const char *str;
1198
1199 switch (value) {
1200 default:
1202 str = "NotAvailable";
1203 break;
1205 str = "Free";
1206 break;
1208 str = "FreeFromBeginning";
1209 break;
1211 str = "Duration";
1212 break;
1214 str = "Flat";
1215 break;
1217 str = "Volume";
1218 break;
1220 str = "SpecialCode";
1221 break;
1222 }
1223 return str;
1224}
@ AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING
Definition: aoc.h:158
@ AST_AOC_RATE_TYPE_NA
Definition: aoc.h:156
@ AST_AOC_RATE_TYPE_FREE
Definition: aoc.h:157

References AST_AOC_RATE_TYPE_DURATION, AST_AOC_RATE_TYPE_FLAT, AST_AOC_RATE_TYPE_FREE, AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING, AST_AOC_RATE_TYPE_NA, AST_AOC_RATE_TYPE_SPECIAL_CODE, AST_AOC_RATE_TYPE_VOLUME, str, and value.

Referenced by aoc_s_event(), and s_to_json().

◆ aoc_request_event()

static void aoc_request_event ( const struct ast_aoc_decoded decoded,
struct ast_str **  msg 
)
static

Definition at line 1428 of file aoc.c.

1429{
1430 if (decoded->request_flag) {
1431 ast_str_append(msg, 0, "AOCRequest:");
1432 if (decoded->request_flag & AST_AOC_REQUEST_S) {
1433 ast_str_append(msg, 0, "S");
1434 }
1435 if (decoded->request_flag & AST_AOC_REQUEST_D) {
1436 ast_str_append(msg, 0, "D");
1437 }
1438 if (decoded->request_flag & AST_AOC_REQUEST_E) {
1439 ast_str_append(msg, 0, "E");
1440 }
1441 ast_str_append(msg, 0, "\r\n");
1442
1443 } else {
1444 ast_str_append(msg, 0, "AOCRequest: NONE\r\n");
1445 }
1446}
@ AST_AOC_REQUEST_E
Definition: aoc.h:79
@ AST_AOC_REQUEST_D
Definition: aoc.h:78
@ AST_AOC_REQUEST_S
Definition: aoc.h:77
enum ast_aoc_request request_flag
Definition: aoc.c:217

References AST_AOC_REQUEST_D, AST_AOC_REQUEST_E, AST_AOC_REQUEST_S, ast_str_append(), and ast_aoc_decoded::request_flag.

Referenced by ast_aoc_decoded2str().

◆ aoc_s_add_entry()

static int aoc_s_add_entry ( struct ast_aoc_decoded decoded,
struct ast_aoc_s_entry entry 
)
static

◆ aoc_s_event()

static void aoc_s_event ( const struct ast_aoc_decoded decoded,
struct ast_str **  msg 
)
static

Definition at line 1448 of file aoc.c.

1449{
1450 const char *rate_str;
1451 char prefix[32];
1452 int idx;
1453
1454 ast_str_append(msg, 0, "NumberRates: %d\r\n", decoded->aoc_s_count);
1455 for (idx = 0; idx < decoded->aoc_s_count; ++idx) {
1456 snprintf(prefix, sizeof(prefix), "Rate(%d)", idx);
1457
1458 ast_str_append(msg, 0, "%s/Chargeable: %s\r\n", prefix,
1460 if (decoded->aoc_s_entries[idx].charged_item == AST_AOC_CHARGED_ITEM_NA) {
1461 continue;
1462 }
1463 rate_str = aoc_rate_type_str(decoded->aoc_s_entries[idx].rate_type);
1464 ast_str_append(msg, 0, "%s/Type: %s\r\n", prefix, rate_str);
1465 switch (decoded->aoc_s_entries[idx].rate_type) {
1467 strcat(prefix, "/");
1468 strcat(prefix, rate_str);
1469 ast_str_append(msg, 0, "%s/Currency: %s\r\n", prefix,
1472 decoded->aoc_s_entries[idx].rate.duration.amount,
1473 decoded->aoc_s_entries[idx].rate.duration.multiplier);
1474 ast_str_append(msg, 0, "%s/ChargingType: %s\r\n", prefix,
1476 "StepFunction" : "ContinuousCharging");
1477 aoc_time_str(msg, prefix, "Time",
1478 decoded->aoc_s_entries[idx].rate.duration.time,
1479 decoded->aoc_s_entries[idx].rate.duration.time_scale);
1480 if (decoded->aoc_s_entries[idx].rate.duration.granularity_time) {
1481 aoc_time_str(msg, prefix, "Granularity",
1484 }
1485 break;
1487 strcat(prefix, "/");
1488 strcat(prefix, rate_str);
1489 ast_str_append(msg, 0, "%s/Currency: %s\r\n", prefix,
1490 decoded->aoc_s_entries[idx].rate.flat.currency_name);
1492 decoded->aoc_s_entries[idx].rate.flat.amount,
1493 decoded->aoc_s_entries[idx].rate.flat.multiplier);
1494 break;
1496 strcat(prefix, "/");
1497 strcat(prefix, rate_str);
1498 ast_str_append(msg, 0, "%s/Currency: %s\r\n", prefix,
1499 decoded->aoc_s_entries[idx].rate.volume.currency_name);
1501 decoded->aoc_s_entries[idx].rate.volume.amount,
1502 decoded->aoc_s_entries[idx].rate.volume.multiplier);
1503 ast_str_append(msg, 0, "%s/Unit: %s\r\n", prefix,
1505 break;
1507 ast_str_append(msg, 0, "%s/%s: %d\r\n", prefix, rate_str,
1508 decoded->aoc_s_entries[idx].rate.special_code);
1509 break;
1510 default:
1511 break;
1512 }
1513 }
1514}
static const char * aoc_charged_item_str(enum ast_aoc_s_charged_item value)
Definition: aoc.c:1130
static const char * aoc_volume_unit_str(enum ast_aoc_volume_unit value)
Definition: aoc.c:1102
static void aoc_time_str(struct ast_str **msg, const char *prefix, const char *name, unsigned long time, enum ast_aoc_time_scale scale)
Definition: aoc.c:1402
static const char * aoc_rate_type_str(enum ast_aoc_s_rate_type value)
Definition: aoc.c:1195

References ast_aoc_duration_rate::amount, ast_aoc_volume_rate::amount, ast_aoc_flat_rate::amount, aoc_amount_str(), aoc_charged_item_str(), aoc_rate_type_str(), ast_aoc_decoded::aoc_s_count, ast_aoc_decoded::aoc_s_entries, aoc_time_str(), aoc_volume_unit_str(), AST_AOC_CHARGED_ITEM_NA, AST_AOC_RATE_TYPE_DURATION, AST_AOC_RATE_TYPE_FLAT, AST_AOC_RATE_TYPE_SPECIAL_CODE, AST_AOC_RATE_TYPE_VOLUME, ast_str_append(), ast_aoc_s_entry::charged_item, ast_aoc_duration_rate::charging_type, ast_aoc_duration_rate::currency_name, ast_aoc_volume_rate::currency_name, ast_aoc_flat_rate::currency_name, ast_aoc_s_entry::duration, ast_aoc_s_entry::flat, ast_aoc_duration_rate::granularity_time, ast_aoc_duration_rate::granularity_time_scale, ast_aoc_duration_rate::multiplier, ast_aoc_volume_rate::multiplier, ast_aoc_flat_rate::multiplier, prefix, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, ast_aoc_s_entry::special_code, ast_aoc_duration_rate::time, ast_aoc_duration_rate::time_scale, ast_aoc_s_entry::volume, and ast_aoc_volume_rate::volume_unit.

Referenced by ast_aoc_decoded2str().

◆ aoc_s_to_ami()

static struct ast_manager_event_blob * aoc_s_to_ami ( struct stasis_message message)
static

Definition at line 1900 of file aoc.c.

1901{
1902 return aoc_to_ami(message, "AOC-S");
1903}

References aoc_to_ami().

◆ aoc_s_type()

struct stasis_message_type * aoc_s_type ( void  )

◆ aoc_scale_str()

static const char * aoc_scale_str ( enum ast_aoc_time_scale  value)
static

Definition at line 1235 of file aoc.c.

1236{
1237 const char *str;
1238
1239 switch (value) {
1240 default:
1242 str = "OneHundredthSecond";
1243 break;
1245 str = "OneTenthSecond";
1246 break;
1248 str = "Second";
1249 break;
1251 str = "TenSeconds";
1252 break;
1254 str = "Minute";
1255 break;
1257 str = "Hour";
1258 break;
1260 str = "Day";
1261 break;
1262 }
1263 return str;
1264}
@ AST_AOC_TIME_SCALE_TEN_SECOND
Definition: aoc.h:91
@ AST_AOC_TIME_SCALE_DAY
Definition: aoc.h:94
@ AST_AOC_TIME_SCALE_TENTH_SECOND
Definition: aoc.h:89
@ AST_AOC_TIME_SCALE_MINUTE
Definition: aoc.h:92
@ AST_AOC_TIME_SCALE_SECOND
Definition: aoc.h:90
@ AST_AOC_TIME_SCALE_HOUR
Definition: aoc.h:93
@ AST_AOC_TIME_SCALE_HUNDREDTH_SECOND
Definition: aoc.h:88

References AST_AOC_TIME_SCALE_DAY, AST_AOC_TIME_SCALE_HOUR, AST_AOC_TIME_SCALE_HUNDREDTH_SECOND, AST_AOC_TIME_SCALE_MINUTE, AST_AOC_TIME_SCALE_SECOND, AST_AOC_TIME_SCALE_TEN_SECOND, AST_AOC_TIME_SCALE_TENTH_SECOND, str, and value.

Referenced by aoc_time_str().

◆ aoc_shutdown()

static void aoc_shutdown ( void  )
static

Definition at line 2021 of file aoc.c.

2022{
2026
2028}
struct stasis_message_type * aoc_s_type(void)
static struct ast_cli_entry aoc_cli[]
Definition: aoc.c:2017
struct stasis_message_type * aoc_d_type(void)
struct stasis_message_type * aoc_e_type(void)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1515

References aoc_cli, aoc_d_type(), aoc_e_type(), aoc_s_type(), ARRAY_LEN, ast_cli_unregister_multiple(), and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by ast_aoc_cli_init().

◆ aoc_time_str()

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

Definition at line 1402 of file aoc.c.

1403{
1404 ast_str_append(msg, 0, "%s/%s/Length: %lu\r\n", prefix, name, time);
1405 ast_str_append(msg, 0, "%s/%s/Scale: %s\r\n", prefix, name,
1406 aoc_scale_str(scale));
1407}
static const char * aoc_scale_str(enum ast_aoc_time_scale value)
Definition: aoc.c:1235

References aoc_scale_str(), ast_str_append(), name, and prefix.

Referenced by aoc_s_event().

◆ aoc_to_ami()

static struct ast_manager_event_blob * aoc_to_ami ( struct stasis_message message,
const char *  event_name 
)
static

Definition at line 1874 of file aoc.c.

1876{
1877 struct aoc_event_blob *aoc_event = stasis_message_data(message);
1878 struct ast_str *channel = NULL;
1879 struct ast_str *aoc;
1880 struct ast_manager_event_blob *ev = NULL;
1881
1882 if (aoc_event->snapshot) {
1884 if (!channel) {
1885 return NULL;
1886 }
1887 }
1888
1889 aoc = ast_manager_str_from_json_object(aoc_event->blob, NULL);
1890 if (aoc && !ast_strlen_zero(ast_str_buffer(aoc))) {
1891 ev = ast_manager_event_blob_create(EVENT_FLAG_AOC, event_name, "%s%s",
1892 AS_OR(channel, ""), ast_str_buffer(aoc));
1893 }
1894
1895 ast_free(aoc);
1896 ast_free(channel);
1897 return ev;
1898}
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.
Definition: manager.c:555
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_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.
Definition: manager.c:10237
#define EVENT_FLAG_AOC
Definition: manager.h:91
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define AS_OR(a, b)
Definition: strings.h:49
Struct containing info for an AMI event to send out.
Definition: manager.h:503

References AS_OR, ast_free, ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_manager_str_from_json_object(), ast_str_buffer(), ast_strlen_zero(), aoc_event_blob::blob, EVENT_FLAG_AOC, NULL, aoc_event_blob::snapshot, and stasis_message_data().

Referenced by aoc_d_to_ami(), aoc_e_to_ami(), and aoc_s_to_ami().

◆ aoc_type_of_totaling_str()

static const char * aoc_type_of_totaling_str ( enum ast_aoc_total_type  value)
static

Definition at line 1170 of file aoc.c.

1171{
1172 const char *str;
1173
1174 switch (value) {
1175 default:
1176 case AST_AOC_SUBTOTAL:
1177 str = "SubTotal";
1178 break;
1179 case AST_AOC_TOTAL:
1180 str = "Total";
1181 break;
1182 }
1183 return str;
1184}
@ AST_AOC_TOTAL
Definition: aoc.h:83
@ AST_AOC_SUBTOTAL
Definition: aoc.h:84

References AST_AOC_SUBTOTAL, AST_AOC_TOTAL, str, and value.

Referenced by aoc_d_event(), and charge_to_json().

◆ aoc_volume_unit_str()

static const char * aoc_volume_unit_str ( enum ast_aoc_volume_unit  value)
static

Definition at line 1102 of file aoc.c.

1103{
1104 const char *str;
1105
1106 switch (value) {
1107 default:
1109 str = "Octet";
1110 break;
1112 str = "Segment";
1113 break;
1115 str = "Message";
1116 break;
1117 }
1118 return str;
1119}
@ AST_AOC_VOLUME_UNIT_OCTET
Definition: aoc.h:126
@ AST_AOC_VOLUME_UNIT_SEGMENT
Definition: aoc.h:127
@ AST_AOC_VOLUME_UNIT_MESSAGE
Definition: aoc.h:128

References AST_AOC_VOLUME_UNIT_MESSAGE, AST_AOC_VOLUME_UNIT_OCTET, AST_AOC_VOLUME_UNIT_SEGMENT, str, and value.

Referenced by aoc_s_event(), and s_to_json().

◆ association_to_json()

static struct ast_json * association_to_json ( const struct ast_aoc_decoded decoded)
static

Definition at line 1696 of file aoc.c.

1697{
1698 switch (decoded->charging_association.charging_type) {
1700 return ast_json_pack("{s:s, s:i}",
1702 "Plan", decoded->charging_association.charge.number.plan);
1704 return ast_json_pack("{s:i}", "ID", decoded->charging_association.charge.id);
1706 default:
1707 return ast_json_null();
1708 }
1709}
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
Definition: json.h:224

References AST_AOC_CHARGING_ASSOCIATION_ID, AST_AOC_CHARGING_ASSOCIATION_NA, AST_AOC_CHARGING_ASSOCIATION_NUMBER, ast_json_null(), ast_json_pack(), AST_JSON_UTF8_VALIDATE, ast_aoc_charging_association::charge, ast_aoc_decoded::charging_association, ast_aoc_charging_association::charging_type, ast_aoc_charging_association::id, ast_aoc_charging_association_number::number, ast_aoc_charging_association::number, and ast_aoc_charging_association_number::plan.

Referenced by e_to_json().

◆ ast_aoc_add_unit_entry()

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 986 of file aoc.c.

991{
992 if ((decoded->msg_type == AST_AOC_REQUEST) ||
993 (decoded->unit_count >= ARRAY_LEN(decoded->unit_list))) {
994 return -1;
995 }
996
997 if (!amount_is_present && !type_is_present) {
998 return -1;
999 }
1000
1001 decoded->unit_list[decoded->unit_count].valid_amount = amount_is_present;
1002 if (amount_is_present) {
1003 decoded->unit_list[decoded->unit_count].amount = amount;
1004 } else {
1005 decoded->unit_list[decoded->unit_count].amount = 0;
1006 }
1007
1008 decoded->unit_list[decoded->unit_count].valid_type = type_is_present;
1009 if (type_is_present) {
1010 decoded->unit_list[decoded->unit_count].type = type;
1011 } else {
1012 decoded->unit_list[decoded->unit_count].type = 0;
1013 }
1014 decoded->unit_count++;
1015
1016 return 0;
1017}
@ AST_AOC_REQUEST
Definition: aoc.h:63
static const char type[]
Definition: chan_ooh323.c:109
enum ast_aoc_type msg_type
Definition: aoc.c:215

References ast_aoc_unit_entry::amount, ARRAY_LEN, AST_AOC_REQUEST, ast_aoc_decoded::msg_type, type, ast_aoc_unit_entry::type, ast_aoc_decoded::unit_count, ast_aoc_decoded::unit_list, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by action_aoc_de_message(), aoc_parse_ie(), and AST_TEST_DEFINE().

◆ ast_aoc_cli_init()

int ast_aoc_cli_init ( void  )

enable aoc cli options

Definition at line 2029 of file aoc.c.

2030{
2034
2037}
static void aoc_shutdown(void)
Definition: aoc.c:2021
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493

References aoc_cli, aoc_d_type(), aoc_e_type(), aoc_s_type(), aoc_shutdown(), ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), and STASIS_MESSAGE_TYPE_INIT.

Referenced by asterisk_daemon().

◆ ast_aoc_create()

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 285 of file aoc.c.

288{
289 struct ast_aoc_decoded *decoded = NULL;
290
291 /* verify input */
292 if (((unsigned int) charge_type > AST_AOC_CHARGE_UNIT) ||
293 ((unsigned int) msg_type > AST_AOC_E) ||
294 ((msg_type == AST_AOC_REQUEST) && !requests)) {
295
296 ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object, invalid input\n");
297 return NULL;
298 }
299
300 if (!(decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded)))) {
301 ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
302 return NULL;
303 }
304
305 decoded->msg_type = msg_type;
306
307 if (msg_type == AST_AOC_REQUEST) {
308 decoded->request_flag = requests;
309 } else if ((msg_type == AST_AOC_D) || (msg_type == AST_AOC_E)) {
310 decoded->charge_type = charge_type;
311 }
312
313 return decoded;
314}
@ AST_AOC_D
Definition: aoc.h:65
@ AST_AOC_E
Definition: aoc.h:66
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
static struct requests requests

References AST_AOC_CHARGE_UNIT, AST_AOC_D, AST_AOC_E, AST_AOC_REQUEST, ast_calloc, ast_log, ast_aoc_decoded::charge_type, LOG_WARNING, ast_aoc_decoded::msg_type, NULL, ast_aoc_decoded::request_flag, and requests.

Referenced by action_aoc_de_message(), action_aoc_s_message(), and AST_TEST_DEFINE().

◆ ast_aoc_decode()

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 458 of file aoc.c.

459{
460 struct ast_aoc_decoded *decoded;
461
462 /* verify our encoded payload is actually large enough to hold all the ies */
463 if ((size - (sizeof(struct ast_aoc_encoded)) != ntohs(encoded->datalen))) {
464 ast_log(LOG_WARNING, "Corrupted aoc encoded object, can not decode\n");
465 return NULL;
466 }
467
468 if (!(decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded)))) {
469 ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
470 return NULL;
471 }
472
473 /* decode flags */
474
476 decoded->msg_type = AST_AOC_S;
477 } else if (encoded->flags & AST_AOC_ENCODED_TYPE_E) {
478 decoded->msg_type = AST_AOC_E;
479 } else if (encoded->flags & AST_AOC_ENCODED_TYPE_D) {
480 decoded->msg_type = AST_AOC_D;
481 } else {
482 decoded->msg_type = AST_AOC_REQUEST;
483 }
484
485 if (decoded->msg_type == AST_AOC_REQUEST) {
486 if (encoded->flags & AST_AOC_ENCODED_REQUEST_S) {
488 }
489 if (encoded->flags & AST_AOC_ENCODED_REQUEST_D) {
491 }
492 if (encoded->flags & AST_AOC_ENCODED_REQUEST_E) {
494 }
495 } else if ((decoded->msg_type == AST_AOC_D) || (decoded->msg_type == AST_AOC_E)) {
502 } else {
504 }
505
506 if (encoded->flags & AST_AOC_ENCODED_CHARGE_SUBTOTAL) {
507 decoded->total_type = AST_AOC_SUBTOTAL;
508 }
509 }
510
511 /* decode information elements */
512 aoc_parse_ie(decoded, encoded->data, ntohs(encoded->datalen));
513
514 if (aoc_debug_enabled) {
515 aoc_display_decoded_debug(decoded, 1, chan);
516 }
517
518 return decoded;
519}
#define AST_AOC_ENCODED_CHARGE_UNIT
Definition: aoc.c:193
static int aoc_parse_ie(struct ast_aoc_decoded *decoded, unsigned char *data, unsigned int datalen)
Definition: aoc.c:378
#define AST_AOC_ENCODED_TYPE_D
Definition: aoc.c:182
#define AST_AOC_ENCODED_CHARGE_CURRENCY
Definition: aoc.c:192
#define AST_AOC_ENCODED_REQUEST_E
Definition: aoc.c:188
#define AST_AOC_ENCODED_REQUEST_D
Definition: aoc.c:187
static void aoc_display_decoded_debug(const struct ast_aoc_decoded *decoded, int decoding, struct ast_channel *chan)
Definition: aoc.c:1991
#define AST_AOC_ENCODED_TYPE_S
Definition: aoc.c:184
#define AST_AOC_ENCODED_CHARGE_SUBTOTAL
Definition: aoc.c:195
#define AST_AOC_ENCODED_CHARGE_FREE
Definition: aoc.c:191
#define AST_AOC_ENCODED_REQUEST_S
Definition: aoc.c:186
#define AST_AOC_ENCODED_TYPE_E
Definition: aoc.c:183
@ AST_AOC_S
Definition: aoc.h:64
uint16_t datalen
Definition: aoc.c:209
uint8_t flags
Definition: aoc.c:208
unsigned char data[0]
Definition: aoc.c:210

References aoc_debug_enabled, aoc_display_decoded_debug(), aoc_parse_ie(), AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_NA, AST_AOC_CHARGE_UNIT, AST_AOC_D, AST_AOC_E, AST_AOC_ENCODED_CHARGE_CURRENCY, AST_AOC_ENCODED_CHARGE_FREE, AST_AOC_ENCODED_CHARGE_SUBTOTAL, AST_AOC_ENCODED_CHARGE_UNIT, AST_AOC_ENCODED_REQUEST_D, AST_AOC_ENCODED_REQUEST_E, AST_AOC_ENCODED_REQUEST_S, AST_AOC_ENCODED_TYPE_D, AST_AOC_ENCODED_TYPE_E, AST_AOC_ENCODED_TYPE_S, AST_AOC_REQUEST, AST_AOC_REQUEST_D, AST_AOC_REQUEST_E, AST_AOC_REQUEST_S, AST_AOC_S, AST_AOC_SUBTOTAL, ast_calloc, ast_log, ast_aoc_decoded::charge_type, ast_aoc_encoded::data, ast_aoc_encoded::datalen, ast_aoc_encoded::flags, LOG_WARNING, ast_aoc_decoded::msg_type, NULL, ast_aoc_decoded::request_flag, and ast_aoc_decoded::total_type.

Referenced by aoc_framehook(), ast_aoc_test_encode_decode_match(), and wait_for_answer().

◆ ast_aoc_decoded2str()

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 1963 of file aoc.c.

1964{
1965 if (!decoded || !msg) {
1966 return -1;
1967 }
1968
1969 switch (decoded->msg_type) {
1970 case AST_AOC_S:
1971 ast_str_append(msg, 0, "AOC-S\r\n");
1972 aoc_s_event(decoded, msg);
1973 break;
1974 case AST_AOC_D:
1975 ast_str_append(msg, 0, "AOC-D\r\n");
1976 aoc_d_event(decoded, msg);
1977 break;
1978 case AST_AOC_E:
1979 ast_str_append(msg, 0, "AOC-E\r\n");
1980 aoc_e_event(decoded, msg);
1981 break;
1982 case AST_AOC_REQUEST:
1983 ast_str_append(msg, 0, "AOC-Request\r\n");
1984 aoc_request_event(decoded, msg);
1985 break;
1986 }
1987
1988 return 0;
1989}
static void aoc_e_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Definition: aoc.c:1565
static void aoc_request_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Definition: aoc.c:1428
static void aoc_s_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Definition: aoc.c:1448
static void aoc_d_event(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Definition: aoc.c:1516

References aoc_d_event(), aoc_e_event(), aoc_request_event(), aoc_s_event(), AST_AOC_D, AST_AOC_E, AST_AOC_REQUEST, AST_AOC_S, ast_str_append(), and ast_aoc_decoded::msg_type.

Referenced by aoc_display_decoded_debug(), and AST_TEST_DEFINE().

◆ ast_aoc_destroy_decoded()

void * ast_aoc_destroy_decoded ( struct ast_aoc_decoded decoded)

◆ ast_aoc_destroy_encoded()

void * ast_aoc_destroy_encoded ( struct ast_aoc_encoded encoded)

free an ast_aoc_encoded object

Definition at line 322 of file aoc.c.

323{
324 ast_free(encoded);
325 return NULL;
326}

References ast_free, and NULL.

Referenced by action_aocmessage(), ast_aoc_test_encode_decode_match(), and wait_for_answer().

◆ ast_aoc_encode()

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 659 of file aoc.c.

660{
661 struct aoc_ie_data ied;
662 struct ast_aoc_encoded *encoded = NULL;
663 size_t size = 0;
664
665 if (!decoded || !out_size) {
666 return NULL;
667 }
668
669 *out_size = 0;
670
671 /* create information element buffer before allocating the payload,
672 * by doing this the exact size of the payload + the id data can be
673 * allocated all at once. */
674 aoc_create_ie_data(decoded, &ied);
675
676 size = sizeof(struct ast_aoc_encoded) + ied.pos;
677
678 if (!(encoded = ast_calloc(1, size))) {
679 ast_log(LOG_WARNING, "Failed to create ast_aoc_encoded object during decode routine. \n");
680 return NULL;
681 }
682
683 /* -- Set ie data buffer */
684 if (ied.pos) {
685 /* this is safe because encoded was allocated to fit this perfectly */
686 memcpy(encoded->data, ied.buf, ied.pos);
687 encoded->datalen = htons(ied.pos);
688 }
689
690 /* --- Set Flags --- */
691 switch (decoded->msg_type) {
692 case AST_AOC_S:
693 encoded->flags = AST_AOC_ENCODED_TYPE_S;
694 break;
695 case AST_AOC_D:
696 encoded->flags = AST_AOC_ENCODED_TYPE_D;
697 break;
698 case AST_AOC_E:
699 encoded->flags = AST_AOC_ENCODED_TYPE_E;
700 break;
701 case AST_AOC_REQUEST:
703 default:
704 break;
705 }
706
707 /* if it is type request, set the types requested, else set charge type */
708 if (decoded->msg_type == AST_AOC_REQUEST) {
709 if (decoded->request_flag & AST_AOC_REQUEST_S) {
711 }
712 if (decoded->request_flag & AST_AOC_REQUEST_D) {
714 }
715 if (decoded->request_flag & AST_AOC_REQUEST_E) {
717 }
718 } else if ((decoded->msg_type == AST_AOC_D) || (decoded->msg_type == AST_AOC_E)) {
719 switch (decoded->charge_type) {
722 break;
725 break;
729 default:
731 break;
732 }
733
734 if (decoded->total_type == AST_AOC_SUBTOTAL) {
736 }
737 }
738
739 /* --- Set Version Number --- */
741
742 /* set the output size */
743 *out_size = size;
744
745 if (aoc_debug_enabled) {
746 aoc_display_decoded_debug(decoded, 0, chan);
747 }
748
749 return encoded;
750}
#define AST_AOC_ENCODED_CHARGE_NA
Definition: aoc.c:190
#define AST_AOC_ENCODE_VERSION
Definition: aoc.c:198
#define AST_AOC_ENCODED_TYPE_REQUEST
Definition: aoc.c:181
static void aoc_create_ie_data(struct ast_aoc_decoded *decoded, struct aoc_ie_data *ied)
Definition: aoc.c:592
uint8_t version
Definition: aoc.c:207

References aoc_create_ie_data(), aoc_debug_enabled, aoc_display_decoded_debug(), AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_NA, AST_AOC_CHARGE_UNIT, AST_AOC_D, AST_AOC_E, AST_AOC_ENCODE_VERSION, AST_AOC_ENCODED_CHARGE_CURRENCY, AST_AOC_ENCODED_CHARGE_FREE, AST_AOC_ENCODED_CHARGE_NA, AST_AOC_ENCODED_CHARGE_SUBTOTAL, AST_AOC_ENCODED_CHARGE_UNIT, AST_AOC_ENCODED_REQUEST_D, AST_AOC_ENCODED_REQUEST_E, AST_AOC_ENCODED_REQUEST_S, AST_AOC_ENCODED_TYPE_D, AST_AOC_ENCODED_TYPE_E, AST_AOC_ENCODED_TYPE_REQUEST, AST_AOC_ENCODED_TYPE_S, AST_AOC_REQUEST, AST_AOC_REQUEST_D, AST_AOC_REQUEST_E, AST_AOC_REQUEST_S, AST_AOC_S, AST_AOC_SUBTOTAL, ast_calloc, ast_log, aoc_ie_data::buf, ast_aoc_decoded::charge_type, ast_aoc_encoded::data, ast_aoc_encoded::datalen, ast_aoc_encoded::flags, LOG_WARNING, ast_aoc_decoded::msg_type, NULL, aoc_ie_data::pos, ast_aoc_decoded::request_flag, ast_aoc_decoded::total_type, and ast_aoc_encoded::version.

Referenced by action_aocmessage(), ast_aoc_test_encode_decode_match(), and wait_for_answer().

◆ ast_aoc_get_association_info()

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

Definition at line 1060 of file aoc.c.

1061{
1062 return &decoded->charging_association;
1063}

References ast_aoc_decoded::charging_association.

Referenced by AST_TEST_DEFINE().

◆ ast_aoc_get_billing_id()

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

Definition at line 1044 of file aoc.c.

1045{
1046 return decoded->billing_id;
1047}

References ast_aoc_decoded::billing_id.

Referenced by AST_TEST_DEFINE().

◆ ast_aoc_get_charge_type()

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

Definition at line 906 of file aoc.c.

907{
908 return decoded->charge_type;
909}

References ast_aoc_decoded::charge_type.

Referenced by aoc_send_as_xml(), and AST_TEST_DEFINE().

◆ ast_aoc_get_currency_amount()

unsigned int ast_aoc_get_currency_amount ( struct ast_aoc_decoded decoded)

get the currency amount for AOC-D and AOC-E messages

Definition at line 949 of file aoc.c.

950{
951 return decoded->currency_amount;
952}

References ast_aoc_decoded::currency_amount.

Referenced by aoc_send_as_xml(), and AST_TEST_DEFINE().

◆ ast_aoc_get_currency_multiplier()

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

Definition at line 954 of file aoc.c.

955{
956 return decoded->multiplier;
957}

References ast_aoc_decoded::multiplier.

Referenced by aoc_send_as_xml(), and AST_TEST_DEFINE().

◆ ast_aoc_get_currency_multiplier_decimal()

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

Definition at line 959 of file aoc.c.

960{
961 switch (decoded->multiplier) {
963 return "0.001";
965 return "0.01";
967 return "0.1";
968 case AST_AOC_MULT_ONE:
969 return "1.0";
970 case AST_AOC_MULT_TEN:
971 return "10.0";
973 return "100.0";
975 return "1000.0";
976 default:
977 return "1.0";
978 }
979}

References AST_AOC_MULT_HUNDRED, AST_AOC_MULT_ONE, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETENTH, AST_AOC_MULT_ONETHOUSANDTH, AST_AOC_MULT_TEN, AST_AOC_MULT_THOUSAND, and ast_aoc_decoded::multiplier.

◆ ast_aoc_get_currency_name()

const char * ast_aoc_get_currency_name ( struct ast_aoc_decoded decoded)

get the currency name for AOC-D and AOC-E messages

Definition at line 981 of file aoc.c.

982{
983 return decoded->currency_name;
984}

References ast_aoc_decoded::currency_name.

Referenced by aoc_send_as_xml(), and AST_TEST_DEFINE().

◆ ast_aoc_get_msg_type()

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

Definition at line 901 of file aoc.c.

902{
903 return decoded->msg_type;
904}

References ast_aoc_decoded::msg_type.

Referenced by aoc_send_as_xml(), AST_TEST_DEFINE(), and wait_for_answer().

◆ ast_aoc_get_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

Definition at line 911 of file aoc.c.

912{
913 return decoded->request_flag;
914}

References ast_aoc_decoded::request_flag.

Referenced by AST_TEST_DEFINE().

◆ ast_aoc_get_termination_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.

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 1088 of file aoc.c.

1089{
1090 return decoded->termination_request;
1091}

References ast_aoc_decoded::termination_request.

Referenced by AST_TEST_DEFINE().

◆ ast_aoc_get_total_type()

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

Definition at line 923 of file aoc.c.

924{
925 return decoded->total_type;
926}

References ast_aoc_decoded::total_type.

Referenced by aoc_send_as_xml(), and AST_TEST_DEFINE().

◆ ast_aoc_get_unit_count()

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

Definition at line 1028 of file aoc.c.

1029{
1030 return decoded->unit_count;
1031}

References ast_aoc_decoded::unit_count.

Referenced by AST_TEST_DEFINE().

◆ ast_aoc_get_unit_info()

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 1019 of file aoc.c.

1020{
1021 if (entry_number >= decoded->unit_count) {
1022 return NULL;
1023 }
1024
1025 return (const struct ast_aoc_unit_entry *) &decoded->unit_list[entry_number];
1026}
Definition: aoc.h:178

References NULL, ast_aoc_decoded::unit_count, and ast_aoc_decoded::unit_list.

Referenced by aoc_send_as_xml(), and AST_TEST_DEFINE().

◆ ast_aoc_manager_event()

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 1931 of file aoc.c.

1932{
1933 struct ast_json *blob;
1934 struct stasis_message_type *msg_type;
1935
1936 if (!decoded) {
1937 return -1;
1938 }
1939
1940 switch (decoded->msg_type) {
1941 case AST_AOC_S:
1942 blob = s_to_json(decoded);
1943 msg_type = aoc_s_type();
1944 break;
1945 case AST_AOC_D:
1946 blob = d_to_json(decoded);
1947 msg_type = aoc_d_type();
1948 break;
1949 case AST_AOC_E:
1950 blob = e_to_json(decoded);
1951 msg_type = aoc_e_type();
1952 break;
1953 default:
1954 /* events for AST_AOC_REQUEST are not generated here */
1955 return 0;
1956 }
1957
1958 aoc_publish_blob(chan, msg_type, blob);
1959 ast_json_unref(blob);
1960 return 0;
1961}
static struct ast_json * s_to_json(const struct ast_aoc_decoded *decoded)
Definition: aoc.c:1711
static struct ast_json * d_to_json(const struct ast_aoc_decoded *decoded)
Definition: aoc.c:1802
static void aoc_publish_blob(struct ast_channel *chan, struct stasis_message_type *msg_type, struct ast_json *blob)
Definition: aoc.c:1838
static struct ast_json * e_to_json(const struct ast_aoc_decoded *decoded)
Definition: aoc.c:1807
Abstract JSON element (object, array, string, int, ...).

References aoc_d_type(), aoc_e_type(), aoc_publish_blob(), aoc_s_type(), AST_AOC_D, AST_AOC_E, AST_AOC_S, ast_json_unref(), d_to_json(), e_to_json(), ast_aoc_decoded::msg_type, and s_to_json().

◆ ast_aoc_s_add_rate_duration()

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 779 of file aoc.c.

789{
790
791 struct ast_aoc_s_entry entry = { 0, };
792
795 entry.rate.duration.amount = amount;
796 entry.rate.duration.multiplier = multiplier;
797 entry.rate.duration.time = time;
798 entry.rate.duration.time_scale = time_scale;
799 entry.rate.duration.granularity_time = granularity_time;
800 entry.rate.duration.granularity_time_scale = granularity_time_scale;
801 entry.rate.duration.charging_type = step_function ? 1 : 0;
802
803 if (!ast_strlen_zero(currency_name)) {
804 ast_copy_string(entry.rate.duration.currency_name, currency_name, sizeof(entry.rate.duration.currency_name));
805 }
806
807 return aoc_s_add_entry(decoded, &entry);
808}

References ast_aoc_duration_rate::amount, aoc_s_add_entry(), AST_AOC_RATE_TYPE_DURATION, ast_copy_string(), ast_strlen_zero(), ast_aoc_s_entry::charged_item, ast_aoc_duration_rate::charging_type, ast_aoc_duration_rate::currency_name, ast_aoc_s_entry::duration, ast_aoc_duration_rate::granularity_time, ast_aoc_duration_rate::granularity_time_scale, ast_aoc_duration_rate::multiplier, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, ast_aoc_duration_rate::time, and ast_aoc_duration_rate::time_scale.

Referenced by action_aoc_s_submessage(), and AST_TEST_DEFINE().

◆ ast_aoc_s_add_rate_flat()

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 810 of file aoc.c.

815{
816 struct ast_aoc_s_entry entry = { 0, };
817
820 entry.rate.flat.amount = amount;
821 entry.rate.flat.multiplier = multiplier;
822
823 if (!ast_strlen_zero(currency_name)) {
824 ast_copy_string(entry.rate.flat.currency_name, currency_name, sizeof(entry.rate.flat.currency_name));
825 }
826
827 return aoc_s_add_entry(decoded, &entry);
828}

References ast_aoc_flat_rate::amount, aoc_s_add_entry(), AST_AOC_RATE_TYPE_FLAT, ast_copy_string(), ast_strlen_zero(), ast_aoc_s_entry::charged_item, ast_aoc_flat_rate::currency_name, ast_aoc_s_entry::flat, ast_aoc_flat_rate::multiplier, ast_aoc_s_entry::rate, and ast_aoc_s_entry::rate_type.

Referenced by action_aoc_s_submessage(), and AST_TEST_DEFINE().

◆ ast_aoc_s_add_rate_free()

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 866 of file aoc.c.

869{
870 struct ast_aoc_s_entry entry = { 0, };
871
874
875 return aoc_s_add_entry(decoded, &entry);
876}

References aoc_s_add_entry(), AST_AOC_RATE_TYPE_FREE, AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING, ast_aoc_s_entry::charged_item, and ast_aoc_s_entry::rate_type.

Referenced by action_aoc_s_submessage(), and AST_TEST_DEFINE().

◆ ast_aoc_s_add_rate_na()

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 878 of file aoc.c.

880{
881 struct ast_aoc_s_entry entry = { 0, };
882
885
886 return aoc_s_add_entry(decoded, &entry);
887}

References aoc_s_add_entry(), AST_AOC_RATE_TYPE_NA, ast_aoc_s_entry::charged_item, and ast_aoc_s_entry::rate_type.

Referenced by action_aoc_s_submessage(), and AST_TEST_DEFINE().

◆ ast_aoc_s_add_rate_special_charge_code()

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 853 of file aoc.c.

856{
857 struct ast_aoc_s_entry entry = { 0, };
858
861 entry.rate.special_code = code;
862
863 return aoc_s_add_entry(decoded, &entry);
864}

References aoc_s_add_entry(), AST_AOC_RATE_TYPE_SPECIAL_CODE, ast_aoc_s_entry::charged_item, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, and ast_aoc_s_entry::special_code.

Referenced by action_aoc_s_submessage().

◆ ast_aoc_s_add_rate_volume()

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 831 of file aoc.c.

837{
838 struct ast_aoc_s_entry entry = { 0, };
839
842 entry.rate.volume.multiplier = multiplier;
843 entry.rate.volume.amount = amount;
844 entry.rate.volume.volume_unit = volume_unit;
845
846 if (!ast_strlen_zero(currency_name)) {
847 ast_copy_string(entry.rate.volume.currency_name, currency_name, sizeof(entry.rate.volume.currency_name));
848 }
849
850 return aoc_s_add_entry(decoded, &entry);
851}

References ast_aoc_volume_rate::amount, aoc_s_add_entry(), AST_AOC_RATE_TYPE_VOLUME, ast_copy_string(), ast_strlen_zero(), ast_aoc_s_entry::charged_item, ast_aoc_volume_rate::currency_name, ast_aoc_volume_rate::multiplier, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, ast_aoc_s_entry::volume, and ast_aoc_volume_rate::volume_unit.

Referenced by action_aoc_s_submessage(), and AST_TEST_DEFINE().

◆ ast_aoc_s_add_special_arrangement()

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 889 of file aoc.c.

891{
892 struct ast_aoc_s_entry entry = { 0, };
893
896 entry.rate.special_code = code;
897
898 return aoc_s_add_entry(decoded, &entry);
899}

References aoc_s_add_entry(), AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT, AST_AOC_RATE_TYPE_SPECIAL_CODE, ast_aoc_s_entry::charged_item, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, and ast_aoc_s_entry::special_code.

Referenced by action_aoc_s_submessage().

◆ ast_aoc_s_get_count()

unsigned int ast_aoc_s_get_count ( struct ast_aoc_decoded decoded)

get the number rates associated with an AOC-S message

Definition at line 765 of file aoc.c.

766{
767 return decoded->aoc_s_count;
768}

References ast_aoc_decoded::aoc_s_count.

Referenced by action_aoc_s_message(), and aoc_send_as_xml().

◆ ast_aoc_s_get_rate_info()

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 770 of file aoc.c.

771{
772 if (entry_number >= decoded->aoc_s_count) {
773 return NULL;
774 }
775
776 return (const struct ast_aoc_s_entry *) &decoded->aoc_s_entries[entry_number];
777}

References ast_aoc_decoded::aoc_s_count, ast_aoc_decoded::aoc_s_entries, and NULL.

Referenced by aoc_send_as_xml().

◆ ast_aoc_set_association_id()

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 1049 of file aoc.c.

1050{
1051 if (decoded->msg_type != AST_AOC_E) {
1052 return -1;
1053 }
1054 memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
1056 decoded->charging_association.charge.id = id;
1057 return 0;
1058}
enum queue_result id
Definition: app_queue.c:1808

References AST_AOC_CHARGING_ASSOCIATION_ID, AST_AOC_E, ast_aoc_charging_association::charge, ast_aoc_decoded::charging_association, ast_aoc_charging_association::charging_type, id, ast_aoc_charging_association::id, and ast_aoc_decoded::msg_type.

Referenced by action_aoc_de_message(), and AST_TEST_DEFINE().

◆ ast_aoc_set_association_number()

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 1065 of file aoc.c.

1066{
1067 if ((decoded->msg_type != AST_AOC_E) || ast_strlen_zero(num)) {
1068 return -1;
1069 }
1070 memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
1072 decoded->charging_association.charge.number.plan = plan;
1074
1075 return 0;
1076}

References AST_AOC_CHARGING_ASSOCIATION_NUMBER, AST_AOC_E, ast_copy_string(), ast_strlen_zero(), ast_aoc_charging_association::charge, ast_aoc_decoded::charging_association, ast_aoc_charging_association::charging_type, ast_aoc_decoded::msg_type, ast_aoc_charging_association_number::number, ast_aoc_charging_association::number, and ast_aoc_charging_association_number::plan.

Referenced by action_aoc_de_message(), and AST_TEST_DEFINE().

◆ ast_aoc_set_billing_id()

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 1033 of file aoc.c.

1034{
1035 if ((id >= AST_AOC_BILLING_NUM_ENTRIES) || (id < AST_AOC_BILLING_NA)) {
1036 return -1;
1037 }
1038
1039 decoded->billing_id = id;
1040
1041 return 0;
1042}

References AST_AOC_BILLING_NA, AST_AOC_BILLING_NUM_ENTRIES, ast_aoc_decoded::billing_id, and id.

Referenced by action_aoc_de_message(), and AST_TEST_DEFINE().

◆ ast_aoc_set_currency_info()

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 928 of file aoc.c.

932{
933
934 if (!ast_strlen_zero(name)) {
935 ast_copy_string(decoded->currency_name, name, sizeof(decoded->currency_name));
936 }
937
938 decoded->currency_amount = amount;
939
940 if (multiplier && (multiplier < AST_AOC_MULT_NUM_ENTRIES)) {
941 decoded->multiplier = multiplier;
942 } else {
943 decoded->multiplier = AST_AOC_MULT_ONE;
944 }
945
946 return 0;
947}

References AST_AOC_MULT_NUM_ENTRIES, AST_AOC_MULT_ONE, ast_copy_string(), ast_strlen_zero(), ast_aoc_decoded::currency_amount, ast_aoc_decoded::currency_name, ast_aoc_decoded::multiplier, and name.

Referenced by action_aoc_de_message(), and AST_TEST_DEFINE().

◆ ast_aoc_set_termination_request()

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 1078 of file aoc.c.

1079{
1080 if (decoded->msg_type != AST_AOC_REQUEST) {
1081 return -1;
1082 }
1083 decoded->termination_request = 1;
1084
1085 return 0;
1086}

References AST_AOC_REQUEST, ast_aoc_decoded::msg_type, and ast_aoc_decoded::termination_request.

Referenced by AST_TEST_DEFINE().

◆ ast_aoc_set_total_type()

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 916 of file aoc.c.

918{
919 decoded->total_type = type;
920 return 0;
921}

References ast_aoc_decoded::total_type, and type.

Referenced by action_aoc_de_message(), and AST_TEST_DEFINE().

◆ ast_aoc_test_encode_decode_match()

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 1339 of file aoc.c.

1340{
1341 struct ast_aoc_decoded *new_decoded = NULL;
1342 struct ast_aoc_encoded *encoded = NULL;
1343 size_t size;
1344 int res = 0;
1345
1346 if (!(encoded = ast_aoc_encode(decoded, &size, NULL))) {
1347 return -1;
1348 }
1349
1350 if (!(new_decoded = ast_aoc_decode(encoded, size, NULL))) {
1351 ast_free(encoded);
1352 return -1;
1353 }
1354
1355 if (memcmp(new_decoded, decoded, sizeof(struct ast_aoc_decoded))) {
1356 res = -1;
1357 }
1358
1359 ast_aoc_destroy_decoded(new_decoded);
1360 ast_aoc_destroy_encoded(encoded);
1361 return res;
1362}
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition: aoc.c:322
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:458
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:316
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:659

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

Referenced by AST_TEST_DEFINE().

◆ charge_to_json()

static struct ast_json * charge_to_json ( const struct ast_aoc_decoded decoded)
static

Definition at line 1669 of file aoc.c.

1670{
1671 struct ast_json *obj;
1672 const char *obj_type;
1673
1674 if (decoded->charge_type != AST_AOC_CHARGE_CURRENCY &&
1675 decoded->charge_type != AST_AOC_CHARGE_UNIT) {
1676 return ast_json_pack("{s:s}",
1677 "Type", aoc_charge_type_str(decoded->charge_type));
1678 }
1679
1680 if (decoded->charge_type == AST_AOC_CHARGE_CURRENCY) {
1681 obj_type = "Currency";
1682 obj = currency_to_json(decoded->currency_name, decoded->currency_amount,
1683 decoded->multiplier);
1684 } else { /* decoded->charge_type == AST_AOC_CHARGE_UNIT */
1685 obj_type = "Units";
1686 obj = units_to_json(decoded);
1687 }
1688
1689 return ast_json_pack("{s:s, s:s, s:s, s:o}",
1690 "Type", aoc_charge_type_str(decoded->charge_type),
1691 "BillingID", aoc_billingid_str(decoded->billing_id),
1692 "TotalType", aoc_type_of_totaling_str(decoded->total_type),
1693 obj_type, obj);
1694}
static struct ast_json * units_to_json(const struct ast_aoc_decoded *decoded)
Definition: aoc.c:1628
static struct ast_json * currency_to_json(const char *name, int cost, enum ast_aoc_currency_multiplier mult)
Definition: aoc.c:1660

References aoc_billingid_str(), aoc_charge_type_str(), aoc_type_of_totaling_str(), AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_UNIT, ast_json_pack(), ast_aoc_decoded::billing_id, ast_aoc_decoded::charge_type, ast_aoc_decoded::currency_amount, ast_aoc_decoded::currency_name, currency_to_json(), ast_aoc_decoded::multiplier, ast_aoc_decoded::total_type, and units_to_json().

Referenced by d_to_json(), and e_to_json().

◆ currency_to_json()

static struct ast_json * currency_to_json ( const char *  name,
int  cost,
enum ast_aoc_currency_multiplier  mult 
)
static

Definition at line 1660 of file aoc.c.

1662{
1663 return ast_json_pack("{s:s, s:i, s:s}",
1665 "Cost", cost,
1666 "Multiplier", aoc_multiplier_str(mult));
1667}

References aoc_multiplier_str(), ast_json_pack(), AST_JSON_UTF8_VALIDATE, and name.

Referenced by charge_to_json(), and s_to_json().

◆ d_to_json()

static struct ast_json * d_to_json ( const struct ast_aoc_decoded decoded)
static

Definition at line 1802 of file aoc.c.

1803{
1804 return ast_json_pack("{s:o}", "Charge", charge_to_json(decoded));
1805}
static struct ast_json * charge_to_json(const struct ast_aoc_decoded *decoded)
Definition: aoc.c:1669

References ast_json_pack(), and charge_to_json().

Referenced by ast_aoc_manager_event().

◆ e_to_json()

static struct ast_json * e_to_json ( const struct ast_aoc_decoded decoded)
static

Definition at line 1807 of file aoc.c.

1808{
1809 return ast_json_pack("{s:o, s:o}",
1810 "ChargingAssociation", association_to_json(decoded),
1811 "Charge", charge_to_json(decoded));
1812}
static struct ast_json * association_to_json(const struct ast_aoc_decoded *decoded)
Definition: aoc.c:1696

References association_to_json(), ast_json_pack(), and charge_to_json().

Referenced by ast_aoc_manager_event().

◆ s_to_json()

static struct ast_json * s_to_json ( const struct ast_aoc_decoded decoded)
static

Definition at line 1711 of file aoc.c.

1712{
1713 int i;
1714 struct ast_json *rates = ast_json_array_create();
1715
1716 if (!rates) {
1717 return ast_json_null();
1718 }
1719
1720 for (i = 0; i < decoded->aoc_s_count; ++i) {
1721 struct ast_json *rate;
1722 struct ast_json *type = NULL;
1723 struct ast_json *currency;
1724 const char *charge_item = aoc_charged_item_str(
1725 decoded->aoc_s_entries[i].charged_item);
1726
1728 rate = ast_json_pack("{s:s}", "Chargeable", charge_item);
1729 if (ast_json_array_append(rates, rate)) {
1730 break;
1731 }
1732 continue;
1733 }
1734
1735 switch (decoded->aoc_s_entries[i].rate_type) {
1737 {
1738 struct ast_json *time;
1739 struct ast_json *granularity = NULL;
1740
1741 currency = currency_to_json(
1743 decoded->aoc_s_entries[i].rate.duration.amount,
1745
1746 time = ast_json_pack("{s:I, s:i}",
1747 "Length", (ast_json_int_t)decoded->aoc_s_entries[i].rate.duration.time,
1748 "Scale", decoded->aoc_s_entries[i].rate.duration.time_scale);
1749
1750 if (decoded->aoc_s_entries[i].rate.duration.granularity_time) {
1751 granularity = ast_json_pack("{s:I, s:i}",
1753 "Scale", decoded->aoc_s_entries[i].rate.duration.granularity_time_scale);
1754 }
1755
1756 type = ast_json_pack("{s:o, s:s, s:o, s:o}",
1757 "Currency", currency,
1758 "ChargingType", decoded->aoc_s_entries[i].rate.duration.charging_type
1759 ? "StepFunction" : "ContinuousCharging",
1760 "Time", time,
1761 "Granularity", granularity ?: ast_json_null());
1762
1763 break;
1764 }
1766 currency = currency_to_json(
1768 decoded->aoc_s_entries[i].rate.flat.amount,
1769 decoded->aoc_s_entries[i].rate.flat.multiplier);
1770
1771 type = ast_json_pack("{s:o}", "Currency", currency);
1772 break;
1774 currency = currency_to_json(
1776 decoded->aoc_s_entries[i].rate.volume.amount,
1777 decoded->aoc_s_entries[i].rate.volume.multiplier);
1778
1779 type = ast_json_pack("{s:s, s:o}",
1780 "Unit", aoc_volume_unit_str(
1781 decoded->aoc_s_entries[i].rate.volume.volume_unit),
1782 "Currency", currency);
1783 break;
1785 type = ast_json_pack("{s:i}",
1786 "SpecialCode", decoded->aoc_s_entries[i].rate.special_code);
1787 break;
1788 default:
1789 break;
1790 }
1791
1792 rate = ast_json_pack("{s:s, s:o}",
1793 "Chargeable", charge_item,
1795 if (ast_json_array_append(rates, rate)) {
1796 break;
1797 }
1798 }
1799 return rates;
1800}
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition: json.h:87

References ast_aoc_duration_rate::amount, ast_aoc_volume_rate::amount, ast_aoc_flat_rate::amount, aoc_charged_item_str(), aoc_rate_type_str(), ast_aoc_decoded::aoc_s_count, ast_aoc_decoded::aoc_s_entries, aoc_volume_unit_str(), AST_AOC_CHARGED_ITEM_NA, AST_AOC_RATE_TYPE_DURATION, AST_AOC_RATE_TYPE_FLAT, AST_AOC_RATE_TYPE_SPECIAL_CODE, AST_AOC_RATE_TYPE_VOLUME, ast_json_array_append(), ast_json_array_create(), ast_json_null(), ast_json_pack(), ast_aoc_s_entry::charged_item, ast_aoc_duration_rate::charging_type, ast_aoc_duration_rate::currency_name, ast_aoc_volume_rate::currency_name, ast_aoc_flat_rate::currency_name, currency_to_json(), ast_aoc_s_entry::duration, ast_aoc_s_entry::flat, ast_aoc_duration_rate::granularity_time, ast_aoc_duration_rate::granularity_time_scale, ast_aoc_duration_rate::multiplier, ast_aoc_volume_rate::multiplier, ast_aoc_flat_rate::multiplier, NULL, ast_aoc_s_entry::rate, ast_aoc_s_entry::rate_type, ast_aoc_s_entry::special_code, ast_aoc_duration_rate::time, ast_aoc_duration_rate::time_scale, type, ast_aoc_s_entry::volume, and ast_aoc_volume_rate::volume_unit.

Referenced by ast_aoc_manager_event().

◆ STASIS_MESSAGE_TYPE_DEFN() [1/3]

STASIS_MESSAGE_TYPE_DEFN ( aoc_d_type  ,
to_ami = aoc_d_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [2/3]

STASIS_MESSAGE_TYPE_DEFN ( aoc_e_type  ,
to_ami = aoc_e_to_ami 
)

◆ STASIS_MESSAGE_TYPE_DEFN() [3/3]

STASIS_MESSAGE_TYPE_DEFN ( aoc_s_type  ,
to_ami = aoc_s_to_ami 
)

◆ units_to_json()

static struct ast_json * units_to_json ( const struct ast_aoc_decoded decoded)
static

Definition at line 1628 of file aoc.c.

1629{
1630 int i;
1631 struct ast_json *units = ast_json_array_create();
1632
1633 if (!units) {
1634 return ast_json_null();
1635 }
1636
1637 for (i = 0; i < decoded->unit_count; ++i) {
1638 struct ast_json *unit = ast_json_object_create();
1639
1640 if (decoded->unit_list[i].valid_amount) {
1642 unit, "NumberOf", ast_json_stringf(
1643 "%u", decoded->unit_list[i].amount));
1644 }
1645
1646 if (decoded->unit_list[i].valid_type) {
1648 unit, "TypeOf", ast_json_stringf(
1649 "%u", decoded->unit_list[i].type));
1650 }
1651
1652 if (ast_json_array_append(units, unit)) {
1653 break;
1654 }
1655 }
1656
1657 return units;
1658}
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
struct ast_json * ast_json_stringf(const char *format,...)
Create a JSON string, printf style.
Definition: json.c:293
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414

References ast_aoc_unit_entry::amount, ast_json_array_append(), ast_json_array_create(), ast_json_null(), ast_json_object_create(), ast_json_object_set(), ast_json_stringf(), ast_aoc_unit_entry::type, ast_aoc_decoded::unit_count, ast_aoc_decoded::unit_list, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

Referenced by charge_to_json().

Variable Documentation

◆ aoc_cli

struct ast_cli_entry aoc_cli[]
static
Initial value:
= {
{ .handler = aoc_cli_debug_enable , .summary = "enable cli debugging of AOC messages" ,},
}
static char * aoc_cli_debug_enable(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: aoc.c:1364

Definition at line 2017 of file aoc.c.

Referenced by aoc_shutdown(), and ast_aoc_cli_init().

◆ aoc_debug_enabled

char aoc_debug_enabled = 0
static

Definition at line 201 of file aoc.c.

Referenced by aoc_cli_debug_enable(), ast_aoc_decode(), and ast_aoc_encode().