Add text responses as json with msg key
This commit is contained in:
		
							parent
							
								
									f97b149376
								
							
						
					
					
						commit
						1d6e8ff037
					
				
					 18 changed files with 114 additions and 83 deletions
				
			
		| 
						 | 
					@ -1,2 +1,2 @@
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
Checks: 'clang-diagnostics-*,clang-analyzer-*,linuxkernel-*,modernize-*'
 | 
					Checks: 'clang-diagnostics-*,clang-analyzer-*,linuxkernel-*,modernize-*,readability-*'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,6 +53,9 @@ endpoint_func_index(struct mg_connection *nc, struct http_message *hm, endpoint_
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
endpoint_func_not_found(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
 | 
					endpoint_func_not_found(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					endpoint_response_msg(endpoint_response_t *response, int status_code, const char *content, int content_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
endpoint_response_text(endpoint_response_t *response, int status_code, const char *content, int content_length);
 | 
					endpoint_response_text(endpoint_response_t *response, int status_code, const char *content, int content_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,20 +5,26 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define M_STRLEN(s) ((sizeof(s)/sizeof(s[0])) - sizeof(s[0]))
 | 
					#define M_STRLEN(s) ((sizeof(s)/sizeof(s[0])) - sizeof(s[0]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define M_RESPONSE_TEXT_STATIC(logger_func, response, code, content) do { logger_func("%s\n", content); endpoint_response_text(response, code, content, M_STRLEN(content)); } while(0)
 | 
					#define M_RESPONSE_MSG(logger_func, response, code, content) do { logger_func("%s\n", content); endpoint_response_msg(response, code, content, M_STRLEN(content)); } while(0)
 | 
				
			||||||
#define M_RESPONSE_400_NO_VALID_JSON(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request is not valid json")
 | 
					#define M_RESPONSE_TEXT(logger_func, response, code, content) do { logger_func("%s\n", content); endpoint_response_text(response, code, content, M_STRLEN(content)); } while(0)
 | 
				
			||||||
#define M_RESPONSE_400_NO_VALID_ID(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contain valid id (uuid)")
 | 
					 | 
				
			||||||
#define M_RESPONSE_400_NO_NAME(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contain a name")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define M_RESPONSE_403_PROTECTED_SCHEDULE(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 403, "the target schedule is protected")
 | 
					#define M_RESPONSE_400_NO_VALID_JSON(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request is not valid json")
 | 
				
			||||||
 | 
					#define M_RESPONSE_400_NO_VALID_ID(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain a valid id (uuid)")
 | 
				
			||||||
 | 
					#define M_RESPONSE_400_NO_NAME(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain a name")
 | 
				
			||||||
 | 
					#define M_RESPONSE_400_NO_VALID_NAME(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain a valid name")
 | 
				
			||||||
 | 
					#define M_RESPONSE_400_NO_IP(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain an ip address")
 | 
				
			||||||
 | 
					#define M_RESPONSE_400_NO_VALID_IP(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain a valid ip address")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define M_RESPONSE_404_NO_CONTROLLER_FOUND_FOR_ID(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no controller was found for the requested id")
 | 
					#define M_RESPONSE_403_PROTECTED_SCHEDULE(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 403, "the target schedule is protected")
 | 
				
			||||||
#define M_RESPONSE_404_NO_SCHEDULE_FOUND_FOR_ID(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no schedule was found for the requested id")
 | 
					 | 
				
			||||||
#define M_RESPONSE_404_NO_MACRO_FOUND_FOR_ID(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no schedule was found for the requested id")
 | 
					 | 
				
			||||||
#define M_RESPONSE_404_NO_TAG_FOUND(response) M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "the requested tag was not found")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define M_RESPONSE_500_FAILED_TO_SAVE_TO_DATABASE(response) M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "the server failed to save to the database")
 | 
					#define M_RESPONSE_404_NO_CONTROLLER_FOUND_FOR_ID(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "no controller was found for the requested id")
 | 
				
			||||||
#define M_RESPONSE_500_FAILED_TO_READ_FROM_DATABASE(response) M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "the server failed to read from the database")
 | 
					#define M_RESPONSE_404_NO_RELAY_FOUND_FOR_ID_AND_NUMBER(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "no relay was found for the requested controller id and relay number")
 | 
				
			||||||
#define M_RESPONSE_500_FAILED_TO_DELETE_FROM_DATABASE(response) M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "the server failed to delete from the database")
 | 
					#define M_RESPONSE_404_NO_SCHEDULE_FOUND_FOR_ID(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "no schedule was found for the requested id")
 | 
				
			||||||
 | 
					#define M_RESPONSE_404_NO_MACRO_FOUND_FOR_ID(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "no schedule was found for the requested id")
 | 
				
			||||||
 | 
					#define M_RESPONSE_404_NO_TAG_FOUND(response) M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "the requested tag was not found")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define M_RESPONSE_500_FAILED_TO_SAVE_TO_DATABASE(response) M_RESPONSE_MSG(LOGGER_ERR, response, 500, "the server failed to save to the database")
 | 
				
			||||||
 | 
					#define M_RESPONSE_500_FAILED_TO_READ_FROM_DATABASE(response) M_RESPONSE_MSG(LOGGER_ERR, response, 500, "the server failed to read from the database")
 | 
				
			||||||
 | 
					#define M_RESPONSE_500_FAILED_TO_DELETE_FROM_DATABASE(response) M_RESPONSE_MSG(LOGGER_ERR, response, 500, "the server failed to delete from the database")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* CORE_MACROS_H */
 | 
					#endif /* CORE_MACROS_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -211,8 +211,6 @@ command_controller_name_set(controller_t *controller)
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
command_send(controller_t *controller, char *payload, uint32_t payload_size)
 | 
					command_send(controller_t *controller, char *payload, uint32_t payload_size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int bytes_transferred;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int fd_controller = helper_connect_tcp_server(controller->ip, controller->port);
 | 
					    int fd_controller = helper_connect_tcp_server(controller->ip, controller->port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(fd_controller == -1)
 | 
					    if(fd_controller == -1)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,6 +42,32 @@ endpoint_func_not_found(struct mg_connection *nc, struct http_message *hm, endpo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					endpoint_response_msg(endpoint_response_t *response, int status_code, const char *content, int content_length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    cJSON *json;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    json = cJSON_CreateObject();
 | 
				
			||||||
 | 
					    cJSON *json_msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(content_length)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        json_msg = cJSON_CreateStringReference(content);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        json_msg = cJSON_CreateString(content);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if(json_msg == NULL)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        endpoint_response_text(response, status_code, content, content_length);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    cJSON_AddItemToObject(json, "msg", json_msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    endpoint_response_json(response, status_code, json);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
endpoint_response_text(endpoint_response_t *response, int status_code, const char *content, int content_length)
 | 
					endpoint_response_text(endpoint_response_t *response, int status_code, const char *content, int content_length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -84,5 +110,5 @@ endpoint_response_json(endpoint_response_t *response, int status_code, const cJS
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to print json");
 | 
					    M_RESPONSE_MSG(LOGGER_ERR, response, 500, "failed to print json");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ api_v1_controllers_STR_GET(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!controller)
 | 
					    if(!controller)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no controller found for id");
 | 
					        M_RESPONSE_404_NO_CONTROLLER_FOUND_FOR_ID(response);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    LOGGER_DEBUG("returning controller for uid '%s'\n", args[0].value.v_str);
 | 
					    LOGGER_DEBUG("returning controller for uid '%s'\n", args[0].value.v_str);
 | 
				
			||||||
| 
						 | 
					@ -78,7 +78,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            controller_free(controller);
 | 
					            controller_free(controller);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the given name is invalid");
 | 
					            M_RESPONSE_400_NO_VALID_NAME(response);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,7 +95,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            controller_free(controller);
 | 
					            controller_free(controller);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "no ip address given");
 | 
					            M_RESPONSE_400_NO_IP(response);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +111,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            controller_free(controller);
 | 
					            controller_free(controller);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the given ip address is not valid");
 | 
					            M_RESPONSE_400_NO_VALID_IP(response);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -121,7 +121,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
        controller_free(controller);
 | 
					        controller_free(controller);
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to save controller to database");
 | 
					        M_RESPONSE_500_FAILED_TO_SAVE_TO_DATABASE(response);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    LOGGER_DEBUG("saved controller %s\n", args[0].value.v_str);
 | 
					    LOGGER_DEBUG("saved controller %s\n", args[0].value.v_str);
 | 
				
			||||||
| 
						 | 
					@ -161,11 +161,11 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(controller_remove(controller))
 | 
					    if(controller_remove(controller))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to remove controller from database");
 | 
					        M_RESPONSE_500_FAILED_TO_DELETE_FROM_DATABASE(response);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "deleted controller");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "deleted controller");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    controller_free(controller);
 | 
					    controller_free(controller);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ api_v1_controllers_STR_relays_INT_GET(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!relay)
 | 
					    if(!relay)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no relay for this controller found");
 | 
					        M_RESPONSE_404_NO_RELAY_FOUND_FOR_ID_AND_NUMBER(response);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,7 +76,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(args[1].value.v_int > controller_relay_count)
 | 
					    if(args[1].value.v_int > controller_relay_count)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "relay number is too high for this controller");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "relay number is too high for this controller");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -137,7 +137,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one schedule is missing an id");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one schedule is missing an id");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            uuid_t target_uid;
 | 
					            uuid_t target_uid;
 | 
				
			||||||
| 
						 | 
					@ -145,7 +145,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "at least one schedule has a bad id");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "at least one schedule has a bad id");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,7 +174,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "active schedule has a bad uid");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "active schedule has a bad uid");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            relay->schedules[day_of_week] = schedule_get_by_uid_or_off(target_uid);
 | 
					            relay->schedules[day_of_week] = schedule_get_by_uid_or_off(target_uid);
 | 
				
			||||||
| 
						 | 
					@ -190,7 +190,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
        database_transaction_rollback(&lock);
 | 
					        database_transaction_rollback(&lock);
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to save relay to database");
 | 
					        M_RESPONSE_500_FAILED_TO_SAVE_TO_DATABASE(response);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -214,7 +214,7 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *nc, struct http_mess
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                free(tag_ids);
 | 
					                free(tag_ids);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "invalid tag in tags");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "invalid tag in tags");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            const char *tag = json_tag->valuestring;
 | 
					            const char *tag = json_tag->valuestring;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ api_v1_controllers_STR_relays_INT_pulse_POST(struct mg_connection *nc, struct ht
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!relay)
 | 
					    if(!relay)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no relay found");
 | 
					        M_RESPONSE_404_NO_RELAY_FOUND_FOR_ID_AND_NUMBER(response);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,6 +58,6 @@ api_v1_controllers_STR_relays_INT_pulse_POST(struct mg_connection *nc, struct ht
 | 
				
			||||||
    LOGGER_DEBUG("commanding pulse to relay %d for controller %s\n", args[1].value.v_int, args[0].value.v_str);
 | 
					    LOGGER_DEBUG("commanding pulse to relay %d for controller %s\n", args[1].value.v_int, args[0].value.v_str);
 | 
				
			||||||
    command_relay_pulse(relay, duration);
 | 
					    command_relay_pulse(relay, duration);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "sent pulse");
 | 
					    M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "sent pulse");
 | 
				
			||||||
    relay_free(relay);
 | 
					    relay_free(relay);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,7 +116,7 @@ api_v1_controllers_discover_PUT(struct mg_connection *nc, struct http_message *h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(discover_server_port == -1)
 | 
					    if(discover_server_port == -1)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "the server failed to prepare discovery");
 | 
					        M_RESPONSE_MSG(LOGGER_ERR, response, 500, "the server failed to prepare discovery");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,7 +126,7 @@ api_v1_controllers_discover_PUT(struct mg_connection *nc, struct http_message *h
 | 
				
			||||||
    LOGGER_DEBUG("sending udp broadcast\n");
 | 
					    LOGGER_DEBUG("sending udp broadcast\n");
 | 
				
			||||||
    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)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "the server failed to send discovery broadcast");
 | 
					        M_RESPONSE_MSG(LOGGER_ERR, response, 500, "the server failed to send discovery broadcast");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -172,8 +172,6 @@ api_v1_controllers_discover_PUT(struct mg_connection *nc, struct http_message *h
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            char *answer_payload = (char*)malloc((payload_length));
 | 
					            char *answer_payload = (char*)malloc((payload_length));
 | 
				
			||||||
            ssize_t bytes_transferred;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if(recv(client_fd, answer_payload, payload_length, 0) <= 0)
 | 
					            if(recv(client_fd, answer_payload, payload_length, 0) <= 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                LOGGER_ERR("error receiving payload from client\n");
 | 
					                LOGGER_ERR("error receiving payload from client\n");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contains actions for the macro");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contains actions for the macro");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -93,7 +93,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action without weekday");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action without weekday");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,7 +104,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action without schedule");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action without schedule");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        cJSON *json_action_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_action_schedule, "id");
 | 
					        cJSON *json_action_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_action_schedule, "id");
 | 
				
			||||||
