summaryrefslogtreecommitdiff
path: root/tools/source/fsys
diff options
context:
space:
mode:
authorChr. Rossmanith <ChrRossmanith@gmx.de>2014-06-03 22:33:25 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-06-06 11:13:07 +0200
commit8b46d5c849a24e67fb2807a80164caf9001d9544 (patch)
tree50c98b15074dfdfd65e7ce225315f46348f07ffb /tools/source/fsys
parent44f422048754c5fe3540750eec996c8a63bf6da4 (diff)
new method INetURLObject::getData() for data urls
Signed-off-by: Stephan Bergmann <sbergman@redhat.com> Conflicts: tools/source/fsys/urlobj.cxx Change-Id: I59b5b95cf9b65920ec04922fdb25e4228fd22995
Diffstat (limited to 'tools/source/fsys')
-rw-r--r--tools/source/fsys/urlobj.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index 69b84a922c0a..08583fb9e4cc 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -20,6 +20,7 @@
#include <tools/urlobj.hxx>
#include <tools/debug.hxx>
#include <tools/inetmime.hxx>
+#include <tools/stream.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/util/XStringWidth.hpp>
#include <osl/diagnose.h>
@@ -37,6 +38,10 @@
#include <string.h>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <sax/tools/converter.hxx>
+#include <rtl/uri.hxx>
+
namespace unnamed_tools_urlobj {} using namespace unnamed_tools_urlobj;
// unnamed namespaces don't work well yet...
@@ -583,6 +588,44 @@ void INetURLObject::setInvalid()
m_aFragment.clear();
}
+SvMemoryStream* INetURLObject::getData()
+{
+ if( GetProtocol() != INET_PROT_DATA )
+ {
+ return NULL;
+ }
+
+ OUString sURLPath = GetURLPath( DECODE_WITH_CHARSET, RTL_TEXTENCODING_ISO_8859_1 );
+ OUString sType, sSubType;
+ OUString sBase64Enc(";base64,");
+
+ INetContentTypeParameterList params;
+ sal_Unicode const * pSkippedMediatype = INetMIME::scanContentType( sURLPath.getStr(), sURLPath.getStr() + sURLPath.getLength(), &sType, &sSubType, &params );
+ sal_Int32 nCharactersSkipped = pSkippedMediatype-sURLPath.getStr();
+ sal_Int32 nCommaIndex = sURLPath.indexOf( ",", nCharactersSkipped );
+ sal_Int32 nBase64Index = sURLPath.indexOf( sBase64Enc, nCharactersSkipped );
+ SvMemoryStream* aStream=NULL;
+
+ if( nBase64Index >= 0 && nBase64Index < nCommaIndex )
+ {
+ // base64 decoding
+ OUString sBase64Data = sURLPath.copy( nBase64Index + sBase64Enc.getLength() );
+ css::uno::Sequence< sal_Int8 > aDecodedData;
+ ::sax::Converter::decodeBase64( aDecodedData, sBase64Data );
+ if( aDecodedData.hasElements() )
+ {
+ aStream = new SvMemoryStream( aDecodedData.getArray(), aDecodedData.getLength(), STREAM_READ );
+ }
+ }
+ else
+ {
+ // URL decoding
+ OUString sURLEncodedData = sURLPath.copy( nCommaIndex+1 );
+ aStream = new SvMemoryStream( const_cast< sal_Char * >(OUStringToOString(sURLEncodedData, RTL_TEXTENCODING_UTF8).getStr()), sURLEncodedData.getLength(), STREAM_READ);
+ }
+ return aStream;
+}
+
namespace unnamed_tools_urlobj {
INetURLObject::FSysStyle guessFSysStyleByCounting(sal_Unicode const * pBegin,