2 local-def.h -- provide a REST/HTTP interface
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.
26 #include <microhttpd.h>
28 /* other definitions --------------------------------------------------- */
30 // Note: because of a bug in libmagic MAGIC_DB NULL should not be used for default
31 #define OPA_INDEX "index.html"
32 #define MAX_ALIAS 10 // max number of aliases
33 #define COOKIE_NAME "afb-session"
35 #define DEFLT_CNTX_TIMEOUT 3600 // default Client Connection Timeout
36 #define DEFLT_API_TIMEOUT 0 // default Plugin API Timeout [0=NoLimit for Debug Only]
37 #define DEFLT_API_TIMEOUT 0 // default Plugin API Timeout
38 #define DEFLT_CACHE_TIMEOUT 100000 // default Static File Chache [Client Side Cache 100000~=1day]
39 #define DEFLT_AUTH_TOKEN NULL // expect for debug should == NULL
40 #define DEFLT_HTTP_TIMEOUT 15 // Max MibMicroHttp timeout
41 #define AFB_MAX_PLUGINS 20 // Max number of plugins for a given binder
54 #define AUDIO_BUFFER "/tmp/buf"
56 extern int verbose; // this is the only global variable
58 // prebuild json error are constructed in helper-api.c
59 typedef enum { AFB_FALSE, AFB_TRUE, AFB_FATAL, AFB_FAIL, AFB_WARNING, AFB_EMPTY, AFB_SUCCESS, AFB_DONE, AFB_UNAUTH} AFB_error;
61 #define MAX_POST_SIZE 4096 // maximum size for POST data
62 #define CTX_NBCLIENTS 10 // allow a default of 10 authenticated clients
74 AFB_PLUGIN_JSON = 123456789,
75 AFB_PLUGIN_JSCRIPT = 987654321,
76 AFB_PLUGIN_RAW = 987123546
79 // Enum for Session/Token/Authentication middleware
93 enum AFB_sessionE session;
94 struct json_object* (*callback)();
101 enum AFB_pluginE type;
104 const struct AFB_restapi *apis;
105 void (*freeCtxCB)(void*); // callback to free application context [null for standard free]
108 typedef enum AFB_pluginE AFB_pluginE;
109 typedef enum AFB_sessionE AFB_sessionE;
110 typedef struct json_object* (*AFB_apiCB)();
111 typedef void (*AFB_freeCtxCB)(void*);
112 typedef struct AFB_restapi AFB_restapi;
113 typedef struct AFB_plugin AFB_plugin;
124 typedef enum {AFB_MODE_LOCAL=0, AFB_MODE_REMOTE, AFB_MODE_GLOBAL} AFB_Mode;
129 typedef enum {AFB_POST_NONE=0, AFB_POST_JSON, AFB_POST_FORM, AFB_POST_EMPTY} AFB_PostType;
133 // Post Upload File Handle
138 struct json_object* jresp;
142 int len; // post element size
143 char *data; // post data in raw format
144 AFB_PostType type; // Json type
149 void* ctx; // Application context
150 int len; // current len for post
151 int uid; // post uid for debug
152 AFB_PostType type; // JSON or FORM
153 AFB_apiCB completeCB; // callback when post is completed
154 char *privatebuf; // use internally to keep track or partial buffer
155 struct MHD_PostProcessor *pp; // iterator handle
159 enum MHD_ValueKind kind; // kind type of the value
160 const char *key; // key 0-terminated key for the value
161 const char *filename; // filename of the uploaded file, NULL if not known
162 const char *mimetype; // content_type mime-type of the data, NULL if not known
163 const char *encoding; // transfer_encoding encoding of the data, NULL if not known
164 const char *data; // data pointer to size bytes of data at the specified offset
165 uint64_t offset; // offset of data in the overall value
166 size_t len; // number of bytes in data available
187 // main config structure
190 char *console; // console device name (can be a file or a tty)
192 char *ldpaths; // list of plugins directories
193 char *rootdir; // base dir for httpd file download
194 char *rootbase; // Angular HTML5 base URL
195 char *rootapi; // Base URL for REST APIs
196 char *sessiondir; // where to store mixer session files
197 char *token; // initial authentication token [default NULL no session]
200 int cntxTimeout; // Client Session Context timeout
201 AFB_Mode mode; // mode of listening
202 AFB_aliasdir *aliasdir; // alias mapping for icons,apps,...
205 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
209 const char *prefix; // plugin convivial name
212 AFB_PostRequest *post;
214 struct json_object *jresp;
215 void *context; // Hold Client Context when using session
216 int restfull; // request is resfull [uuid token provided]
217 int errcode; // http error code
218 struct AFB_config *config; // plugin may need access to config
219 struct afb_req *areq;
222 struct afb_hsrv_handler;
227 struct AFB_config *config; // pointer to current config
228 // List of commands to execute
229 int background; // run in backround mode
230 int foreground; // run in forground mode
231 char *cacheTimeout; // http require timeout to be a string
232 struct MHD_Daemon *httpd; // structure for httpd handler
233 int fakemod; // respond to GET/POST request without interacting with sndboard
234 int readyfd; // a #fd to signal when ready to serve
235 magic_t magic; // Mime type file magic lib
236 struct afb_hsrv_handler *handlers;
240 typedef struct AFB_config AFB_config;
241 typedef struct AFB_session AFB_session;
243 #include "proto-def.h"
245 #endif /* LOCAL_DEF_H */