Module: sems
Branch: master
Commit: 612c50db299c78099ec08e48e17e859af948b018
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=612c50db299c78099ec08e48e17e859af948b018

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Mon Apr 28 17:30:55 2014 +0200

b/f:core: handle AmMimeBody boundary correctly in addParts

---

 core/AmMimeBody.cpp |   28 ++++++++++++++++++++++++++--
 core/AmMimeBody.h   |    3 +++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/core/AmMimeBody.cpp b/core/AmMimeBody.cpp
index 044a2f6..fb3c912 100644
--- a/core/AmMimeBody.cpp
+++ b/core/AmMimeBody.cpp
@@ -4,6 +4,7 @@
 #include "sip/defs.h"
 
 #include "log.h"
+#include "AmUtils.h"
 
 #include <memory>
 using std::auto_ptr;
@@ -112,6 +113,22 @@ void AmContentType::clearParams()
   }
 }
 
+void AmContentType::resetBoundary()
+{
+  Params::iterator it = params.begin();
+  while (it != params.end()) {
+    Params::iterator l_it = it;
+    it++;
+    if ((*l_it)->type == Param::BOUNDARY)
+      delete *l_it;
+      params.erase(l_it);
+  }
+
+  params.push_back(new Param(BOUNDARY_str, int2hex(get_random())));
+  params.back()->type = Param::BOUNDARY;
+  mp_boundary = params.back();
+}
+
 void AmMimeBody::clearParts()
 {
   while(!parts.empty()){
@@ -574,12 +591,15 @@ void AmMimeBody::convertToMultipart()
 {
   AmContentType n_ct;
   n_ct.parse(MULTIPART_MIXED); // never fails
+  n_ct.resetBoundary();
 
   AmMimeBody* n_part = new AmMimeBody(*this);
   n_part->ct = ct;
 
   parts.push_back(n_part);
   ct = n_ct;
+
+  content_len = 0;
 }
 
 void AmContentType::setType(const string& t)
@@ -745,10 +765,14 @@ void AmMimeBody::print(string& buf) const
     buf += string((const char*)payload,content_len);
   }
   else {
+
+    // if (ct.mp_boundary == NULL)
+    //   ct.resetBoundary(); 
+
     for(Parts::const_iterator it = parts.begin();
        it != parts.end(); ++it) {
 
-      buf += "--" + ct.mp_boundary->value + CRLF;
+      buf += "--" + (ct.mp_boundary != NULL ? ct.mp_boundary->value : 
string("") ) + CRLF;
       buf += SIP_HDR_CONTENT_TYPE COLSP + (*it)->getCTHdr() + CRLF;
       buf += (*it)->hdrs + CRLF;
       (*it)->print(buf);
@@ -756,7 +780,7 @@ void AmMimeBody::print(string& buf) const
     }
 
     if(!parts.empty()) {
-      buf += "--" + ct.mp_boundary->value + "--" CRLF;
+      buf += "--" + (ct.mp_boundary != NULL ? ct.mp_boundary->value : 
string("") ) + "--" CRLF;
     }
   }
 }
diff --git a/core/AmMimeBody.h b/core/AmMimeBody.h
index 20f8b8c..6f020ac 100644
--- a/core/AmMimeBody.h
+++ b/core/AmMimeBody.h
@@ -63,6 +63,9 @@ struct AmContentType
 
   /** Clear and free param list */
   void clearParams();
+
+  /** set a random boundary string */
+  void resetBoundary();
 };
 
 class AmMimeBody

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to