00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <sys/types.h>
00005 #include <sys/socket.h>
00006 #include <netinet/in.h>
00007 #include <arpa/inet.h>
00008 #include "logparse.h"
00009
00010
00011 int lf_get_next_entry(FILE *fp, lf_entry &ne)
00012 {
00013 char buf[MAXBUF];
00014
00015 if ((fgets(buf, MAXBUF, fp) == NULL) || feof(fp) || ferror(fp)) {
00016 return 1;
00017 }
00018
00019
00020 char *p = buf, *q, *tmp1, *tmp2, *ret_code;
00021 u_int32_t lapse;
00022
00023
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
00031 q = strtok(NULL, " ");
00032 ne.cid = (u_int32_t)inet_addr(q);
00033
00034
00035 ret_code = strtok(NULL, " ");
00036 if (ret_code == NULL) { abort(); }
00037
00038
00039
00040
00041 q = strtok(NULL, " ");
00042 ne.size = strtoul(q, NULL, 10);
00043
00044
00045 q = strtok(NULL, " ");
00046 if (strcmp(q, "GET") != 0)
00047 return -1;
00048
00049
00050 q = strtok(NULL, " ");
00051 if (q == NULL) abort();
00052 if (strchr(q, '?') != NULL)
00053
00054 return -1;
00055 ne.url = new char[strlen(q) + 1];
00056 strcpy(ne.url, q);
00057
00058
00059 tmp1 = strtok(q, "/");
00060 if (strcmp(tmp1, "http:") != 0) {
00061
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
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;
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;
00084 }
00085 delete []tmp1;
00086
00087
00088 return 0;
00089 }
00090
00091
00092