X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Flogcollector%2Fread_multiline.c;h=0d353d31f481fbe5639bc6cefefe38212a73475e;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=29a565d736305bf1cead0539b277c788a2b60cb2;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/logcollector/read_multiline.c b/src/logcollector/read_multiline.c old mode 100755 new mode 100644 index 29a565d..0d353d3 --- a/src/logcollector/read_multiline.c +++ b/src/logcollector/read_multiline.c @@ -1,5 +1,3 @@ -/* @(#) $Id$ */ - /* Copyright (C) 2010 Trend Micro Inc. * All right reserved. * @@ -9,99 +7,80 @@ * Foundation */ -/* Read the syslog */ - - #include "shared.h" #include "logcollector.h" - -/* Read multiline logs. */ +/* Read multiline logs */ void *read_multiline(int pos, int *rc, int drop_it) { int __ms = 0; int linecount; int linesgot = 0; - int buffer_size = 0; + size_t buffer_size = 0; char *p; char str[OS_MAXSTR + 1]; - char buffer[OS_MAXSTR +1]; - + char buffer[OS_MAXSTR + 1]; fpos_t fp_pos; buffer[0] = '\0'; buffer[OS_MAXSTR] = '\0'; - str[OS_MAXSTR]= '\0'; + str[OS_MAXSTR] = '\0'; *rc = 0; linecount = atoi(logff[pos].logformat); - /* Getting initial file location */ + /* Get initial file location */ fgetpos(logff[pos].fp, &fp_pos); - while(fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL) - { + while (fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL) { linesgot++; - /* Getting the last occurence of \n */ - if ((p = strrchr(str, '\n')) != NULL) - { + /* Get the last occurrence of \n */ + if ((p = strrchr(str, '\n')) != NULL) { *p = '\0'; } - + /* If we didn't get the new line, because the * size is large, send what we got so far. */ - else if(strlen(str) >= (OS_MAXSTR - OS_LOG_HEADER - 2)) - { + else if (strlen(str) >= (OS_MAXSTR - OS_LOG_HEADER - 2)) { /* Message size > maximum allowed */ __ms = 1; - } - else - { + } else { /* Message not complete. Return. */ - debug1("%s: Message not complete. Trying again: '%s'", ARGV0,str); + debug1("%s: Message not complete. Trying again: '%s'", ARGV0, str); fsetpos(logff[pos].fp, &fp_pos); break; - } - - #ifdef WIN32 - if ((p = strrchr(str, '\r')) != NULL) - { + } + +#ifdef WIN32 + if ((p = strrchr(str, '\r')) != NULL) { *p = '\0'; } - #endif - +#endif + debug2("%s: DEBUG: Reading message: '%s'", ARGV0, str); - - /* Adding to buffer. */ + /* Add to buffer */ buffer_size = strlen(buffer); - if(buffer[0] != '\0') - { + if (buffer[0] != '\0') { buffer[buffer_size] = ' '; buffer_size++; } - strncpy(buffer + buffer_size, str, OS_MAXSTR - buffer_size -2); + strncpy(buffer + buffer_size, str, OS_MAXSTR - buffer_size - 2); - - if(linesgot < linecount) - { + if (linesgot < linecount) { continue; } - - - /* Sending message to queue */ - if(drop_it == 0) - { - if(SendMSG(logr_queue, buffer, logff[pos].file, - LOCALFILE_MQ) < 0) - { + + /* Send message to queue */ + if (drop_it == 0) { + if (SendMSG(logr_queue, buffer, logff[pos].file, + LOCALFILE_MQ) < 0) { merror(QUEUE_SEND, ARGV0); - if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0) - { + if ((logr_queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) { ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH); } } @@ -110,26 +89,22 @@ void *read_multiline(int pos, int *rc, int drop_it) buffer[0] = '\0'; - /* Incorrectly message size */ - if(__ms) - { + /* Incorrect message size */ + if (__ms) { merror("%s: Large message size: '%s'", ARGV0, str); - while(fgets(str, OS_MAXSTR - 2, logff[pos].fp) != NULL) - { - /* Getting the last occurence of \n */ - if ((p = strrchr(str, '\n')) != NULL) - { + while (fgets(str, OS_MAXSTR - 2, logff[pos].fp) != NULL) { + /* Get the last occurrence of \n */ + if ((p = strrchr(str, '\n')) != NULL) { break; } } __ms = 0; } - + fgetpos(logff[pos].fp, &fp_pos); continue; } - return(NULL); + return (NULL); } -/* EOF */