-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.hh
125 lines (100 loc) · 5.16 KB
/
server.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/************************************************************************
FAUST Architecture File
Copyright (C) 2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
#ifndef _FAUST_SERVER_
#define _FAUST_SERVER_
#include "LRUSessionsCache.hh"
#include "microhttpd.h"
#include "utilities.hh"
// Boost libraries
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#ifndef MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS
#define MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS "Access-Control-Expose-Headers"
#endif
namespace fs = boost::filesystem;
struct connection_info_struct {
int connectiontype; // GET or POST
struct MHD_PostProcessor* postprocessor; // the POST processor used internally by microhttpd
FILE* fp; // a pointer to the file to which the data is being written
string tmppath; // the path in which the provisional file exists
string filename; // the name of the file
string answerstring; // the answer sent to the user after upload
int answercode; // used internally by microhttpd to see where things went wrong or right
string directory; // the path in which the final file exists
string makefile_directory; // the path from which makefiles should be copied
};
struct string_and_exitstatus {
string str;
int exitstatus;
};
class FaustServer {
int fPort;
unsigned int fMaxClients;
fs::path fDirectory;
fs::path fMakefileDirectory;
fs::path fLogfile;
struct MHD_Daemon* fDaemon;
string fTargets;
LRUSessionsCache fSessionCache;
public:
FaustServer(int port, int max_clients, const fs::path& directory, const fs::path& makefile_directory,
const fs::path& logfile, int maxSessions);
virtual ~FaustServer() = default;
;
bool start();
void stop();
unsigned int getMaxClients() const
{
return fMaxClients; ///< Max number of clients allowed to connect at a given time.
}
fs::path getDirectory() const
{
return fDirectory; ///< Directory to which the uploaded files are being written.
}
fs::path getMakefileDirectory() const
{
return fMakefileDirectory; ///< Directory that the makefiles should be copied from.
}
fs::path getLogfile() const
{
return fLogfile; ///< Path to the logfile.
}
private:
static unsigned int nr_of_uploading_clients;
static int get_params(void* cls, enum MHD_ValueKind, const char* key, const char* data);
static int send_page(struct MHD_Connection* connection, const char* page, int length, int status_code,
const char* type, const char* location);
static int send_file(struct MHD_Connection* connection, const fs::path& filepath, const char* mimetype);
static int iterate_post(void* coninfo_cls, enum MHD_ValueKind kind, const char* key, const char* filename,
const char* content_type, const char* transfer_encoding, const char* data, uint64_t off,
size_t size);
static void request_completed(void* cls, struct MHD_Connection* connection, void** con_cls,
enum MHD_RequestTerminationCode toe);
static int staticAnswerToConnection(void* cls, struct MHD_Connection* connection, const char* url,
const char* method, const char* version, const char* upload_data,
size_t* upload_data_size, void** con_cls);
int dispatchGETConnections(struct MHD_Connection* connection, const string& url);
int dispatchPOSTConnections(struct MHD_Connection* connection, const string& url, const char* upload_data,
size_t* upload_data_size, void** con_cls);
int makeAndSendResourceFile(struct MHD_Connection* connection, const string& raw_url);
std::string getMakefileArtifactName(const fs::path&);
};
#endif