amiws
2.2.1
|
AMI (Asterisk Management Interface) messages read/create functions interface. AMI packet is implemented as linked list of headers. More...
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Classes | |
struct | AMIVer_ |
struct | AMIHeader_ |
struct | AMIQueue_ |
struct | AMIPacket_ |
Macros | |
#define | amipack_length(pack) (pack)->length + 2 |
#define | amipack_type(pack, ptype) (pack)->type = ptype |
#define | amipack_size(pack) (pack)->size |
#define | amipack_append_action(pack, val, len) amipack_append((pack), strdup("Action"), 6, val, len) |
Typedefs | |
typedef struct AMIVer_ | AMIVer |
typedef struct AMIHeader_ | AMIHeader |
typedef struct AMIQueue_ | AMIQueue |
typedef struct AMIPacket_ | AMIPacket |
Enumerations | |
enum | pack_type { AMI_UNKNOWN , AMI_PROMPT , AMI_ACTION , AMI_EVENT , AMI_RESPONSE , AMI_RESPCMD , AMI_QUEUE } |
Functions | |
AMIPacket * | amipack_init () |
void | amipack_destroy (AMIPacket *pack) |
AMIQueue * | amipack_queue_init () |
void | amipack_queue_destroy (AMIQueue *queue) |
AMIHeader * | amiheader_create (char *name, size_t name_size, char *value, size_t value_size) |
void | amiheader_destroy (AMIHeader *hdr) |
size_t | amipack_to_str (AMIPacket *pack, char **pstr) |
size_t | amiheader_to_str (AMIHeader *hdr, char *buf) |
int | amipack_append (AMIPacket *pack, char *hdr_name, size_t name_size, char *hdr_value, size_t value_size) |
int | amipack_list_append (AMIPacket *pack, AMIHeader *header) |
size_t | amiheader_find (AMIPacket *pack, const char *name, char **value) |
enum pack_type | amipack_parser_detect (const char *packet) |
int | amipack_parser_prompt (const char *packet, AMIVer *version) |
AMIPacket * | amipack_parser_message (const char *pack_str) |
AMIPacket * | amipack_parser_command (const char *packet) |
AMIQueue * | amipack_parser_queue (const char *packet) |
AMI (Asterisk Management Interface) messages read/create functions interface. AMI packet is implemented as linked list of headers.
amiws – Library with functions for read/create AMI packets Copyright (C) 2017, Stas Kobzar stask obza r@mod ulis .ca
This file is part of amiws.
amiws is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
amiws is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with amiws. If not, see http://www.gnu.org/licenses/.
#define amipack_append_action | ( | pack, | |
val, | |||
len | |||
) | amipack_append((pack), strdup("Action"), 6, val, len) |
Append Action header.
#define amipack_length | ( | pack | ) | (pack)->length + 2 |
Return length of the packet as string representation. All headers length + CRLF stanza (2 bytes)
#define amipack_size | ( | pack | ) | (pack)->size |
Number of headers in packet.
#define amipack_type | ( | pack, | |
ptype | |||
) | (pack)->type = ptype |
Set AMI packet type.
typedef struct AMIHeader_ AMIHeader |
AMI header structure.
typedef struct AMIPacket_ AMIPacket |
AMI packet structure.
AMI queue structure. Action "Queues" returns none standard AMI response.
enum pack_type |
AMI packet types.
AMIHeader* amiheader_create | ( | char * | name, |
size_t | name_size, | ||
char * | value, | ||
size_t | value_size | ||
) |
Create new AMI header with given parameters. Will allocated memory for AMIHeader and return pointer to it.
name | AMI header name |
name_size | Name field size |
value | AMI header value |
value_size | Value field size |
void amiheader_destroy | ( | AMIHeader * | hdr | ) |
Destroy AMI header and free memory.
hdr | AMI header to destroy |
size_t amiheader_find | ( | AMIPacket * | pack, |
const char * | name, | ||
char ** | value | ||
) |
Search header by header name. Will return header value length in packet exists otherwise -1. Will return only first found header value.
pack | AMI packet structure pointer |
name | Header name |
value | String where the found value will be stored. |
size_t amiheader_to_str | ( | AMIHeader * | hdr, |
char * | buf | ||
) |
Convert AMIHeader pstr string.
hdr | AMI header structure pointer |
buf | Header as string "Name: value\r\n" |
int amipack_append | ( | AMIPacket * | pack, |
char * | hdr_name, | ||
size_t | name_size, | ||
char * | hdr_value, | ||
size_t | value_size | ||
) |
Append header to AMI packet. Will create new AMI header using given type and value string. New header will be appanded to the head of linked list.
pack | Pointer to AMI packet structure |
hdr_name | AMI header name as string. |
name_size | Header name size |
hdr_value | AMI header value as string. |
value_size | AMI header value size |
void amipack_destroy | ( | AMIPacket * | pack | ) |
Destroy AMI packet and free memory.
pack | AMI header to destroy |
AMIPacket* amipack_init | ( | ) |
Initiate AMIPacket and allocate memory. AMI packet is implemented as linked list data structure.
Append AMI header to packet.
pack | AMI packet structure pointer |
header | AMI header structure pointer |
AMIPacket* amipack_parser_command | ( | const char * | packet | ) |
Parse AMI Response for Command.
packet | Packet received from server as bytes array. |
enum pack_type amipack_parser_detect | ( | const char * | packet | ) |
Detect AMI packet type.
packet | Packet received from server as bytes array. |
AMIPacket* amipack_parser_message | ( | const char * | pack_str | ) |
Parse AMI packet to AMIPacket structure.
pack_str | Bytes array received from server. |
int amipack_parser_prompt | ( | const char * | packet, |
AMIVer * | version | ||
) |
Parse AMI protocol prompt string when user logged in. Will set AMIver structure with parsed server AMI version. Prompt header example: Asterisk Call Manager/1.1
packet | Packet received from server as bytes array. |
version | AMIVer struct will be set when packet parsed |
AMIQueue* amipack_parser_queue | ( | const char * | packet | ) |
Parse AMI Queue Action response.
packet | Packet received from server as bytes array. |
void amipack_queue_destroy | ( | AMIQueue * | queue | ) |
Destroy Queue structrue.
pack | AMI header to destroy |
AMIQueue* amipack_queue_init | ( | ) |
Initiate Queue member
size_t amipack_to_str | ( | AMIPacket * | pack, |
char ** | pstr | ||
) |
Convert AMIPacket to string. Will allocate memory for the string, set packet as string and return pointer to the char array.
pack | AMI packet structure pointer |
pstr | AMI packet as string |