changed to new try (mongoose)
This commit is contained in:
parent
3281cb1b6e
commit
66e45594ce
|
@ -0,0 +1,3 @@
|
|||
[submodule "mongoose"]
|
||||
path = mongoose
|
||||
url = git@github.com:cesanta/mongoose.git
|
|
@ -3,11 +3,13 @@
|
|||
## to provide a way for the user to supply additional arguments.
|
||||
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
|
||||
|
||||
AM_CXXFLAGS = -std=c++11
|
||||
bin_PROGRAMS=siccc
|
||||
|
||||
siccc_SOURCES = src/options.c src/sicmain.cc
|
||||
siccc_SOURCES = src/options.c src/sicmain.cc mongoose/mongoose.c
|
||||
siccc_CFLAGS =
|
||||
siccc_LDADD =
|
||||
sicc_CXXFLAGS = -ggdb -I ../mongoose/mongoose.c
|
||||
siccc_LDFLAGS = -ldl -pthread
|
||||
|
||||
options.c: options.ggo
|
||||
options.h: options.ggo
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 03d846529d4baf96675858849000219dae91c072
|
|
@ -1,20 +1,23 @@
|
|||
package "<packname>"
|
||||
version "<version>"
|
||||
package "siccc"
|
||||
version "0"
|
||||
|
||||
|
||||
purpose "This is our port of the famous „sharingg is carin“ application by Astro of C3D2: Instant filesharing made simple for $HOME networks. The Port to C++ is meant as a C++ training and to allow SIC to be deployed to small and embedded plattforms"
|
||||
|
||||
args "-C -a sic_conf -f cmd_parser"
|
||||
args "-C -a sic_conf -f cmd_parser --default-optional"
|
||||
|
||||
|
||||
option "listen" l "Specifies the adress to bind to" default="::1" string required multiple
|
||||
option "port" p "The portnumber listened to" default="12380" int
|
||||
option "listen" l "Specifies the adress to bind to" string multiple default="::1"
|
||||
option "port" p "The portnumber listened to" default="12380" int optional
|
||||
|
||||
option "saveconf" s "Save the actual configuration to a file" flag off
|
||||
|
||||
option "conffile" f "The Configurationfile to use" string default="/etc/triggerd.conf"
|
||||
option "conffile" c "The Configurationfile to use" string default="./siccc.conf"
|
||||
|
||||
option "verbose" v "increas the verbosity" flag off
|
||||
|
||||
option "daemonize" D "Detach from calling terminal" flag off
|
||||
|
||||
option "dns" d "also start an dns fakeserver"
|
||||
|
||||
option "filedir" f "Directory for data storage. Musst be r/w able" string default="./files/"
|
||||
|
|
|
@ -1,16 +1,101 @@
|
|||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
#include "options.h"
|
||||
|
||||
//globally accessible config
|
||||
static struct sic_conf args_info;
|
||||
|
||||
using std::cout;
|
||||
|
||||
static int event_handler(struct mg_event *event) {
|
||||
|
||||
if (event->type == MG_REQUEST_BEGIN) {
|
||||
if (!strcmp(
|
||||
event->request_info->uri,
|
||||
"/handle_post_request")) {
|
||||
char path[200];
|
||||
FILE *fp = mg_upload(event->conn,
|
||||
"/tmp",
|
||||
path,
|
||||
sizeof(path));
|
||||
if (fp != NULL) {
|
||||
fclose(fp);
|
||||
mg_printf(event->conn,
|
||||
"HTTP/1.0 200 OK\r\n\r\nSaved: [%s]",
|
||||
path);
|
||||
} else {
|
||||
mg_printf(event->conn,"%s",
|
||||
"HTTP/1.0 200 OK\r\n\r\nNo files sent");
|
||||
}
|
||||
} else {
|
||||
// Show HTML form. Make sure it has enctype="multipart/form-data" attr.
|
||||
static const char *html_form =
|
||||
"<html><body>Upload example."
|
||||
"<form method=\"POST\" action=\"/handle_post_request\" "
|
||||
" enctype=\"multipart/form-data\">"
|
||||
"<input type=\"file\" name=\"file\" /> <br/>"
|
||||
"<input type=\"submit\" value=\"Upload\" />"
|
||||
"</form></body></html>";
|
||||
|
||||
mg_printf(event->conn, "HTTP/1.0 200 OK\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
"Content-Type: text/html\r\n\r\n%s",
|
||||
(int) strlen(html_form), html_form);
|
||||
}
|
||||
|
||||
// Mark request as processed
|
||||
return 1;
|
||||
}
|
||||
|
||||
// All other events left unprocessed
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
class MongooseHandler{
|
||||
private:
|
||||
struct mg_context *ctx;
|
||||
//const char *options[];
|
||||
unsigned short listenport;
|
||||
|
||||
// = {"listening_ports", "8080", NULL};
|
||||
|
||||
public:
|
||||
|
||||
//default listenport:8080
|
||||
MongooseHandler(int listenport=8080):
|
||||
ctx(nullptr),
|
||||
listenport(listenport)
|
||||
{
|
||||
char portstring[8];
|
||||
std::snprintf(portstring,8,"%d",this->listenport);
|
||||
const char *options[] =
|
||||
{"listening_ports",portstring,nullptr};
|
||||
this->ctx= mg_start(options, &event_handler,nullptr);
|
||||
}
|
||||
|
||||
//no copy constructor:
|
||||
MongooseHandler( const MongooseHandler &) = delete;
|
||||
|
||||
//destructor stops the server
|
||||
~MongooseHandler(){
|
||||
if (this->ctx){
|
||||
mg_stop(this->ctx);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int result = 0;
|
||||
MongooseHandler m;
|
||||
|
||||
struct cmd_parser_params *params;
|
||||
|
||||
|
@ -52,14 +137,19 @@ int main(int argc, char **argv)
|
|||
args_info.listen_arg[i] <<std::endl;
|
||||
|
||||
if (args_info.saveconf_given) {
|
||||
if (cmd_parser_file_save
|
||||
(args_info.conffile_arg, &args_info) == EXIT_FAILURE)
|
||||
if (cmd_parser_file_save(args_info.conffile_arg,
|
||||
&args_info) == EXIT_FAILURE)
|
||||
result = 1;
|
||||
else
|
||||
cout << "saved configuration file "<<
|
||||
args_info.conffile_arg <<
|
||||
", \n" << std::endl;
|
||||
}
|
||||
m = MongooseHandler(args_info.port_arg);
|
||||
if (!args_info.daemonize_flag) {
|
||||
while(1)
|
||||
getchar();
|
||||
}
|
||||
|
||||
stop:
|
||||
//deallocate structures
|
||||
|
|
Loading…
Reference in New Issue