[pan2] fix giganews xfeature for groups task
- From: Heinrich Müller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] fix giganews xfeature for groups task
- Date: Thu, 21 Nov 2013 21:42:43 +0000 (UTC)
commit 8325c88e0f4b25950fc72eeaeebb05ce03d98ee6
Author: Heinrich Müller <henmull src gnome org>
Date: Thu Nov 21 22:21:18 2013 +0100
fix giganews xfeature for groups task
pan/general/compression.cc | 121 +++++---------------------------------------
pan/general/compression.h | 2 +-
pan/gui/gui.cc | 2 +
pan/tasks/nntp.cc | 15 +++--
pan/tasks/task-groups.cc | 33 +++++++++---
pan/tasks/task-xover.cc | 7 ++-
6 files changed, 56 insertions(+), 124 deletions(-)
---
diff --git a/pan/general/compression.cc b/pan/general/compression.cc
index 5c02125..bb90f47 100644
--- a/pan/general/compression.cc
+++ b/pan/general/compression.cc
@@ -40,86 +40,6 @@ namespace
#define LINELEN_MIN 2048
#define LINELEN_MAX 32768
- struct gzip_line {
- std::stringstream* stream;
- char *start;
- char *where;
- size_t remaining;
- size_t allocated;
- int eof;
- };
-
- void
- line_init(struct gzip_line *line, std::stringstream* stream)
- {
- line->stream = stream;
- line->allocated = LINELEN_MIN;
- line->where = line->start = (char*)calloc(1, line->allocated);
- line->remaining = 0;
- line->eof = 0;
- }
-
- int
- line_read(struct gzip_line *line, char **p)
- {
- char *where;
- char *lf = NULL;
-
- if (line->remaining != 0) {
- if (line->start != line->where) {
- memmove(line->start, line->where, line->remaining);
- lf = (char*)memchr(line->start, '\n', line->remaining);
- }
- }
- where = line->start + line->remaining;
-
- if (lf == NULL) {
- do {
- ssize_t count;
- if (where == line->start + line->allocated) {
- size_t newsize = line->allocated * 2;
- if (newsize > LINELEN_MAX)
- newsize = LINELEN_MAX;
- if (newsize == line->allocated) {
- where = line->start;
- line->eof = 1;
- } else {
- line->start = (char*)realloc(line->start, newsize);
- where = line->start + line->allocated;
- line->allocated = newsize;
- }
- }
-
- do {
- count = line->stream->readsome(where, line->allocated - (where - line->start));
- } while (count == -1);
-
- if (count < 0) {
- count = 0;
- }
-
- if (count == 0) {
- line->eof = 1;
- lf = where;
- where++;
- break;
- }
- lf = (char*)memchr(where, '\n', count);
- where += count;
- } while (lf == NULL);
- }
-
- line->where = lf + 1;
- line->remaining = where - line->where;
-
- *lf = '\0';
- *p = line->start;
- if (line->eof)
- return lf - line->start;
- return lf - line->start + 1; /* <<=== length includes terminator '\0' */
- }
-
-
}
bool
@@ -260,36 +180,21 @@ compression::inflate_zlib(std::stringstream *source, std::stringstream *dest,
return ret == Z_STREAM_END ? true : false;
}
-void compression::inflate_gzip (std::stringstream* stream, std::vector<std::string>& fillme)
+void compression::inflate_gzip (std::stringstream* stream, std::stringstream* out)
{
- struct gzip_line g_line;
- size_t len;
- char* buf;
- char buf2[4096];
+ std::string line;
+ std::istringstream in_str(stream->str());
- line_init(&g_line, stream);
-
- std::stringstream dest, dest2;
- while (!g_line.eof) {
- while ((len = line_read(&g_line, &buf)) > 0) {
- buf[len-1] = '\n';
- dest.write(buf, len);
- if (len >= 3 && strncmp(buf + len - 1, ".", 1) == 0) {
- g_line.eof = 1;
- break;
- }
- }
+ while (std::getline(in_str, line, '\r'))
+ {
+ StringView str(line.c_str());
+ if (str.str[str.len - 1] == '.')
+ {
+ str.rtruncate(1);
+ if (str.len != 0)
+ *out<<str<<"\n";
+ break;
+ }
}
-
- std::ofstream out ("/home/imhotep/compression/out");
- out << dest2.str();
- out.close();
-
- int cnt=0;
- while (!dest2.getline(buf2,4096).eof())
- {if (buf2) fillme.push_back(std::string(buf2));
- ++cnt;}
-
stream->clear();
-
}
diff --git a/pan/general/compression.h b/pan/general/compression.h
index 2782ff2..6c72c63 100644
--- a/pan/general/compression.h
+++ b/pan/general/compression.h
@@ -48,7 +48,7 @@ namespace pan
bool ydecode(std::stringstream* in, std::stringstream* out);
- void inflate_gzip (std::stringstream* stream, std::vector<std::string>& fillme);
+ void inflate_gzip (std::stringstream*, std::stringstream*);
}
}
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 8fbcbf0..ef415e7 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -364,6 +364,7 @@ GUI :: GUI (Data& data, Queue& queue, Prefs& prefs, GroupPrefs& group_prefs):
if (_prefs.get_flag ("get-new-headers-on-startup", false))
activate_action ("get-new-headers-in-subscribed-groups");
+ _queue.add_listener (this);
_prefs.add_listener (this);
_certstore.add_listener(this);
Log::get().add_listener (this);
@@ -456,6 +457,7 @@ GUI :: ~GUI ()
_certstore.remove_listener(this);
_data.remove_listener(this);
_prefs.remove_listener (this);
+ _queue.remove_listener (this);
Log::get().remove_listener (this);
}
diff --git a/pan/tasks/nntp.cc b/pan/tasks/nntp.cc
index c42d334..ff12a43 100644
--- a/pan/tasks/nntp.cc
+++ b/pan/tasks/nntp.cc
@@ -85,15 +85,15 @@ NNTP :: on_socket_response (Socket * sock UNUSED, const StringView& line_in)
if (_nntp_response_text)
{
+ state = CMD_MORE;
+
if (line.len==1 && line.str[0]=='.') // end-of-list
{
state = CMD_DONE;
_nntp_response_text = false;
}
- else
+ else if (!_compression)
{
- state = CMD_MORE;
-
if (line.len>=2 && line.str[0]=='.' && line.str[1]=='.') // rfc 977: 2.4.1
line.rtruncate (line.len-1);
@@ -104,12 +104,15 @@ NNTP :: on_socket_response (Socket * sock UNUSED, const StringView& line_in)
if (_compression)
{
- if (line_in.len >= 3 &&
- strncmp(line_in.str + line_in.len - 3, ".\r\n", 3) == 0)
+
+ StringView l(line);
+ if (_listener)
+ _listener->on_nntp_line (this, l);
+
+ if (l.str[l.len-1]=='.')
{
_nntp_response_text = false;
_compression = false;
- line = EOL;
state = CMD_DONE;
}
}
diff --git a/pan/tasks/task-groups.cc b/pan/tasks/task-groups.cc
index d0ad676..08c1d48 100644
--- a/pan/tasks/task-groups.cc
+++ b/pan/tasks/task-groups.cc
@@ -81,7 +81,9 @@ TaskGroups :: on_nntp_line (NNTP * nntp,
{
// gzip compression
if (nntp->_compression)
- stream<<line<<"\r\n";
+ {
+ stream<<line;
+ }
else on_nntp_line_process (nntp, line);
}
void
@@ -153,16 +155,31 @@ TaskGroups :: on_nntp_done (NNTP * nntp,
const Quark& server(nntp->_server);
CompressionType comp;
_data.get_server_compression_type(server, comp);
- const bool compression (comp == HEADER_COMPRESS_XFEATURE);
+ const bool is_gzipped (comp == HEADER_COMPRESS_XFEATURE);
- if (response == EOL && compression)
+ if (is_gzipped)
{
- std::vector<std::string> lines;
- compression::inflate_gzip (&stream, lines);
- foreach (std::vector<std::string>, lines, it)
- on_nntp_line_process (nntp, *it);
- }
+ std::ofstream of("/home/imhotep/out");
+ of << stream.str();
+ of.close();
+ std::stringstream out,out2;
+ bool fail = !compression::inflate_zlib(&stream, &out, comp);
+ if (!fail)
+ {
+ char buf[4096];
+ while (true)
+ {
+ std::istream& str = out.getline(buf, sizeof(buf));
+ if (str.fail() || str.bad() || str.eof()) break;
+ on_nntp_line_process(nntp, buf);
+ }
+ } else
+ {
+ _state.set_completed();
+ set_finished(ERR_LOCAL);
+ }
+ }
if (_step == LIST_NEWSGROUPS)
{
diff --git a/pan/tasks/task-xover.cc b/pan/tasks/task-xover.cc
index f941190..4d48dd9 100644
--- a/pan/tasks/task-xover.cc
+++ b/pan/tasks/task-xover.cc
@@ -440,17 +440,22 @@ TaskXOver::on_nntp_done(NNTP * nntp, Health health, const StringView & response)
if (response == EOL && compression_enabled)
{
- std::stringstream* buffer = _streams[nntp->_socket->get_id()];
+ std::stringstream* buffer(0);
std::stringstream out, out2;
if (comp == HEADER_COMPRESS_XZVER || comp == HEADER_COMPRESS_DIABLO )
{
+ buffer = _streams[nntp->_socket->get_id()];
if (compression::ydecode(buffer, &out))
fail = !compression::inflate_zlib(&out, &out2, comp);
else
fail = true;
}
else
+ {
+ buffer = new std::stringstream();
+ compression::inflate_gzip(_streams[nntp->_socket->get_id()], buffer);
fail = !compression::inflate_zlib(buffer, &out2, comp);
+ }
buffer->clear();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]