- Timestamp:
- 11/26/08 02:51:23 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ithildin-1.1/modules/ircd/protocols/shared/rfc1459_io.c
r825 r828 22 22 int ret = 0; 23 23 char *s; 24 bool dirtybuffer; 24 25 25 26 /* If we were force-called (ep is NULL) we assume there is data in our … … 35 36 36 37 while (cp->buflen > 0) { 38 dirtybuffer = false; 37 39 /* if the buffer is full but no terminating character (\n) is 38 40 found, we cheat */ … … 45 47 s++; 46 48 49 /* A command without a newline, add it and note that the 50 * future contents of the buffer are dirty (handled below 51 * when we pass out the data) */ 47 52 if (s == cp->buf + cp->bufsize) { 48 53 cp->buf[cp->bufsize - 1] = '\n'; 49 54 s = cp->buf + cp->bufsize - 1; 55 dirtybuffer = true; 50 56 } 51 57 } else { … … 55 61 break; /* no separator found, try reading some more */ 56 62 } 57 /* make a local copy of the packet, then pass it off to the parser. 58 * Bump the rest of the contents of 'buf' down if we read more than 59 * we have parsed. */ 63 60 64 /* null-terminate and get rid of the [\r]\n sequence. */ 61 65 if (s > cp->buf && *(s - 1) == '\r') … … 63 67 else 64 68 *s = '\0'; 69 65 70 log_debug("[%s] <%s< %s", ircd.me->name, 66 71 (cp->cli != NULL ? cp->cli->nick : 67 72 (cp->srv != NULL ? cp->srv->name : "")), cp->buf); 68 if ((ret = packet_parse(cp)) == IRCD_CONNECTION_CLOSED) 69 return (void *)ret; /* connection closed, stop immediately */ 73 /* Don't parse the packet if the buffer is dirty, otherwise do 74 * call the parser. */ 75 if (!(cp->flags & IRCD_CONNFL_DIRTYBUFFER)) 76 { 77 if ((ret = packet_parse(cp)) == IRCD_CONNECTION_CLOSED) 78 return (void *)ret; /* connection closed, stop immediately */ 79 } else 80 cp->flags &= ~IRCD_CONNFL_DIRTYBUFFER; 81 70 82 s++; /* increment s, now we see if our packet contains more data */ 71 83 if (s - cp->buf < cp->buflen) { … … 77 89 *cp->buf = '\0'; /* zero it out */ 78 90 } 91 92 /* If the buffer is marked dirty, set the flag now on the 93 * connection (since we have passed off the previous command) */ 94 if (dirtybuffer) 95 cp->flags |= IRCD_CONNFL_DIRTYBUFFER; 79 96 80 97 if (ret == IRCD_PROTOCOL_CHANGED) … … 128 145 buf[sm.len++] = ' '; 129 146 130 sm.len += vsnprintf(&buf[sm.len], MAX_PACKET_LEN - 3 - sm.len, msg, 131 args); 147 sm.len += vsnprintf(&buf[sm.len], MAX_PACKET_LEN - sm.len, msg, args); 132 148 } 133 149 … … 139 155 (to != NULL ? to : ""), buf); 140 156 141 strcpy(&buf[sm.len], "\r\n"); 142 sm.len += 2; 157 /* Terminate the command */ 158 if (sm.len > MAX_PACKET_LEN - 2) 159 sm.len = MAX_PACKET_LEN - 2; 160 buf[sm.len++] = '\r'; 161 buf[sm.len++] = '\n'; 143 162 144 163 return &sm;
Note: See TracChangeset
for help on using the changeset viewer.
