Archived
1
0
This commit is contained in:
Jeff Becker 2017-05-03 18:31:19 -04:00
parent 37598e187d
commit 4469462cb7
2 changed files with 6 additions and 32 deletions

View File

@ -4,19 +4,12 @@ namespace nntpchan {
LineReader::LineReader(size_t limit) : m_close(false), lineLimit(limit) {}
void LineReader::Data(const char * d, ssize_t l)
void LineReader::Data(const char * data, ssize_t l)
{
if(l <= 0) return;
// process leftovers
std::string current = m_leftovers + std::string(d, l);
if(current.size() > lineLimit) {
m_close = true;
return;
}
std::size_t idx = 0;
std::size_t pos = 0;
ssize_t begin = l;
const char * data = current.c_str();
while(l-- > 0) {
char c = data[idx++];
if(c == '\n') {
@ -31,13 +24,6 @@ namespace nntpchan {
pos ++;
}
}
if (idx < begin)
{
// leftovers
m_leftovers = std::string(data, begin-idx);
}
else
m_leftovers = "";
}
void LineReader::OnLine(const char *d, const size_t l)

View File

@ -41,8 +41,8 @@ namespace nntpchan
}
else if(m_state == eStateStoreArticle)
{
OnData(line.c_str(), line.size());
OnData("\n", 1);
std::string l = line + "\r\n";
OnData(l.c_str(), l.size());
}
else
{
@ -55,27 +55,15 @@ namespace nntpchan
if(l <= 0 ) return;
if(m_state == eStateStoreArticle)
{
const char * end = strstr(data, "\n.\n");
const char * end = strstr(data, "\r\n.\r\n");
if(end)
{
std::size_t diff = end - data ;
if(m_article)
m_article->write(data, diff);
ArticleObtained();
diff += 3;
OnData(end+3, l-diff);
return;
}
end = strstr(data, "\r\n.\r\n");
if(end)
{
std::size_t diff = end - data ;
if(m_article)
m_article->write(data, diff);
m_article->write(data, diff+2);
ArticleObtained();
diff += 5;
OnData(end+5, l-diff);
return;
Data(end+5, l-diff);
return;
}
if(m_article)