[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 5 commits - desktop/inc desktop/source include/LibreOfficeKit

Michael Stahl mstahl at redhat.com
Fri Jan 29 08:32:31 PST 2016


 desktop/inc/lib/init.hxx                     |   12 +++
 desktop/source/lib/init.cxx                  |   45 +++++++++++
 desktop/source/lib/lokinteractionhandler.cxx |  107 +++++++++++++++++++++++++--
 desktop/source/lib/lokinteractionhandler.hxx |   15 +++
 include/LibreOfficeKit/LibreOfficeKit.h      |   12 +++
 include/LibreOfficeKit/LibreOfficeKit.hxx    |   41 ++++++++++
 include/LibreOfficeKit/LibreOfficeKitEnums.h |   45 +++++++++++
 include/LibreOfficeKit/LibreOfficeKitInit.h  |   15 ++-
 8 files changed, 277 insertions(+), 15 deletions(-)

New commits:
commit 9dd1b28174e590a019fa4162b6dc5a069e9af0a5
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Jan 22 13:39:32 2016 +0100

    libreofficekit: password interaction optional and off by default
    
    Add setOptionalFeatures() function that clients must call during
    initialization, and enum LibreOfficeKitOptionalFeatures.
    
    Reviewed-on: https://gerrit.libreoffice.org/21809
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>
    (cherry picked from commit 23a0ee3c01c3588472e1c19605909d6b9401253c)
    
    libreofficekit: ask for password when loading encrypted documents
    (cherry picked from commit 2b63e576a5cf06f4af877d63403ad7955ac71b72)
    
    desktop: use x prefix for uno::Reference
    (cherry picked from commit 0101cd3da6262169fa273309a86ba5e7cfe573bf)
    
    loplugin:defaultparams
    (cherry picked from commit 95c8b8e85d3328bfbe906ef3f69145842aae01db)
    
    (cherry picked from commit 2241a7fd97b8b70d2d3106ac531cc72192ad708f)
    
    Conflicts:
    	desktop/inc/lib/init.hxx
    	desktop/source/lib/lokinteractionhandler.hxx
    	libreofficekit/source/gtk/lokdocview.cxx
    
    Change-Id: I73035193c87033052921c3aad94fdc057fe81111

diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index cb7df6f..b836052 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -7,15 +7,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 #include <LibreOfficeKit/LibreOfficeKit.h>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <boost/shared_ptr.hpp>
+#include <map>
 #include "../../source/inc/desktopdllapi.h"
 #include <osl/thread.h>
 
 using namespace css;
 using namespace boost;
 
+class LOKInteractionHandler;
+
 namespace desktop {
     struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
     {
@@ -35,7 +39,15 @@ namespace desktop {
         oslThread maThread;
         LibreOfficeKitCallback mpCallback;
         void *mpCallbackData;
+        int64_t mOptionalFeatures;
+        std::map<OString, rtl::Reference<LOKInteractionHandler>> mInteractionMap;
 
         LibLibreOffice_Impl();
+        ~LibLibreOffice_Impl();
+
+        bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
+        {
+            return (mOptionalFeatures & feature) != 0;
+        }
     };
 }
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 81d2a99..ccb2e40 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -449,11 +449,16 @@ static void                    lo_registerCallback (LibreOfficeKit* pThis,
                                                     LibreOfficeKitCallback pCallback,
                                                     void* pData);
 static char* lo_getFilterTypes(LibreOfficeKit* pThis);
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t features);
+static void                    lo_setDocumentPassword(LibreOfficeKit* pThis,
+                                                       const char* pURL,
+                                                       const char* pPassword);
 
 LibLibreOffice_Impl::LibLibreOffice_Impl()
     : maThread(0)
     , mpCallback(nullptr)
     , mpCallbackData(nullptr)
+    , mOptionalFeatures(0)
 {
     if(!(m_pOfficeClass = gOfficeClass.lock())) {
         m_pOfficeClass.reset(new LibreOfficeKitClass);
@@ -466,6 +471,8 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
         m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
         m_pOfficeClass->registerCallback = lo_registerCallback;
         m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
+        m_pOfficeClass->setOptionalFeatures = lo_setOptionalFeatures;
+        m_pOfficeClass->setDocumentPassword = lo_setDocumentPassword;
 
         gOfficeClass = m_pOfficeClass;
     }
@@ -473,6 +480,10 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
     pClass = m_pOfficeClass.get();
 }
 
+LibLibreOffice_Impl::~LibLibreOffice_Impl()
+{
+}
+
 namespace
 {
 
@@ -534,7 +545,10 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
                                                        uno::makeAny(OUString::createFromAscii(pOptions)),
                                                        beans::PropertyState_DIRECT_VALUE);
 
-        uno::Reference<task::XInteractionHandler2> xInteraction(new LOKInteractionHandler(::comphelper::getProcessComponentContext()));
+        rtl::Reference<LOKInteractionHandler> const pInteraction(
+            new LOKInteractionHandler(::comphelper::getProcessComponentContext(), pLib));
+        auto const pair(pLib->mInteractionMap.insert(std::make_pair(aURL.toUtf8(), pInteraction)));
+        uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction.get());
         aFilterOptions[1].Name = "InteractionHandler";
         aFilterOptions[1].Value <<= xInteraction;
 
@@ -553,6 +567,12 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
                                             aURL, OUString("_blank"), 0,
                                             aFilterOptions);
 
+        assert(!xComponent.is() || pair.second); // concurrent loading of same URL ought to fail
+        if (!pair.second)
+        {
+            pLib->mInteractionMap.erase(aURL.toUtf8());
+        }
+
         if (!xComponent.is())
         {
             pLib->maLastExceptionMsg = "loadComponentFromURL returned an empty reference";
@@ -1657,6 +1677,22 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
     return strdup(aStream.str().c_str());
 }
 
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t const features)
+{
+    LibLibreOffice_Impl *const pLib = static_cast<LibLibreOffice_Impl*>(pThis);
+    pLib->mOptionalFeatures = features;
+}
+
+static void lo_setDocumentPassword(LibreOfficeKit* pThis,
+        const char* pURL, const char* pPassword)
+{
+    assert(pThis);
+    assert(pURL);
+    LibLibreOffice_Impl *const pLib = static_cast<LibLibreOffice_Impl*>(pThis);
+    assert(pLib->mInteractionMap.find(OString(pURL)) != pLib->mInteractionMap.end());
+    pLib->mInteractionMap.find(OString(pURL))->second->SetPassword(pPassword);
+}
+
 static void force_c_locale()
 {
     // force locale (and resource files loaded) to en-US
diff --git a/desktop/source/lib/lokinteractionhandler.cxx b/desktop/source/lib/lokinteractionhandler.cxx
index 1d20b02..50a7972 100644
--- a/desktop/source/lib/lokinteractionhandler.cxx
+++ b/desktop/source/lib/lokinteractionhandler.cxx
@@ -19,14 +19,28 @@
 
 #include "lokinteractionhandler.hxx"
 
+#include <rtl/ref.hxx>
 #include <cppuhelper/supportsservice.hxx>
 
+#include <com/sun/star/task/XInteractionAbort.hpp>
 #include <com/sun/star/task/XInteractionApprove.hpp>
+#include <com/sun/star/task/XInteractionPassword2.hpp>
+#include <com/sun/star/task/DocumentPasswordRequest2.hpp>
+
+#define LOK_USE_UNSTABLE_API
+#include <../../inc/lib/init.hxx>
+
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 using namespace com::sun::star;
 
-LOKInteractionHandler::LOKInteractionHandler(uno::Reference<uno::XComponentContext> const & /*rxContext*/)
+LOKInteractionHandler::LOKInteractionHandler(
+        uno::Reference<uno::XComponentContext> const & /*rxContext*/,
+        desktop::LibLibreOffice_Impl *const pLOKit)
+    : m_pLOKit(pLOKit)
+    , m_usePassword(false)
 {
+    assert(m_pLOKit);
 }
 
 LOKInteractionHandler::~LOKInteractionHandler()
@@ -58,15 +72,84 @@ void SAL_CALL LOKInteractionHandler::initialize(uno::Sequence<uno::Any> const &
 {
 }
 
-void SAL_CALL LOKInteractionHandler::handle(uno::Reference<task::XInteractionRequest> const & rRequest) throw (uno::RuntimeException, std::exception)
+void SAL_CALL LOKInteractionHandler::handle(
+        uno::Reference<task::XInteractionRequest> const & xRequest)
+throw (uno::RuntimeException, std::exception)
 {
     // just do the same thing in both cases
-    handleInteractionRequest(rRequest);
+    handleInteractionRequest(xRequest);
 }
 
-sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(const uno::Reference<task::XInteractionRequest >& rRequest) throw ( uno::RuntimeException, std::exception )
+sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(
+        const uno::Reference<task::XInteractionRequest>& xRequest)
+throw (uno::RuntimeException, std::exception)
 {
-    uno::Sequence<uno::Reference<task::XInteractionContinuation>> const &rContinuations = rRequest->getContinuations();
+    uno::Sequence<uno::Reference<task::XInteractionContinuation>> const &rContinuations = xRequest->getContinuations();
+
+    uno::Any const request(xRequest->getRequest());
+    task::DocumentPasswordRequest2 passwordRequest;
+    if (request >>= passwordRequest)
+    {
+        if (m_pLOKit->hasOptionalFeature((passwordRequest.IsRequestPasswordToModify)
+                    ? LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY
+                    : LOK_FEATURE_DOCUMENT_PASSWORD))
+        {
+            OString const url(passwordRequest.Name.toUtf8());
+            m_pLOKit->mpCallback(passwordRequest.IsRequestPasswordToModify
+                        ? LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY
+                        : LOK_CALLBACK_DOCUMENT_PASSWORD,
+                    url.getStr(),
+                    m_pLOKit->mpCallbackData);
+
+            // block until SetPassword is called
+            m_havePassword.wait();
+            m_havePassword.reset();
+        }
+
+        for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
+        {
+            if (m_usePassword)
+            {
+                if (passwordRequest.IsRequestPasswordToModify)
+                {
+                    uno::Reference<task::XInteractionPassword2> const xIPW2(
+                            rContinuations[i], uno::UNO_QUERY);
+                    xIPW2->setPasswordToModify(m_Password);
+                    xIPW2->select();
+                }
+                else
+                {
+                    uno::Reference<task::XInteractionPassword> const xIPW(
+                            rContinuations[i], uno::UNO_QUERY);
+                    if (xIPW.is())
+                    {
+                        xIPW->setPassword(m_Password);
+                        xIPW->select();
+                    }
+                }
+            }
+            else
+            {
+                if (passwordRequest.IsRequestPasswordToModify)
+                {
+                    uno::Reference<task::XInteractionPassword2> const xIPW2(
+                            rContinuations[i], uno::UNO_QUERY);
+                    xIPW2->setRecommendReadOnly(true);
+                    xIPW2->select();
+                }
+                else
+                {
+                    uno::Reference<task::XInteractionAbort> const xAbort(
+                            rContinuations[i], uno::UNO_QUERY);
+                    if (xAbort.is())
+                    {
+                        xAbort->select();
+                    }
+                }
+            }
+        }
+        return sal_True;
+    }
 
     // TODO: add LOK api that allows handling this for real, for the moment we
     // just set the interaction as 'Approved'
@@ -80,4 +163,18 @@ sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(const uno::Ref
     return sal_True;
 }
 
+void LOKInteractionHandler::SetPassword(char const*const pPassword)
+{
+    if (pPassword)
+    {
+        m_Password = OUString(pPassword, strlen(pPassword), RTL_TEXTENCODING_UTF8);
+        m_usePassword = true;
+    }
+    else
+    {
+        m_usePassword = false;
+    }
+    m_havePassword.set();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/lib/lokinteractionhandler.hxx b/desktop/source/lib/lokinteractionhandler.hxx
index 6d4aa82..2999cbb 100644
--- a/desktop/source/lib/lokinteractionhandler.hxx
+++ b/desktop/source/lib/lokinteractionhandler.hxx
@@ -20,12 +20,15 @@
 #ifndef INCLUDED_DESKTOP_SOURCE_LIB_LOKINTERACTIONHANDLER_HXX
 #define INCLUDED_DESKTOP_SOURCE_LIB_LOKINTERACTIONHANDLER_HXX
 
+#include <osl/conditn.hxx>
 #include <cppuhelper/implbase.hxx>
 
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/task/InteractionHandler.hpp>
 
+namespace desktop { struct LibLibreOffice_Impl; }
+
 /** InteractionHandler is an interface that provides the user with various dialogs / error messages.
 
 We need an own implementation for the LibreOfficeKit so that we can route the
@@ -38,11 +41,21 @@ class LOKInteractionHandler: public cppu::WeakImplHelper<com::sun::star::lang::X
                                                          com::sun::star::lang::XInitialization,
                                                          com::sun::star::task::XInteractionHandler2>
 {
+private:
+    desktop::LibLibreOffice_Impl * m_pLOKit;
+    OUString m_Password;
+    bool m_usePassword;
+    osl::Condition m_havePassword;
+
     LOKInteractionHandler(const LOKInteractionHandler&) SAL_DELETED_FUNCTION;
     LOKInteractionHandler& operator=(const LOKInteractionHandler&) SAL_DELETED_FUNCTION;
 
 public:
-    explicit LOKInteractionHandler(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const & rxContext);
+    void SetPassword(char const* pPassword);
+
+    explicit LOKInteractionHandler(
+            com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const & rxContext,
+            desktop::LibLibreOffice_Impl *);
 
     virtual ~LOKInteractionHandler();
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index c4c1749..b3b61ba 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -15,6 +15,7 @@
 #ifdef LOK_USE_UNSTABLE_API
 // the unstable API needs C99's bool
 #include <stdbool.h>
+#include <stdint.h>
 #endif
 
 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
@@ -64,6 +65,14 @@ struct _LibreOfficeKitClass
 
     /// @see lok::Office::getFilterTypes().
     char* (*getFilterTypes) (LibreOfficeKit* pThis);
+
+    /// @see lok::Office::setOptionalFeatures().
+    void (*setOptionalFeatures)(LibreOfficeKit* pThis, uint64_t features);
+
+    /// @see lok::Office::setDocumentPassword().
+    void (*setDocumentPassword) (LibreOfficeKit* pThis,
+            char const* pURL,
+            char const* pPassword);
 #endif
 
 };
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 0f3e0f1..df9e211 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -458,6 +458,40 @@ public:
     {
         return mpThis->pClass->getFilterTypes(mpThis);
     }
+
+    /**
+     * Set bitmask of optional features supported by the client.
+     *
+     * @see LibreOfficeKitOptionalFeatures
+     */
+    void setOptionalFeatures(uint64_t features)
+    {
+        return mpThis->pClass->setOptionalFeatures(mpThis, features);
+    }
+
+    /**
+     * Set password required for loading or editing a document.
+     *
+     * Loading the document is blocked until the password is provided.
+     *
+     * @param pURL      the URL of the document, as sent to the callback
+     * @param pPassword the password, nullptr indicates no password
+     *
+     * In response to LOK_CALLBACK_DOCUMENT_PASSWORD, a vaild password
+     * will continue loading the document, an invalid password will
+     * result in another LOK_CALLBACK_DOCUMENT_PASSWORD request,
+     * and a NULL password will abort loading the document.
+     *
+     * In response to LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY, a vaild
+     * password will continue loading the document, an invalid password will
+     * result in another LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY request,
+     * and a NULL password will continue loading the document in read-only
+     * mode.
+     */
+    inline void setDocumentPassword(char const* pURL, char const* pPassword)
+    {
+        mpThis->pClass->setDocumentPassword(mpThis, pURL, pPassword);
+    }
 #endif // LOK_USE_UNSTABLE_API
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index a0f5e88..5931f78 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -40,6 +40,32 @@ typedef enum
 }
 LibreOfficeKitTileMode;
 
+/** Optional features of LibreOfficeKit, in particular callbacks that block
+ *  LibreOfficeKit until the corresponding reply is received, which would
+ *  deadlock if the client does not support the feature.
+ *
+ *  @see lok::Office::setOptionalFeatures().
+ */
+typedef enum
+{
+    /**
+     * Handle LOK_CALLBACK_DOCUMENT_PASSWORD by prompting the user
+     * for a password.
+     *
+     * @see lok::Office::setDocumentPassword().
+     */
+    LOK_FEATURE_DOCUMENT_PASSWORD = (1ULL << 0),
+
+    /**
+     * Handle LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY by prompting the user
+     * for a password.
+     *
+     * @see lok::Office::setDocumentPassword().
+     */
+    LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY = (1ULL << 1),
+}
+LibreOfficeKitOptionalFeatures;
+
 typedef enum
 {
     /**
@@ -221,7 +247,24 @@ typedef enum
     /**
      * The text content of the formula bar in Calc.
      */
-    LOK_CALLBACK_CELL_FORMULA
+    LOK_CALLBACK_CELL_FORMULA,
+
+    /**
+     * Loading a document requires a password.
+     *
+     * Loading the document is blocked until the password is provided via
+     * lok::Office::setDocumentPassword().  The document cannot be loaded
+     * without the password.
+     */
+    LOK_CALLBACK_DOCUMENT_PASSWORD,
+
+    /**
+     * Editing a document requires a password.
+     *
+     * Loading the document is blocked until the password is provided via
+     * lok::Office::setDocumentPassword().
+     */
+    LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY,
 }
 LibreOfficeKitCallbackType;
 
commit eb583e76b016540aed3f6658a6711570e8f7214c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jan 21 09:10:29 2016 +0100

    Clean up lok::Office::freeError()
    
    - let it take a non-const pointer, just like free() or g_free() does
    - remove lok::Document::freeError(), which was declared, but not
      implemented
    - move the declaration at the end of the stable API, but before the
      unstable section
    
    (cherry picked from commit 8e0c4694f89dd66314faf5cfd411f58f2f8e1bca)
    
    Conflicts:
    	include/LibreOfficeKit/LibreOfficeKit.h
    	include/LibreOfficeKit/LibreOfficeKit.hxx
    
    Change-Id: I5a8ced61fc87641dc2fa0ea3615a350361fae3a1

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 2d2e9f0..81d2a99 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -441,7 +441,7 @@ static void                    lo_destroy       (LibreOfficeKit* pThis);
 static int                     lo_initialize    (LibreOfficeKit* pThis, const char* pInstallPath, const char* pUserProfilePath);
 static LibreOfficeKitDocument* lo_documentLoad  (LibreOfficeKit* pThis, const char* pURL);
 static char *                  lo_getError      (LibreOfficeKit* pThis);
-static void                    lo_freeError     (const char *pfree);
+static void                    lo_freeError     (char* pFree);
 static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThis,
                                                            const char* pURL,
                                                            const char* pOptions);
@@ -1615,9 +1615,10 @@ static char* lo_getError (LibreOfficeKit *pThis)
     strcpy(pMemory, aString.getStr());
     return pMemory;
 }
-static void lo_freeError(const char *pfree)
+
+static void lo_freeError(char* pFree)
 {
-    free(const_cast<char *>(pfree));
+    free(pFree);
 }
 
 static char* lo_getFilterTypes(LibreOfficeKit* pThis)
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index ec8c547..c4c1749 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -55,6 +55,8 @@ struct _LibreOfficeKitClass
     LibreOfficeKitDocument* (*documentLoadWithOptions) (LibreOfficeKit* pThis,
                                                         const char* pURL,
                                                         const char* pOptions);
+    void (*freeError) (char* pFree);
+
 #ifdef LOK_USE_UNSTABLE_API
     void (*registerCallback) (LibreOfficeKit* pThis,
                               LibreOfficeKitCallback pCallback,
@@ -63,7 +65,6 @@ struct _LibreOfficeKitClass
     /// @see lok::Office::getFilterTypes().
     char* (*getFilterTypes) (LibreOfficeKit* pThis);
 #endif
-    void  (*freeError)     (const char *pfree);
 
 };
 
@@ -84,7 +85,6 @@ struct _LibreOfficeKitDocumentClass
                    const char* pUrl,
                    const char* pFormat,
                    const char* pFilterOptions);
-    void  (*freeError)     (const char *pfree);
 
 #ifdef LOK_USE_UNSTABLE_API
     /// @see lok::Document::getDocumentType().
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 5a1ed910a..0f3e0f1 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -53,10 +53,6 @@ public:
 
     /// Gives access to the underlying C pointer.
     inline LibreOfficeKitDocument *get() { return mpDoc; }
-    inline void freeError(const char *pfree)
-    {
-        mpDoc->pClass->freeError(pfree);
-    }
 
 #ifdef LOK_USE_UNSTABLE_API
     /**
@@ -435,9 +431,11 @@ public:
     {
         return mpThis->pClass->getError(mpThis);
     }
-    inline void freeError(const char *pfree)
+
+    /// Frees the memory pointed to by pFree.
+    inline void freeError(char* pFree)
     {
-        mpThis->pClass->freeError(pfree);
+        mpThis->pClass->freeError(pFree);
     }
 
 
commit 4202952ec911aa48908943e96dd516384193dfac
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jan 19 22:05:00 2016 +0100

    loplugin:cstylecast
    
    Change-Id: Ib4052fa88cce3b21d20d050fff9c8d32fcde4c20
    (cherry picked from commit 10c9f31ad7d0696327b67b6d2a4e3f244473d877)

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a02a3a2..2d2e9f0 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1617,7 +1617,7 @@ static char* lo_getError (LibreOfficeKit *pThis)
 }
 static void lo_freeError(const char *pfree)
 {
-    free((void *) pfree);
+    free(const_cast<char *>(pfree));
 }
 
 static char* lo_getFilterTypes(LibreOfficeKit* pThis)
commit b0e1a040f475254195dc25393c89bda9071dbdf4
Author: Oliver Specht <oliver.specht at cib.de>
Date:   Wed Jan 20 07:52:51 2016 +0100

    freeError function moved to the end of the list
    
    Change-Id: I4aed102b25ddcd5f2e8fa03395e2ffd89c858bb9
    Reviewed-on: https://gerrit.libreoffice.org/21619
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Oliver Specht <oliver.specht at cib.de>
    (cherry picked from commit 23c2c7c9cb86db4a36f8a798e63402a053816ef2)

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 555fb48..ec8c547 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -51,7 +51,6 @@ struct _LibreOfficeKitClass
                                              const char* pURL);
 
     char* (*getError) (LibreOfficeKit* pThis);
-    void  (*freeError)     (const char *pfree);
 
     LibreOfficeKitDocument* (*documentLoadWithOptions) (LibreOfficeKit* pThis,
                                                         const char* pURL,
@@ -64,6 +63,8 @@ struct _LibreOfficeKitClass
     /// @see lok::Office::getFilterTypes().
     char* (*getFilterTypes) (LibreOfficeKit* pThis);
 #endif
+    void  (*freeError)     (const char *pfree);
+
 };
 
 #define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
commit 375f32c3307f9521ab6397621832dfd0754be654
Author: Oliver Specht <oliver.specht at cib.de>
Date:   Tue Jan 19 10:58:07 2016 +0100

    Make LibreOffice kit usable on windows
    
    Uses Ascii variants of LoadLibrary,Get/SetEnvironmentVariable_A_
    and adds a freeError function
    includes windows.h instead of pre/postwin.h
    
    (cherry picked from commit 442a022cf7baefbd5519ea55c7978cf839e1f44d)
    
    Conflicts:
    	include/LibreOfficeKit/LibreOfficeKitInit.h
    
    Change-Id: I88b7e3ed3818078efec5688e207da47dc4049b98

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index cbce5cc..a02a3a2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -441,6 +441,7 @@ static void                    lo_destroy       (LibreOfficeKit* pThis);
 static int                     lo_initialize    (LibreOfficeKit* pThis, const char* pInstallPath, const char* pUserProfilePath);
 static LibreOfficeKitDocument* lo_documentLoad  (LibreOfficeKit* pThis, const char* pURL);
 static char *                  lo_getError      (LibreOfficeKit* pThis);
+static void                    lo_freeError     (const char *pfree);
 static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThis,
                                                            const char* pURL,
                                                            const char* pOptions);
@@ -461,6 +462,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
         m_pOfficeClass->destroy = lo_destroy;
         m_pOfficeClass->documentLoad = lo_documentLoad;
         m_pOfficeClass->getError = lo_getError;
+        m_pOfficeClass->freeError = lo_freeError;
         m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
         m_pOfficeClass->registerCallback = lo_registerCallback;
         m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
@@ -1613,6 +1615,10 @@ static char* lo_getError (LibreOfficeKit *pThis)
     strcpy(pMemory, aString.getStr());
     return pMemory;
 }
+static void lo_freeError(const char *pfree)
+{
+    free((void *) pfree);
+}
 
 static char* lo_getFilterTypes(LibreOfficeKit* pThis)
 {
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index a78c0aa..555fb48 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -51,6 +51,7 @@ struct _LibreOfficeKitClass
                                              const char* pURL);
 
     char* (*getError) (LibreOfficeKit* pThis);
+    void  (*freeError)     (const char *pfree);
 
     LibreOfficeKitDocument* (*documentLoadWithOptions) (LibreOfficeKit* pThis,
                                                         const char* pURL,
@@ -82,6 +83,7 @@ struct _LibreOfficeKitDocumentClass
                    const char* pUrl,
                    const char* pFormat,
                    const char* pFilterOptions);
+    void  (*freeError)     (const char *pfree);
 
 #ifdef LOK_USE_UNSTABLE_API
     /// @see lok::Document::getDocumentType().
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 9960089..5a1ed910a 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -53,6 +53,10 @@ public:
 
     /// Gives access to the underlying C pointer.
     inline LibreOfficeKitDocument *get() { return mpDoc; }
+    inline void freeError(const char *pfree)
+    {
+        mpDoc->pClass->freeError(pfree);
+    }
 
 #ifdef LOK_USE_UNSTABLE_API
     /**
@@ -431,6 +435,11 @@ public:
     {
         return mpThis->pClass->getError(mpThis);
     }
+    inline void freeError(const char *pfree)
+    {
+        mpThis->pClass->freeError(pfree);
+    }
+
 
 #ifdef LOK_USE_UNSTABLE_API
     /**
diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h
index c2f3426..5e56608 100644
--- a/include/LibreOfficeKit/LibreOfficeKitInit.h
+++ b/include/LibreOfficeKit/LibreOfficeKitInit.h
@@ -82,7 +82,7 @@ extern "C"
 
     void *lok_loadlib(const char *pFN)
     {
-        return (void *) LoadLibrary(pFN);
+        return (void *) LoadLibraryA(pFN);
     }
 
     char *lok_dlerror(void)
@@ -108,11 +108,11 @@ extern "C"
             return;
 
         char* sEnvPath = NULL;
-        DWORD  cChars = GetEnvironmentVariable("PATH", sEnvPath, 0);
+        DWORD  cChars = GetEnvironmentVariableA("PATH", sEnvPath, 0);
         if (cChars > 0)
         {
             sEnvPath = new char[cChars];
-            cChars = GetEnvironmentVariable("PATH", sEnvPath, cChars);
+            cChars = GetEnvironmentVariableA("PATH", sEnvPath, cChars);
             //If PATH is not set then it is no error
             if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND)
             {
@@ -122,17 +122,18 @@ extern "C"
         }
         //prepare the new PATH. Add the Ure/bin directory at the front.
         //note also adding ';'
-        char * sNewPath = new char[strlen(sEnvPath) + strlen(pPath) + strlen(UNOPATH) + 2];
+        char * sNewPath = new char[strlen(sEnvPath) + strlen(pPath) * 2 + strlen(UNOPATH) + 4];
         sNewPath[0] = L'\0';
-        strcat(sNewPath, pPath);
-        strcat(sNewPath, UNOPATH);
+        strcat(sNewPath, pPath);     // program to PATH
+        strcat(sNewPath, ";");
+        strcat(sNewPath, UNOPATH);   // UNO to PATH
         if (strlen(sEnvPath))
         {
             strcat(sNewPath, ";");
             strcat(sNewPath, sEnvPath);
         }
 
-        SetEnvironmentVariable("PATH", sNewPath);
+        SetEnvironmentVariableA("PATH", sNewPath);
 
         delete[] sEnvPath;
         delete[] sNewPath;


More information about the Libreoffice-commits mailing list