Browse Source

* dprintf() now longer uses a static char buffer, don't know why it was
* Now appending \r\n for server data, using write_to_server()


svn: 1579

Bryan Drewery 21 years ago
parent
commit
8eaa6e7707

+ 8 - 5
src/dccutil.c

@@ -157,14 +157,13 @@ colorbuf(char *buf, size_t len, int idx)
 void
 void
 dprintf(int idx, const char *format, ...)
 dprintf(int idx, const char *format, ...)
 {
 {
-  static char buf[1024] = "";
+  char buf[1024] = "";
   size_t len;
   size_t len;
   va_list va;
   va_list va;
 
 
   va_start(va, format);
   va_start(va, format);
   egg_vsnprintf(buf, 1023, format, va);
   egg_vsnprintf(buf, 1023, format, va);
   va_end(va);
   va_end(va);
-
   /* We can not use the return value vsnprintf() to determine where
   /* We can not use the return value vsnprintf() to determine where
    * to null terminate. The C99 standard specifies that vsnprintf()
    * to null terminate. The C99 standard specifies that vsnprintf()
    * shall return the number of bytes that would be written if the
    * shall return the number of bytes that would be written if the
@@ -199,9 +198,13 @@ dprintf(int idx, const char *format, ...)
       case DP_SERVER_NEXT:
       case DP_SERVER_NEXT:
       case DP_HELP_NEXT:
       case DP_HELP_NEXT:
       case DP_DUMP:
       case DP_DUMP:
-        if ((idx == DP_DUMP || floodless) && server_online && serv != -1)
-          tputs(serv, buf, len);
-        else
+        len -= remove_crlf_r(buf);
+
+        if ((idx == DP_DUMP || floodless) && server_online && serv != -1) {
+          if (debug_output)
+            putlog(LOG_SRVOUT, "@", "[m->] %s", buf);
+          write_to_server(buf, len);
+        } else
           queue_server(idx, buf, len);
           queue_server(idx, buf, len);
         break;
         break;
 #endif /* LEAF */
 #endif /* LEAF */

+ 2 - 1
src/mod/irc.mod/chan.c

@@ -1065,7 +1065,7 @@ do_take(struct chanset_t *chan)
   register unsigned int lines_max = 5, lines = 0, deopn, i;
   register unsigned int lines_max = 5, lines = 0, deopn, i;
 
 
   if (floodless)
   if (floodless)
-    lines_max = 10;
+    lines_max = 15;
 
 
   for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
   for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
     hasop = (m->flags & CHANOP);
     hasop = (m->flags & CHANOP);
@@ -1117,6 +1117,7 @@ do_take(struct chanset_t *chan)
     else
     else
       modeline = take_massopline(op, &to_op);
       modeline = take_massopline(op, &to_op);
     strcat(work, modeline);
     strcat(work, modeline);
+    strcat(work, "\r");
     strcat(work, "\n");
     strcat(work, "\n");
     lines++;
     lines++;
     free(modeline);
     free(modeline);

+ 1 - 0
src/mod/irc.mod/cmdsirc.c

@@ -784,6 +784,7 @@ void mdop_request(char *botnick, char *code, char *par)
       strcat(work, p);
       strcat(work, p);
       cnt++;
       cnt++;
     }
     }
+    strcat(work, "\r");
     strcat(work, "\n");
     strcat(work, "\n");
   }
   }
   tputs(serv, work, strlen(work));
   tputs(serv, work, strlen(work));

+ 13 - 13
src/mod/irc.mod/mode.c

@@ -131,7 +131,7 @@ flush_cookies(struct chanset_t *chan, int pri)
     if (pri == QUICK) {
     if (pri == QUICK) {
       char outbuf[201] = "";
       char outbuf[201] = "";
 
 
-      sprintf(outbuf, "MODE %s %s\n", chan->name, out);
+      sprintf(outbuf, "MODE %s %s\r\n", chan->name, out);
       tputs(serv, outbuf, strlen(outbuf));
       tputs(serv, outbuf, strlen(outbuf));
       /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
       /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
     } else
     } else
