39ae3181f2f5e59818bbb6eda8f1765aec214fcd
[src/app-framework-binder.git] / src / local-def.h
1 /*
2    local-def.h -- provide a REST/HTTP interface
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 #ifndef LOCAL_DEF_H
22 #define LOCAL_DEF_H
23
24 #include <json.h>
25 #include <magic.h>
26 #include <microhttpd.h>
27
28 /* other definitions --------------------------------------------------- */
29
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"
34
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
42
43 #ifndef FALSE
44   #define FALSE 0
45 #endif
46 #ifndef TRUE
47   #define TRUE 1
48 #endif
49
50 #define PUBLIC
51 #define STATIC    static
52 #define FAILED    -1
53
54 #define AUDIO_BUFFER "/tmp/buf"
55
56 extern int verbose;  // this is the only global variable
57
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;
60
61 #define MAX_POST_SIZE  4096   // maximum size for POST data
62 #define CTX_NBCLIENTS   10   // allow a default of 10 authenticated clients
63
64
65
66
67
68
69
70
71
72
73 enum AFB_Mode;
74
75
76 typedef struct {
77   char  *url;
78   char  *path;
79   size_t len;
80 } AFB_aliasdir;
81
82 // main config structure
83 struct AFB_config
84 {
85   char *console;           // console device name (can be a file or a tty)
86   int   httpdPort;
87   char *ldpaths;           // list of plugins directories
88   char *rootdir;           // base dir for httpd file download
89   char *rootbase;          // Angular HTML5 base URL
90   char *rootapi;           // Base URL for REST APIs
91   char *sessiondir;        // where to store mixer session files
92   char *token;             // initial authentication token [default NULL no session]
93   int  cacheTimeout;
94   int  apiTimeout;
95   int  cntxTimeout;        // Client Session Context timeout
96   int mode;           // mode of listening
97   AFB_aliasdir *aliasdir;  // alias mapping for icons,apps,...
98 };
99
100 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
101 typedef struct {
102   const char *uuid;
103   const char *url;
104   const char *prefix;              // plugin convivial name
105   const char *method;
106 /*
107   AFB_PostRequest *post;
108 */
109   struct json_object *jresp;
110   void *context;             // Hold Client Context when using session
111   int  restfull;             // request is resfull [uuid token provided]
112   int  errcode;              // http error code
113   struct AFB_config *config;         // plugin may need access to config
114   struct afb_req *areq;
115 } AFB_request;
116
117 struct afb_hsrv_handler;
118 struct MHD_Daemon;
119
120 struct AFB_session
121 {
122   struct AFB_config  *config;   // pointer to current config
123   // List of commands to execute
124   int  background;        // run in backround mode
125   int  foreground;        // run in forground mode
126   char *cacheTimeout;     // http require timeout to be a string
127   struct MHD_Daemon *httpd;            // structure for httpd handler
128   int  fakemod;           // respond to GET/POST request without interacting with sndboard
129   int  readyfd;           // a #fd to signal when ready to serve
130   magic_t  magic;         // Mime type file magic lib
131   struct afb_hsrv_handler *handlers;
132 };
133
134
135 typedef struct AFB_config AFB_config;
136 typedef struct AFB_session AFB_session;
137
138 #include "proto-def.h"
139
140 #endif /* LOCAL_DEF_H */