amiws 2.2.1
Loading...
Searching...
No Matches
amiws.h
Go to the documentation of this file.
1
20
28
29#ifndef __AMIWS_H
30#define __AMIWS_H
31
32#include <stdio.h>
33#include <syslog.h>
34#include <yaml.h>
35
36#include "amipack.h"
37#include "config.h"
38#include "frozen.h"
39#include "mongoose.h"
40
42#define DEFAULT_CONF_FILE "/etc/amiws.yaml"
44#define DEFAULT_WEB_ROOT "./web_root"
46#define DEFAULT_LOG_LEVEL LOG_INFO
48#define DEFAULT_LOG_FACILITY LOG_SYSLOG
50#define DEFAULT_WEBSOCK_PORT 8000
52#define POLL_SLEEP 1000
53
55#define intval(val) str2int(val, strlen(val))
56
58#define macro_init_conf(conf) conf = (struct amiws_config *) malloc(sizeof(struct amiws_config));\
59 conf->log_level = DEFAULT_LOG_LEVEL; \
60 conf->log_facility = DEFAULT_LOG_FACILITY; \
61 conf->ws_port = DEFAULT_WEBSOCK_PORT; \
62 conf->size = 0; \
63 conf->head = NULL; \
64 conf->tail = NULL; \
65 conf->web_root = NULL; \
66 conf->auth_domain = NULL; \
67 conf->parse_fail = 0; \
68 conf->syntax_error = 0; \
69 conf->auth_file = NULL;
70
71
73#define macro_init_conn(conn) conn = (struct amiws_conn *) malloc(sizeof(struct amiws_conn)); \
74 conn->port = 5038; \
75 conn->address = NULL; \
76 conn->name = NULL; \
77 conn->host = NULL; \
78 conn->username = NULL; \
79 conn->secret = NULL; \
80 conn->is_ssl = 0; \
81
82
88 struct amiws_conn *head;
89 struct amiws_conn *tail;
90 int size;
93 int ws_port;
94 char *web_root;
96 char *auth_file;
99#if MG_ENABLE_SSL
100 char *ssl_cert;
101 char *ssl_key;
102#endif
103
104 int parse_fail:1;
105 int syntax_error:1;
106};
107
112 int id;
113 char *name;
114 char *address;
115 unsigned int port;
116 char *host;
117 char *username;
118 char *secret;
119 AMIVer ami_ver;
120#if MG_ENABLE_SSL
121 char *ssl_cert;
122 char *ssl_key;
123#endif
124 int is_ssl;
125 struct amiws_conn *next;
126};
127
134void amiws_init(struct amiws_config *conf);
135
140void amiws_connect_ami_server(struct amiws_conn *conn);
141
145void amiws_destroy();
146
150void amiws_loop();
151
158void ami_ev_handler(struct mg_connection *nc, int ev, void *ev_data);
159
166void websock_ev_handler (struct mg_connection *nc, int ev, void *ev_data);
167
173void websock_send (struct mg_connection *nc, const char *json);
174
180void ami_login(struct mg_connection *nc, struct amiws_conn *conn);
181
189char *amipack_to_json(const char *buf, int len, struct amiws_conn *conn);
190
196struct amiws_config *read_conf(const char *filename);
197
205int scan_amipack(const char *pack, size_t len);
206
211void free_conf(struct amiws_config *conf);
212
213/* private methods */
214
215static void recv_callback(struct mbuf *io, struct amiws_conn *conn, struct mg_connection *nc);
216
217static void read_buffer(struct mbuf *io, struct mg_connection *nc);
218
219void set_conf_param(struct amiws_config *conf, char *key, char *value);
220
221void set_conn_param(struct amiws_conn *conn, char *key, char *value);
222
223static int str2int(const char *val, int len);
224
225static char* int2str(const char *val, int len);
226
227static int auth_fail(AMIPacket *amipack);
228
229static void send_ami_action(struct websocket_message *wm, struct mg_connection *nc);
230
231static void json_scan_cb(void *callback_data,
232 const char *name, size_t name_len,
233 const char *path,
234 const struct json_token *token);
235
236static struct amiws_config *valid_conf(struct amiws_config *conf);
237
238static int is_valid_auth_settings(struct amiws_config *conf);
239
240#if MG_ENABLE_SSL
241static int is_valid_ssl_settings(struct amiws_config *conf);
242
243static int is_valid_ssl_conn_settings(struct amiws_conn *conn);
244#endif
245
246#endif
void websock_send(struct mg_connection *nc, const char *json)
Definition amiws_lib.c:257
struct amiws_config * read_conf(const char *filename)
Definition config.c:32
void ami_ev_handler(struct mg_connection *nc, int ev, void *ev_data)
Definition amiws_lib.c:114
void amiws_init(struct amiws_config *conf)
Definition amiws_lib.c:34
void amiws_destroy()
Definition amiws_lib.c:101
void amiws_connect_ami_server(struct amiws_conn *conn)
Definition amiws_lib.c:77
void ami_login(struct mg_connection *nc, struct amiws_conn *conn)
Definition amiws_lib.c:305
void amiws_loop()
Definition amiws_lib.c:108
int scan_amipack(const char *pack, size_t len)
Definition amiws_lib.c:354
char * amipack_to_json(const char *buf, int len, struct amiws_conn *conn)
Definition amiws_lib.c:169
void free_conf(struct amiws_config *conf)
Definition config.c:221
void websock_ev_handler(struct mg_connection *nc, int ev, void *ev_data)
Definition amiws_lib.c:271
Definition amiws.h:87
char * auth_file
Definition amiws.h:96
char * web_root
Definition amiws.h:94
int ws_port
Definition amiws.h:93
int log_facility
Definition amiws.h:91
char * auth_domain
Definition amiws.h:95
int log_level
Definition amiws.h:92
struct amiws_conn * head
Definition amiws.h:88
struct amiws_conn * tail
Definition amiws.h:89
int size
Definition amiws.h:90
Definition amiws.h:111
char * name
Definition amiws.h:113
int id
Definition amiws.h:112
struct amiws_conn * next
Definition amiws.h:125
int is_ssl
Definition amiws.h:124
char * host
Definition amiws.h:116
char * username
Definition amiws.h:117
char * address
Definition amiws.h:114
char * secret
Definition amiws.h:118
unsigned int port
Definition amiws.h:115
AMIVer ami_ver
Definition amiws.h:119