Skip to content

Commit

Permalink
fixed listing and added type="json" or type="pcap"
Browse files Browse the repository at this point in the history
  • Loading branch information
Per-Grana committed May 19, 2011
1 parent baef921 commit f8eb0b4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Pcap_file
m_packetbuffer = 0;
m_packetbuffer_len = 0;
m_eof = false;
m_snapshot_length = 0;
m_gzipped = false;
}
~Pcap_file()
{
Expand Down Expand Up @@ -149,7 +151,7 @@ class Pcap_file
return;
}
if (m_zipbuffer.m_buffer_len == m_zipbuffer.m_buffer_pos)
m_zip.inflate(m_filebuffer,m_zipbuffer);
m_zip.inflate(m_filebuffer,m_zipbuffer);
}
}
void set_gzipped()
Expand Down
17 changes: 14 additions & 3 deletions src/segzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ class Zip
public:
Zip()
{
m_init = true;
m_error = false;
m_init = true;
m_error = false;
m_run_end = false;
m_stream.next_out = 0;
m_stream.avail_out = 0;
}
~Zip()
{
if (m_run_end)
::inflateEnd(&m_stream);
}
bool inflate(Buffer &in,Buffer &out)
{
if (m_error)
{
in.m_buffer_pos = in.m_buffer_len;
in.m_buffer_pos = in.m_buffer_len;
out.m_buffer_len = 0;
return false;
}
Expand All @@ -86,6 +92,7 @@ class Zip
if (inflateInit2(&m_stream,15+32)!=Z_OK)
{
m_error=true;
out.m_buffer_len = 0;
in.m_buffer_pos = in.m_buffer_len;
return false;
}
Expand All @@ -97,9 +104,12 @@ class Zip

if (ret != Z_OK)
::inflateEnd(&m_stream);
else
m_run_end=true;
if (ret != Z_OK && ret != Z_STREAM_END)
{
m_error = true;
out.m_buffer_len = 0;
in.m_buffer_pos = in.m_buffer_len=0;
return false;
}
Expand All @@ -110,6 +120,7 @@ class Zip
return true;
}
bool m_init;
bool m_run_end;
bool m_error;
z_stream m_stream;
};
Expand Down
25 changes: 22 additions & 3 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,9 @@ class Page
}
else
{
bool found = false;
std::string str = subject;
transform(str.begin(), str.end(),str.begin(), tolower );
FILE *fp = fopen(subject.c_str(),"rb");
if (fp)
{
Expand All @@ -836,12 +839,28 @@ class Page
unsigned char * data=0;
int s=0,us,len;
data = pfile.get_packet(len, s, us);
printf(" %c{\n \"data\" : \"%s\",\n \"attr\" : { \"id\" : \"%s\", \"size\": %d, \"time\": %d },\n \"children\" : [] }\n",
comma,d->d_name,join_path(m_url.get_path(),d->d_name).substr(5).c_str(), int(statbuf.st_size),s );
comma=',';
if (data)
{
printf(" %c{\n \"data\" : \"%s\",\n \"attr\" : { \"id\" : \"%s\", \"size\": %d, \"time\": %d,\"type\": \"pcap\" },\n \"children\" : [] }\n",
comma,d->d_name,join_path(m_url.get_path(),d->d_name).substr(5).c_str(), int(statbuf.st_size),s );
comma = ',';
found = true;
}
}
fclose(fp);
}
if (!found)
{
std::string str = subject;
transform(str.begin(), str.end(),str.begin(), tolower );
if ( str.rfind(".json") == str.length()-5 )
{
printf(" %c{\n \"data\" : \"%s\",\n \"attr\" : { \"id\" : \"%s\", \"size\": %d, \"type\": \"json\" },\n \"children\" : [] }\n",
comma,d->d_name,join_path(m_url.get_path(),d->d_name).substr(5).c_str(), int(statbuf.st_size) );
comma= ',';
found = true;
}
}
}
}

Expand Down

0 comments on commit f8eb0b4

Please sign in to comment.