add: test
add: period filters fix: invalid reads (lost invalid json debug output)
This commit is contained in:
		
							parent
							
								
									f2a40ca330
								
							
						
					
					
						commit
						2d992cfe3c
					
				
					 6 changed files with 181 additions and 32 deletions
				
			
		| 
						 | 
				
			
			@ -106,13 +106,6 @@ api_v1_controllers_STR_PUT(struct http_message *hm, endpoint_args_t *args, endpo
 | 
			
		|||
 | 
			
		||||
    if(json == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        const char *error_ptr = cJSON_GetErrorPtr();
 | 
			
		||||
        if (error_ptr != NULL)
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("error before: %s\n", error_ptr);
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "no valid json was supplied";
 | 
			
		||||
        response->status_code = 400;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -147,13 +147,6 @@ api_v1_controllers_STR_relays_INT_PUT(struct http_message *hm, endpoint_args_t *
 | 
			
		|||
 | 
			
		||||
    if(json == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        const char *error_ptr = cJSON_GetErrorPtr();
 | 
			
		||||
        if (error_ptr != NULL)
 | 
			
		||||
        {
 | 
			
		||||
            LOG_ERROR("error before: %s\n", error_ptr);
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "no valid json was supplied";
 | 
			
		||||
        response->status_code = 400;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,13 +15,6 @@ api_v1_schedules_POST(struct http_message *hm, endpoint_args_t *args, endpoint_r
 | 
			
		|||
 | 
			
		||||
    if(json == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        const char *error_ptr = cJSON_GetErrorPtr();
 | 
			
		||||
        if (error_ptr != NULL)
 | 
			
		||||
        {
 | 
			
		||||
            LOG_ERROR("error before: %s\n", error_ptr);
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "no valid json was supplied";
 | 
			
		||||
        response->status_code = 400;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
| 
						 | 
				
			
			@ -69,12 +62,30 @@ api_v1_schedules_POST(struct http_message *hm, endpoint_args_t *args, endpoint_r
 | 
			
		|||
        if(!cJSON_IsString(json_period_start) || (json_period_start->valuestring == NULL))
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("period is missing start\n");
 | 
			
		||||
            continue;
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
            schedule_free(new_schedule);
 | 
			
		||||
 | 
			
		||||
            static const char content[] = "one period is missing a start";
 | 
			
		||||
            response->status_code = 400;
 | 
			
		||||
            response->content_type = "text/plain";
 | 
			
		||||
            response->content_length = STRLEN(content);;
 | 
			
		||||
            response->content = content;
 | 
			
		||||
            response->alloced_content = false;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if(!cJSON_IsString(json_period_end) || (json_period_end->valuestring == NULL))
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("period is missing end\n");
 | 
			
		||||
            continue;
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
            schedule_free(new_schedule);
 | 
			
		||||
 | 
			
		||||
            static const char content[] = "one period is missing an end";
 | 
			
		||||
            response->status_code = 400;
 | 
			
		||||
            response->content_type = "text/plain";
 | 
			
		||||
            response->content_length = STRLEN(content);;
 | 
			
		||||
            response->content = content;
 | 
			
		||||
            response->alloced_content = false;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        uint16_t start;
 | 
			
		||||
| 
						 | 
				
			
			@ -82,12 +93,30 @@ api_v1_schedules_POST(struct http_message *hm, endpoint_args_t *args, endpoint_r
 | 
			
		|||
        if(period_helper_parse_hhmm(json_period_start->valuestring, &start))
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("couldn't parse start '%s'\n", json_period_start->valuestring);
 | 
			
		||||
            continue;
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
            schedule_free(new_schedule);
 | 
			
		||||
 | 
			
		||||
            static const char content[] = "the start for one period is invalid";
 | 
			
		||||
            response->status_code = 400;
 | 
			
		||||
            response->content_type = "text/plain";
 | 
			
		||||
            response->content_length = STRLEN(content);;
 | 
			
		||||
            response->content = content;
 | 
			
		||||
            response->alloced_content = false;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if(period_helper_parse_hhmm(json_period_end->valuestring, &end))
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("couldn't parse end '%s'\n", json_period_end->valuestring);
 | 
			
		||||
            continue;
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
            schedule_free(new_schedule);
 | 
			
		||||
 | 
			
		||||
            static const char content[] = "the end for one period is invalid";
 | 
			
		||||
            response->status_code = 400;
 | 
			
		||||
            response->content_type = "text/plain";
 | 
			
		||||
            response->content_length = STRLEN(content);;
 | 
			
		||||
            response->content = content;
 | 
			
		||||
            response->alloced_content = false;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        new_schedule->periods[periods_valid].start = start;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,13 +108,6 @@ api_v1_schedules_STR_PUT(struct http_message *hm, endpoint_args_t *args, endpoin
 | 
			
		|||
 | 
			
		||||
    if(json == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        const char *error_ptr = cJSON_GetErrorPtr();
 | 
			
		||||
        if (error_ptr != NULL)
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("error before: %s\n", error_ptr);
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "no valid json was supplied";
 | 
			
		||||
        response->status_code = 400;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue