aoc.h File Reference

Generic Advice of Charge encode and decode routines. More...

#include "asterisk/channel.h"

Include dependency graph for aoc.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_aoc_charging_association
struct  ast_aoc_charging_association_number
struct  ast_aoc_duration_rate
struct  ast_aoc_flat_rate
struct  ast_aoc_s_entry
struct  ast_aoc_time
struct  ast_aoc_unit_entry
struct  ast_aoc_volume_rate

Defines

#define AOC_CURRENCY_NAME_SIZE   (10 + 1)

Enumerations

enum  ast_aoc_billing_id {
  AST_AOC_BILLING_NA = 0, AST_AOC_BILLING_NORMAL, AST_AOC_BILLING_REVERSE_CHARGE, AST_AOC_BILLING_CREDIT_CARD,
  AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL, AST_AOC_BILLING_CALL_FWD_BUSY, AST_AOC_BILLING_CALL_FWD_NO_REPLY, AST_AOC_BILLING_CALL_DEFLECTION,
  AST_AOC_BILLING_CALL_TRANSFER, AST_AOC_BILLING_NUM_ENTRIES
}
 Defines the billing id options for an aoc message. More...
enum  ast_aoc_charge_type { AST_AOC_CHARGE_NA = 0, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_UNIT }
enum  AST_AOC_CHARGING_ASSOCIATION { AST_AOC_CHARGING_ASSOCIATION_NA, AST_AOC_CHARGING_ASSOCIATION_NUMBER, AST_AOC_CHARGING_ASSOCIATION_ID }
enum  ast_aoc_currency_multiplier {
  AST_AOC_MULT_ONETHOUSANDTH = 1, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETENTH, AST_AOC_MULT_ONE,
  AST_AOC_MULT_TEN, AST_AOC_MULT_HUNDRED, AST_AOC_MULT_THOUSAND, AST_AOC_MULT_NUM_ENTRIES
}
 Defines the currency multiplier for an aoc message. More...
enum  ast_aoc_request { AST_AOC_REQUEST_S = (1 << 0), AST_AOC_REQUEST_D = (1 << 1), AST_AOC_REQUEST_E = (1 << 2) }
enum  ast_aoc_s_charged_item {
  AST_AOC_CHARGED_ITEM_NA, AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT, AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION, AST_AOC_CHARGED_ITEM_CALL_ATTEMPT,
  AST_AOC_CHARGED_ITEM_CALL_SETUP, AST_AOC_CHARGED_ITEM_USER_USER_INFO, AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE
}
enum  ast_aoc_s_rate_type {
  AST_AOC_RATE_TYPE_NA, AST_AOC_RATE_TYPE_FREE, AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING, AST_AOC_RATE_TYPE_DURATION,
  AST_AOC_RATE_TYPE_FLAT, AST_AOC_RATE_TYPE_VOLUME, AST_AOC_RATE_TYPE_SPECIAL_CODE
}
enum  ast_aoc_time_scale {
  AST_AOC_TIME_SCALE_HUNDREDTH_SECOND, AST_AOC_TIME_SCALE_TENTH_SECOND, AST_AOC_TIME_SCALE_SECOND, AST_AOC_TIME_SCALE_TEN_SECOND,
  AST_AOC_TIME_SCALE_MINUTE, AST_AOC_TIME_SCALE_HOUR, AST_AOC_TIME_SCALE_DAY
}
enum  ast_aoc_total_type { AST_AOC_TOTAL = 0, AST_AOC_SUBTOTAL = 1 }
enum  ast_aoc_type { AST_AOC_REQUEST = 0, AST_AOC_S, AST_AOC_D, AST_AOC_E }
enum  ast_aoc_volume_unit { AST_AOC_VOLUME_UNIT_OCTET, AST_AOC_VOLUME_UNIT_SEGMENT, AST_AOC_VOLUME_UNIT_MESSAGE }

Functions

int ast_aoc_add_unit_entry (struct ast_aoc_decoded *decoded, const unsigned int amount_is_present, const unsigned int amount, const unsigned int type_is_present, const unsigned int type)
 Adds a unit entry into the list of units.
int ast_aoc_cli_init (void)
 enable aoc cli options
struct ast_aoc_decodedast_aoc_create (const enum ast_aoc_type msg_type, const enum ast_aoc_charge_type charge_type, const enum ast_aoc_request requests)
 creates a ast_aoc_decode object of a specific message type
