Browse Source

* Fixed some bugs with the new conf/binary loading

svn: 1306
Bryan Drewery 22 years ago
parent
commit
21c030d791
2 changed files with 60 additions and 49 deletions
  1. 9 1
      src/binary.c
  2. 51 48
      src/conf.c

+ 9 - 1
src/binary.c

@@ -352,10 +352,18 @@ void write_settings(const char *fname, int die)
     exit(0);
     exit(0);
 }
 }
 
 
+static void 
+clear_settings(void)
+{
+  memset(&settings.bots, 0, sizeof(settings_t) - 3467);
+}
+
 void conf_to_bin(conf_t *in)
 void conf_to_bin(conf_t *in)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
-  printf("converting conf to bin\n");
+  
+  clear_settings();
+  sdprintf("converting conf to bin\n");
   sprintf(settings.uid, "%d", in->uid);
   sprintf(settings.uid, "%d", in->uid);
   sprintf(settings.watcher, "%d", in->watcher);
   sprintf(settings.watcher, "%d", in->watcher);
   sprintf(settings.autocron, "%d", in->autocron);
   sprintf(settings.autocron, "%d", in->autocron);

+ 51 - 48
src/conf.c

@@ -27,6 +27,31 @@ char cfile[DIRMAX] = "";
 conf_t conf;                    /* global conf struct */
 conf_t conf;                    /* global conf struct */
 conf_t conffile;                /* just some config options only avail during loading */
 conf_t conffile;                /* just some config options only avail during loading */
 
 
+static void
+tellconf(conf_t * inconf)
+{
+  conf_bot *bot;
+  int i = 0;
+
+  sdprintf("uid: %d\n", inconf->uid);
+  sdprintf("homedir: %s\n", inconf->homedir);
+  sdprintf("binpath: %s\n", inconf->binpath);
+  sdprintf("binname: %s\n", inconf->binname);
+  sdprintf("portmin: %d\n", inconf->portmin);
+  sdprintf("portmax: %d\n", inconf->portmax);
+  sdprintf("pscloak: %d\n", inconf->pscloak);
+  sdprintf("autocron: %d\n", inconf->autocron);
+  sdprintf("autouname: %d\n", inconf->autouname);
+  sdprintf("watcher: %d\n", inconf->watcher);
+  for (bot = inconf->bots; bot && bot->nick; bot = bot->next) {
+    i++;
+    sdprintf("%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
+             bot->nick,
+             bot->ip ? bot->ip : "",
+             bot->host ? bot->host : "", bot->ip6 ? bot->ip6 : "", bot->host6 ? bot->host6 : "", bot->pid);
+  }
+}
+
 #ifdef LEAF
 #ifdef LEAF
 void
 void
 spawnbots()
 spawnbots()
@@ -186,7 +211,7 @@ confedit()
 #  else
 #  else
               WCOREDUMP(waiter)
               WCOREDUMP(waiter)
 #  endif
 #  endif
-       /* CYGWIN_HACKS */
+              /* CYGWIN_HACKS */
               ? "" : "no ");
               ? "" : "no ");
       goto fatal;
       goto fatal;
     } else {
     } else {
@@ -201,11 +226,10 @@ confedit()
 
 
   if (!can_stat(s))
   if (!can_stat(s))
     fatal("Error reading new config file", 0);
     fatal("Error reading new config file", 0);
-
-  readconf(s, 0);	/* read cleartext conf tmp into &settings */
+  readconf(s, 0);               /* read cleartext conf tmp into &settings */
   unlink(s);
   unlink(s);
-  conf_to_bin(&conffile);	/* will exit */
-  exit(0);	/* never reached */
+  conf_to_bin(&conffile);       /* will exit */
+  exit(0);                      /* never reached */
 
 
 fatal:
 fatal:
   unlink(s);
   unlink(s);
@@ -308,8 +332,8 @@ checkpid(char *nick, conf_bot * bot)
 
 
 #ifdef HUB
 #ifdef HUB
 static
 static
-#endif /* HUB */
-void
+#endif                          /* HUB */
+  void
 conf_addbot(char *nick, char *ip, char *host, char *ip6)
 conf_addbot(char *nick, char *ip, char *host, char *ip6)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
@@ -351,7 +375,7 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
   bot->pid = checkpid(nick, bot);
   bot->pid = checkpid(nick, bot);
 }
 }
 
 