| 
						 | 
					@ -114,7 +114,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action without schedule id");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action without schedule id");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        uuid_t action_schedule_uid;
 | 
					        uuid_t action_schedule_uid;
 | 
				
			||||||
| 
						 | 
					@ -124,7 +124,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action with an invalid schedule id");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action with an invalid schedule id");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,7 +135,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "the schedule for at least one action was not found");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "the schedule for at least one action was not found");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,7 +150,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action without relay");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action without relay");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        cJSON *json_action_relay_number = cJSON_GetObjectItemCaseSensitive(json_action_relay, "number");
 | 
					        cJSON *json_action_relay_number = cJSON_GetObjectItemCaseSensitive(json_action_relay, "number");
 | 
				
			||||||
| 
						 | 
					@ -160,7 +160,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action without relay number");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action without relay number");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        cJSON *json_action_relay_controller_uid = cJSON_GetObjectItemCaseSensitive(json_action_relay, "controller_id");
 | 
					        cJSON *json_action_relay_controller_uid = cJSON_GetObjectItemCaseSensitive(json_action_relay, "controller_id");
 | 
				
			||||||
| 
						 | 
					@ -170,7 +170,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action without relay controller id");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action without relay controller id");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        uuid_t action_controller_uid;
 | 
					        uuid_t action_controller_uid;
 | 
				
			||||||
