Simplify Attachment code by using just Data
authorAndre Heinecke <aheinecke@intevation.de>
Fri, 7 Oct 2016 12:04:07 +0000 (14:04 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Fri, 7 Oct 2016 12:04:07 +0000 (14:04 +0200)
* src/attachment.cpp (Attachment::get_data): Direct access
to the underlying data structure.
* src/attachment.h, src/mimedataprovider.cpp: Update accordingly.

--
The plan was initially to use a MAPI Stream to hold the data
now with the testing on GNU/Linux it's better to use a platform
independent data structure and that simplifies the code.

src/attachment.cpp
src/attachment.h
src/mimedataprovider.cpp

index 2dac020..fc528c7 100644 (file)
@@ -51,34 +51,8 @@ Attachment::set_attach_type(attachtype_t type)
   m_type = type;
 }
 
-bool
-Attachment::isSupported(GpgME::DataProvider::Operation op) const
+GpgME::Data &
+Attachment::get_data()
 {
-  return op == GpgME::DataProvider::Read ||
-         op == GpgME::DataProvider::Write ||
-         op == GpgME::DataProvider::Seek ||
-         op == GpgME::DataProvider::Release;
-}
-
-ssize_t
-Attachment::read(void *buffer, size_t bufSize)
-{
-  return m_data.read (buffer, bufSize);
-}
-
-ssize_t
-Attachment::write(const void *data, size_t size)
-{
-  return m_data.write (data, size);
-}
-
-off_t Attachment::seek(off_t offset, int whence)
-{
-  return m_data.seek (offset, whence);
-}
-
-void Attachment::release()
-{
-  /* No op. */
-  log_debug ("%s:%s", SRCNAME, __func__);
+  return m_data;
 }
index f2ba143..47c536e 100644 (file)
 
 #include <string>
 
-#include <gpgme++/interfaces/dataprovider.h>
 #include <gpgme++/data.h>
 
 /** Helper class for attachment actions. */
-class Attachment : public GpgME::DataProvider
+class Attachment
 {
 public:
   /** Creates and opens a new in memory attachment. */
@@ -39,12 +38,8 @@ public:
 
   void set_attach_type(attachtype_t type);
 
-  /* Dataprovider interface */
-  bool isSupported(Operation) const;
-  ssize_t read(void *buffer, size_t bufSize);
-  ssize_t write(const void *buffer, size_t bufSize);
-  off_t seek(off_t offset, int whence);
-  void release();
+  /* get the underlying data structure */
+  GpgME::Data& get_data();
 
 private:
   GpgME::Data m_data;
index 59fcd38..a4aea43 100644 (file)
@@ -662,10 +662,10 @@ MimeDataProvider::collect_input_lines(const char *input, size_t insize)
                 }
               else if (m_mime_ctx->current_attachment && len)
                 {
-                  m_mime_ctx->current_attachment->write(linebuf, len);
+                  m_mime_ctx->current_attachment->get_data().write(linebuf, len);
                   if (!m_mime_ctx->is_base64_encoded && !slbrk)
                     {
-                      m_mime_ctx->current_attachment->write("\r\n", 2);
+                      m_mime_ctx->current_attachment->get_data().write("\r\n", 2);
                     }
                 }
               else