diff options
author | Chr. Rossmanith <ChrRossmanith@gmx.de> | 2014-06-03 22:33:25 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-06-06 11:13:07 +0200 |
commit | 8b46d5c849a24e67fb2807a80164caf9001d9544 (patch) | |
tree | 50c98b15074dfdfd65e7ce225315f46348f07ffb /tools | |
parent | use sfntLen in DumpSfnts to do some sanity checking (diff) | |
download | core-8b46d5c849a24e67fb2807a80164caf9001d9544.tar.gz core-8b46d5c849a24e67fb2807a80164caf9001d9544.zip |
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')
-rw-r--r-- | tools/Library_tl.mk | 1 | ||||
-rw-r--r-- | tools/source/fsys/urlobj.cxx | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index c6ee6cbe8f48..856471bbf7ba 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,tl,\ i18nlangtag \ cppu \ sal \ + sax \ $(gb_UWINAPI) \ )) 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, ¶ms ); + 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, |