@@ -269,7 +269,7 @@ flush_mode(struct chanset_t *chan, int pri)
     if (pri == QUICK) {
     if (pri == QUICK) {
       char outbuf[201] = "";
       char outbuf[201] = "";
 
 
-      sprintf(outbuf, "MODE %s %s\n", chan->name, out);
+      sprintf(outbuf, "MODE %s %s\r\n", chan->name, out);
       tputs(serv, outbuf, strlen(outbuf));
       tputs(serv, outbuf, strlen(outbuf));
       /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
       /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
     } else
     } else
@@ -515,13 +515,13 @@ got_op(struct chanset_t *chan, memberlist *m, memberlist *mv)
       char outbuf[101] = ""; 
       char outbuf[101] = ""; 
 
 
       if (num == 4) {
       if (num == 4) {
-        sprintf(outbuf, "MODE %s -o %s\n", chan->name, mv->nick);
+        sprintf(outbuf, "MODE %s -o %s\r\n", chan->name, mv->nick);
       } else if (num == 5) {
       } else if (num == 5) {
-        sprintf(outbuf, "MODE %s -o %s\n", chan->name, m->nick);
+        sprintf(outbuf, "MODE %s -o %s\r\n", chan->name, m->nick);
       } else if (num == 6) {
       } else if (num == 6) {
-        sprintf(outbuf, "KICK %s %s :%s\n", chan->name, mv->nick, response(RES_BITCHOPPED));
+        sprintf(outbuf, "KICK %s %s :%s\r\n", chan->name, mv->nick, response(RES_BITCHOPPED));
       } else if (num == 7) {
       } else if (num == 7) {
-        sprintf(outbuf, "KICK %s %s :%s\n", chan->name, m->nick, response(RES_BITCHOP));
+        sprintf(outbuf, "KICK %s %s :%s\r\n", chan->name, m->nick, response(RES_BITCHOP));
       } else
       } else
         add_mode(chan, '-', 'o', mv->nick);
         add_mode(chan, '-', 'o', mv->nick);
 
 
