Changeset 6 in Main for trunk/Server
- Timestamp:
- Sep 13, 2024, 7:28:20 PM (2 months ago)
- Location:
- trunk/Server
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/Makefile
r4 r6 11 11 12 12 tewi$(EXEC): $(OBJS) ../Common/common.a 13 $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) ../Common/common.a 13 $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) ../Common/common.a -lssl -lcrypto 14 14 15 15 .c.o: -
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; -
trunk/Server/main.c
r4 r6 4 4 #include <stdbool.h> 5 5 #include <string.h> 6 7 #include <openssl/opensslv.h> 6 8 7 9 #include <cm_log.h> … … 20 22 if(!cm_do_log) { 21 23 cm_do_log = true; 22 cm_log("", "This is Tewi HTTPd, version %s ", tw_get_version());24 cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT); 23 25 } else { 24 26 cm_do_log = true; 25 27 } 26 } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {28 } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) { 27 29 i++; 28 if(argv[i] == NULL) {30 if(argv[i] == NULL) { 29 31 fprintf(stderr, "Missing argument\n"); 30 32 return 1; … … 37 39 } 38 40 } 39 if(tw_config_read(config) != 0){ 41 tw_config_init(); 42 if(tw_config_read(config) != 0) { 40 43 fprintf(stderr, "Could not read the config\n"); 41 44 return 1; -
trunk/Server/tw_config.h
r4 r6 4 4 #define __TW_CONFIG_H__ 5 5 6 struct tw_config_entry {}; 7 8 struct tw_config { 9 struct tw_config_entry root; 10 }; 11 12 void tw_config_init(void); 6 13 int tw_config_read(const char* path); 7 14
Note:
See TracChangeset
for help on using the changeset viewer.