+void getmainconfig(const char *configfile) {
+ FILE *f;
+ char line[1024];
+ char *p, *opt, *endopt, *val, *endval;
+
+ printf("opening file %s for reading\n", configfile);
+ f = fopen(configfile, "r");
+ if (!f)
+ errx("getmainconfig failed to open %s for reading", configfile);
+
+ memset(&options, 0, sizeof(options));
+
+ while (fgets(line, 1024, f)) {
+ for (p = line; *p == ' ' || *p == '\t'; p++);
+ if (!*p || *p == '#' || *p == '\n')
+ continue;
+ opt = p++;
+ for (; *p && *p != ' ' && *p != '\t' && *p != '\n'; p++);
+ endopt = p - 1;
+ for (; *p == ' ' || *p == '\t'; p++);
+ if (!*p || *p == '\n') {
+ endopt[1] = '\0';
+ printf("error in %s, option %s has no value\n", configfile, opt);
+ exit(1);
+ }
+ val = p;
+ for (; *p && *p != '\n'; p++)
+ if (*p != ' ' && *p != '\t')
+ endval = p;
+ endopt[1] = '\0';
+ endval[1] = '\0';
+ printf("getmainconfig: %s = %s\n", opt, val);
+
+ if (!strcasecmp(opt, "TLSCertificateFile")) {
+ options.tlscertificatefile = stringcopy(val, 0);
+ continue;
+ }
+ if (!strcasecmp(opt, "TLSCertificateKeyFile")) {
+ options.tlscertificatekeyfile = stringcopy(val, 0);
+ continue;
+ }
+ if (!strcasecmp(opt, "UDPServerPort")) {
+ options.udpserverport = stringcopy(val, 0);
+ continue;
+ }
+
+ printf("error in %s, unknown option %s\n", configfile, opt);
+ exit(1);
+ }
+ fclose(f);
+
+ if (!options.udpserverport)
+ options.udpserverport = stringcopy(DEFAULT_UDP_PORT, 0);
+}
+
+#if 0