@@ -1007,7 +1007,7 @@ gotmode(char *from, char *msg)
           if (role && (!u || (u && !u->bot)) && m && !chan_sentkick(m)) {
           if (role && (!u || (u && !u->bot)) && m && !chan_sentkick(m)) {
             if (deops >= 3) {
             if (deops >= 3) {
               m->flags |= SENTKICK;
               m->flags |= SENTKICK;
-              sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
+              sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
               tputs(serv, tmp, strlen(tmp));
               tputs(serv, tmp, strlen(tmp));
               if (u) {
               if (u) {
                 sprintf(tmp, "Mass deop on %s by %s", chan->dname, m->nick);
                 sprintf(tmp, "Mass deop on %s by %s", chan->dname, m->nick);
@@ -1019,7 +1019,7 @@ gotmode(char *from, char *msg)
             if (ops >= 3) {
             if (ops >= 3) {
               if (channel_nomop(chan)) {
               if (channel_nomop(chan)) {
                 m->flags |= SENTKICK;
                 m->flags |= SENTKICK;
-                sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
+                sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
                 tputs(serv, tmp, strlen(tmp));
                 tputs(serv, tmp, strlen(tmp));
                 if (u) {
                 if (u) {
                   sprintf(tmp, "Mass op on %s by %s", chan->dname, m->nick);
                   sprintf(tmp, "Mass op on %s by %s", chan->dname, m->nick);
@@ -1053,7 +1053,7 @@ gotmode(char *from, char *msg)
                   case 1:
                   case 1:
                     /* Kick opper */
                     /* Kick opper */
                     if (!m || !chan_sentkick(m)) {
                     if (!m || !chan_sentkick(m)) {
-                      sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_BADOP));
+                      sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_BADOP));
                       tputs(serv, tmp, strlen(tmp));
                       tputs(serv, tmp, strlen(tmp));
                       if (m)
                       if (m)
                         m->flags |= SENTKICK;
                         m->flags |= SENTKICK;
@@ -1078,7 +1078,7 @@ gotmode(char *from, char *msg)
                       if (mo) {
                       if (mo) {
                         if (!(mo->flags & CHANOP)) {
                         if (!(mo->flags & CHANOP)) {
                           if (!chan_sentkick(mo)) {
                           if (!chan_sentkick(mo)) {
-                            sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix, response(RES_BADOPPED));
+                            sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, trg, kickprefix, response(RES_BADOPPED));
                             tputs(serv, tmp, strlen(tmp));
                             tputs(serv, tmp, strlen(tmp));
                             mo->flags |= SENTKICK;
                             mo->flags |= SENTKICK;
                           }
                           }
@@ -1108,7 +1108,7 @@ gotmode(char *from, char *msg)
                 case 1:
                 case 1:
                   /* Kick opper */
                   /* Kick opper */
                   if (!m || !chan_sentkick(m)) {
                   if (!m || !chan_sentkick(m)) {
-                    sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
+                    sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
                     tputs(serv, tmp, strlen(tmp));
                     tputs(serv, tmp, strlen(tmp));
                     if (m)
                     if (m)
                       m->flags |= SENTKICK;
                       m->flags |= SENTKICK;
@@ -1131,13 +1131,13 @@ gotmode(char *from, char *msg)
                     if (mv) {
                     if (mv) {
                       if (!(mv->flags & CHANOP) && !match_my_nick(mv->nick)) {
                       if (!(mv->flags & CHANOP) && !match_my_nick(mv->nick)) {
                         if (!chan_sentkick(mv)) {
                         if (!chan_sentkick(mv)) {
-                          sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, mv->nick, kickprefix, response(RES_MANUALOPPED));
+                          sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, mv->nick, kickprefix, response(RES_MANUALOPPED));
                           tputs(serv, tmp, strlen(tmp));
                           tputs(serv, tmp, strlen(tmp));
                           mv->flags |= SENTKICK;
                           mv->flags |= SENTKICK;
                         }
                         }
                       }
                       }
                     } else {
                     } else {
-                      sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix, response(RES_MANUALOPPED));
+                      sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, trg, kickprefix, response(RES_MANUALOPPED));
                       tputs(serv, tmp, strlen(tmp));
                       tputs(serv, tmp, strlen(tmp));
                     }
                     }
                   }
                   }

+ 2 - 1
src/mod/server.mod/cmdsserv.c

@@ -35,6 +35,7 @@ static void cmd_servers(int idx, char *par)
 static void cmd_dump(int idx, char *par)
 static void cmd_dump(int idx, char *par)
 {
 {
   putlog(LOG_CMDS, "*", "#%s# dump %s", dcc[idx].nick, par);
   putlog(LOG_CMDS, "*", "#%s# dump %s", dcc[idx].nick, par);
+
   if (!isowner(dcc[idx].nick)) {
   if (!isowner(dcc[idx].nick)) {
     dprintf(idx, "What?  You need '%shelp'\n", settings.dcc_prefix);
     dprintf(idx, "What?  You need '%shelp'\n", settings.dcc_prefix);
     return;
     return;
@@ -44,7 +45,7 @@ static void cmd_dump(int idx, char *par)
     return;
     return;
   }
   }
 
 
-  tputs(serv, par, strlen(par));
+  dprintf(DP_DUMP, "%s\n", par);
 }
 }
 
 
 static void cmd_jump(int idx, char *par)
 static void cmd_jump(int idx, char *par)

+ 8 - 34
src/mod/server.mod/server.c

@@ -143,11 +143,9 @@ static void deq_msg()
         burst++;
         burst++;
         continue;
         continue;
       }
       }
-      tputs(serv, modeq.head->msg, modeq.head->len);
-      if (debug_output) {
-	modeq.head->msg[strlen(modeq.head->msg) - 1] = 0; /* delete the "\n" */
+      write_to_server(modeq.head->msg, modeq.head->len);
+      if (debug_output)
         putlog(LOG_SRVOUT, "@", "[m->] %s", modeq.head->msg);
         putlog(LOG_SRVOUT, "@", "[m->] %s", modeq.head->msg);
-      }
       modeq.tot--;
       modeq.tot--;
       last_time += calc_penalty(modeq.head->msg);
       last_time += calc_penalty(modeq.head->msg);
       q = modeq.head->next;
       q = modeq.head->next;
@@ -167,9 +165,8 @@ static void deq_msg()
     burst++;
     burst++;
     if (fast_deq(DP_SERVER))
     if (fast_deq(DP_SERVER))
       return;
       return;
-    tputs(serv, mq.head->msg, mq.head->len);
+    write_to_server(mq.head->msg, mq.head->len);
     if (debug_output) {
     if (debug_output) {
-      mq.head->msg[strlen(mq.head->msg) - 1] = 0; /* delete the "\n" */
       putlog(LOG_SRVOUT, "@", "[s->] %s", mq.head->msg);
       putlog(LOG_SRVOUT, "@", "[s->] %s", mq.head->msg);
     }
     }
     mq.tot--;
     mq.tot--;
@@ -189,9 +186,8 @@ static void deq_msg()
     return;
     return;
   if (fast_deq(DP_HELP))
   if (fast_deq(DP_HELP))
     return;
     return;
-  tputs(serv, hq.head->msg, hq.head->len);
+  write_to_server(hq.head->msg, hq.head->len);
   if (debug_output) {
   if (debug_output) {
-    hq.head->msg[strlen(hq.head->msg) - 1] = 0; /* delete the "\n" */
     putlog(LOG_SRVOUT, "@", "[h->] %s", hq.head->msg);
     putlog(LOG_SRVOUT, "@", "[h->] %s", hq.head->msg);
   }
   }
   hq.tot--;
   hq.tot--;
@@ -212,8 +208,6 @@ static int calc_penalty(char * msg)
   char *cmd = NULL, *par1 = NULL, *par2 = NULL, *par3 = NULL;
   char *cmd = NULL, *par1 = NULL, *par2 = NULL, *par3 = NULL;
   register int penalty, i, ii;
   register int penalty, i, ii;
 
 
-  if (msg[strlen(msg) - 1] == '\n')
-    msg[strlen(msg) - 1] = '\0';
   cmd = newsplit(&msg);
   cmd = newsplit(&msg);
   if (msg)
   if (msg)
     i = strlen(msg);
     i = strlen(msg);
@@ -410,8 +404,6 @@ static bool fast_deq(int which)
   }
   }
   to = newsplit(&msg);
   to = newsplit(&msg);
   len = strlen(to);
   len = strlen(to);
-  if (to[len - 1] == '\n')
-    to[len -1] = 0;
   simple_sprintf(victims, "%s", to);
   simple_sprintf(victims, "%s", to);
   while (m) {
   while (m) {
     nm = m->next;
     nm = m->next;
@@ -422,8 +414,6 @@ static bool fast_deq(int which)
     nextcmd = newsplit(&nextmsg);
     nextcmd = newsplit(&nextmsg);
     nextto = newsplit(&nextmsg);
     nextto = newsplit(&nextmsg);
     len = strlen(nextto);
     len = strlen(nextto);
-    if (nextto[len - 1] == '\n')
-      nextto[len - 1] = 0;
     if ( strcmp(to, nextto) /* we don't stack to the same recipients */
     if ( strcmp(to, nextto) /* we don't stack to the same recipients */
         && !strcmp(cmd, nextcmd) && !strcmp(msg, nextmsg)
         && !strcmp(cmd, nextcmd) && !strcmp(msg, nextmsg)
         && ((strlen(cmd) + strlen(victims) + strlen(nextto)
         && ((strlen(cmd) + strlen(victims) + strlen(nextto)
@@ -447,8 +437,7 @@ static bool fast_deq(int which)
   if (doit) {
   if (doit) {
     simple_sprintf(tosend, "%s %s %s", cmd, victims, msg);
     simple_sprintf(tosend, "%s %s %s", cmd, victims, msg);
     len = strlen(tosend);
     len = strlen(tosend);
-    tosend[len - 1] = '\n';
-    tputs(serv, tosend, len);
+    write_to_server(tosend, len);
     m = h->head->next;
     m = h->head->next;
     free(h->head->msg);
     free(h->head->msg);
     free(h->head);
     free(h->head);
@@ -457,7 +446,6 @@ static bool fast_deq(int which)
       h->last = 0;
       h->last = 0;
     h->tot--;
     h->tot--;
     if (debug_output) {
     if (debug_output) {
-      tosend[len - 1] = 0;
       switch (which) {
       switch (which) {
         case DP_MODE:
         case DP_MODE:
           putlog(LOG_SRVOUT, "*", "[m=>] %s", tosend);
           putlog(LOG_SRVOUT, "*", "[m=>] %s", tosend);
@@ -495,22 +483,9 @@ void queue_server(int which, char *buf, int len)
     return;
     return;
 
 
   struct msgq_head *h = NULL, tempq;
   struct msgq_head *h = NULL, tempq;
-  struct msgq *q = NULL, *tq = NULL, *tqq = NULL;
+  struct msgq *q = NULL;
   int qnext = 0;
   int qnext = 0;
 
 
-  /* No queue for PING and PONG - drummer */
-  if (!egg_strncasecmp(buf, "PING", 4) || !egg_strncasecmp(buf, "PONG", 4)) {
-    if (buf[1] == 'I' || buf[1] == 'i')
-      lastpingtime = now;	/* lagmeter */
-    tputs(serv, buf, len);
-    if (debug_output) {
-      if (buf[len - 1] == '\n')
-        buf[len - 1] = 0;
-      putlog(LOG_SRVOUT, "@", "[m->] %s", buf);
-    }
-    return;
-  }
-
   switch (which) {
   switch (which) {
   case DP_MODE_NEXT:
   case DP_MODE_NEXT:
     qnext = 1;
     qnext = 1;
@@ -586,8 +561,6 @@ void queue_server(int which, char *buf, int len)
   }
   }
 
 
   if (debug_output && !h->warned) {
   if (debug_output && !h->warned) {
-    if (buf[len - 1] == '\n')
-      buf[len - 1] = 0;
     switch (which) {
     switch (which) {
     case DP_MODE:
     case DP_MODE:
       putlog(LOG_SRVOUT, "@", "[!m] %s", buf);
       putlog(LOG_SRVOUT, "@", "[!m] %s", buf);
@@ -952,7 +925,8 @@ static void server_secondly()
 static void server_check_lag()
 static void server_check_lag()
 {
 {
   if (server_online && !waiting_for_awake && !trying_server) {
   if (server_online && !waiting_for_awake && !trying_server) {
-    dprintf(DP_MODE, "PING :%li\n", now);
+    dprintf(DP_DUMP, "PING :%li\n", now);
+    lastpingtime = now;
     waiting_for_awake = 1;
     waiting_for_awake = 1;
   }
   }
 }
 }

+ 4 - 0
src/mod/server.mod/server.h

@@ -18,6 +18,10 @@
         else                                                            \
         else                                                            \
                 (x) = newsplit(&(x));                                   \
                 (x) = newsplit(&(x));                                   \
 } while (0)
 } while (0)
+#define write_to_server(x,y) do {                       \
+        tputs(serv, (x), (y));                          \
+        tputs(serv, "\r\n", 2);                         \
+} while (0)
 
 
 
 
 struct server_list {
 struct server_list {