mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 15:28:28 -05:00
added command line parameters for webui port and base directory.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8069 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
21575dd416
commit
0cd3f3868e
@ -80,7 +80,7 @@ public:
|
||||
if(strcmp(method, "POST") == 0)
|
||||
{
|
||||
mState = WAITING_DATA;
|
||||
// first time there is no data, do nohtin and return
|
||||
// first time there is no data, do nothing and return
|
||||
return MHD_YES;
|
||||
}
|
||||
}
|
||||
@ -223,7 +223,11 @@ ApiServerMHD::ApiServerMHD(std::string root_dir, uint16_t port):
|
||||
mRootDir(root_dir), mPort(port),
|
||||
mDaemon(0)
|
||||
{
|
||||
|
||||
// make sure the docroot dir ends with a slash
|
||||
if(mRootDir.empty())
|
||||
mRootDir = "./";
|
||||
else if (mRootDir[mRootDir.size()-1] != '/' && mRootDir[mRootDir.size()-1] != '\\')
|
||||
mRootDir += "/";
|
||||
}
|
||||
|
||||
ApiServerMHD::~ApiServerMHD()
|
||||
@ -245,7 +249,7 @@ bool ApiServerMHD::start()
|
||||
MHD_OPTION_END);
|
||||
if(mDaemon)
|
||||
{
|
||||
std::cerr << "ApiServerMHD::start() SUCCESS. Started server on port " << mPort << ". mRootDir=\"" << mRootDir << "\"" << std::endl;
|
||||
std::cerr << "ApiServerMHD::start() SUCCESS. Started server on port " << mPort << ". Serving files from \"" << mRootDir << "\" at /" << std::endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -348,7 +352,7 @@ int ApiServerMHD::accessHandlerCallback(MHD_Connection *connection,
|
||||
}
|
||||
|
||||
// else server static files
|
||||
std::string filename = std::string(".") + url;
|
||||
std::string filename = mRootDir + url;
|
||||
// important: binary open mode,
|
||||
// else libmicrohttpd will replace crlf with lf and add garbage at the end of the file
|
||||
FILE* fd = fopen(filename.c_str(), "rb");
|
||||
|
@ -116,7 +116,7 @@ namespace
|
||||
const char* desc="",
|
||||
bool mandatory = true)
|
||||
{
|
||||
return ValueHolder<T>(l,b,desc,mandatory);
|
||||
return ValueHolder<T>(l,b,valueName,desc,mandatory);
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Interface of OptionHolder
|
||||
|
@ -74,29 +74,36 @@ int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef ENABLE_WEBUI
|
||||
|
||||
std::string docroot;
|
||||
bool is_portable = false;
|
||||
#ifdef WINDOWS_SYS
|
||||
// test for portable version
|
||||
if (GetFileAttributes(L"portable") != (DWORD) -1) {
|
||||
is_portable = true;
|
||||
}
|
||||
#endif
|
||||
std::string docroot = "./";
|
||||
uint16_t httpPort = 0;
|
||||
|
||||
resource_api::ApiServerMHD httpd(docroot, 9090);
|
||||
argstream args(argc, argv);
|
||||
args >> parameter("webinterface", httpPort, "port", "Enable webinterface on the specified port", false);
|
||||
args >> parameter("docroot", docroot, "path", "Serve static files from this path.", false);
|
||||
args >> help();
|
||||
|
||||
resource_api::RsControlModule ctrl_mod(argc, argv, httpd.getApiServer().getStateTokenServer(), &httpd.getApiServer());
|
||||
httpd.getApiServer().addResourceHandler("control", dynamic_cast<resource_api::ResourceRouter*>(&ctrl_mod), &resource_api::RsControlModule::handleRequest);
|
||||
|
||||
httpd.start();
|
||||
|
||||
while(ctrl_mod.processShouldExit() == false)
|
||||
if (args.helpRequested())
|
||||
{
|
||||
usleep(20*1000);
|
||||
std::cerr << args.usage() << std::endl;
|
||||
}
|
||||
httpd.stop();
|
||||
|
||||
return 1;
|
||||
if(httpPort != 0)
|
||||
{
|
||||
resource_api::ApiServerMHD httpd(docroot, httpPort);
|
||||
|
||||
resource_api::RsControlModule ctrl_mod(argc, argv, httpd.getApiServer().getStateTokenServer(), &httpd.getApiServer());
|
||||
httpd.getApiServer().addResourceHandler("control", dynamic_cast<resource_api::ResourceRouter*>(&ctrl_mod), &resource_api::RsControlModule::handleRequest);
|
||||
|
||||
httpd.start();
|
||||
|
||||
while(ctrl_mod.processShouldExit() == false)
|
||||
{
|
||||
usleep(20*1000);
|
||||
}
|
||||
httpd.stop();
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Retroshare startup is configured using an RsInit object.
|
||||
|
Loading…
x
Reference in New Issue
Block a user