Просмотр исходного кода

* Made itraffic_* otraffic_* into a single struct.

svn: 583
Bryan Drewery 22 лет назад
Родитель
Сommit
cf98bc47be
6 измененных файлов с 104 добавлено и 118 удалено
  1. 3 3
      src/Makefile.in
  2. 51 59
      src/cmds.c
  3. 25 44
      src/main.c
  4. 1 1
      src/misc.c
  5. 9 11
      src/net.c
  6. 15 0
      src/traffic.h

+ 3 - 3
src/Makefile.in

@@ -129,7 +129,7 @@ cmds.o: cmds.c stringfix main.h ../config.h conf.h lang.h eggdrop.h flags.h prot
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
  compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
- tandem.h modules.h mod/modvals.h help.h 
+ tandem.h modules.h mod/modvals.h help.h traffic.h
 config.o: config.c stringfix main.h ../config.h conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h chan.h users.h compat/compat.h compat/inet_aton.h \
  compat/inet_ntop.h ../src/main.h compat/snprintf.h  compat/memset.h \
@@ -173,7 +173,7 @@ main.o: main.c stringfix main.h build.h ../config.h conf.h lang.h eggdrop.h flag
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
  compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
- modules.h mod/modvals.h tandem.h  egg_timer.h
+ modules.h mod/modvals.h tandem.h  egg_timer.h traffic.h
 match.o: match.c stringfix ./main.h
 mem.o: mem.c stringfix main.h ../config.h conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
@@ -199,7 +199,7 @@ net.o: net.c stringfix main.h ../config.h conf.h lang.h eggdrop.h flags.h proto.
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
  compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
- egg_timer.h
+ egg_timer.h traffic.h
 rfc1459.o: rfc1459.c stringfix main.h ../config.h conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
  users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \

+ 51 - 59
src/cmds.c

@@ -9,6 +9,7 @@
 #include "tandem.h"
 #include "modules.h"
 #include "help.h"
+#include "traffic.h" /* egg_traffic_t */
 #include <ctype.h>
 #include <stdlib.h>
 #include <pwd.h>
@@ -23,16 +24,7 @@ extern int		 dcc_total, remote_boots, backgrd,
 			 strict_host, quiet_save, cfg_count,
 			 server_lag, egg_numver, localhub;
 
-extern unsigned long	 otraffic_irc, otraffic_irc_today,
-			 itraffic_irc, itraffic_irc_today,
-			 otraffic_bn, otraffic_bn_today,
-			 itraffic_bn, itraffic_bn_today,
-			 otraffic_dcc, otraffic_dcc_today,
-			 itraffic_dcc, itraffic_dcc_today,
-			 otraffic_trans, otraffic_trans_today,
-			 itraffic_trans, itraffic_trans_today,
-			 otraffic_unknown, otraffic_unknown_today,
-			 itraffic_unknown, itraffic_unknown_today;
+extern egg_traffic_t traffic;
 extern Tcl_Interp 	 *interp;
 extern char		 botnetnick[], origbotname[], ver[], network[],
 			 owner[], quit_msg[], dcc_prefix[], pid_file[],
@@ -3950,64 +3942,64 @@ static void cmd_traffic(struct userrec *u, int idx, char *par)
 
   dprintf(idx, STR("Traffic since last restart\n"));
   dprintf(idx, "==========================\n");
