Przeglądaj źródła

* DCC[] list is no longer shifter
-idxs are no longer shifted and lost
* findanyidx() is now static


svn: 1462

Bryan Drewery 21 lat temu
rodzic
commit
1653d4ddcc
6 zmienionych plików z 31 dodań i 85 usunięć
  1. 2 20
      src/dcc.c
  2. 2 2
      src/dcc.h
  3. 25 57
      src/dccutil.c
  4. 1 4
      src/main.c
  5. 1 1
      src/net.c
  6. 0 1
      src/net.h

+ 2 - 20
src/dcc.c

@@ -41,7 +41,8 @@
 
 struct dcc_t *dcc = NULL;       /* DCC list                                */
 time_t timesync = 0;
-int dcc_total = 0;              /* Total dcc's                             */
+int dcc_total = 0;              /* size of dcc table                             */
+int dccn = 0;			/* actual number of dcc entries */
 
 static time_t password_timeout = 20;       /* Time to wait for a password from a user */
 static time_t auth_timeout = 40;
@@ -1683,25 +1684,6 @@ struct dcc_table DCC_SOCKET = {
   NULL
 };
 
-static void
-display_dcc_lost(int idx, char *buf)
-{
-  strcpy(buf, "lost");
-}
-
-struct dcc_table DCC_LOST = {
-  "LOST",
-  0,
-  NULL,
-  dcc_socket,
-  NULL,
-  NULL,
-  display_dcc_lost,
-  NULL,
-  NULL,
-  NULL
-};
-
 void
 dcc_identwait(int idx, char *buf, int len)
 {

+ 2 - 2
src/dcc.h

@@ -213,11 +213,11 @@ struct dupwait_info {
 #define TLN_ECHO_C      "\001"
 
 extern struct dcc_t 		*dcc;
-extern int 			dcc_total;
+extern int 			dcc_total, dccn;
 extern time_t			timesync;
 extern char			network[];
 
-extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_BOT_NEW,
+extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_BOT_NEW,
  DCC_RELAY, DCC_RELAYING, DCC_FORK_RELAY, DCC_PRE_RELAY, DCC_CHAT_PASS,
  DCC_FORK_BOT, DCC_SOCKET, DCC_TELNET_ID, DCC_TELNET_NEW, DCC_TELNET_PW,
  DCC_TELNET, DCC_IDENT, DCC_IDENTWAIT, DCC_DNSWAIT, DCC_IDENTD, DCC_IDENTD_CONNECT;

+ 25 - 57
src/dccutil.c

@@ -358,58 +358,13 @@ void lostdcc(int n)
   egg_bzero(&dcc[n], sizeof(struct dcc_t));
 
   dcc[n].sock = -1;
-  dcc[n].type = &DCC_LOST;
-}
-
-/* Remove entry from dcc list. Think twice before using this function,
- * because it invalidates any variables that point to a specific dcc
- * entry!
- *
- * Note: The entry will be deconstructed if it was not deconstructed
- *       already. This case should normally not occur.
- */
-static void removedcc(int n)
-{
-  sdprintf("removedcc(%d)", n);
-  if (dcc[n].type && dcc[n].type->kill)
-    dcc[n].type->kill(n, dcc[n].u.other);
-  else if (dcc[n].u.other)
-    free(dcc[n].u.other);
+  dcc[n].type = NULL;
 
-  dcc_total--;
-
-  if (n < dcc_total) {
-    egg_memcpy(&dcc[n], &dcc[dcc_total], sizeof(struct dcc_t));
-    sdprintf("idx: %d -> %d", dcc_total, n);
-  } else
-    egg_bzero(&dcc[n], sizeof(struct dcc_t)); /* drummer */
-}
+  dccn--;
 
-/* Clean up sockets that were just left for dead.
- */
-void dcc_remove_lost(void)
-{
-  for (int i = 0; i < dcc_total; i++) {
-    if (dcc[i].type && dcc[i].type == &DCC_LOST) {
-      dcc[i].type = NULL;
-      dcc[i].sock = -1;
-      removedcc(i);
-      i--;
-    }
-  }
-#ifdef LEAF
-  /* check if any of our idx's moved. */
-  if (serv >= 0 && (servidx >= 0 && servidx < dcc_total && dcc[servidx].sock != serv) || (servidx >= dcc_total)) {
-    sdprintf("changing serv: %d servidx: %d to ...", serv, servidx);
-    servidx = findanyidx(serv);		
-    sdprintf("...      serv: %d servidx: %d", serv, servidx);
-  }
-#endif /* LEAF */
-  if (dns_sock >= 0 && (dns_idx >= 0 && dns_idx < dcc_total && dcc[dns_idx].sock != dns_sock) || (dns_idx >= dcc_total)) {
-    sdprintf("changing dns_sock: %d dns_idx: %d to ...", dns_sock, dns_idx);
-    dns_idx = findanyidx(dns_sock);	
-    sdprintf("...      dns_sock: %d dns_idx: %d", dns_sock, dns_idx);
-  }
+  /* last entry! make table smaller :) */
+  if (n == (dcc_total - 1))
+    dcc_total--;
 }
 
 /* Show list of current dcc's to a dcc-chatter
@@ -435,7 +390,8 @@ void tell_dcc(int idx)
                         "----------------------------------------", "----");
 
   egg_snprintf(format, sizeof format, "%%-4d %%-4d %%08X %%5ud %%-%us %%-40s %%s\n", nicklen);
-
+ 
+  dprintf(idx, "dccn: %d, dcc_total: %d\n", dccn, dcc_total);
 #ifdef LEAF
   dprintf(idx, "dns_idx: %d, servidx: %d\n", dns_idx, servidx);
 #endif /* LEAF */
@@ -452,8 +408,6 @@ void tell_dcc(int idx)
       sprintf(other, "?:%lX  !! ERROR !!", (long) dcc[i].type);
       break;
     }
