fix: better logging behaviour
This commit is contained in:
parent
3e6d0333b7
commit
398019afe8
36 changed files with 256 additions and 188 deletions
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project(core
|
project(core
|
||||||
VERSION 0.2.3
|
VERSION 0.2.4
|
||||||
LANGUAGES C)
|
LANGUAGES C)
|
||||||
|
|
||||||
add_executable(core src/main.c)
|
add_executable(core src/main.c)
|
||||||
|
|
1
core.ini
1
core.ini
|
@ -13,3 +13,4 @@ discovery-port = 4421
|
||||||
mqtt-port = 1885
|
mqtt-port = 1885
|
||||||
|
|
||||||
log-level = debug
|
log-level = debug
|
||||||
|
log-file = stdout
|
||||||
|
|
|
@ -12,23 +12,14 @@ typedef enum
|
||||||
RUN_TYPE_INVALID,
|
RUN_TYPE_INVALID,
|
||||||
} run_type_t;
|
} run_type_t;
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LOG_LEVEL_TRACE = 5,
|
|
||||||
LOG_LEVEL_DEBUG = 4,
|
|
||||||
LOG_LEVEL_INFO = 3,
|
|
||||||
LOG_LEVEL_WARN = 2,
|
|
||||||
LOG_LEVEL_ERROR = 1,
|
|
||||||
LOG_LEVEL_FATAL = 0,
|
|
||||||
} log_level_t;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *file;
|
char *file;
|
||||||
char database[256];
|
char database[256];
|
||||||
char user[256];
|
char user[256];
|
||||||
char group[256];
|
char group[256];
|
||||||
log_level_t log_level;
|
int log_level;
|
||||||
|
FILE *log_file;
|
||||||
run_type_t run_type;
|
run_type_t run_type;
|
||||||
uint16_t server_port;
|
uint16_t server_port;
|
||||||
uint16_t discovery_port;
|
uint16_t discovery_port;
|
||||||
|
|
|
@ -3,18 +3,20 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
logger_log(FILE *stream, log_level_t level, const char *filename, int line, const char *func, const char *msg, ...);
|
logger_log(int level, const char *filename, int line, const char *func, const char *msg, ...);
|
||||||
|
|
||||||
#define LOG_TRACE(...) logger_log(stdout, LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
#define LOGGER_DEBUG(...) logger_log(LOG_DEBUG , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_DEBUG(...) logger_log(stdout, LOG_LEVEL_DEBUG, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
#define LOGGER_INFO(...) logger_log(LOG_INFO , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_INFO(...) logger_log(stdout, LOG_LEVEL_INFO , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
#define LOGGER_NOTICE(...) logger_log(LOG_NOTICE , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_WARN(...) logger_log(stdout, LOG_LEVEL_WARN , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
#define LOGGER_WARNING(...) logger_log(LOG_WARNING, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_ERROR(...) logger_log(stderr, LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
#define LOGGER_ERR(...) logger_log(LOG_ERR , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_FATAL(...) logger_log(stderr, LOG_LEVEL_FATAL, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
#define LOGGER_CRIT(...) logger_log(LOG_CRIT , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
|
#define LOGGER_EMERG(...) logger_log(LOG_EMERG , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
|
|
||||||
#endif //CORE_LOGGER_H
|
#endif //CORE_LOGGER_H
|
||||||
|
|
|
@ -15,7 +15,7 @@ command_set_relay_schedule(relay_t *relay)
|
||||||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_ERROR("couldn't find controller\n");
|
LOGGER_ERR("couldn't find controller\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ command_set_relay_schedule(relay_t *relay)
|
||||||
// finish writing
|
// finish writing
|
||||||
if (mpack_writer_destroy(&writer) != mpack_ok)
|
if (mpack_writer_destroy(&writer) != mpack_ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("an error occurred encoding the data");
|
LOGGER_ERR("an error occurred encoding the data");
|
||||||
controller_free(controller);
|
controller_free(controller);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ command_set_controller_name(controller_t *controller)
|
||||||
// finish writing
|
// finish writing
|
||||||
if (mpack_writer_destroy(&writer) != mpack_ok)
|
if (mpack_writer_destroy(&writer) != mpack_ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("an error occurred encoding the data");
|
LOGGER_ERR("an error occurred encoding the data");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ command_set_controller_name(controller_t *controller)
|
||||||
int
|
int
|
||||||
command_send(controller_t *controller, int command_code, char *payload, uint32_t payload_size)
|
command_send(controller_t *controller, int command_code, char *payload, uint32_t payload_size)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("commanding %d\n", command_code);
|
LOGGER_DEBUG("commanding %d\n", command_code);
|
||||||
|
|
||||||
int bytes_transferred;
|
int bytes_transferred;
|
||||||
|
|
||||||
|
@ -121,18 +121,18 @@ command_send(controller_t *controller, int command_code, char *payload, uint32_t
|
||||||
|
|
||||||
if(fd_controller == -1)
|
if(fd_controller == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("can't open command socket %s:%d\n", controller->ip, controller->port);
|
LOGGER_ERR("can't open command socket %s:%d\n", controller->ip, controller->port);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((bytes_transferred = send(fd_controller, &payload_size, sizeof(payload_size), 0)) <= 0)
|
if((bytes_transferred = send(fd_controller, &payload_size, sizeof(payload_size), 0)) <= 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error during sending size\n");
|
LOGGER_ERR("error during sending size\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if((bytes_transferred = send(fd_controller, payload, payload_size, 0)) <= 0)
|
if((bytes_transferred = send(fd_controller, payload, payload_size, 0)) <= 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error during sending\n");
|
LOGGER_ERR("error during sending\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ command_pulse(relay_t *relay, uint8_t duration)
|
||||||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_ERROR("couldn't find controller\n");
|
LOGGER_ERR("couldn't find controller\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ command_pulse(relay_t *relay, uint8_t duration)
|
||||||
// finish writing
|
// finish writing
|
||||||
if (mpack_writer_destroy(&writer) != mpack_ok)
|
if (mpack_writer_destroy(&writer) != mpack_ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("an error occurred encoding the data");
|
LOGGER_ERR("an error occurred encoding the data");
|
||||||
controller_free(controller);
|
controller_free(controller);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
63
src/config.c
63
src/config.c
|
@ -10,40 +10,69 @@ config_t global_config;
|
||||||
(ini_array_match(SECTION, disp->append_to, '.', disp->format) && \
|
(ini_array_match(SECTION, disp->append_to, '.', disp->format) && \
|
||||||
ini_string_match_ii(KEY, disp->data, disp->format))
|
ini_string_match_ii(KEY, disp->data, disp->format))
|
||||||
|
|
||||||
int
|
static int
|
||||||
config_load_log_level(IniDispatch *disp, config_t *config)
|
config_load_log_level(IniDispatch *disp, config_t *config)
|
||||||
{
|
{
|
||||||
if(strcasecmp(disp->value, "trace") == 0)
|
|
||||||
{
|
|
||||||
config->log_level = LOG_LEVEL_TRACE;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(strcasecmp(disp->value, "debug") == 0)
|
if(strcasecmp(disp->value, "debug") == 0)
|
||||||
{
|
{
|
||||||
config->log_level = LOG_LEVEL_DEBUG;
|
setlogmask(LOG_UPTO(LOG_DEBUG));
|
||||||
|
config->log_level = LOG_DEBUG;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcasecmp(disp->value, "info") == 0)
|
if(strcasecmp(disp->value, "info") == 0)
|
||||||
{
|
{
|
||||||
config->log_level = LOG_LEVEL_INFO;
|
setlogmask(LOG_UPTO(LOG_INFO));
|
||||||
|
config->log_level = LOG_INFO;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcasecmp(disp->value, "warn") == 0)
|
if(strcasecmp(disp->value, "notice") == 0)
|
||||||
{
|
{
|
||||||
config->log_level = LOG_LEVEL_WARN;
|
setlogmask(LOG_UPTO(LOG_NOTICE));
|
||||||
|
config->log_level = LOG_NOTICE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcasecmp(disp->value, "error") == 0)
|
if(strcasecmp(disp->value, "warning") == 0)
|
||||||
{
|
{
|
||||||
config->log_level = LOG_LEVEL_ERROR;
|
setlogmask(LOG_UPTO(LOG_WARNING));
|
||||||
|
config->log_level = LOG_WARNING;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcasecmp(disp->value, "fatal") == 0)
|
if(strcasecmp(disp->value, "err") == 0)
|
||||||
{
|
{
|
||||||
config->log_level = LOG_LEVEL_FATAL;
|
setlogmask(LOG_UPTO(LOG_ERR));
|
||||||
|
config->log_level = LOG_ERR;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG_WARN("invalid log-level '%s'\n", disp->value);
|
if(strcasecmp(disp->value, "crit") == 0)
|
||||||
|
{
|
||||||
|
setlogmask(LOG_UPTO(LOG_CRIT));
|
||||||
|
config->log_level = LOG_CRIT;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(strcasecmp(disp->value, "emerg") == 0)
|
||||||
|
{
|
||||||
|
setlogmask(LOG_UPTO(LOG_EMERG));
|
||||||
|
config->log_level = LOG_EMERG;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LOGGER_WARNING("invalid log-level '%s'\n", disp->value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
config_load_log_file(IniDispatch *disp, config_t *config)
|
||||||
|
{
|
||||||
|
if(strcasecmp(disp->value, "stdout") == 0)
|
||||||
|
{
|
||||||
|
config->log_file = stdout;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(strcasecmp(disp->value, "stderr") == 0)
|
||||||
|
{
|
||||||
|
config->log_file = stderr;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
config->log_file = fopen(disp->value, "a+");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +127,10 @@ config_load(IniDispatch *disp, void *config_void)
|
||||||
{
|
{
|
||||||
return config_load_log_level(disp, config);
|
return config_load_log_level(disp, config);
|
||||||
}
|
}
|
||||||
|
if(CONFINI_IS_KEY("core", "log-file"))
|
||||||
|
{
|
||||||
|
return config_load_log_file(disp, config);
|
||||||
|
}
|
||||||
if(CONFINI_IS_KEY("core", "server-port"))
|
if(CONFINI_IS_KEY("core", "server-port"))
|
||||||
{
|
{
|
||||||
config->server_port = atoi(disp->value);
|
config->server_port = atoi(disp->value);
|
||||||
|
|
|
@ -33,11 +33,11 @@ database_migrate()
|
||||||
switch(version_num)
|
switch(version_num)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
LOG_INFO("migrating LEVEL 0\n");
|
LOGGER_INFO("migrating LEVEL 0\n");
|
||||||
rc = sqlite3_exec(global_database, (const char *)sql_migration_0_sql, NULL, NULL, &err_msg);
|
rc = sqlite3_exec(global_database, (const char *)sql_migration_0_sql, NULL, NULL, &err_msg);
|
||||||
if(rc != 0)
|
if(rc != 0)
|
||||||
{
|
{
|
||||||
LOG_FATAL("couldn't migrate LEVEL 0 (%s)\n", err_msg);
|
LOGGER_CRIT("couldn't migrate LEVEL 0 (%s)\n", err_msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
new_version_num = 1;
|
new_version_num = 1;
|
||||||
|
@ -58,7 +58,7 @@ database_migrate()
|
||||||
rc = sqlite3_step(stmt);
|
rc = sqlite3_step(stmt);
|
||||||
if (rc != SQLITE_DONE)
|
if (rc != SQLITE_DONE)
|
||||||
{
|
{
|
||||||
LOG_FATAL("couldn't write new schema version\n");
|
LOGGER_CRIT("couldn't write new schema version\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
|
@ -32,7 +32,7 @@ endpoint_func_not_found(struct mg_connection *nc, struct http_message *hm, endpo
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_DEBUG("404 file not found\n");
|
LOGGER_DEBUG("404 file not found\n");
|
||||||
response->status_code = 404;
|
response->status_code = 404;
|
||||||
response->content_type = global_config.not_found_content_type;
|
response->content_type = global_config.not_found_content_type;
|
||||||
response->content_length = strlen(global_config.not_found_content);
|
response->content_length = strlen(global_config.not_found_content);
|
||||||
|
@ -84,7 +84,7 @@ endpoint_response_json(endpoint_response_t *response, int status_code, const cJS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR("failed to print schedule json\n");
|
LOGGER_ERR("failed to print schedule json\n");
|
||||||
|
|
||||||
static const char content[] = "failed to print json";
|
static const char content[] = "failed to print json";
|
||||||
endpoint_response_text(response, status_code, content, STRLEN(content));
|
endpoint_response_text(response, status_code, content, STRLEN(content));
|
||||||
|
|
|
@ -18,7 +18,7 @@ api_v1_controllers_STR_GET(struct mg_connection *nc, struct http_message *hm, en
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(args[0].value.v_str, target_uid))
|
if(uuid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -29,7 +29,7 @@ api_v1_controllers_STR_GET(struct mg_connection *nc, struct http_message *hm, en
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -52,7 +52,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(args[0].value.v_str, target_uid))
|
if(uuid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -63,7 +63,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -130,7 +130,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
|
||||||
|
|
||||||
if(controller_save(controller))
|
if(controller_save(controller))
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to save controller\n");
|
LOGGER_ERR("failed to save controller\n");
|
||||||
controller_free(controller);
|
controller_free(controller);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(target_uid_str, target_uid))
|
if(uuid_parse(target_uid_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -171,7 +171,7 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -180,7 +180,7 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
|
||||||
|
|
||||||
if(controller_remove(controller))
|
if(controller_remove(controller))
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to remove controller from database\n");
|
LOGGER_ERR("failed to remove controller from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to remove controller from database";
|
static const char content[] = "failed to remove controller from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
|
|
@ -15,7 +15,7 @@ api_v1_controllers_STR_relays_GET(struct mg_connection *nc, struct http_message
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(args[0].value.v_str, target_uid))
|
if(uuid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -26,7 +26,7 @@ api_v1_controllers_STR_relays_GET(struct mg_connection *nc, struct http_message
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
|
|
@ -18,7 +18,7 @@ api_v1_controllers_STR_relays_INT_GET(struct mg_connection *nc, struct http_mess
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(args[0].value.v_str, target_uid))
|
if(uuid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -29,7 +29,7 @@ api_v1_controllers_STR_relays_INT_GET(struct mg_connection *nc, struct http_mess
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -40,7 +40,7 @@ api_v1_controllers_STR_relays_INT_GET(struct mg_connection *nc, struct http_mess
|
||||||
|
|
||||||
if(!relay)
|
if(!relay)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a relay with num %d for controller '%s'\n", args[1].value.v_int, args[0].value.v_str);
|
LOGGER_DEBUG("could not find a relay with num %d for controller '%s'\n", args[1].value.v_int, args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no relay for this controller found";
|
static const char content[] = "no relay for this controller found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -64,7 +64,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(args[0].value.v_str, target_uid))
|
if(uuid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -75,7 +75,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -134,7 +134,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
cJSON *json_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_schedule, "id");
|
cJSON *json_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_schedule, "id");
|
||||||
if(!cJSON_IsString(json_schedule_uid) || (json_schedule_uid->valuestring == NULL))
|
if(!cJSON_IsString(json_schedule_uid) || (json_schedule_uid->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("schedules[%d] is missing uid\n", schedule_position);
|
LOGGER_DEBUG("schedules[%d] is missing uid\n", schedule_position);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
static const char content[] = "at least one schedule is missing an id";
|
static const char content[] = "at least one schedule is missing an id";
|
||||||
|
@ -144,7 +144,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(schedule_uid_parse(json_schedule_uid->valuestring, target_uid))
|
if(schedule_uid_parse(json_schedule_uid->valuestring, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("schedules[%d] has bad uid\n", schedule_position);
|
LOGGER_DEBUG("schedules[%d] has bad uid\n", schedule_position);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
static const char content[] = "at least one schedule has a bad id";
|
static const char content[] = "at least one schedule has a bad id";
|
||||||
|
@ -174,7 +174,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(schedule_uid_parse(json_active_schedule_uid->valuestring, target_uid))
|
if(schedule_uid_parse(json_active_schedule_uid->valuestring, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("active_schedule has bad uid\n");
|
LOGGER_DEBUG("active_schedule has bad uid\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
static const char content[] = "active_schedule has a bad id";
|
static const char content[] = "active_schedule has a bad id";
|
||||||
|
@ -187,7 +187,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
|
|
||||||
if(relay_save(relay))
|
if(relay_save(relay))
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to save relay\n");
|
LOGGER_ERR("failed to save relay\n");
|
||||||
free(controller);
|
free(controller);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
|
||||||
{
|
{
|
||||||
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("invalid tag in tags\n");
|
LOGGER_DEBUG("invalid tag in tags\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const char *tag = json_tag->valuestring;
|
const char *tag = json_tag->valuestring;
|
||||||
|
|
|
@ -18,7 +18,7 @@ api_v1_controllers_STR_relays_INT_pulse_POST(struct mg_connection *nc, struct ht
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(uuid_parse(args[0].value.v_str, target_uid))
|
if(uuid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -29,7 +29,7 @@ api_v1_controllers_STR_relays_INT_pulse_POST(struct mg_connection *nc, struct ht
|
||||||
|
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no controller for id found";
|
static const char content[] = "no controller for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -40,7 +40,7 @@ api_v1_controllers_STR_relays_INT_pulse_POST(struct mg_connection *nc, struct ht
|
||||||
|
|
||||||
if(!relay)
|
if(!relay)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a relay with num %d for controller '%s'\n", args[1].value.v_int, args[0].value.v_str);
|
LOGGER_DEBUG("could not find a relay with num %d for controller '%s'\n", args[1].value.v_int, args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no relay for this controller found";
|
static const char content[] = "no relay for this controller found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
|
|
@ -30,21 +30,21 @@ bind_tcp_server(const char *addr, const char *port, int max_client_backlog)
|
||||||
|
|
||||||
if ((status = getaddrinfo(addr, port, &hints, &res)) != 0)
|
if ((status = getaddrinfo(addr, port, &hints, &res)) != 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error getting address info: %s\n", gai_strerror(status));
|
LOGGER_ERR("error getting address info: %s\n", gai_strerror(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
|
|
||||||
if ((status = bind(fd, res->ai_addr, res->ai_addrlen)) == -1)
|
if ((status = bind(fd, res->ai_addr, res->ai_addrlen)) == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error binding socket: %s\n", status);
|
LOGGER_ERR("error binding socket: %s\n", status);
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = listen(fd, max_client_backlog)) == -1)
|
if ((status = listen(fd, max_client_backlog)) == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error setting up listener: %s\n", status);
|
LOGGER_ERR("error setting up listener: %s\n", status);
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -78,14 +78,14 @@ send_udp_broadcast(const char *addr, uint16_t port, void *message, size_t length
|
||||||
|
|
||||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error creating socket\n");
|
LOGGER_ERR("error creating socket\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int broadcast = 1;
|
int broadcast = 1;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof broadcast) < 0)
|
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof broadcast) < 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error setting broadcast\n");
|
LOGGER_ERR("error setting broadcast\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ send_udp_broadcast(const char *addr, uint16_t port, void *message, size_t length
|
||||||
|
|
||||||
if(sendto(fd, message, length, 0, (struct sockaddr *)&their_addr, sizeof(their_addr)) < 0)
|
if(sendto(fd, message, length, 0, (struct sockaddr *)&their_addr, sizeof(their_addr)) < 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error sending broadcast (%d): '%s'\n", errno, strerror(errno));
|
LOGGER_ERR("error sending broadcast (%d): '%s'\n", errno, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -114,7 +114,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
|
|
||||||
if(discover_server_port == -1)
|
if(discover_server_port == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to get server port for discovery\n");
|
LOGGER_ERR("failed to get server port for discovery\n");
|
||||||
static const char content[] = "";
|
static const char content[] = "";
|
||||||
response->status_code = 500;
|
response->status_code = 500;
|
||||||
response->content_type = "text/plain";
|
response->content_type = "text/plain";
|
||||||
|
@ -129,7 +129,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
|
|
||||||
if(send_udp_broadcast("255.255.255.255", global_config.discovery_port, payload, sizeof(payload)) < 0)
|
if(send_udp_broadcast("255.255.255.255", global_config.discovery_port, payload, sizeof(payload)) < 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to send UDP broadcast\n");
|
LOGGER_ERR("failed to send UDP broadcast\n");
|
||||||
static const char content[] = "";
|
static const char content[] = "";
|
||||||
response->status_code = 500;
|
response->status_code = 500;
|
||||||
response->content_type = "text/plain";
|
response->content_type = "text/plain";
|
||||||
|
@ -168,7 +168,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
{
|
{
|
||||||
if((client_fd = accept(discover_server_socket, (struct sockaddr *) &their_addr, &addr_size)) < 0)
|
if((client_fd = accept(discover_server_socket, (struct sockaddr *) &their_addr, &addr_size)) < 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error accepting client %s\n", strerror(errno));
|
LOGGER_ERR("error accepting client %s\n", strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
|
|
||||||
if(recv(client_fd, &payload_length, sizeof(payload_length), 0) <= 0)
|
if(recv(client_fd, &payload_length, sizeof(payload_length), 0) <= 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error receiving header from client\n");
|
LOGGER_ERR("error receiving header from client\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
|
|
||||||
if((bytes_transferred = recv(client_fd, answer_payload, payload_length, 0)) <= 0)
|
if((bytes_transferred = recv(client_fd, answer_payload, payload_length, 0)) <= 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error receiving payload from client\n");
|
LOGGER_ERR("error receiving payload from client\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
if(getpeername(client_fd, (struct sockaddr *)&addr, &client_addr_size) != 0)
|
if(getpeername(client_fd, (struct sockaddr *)&addr, &client_addr_size) != 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
LOG_ERROR("error receiving payload from client\n");
|
LOGGER_ERR("error receiving payload from client\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
|
||||||
{
|
{
|
||||||
known_controllers[i]->active = false;
|
known_controllers[i]->active = false;
|
||||||
controller_save(known_controllers[i]);
|
controller_save(known_controllers[i]);
|
||||||
LOG_DEBUG("lost: %s\n", known_controllers[i]->name);
|
LOGGER_DEBUG("lost: %s\n", known_controllers[i]->name);
|
||||||
}
|
}
|
||||||
controller_free_list(known_controllers);
|
controller_free_list(known_controllers);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ api_v1_relays_tag_STR_GET(struct mg_connection *nc, struct http_message *hm, end
|
||||||
int *relays_ids = junction_tag_get_relays_for_tag_id(tag_id);
|
int *relays_ids = junction_tag_get_relays_for_tag_id(tag_id);
|
||||||
if(relays_ids == NULL)
|
if(relays_ids == NULL)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to load relays for tag from database\n");
|
LOGGER_ERR("failed to load relays for tag from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to load relays for tag from database";
|
static const char content[] = "failed to load relays for tag from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
|
|
@ -24,7 +24,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
cJSON *json_name = cJSON_GetObjectItemCaseSensitive(json, "name");
|
cJSON *json_name = cJSON_GetObjectItemCaseSensitive(json, "name");
|
||||||
if(!cJSON_IsString(json_name) || (json_name->valuestring == NULL))
|
if(!cJSON_IsString(json_name) || (json_name->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("no name for schedule provided\n");
|
LOGGER_DEBUG("no name for schedule provided\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
static const char content[] = "no name for schedule provided";
|
static const char content[] = "no name for schedule provided";
|
||||||
|
@ -34,7 +34,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
cJSON *json_periods = cJSON_GetObjectItemCaseSensitive(json, "periods");
|
cJSON *json_periods = cJSON_GetObjectItemCaseSensitive(json, "periods");
|
||||||
if(!cJSON_IsArray(json_periods))
|
if(!cJSON_IsArray(json_periods))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("no periods for schedule provided\n");
|
LOGGER_DEBUG("no periods for schedule provided\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
static const char content[] = "no periods for schedule provided";
|
static const char content[] = "no periods for schedule provided";
|
||||||
|
@ -48,7 +48,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
{
|
{
|
||||||
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("invalid tag in tags\n");
|
LOGGER_DEBUG("invalid tag in tags\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
static const char content[] = "invalid tag in tags";
|
static const char content[] = "invalid tag in tags";
|
||||||
|
@ -78,7 +78,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
|
|
||||||
if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
|
if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("period is missing start\n");
|
LOGGER_DEBUG("period is missing start\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
}
|
}
|
||||||
if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
|
if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("period is missing end\n");
|
LOGGER_DEBUG("period is missing end\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
uint16_t end;
|
uint16_t end;
|
||||||
if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
|
if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
|
LOGGER_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
||||||
}
|
}
|
||||||
if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
|
if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
|
LOGGER_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ api_v1_schedules_STR_GET(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(schedule_uid_parse(args[0].value.v_str, target_uid))
|
if(schedule_uid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -30,7 +30,7 @@ api_v1_schedules_STR_GET(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
|
|
||||||
if(!schedule)
|
if(!schedule)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a schedule for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a schedule for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no schedule for id found";
|
static const char content[] = "no schedule for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -53,7 +53,7 @@ api_v1_schedules_STR_PUT(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(schedule_uid_parse(args[0].value.v_str, target_uid))
|
if(schedule_uid_parse(args[0].value.v_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -64,7 +64,7 @@ api_v1_schedules_STR_PUT(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
|
|
||||||
if(!schedule)
|
if(!schedule)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a schedule for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a schedule for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no schedule for id found";
|
static const char content[] = "no schedule for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -105,12 +105,12 @@ api_v1_schedules_STR_PUT(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
|
|
||||||
if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
|
if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("period is missing start\n");
|
LOGGER_DEBUG("period is missing start\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
|
if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("period is missing end\n");
|
LOGGER_DEBUG("period is missing end\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,12 +118,12 @@ api_v1_schedules_STR_PUT(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
uint16_t end;
|
uint16_t end;
|
||||||
if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
|
if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
|
LOGGER_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
|
if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
|
LOGGER_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ api_v1_schedules_STR_PUT(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
|
|
||||||
if(schedule_save(schedule))
|
if(schedule_save(schedule))
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to save schedule\n");
|
LOGGER_ERR("failed to save schedule\n");
|
||||||
free(schedule);
|
free(schedule);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ api_v1_schedules_STR_PUT(struct mg_connection *nc, struct http_message *hm, endp
|
||||||
{
|
{
|
||||||
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("invalid tag in tags\n");
|
LOGGER_DEBUG("invalid tag in tags\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const char *tag = json_tag->valuestring;
|
const char *tag = json_tag->valuestring;
|
||||||
|
@ -195,7 +195,7 @@ api_v1_schedules_STR_DELETE(struct mg_connection *nc, struct http_message *hm, e
|
||||||
uuid_t target_uid;
|
uuid_t target_uid;
|
||||||
if(schedule_uid_parse(target_uid_str, target_uid))
|
if(schedule_uid_parse(target_uid_str, target_uid))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to unparse uid\n");
|
LOGGER_DEBUG("failed to unparse uid\n");
|
||||||
|
|
||||||
static const char content[] = "given id was invalid";
|
static const char content[] = "given id was invalid";
|
||||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||||
|
@ -206,7 +206,7 @@ api_v1_schedules_STR_DELETE(struct mg_connection *nc, struct http_message *hm, e
|
||||||
|
|
||||||
if(!schedule)
|
if(!schedule)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("could not find a schedule for uid '%s'\n", args[0].value.v_str);
|
LOGGER_DEBUG("could not find a schedule for uid '%s'\n", args[0].value.v_str);
|
||||||
|
|
||||||
static const char content[] = "no schedule for id found";
|
static const char content[] = "no schedule for id found";
|
||||||
endpoint_response_text(response, 404, content, STRLEN(content));
|
endpoint_response_text(response, 404, content, STRLEN(content));
|
||||||
|
@ -224,7 +224,7 @@ api_v1_schedules_STR_DELETE(struct mg_connection *nc, struct http_message *hm, e
|
||||||
|
|
||||||
if(schedule_remove(schedule))
|
if(schedule_remove(schedule))
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to remove schedule from database\n");
|
LOGGER_ERR("failed to remove schedule from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to remove schedule from database";
|
static const char content[] = "failed to remove schedule from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
|
|
@ -28,7 +28,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
cJSON *json_name = cJSON_GetObjectItemCaseSensitive(json, "name");
|
cJSON *json_name = cJSON_GetObjectItemCaseSensitive(json, "name");
|
||||||
if(!cJSON_IsString(json_name) || (json_name->valuestring == NULL))
|
if(!cJSON_IsString(json_name) || (json_name->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("no name for schedule provided\n");
|
LOGGER_DEBUG("no name for schedule provided\n");
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
|
|
||||||
static const char content[] = "no name for schedule provided";
|
static const char content[] = "no name for schedule provided";
|
||||||
|
@ -38,7 +38,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
cJSON *json_periods = cJSON_GetObjectItemCaseSensitive(json, "periods");
|
cJSON *json_periods = cJSON_GetObjectItemCaseSensitive(json, "periods");
|
||||||
if(!cJSON_IsArray(json_periods))
|
if(!cJSON_IsArray(json_periods))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("no periods for schedule provided\n");
|
LOGGER_DEBUG("no periods for schedule provided\n");
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
|
|
||||||
static const char content[] = "no periods for schedule provided";
|
static const char content[] = "no periods for schedule provided";
|
||||||
|
@ -52,7 +52,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
{
|
{
|
||||||
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("invalid tag in tags\n");
|
LOGGER_DEBUG("invalid tag in tags\n");
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
|
|
||||||
static const char content[] = "invalid tag in tags";
|
static const char content[] = "invalid tag in tags";
|
||||||
|
@ -82,7 +82,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
|
|
||||||
if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
|
if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("period is missing start\n");
|
LOGGER_DEBUG("period is missing start\n");
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
}
|
}
|
||||||
if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
|
if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("period is missing end\n");
|
LOGGER_DEBUG("period is missing end\n");
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
uint16_t end;
|
uint16_t end;
|
||||||
if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
|
if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
|
LOGGER_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
|
||||||
}
|
}
|
||||||
if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
|
if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
|
LOGGER_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
|
||||||
cJSON_Delete(json_list);
|
cJSON_Delete(json_list);
|
||||||
schedule_free(new_schedule);
|
schedule_free(new_schedule);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ api_v1_schedules_tag_STR_GET(struct mg_connection *nc, struct http_message *hm,
|
||||||
int *schedules_ids = junction_tag_get_schedules_for_tag_id(tag_id);
|
int *schedules_ids = junction_tag_get_schedules_for_tag_id(tag_id);
|
||||||
if(schedules_ids == NULL)
|
if(schedules_ids == NULL)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to load schedules for tag from database\n");
|
LOGGER_ERR("failed to load schedules for tag from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to load schedules for tag from database";
|
static const char content[] = "failed to load schedules for tag from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
|
|
@ -21,7 +21,7 @@ api_v1_tags_GET(struct mg_connection *nc, struct http_message *hm, endpoint_args
|
||||||
cJSON *json_tag = cJSON_CreateString(all_tags[i]);
|
cJSON *json_tag = cJSON_CreateString(all_tags[i]);
|
||||||
if (json_tag == NULL)
|
if (json_tag == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to add tag from string '%s'\n", all_tags[i]);
|
LOGGER_DEBUG("failed to add tag from string '%s'\n", all_tags[i]);
|
||||||
free(all_tags[i]);
|
free(all_tags[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ api_v1_tags_STR_GET(struct mg_connection *nc, struct http_message *hm, endpoint_
|
||||||
int *relays_ids = junction_tag_get_relays_for_tag_id(tag_id);
|
int *relays_ids = junction_tag_get_relays_for_tag_id(tag_id);
|
||||||
if(relays_ids == NULL)
|
if(relays_ids == NULL)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to load relays for tag from database\n");
|
LOGGER_ERR("failed to load relays for tag from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to load relays for tag from database";
|
static const char content[] = "failed to load relays for tag from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
@ -32,7 +32,7 @@ api_v1_tags_STR_GET(struct mg_connection *nc, struct http_message *hm, endpoint_
|
||||||
int *schedules_ids = junction_tag_get_schedules_for_tag_id(tag_id);
|
int *schedules_ids = junction_tag_get_schedules_for_tag_id(tag_id);
|
||||||
if(schedules_ids == NULL)
|
if(schedules_ids == NULL)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to load schedules for tag from database\n");
|
LOGGER_ERR("failed to load schedules for tag from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to load schedules for tag from database";
|
static const char content[] = "failed to load schedules for tag from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
@ -98,7 +98,7 @@ api_v1_tags_STR_DELETE(struct mg_connection *nc, struct http_message *hm, endpoi
|
||||||
|
|
||||||
if(tag_remove(tag_id))
|
if(tag_remove(tag_id))
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to remove tag from database\n");
|
LOGGER_ERR("failed to remove tag from database\n");
|
||||||
|
|
||||||
static const char content[] = "failed to remove tag from database";
|
static const char content[] = "failed to remove tag from database";
|
||||||
endpoint_response_text(response, 500, content, STRLEN(content));
|
endpoint_response_text(response, 500, content, STRLEN(content));
|
||||||
|
|
|
@ -55,8 +55,6 @@ send_response(struct mg_connection *nc, endpoint_response_t *response)
|
||||||
static void
|
static void
|
||||||
handle_websocket_request(struct mg_connection *nc, struct http_message *hm)
|
handle_websocket_request(struct mg_connection *nc, struct http_message *hm)
|
||||||
{
|
{
|
||||||
LOG_TRACE("new websocket %.*s request for %.*s\n", hm->method.len, hm->method.p, hm->uri.len, hm->uri.p);
|
|
||||||
|
|
||||||
struct mg_str method_websocket_str = mg_mk_str("WEBSOCKET");
|
struct mg_str method_websocket_str = mg_mk_str("WEBSOCKET");
|
||||||
endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &method_websocket_str);
|
endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &method_websocket_str);
|
||||||
|
|
||||||
|
@ -81,8 +79,6 @@ handle_websocket_request(struct mg_connection *nc, struct http_message *hm)
|
||||||
static void
|
static void
|
||||||
handle_http_request(struct mg_connection *nc, struct http_message *hm)
|
handle_http_request(struct mg_connection *nc, struct http_message *hm)
|
||||||
{
|
{
|
||||||
LOG_TRACE("new http %.*s request for %.*s\n", hm->method.len, hm->method.p, hm->uri.len, hm->uri.p);
|
|
||||||
|
|
||||||
endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &hm->method);
|
endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &hm->method);
|
||||||
|
|
||||||
endpoint_response_t response;
|
endpoint_response_t response;
|
||||||
|
@ -106,7 +102,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
|
||||||
++request_file;
|
++request_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("%s\n", request_file);
|
LOGGER_DEBUG("%s\n", request_file);
|
||||||
char *request_file_path = malloc(sizeof(char) * (strlen(request_file) + strlen(global_config.content_dir) + 2));
|
char *request_file_path = malloc(sizeof(char) * (strlen(request_file) + strlen(global_config.content_dir) + 2));
|
||||||
sprintf(request_file_path, "%s/%s", global_config.content_dir, request_file);
|
sprintf(request_file_path, "%s/%s", global_config.content_dir, request_file);
|
||||||
int access_result = access(request_file_path, R_OK);
|
int access_result = access(request_file_path, R_OK);
|
||||||
|
|
|
@ -47,7 +47,7 @@ handle_mqtt_publish(struct mg_mqtt_message *msg)
|
||||||
char *topic = malloc(sizeof(char) * (msg->topic.len + 1));
|
char *topic = malloc(sizeof(char) * (msg->topic.len + 1));
|
||||||
strncpy(topic, msg->topic.p, msg->topic.len);
|
strncpy(topic, msg->topic.p, msg->topic.len);
|
||||||
topic[msg->topic.len] = '\0';
|
topic[msg->topic.len] = '\0';
|
||||||
LOG_DEBUG("received mqtt publish for topic %s\n", topic);
|
LOGGER_DEBUG("received mqtt publish for topic %s\n", topic);
|
||||||
|
|
||||||
char *payload = malloc(sizeof(char) * (msg->payload.len + 1));
|
char *payload = malloc(sizeof(char) * (msg->payload.len + 1));
|
||||||
strncpy(payload, msg->payload.p, msg->payload.len);
|
strncpy(payload, msg->payload.p, msg->payload.len);
|
||||||
|
|
|
@ -20,7 +20,7 @@ helper_connect_tcp_server(char* host, uint16_t port)
|
||||||
hints.ai_socktype = SOCK_STREAM; //set socket flag
|
hints.ai_socktype = SOCK_STREAM; //set socket flag
|
||||||
|
|
||||||
if ((status = getaddrinfo(host, port_str, &hints, &res)) != 0) { //getaddrinfo() will evaluate the given address, using the hints-flags and port, and return an IP address and other server infos
|
if ((status = getaddrinfo(host, port_str, &hints, &res)) != 0) { //getaddrinfo() will evaluate the given address, using the hints-flags and port, and return an IP address and other server infos
|
||||||
LOG_ERROR("getaddrinfo: %s\n", gai_strerror(status));
|
LOGGER_ERR("getaddrinfo: %s\n", gai_strerror(status));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ helper_connect_tcp_server(char* host, uint16_t port)
|
||||||
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); //creating Socket
|
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); //creating Socket
|
||||||
|
|
||||||
if ((status = connect(s, res->ai_addr, res->ai_addrlen)) != 0) {
|
if ((status = connect(s, res->ai_addr, res->ai_addrlen)) != 0) {
|
||||||
LOG_ERROR("connect() failed\n");
|
LOGGER_ERR("connect() failed\n");
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ get_uid_for_user(char *user)
|
||||||
|
|
||||||
if(pwd == NULL)
|
if(pwd == NULL)
|
||||||
{
|
{
|
||||||
LOG_FATAL("couldn't find user to drop privileges\n");
|
LOGGER_CRIT("couldn't find user to drop privileges\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ get_gid_for_group(char *group)
|
||||||
|
|
||||||
if(grp == NULL)
|
if(grp == NULL)
|
||||||
{
|
{
|
||||||
LOG_FATAL("couldn't find group to drop privileges\n");
|
LOGGER_CRIT("couldn't find group to drop privileges\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,16 +62,16 @@ helper_drop_privileges()
|
||||||
uid_t uid = get_uid_for_user(global_config.user);
|
uid_t uid = get_uid_for_user(global_config.user);
|
||||||
gid_t gid = get_gid_for_group(global_config.group);
|
gid_t gid = get_gid_for_group(global_config.group);
|
||||||
|
|
||||||
LOG_DEBUG("drop privileges to %lu:%lu\n", uid, gid);
|
LOGGER_DEBUG("drop privileges to %lu:%lu\n", uid, gid);
|
||||||
|
|
||||||
if (setgid(gid) == -1)
|
if (setgid(gid) == -1)
|
||||||
{
|
{
|
||||||
LOG_FATAL("failed to drop group privileges\n");
|
LOGGER_CRIT("failed to drop group privileges\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (setuid(uid) == -1)
|
if (setuid(uid) == -1)
|
||||||
{
|
{
|
||||||
LOG_FATAL("failed to drop user privileges\n");
|
LOGGER_CRIT("failed to drop user privileges\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,12 +50,12 @@ helper_parse_cli(int argc, const char **argv, config_t *config)
|
||||||
config->run_type = RUN_TYPE_START;
|
config->run_type = RUN_TYPE_START;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG_FATAL("bad action '%s' given ('start')\n", argv[0]);
|
LOGGER_CRIT("bad action '%s' given ('start')\n", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_FATAL("no action given ('start')\n");
|
LOGGER_CRIT("no action given ('start')\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
71
src/logger.c
71
src/logger.c
|
@ -5,44 +5,56 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
|
|
||||||
#define COLOR_TRACE COLOR_GREEN
|
const char *COLOR_DEBUG = COLOR_GREEN;
|
||||||
#define COLOR_DEBUG COLOR_BLUE
|
const char *COLOR_INFO = COLOR_CYAN;
|
||||||
#define COLOR_INFO COLOR_CYAN
|
const char *COLOR_NOTICE = COLOR_CYAN;
|
||||||
#define COLOR_WARN COLOR_YELLOW
|
const char *COLOR_WARNING = COLOR_YELLOW;
|
||||||
#define COLOR_ERROR COLOR_RED
|
const char *COLOR_ERR = COLOR_RED;
|
||||||
#define COLOR_FATAL COLOR_MAGENTA
|
const char *COLOR_CRIT = COLOR_MAGENTA;
|
||||||
|
const char *COLOR_EMERG = COLOR_MAGENTA;
|
||||||
|
|
||||||
void
|
void
|
||||||
logger_log(FILE *stream, log_level_t level, const char *filename, int line, const char *func, const char *msg, ...)
|
logger_log(int level, const char *filename, int line, const char *func, const char *msg, ...)
|
||||||
{
|
{
|
||||||
if(global_config.log_level < level)
|
if(global_config.log_level < level)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const char *level_str;
|
||||||
|
const char *color;
|
||||||
|
|
||||||
switch(level)
|
switch(level)
|
||||||
{
|
{
|
||||||
case LOG_LEVEL_TRACE:
|
case LOG_DEBUG:
|
||||||
fprintf(stream, COLOR_TRACE "[TRACE] ");
|
color = COLOR_DEBUG;
|
||||||
|
level_str = "DEBUG";
|
||||||
break;
|
break;
|
||||||
case LOG_LEVEL_DEBUG:
|
case LOG_INFO:
|
||||||
fprintf(stream, COLOR_DEBUG "[DEBUG] ");
|
color = COLOR_INFO;
|
||||||
|
level_str = "INFO";
|
||||||
break;
|
break;
|
||||||
case LOG_LEVEL_INFO:
|
case LOG_NOTICE:
|
||||||
fprintf(stream, COLOR_INFO "[INFO ] ");
|
color = COLOR_NOTICE;
|
||||||
|
level_str = "NOTE";
|
||||||
break;
|
break;
|
||||||
case LOG_LEVEL_WARN:
|
case LOG_WARNING:
|
||||||
fprintf(stream, COLOR_WARN "[WARN ] ");
|
color = COLOR_WARNING;
|
||||||
|
level_str = "WARN";
|
||||||
break;
|
break;
|
||||||
case LOG_LEVEL_ERROR:
|
case LOG_ERR:
|
||||||
fprintf(stream, COLOR_ERROR "[ERROR] ");
|
color = COLOR_ERR;
|
||||||
|
level_str = "ERROR";
|
||||||
break;
|
break;
|
||||||
case LOG_LEVEL_FATAL:
|
case LOG_CRIT:
|
||||||
fprintf(stream, COLOR_FATAL "[FATAL] ");
|
color = COLOR_CRIT;
|
||||||
|
level_str = "CRIT";
|
||||||
|
break;
|
||||||
|
case LOG_EMERG:
|
||||||
|
color = COLOR_EMERG;
|
||||||
|
level_str = "EMERG";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stream, COLOR_NONE "[LOG ] ");
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char timestamp_str[32];
|
char timestamp_str[32];
|
||||||
|
@ -50,10 +62,23 @@ logger_log(FILE *stream, log_level_t level, const char *filename, int line, cons
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
strftime(timestamp_str, 32, "%Y-%m-%d %H:%M:%S", localtime(&rawtime));
|
strftime(timestamp_str, 32, "%Y-%m-%d %H:%M:%S", localtime(&rawtime));
|
||||||
|
|
||||||
fprintf(stream, "%s %s:%d:%s " COLOR_NONE, timestamp_str, filename, line, func);
|
char *buffer = malloc(sizeof(char) * (128 + strlen(msg)));
|
||||||
|
sprintf(buffer, "%s[%5s] %s:%d:%s " COLOR_NONE "%s", color, level_str, filename, line, func, msg);
|
||||||
|
|
||||||
|
//fprintf(stream, "%s %s:%d:%s " COLOR_NONE, timestamp_str, filename, line, func);
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, msg);
|
va_start(args, msg);
|
||||||
vfprintf(stream, msg, args);
|
vsyslog(level, buffer, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
|
char *buffer_timed = malloc(sizeof(char) * (strlen(timestamp_str) + strlen(buffer) + 2));
|
||||||
|
sprintf(buffer_timed, "%s %s", timestamp_str, buffer);
|
||||||
|
va_start(args, msg);
|
||||||
|
vfprintf(global_config.log_file, buffer_timed, args);
|
||||||
|
fflush(global_config.log_file);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
free(buffer_timed);
|
||||||
}
|
}
|
||||||
|
|
28
src/main.c
28
src/main.c
|
@ -2,6 +2,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
#include <router.h>
|
#include <router.h>
|
||||||
|
@ -20,7 +21,7 @@ static struct mg_mgr mgr;
|
||||||
static void
|
static void
|
||||||
terminate(int signum)
|
terminate(int signum)
|
||||||
{
|
{
|
||||||
LOG_INFO("terminating controller (%d)\n", signum);
|
LOGGER_INFO("terminating controller (%d)\n", signum);
|
||||||
|
|
||||||
mg_mgr_free(&mgr);
|
mg_mgr_free(&mgr);
|
||||||
|
|
||||||
|
@ -29,6 +30,8 @@ terminate(int signum)
|
||||||
router_free();
|
router_free();
|
||||||
status_free();
|
status_free();
|
||||||
|
|
||||||
|
closelog();
|
||||||
|
|
||||||
exit(signum);
|
exit(signum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +50,20 @@ main(int argc, const char** argv)
|
||||||
signal(SIGABRT, terminate);
|
signal(SIGABRT, terminate);
|
||||||
signal(SIGTERM, terminate);
|
signal(SIGTERM, terminate);
|
||||||
|
|
||||||
|
setlogmask(LOG_UPTO(LOG_INFO));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************** LOAD CONFIG ********************/
|
/******************** LOAD CONFIG ********************/
|
||||||
|
|
||||||
global_config.file = "core.ini";
|
global_config.file = "core.ini";
|
||||||
global_config.log_level = LOG_LEVEL_INFO;
|
|
||||||
global_config.discovery_port = 4421;
|
global_config.discovery_port = 4421;
|
||||||
global_config.mqtt_port = 1885;
|
global_config.mqtt_port = 1885;
|
||||||
global_config.server_port = 5000;
|
global_config.server_port = 5000;
|
||||||
|
|
||||||
|
global_config.log_level = LOG_INFO;
|
||||||
|
global_config.log_file = stdout;
|
||||||
|
|
||||||
strcpy(global_config.user, "");
|
strcpy(global_config.user, "");
|
||||||
strcpy(global_config.group, "");
|
strcpy(global_config.group, "");
|
||||||
|
|
||||||
|
@ -70,12 +78,12 @@ main(int argc, const char** argv)
|
||||||
FILE * const ini_file = fopen(global_config.file, "rb");
|
FILE * const ini_file = fopen(global_config.file, "rb");
|
||||||
if(ini_file == NULL)
|
if(ini_file == NULL)
|
||||||
{
|
{
|
||||||
LOG_FATAL("config file '%s' was not found\n", global_config.file);
|
LOGGER_CRIT("config file '%s' was not found\n", global_config.file);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if(load_ini_file( ini_file, INI_DEFAULT_FORMAT, NULL, config_load, &global_config))
|
if(load_ini_file( ini_file, INI_DEFAULT_FORMAT, NULL, config_load, &global_config))
|
||||||
{
|
{
|
||||||
LOG_FATAL("unable to parse ini file\n");
|
LOGGER_CRIT("unable to parse ini file\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +94,12 @@ main(int argc, const char** argv)
|
||||||
global_config.http_server_opts.enable_directory_listing = "no";
|
global_config.http_server_opts.enable_directory_listing = "no";
|
||||||
global_config.http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";
|
global_config.http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";
|
||||||
|
|
||||||
|
if(global_config.log_file == NULL)
|
||||||
|
{
|
||||||
|
global_config.log_file = stdout;
|
||||||
|
}
|
||||||
|
openlog("emgauwa-core", 0, LOG_USER);
|
||||||
|
|
||||||
|
|
||||||
/******************** SETUP CONNECTION ********************/
|
/******************** SETUP CONNECTION ********************/
|
||||||
|
|
||||||
|
@ -98,7 +112,7 @@ main(int argc, const char** argv)
|
||||||
struct mg_connection *c_http = mg_bind(&mgr, address, handler_http);
|
struct mg_connection *c_http = mg_bind(&mgr, address, handler_http);
|
||||||
if(c_http == NULL)
|
if(c_http == NULL)
|
||||||
{
|
{
|
||||||
LOG_FATAL("failed to bind http server to port %u\n", global_config.server_port);
|
LOGGER_CRIT("failed to bind http server to port %u\n", global_config.server_port);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
mg_set_protocol_http_websocket(c_http);
|
mg_set_protocol_http_websocket(c_http);
|
||||||
|
@ -107,7 +121,7 @@ main(int argc, const char** argv)
|
||||||
struct mg_connection *c_mqtt = mg_bind(&mgr, address, handler_mqtt);
|
struct mg_connection *c_mqtt = mg_bind(&mgr, address, handler_mqtt);
|
||||||
if(c_mqtt == NULL)
|
if(c_mqtt == NULL)
|
||||||
{
|
{
|
||||||
LOG_FATAL("failed to bind mqtt server to port %u\n", global_config.mqtt_port);
|
LOGGER_CRIT("failed to bind mqtt server to port %u\n", global_config.mqtt_port);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
mg_mqtt_broker_init(&brk, NULL);
|
mg_mqtt_broker_init(&brk, NULL);
|
||||||
|
@ -123,7 +137,7 @@ main(int argc, const char** argv)
|
||||||
|
|
||||||
if(rc)
|
if(rc)
|
||||||
{
|
{
|
||||||
LOG_FATAL("can't open database: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_CRIT("can't open database: %s\n", sqlite3_errmsg(global_database));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ controller_db_select(sqlite3_stmt *stmt)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting controllers from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting controllers from database: %s\n", sqlite3_errstr(s));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,11 +130,11 @@ controller_save(controller_t *controller)
|
||||||
{
|
{
|
||||||
if(controller->id)
|
if(controller->id)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error inserting data: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error inserting data: %s\n", sqlite3_errmsg(global_database));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error updating data: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error updating data: %s\n", sqlite3_errmsg(global_database));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -21,7 +21,7 @@ junction_relay_schedule_insert(uint8_t weekday, int relay_id, int schedule_id)
|
||||||
rc = sqlite3_step(stmt);
|
rc = sqlite3_step(stmt);
|
||||||
if (rc != SQLITE_DONE)
|
if (rc != SQLITE_DONE)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error inserting data: %s", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error inserting data: %s", sqlite3_errmsg(global_database));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ get_ids(sqlite3_stmt *stmt)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting relays from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting relays from database: %s\n", sqlite3_errstr(s));
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ relay_db_select_mapper(sqlite3_stmt *stmt)
|
||||||
{
|
{
|
||||||
if(schedules[i] == NULL)
|
if(schedules[i] == NULL)
|
||||||
{
|
{
|
||||||
LOG_ERROR("got only %d/7 schedules for relay_id %d\n", i, new_relay->id);
|
LOGGER_ERR("got only %d/7 schedules for relay_id %d\n", i, new_relay->id);
|
||||||
relay_free(new_relay);
|
relay_free(new_relay);
|
||||||
free(schedules);
|
free(schedules);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -111,7 +111,7 @@ relay_db_select(sqlite3_stmt *stmt)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting relays from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting relays from database: %s\n", sqlite3_errstr(s));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,11 +140,11 @@ relay_save(relay_t *relay)
|
||||||
{
|
{
|
||||||
if(relay->id)
|
if(relay->id)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error inserting data: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error inserting data: %s\n", sqlite3_errmsg(global_database));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error updating data: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error updating data: %s\n", sqlite3_errmsg(global_database));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -203,7 +203,7 @@ relay_to_json(relay_t *relay)
|
||||||
cJSON *json_number = cJSON_CreateNumber(relay->number);
|
cJSON *json_number = cJSON_CreateNumber(relay->number);
|
||||||
if(json_number == NULL)
|
if(json_number == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to make number\n");
|
LOGGER_DEBUG("failed to make number\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ relay_to_json(relay_t *relay)
|
||||||
cJSON *json_name = cJSON_CreateString(relay->name);
|
cJSON *json_name = cJSON_CreateString(relay->name);
|
||||||
if(json_name == NULL)
|
if(json_name == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to make name\n");
|
LOGGER_DEBUG("failed to make name\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ relay_to_json(relay_t *relay)
|
||||||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||||
if(!controller)
|
if(!controller)
|
||||||
{
|
{
|
||||||
LOG_WARN("failed to get controller\n");
|
LOGGER_WARNING("failed to get controller\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ relay_to_json(relay_t *relay)
|
||||||
cJSON *json_controller_id = cJSON_CreateString(uuid_str);
|
cJSON *json_controller_id = cJSON_CreateString(uuid_str);
|
||||||
if(json_controller_id == NULL)
|
if(json_controller_id == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to make controller id\n");
|
LOGGER_DEBUG("failed to make controller id\n");
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ relay_to_json(relay_t *relay)
|
||||||
cJSON *json_tag = cJSON_CreateString(tag);
|
cJSON *json_tag = cJSON_CreateString(tag);
|
||||||
if (json_tag == NULL)
|
if (json_tag == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to add tag from string '%s'\n", tag);
|
LOGGER_DEBUG("failed to add tag from string '%s'\n", tag);
|
||||||
free(tag);
|
free(tag);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ schedule_db_select(sqlite3_stmt *stmt)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting schedules from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting schedules from database: %s\n", sqlite3_errstr(s));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,11 +125,11 @@ schedule_save(schedule_t *schedule)
|
||||||
{
|
{
|
||||||
if(schedule->id)
|
if(schedule->id)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error inserting data: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error inserting data: %s\n", sqlite3_errmsg(global_database));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error updating data: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error updating data: %s\n", sqlite3_errmsg(global_database));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -262,7 +262,7 @@ schedule_to_json(schedule_t *schedule)
|
||||||
cJSON *json_period_start = cJSON_CreateString(start_str);
|
cJSON *json_period_start = cJSON_CreateString(start_str);
|
||||||
if (json_period_start == NULL)
|
if (json_period_start == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to add start period from string '%s'\n", start_str);
|
LOGGER_DEBUG("failed to add start period from string '%s'\n", start_str);
|
||||||
cJSON_Delete(json_period);
|
cJSON_Delete(json_period);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ schedule_to_json(schedule_t *schedule)
|
||||||
cJSON *json_period_end = cJSON_CreateString(end_str);
|
cJSON *json_period_end = cJSON_CreateString(end_str);
|
||||||
if (json_period_end == NULL)
|
if (json_period_end == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to add end period from string '%s'\n", end_str);
|
LOGGER_DEBUG("failed to add end period from string '%s'\n", end_str);
|
||||||
cJSON_Delete(json_period);
|
cJSON_Delete(json_period);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ schedule_to_json(schedule_t *schedule)
|
||||||
cJSON *json_tag = cJSON_CreateString(tag);
|
cJSON *json_tag = cJSON_CreateString(tag);
|
||||||
if (json_tag == NULL)
|
if (json_tag == NULL)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("failed to add tag from string '%s'\n", tag);
|
LOGGER_DEBUG("failed to add tag from string '%s'\n", tag);
|
||||||
free(tag);
|
free(tag);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ tag_save(int id, const char *tag)
|
||||||
rc = sqlite3_step(stmt);
|
rc = sqlite3_step(stmt);
|
||||||
if (rc != SQLITE_DONE)
|
if (rc != SQLITE_DONE)
|
||||||
{
|
{
|
||||||
LOG_ERROR("error saving tag: %s\n", sqlite3_errmsg(global_database));
|
LOGGER_ERR("error saving tag: %s\n", sqlite3_errmsg(global_database));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ tag_get_tag(int id)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting tags from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting tags from database: %s\n", sqlite3_errstr(s));
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ tag_get_all()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting tags from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting tags from database: %s\n", sqlite3_errstr(s));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ tag_get_id(const char *tag)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("error selecting tags from database: %s\n", sqlite3_errstr(s));
|
LOGGER_ERR("error selecting tags from database: %s\n", sqlite3_errstr(s));
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ router_register_endpoint(const char *route, int method, endpoint_func_f func)
|
||||||
|
|
||||||
if(endpoints_registered >= ROUTER_ENDPOINTS_MAX_COUNT)
|
if(endpoints_registered >= ROUTER_ENDPOINTS_MAX_COUNT)
|
||||||
{
|
{
|
||||||
LOG_ERROR("can't register more than %d endpoints\n", ROUTER_ENDPOINTS_MAX_COUNT);
|
LOGGER_ERR("can't register more than %d endpoints\n", ROUTER_ENDPOINTS_MAX_COUNT);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,12 @@ name = new emgauwa device
|
||||||
discovery-port = 4422
|
discovery-port = 4422
|
||||||
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
|
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
|
||||||
mqtt-port = 1886
|
mqtt-port = 1886
|
||||||
|
mqtt-host = localhost
|
||||||
|
|
||||||
relay-count = 10
|
relay-count = 10
|
||||||
database = controller_db.lmdb
|
database = controller_db.lmdb
|
||||||
log-level = debug
|
log-level = debug
|
||||||
|
log-file = stdout
|
||||||
|
|
||||||
[relay-0]
|
[relay-0]
|
||||||
driver = piface
|
driver = piface
|
||||||
|
@ -44,11 +46,13 @@ inverted = 1
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 1
|
pin = 1
|
||||||
inverted = 1
|
inverted = 1
|
||||||
|
pulse-duration = 3
|
||||||
|
|
||||||
[relay-7]
|
[relay-7]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 0
|
pin = 0
|
||||||
inverted = 1
|
inverted = 1
|
||||||
|
pulse-duration = 3
|
||||||
|
|
||||||
[relay-8]
|
[relay-8]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
[core]
|
[core]
|
||||||
server-port = 5000
|
server-port = 5000
|
||||||
database = core.sqlite
|
database = core.sqlite
|
||||||
|
content-dir = /usr/share/webapps/emgauwa
|
||||||
not-found-file = 404.html
|
not-found-file = 404.html
|
||||||
not-found-file-mime = text/html
|
not-found-file-mime = text/html
|
||||||
not-found-content = 404 - NOT FOUND
|
not-found-content = 404 - NOT FOUND
|
||||||
not-found-content-type = text/plain
|
not-found-content-type = text/plain
|
||||||
|
|
||||||
: 4421 for dev-env; 4420 for testing-env; 4419 for prod-env; 4422 for testing
|
: 4422 for testing; 4421 for dev-env; 4420 for testing-env; 4419 for prod-env
|
||||||
discovery-port = 4422
|
discovery-port = 4422
|
||||||
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
|
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
|
||||||
mqtt-port = 1886
|
mqtt-port = 1886
|
||||||
|
|
||||||
log-level = debug
|
log-level = debug
|
||||||
|
log-file = stdout
|
||||||
|
|
Loading…
Reference in a new issue