Преглед изворни кода

* Added cmd_bupdate
* Debugging code in the transfer/update
* Fixed up sone stuff in the netcore


svn: 892

Bryan Drewery пре 22 година
родитељ
комит
b0aa1c1afe
10 измењених фајлова са 77 додато и 33 уклоњено
  1. 2 2
      src/binary.c
  2. 3 3
      src/cmds.c
  3. 1 1
      src/main.c
  4. 1 1
      src/mod/compress.mod/compress.c
  5. 19 1
      src/mod/transfer.mod/transfer.c
  6. 26 1
      src/mod/update.mod/update.c
  7. 22 21
      src/net.c
  8. 1 1
      src/net.h
  9. 1 1
      src/shell.c
  10. 1 1
      src/stringfix.c

+ 2 - 2
src/binary.c

@@ -81,7 +81,7 @@ bin_md5(const char *fname, int todo)
         i -= 16;
         continue;
       }
-      if (fwrite(buf, 1, sizeof buf - 1, fn) != (sizeof(buf) - 1)) {
+      if (fwrite(buf, sizeof buf - 1, 1, fn) != 1) {
         fclose(f);
         fclose(fn);
         unlink(s);
@@ -93,7 +93,7 @@ bin_md5(const char *fname, int todo)
         char *enc_hash = NULL;
 
         enc_hash = encrypt_string(SALT1, hash);
-        fwrite(enc_hash, 1, strlen(enc_hash), fn);
+        fwrite(enc_hash, strlen(enc_hash), 1, fn);
         i = strlen(enc_hash);			/* skip the next strlen(enc_hash) bytes */
         free(enc_hash);
       }

+ 3 - 3
src/cmds.c

@@ -1951,11 +1951,11 @@ static void cmd_debug(struct userrec *u, int idx, char *par)
 
   if (par[0])
     cmd = newsplit(&par);
-  if (cmd && !strcmp(cmd, "timesync") || !cmd)
+  if (!cmd || (cmd && !strcmp(cmd, "timesync")))
     dprintf(idx, "Timesync: %li (%li)\n", now + timesync, timesync);
-  if (cmd && !strcmp(cmd, "now") || !cmd)
+  if (!cmd || (cmd && !strcmp(cmd, "now")))
     dprintf(idx, "Now: %li\n", now);
-  if (cmd && !strcmp(cmd, "role") || !cmd)
+  if (!cmd || (cmd && !strcmp(cmd, "role")))
     dprintf(idx, "Role: %d\n", role);
   if (!cmd || (cmd &&!strcmp(cmd, "net")))
     tell_netdebug(idx);

+ 1 - 1
src/main.c

@@ -899,7 +899,7 @@ int main(int argc, char **argv)
 
   while (1) {
     int socket_cleanup = 0, i, xx;
-    char buf[SGRAB + 9] = "";
+    char buf[SGRAB + 10] = "";
 
     /* Lets move some of this here, reducing the numer of actual
      * calls to periodic_timers

+ 1 - 1
src/mod/compress.mod/compress.c

@@ -146,7 +146,7 @@ static int uncompress_to_file(char *f_src, char *f_target)
     }
     if (!len)
       break;
-    if ((int) fwrite(buf, 1, (unsigned int) len, fout) != len) {
+    if ((int) fwrite(buf, (unsigned int) len, 1, fout) != 1) {
       putlog(LOG_MISC, "*", "Failed to uncompress file `%s': fwrite failed: %s.",
 	     f_src, strerror(errno));
       return COMPF_ERROR;

+ 19 - 1
src/mod/transfer.mod/transfer.c

@@ -318,6 +318,9 @@ void eof_dcc_fork_send(int idx)
   lostdcc(idx);
 }
 
+int tlen = 0;
+int tslen = 0;
+
 static void eof_dcc_send(int idx)
 {
   int ok, j;
@@ -330,6 +333,7 @@ static void eof_dcc_send(int idx)
 
     /* Success */
     ok = 0;
+putlog(LOG_MISC, "*", "tlen: %d tslen: %d length: %d status: %d", tlen, tslen, dcc[idx].u.xfer->length, dcc[idx].status);
     if (!strcmp(dcc[idx].nick, "*users")) {
       finish_share(idx);
       killsock(dcc[idx].sock);
@@ -720,10 +724,18 @@ void eof_dcc_get(int idx)
 
 void dcc_send(int idx, char *buf, int len)
 {
-  char s[512] = "", *b = NULL;
+  char s[SGRAB + 2] = "", *b = NULL;
   unsigned long sent;
 
   fwrite(buf, len, 1, dcc[idx].u.xfer->f);
+
+//  if (len != strlen(buf))
+//;
+//    putlog(LOG_MISC, "*", "fwrite() came up WRONG!! len: %d strlen: %d", len, strlen(buf));
+
+  tlen += len;
+  tslen += strlen(buf);
+
   dcc[idx].status += len;
   /* Put in network byte order */
   sent = dcc[idx].status;
@@ -959,10 +971,16 @@ void dcc_fork_send(int idx, char *x, int y)
   if (dcc[idx].type != &DCC_FORK_SEND)
     return;
   dcc[idx].type = &DCC_SEND;
+//  dcc[idx].status = 0;
+putlog(LOG_MISC, "*", "status: %d", dcc[idx].status);
   dcc[idx].u.xfer->start_time = now;
   egg_snprintf(s1, sizeof s1, "%s!%s", dcc[idx].nick, dcc[idx].host);
   if (strcmp(dcc[idx].nick, "*users") && strcmp(dcc[idx].nick, "*binary"))
     putlog(LOG_MISC, "*", TRANSFER_DCC_CONN, dcc[idx].u.xfer->origname, s1);
+  tlen = 0;
+  tslen = 0;
+
+
 }
 
 struct dcc_table DCC_GET =

+ 26 - 1
src/mod/update.mod/update.c

@@ -73,9 +73,12 @@ static void update_fileq(int idx, char *par)
   if (!isupdatehub()) {
 #endif /* LEAF */
     dprintf(idx, "sb uy\n");
-  } else if (isupdatehub()) {
+  } 
+#ifdef HUB
+  else if (isupdatehub()) {
     dprintf(idx, "sb un I am the update hub, NOT YOU.\n");
   }
+#endif /* HUB */
 }
 
 /* us <ip> <port> <length>
@@ -472,10 +475,32 @@ void update_report(int idx, int details)
   }
 }
 
+#ifdef HUB
+static void cmd_bupdate(struct userrec *u, int idx, char *par)
+{
+  int i;
+
+  for (i = 0; i < dcc_total; i++) {
+    if (!egg_strcasecmp(dcc[i].nick, par)) {
+      dprintf(i, "sb u?\n");
+      dcc[i].status &= ~(STAT_SENDINGU | STAT_UPDATED);
+      dcc[i].status |= STAT_OFFEREDU;
+    }
+  }
+}
+
+cmd_t update_cmds[] =
+{
+  {"bupdate",		"a",	(Function) cmd_bupdate,		NULL},
+  {NULL,		NULL,	NULL,				NULL}
+};
+#endif /* HUB */
+
 void update_init()
 {
   add_builtins("bot", update_bot);
 #ifdef HUB
+  add_builtins("dcc", update_cmds);
   timer_create_secs(30, "check_updates", (Function) check_updates);
 #endif /* HUB */
   def_dcc_bot_kill = DCC_BOT.kill;

+ 22 - 21
src/net.c

@@ -1072,7 +1072,7 @@ static int sockread(char *s, int *len)
   fd_set fd;
   int fds = 0, i, x, fdtmp;
   struct timeval t;
-  int grab = SGRAB;
+  int grab = SGRAB + 1;
   egg_timeval_t howlong;
 
   if (timer_get_shortest(&howlong)) {
@@ -1310,13 +1310,12 @@ char *botlink_encrypt(int snum, char *src)
 
 int sockgets(char *s, int *len)
 {
-  char xx[SGRAB + 3] = "", *p = NULL, *px = NULL;
-  int ret, i, data = 0, grab = SGRAB+1;
+  char xx[SGRAB + 4] = "", *p = NULL, *px = NULL;
+  int ret, i, data = 0;
 
   for (i = 0; i < MAXSOCKS; i++) {
     /* Check for stored-up data waiting to be processed */
-    if (!(socklist[i].flags & SOCK_UNUSED) &&
-	!(socklist[i].flags & SOCK_BUFFER) && (socklist[i].inbuf != NULL)) {
+    if (!(socklist[i].flags & SOCK_UNUSED) && !(socklist[i].flags & SOCK_BUFFER) && (socklist[i].inbuf != NULL)) {
       if (!(socklist[i].flags & SOCK_BINARY)) {
 	/* look for \r too cos windows can't follow RFCs */
 	p = strchr(socklist[i].inbuf, '\n');
@@ -1324,10 +1323,10 @@ int sockgets(char *s, int *len)
 	  p = strchr(socklist[i].inbuf, '\r');
 	if (p != NULL) {
 	  *p = 0;
-	  if (strlen(socklist[i].inbuf) > (grab - 2))
-	    socklist[i].inbuf[(grab - 2)] = 0;
+	  if (strlen(socklist[i].inbuf) > SGRAB)
+	    socklist[i].inbuf[SGRAB] = 0;
 	  strcpy(s, socklist[i].inbuf);
-	  px = (char *) calloc(1, strlen(p + 1) + 1);
+	  px = calloc(1, strlen(p + 1) + 1);
 	  strcpy(px, p + 1);
 	  free(socklist[i].inbuf);
 	  if (px[0])
@@ -1345,16 +1344,17 @@ int sockgets(char *s, int *len)
 	  return socklist[i].sock;
 	}
       } else {
+/* FIXME, THESE SGRABS SHOULD BE 510 I THINK. */
 	/* Handling buffered binary data (must have been SOCK_BUFFER before). */
-	if (socklist[i].inbuflen <= (grab - 2)) {
+	if (socklist[i].inbuflen <= SGRAB) {
 	  *len = socklist[i].inbuflen;
 	  egg_memcpy(s, socklist[i].inbuf, socklist[i].inbuflen);
 	  free(socklist[i].inbuf);
           socklist[i].inbuf = NULL;
 	  socklist[i].inbuflen = 0;
 	} else {
-	  /* Split up into chunks of grab bytes. */
-	  *len = (grab - 2);
+	  /* Split up into chunks of SGRAB bytes. */
+	  *len = SGRAB;
 	  egg_memcpy(s, socklist[i].inbuf, *len);
 	  egg_memcpy(socklist[i].inbuf, socklist[i].inbuf + *len, *len);
 	  socklist[i].inbuflen -= *len;
@@ -1384,7 +1384,7 @@ int sockgets(char *s, int *len)
       socklist[ret].flags &= ~SOCK_STRONGCONN;
       /* Buffer any data that came in, for future read. */
       socklist[ret].inbuflen = *len;
-      socklist[ret].inbuf = (char *) calloc(1, *len + 1);
+      socklist[ret].inbuf = calloc(1, *len + 1);
       /* It might be binary data. You never know. */
       egg_memcpy(socklist[ret].inbuf, xx, *len);
       socklist[ret].inbuf[*len] = 0;
@@ -1412,21 +1412,21 @@ int sockgets(char *s, int *len)
   /* Might be necessary to prepend stored-up data! */
   if (socklist[ret].inbuf != NULL) {
     p = socklist[ret].inbuf;
-    socklist[ret].inbuf = (char *) calloc(1, strlen(p) + strlen(xx) + 1);
+    socklist[ret].inbuf = calloc(1, strlen(p) + strlen(xx) + 1);
     strcpy(socklist[ret].inbuf, p);
     strcat(socklist[ret].inbuf, xx);
     free(p);
-    if (strlen(socklist[ret].inbuf) < grab) {
+    if (strlen(socklist[ret].inbuf) < (SGRAB + 2)) {
       strcpy(xx, socklist[ret].inbuf);
       free(socklist[ret].inbuf);
       socklist[ret].inbuf = NULL;
       socklist[ret].inbuflen = 0;
     } else {
       p = socklist[ret].inbuf;
-      socklist[ret].inbuflen = strlen(p) - (grab - 2);
+      socklist[ret].inbuflen = strlen(p) - SGRAB;
       socklist[ret].inbuf = (char *) calloc(1, socklist[ret].inbuflen + 1); 
-      strcpy(socklist[ret].inbuf, p + (grab - 2));
-      *(p + (grab - 2)) = 0;
+      strcpy(socklist[ret].inbuf, p + SGRAB);
+      *(p + SGRAB) = 0;
       strcpy(xx, p);
       free(p);
       /* (leave the rest to be post-pended later) */
@@ -1441,14 +1441,15 @@ int sockgets(char *s, int *len)
     strcpy(s, xx);
 /*    strcpy(xx, p + 1); */
     sprintf(xx, "%s", p + 1);
-    if (s[0] && strlen(s) && (s[strlen(s) - 1] == '\r'))
+//    if (s[0] && strlen(s) && (s[strlen(s) - 1] == '\r'))
+    if (s[strlen(s) - 1] == '\r')
       s[strlen(s) - 1] = 0;
     data = 1;			/* DCC_CHAT may now need to process a blank line */
 /* NO! */
 /* if (!s[0]) strcpy(s," ");  */
   } else {
     s[0] = 0;
-    if (strlen(xx) >= (grab - 2)) {
+    if (strlen(xx) >= SGRAB) {
       /* String is too long, so just insert fake \n */
       strcpy(s, xx);
       xx[0] = 0;
@@ -1469,13 +1470,13 @@ int sockgets(char *s, int *len)
   if (socklist[ret].inbuf != NULL) {
     p = socklist[ret].inbuf;
     socklist[ret].inbuflen = strlen(p) + strlen(xx);
-    socklist[ret].inbuf = (char *) calloc(1, socklist[ret].inbuflen + 1);
+    socklist[ret].inbuf = calloc(1, socklist[ret].inbuflen + 1);
     strcpy(socklist[ret].inbuf, xx);
     strcat(socklist[ret].inbuf, p);
     free(p);
   } else {
     socklist[ret].inbuflen = strlen(xx);
-    socklist[ret].inbuf = (char *) calloc(1, socklist[ret].inbuflen + 1);
+    socklist[ret].inbuf = calloc(1, socklist[ret].inbuflen + 1);
     strcpy(socklist[ret].inbuf, xx);
   }
   if (data) {

+ 1 - 1
src/net.h

@@ -39,7 +39,7 @@
 #  endif
 #endif
 
-#define SGRAB 2011         /* How much data to allow through sockets. */
+#define SGRAB 2010         /* How much data to allow through sockets. */
 
 enum {
   EGG_OPTION_SET        = 1,    /* Set option(s).               */

+ 1 - 1
src/shell.c

@@ -380,7 +380,7 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
   }
   unlink(tmpfile);
   if (input) {
-    if (fwrite(input, 1, strlen(input), inpFile) != strlen(input)) {
+    if (fwrite(input, strlen(input), 1, inpFile) != 1) {
       fclose(inpFile);
       putlog(LOG_ERRORS, "*", "exec: Couldn't write to '%s': %s", tmpfile, strerror(errno));
       return 0;

+ 1 - 1
src/stringfix.c

@@ -162,7 +162,7 @@ int main(int argc, char *argv[0])
   }
 
   if ((f = fopen(argv[2], "w"))) {
-    fwrite(outbuf, 1, strlen(outbuf), f);
+    fwrite(outbuf, strlen(outbuf), 1, f);
     fclose(f);
   }
   /*  printf(outbuf); */