-    if (dcc[i].type == &DCC_LOST)
-      dprintf(idx, "LOST:\n");
     dprintf(idx, format, dcc[i].sock, i, dcc[i].addr, dcc[i].port, dcc[i].nick, dcc[i].host + j, other);
    }
   }
@@ -537,18 +491,32 @@ void flush_lines(int idx, struct chat_info *ci)
 
 int new_dcc(struct dcc_table *type, int xtra_size)
 {
-  int i = dcc_total;
-
   if (dcc_total == max_dcc)
     return -1;
-  dcc_total++;
+
+  int i = 0;
+
+  /* Find the first gap */
+  for (i = 0; i <= dcc_total; i++)
+    if (!dcc[i].type)
+      break;
+
+  /* we managed to get to the end of the list! */
+  if (i == dcc_total) {
+    i = dcc_total;
+    dcc_total++;
+  }
+   
+  dccn++;
+
+  /* empty out the memory for the entry */
   egg_bzero((char *) &dcc[i], sizeof(struct dcc_t));
 
   dcc[i].type = type;
   if (xtra_size)
     dcc[i].u.other = (char *) calloc(1, xtra_size);
 
-  sdprintf("new_dcc: %d (dcc_total: %d)", i, dcc_total);
+  sdprintf("new_dcc: %d (dccn/dcc_total: %d/%d)", i, dccn, dcc_total);
   return i;
 }
 

+ 1 - 4
src/main.c

@@ -178,7 +178,7 @@ void fatal(const char *s, int recoverable)
 static void check_expired_dcc()
 {
   for (int i = 0; i < dcc_total; i++)
-    if (dcc[i].type && (dcc[i].type != &DCC_LOST) && dcc[i].type->timeout_val &&
+    if (dcc[i].type && dcc[i].type->timeout_val &&
 	((now - dcc[i].timeval) > *(dcc[i].type->timeout_val))) {
       if (dcc[i].type->timeout)
 	dcc[i].type->timeout(i);
@@ -933,9 +933,6 @@ printf("out: %s\n", out);
     if (!socket_cleanup) {
       socket_cleanup = 5;
 
-      /* Remove dead dcc entries. */
-      dcc_remove_lost();
-
       /* Check for server or dcc activity. */
       dequeue_sockets();		
     } else

+ 1 - 1
src/net.c

@@ -1578,7 +1578,7 @@ int findanysnum(register int sock)
   return -1;
 }
 
-int findanyidx(register int sock)
+static int findanyidx(register int sock)
 {
   register int j;
 

+ 0 - 1
src/net.h

@@ -146,7 +146,6 @@ int sockprotocol(int);
 int hostprotocol(char *);
 void real_killsock(int, const char *, int);
 int answer(int, char *, in_addr_t *, port_t *, int);
-int findanyidx(register int);
 int findanysnum(register int);
 int open_listen(port_t *);
 int open_listen_by_af(port_t *, int);