summaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/server.c b/server.c
index 9b9788b..25cfad7 100644
--- a/server.c
+++ b/server.c
@@ -203,9 +203,71 @@ bool
server_commit(struct cfg *cfg, struct server *scfg)
{
struct server_local *local;
+ uint16_t port;
+
+ if (!scfg || !scfg->name)
+ return false;
+
+ if (!list_empty(&scfg->proxys))
+ return false;
+
+ /* FIXME: running? */
+
+ switch (scfg->type) {
+ case SERVER_TYPE_ANNOUNCE:
+ if (scfg->announce_port < 1)
+ return false;
+ if (!list_empty(&scfg->locals))
+ return false;
+ if (!list_empty(&scfg->remotes))
+ return false;
+ break;
+
+ case SERVER_TYPE_PROXY:
+ if (scfg->announce_port >= 1)
+ return false;
+ if (list_empty(&scfg->locals))
+ return false;
+ if (list_empty(&scfg->remotes))
+ return false;
+
+ list_for_each_entry(local, &scfg->locals, list) {
+ port = sockaddr_port(&local->addr);
+
+ if (port == 0)
+ return false;
+
+ if (scfg->announce_port < 1)
+ scfg->announce_port = port;
+
+ if (scfg->announce_port != port) {
+ fprintf(stderr, "Multiple announce ports!?\n");
+ return false;
+ }
+ }
+
+ if (scfg->announce_port < 1)
+ return false;
+
+ break;
+
+ default:
+ return false;
+ }
+
+ if (!scfg->pretty_name) {
+ char *suffix;
+
+ suffix = strrchr(scfg->name, '.');
+ if (!suffix || suffix == scfg->name)
+ return false;
+
+ scfg->pretty_name = strndup(scfg->name, suffix - scfg->name);
+ if (!scfg->pretty_name)
+ return false;
+ }
/* FIXME: config, dont reread config if server running, make sure fd is available before this is called */
- /* FIXME: verify correct cfg */
server_dump(scfg);
list_for_each_entry(local, &scfg->locals, list) {
@@ -315,6 +377,11 @@ server_new(struct cfg *cfg, const char *name)
list_init(&scfg->remotes);
list_init(&scfg->locals);
list_init(&scfg->proxys);
+ memset(&scfg->mcast_iov, 0, sizeof(scfg->mcast_iov));
+ scfg->mcast_iov.iov_base = scfg->mcast_buf;
+ memset(&scfg->mcast_msg, 0, sizeof(scfg->mcast_msg));
+ scfg->mcast_msg.msg_iov = &scfg->mcast_iov;
+ scfg->mcast_msg.msg_iovlen = 1;
list_add(&scfg->list, &cfg->servers);
return scfg;