amiws  2.2.1
Functions | Variables
amiws_lib.c File Reference

AMI/web-socket functions. More...

#include "amiws.h"
Include dependency graph for amiws_lib.c:

Functions

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)
 
char * amipack_to_json (const char *ami_pack_str, int len, struct amiws_conn *conn)
 
void websock_send (struct mg_connection *nc, const char *json)
 
void websock_ev_handler (struct mg_connection *nc, int ev, void *ev_data)
 
void ami_login (struct mg_connection *nc, struct amiws_conn *conn)
 
int scan_amipack (const char *p, size_t len)
 

Variables

struct mg_connection * nc_ws
 

Detailed Description

AMI/web-socket 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

◆ 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.

◆ 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.