Skip to content

Commit

Permalink
Use libxml2 for configuration parsing
Browse files Browse the repository at this point in the history
IB-7946

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma committed Mar 3, 2024
1 parent 7b4c297 commit 78c7428
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 199 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
brew unlink python@3.10 || true
brew unlink python@3.11 || true
brew unlink python@3.12 || true
brew unlink xz
- name: Cache
uses: actions/cache@v4
id: cache
Expand All @@ -45,6 +46,9 @@ jobs:
- name: Build xml-security-c
if: steps.cache.outputs.cache-hit != 'true'
run: ./prepare_osx_build_environment.sh xmlsec ${{ matrix.target }}
- name: Build libxml2
if: steps.cache.outputs.cache-hit != 'true'
run: ./prepare_osx_build_environment.sh libxml2 ${{ matrix.target }}
- name: Move to cache
if: steps.cache.outputs.cache-hit != 'true'
run: |
Expand Down Expand Up @@ -84,7 +88,7 @@ jobs:
- name: Install Deps
run: |
dnf install -y --setopt=install_weak_deps=False \
git gcc-c++ cmake rpm-build xml-security-c-devel zlib-devel vim-common doxygen boost-test swig python3-devel java-1.8.0-openjdk-devel xsd minizip-devel
git gcc-c++ cmake rpm-build xml-security-c-devel libxml2-devel zlib-devel vim-common doxygen boost-test swig python3-devel java-1.8.0-openjdk-devel xsd minizip-devel
- name: Install CMake
if: matrix.container == 'fedora:39'
run: |
Expand Down Expand Up @@ -118,7 +122,7 @@ jobs:
DEBEMAIL: github-actions@github.com
steps:
- name: Install dependencies
run: apt update -qq && apt install --no-install-recommends -y git lsb-release fakeroot build-essential devscripts debhelper cmake xxd xsdcxx libxml-security-c-dev zlib1g-dev doxygen swig openjdk-8-jdk-headless libpython3-dev python3-distutils libboost-test-dev lintian
run: apt update -qq && apt install --no-install-recommends -y git lsb-release fakeroot build-essential devscripts debhelper cmake xxd xsdcxx libxml-security-c-dev libxml2-dev zlib1g-dev doxygen swig openjdk-8-jdk-headless libpython3-dev python3-distutils libboost-test-dev lintian
- name: Checkout
uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ find_package(OpenSSL 1.1.1 REQUIRED)
find_package(PKCS11)
#find_package(PoDoFo)
find_package(Threads)
find_package(LibXml2 REQUIRED)
find_package(XmlSecurityC REQUIRED)
find_package(XSD 4.0 REQUIRED)
find_package(ZLIB REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
1. Install dependencies

# Ubuntu
sudo apt install cmake xxd libxml-security-c-dev xsdcxx libssl-dev zlib1g-dev
sudo apt install cmake xxd libxml-security-c-dev xsdcxx libxml2-dev libssl-dev zlib1g-dev
# Fedora
sudo dnf install cmake gcc-c++ openssl-devel xerces-c-devel xml-security-c-devel xsd zlib-devel vim-common
sudo dnf install cmake gcc-c++ openssl-devel xerces-c-devel xml-security-c-devel xsd libxml2-devel zlib-devel vim-common

* doxygen - Optional, for API documentation
* libboost-test-dev - Optional, for unittests
Expand Down
1 change: 1 addition & 0 deletions libdigidocpp.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<File Source="$(var.VCPKG)\Xalan-C_1_12.dll" />
<File Source="$(var.VCPKG)\XalanMessages_1_12.dll" />
<File Source="$(var.VCPKG)\xsec_2_0.dll" />
<File Source="$(var.VCPKG)\libxml2.dll"/>
<File Name="digidocpp.dll" />
<File Name="digidoc-tool.exe" />
<File Source="$(var.libdigidocpp)\etc\digidocpp\digidocpp.conf" />
Expand Down
9 changes: 5 additions & 4 deletions prepare_osx_build_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ XALAN_DIR=xalan_c-1.12
XMLSEC_DIR=xml-security-c-2.0.4
XSD=xsd-4.0.0-i686-macosx
OPENSSL_DIR=openssl-3.0.13
LIBXML2_DIR=libxml2-2.11.5
LIBXML2_DIR=libxml2-2.12.5
ANDROID_NDK=android-ndk-r26b
FREETYPE_DIR=freetype-2.10.1
FONTCONFIG_DIR=fontconfig-2.13.1
Expand Down Expand Up @@ -232,11 +232,11 @@ function libxml2 {
return 0
;;
esac
if [ ! -f ${LIBXML2_DIR}.tar.gz ]; then
curl -O -L http://xmlsoft.org/sources/${LIBXML2_DIR}.tar.gz
if [ ! -f ${LIBXML2_DIR}.tar.xz ]; then
curl -O -L https://download.gnome.org/sources/libxml2/2.12/${LIBXML2_DIR}.tar.xz
fi
rm -rf ${LIBXML2_DIR}
tar xf ${LIBXML2_DIR}.tar.gz
tar xf ${LIBXML2_DIR}.tar.xz
cd ${LIBXML2_DIR}
./configure --prefix=${TARGET_PATH} ${CONFIGURE} --without-python
# Android is missing glob.h
Expand Down Expand Up @@ -429,6 +429,7 @@ case "$@" in
openssl
xalan
xml_security
libxml2
;;
*)
echo "Usage:"
Expand Down
4 changes: 2 additions & 2 deletions src/ASiContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ unique_ptr<iostream> ASiContainer::dataStream(const string &path, const ZipSeria
*/
void ASiContainer::addDataFile(const string &path, const string &mediaType)
{
string fileName = File::fileName(path);
string fileName(File::fileName(path));
addDataFileChecks(fileName, mediaType);
if(!File::fileExists(path))
THROW("Document file '%s' does not exist.", path.c_str());

ZipSerialize::Properties prop { appInfo(), File::modifiedTime(path), File::fileSize(path) };
bool useTempFile = prop.size > MAX_MEM_FILE;
zproperty(File::fileName(path), std::move(prop));
zproperty(fileName, std::move(prop));
unique_ptr<istream> is;
if(useTempFile)
{
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ configure_file( ${CMAKE_SOURCE_DIR}/etc/digidocpp.conf.cmake digidocpp.conf )

set(SCHEMA_DIR ${CMAKE_SOURCE_DIR}/etc/schema)
set(XML_DIR ${CMAKE_CURRENT_BINARY_DIR}/xml)
XSD_SCHEMA( xsd_SRCS IGNORE ${XML_DIR} ${SCHEMA_DIR}/conf.xsd
--root-element configuration )
XSD_SCHEMA( xsd_SRCS IGNORE ${XML_DIR} ${SCHEMA_DIR}/OpenDocument_manifest.xsd
--root-element manifest
--namespace-map urn:oasis:names:tc:opendocument:xmlns:manifest:1.0=digidoc::manifest )
Expand Down Expand Up @@ -161,6 +159,7 @@ add_library(digidocpp_priv STATIC
xml/SecureDOMParser.cpp
xml/UnsignedSignaturePropertiesType.cpp
xml/URIResolver.cpp
xml/XMLDocument.h
)

set_target_properties(digidocpp_util digidocpp_priv PROPERTIES
Expand All @@ -183,6 +182,7 @@ target_link_libraries(digidocpp_priv
digidocpp_util
XmlSecurityC::XmlSecurityC
ZLIB::ZLIB
LibXml2::LibXml2
$<$<C_COMPILER_ID:MSVC>:Ws2_32>
)

Expand Down
3 changes: 3 additions & 0 deletions src/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "util/File.h"
#include "util/log.h"

#include <libxml/parser.h>

DIGIDOCPP_WARNING_PUSH
DIGIDOCPP_WARNING_DISABLE_CLANG("-Wnull-conversion")
DIGIDOCPP_WARNING_DISABLE_MSVC(4005)
Expand Down Expand Up @@ -188,6 +190,7 @@ void digidoc::terminate()
XMLPlatformUtils::Terminate();

util::File::deleteTempFiles();
xmlCleanupParser();
} catch (...) {
// Don't throw on terminate
}
Expand Down
2 changes: 1 addition & 1 deletion src/SiVaContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ SiVaContainer::SiVaContainer(const string &path, ContainerOpenCB *cb, bool useHa
{
DEBUG("SiVaContainer::SiVaContainer(%s, %d)", path.c_str(), useHashCode);
unique_ptr<istream> ifs = make_unique<ifstream>(File::encodeName(d->path = path), ifstream::binary);
auto fileName = File::fileName(path);
string fileName(File::fileName(path));
istream *is = ifs.get();
if(File::fileExtension(path, {"ddoc"}))
{
Expand Down
Loading

0 comments on commit 78c7428

Please sign in to comment.