[Libreoffice-commits] online.git: 2 commits - kit/DummyLibreOfficeKit.cpp kit/DummyLibreOfficeKit.hpp kit/Kit.cpp Makefile.am test/helpers.hpp

Jan Holesovsky kendy at collabora.com
Wed Feb 8 11:03:51 UTC 2017


 Makefile.am                 |    6 
 kit/DummyLibreOfficeKit.cpp |  592 ++++++++++++++++++++++++++++++++++++++++++++
 kit/DummyLibreOfficeKit.hpp |   29 ++
 kit/Kit.cpp                 |    7 
 test/helpers.hpp            |    4 
 5 files changed, 636 insertions(+), 2 deletions(-)

New commits:
commit 5873d15c6257550857eeba24c227053acf6a313e
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Feb 8 11:46:11 2017 +0100

    fuzzer: Use the dummy LOK implementation when fuzzing.
    
    Now it is possible to use:
    
      ./loolwsd_fuzzer --config-file=loolwsd.xml --o:storage.filesystem[@allow]=true --o:logging.level=fatal --fuzz=/tmp/looltrace
    
    Ie. no need to specify the LibreOffice install location.  Ideally worth
    disabling the logging output too, to gain higher performance.
    
    Change-Id: I4fa5f275cd4f4a52fe2cd07e658cea726f6f31c2

diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 29fc24f..21300d9 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -65,6 +65,10 @@
 
 #include "common/SigUtil.hpp"
 
+#ifdef FUZZER
+#include <kit/DummyLibreOfficeKit.hpp>
+#endif
+
 #define LIB_SOFFICEAPP  "lib" "sofficeapp" ".so"
 #define LIB_MERGED      "lib" "mergedlo" ".so"
 