struct ast_aoc_decodedast_aoc_decode (struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
 decodes an encoded aoc payload.
int ast_aoc_decoded2str (const struct ast_aoc_decoded *decoded, struct ast_str **msg)
 Convert decoded aoc msg to string representation.
void * ast_aoc_destroy_decoded (struct ast_aoc_decoded *decoded)
 free an ast_aoc_decoded object
void * ast_aoc_destroy_encoded (struct ast_aoc_encoded *encoded)
 free an ast_aoc_encoded object
struct ast_aoc_encodedast_aoc_encode (struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
 encodes a decoded aoc structure so it can be passed on the wire
struct
ast_aoc_charging_association
ast_aoc_get_association_info (struct ast_aoc_decoded *decoded)
 get the charging association info for AOC-E messages
enum ast_aoc_billing_id ast_aoc_get_billing_id (struct ast_aoc_decoded *decoded)
 get the billing id for AOC-D and AOC-E messages
enum ast_aoc_charge_type ast_aoc_get_charge_type (struct ast_aoc_decoded *decoded)
 get the charging type for an AOC-D or AOC-E message
unsigned int ast_aoc_get_currency_amount (struct ast_aoc_decoded *decoded)
 get the currency amount for AOC-D and AOC-E messages
enum ast_aoc_currency_multiplier ast_aoc_get_currency_multiplier (struct ast_aoc_decoded *decoded)
 get the currency multiplier for AOC-D and AOC-E messages
const char * ast_aoc_get_currency_multiplier_decimal (struct ast_aoc_decoded *decoded)
 get the currency multiplier for AOC-D and AOC-E messages in decimal format
const char * ast_aoc_get_currency_name (struct ast_aoc_decoded *decoded)
 get the currency name for AOC-D and AOC-E messages
enum ast_aoc_type ast_aoc_get_msg_type (struct ast_aoc_decoded *decoded)
 get the message type, AOC-D, AOC-E, or AOC Request
enum ast_aoc_request ast_aoc_get_request (struct ast_aoc_decoded *decoded)
 get the types of AOC requested for when message type is AOC Request
int ast_aoc_get_termination_request (struct ast_aoc_decoded *decoded)
 get whether or not the AST_AOC_REQUEST message as a termination request.
enum ast_aoc_total_type ast_aoc_get_total_type (struct ast_aoc_decoded *decoded)
 get the type of total for a AOC-D message
unsigned int ast_aoc_get_unit_count (struct ast_aoc_decoded *decoded)
 get the number of unit entries for AOC-D and AOC-E messages
struct ast_aoc_unit_entryast_aoc_get_unit_info (struct ast_aoc_decoded *decoded, unsigned int entry_number)
 get a specific unit entry.
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
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.
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.
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.
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.
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.
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.
int ast_aoc_s_add_special_arrangement (struct ast_aoc_decoded *decoded, unsigned int code)
 Add AOC-S special arrangement entry.
unsigned int ast_aoc_s_get_count (struct ast_aoc_decoded *decoded)
 get the number rates associated with an AOC-S message
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.
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
int ast_aoc_set_association_number (struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
 set the charging accociation number for an AOC-E message
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
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.
int ast_aoc_set_termination_request (struct ast_aoc_decoded *decoded)
 Mark the AST_AOC_REQUEST message as a termination request.
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.
int ast_aoc_test_encode_decode_match (struct ast_aoc_decoded *decoded)
 test aoc encode decode routines.


Detailed Description

Generic Advice of Charge encode and decode routines.

Author:
David Vossel <dvossel@digium.com>

Definition in file aoc.h.


Define Documentation

#define AOC_CURRENCY_NAME_SIZE   (10 + 1)

Definition at line 31 of file aoc.h.


Enumeration Type Documentation

Defines the billing id options for an aoc message.

Note:
AOC-D is limited to NORMAL, REVERSE_CHARGE, and CREDIT_CARD.
Enumerator:
AST_AOC_BILLING_NA 
AST_AOC_BILLING_NORMAL 
AST_AOC_BILLING_REVERSE_CHARGE 
AST_AOC_BILLING_CREDIT_CARD 
AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL 
AST_AOC_BILLING_CALL_FWD_BUSY 
AST_AOC_BILLING_CALL_FWD_NO_REPLY 
AST_AOC_BILLING_CALL_DEFLECTION 
AST_AOC_BILLING_CALL_TRANSFER 
AST_AOC_BILLING_NUM_ENTRIES 

Definition at line 49 of file aoc.h.

Enumerator:
AST_AOC_CHARGE_NA 
AST_AOC_CHARGE_FREE 
AST_AOC_CHARGE_CURRENCY 
AST_AOC_CHARGE_UNIT 

Definition at line 69 of file aoc.h.

00069                          {
00070    AST_AOC_CHARGE_NA = 0,
00071    AST_AOC_CHARGE_FREE,
00072    AST_AOC_CHARGE_CURRENCY,
00073    AST_AOC_CHARGE_UNIT, /* unit must remain the last item in enum */
00074 };

Enumerator:
AST_AOC_CHARGING_ASSOCIATION_NA 
AST_AOC_CHARGING_ASSOCIATION_NUMBER 
AST_AOC_CHARGING_ASSOCIATION_ID 

Definition at line 185 of file aoc.h.

Defines the currency multiplier for an aoc message.

Enumerator:
AST_AOC_MULT_ONETHOUSANDTH 
AST_AOC_MULT_ONEHUNDREDTH 
AST_AOC_MULT_ONETENTH 
AST_AOC_MULT_ONE 
AST_AOC_MULT_TEN 
AST_AOC_MULT_HUNDRED 
AST_AOC_MULT_THOUSAND 
AST_AOC_MULT_NUM_ENTRIES 

Definition at line 34 of file aoc.h.

00034                                  {
00035    AST_AOC_MULT_ONETHOUSANDTH = 1,
00036    AST_AOC_MULT_ONEHUNDREDTH,
00037    AST_AOC_MULT_ONETENTH,
00038    AST_AOC_MULT_ONE,
00039    AST_AOC_MULT_TEN,
00040    AST_AOC_MULT_HUNDRED,
00041    AST_AOC_MULT_THOUSAND,
00042    AST_AOC_MULT_NUM_ENTRIES, /* must remain the last item in enum, this is not a valid type */
00043 };

Enumerator:
AST_AOC_REQUEST_S 
AST_AOC_REQUEST_D 
AST_AOC_REQUEST_E 

Definition at line 76 of file aoc.h.

00076                      {
00077    AST_AOC_REQUEST_S = (1 << 0),
00078    AST_AOC_REQUEST_D = (1 << 1),
00079    AST_AOC_REQUEST_E = (1 << 2),
00080 };

Enumerator:
AST_AOC_CHARGED_ITEM_NA 
AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT 
AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION 
AST_AOC_CHARGED_ITEM_CALL_ATTEMPT 
AST_AOC_CHARGED_ITEM_CALL_SETUP 
AST_AOC_CHARGED_ITEM_USER_USER_INFO 
AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE 

Definition at line 145 of file aoc.h.

Enumerator:
AST_AOC_RATE_TYPE_NA 
AST_AOC_RATE_TYPE_FREE 
AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING 
AST_AOC_RATE_TYPE_DURATION 
AST_AOC_RATE_TYPE_FLAT 
AST_AOC_RATE_TYPE_VOLUME 
AST_AOC_RATE_TYPE_SPECIAL_CODE 

Definition at line 155 of file aoc.h.

Enumerator:
AST_AOC_TIME_SCALE_HUNDREDTH_SECOND 
AST_AOC_TIME_SCALE_TENTH_SECOND 
AST_AOC_TIME_SCALE_SECOND 
AST_AOC_TIME_SCALE_TEN_SECOND 
AST_AOC_TIME_SCALE_MINUTE 
AST_AOC_TIME_SCALE_HOUR 
AST_AOC_TIME_SCALE_DAY 

Definition at line 87 of file aoc.h.

Enumerator:
AST_AOC_TOTAL 
AST_AOC_SUBTOTAL 

Definition at line 82 of file aoc.h.

00082                         {
00083    AST_AOC_TOTAL = 0,
00084    AST_AOC_SUBTOTAL = 1,
00085 };

Enumerator:
AST_AOC_REQUEST 
AST_AOC_S 
AST_AOC_D 
AST_AOC_E 

Definition at line 62 of file aoc.h.

00062                   {
00063    AST_AOC_REQUEST = 0,
00064    AST_AOC_S,
00065    AST_AOC_D,
00066    AST_AOC_E, /* aoc-e must remain the last item in this enum */
00067 };

Enumerator:
AST_AOC_VOLUME_UNIT_OCTET 
AST_AOC_VOLUME_UNIT_SEGMENT 
AST_AOC_VOLUME_UNIT_MESSAGE 

Definition at line 125 of file aoc.h.


Function Documentation

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

Adds a unit entry into the list of units.

Since:
1.8
Parameters:
decoded ast_aoc_decoded struct to set values on
amount_is_present set this if the number of units is actually present.
amount number of units
type_is_present set this if the type value is present
type unit type
Note:
If neither the amount nor the type is present, the entry will not be added.
Return values:
0 success

Definition at line 964 of file aoc.c.

References ast_aoc_unit_entry::amount, ARRAY_LEN, AST_AOC_REQUEST, ast_aoc_decoded::msg_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_aocmessage(), aoc_parse_ie(), and AST_TEST_DEFINE().

00969 {
00970    if ((decoded->msg_type == AST_AOC_REQUEST) ||
00971       (decoded->unit_count >= ARRAY_LEN(decoded->unit_list))) {
00972       return -1;
00973    }
00974 
00975    if (!amount_is_present && !type_is_present) {
00976       return -1;
00977    }
00978 
00979    decoded->unit_list[decoded->unit_count].valid_amount = amount_is_present;
00980    if (amount_is_present) {
00981       decoded->unit_list[decoded->unit_count].amount = amount;
00982    } else {
00983       decoded->unit_list[decoded->unit_count].amount = 0;
00984    }
00985 
00986    decoded->unit_list[decoded->unit_count].valid_type = type_is_present;
00987    if (type_is_present) {
00988       decoded->unit_list[decoded->unit_count].type = type;
00989    } else {
00990       decoded->unit_list[decoded->unit_count].type = 0;
00991    }
00992    decoded->unit_count++;
00993 
00994    return 0;
00995 }

int ast_aoc_cli_init ( void   ) 

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 
) [read]

creates a ast_aoc_decode object of a specific message type

Since:
1.8
Parameters:
msg_type AOC-D, AOC-E, or AOC Request
charge_type this is ignored if message type is not AOC-D or AOC-E.
requests flags. This defines the types of AOC requested. This field should only be set when the message type is AOC Request, the value is ignored otherwise.
Return values:
heap allocated ast_aoc_decoded object ptr on success
NULL failure

Definition at line 263 of file aoc.c.

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, and ast_aoc_decoded::request_flag.

Referenced by action_aocmessage(), and AST_TEST_DEFINE().

00266 {
00267    struct ast_aoc_decoded *decoded = NULL;
00268 
00269    /* verify input */
00270    if (((unsigned int) charge_type > AST_AOC_CHARGE_UNIT) ||
00271       ((unsigned int) msg_type > AST_AOC_E) ||
00272       ((msg_type == AST_AOC_REQUEST) && !requests)) {
00273 
00274       ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object, invalid input\n");
00275       return NULL;
00276    }
00277 
00278    if (!(decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded)))) {
00279       ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
00280       return NULL;
00281    }
00282 
00283    decoded->msg_type = msg_type;
00284 
00285    if (msg_type == AST_AOC_REQUEST) {
00286       decoded->request_flag = requests;
00287    } else if ((msg_type == AST_AOC_D) || (msg_type == AST_AOC_E)) {
00288       decoded->charge_type = charge_type;
00289    }
00290 
00291    return decoded;
00292 }

