#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "config.h"Include dependency graph for ucb/logparse.h:

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

Go to the source code of this file.
Compounds | |
| struct | lf_entry_st |
Defines | |
| #define | PB_CLNT_NO_CACHE 1 |
| #define | PB_CLNT_KEEP_ALIVE 2 |
| #define | PB_CLNT_CACHE_CNTRL 4 |
| #define | PB_CLNT_IF_MOD_SINCE 8 |
| #define | PB_CLNT_UNLESS 16 |
| #define | PB_SRVR_NO_CACHE 1 |
| #define | PB_SRVR_CACHE_CNTRL 2 |
| #define | PB_SRVR_EXPIRES 4 |
| #define | PB_SRVR_LAST_MODIFIED 8 |
Typedefs | |
| typedef lf_entry_st | lf_entry |
Functions | |
| int | lf_get_next_entry (int logfile_fd, lf_entry *nextentry, int vers) |
| void | lf_convert_order (lf_entry *convertme) |
| int | lf_write (FILE *outf, lf_entry *writeme) |
| void | lf_dump (FILE *dumpf, lf_entry *dumpme) |
| void | lf_ntoa (unsigned long addr, char *addrbuf) |
|
|
Definition at line 50 of file ucb/logparse.h. |
|
|
Definition at line 51 of file ucb/logparse.h. |
|
|
Definition at line 49 of file ucb/logparse.h. |
|
|
Definition at line 48 of file ucb/logparse.h. Referenced by lf_analyze(). |
|
|
Definition at line 52 of file ucb/logparse.h. |
|
|
Definition at line 55 of file ucb/logparse.h. |
|
|
Definition at line 56 of file ucb/logparse.h. |
|
|
Definition at line 57 of file ucb/logparse.h. |
|
|
Definition at line 54 of file ucb/logparse.h. Referenced by lf_analyze(). |
|
|
|
|
|
This function will convert all of the entries in the record into/from host order. This function is its own inverse. This function cannot fail. Definition at line 118 of file ucb/logparse.cc. References lf_entry_st::cims, lf_entry_st::cip, lf_entry_st::cpt, lf_entry_st::crs, lf_entry_st::cru, lf_entry_st::rdl, lf_entry_st::rhl, lf_entry_st::sexp, lf_entry_st::sip, lf_entry_st::slmd, lf_entry_st::sls, lf_entry_st::slu, lf_entry_st::spt, lf_entry_st::srs, lf_entry_st::sru, and lf_entry_st::urllen. Referenced by lf_analyze(), and lf_dump().
00119 {
00120 convertme->crs = ntohl(convertme->crs);
00121 convertme->cru = ntohl(convertme->cru);
00122 convertme->srs = ntohl(convertme->srs);
00123 convertme->sru = ntohl(convertme->sru);
00124 convertme->sls = ntohl(convertme->sls);
00125 convertme->slu = ntohl(convertme->slu);
00126 convertme->cip = ntohl(convertme->cip);
00127 convertme->cpt = ntohs(convertme->cpt);
00128 convertme->sip = ntohl(convertme->sip);
00129 convertme->spt = ntohs(convertme->spt);
00130 convertme->cims = ntohl(convertme->cims);
00131 convertme->sexp = ntohl(convertme->sexp);
00132 convertme->slmd = ntohl(convertme->slmd);
00133 convertme->rhl = ntohl(convertme->rhl);
00134 convertme->rdl = ntohl(convertme->rdl);
00135 convertme->urllen = ntohs(convertme->urllen);
00136 }
|
|
||||||||||||
|
This function will dump a human-readable output version of the record to the passed-in file pointer. Assume that the record is in NETWORK order. Nothing can possibly go wrong. :) Definition at line 190 of file ucb/logparse.cc. References lf_entry_st::cims, lf_entry_st::cip, lf_entry_st::cprg, lf_entry_st::cpt, lf_entry_st::crs, lf_entry_st::cru, lf_convert_order(), lf_ntoa(), lf_entry_st::rdl, lf_entry_st::rhl, lf_entry_st::sexp, lf_entry_st::sip, lf_entry_st::slmd, lf_entry_st::sls, lf_entry_st::slu, lf_entry_st::sprg, lf_entry_st::spt, lf_entry_st::srs, lf_entry_st::sru, lf_entry_st::url, and lf_entry_st::urllen.
00191 {
00192 char addr1buf[128], addr2buf[128];
00193
00194 lf_convert_order(dumpme);
00195 lf_ntoa(dumpme->cip, addr1buf);
00196 lf_ntoa(dumpme->sip, addr2buf);
00197 fprintf(dumpf, "%lu:%lu %lu:%lu %lu:%lu %s:%hu %s:%hu %u %u ",
00198 dumpme->crs, dumpme->cru, dumpme->srs, dumpme->sru,
00199 dumpme->sls, dumpme->slu, addr1buf, dumpme->cpt,
00200 addr2buf, dumpme->spt, dumpme->cprg, dumpme->sprg);
00201 fprintf(dumpf, "%lu %lu %lu %lu %lu %u %s\n",
00202 dumpme->cims, dumpme->sexp, dumpme->slmd, dumpme->rhl,
00203 dumpme->rdl, dumpme->urllen, dumpme->url);
00204 lf_convert_order(dumpme);
00205 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
lf_get_next_entry will suck the next record out of the logfile, and return a lf_entry record witih the information stuffed into it. Note that memory WILL be allocated for the url field; the caller is responsible for freeing the memory when done. The logfile should have everything stored in network order, if all is well. This function returns 0 on success, 1 for EOF, and something else otherwise. On failure, no memory will have been allocated. Definition at line 55 of file ucb/logparse.cc. References lf_entry_st::cims, lf_entry_st::cip, correct_read(), lf_entry_st::cprg, lf_entry_st::cpt, lf_entry_st::crs, lf_entry_st::cru, lf_entry_st::rdl, lf_entry_st::rhl, lf_entry_st::sexp, lf_entry_st::sip, lf_entry_st::slmd, lf_entry_st::sls, lf_entry_st::slu, lf_entry_st::sprg, lf_entry_st::spt, lf_entry_st::srs, lf_entry_st::sru, lf_entry_st::url, lf_entry_st::urllen, and lf_entry_st::version. Referenced by main().
00056 {
00057 unsigned char blockbuf[60], *tmp;
00058 int uln, ret;
00059
00060 if ((ret = correct_read(logfile_fd, (char *)blockbuf, (size_t) 60)) != 60) {
00061 if (ret == 0)
00062 return 1;
00063 /* fprintf(stderr, "read 60 failed...%d\n", ret); */
00064 return 2;
00065 }
00066
00067 /* We got one! */
00068 nextentry->version = vers;
00069 memcpy( &(nextentry->crs), blockbuf+0, 4);
00070 memcpy( &(nextentry->cru), blockbuf+4, 4);
00071 memcpy( &(nextentry->srs), blockbuf+8, 4);
00072 memcpy( &(nextentry->sru), blockbuf+12, 4);
00073 memcpy( &(nextentry->sls), blockbuf+16, 4);
00074 memcpy( &(nextentry->slu), blockbuf+20, 4);
00075 memcpy( &(nextentry->cip), blockbuf+24, 4);
00076 memcpy( &(nextentry->cpt), blockbuf+28, 2);
00077 memcpy( &(nextentry->sip), blockbuf+30, 4);
00078 memcpy( &(nextentry->spt), blockbuf+34, 2);
00079 memcpy( &(nextentry->cprg), blockbuf+36, 1);
00080 memcpy( &(nextentry->sprg), blockbuf+37, 1);
00081 memcpy( &(nextentry->cims), blockbuf+38, 4);
00082 memcpy( &(nextentry->sexp), blockbuf+42, 4);
00083 memcpy( &(nextentry->slmd), blockbuf+46, 4);
00084 memcpy( &(nextentry->rhl), blockbuf+50, 4);
00085 memcpy( &(nextentry->rdl), blockbuf+54, 4);
00086 memcpy( &(nextentry->urllen), blockbuf+58, 2);
00087
00088 /* Now let's read in that url */
00089 uln = ntohs(nextentry->urllen);
00090 nextentry->url = (unsigned char *) malloc(sizeof(char) *
00091 (int) (uln + 1));
00092 if (nextentry->url == NULL) {
00093 fprintf(stderr, "out of memory in lf_get_next_netry!\n");
00094 exit(1);
00095 }
00096 if ((ret = correct_read(logfile_fd, (char *) (nextentry->url), (size_t) uln))
00097 != uln ) {
00098 if (ret == 0) {
00099 free(nextentry->url);
00100 return 1;
00101 }
00102 fprintf(stderr, "read of %d failed %d\n", (size_t) uln, ret);
00103 perror("aargh.");
00104 free(nextentry->url);
00105 return 2;
00106 }
00107 tmp = nextentry->url;
00108 *(tmp + uln) = '\0';
00109 return 0;
00110 }
|
Here is the call graph for this function:

|
||||||||||||
|
lf_ntoa takes a network IP address (in host order) and converts it to an ascii representation. addrbuf had better be 16 bytes or more... Definition at line 212 of file ucb/logparse.cc. Referenced by lf_dump().
00213 {
00214 sprintf(addrbuf, "%lu.%lu.%lu.%lu",
00215 (addr >> 24),
00216 (addr >> 16) % 256,
00217 (addr >> 8) % 256,
00218 (addr) % 256);
00219 }
|
|
||||||||||||
|
This function will write the entry pointed to by writeme back out to the file outf, in the canonical logfile binary format. It returns 0 on success, something else on failure. Definition at line 143 of file ucb/logparse.cc. References lf_entry_st::cims, lf_entry_st::cip, lf_entry_st::cprg, lf_entry_st::cpt, lf_entry_st::crs, lf_entry_st::cru, lf_entry_st::rdl, lf_entry_st::rhl, lf_entry_st::sexp, lf_entry_st::sip, lf_entry_st::slmd, lf_entry_st::sls, lf_entry_st::slu, lf_entry_st::sprg, lf_entry_st::spt, lf_entry_st::srs, lf_entry_st::sru, lf_entry_st::url, and lf_entry_st::urllen.
00144 {
00145 unsigned char blockbuf[60];
00146 int uln, ret;
00147
00148 memcpy( blockbuf+0, &(writeme->crs), 4);
00149 memcpy( blockbuf+4, &(writeme->cru), 4);
00150 memcpy( blockbuf+8, &(writeme->srs), 4);
00151 memcpy( blockbuf+12, &(writeme->sru), 4);
00152 memcpy( blockbuf+16, &(writeme->sls), 4);
00153 memcpy( blockbuf+20, &(writeme->slu), 4);
00154 memcpy( blockbuf+24, &(writeme->cip), 4);
00155 memcpy( blockbuf+28, &(writeme->cpt), 2);
00156 memcpy( blockbuf+30, &(writeme->sip), 4);
00157 memcpy( blockbuf+34, &(writeme->spt), 2);
00158 memcpy( blockbuf+36, &(writeme->cprg), 1);
00159 memcpy( blockbuf+37, &(writeme->sprg), 1);
00160 memcpy( blockbuf+38, &(writeme->cims), 4);
00161 memcpy( blockbuf+42, &(writeme->sexp), 4);
00162 memcpy( blockbuf+46, &(writeme->slmd), 4);
00163 memcpy( blockbuf+50, &(writeme->rhl), 4);
00164 memcpy( blockbuf+54, &(writeme->rdl), 4);
00165 memcpy( blockbuf+58, &(writeme->urllen), 2);
00166
00167 ret = fwrite(&(blockbuf[0]), 60, 1, outf);
00168 if (ret != 1) {
00169 fprintf(stderr, "write 60 failed...%d\n", ret);
00170 perror("arrgh1");
00171 return 1;
00172 }
00173
00174 /* Now let's write out that url */
00175 uln = ntohs(writeme->urllen);
00176 ret = fwrite(writeme->url, (size_t) uln, 1, outf);
00177 if (ret != 1) {
00178 fprintf(stderr, "write of %d failed %d\n", (size_t) uln, ret);
00179 perror("aargh.");
00180 return 2;
00181 }
00182 return 0;
00183 }
|
1.3.3