#include <stdlib.h>
#include "config.h"
Include dependency graph for nlanr/logparse.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | lf_entry |
Functions | |
| int | lf_get_next_entry (FILE *fp, lf_entry &ne) |
Variables | |
| const int | MAXBUF = 4096 |
|
||||||||||||
|
Definition at line 11 of file nlanr/logparse.cc. References abort(), lf_entry::cid, MAXBUF, lf_entry::rt, lf_entry::sid, lf_entry::size, and lf_entry::url. 00012 { 00013 char buf[MAXBUF]; // must be large enough for a cache log 00014 00015 if ((fgets(buf, MAXBUF, fp) == NULL) || feof(fp) || ferror(fp)) { 00016 return 1; 00017 } 00018 00019 // Parse a line and fill an lf_entry 00020 char *p = buf, *q, *tmp1, *tmp2, *ret_code; 00021 u_int32_t lapse; 00022 00023 // first two entries: <TimeStamp> and <Elapsed Time> 00024 q = strtok(p, " "); 00025 ne.rt = strtod(q, NULL); 00026 q = strtok(NULL, " "); 00027 lapse = strtoul(q, NULL, 10); 00028 ne.rt -= (double)lapse/1000.0; 00029 00030 // Client address 00031 q = strtok(NULL, " "); 00032 ne.cid = (u_int32_t)inet_addr(q); 00033 00034 // Log tags, do not store them but use it to filter entries 00035 ret_code = strtok(NULL, " "); 00036 if (ret_code == NULL) { abort(); } 00037 // XXX Have to handle this return code in the end because we are using 00038 // strtok() and it cannot interleave two strings :( STUPID!! 00039 00040 // Page size 00041 q = strtok(NULL, " "); 00042 ne.size = strtoul(q, NULL, 10); 00043 00044 // Request method, GET only 00045 q = strtok(NULL, " "); 00046 if (strcmp(q, "GET") != 0) 00047 return -1; 00048 00049 // URL 00050 q = strtok(NULL, " "); 00051 if (q == NULL) abort(); 00052 if (strchr(q, '?') != NULL) 00053 // Do not accept any URL containing '?' 00054 return -1; 00055 ne.url = new char[strlen(q) + 1]; 00056 strcpy(ne.url, q); 00057 // Try to locate server name from the URL 00058 // XXX no more parsing from the original string!!!! 00059 tmp1 = strtok(q, "/"); 00060 if (strcmp(tmp1, "http:") != 0) { 00061 // How come this isn't a http request??? 00062 delete []ne.url; 00063 return -1; 00064 } 00065 tmp1 = strtok(NULL, "/"); 00066 if (tmp1 == NULL) abort(); 00067 ne.sid = new char[strlen(tmp1) + 1]; 00068 strcpy(ne.sid, tmp1); 00069 00070 // Now check return codes 00071 if (ret_code == NULL) abort(); 00072 tmp1 = new char[strlen(ret_code)+1]; 00073 strcpy(tmp1, ret_code); 00074 tmp2 = strtok(tmp1, "/"); 00075 tmp2 += 4; // Ignore the first 4 char "TCP_" 00076 if ((strcmp(tmp2, "MISS") == 0) || 00077 (strcmp(tmp2, "CLIENT_REFRESH_MISS") == 0) || 00078 (strcmp(tmp2, "IMS_MISS") == 0) || 00079 (strcmp(tmp2, "DENIED") == 0)) { 00080 delete []ne.url; 00081 delete []ne.sid; 00082 delete []tmp1; 00083 return -1; // Return negative to discard this entry 00084 } 00085 delete []tmp1; 00086 00087 // All the rest are useless, do not parse them 00088 return 0; 00089 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 17 of file nlanr/logparse.h. Referenced by lf_get_next_entry(). |
1.4.6