From fd32788092fcb29526ae73ae3bae6767dbb1e490 Mon Sep 17 00:00:00 2001 From: Cédric Bosdonnat Date: Mon, 4 Jun 2012 10:13:17 +0200 Subject: CMIS UCP: changed URLs to have hierarchical path Hierarchical path is assumed in loads of places, changed the URLs to the following: * Binding URL is encoded in the authority part, the repository ID is set as a fragment of the binding URL. * The hierarchical path reflects one of the path to the document on the server :x Change-Id: I8214daeb1d9c9b0f6ab86bdf60875e7e4e5369f4 --- tools/qa/cppunit/test_urlobj.cxx | 31 ++++++++++++++++++++------- tools/source/fsys/urlobj.cxx | 46 ++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 15 deletions(-) (limited to 'tools') diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx index da11113111d1..0a3a714f2942 100644 --- a/tools/qa/cppunit/test_urlobj.cxx +++ b/tools/qa/cppunit/test_urlobj.cxx @@ -245,14 +245,29 @@ namespace tools_urlobj void urlobjCmisTest( ) { - INetURLObject aUrl( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "cmis+atom://foo.bar.com:8080/my%2Fcmis%2Fatom/path/to/content" ) ) ); - CPPUNIT_ASSERT_EQUAL( std::string( "foo.bar.com" ), - OUSTR_TO_STDSTR( aUrl.GetHost( INetURLObject::NO_DECODE ) ) ); - CPPUNIT_ASSERT( aUrl.GetPort( ) == 8080 ); - CPPUNIT_ASSERT_EQUAL( std::string( "/my%2Fcmis%2Fatom/path/to/content" ), - OUSTR_TO_STDSTR( aUrl.GetURLPath( INetURLObject::NO_DECODE ) ) ); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong protocol found", INET_PROT_CMIS_ATOM, aUrl.GetProtocol( ) ); + // Test with a username part + { + INetURLObject aUrl( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "vnd.libreoffice.cmis+atom://username@http:%2F%2Ffoo.bar.com:8080%2Fmy%2Fcmis%2Fatom%23repo-id-encoded/path/to/content" ) ) ); + CPPUNIT_ASSERT_EQUAL( std::string( "http://foo.bar.com:8080/my/cmis/atom#repo-id-encoded" ), + OUSTR_TO_STDSTR( aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET ) ) ); + CPPUNIT_ASSERT_EQUAL( std::string( "username" ), OUSTR_TO_STDSTR( aUrl.GetUser( ) ) ); + CPPUNIT_ASSERT_EQUAL( std::string( "/path/to/content" ), + OUSTR_TO_STDSTR( aUrl.GetURLPath( INetURLObject::NO_DECODE ) ) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong protocol found", INET_PROT_CMIS_ATOM, aUrl.GetProtocol( ) ); + } + + // Test without a username part + { + INetURLObject aUrl( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "vnd.libreoffice.cmis+atom://http:%2F%2Ffoo.bar.com:8080%2Fmy%2Fcmis%2Fatom%23repo-id-encoded/path/to/content" ) ) ); + CPPUNIT_ASSERT_EQUAL( std::string( "http://foo.bar.com:8080/my/cmis/atom#repo-id-encoded" ), + OUSTR_TO_STDSTR( aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET ) ) ); + CPPUNIT_ASSERT( !aUrl.HasUserData() ); + CPPUNIT_ASSERT_EQUAL( std::string( "/path/to/content" ), + OUSTR_TO_STDSTR( aUrl.GetURLPath( INetURLObject::NO_DECODE ) ) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong protocol found", INET_PROT_CMIS_ATOM, aUrl.GetProtocol( ) ); + } } // Change the following lines only, if you add, remove or rename diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx index 49477eb68a91..eb125fe19983 100644 --- a/tools/source/fsys/urlobj.cxx +++ b/tools/source/fsys/urlobj.cxx @@ -428,8 +428,8 @@ static INetURLObject::SchemeInfo const aSchemeInfoMap[INET_PROT_END] false, true }, { "sftp", "sftp://", 22, true, true, false, true, true, true, true, true }, - { "cmis+atom", "cmis+atom://", 0, true, true, false, - true, true, true, true, true } }; + { "vnd.libreoffice.cmis+atom", "vnd.libreoffice.cmis+atom://", 0, true, true, false, + false, true, false, true, true } }; // static @@ -957,6 +957,7 @@ bool INetURLObject::setAbsURIRef(rtl::OUString const & rTheAbsURIRef, } case INET_PROT_VND_SUN_STAR_PKG: + case INET_PROT_CMIS_ATOM: { if (pEnd - pPos < 2 || *pPos++ != '/' || *pPos++ != '/') { @@ -964,8 +965,10 @@ bool INetURLObject::setAbsURIRef(rtl::OUString const & rTheAbsURIRef, return false; } aSynAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); - rtl::OUStringBuffer aSynAuthority; - while (pPos < pEnd + rtl::OUStringBuffer aSynUser; + + bool bHasUser = false; + while (pPos < pEnd && *pPos != '@' && *pPos != '/' && *pPos != '?' && *pPos != nFragmentDelimiter) { @@ -973,9 +976,38 @@ bool INetURLObject::setAbsURIRef(rtl::OUString const & rTheAbsURIRef, sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, cEscapePrefix, eMechanism, eCharset, eEscapeType); - appendUCS4(aSynAuthority, nUTF32, eEscapeType, bOctets, - PART_AUTHORITY, cEscapePrefix, eCharset, + appendUCS4(aSynUser, nUTF32, eEscapeType, bOctets, + PART_USER_PASSWORD, cEscapePrefix, eCharset, false); + + bHasUser = *pPos == '@'; + } + + rtl::OUStringBuffer aSynAuthority; + if ( !bHasUser ) + { + aSynAuthority = aSynUser; + } + else + { + m_aUser.set(aSynAbsURIRef, + aSynUser.makeStringAndClear(), + aSynAbsURIRef.getLength()); + aSynAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("@")); + ++pPos; + + while (pPos < pEnd + && *pPos != '/' && *pPos != '?' + && *pPos != nFragmentDelimiter) + { + EscapeType eEscapeType; + sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, + cEscapePrefix, eMechanism, + eCharset, eEscapeType); + appendUCS4(aSynAuthority, nUTF32, eEscapeType, bOctets, + PART_AUTHORITY, cEscapePrefix, eCharset, + false); + } } if (aSynAuthority.getLength() == 0) { @@ -2133,7 +2165,6 @@ INetURLObject::getPrefix(sal_Unicode const *& rBegin, { ".uno:", "staroffice.uno:", INET_PROT_UNO, PrefixInfo::INTERNAL }, { "cid:", 0, INET_PROT_CID, PrefixInfo::OFFICIAL }, - { "cmis+atom:", 0, INET_PROT_CMIS_ATOM, PrefixInfo::INTERNAL }, { "data:", 0, INET_PROT_DATA, PrefixInfo::OFFICIAL }, { "db:", "staroffice.db:", INET_PROT_DB, PrefixInfo::INTERNAL }, { "file:", 0, INET_PROT_FILE, PrefixInfo::OFFICIAL }, @@ -2203,6 +2234,7 @@ INetURLObject::getPrefix(sal_Unicode const *& rBegin, { "telnet:", 0, INET_PROT_TELNET, PrefixInfo::OFFICIAL }, { "vim:", "staroffice.vim:", INET_PROT_VIM, PrefixInfo::INTERNAL }, + { "vnd.libreoffice.cmis+atom:", 0, INET_PROT_CMIS_ATOM, PrefixInfo::INTERNAL }, { "vnd.sun.star.cmd:", 0, INET_PROT_VND_SUN_STAR_CMD, PrefixInfo::OFFICIAL }, { "vnd.sun.star.expand:", 0, INET_PROT_VND_SUN_STAR_EXPAND, -- cgit