struct ast_aoc_decoded* ast_aoc_decode ( struct ast_aoc_encoded encoded,
size_t  size,
struct ast_channel chan 
) [read]

decodes an encoded aoc payload.

Since:
1.8
Parameters:
encoded the encoded payload to decode.
size total size of encoded payload
chan ast channel, Optional for DEBUG output purposes
Return values:
heap allocated ast_aoc_decoded object ptr on success
NULL failure

Definition at line 436 of file aoc.c.

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 ast_aoc_test_encode_decode_match(), sip_indicate(), and wait_for_answer().

00437 {
00438    struct ast_aoc_decoded *decoded;
00439 
00440    /* verify our encoded payload is actually large enough to hold all the ies */
00441    if ((size - (sizeof(struct ast_aoc_encoded)) != ntohs(encoded->datalen))) {
00442       ast_log(LOG_WARNING, "Corrupted aoc encoded object, can not decode\n");
00443       return NULL;
00444    }
00445 
00446    if (!(decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded)))) {
00447       ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
00448       return NULL;
00449    }
00450 
00451    /* decode flags */
00452 
00453    if ((encoded->flags & AST_AOC_ENCODED_TYPE_S) == AST_AOC_ENCODED_TYPE_S) {
00454       decoded->msg_type = AST_AOC_S;
00455    } else if (encoded->flags & AST_AOC_ENCODED_TYPE_E) {
00456       decoded->msg_type = AST_AOC_E;
00457    } else if (encoded->flags & AST_AOC_ENCODED_TYPE_D) {
00458       decoded->msg_type = AST_AOC_D;
00459    } else {
00460       decoded->msg_type = AST_AOC_REQUEST;
00461    }
00462 
00463    if (decoded->msg_type == AST_AOC_REQUEST) {
00464       if (encoded->flags & AST_AOC_ENCODED_REQUEST_S) {
00465          decoded->request_flag |= AST_AOC_REQUEST_S;
00466       }
00467       if (encoded->flags & AST_AOC_ENCODED_REQUEST_D) {
00468          decoded->request_flag |= AST_AOC_REQUEST_D;
00469       }
00470       if (encoded->flags & AST_AOC_ENCODED_REQUEST_E) {
00471          decoded->request_flag |= AST_AOC_REQUEST_E;
00472       }
00473    } else if ((decoded->msg_type == AST_AOC_D) || (decoded->msg_type == AST_AOC_E)) {
00474       if ((encoded->flags & AST_AOC_ENCODED_CHARGE_UNIT) == AST_AOC_ENCODED_CHARGE_UNIT) {
00475          decoded->charge_type = AST_AOC_CHARGE_UNIT;
00476       } else if ((encoded->flags & AST_AOC_ENCODED_CHARGE_CURRENCY) == AST_AOC_ENCODED_CHARGE_CURRENCY) {
00477          decoded->charge_type = AST_AOC_CHARGE_CURRENCY;
00478       } else if ((encoded->flags & AST_AOC_ENCODED_CHARGE_FREE) == AST_AOC_ENCODED_CHARGE_FREE) {
00479          decoded->charge_type = AST_AOC_CHARGE_FREE;
00480       } else {
00481          decoded->charge_type = AST_AOC_CHARGE_NA;
00482       }
00483 
00484       if (encoded->flags & AST_AOC_ENCODED_CHARGE_SUBTOTAL) {
00485          decoded->total_type = AST_AOC_SUBTOTAL;
00486       }
00487    }
00488 
00489    /* decode information elements */
00490    aoc_parse_ie(decoded, encoded->data, ntohs(encoded->datalen));
00491 
00492    if (aoc_debug_enabled) {
00493       aoc_display_decoded_debug(decoded, 1, chan);
00494    }
00495 
00496    return decoded;
00497 }

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:
decoded ast_aoc_decoded struct to convert to string
msg dynamic heap allocated ast_str object to store string representation in
Return values:
0 success
-1 failure

