add: endpoint /tags
fix: leaks from config (now using static length for config strings)
This commit is contained in:
		
							parent
							
								
									0f1cd9c02c
								
							
						
					
					
						commit
						a78815cb32
					
				
					 10 changed files with 147 additions and 16 deletions
				
			
		
							
								
								
									
										35
									
								
								endpoints/api_v1_tags.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								endpoints/api_v1_tags.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
#include <cJSON.h>
 | 
			
		||||
#include <macros.h>
 | 
			
		||||
#include <constants.h>
 | 
			
		||||
#include <endpoints/api_v1_tags.h>
 | 
			
		||||
#include <logger.h>
 | 
			
		||||
#include <models/tag.h>
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
api_v1_tags_GET(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response)
 | 
			
		||||
{
 | 
			
		||||
    (void)args;
 | 
			
		||||
    (void)hm;
 | 
			
		||||
    (void)nc;
 | 
			
		||||
 | 
			
		||||
    char** all_tags = tag_get_all();
 | 
			
		||||
 | 
			
		||||
    cJSON *json = cJSON_CreateArray();
 | 
			
		||||
 | 
			
		||||
    for(int i = 0; all_tags[i] != NULL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        cJSON *json_tag = cJSON_CreateString(all_tags[i]);
 | 
			
		||||
        if (json_tag == NULL)
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("failed to add tag from string '%s'\n", all_tags[i]);
 | 
			
		||||
            free(all_tags[i]);
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_AddItemToArray(json, json_tag);
 | 
			
		||||
        free(all_tags[i]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    endpoint_response_json(response, 200, json);
 | 
			
		||||
    cJSON_Delete(json);
 | 
			
		||||
    free(all_tags);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue