Skip to content

01 Introduction

Stas Kobzar edited this page Feb 26, 2017 · 5 revisions

libamip is a simple library for creating and parsing AMI (Asterisk Manager Interface) packets.

More information about AMI:

libamip provides API for creating and parsing AMI packets:

AMI packet is implemented as linked list of headers and represented as structure AMIPack:

typedef struct AMIPacket_ {

  int             size;   /*!< Number of headers. */

  size_t          length; /*!< Total length of all headers as string. */

  enum pack_type  type;   /*!< AMI packet type: Action, Event etc. */

  AMIHeader       *head;  /*!< Linked list head pointer to AMI header. */
  AMIHeader       *tail;  /*!< Linked list tail pointer to AMI header. */

} AMIPacket;

AMI header has simple structure of type "Header: Value\r\n" and represented with structure AMIHeader:

typedef struct AMIHeader_ {

  enum header_type    type;  /*!< AMI Header type. */

  struct str         *name;  /*!< AMI header name as string. */
  struct str         *value; /*!< AMI header value as string. */

  struct AMIHeader_   *next; /*!< Next AMI header pointer. Linked list element. */

} AMIHeader;

AMI packet contains is of the following main types:

  • Action (AMI_ACTION)
  • Event (AMI_EVENT)
  • Response (AMI_RESPONSE)
  • Special type AMI_UNKNOWN if anything else.

Additionally, libamip uses structure to facilitate strings manipulation:

struct str {
  char    *buf; /*!< String buffer. */
  size_t  len;  /*!< String length. */
};

And two functions to create and destroy "struct str":

struct str *str_set (const char *buf);
void str_destroy (struct str *s);

Clone this wiki locally