-  if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
-      itraffic_irc_today > 0) {
+  if (traffic.out_total.irc > 0 || traffic.in_total.irc > 0 || traffic.out_today.irc > 0 ||
+      traffic.in_today.irc > 0) {
     dprintf(idx, "IRC:\n");
-    dprintf(idx, "  out: %s", btos(otraffic_irc + otraffic_irc_today));
-              dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
-    dprintf(idx, "   in: %s", btos(itraffic_irc + itraffic_irc_today));
-              dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
-  }
-  if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
-      itraffic_bn_today > 0) {
-    dprintf(idx, STR("Botnet:\n"));
-    dprintf(idx, "  out: %s", btos(otraffic_bn + otraffic_bn_today));
-              dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
-    dprintf(idx, "   in: %s", btos(itraffic_bn + itraffic_bn_today));
-              dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
-  }
-  if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
-      itraffic_dcc_today > 0) {
-    dprintf(idx, STR("Partyline:\n"));
-    itmp = otraffic_dcc + otraffic_dcc_today;
-    itmp2 = otraffic_dcc_today;
+    dprintf(idx, "  out: %s", btos(traffic.out_total.irc + traffic.out_today.irc));
+              dprintf(idx, " (%s today)\n", btos(traffic.out_today.irc));
+    dprintf(idx, "   in: %s", btos(traffic.in_total.irc + traffic.in_today.irc));
+              dprintf(idx, " (%s today)\n", btos(traffic.in_today.irc));
+  }
+  if (traffic.out_total.bn > 0 || traffic.in_total.bn > 0 || traffic.out_today.bn > 0 ||
+      traffic.in_today.bn > 0) {
+    dprintf(idx, "Botnet:\n");
+    dprintf(idx, "  out: %s", btos(traffic.out_total.bn + traffic.out_today.bn));
+              dprintf(idx, " (%s today)\n", btos(traffic.out_today.bn));
+    dprintf(idx, "   in: %s", btos(traffic.in_total.bn + traffic.in_today.bn));
+              dprintf(idx, " (%s today)\n", btos(traffic.in_today.bn));
+  }
+  if (traffic.out_total.dcc > 0 || traffic.in_total.dcc > 0 || traffic.out_today.dcc > 0 ||
+      traffic.in_today.dcc > 0) {
+    dprintf(idx, "Partyline:\n");
+    itmp = traffic.out_total.dcc + traffic.out_today.dcc;
+    itmp2 = traffic.out_today.dcc;
     dprintf(idx, "  out: %s", btos(itmp));
               dprintf(idx, " (%s today)\n", btos(itmp2));
-    dprintf(idx, "   in: %s", btos(itraffic_dcc + itraffic_dcc_today));
-              dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
-  }
-  if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
-      itraffic_trans_today > 0) {
-    dprintf(idx, STR("Transfer.mod:\n"));
-    dprintf(idx, "  out: %s", btos(otraffic_trans + otraffic_trans_today));
-              dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
-    dprintf(idx, "   in: %s", btos(itraffic_trans + itraffic_trans_today));
-              dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
-  }
-  if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
+    dprintf(idx, "   in: %s", btos(traffic.in_total.dcc + traffic.in_today.dcc));
+              dprintf(idx, " (%s today)\n", btos(traffic.in_today.dcc));
+  }
+  if (traffic.out_total.trans > 0 || traffic.in_total.trans > 0 || traffic.out_today.trans > 0 ||
+      traffic.in_today.trans > 0) {
+    dprintf(idx, "Transfer.mod:\n");
+    dprintf(idx, "  out: %s", btos(traffic.out_total.trans + traffic.out_today.trans));
+              dprintf(idx, " (%s today)\n", btos(traffic.out_today.trans));
+    dprintf(idx, "   in: %s", btos(traffic.in_total.trans + traffic.in_today.trans));
+              dprintf(idx, " (%s today)\n", btos(traffic.in_today.trans));
+  }
+  if (traffic.out_total.unknown > 0 || traffic.out_today.unknown > 0) {
     dprintf(idx, "Misc:\n");
-    dprintf(idx, "  out: %s", btos(otraffic_unknown + otraffic_unknown_today));
-              dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
-    dprintf(idx, "   in: %s", btos(itraffic_unknown + itraffic_unknown_today));
-              dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
+    dprintf(idx, "  out: %s", btos(traffic.out_total.unknown + traffic.out_today.unknown));
+              dprintf(idx, " (%s today)\n", btos(traffic.out_today.unknown));
+    dprintf(idx, "   in: %s", btos(traffic.in_total.unknown + traffic.in_today.unknown));
+              dprintf(idx, " (%s today)\n", btos(traffic.in_today.unknown));
   }
   dprintf(idx, "---\n");
   dprintf(idx, "Total:\n");
-  itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans
-         + otraffic_unknown + otraffic_irc_today + otraffic_bn_today
-         + otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
-  itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today
-         + otraffic_trans_today + otraffic_unknown_today;
+  itmp = traffic.out_total.irc + traffic.out_total.bn + traffic.out_total.dcc + traffic.out_total.trans
+         + traffic.out_total.unknown + traffic.out_today.irc + traffic.out_today.bn
+         + traffic.out_today.dcc + traffic.out_today.trans + traffic.out_today.unknown;
+  itmp2 = traffic.out_today.irc + traffic.out_today.bn + traffic.out_today.dcc
+         + traffic.out_today.trans + traffic.out_today.unknown;
   dprintf(idx, "  out: %s", btos(itmp));
               dprintf(idx, " (%s today)\n", btos(itmp2));
