[Libreoffice-commits] core.git: Branch 'libreoffice-6-1-3' - dtrans/Library_mcnttype.mk dtrans/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 19 08:36:44 UTC 2018


 dtrans/Library_mcnttype.mk         |    1 
 dtrans/source/cnttype/mcnttype.cxx |  269 ++-----------------------------------
 dtrans/source/cnttype/mcnttype.hxx |    3 
 3 files changed, 19 insertions(+), 254 deletions(-)

New commits:
commit 90173417577338ba837cd1ed51276b3e3c8a50df
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Oct 11 17:31:30 2018 +0200
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Oct 19 10:35:04 2018 +0200

    tdf#120158: Base CMimeContentType on INetMIME::scanContentType
    
    ...instead of using yet another local implementation of parsing media types.
    
    CMimeContentType is the implementation of the UNO
    css.datatransfer.XMimeContentType interface.  One observable change in behavior
    is that type, subtype, and parameter names will now always be reported in lower
    case instead of with the casing from the input preserved (but those differences
    in casing are functionally equivalent per the media type specification).  Also,
    parameter names supplied to the hasParameter and getParameterValue functions are
    now also treated case-insensitive.
    
    The upside of this change is that INetMIME::scanContentType (via "The encoding
    of rMediaType should be US-ASCII, but any Unicode values in the range U+0080..
    U+FFFF are interpreted 'as appropriate.'") already implicitly supports RFC 6532
    "Internationalized Email Headers" extensions for media types, allowing quoted-
    string parameter values to contain non-ASCII Unicode characters.
    
    That means that tfd#120158 "Impossible to paste special in Writer from Calc in
    Libreoffice 6.1.x in some UI languages - the dialogue caption says 'unknown
    source'" can be fixed by just allowing non-ASCII typename parameters being
    generated in ImplGetParameterString in svtools/source/misc/transfer.cxx, and
    reverting the problematic (see the comments there) previous fix
    <https://gerrit.libreoffice.org/61601> "tdf#120158: fix ImplGetParameterString
    for typename".  (Which will be done in a follow-up commit, to ease potential
    backporting, as that previous fix has already been backported to some versions
    but not to others.)
    
    Reviewed-on: https://gerrit.libreoffice.org/61684
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    (cherry picked from commit b75e3ded1f73c943fb09f117e476e367ac0c3413)
    Conflicts:
            dtrans/source/cnttype/mcnttype.cxx
    
    Change-Id: I5d4d3586e8046f288a97605b000e262a8db5a4e9
    Reviewed-on: https://gerrit.libreoffice.org/61702
    Reviewed-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/dtrans/Library_mcnttype.mk b/dtrans/Library_mcnttype.mk
