[pan2/testing: 138/279] fixed error in encode_cache that accidentally read over EOF and put 0xff into the finished file



commit 026c5afee21b14647092f2ac614478f15570103b
Author: Heinrich Mueller <sphemuel stud informatik uni-erlangen de>
Date:   Thu Jun 30 10:04:55 2011 +0200

    fixed error in encode_cache that accidentally read over EOF and put 0xff into
    the finished file

 pan/data/encode-cache.cc       |    8 +++++---
 pan/tasks/task-upload.cc       |   23 ++++++++++++++++-------
 pan/tasks/task-weak-ordering.h |    1 +
 3 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/pan/data/encode-cache.cc b/pan/data/encode-cache.cc
index e29fb76..473ddea 100644
--- a/pan/data/encode-cache.cc
+++ b/pan/data/encode-cache.cc
@@ -191,11 +191,13 @@ EncodeCache :: get_data(std::string& data, const Quark& where)
 {
   char buf[4096];
   get_filename(buf, where);
-  std::ifstream in(buf, std::ifstream::in);
+  std::ifstream in(buf, std::ios::in);
   std::stringstream out;
-  while (in.good())
-    out << (char) in.get();
 
+  while (in.getline(buf,sizeof(buf)))
+    out << buf << "\n";
+
+  in.close();
   data = out.str();
 }
 
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index e1f783b..f155177 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -124,9 +124,10 @@ TaskUpload :: update_work (NNTP* checkin_pending)
 {
 
   int working(0);
+  Needed n;
   foreach (needed_t, _needed, nit)
   {
-    Needed& n (nit->second);
+    n = nit->second;
     if (n.nntp && n.nntp!=checkin_pending)
       ++working;
   }
@@ -143,6 +144,12 @@ TaskUpload :: update_work (NNTP* checkin_pending)
   else if ((_encoder_has_run && !_needed.empty()))
   {
     _state.set_need_nntp(_server);
+    std::string data;
+    _cache.get_data(data,n.message_id.c_str());
+//    prepend_headers(_msg,&n, data);
+    std::ofstream dbg("/home/imhotep/dbg",std::ios::out);
+    dbg<<StringView(data);
+
   }
   else if (_needed.empty())
   {
@@ -171,8 +178,8 @@ TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::st
     //extract body
     gboolean unused;
     char * body (g_mime_object_to_string ((GMimeObject *) msg));
-    out<< body<<"\r\n";
-    out<<d;
+    out << body << "\n";
+    out << d;
     d = out.str();
 }
 
@@ -204,8 +211,9 @@ TaskUpload :: use_nntp (NNTP * nntp)
     std::string data;
     _cache.get_data(data,needed->message_id.c_str());
     prepend_headers(_msg,needed, data);
-    /* update cache file */
-//    _cache.update_file (data,needed->message_id.c_str());
+    std::ofstream dbg("/home/imhotep/dbg",std::ios::out);
+    dbg<<StringView(data);
+    dbg.close();
     nntp->post(StringView(data), this);
     update_work ();
   }
@@ -304,6 +312,7 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
     case TOO_MANY_CONNECTIONS:
       // lockout for 120 secs, but try
       _state.set_need_nntp(nntp->_server);
+
       break;
     default:
       this->stop();
@@ -403,6 +412,6 @@ TaskUpload :: ~TaskUpload ()
       _encoder->cancel_silently();
 
   g_object_unref (G_OBJECT(_msg));
-  _cache.release(_mids);
-  _cache.resize();
+//  _cache.release(_mids);
+//  _cache.resize();
 }
diff --git a/pan/tasks/task-weak-ordering.h b/pan/tasks/task-weak-ordering.h
index 36fe5d0..118fe12 100644
--- a/pan/tasks/task-weak-ordering.h
+++ b/pan/tasks/task-weak-ordering.h
@@ -70,6 +70,7 @@ namespace pan
       if (a_rank != b_rank)
         return a_rank < b_rank;
 
+      ///DBG segfault (??)
       if (a_type == SAVE) { // order 'save' by oldest
         const time_t a_time (dynamic_cast<const TaskArticle*>(a)->get_time_posted ());
         const time_t b_time (dynamic_cast<const TaskArticle*>(b)->get_time_posted ());



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]