Definition at line 1942 of file aoc.c.

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().

01943 {
01944    if (!decoded || !msg) {
01945       return -1;
01946    }
01947 
01948    switch (decoded->msg_type) {
01949    case AST_AOC_S:
01950       ast_str_append(msg, 0, "AOC-S\r\n");
01951       aoc_s_event(decoded, msg);
01952       break;
01953    case AST_AOC_D:
01954       ast_str_append(msg, 0, "AOC-D\r\n");
01955       aoc_d_event(decoded, msg);
01956       break;
01957    case AST_AOC_E:
01958       ast_str_append(msg, 0, "AOC-E\r\n");
01959       aoc_e_event(decoded, msg);
01960       break;
01961    case AST_AOC_REQUEST:
01962       ast_str_append(msg, 0, "AOC-Request\r\n");
01963       aoc_request_event(decoded, msg);
01964       break;
01965    }
01966 
01967    return 0;
01968 }

void* ast_aoc_destroy_decoded ( struct ast_aoc_decoded decoded  ) 

free an ast_aoc_decoded object

Definition at line 294 of file aoc.c.

References ast_free, and NULL.

Referenced by action_aocmessage(), ast_aoc_test_encode_decode_match(), AST_TEST_DEFINE(), chanlist_free(), hangupcalls(), sip_indicate(), and wait_for_answer().

