My initial commit message
[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    $Id: $
21 */
22
23 #define _GNU_SOURCE
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <errno.h>
31 #include <termios.h>
32 #include <sys/ioctl.h>
33 #include <sys/signal.h>
34 #include <sys/types.h>
35 #include <time.h>
36 #include <json.h>
37 #include <microhttpd.h>
38
39
40 #define AJQ_VERSION "0.1"
41
42 /* other definitions --------------------------------------------------- */
43
44 typedef int BOOL;
45 #ifndef FALSE
46   #define FALSE 0
47 #endif
48 #ifndef TRUE
49   #define TRUE 1
50 #endif
51
52 #define PUBLIC
53 #define STATIC    static
54 #define FAILED    -1
55
56 // prebuild json error are constructed in config.c
57 typedef enum  { AFB_FALSE, AFB_TRUE, AFB_FATAL, AFB_FAIL, AFB_WARNING, AFB_EMPTY, AFB_SUCCESS} AFB_ERROR;
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
83 // some usefull static object initialized when entering listen loop.
84 extern int verbose;
85 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
86 typedef struct {
87   const char *url;
88   char *plugin;
89   char *api;
90   char *post;
91   struct MHD_Connection *connection;
92 } AFB_request;
93
94 typedef struct {
95      char *msg;
96      int  len;
97 } AFB_redirect_msg;
98
99 // main config structure
100 typedef struct {
101   char *logname;           // logfile path for info & error log
102   char *console;           // console device name (can be a file or a tty)
103   int  localhostOnly;
104   int   httpdPort;
105   char *smack;             // smack label
106   char *plugins;           // list of requested plugins
107   char *rootdir;           // base dir for httpd file download
108   char *rootbase;          // Angular HTML5 base URL
109   char *rootapi;           // Base URL for REST APIs
110   char *pidfile;           // where to store pid when running background
111   char *sessiondir;        // where to store mixer session files
112   char *configfile;        // where to store configuration on gateway exit
113   uid_t setuid;
114   int  cacheTimeout;
115   AFB_redirect_msg html5;  // html5 redirect message
116 } AFB_config;
117
118 // Command line structure hold cli --command + help text
119 typedef struct {
120   int  val;        // command number within application
121   int  has_arg;    // command number within application
122   char *name;      // command as used in --xxxx cli
123   char *help;      // help text
124 } AFB_options;
125
126 typedef json_object* (*AFB_apiCB)();
127
128 // API definition
129 typedef struct {
130   char *name;
131   AFB_apiCB callback;
132   char *info;
133 } AFB_restapi;
134
135 // Plugin definition
136 typedef struct {
137   AFB_type type;  
138   char *info;
139   char *prefix;
140   json_object *jtype;
141   AFB_restapi *apis;
142 } AFB_plugin;
143
144 typedef struct {
145   AFB_config  *config;   // pointer to current config
146   // List of commands to execute
147   int  killPrevious;
148   int  background;        // run in backround mode
149   int  foreground;        // run in forground mode
150   int  checkAlsa;         // Display active Alsa Board
151   int  configsave;        // Save config on disk on start
152   char *cacheTimeout;     // http require timeout to be a string
153   void *httpd;            // anonymous structure for httpd handler
154   int  fakemod;           // respond to GET/POST request without interacting with sndboard
155   int  forceexit;         // when autoconfig from script force exit before starting server
156   AFB_plugin **plugins;   // pointer to REST/API plugins 
157 } AFB_session;
158
159
160 #include "proto-def.h"