summaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c72
1 files changed, 63 insertions, 9 deletions
diff --git a/server.c b/server.c
index 3ea6d77..44779eb 100644
--- a/server.c
+++ b/server.c
@@ -19,6 +19,21 @@ struct server_local {
struct list_head list;
};
+static bool
+set_property(struct cfg *cfg, struct server *scfg, char **property, const char *value)
+{
+ if (!cfg || !scfg || empty_str(value) || *property)
+ return false;
+
+ *property = strdup(value);
+ if (!*property) {
+ perror("strdup");
+ return false;
+ }
+
+ return true;
+}
+
void
server_refdump(struct server *server)
{
@@ -42,6 +57,8 @@ server_free(struct uring_task *task)
fprintf(stderr, "Freeing scfg %s\n", scfg->name);
list_del(&scfg->list);
free(scfg->pretty_name);
+ free(scfg->start_exec);
+ free(scfg->stop_exec);
free(scfg->name);
free(scfg);
}
@@ -222,7 +239,10 @@ server_commit(struct cfg *cfg, struct server *scfg)
case SERVER_TYPE_ANNOUNCE:
if (scfg->announce_port < 1)
return false;
- if (scfg->idle_timeout > 0)
+ if (scfg->idle_timeout > 0 &&
+ scfg->stop_method == SERVER_STOP_METHOD_UNDEFINED)
+ return false;
+ if (scfg->start_method != SERVER_START_METHOD_UNDEFINED)
return false;
if (!list_empty(&scfg->locals))
return false;
@@ -233,6 +253,9 @@ server_commit(struct cfg *cfg, struct server *scfg)
case SERVER_TYPE_PROXY:
if (scfg->announce_port >= 1)
return false;
+ if (scfg->idle_timeout > 0 &&
+ scfg->stop_method == SERVER_STOP_METHOD_UNDEFINED)
+ return false;
if (list_empty(&scfg->locals))
return false;
if (list_empty(&scfg->remotes))
@@ -319,6 +342,42 @@ server_add_local(struct cfg *cfg, struct server *scfg, struct sockaddr_in46 *add
}
bool
+server_set_stop_method(struct cfg *cfg, struct server *scfg,
+ enum server_stop_method stop_method)
+{
+ if (scfg->stop_method != SERVER_STOP_METHOD_UNDEFINED ||
+ stop_method == SERVER_STOP_METHOD_UNDEFINED)
+ return false;
+
+ scfg->stop_method = stop_method;
+ return true;
+}
+
+bool
+server_set_start_method(struct cfg *cfg, struct server *scfg,
+ enum server_start_method start_method)
+{
+ if (scfg->start_method != SERVER_START_METHOD_UNDEFINED ||
+ start_method == SERVER_START_METHOD_UNDEFINED)
+ return false;
+
+ scfg->start_method = start_method;
+ return true;
+}
+
+bool
+server_set_stop_exec(struct cfg *cfg, struct server *scfg, const char *cmd)
+{
+ return set_property(cfg, scfg, &scfg->stop_exec, cmd);
+}
+
+bool
+server_set_start_exec(struct cfg *cfg, struct server *scfg, const char *cmd)
+{
+ return set_property(cfg, scfg, &scfg->start_exec, cmd);
+}
+
+bool
server_set_idle_timeout(struct cfg *cfg, struct server *scfg, uint16_t timeout)
{
if (!scfg || scfg->idle_timeout != 0)
@@ -361,14 +420,7 @@ server_set_type(struct cfg *cfg, struct server *scfg, enum server_type type)
bool
server_set_pretty_name(struct cfg *cfg, struct server *scfg, const char *pretty_name)
{
- if (!pretty_name || pretty_name[0] == '\0' || !scfg || scfg->pretty_name)
- return false;
-
- scfg->pretty_name = strdup(pretty_name);
- if (!scfg->pretty_name)
- return false;
-
- return true;
+ return set_property(cfg, scfg, &scfg->pretty_name, pretty_name);
}
struct server *
@@ -393,6 +445,8 @@ server_new(struct cfg *cfg, const char *name)
scfg->type = SERVER_TYPE_UNDEFINED;
scfg->name = strdup(name);
scfg->running = false;
+ scfg->stop_method = SERVER_STOP_METHOD_UNDEFINED;
+ scfg->start_method = SERVER_START_METHOD_UNDEFINED;
uring_task_init(&scfg->task, "scfg", uring_parent(cfg), server_free);
list_init(&scfg->remotes);
list_init(&scfg->locals);