Changeset 12 in Main for trunk/Server/config.c
- Timestamp:
- Sep 13, 2024, 10:36:03 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/config.c
r7 r12 7 7 #include <stdlib.h> 8 8 #include <string.h> 9 #include <unistd.h> 9 10 10 11 #include <cm_string.h> … … 13 14 struct tw_config config; 14 15 16 struct tw_config_entry* tw_vhost_match(const char* name, int port) { 17 int i; 18 for(i = 0; i < config.vhost_count; i++) { 19 if(strcmp(config.vhosts[i].name, name) == 0 && config.vhosts[i].port == port) { 20 return &config.vhosts[i]; 21 } 22 } 23 return &config.root; 24 } 25 15 26 void tw_config_init(void) { 16 27 int i; … … 18 29 config.ports[i] = -1; 19 30 } 31 for(i = 0; i < MAX_VHOSTS; i++) { 32 config.vhosts[i].sslkey = NULL; 33 config.vhosts[i].sslcert = NULL; 34 } 35 config.root.sslkey = NULL; 36 config.root.sslcert = NULL; 37 config.vhost_count = 0; 38 gethostname(config.hostname, 1024); 20 39 } 21 40 … … 30 49 line[0] = 0; 31 50 int stop = 0; 51 struct tw_config_entry* current = &config.root; 32 52 char* vhost = NULL; 33 53 while(stop == 0) { … … 48 68 } else if(cm_strcaseequ(r[0], "BeginVirtualHost")) { 49 69 if(vhost != NULL) { 50 cm_log("Config", "Already in virtual host section ");70 cm_log("Config", "Already in virtual host section at line %d", ln); 51 71 stop = 1; 52 72 } else { 53 73 if(r[1] == NULL) { 54 cm_log("Config", "Missing virtual host ");74 cm_log("Config", "Missing virtual host at line %d", ln); 55 75 stop = 1; 56 76 } else { 57 77 vhost = cm_strdup(r[1]); 78 current = &config.vhosts[config.vhost_count++]; 79 int i; 80 current->name = cm_strdup(vhost); 81 current->port = 80; 82 for(i = 0; vhost[i] != 0; i++) { 83 if(vhost[i] == ':') { 84 current->name[i] = 0; 85 current->port = atoi(current->name + i + 1); 86 break; 87 } 88 } 58 89 } 59 90 } 60 91 } else if(cm_strcaseequ(r[0], "EndVirtualHost")) { 61 92 if(vhost == NULL) { 62 cm_log("Config", "Not in virtual host section ");93 cm_log("Config", "Not in virtual host section at line %d", ln); 63 94 stop = 1; 64 95 } else { 65 96 free(vhost); 66 97 vhost = NULL; 98 current = &config.root; 67 99 } 68 100 } else if(cm_strcaseequ(r[0], "Listen") || cm_strcaseequ(r[0], "ListenSSL")) { … … 75 107 ; 76 108 config.ports[j] = port; 109 } 110 } else if(cm_strcaseequ(r[0], "SSLKey")) { 111 if(r[1] == NULL) { 112 cm_log("Config", "Missing path at line %d", ln); 113 stop = 1; 114 } else { 115 if(current->sslkey != NULL) free(current->sslkey); 116 current->sslkey = cm_strdup(r[1]); 117 } 118 } else if(cm_strcaseequ(r[0], "SSLCertificate")) { 119 if(r[1] == NULL) { 120 cm_log("Config", "Missing path at line %d", ln); 121 stop = 1; 122 } else { 123 if(current->sslcert != NULL) free(current->sslcert); 124 current->sslcert = cm_strdup(r[1]); 77 125 } 78 126 } else {
Note:
See TracChangeset
for help on using the changeset viewer.