-  dprintf(idx, "   in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc
-	  + itraffic_trans + itraffic_unknown + itraffic_irc_today
-	  + itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today
-	  + itraffic_unknown_today));
-  dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today
-          + itraffic_dcc_today + itraffic_trans_today
-	  + itraffic_unknown_today));
-  putlog(LOG_CMDS, "*", STR("#%s# traffic"), dcc[idx].nick);
+  dprintf(idx, "   in: %s", btos(traffic.in_total.irc + traffic.in_total.bn + traffic.in_total.dcc
+	  + traffic.in_total.trans + traffic.in_total.unknown + traffic.in_today.irc
+	  + traffic.in_today.bn + traffic.in_today.dcc + traffic.in_today.trans
+	  + traffic.in_today.unknown));
+  dprintf(idx, " (%s today)\n", btos(traffic.in_today.irc + traffic.in_today.bn
+          + traffic.in_today.dcc + traffic.in_today.trans
+	  + traffic.in_today.unknown));
+  putlog(LOG_CMDS, "*", "#%s# traffic", dcc[idx].nick);
 }
 
 static char traffictxt[20];

+ 25 - 44
src/main.c

@@ -113,28 +113,8 @@ extern struct cfg_entry CFG_FORKINTERVAL;
 
 /* Traffic stats
  */
-unsigned long	otraffic_irc = 0;
-unsigned long	otraffic_irc_today = 0;
-unsigned long	otraffic_bn = 0;
-unsigned long	otraffic_bn_today = 0;
-unsigned long	otraffic_dcc = 0;
-unsigned long	otraffic_dcc_today = 0;
-unsigned long	otraffic_filesys = 0;
-unsigned long	otraffic_filesys_today = 0;
-unsigned long	otraffic_trans = 0;
-unsigned long	otraffic_trans_today = 0;
-unsigned long	otraffic_unknown = 0;
-unsigned long	otraffic_unknown_today = 0;
-unsigned long	itraffic_irc = 0;
-unsigned long	itraffic_irc_today = 0;
-unsigned long	itraffic_bn = 0;
-unsigned long	itraffic_bn_today = 0;
-unsigned long	itraffic_dcc = 0;
-unsigned long	itraffic_dcc_today = 0;
-unsigned long	itraffic_trans = 0;
-unsigned long	itraffic_trans_today = 0;
-unsigned long	itraffic_unknown = 0;
-unsigned long	itraffic_unknown_today = 0;
+#include "traffic.h" /* egg_traffic_t */
+egg_traffic_t traffic;
 
 void fatal(const char *s, int recoverable)
 {
@@ -627,21 +607,22 @@ static void event_save()
 
 static void event_resettraffic()
 {
-  otraffic_irc += otraffic_irc_today;
-  itraffic_irc += itraffic_irc_today;
-  otraffic_bn += otraffic_bn_today;
-  itraffic_bn += itraffic_bn_today;
-  otraffic_dcc += otraffic_dcc_today;
-  itraffic_dcc += itraffic_dcc_today;
-  otraffic_unknown += otraffic_unknown_today;
-  itraffic_unknown += itraffic_unknown_today;
-  otraffic_trans += otraffic_trans_today;
-  itraffic_trans += itraffic_trans_today;
-  otraffic_irc_today = otraffic_bn_today = 0;
-  otraffic_dcc_today = otraffic_unknown_today = 0;
-  itraffic_irc_today = itraffic_bn_today = 0;
-  itraffic_dcc_today = itraffic_unknown_today = 0;
-  itraffic_trans_today = otraffic_trans_today = 0;
+	traffic.out_total.irc += traffic.out_today.irc;
+	traffic.out_total.bn += traffic.out_today.bn;
+	traffic.out_total.dcc += traffic.out_today.dcc;
+	traffic.out_total.filesys += traffic.out_today.filesys;
+	traffic.out_total.trans += traffic.out_today.trans;
+	traffic.out_total.unknown += traffic.out_today.unknown;
+
+	traffic.in_total.irc += traffic.in_today.irc;
+	traffic.in_total.bn += traffic.in_today.bn;
+	traffic.in_total.dcc += traffic.in_today.dcc;
+	traffic.in_total.filesys += traffic.in_today.filesys;
+	traffic.in_total.trans += traffic.in_today.trans;
+	traffic.in_total.unknown += traffic.in_today.unknown;
+
+	egg_memset(&traffic.out_today, 0, sizeof(traffic.out_today));
+	egg_memset(&traffic.in_today, 0, sizeof(traffic.in_today));
 }
 
 extern module_entry *module_list;
@@ -1417,19 +1398,19 @@ int main(int argc, char **argv)
 	    /* Traffic stats */
 	    if (dcc[idx].type->name) {
 	      if (!strncmp(dcc[idx].type->name, "BOT", 3))
-		itraffic_bn_today += strlen(buf) + 1;
+		traffic.in_today.bn += strlen(buf) + 1;
 	      else if (!strcmp(dcc[idx].type->name, "SERVER"))
-		itraffic_irc_today += strlen(buf) + 1;
+		traffic.in_today.irc += strlen(buf) + 1;
 	      else if (!strncmp(dcc[idx].type->name, "CHAT", 4))
-		itraffic_dcc_today += strlen(buf) + 1;
+		traffic.in_today.dcc += strlen(buf) + 1;
 	      else if (!strncmp(dcc[idx].type->name, "FILES", 5))
-		itraffic_dcc_today += strlen(buf) + 1;
+		traffic.in_today.dcc += strlen(buf) + 1;
 	      else if (!strcmp(dcc[idx].type->name, "SEND"))
-		itraffic_trans_today += strlen(buf) + 1;
+		traffic.in_today.trans += strlen(buf) + 1;
 	      else if (!strncmp(dcc[idx].type->name, "GET", 3))
-		itraffic_trans_today += strlen(buf) + 1;
+		traffic.in_today.trans += strlen(buf) + 1;
 	      else
-		itraffic_unknown_today += strlen(buf) + 1;
+		traffic.in_today.unknown += strlen(buf) + 1;
 	    }
 	    dcc[idx].type->activity(idx, buf, i);
 	  } else