index c139e88fed27..2442a01cb721 100644
--- a/dtrans/Library_mcnttype.mk
+++ b/dtrans/Library_mcnttype.mk
@@ -27,6 +27,7 @@ $(eval $(call gb_Library_use_libraries,mcnttype,\
 	cppu \
 	cppuhelper \
 	sal \
+	tl \
 ))
 
 $(eval $(call gb_Library_add_exception_objects,mcnttype,\
diff --git a/dtrans/source/cnttype/mcnttype.cxx b/dtrans/source/cnttype/mcnttype.cxx
index 3f982dd8a62c..483806163bea 100644
--- a/dtrans/source/cnttype/mcnttype.cxx
+++ b/dtrans/source/cnttype/mcnttype.cxx
@@ -20,20 +20,16 @@
 #include <sal/config.h>
 
 #include <com/sun/star/container/NoSuchElementException.hpp>
+#include <rtl/ustring.hxx>
+#include <tools/inetmime.hxx>
 
 #include "mcnttype.hxx"
 
 using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
 using namespace com::sun::star::container;
 using namespace std;
 using namespace osl;
 
-const char TSPECIALS[] =  "()<>@,;:\\\"/[]?=";
-const char TOKEN[] = "!#$%&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~.";
-const char SPACE[] = " ";
-const char SEMICOLON[] = ";";
-
 CMimeContentType::CMimeContentType( const OUString& aCntType )
 {
     init( aCntType );
@@ -75,267 +71,38 @@ Sequence< OUString > SAL_CALL CMimeContentType::getParameters( )
 sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName )
 {
     MutexGuard aGuard( m_aMutex );
-    return ( m_ParameterMap.end( ) != m_ParameterMap.find( aName ) );
+    return ( m_ParameterMap.end( ) != m_ParameterMap.find( aName.toAsciiLowerCase() ) );
 }
 
 OUString SAL_CALL CMimeContentType::getParameterValue( const OUString& aName )
 {
+    auto const lower = aName.toAsciiLowerCase();
+
     MutexGuard aGuard( m_aMutex );
 
-    if ( !hasParameter( aName ) )
+    if ( !hasParameter( lower ) )
         throw NoSuchElementException( );
 
-    return m_ParameterMap.find( aName )->second;
+    return m_ParameterMap.find( lower )->second;
 }
 
 void CMimeContentType::init( const OUString& aCntType )
 {
-    if ( aCntType.isEmpty( ) )
-        throw IllegalArgumentException( );
-
-    m_nPos = 0;
-    m_ContentType = aCntType;
-    getSym( );
-    type();
-}
-
-void CMimeContentType::getSym()
-{
-    if ( m_nPos < m_ContentType.getLength( ) )
+    INetContentTypeParameterList params;
+    if (INetMIME::scanContentType(aCntType, &m_MediaType, &m_MediaSubtype, &params)
+        != aCntType.getStr() + aCntType.getLength())
     {
-        m_nxtSym = m_ContentType.copy(m_nPos, 1);
-        ++m_nPos;
-        return;
+        throw css::lang::IllegalArgumentException(
+            "illegal media type " + aCntType, css::uno::Reference<css::uno::XInterface>(), -1);
     }
-
-    m_nxtSym = OUString( );
-}
-
-void CMimeContentType::acceptSym( const OUString& pSymTlb )
-{
-    if ( pSymTlb.indexOf( m_nxtSym ) < 0 )
-        throw IllegalArgumentException( );
-
-    getSym();
-}
-
-void CMimeContentType::skipSpaces()
-{
-    while (m_nxtSym == SPACE)
-        getSym( );
-}
-
-void CMimeContentType::type()
-{
-    skipSpaces( );
-
-    OUString sToken(TOKEN);
-
-    // check FIRST( type )
-    if ( !isInRange( m_nxtSym, sToken ) )
-        throw IllegalArgumentException( );
-
-    // parse
-    while(  !m_nxtSym.isEmpty( ) )
-    {
-        if ( isInRange( m_nxtSym, sToken ) )
-            m_MediaType += m_nxtSym;
-        else if ( isInRange( m_nxtSym, "/ " ) )
-            break;
-        else
-            throw IllegalArgumentException( );
-        getSym( );
-    }
-
-    // check FOLLOW( type )
-    skipSpaces( );
-    acceptSym( "/" );
-
-    subtype( );
-}
-
-void CMimeContentType::subtype()
-{
-    skipSpaces( );
-
-    OUString sToken(TOKEN);
-
-    // check FIRST( subtype )
-    if ( !isInRange( m_nxtSym, sToken ) )
-        throw IllegalArgumentException( );
-
-    while( !m_nxtSym.isEmpty( ) )
-    {
-        if ( isInRange( m_nxtSym, sToken ) )
-            m_MediaSubtype += m_nxtSym;
-        else if ( isInRange( m_nxtSym, "; " ) )
-            break;
-        else
-            throw IllegalArgumentException( );
-        getSym( );
-    }
-
-    // parse the rest
-    skipSpaces( );
-    trailer();
-}
-
-void CMimeContentType::trailer()
-{
-    OUString sToken(TOKEN);
-    while( !m_nxtSym.isEmpty( ) )
-    {
-        if ( m_nxtSym == "(" )
-        {
-            getSym( );
-            comment( );
-            acceptSym( ")" );
+    for (auto const & i: params) {
+        if (!i.second.m_bConverted) {
+            throw css::lang::IllegalArgumentException(
+                "illegal parameter value in media type " + aCntType,
+                css::uno::Reference<css::uno::XInterface>(), -1);
         }
-        else if ( m_nxtSym == ";" )
-        {
-            // get the parameter name
-            getSym( );
-            skipSpaces( );
-
-            if ( !isInRange( m_nxtSym, sToken ) )
-                throw IllegalArgumentException( );
-
-            OUString pname = pName( );
-
-            skipSpaces();
-            acceptSym( "=" );
-
-            // get the parameter value
-            skipSpaces( );
-
-            OUString pvalue = pValue( );
-
-            // insert into map
-            if ( !m_ParameterMap.insert( pair < const OUString, OUString > ( pname, pvalue ) ).second )
-                throw IllegalArgumentException( );
-        }
-        else
-            throw IllegalArgumentException( );
-
-        skipSpaces( );
+        m_ParameterMap[OUString::fromUtf8(i.first)] = i.second.m_sValue;
     }
 }
 
-OUString CMimeContentType::pName( )
-{
-    OUString pname;
-
-    OUString sToken(TOKEN);
-    while( !m_nxtSym.isEmpty( ) )
-    {
-        if ( isInRange( m_nxtSym, sToken ) )
-            pname += m_nxtSym;
-        else if ( isInRange( m_nxtSym, "= " ) )
-            break;
-        else
-            throw IllegalArgumentException( );
-        getSym( );
-    }
-
-    return pname;
-}
-
-OUString CMimeContentType::pValue( )
-{
-    OUString pvalue;
-
-    OUString sToken(TOKEN);
-    // quoted pvalue
-    if ( m_nxtSym == "\"" )
-    {
-        getSym( );
-        pvalue = quotedPValue( );
-
-        if ( pvalue[pvalue.getLength() - 1] != '"' )
-            throw IllegalArgumentException( );
-
-        // remove the last quote-sign
-        pvalue = pvalue.copy(0, pvalue.getLength() - 1);
-
-        if ( pvalue.isEmpty( ) )
-            throw IllegalArgumentException( );
-    }
-    else if ( isInRange( m_nxtSym, sToken ) ) // unquoted pvalue
-    {
-        pvalue = nonquotedPValue( );
-    }
-    else
-        throw IllegalArgumentException( );
-
-    return pvalue;
-}
-
-// the following combinations within a quoted value are not allowed:
-// '";' (quote sign followed by semicolon) and '" ' (quote sign followed
-// by space)
-
-OUString CMimeContentType::quotedPValue( )
-{
-    OUString pvalue;
-    bool bAfterQuoteSign = false;
-
-    while ( !m_nxtSym.isEmpty( ) )
-    {
-        if ( bAfterQuoteSign && (
-            (m_nxtSym == SPACE) ||
-            (m_nxtSym == SEMICOLON))
-           )
-        {
-            break;
-        }
-        else if ( isInRange( m_nxtSym, OUStringLiteral(TOKEN) + TSPECIALS + SPACE ) )
-        {
-            pvalue += m_nxtSym;
-            bAfterQuoteSign = m_nxtSym == "\"";
-        }
-        else
-            throw IllegalArgumentException( );
-        getSym( );
-    }
-
-    return pvalue;
-}
-
-OUString CMimeContentType::nonquotedPValue( )
-{
-    OUString pvalue;
-
-    OUString sToken(TOKEN);
-    while ( !m_nxtSym.isEmpty( ) )
-    {
-        if ( isInRange( m_nxtSym, sToken ) )
-            pvalue += m_nxtSym;
-        else if ( isInRange( m_nxtSym, "; " ) )
-            break;
-        else
-            throw IllegalArgumentException( );
-        getSym( );
-    }
-
-    return pvalue;
-}
-
-void CMimeContentType::comment()
-{
-    while ( !m_nxtSym.isEmpty( ) )
-    {
-        if ( isInRange( m_nxtSym, OUStringLiteral(TOKEN) + SPACE ) )
-            getSym( );
-        else if ( m_nxtSym == ")" )
-            break;
-        else
-            throw IllegalArgumentException( );
-    }
-}
-
-bool CMimeContentType::isInRange( const OUString& aChr, const OUString& aRange )
-{
-    return ( aRange.indexOf( aChr ) > -1 );
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dtrans/source/cnttype/mcnttype.hxx b/dtrans/source/cnttype/mcnttype.hxx
index 35fb37fbdba1..68c4bff5a258 100644
--- a/dtrans/source/cnttype/mcnttype.hxx
+++ b/dtrans/source/cnttype/mcnttype.hxx
@@ -66,10 +66,7 @@ private:
     ::osl::Mutex                             m_aMutex;
     OUString                            m_MediaType;
     OUString                            m_MediaSubtype;
-    OUString                            m_ContentType;
     std::map< OUString, OUString > m_ParameterMap;
-    sal_Int32                                m_nPos;
-    OUString                            m_nxtSym;
 };
 
 #endif


More information about the Libreoffice-commits mailing list