-void 
+void
 free_bot(char *botn)
 free_bot(char *botn)
 {
 {
   conf_bot *bot = NULL, *old = NULL;
   conf_bot *bot = NULL, *old = NULL;
@@ -385,9 +409,9 @@ int
 conf_delbot(char *botn)
 conf_delbot(char *botn)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
-  
+
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
-    if (!strcmp(bot->nick, botn)) { /* found it! */
+    if (!strcmp(bot->nick, botn)) {     /* found it! */
       bot->pid = checkpid(bot->nick, bot);
       bot->pid = checkpid(bot->nick, bot);
       killbot(bot->nick);
       killbot(bot->nick);
       free_bot(bot->nick);
       free_bot(bot->nick);
@@ -398,8 +422,8 @@ conf_delbot(char *botn)
 }
 }
 #endif /* LEAF */
 #endif /* LEAF */
 
 
-void
-free_conf()
+static void
+free_conf_bots(void)
 {
 {
   conf_bot *bot = NULL, *bot_n = NULL;
   conf_bot *bot = NULL, *bot_n = NULL;
 
 
@@ -407,6 +431,11 @@ free_conf()
     bot_n = bot->next;
     bot_n = bot->next;
     free_bot(bot->nick);
     free_bot(bot->nick);
   }
   }
+}
+
+void free_conf(void)
+{
+  free_conf_bots();
   free(conffile.uname);
   free(conffile.uname);
   free(conffile.username);
   free(conffile.username);
   free(conffile.homedir);
   free(conffile.homedir);
@@ -476,6 +505,7 @@ readconf(char *fname, int bits)
   if (!(f = fopen(fname, "r")))
   if (!(f = fopen(fname, "r")))
     fatal("Cannot read config", 0);
     fatal("Cannot read config", 0);
 
 
+  free_conf_bots();
   inbuf = calloc(1, 201);
   inbuf = calloc(1, 201);
   while (fgets(inbuf, 201, f) != NULL) {
   while (fgets(inbuf, 201, f) != NULL) {
     char *line = NULL, *temp_ptr = NULL;
     char *line = NULL, *temp_ptr = NULL;
@@ -525,7 +555,7 @@ readconf(char *fname, int bits)
         if (!strcmp(option, "autocron")) {      /* automatically check/create crontab? */
         if (!strcmp(option, "autocron")) {      /* automatically check/create crontab? */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
             conffile.autocron = atoi(line);
             conffile.autocron = atoi(line);
-       
+
         } else if (!strcmp(option, "autouname")) {      /* auto update uname contents? */
         } else if (!strcmp(option, "autouname")) {      /* auto update uname contents? */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
             conffile.autouname = atoi(line);
             conffile.autouname = atoi(line);
@@ -665,7 +695,8 @@ writeconf(char *filename, FILE * stream, int bits)
   } else
   } else
     my_write(f, "! binpath %s\n", conffile.binpath);
     my_write(f, "! binpath %s\n", conffile.binpath);
 
 
-  comment("# binname is relative to binpath, if you change this, you'll need to manually remove the old one from crontab.");
+  comment
+    ("# binname is relative to binpath, if you change this, you'll need to manually remove the old one from crontab.");
   my_write(f, "! binname %s\n", conffile.binname);
   my_write(f, "! binname %s\n", conffile.binname);
 
 
   comment("");
   comment("");
@@ -703,7 +734,8 @@ writeconf(char *filename, FILE * stream, int bits)
 #endif /* CYGWIN_HACKS */
 #endif /* CYGWIN_HACKS */
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
     my_write(f, "%s %s %s%s %s\n", bot->nick,
     my_write(f, "%s %s %s%s %s\n", bot->nick,
-             bot->ip ? bot->ip : ".", bot->host6 ? "+" : "", bot->host ? bot->host : (bot->host6 ? bot->host6 : "."), bot->ip6 ? bot->ip6 : "");
+             bot->ip ? bot->ip : ".", bot->host6 ? "+" : "",
+             bot->host ? bot->host : (bot->host6 ? bot->host6 : "."), bot->ip6 ? bot->ip6 : "");
   }
   }
 
 
   fflush(f);
   fflush(f);
@@ -770,38 +802,8 @@ fillconf(conf_t * inconf)
   inconf->uid = conffile.uid;
   inconf->uid = conffile.uid;
 }
 }
 
 
-/*
-static void 
-tellconf(conf_t *inconf)
-{
-conf_bot *bot;
-int i = 0;
-
-printf("uid: %d\n", inconf->uid);
-printf("homedir: %s\n", inconf->homedir);
-printf("binpath: %s\n", inconf->binpath);
-printf("binname: %s\n", inconf->binname);
-printf("portmin: %d\n", inconf->portmin);
-printf("portmax: %d\n", inconf->portmax);
-printf("pscloak: %d\n", inconf->pscloak);
-printf("autocron: %d\n", inconf->autocron);
-printf("autouname: %d\n", inconf->autouname);
-printf("watcher: %d\n", inconf->watcher);
-    for (bot = inconf->bots; bot && bot->nick; bot = bot->next) {
-      i++;
-      printf("%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
-                      bot->nick,
-                      bot->ip ? bot->ip : "",
-                      bot->host ? bot->host : "",
-                      bot->ip6 ? bot->ip6 : "",
-                      bot->host6 ? bot->host6 : "",
-                      bot->pid);
-    }
-printf("\n\n\n\n");
-}
-*/
-
-void bin_to_conf(settings_t *in)
+void
+bin_to_conf(settings_t * in)
 {
 {
 /* printf("Converting binary data to conf struct\n"); */
 /* printf("Converting binary data to conf struct\n"); */
   conffile.uid = atol(settings.uid);
   conffile.uid = atol(settings.uid);
@@ -820,6 +822,7 @@ void bin_to_conf(settings_t *in)
   /* BOTS */
   /* BOTS */
   {
   {
     char *p = NULL, *tmp = NULL, *tmpp = NULL;
     char *p = NULL, *tmp = NULL, *tmpp = NULL;
+
     tmp = tmpp = strdup(settings.bots);
     tmp = tmpp = strdup(settings.bots);
     while ((p = strchr(tmp, ','))) {
     while ((p = strchr(tmp, ','))) {
       char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
       char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
@@ -844,5 +847,5 @@ void bin_to_conf(settings_t *in)
     }
     }
     free(tmpp);
     free(tmpp);
   }
   }
-  /* tellconf(&conffile); */
+  tellconf(&conffile);
 }
 }