Add CMake build files (required by Yocto build process)
[src/app-framework-binder.git] / include / local-def.h
1 /*
2    alsajson-gw -- provide a REST/HTTP interface to ALSA-Mixer
3
4    Copyright (C) 2015, Fulup Ar Foll
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22 #ifndef _GNU_SOURCE
23   #define _GNU_SOURCE
24 #endif
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #include <termios.h>
33 #include <sys/ioctl.h>
34 #include <sys/signal.h>
35 #include <sys/types.h>
36 #include <time.h>
37 #include <json.h>
38 #include <microhttpd.h>
39 #include <magic.h>
40 #include <setjmp.h>
41 #include <signal.h>
42
43
44
45 #define AJQ_VERSION "0.1"
46
47 /* other definitions --------------------------------------------------- */
48
49 // Note: because of a bug in libmagic MAGIC_DB NULL should not be used for default
50 #define MAGIC_DB "/usr/share/misc/magic.mgc"
51 #define OPA_INDEX "index.html"
52 #define MAX_ALIAS 10  // max number of aliases
53
54 typedef int BOOL;
55 #ifndef FALSE
56   #define FALSE 0
57 #endif
58 #ifndef TRUE
59   #define TRUE 1
60 #endif
61
62 #define PUBLIC
63 #define STATIC    static
64 #define FAILED    -1
65
66 // prebuild json error are constructed in config.c
67 typedef enum  { AFB_FALSE, AFB_TRUE, AFB_FATAL, AFB_FAIL, AFB_WARNING, AFB_EMPTY, AFB_SUCCESS} AFB_error;
68
69 extern char *ERROR_LABEL[];
70 #define ERROR_LABEL_DEF {"false", "true","fatal", "fail", "warning", "empty", "success"}
71
72 #define BANNER "<html><head><title>Application Framework Binder</title></head><body>Application Framework </body></html>"
73 #define JSON_CONTENT  "application/json"
74 #define MAX_POST_SIZE  4096   // maximum size for POST data
75
76 // use to check anonymous data when using dynamic loadable lib
77 typedef enum  {AFB_PLUGIN=1234, AFB_REQUEST=5678} AFB_type;
78
79 // Error code are requested through function to manage json usage count
80 typedef struct {
81   int   level;
82   char* label;
83   json_object *json;
84 } AFB_errorT;
85
86 // Post handler
87 typedef struct {
88   char* data;
89   int   len;
90   int   uid;
91 } AFB_HttpPost;
92
93 typedef struct {
94   char  path[512];
95   int   fd;
96 } AFB_staticfile;
97
98 typedef struct {
99   char  *url;
100   char  *path;
101   size_t len;
102 } AFB_aliasdir;
103
104
105 // some usefull static object initialized when entering listen loop.
106 extern int verbose;
107 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
108 typedef struct {
109   const char *url;
110   char *plugin;
111   char *api;
112   char *post;
113   struct MHD_Connection *connection;
114   sigjmp_buf checkPluginCall; // context save for timeout set/longjmp
115 } AFB_request;
116
117 typedef struct {
118      char    *msg;
119      size_t  len;
120 } AFB_redirect_msg;
121
122 // main config structure
123 typedef struct {
124   char *logname;           // logfile path for info & error log
125   char *console;           // console device name (can be a file or a tty)
126   int  localhostOnly;
127   int   httpdPort;
128   char *smack;             // smack label
129   char *plugins;           // list of requested plugins
130   char *rootdir;           // base dir for httpd file download
131   char *rootbase;          // Angular HTML5 base URL
132   char *rootapi;           // Base URL for REST APIs
133   char *pidfile;           // where to store pid when running background
134   char *sessiondir;        // where to store mixer session files
135   char *configfile;        // where to store configuration on gateway exit
136   uid_t setuid;
137   int  cacheTimeout;
138   int  apiTimeout;
139   AFB_aliasdir *aliasdir;  // alias mapping for icons,apps,...
140 } AFB_config;
141
142 // Command line structure hold cli --command + help text
143 typedef struct {
144   int  val;        // command number within application
145   int  has_arg;    // command number within application
146   char *name;      // command as used in --xxxx cli
147   char *help;      // help text
148 } AFB_options;
149
150 typedef json_object* (*AFB_apiCB)();
151
152 // API definition
153 typedef struct {
154   char *name;
155   AFB_apiCB callback;
156   char *info;
157   void * handle;
158 } AFB_restapi;
159
160 // Plugin definition
161 typedef struct {
162   AFB_type type;  
163   char *info;
164   char *prefix;
165   size_t prefixlen;
166   json_object *jtype;
167   AFB_restapi *apis;
168 } AFB_plugin;
169
170 typedef struct {
171   AFB_config  *config;   // pointer to current config
172   // List of commands to execute
173   int  killPrevious;
174   int  background;        // run in backround mode
175   int  foreground;        // run in forground mode
176   int  checkAlsa;         // Display active Alsa Board
177   int  configsave;        // Save config on disk on start
178   char *cacheTimeout;     // http require timeout to be a string
179   void *httpd;            // anonymous structure for httpd handler
180   int  fakemod;           // respond to GET/POST request without interacting with sndboard
181   int  forceexit;         // when autoconfig from script force exit before starting server
182   AFB_plugin **plugins;   // pointer to REST/API plugins 
183   magic_t  magic;         // Mime type file magic lib
184   sigjmp_buf restartCkpt; // context save for restart set/longjmp
185 } AFB_session;
186
187
188 #include "proto-def.h"