add: content_dir config
This commit is contained in:
		
							parent
							
								
									ab02ebc238
								
							
						
					
					
						commit
						77b2fafaff
					
				
					 6 changed files with 14 additions and 3 deletions
				
			
		| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
cmake_minimum_required (VERSION 3.7)
 | 
					cmake_minimum_required (VERSION 3.7)
 | 
				
			||||||
project(core
 | 
					project(core
 | 
				
			||||||
        VERSION 0.2.1
 | 
					        VERSION 0.2.2
 | 
				
			||||||
        LANGUAGES C)
 | 
					        LANGUAGES C)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_executable(core src/main.c)
 | 
					add_executable(core src/main.c)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								core.ini
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								core.ini
									
										
									
									
									
								
							| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
[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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,7 @@ typedef struct
 | 
				
			||||||
    uint16_t server_port;
 | 
					    uint16_t server_port;
 | 
				
			||||||
    uint16_t discovery_port;
 | 
					    uint16_t discovery_port;
 | 
				
			||||||
    uint16_t mqtt_port;
 | 
					    uint16_t mqtt_port;
 | 
				
			||||||
 | 
					    char content_dir[1024];
 | 
				
			||||||
    char not_found_file[256];
 | 
					    char not_found_file[256];
 | 
				
			||||||
    char not_found_file_type[256];
 | 
					    char not_found_file_type[256];
 | 
				
			||||||
    char not_found_content[256];
 | 
					    char not_found_content[256];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,6 +69,11 @@ config_load(IniDispatch *disp, void *config_void)
 | 
				
			||||||
            strcpy(config->group, disp->value);
 | 
					            strcpy(config->group, disp->value);
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if(CONFINI_IS_KEY("core", "content-dir"))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strcpy(config->content_dir, disp->value);
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if(CONFINI_IS_KEY("core", "not-found-file"))
 | 
					        if(CONFINI_IS_KEY("core", "not-found-file"))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            strcpy(config->not_found_file, disp->value);
 | 
					            strcpy(config->not_found_file, disp->value);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,7 +107,10 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        LOG_DEBUG("%s\n", request_file);
 | 
					        LOG_DEBUG("%s\n", request_file);
 | 
				
			||||||
        int access_result = access(request_file, R_OK);
 | 
					        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);
 | 
				
			||||||
 | 
					        int access_result = access(request_file_path, R_OK);
 | 
				
			||||||
 | 
					        free(request_file_path);
 | 
				
			||||||
        free(request_file_org);
 | 
					        free(request_file_org);
 | 
				
			||||||
        if(access_result != -1)
 | 
					        if(access_result != -1)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,6 +59,7 @@ main(int argc, const char** argv)
 | 
				
			||||||
    strcpy(global_config.user, "");
 | 
					    strcpy(global_config.user, "");
 | 
				
			||||||
    strcpy(global_config.group, "");
 | 
					    strcpy(global_config.group, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strcpy(global_config.content_dir, ".");
 | 
				
			||||||
    strcpy(global_config.not_found_file, "404.html");
 | 
					    strcpy(global_config.not_found_file, "404.html");
 | 
				
			||||||
    strcpy(global_config.not_found_file_type, "text/html");
 | 
					    strcpy(global_config.not_found_file_type, "text/html");
 | 
				
			||||||
    strcpy(global_config.not_found_content, "404 - NOT FOUND");
 | 
					    strcpy(global_config.not_found_content, "404 - NOT FOUND");
 | 
				
			||||||
| 
						 | 
					@ -81,7 +82,7 @@ main(int argc, const char** argv)
 | 
				
			||||||
    fclose(ini_file);
 | 
					    fclose(ini_file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset(&global_config.http_server_opts, 0, sizeof(global_config.http_server_opts));
 | 
					    memset(&global_config.http_server_opts, 0, sizeof(global_config.http_server_opts));
 | 
				
			||||||
    global_config.http_server_opts.document_root = ".";  // Serve current directory
 | 
					    global_config.http_server_opts.document_root = global_config.content_dir;
 | 
				
			||||||
    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: *";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue