Beispiel #1
0
int irc_handle_data(irc_t *irc) {
   char tempbuffer[MSG_LEN];
   int rc, i;

   if ( (rc = sck_recv(irc->s, tempbuffer, sizeof(tempbuffer) - 2 ) ) <= 0 ) {
      fprintf(stderr, "Still trying to figure out this error\n");
      return -1;
   }
   tempbuffer[rc] = '\0';
   for ( i = 0; i < rc; ++i ) {
      switch (tempbuffer[i]) {
         case '\r':
         case '\n': {
            irc->servbuf[irc->bufptr] = '\0';
            irc->bufptr = 0;
            if ( irc_parse_action(irc) < 0 )
               return -1;
            break;
         }
         default: {
            irc->servbuf[irc->bufptr] = tempbuffer[i];
            if ( irc->bufptr >= (sizeof ( irc->servbuf ) -1 ) ); // Overflow!
            else
               irc->bufptr++;
         }
      }
   }
   return 0;
}
Beispiel #2
0
int irc_handle_data(irc_t *irc) {
    char tempbuffer[1024];
    int rc, i;
    if ((rc = sck_recv(irc->s, tempbuffer, sizeof(tempbuffer) - 2)) <= 0) {
        fprintf(stderr, ":v\n");
        return -1;
    }
    tempbuffer[rc] = '\0';
    for (i = 0; i < rc; ++i) {
        switch (tempbuffer[i]) {
            case '\r':
            case '\n':
                irc->servbuf[irc->bufptr] = '\0';
                irc->bufptr = 0;
                return irc_parse_action(irc);
            default:
                irc->servbuf[irc->bufptr] = tempbuffer[i];
                if (irc->bufptr < (sizeof (irc->servbuf) - 1)) {
                    irc->bufptr++;
                }
        }
    }
    return 0;
}