+ 1 - 1
src/misc.c

@@ -1063,7 +1063,7 @@ void check_trace(int n)
 #ifdef S_ANTITRACE
   int x, parent, i;
   struct sigaction sv, *oldsv = NULL;
-return;
+
   if (n && !strcmp((char *) CFG_TRACE.ldata ? CFG_TRACE.ldata : CFG_TRACE.gdata ? CFG_TRACE.gdata : "ignore", "ignore"))
     return;
   parent = getpid();

+ 9 - 11
src/net.c

@@ -7,6 +7,7 @@
 #include <fcntl.h>
 #include "main.h"
 #include "proto.h"
+#include "traffic.h" /* egg_traffic_t */
 #include <limits.h>
 #include <string.h>
 #include <netdb.h>
@@ -39,10 +40,7 @@
 
 extern struct dcc_t	*dcc;
 extern int		 backgrd, use_stderr, resolve_timeout, dcc_total;
-extern unsigned long	 otraffic_irc_today, otraffic_bn_today,
-			 otraffic_dcc_today, otraffic_filesys_today,
-			 otraffic_trans_today, otraffic_unknown_today;
-
+extern egg_traffic_t traffic;
 
 #ifdef HAVE_SSL
   SSL_CTX 		*ssl_c_ctx = NULL, *ssl_s_ctx = NULL;
@@ -1539,19 +1537,19 @@ void tputs(register int z, char *s, unsigned int len)
       for (idx = 0; idx < dcc_total; idx++) {
         if ((dcc[idx].sock == z) && dcc[idx].type && dcc[idx].type->name) {
           if (!strncmp(dcc[idx].type->name, "BOT", 3))
-            otraffic_bn_today += len;
+                traffic.out_today.bn += len;
           else if (!strcmp(dcc[idx].type->name, "SERVER"))
-            otraffic_irc_today += len;
+                traffic.out_today.irc += len;
           else if (!strncmp(dcc[idx].type->name, "CHAT", 4))
-            otraffic_dcc_today += len;
+                traffic.out_today.dcc += len;
           else if (!strncmp(dcc[idx].type->name, "FILES", 5))
-            otraffic_filesys_today += len;
+                traffic.out_today.filesys += len;
           else if (!strcmp(dcc[idx].type->name, "SEND"))
-            otraffic_trans_today += len;
+                traffic.out_today.trans += len;
           else if (!strncmp(dcc[idx].type->name, "GET", 3))
-            otraffic_trans_today += len;
+                traffic.out_today.trans += len;
           else
-            otraffic_unknown_today += len;
+                traffic.out_today.unknown += len;
           break;
         }
       }

+ 15 - 0
src/traffic.h

@@ -0,0 +1,15 @@
+#ifndef _TRAFFIC_H_
+#define _TRAFFIC_H_
+
+typedef struct {
+	struct {
+		unsigned long irc;
+		unsigned long bn;
+		unsigned long dcc;
+		unsigned long filesys;
+		unsigned long trans;
+		unsigned long unknown;
+	} in_total, in_today, out_total, out_today;
+} egg_traffic_t;
+
+#endif /* _TRAFFIC_H_ */