00295 {
00296    ast_free(decoded);
00297    return NULL;
00298 }

void* ast_aoc_destroy_encoded ( struct ast_aoc_encoded encoded  ) 

free an ast_aoc_encoded object

Definition at line 300 of file aoc.c.

References ast_free, and NULL.

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

00301 {
00302    ast_free(encoded);
00303    return NULL;
00304 }

struct ast_aoc_encoded* ast_aoc_encode ( struct ast_aoc_decoded decoded,
size_t *  out_size,
struct ast_channel chan 
) [read]

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

Since:
1.8
Parameters:
decoded the decoded struct to be encoded
out_size output parameter representing size of encoded data
chan ast channel, Optional for DEBUG output purposes
Return values:
pointer to encoded data
NULL failure

Definition at line 637 of file aoc.c.

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, 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, ast_aoc_decoded::total_type, and ast_aoc_encoded::version.

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

00638 {
00639    struct aoc_ie_data ied;
00640    struct ast_aoc_encoded *encoded = NULL;
00641    size_t size = 0;
00642 
00643    if (!decoded || !out_size) {
00644       return NULL;
00645    }
00646 
00647    *out_size = 0;
00648 
00649    /* create information element buffer before allocating the payload,
00650     * by doing this the exact size of the payload + the id data can be
00651     * allocated all at once. */
00652    aoc_create_ie_data(decoded, &ied);
00653 
00654    size = sizeof(struct ast_aoc_encoded) + ied.pos;
00655 
00656    if (!(encoded = ast_calloc(1, size))) {
00657       ast_log(LOG_WARNING, "Failed to create ast_aoc_encoded object during decode routine. \n");
00658       return NULL;
00659    }
00660 
00661    /* -- Set ie data buffer */
00662    if (ied.pos) {
00663       /* this is safe because encoded was allocated to fit this perfectly */
00664       memcpy(encoded->data, ied.buf, ied.pos);
00665       encoded->datalen = htons(ied.pos);
00666    }
00667 
00668    /* --- Set Flags --- */
00669    switch (decoded->msg_type) {
00670    case AST_AOC_S:
00671       encoded->flags = AST_AOC_ENCODED_TYPE_S;
00672       break;
00673    case AST_AOC_D:
00674       encoded->flags = AST_AOC_ENCODED_TYPE_D;
00675       break;
00676    case AST_AOC_E:
00677       encoded->flags = AST_AOC_ENCODED_TYPE_E;
00678       break;
00679    case AST_AOC_REQUEST:
00680       encoded->flags = AST_AOC_ENCODED_TYPE_REQUEST;
00681    default:
00682       break;
00683    }
00684 
00685    /* if it is type request, set the types requested, else set charge type */
00686    if (decoded->msg_type == AST_AOC_REQUEST) {
00687       if (decoded->request_flag & AST_AOC_REQUEST_S) {
00688          encoded->flags |= AST_AOC_ENCODED_REQUEST_S;
00689       }
00690       if (decoded->request_flag & AST_AOC_REQUEST_D) {
00691          encoded->flags |= AST_AOC_ENCODED_REQUEST_D;
00692       }
00693       if (decoded->request_flag & AST_AOC_REQUEST_E) {
00694          encoded->flags |= AST_AOC_ENCODED_REQUEST_E;
00695       }
00696    } else if ((decoded->msg_type == AST_AOC_D) || (decoded->msg_type == AST_AOC_E)) {
00697       switch (decoded->charge_type) {
00698       case AST_AOC_CHARGE_UNIT:
00699          encoded->flags |= AST_AOC_ENCODED_CHARGE_UNIT;
00700          break;
00701       case AST_AOC_CHARGE_CURRENCY:
00702          encoded->flags |= AST_AOC_ENCODED_CHARGE_CURRENCY;
00703          break;
00704       case AST_AOC_CHARGE_FREE:
00705          encoded->flags |= AST_AOC_ENCODED_CHARGE_FREE;
00706       case AST_AOC_CHARGE_NA:
00707       default:
00708          encoded->flags |= AST_AOC_ENCODED_CHARGE_NA;
00709          break;
00710       }
00711 
00712       if (decoded->total_type == AST_AOC_SUBTOTAL) {
00713          encoded->flags |= AST_AOC_ENCODED_CHARGE_SUBTOTAL;
00714       }
00715    }
00716 
00717    /* --- Set Version Number --- */
00718    encoded->version = AST_AOC_ENCODE_VERSION;
00719 
00720    /* set the output size  */
00721    *out_size = size;
00722 
00723    if (aoc_debug_enabled) {
00724       aoc_display_decoded_debug(decoded, 0, chan);
00725    }
00726 
00727    return encoded;
00728 }

