2 alsajson-gw -- provide a REST/HTTP interface to ALSA-Mixer
4 Copyright (C) 2015, Fulup Ar Foll
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.
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.
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.
33 #include <sys/ioctl.h>
34 #include <sys/signal.h>
35 #include <sys/types.h>
38 #include <microhttpd.h>
45 #define AJQ_VERSION "0.1"
47 /* other definitions --------------------------------------------------- */
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
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_DONE} AFB_error;
69 extern char *ERROR_LABEL[];
70 #define ERROR_LABEL_DEF {"false", "true","fatal", "fail", "warning", "empty", "success"}
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
76 // use to check anonymous data when using dynamic loadable lib
77 typedef enum {AFB_PLUGIN=1234, AFB_REQUEST=5678} AFB_type;
79 // Error code are requested through function to manage json usage count
105 // some usefull static object initialized when entering listen loop.
107 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
114 struct MHD_Connection *connection;
115 sigjmp_buf checkPluginCall; // context save for timeout set/longjmp
123 // main config structure
125 char *logname; // logfile path for info & error log
126 char *console; // console device name (can be a file or a tty)
129 char *smack; // smack label
130 char *plugins; // list of requested plugins
131 char *rootdir; // base dir for httpd file download
132 char *rootbase; // Angular HTML5 base URL
133 char *rootapi; // Base URL for REST APIs
134 char *pidfile; // where to store pid when running background
135 char *sessiondir; // where to store mixer session files
136 char *configfile; // where to store configuration on gateway exit
140 AFB_aliasdir *aliasdir; // alias mapping for icons,apps,...
143 // Command line structure hold cli --command + help text
145 int val; // command number within application
146 int has_arg; // command number within application
147 char *name; // command as used in --xxxx cli
148 char *help; // help text
152 int len; // command number within application
156 typedef json_object* (*AFB_apiCB)();
164 AFB_privateApi *private;
178 AFB_config *config; // pointer to current config
179 // List of commands to execute
181 int background; // run in backround mode
182 int foreground; // run in forground mode
183 int checkAlsa; // Display active Alsa Board
184 int configsave; // Save config on disk on start
185 char *cacheTimeout; // http require timeout to be a string
186 void *httpd; // anonymous structure for httpd handler
187 int fakemod; // respond to GET/POST request without interacting with sndboard
188 int forceexit; // when autoconfig from script force exit before starting server
189 AFB_plugin **plugins; // pointer to REST/API plugins
190 magic_t magic; // Mime type file magic lib
191 sigjmp_buf restartCkpt; // context save for restart set/longjmp
195 #include "proto-def.h"