| 
						 | 
					@ -180,7 +180,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an action with an invalid relay controller id");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an action with an invalid relay controller id");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -191,7 +191,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "the controller for at least one action relay was not found");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "the controller for at least one action relay was not found");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -207,7 +207,7 @@ api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_a
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(new_macro);
 | 
					            macro_free(new_macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "the relay for at least one action was not found");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 404, "the relay for at least one action was not found");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,7 +81,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            macro_free(macro);
 | 
					            macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "macro could not be saved");
 | 
					            M_RESPONSE_500_FAILED_TO_SAVE_TO_DATABASE(response);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -101,7 +101,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a weekday");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a weekday");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,7 +112,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            cJSON *json_action_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_action_schedule, "id");
 | 
					            cJSON *json_action_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_action_schedule, "id");
 | 
				
			||||||
| 
						 | 
					@ -122,7 +122,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule id");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule id");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            uuid_t action_schedule_uid;
 | 
					            uuid_t action_schedule_uid;
 | 
				
			||||||
| 
						 | 
					@ -132,7 +132,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action has a bad schedule id");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action has a bad schedule id");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -143,7 +143,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action schedule was not found");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action schedule was not found");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,7 +158,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a relay");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a relay");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            cJSON *json_action_relay_number = cJSON_GetObjectItemCaseSensitive(json_action_relay, "number");
 | 
					            cJSON *json_action_relay_number = cJSON_GetObjectItemCaseSensitive(json_action_relay, "number");
 | 
				
			||||||