struct ast_aoc_charging_association* ast_aoc_get_association_info ( struct ast_aoc_decoded decoded  )  [read]

get the charging association info for AOC-E messages

Definition at line 1038 of file aoc.c.

References ast_aoc_decoded::charging_association.

Referenced by AST_TEST_DEFINE().

01039 {
01040    return &decoded->charging_association;
01041 }

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

References ast_aoc_decoded::billing_id.

Referenced by AST_TEST_DEFINE().

01023 {
01024    return decoded->billing_id;
01025 }

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

References ast_aoc_decoded::charge_type.

Referenced by AST_TEST_DEFINE(), and transmit_info_with_aoc().

00885 {
00886    return decoded->charge_type;
00887 }

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

References ast_aoc_decoded::currency_amount.

Referenced by AST_TEST_DEFINE(), and transmit_info_with_aoc().

00928 {
00929    return decoded->currency_amount;
00930 }

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

References ast_aoc_decoded::multiplier.

Referenced by AST_TEST_DEFINE().

00933 {
00934    return decoded->multiplier;
00935 }

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

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.

Referenced by transmit_info_with_aoc().

00938 {
00939    switch (decoded->multiplier) {
00940    case AST_AOC_MULT_ONETHOUSANDTH:
00941       return "0.001";
00942    case AST_AOC_MULT_ONEHUNDREDTH:
00943       return "0.01";
00944    case AST_AOC_MULT_ONETENTH:
00945       return "0.1";
00946    case AST_AOC_MULT_ONE:
00947       return "1.0";
00948    case AST_AOC_MULT_TEN:
00949       return "10.0";
00950    case AST_AOC_MULT_HUNDRED:
00951       return "100.0";
00952    case AST_AOC_MULT_THOUSAND:
00953       return "1000.0";
00954    default:
00955       return "1.0";
00956    }
00957 }

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

References ast_aoc_decoded::currency_name.

Referenced by AST_TEST_DEFINE(), and transmit_info_with_aoc().

00960 {
00961    return decoded->currency_name;
00962 }

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

References ast_aoc_decoded::msg_type.

Referenced by AST_TEST_DEFINE(), sip_indicate(), transmit_info_with_aoc(), and wait_for_answer().

00880 {
00881    return decoded->msg_type;
00882 }

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

References ast_aoc_decoded::request_flag.

Referenced by AST_TEST_DEFINE().

00890 {
00891    return decoded->request_flag;
00892 }

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:
decoded ast_aoc_decoded struct to get values on
Return values:
0 not a termination request
1 is a termination request

Definition at line 1066 of file aoc.c.

References ast_aoc_decoded::termination_request.

Referenced by AST_TEST_DEFINE(), and sip_indicate().

01067 {
01068    return decoded->termination_request;
01069 }

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

References ast_aoc_decoded::total_type.

Referenced by AST_TEST_DEFINE().

00902 {
00903    return decoded->total_type;
00904 }

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

References ast_aoc_decoded::unit_count.

Referenced by AST_TEST_DEFINE().

01007 {
01008    return decoded->unit_count;
01009 }

struct ast_aoc_unit_entry* ast_aoc_get_unit_info ( struct ast_aoc_decoded decoded,
unsigned int  entry_number 
) [read]

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

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

Referenced by AST_TEST_DEFINE(), and transmit_info_with_aoc().

00998 {
00999    if (entry_number >= decoded->unit_count) {
01000       return NULL;
01001    }
01002 
01003    return (const struct ast_aoc_unit_entry *) &decoded->unit_list[entry_number];
01004 }

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

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().

01911 {
01912    struct ast_json *blob;
01913    struct stasis_message_type *msg_type;
01914 
01915    if (!decoded) {
01916       return -1;
01917    }
01918 
01919    switch (decoded->msg_type) {
01920    case AST_AOC_S:
01921       blob = s_to_json(decoded);
01922       msg_type = aoc_s_type();
01923       break;
01924    case AST_AOC_D:
01925       blob = d_to_json(decoded);
01926       msg_type = aoc_d_type();
01927       break;
01928    case AST_AOC_E:
01929       blob = e_to_json(decoded);
01930       msg_type = aoc_e_type();
01931       break;
01932    default:
01933       /* events for AST_AOC_REQUEST are not generated here */
01934       return 0;
01935    }
01936 
01937    aoc_publish_blob(chan, msg_type, blob);
01938    ast_json_unref(blob);
01939    return 0;
01940 }

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:
decoded aoc decoded object to add entry to
charged_item ast_aoc_s_charged_item
amount currency amount
multiplier currency multiplier
currency_name truncated after 10 characters
time 
time_scale from ast_aoc_time_scale enum
granularity_time (optional, set to 0 if not present);
granularity_time_scale (optional, set to 0 if not present);
step_function set to 1 if this is to use a step function, 0 if continuious
Return values:
0 success
-1 failure

