diff sip-in/readconf.c @ 89:e64d4d44025d

sip-in/readconf.c: first step toward non-trivial settings
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 23 Sep 2022 18:51:42 -0800
parents 709b78a4ebf0
children 736c2d68595f
line wrap: on
line diff
--- a/sip-in/readconf.c	Wed Sep 21 07:58:16 2022 -0800
+++ b/sip-in/readconf.c	Fri Sep 23 18:51:42 2022 -0800
@@ -28,11 +28,35 @@
 };
 
 static void
+require_one_arg(st, kw, arg)
+	struct parse_state *st;
+	char *kw, *arg;
+{
+	char *cp;
+
+	if (*arg == '\0' || *arg == '#') {
+inv_syntax:	fprintf(stderr,
+			"%s line %d: %s setting requires one argument\n",
+			config_file_pathname, st->lineno, kw);
+		exit(1);
+	}
+	for (cp = arg; *cp && !isspace(*cp); cp++)
+		;
+	if (*cp)
+		*cp++ = '\0';
+	while (isspace(*cp))
+		cp++;
+	if (*cp != '\0' && *cp != '#')
+		goto inv_syntax;
+}
+
+static void
 handle_ip(st, kw, var, arg)
 	struct parse_state *st;
 	char *kw, *arg;
 	struct in_addr *var;
 {
+	require_one_arg(st, kw, arg);
 	var->s_addr = inet_addr(arg);
 	if (var->s_addr == INADDR_NONE) {
 		fprintf(stderr,
@@ -50,6 +74,7 @@
 {
 	char *endp;
 
+	require_one_arg(st, kw, arg);
 	*var = strtoul(arg, &endp, 10);
 	if (*endp) {
 		fprintf(stderr, "%s line %d: invalid numeric argument \"%s\"\n",
@@ -64,6 +89,7 @@
 	char *kw, *arg;
 	int *var;
 {
+	require_one_arg(st, kw, arg);
 	if (!strcmp(arg, "true") || !strcmp(arg, "on") || !strcmp(arg, "yes")
 	    || !strcmp(arg, "1")) {
 		*var = 1;
@@ -84,7 +110,7 @@
 	struct parse_state *st;
 	char *line;
 {
-	char *cp, *np, *arg;
+	char *cp, *kw;
 	void (*handler)(), *var;
 	int set_id;
 
@@ -97,49 +123,35 @@
 		;
 	if (*cp == '\0' || *cp == '#')
 		return;
-	for (np = cp; *cp && !isspace(*cp); cp++)
+	for (kw = cp; *cp && !isspace(*cp); cp++)
 		;
 	if (*cp)
 		*cp++ = '\0';
-	if (!strcmp(np, "bind-ip")) {
+	if (!strcmp(kw, "bind-ip")) {
 		handler = handle_ip;
 		var = &sip_bind_ip;
 		set_id = 1;
-	} else if (!strcmp(np, "bind-port")) {
+	} else if (!strcmp(kw, "bind-port")) {
 		handler = handle_num;
 		var = &sip_bind_port;
 		set_id = 2;
-	} else if (!strcmp(np, "use-100rel")) {
+	} else if (!strcmp(kw, "use-100rel")) {
 		handler = handle_bool;
 		var = &cfg_use_100rel;
 		set_id = 0;
 	} else {
 		fprintf(stderr, "%s line %d: non-understood keyword \"%s\"\n",
-			config_file_pathname, st->lineno, np);
+			config_file_pathname, st->lineno, kw);
 		exit(1);
 	}
 	if (st->set_mask & set_id) {
 		fprintf(stderr, "%s line %d: duplicate %s setting\n",
-			config_file_pathname, st->lineno, np);
+			config_file_pathname, st->lineno, kw);
 		exit(1);
 	}
 	while (isspace(*cp))
 		cp++;
-	if (*cp == '\0' || *cp == '#') {
-inv_syntax:	fprintf(stderr,
-			"%s line %d: %s setting requires one argument\n",
-			config_file_pathname, st->lineno, np);
-		exit(1);
-	}
-	for (arg = cp; *cp && !isspace(*cp); cp++)
-		;
-	if (*cp)
-		*cp++ = '\0';
-	while (isspace(*cp))
-		cp++;
-	if (*cp != '\0' && *cp != '#')
-		goto inv_syntax;
-	handler(st, np, var, arg);
+	handler(st, kw, var, cp);
 	st->set_mask |= set_id;
 }