#!/usr/bin/env python

import pickle, socket

f = open('data')
data = f.read()
f.close()

entryCount = pickle.decode_long(data[20:24])
offset = 188

while entryCount:
  if len(data) < offset + 16:
    break

  entryLen = pickle.decode_long(data[offset + 12:offset + 16])
  if len(data) < offset + entryLen:
    break

  print str(offset) + ':' + str(offset + entryLen)

  chi = socket.inet_ntop(socket.AF_INET, data[offset + 36:offset + 40])
  print str(offset + 36) + ':' + str(offset + 40) + '  chi: ' + chi

  crc = chr(pickle.decode_long(data[offset + 40:offset + 48]))

  # LogAccessHttp::marshal_proxy_resp_squid_len()
  psql = pickle.decode_long(data[offset + 56:offset + 64])

  # LogAccessHttp::marshal_client_req_http_method()
  start = offset + 64
  end = data.index('\0', start)
  cqhm = data[start:end]
  print str(start) + ':' + str(end) + ' cqhm: ' + cqhm

  # LogAccessHttp::marshal_client_req_url_canon()
  start = (end + 1 - offset + 0x7 & ~0x7) + offset
  end = data.index('\0', start)
  cquc = data[start:end]
  print str(start) + ':' + str(end) + ' cquc: ' + cquc

  # LogAccessHttp::marshal_client_auth_user_name()
  start = (end + 1 - offset + 0x7 & ~0x7) + offset
  end = data.index('\0', start)
  caun = data[start:end]

  # LogAccessHttp::marshal_proxy_hierarchy_route()
  start = (end + 1 - offset + 0x7 & ~0x7) + offset
  end = start + 8
  phr = data[start:end]

  # LogAccessHttp::marshal_server_host_name()
  start = end
  end = data.index('\0', start)
  pqsn = data[start:end]
  print str(start) + ':' + str(end) + ' pqsn: ' + pqsn

  if entryCount == 36:
    a = open('tmp', 'w')
    a.write(data[offset:offset + entryLen])
    a.close()

  entryCount -= 1
  offset += entryLen

  print
