33#define AEAP_RECV_SIZE 32768
45#define USER_DATA_BUCKETS 11
60static int tsx_end(
void *obj,
void *arg,
int flags)
103 aeap_user_data_hash_fn,
NULL, aeap_user_data_cmp_fn);
112 aeap_error(aeap,
NULL,
"unable to create transactions container");
144 strcpy(data->
id,
id);
211 for (i = 0; i < size; ++i) {
225 return on_message(aeap, msg, data);
231 "Unsupported and/or un-handled message"));
277 goto aeap_receive_error;
286 goto aeap_receive_error;
300 ast_debug(3,
"AEAP: received message: %s\n", (
char *)
buf);
321 aeap_error(aeap,
NULL,
"unrecoverable read error, disconnecting");
int ast_aeap_disconnect(struct ast_aeap *aeap)
Disconnect an Asterisk external application object.
static void aeap_destructor(void *obj)
AO2_STRING_FIELD_CMP_FN(aeap_user_data, id)
int ast_aeap_user_data_register(struct ast_aeap *aeap, const char *id, void *obj, ast_aeap_user_obj_cleanup cleanup)
Register a user data object.
static int tsx_end(void *obj, void *arg, int flags)
static struct aeap_user_data * aeap_user_data_create(const char *id, void *obj, ast_aeap_user_obj_cleanup cleanup)
#define USER_DATA_BUCKETS
static int raise_msg_handler(struct ast_aeap *aeap, const struct ast_aeap_message_handler *handlers, size_t size, struct ast_aeap_message *msg, void *data)
void * ast_aeap_user_data_object_by_id(struct ast_aeap *aeap, const char *id)
Retrieve a registered user data object by its id.
int ast_aeap_send_msg(struct ast_aeap *aeap, struct ast_aeap_message *msg)
Send a message to an external application.
int ast_aeap_send_msg_tsx(struct ast_aeap *aeap, struct ast_aeap_tsx_params *params)
Send a transaction based message to an external application using the given parameters.
static int aeap_send(struct ast_aeap *aeap, const void *buf, uintmax_t size, enum AST_AEAP_DATA_TYPE type)
int ast_aeap_send_binary(struct ast_aeap *aeap, const void *buf, uintmax_t size)
Send a binary data to an external application.
static void raise_msg(struct ast_aeap *aeap, const void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE serial_type)
void ast_aeap_user_data_unregister(struct ast_aeap *aeap, const char *id)
Un-register a user data object.
AO2_STRING_FIELD_HASH_FN(aeap_user_data, id)
struct ast_aeap * ast_aeap_create(const char *transport_type, const struct ast_aeap_params *params)
Create an Asterisk external application object.
static void * aeap_receive(void *data)
int ast_aeap_connect(struct ast_aeap *aeap, const char *url, const char *protocol, int timeout)
Connect to an external application.
struct ast_aeap * ast_aeap_create_and_connect(const char *type, const struct ast_aeap_params *params, const char *url, const char *protocol, int timeout)
Create and connect to an Asterisk external application.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
#define ast_debug(level,...)
Log a DEBUG message.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
#define AST_PTHREADT_NULL
static void * cleanup(void *unused)
#define aeap_error(obj, name, fmt,...)
Log an Asterisk external application error.
Asterisk External Application Protocol API.
AST_AEAP_DATA_TYPE
Supported Asterisk external application data types.
@ AST_AEAP_DATA_TYPE_BINARY
@ AST_AEAP_DATA_TYPE_STRING
int(* ast_aeap_on_message)(struct ast_aeap *aeap, struct ast_aeap_message *message, void *obj)
Event raised when a message is received.
void(* ast_aeap_user_obj_cleanup)(void *obj)
Callback to cleanup a user object.
Asterisk External Application Protocol Message API.
int ast_aeap_message_serialize(const struct ast_aeap_message *message, void **buf, intmax_t *size)
Serialize the given message object into a byte/char buffer.
struct ast_aeap_message * ast_aeap_message_create_error(const struct ast_aeap_message_type *type, const char *name, const char *id, const char *error_msg)
Create an Asterisk external application error response object.
int ast_aeap_message_is_request(const struct ast_aeap_message *message)
Retrieve whether or not this is a request message.
const char * ast_aeap_message_id(const struct ast_aeap_message *message)
Retrieve a message id.
int ast_aeap_message_is_response(const struct ast_aeap_message *message)
Retrieve whether or not this is a response message.
const char * ast_aeap_message_name(const struct ast_aeap_message *message)
Retrieve a message name.
const char * ast_aeap_message_error_msg(const struct ast_aeap_message *message)
Retrieve the error message if it has one.
int ast_aeap_message_is_named(const struct ast_aeap_message *message, const char *name)
Check whether or not a message's name matches the given one.
struct ast_aeap_message * ast_aeap_message_deserialize(const struct ast_aeap_message_type *type, const void *buf, intmax_t size)
Deserialize the given buffer into an Asterisk external application message object.
enum AST_AEAP_DATA_TYPE ast_aeap_message_serial_type(const struct ast_aeap_message_type *type)
Retrieve the serial type a message type.
String manipulation functions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
struct ast_aeap_tsx_params params
Asterisk external application transport structure to be "derived" by specific transport implementatio...
An Asterisk external application message handler.
ast_aeap_on_message on_message
enum AST_AEAP_DATA_TYPE serial_type
Asterisk external application base message.
const struct ast_aeap_message_type * type
Callbacks and other parameters used by an Asterisk external application object.
const struct ast_aeap_message_type * msg_type
void(* on_string)(struct ast_aeap *aeap, const char *buf, intmax_t size)
Raised when string data is received.
uintmax_t response_handlers_size
void(* on_error)(struct ast_aeap *aeap)
Raised when an error occurs during reading.
uintmax_t request_handlers_size
const struct ast_aeap_message_handler * response_handlers
const struct ast_aeap_message_handler * request_handlers
void(* on_binary)(struct ast_aeap *aeap, const void *buf, intmax_t size)
Raised when binary data is received.
Parameters to be used when sending a transaction based message.
struct ast_aeap_message * msg
struct aeap_transport * transport
const struct ast_aeap_params * params
struct ao2_container * transactions
struct ao2_container * user_data
static const struct ast_aeap_message_handler handlers[]
void * aeap_transaction_user_obj(struct aeap_transaction *tsx)
Retrieve the user object associated with the transaction.
int aeap_transaction_cancel_timer(struct aeap_transaction *tsx)
Cancel the transaction timer.
int aeap_transaction_result(struct aeap_transaction *tsx)
Get a transaction's result.
struct ao2_container * aeap_transactions_create(void)
Create an Asterisk external application transactions container.
struct aeap_transaction * aeap_transaction_create_and_add(struct ao2_container *transactions, const char *id, struct ast_aeap_tsx_params *params, struct ast_aeap *aeap)
Create a transaction object, and add it to the given container.
void aeap_transaction_end(struct aeap_transaction *tsx, int result)
End a transaction, and remove it from the given container.
struct aeap_transaction * aeap_transaction_get(struct ao2_container *transactions, const char *id)
Retrieve a transaction for the id from the container.
int aeap_transaction_start(struct aeap_transaction *tsx)
Start the transaction.
void aeap_transaction_params_cleanup(struct ast_aeap_tsx_params *params)
Clean up parameter references, and possibly call optional user object cleanup.
intmax_t aeap_transport_write(struct aeap_transport *transport, const void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE wtype)
Write data to the transport.
int aeap_transport_connect(struct aeap_transport *transport, const char *url, const char *protocol, int timeout)
Connect a transport.
void aeap_transport_destroy(struct aeap_transport *transport)
Destroy a transport.
intmax_t aeap_transport_read(struct aeap_transport *transport, void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE *rtype)
Read data from the transport.
int aeap_transport_is_connected(struct aeap_transport *transport)
Whether or not the transport is in a connected state.
struct aeap_transport * aeap_transport_create(const char *type)
Create an Asterisk external application transport.
int aeap_transport_disconnect(struct aeap_transport *transport)
Disconnect a transport.
#define ast_pthread_create_background(a, b, c, d)