Re: VCard: getting photo
From: Jakob Schröter <js@xxxxxxxxxx>
Date: Wed, 16 Jan 2008 02:55:39 +0100 (CET)
Hi,

On Sunday January 13 2008, Dmitry Nezhevenko wrote:
> Hi. Can anybody confirm, that gloox correctly gets binary data of photo
> from VCard?
>
> I always get bigger content than real (vcard.photo().binval.size() > than
> real value) and photo content is broken.

Does the attached patch help? It seems some server and/or client 
implementations add line breaks to the base64-encoded image data to produce 
some MIME-like format. The vcard spec is not clear about this, so this patch 
works around that.

cheers,
Jakob
Index: src/vcard.cpp
===================================================================
--- src/vcard.cpp       (revision 3511)
+++ src/vcard.cpp       (working copy)
@@ -70,8 +70,12 @@
         }
         else if( (*it)->hasChild( "TYPE" ) && (*it)->hasChild( "BINVAL" ) )
         {
+          std::string binval = (*it)->findChild( "BINVAL" )->cdata();
+          std::string::size_type pos = 0;
+          while( ( pos = binval.find( '\n' ) ) != std::string::npos )
+            binval.erase( pos, 1 );
           m_photo.type = (*it)->findChild( "TYPE" )->cdata();
-          m_photo.binval = Base64::decode64( (*it)->findChild( "BINVAL" 
)->cdata() );
+          m_photo.binval = Base64::decode64( binval );
           m_PHOTO = true;
         }
       }
@@ -84,8 +88,12 @@
         }
         else if( (*it)->hasChild( "TYPE" ) && (*it)->hasChild( "BINVAL" ) )
         {
+          std::string binval = (*it)->findChild( "BINVAL" )->cdata();
+          std::string::size_type pos = 0;
+          while( ( pos = binval.find( '\n' ) ) != std::string::npos )
+            binval.erase( pos, 1 );
           m_logo.type = (*it)->findChild( "TYPE" )->cdata();
-          m_logo.binval = Base64::decode64( (*it)->findChild( "BINVAL" 
)->cdata() );
+          m_logo.binval = Base64::decode64( binval );
           m_LOGO = true;
         }
       }
@@ -217,7 +225,7 @@
     if( !type.empty() && !binval.empty() )
     {
       m_photo.type = type;
-      m_photo.binval = Base64::encode64( binval );
+      m_photo.binval = binval;
       m_PHOTO = true;
     }
   }
@@ -236,7 +244,7 @@
     if( !type.empty() && !binval.empty() )
     {
       m_logo.type = type;
-      m_logo.binval = Base64::encode64( binval );
+      m_logo.binval = binval;
       m_LOGO = true;
     }
   }
@@ -386,7 +394,7 @@
       else if( !m_photo.type.empty() && !m_photo.binval.empty() )
       {
         new Tag( p, "TYPE", m_photo.type );
-        new Tag( p, "BINVAL", m_photo.binval );
+        new Tag( p, "BINVAL", Base64::encode64( m_photo.binval ) );
       }
     }
 
@@ -400,7 +408,7 @@
       else if( !m_logo.type.empty() && !m_logo.binval.empty() )
       {
         new Tag( l, "TYPE", m_logo.type );
-        new Tag( l, "BINVAL", m_logo.binval );
+        new Tag( l, "BINVAL", Base64::encode64( m_logo.binval ) );
       }
     }
 

Attachment: signature.asc
Description: This is a digitally signed message part.