3f0a26a0b0f0950e6236e9d8f753443e4de2510c
[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 #define _GNU_SOURCE
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 #include <termios.h>
31 #include <sys/ioctl.h>
32 #include <sys/signal.h>
33 #include <sys/types.h>
34 #include <time.h>
35 #include <json.h>
36 #include <microhttpd.h>
37 #include <magic.h>
38
39 #define AJQ_VERSION "0.1"
40
41 /* other definitions --------------------------------------------------- */
42
43 typedef int BOOL;
44 #ifndef FALSE
45   #define FALSE 0
46 #endif
47 #ifndef TRUE
48   #define TRUE 1
49 #endif
50
51 #define PUBLIC
52 #define STATIC    static
53 #define FAILED    -1
54
55 // prebuild json error are constructed in config.c
56 typedef enum  { AFB_FALSE, AFB_TRUE, AFB_FATAL, AFB_FAIL, AFB_WARNING, AFB_EMPTY, AFB_SUCCESS} AFB_error;
57
58 extern char *ERROR_LABEL[];
59 #define ERROR_LABEL_DEF {"false", "true","fatal", "fail", "warning", "empty", "success"}
60
61 #define BANNER "<html><head><title>Application Framework Binder</title></head><body>Application Framework </body></html>"
62 #define JSON_CONTENT  "application/json"
63 #define MAX_POST_SIZE  4096   // maximum size for POST data
64
65 // use to check anonymous data when using dynamic loadable lib
66 typedef enum  {AFB_PLUGIN=1234, AFB_REQUEST=5678} AFB_type;
67
68 // Error code are requested through function to manage json usage count
69 typedef struct {
70   int   level;
71   char* label;
72   json_object *json;
73 } AFB_errorT;
74
75 // Post handler
76 typedef struct {
77   char* data;
78   int   len;
79   int   uid;
80 } AFB_HttpPost;
81
82 typedef struct {
83   char  path[512];
84   int   fd;
85 } AFB_staticfile;
86
87
88 // some usefull static object initialized when entering listen loop.
89 extern int verbose;
90 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
91 typedef struct {
92   const char *url;
93   char *plugin;
94   char *api;
95   char *post;
96   struct MHD_Connection *connection;
97 } AFB_request;
98
99 typedef struct {
100      char *msg;
101      int  len;
102 } AFB_redirect_msg;
103
104 // main config structure
105 typedef struct {
106   char *logname;           // logfile path for info & error log
107   char *console;           // console device name (can be a file or a tty)
108   int  localhostOnly;
109   int   httpdPort;
110   char *smack;             // smack label
111   char *plugins;           // list of requested plugins
112   char *rootdir;           // base dir for httpd file download
113   char *rootbase;          // Angular HTML5 base URL
114   char *rootapi;           // Base URL for REST APIs
115   char *pidfile;           // where to store pid when running background
116   char *sessiondir;        // where to store mixer session files
117   char *configfile;        // where to store configuration on gateway exit
118   uid_t setuid;
119   int  cacheTimeout;
120 } AFB_config;
121
122 // Command line structure hold cli --command + help text
123 typedef struct {
124   int  val;        // command number within application
125   int  has_arg;    // command number within application
126   char *name;      // command as used in --xxxx cli
127   char *help;      // help text
128 } AFB_options;
129
130 typedef json_object* (*AFB_apiCB)();
131
132 // API definition
133 typedef struct {
134   char *name;
135   AFB_apiCB callback;
136   char *info;
137 } AFB_restapi;
138
139 // Plugin definition
140 typedef struct {
141   AFB_type type;  
142   char *info;
143   char *prefix;
144   size_t prefixlen;
145   json_object *jtype;
146   AFB_restapi *apis;
147 } AFB_plugin;
148
149 typedef struct {
150   AFB_config  *config;   // pointer to current config
151   // List of commands to execute
152   int  killPrevious;
153   int  background;        // run in backround mode
154   int  foreground;        // run in forground mode
155   int  checkAlsa;         // Display active Alsa Board
156   int  configsave;        // Save config on disk on start
157   char *cacheTimeout;     // http require timeout to be a string
158   void *httpd;            // anonymous structure for httpd handler
159   int  fakemod;           // respond to GET/POST request without interacting with sndboard
160   int  forceexit;         // when autoconfig from script force exit before starting server
161   AFB_plugin **plugins;   // pointer to REST/API plugins 
162   magic_t  magic;         // Mime type file magic lib
163 } AFB_session;
164
165
166 #include "proto-def.h"