Definition at line 757 of file aoc.c.

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 AST_TEST_DEFINE().

00767 {
00768 
00769    struct ast_aoc_s_entry entry = { 0, };
00770 
00771    entry.charged_item = charged_item;
00772    entry.rate_type = AST_AOC_RATE_TYPE_DURATION;
00773    entry.rate.duration.amount = amount;
00774    entry.rate.duration.multiplier = multiplier;
00775    entry.rate.duration.time = time;
00776    entry.rate.duration.time_scale = time_scale;
00777    entry.rate.duration.granularity_time = granularity_time;
00778    entry.rate.duration.granularity_time_scale = granularity_time_scale;
00779    entry.rate.duration.charging_type = step_function ? 1 : 0;
00780 
00781    if (!ast_strlen_zero(currency_name)) {
00782       ast_copy_string(entry.rate.duration.currency_name, currency_name, sizeof(entry.rate.duration.currency_name));
00783    }
00784 
00785    return aoc_s_add_entry(decoded, &entry);
00786 }

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:
decoded aoc decoded object to add entry to
charged_item ast_aoc_s_charged_item
amount currency amount
multiplier currency multiplier
currency_name truncated after 10 characters
Return values:
0 success
-1 failure

Definition at line 788 of file aoc.c.

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 AST_TEST_DEFINE().

00793 {
00794    struct ast_aoc_s_entry entry = { 0, };
00795 
00796    entry.charged_item = charged_item;
00797    entry.rate_type = AST_AOC_RATE_TYPE_FLAT;
00798    entry.rate.flat.amount = amount;
00799    entry.rate.flat.multiplier = multiplier;
00800 
00801    if (!ast_strlen_zero(currency_name)) {
00802       ast_copy_string(entry.rate.flat.currency_name, currency_name, sizeof(entry.rate.flat.currency_name));
00803    }
00804 
00805    return aoc_s_add_entry(decoded, &entry);
00806 }

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:
decoded aoc decoded object to add entry to
charged_item ast_aoc_s_charged_item
from_beginning TRUE if the rate is free from beginning.
Return values:
0 success
-1 failure

Definition at line 844 of file aoc.c.

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 AST_TEST_DEFINE().

00847 {
00848    struct ast_aoc_s_entry entry = { 0, };
00849 
00850    entry.charged_item = charged_item;
00851    entry.rate_type = from_beginning ? AST_AOC_RATE_TYPE_FREE_FROM_BEGINNING : AST_AOC_RATE_TYPE_FREE;
00852 
00853    return aoc_s_add_entry(decoded, &entry);
00854 }

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:
decoded aoc decoded object to add entry to
charged_item ast_aoc_s_charged_item
Return values:
0 success
-1 failure

Definition at line 856 of file aoc.c.

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 AST_TEST_DEFINE().

00858 {
00859    struct ast_aoc_s_entry entry = { 0, };
00860 
00861    entry.charged_item = charged_item;
00862    entry.rate_type = AST_AOC_RATE_TYPE_NA;
00863 
00864    return aoc_s_add_entry(decoded, &entry);
00865 }

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:
decoded aoc decoded object to add entry to
charged_item ast_aoc_s_charged_item
code special charging code
Return values:
0 success
-1 failure

Definition at line 831 of file aoc.c.

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.

00834 {
00835    struct ast_aoc_s_entry entry = { 0, };
00836 
00837    entry.charged_item = charged_item;
00838    entry.rate_type = AST_AOC_RATE_TYPE_SPECIAL_CODE;
00839    entry.rate.special_code = code;
00840 
00841    return aoc_s_add_entry(decoded, &entry);
00842 }

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:
decoded aoc decoded object to add entry to
charged_item ast_aoc_s_charged_item
volume_unit from ast_aoc_volume_unit enum
amount currency amount
multiplier currency multiplier
currency_name truncated after 10 characters
Return values:
0 success
-1 failure

Definition at line 809 of file aoc.c.

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 AST_TEST_DEFINE().

00815 {
00816    struct ast_aoc_s_entry entry = { 0, };
00817 
00818    entry.charged_item = charged_item;
00819    entry.rate_type = AST_AOC_RATE_TYPE_VOLUME;
00820    entry.rate.volume.multiplier = multiplier;
00821    entry.rate.volume.amount = amount;
00822    entry.rate.volume.volume_unit = volume_unit;
00823 
00824    if (!ast_strlen_zero(currency_name)) {
00825       ast_copy_string(entry.rate.volume.currency_name, currency_name, sizeof(entry.rate.volume.currency_name));
00826    }
00827 
00828    return aoc_s_add_entry(decoded, &entry);
00829 }

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:
decoded aoc decoded object to add entry to
code special arrangement code
Return values:
0 success
-1 failure

Definition at line 867 of file aoc.c.

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.

00869 {
00870    struct ast_aoc_s_entry entry = { 0, };
00871 
00872    entry.charged_item = AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT;
00873    entry.rate_type = AST_AOC_RATE_TYPE_SPECIAL_CODE;
00874    entry.rate.special_code = code;
00875 
00876    return aoc_s_add_entry(decoded, &entry);
00877 }

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

