#include #include #include #include #include #include #include #include "vdommstat.h" #define __DEBUG__ FALSE // You want to compile with debug? int main (int argc, char *argv[]) { char tmpstr[1024]; while (fgets(logline, 8192, stdin)!=NULL) { set_log_indexes (logline, &line_indexes); /******************************************************** * DEBUG CODE * ********************************************************/ #if __DEBUG__ // debug the TIMESTAMP strncpy (tmpstr, line_indexes.o_timestamp, line_indexes.l_timestamp); tmpstr[line_indexes.l_timestamp]=0; printf ("%s|", tmpstr); // debug the HOSTNAME strncpy (tmpstr, line_indexes.o_hostname, line_indexes.l_hostname); tmpstr[line_indexes.l_hostname]=0; printf ("%s|", tmpstr); // debug the TAG strncpy (tmpstr, line_indexes.o_tag, line_indexes.l_tag); tmpstr[line_indexes.l_tag]=0; printf ("%s|", tmpstr); // debug the CONTENT printf ("%12s", line_indexes.o_content); #endif /******************************************************** * END OF DEBUG CODE * ********************************************************/ // Now we begin checking the TAG's for controls we require if (strncmp (line_indexes.o_tag, "sm-mta", line_indexes.l_tag) == 0) { content_pid_indexes (line_indexes.o_content, &line_indexes); //printf("%.*f\n", 8, 123.456); printf ("%.*s\n", line_indexes.l_pid, line_indexes.o_pid); content_qid_indexes (line_indexes.o_content, &line_indexes); printf ("%.*s\n", line_indexes.l_qid, line_indexes.o_qid); /* content_pid_indexes (line_indexes.o_content, &line_indexes); strncpy (tmpstr, line_indexes.o_pid, line_indexes.l_pid); tmpstr[line_indexes.l_pid]=0; printf ("%s", tmpstr); content_qid_indexes (line_indexes.o_content, &line_indexes); strncpy (tmpstr, line_indexes.o_qid, line_indexes.l_qid); tmpstr[line_indexes.l_qid]=0; printf ("%s\n", tmpstr); */ } } } /**************************************************************************** * Locates the string location and lenght for TIMESTAMP HOSTNAME TAG CONTENT * ****************************************************************************/ void set_log_indexes (char *line, struct slidx *indexes) { bool btmp; char *eotidx; unsigned char ctmp; unsigned int n; // Set the index and length of TIMESTAMP indexes->o_timestamp = line; indexes->l_timestamp = 15; // Set the index and length of the HOSTNAME indexes->o_hostname = line + 16; indexes->l_hostname = strcspn (&line[16], " "); // Set the index and lenght of the TAG indexes->o_tag = line + (17 + indexes->l_hostname); eotidx = indexes->o_tag; btmp = FALSE; n = 0; do { ctmp = *eotidx; if (ctmp == '[' || ctmp == ':' || ctmp == ' ') { btmp = TRUE; } else { eotidx++; n++; } } while (!btmp); indexes->l_tag = n; // Set the index of the CONTENT indexes->o_content = indexes->o_tag + indexes->l_tag; } /******************************************************** * Locates the location and lenght of the PID in CONTENT * ********************************************************/ void content_pid_indexes (char *line, struct slidx *indexes) { indexes->o_pid = line + 1; indexes->l_pid = (strcspn (line, "]: ") -1 ); } /************************************************************ * Locates the location and lenght of the QUEUEID in CONTENT * ************************************************************/ void content_qid_indexes (char *line, struct slidx *indexes) { indexes->o_qid = (strstr (line, "]: ") + 3); indexes->l_qid = (strcspn (indexes->o_qid, " ") - 1); } /************************************************ * Print out a section of the string * ************************************************/ // EOF