| 
						 | 
					@ -168,7 +168,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a relay number");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a relay number");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            cJSON *json_action_relay_controller_uid = cJSON_GetObjectItemCaseSensitive(json_action_relay, "controller_id");
 | 
					            cJSON *json_action_relay_controller_uid = cJSON_GetObjectItemCaseSensitive(json_action_relay, "controller_id");
 | 
				
			||||||
| 
						 | 
					@ -178,7 +178,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a relay controller id");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a relay controller id");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            uuid_t action_controller_uid;
 | 
					            uuid_t action_controller_uid;
 | 
				
			||||||
| 
						 | 
					@ -188,7 +188,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action has a bad relay controller id");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action has a bad relay controller id");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -199,7 +199,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action relay controller was not found");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action relay controller was not found");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -215,7 +215,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
                cJSON_Delete(json);
 | 
					                cJSON_Delete(json);
 | 
				
			||||||
                macro_free(macro);
 | 
					                macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "action relay was not found");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "action relay was not found");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -264,17 +264,17 @@ api_v1_macros_STR_DELETE(struct mg_connection *nc, struct http_message *hm, endp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!macro)
 | 
					    if(!macro)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no macro with id found");
 | 
					        M_RESPONSE_404_NO_MACRO_FOUND_FOR_ID(response);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(macro_remove(macro))
 | 
					    if(macro_remove(macro))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to remove macro from database");
 | 
					        M_RESPONSE_500_FAILED_TO_DELETE_FROM_DATABASE(response);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "deleted macro");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "deleted macro");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    macro_free(macro);
 | 
					    macro_free(macro);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,5 +60,5 @@ api_v1_macros_STR_execute_PUT(struct mg_connection *nc, struct http_message *hm,
 | 
				
			||||||
    macro_action_free_list(macro_actions);
 | 
					    macro_action_free_list(macro_actions);
 | 
				
			||||||
    macro_free(macro);
 | 
					    macro_free(macro);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "macro got executed");
 | 
					    M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "macro got executed");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contain periods");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain periods");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one invalid tag");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one invalid tag");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -75,7 +75,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            schedule_free(new_schedule);
 | 
					            schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period without a start");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period without a start");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
 | 
					        if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
 | 
				
			||||||
