amiws 2.2.1
Loading...
Searching...
No Matches
amipack.c File Reference

AMI (Asterisk Management Interface) messages read/create functions. More...

#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "amipack.h"
Include dependency graph for amipack.c:

Functions

AMIPacketamipack_init ()
 
AMIQueueamipack_queue_init ()
 
void amipack_queue_destroy (AMIQueue *queue)
 
void amiheader_destroy (AMIHeader *hdr)
 
AMIHeaderamiheader_create (char *name, size_t name_size, char *value, size_t value_size)
 
void amipack_destroy (AMIPacket *pack)
 
size_t amiheader_to_str (AMIHeader *hdr, char *buf)
 
size_t amipack_to_str (AMIPacket *pack, char **pstr)
 
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 **val)
 

Detailed Description

AMI (Asterisk Management Interface) messages read/create functions.

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

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_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