mirror of
https://github.com/simon987/sist2.git
synced 2025-12-12 23:18:51 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a2820d339 | |||
| b7f13f425c | |||
| d1a2f9b1d5 | |||
| 71f17986db | |||
| acdd2fb3c1 | |||
| 0cda6c00e1 | |||
| 14d0e5a1e1 | |||
| 0d06d39281 | |||
| 80708ca636 | |||
|
|
43b7b40dc4 | ||
| d051f541e2 | |||
| 0eefbac7b4 | |||
| 663f8e21c1 | |||
| 80fbcb2a01 | |||
| 8451109ecd | |||
| d6fe61cfdc | |||
| 254094130f | |||
| eaaa75c04c | |||
| bb87f4270f |
48
.gitmodules
vendored
48
.gitmodules
vendored
@@ -4,30 +4,42 @@
|
|||||||
[submodule "cJSON"]
|
[submodule "cJSON"]
|
||||||
path = cJSON
|
path = cJSON
|
||||||
url = https://github.com/DaveGamble/cJSON
|
url = https://github.com/DaveGamble/cJSON
|
||||||
[submodule "lib/mupdf"]
|
|
||||||
path = lib/mupdf
|
|
||||||
url = git://git.ghostscript.com/mupdf.git
|
|
||||||
[submodule "lib/onion"]
|
|
||||||
path = lib/onion
|
|
||||||
url = https://github.com/davidmoreno/onion
|
|
||||||
[submodule "lib/ffmpeg"]
|
|
||||||
path = lib/ffmpeg
|
|
||||||
url = https://git.ffmpeg.org/ffmpeg.git
|
|
||||||
[submodule "lmdb"]
|
[submodule "lmdb"]
|
||||||
path = lmdb
|
path = lmdb
|
||||||
url = https://github.com/LMDB/lmdb
|
url = https://github.com/LMDB/lmdb
|
||||||
[submodule "utf8.h"]
|
[submodule "utf8.h"]
|
||||||
path = utf8.h
|
path = utf8.h
|
||||||
url = https://github.com/sheredom/utf8.h
|
url = https://github.com/sheredom/utf8.h
|
||||||
[submodule "lib/openjpeg"]
|
|
||||||
path = lib/openjpeg
|
|
||||||
url = https://github.com/uclouvain/openjpeg
|
|
||||||
[submodule "lib/harfbuzz"]
|
|
||||||
path = lib/harfbuzz
|
|
||||||
url = https://github.com/harfbuzz/harfbuzz
|
|
||||||
[submodule "lib/libmagic"]
|
|
||||||
path = lib/libmagic
|
|
||||||
url = https://github.com/threatstack/libmagic
|
|
||||||
[submodule "lib/bzip2-1.0.6"]
|
[submodule "lib/bzip2-1.0.6"]
|
||||||
path = lib/bzip2-1.0.6
|
path = lib/bzip2-1.0.6
|
||||||
url = https://github.com/enthought/bzip2-1.0.6
|
url = https://github.com/enthought/bzip2-1.0.6
|
||||||
|
[submodule "lib/libmagic"]
|
||||||
|
path = lib/libmagic
|
||||||
|
url = https://github.com/threatstack/libmagic
|
||||||
|
[submodule "lib/harfbuzz"]
|
||||||
|
path = lib/harfbuzz
|
||||||
|
url = https://github.com/harfbuzz/harfbuzz
|
||||||
|
[submodule "lib/openjpeg"]
|
||||||
|
path = lib/openjpeg
|
||||||
|
url = https://github.com/uclouvain/openjpeg
|
||||||
|
[submodule "lib/ffmpeg"]
|
||||||
|
path = lib/ffmpeg
|
||||||
|
url = https://git.ffmpeg.org/ffmpeg.git
|
||||||
|
[submodule "lib/onion"]
|
||||||
|
path = lib/onion
|
||||||
|
url = https://github.com/davidmoreno/onion
|
||||||
|
[submodule "lib/mupdf"]
|
||||||
|
path = lib/mupdf
|
||||||
|
url = git://git.ghostscript.com/mupdf.git
|
||||||
|
[submodule "lib/zstd"]
|
||||||
|
path = lib/zstd
|
||||||
|
url = https://github.com/facebook/zstd
|
||||||
|
[submodule "lib/lz4"]
|
||||||
|
path = lib/lz4
|
||||||
|
url = https://github.com/lz4/lz4
|
||||||
|
[submodule "lib/libarchive"]
|
||||||
|
path = lib/libarchive
|
||||||
|
url = https://github.com/libarchive/libarchive
|
||||||
|
[submodule "lib/libxml2"]
|
||||||
|
path = lib/libxml2
|
||||||
|
url = https://github.com/GNOME/libxml2
|
||||||
|
|||||||
69
.teamcity/settings.kts
vendored
Normal file
69
.teamcity/settings.kts
vendored
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.*
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.ExecBuildStep
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.exec
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot
|
||||||
|
|
||||||
|
/*
|
||||||
|
The settings script is an entry point for defining a TeamCity
|
||||||
|
project hierarchy. The script should contain a single call to the
|
||||||
|
project() function with a Project instance or an init function as
|
||||||
|
an argument.
|
||||||
|
|
||||||
|
VcsRoots, BuildTypes, Templates, and subprojects can be
|
||||||
|
registered inside the project using the vcsRoot(), buildType(),
|
||||||
|
template(), and subProject() methods respectively.
|
||||||
|
|
||||||
|
To debug settings scripts in command-line, run the
|
||||||
|
|
||||||
|
mvnDebug org.jetbrains.teamcity:teamcity-configs-maven-plugin:generate
|
||||||
|
|
||||||
|
command and attach your debugger to the port 8000.
|
||||||
|
|
||||||
|
To debug in IntelliJ Idea, open the 'Maven Projects' tool window (View
|
||||||
|
-> Tool Windows -> Maven Projects), find the generate task node
|
||||||
|
(Plugins -> teamcity-configs -> teamcity-configs:generate), the
|
||||||
|
'Debug' option is available in the context menu for the task.
|
||||||
|
*/
|
||||||
|
|
||||||
|
version = "2019.2"
|
||||||
|
|
||||||
|
project {
|
||||||
|
|
||||||
|
vcsRoot(HttpsGithubComSimon987sist2refsHeadsMaster)
|
||||||
|
|
||||||
|
buildType(Build)
|
||||||
|
}
|
||||||
|
|
||||||
|
object Build : BuildType({
|
||||||
|
name = "Build"
|
||||||
|
|
||||||
|
artifactRules = """
|
||||||
|
sist2
|
||||||
|
sist2_scan
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
vcs {
|
||||||
|
root(HttpsGithubComSimon987sist2refsHeadsMaster)
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
exec {
|
||||||
|
name = "Build"
|
||||||
|
path = "./ci/build.sh"
|
||||||
|
dockerImage = "simon987/general_ci"
|
||||||
|
dockerImagePlatform = ExecBuildStep.ImagePlatform.Linux
|
||||||
|
dockerPull = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
triggers {
|
||||||
|
vcs {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
object HttpsGithubComSimon987sist2refsHeadsMaster : GitVcsRoot({
|
||||||
|
name = "https://github.com/simon987/sist2#refs/heads/master"
|
||||||
|
url = "https://github.com/simon987/sist2"
|
||||||
|
})
|
||||||
@@ -27,6 +27,9 @@ if (WITH_SIST2)
|
|||||||
src/index/elastic.c src/index/elastic.h
|
src/index/elastic.c src/index/elastic.h
|
||||||
src/util.c src/util.h
|
src/util.c src/util.h
|
||||||
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
||||||
|
src/parsing/arc.c src/parsing/arc.h
|
||||||
|
src/parsing/doc.c src/parsing/doc.h
|
||||||
|
src/log.c src/log.h
|
||||||
|
|
||||||
# argparse
|
# argparse
|
||||||
argparse/argparse.h argparse/argparse.c
|
argparse/argparse.h argparse/argparse.c
|
||||||
@@ -41,7 +44,7 @@ if (WITH_SIST2)
|
|||||||
|
|
||||||
# utf8.h
|
# utf8.h
|
||||||
utf8.h/utf8.h
|
utf8.h/utf8.h
|
||||||
src/parsing/arc.c src/parsing/arc.h)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (WITH_SIST2_SCAN)
|
if (WITH_SIST2_SCAN)
|
||||||
@@ -60,6 +63,9 @@ if (WITH_SIST2_SCAN)
|
|||||||
src/parsing/text.h src/parsing/text.c
|
src/parsing/text.h src/parsing/text.c
|
||||||
src/util.c src/util.h
|
src/util.c src/util.h
|
||||||
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
||||||
|
src/parsing/arc.h src/parsing/arc.c
|
||||||
|
src/parsing/doc.h src/parsing/doc.c
|
||||||
|
src/log.h src/log.c
|
||||||
|
|
||||||
# argparse
|
# argparse
|
||||||
argparse/argparse.h argparse/argparse.c
|
argparse/argparse.h argparse/argparse.c
|
||||||
@@ -74,22 +80,19 @@ if (WITH_SIST2_SCAN)
|
|||||||
|
|
||||||
# utf8.h
|
# utf8.h
|
||||||
utf8.h/utf8.h
|
utf8.h/utf8.h
|
||||||
src/parsing/arc.c src/parsing/arc.h)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig/")
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig/")
|
||||||
|
|
||||||
find_package(LibMagic REQUIRED)
|
#find_package(OpenSSL REQUIRED)
|
||||||
find_package(FFmpeg REQUIRED)
|
|
||||||
find_package(OpenSSL REQUIRED)
|
|
||||||
find_package(Freetype REQUIRED)
|
find_package(Freetype REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
||||||
pkg_check_modules(GOBJECT REQUIRED gobject-2.0)
|
pkg_check_modules(GOBJECT REQUIRED gobject-2.0)
|
||||||
pkg_check_modules(UUID REQUIRED uuid)
|
pkg_check_modules(UUID REQUIRED uuid)
|
||||||
|
|
||||||
add_definitions(${LIBMAGIC_CFLAGS_OTHER})
|
|
||||||
add_definitions(${UUID_CFLAGS_OTHER})
|
add_definitions(${UUID_CFLAGS_OTHER})
|
||||||
add_definitions(${GLIB_CFLAGS_OTHER})
|
add_definitions(${GLIB_CFLAGS_OTHER})
|
||||||
add_definitions(${GOBJECT_CFLAGS_OTHER})
|
add_definitions(${GOBJECT_CFLAGS_OTHER})
|
||||||
@@ -102,22 +105,21 @@ list(REMOVE_ITEM UUID_LIBRARIES pcre)
|
|||||||
if (WITH_SIST2)
|
if (WITH_SIST2)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
sist2 PUBLIC
|
sist2 PUBLIC
|
||||||
${LIBMAGIC_INCLUDE_DIRS}
|
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
${GOBJECT_INCLUDE_DIRS}
|
||||||
${OPENSSL_INCLUDE_DIR}
|
|
||||||
${FFMPEG_INCLUDE_DIRS}
|
|
||||||
${GLIB_INCLUDE_DIRS}
|
${GLIB_INCLUDE_DIRS}
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/ffmpeg/
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
${FREETYPE_INCLUDE_DIRS}
|
||||||
${UUID_INCLUDE_DIRS}
|
${UUID_INCLUDE_DIRS}
|
||||||
${PROJECT_SOURCE_DIR}/
|
${PROJECT_SOURCE_DIR}/
|
||||||
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
||||||
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
||||||
|
${PROJECT_SOURCE_DIR}/include/
|
||||||
|
/usr/include/libxml2/
|
||||||
)
|
)
|
||||||
target_link_directories(
|
target_link_directories(
|
||||||
sist2 PUBLIC
|
sist2 PUBLIC
|
||||||
${UUID_LIBRARY_DIRS}
|
${UUID_LIBRARY_DIRS}
|
||||||
${FFMPEG_LIBRARY_DIRS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -142,8 +144,6 @@ if (WITH_SIST2)
|
|||||||
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
||||||
# ${FFMPEG_LIBRARIES}
|
|
||||||
# swscale
|
|
||||||
|
|
||||||
# mupdf
|
# mupdf
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
||||||
@@ -156,11 +156,17 @@ if (WITH_SIST2)
|
|||||||
curl
|
curl
|
||||||
m
|
m
|
||||||
bz2
|
bz2
|
||||||
magic
|
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
||||||
freetype
|
freetype
|
||||||
archive
|
archive
|
||||||
|
|
||||||
|
# ${PROJECT_SOURCE_DIR}/lib/libxml2.a
|
||||||
|
xml2
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libmce.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libopc.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libplib.a
|
||||||
)
|
)
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
@@ -182,7 +188,7 @@ if (WITH_SIST2_SCAN)
|
|||||||
${LIBMAGIC_INCLUDE_DIRS}
|
${LIBMAGIC_INCLUDE_DIRS}
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
${GOBJECT_INCLUDE_DIRS}
|
||||||
${OPENSSL_INCLUDE_DIR}
|
${OPENSSL_INCLUDE_DIR}
|
||||||
${FFMPEG_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lib/ffmpeg/
|
||||||
${GLIB_INCLUDE_DIRS}
|
${GLIB_INCLUDE_DIRS}
|
||||||
${UUID_INCLUDE_DIRS}
|
${UUID_INCLUDE_DIRS}
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
${FREETYPE_INCLUDE_DIRS}
|
||||||
@@ -190,11 +196,12 @@ if (WITH_SIST2_SCAN)
|
|||||||
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
||||||
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
||||||
|
${PROJECT_SOURCE_DIR}/include/
|
||||||
|
/usr/include/libxml2/
|
||||||
)
|
)
|
||||||
target_link_directories(
|
target_link_directories(
|
||||||
sist2_scan PUBLIC
|
sist2_scan PUBLIC
|
||||||
${UUID_LIBRARY_DIRS}
|
${UUID_LIBRARY_DIRS}
|
||||||
${FFMPEG_LIBRARY_DIRS}
|
|
||||||
)
|
)
|
||||||
target_compile_options(sist2_scan
|
target_compile_options(sist2_scan
|
||||||
PRIVATE
|
PRIVATE
|
||||||
@@ -234,6 +241,11 @@ if (WITH_SIST2_SCAN)
|
|||||||
${PROJECT_SOURCE_DIR}/lib/liblz4.a
|
${PROJECT_SOURCE_DIR}/lib/liblz4.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/liblzma.a
|
${PROJECT_SOURCE_DIR}/lib/liblzma.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libzstd.a
|
${PROJECT_SOURCE_DIR}/lib/libzstd.a
|
||||||
|
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libxml2.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libmce.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libopc.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libplib.a
|
||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ FROM ubuntu:19.10
|
|||||||
MAINTAINER simon987 <me@simon987.net>
|
MAINTAINER simon987 <me@simon987.net>
|
||||||
|
|
||||||
RUN apt update
|
RUN apt update
|
||||||
RUN apt install -y libglib2.0-0 libcurl4 libmagic1 libharfbuzz-bin libopenjp2-7
|
RUN apt install -y libglib2.0-0 libcurl4 libmagic1 libharfbuzz-bin libopenjp2-7 libarchive13 liblzma5 libzstd1 liblz4-1
|
||||||
|
|
||||||
ADD sist2 /root/sist2
|
ADD sist2 /root/sist2
|
||||||
|
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -92,7 +92,7 @@ pdf,xps,cbz,fb2,epub | MuPDF | yes | yes, `png` | title |
|
|||||||
ttf,ttc,cff,woff,fnt,otf | Freetype2 | - | yes, `bmp` | Name & style |
|
ttf,ttc,cff,woff,fnt,otf | Freetype2 | - | yes, `bmp` | Name & style |
|
||||||
`text/plain` | *(none)* | yes | no | - |
|
`text/plain` | *(none)* | yes | no | - |
|
||||||
tar, zip, rar, 7z, ar ... | Libarchive | yes\* | - | no |
|
tar, zip, rar, 7z, ar ... | Libarchive | yes\* | - | no |
|
||||||
docx, xlsx, pptx | | yes | no | *planned* |
|
docx, xlsx, pptx | libOPC | yes | no | no |
|
||||||
|
|
||||||
\* *See [Archive files](#archive-files)*
|
\* *See [Archive files](#archive-files)*
|
||||||
|
|
||||||
@@ -121,15 +121,15 @@ binaries.
|
|||||||
|
|
||||||
*(Debian)*
|
*(Debian)*
|
||||||
```bash
|
```bash
|
||||||
apt install git cmake pkg-config libglib2.0-dev\
|
apt install git cmake pkg-config libglib2.0-dev \
|
||||||
libssl-dev uuid-dev libavformat-dev libswscale-dev \
|
libssl-dev uuid-dev python3 libmagic-dev libfreetype6-dev \
|
||||||
python3 libmagic-dev libfreetype6-dev libcurl-dev \
|
libcurl-dev libbz2-dev yasm libharfbuzz-dev ragel \
|
||||||
libbz2-dev yasm libharfbuzz-dev ragel
|
libarchive-dev
|
||||||
```
|
```
|
||||||
*(FreeBSD)*
|
*(FreeBSD)*
|
||||||
```bash
|
```bash
|
||||||
pkg install cmake gcc yasm gmake bash ffmpeg e2fsprogs-uuid\
|
pkg install cmake gcc yasm gmake bash ffmpeg e2fsprogs-uuid\
|
||||||
autotools ragel
|
autotools ragel libarchive
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build
|
2. Build
|
||||||
|
|||||||
2
cJSON
2
cJSON
Submodule cJSON updated: 533ff8a783...2d4ad84192
8
ci/build.sh
Normal file
8
ci/build.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
./scripts/get_static_libs.sh
|
||||||
|
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
strip sist2
|
||||||
|
strip sist2_scan
|
||||||
53
include/mce/config.h
Normal file
53
include/mce/config.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**@file config/mce/config.h
|
||||||
|
*/
|
||||||
|
#ifndef MCE_CONFIG_H
|
||||||
|
#define MCE_CONFIG_H
|
||||||
|
|
||||||
|
#include <libxml/xmlstring.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <plib/plib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MCE_NAMESPACE_SUBSUMPTION_ENABLED 0
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MCE_CONFIG_H */
|
||||||
189
include/mce/helper.h
Normal file
189
include/mce/helper.h
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file mce/helper.h
|
||||||
|
Helper functions needed by mce/textreader.h and mce/textwriter.h to implement MCE:
|
||||||
|
- mceQNameLevelAdd(), mceQNameLevelLookup() and mceQNameLevelCleanup() maintain a set of mceQNameLevel_t tuples.
|
||||||
|
- mceQNameLevelPush() and mceQNameLevelPopIfMatch() maintain a stack of mceQNameLevel_t tuples.
|
||||||
|
- mceCtxInit(), mceCtxCleanup() and mceCtxUnderstandsNamespace() manage a context which holds all information needed to do MCE proprocessing.
|
||||||
|
*/
|
||||||
|
#include <mce/config.h>
|
||||||
|
|
||||||
|
#ifndef MCE_HELPER_H
|
||||||
|
#define MCE_HELPER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Tiple (ns, ln, level).
|
||||||
|
*/
|
||||||
|
typedef struct MCE_QNAME_LEVEL {
|
||||||
|
xmlChar *ns;
|
||||||
|
xmlChar *ln;
|
||||||
|
puint32_t level;
|
||||||
|
puint32_t flag; // used by mceTextWriter
|
||||||
|
} mceQNameLevel_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
typedef enum MCE_SKIP_STATE_ENUM {
|
||||||
|
MCE_SKIP_STATE_IGNORE,
|
||||||
|
MCE_SKIP_STATE_ALTERNATE_CONTENT,
|
||||||
|
MCE_SKIP_STATE_CHOICE_MATCHED
|
||||||
|
} mceSkipState_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Represents an intervall of levels which are "skipped" i.e. ignored.
|
||||||
|
*/
|
||||||
|
typedef struct MCE_SKIP_ITEM {
|
||||||
|
puint32_t level_start;
|
||||||
|
puint32_t level_end;
|
||||||
|
mceSkipState_t state;
|
||||||
|
} mceSkipItem_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Either represents a set of (ns, ln, level) triples.
|
||||||
|
*/
|
||||||
|
typedef struct MCE_QNAME_LEVEL_SET {
|
||||||
|
mceQNameLevel_t *list_array;
|
||||||
|
puint32_t list_items;
|
||||||
|
puint32_t max_level;
|
||||||
|
} mceQNameLevelSet_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The skip stack.
|
||||||
|
*/
|
||||||
|
typedef struct MCE_SKIP_STACK {
|
||||||
|
mceSkipItem_t *stack_array;
|
||||||
|
puint32_t stack_items;
|
||||||
|
} mceSkipStack_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum MCE_ERROR_ENUM {
|
||||||
|
MCE_ERROR_NONE,
|
||||||
|
MCE_ERROR_XML,
|
||||||
|
MCE_ERROR_MUST_UNDERSTAND,
|
||||||
|
MCE_ERROR_VALIDATION,
|
||||||
|
MCE_ERROR_MEMORY
|
||||||
|
} mceError_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Holds all information to do MCE preprocessing.
|
||||||
|
*/
|
||||||
|
typedef struct MCE_CONTEXT {
|
||||||
|
mceQNameLevelSet_t ignorable_set;
|
||||||
|
mceQNameLevelSet_t understands_set;
|
||||||
|
mceQNameLevelSet_t processcontent_set;
|
||||||
|
mceQNameLevelSet_t suspended_set;
|
||||||
|
#if (MCE_NAMESPACE_SUBSUMPTION_ENABLED)
|
||||||
|
mceQNameLevelSet_t subsume_namespace_set;
|
||||||
|
mceQNameLevelSet_t subsume_exclude_set;
|
||||||
|
mceQNameLevelSet_t subsume_prefix_set;
|
||||||
|
#endif
|
||||||
|
mceSkipStack_t skip_stack;
|
||||||
|
mceError_t error;
|
||||||
|
pbool_t mce_disabled;
|
||||||
|
puint32_t suspended_level;
|
||||||
|
} mceCtx_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Add a new tiple (ns, ln, level) to the triple set \c qname_level_set.
|
||||||
|
The \c ns_sub string is optional and will not be touched.
|
||||||
|
*/
|
||||||
|
pbool_t mceQNameLevelAdd(mceQNameLevelSet_t *qname_level_set, const xmlChar *ns, const xmlChar *ln, puint32_t level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Lookup a tiple (ns, ln, level) via \c ns and \c ln. If \c ignore_ln is PTRUE then the first tiple matching \c ns will be returned.
|
||||||
|
*/
|
||||||
|
mceQNameLevel_t* mceQNameLevelLookup(mceQNameLevelSet_t *qname_level_set, const xmlChar *ns, const xmlChar *ln, pbool_t ignore_ln);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Remove all triples (ns, ln, level) where the level greater or equal to \c level.
|
||||||
|
*/
|
||||||
|
pbool_t mceQNameLevelCleanup(mceQNameLevelSet_t *qname_level_set, puint32_t level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Push a new skip intervall (level_start, level_end, state) on the stack \c skip_stack.
|
||||||
|
*/
|
||||||
|
pbool_t mceSkipStackPush(mceSkipStack_t *skip_stack, puint32_t level_start, puint32_t level_end, mceSkipState_t state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Pop the intervall (ns, ln, level) from the stack \c qname_level_array.
|
||||||
|
*/
|
||||||
|
void mceSkipStackPop(mceSkipStack_t *skip_stack);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns top item or NULL.
|
||||||
|
*/
|
||||||
|
mceSkipItem_t *mceSkipStackTop(mceSkipStack_t *skip_stack);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns TRUE, if the \c level is in the top skip intervall.
|
||||||
|
*/
|
||||||
|
pbool_t mceSkipStackSkip(mceSkipStack_t *skip_stack, puint32_t level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the mceCtx_t \c ctx.
|
||||||
|
*/
|
||||||
|
pbool_t mceCtxInit(mceCtx_t *ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cleanup, i.e. release all resourced from the mceCtx_t \c ctx.
|
||||||
|
*/
|
||||||
|
pbool_t mceCtxCleanup(mceCtx_t *ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Register the namespace \ns in \c ctx.
|
||||||
|
*/
|
||||||
|
pbool_t mceCtxUnderstandsNamespace(mceCtx_t *ctx, const xmlChar *ns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Register the namespace \ns in \c ctx.
|
||||||
|
*/
|
||||||
|
pbool_t mceCtxSuspendProcessing(mceCtx_t *ctx, const xmlChar *ns, const xmlChar *ln);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if (MCE_NAMESPACE_SUBSUMPTION_ENABLED)
|
||||||
|
/**
|
||||||
|
Subsume namespace \c ns_new with \c ns_old.
|
||||||
|
*/
|
||||||
|
pbool_t mceCtxSubsumeNamespace(mceCtx_t *ctx, const xmlChar *prefix_new, const xmlChar *ns_new, const xmlChar *ns_old);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MCE_HELPER_H */
|
||||||
464
include/mce/textreader.h
Normal file
464
include/mce/textreader.h
Normal file
@@ -0,0 +1,464 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file mce/textreader.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#ifndef MCE_TEXTREADER_H
|
||||||
|
#define MCE_TEXTREADER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
A handle to an MCE-aware libxml2 xmlTextReader.
|
||||||
|
*/
|
||||||
|
typedef struct MCE_TEXTREADER mceTextReader_t;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <mce/config.h>
|
||||||
|
#include <opc/opc.h>
|
||||||
|
#include <mce/helper.h>
|
||||||
|
#include <libxml/xmlwriter.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct MCE_TEXTREADER {
|
||||||
|
xmlTextReaderPtr reader;
|
||||||
|
mceCtx_t mceCtx;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Wrapper around an libxml2 xmlTextReaderRead function.
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderRead
|
||||||
|
*/
|
||||||
|
int mceTextReaderRead(mceTextReader_t *mceTextReader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Wrapper around a libxml2 xmlTextReaderNext function.
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderNext
|
||||||
|
*/
|
||||||
|
int mceTextReaderNext(mceTextReader_t *mceTextReader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates an mceTextReader from an XmlTextReader.
|
||||||
|
\code
|
||||||
|
mceTextReader reader;
|
||||||
|
mceTextReaderInit(&reader, xmlNewTextReaderFilename("sample.xml"));
|
||||||
|
// reader is ready to use.
|
||||||
|
mceTextReaderCleanup(&reader);
|
||||||
|
\endcode
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlreader.html#xmlNewTextReaderFilename
|
||||||
|
*/
|
||||||
|
int mceTextReaderInit(mceTextReader_t *mceTextReader, xmlTextReaderPtr reader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cleanup MCE reader, i.e. free all resources. Also calls xmlTextReaderClose and xmlFreeTextReader.
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderClose
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlreader.html#xmlFreeTextReader
|
||||||
|
*/
|
||||||
|
int mceTextReaderCleanup(mceTextReader_t *mceTextReader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Reads all events \c mceTextReader and pipes them to \writer.
|
||||||
|
\code
|
||||||
|
mceTextReader reader;
|
||||||
|
mceTextReaderInit(&reader, xmlNewTextReaderFilename("sample.xml"));
|
||||||
|
mceTextReaderUnderstandsNamespace(&reader, _X("http://myextension"));
|
||||||
|
xmlTextWriterPtr writer=xmlNewTextWriterFilename("out.xml", 0);
|
||||||
|
mceTextReaderDump(&reader, writer, P_FALSE);
|
||||||
|
xmlFreeTextWriter(writer);
|
||||||
|
mceTextReaderCleanup(&reader);
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
int mceTextReaderDump(mceTextReader_t *mceTextReader, xmlTextWriter *writer, pbool_t fragment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Registers an MCE namespace.
|
||||||
|
\see mceTextReaderDump()
|
||||||
|
*/
|
||||||
|
int mceTextReaderUnderstandsNamespace(mceTextReader_t *mceTextReader, const xmlChar *ns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Disable MCE processing.
|
||||||
|
\return Returns old value.
|
||||||
|
*/
|
||||||
|
pbool_t mceTextReaderDisableMCE(mceTextReader_t *mceTextReader, pbool_t flag);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Signal an error to the MCE processor.
|
||||||
|
*/
|
||||||
|
void mceRaiseError(xmlTextReader *reader, mceCtx_t *ctx, mceError_t error, const xmlChar *str, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Internal function which does the MCE postprocessing. E.g. mceTextReaderRead() is implemented as
|
||||||
|
\code
|
||||||
|
mceTextReaderPostprocess(mceTextReader->reader, &mceTextReader->mceCtx, xmlTextReaderRead(mceTextReader->reader))
|
||||||
|
\endcode
|
||||||
|
This function is exposed to make existing libxm2 xmlTextReader MCE aware.
|
||||||
|
*/
|
||||||
|
int mceTextReaderPostprocess(xmlTextReader *reader, mceCtx_t *ctx, int ret);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the error code.
|
||||||
|
*/
|
||||||
|
mceError_t mceTextReaderGetError(mceTextReader_t *mceTextReader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper macro to declare a start/end document block in a declarative way:
|
||||||
|
\code
|
||||||
|
mce_start_document(reader) {
|
||||||
|
} mce_end_document(reader);
|
||||||
|
\endcode
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_document(_reader_) \
|
||||||
|
if (NULL!=(_reader_)) { \
|
||||||
|
mceTextReaderRead(_reader_); \
|
||||||
|
if (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_document.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_document(_reader_) \
|
||||||
|
} /* if (NULL!=reader) */ \
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Container for mce_start_element and mce_start_attribute declarations.
|
||||||
|
\see mce_match_element
|
||||||
|
\see mce_match_attribute
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_choice(_reader_) \
|
||||||
|
if (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_choice
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_choice(_reader_)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Skips the attributes.
|
||||||
|
\see mce_match_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_skip_attributes(_reader_) \
|
||||||
|
mce_start_attributes(_reader_) { \
|
||||||
|
} mce_end_attributes(_reader_);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Skips the attributes.
|
||||||
|
\see mce_match_attribute.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_skip_children(_reader_) \
|
||||||
|
mce_start_children(_reader_) { \
|
||||||
|
} mce_end_children(_reader_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_children(_reader_) \
|
||||||
|
if (!xmlTextReaderIsEmptyElement((_reader_)->reader)) { \
|
||||||
|
mceTextReaderRead(_reader_); do { \
|
||||||
|
if (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_children(_reader_) \
|
||||||
|
else { \
|
||||||
|
if (XML_READER_TYPE_END_ELEMENT!=xmlTextReaderNodeType((_reader_)->reader)) { \
|
||||||
|
mceTextReaderNext(_reader_); /*skip unhandled element */ \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while(XML_READER_TYPE_END_ELEMENT!=xmlTextReaderNodeType((_reader_)->reader) && \
|
||||||
|
XML_READER_TYPE_NONE!=xmlTextReaderNodeType((_reader_)->reader)); \
|
||||||
|
} /* if (!xmlTextReaderIsEmptyElement(reader->reader)) */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper macro to match an element. Usefull for calling code in a seperate function:
|
||||||
|
|
||||||
|
\code
|
||||||
|
void handleElement(reader) {
|
||||||
|
mce_start_choice(reader) {
|
||||||
|
mce_start_element(reader, _X("ns"), _X("element")) {
|
||||||
|
|
||||||
|
} mce_end_element(reader)
|
||||||
|
} mce_end_choice(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse(reader) {
|
||||||
|
mce_start_document(reader) {
|
||||||
|
mce_start_element(reader, _X("ns"), _X("ln")) {
|
||||||
|
mce_skip_attributes(reader);
|
||||||
|
mce_start_children(reader) {
|
||||||
|
mce_match_element(reader, _X("ns"), _X("element")) {
|
||||||
|
handleElement(reader);
|
||||||
|
}
|
||||||
|
} mce_end_children(reader);
|
||||||
|
} mce_end_element();
|
||||||
|
} mce_end_document(reader);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_match_element(_reader_, ns, ln) \
|
||||||
|
} else if (XML_READER_TYPE_ELEMENT==xmlTextReaderNodeType((_reader_)->reader) \
|
||||||
|
&& (NULL==ns || 0==xmlStrcmp(ns, xmlTextReaderConstNamespaceUri((_reader_)->reader))) \
|
||||||
|
&& (NULL==ln || 0==xmlStrcmp(ln, xmlTextReaderConstLocalName((_reader_)->reader)))) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper macro to declare a element block in a declarative way:
|
||||||
|
\code
|
||||||
|
mce_start_element(reader) {
|
||||||
|
mce_start_attributes(reader) {
|
||||||
|
mce_start_attribute(reader, _X("ns"), _X("lnA")) {
|
||||||
|
// code for handling lnA.
|
||||||
|
} mce_end_attribute(reader);
|
||||||
|
mce_start_attribute(reader, _X("ns"), _X("lnB")) {
|
||||||
|
// code for handling lnB.
|
||||||
|
} mce_end_attribute(reader);
|
||||||
|
} mce_end_attributes(reader);
|
||||||
|
mce_start_children(reader) {
|
||||||
|
mce_start_element(reader, _X("ns"), _X("lnA")) {
|
||||||
|
// code for handling lnA.
|
||||||
|
} mce_end_element(reader);
|
||||||
|
mce_start_element(reader, _X("ns"), _X("lnB")) {
|
||||||
|
// code for handling lnB.
|
||||||
|
} mce_end_element(reader);
|
||||||
|
mce_start_text(reader) {
|
||||||
|
// code for handling text.
|
||||||
|
} mce_end_text(reader);
|
||||||
|
} mce_end_children(reader);
|
||||||
|
} mce_end_element(reader);
|
||||||
|
\endcode
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_element(_reader_, ns, ln) \
|
||||||
|
mce_match_element(_reader_, ns, ln)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_element(_reader_) \
|
||||||
|
mceTextReaderNext(_reader_)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Matches #TEXT without consuming it.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_match_text(_reader_) \
|
||||||
|
} else if (XML_READER_TYPE_TEXT==xmlTextReaderNodeType((_reader_)->reader) \
|
||||||
|
|| XML_READER_TYPE_SIGNIFICANT_WHITESPACE==xmlTextReaderNodeType((_reader_)->reader)) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_text(_reader_) \
|
||||||
|
mce_match_text(_reader_)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_text(_reader_) \
|
||||||
|
mceTextReaderNext(_reader_)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_attributes(_reader_) \
|
||||||
|
if (1==xmlTextReaderMoveToFirstAttribute((_reader_)->reader)) { \
|
||||||
|
do { \
|
||||||
|
if (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_attributes(_reader_) \
|
||||||
|
else { /* skipped attribute */ } \
|
||||||
|
} while(1==xmlTextReaderMoveToNextAttribute((_reader_)->reader)); \
|
||||||
|
xmlTextReaderMoveToElement((_reader_)->reader); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper macro to match an attribute. Usefull for calling code in a seperate function:
|
||||||
|
|
||||||
|
\code
|
||||||
|
void handleA(reader) {
|
||||||
|
mce_start_choice(reader) {
|
||||||
|
mce_start_attribute(reader, _X("ns"), _X("attr")) {
|
||||||
|
|
||||||
|
} mce_end_attribute(reader);
|
||||||
|
} mce_end_choice(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse(reader) {
|
||||||
|
mce_start_document(reader) {
|
||||||
|
mce_start_element(reader, _X("ns"), _X("ln")) {
|
||||||
|
mce_start_attributes(reader) {
|
||||||
|
mce_match_attribute(reader, _X("ns"), _X("attr")) {
|
||||||
|
handleA(reader);
|
||||||
|
}
|
||||||
|
} mce_end_attributes(reader);
|
||||||
|
mce_skip_children(reader);
|
||||||
|
} mce_end_element();
|
||||||
|
} mce_end_document(reader);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_match_attribute(_reader_, ns, ln) \
|
||||||
|
} else if ((NULL==ns || 0==xmlStrcmp(ns, xmlTextReaderConstNamespaceUri((_reader_)->reader))) \
|
||||||
|
&& (NULL==ln || 0==xmlStrcmp(ln, xmlTextReaderConstLocalName((_reader_)->reader)))) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_start_attribute(_reader_, ns, ln) \
|
||||||
|
mce_match_attribute(_reader_, ns, ln)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_start_element.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_end_attribute(_reader_)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Error handling for MCE parsers.
|
||||||
|
\code
|
||||||
|
mce_start_element(&reader, NULL, _X("Default")) {
|
||||||
|
const xmlChar *ext=NULL;
|
||||||
|
const xmlChar *type=NULL;
|
||||||
|
mce_start_attributes(&reader) {
|
||||||
|
mce_start_attribute(&reader, NULL, _X("Extension")) {
|
||||||
|
ext=xmlTextReaderConstValue(reader.reader);
|
||||||
|
} mce_end_attribute(&reader);
|
||||||
|
mce_start_attribute(&reader, NULL, _X("ContentType")) {
|
||||||
|
type=xmlTextReaderConstValue(reader.reader);
|
||||||
|
} mce_end_attribute(&reader);
|
||||||
|
} mce_end_attributes(&reader);
|
||||||
|
mce_error_guard_start(&reader) {
|
||||||
|
mce_error(&reader, NULL==ext || ext[0]==0, MCE_ERROR_VALIDATION, "Missing @Extension attribute!");
|
||||||
|
mce_error(&reader, NULL==type || type[0]==0, MCE_ERROR_VALIDATION, "Missing @ContentType attribute!");
|
||||||
|
opcContainerType *ct=insertType(c, type, OPC_TRUE);
|
||||||
|
mce_error(&reader, NULL==ct, MCE_ERROR_MEMORY, NULL);
|
||||||
|
opcContainerExtension *ce=opcContainerInsertExtension(c, ext, OPC_TRUE);
|
||||||
|
mce_error(&reader, NULL==ce, MCE_ERROR_MEMORY, NULL);
|
||||||
|
mce_errorf(&reader, NULL!=ce->type && 0!=xmlStrcmp(ce->type, type), MCE_ERROR_VALIDATION, "Extension \"%s\" is mapped to type \"%s\" as well as \"%s\"", ext, type, ce->type);
|
||||||
|
ce->type=ct->type;
|
||||||
|
} mce_error_guard_end(&reader);
|
||||||
|
mce_skip_children(&reader);
|
||||||
|
} mce_end_element(&reader);
|
||||||
|
\endcode
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_error_guard_start(_reader_) if (MCE_ERROR_NONE==(_reader_)->mceCtx.error) do {
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_error_guard_start
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_error_guard_end(_reader_) } while(0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Signal an error if guard if false.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_error(_reader_, guard, err, msg) if (guard) { (_reader_)->mceCtx.error=(err); fprintf(stderr, (NULL!=msg?msg:#err)); continue; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Signal an error if guard if false.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define mce_errorf(_reader_, guard, err, msg, ...) if (guard) { mceRaiseError((_reader_)->reader, &(_reader_)->mceCtx, err, _X((NULL!=msg?msg:#err)), ##__VA_ARGS__ ); continue; }
|
||||||
|
#else
|
||||||
|
#define mce_errorf(_reader_, guard, err, msg, ...) if (guard) { mceRaiseError((_reader_)->reader, &(_reader_)->mceCtx, err, _X((NULL!=msg?msg:#err)), __VA_ARGS__ ); continue; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Only issues the error when in "strict mode".
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_error_strict mce_error
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see mce_error_strict
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_error_strictf mce_errorf
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Marker for a MCE defintion.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_def
|
||||||
|
|
||||||
|
/**
|
||||||
|
Marker for a MCE reference.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define mce_ref(r) (r)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MCE_TEXTREADER_H */
|
||||||
176
include/mce/textwriter.h
Normal file
176
include/mce/textwriter.h
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file mce/textwriter.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <mce/config.h>
|
||||||
|
#include <libxml/xmlwriter.h>
|
||||||
|
#include <mce/helper.h>
|
||||||
|
|
||||||
|
#ifndef MCE_TEXTWRITER_H
|
||||||
|
#define MCE_TEXTWRITER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Default flags for an MCE namespace declaration.
|
||||||
|
*/
|
||||||
|
#define MCE_DEFAULT 0x0
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flags MCE namespace declaration "ignorable".
|
||||||
|
*/
|
||||||
|
#define MCE_IGNORABLE 0x1
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flags MCE namespace declaration "must understand".
|
||||||
|
*/
|
||||||
|
#define MCE_MUSTUNDERSTAND 0x2
|
||||||
|
|
||||||
|
/**
|
||||||
|
The MCE text writer context.
|
||||||
|
*/
|
||||||
|
typedef struct MCE_TEXTWRITER_STRUCT mceTextWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a new MCE text writer.
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlIO.html#xmlOutputBufferCreateIO
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlNewTextWriter
|
||||||
|
*/
|
||||||
|
mceTextWriter *mceTextWriterCreateIO(xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void *ioctx, xmlCharEncodingHandlerPtr encoder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper which create a new MCE text writer for a FILE handle.
|
||||||
|
*/
|
||||||
|
mceTextWriter *mceNewTextWriterFile(FILE *file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Free all resources for \w.
|
||||||
|
*/
|
||||||
|
int mceTextWriterFree(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterStartDocument
|
||||||
|
*/
|
||||||
|
int mceTextWriterStartDocument(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterEndDocument
|
||||||
|
*/
|
||||||
|
int mceTextWriterEndDocument(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Start a new XML element. If ns==NULL then there is no namespace and ""==ns means the default namespace.
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterStartElement
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterStartElementNS
|
||||||
|
*/
|
||||||
|
int mceTextWriterStartElement(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterEndElement
|
||||||
|
*/
|
||||||
|
int mceTextWriterEndElement(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterWriteString
|
||||||
|
*/
|
||||||
|
int mceTextWriterWriteString(mceTextWriter *w, const xmlChar *content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Register a namespace. Must be called before mceTextWriterStartElement.
|
||||||
|
\see MCE_DEFAULT
|
||||||
|
\see MCE_IGNORABLE
|
||||||
|
\see MCE_MUSTUNDERSTAND
|
||||||
|
*/
|
||||||
|
const xmlChar *mceTextWriterRegisterNamespace(mceTextWriter *w, const xmlChar *ns, const xmlChar *prefix, int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Register qname (ns, ln) as a "process content" element wrt. MCE. Must be called before mceTextWriterStartElement.
|
||||||
|
*/
|
||||||
|
int mceTextWriterProcessContent(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Writes a formatted attribute.
|
||||||
|
\see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterWriteFormatAttribute
|
||||||
|
*/
|
||||||
|
int mceTextWriterAttributeF(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln, const char *value, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Starts an MCE alternate content section.
|
||||||
|
*/
|
||||||
|
int mceTextWriterStartAlternateContent(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ends an MCE alternate content section.
|
||||||
|
*/
|
||||||
|
int mceTextWriterEndAlternateContent(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Start an MCE choice.
|
||||||
|
*/
|
||||||
|
int mceTextWriterStartChoice(mceTextWriter *w, const xmlChar *ns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ends an MCE choice.
|
||||||
|
*/
|
||||||
|
int mceTextWriterEndChoice(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Start an MCE fallback.
|
||||||
|
*/
|
||||||
|
int mceTextWriterStartFallback(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ends an MCE fallback.
|
||||||
|
*/
|
||||||
|
int mceTextWriterEndFallback(mceTextWriter *w);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the underlying xmlTextWriter.
|
||||||
|
*/
|
||||||
|
xmlTextWriterPtr mceTextWriterIntern(mceTextWriter *w);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper which create a new xmlTextWriterPtr for a FILE handle.
|
||||||
|
*/
|
||||||
|
xmlTextWriterPtr xmlNewTextWriterFile(FILE *file);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MCE_TEXTWRITER_H */
|
||||||
189
include/opc/config.h
Normal file
189
include/opc/config.h
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**@file config/opc/config.h
|
||||||
|
*/
|
||||||
|
#ifndef OPC_CONFIG_H
|
||||||
|
#define OPC_CONFIG_H
|
||||||
|
|
||||||
|
#include <libxml/xmlstring.h>
|
||||||
|
#include <plib/plib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Assert expression e is true. Will be removed entirely in release mode.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_ASSERT(e) assert(e)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Assert expression e is true. Expression will be executed in release mode too.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define OPC_ENSURE(e) (void)(e)
|
||||||
|
#else
|
||||||
|
#define OPC_ENSURE(e) assert(e)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constant for boolean true.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_TRUE (0==0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constant for boolean false.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_FALSE (0==1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Boolean type.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef pbool_t opc_bool_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Type which represents an offset in e.g. a file.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef pofs_t opc_ofs_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
8-bit unsigned integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef puint8_t opc_uint8_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
16-bit unsigned integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef puint16_t opc_uint16_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
32-bit unsigned integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef puint32_t opc_uint32_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
64-bit unsigned integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef puint64_t opc_uint64_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
8-bit signed integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef pint8_t opc_int8_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
16-bit signed integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef pint16_t opc_int16_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
32-bit signed integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef pint32_t opc_int32_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
64-bit signed integer.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
typedef pint64_t opc_int64_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Default size fo the deflate buffer used by zlib.
|
||||||
|
*/
|
||||||
|
#define OPC_DEFLATE_BUFFER_SIZE 4096
|
||||||
|
|
||||||
|
/**
|
||||||
|
Max system path len.
|
||||||
|
*/
|
||||||
|
#define OPC_MAX_PATH 512
|
||||||
|
|
||||||
|
/**
|
||||||
|
Error codes for the OPC module.
|
||||||
|
*/
|
||||||
|
typedef enum OPC_ERROR_ENUM {
|
||||||
|
OPC_ERROR_NONE,
|
||||||
|
OPC_ERROR_STREAM,
|
||||||
|
OPC_ERROR_SEEK, // can't seek
|
||||||
|
OPC_ERROR_UNSUPPORTED_DATA_DESCRIPTOR,
|
||||||
|
OPC_ERROR_UNSUPPORTED_COMPRESSION,
|
||||||
|
OPC_ERROR_DEFLATE,
|
||||||
|
OPC_ERROR_HEADER,
|
||||||
|
OPC_ERROR_MEMORY,
|
||||||
|
OPC_ERROR_XML,
|
||||||
|
OPC_ERROR_USER // user triggered an abort
|
||||||
|
} opc_error_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Compression options for OPC streams.
|
||||||
|
*/
|
||||||
|
typedef enum OPC_COMPRESSIONOPTION_ENUM {
|
||||||
|
OPC_COMPRESSIONOPTION_NONE,
|
||||||
|
OPC_COMPRESSIONOPTION_NORMAL,
|
||||||
|
OPC_COMPRESSIONOPTION_MAXIMUM,
|
||||||
|
OPC_COMPRESSIONOPTION_FAST,
|
||||||
|
OPC_COMPRESSIONOPTION_SUPERFAST
|
||||||
|
} opcCompressionOption_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Helper for debug logs.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define opc_logf printf
|
||||||
|
|
||||||
|
/**
|
||||||
|
Abstraction for memset(m, 0, s).
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define opc_bzero_mem(m,s) memset(m, 0, s)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_CONFIG_H */
|
||||||
300
include/opc/container.h
Normal file
300
include/opc/container.h
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/container.h
|
||||||
|
|
||||||
|
The container.h module has the fundamental methods for dealing with ZIP-based OPC container.
|
||||||
|
|
||||||
|
OPC container can be opened in READ-ONLY mode, WRITE-ONLY mode, READ/WRITE mode, TEMPLATE mode and TRANSITION mode.
|
||||||
|
The most notable mode is the READ/WRITE mode, which gives you concurrent stream-based READ and WRITE access to a
|
||||||
|
single ZIP-based OPC container. This is achieved without the use of temporary files by taking advantage of the
|
||||||
|
OPC specific “interleave” mode. \see http://standards.iso.org/ittf/PubliclyAvailableStandards/c051459_ISOIEC_29500-2_2008(E).zip
|
||||||
|
|
||||||
|
The TEMPLATE mode allows very fast customized "cloning" of ZIP-based OPC container by using "RAW access" to the ZIP streams.
|
||||||
|
The TRANSITION mode is a special version of the TEMPLATE mode, which allows transition-based READ/WRITE access to the
|
||||||
|
ZIP-based OPC container using a temporary file.
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
#include <opc/file.h>
|
||||||
|
|
||||||
|
#ifndef OPC_CONTAINER_H
|
||||||
|
#define OPC_CONTAINER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
Handle to an OPC container created by \ref opcContainerOpen.
|
||||||
|
\see opcContainerOpen.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_CONTAINER_STRUCT opcContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modes for opcContainerOpen();
|
||||||
|
\see opcContainerOpen
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
/**
|
||||||
|
Opens the OPC container denoted by \a fileName in READ-ONLY mode. The \a destName parameter must be \a NULL.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_OPEN_READ_ONLY=0,
|
||||||
|
/**
|
||||||
|
Opens the OPC container denoted by \a fileName in WRITE-ONLY mode. The \a destName parameter must be \a NULL.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_OPEN_WRITE_ONLY=1,
|
||||||
|
/**
|
||||||
|
Opens the OPC container denoted by \a fileName in READ/WRITE mode. The \a destName parameter must be \a NULL.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_OPEN_READ_WRITE=2,
|
||||||
|
/**
|
||||||
|
This mode will open the container denoted by \a fileName in READ-ONLY mode and the container denoted by
|
||||||
|
\a destName in write-only mode. Any modifications will be written to the container denoted by \a destName
|
||||||
|
and the unmodified streams from \a fileName will be written to \a destName on closing.
|
||||||
|
\warning Currently not implemented.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_OPEN_TEMPLATE=3,
|
||||||
|
/**
|
||||||
|
Like the OPC_OPEN_TEMPLATE mode, but the \a destName will be renamed to the \a fileName on closing. If \a destName
|
||||||
|
is \a NULL, then the name of the temporary file will be generated automatically.
|
||||||
|
\warning Currently not implemented.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_OPEN_TRANSITION=4
|
||||||
|
} opcContainerOpenMode;
|
||||||
|
|
||||||
|
/** Modes for opcContainerClose.
|
||||||
|
\see opcContainerClose.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
/**
|
||||||
|
Close the OPC container without any further postprocessing.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_CLOSE_NOW = 0,
|
||||||
|
/**
|
||||||
|
Close the OPC container and trim the file by removing unused fragments like e.g.
|
||||||
|
deleted parts.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_CLOSE_TRIM = 1,
|
||||||
|
/**
|
||||||
|
Close the OPC container like in \a OPC_CLOSE_TRIM mode, but additionally remove any
|
||||||
|
"interleaved" parts by reordering them.
|
||||||
|
\warning Currently not implemented. Same semantic as OPC_CLOSE_TRIM.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
OPC_CLOSE_DEFRAG = 2
|
||||||
|
} opcContainerCloseMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Opens a ZIP-based OPC container.
|
||||||
|
@param[in] fileName. For more details see \ref opcContainerOpenMode.
|
||||||
|
@param[in] mode. For more details see \ref opcContainerOpenMode.
|
||||||
|
@param[in] userContext. Will not be modified by libopc. Can be used to e.g. store the "this" pointer for C++ bindings.
|
||||||
|
@param[in] destName. For more details see \ref opcContainerOpenMode.
|
||||||
|
@return \a NULL if failed.
|
||||||
|
\see opcContainerOpenMode
|
||||||
|
\see opcContainerDump
|
||||||
|
*/
|
||||||
|
opcContainer* opcContainerOpen(const xmlChar *fileName,
|
||||||
|
opcContainerOpenMode mode,
|
||||||
|
void *userContext,
|
||||||
|
const xmlChar *destName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Opens a ZIP-based OPC container from memory.
|
||||||
|
@param[in] data.
|
||||||
|
@param[in] data_len.
|
||||||
|
@param[in] userContext. Will not be modified by libopc. Can be used to e.g. store the "this" pointer for C++ bindings.
|
||||||
|
@param[in] mode. For more details see \ref opcContainerOpenMode.
|
||||||
|
@return \a NULL if failed.
|
||||||
|
*/
|
||||||
|
opcContainer* opcContainerOpenMem(const opc_uint8_t *data, opc_uint32_t data_len,
|
||||||
|
opcContainerOpenMode mode,
|
||||||
|
void *userContext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Opens a ZIP-based OPC container from memory.
|
||||||
|
@param[in] ioread.
|
||||||
|
@param[in] iowrite.
|
||||||
|
@param[in] ioclose.
|
||||||
|
@param[in] ioseek.
|
||||||
|
@param[in] iotrim.
|
||||||
|
@param[in] ioflush.
|
||||||
|
@param[in] iocontext.
|
||||||
|
@param[in] file_size.
|
||||||
|
@param[in] userContext. Will not be modified by libopc. Can be used to e.g. store the "this" pointer for C++ bindings.
|
||||||
|
@param[in] mode. For more details see \ref opcContainerOpenMode.
|
||||||
|
@return \a NULL if failed.
|
||||||
|
*/
|
||||||
|
opcContainer* opcContainerOpenIO(opcFileReadCallback *ioread,
|
||||||
|
opcFileWriteCallback *iowrite,
|
||||||
|
opcFileCloseCallback *ioclose,
|
||||||
|
opcFileSeekCallback *ioseek,
|
||||||
|
opcFileTrimCallback *iotrim,
|
||||||
|
opcFileFlushCallback *ioflush,
|
||||||
|
void *iocontext,
|
||||||
|
pofs_t file_size,
|
||||||
|
opcContainerOpenMode mode,
|
||||||
|
void *userContext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Close an OPC container.
|
||||||
|
@param[in] c. \ref opcContainer openered by \ref opcContainerOpen.
|
||||||
|
@param[in] mode. For more information see \ref opcContainerCloseMode.
|
||||||
|
@return Non-zero if successful.
|
||||||
|
\see opcContainerOpen
|
||||||
|
\see opcContainerCloseMode
|
||||||
|
*/
|
||||||
|
opc_error_t opcContainerClose(opcContainer *c, opcContainerCloseMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the unmodified user context passed to \ref opcContainerOpen.
|
||||||
|
\see opcContainerOpen
|
||||||
|
*/
|
||||||
|
void *opcContainerGetUserContext(opcContainer *c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
List all types, relations and parts of the container \a c to \a out.
|
||||||
|
\par Sample:
|
||||||
|
\include opc_dump.c
|
||||||
|
*/
|
||||||
|
opc_error_t opcContainerDump(opcContainer *c, FILE *out);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Exports the OPC container to "Flat OPC" (http://blogs.msdn.com/b/ericwhite/archive/2008/09/29/the-flat-opc-format.aspx).
|
||||||
|
The flat versions of an OPC file are very important when dealing with e.g XSL(T)-based or Javascript-based transformations.
|
||||||
|
\see opcContainerFlatImport.
|
||||||
|
\todo Implementation needed.
|
||||||
|
*/
|
||||||
|
int opcContainerFlatExport(opcContainer *c, const xmlChar *fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Imports the flat version of an OPC container.
|
||||||
|
\see opcContainerFlatExport.
|
||||||
|
\todo Implementation needed.
|
||||||
|
*/
|
||||||
|
int opcContainerFlatImport(opcContainer *c, const xmlChar *fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Iterate all types.
|
||||||
|
\code
|
||||||
|
for(xmlChar *type=opcContentTypeFirst(c);
|
||||||
|
NULL!=type;
|
||||||
|
type=opcContentTypeNext(c, type)) {
|
||||||
|
printf("%s\n", type);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
const xmlChar *opcContentTypeFirst(opcContainer *container);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcContentTypeNext()
|
||||||
|
*/
|
||||||
|
const xmlChar *opcContentTypeNext(opcContainer *container, const xmlChar *type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Iterate extensions.
|
||||||
|
\code
|
||||||
|
for(const xmlChar *ext=opcExtensionFirst(c);
|
||||||
|
NULL!=ext;
|
||||||
|
ext=opcExtensionNext(ext)) {
|
||||||
|
printf("%s\n", ext);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
const xmlChar *opcExtensionFirst(opcContainer *container);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcExtensionFirst()
|
||||||
|
*/
|
||||||
|
const xmlChar *opcExtensionNext(opcContainer *container, const xmlChar *ext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get registered type for extension.
|
||||||
|
\see opcExtensionRegister()
|
||||||
|
*/
|
||||||
|
const xmlChar *opcExtensionGetType(opcContainer *container, const xmlChar *ext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Register a mime-type and and extension.
|
||||||
|
\see opcExtensionGetType()
|
||||||
|
*/
|
||||||
|
const xmlChar *opcExtensionRegister(opcContainer *container, const xmlChar *ext, const xmlChar *type);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Iterator through all relation types of the container:
|
||||||
|
\code
|
||||||
|
for(xmlChar *type=opcRelationTypeFirst(c);
|
||||||
|
NULL!=type;
|
||||||
|
type=opcRelationTypeNext(c, type)) {
|
||||||
|
printf("%s\n", type);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
const xmlChar *opcRelationTypeFirst(opcContainer *container);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcRelationTypeFirst()
|
||||||
|
*/
|
||||||
|
const xmlChar *opcRelationTypeNext(opcContainer *container, const xmlChar *type);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Iterator through all relation types of the container:
|
||||||
|
\code
|
||||||
|
for(xmlChar *target=opcExternalTargetFirst(c);
|
||||||
|
NULL!=target;
|
||||||
|
type=opcExternalTargetNext(c, target)) {
|
||||||
|
printf("%s\n", target);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
const xmlChar *opcExternalTargetFirst(opcContainer *container);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcExternalTargetFirst()
|
||||||
|
*/
|
||||||
|
const xmlChar *opcExternalTargetNext(opcContainer *container, const xmlChar *target);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_CONTAINER_H */
|
||||||
200
include/opc/file.h
Normal file
200
include/opc/file.h
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/file.h
|
||||||
|
The opc module contains the file library functions.
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
|
||||||
|
#ifndef OPC_FILE_H
|
||||||
|
#define OPC_FILE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag for READ access.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_FILE_READ (1<<0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag for WRITE access.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_FILE_WRITE (1<<1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag indicates that file will be truncated when opened.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_FILE_TRUNC (1<<2)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Abstraction for see modes.
|
||||||
|
*/
|
||||||
|
typedef enum OPC_FILESEEKMODE_ENUM {
|
||||||
|
opcFileSeekSet = SEEK_SET,
|
||||||
|
opcFileSeekCur = SEEK_CUR,
|
||||||
|
opcFileSeekEnd = SEEK_END
|
||||||
|
} opcFileSeekMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback to read a file. E.g. for a FILE * context this can be implemented as
|
||||||
|
\code
|
||||||
|
static int opcFileRead(void *iocontext, char *buffer, int len) {
|
||||||
|
return fread(buffer, sizeof(char), len, (FILE*)iocontext);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
typedef int opcFileReadCallback(void *iocontext, char *buffer, int len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback to write a file. E.g. for a FILE * context this can be implemented as
|
||||||
|
\code
|
||||||
|
static int opcFileWrite(void *iocontext, const char *buffer, int len) {
|
||||||
|
return fwrite(buffer, sizeof(char), len, (FILE*)iocontext);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
typedef int opcFileWriteCallback(void *iocontext, const char *buffer, int len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback to close a file. E.g. for a FILE * context this can be implemented as
|
||||||
|
\code
|
||||||
|
static int opcFileClose(void *iocontext) {
|
||||||
|
return fclose((FILE*)iocontext);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
typedef int opcFileCloseCallback(void *iocontext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback to seek a file. E.g. for a FILE * context this can be implemented as
|
||||||
|
\code
|
||||||
|
static opc_ofs_t opcFileSeek(void *iocontext, opc_ofs_t ofs) {
|
||||||
|
int ret=fseek((FILE*)iocontext, ofs, SEEK_SET);
|
||||||
|
if (ret>=0) {
|
||||||
|
return ftell((FILE*)iocontext);
|
||||||
|
} else {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
typedef opc_ofs_t opcFileSeekCallback(void *iocontext, opc_ofs_t ofs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback to trim a file. E.g. for a FILE * context this can be implemented as
|
||||||
|
\code
|
||||||
|
static int opcFileTrim(void *iocontext, opc_ofs_t new_size) {
|
||||||
|
#ifdef WIN32
|
||||||
|
return _chsize(fileno((FILE*)iocontext), new_size);
|
||||||
|
#else
|
||||||
|
return ftruncate(fileno((FILE*)iocontext), new_size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
typedef int opcFileTrimCallback(void *iocontext, opc_ofs_t new_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback to flush a file. E.g. for a FILE * context this can be implemented as
|
||||||
|
\code
|
||||||
|
static int opcFileFlush(void *iocontext) {
|
||||||
|
return fflush((FILE*)iocontext);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
typedef int opcFileFlushCallback(void *iocontext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Represents a state of a file, i.e. file position (buf_pos) and error status (err).
|
||||||
|
*/
|
||||||
|
typedef struct OPC_FILERAWSTATE_STRUCT {
|
||||||
|
opc_error_t err;
|
||||||
|
opc_ofs_t buf_pos; // current pos in file
|
||||||
|
} opcFileRawState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
File IO context.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_IO_STRUCT {
|
||||||
|
opcFileReadCallback *_ioread;
|
||||||
|
opcFileWriteCallback *_iowrite;
|
||||||
|
opcFileCloseCallback *_ioclose;
|
||||||
|
opcFileSeekCallback *_ioseek;
|
||||||
|
opcFileTrimCallback *_iotrim;
|
||||||
|
opcFileFlushCallback *_ioflush;
|
||||||
|
void *iocontext;
|
||||||
|
int flags;
|
||||||
|
opcFileRawState state;
|
||||||
|
opc_ofs_t file_size;
|
||||||
|
} opcIO_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize an IO context.
|
||||||
|
*/
|
||||||
|
opc_error_t opcFileInitIO(opcIO_t *io,
|
||||||
|
opcFileReadCallback *ioread,
|
||||||
|
opcFileWriteCallback *iowrite,
|
||||||
|
opcFileCloseCallback *ioclose,
|
||||||
|
opcFileSeekCallback *ioseek,
|
||||||
|
opcFileTrimCallback *iotrim,
|
||||||
|
opcFileFlushCallback *ioflush,
|
||||||
|
void *iocontext,
|
||||||
|
pofs_t file_size,
|
||||||
|
int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize an IO context for a file.
|
||||||
|
*/
|
||||||
|
opc_error_t opcFileInitIOFile(opcIO_t *io, const xmlChar *filename, int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize an IO for memory.
|
||||||
|
\warning Currently supports READ-ONLY file access.
|
||||||
|
*/
|
||||||
|
opc_error_t opcFileInitIOMemory(opcIO_t *io, const opc_uint8_t *data, opc_uint32_t data_len, int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cleanup an IO context, i.e. release all system resources.
|
||||||
|
*/
|
||||||
|
opc_error_t opcFileCleanupIO(opcIO_t *io);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_FILE_H */
|
||||||
60
include/opc/helper.h
Normal file
60
include/opc/helper.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/helper.h
|
||||||
|
Contains helper functions for the opc module.
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
|
||||||
|
#ifndef OPC_HELPER_H
|
||||||
|
#define OPC_HELPER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructs a segment name.
|
||||||
|
*/
|
||||||
|
opc_uint16_t opcHelperAssembleSegmentName(char *out, opc_uint16_t out_size, const xmlChar *name, opc_uint32_t segment_number, opc_uint32_t next_segment_id, opc_bool_t rels_segment, opc_uint16_t *out_max);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Splits a filename into the segment informations.
|
||||||
|
*/
|
||||||
|
opc_error_t opcHelperSplitFilename(opc_uint8_t *filename, opc_uint32_t filename_length, opc_uint32_t *segment_number, opc_bool_t *last_segment, opc_bool_t *rel_segment);
|
||||||
|
|
||||||
|
#endif /* OPC_HELPER_H */
|
||||||
74
include/opc/inputstream.h
Normal file
74
include/opc/inputstream.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/inputstream.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
|
||||||
|
#ifndef OPC_INPUTSTREAM_H
|
||||||
|
#define OPC_INPUTSTREAM_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
Internal type which represents a binary input stream.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_CONTAINER_INPUTSTREAM_STRUCT opcContainerInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Opens the part \c name of the \c container for reading.
|
||||||
|
*/
|
||||||
|
opcContainerInputStream* opcContainerOpenInputStream(opcContainer *container, const xmlChar *name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Reads maximal \c buffer_len bytes from the input \c stream to \c buffer.
|
||||||
|
\return The number of byes read or "0" in case of an error or end-of-stream.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcContainerReadInputStream(opcContainerInputStream* stream, opc_uint8_t *buffer, opc_uint32_t buffer_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Closes the input stream and releases all system resources.
|
||||||
|
*/
|
||||||
|
opc_error_t opcContainerCloseInputStream(opcContainerInputStream* stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the type of compression used for the stream.
|
||||||
|
*/
|
||||||
|
opcCompressionOption_t opcContainerGetInputStreamCompressionOption(opcContainerInputStream* stream);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_INPUTSTREAM_H */
|
||||||
73
include/opc/opc.h
Normal file
73
include/opc/opc.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/opc.h
|
||||||
|
The opc module contains the basic library functions.
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
#include <opc/container.h>
|
||||||
|
#include <opc/part.h>
|
||||||
|
#include <opc/relation.h>
|
||||||
|
#include <opc/inputstream.h>
|
||||||
|
#include <opc/outputstream.h>
|
||||||
|
#include <opc/zip.h>
|
||||||
|
#include <opc/xmlreader.h>
|
||||||
|
#include <opc/xmlwriter.h>
|
||||||
|
#include <opc/properties.h>
|
||||||
|
|
||||||
|
#ifndef OPC_OPC_H
|
||||||
|
#define OPC_OPC_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize libopc.
|
||||||
|
* Sample:
|
||||||
|
* \include opc_helloworld.c
|
||||||
|
* @return Non-zero if successful.
|
||||||
|
*/
|
||||||
|
opc_error_t opcInitLibrary();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free libopc. Clean up all resources.
|
||||||
|
* @return Non-zero if successful.
|
||||||
|
* \see opcInitLibrary.
|
||||||
|
*/
|
||||||
|
opc_error_t opcFreeLibrary();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_OPC_H */
|
||||||
71
include/opc/outputstream.h
Normal file
71
include/opc/outputstream.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/outputstream.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
|
||||||
|
#ifndef OPC_OUTPUTSTREAM_H
|
||||||
|
#define OPC_OUTPUTSTREAM_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
Internal type which represents a binary output stream.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_CONTAINER_OUTPUTSTREAM_STRUCT opcContainerOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Open the part \c name or writing in \c container with compression \c compression_option.
|
||||||
|
\note Make sure the part exists!
|
||||||
|
\see opcPartCreate.
|
||||||
|
*/
|
||||||
|
opcContainerOutputStream* opcContainerCreateOutputStream(opcContainer *container, const xmlChar *name, opcCompressionOption_t compression_option);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write \c buffer_len bytes from \c buffer to \c stream.
|
||||||
|
\return Returns the number of bytes written.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcContainerWriteOutputStream(opcContainerOutputStream* stream, const opc_uint8_t *buffer, opc_uint32_t buffer_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Close the \c stream and free all associated resources.
|
||||||
|
*/
|
||||||
|
opc_error_t opcContainerCloseOutputStream(opcContainerOutputStream* stream);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_OUTPUTSTREAM_H */
|
||||||
118
include/opc/part.h
Normal file
118
include/opc/part.h
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/part.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
|
||||||
|
#ifndef OPC_PART_H
|
||||||
|
#define OPC_PART_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
Handle to an OPC part created by \ref opcPartOpen.
|
||||||
|
\see opcPartOpen.
|
||||||
|
*/
|
||||||
|
typedef xmlChar* opcPart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Represents an invalid (resp. NULL) part.
|
||||||
|
In releations OPC_PART_INVALID also represents the root part.
|
||||||
|
\hideinitializer
|
||||||
|
*/
|
||||||
|
#define OPC_PART_INVALID NULL
|
||||||
|
|
||||||
|
/**
|
||||||
|
Find a part in a \ container by \c absolutePath and/or \c type.
|
||||||
|
Currently no flags are supported.
|
||||||
|
*/
|
||||||
|
opcPart opcPartFind(opcContainer *container,
|
||||||
|
const xmlChar *absolutePath,
|
||||||
|
const xmlChar *type,
|
||||||
|
int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a part in a \ container with \c absolutePath and \c type.
|
||||||
|
Currently no flags are supported.
|
||||||
|
*/
|
||||||
|
opcPart opcPartCreate(opcContainer *container,
|
||||||
|
const xmlChar *absolutePath,
|
||||||
|
const xmlChar *type,
|
||||||
|
int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the type of the container.
|
||||||
|
The string is interned and must not be freed.
|
||||||
|
*/
|
||||||
|
const xmlChar *opcPartGetType(opcContainer *c, opcPart part);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the type of the container.
|
||||||
|
If \c override_only then the return value will be NULL for parts not having an override type.
|
||||||
|
The string is interned and must not be freed.
|
||||||
|
*/
|
||||||
|
const xmlChar *opcPartGetTypeEx(opcContainer *c, opcPart part, opc_bool_t override_only);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Deleted that part \c absolutePath in the \c container.
|
||||||
|
*/
|
||||||
|
opc_error_t opcPartDelete(opcContainer *container, const xmlChar *absolutePath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the first part.
|
||||||
|
\code
|
||||||
|
for(opcPart part=opcPartGetFirst(c);OPC_PART_INVALID!=part;part=opcPartGetNext(c, part)) {
|
||||||
|
printf("%s; \n", part, opcPartGetType(c, part));
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
opcPart opcPartGetFirst(opcContainer *container);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the next part.
|
||||||
|
\see opcPartGetFirst
|
||||||
|
*/
|
||||||
|
opcPart opcPartGetNext(opcContainer *container, opcPart part);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the size in bytes of the \c part.
|
||||||
|
*/
|
||||||
|
opc_ofs_t opcPartGetSize(opcContainer *c, opcPart part);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_PART_H */
|
||||||
121
include/opc/properties.h
Executable file
121
include/opc/properties.h
Executable file
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/properties.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
#include <opc/container.h>
|
||||||
|
|
||||||
|
#ifndef OPC_PROPERTIES_H
|
||||||
|
#define OPC_PROPERTIES_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Represents a simple Dublin Core type.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_DC_SIMPLE_TYPE {
|
||||||
|
xmlChar *str;
|
||||||
|
xmlChar *lang;
|
||||||
|
} opcDCSimpleType_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Represents the core properties of an OPC container.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_PROPERTIES_STRUCT {
|
||||||
|
xmlChar *category; /* xsd:string */
|
||||||
|
xmlChar *contentStatus; /* xsd:string */
|
||||||
|
xmlChar *created; /* dc:date */
|
||||||
|
opcDCSimpleType_t creator; /* dc:any */
|
||||||
|
opcDCSimpleType_t description; /* dc:any */
|
||||||
|
opcDCSimpleType_t identifier; /* dc:any */
|
||||||
|
opcDCSimpleType_t *keyword_array; /* cp:CT_Keywords */
|
||||||
|
opc_uint32_t keyword_items;
|
||||||
|
opcDCSimpleType_t language; /* dc:any */
|
||||||
|
xmlChar *lastModifiedBy; /* xsd:string */
|
||||||
|
xmlChar *lastPrinted; /* xsd:dateTime */
|
||||||
|
xmlChar *modified; /* dc:date */
|
||||||
|
xmlChar *revision; /* xsd:string */
|
||||||
|
opcDCSimpleType_t subject; /* dc:any */
|
||||||
|
opcDCSimpleType_t title; /* dc:any */
|
||||||
|
xmlChar *version; /* xsd:string */
|
||||||
|
} opcProperties_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the core properties \c cp.
|
||||||
|
\see opcCorePropertiesSetString
|
||||||
|
*/
|
||||||
|
opc_error_t opcCorePropertiesInit(opcProperties_t *cp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cleanup the core properties \c cp, i.e. release all resources.
|
||||||
|
\see opcCorePropertiesSetString
|
||||||
|
*/
|
||||||
|
opc_error_t opcCorePropertiesCleanup(opcProperties_t *cp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Rease the core properties \c cp from the container \c.
|
||||||
|
*/
|
||||||
|
opc_error_t opcCorePropertiesRead(opcProperties_t *cp, opcContainer *c);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write/Update the core properties \c cp in the container \c.
|
||||||
|
*/
|
||||||
|
opc_error_t opcCorePropertiesWrite(opcProperties_t *cp, opcContainer *c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Update a string in the core properties the right way.
|
||||||
|
\code
|
||||||
|
opcProperties_t cp;
|
||||||
|
opcCorePropertiesInit(&cp);
|
||||||
|
opcCorePropertiesSetString(&cp.revision, "1");
|
||||||
|
opcCorePropertiesSetStringLang(&cp.creator, "Florian Reuter", NULL);
|
||||||
|
opcCorePropertiesCleanup(&cp);
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
opc_error_t opcCorePropertiesSetString(xmlChar **prop, const xmlChar *str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Update a core properties the right way.
|
||||||
|
\see opcCorePropertiesSetString
|
||||||
|
*/
|
||||||
|
opc_error_t opcCorePropertiesSetStringLang(opcDCSimpleType_t *prop, const xmlChar *str, const xmlChar *lang);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_PROPERTIES_H */
|
||||||
140
include/opc/relation.h
Normal file
140
include/opc/relation.h
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/relation.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
|
||||||
|
#ifndef OPC_RELATION_H
|
||||||
|
#define OPC_RELATION_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indentifier for an OPC relation.
|
||||||
|
*/
|
||||||
|
typedef opc_uint32_t opcRelation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constant which represents an invalid relation.
|
||||||
|
*/
|
||||||
|
#define OPC_RELATION_INVALID (-1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Find a relation originating from \c part in \c container with \c relationId and/or \c mimeType.
|
||||||
|
If \c part is OPC_PART_INVALID then part represents the root part.
|
||||||
|
@param[in] relationId The relationId (e.g. "rId1") or NULL.
|
||||||
|
@param[in] mimeType The mimeType or NULL.
|
||||||
|
*/
|
||||||
|
opcRelation opcRelationFind(opcContainer *container, opcPart part, const xmlChar *relationId, const xmlChar *mimeType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Deleted the relation from the container.
|
||||||
|
\see opcRelationFind.
|
||||||
|
*/
|
||||||
|
opc_error_t opcRelationDelete(opcContainer *container, opcPart part, const xmlChar *relationId, const xmlChar *mimeType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the first relation.
|
||||||
|
The following code will dump all relations:
|
||||||
|
\code
|
||||||
|
for(opcPart part=opcPartGetFirst(c);OPC_PART_INVALID!=part;part=opcPartGetNext(c, part)) {
|
||||||
|
for(opcRelation rel=opcRelationFirst(part, c);
|
||||||
|
OPC_PART_INVALID!=rel;
|
||||||
|
rel=opcRelationNext(c, rel)) {
|
||||||
|
opcPart internal_target=opcRelationGetInternalTarget(c, part, rel);
|
||||||
|
const xmlChar *external_target=opcRelationGetExternalTarget(c, part, rel);
|
||||||
|
const xmlChar *target=(NULL!=internal_target?internal_target:external_target);
|
||||||
|
const xmlChar *prefix=NULL;
|
||||||
|
opc_uint32_t counter=-1;
|
||||||
|
const xmlChar *type=NULL;
|
||||||
|
opcRelationGetInformation(c, part, rel, &prefix, &counter, &type);
|
||||||
|
if (-1==counter) { // no counter after prefix
|
||||||
|
printf("%s;%s;%s;%s\n", part, prefix, target, type);
|
||||||
|
} else {
|
||||||
|
printf("%s;%s%i;%s;%s\n", part, prefix, counter, target, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
opcRelation opcRelationFirst(opcContainer *container, opcPart part);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcRelationFirst
|
||||||
|
*/
|
||||||
|
opcRelation opcRelationNext(opcContainer *container, opcPart part, opcRelation relation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the internal target.
|
||||||
|
\note To test for an external target use opcRelationGetExternalTarget.
|
||||||
|
\see opcRelationGetExternalTarget
|
||||||
|
*/
|
||||||
|
opcPart opcRelationGetInternalTarget(opcContainer *container, opcPart part, opcRelation relation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the external target or NULL if it is an internal target.
|
||||||
|
The string is interned. Must not be freed.
|
||||||
|
\see opcRelationGetExternalTarget
|
||||||
|
*/
|
||||||
|
const xmlChar *opcRelationGetExternalTarget(opcContainer *container, opcPart part, opcRelation relation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the relations type.
|
||||||
|
The string is interned. Must not be freed.
|
||||||
|
*/
|
||||||
|
const xmlChar *opcRelationGetType(opcContainer *container, opcPart part, opcRelation relation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get information about a relation.
|
||||||
|
\see opcRelationFirst
|
||||||
|
*/
|
||||||
|
void opcRelationGetInformation(opcContainer *container, opcPart part, opcRelation relation, const xmlChar **prefix, opc_uint32_t *counter, const xmlChar **type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Add a relation to \c container from \c src part to \c dest part with id \c rid and type \c type.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcRelationAdd(opcContainer *container, opcPart src, const xmlChar *rid, opcPart dest, const xmlChar *type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Add an external relation to \c container from \c src part to \c target URL with id \c rid and type \c type.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcRelationAddExternal(opcContainer *container, opcPart src, const xmlChar *rid, const xmlChar *target, const xmlChar *type);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_RELATION_H */
|
||||||
69
include/opc/xmlreader.h
Normal file
69
include/opc/xmlreader.h
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/xmlreader.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OPC_XMLREADER_H
|
||||||
|
#define OPC_XMLREADER_H
|
||||||
|
|
||||||
|
#include <opc/config.h>
|
||||||
|
#include <libxml/xmlreader.h>
|
||||||
|
#include <mce/textreader.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Open an MCE reader for \c partName. Parameters \c URL, \c encoding and \c options will be passed unmodified to
|
||||||
|
http://xmlsoft.org/html/libxml-xmlreader.html#xmlReaderForIO and they can we NULL, NULL, 0.
|
||||||
|
\note Make sure the part exists.
|
||||||
|
\see opcPartFind
|
||||||
|
*/
|
||||||
|
opc_error_t opcXmlReaderOpen(opcContainer *container, mceTextReader_t *mceTextReader, const xmlChar *partName, const char * URL, const char * encoding, int options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an libxml DOM document. Parameters \c URL, \c encoding and \c options will be passed unmodified to
|
||||||
|
http://xmlsoft.org/html/libxml-parser.html#xmlReadIO and they can we NULL, NULL, 0.
|
||||||
|
\note Make sure the part exists.
|
||||||
|
\see opcPartFind
|
||||||
|
*/
|
||||||
|
xmlDocPtr opcXmlReaderReadDoc(opcContainer *container, const xmlChar *partName, const char * URL, const char * encoding, int options);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_XMLREADER_H */
|
||||||
57
include/opc/xmlwriter.h
Normal file
57
include/opc/xmlwriter.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/xmlwriter.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
#include <mce/textwriter.h>
|
||||||
|
|
||||||
|
#ifndef OPC_XMLWRITER_H
|
||||||
|
#define OPC_XMLWRITER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create an MCE text writer for \c part in \c container with compression \c compression_option.
|
||||||
|
\note Make sure the part exists.
|
||||||
|
\see opcPartFind
|
||||||
|
*/
|
||||||
|
mceTextWriter *mceTextWriterOpen(opcContainer *c, opcPart part, opcCompressionOption_t compression_option);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_XMLWRITER_H */
|
||||||
255
include/opc/zip.h
Normal file
255
include/opc/zip.h
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/** @file opc/zip.h
|
||||||
|
The ZIP file backend of an OPC container.
|
||||||
|
*/
|
||||||
|
#include <opc/config.h>
|
||||||
|
#include <opc/file.h>
|
||||||
|
#include <opc/container.h>
|
||||||
|
|
||||||
|
#ifndef OPC_ZIP_H
|
||||||
|
#define OPC_ZIP_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Default growth hint of an OPC stream.
|
||||||
|
*/
|
||||||
|
#define OPC_DEFAULT_GROWTH_HINT 512
|
||||||
|
|
||||||
|
/**
|
||||||
|
Handle to a ZIP archive.
|
||||||
|
\see internal.h
|
||||||
|
*/
|
||||||
|
typedef struct OPC_ZIP_STRUCT opcZip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Handle to a raw ZIP input stream.
|
||||||
|
\see internal.h
|
||||||
|
*/
|
||||||
|
typedef struct OPC_ZIPINPUTSTREAM_STRUCT opcZipInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Handle to a raw ZIP output stream.
|
||||||
|
\see internal.h
|
||||||
|
*/
|
||||||
|
typedef struct OPC_ZIPOUTPUTSTREAM_STRUCT opcZipOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Holds all information of a ZIP segment.
|
||||||
|
*/
|
||||||
|
typedef struct OPC_ZIP_SEGMENT_INFO_STRUCT {
|
||||||
|
xmlChar name[OPC_MAX_PATH];
|
||||||
|
opc_uint32_t name_len;
|
||||||
|
opc_uint32_t segment_number;
|
||||||
|
opc_bool_t last_segment;
|
||||||
|
opc_bool_t rels_segment;
|
||||||
|
opc_uint32_t header_size;
|
||||||
|
opc_uint32_t min_header_size;
|
||||||
|
opc_uint32_t trailing_bytes;
|
||||||
|
opc_uint32_t compressed_size;
|
||||||
|
opc_uint32_t uncompressed_size;
|
||||||
|
opc_uint16_t bit_flag;
|
||||||
|
opc_uint32_t data_crc;
|
||||||
|
opc_uint16_t compression_method;
|
||||||
|
opc_ofs_t stream_ofs;
|
||||||
|
opc_uint16_t growth_hint;
|
||||||
|
} opcZipSegmentInfo_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcZipLoader
|
||||||
|
*/
|
||||||
|
typedef int opcZipLoaderOpenCallback(void *iocontext);
|
||||||
|
/**
|
||||||
|
\see opcZipLoader
|
||||||
|
*/
|
||||||
|
typedef int opcZipLoaderSkipCallback(void *iocontext);
|
||||||
|
/**
|
||||||
|
\see opcZipLoader
|
||||||
|
*/
|
||||||
|
typedef int opcZipLoaderReadCallback(void *iocontext, char *buffer, int len);
|
||||||
|
/**
|
||||||
|
\see opcZipLoader
|
||||||
|
*/
|
||||||
|
typedef int opcZipLoaderCloseCallback(void *iocontext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcZipLoader
|
||||||
|
*/
|
||||||
|
typedef opc_error_t (opcZipLoaderSegmentCallback_t)(void *iocontext, void *userctx, opcZipSegmentInfo_t *info, opcZipLoaderOpenCallback *open, opcZipLoaderReadCallback *read, opcZipLoaderCloseCallback *close, opcZipLoaderSkipCallback *skip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Walks every segment in a ZIP archive and calls the \c segmentCallback callback method.
|
||||||
|
The implementer \c segmentCallback method must then eiher use the passed \c open, \c read and \c close methods
|
||||||
|
to read the stream or the passed \c skip methods to skip the stream.
|
||||||
|
This method can be used to e.g. read ZIP file in stream mode.
|
||||||
|
*/
|
||||||
|
opc_error_t opcZipLoader(opcIO_t *io, void *userctx, opcZipLoaderSegmentCallback_t *segmentCallback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\see opcZipClose
|
||||||
|
*/
|
||||||
|
typedef opc_error_t (opcZipSegmentReleaseCallback)(opcZip *zip, opc_uint32_t segment_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Closes the ZIP archive \c zip and will call \c releaseCallback for every segment to give the implementer a chance
|
||||||
|
to free user resources.
|
||||||
|
*/
|
||||||
|
void opcZipClose(opcZip *zip, opcZipSegmentReleaseCallback* releaseCallback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates an empty ZIP archive with the given \c io.
|
||||||
|
*/
|
||||||
|
opcZip *opcZipCreate(opcIO_t *io);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Commits all buffers and writes the ZIP archives local header directories.
|
||||||
|
if \c trim is true then padding bytes will be removed, i.e. the ZIP file size fill be minimalized.
|
||||||
|
*/
|
||||||
|
opc_error_t opcZipCommit(opcZip *zip, opc_bool_t trim);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Garbage collection on the passed \c zip archive. This will e.g. make deleted files available as free space.
|
||||||
|
*/
|
||||||
|
opc_error_t opcZipGC(opcZip *zip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load segment information into \c info.
|
||||||
|
If \c rels_segment is -1 then load the info for part with name \c partName.
|
||||||
|
Otherwise load the segment information for the ".rels." segment of \c partName.
|
||||||
|
\return Returns the segment_id.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcZipLoadSegment(opcZip *zip, const xmlChar *partName, opc_bool_t rels_segment, opcZipSegmentInfo_t *info);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a segment with the given parameters.
|
||||||
|
\return Returns the segment_id.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcZipCreateSegment(opcZip *zip,
|
||||||
|
const xmlChar *partName,
|
||||||
|
opc_bool_t relsSegment,
|
||||||
|
opc_uint32_t segment_size,
|
||||||
|
opc_uint32_t growth_hint,
|
||||||
|
opc_uint16_t compression_method,
|
||||||
|
opc_uint16_t bit_flag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates an input stream for the segment with \c segment_id.
|
||||||
|
\see opcZipLoadSegment
|
||||||
|
\see opcZipCreateSegment
|
||||||
|
*/
|
||||||
|
opcZipInputStream *opcZipOpenInputStream(opcZip *zip, opc_uint32_t segment_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Free all resources of the input stream.
|
||||||
|
*/
|
||||||
|
opc_error_t opcZipCloseInputStream(opcZip *zip, opcZipInputStream *stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Read maximal \c buf_len bytes from the input stream into \buf.
|
||||||
|
\return Returns the number of bytes read.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcZipReadInputStream(opcZip *zip, opcZipInputStream *stream, opc_uint8_t *buf, opc_uint32_t buf_len);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates an output stream for the segment with \c segment_id.
|
||||||
|
If \c *segment_id is -1 then a new segment will be created.
|
||||||
|
Otherwise the segment with \c *segment_id will be overwritten.
|
||||||
|
*/
|
||||||
|
opcZipOutputStream *opcZipCreateOutputStream(opcZip *zip,
|
||||||
|
opc_uint32_t *segment_id,
|
||||||
|
const xmlChar *partName,
|
||||||
|
opc_bool_t relsSegment,
|
||||||
|
opc_uint32_t segment_size,
|
||||||
|
opc_uint32_t growth_hint,
|
||||||
|
opc_uint16_t compression_method,
|
||||||
|
opc_uint16_t bit_flag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Opens an existing ouput stream for reading.
|
||||||
|
The \c *segment_id will be set to -1 and reset on opcZipCloseOutputStream.
|
||||||
|
\see opcZipCloseOutputStream
|
||||||
|
*/
|
||||||
|
opcZipOutputStream *opcZipOpenOutputStream(opcZip *zip, opc_uint32_t *segment_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Will close the stream and free all resources. Additionally the new segment id will be stored in \c *segment_id.
|
||||||
|
\see opcZipOpenOutputStream
|
||||||
|
*/
|
||||||
|
opc_error_t opcZipCloseOutputStream(opcZip *zip, opcZipOutputStream *stream, opc_uint32_t *segment_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write \c buf_len bytes to \c buf.
|
||||||
|
\return Returns the number of bytes written.
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcZipWriteOutputStream(opcZip *zip, opcZipOutputStream *stream, const opc_uint8_t *buf, opc_uint32_t buf_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the first segment id or -1.
|
||||||
|
Use the following code to iterarte through all segments.
|
||||||
|
\code
|
||||||
|
for(opc_uint32_t segment_id=opcZipGetFirstSegmentId(zip);
|
||||||
|
-1!=segment_id;
|
||||||
|
segment_id=opcZipGetNextSegmentId(zip, segment_id) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
\see opcZipGetNextSegmentId
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcZipGetFirstSegmentId(opcZip *zip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the next segment id or -1.
|
||||||
|
\see opcZipGetFirstSegmentId
|
||||||
|
*/
|
||||||
|
opc_uint32_t opcZipGetNextSegmentId(opcZip *zip, opc_uint32_t segment_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns info about the given segment id.
|
||||||
|
*/
|
||||||
|
opc_error_t opcZipGetSegmentInfo(opcZip *zip, opc_uint32_t segment_id, const xmlChar **name, opc_bool_t *rels_segment, opc_uint32_t *crc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Marks a given segments as deleted.
|
||||||
|
\see opcZipGC
|
||||||
|
*/
|
||||||
|
opc_bool_t opcZipSegmentDelete(opcZip *zip, opc_uint32_t *first_segment, opc_uint32_t *last_segment, opcZipSegmentReleaseCallback* releaseCallback);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPC_ZIP_H */
|
||||||
168
include/plib/plib.h
Normal file
168
include/plib/plib.h
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
/* include/plib/plib.h. Generated from plib.h by configure. */
|
||||||
|
/*
|
||||||
|
Copyright (c) 2010, Florian Reuter
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Florian Reuter nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this
|
||||||
|
software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
#ifndef _PLIB_PLIB_H_
|
||||||
|
#define _PLIB_PLIB_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
#define HAVE_STDDEF_H 1
|
||||||
|
#define HAVE_STDIO_H 1
|
||||||
|
#define HAVE_STRING_H 1
|
||||||
|
#define HAVE_LIMITS_H 1
|
||||||
|
#define HAVE_STDLIB_H 1
|
||||||
|
/* #undef HAVE_IO_H */
|
||||||
|
#define HAVE_UNISTD_H 1
|
||||||
|
#define HAVE_SYS_TYPES_H 1
|
||||||
|
#define IS_CONFIGURED 1
|
||||||
|
|
||||||
|
#if !defined(IS_CONFIGURED)
|
||||||
|
#if defined(WIN32)
|
||||||
|
#define HAVE_STRING_H 1
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
#define HAVE_LIMITS_H 1
|
||||||
|
#define HAVE_STDDEF_H 1
|
||||||
|
#define HAVE_STDIO_H 1
|
||||||
|
#define HAVE_STDLIB_H 1
|
||||||
|
#define HAVE_IO_H
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#else
|
||||||
|
#error "configure not executed and we are not on a win32 machine? please run configure or define WIN32 is you are on a WIN32 platform."
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDDEF_H
|
||||||
|
#include <stddef.h>
|
||||||
|
typedef size_t pofs_t; // maximum file offset for eg. read write ops
|
||||||
|
#else
|
||||||
|
#error "system types can not be determined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDIO_H
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#error "system io can not be determined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDINT_H
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef int8_t pint8_t;
|
||||||
|
typedef uint8_t puint8_t;
|
||||||
|
|
||||||
|
typedef int16_t pint16_t;
|
||||||
|
typedef uint16_t puint16_t;
|
||||||
|
|
||||||
|
typedef int32_t pint32_t;
|
||||||
|
typedef uint32_t puint32_t;
|
||||||
|
|
||||||
|
typedef int64_t pint64_t;
|
||||||
|
typedef uint64_t puint64_t;
|
||||||
|
|
||||||
|
typedef int pbool_t;
|
||||||
|
|
||||||
|
typedef size_t psize_t;
|
||||||
|
|
||||||
|
// INTN_MAX, INTN_MIN, UINTN_MAX
|
||||||
|
#else
|
||||||
|
#error "system types can not be determined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LIMITS_H
|
||||||
|
#include <limits.h>
|
||||||
|
#define PUINT8_MAX UCHAR_MAX
|
||||||
|
#define PINT32_MAX INT_MAX
|
||||||
|
#define PINT32_MIN INT_MIN
|
||||||
|
#define PUINT32_MAX UINT_MAX
|
||||||
|
#define PUINT32_MIN 0
|
||||||
|
#define PUINT16_MAX USHRT_MAX
|
||||||
|
#define PUINT16_MIN 0
|
||||||
|
#else
|
||||||
|
#error "limits can not be determined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_IO_H
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts an ASCII string to a xmlChar string. This only works for ASCII strings.
|
||||||
|
*/
|
||||||
|
#ifndef _X
|
||||||
|
#define _X(s) BAD_CAST(s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts an xmlChar string to an ASCII string. This only works for ASCII charsets.
|
||||||
|
*/
|
||||||
|
#ifndef _X2C
|
||||||
|
#define _X2C(s) ((char*)(s))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define PASSERT(e) assert(e)
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define PENSURE(e) (void)(e)
|
||||||
|
#else
|
||||||
|
#define PENSURE(e) assert(e)
|
||||||
|
#endif
|
||||||
|
#define PTRUE (0==0)
|
||||||
|
#define PFALSE (0==1)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _PLIB_PLIB_H_ */
|
||||||
1
lib/bzip2-1.0.6
Submodule
1
lib/bzip2-1.0.6
Submodule
Submodule lib/bzip2-1.0.6 added at 288acf97a1
1
lib/ffmpeg
Submodule
1
lib/ffmpeg
Submodule
Submodule lib/ffmpeg added at 8887991a31
1
lib/harfbuzz
Submodule
1
lib/harfbuzz
Submodule
Submodule lib/harfbuzz added at b28c282585
1
lib/libarchive
Submodule
1
lib/libarchive
Submodule
Submodule lib/libarchive added at 6f4fceb714
1
lib/libmagic
Submodule
1
lib/libmagic
Submodule
Submodule lib/libmagic added at 1249b5cd02
BIN
lib/libopc/libmce.a
Normal file
BIN
lib/libopc/libmce.a
Normal file
Binary file not shown.
BIN
lib/libopc/libopc.a
Normal file
BIN
lib/libopc/libopc.a
Normal file
Binary file not shown.
BIN
lib/libopc/libplib.a
Normal file
BIN
lib/libopc/libplib.a
Normal file
Binary file not shown.
1
lib/libxml2
Submodule
1
lib/libxml2
Submodule
Submodule lib/libxml2 added at 0815302dee
1
lib/lz4
Submodule
1
lib/lz4
Submodule
Submodule lib/lz4 added at 0f749838bf
1
lib/mupdf
Submodule
1
lib/mupdf
Submodule
Submodule lib/mupdf added at c50ac19e41
1
lib/onion
Submodule
1
lib/onion
Submodule
Submodule lib/onion added at 73329b61eb
1
lib/openjpeg
Submodule
1
lib/openjpeg
Submodule
Submodule lib/openjpeg added at ac3737372a
1
lib/zstd
Submodule
1
lib/zstd
Submodule
Submodule lib/zstd added at d73e2fb465
2
mime.csv
2
mime.csv
@@ -252,7 +252,7 @@ text/html, acgi|htm|html|htmls|htx|shtml
|
|||||||
text/javascript, js
|
text/javascript, js
|
||||||
text/mcf, mcf
|
text/mcf, mcf
|
||||||
text/pascal, pas
|
text/pascal, pas
|
||||||
text/plain, com|cmd|conf|def|g|idc|list|lst|mar|sdml|text|txt|md|groovy|license|properties|desktop|ini|rst|cmake|ipynb|readme|less|lo|go|yml|d|cs|hpp|srt|nfo|sfv|m3u
|
text/plain, com|cmd|conf|def|g|idc|list|lst|mar|sdml|text|txt|md|groovy|license|properties|desktop|ini|rst|cmake|ipynb|readme|less|lo|go|yml|d|cs|hpp|srt|nfo|sfv|m3u|csv|eml
|
||||||
text/richtext, rt|rtf|rtx
|
text/richtext, rt|rtf|rtx
|
||||||
text/rtf,
|
text/rtf,
|
||||||
text/scriplet, wsc
|
text/scriplet, wsc
|
||||||
|
|||||||
|
@@ -1,8 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
THREADS=$(nproc)
|
||||||
|
|
||||||
cd lib
|
cd lib
|
||||||
|
|
||||||
cd mupdf
|
cd mupdf
|
||||||
USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no make -j 4
|
make USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mv mupdf/build/release/libmupdf.a .
|
mv mupdf/build/release/libmupdf.a .
|
||||||
@@ -12,7 +15,7 @@ mv mupdf/build/release/libmupdf-third.a .
|
|||||||
cd openjpeg
|
cd openjpeg
|
||||||
#cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG"
|
#cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG"
|
||||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv openjpeg/bin/libopenjp2.a .
|
mv openjpeg/bin/libopenjp2.a .
|
||||||
|
|
||||||
@@ -20,7 +23,7 @@ mv openjpeg/bin/libopenjp2.a .
|
|||||||
cd harfbuzz
|
cd harfbuzz
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --disable-shared --enable-static
|
./configure --disable-shared --enable-static
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv harfbuzz/src/.libs/libharfbuzz.a .
|
mv harfbuzz/src/.libs/libharfbuzz.a .
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ cd ffmpeg
|
|||||||
--disable-manpages --disable-postproc --disable-avfilter \
|
--disable-manpages --disable-postproc --disable-avfilter \
|
||||||
--disable-alsa --disable-lzma --disable-xlib --disable-debug\
|
--disable-alsa --disable-lzma --disable-xlib --disable-debug\
|
||||||
--disable-vdpau --disable-vaapi --disable-sdl2 --disable-network
|
--disable-vdpau --disable-vaapi --disable-sdl2 --disable-network
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mv ffmpeg/libavcodec/libavcodec.a .
|
mv ffmpeg/libavcodec/libavcodec.a .
|
||||||
@@ -48,14 +51,14 @@ cmake -DONION_USE_SSL=false -DONION_USE_PAM=false -DONION_USE_PNG=false -DONION_
|
|||||||
-DONION_USE_JPEG=false -DONION_USE_XML2=false -DONION_USE_SYSTEMD=false -DONION_USE_SQLITE3=false \
|
-DONION_USE_JPEG=false -DONION_USE_XML2=false -DONION_USE_SYSTEMD=false -DONION_USE_SQLITE3=false \
|
||||||
-DONION_USE_REDIS=false -DONION_USE_GC=false -DONION_USE_TESTS=false -DONION_EXAMPLES=false \
|
-DONION_USE_REDIS=false -DONION_USE_GC=false -DONION_USE_TESTS=false -DONION_EXAMPLES=false \
|
||||||
-DONION_USE_BINDINGS_CPP=false ..
|
-DONION_USE_BINDINGS_CPP=false ..
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
mv onion/build/src/onion/libonion_static.a .
|
mv onion/build/src/onion/libonion_static.a .
|
||||||
|
|
||||||
#bzip2
|
#bzip2
|
||||||
cd bzip2-1.0.6
|
cd bzip2-1.0.6
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv bzip2-1.0.6/libbz2.a .
|
mv bzip2-1.0.6/libbz2.a .
|
||||||
|
|
||||||
@@ -63,24 +66,22 @@ mv bzip2-1.0.6/libbz2.a .
|
|||||||
cd libmagic
|
cd libmagic
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --enable-static --disable-shared
|
./configure --enable-static --disable-shared
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv libmagic/src/.libs/libmagic.a .
|
mv libmagic/src/.libs/libmagic.a .
|
||||||
|
|
||||||
# libarchive
|
# libarchive
|
||||||
git clone https://github.com/libarchive/libarchive
|
|
||||||
cd libarchive/build
|
cd libarchive/build
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
cd ..
|
cd ..
|
||||||
./configure --without-nettle --without-expat --without-xml2 --without-openssl
|
./configure --without-nettle --without-expat --without-xml2 --without-openssl
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv libarchive/.libs/libarchive.a .
|
mv libarchive/.libs/libarchive.a .
|
||||||
|
|
||||||
# lz4
|
# lz4
|
||||||
git clone https://github.com/lz4/lz4
|
|
||||||
cd lz4
|
cd lz4
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv lz4/lib/liblz4.a .
|
mv lz4/lib/liblz4.a .
|
||||||
|
|
||||||
@@ -91,15 +92,21 @@ rm xz-5.2.3.tar.gz
|
|||||||
cd xz-5.2.3
|
cd xz-5.2.3
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure
|
./configure
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv xz-5.2.3/src/liblzma/.libs/liblzma.a .
|
mv xz-5.2.3/src/liblzma/.libs/liblzma.a .
|
||||||
|
|
||||||
# zstd
|
# zstd
|
||||||
git clone https://github.com/facebook/zstd
|
|
||||||
cd zstd
|
cd zstd
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv zstd/lib/libzstd.a .
|
mv zstd/lib/libzstd.a .
|
||||||
|
|
||||||
|
# xml2
|
||||||
|
cd libxml2
|
||||||
|
./autogen.sh --without-zlib --without-lzma
|
||||||
|
make
|
||||||
|
cd ..
|
||||||
|
mv libxml2/.libs/libxml2.a .
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ arc_filter = (
|
|||||||
"application/x-lzop",
|
"application/x-lzop",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
doc = (
|
||||||
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||||
|
)
|
||||||
|
|
||||||
cnt = 1
|
cnt = 1
|
||||||
|
|
||||||
|
|
||||||
@@ -74,6 +80,8 @@ def mime_id(mime):
|
|||||||
mime_id += " | 0x10000000"
|
mime_id += " | 0x10000000"
|
||||||
elif mime in arc_filter:
|
elif mime in arc_filter:
|
||||||
mime_id += " | 0x08000000"
|
mime_id += " | 0x08000000"
|
||||||
|
elif mime in doc:
|
||||||
|
mime_id += " | 0x04000000"
|
||||||
elif mime == "application/x-empty":
|
elif mime == "application/x-empty":
|
||||||
return "1"
|
return "1"
|
||||||
return mime_id
|
return mime_id
|
||||||
|
|||||||
35
src/cli.c
35
src/cli.c
@@ -1,4 +1,5 @@
|
|||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
#include "ctx.h"
|
||||||
|
|
||||||
#define DEFAULT_OUTPUT "index.sist2/"
|
#define DEFAULT_OUTPUT "index.sist2/"
|
||||||
#define DEFAULT_CONTENT_SIZE 32768
|
#define DEFAULT_CONTENT_SIZE 32768
|
||||||
@@ -134,6 +135,19 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
fprintf(stderr, "Archive mode must be one of (skip, list, shallow, recurse), got '%s'", args->archive);
|
fprintf(stderr, "Archive mode must be one of (skip, list, shallow, recurse), got '%s'", args->archive);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
||||||
|
LOG_DEBUGF("cli.c", "arg size=%d", args->size)
|
||||||
|
LOG_DEBUGF("cli.c", "arg content_size=%d", args->content_size)
|
||||||
|
LOG_DEBUGF("cli.c", "arg threads=%d", args->threads)
|
||||||
|
LOG_DEBUGF("cli.c", "arg incremental=%s", args->incremental)
|
||||||
|
LOG_DEBUGF("cli.c", "arg output=%s", args->output)
|
||||||
|
LOG_DEBUGF("cli.c", "arg rewrite_url=%s", args->rewrite_url)
|
||||||
|
LOG_DEBUGF("cli.c", "arg name=%s", args->name)
|
||||||
|
LOG_DEBUGF("cli.c", "arg depth=%d", args->depth)
|
||||||
|
LOG_DEBUGF("cli.c", "arg path=%s", args->path)
|
||||||
|
LOG_DEBUGF("cli.c", "arg archive=%s", args->archive)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +203,14 @@ int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
|||||||
args->batch_size = DEFAULT_BATCH_SIZE;
|
args->batch_size = DEFAULT_BATCH_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DEBUGF("cli.c", "arg es_url=%s", args->es_url)
|
||||||
|
LOG_DEBUGF("cli.c", "arg index_path=%s", args->index_path)
|
||||||
|
LOG_DEBUGF("cli.c", "arg script_path=%s", args->script_path)
|
||||||
|
LOG_DEBUGF("cli.c", "arg script=%s", args->script)
|
||||||
|
LOG_DEBUGF("cli.c", "arg print=%d", args->print)
|
||||||
|
LOG_DEBUGF("cli.c", "arg batch_size=%d", args->batch_size)
|
||||||
|
LOG_DEBUGF("cli.c", "arg force_reset=%d", args->force_reset)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,10 +245,21 @@ int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
|||||||
for (int i = 0; i < args->index_count; i++) {
|
for (int i = 0; i < args->index_count; i++) {
|
||||||
char *abs_path = abspath(args->indices[i]);
|
char *abs_path = abspath(args->indices[i]);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s\n", abs_path);
|
fprintf(stderr, "File not found: %s\n", args->indices[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DEBUGF("cli.c", "arg es_url=%s", args->es_url)
|
||||||
|
LOG_DEBUGF("cli.c", "arg bind=%s", args->bind)
|
||||||
|
LOG_DEBUGF("cli.c", "arg port=%s", args->port)
|
||||||
|
LOG_DEBUGF("cli.c", "arg credentials=%s", args->credentials)
|
||||||
|
LOG_DEBUGF("cli.c", "arg b64credentials=%s", args->b64credentials)
|
||||||
|
LOG_DEBUGF("cli.c", "arg index_count=%d", args->index_count)
|
||||||
|
for (int i = 0; i < args->index_count; i++) {
|
||||||
|
LOG_DEBUGF("cli.c", "arg indices[%d]=%s", i, args->indices[i])
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ struct {
|
|||||||
float tn_qscale;
|
float tn_qscale;
|
||||||
int depth;
|
int depth;
|
||||||
archive_mode_t archive_mode;
|
archive_mode_t archive_mode;
|
||||||
|
int verbose;
|
||||||
|
int very_verbose;
|
||||||
|
|
||||||
size_t stat_tn_size;
|
size_t stat_tn_size;
|
||||||
size_t stat_index_size;
|
size_t stat_index_size;
|
||||||
@@ -27,6 +29,11 @@ struct {
|
|||||||
pthread_mutex_t mupdf_mu;
|
pthread_mutex_t mupdf_mu;
|
||||||
} ScanCtx;
|
} ScanCtx;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int verbose;
|
||||||
|
int very_verbose;
|
||||||
|
int no_color;
|
||||||
|
} LogCtx;
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
@@ -262,8 +262,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Invalid meta key (corrupt index): %x\n", key);
|
LOG_FATALF("serialize.c", "Invalid meta key (corrupt index): %x", key)
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key = getc(file);
|
key = getc(file);
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ store_t *store_create(char *path) {
|
|||||||
mdb_env_create(&store->env);
|
mdb_env_create(&store->env);
|
||||||
|
|
||||||
int open_ret = mdb_env_open(store->env,
|
int open_ret = mdb_env_open(store->env,
|
||||||
path,
|
path,
|
||||||
MDB_WRITEMAP | MDB_MAPASYNC,
|
MDB_WRITEMAP | MDB_MAPASYNC,
|
||||||
S_IRUSR | S_IWUSR
|
S_IRUSR | S_IWUSR
|
||||||
);
|
);
|
||||||
|
|
||||||
if (open_ret != 0) {
|
if (open_ret != 0) {
|
||||||
@@ -42,6 +42,12 @@ void store_destroy(store_t *store) {
|
|||||||
|
|
||||||
void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t buf_len) {
|
void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t buf_len) {
|
||||||
|
|
||||||
|
if (LogCtx.very_verbose) {
|
||||||
|
char uuid_str[UUID_STR_LEN];
|
||||||
|
uuid_unparse((unsigned char *) key, uuid_str);
|
||||||
|
LOG_DEBUGF("store.c", "Store write {%s} %lu bytes", uuid_str, buf_len)
|
||||||
|
}
|
||||||
|
|
||||||
MDB_val mdb_key;
|
MDB_val mdb_key;
|
||||||
mdb_key.mv_data = key;
|
mdb_key.mv_data = key;
|
||||||
mdb_key.mv_size = key_len;
|
mdb_key.mv_size = key_len;
|
||||||
@@ -68,6 +74,8 @@ void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t bu
|
|||||||
mdb_env_set_mapsize(store->env, store->size);
|
mdb_env_set_mapsize(store->env, store->size);
|
||||||
mdb_txn_begin(store->env, NULL, 0, &txn);
|
mdb_txn_begin(store->env, NULL, 0, &txn);
|
||||||
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
||||||
|
|
||||||
|
LOG_INFOF("store.c", "Updated mdb mapsize to %lu bytes", store->size)
|
||||||
}
|
}
|
||||||
|
|
||||||
mdb_txn_commit(txn);
|
mdb_txn_commit(txn);
|
||||||
|
|||||||
99
src/log.c
Normal file
99
src/log.c
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
const char *log_colors[] = {
|
||||||
|
"\033[34m", "\033[01;34m", "\033[0m",
|
||||||
|
"\033[01;33m", "\033[31m", "\033[01;31m"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *log_levels[] = {
|
||||||
|
"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"
|
||||||
|
};
|
||||||
|
|
||||||
|
void sist_logf(char *filepath, int level, char *format, ...) {
|
||||||
|
|
||||||
|
static int is_tty = -1;
|
||||||
|
if (is_tty == -1) {
|
||||||
|
is_tty = isatty(STDERR_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
char log_str[LOG_MAX_LENGTH];
|
||||||
|
|
||||||
|
unsigned long long pid = (unsigned long long) pthread_self();
|
||||||
|
|
||||||
|
char datetime[32];
|
||||||
|
time_t t;
|
||||||
|
struct tm result;
|
||||||
|
t = time(NULL);
|
||||||
|
localtime_r(&t, &result);
|
||||||
|
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", &result);
|
||||||
|
|
||||||
|
int log_len;
|
||||||
|
if (is_tty) {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"\033[%dm[%04X]%s [%s] [%s %s] ",
|
||||||
|
31 + ((unsigned int) (pid)) % 7, pid, log_colors[level],
|
||||||
|
datetime, log_levels[level], filepath
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"[%04X] [%s] [%s %s] ",
|
||||||
|
pid, datetime, log_levels[level], filepath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
size_t maxsize = sizeof(log_str) - log_len;
|
||||||
|
log_len += vsnprintf(log_str + log_len, maxsize, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (is_tty) {
|
||||||
|
log_len += sprintf(log_str + log_len, "\033[0m\n");
|
||||||
|
} else {
|
||||||
|
*(log_str + log_len) = '\n';
|
||||||
|
log_len += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
write(STDOUT_FILENO, log_str, log_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sist_log(char *filepath, int level, char *str) {
|
||||||
|
|
||||||
|
static int is_tty = -1;
|
||||||
|
if (is_tty == -1) {
|
||||||
|
is_tty = isatty(STDERR_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
char log_str[LOG_MAX_LENGTH];
|
||||||
|
|
||||||
|
unsigned long long pid = (unsigned long long) pthread_self();
|
||||||
|
|
||||||
|
char datetime[32];
|
||||||
|
time_t t;
|
||||||
|
struct tm result;
|
||||||
|
t = time(NULL);
|
||||||
|
localtime_r(&t, &result);
|
||||||
|
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", &result);
|
||||||
|
|
||||||
|
int log_len;
|
||||||
|
if (is_tty) {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"\033[%dm[%04X]%s [%s] [%s %s] %s \033[0m\n",
|
||||||
|
31 + ((unsigned int) (pid)) % 7, pid, log_colors[level],
|
||||||
|
datetime, log_levels[level], filepath,
|
||||||
|
str
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"[%04X] [%s] [%s %s] %s \n",
|
||||||
|
pid, datetime, log_levels[level], filepath,
|
||||||
|
str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
write(STDERR_FILENO, log_str, log_len);
|
||||||
|
}
|
||||||
45
src/log.h
Normal file
45
src/log.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef SIST2_LOG_H
|
||||||
|
#define SIST2_LOG_H
|
||||||
|
|
||||||
|
#define LOG_MAX_LENGTH 8192
|
||||||
|
|
||||||
|
#define SIST_DEBUG 0
|
||||||
|
#define SIST_INFO 1
|
||||||
|
#define SIST_WARNING 2
|
||||||
|
#define SIST_ERROR 3
|
||||||
|
#define SIST_FATAL 4
|
||||||
|
|
||||||
|
#define LOG_DEBUGF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.very_verbose) {sist_logf(filepath, SIST_DEBUG, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_DEBUG(filepath, str) \
|
||||||
|
if (LogCtx.very_verbose) {sist_log(filepath, SIST_DEBUG, str);}
|
||||||
|
|
||||||
|
#define LOG_INFOF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.verbose) {sist_logf(filepath, SIST_INFO, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_INFO(filepath, str) \
|
||||||
|
if (LogCtx.verbose) {sist_log(filepath, SIST_INFO, str);}
|
||||||
|
|
||||||
|
#define LOG_WARNINGF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.verbose) {sist_logf(filepath, SIST_WARNING, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_WARNING(filepath, str) \
|
||||||
|
if (LogCtx.verbose) {sist_log(filepath, SIST_WARNING, str);}
|
||||||
|
|
||||||
|
#define LOG_ERRORF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.verbose) {sist_logf(filepath, SIST_ERROR, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_ERROR(filepath, str) \
|
||||||
|
if (LogCtx.verbose) {sist_log(filepath, SIST_ERROR, str);}
|
||||||
|
|
||||||
|
#define LOG_FATALF(filepath, fmt, ...) \
|
||||||
|
sist_logf(filepath, SIST_FATAL, fmt, __VA_ARGS__);\
|
||||||
|
exit(-1);
|
||||||
|
#define LOG_FATAL(filepath, str) \
|
||||||
|
sist_log(filepath, SIST_FATAL, str);\
|
||||||
|
exit(-1);
|
||||||
|
|
||||||
|
#include "src/sist.h"
|
||||||
|
|
||||||
|
void sist_logf(char *filepath, int level, char *format, ...);
|
||||||
|
|
||||||
|
void sist_log(char *filepath, int level, char *str);
|
||||||
|
|
||||||
|
#endif
|
||||||
30
src/main.c
30
src/main.c
@@ -10,7 +10,7 @@
|
|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
static const char *const Version = "1.1.10";
|
static const char *const Version = "1.1.14";
|
||||||
static const char *const usage[] = {
|
static const char *const usage[] = {
|
||||||
"sist2 scan [OPTION]... PATH",
|
"sist2 scan [OPTION]... PATH",
|
||||||
"sist2 index [OPTION]... INDEX",
|
"sist2 index [OPTION]... INDEX",
|
||||||
@@ -23,6 +23,7 @@ void global_init() {
|
|||||||
curl_global_init(CURL_GLOBAL_NOTHING);
|
curl_global_init(CURL_GLOBAL_NOTHING);
|
||||||
#endif
|
#endif
|
||||||
av_log_set_level(AV_LOG_QUIET);
|
av_log_set_level(AV_LOG_QUIET);
|
||||||
|
opcInitLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_dir(const char *dirpath) {
|
void init_dir(const char *dirpath) {
|
||||||
@@ -39,24 +40,7 @@ void init_dir(const char *dirpath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void scan_print_header() {
|
void scan_print_header() {
|
||||||
printf("sist2 V%s\n", Version);
|
LOG_INFOF("main.c", "sist2 v%s", Version)
|
||||||
printf("---------------------\n");
|
|
||||||
printf("threads\t\t\t%d\n", ScanCtx.threads);
|
|
||||||
printf("tn_qscale\t\t%.1f/31.0\n", ScanCtx.tn_qscale);
|
|
||||||
|
|
||||||
if (ScanCtx.tn_size > 0) {
|
|
||||||
printf("tn_size\t\t\t%dpx\n", ScanCtx.tn_size);
|
|
||||||
} else {
|
|
||||||
printf("tn_size\t\t\tdisabled\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ScanCtx.content_size > 0) {
|
|
||||||
printf("content_size\t\t%d B\n", ScanCtx.content_size);
|
|
||||||
} else {
|
|
||||||
printf("content_size\t\t\tdisabled\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("output\t\t\t%s\n", ScanCtx.index.path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sist2_scan(scan_args_t *args) {
|
void sist2_scan(scan_args_t *args) {
|
||||||
@@ -235,6 +219,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
OPT_HELP(),
|
OPT_HELP(),
|
||||||
|
|
||||||
OPT_BOOLEAN('v', "version", &arg_version, "Show version and exit"),
|
OPT_BOOLEAN('v', "version", &arg_version, "Show version and exit"),
|
||||||
|
OPT_BOOLEAN(0, "verbose", &LogCtx.verbose, "Turn on logging"),
|
||||||
|
OPT_BOOLEAN(0, "very-verbose", &LogCtx.very_verbose, "Turn on debug messages"),
|
||||||
|
|
||||||
OPT_GROUP("Scan options"),
|
OPT_GROUP("Scan options"),
|
||||||
OPT_INTEGER('t', "threads", &scan_args->threads, "Number of threads. DEFAULT=1"),
|
OPT_INTEGER('t', "threads", &scan_args->threads, "Number of threads. DEFAULT=1"),
|
||||||
@@ -257,7 +243,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
OPT_GROUP("Index options"),
|
OPT_GROUP("Index options"),
|
||||||
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url with port. DEFAULT=http://localhost:9200"),
|
||||||
OPT_BOOLEAN('p', "print", &index_args->print, "Just print JSON documents to stdout."),
|
OPT_BOOLEAN('p', "print", &index_args->print, "Just print JSON documents to stdout."),
|
||||||
OPT_STRING(0, "script-file", &index_args->script_path, "Path to user script."),
|
OPT_STRING(0, "script-file", &index_args->script_path, "Path to user script."),
|
||||||
OPT_INTEGER(0, "batch-size", &index_args->batch_size, "Index batch size. DEFAULT: 100"),
|
OPT_INTEGER(0, "batch-size", &index_args->batch_size, "Index batch size. DEFAULT: 100"),
|
||||||
@@ -284,6 +270,10 @@ int main(int argc, const char *argv[]) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LogCtx.very_verbose != 0) {
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
web_args->es_url = common_es_url;
|
web_args->es_url = common_es_url;
|
||||||
index_args->es_url = common_es_url;
|
index_args->es_url = common_es_url;
|
||||||
|
|||||||
@@ -67,18 +67,24 @@ void parse_archive(vfile_t *f, document_t *doc) {
|
|||||||
struct archive *a;
|
struct archive *a;
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
|
|
||||||
a = archive_read_new();
|
|
||||||
|
|
||||||
archive_read_support_filter_all(a);
|
|
||||||
archive_read_support_format_all(a);
|
|
||||||
|
|
||||||
arc_data_f data;
|
arc_data_f data;
|
||||||
data.f = f;
|
data.f = f;
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if (data.f->is_fs_file) {
|
if (data.f->is_fs_file) {
|
||||||
|
|
||||||
|
a = archive_read_new();
|
||||||
|
archive_read_support_filter_all(a);
|
||||||
|
archive_read_support_format_all(a);
|
||||||
|
|
||||||
ret = archive_read_open_filename(a, doc->filepath, ARC_BUF_SIZE);
|
ret = archive_read_open_filename(a, doc->filepath, ARC_BUF_SIZE);
|
||||||
} else if (ScanCtx.archive_mode == ARC_MODE_RECURSE) {
|
} else if (ScanCtx.archive_mode == ARC_MODE_RECURSE) {
|
||||||
|
|
||||||
|
a = archive_read_new();
|
||||||
|
archive_read_support_filter_all(a);
|
||||||
|
archive_read_support_format_all(a);
|
||||||
|
|
||||||
ret = archive_read_open(
|
ret = archive_read_open(
|
||||||
a, &data,
|
a, &data,
|
||||||
vfile_open_callback,
|
vfile_open_callback,
|
||||||
@@ -86,12 +92,11 @@ void parse_archive(vfile_t *f, document_t *doc) {
|
|||||||
vfile_close_callback
|
vfile_close_callback
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
archive_read_free(a);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != ARCHIVE_OK) {
|
if (ret != ARCHIVE_OK) {
|
||||||
fprintf(stderr, "OPEN[%d]:%s %s\n", ret, archive_error_string(a), doc->filepath);
|
LOG_ERRORF(doc->filepath, "(arc.c) [%d] %s", ret, archive_error_string(a))
|
||||||
archive_read_free(a);
|
archive_read_free(a);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
107
src/parsing/doc.c
Normal file
107
src/parsing/doc.c
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#include "doc.h"
|
||||||
|
#include "src/ctx.h"
|
||||||
|
|
||||||
|
void dump_text(mceTextReader_t *reader, dyn_buffer_t *buf) {
|
||||||
|
|
||||||
|
mce_skip_attributes(reader);
|
||||||
|
|
||||||
|
mce_start_children(reader) {
|
||||||
|
mce_start_element(reader, NULL, _X("t")) {
|
||||||
|
mce_skip_attributes(reader);
|
||||||
|
mce_start_children(reader) {
|
||||||
|
mce_start_text(reader) {
|
||||||
|
char *str = (char *) xmlTextReaderConstValue(reader->reader);
|
||||||
|
dyn_buffer_append_string(buf, str);
|
||||||
|
dyn_buffer_write_char(buf, ' ');
|
||||||
|
} mce_end_text(reader);
|
||||||
|
} mce_end_children(reader);
|
||||||
|
} mce_end_element(reader);
|
||||||
|
|
||||||
|
mce_start_element(reader, NULL, NULL) {
|
||||||
|
dump_text(reader, buf);
|
||||||
|
} mce_end_element(reader);
|
||||||
|
|
||||||
|
} mce_end_children(reader)
|
||||||
|
}
|
||||||
|
|
||||||
|
__always_inline
|
||||||
|
int should_read_part(opcPart part) {
|
||||||
|
|
||||||
|
char *part_name = (char *) part;
|
||||||
|
|
||||||
|
if (part == NULL) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( // Word
|
||||||
|
strcmp(part_name, "word/document.xml") == 0
|
||||||
|
|| strncmp(part_name, "word/footer", sizeof("word/footer") - 1) == 0
|
||||||
|
|| strncmp(part_name, "word/header", sizeof("word/header") - 1) == 0
|
||||||
|
// PowerPoint
|
||||||
|
|| strncmp(part_name, "ppt/slides/slide", sizeof("ppt/slides/slide") - 1) == 0
|
||||||
|
|| strncmp(part_name, "ppt/notesSlides/notesSlide", sizeof("ppt/notesSlides/notesSlide") - 1) == 0
|
||||||
|
// Excel
|
||||||
|
|| strncmp(part_name, "xl/worksheets/sheet", sizeof("xl/worksheets/sheet") - 1) == 0
|
||||||
|
|| strcmp(part_name, "xl/sharedStrings.xml") == 0
|
||||||
|
|| strcmp(part_name, "xl/workbook.xml") == 0
|
||||||
|
) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
__always_inline
|
||||||
|
void read_part(opcContainer *c, dyn_buffer_t *buf, opcPart part, document_t *doc) {
|
||||||
|
|
||||||
|
mceTextReader_t reader;
|
||||||
|
int ret = opcXmlReaderOpen(c, &reader, part, NULL, "UTF-8", 0);
|
||||||
|
|
||||||
|
if (ret != OPC_ERROR_NONE) {
|
||||||
|
LOG_ERRORF(doc->filepath, "(doc.c) opcXmlReaderOpen() returned error code %d", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mce_start_document(&reader) {
|
||||||
|
mce_start_element(&reader, NULL, NULL) {
|
||||||
|
dump_text(&reader, buf);
|
||||||
|
} mce_end_element(&reader);
|
||||||
|
} mce_end_document(&reader);
|
||||||
|
|
||||||
|
mceTextReaderCleanup(&reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_doc(void *mem, size_t mem_len, document_t *doc) {
|
||||||
|
|
||||||
|
if (mem == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
opcContainer *c = opcContainerOpenMem(mem, mem_len, OPC_OPEN_READ_ONLY, NULL);
|
||||||
|
if (c == NULL) {
|
||||||
|
LOG_ERROR(doc->filepath, "(doc.c) Couldn't open document with opcContainerOpenMem()");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_buffer_t buf = dyn_buffer_create();
|
||||||
|
|
||||||
|
opcPart part = opcPartGetFirst(c);
|
||||||
|
do {
|
||||||
|
if (should_read_part(part)) {
|
||||||
|
read_part(c, &buf, part, doc);
|
||||||
|
}
|
||||||
|
} while ((part = opcPartGetNext(c, part)));
|
||||||
|
|
||||||
|
opcContainerClose(c, OPC_CLOSE_NOW);
|
||||||
|
|
||||||
|
if (buf.cur > 0) {
|
||||||
|
dyn_buffer_write_char(&buf, '\0');
|
||||||
|
|
||||||
|
meta_line_t *meta = malloc(sizeof(meta_line_t) + buf.cur);
|
||||||
|
meta->key = MetaContent;
|
||||||
|
strcpy(meta->strval, buf.buf);
|
||||||
|
APPEND_META(doc, meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_buffer_destroy(&buf);
|
||||||
|
}
|
||||||
8
src/parsing/doc.h
Normal file
8
src/parsing/doc.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIST2_DOC_H
|
||||||
|
#define SIST2_DOC_H
|
||||||
|
|
||||||
|
#include "src/sist.h"
|
||||||
|
|
||||||
|
void parse_doc(void *buf, size_t buf_len, document_t *doc);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -147,6 +147,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
FT_Face face;
|
FT_Face face;
|
||||||
FT_Error err = FT_New_Memory_Face(ft_lib, (unsigned char *) buf, buf_len, 0, &face);
|
FT_Error err = FT_New_Memory_Face(ft_lib, (unsigned char *) buf, buf_len, 0, &face);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_ERRORF(doc->filepath, "(font.c) FT_New_Memory_Face() returned error code [%d] %s", err, ft_error_string(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +177,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
|
|
||||||
err = FT_Set_Pixel_Sizes(face, 0, pixel);
|
err = FT_Set_Pixel_Sizes(face, 0, pixel);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "(font.c) FT_Set_Pixel_Sizes() returned error code [%d] %s", err, ft_error_string(err))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +196,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
c = c >= 'a' && c <= 'z' ? c - 32 : c + 32;
|
c = c >= 'a' && c <= 'z' ? c - 32 : c + 32;
|
||||||
err = FT_Load_Char(face, c, FT_LOAD_NO_HINTING | FT_LOAD_RENDER);
|
err = FT_Load_Char(face, c, FT_LOAD_NO_HINTING | FT_LOAD_RENDER);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "(font.c) FT_Load_Char() returned error code [%d] %s", err, ft_error_string(err));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ AVFrame *scale_frame(const AVCodecContext *decoder, const AVFrame *frame, int si
|
|||||||
return scaled_frame;
|
return scaled_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int stream_idx) {
|
__always_inline
|
||||||
|
AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int stream_idx, document_t *doc) {
|
||||||
AVFrame *frame = av_frame_alloc();
|
AVFrame *frame = av_frame_alloc();
|
||||||
|
|
||||||
AVPacket avPacket;
|
AVPacket avPacket;
|
||||||
@@ -90,9 +91,12 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
int read_frame_ret = av_read_frame(pFormatCtx, &avPacket);
|
int read_frame_ret = av_read_frame(pFormatCtx, &avPacket);
|
||||||
|
|
||||||
if (read_frame_ret != 0) {
|
if (read_frame_ret != 0) {
|
||||||
// if (read_frame_ret != AVERROR_EOF) {
|
if (read_frame_ret != AVERROR_EOF) {
|
||||||
// fprintf(stderr, "Error reading frame: %d\n", read_frame_ret);
|
LOG_WARNINGF(doc->filepath,
|
||||||
// }
|
"(media.c) avcodec_read_frame() returned error code [%d] %s",
|
||||||
|
read_frame_ret, av_err2str(read_frame_ret)
|
||||||
|
)
|
||||||
|
}
|
||||||
av_frame_free(&frame);
|
av_frame_free(&frame);
|
||||||
av_packet_unref(&avPacket);
|
av_packet_unref(&avPacket);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -109,7 +113,10 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
// Feed it to decoder
|
// Feed it to decoder
|
||||||
int decode_ret = avcodec_send_packet(decoder, &avPacket);
|
int decode_ret = avcodec_send_packet(decoder, &avPacket);
|
||||||
if (decode_ret != 0) {
|
if (decode_ret != 0) {
|
||||||
printf("Error decoding frame: %s\n", av_err2str(decode_ret));
|
LOG_WARNINGF(doc->filepath,
|
||||||
|
"(media.c) avcodec_send_packet() returned error code [%d] %s",
|
||||||
|
decode_ret, av_err2str(decode_ret)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
av_packet_unref(&avPacket);
|
av_packet_unref(&avPacket);
|
||||||
receive_ret = avcodec_receive_frame(decoder, frame);
|
receive_ret = avcodec_receive_frame(decoder, frame);
|
||||||
@@ -152,7 +159,8 @@ void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) {
|
void
|
||||||
|
append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) {
|
||||||
|
|
||||||
if (is_video) {
|
if (is_video) {
|
||||||
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
||||||
@@ -259,7 +267,7 @@ void parse_media(AVFormatContext *pFormatCtx, document_t *doc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFrame *frame = read_frame(pFormatCtx, decoder, video_stream);
|
AVFrame *frame = read_frame(pFormatCtx, decoder, video_stream, doc);
|
||||||
if (frame == NULL) {
|
if (frame == NULL) {
|
||||||
avcodec_free_context(&decoder);
|
avcodec_free_context(&decoder);
|
||||||
avformat_close_input(&pFormatCtx);
|
avformat_close_input(&pFormatCtx);
|
||||||
@@ -308,12 +316,14 @@ void parse_media_filename(const char *filepath, document_t *doc) {
|
|||||||
|
|
||||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||||
if (pFormatCtx == NULL) {
|
if (pFormatCtx == NULL) {
|
||||||
fprintf(stderr, "Could not allocate AVFormatContext! %s \n", filepath);
|
LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
fprintf(stderr, "media error: %s %s\n", filepath, av_err2str(res));
|
LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res))
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
avformat_free_context(pFormatCtx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +346,7 @@ void parse_media_vfile(struct vfile *f, document_t *doc) {
|
|||||||
|
|
||||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||||
if (pFormatCtx == NULL) {
|
if (pFormatCtx == NULL) {
|
||||||
fprintf(stderr, "Could not allocate AVFormatContext! %s \n", f->filepath);
|
LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,13 +359,22 @@ void parse_media_vfile(struct vfile *f, document_t *doc) {
|
|||||||
int res = avformat_open_input(&pFormatCtx, "", NULL, NULL);
|
int res = avformat_open_input(&pFormatCtx, "", NULL, NULL);
|
||||||
if (res == -5) {
|
if (res == -5) {
|
||||||
// Tried to parse media that requires seek
|
// Tried to parse media that requires seek
|
||||||
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
avformat_free_context(pFormatCtx);
|
||||||
return;
|
return;
|
||||||
} else if(res < 0) {
|
} else if (res < 0) {
|
||||||
fprintf(stderr, "media error: %s %s\n", f->filepath, av_err2str(res));
|
LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res))
|
||||||
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
avformat_free_context(pFormatCtx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_media(pFormatCtx, doc);
|
parse_media(pFormatCtx, doc);
|
||||||
av_free(io_ctx);
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
#define ARC_FILTER_MASK 0x08000000
|
#define ARC_FILTER_MASK 0x08000000
|
||||||
#define IS_ARC_FILTER(mime_id) (mime_id & ARC_FILTER_MASK) == ARC_FILTER_MASK
|
#define IS_ARC_FILTER(mime_id) (mime_id & ARC_FILTER_MASK) == ARC_FILTER_MASK
|
||||||
|
|
||||||
|
#define DOC_MASK 0x04000000
|
||||||
|
#define IS_DOC(mime_id) (mime_id & DOC_MASK) == DOC_MASK
|
||||||
|
|
||||||
enum major_mime {
|
enum major_mime {
|
||||||
MimeInvalid = 0,
|
MimeInvalid = 0,
|
||||||
MimeModel = 1,
|
MimeModel = 1,
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ enum mime {
|
|||||||
application_vnd_oasis_opendocument_presentation=655424,
|
application_vnd_oasis_opendocument_presentation=655424,
|
||||||
application_vnd_oasis_opendocument_spreadsheet=655425,
|
application_vnd_oasis_opendocument_spreadsheet=655425,
|
||||||
application_vnd_oasis_opendocument_text=655426,
|
application_vnd_oasis_opendocument_text=655426,
|
||||||
application_vnd_openxmlformats_officedocument_presentationml_presentation=655427,
|
application_vnd_openxmlformats_officedocument_presentationml_presentation=655427 | 0x04000000,
|
||||||
application_vnd_openxmlformats_officedocument_spreadsheetml_sheet=655428,
|
application_vnd_openxmlformats_officedocument_spreadsheetml_sheet=655428 | 0x04000000,
|
||||||
application_vnd_openxmlformats_officedocument_wordprocessingml_document=655429,
|
application_vnd_openxmlformats_officedocument_wordprocessingml_document=655429 | 0x04000000,
|
||||||
application_vnd_symbian_install=655430,
|
application_vnd_symbian_install=655430,
|
||||||
application_vnd_tcpdump_pcap=655431,
|
application_vnd_tcpdump_pcap=655431,
|
||||||
application_vnd_wap_wmlc=655432,
|
application_vnd_wap_wmlc=655432,
|
||||||
@@ -1193,6 +1193,8 @@ g_hash_table_insert(ext_table, "srt", (gpointer)text_plain);
|
|||||||
g_hash_table_insert(ext_table, "nfo", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "nfo", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "sfv", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "sfv", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "m3u", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "m3u", (gpointer)text_plain);
|
||||||
|
g_hash_table_insert(ext_table, "csv", (gpointer)text_plain);
|
||||||
|
g_hash_table_insert(ext_table, "eml", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "rt", (gpointer)text_richtext);
|
g_hash_table_insert(ext_table, "rt", (gpointer)text_richtext);
|
||||||
g_hash_table_insert(ext_table, "rtf", (gpointer)text_richtext);
|
g_hash_table_insert(ext_table, "rtf", (gpointer)text_richtext);
|
||||||
g_hash_table_insert(ext_table, "rtx", (gpointer)text_richtext);
|
g_hash_table_insert(ext_table, "rtx", (gpointer)text_richtext);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <src/ctx.h>
|
|
||||||
#include "src/sist.h"
|
#include "src/sist.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
@@ -9,8 +8,7 @@ int fs_read(struct vfile *f, void *buf, size_t size) {
|
|||||||
if (f->fd == -1) {
|
if (f->fd == -1) {
|
||||||
f->fd = open(f->filepath, O_RDONLY);
|
f->fd = open(f->filepath, O_RDONLY);
|
||||||
if (f->fd == -1) {
|
if (f->fd == -1) {
|
||||||
perror("open");
|
LOG_ERRORF(f->filepath, "open(): [%d] %s", errno, strerror(errno))
|
||||||
printf("%s\n", f->filepath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +37,7 @@ void *read_all(parse_job_t *job, const char *buf, int bytes_read) {
|
|||||||
|
|
||||||
int ret = job->vfile.read(&job->vfile, full_buf + bytes_read, job->info.st_size - bytes_read);
|
int ret = job->vfile.read(&job->vfile, full_buf + bytes_read, job->info.st_size - bytes_read);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
perror("read");
|
LOG_ERRORF(job->filepath, "read(): [%d] %s", errno, strerror(errno))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +73,12 @@ void parse(void *arg) {
|
|||||||
uuid_generate(doc.uuid);
|
uuid_generate(doc.uuid);
|
||||||
char *buf[PARSE_BUF_SIZE];
|
char *buf[PARSE_BUF_SIZE];
|
||||||
|
|
||||||
|
if (LogCtx.very_verbose) {
|
||||||
|
char uuid_str[UUID_STR_LEN];
|
||||||
|
uuid_unparse(doc.uuid, uuid_str);
|
||||||
|
LOG_DEBUGF(job->filepath, "Starting parse job {%s}", uuid_str)
|
||||||
|
}
|
||||||
|
|
||||||
if (job->info.st_size == 0) {
|
if (job->info.st_size == 0) {
|
||||||
doc.mime = MIME_EMPTY;
|
doc.mime = MIME_EMPTY;
|
||||||
} else if (*(job->filepath + job->ext) != '\0' && (job->ext - job->base != 1)) {
|
} else if (*(job->filepath + job->ext) != '\0' && (job->ext - job->base != 1)) {
|
||||||
@@ -87,6 +91,7 @@ void parse(void *arg) {
|
|||||||
// Get mime type with libmagic
|
// Get mime type with libmagic
|
||||||
bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
|
bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
|
||||||
if (bytes_read == -1) {
|
if (bytes_read == -1) {
|
||||||
|
LOG_WARNINGF(job->filepath, "read() Error: %s", strerror(errno))
|
||||||
CLOSE_FILE(job->vfile)
|
CLOSE_FILE(job->vfile)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -95,7 +100,7 @@ void parse(void *arg) {
|
|||||||
if (magic_mime_str != NULL) {
|
if (magic_mime_str != NULL) {
|
||||||
doc.mime = mime_get_mime_by_string(ScanCtx.mime_table, magic_mime_str);
|
doc.mime = mime_get_mime_by_string(ScanCtx.mime_table, magic_mime_str);
|
||||||
if (doc.mime == 0) {
|
if (doc.mime == 0) {
|
||||||
fprintf(stderr, "Couldn't find mime %s, %s\n", magic_mime_str, job->filepath + job->base);
|
LOG_WARNINGF(job->filepath, "Couldn't find mime %s", magic_mime_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,6 +142,13 @@ void parse(void *arg) {
|
|||||||
(IS_ARC_FILTER(doc.mime) && should_parse_filtered_file(doc.filepath, doc.ext))
|
(IS_ARC_FILTER(doc.mime) && should_parse_filtered_file(doc.filepath, doc.ext))
|
||||||
)) {
|
)) {
|
||||||
parse_archive(&job->vfile, &doc);
|
parse_archive(&job->vfile, &doc);
|
||||||
|
} else if (ScanCtx.content_size > 0 && IS_DOC(doc.mime)) {
|
||||||
|
void *doc_buf = read_all(job, (char *) buf, bytes_read);
|
||||||
|
parse_doc(doc_buf, doc.size, &doc);
|
||||||
|
|
||||||
|
if (doc_buf != buf && doc_buf != NULL) {
|
||||||
|
free(doc_buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Parent meta
|
//Parent meta
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
fz_drop_page(ctx, cover);
|
fz_drop_page(ctx, cover);
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
fz_drop_page(ctx, cover);
|
fz_drop_page(ctx, cover);
|
||||||
fz_drop_pixmap(ctx, pixmap);
|
fz_drop_pixmap(ctx, pixmap);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -76,6 +78,7 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
fz_drop_pixmap(ctx, pixmap);
|
fz_drop_pixmap(ctx, pixmap);
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_new_buffer_from_pixmap_as_png() returned error code [%d] %s", err, ctx->error.message)
|
||||||
fz_drop_page(ctx, cover);
|
fz_drop_page(ctx, cover);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -83,14 +86,23 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
return cover;
|
return cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fz_noop_callback(__attribute__((unused)) void *user, __attribute__((unused)) const char *message) {}
|
void fz_err_callback(void *user, __attribute__((unused)) const char *message) {
|
||||||
|
if (LogCtx.verbose) {
|
||||||
|
document_t *doc = (document_t*) user;
|
||||||
|
LOG_WARNINGF(doc->filepath, "FZ: %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_ctx(fz_context *ctx) {
|
__always_inline
|
||||||
|
void init_ctx(fz_context *ctx, document_t *doc) {
|
||||||
fz_disable_icc(ctx);
|
fz_disable_icc(ctx);
|
||||||
fz_register_document_handlers(ctx);
|
fz_register_document_handlers(ctx);
|
||||||
ctx->warn.print = fz_noop_callback;
|
|
||||||
ctx->error.print = fz_noop_callback;
|
ctx->warn.print_user = doc;
|
||||||
|
ctx->warn.print = fz_err_callback;
|
||||||
|
ctx->error.print_user = doc;
|
||||||
|
ctx->error.print = fz_err_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
||||||
@@ -125,7 +137,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
}
|
}
|
||||||
fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
||||||
|
|
||||||
init_ctx(ctx);
|
init_ctx(ctx, doc);
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
@@ -171,6 +183,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_count_pages() returned error code [%d] %s", err, ctx->error.message)
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
fz_drop_document(ctx, fzdoc);
|
fz_drop_document(ctx, fzdoc);
|
||||||
fz_drop_context(ctx);
|
fz_drop_context(ctx);
|
||||||
@@ -210,6 +223,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
fz_catch(ctx)
|
fz_catch(ctx)
|
||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
text_buffer_destroy(&text_buf);
|
text_buffer_destroy(&text_buf);
|
||||||
fz_drop_page(ctx, page);
|
fz_drop_page(ctx, page);
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
@@ -234,6 +248,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
text_buffer_destroy(&text_buf);
|
text_buffer_destroy(&text_buf);
|
||||||
fz_drop_page(ctx, page);
|
fz_drop_page(ctx, page);
|
||||||
fz_drop_stext_page(ctx, stext);
|
fz_drop_stext_page(ctx, stext);
|
||||||
@@ -272,4 +287,3 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
fz_drop_document(ctx, fzdoc);
|
fz_drop_document(ctx, fzdoc);
|
||||||
fz_drop_context(ctx);
|
fz_drop_context(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/sist.h
14
src/sist.h
@@ -12,11 +12,11 @@
|
|||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
#include <uuid.h>
|
#include <uuid.h>
|
||||||
#include <magic.h>
|
#include <magic.h>
|
||||||
#include <libavformat/avformat.h>
|
#include "libavformat/avformat.h"
|
||||||
#include <libswscale/swscale.h>
|
#include "libswscale/swscale.h"
|
||||||
#include <libswresample/swresample.h>
|
#include "libswresample/swresample.h"
|
||||||
#include <libavcodec/avcodec.h>
|
#include "libavcodec/avcodec.h"
|
||||||
#include <libavutil/imgutils.h>
|
#include "libavutil/imgutils.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <mupdf/fitz.h>
|
#include <mupdf/fitz.h>
|
||||||
#include <mupdf/pdf.h>
|
#include <mupdf/pdf.h>
|
||||||
@@ -30,6 +30,8 @@
|
|||||||
#include "freetype/freetype.h"
|
#include "freetype/freetype.h"
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
|
#include <opc/opc.h>
|
||||||
|
#include <libxml/xmlstring.h>
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
#include <onion/onion.h>
|
#include <onion/onion.h>
|
||||||
@@ -55,7 +57,9 @@
|
|||||||
#include "parsing/media.h"
|
#include "parsing/media.h"
|
||||||
#include "parsing/font.h"
|
#include "parsing/font.h"
|
||||||
#include "parsing/arc.h"
|
#include "parsing/arc.h"
|
||||||
|
#include "parsing/doc.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
#include "log.h"
|
||||||
#include "utf8.h/utf8.h"
|
#include "utf8.h/utf8.h"
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
|
|||||||
10
src/tpool.c
10
src/tpool.c
@@ -136,6 +136,7 @@ static void *tpool_worker(void *arg) {
|
|||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Executing cleaup function")
|
||||||
pool->cleanup_func();
|
pool->cleanup_func();
|
||||||
|
|
||||||
pthread_cond_signal(&(pool->working_cond));
|
pthread_cond_signal(&(pool->working_cond));
|
||||||
@@ -144,6 +145,7 @@ static void *tpool_worker(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tpool_wait(tpool_t *pool) {
|
void tpool_wait(tpool_t *pool) {
|
||||||
|
LOG_INFO("tpool.c", "Waiting for worker threads to finish")
|
||||||
pthread_mutex_lock(&(pool->work_mutex));
|
pthread_mutex_lock(&(pool->work_mutex));
|
||||||
while (1) {
|
while (1) {
|
||||||
if (pool->done_cnt < pool->work_cnt) {
|
if (pool->done_cnt < pool->work_cnt) {
|
||||||
@@ -159,6 +161,8 @@ void tpool_wait(tpool_t *pool) {
|
|||||||
}
|
}
|
||||||
progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Worker threads finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
void tpool_destroy(tpool_t *pool) {
|
void tpool_destroy(tpool_t *pool) {
|
||||||
@@ -166,6 +170,8 @@ void tpool_destroy(tpool_t *pool) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Destroying thread pool")
|
||||||
|
|
||||||
pthread_mutex_lock(&(pool->work_mutex));
|
pthread_mutex_lock(&(pool->work_mutex));
|
||||||
tpool_work_t *work = pool->work_head;
|
tpool_work_t *work = pool->work_head;
|
||||||
while (work != NULL) {
|
while (work != NULL) {
|
||||||
@@ -185,6 +191,8 @@ void tpool_destroy(tpool_t *pool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Final cleanup")
|
||||||
|
|
||||||
pthread_mutex_destroy(&(pool->work_mutex));
|
pthread_mutex_destroy(&(pool->work_mutex));
|
||||||
pthread_cond_destroy(&(pool->has_work_cond));
|
pthread_cond_destroy(&(pool->has_work_cond));
|
||||||
pthread_cond_destroy(&(pool->working_cond));
|
pthread_cond_destroy(&(pool->working_cond));
|
||||||
@@ -220,6 +228,8 @@ tpool_t *tpool_create(size_t thread_cnt, void cleanup_func()) {
|
|||||||
|
|
||||||
void tpool_start(tpool_t *pool) {
|
void tpool_start(tpool_t *pool) {
|
||||||
|
|
||||||
|
LOG_INFOF("tpool.c", "Starting thread pool with %d threads", pool->thread_cnt)
|
||||||
|
|
||||||
for (size_t i = 0; i < pool->thread_cnt; i++) {
|
for (size_t i = 0; i < pool->thread_cnt; i++) {
|
||||||
pthread_create(&pool->threads[i], NULL, tpool_worker, pool);
|
pthread_create(&pool->threads[i], NULL, tpool_worker, pool);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -2,6 +2,23 @@
|
|||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.path-row {
|
||||||
|
display: -ms-flexbox;
|
||||||
|
display: flex;
|
||||||
|
-ms-flex-align: start;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-container {
|
||||||
|
margin-left: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.path-line {
|
||||||
|
color: #BBB;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #00BCD4;
|
color: #00BCD4;
|
||||||
}
|
}
|
||||||
@@ -24,7 +41,11 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sub-document {
|
.sub-document {
|
||||||
background: #37474F;
|
background: #37474F !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item.sub-document {
|
||||||
|
border-top: 1px solid #646464 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sub-document .text-muted {
|
.sub-document .text-muted {
|
||||||
@@ -112,6 +133,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
|
width: 100%;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|||||||
1
web/css/jquery.toast.min.css
vendored
Normal file
1
web/css/jquery.toast.min.css
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.jq-toast-wrap,.jq-toast-wrap *{margin:0;padding:0}.jq-toast-wrap{display:block;position:fixed;width:250px;pointer-events:none!important;letter-spacing:normal;z-index:9000!important}.jq-toast-wrap.bottom-left{bottom:20px;left:20px}.jq-toast-wrap.bottom-right{bottom:20px;right:40px}.jq-toast-wrap.top-left{top:20px;left:20px}.jq-toast-wrap.top-right{top:20px;right:40px}.jq-toast-single{display:block;width:100%;padding:10px;margin:0 0 5px;border-radius:4px;font-size:12px;font-family:arial,sans-serif;line-height:17px;position:relative;pointer-events:all!important;background-color:#444;color:#fff}.jq-toast-single h2{font-family:arial,sans-serif;font-size:14px;margin:0 0 7px;background:0 0;color:inherit;line-height:inherit;letter-spacing:normal}.jq-toast-single a{color:#eee;text-decoration:none;font-weight:700;border-bottom:1px solid #fff;padding-bottom:3px;font-size:12px}.jq-toast-single ul{margin:0 0 0 15px;background:0 0;padding:0}.jq-toast-single ul li{list-style-type:disc!important;line-height:17px;background:0 0;margin:0;padding:0;letter-spacing:normal}.close-jq-toast-single{position:absolute;top:3px;right:7px;font-size:14px;cursor:pointer}.jq-toast-loader{display:block;position:absolute;top:-2px;height:5px;width:0;left:0;border-radius:5px;background:red}.jq-toast-loaded{width:100%}.jq-has-icon{padding:10px 10px 10px 50px;background-repeat:no-repeat;background-position:10px}.jq-icon-info{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGwSURBVEhLtZa9SgNBEMc9sUxxRcoUKSzSWIhXpFMhhYWFhaBg4yPYiWCXZxBLERsLRS3EQkEfwCKdjWJAwSKCgoKCcudv4O5YLrt7EzgXhiU3/4+b2ckmwVjJSpKkQ6wAi4gwhT+z3wRBcEz0yjSseUTrcRyfsHsXmD0AmbHOC9Ii8VImnuXBPglHpQ5wwSVM7sNnTG7Za4JwDdCjxyAiH3nyA2mtaTJufiDZ5dCaqlItILh1NHatfN5skvjx9Z38m69CgzuXmZgVrPIGE763Jx9qKsRozWYw6xOHdER+nn2KkO+Bb+UV5CBN6WC6QtBgbRVozrahAbmm6HtUsgtPC19tFdxXZYBOfkbmFJ1VaHA1VAHjd0pp70oTZzvR+EVrx2Ygfdsq6eu55BHYR8hlcki+n+kERUFG8BrA0BwjeAv2M8WLQBtcy+SD6fNsmnB3AlBLrgTtVW1c2QN4bVWLATaIS60J2Du5y1TiJgjSBvFVZgTmwCU+dAZFoPxGEEs8nyHC9Bwe2GvEJv2WXZb0vjdyFT4Cxk3e/kIqlOGoVLwwPevpYHT+00T+hWwXDf4AJAOUqWcDhbwAAAAASUVORK5CYII=);background-color:#31708f;color:#d9edf7;border-color:#bce8f1}.jq-icon-warning{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGYSURBVEhL5ZSvTsNQFMbXZGICMYGYmJhAQIJAICYQPAACiSDB8AiICQQJT4CqQEwgJvYASAQCiZiYmJhAIBATCARJy+9rTsldd8sKu1M0+dLb057v6/lbq/2rK0mS/TRNj9cWNAKPYIJII7gIxCcQ51cvqID+GIEX8ASG4B1bK5gIZFeQfoJdEXOfgX4QAQg7kH2A65yQ87lyxb27sggkAzAuFhbbg1K2kgCkB1bVwyIR9m2L7PRPIhDUIXgGtyKw575yz3lTNs6X4JXnjV+LKM/m3MydnTbtOKIjtz6VhCBq4vSm3ncdrD2lk0VgUXSVKjVDJXJzijW1RQdsU7F77He8u68koNZTz8Oz5yGa6J3H3lZ0xYgXBK2QymlWWA+RWnYhskLBv2vmE+hBMCtbA7KX5drWyRT/2JsqZ2IvfB9Y4bWDNMFbJRFmC9E74SoS0CqulwjkC0+5bpcV1CZ8NMej4pjy0U+doDQsGyo1hzVJttIjhQ7GnBtRFN1UarUlH8F3xict+HY07rEzoUGPlWcjRFRr4/gChZgc3ZL2d8oAAAAASUVORK5CYII=);background-color:#8a6d3b;color:#fcf8e3;border-color:#faebcc}.jq-icon-error{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHOSURBVEhLrZa/SgNBEMZzh0WKCClSCKaIYOED+AAKeQQLG8HWztLCImBrYadgIdY+gIKNYkBFSwu7CAoqCgkkoGBI/E28PdbLZmeDLgzZzcx83/zZ2SSXC1j9fr+I1Hq93g2yxH4iwM1vkoBWAdxCmpzTxfkN2RcyZNaHFIkSo10+8kgxkXIURV5HGxTmFuc75B2RfQkpxHG8aAgaAFa0tAHqYFfQ7Iwe2yhODk8+J4C7yAoRTWI3w/4klGRgR4lO7Rpn9+gvMyWp+uxFh8+H+ARlgN1nJuJuQAYvNkEnwGFck18Er4q3egEc/oO+mhLdKgRyhdNFiacC0rlOCbhNVz4H9FnAYgDBvU3QIioZlJFLJtsoHYRDfiZoUyIxqCtRpVlANq0EU4dApjrtgezPFad5S19Wgjkc0hNVnuF4HjVA6C7QrSIbylB+oZe3aHgBsqlNqKYH48jXyJKMuAbiyVJ8KzaB3eRc0pg9VwQ4niFryI68qiOi3AbjwdsfnAtk0bCjTLJKr6mrD9g8iq/S/B81hguOMlQTnVyG40wAcjnmgsCNESDrjme7wfftP4P7SP4N3CJZdvzoNyGq2c/HWOXJGsvVg+RA/k2MC/wN6I2YA2Pt8GkAAAAASUVORK5CYII=);background-color:#a94442;color:#f2dede;border-color:#ebccd1}.jq-icon-success{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLY2AYBfQMgf///3P8+/evAIgvA/FsIF+BavYDDWMBGroaSMMBiE8VC7AZDrIFaMFnii3AZTjUgsUUWUDA8OdAH6iQbQEhw4HyGsPEcKBXBIC4ARhex4G4BsjmweU1soIFaGg/WtoFZRIZdEvIMhxkCCjXIVsATV6gFGACs4Rsw0EGgIIH3QJYJgHSARQZDrWAB+jawzgs+Q2UO49D7jnRSRGoEFRILcdmEMWGI0cm0JJ2QpYA1RDvcmzJEWhABhD/pqrL0S0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg==);color:#dff0d8;background-color:#3c763d;border-color:#d6e9c6}
|
||||||
@@ -2,6 +2,23 @@
|
|||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.path-row {
|
||||||
|
display: -ms-flexbox;
|
||||||
|
display: flex;
|
||||||
|
-ms-flex-align: start;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-container {
|
||||||
|
margin-left: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.path-line {
|
||||||
|
color: #444;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
@@ -16,7 +33,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sub-document {
|
.sub-document {
|
||||||
background: #AB47BC1F;
|
background: #AB47BC1F !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
@@ -82,6 +99,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
|
width: 100%;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|||||||
1
web/js/7_jquery.toast.min.js
vendored
Normal file
1
web/js/7_jquery.toast.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -367,6 +367,10 @@ function createDocLine(hit) {
|
|||||||
const line = document.createElement("div");
|
const line = document.createElement("div");
|
||||||
line.setAttribute("class", "list-group-item flex-column align-items-start");
|
line.setAttribute("class", "list-group-item flex-column align-items-start");
|
||||||
|
|
||||||
|
if (hit["_source"].hasOwnProperty("parent")) {
|
||||||
|
line.classList.add("sub-document");
|
||||||
|
isSubDocument = true;
|
||||||
|
}
|
||||||
|
|
||||||
const title = makeTitle(hit);
|
const title = makeTitle(hit);
|
||||||
|
|
||||||
@@ -396,8 +400,16 @@ function createDocLine(hit) {
|
|||||||
titleDiv.appendChild(contentDiv);
|
titleDiv.appendChild(contentDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pathLine = document.createElement("div");
|
||||||
|
pathLine.setAttribute("class", "path-row");
|
||||||
|
|
||||||
|
let path = document.createElement("div");
|
||||||
|
path.setAttribute("class", "path-line");
|
||||||
|
path.setAttribute("title", hit["_source"]["path"] + "/");
|
||||||
|
path.appendChild(document.createTextNode(hit["_source"]["path"] + "/"));
|
||||||
|
|
||||||
let tagContainer = document.createElement("div");
|
let tagContainer = document.createElement("div");
|
||||||
tagContainer.setAttribute("class", "");
|
tagContainer.setAttribute("class", "tag-container");
|
||||||
|
|
||||||
for (let i = 0; i < tags.length; i++) {
|
for (let i = 0; i < tags.length; i++) {
|
||||||
tagContainer.appendChild(tags[i]);
|
tagContainer.appendChild(tags[i]);
|
||||||
@@ -409,7 +421,9 @@ function createDocLine(hit) {
|
|||||||
sizeTag.setAttribute("class", "text-muted");
|
sizeTag.setAttribute("class", "text-muted");
|
||||||
tagContainer.appendChild(sizeTag);
|
tagContainer.appendChild(sizeTag);
|
||||||
|
|
||||||
titleDiv.appendChild(tagContainer);
|
titleDiv.appendChild(pathLine);
|
||||||
|
pathLine.appendChild(path);
|
||||||
|
pathLine.appendChild(tagContainer);
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,19 @@ if (localStorage.getItem("mode") === null) {
|
|||||||
mode = localStorage.getItem("mode")
|
mode = localStorage.getItem("mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showEsError() {
|
||||||
|
$.toast({
|
||||||
|
heading: "Elasticsearch connection error",
|
||||||
|
text: "sist2 web module encountered an error while connecting " +
|
||||||
|
"to Elasticsearch. See server logs for more information.",
|
||||||
|
stack: false,
|
||||||
|
bgColor: "#a94442",
|
||||||
|
textColor: "#f2dede",
|
||||||
|
position: 'bottom-right',
|
||||||
|
hideAfter: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
jQuery["jsonPost"] = function (url, data) {
|
jQuery["jsonPost"] = function (url, data) {
|
||||||
return jQuery.ajax({
|
return jQuery.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
@@ -26,6 +39,7 @@ jQuery["jsonPost"] = function (url, data) {
|
|||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
contentType: "application/json"
|
contentType: "application/json"
|
||||||
}).fail(err => {
|
}).fail(err => {
|
||||||
|
showEsError();
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -46,19 +60,28 @@ function toggleFuzzy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$.jsonPost("i").then(resp => {
|
$.jsonPost("i").then(resp => {
|
||||||
|
|
||||||
|
const urlIndices = (new URLSearchParams(location.search)).get("i");
|
||||||
|
|
||||||
resp["indices"].forEach(idx => {
|
resp["indices"].forEach(idx => {
|
||||||
const opt = $("<option>")
|
const opt = $("<option>")
|
||||||
.attr("value", idx.id)
|
.attr("value", idx.id)
|
||||||
.append(idx.name);
|
.append(idx.name);
|
||||||
if (!idx.name.includes("(nsfw)")) {
|
|
||||||
opt.attr("selected", !idx.name.includes("(nsfw)"));
|
if (urlIndices) {
|
||||||
|
if (urlIndices.split(",").indexOf(idx.name) !== -1) {
|
||||||
|
opt.attr("selected", true);
|
||||||
|
selectedIndices.push(idx.id);
|
||||||
|
}
|
||||||
|
} else if (!idx.name.includes("(nsfw)")) {
|
||||||
|
opt.attr("selected", true);
|
||||||
selectedIndices.push(idx.id);
|
selectedIndices.push(idx.id);
|
||||||
}
|
}
|
||||||
$("#indices").append(opt);
|
$("#indices").append(opt);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleTreeClick (tree) {
|
function handleTreeClick(tree) {
|
||||||
return (event, node, handler) => {
|
return (event, node, handler) => {
|
||||||
event.preventTreeDefault();
|
event.preventTreeDefault();
|
||||||
|
|
||||||
@@ -127,7 +150,7 @@ $.jsonPost("es", {
|
|||||||
|
|
||||||
function leafTag(tag) {
|
function leafTag(tag) {
|
||||||
const tokens = tag.split(".");
|
const tokens = tag.split(".");
|
||||||
return tokens[tokens.length-1]
|
return tokens[tokens.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tags tree
|
// Tags tree
|
||||||
@@ -145,8 +168,8 @@ $.jsonPost("es", {
|
|||||||
resp["aggregations"]["tags"]["buckets"]
|
resp["aggregations"]["tags"]["buckets"]
|
||||||
.sort((a, b) => a["key"].localeCompare(b["key"]))
|
.sort((a, b) => a["key"].localeCompare(b["key"]))
|
||||||
.forEach(bucket => {
|
.forEach(bucket => {
|
||||||
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
|
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
|
||||||
});
|
});
|
||||||
|
|
||||||
tagMap.push({"text": "All", "id": "any"});
|
tagMap.push({"text": "All", "id": "any"});
|
||||||
tagTree = new InspireTree({
|
tagTree = new InspireTree({
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<nav class="navbar navbar-expand-lg">
|
<nav class="navbar navbar-expand-lg">
|
||||||
<a class="navbar-brand" href="/">sist2</a>
|
<a class="navbar-brand" href="/">sist2</a>
|
||||||
<span class="badge badge-pill version">v1.1.10</span>
|
<span class="badge badge-pill version">v1.1.14</span>
|
||||||
<span class="tagline">Lightning-fast file system indexer and search tool </span>
|
<span class="tagline">Lightning-fast file system indexer and search tool </span>
|
||||||
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
|
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
Reference in New Issue
Block a user