Commit 7628bd0f authored by Anders Berg's avatar Anders Berg

Starting to get the structure right (I think). Thx for the NULL on each string Poul-Hennning :)

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@613 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 10b229b0
......@@ -28,19 +28,38 @@
/* Ordering-----------------------------------------------------------*/
/* Adding a struct to hold the data for the logline
*
*/
struct logline {
char df_h[4 * (3 + 1)]; // Datafield for %h (IP adress)
// // int y;
// // unsigned char *df_l; // Datafield for %l
// // unsigned char *df_u; // Datafield for %u
// // unsigned char *df_t; // Datafield for %t
// // unsigned char *df_r; // Datafield for %r
// // unsigned char *df_s; // Datafield for %s
// // unsigned char *df_b; // Datafield for %b
// // unsigned char *df_R; // Datafield for %{Referer}i
unsigned char *df_U; // Datafield for %{User-agent}i
};
/* We make a array of pointers to sbuf's. Sbuf is a string buffer.
* The buffer can be made/extended/cleared etc. through a API.
* The array is 65536 long because we will use sessionid as key.
*
*/
* * The buffer can be made/extended/cleared etc. through a API.
* * The array is 65536 long because we will use sessionid as key.
* *
* */
static struct sbuf *ob[65536];
static struct sbuf *ob[65536];
static struct logline ll[65536];
/*
* Clean order is called once in a while. It clears all the sessions that
* where never finished (SLT_SessionClose). Because the data is not complete
* we disregard the data.
*
*/
static void
......@@ -52,16 +71,6 @@ clean_order(void)
if (ob[u] == NULL)
continue;
sbuf_finish(ob[u]);
/* XXX delete this code? Probably, since we write data to disk/screen
* as soon as we have all the data we need anyway. If we are here
* we don't have all the data, hence we don't bother to write out.
*
*
* if (sbuf_len(ob[u]))
* printf("%s\n", sbuf_data(ob[u]));
*/
sbuf_clear(ob[u]);
}
}
......@@ -69,25 +78,13 @@ clean_order(void)
static void
extended_log_format(unsigned char *p, char *w_opt)
{
unsigned u, v;
int i,j,k;
unsigned char *ans;
unsigned u;
int i,j;
unsigned char *tmpPtr;
// Declare the int's that are used to determin if we have all data.
int ll_h = 0; // %h
int ll_l = 0; // %l
int ll_u = 0; // %u
int ll_t = 0; // %t
int ll_r = 0; // %r
int ll_s = 0; // %s
int ll_b = 0; // %b
int ll_R = 0; // %{Referer}i
int ll_U = 0; // %{User-agent}i
// Declare the data where we store the differnt parts
char df_h[4 * (3 + 1)]; // Datafield for %h (IP adress)
char df_l;
char df_u[65536];
char df_U[65536];
if (w_opt != NULL){
// printf(" Has w_opt\n");
......@@ -100,74 +97,43 @@ extended_log_format(unsigned char *p, char *w_opt)
ob[u] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
assert(ob[u] != NULL);
}
v = 0;
switch (p[0]) {
case SLT_SessionOpen:
// Finding the IP adress when data is: "XXX.XXX.XXX.XXX somenumber"
ans = strchr(p + 4, ' ');
j = ans - (p + 4); // length
//printf("Ip address: '%*.*s'\n", j, j, p + 4);
memcpy(df_h, p + 4, j);
df_h[j] = '\0';
//printf("Ip address: %s\n", df_h);
ll_h = 1;
tmpPtr = strchr(p + 4, ' ');
j = strlen(p + 4) - strlen(tmpPtr); // length of IP
strncpy(ll[u].df_h, p + 4, j);
ll[u].df_h[j] = '\0'; // put on a NULL at end of buffer.
break;
case SLT_RxHeader:
if (p[1] >= 11 && !strncasecmp((void *)&p[4], "user-agent:",11)){
// Could actually check for ll_h = 1 also in line above.
// If it is equal 1 we know a new client is in, hence a new User-Agent.
memcpy(df_U, p + 4, p[1]);
df_U[p[1]] = '\0';
//printf("Ip address: %s\n", df_U);
/*sbuf_bcat(ob[u], p + 4, p[1]);
sbuf_cat(ob[u], "\n");
sbuf_finish(ob[u]);
printf("%s", sbuf_data(ob[u]));
sbuf_clear(ob[u]);
*/
ll[u].df_U = strdup(p + 4);
}
break;
case SLT_StatAddr:
break;
case SLT_SessionClose:
printf("Closing session [%d]: %s %s\n",u, ll[u].df_h, ll[u].df_U);
break;
default:
v = 1;
break;
}
if (ll_h && ll_U) {
if (0) {
/* XXX Need to write some code to make the logline
sbuf_printf(ob[u], "%02x %3d %4d %-12s",
p[0], p[1], u, VSL_tags[p[0]]);
if (p[1] > 0) {
sbuf_cat(ob[u], " <");
sbuf_bcat(ob[u], p + 4, p[1]);
sbuf_cat(ob[u], ">");
}
sbuf_cat(ob[u], "\n");
*/
}
/* XXX Do I need this? When is u == 0? I can't seem to see
* it used before this place.
if (u == 0) {
sbuf_finish(ob[u]);
printf("%s", sbuf_data(ob[u]));
sbuf_clear(ob[u]);
return;
}
*/
}
......@@ -186,11 +152,8 @@ main(int argc, char **argv)
int i, c;
unsigned u, v;
unsigned char *p;
//int o_flag = 0;
//int l_flag = 0;
char *w_opt = NULL;
FILE *wfile = NULL;
// int h_opt = 0;
struct VSL_data *vd;
vd = VSL_New();
......@@ -229,43 +192,20 @@ main(int argc, char **argv)
break;
if (i == 0) {
if (w_opt == NULL) {
if (++v == 100)
if (++v == 100){
clean_order();
fflush(stdout);
} else if (++v == 100) {
/* Not sure if needed.
*
*fflush(wfile);
*/
printf("\n Inside the ++v==100 and w_opt is set.\n");
fflush(stdout);
}
}
usleep(50000);
continue;
}
v = 0;
/* XXX probably wanna throw this out. Not sure when needed.
if (wfile != NULL) {
i = fwrite(p, 4 + p[1], 1, wfile);
if (i != 1)
perror(w_opt);
u++;
if (!(u % 1000)) {
printf("%u\r", u);
fflush(stdout);
}
continue;
}
*/
extended_log_format(p, w_opt);
//printf("\n");
}
clean_order();
return (0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment