diff options
-rw-r--r-- | desktop/source/deployment/inc/dp_descriptioninfoset.hxx | 16 | ||||
-rw-r--r-- | desktop/source/deployment/misc/dp_descriptioninfoset.cxx | 44 | ||||
-rw-r--r-- | desktop/source/deployment/registry/package/dp_package.cxx | 66 | ||||
-rw-r--r-- | desktop/source/pkgchk/unopkg/unopkg_app.cxx | 11 | ||||
-rw-r--r-- | desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx | 34 | ||||
-rw-r--r-- | desktop/source/pkgchk/unopkg/unopkg_shared.h | 3 | ||||
-rwxr-xr-x | desktop/test/deployment/simple_license/suppress_license.oxt | bin | 0 -> 2143 bytes | |||
-rw-r--r-- | desktop/test/deployment/simple_license/tests_simple_license.odt | bin | 15621 -> 16629 bytes |
8 files changed, 120 insertions, 54 deletions
diff --git a/desktop/source/deployment/inc/dp_descriptioninfoset.hxx b/desktop/source/deployment/inc/dp_descriptioninfoset.hxx index f9b3e1d989f1..38a1870782ed 100644 --- a/desktop/source/deployment/inc/dp_descriptioninfoset.hxx +++ b/desktop/source/deployment/inc/dp_descriptioninfoset.hxx @@ -53,6 +53,15 @@ namespace rtl { class OUString; } namespace dp_misc { +struct DESKTOP_DEPLOYMENTMISC_DLLPUBLIC SimpleLicenseAttributes +{ + ::rtl::OUString acceptBy; + //Attribute suppress-on-update. Default is false. + bool suppressOnUpdate; + //Attribute suppress-if-required. Default is false. + bool suppressIfRequired; +}; + /** Access to the content of an XML <code>description</code> element. @@ -132,6 +141,13 @@ public: */ ::rtl::OUString getLocalizedLicenseURL() const; + /** returns the attributes of the simple-license element + + As long as there is a simple-license element, the function will return + the structure. If it does not exist, then the optional object is uninitialized. + */ + ::boost::optional<SimpleLicenseAttributes> getSimpleLicenseAttributes() const; + /** returns the localized display name of the extensions. In case there is no localized display-name then an empty string is returned. diff --git a/desktop/source/deployment/misc/dp_descriptioninfoset.cxx b/desktop/source/deployment/misc/dp_descriptioninfoset.cxx index 587e31bebfb9..28f45918e9e2 100644 --- a/desktop/source/deployment/misc/dp_descriptioninfoset.cxx +++ b/desktop/source/deployment/misc/dp_descriptioninfoset.cxx @@ -370,6 +370,50 @@ css::uno::Sequence< ::rtl::OUString > DescriptionInfoset::getUrls( } +::boost::optional<SimpleLicenseAttributes> +DescriptionInfoset::getSimpleLicenseAttributes() const +{ + //Check if the node exist + css::uno::Reference< css::xml::dom::XNode > n; + if (m_element.is()) { + try { + n = m_xpath->selectSingleNode(m_element, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@accept-by"))); + } catch (css::xml::xpath::XPathException &) { + // ignore + } + if (n.is()) + { + SimpleLicenseAttributes attributes; + attributes.acceptBy = + getNodeValueFromExpression(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@accept-by"))); + + ::boost::optional< ::rtl::OUString > suppressOnUpdate = getOptionalValue( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@suppress-on-update"))); + if (suppressOnUpdate) + attributes.suppressOnUpdate = (*suppressOnUpdate).trim().equalsIgnoreAsciiCase( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))); + else + attributes.suppressOnUpdate = false; + + ::boost::optional< ::rtl::OUString > suppressIfRequired = getOptionalValue( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@suppress-if-required"))); + if (suppressIfRequired) + attributes.suppressIfRequired = (*suppressIfRequired).trim().equalsIgnoreAsciiCase( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))); + else + attributes.suppressIfRequired = false; + + return ::boost::optional<SimpleLicenseAttributes>(attributes); + } + } + return ::boost::optional<SimpleLicenseAttributes>(); +} + ::rtl::OUString DescriptionInfoset::getLocalizedDescriptionURL() const { return getLocalizedHREFAttrFromChild(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx index cfe5be59dad0..e45f7fb7ef73 100644 --- a/desktop/source/deployment/registry/package/dp_package.cxx +++ b/desktop/source/deployment/registry/package/dp_package.cxx @@ -70,7 +70,7 @@ #include "com/sun/star/xml/dom/XDocumentBuilder.hpp" #include "com/sun/star/xml/xpath/XXPathAPI.hpp" #include "com/sun/star/deployment/XPackageManager.hpp" - +#include "boost/optional.hpp" #include <vector> #include <stdio.h> @@ -583,21 +583,12 @@ bool BackendImpl::PackageImpl::checkDependencies( { try { - css::uno::Reference<css::xml::dom::XNode> xRoot = desc.getRootElement(); - css::uno::Reference<css::xml::xpath::XXPathAPI> xPath = - getDescriptionInfoset().getXpath(); - - css::uno::Reference<css::xml::dom::XNode> nodeSimpleLic; - try { - nodeSimpleLic = xPath->selectSingleNode(xRoot, - OUSTR("/desc:description/desc:registration/desc:simple-license")); - } catch (css::xml::xpath::XPathException &) { - // ignore - } - - if (!nodeSimpleLic.is()) + DescriptionInfoset info = getDescriptionInfoset(); + ::boost::optional<SimpleLicenseAttributes> simplLicAttr + = info.getSimpleLicenseAttributes(); + if (! simplLicAttr) return true; - OUString sLic = getDescriptionInfoset().getLocalizedLicenseURL(); + OUString sLic = info.getLocalizedLicenseURL(); //If we do not get a localized licence then there is an error in the description.xml //This should be handled by using a validating parser. Therefore we assume that no //license is available. @@ -606,23 +597,20 @@ bool BackendImpl::PackageImpl::checkDependencies( OUSTR("Could not obtain path to license. Possible error in description.xml"), 0, Any()); OUString sHref = desc.getExtensionRootUrl() + OUSTR("/") + sLic; OUString sLicense = getTextFromURL(xCmdEnv, sHref); - //determine who has to agree to the license - css::uno::Reference<css::xml::xpath::XXPathObject> nodeAttribWho3 = - xPath->eval(nodeSimpleLic, - OUSTR("@accept-by")); - OUString sAccept = nodeAttribWho3->getString().trim(); + ////determine who has to agree to the license //check correct value for attribute - if ( ! (sAccept.equals(OUSTR("user")) || sAccept.equals(OUSTR("admin")))) + if ( ! (simplLicAttr->acceptBy.equals(OUSTR("user")) || simplLicAttr->acceptBy.equals(OUSTR("admin")))) throw css::deployment::DeploymentException( OUSTR("Could not obtain attribute simple-lincense@accept-by or it has no valid value"), 0, Any()); //If if @accept-by="user" then every user needs to accept the license before it can be installed. - //Therefore we must prevent the installation as shared extension. + //Therefore we must prevent the installation as shared extension unless suppress-if-required="true" OSL_ASSERT(aContextName.getLength()); - if (sAccept.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared"))) + if (simplLicAttr->acceptBy.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared"))) { - css::deployment::LicenseIndividualAgreementException exc = - css::deployment::LicenseIndividualAgreementException(OUString(), 0, m_name); + css::deployment::LicenseIndividualAgreementException + exc = css::deployment::LicenseIndividualAgreementException( + OUString(), 0, m_name, simplLicAttr->suppressIfRequired); bool approve = false; bool abort = false; @@ -632,32 +620,24 @@ bool BackendImpl::PackageImpl::checkDependencies( OUSTR("Could not interact with user."), 0, Any()); if (abort == true) return false; - //We should always prevent installation - OSL_ASSERT(0); - } - //determine optional attribute simple-license@suppressOnUpdate - css::uno::Reference<css::xml::dom::XElement> elemSimpleLic(nodeSimpleLic, css::uno::UNO_QUERY_THROW); - sal_Bool bSuppress = sal_False; - if (elemSimpleLic->hasAttribute(OUSTR("suppress-on-update"))) - { - if (elemSimpleLic->getAttribute(OUSTR("suppress-on-update")).equals(OUSTR("true"))) - bSuppress = sal_True; + //If the unopkg --suppress-license was used and simplLicAttr->suppressIfRequired == true, + //then the user implicitely accepts the license } //Only use interaction if there is no version of this extension already installed //and the suppress-on-update flag is not set for the new extension - // bInstalled | bSuppress | show license + // bInstalled | bSuppressOnUpdate | show license //---------------------------------------- - // 0 | 0 | 1 - // 0 | 1 | 1 - // 1 | 0 | 1 - // 1 | 1 | 0 + // 0 | 0 | 1 + // 0 | 1 | 1 + // 1 | 0 | 1 + // 1 | 1 | 0 - if ( !(bInstalled && bSuppress)) + if ( !(bInstalled && simplLicAttr->suppressOnUpdate)) { - css::deployment::LicenseException licExc = - css::deployment::LicenseException(OUString(), 0, m_name, sLicense); + css::deployment::LicenseException licExc( + OUString(), 0, m_name, sLicense, simplLicAttr->suppressIfRequired); bool approve = false; bool abort = false; if (! interactContinuation( diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx index 02fde984141c..2acd4f79a781 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx +++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx @@ -82,6 +82,8 @@ const char s_usingText [] = " -V, --version version information\n" " -v, --verbose verbose output to stdout\n" " -f, --force force overwriting existing extensions\n" +" -s, --suppress-license prevents showing the license provided that\n" +" the extension allows it\n" " --log-file <file> custom log file; default: <cache-dir>/log.txt\n" " --shared expert feature: operate on shared installation\n" " deployment context;\n" @@ -103,6 +105,7 @@ const OptionInfo s_option_infos [] = { { RTL_CONSTASCII_STRINGPARAM("shared"), '\0', false }, { RTL_CONSTASCII_STRINGPARAM("deployment-context"), '\0', true }, { RTL_CONSTASCII_STRINGPARAM("bundled"), '\0', false}, + { RTL_CONSTASCII_STRINGPARAM("suppress-license"), 's', false}, { 0, 0, '\0', false } }; @@ -207,6 +210,7 @@ extern "C" int unopkg_main() bool option_force = false; bool option_verbose = false; bool option_bundled = false; + bool option_suppressLicense = false; bool subcmd_add = false; bool subcmd_gui = false; OUString logFile; @@ -230,6 +234,9 @@ extern "C" int unopkg_main() s_option_infos, OUSTR("version") ); OptionInfo const * info_bundled = getOptionInfo( s_option_infos, OUSTR("bundled") ); + OptionInfo const * info_suppressLicense = getOptionInfo( + s_option_infos, OUSTR("suppress-license") ); + Reference<XComponentContext> xComponentContext; Reference<XComponentContext> xLocalComponentContext; @@ -271,6 +278,7 @@ extern "C" int unopkg_main() !readOption( &option_shared, info_shared, &nPos ) && !readOption( &option_force, info_force, &nPos ) && !readOption( &option_bundled, info_bundled, &nPos ) && + !readOption( &option_suppressLicense, info_suppressLicense, &nPos ) && !readArgument( &deploymentContext, info_context, &nPos ) && !isBootstrapVariable(&nPos)) { @@ -342,7 +350,8 @@ extern "C" int unopkg_main() Reference< ::com::sun::star::ucb::XCommandEnvironment > xCmdEnv( createCmdEnv( xComponentContext, logFile, - option_force, option_verbose, option_bundled) ); + option_force, option_verbose, option_bundled, + option_suppressLicense) ); if (subcmd_add || subCommand.equalsAsciiL( diff --git a/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx b/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx index 414a80eccc79..e4a503d98732 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx +++ b/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx @@ -86,6 +86,7 @@ class CommandEnvironmentImpl bool m_option_force_overwrite; bool m_option_verbose; bool m_option_bundled; + bool m_option_suppressLicense; Reference< XComponentContext > m_xComponentContext; Reference< XProgressHandler > m_xLogFile; @@ -99,7 +100,8 @@ public: OUString const & log_file, bool option_force_overwrite, bool option_verbose, - bool option_bundled); + bool option_bundled, + bool option_suppressLicense); // XCommandEnvironment virtual Reference< task::XInteractionHandler > SAL_CALL @@ -124,11 +126,13 @@ CommandEnvironmentImpl::CommandEnvironmentImpl( OUString const & log_file, bool option_force_overwrite, bool option_verbose, - bool option_bundled) + bool option_bundled, + bool option_suppressLicense) : m_logLevel(0), m_option_force_overwrite( option_force_overwrite ), m_option_verbose( option_verbose ), m_option_bundled( option_bundled), + m_option_suppressLicense( option_suppressLicense), m_xComponentContext(xComponentContext) { if (log_file.getLength() > 0) { @@ -279,15 +283,25 @@ void CommandEnvironmentImpl::handle( } else if (request >>= licAgreementExc) { - String sResMsg( ResId( RID_STR_UNOPKG_NO_SHARED_ALLOWED, *DeploymentResMgr::get() ) ); - sResMsg.SearchAndReplaceAllAscii( "%NAME", licAgreementExc.ExtensionName ); - dp_misc::writeConsole(OUSTR("\n") + sResMsg + OUSTR("\n\n")); - abort = true; + if (m_option_suppressLicense && licAgreementExc.SuppressIfRequired) + { + approve = true; + } + else + { + String sResMsg( ResId( RID_STR_UNOPKG_NO_SHARED_ALLOWED, *DeploymentResMgr::get() ) ); + sResMsg.SearchAndReplaceAllAscii( "%NAME", licAgreementExc.ExtensionName ); + dp_misc::writeConsole(OUSTR("\n") + sResMsg + OUSTR("\n\n")); + abort = true; + } } else if (request >>= licExc) { bLicenseException = true; - printLicense(licExc.Text, approve, abort); + if (m_option_suppressLicense && licExc.SuppressIfRequired) + approve = true; + else + printLicense(licExc.Text, approve, abort); } else if (request >>= instExc) { @@ -432,10 +446,12 @@ Reference< XCommandEnvironment > createCmdEnv( OUString const & logFile, bool option_force_overwrite, bool option_verbose, - bool option_bundled) + bool option_bundled, + bool option_suppressLicense) { return new CommandEnvironmentImpl( - xContext, logFile, option_force_overwrite, option_verbose, option_bundled); + xContext, logFile, option_force_overwrite, option_verbose, option_bundled, + option_suppressLicense); } } // unopkg diff --git a/desktop/source/pkgchk/unopkg/unopkg_shared.h b/desktop/source/pkgchk/unopkg/unopkg_shared.h index cd082231774d..6e9d30cf0d42 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_shared.h +++ b/desktop/source/pkgchk/unopkg/unopkg_shared.h @@ -163,7 +163,8 @@ css::uno::Reference<css::ucb::XCommandEnvironment> createCmdEnv( ::rtl::OUString const & logFile, bool option_force_overwrite, bool option_verbose, - bool option_bundled); + bool option_bundled, + bool option_suppressLicense); //============================================================================== void printf_packages( diff --git a/desktop/test/deployment/simple_license/suppress_license.oxt b/desktop/test/deployment/simple_license/suppress_license.oxt Binary files differnew file mode 100755 index 000000000000..2bacd6aa378b --- /dev/null +++ b/desktop/test/deployment/simple_license/suppress_license.oxt diff --git a/desktop/test/deployment/simple_license/tests_simple_license.odt b/desktop/test/deployment/simple_license/tests_simple_license.odt Binary files differindex b0f5410d9987..b0c86e11c69b 100644 --- a/desktop/test/deployment/simple_license/tests_simple_license.odt +++ b/desktop/test/deployment/simple_license/tests_simple_license.odt |