@@ -1716,6 +1720,9 @@ void lokit_main(const std::string& childRoot,
             LibreOfficeKit* kit = UnitKit::get().lok_init(instdir, userdir);
 #else
             LibreOfficeKit* kit = nullptr;
+#ifdef FUZZER
+            kit = dummy_lok_init_2(instdir, userdir);
+#endif
 #endif
             if (!kit)
             {
diff --git a/test/helpers.hpp b/test/helpers.hpp
index 5b9b498..60b94cb 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -128,7 +128,11 @@ void getDocumentPathAndURL(const std::string& docFilename, std::string& document
 inline
 void sendTextFrame(LOOLWebSocket& socket, const std::string& string, const std::string& name = "")
 {
+#ifndef FUZZER
     std::cerr << name << "Sending " << string.size() << " bytes: " << LOOLProtocol::getAbbreviatedMessage(string) << std::endl;
+#else
+    (void) name;
+#endif
     socket.sendFrame(string.data(), string.size());
 }
 
commit ee79577960780cf0e5707d0fee5b2892a4e06e9b
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Feb 8 11:24:19 2017 +0100

    fuzzer: Add a dummy LibreOfficeKit implementation.
    
    This just returns empty values (or does nothing), instead of calling the real
    LibreOffice.
    
    Change-Id: Ie6fe0b554056ba73067a76c22067f088e1346b59

diff --git a/Makefile.am b/Makefile.am
index 651057b..e8e6760 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -86,7 +86,8 @@ loolforkit_SOURCES = $(loolforkit_sources) \
 
 loolwsd_fuzzer_SOURCES = $(loolwsd_sources) \
                          $(loolforkit_sources) \
-                         $(shared_sources)
+                         $(shared_sources) \
+                         kit/DummyLibreOfficeKit.cpp
 
 # build a binary with no caps to help debugging
 loolforkit_nocaps_SOURCES = $(loolforkit_SOURCES)
@@ -136,8 +137,9 @@ shared_headers = common/Common.hpp \
                  common/SpookyV2.h
 
 kit_headers = kit/ChildSession.hpp \
+              kit/DummyLibreOfficeKit.hpp \
               kit/Kit.hpp \
-	      kit/KitHelper.hpp
+              kit/KitHelper.hpp
 
 noinst_HEADERS = $(wsd_headers) $(shared_headers) $(kit_headers) \
                  bundled/include/LibreOfficeKit/LibreOfficeKit.h \
diff --git a/kit/DummyLibreOfficeKit.cpp b/kit/DummyLibreOfficeKit.cpp
new file mode 100644
index 0000000..91bb4fa
--- /dev/null
+++ b/kit/DummyLibreOfficeKit.cpp
@@ -0,0 +1,592 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "DummyLibreOfficeKit.hpp"
+
+#include <cstring>
+#include <memory>
+
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
+
+struct LibLODocument_Impl : public _LibreOfficeKitDocument
+{
+    std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
+
+    LibLODocument_Impl();
+};
+
+struct LibLibreOffice_Impl : public _LibreOfficeKit
+{
+    std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
+
+    LibLibreOffice_Impl();
+};
+
+static LibLibreOffice_Impl *gImpl = nullptr;
+static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
+static std::weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
+
+extern "C"
+{
+
+static void doc_destroy(LibreOfficeKitDocument* pThis);
+static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* pUrl, const char* pFormat, const char* pFilterOptions);
+static int doc_getDocumentType(LibreOfficeKitDocument* pThis);
+static int doc_getParts(LibreOfficeKitDocument* pThis);
+static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis);
+static int doc_getPart(LibreOfficeKitDocument* pThis);
+static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
+static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
+static void doc_setPartMode(LibreOfficeKitDocument* pThis, int nPartMode);
+static void doc_paintTile(LibreOfficeKitDocument* pThis,
+                          unsigned char* pBuffer,
+                          const int nCanvasWidth, const int nCanvasHeight,
+                          const int nTilePosX, const int nTilePosY,
+                          const int nTileWidth, const int nTileHeight);
+static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
+                              unsigned char* pBuffer,
+                              const int nPart,
+                              const int nCanvasWidth, const int nCanvasHeight,
+                              const int nTilePosX, const int nTilePosY,
+                              const int nTileWidth, const int nTileHeight);
+static int doc_getTileMode(LibreOfficeKitDocument* pThis);
+static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
+                                long* pWidth,
+                                long* pHeight);
+static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
+                                       const char* pArguments);
+
+static void doc_registerCallback(LibreOfficeKitDocument* pThis,
+                                LibreOfficeKitCallback pCallback,
+                                void* pData);
+static void doc_postKeyEvent(LibreOfficeKitDocument* pThis,
+                             int nType,
+                             int nCharCode,
+                             int nKeyCode);
+static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
+                                int nType,
+                                int nX,
+                                int nY,
+                                int nCount,
+                                int nButtons,
+                                int nModifier);
+static void doc_postUnoCommand(LibreOfficeKitDocument* pThis,
+                               const char* pCommand,
+                               const char* pArguments,
+                               bool bNotifyWhenFinished);
+static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
+                                  int nType,
+                                  int nX,
+                                  int nY);
+static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
+                                  const char* pMimeType,
+                                  char** pUsedMimeType);
+static bool doc_paste(LibreOfficeKitDocument* pThis,
+                      const char* pMimeType,
+                      const char* pData,
+                      size_t nSize);
+static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
+                                  int nType,
+                                  int nX,
+                                  int nY);
+static void doc_resetSelection (LibreOfficeKitDocument* pThis);
+static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
+static void doc_setClientZoom(LibreOfficeKitDocument* pThis,
+                                    int nTilePixelWidth,
+                                    int nTilePixelHeight,
+                                    int nTileTwipWidth,
+                                    int nTileTwipHeight);
+static void doc_setClientVisibleArea(LibreOfficeKitDocument* pThis, int nX, int nY, int nWidth, int nHeight);
+static int doc_createView(LibreOfficeKitDocument* pThis);
+static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
+static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
+static int doc_getView(LibreOfficeKitDocument* pThis);
+static int doc_getViewsCount(LibreOfficeKitDocument* pThis);
+static bool doc_getViewIds(LibreOfficeKitDocument* pThis, int* pArray, size_t nSize);
+static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis,
+                          const char *pFontName,
+                          const char *pChar,
+                          int* pFontWidth,
+                          int* pFontHeight);
+static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart);
+
+LibLODocument_Impl::LibLODocument_Impl()
+{
+    if (!(m_pDocumentClass = gDocumentClass.lock()))
+    {
+        m_pDocumentClass.reset(new LibreOfficeKitDocumentClass);
+
+        m_pDocumentClass->nSize = sizeof(LibreOfficeKitDocument);
+
+        m_pDocumentClass->destroy = doc_destroy;
+        m_pDocumentClass->saveAs = doc_saveAs;
+        m_pDocumentClass->getDocumentType = doc_getDocumentType;
+        m_pDocumentClass->getParts = doc_getParts;
+        m_pDocumentClass->getPartPageRectangles = doc_getPartPageRectangles;
+        m_pDocumentClass->getPart = doc_getPart;
+        m_pDocumentClass->setPart = doc_setPart;
+        m_pDocumentClass->getPartName = doc_getPartName;
+        m_pDocumentClass->setPartMode = doc_setPartMode;
+        m_pDocumentClass->paintTile = doc_paintTile;
+        m_pDocumentClass->paintPartTile = doc_paintPartTile;
+        m_pDocumentClass->getTileMode = doc_getTileMode;
+        m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
+        m_pDocumentClass->initializeForRendering = doc_initializeForRendering;
+        m_pDocumentClass->registerCallback = doc_registerCallback;
+        m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
+        m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
+        m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
+        m_pDocumentClass->setTextSelection = doc_setTextSelection;
+        m_pDocumentClass->getTextSelection = doc_getTextSelection;
+        m_pDocumentClass->paste = doc_paste;
+        m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
+        m_pDocumentClass->resetSelection = doc_resetSelection;
+        m_pDocumentClass->getCommandValues = doc_getCommandValues;
+        m_pDocumentClass->setClientZoom = doc_setClientZoom;
+        m_pDocumentClass->setClientVisibleArea = doc_setClientVisibleArea;
+
+        m_pDocumentClass->createView = doc_createView;
+        m_pDocumentClass->destroyView = doc_destroyView;
+        m_pDocumentClass->setView = doc_setView;
+        m_pDocumentClass->getView = doc_getView;
+        m_pDocumentClass->getViewsCount = doc_getViewsCount;
+        m_pDocumentClass->getViewIds = doc_getViewIds;
+
+        m_pDocumentClass->renderFont = doc_renderFont;
+        m_pDocumentClass->getPartHash = doc_getPartHash;
+
+        gDocumentClass = m_pDocumentClass;
+    }
+    pClass = m_pDocumentClass.get();
+}
+
+static void                    lo_destroy       (LibreOfficeKit* pThis);
+static LibreOfficeKitDocument* lo_documentLoad  (LibreOfficeKit* pThis, const char* pURL);
+static char *                  lo_getError      (LibreOfficeKit* pThis);
+static void                    lo_freeError     (char* pFree);
+static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThis,
+                                                           const char* pURL,
+                                                           const char* pOptions);
+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);
+static char*                   lo_getVersionInfo(LibreOfficeKit* pThis);
+
+LibLibreOffice_Impl::LibLibreOffice_Impl()
+{
+    if(!m_pOfficeClass) {
+        m_pOfficeClass.reset(new LibreOfficeKitClass);
+        m_pOfficeClass->nSize = sizeof(LibreOfficeKitClass);
+
+        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;
+        m_pOfficeClass->setOptionalFeatures = lo_setOptionalFeatures;
+        m_pOfficeClass->setDocumentPassword = lo_setDocumentPassword;
+        m_pOfficeClass->getVersionInfo = lo_getVersionInfo;
+
+        gOfficeClass = m_pOfficeClass;
+    }
+
+    pClass = m_pOfficeClass.get();
+}
+
+static LibreOfficeKitDocument* lo_documentLoad(LibreOfficeKit* pThis, const char* pURL)
+{
+    return lo_documentLoadWithOptions(pThis, pURL, nullptr);
+}
+
+static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, const char* pURL, const char* pOptions)
+{
+    (void) pThis;
+    (void) pURL;
+    (void) pOptions;
+
+    return new LibLODocument_Impl();
+}
+
+static void lo_registerCallback (LibreOfficeKit* pThis,
+                                 LibreOfficeKitCallback pCallback,
+                                 void* pData)
+{
+    (void) pThis;
+    (void) pCallback;
+    (void) pData;
+}
+
+static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions)
+{
+    (void) pThis;
+    (void) sUrl;
+    (void) pFormat;
+    (void) pFilterOptions;
+
+    return true;
+}
+
+static int doc_getDocumentType (LibreOfficeKitDocument* pThis)
+{
+    (void) pThis;
+    return LOK_DOCTYPE_TEXT;
+}
+
+static int doc_getParts (LibreOfficeKitDocument* pThis)
+{
+    (void) pThis;
+    return 1;
+}
+
+static int doc_getPart (LibreOfficeKitDocument* pThis)
+{
+    (void) pThis;
+    return 0;
+}
+
+static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
+{
+    (void) pThis;
+    (void) nPart;
+}
+
+static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis)
+{
+    (void) pThis;
+    return nullptr;
+}
+
+static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
+{
+    (void) pThis;
+    (void) nPart;
+
+    char* pMemory = static_cast<char*>(malloc(11));
+    strcpy(pMemory, "Dummy part");
+    return pMemory;
+
+}
+
+static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart)
+{
+    (void) pThis;
+    (void) nPart;
+    return nullptr;
+}
+
+static void doc_setPartMode(LibreOfficeKitDocument* pThis,
+                            int nPartMode)
+{
+    (void) pThis;
+    (void) nPartMode;
+}
+
+static void doc_paintTile(LibreOfficeKitDocument* pThis,
+                          unsigned char* pBuffer,
+                          const int nCanvasWidth, const int nCanvasHeight,
+                          const int nTilePosX, const int nTilePosY,
+                          const int nTileWidth, const int nTileHeight)
+{
+    (void) pThis;
+    (void) pBuffer;
+    (void) nCanvasWidth;
+    (void) nCanvasHeight;
+    (void) nTilePosX;
+    (void) nTilePosY;
+    (void) nTileWidth;
+    (void) nTileHeight;
+
+    // TODO maybe at least clean the buffer?
+}
+
+
+static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
+                              unsigned char* pBuffer,
+                              const int nPart,
+                              const int nCanvasWidth, const int nCanvasHeight,
+                              const int nTilePosX, const int nTilePosY,
+                              const int nTileWidth, const int nTileHeight)
+{
+    (void) nPart;
+
+    doc_paintTile(pThis, pBuffer, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+}
+
+static int doc_getTileMode(LibreOfficeKitDocument* /*pThis*/)
+{
+    return LOK_TILEMODE_BGRA;
+}
+
+static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
+                                long* pWidth,
+                                long* pHeight)
+{
+    (void) pThis;
+    // TODO better values here maybe?
+    *pWidth = 10000;
+    *pHeight = 10000;
+}
+
+static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
+                                       const char* pArguments)
+{
+    (void) pThis;
+    (void) pArguments;
+}
+
+static void doc_registerCallback(LibreOfficeKitDocument* pThis,
+                                 LibreOfficeKitCallback pCallback,
+                                 void* pData)
+{
+    (void) pThis;
+    (void) pCallback;
+    (void) pData;
+}
+
+static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
+{
+    (void) pThis;
+    (void) nType;
+    (void) nCharCode;
+    (void) nKeyCode;
+}
+
+static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)
+{
+    (void) pThis;
+    (void) pCommand;
+    (void) pArguments;
+    (void) bNotifyWhenFinished;
+}
+
+static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
+{
+    (void) pThis;
+    (void) nType;
+    (void) nX;
+    (void) nY;
+    (void) nCount;
+    (void) nButtons;
+    (void) nModifier;
+}
+
+static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
+{
+    (void) pThis;
+    (void) nType;
+    (void) nX;
+    (void) nY;
+}
+
+static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pUsedMimeType)
+{
+    (void) pThis;
+    (void) pMimeType;
+    (void) pUsedMimeType;
+
+    char* pMemory = static_cast<char*>(malloc(11));
+    strcpy(pMemory, "Dummy text");
+
+    if (pUsedMimeType)
+    {
+        *pUsedMimeType = static_cast<char*>(malloc(25));
+        strcpy(*pUsedMimeType, "text/plain;charset=utf-8");
+    }
+
+    return pMemory;
+}
+
+static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, const char* pData, size_t nSize)
+{
+    (void) pThis;
+    (void) pMimeType;
+    (void) pData;
+    (void) nSize;
+
+    return true;
+}
+
+static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
+{
+    (void) pThis;
+    (void) nType;
+    (void) nX;
+    (void) nY;
+}
+
+static void doc_resetSelection(LibreOfficeKitDocument* pThis)
+{
+    (void) pThis;
+}
+
+static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
+{
+    (void) pThis;
+    (void) pCommand;
+
+    char* pMemory = static_cast<char*>(malloc(1));
+    strcpy(pMemory, "");
+    return pMemory;
+}
+
+static void doc_setClientZoom(LibreOfficeKitDocument* pThis, int nTilePixelWidth, int nTilePixelHeight,
+        int nTileTwipWidth, int nTileTwipHeight)
+{
+    (void) pThis;
+    (void) nTilePixelWidth;
+    (void) nTilePixelHeight;
+    (void) nTileTwipWidth;
+    (void) nTileTwipHeight;
+}
+
+static void doc_setClientVisibleArea(LibreOfficeKitDocument* pThis, int nX, int nY, int nWidth, int nHeight)
+{
+    (void) pThis;
+    (void) nX;
+    (void) nY;
+    (void) nWidth;
+    (void) nHeight;
+}
+
+static int doc_createView(LibreOfficeKitDocument* /*pThis*/)
+{
+    return 1;
+}
+
+static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
+{
+    (void) nId;
+}
+
+static void doc_setView(LibreOfficeKitDocument* /*pThis*/, int nId)
+{
+    (void) nId;
+}
+
+static int doc_getView(LibreOfficeKitDocument* /*pThis*/)
+{
+    return 1;
+}
+
+static int doc_getViewsCount(LibreOfficeKitDocument* /*pThis*/)
+{
+    return 1;
+}
+
+static bool doc_getViewIds(LibreOfficeKitDocument* /*pThis*/, int* pArray, size_t nSize)
+{
+    (void) pArray;
+    (void) nSize;
+
+    // TODO Should we return something here?
+    return true;
+}
+
+unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/,
+                    const char* pFontName,
+                    const char* pChar,
+                    int* pFontWidth,
+                    int* pFontHeight)
+{
+    (void) pFontName;
+    (void) pChar;
+    (void) pFontWidth;
+    (void) pFontHeight;
+
+    return nullptr;
+}
+
+static char* lo_getError (LibreOfficeKit *pThis)
+{
+    (void) pThis;
+
+    char* pMemory = static_cast<char*>(malloc(12));
+    strcpy(pMemory, "Dummy error");
+    return pMemory;
+}
+
+static void lo_freeError(char* pFree)
+{
+    free(pFree);
+}
+
+static char* lo_getFilterTypes(LibreOfficeKit* pThis)
+{
+    (void) pThis;
+
+    // TODO anything more here?
+    return nullptr;
+}
+
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t const features)
+{
+    (void) pThis;
+    (void) features;
+}
+
+static void lo_setDocumentPassword(LibreOfficeKit* pThis,
+        const char* pURL, const char* pPassword)
+{
+    (void) pThis;
+    (void) pURL;
+    (void) pPassword;
+}
+
+static char* lo_getVersionInfo(LibreOfficeKit* /*pThis*/)
+{
+    const char version[] =
+        "{ "
+        "\"ProductName\": \"Dummy\", "
+        "\"ProductVersion\": \"5.3\", "
+        "\"ProductExtension\": \"Dummy\", "
+        "\"BuildId\": \"1\" "
+        "}";
+
+    char* pVersion = static_cast<char*>(malloc(sizeof(version)));
+    strcpy(pVersion, version);
+    return pVersion;
+}
+
+LibreOfficeKit* dummy_lok_init_2(const char *install_path,  const char *user_profile_url)
+{
+    (void) install_path;
+    (void) user_profile_url;
+
+    if (!gImpl)
+    {
+        gImpl = new LibLibreOffice_Impl();
+    }
+    return static_cast<LibreOfficeKit*>(gImpl);
+}
+
+static void doc_destroy(LibreOfficeKitDocument *pThis)
+{
+    LibLODocument_Impl *pDocument = static_cast<LibLODocument_Impl*>(pThis);
+    delete pDocument;
+}
+
+static void lo_destroy(LibreOfficeKit* pThis)
+{
+    LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
+    gImpl = nullptr;
+
+    delete pLib;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/kit/DummyLibreOfficeKit.hpp b/kit/DummyLibreOfficeKit.hpp
new file mode 100644
index 0000000..c08d878
--- /dev/null
+++ b/kit/DummyLibreOfficeKit.hpp
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_DESKTOP_INC_LIB_INIT_HXX
+#define INCLUDED_DESKTOP_INC_LIB_INIT_HXX
+
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKit.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+LibreOfficeKit* dummy_lok_init_2(const char *install_path,  const char *user_profile_url);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list