\param stop The character indicating the end of the word.
\retval 0 The word is extracted.
-\retval -1 The stop character was not found before the limit or the end of the string is reached.
+\retval -1 The stop character was not found before the limit is reached.
*/
\param stop The character indicating the end of the word.
\retval 0 The word is extracted.
-\retval -1 The stop character was not found before the limit or the end of the string is reached.
+\retval -1 The stop character was not found before the limit is reached.
*/
+/*! \fn int getword_skip(int limit, char *line, int stop)
+Skip one "word" from the text line and remove it from the text line. The word's boundary is defined
+by the \a stop character.
-/*! \fn int getword3(char *word, int limit, char *line, int stop)
-
-This function is now identical to getword().
-
-\param word The buffer to store the extracted word.
-\param limit The size of the buffer. If the stop character isn't found before that limit is reached,
+\param limit The maximum number of characters to skip. If the stop character isn't found before that limit is reached,
the function displays an error message and returns an error code.
\param line The text line from which the word must be extracted.
\param stop The character indicating the end of the word.
-\retval 0 The word is extracted.
-\retval -1 The stop character was not found before the limit or the end of the string is reached.
-
+\retval 0 The word is skipped.
+\retval -1 The stop character was not found before the limit is reached.
*/
int main(int argc,char *argv[])
{
+ enum isa_col_id {
+ ISACOL_Ip,
+ ISACOL_UserName,
+ ISACOL_Date,
+ ISACOL_Time,
+ ISACOL_TimeTaken,
+ ISACOL_Bytes,
+ ISACOL_Uri,
+ ISACOL_Status,
+ ISACOL_Last //last entry of the list !
+ };
FILE *fp_in = NULL, *fp_denied=NULL, *fp_authfail=NULL, *fp_log=NULL;
int narq=0;
int iarq=0;
int exstring=0;
- int i0=0,i1=-1,i2=-1,i3=-1,i4=-1,i5=-1,i6=-1,i7=-1,i8=-1;
+ int isa_ncols=0,isa_cols[ISACOL_Last];
long totregsl=0;
long totregsg=0;
long totregsx=0;
exit(1);
}
} else if(isalog) {
- if(!i0) {
- if (getword(val1,sizeof(val1),bufz,' ')<0){
+ if (bufz[0] == '#') {
+ int ncols,cols[ISACOL_Last];
+
+ fixendofline(bufz);
+ // remove the #Fields: column at the beginning of the line
+ if (getword_skip(1000,bufz,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- fixendofline(bufz);
+ for (ncols=0 ; ncols<ISACOL_Last ; ncols++) cols[ncols]=-1;
+ ncols=0;
while(bufz[0] != '\0') {
if (getword(val1,sizeof(val1),bufz,'\t')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if(strcmp(val1,"c-ip") == 0) i1=i0;
- if(strcmp(val1,"cs-username") == 0) i2=i0;
- if(strcmp(val1,"date") == 0) i3=i0;
- if(strcmp(val1,"time") == 0) i4=i0;
- if(strcmp(val1,"time-taken") == 0) i5=i0;
- if(strcmp(val1,"sc-bytes") == 0) i6=i0;
- if(strcmp(val1,"cs-uri") == 0) i7=i0;
- if(strcmp(val1,"sc-status") == 0) i8=i0;
- i0++;
+ if(strcmp(val1,"c-ip") == 0) cols[ISACOL_Ip]=ncols;
+ if(strcmp(val1,"cs-username") == 0) cols[ISACOL_UserName]=ncols;
+ if(strcmp(val1,"date") == 0) cols[ISACOL_Date]=ncols;
+ if(strcmp(val1,"time") == 0) cols[ISACOL_Time]=ncols;
+ if(strcmp(val1,"time-taken") == 0) cols[ISACOL_TimeTaken]=ncols;
+ if(strcmp(val1,"sc-bytes") == 0) cols[ISACOL_Bytes]=ncols;
+ if(strcmp(val1,"cs-uri") == 0) cols[ISACOL_Uri]=ncols;
+ if(strcmp(val1,"sc-status") == 0) cols[ISACOL_Status]=ncols;
+ ncols++;
}
- if (i1<0) {
- // not the line we are looking for
- i0=0;
+ if (cols[ISACOL_Ip]>=0) {
+ isa_ncols=ncols;
+ for (isa_ncols=0 ; isa_ncols<ncols ; isa_ncols++)
+ isa_cols[isa_ncols]=cols[isa_ncols];
}
+ continue;
}
- if (!fgets(bufz,sizeof(bufz),fp_in)) {
- fprintf(stderr,"SARG: read error in %s\n",arq);
- exit(1);
- }
- for (x=0 ; x<i0 ; x++) {
+ if (!isa_ncols) continue;
+ for (x=0 ; x<isa_ncols ; x++) {
if (getword(val1,sizeof(val1),bufz,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (x==i1) {
+ if (x==isa_cols[ISACOL_Ip]) {
if (strlen(val1)>=sizeof(ip)) {
printf("SARG: Maybe you have a broken IP in your %s file.\n",arq);
exit(1);
}
strcpy(ip,val1);
- } else if (x==i2) {
+ } else if (x==isa_cols[ISACOL_UserName]) {
if (strlen(val1)>=sizeof(user)) {
printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
exit(1);
}
strcpy(user,val1);
- } else if (x==i3) {
+ } else if (x==isa_cols[ISACOL_Date]) {
if (strlen(val1)>=sizeof(data)) {
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
strcpy(data,val1);
- } else if (x==i4) {
+ } else if (x==isa_cols[ISACOL_Time]) {
if (strlen(val1)>=sizeof(hora)) {
printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
exit(1);
}
strcpy(hora,val1);
- } else if (x==i5) {
+ } else if (x==isa_cols[ISACOL_TimeTaken]) {
if (strlen(val1)>=sizeof(elap)) {
printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq);
exit(1);
}
strcpy(elap,val1);
- } else if (x==i6) {
+ } else if (x==isa_cols[ISACOL_Bytes]) {
if (strlen(val1)>=sizeof(tam)) {
printf("SARG: Maybe you have a broken download size in your %s file.\n",arq);
exit(1);
}
strcpy(tam,val1);
- } else if (x==i7) {
+ } else if (x==isa_cols[ISACOL_Uri]) {
if (strlen(val1)>=sizeof(url)) {
printf("SARG: Maybe you have a broken URL in your %s file.\n",arq);
exit(1);
}
strcpy(url,val1);
- } else if (x==i8) {
+ } else if (x==isa_cols[ISACOL_Status]) {
if (strlen(val1)>=sizeof(code)) {
printf("SARG: Maybe you have a broken access code in your %s file.\n",arq);
exit(1);