amiws  2.2.1
Classes | Macros | Typedefs | Enumerations | Functions
amipack.h File Reference

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>
Include dependency graph for amipack.h:
This graph shows which files directly or indirectly include this file:

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

AMIPacketamipack_init ()
 
void amipack_destroy (AMIPacket *pack)
 
AMIQueueamipack_queue_init ()
 
void amipack_queue_destroy (AMIQueue *queue)
 
AMIHeaderamiheader_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)
 
AMIPacketamipack_parser_message (const char *pack_str)
 
AMIPacketamipack_parser_command (const char *packet)
 
AMIQueueamipack_parser_queue (const char *packet)
 

Detailed Description

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.nosp@m.obza.nosp@m.r@mod.nosp@m.ulis.nosp@m..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/.

Author
Stas Kobzar stas..nosp@m.kobz.nosp@m.ar@mo.nosp@m.duli.nosp@m.s.ca

Macro Definition Documentation

◆ amipack_append_action

#define amipack_append_action (   pack,
  val,
  len 
)    amipack_append((pack), strdup("Action"), 6, val, len)

Append Action header.

◆ amipack_length

#define amipack_length (   pack)    (pack)->length + 2

Return length of the packet as string representation. All headers length + CRLF stanza (2 bytes)

◆ amipack_size

#define amipack_size (   pack)    (pack)->size

Number of headers in packet.

◆ amipack_type

#define amipack_type (   pack,
  ptype 
)    (pack)->type = ptype

Set AMI packet type.

Typedef Documentation

◆ AMIHeader

typedef struct AMIHeader_ AMIHeader

AMI header structure.

◆ AMIPacket

typedef struct AMIPacket_ AMIPacket

AMI packet structure.

◆ AMIQueue

typedef struct AMIQueue_ AMIQueue

AMI queue structure. Action "Queues" returns none standard AMI response.

◆ AMIVer

typedef struct AMIVer_ AMIVer

AMI semantic version structure. Used when AMI prompt line parsed.

Enumeration Type Documentation

◆ pack_type

enum pack_type

AMI packet types.

Function Documentation

◆ amiheader_create()

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.

Parameters
nameAMI header name
name_sizeName field size
valueAMI header value
value_sizeValue field size
Returns
AMIHeader pointer to the new structure.

◆ amiheader_destroy()

void amiheader_destroy ( AMIHeader hdr)

Destroy AMI header and free memory.

Parameters
hdrAMI header to destroy

◆ amiheader_find()

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.

Parameters
packAMI packet structure pointer
nameHeader name
valueString where the found value will be stored.
Returns
-1 or length of the header value

◆ amiheader_to_str()

size_t amiheader_to_str ( AMIHeader hdr,
char *  buf 
)

Convert AMIHeader pstr string.

Parameters
hdrAMI header structure pointer
bufHeader as string "Name: value\r\n"
Returns
header characters length

◆ amipack_append()

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.

Parameters
packPointer to AMI packet structure
hdr_nameAMI header name as string.
name_sizeHeader name size
hdr_valueAMI header value as string.
value_sizeAMI header value size
Returns
-1 if error or number of headers in packet

◆ amipack_destroy()

void amipack_destroy ( AMIPacket pack)

Destroy AMI packet and free memory.

Parameters
packAMI header to destroy

◆ amipack_init()

AMIPacket* amipack_init ( )

Initiate AMIPacket and allocate memory. AMI packet is implemented as linked list data structure.

Returns
AMIPacket pointer to the new structure.

◆ amipack_list_append()

int amipack_list_append ( AMIPacket pack,
AMIHeader header 
)

Append AMI header to packet.

Parameters
packAMI packet structure pointer
headerAMI header structure pointer
Returns
-1 if error or number of headers in packet

◆ amipack_parser_command()

AMIPacket* amipack_parser_command ( const char *  packet)

Parse AMI Response for Command.

Parameters
packetPacket received from server as bytes array.
Returns
AMIPacket pointer or NULL if AMI packet failed to parse.

◆ amipack_parser_detect()

enum pack_type amipack_parser_detect ( const char *  packet)

Detect AMI packet type.

Parameters
packetPacket received from server as bytes array.
Returns
packet type

◆ amipack_parser_message()

AMIPacket* amipack_parser_message ( const char *  pack_str)

Parse AMI packet to AMIPacket structure.

Parameters
pack_strBytes array received from server.
Returns
AMIPacket pointer or NULL if AMI packet failed to parse.

◆ amipack_parser_prompt()

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

Parameters
packetPacket received from server as bytes array.
versionAMIVer struct will be set when packet parsed
Returns
1 on success or 0 on fail

◆ amipack_parser_queue()

AMIQueue* amipack_parser_queue ( const char *  packet)

Parse AMI Queue Action response.

Parameters
packetPacket received from server as bytes array.
Returns
packet type

◆ amipack_queue_destroy()

void amipack_queue_destroy ( AMIQueue queue)

Destroy Queue structrue.

Parameters
packAMI header to destroy

◆ amipack_queue_init()

AMIQueue* amipack_queue_init ( )

Initiate Queue member

Returns
AMIQueue pointer to the new structure

◆ amipack_to_str()

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.

Parameters
packAMI packet structure pointer
pstrAMI packet as string
Returns
pointer to AMI packet as string