Changeset 6 in Main for trunk/Server/config.c
- Timestamp:
- Sep 13, 2024, 7:28:20 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/config.c
r5 r6 10 10 #include <cm_log.h> 11 11 12 int tw_config_read(const char* path){ 12 struct tw_config config; 13 14 void tw_config_init(void) {} 15 16 int tw_config_read(const char* path) { 13 17 cm_log("Config", "Reading %s", path); 14 18 char cbuf[2]; 15 19 cbuf[1] = 0; 20 int ln = 0; 16 21 FILE* f = fopen(path, "r"); 17 if(f != NULL) {22 if(f != NULL) { 18 23 char* line = malloc(1); 19 24 line[0] = 0; 20 while(1){ 25 int stop = 0; 26 char* vhost = NULL; 27 while(stop == 0) { 21 28 int c = fread(cbuf, 1, 1, f); 22 if(cbuf[0] == '\n' || c <= 0){ 29 if(cbuf[0] == '\n' || c <= 0) { 30 ln++; 23 31 char* l = cm_trim(line); 24 if(strlen(l) > 0 && l[0] != '#') {32 if(strlen(l) > 0 && l[0] != '#') { 25 33 char** r = cm_split(l, " \t"); 26 34 int i; 27 if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")){ 28 for(i = 1; r[i] != NULL; i++){ 29 if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")){ 30 for(i = 0; r[i] != NULL; i++) free(r[i]); 31 free(r); 32 free(line); 33 free(l); 34 fclose(f); 35 return 1; 35 if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")) { 36 for(i = 1; r[i] != NULL; i++) { 37 if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")) { 38 stop = 1; 39 break; 36 40 } 37 41 } 42 } else if(cm_strcaseequ(r[0], "BeginVirtualHost")) { 43 if(vhost != NULL) { 44 cm_log("Config", "Already in virtual host section"); 45 stop = 1; 46 } else { 47 if(r[1] == NULL) { 48 cm_log("Config", "Missing virtual host"); 49 stop = 1; 50 } else { 51 vhost = cm_strdup(r[1]); 52 } 53 } 54 } else if(cm_strcaseequ(r[0], "EndVirtualHost")) { 55 if(vhost == NULL) { 56 cm_log("Config", "Not in virtual host section"); 57 stop = 1; 58 } else { 59 free(vhost); 60 vhost = NULL; 61 } 62 } else { 63 if(r[0] != NULL) { 64 cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln); 65 } 66 stop = 1; 38 67 } 39 68 for(i = 0; r[i] != NULL; i++) free(r[i]); … … 45 74 line[0] = 0; 46 75 if(c <= 0) break; 47 } else if(cbuf[0] != '\r'){76 } else if(cbuf[0] != '\r') { 48 77 char* tmp = line; 49 78 line = cm_strcat(tmp, cbuf); … … 53 82 free(line); 54 83 fclose(f); 55 return 0;56 } else{84 return stop; 85 } else { 57 86 cm_log("Config", "Could not open the file"); 58 87 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.