Allow multiple ioset backends.
[srvx.git] / src / main.c
index e778f75f839bba854904100d98a327523f052710..fe73b4f64b88abd96b6fc902f59f54ad6b07fbef 100644 (file)
@@ -1,11 +1,12 @@
 /* main.c - srvx
- * Copyright 2000-2004 srvx Development Team
+ * Copyright 2000-2006 srvx Development Team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.  Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,7 +14,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, email srvx-maintainers@srvx.net.
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
 #define PID_FILE "srvx.pid"
@@ -82,7 +84,6 @@ static const struct message_entry msgtab[] = {
     { "MSG_COMMAND_PRIVILEGED", "$b%s$b is a privileged command." },
     { "MSG_COMMAND_DISABLED", "$b%s$b is a disabled command." },
     { "MSG_SETTING_PRIVILEGED", "$b%s$b is a privileged setting." },
-    { "MSG_REGISTER_HANDLE", "You must first register a account with $b$N$b." },
     { "MSG_AUTHENTICATE", "You must first authenticate with $b$N$b." },
     { "MSG_USER_AUTHENTICATE", "%s must first authenticate with $b$N$b." },
     { "MSG_SET_EMAIL_ADDR", "You must first set your account's email address.  (Contact network staff if you cannot auth to your account.)" },
@@ -94,6 +95,7 @@ static const struct message_entry msgtab[] = {
     { "MSG_INVALID_MODES", "$b%s$b is an invalid set of channel modes." },
     { "MSG_INVALID_GLINE", "Invalid G-line '%s'." },
     { "MSG_INVALID_DURATION", "Invalid time span '%s'." },
+    { "MSG_NOT_TARGET_NAME", "You must provide the name of a channel or user." },
     { "MSG_NOT_CHANNEL_NAME", "You must provide a valid channel name." },
     { "MSG_INVALID_CHANNEL", "You must provide the name of a channel that exists." },
     { "MSG_CHANNEL_ABSENT", "You aren't currently in $b%s$b." },
@@ -115,6 +117,20 @@ static const struct message_entry msgtab[] = {
     { "MSG_DB_WRITE_ERROR", "Error while writing database %s." },
     { "MSG_DB_WROTE_DB", "Wrote database %s (in "FMT_TIME_T".%06lu seconds)." },
     { "MSG_DB_WROTE_ALL", "Wrote all databases (in "FMT_TIME_T".%06lu seconds)." },
+    { "MSG_AND", "and" },
+    { "MSG_0_SECONDS", "0 seconds" },
+    { "MSG_YEAR", "year" },
+    { "MSG_YEARS", "years" },
+    { "MSG_WEEK", "week" },
+    { "MSG_WEEKS", "weeks" },
+    { "MSG_DAY", "day" },
+    { "MSG_DAYS", "days" },
+    { "MSG_HOUR", "hour" },
+    { "MSG_HOURS", "hours" },
+    { "MSG_MINUTE", "minute" },
+    { "MSG_MINUTES", "minutes" },
+    { "MSG_SECOND", "second" },
+    { "MSG_SECONDS", "seconds" },
     { NULL, NULL }
 };
 
@@ -125,10 +141,9 @@ uplink_insert(const char *key, void *data, UNUSED_ARG(void *extra))
 {
     struct uplinkNode *uplink = malloc(sizeof(struct uplinkNode));
     struct record_data *rd = data;
+    struct addrinfo hints, *ai;
     int enabled = 1;
     char *str;
-    struct sockaddr_in *sin;
-    unsigned long addr;
 
     if(!uplink)
     {
@@ -158,15 +173,17 @@ uplink_insert(const char *key, void *data, UNUSED_ARG(void *extra))
     uplink->tries = 0;
 
     str = database_get_data(rd->d.object, "bind_address", RECDB_QSTRING);
-    uplink->bind_addr_len = sizeof(*sin);
-    if (str && getipbyname(str, &addr)) 
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_flags = AI_PASSIVE;
+    hints.ai_socktype = SOCK_STREAM;
+    if (!getaddrinfo(str, NULL, &hints, &ai))
     {
-       sin = calloc(1, uplink->bind_addr_len);
-       sin->sin_family = AF_INET;
-       sin->sin_addr.s_addr = addr;
-       uplink->bind_addr = sin;
-    } 
-    else 
+        uplink->bind_addr_len = ai->ai_addrlen;
+       uplink->bind_addr = calloc(1, ai->ai_addrlen);
+        memcpy(uplink->bind_addr, ai->ai_addr, ai->ai_addrlen);
+        freeaddrinfo(ai);
+    }
+    else
     {
        uplink->bind_addr = NULL;
        uplink->bind_addr_len = 0;
@@ -549,12 +566,13 @@ conf_globals(void)
 static int
 set_item_rlimit(const char *name, void *data, void *extra)
 {
-    int rsrc, found;
+    long rsrc;
+    int found;
     struct record_data *rd = data;
     struct rlimit rlim;
     const char *str;
 
-    rsrc = (int)dict_find(extra, name, &found);
+    rsrc = (long)dict_find(extra, name, &found);
     if (!found) {
         log_module(MAIN_LOG, LOG_ERROR, "Invalid rlimit \"%s\" in rlimits section.", name);
         return 0;
@@ -639,7 +657,7 @@ void usage(char *self) {
 void version() {
     printf("    --------------------------------------------------\n"
            "    - "PACKAGE_STRING" ("CODENAME"), Built: " __DATE__ ", " __TIME__".\n"
-           "    - Copyright (C) 2000 - 2003, srvx Development Team\n"
+           "    - Copyright (C) 2000 - 2005, srvx Development Team\n"
            "    --------------------------------------------------\n");
 }
 
@@ -675,6 +693,12 @@ int main(int argc, char *argv[])
     FILE *file_out;
     struct sigaction sv;
 
+#if WITH_MALLOC_BOEHM_GC
+    GC_find_leak = 1;
+    GC_set_warn_proc(gc_warn_proc);
+    GC_enable_incremental();
+#endif
+
     daemon = 1;
     debug = 0;
     tools_init();
@@ -748,14 +772,6 @@ int main(int argc, char *argv[])
 
     version();
 
-#ifdef __CYGWIN__
-    if(daemon)
-    {
-       fprintf(stderr, "Daemon mode not supported under Cygwin.\n");
-       daemon = 0;
-    }
-#endif
-
     if (replay_file) {
         /* We read a line here to "prime" the replay file parser, but
          * mostly to get the right value of "now" for when we do the
@@ -808,24 +824,22 @@ int main(int argc, char *argv[])
     MAIN_LOG = log_register_type("srvx", "file:main.log");
     if (debug)
         log_debug();
-#if WITH_MALLOC_BOEHM_GC
-    GC_set_warn_proc(gc_warn_proc);
-    GC_enable_incremental();
-#endif
     timeq_init();
+    ioset_init();
     init_structs();
     init_parse();
     modcmd_init();
     saxdb_init();
     gline_init();
     sendmail_init();
+    helpfile_init();
     conf_globals(); /* initializes the core services */
     conf_rlimits();
     modules_init();
     message_register_table(msgtab);
     modcmd_finalize();
-    helpfile_finalize();
     saxdb_finalize();
+    helpfile_finalize();
     modules_finalize();
 
     /* The first exit func to be called *should* be saxdb_write_all(). */