#include <stdio.h>
#include "Request.h"

const int LINE_SIZE = 5000;
class SquidLogFile
{
private:
  FILE* FP;
  
  // 0 if this is either closed or an open file, 1 if this is an open pipe.
  int isPipe;

  // Line is modified.
  int stringToRequest(char* line, SquidRequest& req);

public:
  SquidLogFile();

  // If fname = "-" then stdin is used as the input file.
  // If fname ends in ".gz" then is is opened as a pipe with gunzip -c fname
  // Otherwise, it is opened as a file.
  // Returns 0 on success -1 on failure.
  int open(const char* fname);

  // Reads the next transaction from the file.  
  // Returns 0 on success, 1 on EOF, -1 on failure.
  int read(SquidRequest& req);

  void close();
  
  ~SquidLogFile();
};
