fixes
This commit is contained in:
parent
37598e187d
commit
4469462cb7
@ -4,19 +4,12 @@ namespace nntpchan {
|
|||||||
|
|
||||||
LineReader::LineReader(size_t limit) : m_close(false), lineLimit(limit) {}
|
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;
|
if(l <= 0) return;
|
||||||
// process leftovers
|
// 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 idx = 0;
|
||||||
std::size_t pos = 0;
|
std::size_t pos = 0;
|
||||||
ssize_t begin = l;
|
|
||||||
const char * data = current.c_str();
|
|
||||||
while(l-- > 0) {
|
while(l-- > 0) {
|
||||||
char c = data[idx++];
|
char c = data[idx++];
|
||||||
if(c == '\n') {
|
if(c == '\n') {
|
||||||
@ -31,13 +24,6 @@ namespace nntpchan {
|
|||||||
pos ++;
|
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)
|
void LineReader::OnLine(const char *d, const size_t l)
|
||||||
|
@ -41,8 +41,8 @@ namespace nntpchan
|
|||||||
}
|
}
|
||||||
else if(m_state == eStateStoreArticle)
|
else if(m_state == eStateStoreArticle)
|
||||||
{
|
{
|
||||||
OnData(line.c_str(), line.size());
|
std::string l = line + "\r\n";
|
||||||
OnData("\n", 1);
|
OnData(l.c_str(), l.size());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -55,27 +55,15 @@ namespace nntpchan
|
|||||||
if(l <= 0 ) return;
|
if(l <= 0 ) return;
|
||||||
if(m_state == eStateStoreArticle)
|
if(m_state == eStateStoreArticle)
|
||||||
{
|
{
|
||||||
const char * end = strstr(data, "\n.\n");
|
const char * end = strstr(data, "\r\n.\r\n");
|
||||||
if(end)
|
if(end)
|
||||||
{
|
{
|
||||||
std::size_t diff = end - data ;
|
std::size_t diff = end - data ;
|
||||||
if(m_article)
|
if(m_article)
|
||||||
m_article->write(data, diff);
|
m_article->write(data, diff+2);
|
||||||
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);
|
|
||||||
ArticleObtained();
|
ArticleObtained();
|
||||||
diff += 5;
|
diff += 5;
|
||||||
OnData(end+5, l-diff);
|
Data(end+5, l-diff);
|
||||||
return;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(m_article)
|
if(m_article)
|
||||||
|
Reference in New Issue
Block a user