+ yy_opm_timeout = timeout;
+}
+
+static void
+conf_set_opm_listen_address_both(void *data, bool ipv6)
+{
+ struct rb_sockaddr_storage addr;
+ const char *confstr = (ipv6 ? "opm::listen_ipv6" : "opm::listen_ipv4");
+ char *ip = data;
+
+ if(!rb_inet_pton_sock(ip, &addr))
+ {
+ conf_report_error("%s is an invalid address: %s", confstr, ip);
+ return;
+ }
+
+ if(ipv6)
+ {
+ if(GET_SS_FAMILY(&addr) != AF_INET6)
+ {
+ conf_report_error("%s is of the wrong address type: %s", confstr, ip);
+ return;
+ }
+
+ if(yy_opm_address_ipv6 != NULL)
+ {
+ conf_report_error("%s overwrites previous address %s", confstr, ip);
+ return;
+ }
+
+ yy_opm_address_ipv6 = rb_strdup(ip);
+ }
+ else
+ {
+ if(GET_SS_FAMILY(&addr) != AF_INET)
+ {
+ conf_report_error("%s is of the wrong address type: %s", confstr, ip);
+ return;
+ }
+
+ if(yy_opm_address_ipv4 != NULL)
+ {
+ conf_report_error("%s overwrites previous address %s", confstr, ip);
+ return;
+ }
+
+ yy_opm_address_ipv4 = rb_strdup(ip);
+ }
+}
+
+static void
+conf_set_opm_listen_address_ipv4(void *data)
+{
+ conf_set_opm_listen_address_both(data, false);
+}
+
+static void
+conf_set_opm_listen_address_ipv6(void *data)
+{
+ conf_set_opm_listen_address_both(data, true);
+}
+
+static void
+conf_set_opm_listen_port_both(void *data, bool ipv6)
+{
+ int port = *((int *)data);
+ const char *confstr = (ipv6 ? "opm::port_ipv6" : "opm::port_ipv4");
+
+ if(port > 65535 || port <= 0)
+ {
+ conf_report_error("%s is out of range: %d", confstr, port);
+ return;
+ }
+
+ if(ipv6)
+ {
+ if(yy_opm_port_ipv4)
+ {
+ conf_report_error("%s overwrites existing port %hu",
+ confstr, yy_opm_port_ipv4);
+ return;
+ }
+
+ yy_opm_port_ipv4 = port;
+ }
+ else
+ {
+ if(yy_opm_port_ipv6)
+ {
+ conf_report_error("%s overwrites existing port %hu",
+ confstr, yy_opm_port_ipv6);
+ return;
+ }
+
+ yy_opm_port_ipv6 = port;
+ }
+}
+
+static void
+conf_set_opm_listen_port_ipv4(void *data)
+{
+ conf_set_opm_listen_port_both(data, false);
+}
+
+static void
+conf_set_opm_listen_port_ipv6(void *data)
+{
+ conf_set_opm_listen_port_both(data, true);
+}
+
+static void
+conf_set_opm_listen_port(void *data)
+{
+ conf_set_opm_listen_port_both(data, true);
+ conf_set_opm_listen_port_both(data, false);
+}
+
+static void
+conf_set_opm_scan_ports_all(void *data, const char *node, const char *type)
+{
+ conf_parm_t *args = data;
+ for (; args; args = args->next)
+ {
+ rb_dlink_node *ptr;
+ bool dup = false;
+
+ if(CF_TYPE(args->type) != CF_INT)
+ {
+ conf_report_error("%s argument is not an integer -- ignoring.", node);
+ continue;
+ }
+
+ if(args->v.number > 65535 || args->v.number <= 0)
+ {
+ conf_report_error("%s argument is not an integer between 1 and 65535 -- ignoring.", node);
+ continue;
+ }
+
+ /* Check for duplicates */
+ RB_DLINK_FOREACH(ptr, yy_opm_scanner_list.head)
+ {
+ struct opm_scanner *scanner = ptr->data;
+
+ if(scanner->port == args->v.number && strcmp(type, scanner->type) == 0)
+ {
+ conf_report_error("%s argument is duplicate", node);
+ dup = true;
+ break;
+ }
+ }
+
+ if(!dup)
+ {
+ struct opm_scanner *scanner = rb_malloc(sizeof(struct opm_scanner));
+ scanner->port = args->v.number;
+ scanner->type = type;
+ rb_dlinkAdd(scanner, &scanner->node, &yy_opm_scanner_list);
+ }
+ }
+}
+
+static void
+conf_set_opm_scan_ports_socks4(void *data)
+{
+ conf_set_opm_scan_ports_all(data, "opm::socks4_ports", "socks4");
+}
+
+static void
+conf_set_opm_scan_ports_socks5(void *data)
+{
+ conf_set_opm_scan_ports_all(data, "opm::socks5_ports", "socks5");
+}
+
+static void
+conf_set_opm_scan_ports_httpconnect(void *data)
+{
+ conf_set_opm_scan_ports_all(data, "opm::httpconnect_ports", "httpconnect");
+}
+
+static void
+conf_set_opm_scan_ports_httpsconnect(void *data)
+{
+ conf_set_opm_scan_ports_all(data, "opm::httpsconnect_ports", "httpsconnect");