Add active field to service configuration

- Add 'active' field to service_config_t structure (defaults to true)
- Parse 'active' field from service config files (accepts true/1/yes)
- Skip inactive services during service loading
- Maintain backward compatibility with existing configs
parent bff16845
...@@ -68,6 +68,7 @@ typedef struct { ...@@ -68,6 +68,7 @@ typedef struct {
char *tunnel_host; char *tunnel_host;
char *command; char *command;
char *proto; // "tcp" or "udp", default "tcp" char *proto; // "tcp" or "udp", default "tcp"
int active; // Whether this service is active, default true
} service_config_t; } service_config_t;
// Thread arguments // Thread arguments
......
...@@ -298,6 +298,7 @@ service_config_t *load_service_config(const char *config_path) { ...@@ -298,6 +298,7 @@ service_config_t *load_service_config(const char *config_path) {
char line[256]; char line[256];
char current_section[256] = ""; char current_section[256] = "";
int in_service_section = 0; int in_service_section = 0;
int active_parsed = 0; // Track if active was explicitly parsed
while (fgets(line, sizeof(line), file)) { while (fgets(line, sizeof(line), file)) {
line[strcspn(line, "\n")] = 0; line[strcspn(line, "\n")] = 0;
...@@ -328,6 +329,9 @@ service_config_t *load_service_config(const char *config_path) { ...@@ -328,6 +329,9 @@ service_config_t *load_service_config(const char *config_path) {
service->command = strdup(value); service->command = strdup(value);
} else if (strcmp(key, "proto") == 0 && !service->proto) { } else if (strcmp(key, "proto") == 0 && !service->proto) {
service->proto = strdup(value); service->proto = strdup(value);
} else if (strcmp(key, "active") == 0) {
service->active = (strcmp(value, "true") == 0 || strcmp(value, "1") == 0 || strcmp(value, "yes") == 0);
active_parsed = 1;
} }
} }
} }
...@@ -338,6 +342,10 @@ service_config_t *load_service_config(const char *config_path) { ...@@ -338,6 +342,10 @@ service_config_t *load_service_config(const char *config_path) {
if (!service->proto) { if (!service->proto) {
service->proto = strdup("tcp"); service->proto = strdup("tcp");
} }
// active defaults to true if not specified
if (!active_parsed) {
service->active = 1; // Default to true
}
return service; return service;
} }
...@@ -391,7 +399,7 @@ service_config_t **load_services_config(const char *services_path, int *num_serv ...@@ -391,7 +399,7 @@ service_config_t **load_services_config(const char *services_path, int *num_serv
// Check if file is readable // Check if file is readable
if (access(full_path, R_OK) == 0) { if (access(full_path, R_OK) == 0) {
service_config_t *service = load_service_config(full_path); service_config_t *service = load_service_config(full_path);
if (service && service->name) { if (service && service->name && service->active) {
// Check for duplicate service names (later definitions override earlier ones) // Check for duplicate service names (later definitions override earlier ones)
int duplicate = 0; int duplicate = 0;
for (int i = 0; i < *num_services; i++) { for (int i = 0; i < *num_services; i++) {
...@@ -412,13 +420,12 @@ service_config_t **load_services_config(const char *services_path, int *num_serv ...@@ -412,13 +420,12 @@ service_config_t **load_services_config(const char *services_path, int *num_serv
(*num_services)++; (*num_services)++;
} else { } else {
// Free service if realloc failed // Free service if realloc failed
free(service->name); free_service_config(service);
free(service->tunnel_host);
free(service->command);
free(service->proto);
free(service);
} }
} }
} else if (service && service->name && !service->active) {
// Service is inactive, skip it
free_service_config(service);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment