rest-api: add config dir parametrable.
This commit is contained in:
@@ -59,8 +59,6 @@ extern "C" {
|
||||
|
||||
/*------------------------------- GLOBALS ----------------------------------*/
|
||||
|
||||
#define kConfigDirectory "/usr/local/configs/restd/"
|
||||
|
||||
#define kControllerKey "controller"
|
||||
#define kEtagControllerKey "etag_controller"
|
||||
|
||||
@@ -133,9 +131,9 @@ extern "C" struct ubus_context *get_uhttp_server_ctx(void)
|
||||
*
|
||||
* @brief init method from c plugin to uhttp server.
|
||||
*/
|
||||
extern "C" int uhttp_server_setup(struct ubus_context *a_ctx, const struct uhttpd_ops *an_ops)
|
||||
extern "C" int uhttp_server_setup(struct ubus_context *a_ctx, const struct uhttpd_ops *an_ops, const char *a_config_dir_path)
|
||||
{
|
||||
return UhttpServer::get_instance().setup(a_ctx, an_ops);
|
||||
return UhttpServer::get_instance().setup(a_ctx, an_ops, a_config_dir_path);
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -262,12 +260,12 @@ UhttpServer::~UhttpServer(void)
|
||||
*
|
||||
* @brief setup the http server.
|
||||
*/
|
||||
int UhttpServer::setup(struct ubus_context *a_ctx, const struct uhttpd_ops *an_ops)
|
||||
int UhttpServer::setup(struct ubus_context *a_ctx, const struct uhttpd_ops *an_ops, const char *a_config_dir_path)
|
||||
{
|
||||
m_ctx = a_ctx;
|
||||
m_ops = const_cast<struct uhttpd_ops *>(an_ops);
|
||||
|
||||
return load_config_dir();
|
||||
return load_config_dir(a_config_dir_path);
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -419,20 +417,23 @@ int UhttpServer::data_send(struct client *a_client, const char *a_data, int a_le
|
||||
*
|
||||
* @brief Load config from the configuration directory
|
||||
*/
|
||||
int UhttpServer::load_config_dir(void)
|
||||
int UhttpServer::load_config_dir(const char *a_config_dir_path)
|
||||
{
|
||||
DIR *the_rep = NULL;
|
||||
struct dirent *the_dir_ent = NULL;
|
||||
std::string the_path;
|
||||
struct json_object *the_root_node;
|
||||
the_rep = opendir(kConfigDirectory);
|
||||
|
||||
the_rep = opendir(a_config_dir_path);
|
||||
if (the_rep == NULL) {
|
||||
fprintf (stderr, "Impossible to open the config directory. check your parameters.\n");
|
||||
return -1;
|
||||
}
|
||||
while ((the_dir_ent = readdir(the_rep)) != NULL)
|
||||
{
|
||||
if (strcmp(the_dir_ent->d_name, ".") != 0 && strcmp(the_dir_ent->d_name, "..") != 0)
|
||||
{
|
||||
// printf ("load: %s\n", the_dir_ent->d_name);
|
||||
the_path = kConfigDirectory;
|
||||
the_path = a_config_dir_path;
|
||||
the_path += the_dir_ent->d_name;
|
||||
|
||||
the_root_node = load(the_path);
|
||||
|
||||
Reference in New Issue
Block a user