References ast_aoc_decoded::aoc_s_count.

00744 {
00745    return decoded->aoc_s_count;
00746 }

struct ast_aoc_s_entry* ast_aoc_s_get_rate_info ( struct ast_aoc_decoded decoded,
unsigned int  entry_number 
) [read]

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

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

00749 {
00750    if (entry_number >= decoded->aoc_s_count) {
00751       return NULL;
00752    }
00753 
00754    return (const struct ast_aoc_s_entry *) &decoded->aoc_s_entries[entry_number];
00755 }

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:
decoded ast_aoc_decoded struct to set values on
id charging 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:
0 success

Definition at line 1027 of file aoc.c.

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, ast_aoc_charging_association::id, and ast_aoc_decoded::msg_type.

Referenced by action_aocmessage(), and AST_TEST_DEFINE().

01028 {
01029    if (decoded->msg_type != AST_AOC_E) {
01030       return -1;
01031    }
01032    memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
01033    decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_ID;
01034    decoded->charging_association.charge.id = id;
01035    return 0;
01036 }

int ast_aoc_set_association_number ( struct ast_aoc_decoded decoded,
const char *  num,
uint8_t  plan 
)

set the charging accociation number for an AOC-E message

Since:
1.8
Parameters:
decoded ast_aoc_decoded struct to set values on
num charging association number
plan charging 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:
0 success

Definition at line 1043 of file aoc.c.

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_aocmessage(), and AST_TEST_DEFINE().

01044 {
01045    if ((decoded->msg_type != AST_AOC_E) || ast_strlen_zero(num)) {
01046       return -1;
01047    }
01048    memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
01049    decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_NUMBER;
01050    decoded->charging_association.charge.number.plan = plan;
01051    ast_copy_string(decoded->charging_association.charge.number.number, num, sizeof(decoded->charging_association.charge.number.number));
01052 
01053    return 0;
01054 }

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:
decoded ast_aoc_decoded struct to set values on
id billing id
Return values:
0 success

Definition at line 1011 of file aoc.c.

References AST_AOC_BILLING_NA, AST_AOC_BILLING_NUM_ENTRIES, and ast_aoc_decoded::billing_id.

Referenced by action_aocmessage(), and AST_TEST_DEFINE().

01012 {
01013    if ((id >= AST_AOC_BILLING_NUM_ENTRIES) || (id < AST_AOC_BILLING_NA)) {
01014       return -1;
01015    }
01016 
01017    decoded->billing_id = id;
01018 
01019    return 0;
01020 }

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:
decoded ast_aoc_decoded struct to set values on
amount currency amount REQUIRED
multiplier currency multiplier REQUIRED, 0 or undefined value defaults to AST_AOC_MULT_ONE.
name currency name OPTIONAL
Return values:
0 success

Definition at line 906 of file aoc.c.

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, and ast_aoc_decoded::multiplier.

Referenced by action_aocmessage(), and AST_TEST_DEFINE().

00910 {
00911 
00912    if (!ast_strlen_zero(name)) {
00913       ast_copy_string(decoded->currency_name, name, sizeof(decoded->currency_name));
00914    }
00915 
00916    decoded->currency_amount = amount;
00917 
00918    if (multiplier && (multiplier < AST_AOC_MULT_NUM_ENTRIES)) {
00919       decoded->multiplier = multiplier;
00920    } else {
00921       decoded->multiplier = AST_AOC_MULT_ONE;
00922    }
00923 
00924    return 0;
00925 }

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:
decoded ast_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:
0 success
-1 failure

Definition at line 1056 of file aoc.c.

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

Referenced by AST_TEST_DEFINE().

01057 {
01058    if (decoded->msg_type != AST_AOC_REQUEST) {
01059       return -1;
01060    }
01061    decoded->termination_request = 1;
01062 
01063    return 0;
01064 }

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:
decoded ast_aoc_decoded struct to set values on
type total type: TOTAL or SUBTOTAL
Note:
If this value is not set, the default for the message is TOTAL
Return values:
0 success

Definition at line 894 of file aoc.c.

References ast_aoc_decoded::total_type.

Referenced by action_aocmessage(), and AST_TEST_DEFINE().

00896 {
00897    decoded->total_type = type;
00898    return 0;
00899 }

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

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

Referenced by AST_TEST_DEFINE().

01318 {
01319    struct ast_aoc_decoded *new_decoded = NULL;
01320    struct ast_aoc_encoded *encoded = NULL;
01321    size_t size;
01322    int res = 0;
01323 
01324    if (!(encoded = ast_aoc_encode(decoded, &size, NULL))) {
01325       return -1;
01326    }
01327 
01328    if (!(new_decoded = ast_aoc_decode(encoded, size, NULL))) {
01329       ast_free(encoded);
01330       return -1;
01331    }
01332 
01333    if (memcmp(new_decoded, decoded, sizeof(struct ast_aoc_decoded))) {
01334       res = -1;
01335    }
01336 
01337    ast_aoc_destroy_decoded(new_decoded);
01338    ast_aoc_destroy_encoded(encoded);
01339    return res;
01340 }


Generated on Thu Apr 16 06:28:14 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6