amiws  2.2.1
Classes | Macros | Functions
amiws.h File Reference

AMI (Asterisk Management Interface) messages read/create functions interface. AMI packet is implemented as linked list of headers. More...

#include <stdio.h>
#include <syslog.h>
#include <yaml.h>
#include "amipack.h"
#include "config.h"
#include "frozen.h"
#include "mongoose.h"
Include dependency graph for amiws.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  amiws_config
 
struct  amiws_conn
 

Macros

#define DEFAULT_CONF_FILE   "/etc/amiws.yaml"
 
#define DEFAULT_WEB_ROOT   "./web_root"
 
#define DEFAULT_LOG_LEVEL   LOG_INFO
 
#define DEFAULT_LOG_FACILITY   LOG_SYSLOG
 
#define DEFAULT_WEBSOCK_PORT   8000
 
#define POLL_SLEEP   1000
 
#define intval(val)   str2int(val, strlen(val))
 
#define macro_init_conf(conf)
 
#define macro_init_conn(conn)
 

Functions

int isExiting ()
 
void setExiting ()
 
void amiws_init (struct amiws_config *conf)
 
void amiws_connect_ami_server (struct amiws_conn *conn)
 
void amiws_destroy ()
 
void amiws_loop ()
 
void ami_ev_handler (struct mg_connection *nc, int ev, void *ev_data)
 
void websock_ev_handler (struct mg_connection *nc, int ev, void *ev_data)
 
void websock_send (struct mg_connection *nc, const char *json)
 
void ami_login (struct mg_connection *nc, struct amiws_conn *conn)
 
char * amipack_to_json (const char *buf, int len, struct amiws_conn *conn)
 
struct amiws_configread_conf (const char *filename)
 
int scan_amipack (const char *pack, size_t len)
 
void free_conf (struct amiws_config *conf)
 
void set_conf_param (struct amiws_config *conf, char *key, char *value)
 
void set_conn_param (struct amiws_conn *conn, char *key, char *value)
 

Detailed Description

AMI (Asterisk Management Interface) messages read/create functions interface. AMI packet is implemented as linked list of headers.

AMI (Asterisk Management Interface) connector and websocket remote interface 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

Macro Definition Documentation

◆ DEFAULT_CONF_FILE

#define DEFAULT_CONF_FILE   "/etc/amiws.yaml"

Default configuration path.

◆ DEFAULT_LOG_FACILITY

#define DEFAULT_LOG_FACILITY   LOG_SYSLOG

Default log facility as in syslog.h

◆ DEFAULT_LOG_LEVEL

#define DEFAULT_LOG_LEVEL   LOG_INFO

Default log level as in syslog.h

◆ DEFAULT_WEB_ROOT

#define DEFAULT_WEB_ROOT   "./web_root"

Default path to web root with static HTML content.

◆ DEFAULT_WEBSOCK_PORT

#define DEFAULT_WEBSOCK_PORT   8000

Default WebSock and HTTP port.

◆ intval

#define intval (   val)    str2int(val, strlen(val))

Convert string to int

◆ macro_init_conf

#define macro_init_conf (   conf)
Value:
conf = (struct amiws_config *) malloc(sizeof(struct amiws_config));\
memset(conf,0,sizeof(struct amiws_config)); \
conf->log_level = DEFAULT_LOG_LEVEL; \
conf->log_facility = DEFAULT_LOG_FACILITY; \
conf->ws_port = DEFAULT_WEBSOCK_PORT; \
conf->size = 0; \
conf->head = NULL; \
conf->tail = NULL; \
conf->web_root = NULL; \
conf->auth_domain = NULL; \
conf->parse_fail = 0; \
conf->syntax_error = 0; \
conf->auth_file = NULL;
#define DEFAULT_LOG_FACILITY
Definition: amiws.h:48
#define DEFAULT_WEBSOCK_PORT
Definition: amiws.h:50
#define DEFAULT_LOG_LEVEL
Definition: amiws.h:46
Definition: amiws.h:90

Macro to initilize configuration structure.

◆ macro_init_conn

#define macro_init_conn (   conn)
Value:
conn = (struct amiws_conn *) malloc(sizeof(struct amiws_conn)); \
memset(conn,0,sizeof(struct amiws_conn)); \
conn->port = 5038; \
conn->address = NULL; \
conn->name = NULL; \
conn->host = NULL; \
conn->username = NULL; \
conn->secret = NULL; \
conn->is_ssl = 0; \
conn->event_names = NULL; \
Definition: amiws.h:114

Macro to initilize AMI connection.

◆ POLL_SLEEP

#define POLL_SLEEP   1000

Polling interval.

Function Documentation

◆ ami_ev_handler()

void ami_ev_handler ( struct mg_connection *  nc,
int  ev,
void *  ev_data 
)

Callback function for AMI connections.

Parameters
ncConnection structure.
evEvent ID
ev_dataAdditional data passed

◆ ami_login()

void ami_login ( struct mg_connection *  nc,
struct amiws_conn conn 
)

Login to AMI server. Send loging Action.

Parameters
ncConnection structure.
connAMI connection.

◆ amipack_to_json()

char* amipack_to_json ( const char *  buf,
int  len,
struct amiws_conn conn 
)

Convert AMI packet to JSON string.

Parameters
bufAMI packet stream as received from connection
lenBuffer size
connAMI connection.
Returns
JSON string

◆ amiws_connect_ami_server()

void amiws_connect_ami_server ( struct amiws_conn conn)

Connect to AMI server.

Parameters
connConnection configuration structure.

◆ amiws_destroy()

void amiws_destroy ( )

Destroy connections and free memory.

◆ amiws_init()

void amiws_init ( struct amiws_config conf)

Initialize amiws with given configuration. Will start listening for HTTP and WebSocket and connects to AMI servers.

Parameters
confConfiguration structure.

◆ amiws_loop()

void amiws_loop ( )

Main amiws loop step.

◆ free_conf()

void free_conf ( struct amiws_config conf)

Destroy configuration structure.

Parameters
confConfiguration structure.

◆ read_conf()

struct amiws_config* read_conf ( const char *  filename)

Read YAML configuration file.

Parameters
filenamePath to file.
Returns
configuration structure or NULL on error.

◆ scan_amipack()

int scan_amipack ( const char *  pack,
size_t  len 
)

Scan stream and extract AMI packet separated with CRLF CRLF token. TCP connection is feeding packets as stream and this function will get complete packet.

Parameters
packChar stream received from server.
lenStream length

◆ websock_ev_handler()

void websock_ev_handler ( struct mg_connection *  nc,
int  ev,
void *  ev_data 
)

Callback function for HTTP and WebSocket connections.

Parameters
ncConnection structure.
evEvent ID
ev_dataAdditional data passed

◆ websock_send()

void websock_send ( struct mg_connection *  nc,
const char *  json 
)

Send JSON string to WebSocket.

Parameters
ncConnection structure.
jsonJSON string.