| 
						 | 
					@ -83,7 +83,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            schedule_free(new_schedule);
 | 
					            schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period without an end");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period without an end");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            schedule_free(new_schedule);
 | 
					            schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid start");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid start");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
 | 
					        if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
 | 
				
			||||||
| 
						 | 
					@ -102,7 +102,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
				
			||||||
            cJSON_Delete(json);
 | 
					            cJSON_Delete(json);
 | 
				
			||||||
            schedule_free(new_schedule);
 | 
					            schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid end");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid end");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -201,7 +201,7 @@ api_v1_schedules_STR_DELETE(struct mg_connection *nc, struct http_message *hm, e
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "the target schedule got deleted");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "the target schedule got deleted");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    schedule_free(schedule);
 | 
					    schedule_free(schedule);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,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))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contain a name for at least one schedule");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain a name for at least one schedule");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,7 +36,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            cJSON_Delete(json_list);
 | 
					            cJSON_Delete(json_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contain periods for at least one schedule");
 | 
					            M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain periods for at least one schedule");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                cJSON_Delete(json_list);
 | 
					                cJSON_Delete(json_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one invalid tag");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one invalid tag");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -77,7 +77,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
                cJSON_Delete(json_list);
 | 
					                cJSON_Delete(json_list);
 | 
				
			||||||
                schedule_free(new_schedule);
 | 
					                schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period without a start");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period without a start");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
 | 
					            if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
 | 
				
			||||||
| 
						 | 
					@ -85,7 +85,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
                cJSON_Delete(json_list);
 | 
					                cJSON_Delete(json_list);
 | 
				
			||||||
                schedule_free(new_schedule);
 | 
					                schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period without an end");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period without an end");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +96,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
                cJSON_Delete(json_list);
 | 
					                cJSON_Delete(json_list);
 | 
				
			||||||
                schedule_free(new_schedule);
 | 
					                schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid start");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid start");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
 | 
					            if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
 | 
				
			||||||
| 
						 | 
					@ -104,7 +104,7 @@ api_v1_schedules_list_POST(struct mg_connection *nc, struct http_message *hm, en
 | 
				
			||||||
                cJSON_Delete(json_list);
 | 
					                cJSON_Delete(json_list);
 | 
				
			||||||
                schedule_free(new_schedule);
 | 
					                schedule_free(new_schedule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid end");
 | 
					                M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains at least one period with an invalid end");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ api_v1_tags_POST(struct mg_connection *nc, struct http_message *hm, endpoint_arg
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request does not contain a tag");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request does not contain a tag");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ api_v1_tags_POST(struct mg_connection *nc, struct http_message *hm, endpoint_arg
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the request contains an empty tag");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the request contains an empty tag");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,7 +71,7 @@ api_v1_tags_POST(struct mg_connection *nc, struct http_message *hm, endpoint_arg
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        cJSON_Delete(json);
 | 
					        cJSON_Delete(json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "the tag does already exist");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "the tag does already exist");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,6 +94,6 @@ api_v1_tags_STR_DELETE(struct mg_connection *nc, struct http_message *hm, endpoi
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "the tag got deleted");
 | 
					        M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "the tag got deleted");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,7 +84,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    endpoint_response_t response;
 | 
					    endpoint_response_t response;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    M_RESPONSE_TEXT_STATIC(LOGGER_NONE, &response, 500, "server did not create a response");
 | 
					    M_RESPONSE_MSG(LOGGER_NONE, &response, 500, "server did not create a response");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!endpoint)
 | 
					    if(!endpoint)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue