Răsfoiți Sursa

* Moved host/ip buffers in conf_bot to conf_bot.conf_net

svn: 1634
Bryan Drewery 21 ani în urmă
părinte
comite
df79d72a21
9 a modificat fișierele cu 60 adăugiri și 54 ștergeri
  1. 4 4
      src/binary.c
  2. 2 2
      src/cfg.c
  3. 2 2
      src/chanprog.c
  4. 4 4
      src/cmds.c
  5. 29 28
      src/conf.c
  6. 9 4
      src/conf.h
  7. 1 1
      src/mod/channels.mod/cmdschan.c
  8. 1 1
      src/mod/channels.mod/userchan.c
  9. 8 8
      src/net.c

+ 4 - 4
src/binary.c

@@ -371,10 +371,10 @@ void conf_to_bin(conf_t *in)
   for (bot = in->bots; bot && bot->nick; bot = bot->next) {
     sprintf(settings.bots, "%s%s %s %s%s %s,", settings.bots && settings.bots[0] ? settings.bots : "",
                            bot->nick,
-                           bot->ip ? bot->ip : ".", 
-                           bot->host6 ? "+" : "", 
-                           bot->host ? bot->host : (bot->host6 ? bot->host6 : "."),
-                           bot->ip6 ? bot->ip6 : "");
+                           bot->net.ip ? bot->net.ip : ".", 
+                           bot->net.host6 ? "+" : "", 
+                           bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."),
+                           bot->net.ip6 ? bot->net.ip6 : "");
     }
 
   newbin = move_bin(in->binpath, in->binname, 0);

+ 2 - 2
src/cfg.c

@@ -358,10 +358,10 @@ struct cfg_entry CFG_PROCESSLIST = {
 #ifdef LEAF
 static void servers_changed(struct cfg_entry * entry, int * valid) {
   if (!strcmp(entry->name, "servers")) {
-    if (conf.bot->host6 || conf.bot->ip6) /* we want to use the servers6 entry. */
+    if (conf.bot->net.host6 || conf.bot->net.ip6) /* we want to use the servers6 entry. */
       return;
   } else if (!strcmp(entry->name, "servers6")) {
-    if (!conf.bot->host6 && !conf.bot->ip6) /* we probably want to use the normal server list.. */
+    if (!conf.bot->net.host6 && !conf.bot->net.ip6) /* we probably want to use the normal server list.. */
       return;
   }
 

+ 2 - 2
src/chanprog.c

@@ -544,8 +544,8 @@ void chanprog()
     userlist = adduser(userlist, conf.bot->nick, "none", "-", USER_OP, 1);
     conf.bot->u = get_user_by_handle(userlist, conf.bot->nick);
     bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
-    if (conf.bot->ip)
-      bi->address = strdup(conf.bot->ip);
+    if (conf.bot->net.ip)
+      bi->address = strdup(conf.bot->net.ip);
     /* bi->telnet_port = atoi(buf) ? atoi(buf) : 3333; */
     bi->telnet_port = bi->relay_port = 3333;
 #ifdef HUB

+ 4 - 4
src/cmds.c

@@ -1871,10 +1871,10 @@ static void cmd_conf(int idx, char *par)
       if (!listbot || (listbot && !strcmp(listbot, bot->nick)))
         dprintf(idx, "%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->net.ip ? bot->net.ip : "",
+                      bot->net.host ? bot->net.host : "",
+                      bot->net.ip6 ? bot->net.ip6 : "",
+                      bot->net.host6 ? bot->net.host6 : "",
                       bot->pid);
     }
   }

+ 29 - 28
src/conf.c

@@ -15,6 +15,7 @@
 #include "settings.h"
 #include "misc.h"
 #include "misc_file.h"
+#include "socket.h"
 
 #include <errno.h>
 #include <paths.h>
@@ -49,15 +50,15 @@ tellconf(conf_t * inconf)
     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);
+             bot->net.ip ? bot->net.ip : "",
+             bot->net.host ? bot->net.host : "", bot->net.ip6 ? bot->net.ip6 : "", bot->net.host6 ? bot->net.host6 : "", bot->pid);
   }
   sdprintf("bot:\n");
   if (inconf->bot && ((bot = inconf->bot)))
     sdprintf("%s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n",
              bot->nick,
-             bot->ip ? bot->ip : "",
-             bot->host ? bot->host : "", bot->ip6 ? bot->ip6 : "", bot->host6 ? bot->host6 : "", bot->pid);
+             bot->net.ip ? bot->net.ip : "",
+             bot->net.host ? bot->net.host : "", bot->net.ip6 ? bot->net.ip6 : "", bot->net.host6 ? bot->net.host6 : "", bot->pid);
 }
 
 #ifdef LEAF
@@ -357,22 +358,22 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
   }
 #endif /* LEAF */
 
-  bot->ip = NULL;
-  bot->host = NULL;
-  bot->ip6 = NULL;
-  bot->host6 = NULL;
+  bot->net.ip = NULL;
+  bot->net.host = NULL;
+  bot->net.ip6 = NULL;
+  bot->net.host6 = NULL;
 
   if (host && host[0] == '+') {
     host++;
-    bot->host6 = strdup(host);
+    bot->net.host6 = strdup(host);
   } else if (host && strcmp(host, ".")) {
-    bot->host = strdup(host);
+    bot->net.host = strdup(host);
   }
 
-  if (ip && strcmp(ip, "."))
-    bot->ip = strdup(ip);
-  if (ip6 && strcmp(ip6, "."))
-    bot->ip6 = strdup(ip6);
+  if (ip && strcmp(ip, ".") && is_dotted_ip(ip) == AF_INET)
+    bot->net.ip = strdup(ip);
+  if (ip6 && strcmp(ip6, ".") && is_dotted_ip(ip) == AF_INET6)
+    bot->net.ip6 = strdup(ip6);
 
   bot->u = NULL;
   bot->pid = checkpid(nick, bot);
@@ -387,14 +388,14 @@ free_bot(char *botn)
     if (!strcmp(botn, bot->nick)) {
       free(bot->nick);
       free(bot->pid_file);
-      if (bot->ip)
-        free(bot->ip);
-      if (bot->host)
-        free(bot->host);
-      if (bot->ip6)
-        free(bot->ip6);
-      if (bot->host6)
-        free(bot->host6);
+      if (bot->net.ip)
+        free(bot->net.ip);
+      if (bot->net.host)
+        free(bot->net.host);
+      if (bot->net.ip6)
+        free(bot->net.ip6);
+      if (bot->net.host6)
+        free(bot->net.host6);
 
       if (old)
         old->next = bot->next;
@@ -731,8 +732,8 @@ writeconf(char *filename, FILE * stream, int bits)
 #endif /* CYGWIN_HACKS */
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
     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->net.ip ? bot->net.ip : ".", bot->net.host6 ? "+" : "",
+             bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."), bot->net.ip6 ? bot->net.ip6 : "");
   }
 
   fflush(f);
@@ -747,10 +748,10 @@ conf_bot_dup(conf_bot * dest, conf_bot * src)
 {
   dest->nick = src->nick ? strdup(src->nick) : NULL;
   dest->pid_file = src->pid_file ? strdup(src->pid_file) : NULL;
-  dest->ip = src->ip ? strdup(src->ip) : NULL;
-  dest->host = src->host ? strdup(src->host) : NULL;
-  dest->ip6 = src->ip6 ? strdup(src->ip6) : NULL;
-  dest->host6 = src->host6 ? strdup(src->host6) : NULL;
+  dest->net.ip = src->net.ip ? strdup(src->net.ip) : NULL;
+  dest->net.host = src->net.host ? strdup(src->net.host) : NULL;
+  dest->net.ip6 = src->net.ip6 ? strdup(src->net.ip6) : NULL;
+  dest->net.host6 = src->net.host6 ? strdup(src->net.host6) : NULL;
   dest->u = src->u ? src->u : NULL;
   dest->pid = src->pid;
 #ifdef LEAF

+ 9 - 4
src/conf.h

@@ -7,18 +7,23 @@
 #include "eggdrop.h"
 #include "settings.h"
 
+typedef struct conf_net_b {
+  char *host;
+  char *host6;
+  char *ip;
+  char *ip6;
+  int family;
+} conf_net;  
+
 typedef struct conf_bot_b {
   struct conf_bot_b *next;
   struct userrec *u;	/* our own user record */
+  struct conf_net_b net;
   pid_t pid;              /* contains the PID for the bot (read for the pidfile) */
 #ifdef LEAF
   int localhub;         /* bot is localhub */
 #endif /* LEAF */
   char *nick;
-  char *host;
-  char *host6;
-  char *ip;
-  char *ip6;
   char *pid_file;       /* path and filename of the .pid file */
 } conf_bot;
 

+ 1 - 1
src/mod/channels.mod/cmdschan.c

@@ -95,7 +95,7 @@ static void cmd_pls_mask(const char type, int idx, char *par)
 #ifdef LEAF
     egg_snprintf(s1, sizeof s1, "%s!%s", botname, botuserhost);
 #else
-    egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->host);
+    egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->net.host);
 #endif /* LEAF */
   if (type == 'b' && s1[0] && wild_match(s, s1)) {
     dprintf(idx, "I'm not going to ban myself.\n");

+ 1 - 1
src/mod/channels.mod/userchan.c

@@ -296,7 +296,7 @@ bool u_addmask(char type, struct chanset_t *chan, char *who, char *from, char *n
 #ifdef LEAF
     simple_sprintf(s, "%s!%s", botname, botuserhost);
 #else
-    simple_sprintf(s, "%s!%s@%s", origbotname, botuser, conf.bot->host);
+    simple_sprintf(s, "%s!%s@%s", origbotname, botuser, conf.bot->net.host);
 #endif /* LEAF */
   if (s[0] && type == 'b' && wild_match(host, s)) {
     putlog(LOG_MISC, "*", IRC_IBANNEDME);

+ 8 - 8
src/net.c

@@ -289,11 +289,11 @@ void cache_my_ip()
 
   egg_memset(&cached_myip6_so, 0, sizeof(union sockaddr_union));
 
-  if (conf.bot->ip6) {
-    if (get_ip(conf.bot->ip6, &cached_myip6_so))
+  if (conf.bot->net.ip6) {
+    if (get_ip(conf.bot->net.ip6, &cached_myip6_so))
       any = 1;
-  } else if (conf.bot->host6) {
-    if (get_ip(conf.bot->host6, &cached_myip6_so))
+  } else if (conf.bot->net.host6) {
+    if (get_ip(conf.bot->net.host6, &cached_myip6_so))
       any = 1;
   } else
     any = 1;
@@ -304,11 +304,11 @@ void cache_my_ip()
   }
 #endif /* USE_IPV6 */
 
-  if (conf.bot->ip) {
-    if (get_ip(conf.bot->ip, &cached_myip4_so))
+  if (conf.bot->net.ip) {
+    if (get_ip(conf.bot->net.ip, &cached_myip4_so))
       error = 1;
-  } else if (conf.bot->host) {
-    if (get_ip(conf.bot->host, &cached_myip4_so))
+  } else if (conf.bot->net.host) {
+    if (get_ip(conf.bot->net.host, &cached_myip4_so))
       error = 2;
   } else {
 /*