mirror of
https://github.com/simon987/sist2.git
synced 2025-12-12 15:08:53 +00:00
Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| efdde2734e | |||
| 66658fa8f7 | |||
| df41c251e4 | |||
| 3282ab56ba | |||
| 8300838d30 | |||
| c9870a6d3d | |||
| a143cc4fcf | |||
| 9ef1f3781d | |||
| bbee8aa721 | |||
| d22f83c797 | |||
| 50615486a4 | |||
| ca79e4f797 | |||
| 6a9fd08a80 | |||
| cab890dc9b | |||
| b3c4faf2df | |||
| 353937171a | |||
| c80002bea4 | |||
| 56adee9d81 | |||
| d6493d6d5f | |||
| 0967e9676d | |||
| 487e998ea0 | |||
| 919f45c79c | |||
| d42129cfcb | |||
| 754983e34a | |||
| 7c8a3e2f9d | |||
| 3bb24b4453 | |||
| 9a56b959d3 | |||
| 5e3a2dbcc2 | |||
| 573f94f24e | |||
| f5db78a69f | |||
| 5a2820d339 | |||
| b7f13f425c | |||
| d1a2f9b1d5 | |||
| 71f17986db | |||
| acdd2fb3c1 | |||
| 0cda6c00e1 | |||
| 14d0e5a1e1 | |||
| 0d06d39281 | |||
| 80708ca636 | |||
|
|
43b7b40dc4 | ||
| d051f541e2 | |||
| 0eefbac7b4 | |||
| 663f8e21c1 | |||
| 80fbcb2a01 | |||
| 8451109ecd | |||
| d6fe61cfdc | |||
| 254094130f | |||
| eaaa75c04c | |||
| bb87f4270f | |||
| be23201210 | |||
| 9778acda77 | |||
| 8d187926d9 | |||
| 88c37e3523 | |||
| d816dae8b3 | |||
| 4346c3e063 | |||
| 1a1032a8a7 | |||
| 4ab2ba1a02 | |||
| d089601dc5 | |||
| 11df6cc88f | |||
| 373ac01e4e | |||
| 893ff145c5 | |||
| 6111ded77f | |||
| 34cc26b2fd | |||
| 204034d859 | |||
| 16ccc6c0d3 | |||
| 94c617fdc3 | |||
| ebfd7e03ce | |||
| 6931d320a2 | |||
| fc22e52eae | |||
| ba81748a74 | |||
| e72fa1587b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@ bundle*.css
|
|||||||
bundle.js
|
bundle.js
|
||||||
*.a
|
*.a
|
||||||
vgcore.*
|
vgcore.*
|
||||||
|
build/
|
||||||
|
|||||||
42
.gitmodules
vendored
42
.gitmodules
vendored
@@ -4,24 +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"]
|
[submodule "lib/bzip2-1.0.6"]
|
||||||
path = lib/openjpeg
|
path = lib/bzip2-1.0.6
|
||||||
url = https://github.com/uclouvain/openjpeg
|
url = https://github.com/enthought/bzip2-1.0.6
|
||||||
|
[submodule "lib/libmagic"]
|
||||||
|
path = lib/libmagic
|
||||||
|
url = https://github.com/threatstack/libmagic
|
||||||
[submodule "lib/harfbuzz"]
|
[submodule "lib/harfbuzz"]
|
||||||
path = lib/harfbuzz
|
path = lib/harfbuzz
|
||||||
url = https://github.com/harfbuzz/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/tesseract"]
|
||||||
|
path = lib/tesseract
|
||||||
|
url = https://github.com/tesseract-ocr/tesseract
|
||||||
|
[submodule "lib/leptonica"]
|
||||||
|
path = lib/leptonica
|
||||||
|
url = https://github.com/danbloomberg/leptonica
|
||||||
|
[submodule "lib/libtiff"]
|
||||||
|
path = lib/libtiff
|
||||||
|
url = https://gitlab.com/libtiff/libtiff
|
||||||
|
[submodule "lib/libpng"]
|
||||||
|
path = lib/libpng
|
||||||
|
url = https://github.com/glennrp/libpng
|
||||||
|
|||||||
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"
|
||||||
|
})
|
||||||
296
CMakeLists.txt
296
CMakeLists.txt
@@ -1,94 +1,56 @@
|
|||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
|
||||||
option(WITH_SIST2 "Build main executable" ON)
|
|
||||||
option(WITH_SIST2_SCAN "Build scan executable" ON)
|
|
||||||
|
|
||||||
project(sist2 C)
|
project(sist2 C)
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")
|
||||||
|
|
||||||
if (WITH_SIST2)
|
add_executable(
|
||||||
add_executable(
|
sist2
|
||||||
sist2
|
src/main.c
|
||||||
src/main.c
|
src/sist.h
|
||||||
src/sist.h
|
src/io/walk.h src/io/walk.c
|
||||||
src/io/walk.h src/io/walk.c
|
src/parsing/media.h src/parsing/media.c
|
||||||
src/parsing/media.h src/parsing/media.c
|
src/parsing/pdf.h src/parsing/pdf.c
|
||||||
src/parsing/pdf.h src/parsing/pdf.c
|
src/io/store.h src/io/store.c
|
||||||
src/io/store.h src/io/store.c
|
src/tpool.h src/tpool.c
|
||||||
src/tpool.h src/tpool.c
|
src/parsing/parse.h src/parsing/parse.c
|
||||||
src/parsing/parse.h src/parsing/parse.c
|
src/io/serialize.h src/io/serialize.c
|
||||||
src/io/serialize.h src/io/serialize.c
|
src/parsing/mime.h src/parsing/mime.c src/parsing/mime_generated.c
|
||||||
src/parsing/mime.h src/parsing/mime.c src/parsing/mime_generated.c
|
src/parsing/text.h src/parsing/text.c
|
||||||
src/parsing/text.h src/parsing/text.c
|
src/index/web.c src/index/web.h
|
||||||
src/index/web.c src/index/web.h
|
src/web/serve.c src/web/serve.h
|
||||||
src/web/serve.c src/web/serve.h
|
src/web/auth_basic.h src/web/auth_basic.c
|
||||||
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
|
||||||
|
|
||||||
# cJSON
|
# cJSON
|
||||||
cJSON/cJSON.h cJSON/cJSON.c
|
cJSON/cJSON.h cJSON/cJSON.c
|
||||||
|
|
||||||
# LMDB
|
# LMDB
|
||||||
lmdb/libraries/liblmdb/lmdb.h lmdb/libraries/liblmdb/mdb.c
|
lmdb/libraries/liblmdb/lmdb.h lmdb/libraries/liblmdb/mdb.c
|
||||||
lmdb/libraries/liblmdb/midl.h lmdb/libraries/liblmdb/midl.c
|
lmdb/libraries/liblmdb/midl.h lmdb/libraries/liblmdb/midl.c
|
||||||
src/cli.c src/cli.h
|
src/cli.c src/cli.h
|
||||||
|
|
||||||
# utf8.h
|
# utf8.h
|
||||||
utf8.h/utf8.h
|
utf8.h/utf8.h
|
||||||
)
|
)
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (WITH_SIST2_SCAN)
|
|
||||||
add_executable(
|
|
||||||
sist2_scan
|
|
||||||
src/main.c
|
|
||||||
src/sist.h
|
|
||||||
src/io/walk.h src/io/walk.c
|
|
||||||
src/parsing/media.h src/parsing/media.c
|
|
||||||
src/parsing/pdf.h src/parsing/pdf.c
|
|
||||||
src/io/store.h src/io/store.c
|
|
||||||
src/tpool.h src/tpool.c
|
|
||||||
src/parsing/parse.h src/parsing/parse.c
|
|
||||||
src/io/serialize.h src/io/serialize.c
|
|
||||||
src/parsing/mime.h src/parsing/mime.c src/parsing/mime_generated.c
|
|
||||||
src/parsing/text.h src/parsing/text.c
|
|
||||||
src/util.c src/util.h
|
|
||||||
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
|
||||||
|
|
||||||
# argparse
|
|
||||||
argparse/argparse.h argparse/argparse.c
|
|
||||||
|
|
||||||
# cJSON
|
|
||||||
cJSON/cJSON.h cJSON/cJSON.c
|
|
||||||
|
|
||||||
# LMDB
|
|
||||||
lmdb/libraries/liblmdb/lmdb.h lmdb/libraries/liblmdb/mdb.c
|
|
||||||
lmdb/libraries/liblmdb/midl.h lmdb/libraries/liblmdb/midl.c
|
|
||||||
src/cli.c src/cli.h
|
|
||||||
|
|
||||||
# utf8.h
|
|
||||||
utf8.h/utf8.h
|
|
||||||
)
|
|
||||||
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(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})
|
||||||
@@ -98,145 +60,87 @@ list(REMOVE_ITEM GLIB_LIBRARIES pcre)
|
|||||||
list(REMOVE_ITEM GOBJECT_LIBRARIES pcre)
|
list(REMOVE_ITEM GOBJECT_LIBRARIES pcre)
|
||||||
list(REMOVE_ITEM UUID_LIBRARIES pcre)
|
list(REMOVE_ITEM UUID_LIBRARIES pcre)
|
||||||
|
|
||||||
if (WITH_SIST2)
|
target_include_directories(
|
||||||
target_include_directories(
|
sist2 PUBLIC
|
||||||
sist2 PUBLIC
|
${GOBJECT_INCLUDE_DIRS}
|
||||||
${LIBMAGIC_INCLUDE_DIRS}
|
${GLIB_INCLUDE_DIRS}
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lib/ffmpeg/
|
||||||
${OPENSSL_INCLUDE_DIR}
|
${FREETYPE_INCLUDE_DIRS}
|
||||||
${FFMPEG_INCLUDE_DIRS}
|
${UUID_INCLUDE_DIRS}
|
||||||
${GLIB_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
||||||
${UUID_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
||||||
${PROJECT_SOURCE_DIR}/
|
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
||||||
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
${PROJECT_SOURCE_DIR}/include/
|
||||||
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
/usr/include/libxml2/
|
||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
${PROJECT_SOURCE_DIR}/lib/tesseract/include/
|
||||||
)
|
)
|
||||||
target_link_directories(
|
target_link_directories(
|
||||||
sist2 PUBLIC
|
sist2 PUBLIC
|
||||||
${UUID_LIBRARY_DIRS}
|
${UUID_LIBRARY_DIRS}
|
||||||
${FFMPEG_LIBRARY_DIRS}
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
target_compile_options(sist2
|
||||||
|
PRIVATE
|
||||||
|
-Ofast
|
||||||
|
# -march=native
|
||||||
|
-fPIC
|
||||||
|
-fno-stack-protector
|
||||||
|
-fomit-frame-pointer
|
||||||
|
)
|
||||||
|
|
||||||
target_compile_options(sist2
|
TARGET_LINK_LIBRARIES(
|
||||||
PRIVATE
|
sist2
|
||||||
-Ofast
|
|
||||||
# -march=native
|
|
||||||
-fno-stack-protector
|
|
||||||
-fomit-frame-pointer
|
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(
|
${GLIB_LIBRARIES}
|
||||||
sist2
|
${GOBJECT_LIBRARIES}
|
||||||
|
${UUID_LIBRARIES}
|
||||||
|
|
||||||
${GLIB_LIBRARIES}
|
# ffmpeg
|
||||||
${GOBJECT_LIBRARIES}
|
${PROJECT_SOURCE_DIR}/lib/libavcodec.a
|
||||||
${UUID_LIBRARIES}
|
${PROJECT_SOURCE_DIR}/lib/libavformat.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
||||||
|
|
||||||
# ffmpeg
|
# mupdf
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavcodec.a
|
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavformat.a
|
${PROJECT_SOURCE_DIR}/lib/libmupdf-third.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
|
||||||
# ${FFMPEG_LIBRARIES}
|
|
||||||
# swscale
|
|
||||||
|
|
||||||
# mupdf
|
# onion
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf-third.a
|
|
||||||
|
|
||||||
# onion
|
pthread
|
||||||
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
|
||||||
|
|
||||||
pthread
|
m
|
||||||
curl
|
bz2
|
||||||
m
|
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
||||||
bz2
|
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
||||||
magic
|
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
||||||
harfbuzz
|
freetype
|
||||||
openjp2
|
archive
|
||||||
freetype
|
|
||||||
)
|
|
||||||
|
|
||||||
endif ()
|
xml2
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libmce.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libopc.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libopc/libplib.a
|
||||||
|
|
||||||
if (WITH_SIST2_SCAN)
|
${PROJECT_SOURCE_DIR}/lib/libtesseract.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/liblept.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libtiff.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libpng16.a
|
||||||
|
stdc++
|
||||||
|
|
||||||
set_target_properties(
|
# curl
|
||||||
sist2_scan
|
${PROJECT_SOURCE_DIR}/lib/libcurl.a
|
||||||
PROPERTIES COMPILE_DEFINITIONS SIST_SCAN_ONLY
|
${PROJECT_SOURCE_DIR}/lib/libcrypto.a
|
||||||
)
|
${PROJECT_SOURCE_DIR}/lib/libssl.a
|
||||||
set_target_properties(
|
dl
|
||||||
sist2_scan
|
)
|
||||||
PROPERTIES
|
|
||||||
COMPILE_DEFINITIONS SIST_SCAN_ONLY
|
|
||||||
LINK_FLAGS -static
|
|
||||||
)
|
|
||||||
target_include_directories(
|
|
||||||
sist2_scan PUBLIC
|
|
||||||
${LIBMAGIC_INCLUDE_DIRS}
|
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
|
||||||
${OPENSSL_INCLUDE_DIR}
|
|
||||||
${FFMPEG_INCLUDE_DIRS}
|
|
||||||
${GLIB_INCLUDE_DIRS}
|
|
||||||
${UUID_INCLUDE_DIRS}
|
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
|
||||||
${PROJECT_SOURCE_DIR}/
|
|
||||||
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
|
||||||
)
|
|
||||||
target_link_directories(
|
|
||||||
sist2_scan PUBLIC
|
|
||||||
${UUID_LIBRARY_DIRS}
|
|
||||||
${FFMPEG_LIBRARY_DIRS}
|
|
||||||
)
|
|
||||||
target_compile_options(sist2_scan
|
|
||||||
PRIVATE
|
|
||||||
-Ofast
|
|
||||||
# -march=native
|
|
||||||
-fno-stack-protector
|
|
||||||
-fomit-frame-pointer
|
|
||||||
)
|
|
||||||
TARGET_LINK_LIBRARIES(
|
|
||||||
sist2_scan
|
|
||||||
|
|
||||||
${GLIB_LIBRARIES}
|
|
||||||
${GOBJECT_LIBRARIES}
|
|
||||||
${UUID_LIBRARIES}
|
|
||||||
|
|
||||||
# ffmpeg
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavcodec.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavformat.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
|
||||||
|
|
||||||
# mupdf
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf-third.a
|
|
||||||
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libbz2.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
|
||||||
|
|
||||||
pthread
|
|
||||||
m
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
|
||||||
freetype
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
before_sist2
|
before_sist2
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/before_build.sh
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/before_build.sh
|
||||||
)
|
)
|
||||||
|
|
||||||
IF (WITH_SIST2)
|
add_dependencies(sist2 before_sist2)
|
||||||
add_dependencies(sist2 before_sist2)
|
|
||||||
else ()
|
|
||||||
add_dependencies(sist2_scan before_sist2)
|
|
||||||
endif ()
|
|
||||||
|
|||||||
22
Docker/Dockerfile
Normal file
22
Docker/Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
FROM ubuntu:19.10
|
||||||
|
MAINTAINER simon987 <me@simon987.net>
|
||||||
|
|
||||||
|
RUN apt update
|
||||||
|
RUN apt install -y libglib2.0-0 libcurl4 libmagic1 libharfbuzz-bin libopenjp2-7 libarchive13 liblzma5 libzstd1 liblz4-1 \
|
||||||
|
curl libtiff5 libpng16-16
|
||||||
|
|
||||||
|
RUN mkdir -p /usr/share/tessdata && \
|
||||||
|
cd /usr/share/tessdata/ && \
|
||||||
|
curl -o /usr/share/tessdata/hin.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/hin.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/jpn.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/jpn.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/eng.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/eng.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/fra.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/fra.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/rus.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/rus.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/spa.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/spa.traineddata && ls -lh
|
||||||
|
|
||||||
|
ADD sist2 /root/sist2
|
||||||
|
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
ENV LC_ALL C.UTF-8
|
||||||
|
|
||||||
|
ENTRYPOINT ["/root/sist2"]
|
||||||
15
Docker/build.sh
Executable file
15
Docker/build.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
rm ./sist2
|
||||||
|
cp ../sist2 .
|
||||||
|
strip sist2
|
||||||
|
|
||||||
|
version=$(./sist2 --version)
|
||||||
|
|
||||||
|
echo "Version ${version}"
|
||||||
|
docker build . -t simon987/sist2:${version} -t simon987/sist2:latest \
|
||||||
|
-t docker.pkg.github.com/simon987/sist2/sist2:latest -t docker.pkg.github.com/simon987/sist2/sist2:${version}
|
||||||
|
docker push simon987/sist2:${version}
|
||||||
|
docker push simon987/sist2:latest
|
||||||
|
docker push docker.pkg.github.com/simon987/sist2/sist2:latest
|
||||||
|
docker push docker.pkg.github.com/simon987/sist2/sist2:${version}
|
||||||
|
|
||||||
|
docker run --rm -it simon987/sist2 -v
|
||||||
104
README.md
104
README.md
@@ -1,5 +1,6 @@
|
|||||||

|

|
||||||
[](https://www.codefactor.io/repository/github/simon987/sist2)
|
[](https://www.codefactor.io/repository/github/simon987/sist2)
|
||||||
|
[/statusIcon)](https://files.simon987.net/artifacts/Sist2/Build/)
|
||||||
|
|
||||||
# sist2
|
# sist2
|
||||||
|
|
||||||
@@ -11,25 +12,34 @@ sist2 (Simple incremental search tool)
|
|||||||
|
|
||||||
* Fast, low memory usage, multi-threaded
|
* Fast, low memory usage, multi-threaded
|
||||||
* Portable (all its features are packaged in a single executable)
|
* Portable (all its features are packaged in a single executable)
|
||||||
* Extracts text from common file types\*
|
* Extracts text from common file types \*
|
||||||
* Generates thumbnails\*
|
* Generates thumbnails \*
|
||||||
* Incremental scanning
|
* Incremental scanning
|
||||||
|
* Automatic tagging from file attributes via [user scripts](scripting/README.md)
|
||||||
|
* Recursive scan inside archive files \*\*
|
||||||
|
* OCR support with tesseract \*\*\*
|
||||||
|
|
||||||
|
|
||||||
\* See [format support](#format-support)
|
\* See [format support](#format-support)
|
||||||
|
\*\* See [Archive files](#archive-files)
|
||||||
|
\*\*\* See [OCR](#ocr)
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
1. Have an [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) instance running
|
1. Have an [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) instance running
|
||||||
1. Download the [latest sist2 release](https://github.com/simon987/sist2/releases)
|
1.
|
||||||
|
1. Download the [latest sist2 release](https://github.com/simon987/sist2/releases) *
|
||||||
|
1. *(or)* Download a [development snapshot](https://files.simon987.net/artifacts/Sist2/Build/) *(Not recommended!)*
|
||||||
|
1. *(or)* `docker pull simon987/sist2:latest`
|
||||||
|
|
||||||
|
|
||||||
*Windows users*: `sist2` runs under [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
|
\* *Windows users*: **sist2** runs under [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
|
||||||
|
\* *Mac users*: See [#1](https://github.com/simon987/sist2/issues/1)
|
||||||
*Mac users*: See [#1](https://github.com/simon987/sist2/issues/1)
|
|
||||||
|
|
||||||
|
|
||||||
## Example usage
|
## Example usage
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
See help page `sist2 --help` for more details.
|
See help page `sist2 --help` for more details.
|
||||||
@@ -52,19 +62,76 @@ sist2 index --print ./my_idx > raw_documents.ndjson
|
|||||||
sist2 web --bind 0.0.0.0 --port 4321 ./my_idx1 ./my_idx2 ./my_idx3
|
sist2 web --bind 0.0.0.0 --port 4321 ./my_idx1 ./my_idx2 ./my_idx3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Use sist2 with docker
|
||||||
|
|
||||||
|
**scan**
|
||||||
|
```bash
|
||||||
|
docker run -it \
|
||||||
|
-v /path/to/files/:/files \
|
||||||
|
-v $PWD/out/:/out \
|
||||||
|
simon987/sist2 scan -t 4 /files -o /out/my_idx1
|
||||||
|
```
|
||||||
|
**index**
|
||||||
|
```bash
|
||||||
|
docker run -it --network host\
|
||||||
|
-v $PWD/out/:/out \
|
||||||
|
simon987/sist2 index /out/my_idx1
|
||||||
|
```
|
||||||
|
|
||||||
|
**web**
|
||||||
|
```bash
|
||||||
|
docker run --rm --network host -d --name sist2\
|
||||||
|
-v $PWD/out/my_idx:/idx \
|
||||||
|
-v $PWD/my/files:/files
|
||||||
|
simon987/sist2 web --bind 0.0.0.0 /idx
|
||||||
|
docker stop sist2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Format support
|
## Format support
|
||||||
|
|
||||||
File type | Library | Content | Thumbnail | Metadata
|
File type | Library | Content | Thumbnail | Metadata
|
||||||
:---|:---|:---|:---|:---
|
:---|:---|:---|:---|:---
|
||||||
pdf,xps,cbz,cbr,fb2,epub | MuPDF | yes | yes, `png` | title |
|
pdf,xps,cbz,fb2,epub | MuPDF | text+ocr | yes, `png` | title |
|
||||||
`audio/*` | ffmpeg | - | yes, `jpeg` | ID3 tags |
|
`audio/*` | ffmpeg | - | yes, `jpeg` | ID3 tags |
|
||||||
`video/*` | ffmpeg | - | yes, `jpeg` | title, comment |
|
`video/*` | ffmpeg | - | yes, `jpeg` | title, comment, artist |
|
||||||
`image/*` | ffmpeg | - | yes, `jpeg` | *planned* |
|
`image/*` | ffmpeg | - | yes, `jpeg` | `EXIF:Artist`, `EXIF:ImageDescription` |
|
||||||
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 | - |
|
||||||
docx, xlsx, pptx | | *planned* | no | *planned* |
|
tar, zip, rar, 7z, ar ... | Libarchive | yes\* | - | no |
|
||||||
|
docx, xlsx, pptx | libOPC | yes | no | no |
|
||||||
|
|
||||||
|
\* *See [Archive files](#archive-files)*
|
||||||
|
|
||||||
|
### Archive files
|
||||||
|
**sist2** will scan files stored into archive files (zip, tar, 7z...) as if
|
||||||
|
they were directly in the file system. Recursive (archives inside archives)
|
||||||
|
scan is also supported.
|
||||||
|
|
||||||
|
**Limitations**:
|
||||||
|
* Parsing media files with formats that require
|
||||||
|
*seek* (e.g. `.gif`, `.mp4` w/ fragmented metadata etc.) is not supported.
|
||||||
|
* Archive files are scanned sequentially, by a single thread. On systems where
|
||||||
|
**sist2** is not I/O bound, scans might be faster when larger archives are split
|
||||||
|
into smaller parts.
|
||||||
|
|
||||||
|
To check if a media file can be parsed without *seek*, execute `cat file.mp4 | ffprobe -`
|
||||||
|
|
||||||
|
|
||||||
|
### OCR
|
||||||
|
|
||||||
|
You can enable OCR support for pdf,xps,cbz,fb2,epub file types with the
|
||||||
|
`--ocr <lang>` option. Download the language data files with your
|
||||||
|
package manager (`apt install tesseract-ocr-eng`) or directly [from Github](https://github.com/tesseract-ocr/tesseract/wiki/Data-Files).
|
||||||
|
|
||||||
|
The `simon987/sist2` github image comes with common languages
|
||||||
|
(hin, jpn, eng, fra, rus, spa) pre-installed.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
```bash
|
||||||
|
sist2 scan --ocr jpn ~/Books/Manga/
|
||||||
|
sist2 scan --ocr eng ~/Books/Textbooks/
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Build from source
|
## Build from source
|
||||||
@@ -76,15 +143,10 @@ 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 libtiff5 libpng16-16 libpango1.0-dev
|
||||||
```
|
|
||||||
*(FreeBSD)*
|
|
||||||
```bash
|
|
||||||
pkg install cmake gcc yasm gmake bash ffmpeg e2fsprogs-uuid\
|
|
||||||
autotools ragel
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build
|
2. Build
|
||||||
@@ -93,4 +155,4 @@ binaries.
|
|||||||
./scripts/get_static_libs.sh
|
./scripts/get_static_libs.sh
|
||||||
cmake .
|
cmake .
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|||||||
2
cJSON
2
cJSON
Submodule cJSON updated: 533ff8a783...2d4ad84192
7
ci/build.sh
Normal file
7
ci/build.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
./scripts/get_static_libs.sh
|
||||||
|
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
strip sist2
|
||||||
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
Submodule lib/ffmpeg updated: 0481a1f6e5...8887991a31
Submodule lib/harfbuzz updated: 7cde68f10c...b28c282585
1
lib/leptonica
Submodule
1
lib/leptonica
Submodule
Submodule lib/leptonica added at cc03be70fd
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/libpng
Submodule
1
lib/libpng
Submodule
Submodule lib/libpng added at 301f7a1429
1
lib/libtiff
Submodule
1
lib/libtiff
Submodule
Submodule lib/libtiff added at 3db0ff91bc
Submodule lib/mupdf updated: 91782a4348...c50ac19e41
Submodule lib/onion updated: d8d4cc9290...73329b61eb
Submodule lib/openjpeg updated: 5875a6b446...ac3737372a
1
lib/tesseract
Submodule
1
lib/tesseract
Submodule
Submodule lib/tesseract added at f268e6615e
9
mime.csv
9
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
|
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
|
||||||
@@ -410,4 +410,9 @@ text/PGP,
|
|||||||
audio/x-hx-aac-adts,
|
audio/x-hx-aac-adts,
|
||||||
application/x-chrome-extension,
|
application/x-chrome-extension,
|
||||||
image/heic, heic
|
image/heic, heic
|
||||||
image/x-gem,
|
image/x-gem,
|
||||||
|
application/x-lzma, lzma
|
||||||
|
application/warc, warc
|
||||||
|
application/x-lz4, lz4
|
||||||
|
application/x-lzip, lz
|
||||||
|
application/x-lzop, lzo
|
||||||
|
|||||||
|
@@ -7,25 +7,30 @@
|
|||||||
},
|
},
|
||||||
"suggest-path": {
|
"suggest-path": {
|
||||||
"type": "completion",
|
"type": "completion",
|
||||||
"analyzer": "keyword"
|
"analyzer": "case_insensitive_kw_analyzer"
|
||||||
},
|
},
|
||||||
"mime": {
|
"mime": {
|
||||||
"type": "keyword"
|
"type": "keyword"
|
||||||
},
|
},
|
||||||
"videoc": {
|
"videoc": {
|
||||||
"type": "keyword"
|
"type": "keyword",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"audioc": {
|
"audioc": {
|
||||||
"type": "keyword"
|
"type": "keyword",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"duration": {
|
"duration": {
|
||||||
"type": "float"
|
"type": "float",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"width": {
|
"width": {
|
||||||
"type": "integer"
|
"type": "integer",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"height": {
|
"height": {
|
||||||
"type": "integer"
|
"type": "integer",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"mtime": {
|
"mtime": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
@@ -70,6 +75,23 @@
|
|||||||
"analyzer": "my_nGram",
|
"analyzer": "my_nGram",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
|
"_keyword.*": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"_text.*": {
|
||||||
|
"analyzer": "content_analyzer",
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"nGram": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "my_nGram"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"_url": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": false
|
||||||
|
},
|
||||||
"content": {
|
"content": {
|
||||||
"analyzer": "content_analyzer",
|
"analyzer": "content_analyzer",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -80,6 +102,9 @@
|
|||||||
"analyzer": "my_nGram"
|
"analyzer": "my_nGram"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tag": {
|
||||||
|
"type": "keyword"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,12 @@
|
|||||||
"lowercase"
|
"lowercase"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"case_insensitive_kw_analyzer": {
|
||||||
|
"tokenizer": "keyword",
|
||||||
|
"filter": [
|
||||||
|
"lowercase"
|
||||||
|
]
|
||||||
|
},
|
||||||
"my_nGram": {
|
"my_nGram": {
|
||||||
"tokenizer": "my_nGram_tokenizer",
|
"tokenizer": "my_nGram_tokenizer",
|
||||||
"filter": [
|
"filter": [
|
||||||
|
|||||||
117
scripting/README.md
Normal file
117
scripting/README.md
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
## User scripts
|
||||||
|
|
||||||
|
*This document is under construction, more in-depth guide coming soon*
|
||||||
|
|
||||||
|
During the `index` step, you can use the `--script-file <script>` option to
|
||||||
|
modify documents or add user tags. This option is mainly used to
|
||||||
|
implement automatic tagging based on file attributes.
|
||||||
|
|
||||||
|
The scripting language used
|
||||||
|
([Painless Scripting Language](https://www.elastic.co/guide/en/elasticsearch/painless/7.4/index.html))
|
||||||
|
is very similar to Java, but you should be able to create user scripts
|
||||||
|
without programming experience at all if you're somewhat familiar with
|
||||||
|
regex.
|
||||||
|
|
||||||
|
This is the base structure of the documents we're working with:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"_id": "e171405c-fdb5-4feb-bb32-82637bc32084",
|
||||||
|
"_index": "sist2",
|
||||||
|
"_type": "_doc",
|
||||||
|
"_source": {
|
||||||
|
"index": "206b3050-e821-421a-891d-12fcf6c2db0d",
|
||||||
|
"mime": "application/json",
|
||||||
|
"size": 1799,
|
||||||
|
"mtime": 1545443685,
|
||||||
|
"extension": "md",
|
||||||
|
"name": "README",
|
||||||
|
"path": "sist2/scripting",
|
||||||
|
"content": "..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example script**
|
||||||
|
|
||||||
|
This script checks if the `genre` attribute exists, if it does
|
||||||
|
it adds the `genre.<genre>` tag.
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
if (ctx._source?.genre != null) {
|
||||||
|
tags.add("genre." + ctx._source.genre.toLowerCase())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use `.` to create a hierarchical tag tree:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
To use regular expressions, you need to add this line in `/etc/elasticsearch/elasticsearch.yml`
|
||||||
|
```yaml
|
||||||
|
script.painless.regex.enabled: true
|
||||||
|
```
|
||||||
|
Or, if you're using docker add `-e "script.painless.regex.enabled=true"`
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
If `(20XX)` is in the file name, add the `year.<year>` tag:
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
Matcher m = /[\(\.+](20[0-9]{2})[\)\.+]/.matcher(ctx._source.name);
|
||||||
|
if (m.find()) {
|
||||||
|
tags.add("year." + m.group(1))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use default *Calibre* folder structure to infer author.
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
// We expect the book path to look like this:
|
||||||
|
// /path/to/Calibre Library/Author/Title/Title - Author.pdf
|
||||||
|
|
||||||
|
if (ctx._source.name.contains("-") && ctx._source.extension == "pdf") {
|
||||||
|
String[] names = ctx._source.name.splitOnToken('-');
|
||||||
|
tags.add("author." + names[1].strip());
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If the file matches a specific pattern `AAAA-000 fName1 lName1, <fName2 lName2>...`, add the `actress.<actress>` and
|
||||||
|
`studio.<studio>` tag:
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
Matcher m = /([A-Z]{4})-[0-9]{3} (.*)/.matcher(ctx._source.name);
|
||||||
|
if (m.find()) {
|
||||||
|
tags.add("studio." + m.group(1));
|
||||||
|
|
||||||
|
// Take the matched group (.*), and add a tag for
|
||||||
|
// each name, separated by comma
|
||||||
|
for (String name : m.group(2).splitOnToken(',')) {
|
||||||
|
tags.add("actress." + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Set the name of the last folder (`/path/to/<studio>/file.mp4`) to `studio.<studio>` tag
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
if (ctx._source.path != "") {
|
||||||
|
String[] names = ctx._source.path.splitOnToken('/');
|
||||||
|
tags.add("studio." + names[names.length-1]);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Set the name of the last folder (`/path/to/<studio>/file.mp4`) to `studio.<studio>` tag
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
if (ctx._source.path != "") {
|
||||||
|
String[] names = ctx._source.path.splitOnToken('/');
|
||||||
|
tags.add("studio." + names[names.length-1]);
|
||||||
|
}
|
||||||
|
```
|
||||||
BIN
scripting/genre_example.png
Normal file
BIN
scripting/genre_example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -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
|
CFLAGS=-fPIC 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 .
|
||||||
@@ -10,17 +13,16 @@ mv mupdf/build/release/libmupdf-third.a .
|
|||||||
|
|
||||||
# openjp2
|
# openjp2
|
||||||
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 -fPIC"
|
||||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
make -j $THREADS
|
||||||
make -j 4
|
|
||||||
cd ..
|
cd ..
|
||||||
mv openjpeg/bin/libopenjp2.a .
|
mv openjpeg/bin/libopenjp2.a .
|
||||||
|
|
||||||
# harfbuzz
|
# harfbuzz
|
||||||
cd harfbuzz
|
cd harfbuzz
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --disable-shared --enable-static
|
CFLAGS=-fPIC ./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 .
|
||||||
|
|
||||||
@@ -30,8 +32,9 @@ cd ffmpeg
|
|||||||
--disable-ffprobe --disable-doc\
|
--disable-ffprobe --disable-doc\
|
||||||
--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
|
--extra-cflags=-fPIC
|
||||||
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mv ffmpeg/libavcodec/libavcodec.a .
|
mv ffmpeg/libavcodec/libavcodec.a .
|
||||||
@@ -48,26 +51,78 @@ 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
|
||||||
git clone https://github.com/enthought/bzip2-1.0.6
|
|
||||||
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 .
|
||||||
|
|
||||||
# magic
|
# magic
|
||||||
git clone https://github.com/threatstack/libmagic
|
|
||||||
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 .
|
||||||
|
|
||||||
|
# tesseract
|
||||||
|
cd tesseract
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -DSTATIC=on -DBUILD_TRAINING_TOOLS=off -DBUILD_TESTS=off -DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DCMAKE_CXX_FLAGS="-fPIC" ..
|
||||||
|
make -j $THREADS
|
||||||
|
cd ../..
|
||||||
|
mv tesseract/build/libtesseract.a .
|
||||||
|
|
||||||
|
# leptonica
|
||||||
|
cd leptonica
|
||||||
|
./autogen.sh
|
||||||
|
CFLAGS="-fPIC" ./configure --without-zlib --without-jpeg --without-giflib \
|
||||||
|
--without-giflib --without-libwebp --without-libwebpmux --without-libopenjpeg \
|
||||||
|
--enable-static --disable-shared
|
||||||
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
|
mv leptonica/src/.libs/liblept.a .
|
||||||
|
|
||||||
|
# tiff
|
||||||
|
cd libtiff
|
||||||
|
./autogen.sh
|
||||||
|
CFLAGS="-fPIC" CXXFLAGS="-fPIC" CXX_FLAGS="-fPIC" ./configure --enable-static --disable-shared --disable-lzw --disable-jpeg --disable-webp \
|
||||||
|
--disable-lzma --disable-zstd --disable-jbig
|
||||||
|
make -j $THREADS
|
||||||
|
cd ..
|
||||||
|
mv libtiff/libtiff/.libs/libtiff.a .
|
||||||
|
|
||||||
|
# png
|
||||||
|
cd libpng
|
||||||
|
CFLAGS="-fPIC" ./configure --enable-static --disable-shared
|
||||||
|
make -j $THREADS
|
||||||
|
cd ..
|
||||||
|
mv libpng/.libs/libpng16.a .
|
||||||
|
|
||||||
|
# openssl...
|
||||||
|
git clone --depth 1 -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl
|
||||||
|
cd openssl
|
||||||
|
./config --prefix=$(pwd)/../ssl
|
||||||
|
make depend
|
||||||
|
make -j $THREADS
|
||||||
|
make install
|
||||||
|
cd ..
|
||||||
|
mv ./openssl/libcrypto.a ./openssl/libssl.a .
|
||||||
|
|
||||||
|
# curl
|
||||||
|
wget -nc https://curl.haxx.se/download/curl-7.68.0.tar.gz
|
||||||
|
tar -xzf curl-7.68.0.tar.gz
|
||||||
|
cd curl-7.68.0
|
||||||
|
./configure --disable-ldap --disable-ldaps --without-librtmp --disable-rtsp --disable-crypto-auth \
|
||||||
|
--disable-smtp --without-libidn2 --without-nghttp2 --without-brotli --enable-static --disable-shared \
|
||||||
|
--without-libpsl --with-ssl=$(pwd)/../ssl
|
||||||
|
make -j $THREADS
|
||||||
|
cd ..
|
||||||
|
mv curl-7.68.0/lib/.libs/libcurl.a .
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
cd lib
|
|
||||||
|
|
||||||
# mupdf
|
|
||||||
cd mupdf
|
|
||||||
HAVE_X11=no HAVE_GLUT=no gmake -j 4
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
mv mupdf/build/release/libmupdf.a .
|
|
||||||
mv mupdf/build/release/libmupdf-third.a .
|
|
||||||
|
|
||||||
# openjp2
|
|
||||||
cd openjpeg
|
|
||||||
#cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG"
|
|
||||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
|
||||||
gmake -j 4
|
|
||||||
cd ..
|
|
||||||
mv openjpeg/bin/libopenjp2.a .
|
|
||||||
|
|
||||||
# harfbuzz
|
|
||||||
cd harfbuzz
|
|
||||||
./autogen.sh
|
|
||||||
./configure --disable-shared --enable-static
|
|
||||||
gmake -j 4
|
|
||||||
cd ..
|
|
||||||
mv harfbuzz/src/.libs/libharfbuzz.a .
|
|
||||||
|
|
||||||
# ffmpeg
|
|
||||||
cd ffmpeg
|
|
||||||
./configure --disable-shared --enable-static --disable-ffmpeg --disable-ffplay \
|
|
||||||
--disable-ffprobe --disable-doc\
|
|
||||||
--disable-manpages --disable-postproc --disable-avfilter \
|
|
||||||
--disable-alsa --disable-lzma --disable-xlib --disable-debug\
|
|
||||||
--disable-vdpau --disable-vaapi --disable-sdl2 --disable-network
|
|
||||||
gmake -j 4
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
mv ffmpeg/libavcodec/libavcodec.a .
|
|
||||||
mv ffmpeg/libavformat/libavformat.a .
|
|
||||||
mv ffmpeg/libavutil/libavutil.a .
|
|
||||||
mv ffmpeg/libswresample/libswresample.a .
|
|
||||||
mv ffmpeg/libswscale/libswscale.a .
|
|
||||||
|
|
||||||
#bzip2
|
|
||||||
git clone https://github.com/enthought/bzip2-1.0.6
|
|
||||||
cd bzip2-1.0.6
|
|
||||||
make -j 4
|
|
||||||
cd ..
|
|
||||||
mv bzip2-1.0.6/libbz2.a .
|
|
||||||
|
|
||||||
# magic
|
|
||||||
git clone https://github.com/threatstack/libmagic
|
|
||||||
cd libmagic
|
|
||||||
./autogen.sh
|
|
||||||
./configure --enable-static --disable-shared
|
|
||||||
make -j 4
|
|
||||||
cd ..
|
|
||||||
mv libmagic/src/.libs/libmagic.a .
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
@@ -34,6 +34,34 @@ font = (
|
|||||||
"font/woff2"
|
"font/woff2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Archive "formats"
|
||||||
|
archive = (
|
||||||
|
"application/x-tar",
|
||||||
|
"application/zip",
|
||||||
|
"application/x-rar",
|
||||||
|
"application/x-arc",
|
||||||
|
"application/x-warc",
|
||||||
|
"application/x-7z-compressed",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Archive "filters"
|
||||||
|
arc_filter = (
|
||||||
|
"application/gzip",
|
||||||
|
"application/x-bzip2",
|
||||||
|
"application/x-xz",
|
||||||
|
"application/x-zstd",
|
||||||
|
"application/x-lzma",
|
||||||
|
"application/x-lz4",
|
||||||
|
"application/x-lzip",
|
||||||
|
"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
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +76,12 @@ def mime_id(mime):
|
|||||||
mime_id += " | 0x40000000"
|
mime_id += " | 0x40000000"
|
||||||
elif mime in font:
|
elif mime in font:
|
||||||
mime_id += " | 0x20000000"
|
mime_id += " | 0x20000000"
|
||||||
|
elif mime in archive:
|
||||||
|
mime_id += " | 0x10000000"
|
||||||
|
elif mime in arc_filter:
|
||||||
|
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
|
||||||
|
|||||||
176
src/cli.c
176
src/cli.c
@@ -1,22 +1,59 @@
|
|||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
#include "ctx.h"
|
||||||
|
|
||||||
|
#include <tesseract/capi.h>
|
||||||
|
|
||||||
#define DEFAULT_OUTPUT "index.sist2/"
|
#define DEFAULT_OUTPUT "index.sist2/"
|
||||||
#define DEFAULT_CONTENT_SIZE 4096
|
#define DEFAULT_CONTENT_SIZE 32768
|
||||||
#define DEFAULT_QUALITY 15
|
#define DEFAULT_QUALITY 5
|
||||||
#define DEFAULT_SIZE 200
|
#define DEFAULT_SIZE 500
|
||||||
#define DEFAULT_REWRITE_URL ""
|
#define DEFAULT_REWRITE_URL ""
|
||||||
|
|
||||||
#define DEFAULT_ES_URL "http://localhost:9200"
|
#define DEFAULT_ES_URL "http://localhost:9200"
|
||||||
|
#define DEFAULT_BATCH_SIZE 100
|
||||||
|
|
||||||
#define DEFAULT_BIND_ADDR "localhost"
|
#define DEFAULT_BIND_ADDR "localhost"
|
||||||
#define DEFAULT_PORT "4090"
|
#define DEFAULT_PORT "4090"
|
||||||
|
|
||||||
|
const char* TESS_DATAPATHS[] = {
|
||||||
|
"/usr/share/tessdata/",
|
||||||
|
"/usr/share/tesseract-ocr/tessdata/",
|
||||||
|
"./",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
scan_args_t *scan_args_create() {
|
scan_args_t *scan_args_create() {
|
||||||
scan_args_t *args = calloc(sizeof(scan_args_t), 1);
|
scan_args_t *args = calloc(sizeof(scan_args_t), 1);
|
||||||
|
|
||||||
|
args->depth = -1;
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scan_args_destroy(scan_args_t *args) {
|
||||||
|
if (args->name != NULL) {
|
||||||
|
free(args->name);
|
||||||
|
}
|
||||||
|
if (args->path != NULL) {
|
||||||
|
free(args->path);
|
||||||
|
}
|
||||||
|
if (args->output != NULL) {
|
||||||
|
free(args->output);
|
||||||
|
}
|
||||||
|
free(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void index_args_destroy(index_args_t *args) {
|
||||||
|
//todo
|
||||||
|
free(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void web_args_destroy(web_args_t *args) {
|
||||||
|
//todo
|
||||||
|
free(args);
|
||||||
|
}
|
||||||
|
|
||||||
int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Required positional argument: PATH.\n");
|
fprintf(stderr, "Required positional argument: PATH.\n");
|
||||||
@@ -25,7 +62,7 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
|
|
||||||
char *abs_path = abspath(argv[1]);
|
char *abs_path = abspath(argv[1]);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", argv[1]);
|
fprintf(stderr, "File not found: %s\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
args->path = abs_path;
|
args->path = abs_path;
|
||||||
@@ -34,7 +71,7 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
if (args->incremental != NULL) {
|
if (args->incremental != NULL) {
|
||||||
abs_path = abspath(args->incremental);
|
abs_path = abspath(args->incremental);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", args->incremental);
|
fprintf(stderr, "File not found: %s\n", args->incremental);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,16 +85,13 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
|
|
||||||
if (args->size == 0) {
|
if (args->size == 0) {
|
||||||
args->size = DEFAULT_SIZE;
|
args->size = DEFAULT_SIZE;
|
||||||
} else if (args->size <= 0) {
|
} else if (args->size > 0 && args->size < 32) {
|
||||||
fprintf(stderr, "Invalid size: %d\n", args->size);
|
printf("Invalid size: %d\n", args->content_size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->content_size == 0) {
|
if (args->content_size == 0) {
|
||||||
args->content_size = DEFAULT_CONTENT_SIZE;
|
args->content_size = DEFAULT_CONTENT_SIZE;
|
||||||
} else if (args->content_size <= 0) {
|
|
||||||
fprintf(stderr, "Invalid content-size: %d\n", args->content_size);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->threads == 0) {
|
if (args->threads == 0) {
|
||||||
@@ -80,6 +114,12 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->depth < 0) {
|
||||||
|
args->depth = G_MAXINT32;
|
||||||
|
} else {
|
||||||
|
args->depth += 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (args->name == NULL) {
|
if (args->name == NULL) {
|
||||||
args->name = g_path_get_basename(args->output);
|
args->name = g_path_get_basename(args->output);
|
||||||
}
|
}
|
||||||
@@ -87,12 +127,62 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
if (args->rewrite_url == NULL) {
|
if (args->rewrite_url == NULL) {
|
||||||
args->rewrite_url = DEFAULT_REWRITE_URL;
|
args->rewrite_url = DEFAULT_REWRITE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->archive == NULL || strcmp(args->archive, "recurse") == 0) {
|
||||||
|
args->archive_mode = ARC_MODE_RECURSE;
|
||||||
|
} else if (strcmp(args->archive, "list") == 0) {
|
||||||
|
args->archive_mode = ARC_MODE_LIST;
|
||||||
|
} else if (strcmp(args->archive, "shallow") == 0) {
|
||||||
|
args->archive_mode = ARC_MODE_SHALLOW;
|
||||||
|
} else if (strcmp(args->archive, "skip") == 0) {
|
||||||
|
args->archive_mode = ARC_MODE_SKIP;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Archive mode must be one of (skip, list, shallow, recurse), got '%s'", args->archive);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->tesseract_lang != NULL) {
|
||||||
|
TessBaseAPI *api = TessBaseAPICreate();
|
||||||
|
|
||||||
|
char filename[128];
|
||||||
|
sprintf(filename, "%s.traineddata", args->tesseract_lang);
|
||||||
|
const char * path = find_file_in_paths(TESS_DATAPATHS, filename);
|
||||||
|
if (path == NULL) {
|
||||||
|
LOG_FATAL("cli.c", "Could not find tesseract language file!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TessBaseAPIInit3(api, path, args->tesseract_lang);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
TessBaseAPIEnd(api);
|
||||||
|
TessBaseAPIDelete(api);
|
||||||
|
|
||||||
|
args->tesseract_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
LOG_DEBUGF("cli.c", "arg tesseract_lang=%s", args->tesseract_lang)
|
||||||
|
LOG_DEBUGF("cli.c", "arg tesseract_path=%s", args->tesseract_path)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
||||||
|
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Required positional argument: PATH.\n");
|
fprintf(stderr, "Required positional argument: PATH.\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -100,20 +190,62 @@ int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
|||||||
|
|
||||||
char *index_path = abspath(argv[1]);
|
char *index_path = abspath(argv[1]);
|
||||||
if (index_path == NULL) {
|
if (index_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", argv[1]);
|
fprintf(stderr, "File not found: %s\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
args->index_path = argv[1];
|
args->index_path = argv[1];
|
||||||
|
free(index_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->es_url == NULL) {
|
if (args->es_url == NULL) {
|
||||||
args->es_url = DEFAULT_ES_URL;
|
args->es_url = DEFAULT_ES_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->script_path != NULL) {
|
||||||
|
struct stat info;
|
||||||
|
int res = stat(args->script_path, &info);
|
||||||
|
|
||||||
|
if (res == -1) {
|
||||||
|
fprintf(stderr, "Error opening script file '%s': %s\n", args->script_path, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fd = open(args->script_path, O_RDONLY);
|
||||||
|
if (fd == -1) {
|
||||||
|
fprintf(stderr, "Error opening script file '%s': %s\n", args->script_path, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
args->script = malloc(info.st_size + 1);
|
||||||
|
res = read(fd, args->script, info.st_size);
|
||||||
|
if (res == -1) {
|
||||||
|
fprintf(stderr, "Error reading script file '%s': %s\n", args->script_path, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(args->script + info.st_size) = '\0';
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->batch_size == 0) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
||||||
|
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Required positional argument: PATH.\n");
|
fprintf(stderr, "Required positional argument: PATH.\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -131,16 +263,33 @@ int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
|||||||
args->port = DEFAULT_PORT;
|
args->port = DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->credentials != NULL) {
|
||||||
|
args->b64credentials = onion_base64_encode(args->credentials, (int) strlen(args->credentials));
|
||||||
|
//Remove trailing newline
|
||||||
|
*(args->b64credentials + strlen(args->b64credentials) - 1) = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
args->index_count = argc - 1;
|
args->index_count = argc - 1;
|
||||||
args->indices = argv + 1;
|
args->indices = argv + 1;
|
||||||
|
|
||||||
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", 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,5 +302,4 @@ web_args_t *web_args_create() {
|
|||||||
web_args_t *args = calloc(sizeof(web_args_t), 1);
|
web_args_t *args = calloc(sizeof(web_args_t), 1);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
16
src/cli.h
16
src/cli.h
@@ -12,17 +12,25 @@ typedef struct scan_args {
|
|||||||
char *output;
|
char *output;
|
||||||
char *rewrite_url;
|
char *rewrite_url;
|
||||||
char *name;
|
char *name;
|
||||||
|
int depth;
|
||||||
char *path;
|
char *path;
|
||||||
|
char *archive;
|
||||||
|
archive_mode_t archive_mode;
|
||||||
|
char *tesseract_lang;
|
||||||
|
const char *tesseract_path;
|
||||||
} scan_args_t;
|
} scan_args_t;
|
||||||
|
|
||||||
scan_args_t *scan_args_create();
|
scan_args_t *scan_args_create();
|
||||||
|
void scan_args_destroy(scan_args_t *args);
|
||||||
int scan_args_validate(scan_args_t *args, int argc, const char **argv);
|
int scan_args_validate(scan_args_t *args, int argc, const char **argv);
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
typedef struct index_args {
|
typedef struct index_args {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
const char *index_path;
|
const char *index_path;
|
||||||
|
const char *script_path;
|
||||||
|
char *script;
|
||||||
int print;
|
int print;
|
||||||
|
int batch_size;
|
||||||
int force_reset;
|
int force_reset;
|
||||||
} index_args_t;
|
} index_args_t;
|
||||||
|
|
||||||
@@ -30,15 +38,19 @@ typedef struct web_args {
|
|||||||
char *es_url;
|
char *es_url;
|
||||||
char *bind;
|
char *bind;
|
||||||
char *port;
|
char *port;
|
||||||
|
char *credentials;
|
||||||
|
char *b64credentials;
|
||||||
int index_count;
|
int index_count;
|
||||||
const char **indices;
|
const char **indices;
|
||||||
} web_args_t;
|
} web_args_t;
|
||||||
|
|
||||||
index_args_t *index_args_create();
|
index_args_t *index_args_create();
|
||||||
|
void index_args_destroy(index_args_t *args);
|
||||||
|
|
||||||
web_args_t *web_args_create();
|
web_args_t *web_args_create();
|
||||||
|
void web_args_destroy(web_args_t *args);
|
||||||
|
|
||||||
int index_args_validate(index_args_t *args, int argc, const char **argv);
|
int index_args_validate(index_args_t *args, int argc, const char **argv);
|
||||||
int web_args_validate(web_args_t *args, int argc, const char **argv);
|
int web_args_validate(web_args_t *args, int argc, const char **argv);
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
15
src/ctx.h
15
src/ctx.h
@@ -15,6 +15,10 @@ struct {
|
|||||||
int threads;
|
int threads;
|
||||||
int content_size;
|
int content_size;
|
||||||
float tn_qscale;
|
float tn_qscale;
|
||||||
|
int depth;
|
||||||
|
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;
|
||||||
@@ -23,20 +27,27 @@ struct {
|
|||||||
GHashTable *copy_table;
|
GHashTable *copy_table;
|
||||||
|
|
||||||
pthread_mutex_t mupdf_mu;
|
pthread_mutex_t mupdf_mu;
|
||||||
|
char * tesseract_lang;
|
||||||
|
char * tesseract_path;
|
||||||
} ScanCtx;
|
} ScanCtx;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int verbose;
|
||||||
|
int very_verbose;
|
||||||
|
int no_color;
|
||||||
|
} LogCtx;
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
struct {
|
struct {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
|
int batch_size;
|
||||||
} IndexCtx;
|
} IndexCtx;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
int index_count;
|
int index_count;
|
||||||
|
char *b64credentials;
|
||||||
struct index_t indices[16];
|
struct index_t indices[16];
|
||||||
} WebCtx;
|
} WebCtx;
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,11 +6,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <cJSON/cJSON.h>
|
#include <cJSON/cJSON.h>
|
||||||
#include <src/ctx.h>
|
|
||||||
|
|
||||||
#include "static_generated.c"
|
#include "static_generated.c"
|
||||||
|
|
||||||
#define BULK_INDEX_SIZE 100
|
|
||||||
|
|
||||||
typedef struct es_indexer {
|
typedef struct es_indexer {
|
||||||
int queued;
|
int queued;
|
||||||
@@ -29,13 +27,14 @@ void print_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
|||||||
cJSON_AddStringToObject(line, "_id", uuid_str);
|
cJSON_AddStringToObject(line, "_id", uuid_str);
|
||||||
cJSON_AddStringToObject(line, "_index", "sist2");
|
cJSON_AddStringToObject(line, "_index", "sist2");
|
||||||
cJSON_AddStringToObject(line, "_type", "_doc");
|
cJSON_AddStringToObject(line, "_type", "_doc");
|
||||||
cJSON_AddItemToObject(line, "_source", document);
|
cJSON_AddItemReferenceToObject(line, "_source", document);
|
||||||
|
|
||||||
char *json = cJSON_PrintUnformatted(line);
|
char *json = cJSON_PrintUnformatted(line);
|
||||||
|
|
||||||
printf("%s\n", json);
|
printf("%s\n", json);
|
||||||
|
|
||||||
cJSON_free(line);
|
cJSON_free(json);
|
||||||
|
cJSON_Delete(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
||||||
@@ -54,6 +53,40 @@ void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
|||||||
elastic_index_line(bulk_line);
|
elastic_index_line(bulk_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void execute_update_script(const char *script, const char index_id[UUID_STR_LEN]) {
|
||||||
|
|
||||||
|
cJSON *body = cJSON_CreateObject();
|
||||||
|
cJSON *script_obj = cJSON_AddObjectToObject(body, "script");
|
||||||
|
cJSON_AddStringToObject(script_obj, "lang", "painless");
|
||||||
|
cJSON_AddStringToObject(script_obj, "source", script);
|
||||||
|
|
||||||
|
cJSON *query = cJSON_AddObjectToObject(body, "query");
|
||||||
|
cJSON *term_obj = cJSON_AddObjectToObject(query, "term");
|
||||||
|
cJSON_AddStringToObject(term_obj, "index", index_id);
|
||||||
|
|
||||||
|
char * str = cJSON_Print(body);
|
||||||
|
|
||||||
|
char bulk_url[4096];
|
||||||
|
snprintf(bulk_url, 4096, "%s/sist2/_update_by_query?pretty", Indexer->es_url);
|
||||||
|
response_t *r = web_post(bulk_url, str, "Content-Type: application/json");
|
||||||
|
LOG_INFOF("elastic.c", "Executed user script <%d>", r->status_code);
|
||||||
|
cJSON *resp = cJSON_Parse(r->body);
|
||||||
|
|
||||||
|
cJSON_free(str);
|
||||||
|
cJSON_Delete(body);
|
||||||
|
free_response(r);
|
||||||
|
|
||||||
|
cJSON *error = cJSON_GetObjectItem(resp, "error");
|
||||||
|
if (error != NULL) {
|
||||||
|
char *error_str = cJSON_Print(error);
|
||||||
|
|
||||||
|
LOG_ERRORF("elastic.c", "User script error: \n%s", error_str);
|
||||||
|
cJSON_free(error_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(resp);
|
||||||
|
}
|
||||||
|
|
||||||
void elastic_flush() {
|
void elastic_flush() {
|
||||||
|
|
||||||
if (Indexer == NULL) {
|
if (Indexer == NULL) {
|
||||||
@@ -98,7 +131,12 @@ void elastic_flush() {
|
|||||||
char bulk_url[4096];
|
char bulk_url[4096];
|
||||||
snprintf(bulk_url, 4096, "%s/sist2/_bulk", Indexer->es_url);
|
snprintf(bulk_url, 4096, "%s/sist2/_bulk", Indexer->es_url);
|
||||||
response_t *r = web_post(bulk_url, buf, "Content-Type: application/x-ndjson");
|
response_t *r = web_post(bulk_url, buf, "Content-Type: application/x-ndjson");
|
||||||
printf("Indexed %3d documents (%zukB) <%d>\n", count, buf_cur / 1024, r->status_code);
|
|
||||||
|
if (r->status_code == 0) {
|
||||||
|
LOG_FATALF("elastic.c", "Could not connect to %s, make sure that elasticsearch is running!\n", IndexCtx.es_url)
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFOF("elastic.c", "Indexed %d documents (%zukB) <%d>", count, buf_cur / 1024, r->status_code);
|
||||||
|
|
||||||
cJSON *ret_json = cJSON_Parse(r->body);
|
cJSON *ret_json = cJSON_Parse(r->body);
|
||||||
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
||||||
@@ -106,7 +144,7 @@ void elastic_flush() {
|
|||||||
cJSON_ArrayForEach(err, cJSON_GetObjectItem(ret_json, "items")) {
|
cJSON_ArrayForEach(err, cJSON_GetObjectItem(ret_json, "items")) {
|
||||||
if (cJSON_GetObjectItem(cJSON_GetObjectItem(err, "index"), "status")->valueint != 201) {
|
if (cJSON_GetObjectItem(cJSON_GetObjectItem(err, "index"), "status")->valueint != 201) {
|
||||||
char* str = cJSON_Print(err);
|
char* str = cJSON_Print(err);
|
||||||
fprintf(stderr, "%s\n", str);
|
LOG_ERRORF("elastic.c", "%s\n", str);
|
||||||
cJSON_free(str);
|
cJSON_free(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,6 +153,7 @@ void elastic_flush() {
|
|||||||
cJSON_Delete(ret_json);
|
cJSON_Delete(ret_json);
|
||||||
|
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void elastic_index_line(es_bulk_line_t *line) {
|
void elastic_index_line(es_bulk_line_t *line) {
|
||||||
@@ -133,15 +172,14 @@ void elastic_index_line(es_bulk_line_t *line) {
|
|||||||
|
|
||||||
Indexer->queued += 1;
|
Indexer->queued += 1;
|
||||||
|
|
||||||
if (Indexer->queued >= BULK_INDEX_SIZE) {
|
if (Indexer->queued >= IndexCtx.batch_size) {
|
||||||
elastic_flush();
|
elastic_flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
es_indexer_t *create_indexer(const char *url) {
|
es_indexer_t *create_indexer(const char *url) {
|
||||||
|
|
||||||
size_t url_len = strlen(url);
|
char *es_url = malloc(strlen(url) + 1);
|
||||||
char *es_url = malloc(url_len);
|
|
||||||
strcpy(es_url, url);
|
strcpy(es_url, url);
|
||||||
|
|
||||||
es_indexer_t *indexer = malloc(sizeof(es_indexer_t));
|
es_indexer_t *indexer = malloc(sizeof(es_indexer_t));
|
||||||
@@ -154,18 +192,27 @@ es_indexer_t *create_indexer(const char *url) {
|
|||||||
return indexer;
|
return indexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_indexer() {
|
void destroy_indexer(char * script, char index_id[UUID_STR_LEN]) {
|
||||||
|
|
||||||
char url[4096];
|
char url[4096];
|
||||||
|
|
||||||
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
||||||
response_t *r = web_post(url, "", NULL);
|
response_t *r = web_post(url, "", NULL);
|
||||||
printf("Refresh index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Refresh index <%d>", r->status_code);
|
||||||
|
free_response(r);
|
||||||
|
|
||||||
|
if (script != NULL) {
|
||||||
|
execute_update_script(script, index_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
||||||
|
r = web_post(url, "", NULL);
|
||||||
|
LOG_INFOF("elastic.c", "Refresh index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, sizeof(url), "%s/sist2/_forcemerge", IndexCtx.es_url);
|
snprintf(url, sizeof(url), "%s/sist2/_forcemerge", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Merge index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Merge index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
if (Indexer != NULL) {
|
if (Indexer != NULL) {
|
||||||
@@ -185,32 +232,32 @@ void elastic_init(int force_reset) {
|
|||||||
|
|
||||||
if (!index_exists || force_reset) {
|
if (!index_exists || force_reset) {
|
||||||
r = web_delete(url);
|
r = web_delete(url);
|
||||||
printf("Delete index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Delete index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2", IndexCtx.es_url);
|
||||||
r = web_put(url, "", NULL);
|
r = web_put(url, "", NULL);
|
||||||
printf("Create index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Create index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_close", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_close", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Close index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Close index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_settings", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_settings", IndexCtx.es_url);
|
||||||
r = web_put(url, settings_json, "Content-Type: application/json");
|
r = web_put(url, settings_json, "Content-Type: application/json");
|
||||||
printf("Update settings <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Update settings <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_mappings/_doc?include_type_name=true", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_mappings/_doc?include_type_name=true", IndexCtx.es_url);
|
||||||
r = web_put(url, mappings_json, "Content-Type: application/json");
|
r = web_put(url, mappings_json, "Content-Type: application/json");
|
||||||
printf("Update mappings <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Update mappings <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_open", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_open", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Open index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Open index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,3 +274,28 @@ cJSON *elastic_get_document(const char *uuid_str) {
|
|||||||
free_response(r);
|
free_response(r);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *elastic_get_status() {
|
||||||
|
char url[4096];
|
||||||
|
snprintf(url, 4096,
|
||||||
|
"%s/_cluster/state/metadata/sist2?filter_path=metadata.indices.*.state", WebCtx.es_url);
|
||||||
|
|
||||||
|
response_t *r = web_get(url);
|
||||||
|
cJSON *json = NULL;
|
||||||
|
char *status = malloc(128 * sizeof(char));
|
||||||
|
status[0] = '\0';
|
||||||
|
|
||||||
|
if (r->status_code == 200) {
|
||||||
|
json = cJSON_Parse(r->body);
|
||||||
|
const cJSON *metadata = cJSON_GetObjectItem(json, "metadata");
|
||||||
|
if (metadata != NULL) {
|
||||||
|
const cJSON *indices = cJSON_GetObjectItem(metadata, "indices");
|
||||||
|
const cJSON *sist2 = cJSON_GetObjectItem(indices, "sist2");
|
||||||
|
const cJSON *state = cJSON_GetObjectItem(sist2, "state");
|
||||||
|
strcpy(status, state->valuestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free_response(r);
|
||||||
|
cJSON_Delete(json);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]);
|
|||||||
|
|
||||||
es_indexer_t *create_indexer(const char* es_url);
|
es_indexer_t *create_indexer(const char* es_url);
|
||||||
|
|
||||||
void destroy_indexer();
|
void destroy_indexer(char *script, char index_id[UUID_STR_LEN]);
|
||||||
|
|
||||||
void elastic_init(int force_reset);
|
void elastic_init(int force_reset);
|
||||||
|
|
||||||
cJSON *elastic_get_document(const char *uuid_str);
|
cJSON *elastic_get_document(const char *uuid_str);
|
||||||
|
|
||||||
|
char *elastic_get_status();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
#include "serialize.h"
|
#include "serialize.h"
|
||||||
|
|
||||||
static __thread int IndexFd = -1;
|
static __thread int index_fd = -1;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned char uuid[16];
|
unsigned char uuid[16];
|
||||||
@@ -34,6 +34,7 @@ void write_index_descriptor(char *path, index_descriptor_t *desc) {
|
|||||||
cJSON_AddStringToObject(json, "version", desc->version);
|
cJSON_AddStringToObject(json, "version", desc->version);
|
||||||
cJSON_AddStringToObject(json, "root", desc->root);
|
cJSON_AddStringToObject(json, "root", desc->root);
|
||||||
cJSON_AddStringToObject(json, "name", desc->name);
|
cJSON_AddStringToObject(json, "name", desc->name);
|
||||||
|
cJSON_AddStringToObject(json, "type", desc->type);
|
||||||
cJSON_AddStringToObject(json, "rewrite_url", desc->rewrite_url);
|
cJSON_AddStringToObject(json, "rewrite_url", desc->rewrite_url);
|
||||||
cJSON_AddNumberToObject(json, "timestamp", (double) desc->timestamp);
|
cJSON_AddNumberToObject(json, "timestamp", (double) desc->timestamp);
|
||||||
|
|
||||||
@@ -54,6 +55,11 @@ index_descriptor_t read_index_descriptor(char *path) {
|
|||||||
struct stat info;
|
struct stat info;
|
||||||
stat(path, &info);
|
stat(path, &info);
|
||||||
int fd = open(path, O_RDONLY);
|
int fd = open(path, O_RDONLY);
|
||||||
|
|
||||||
|
if (fd == -1) {
|
||||||
|
LOG_FATAL("serialize.c", "Invalid/corrupt index (Could not find descriptor)\n")
|
||||||
|
}
|
||||||
|
|
||||||
char *buf = malloc(info.st_size + 1);
|
char *buf = malloc(info.st_size + 1);
|
||||||
read(fd, buf, info.st_size);
|
read(fd, buf, info.st_size);
|
||||||
*(buf + info.st_size) = '\0';
|
*(buf + info.st_size) = '\0';
|
||||||
@@ -69,6 +75,11 @@ index_descriptor_t read_index_descriptor(char *path) {
|
|||||||
descriptor.root_len = (short) strlen(descriptor.root);
|
descriptor.root_len = (short) strlen(descriptor.root);
|
||||||
strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring);
|
strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring);
|
||||||
strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring);
|
strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring);
|
||||||
|
if (cJSON_GetObjectItem(json, "type") == NULL) {
|
||||||
|
strcpy(descriptor.type, INDEX_TYPE_BIN);
|
||||||
|
} else {
|
||||||
|
strcpy(descriptor.type, cJSON_GetObjectItem(json, "type")->valuestring);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -105,6 +116,24 @@ char *get_meta_key_text(enum metakey meta_key) {
|
|||||||
return "title";
|
return "title";
|
||||||
case MetaFontName:
|
case MetaFontName:
|
||||||
return "font_name";
|
return "font_name";
|
||||||
|
case MetaParent:
|
||||||
|
return "parent";
|
||||||
|
case MetaExifMake:
|
||||||
|
return "exif_make";
|
||||||
|
case MetaExifSoftware:
|
||||||
|
return "exif_software";
|
||||||
|
case MetaExifExposureTime:
|
||||||
|
return "exif_exposure_time";
|
||||||
|
case MetaExifFNumber:
|
||||||
|
return "exif_fnumber";
|
||||||
|
case MetaExifFocalLength:
|
||||||
|
return "exif_focal_length";
|
||||||
|
case MetaExifUserComment:
|
||||||
|
return "exif_user_comment";
|
||||||
|
case MetaExifIsoSpeedRatings:
|
||||||
|
return "exif_iso_speed_ratings";
|
||||||
|
case MetaExifModel:
|
||||||
|
return "exif_model";
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -113,13 +142,13 @@ char *get_meta_key_text(enum metakey meta_key) {
|
|||||||
|
|
||||||
void write_document(document_t *doc) {
|
void write_document(document_t *doc) {
|
||||||
|
|
||||||
if (IndexFd == -1) {
|
if (index_fd == -1) {
|
||||||
char dstfile[PATH_MAX];
|
char dstfile[PATH_MAX];
|
||||||
pthread_t self = pthread_self();
|
pthread_t self = pthread_self();
|
||||||
snprintf(dstfile, PATH_MAX, "%s_index_%lu", ScanCtx.index.path, self);
|
snprintf(dstfile, PATH_MAX, "%s_index_%lu", ScanCtx.index.path, self);
|
||||||
IndexFd = open(dstfile, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
|
index_fd = open(dstfile, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
if (IndexFd == -1) {
|
if (index_fd == -1) {
|
||||||
perror("open");
|
perror("open");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,17 +181,20 @@ void write_document(document_t *doc) {
|
|||||||
}
|
}
|
||||||
dyn_buffer_write_char(&buf, '\n');
|
dyn_buffer_write_char(&buf, '\n');
|
||||||
|
|
||||||
write(IndexFd, buf.buf, buf.cur);
|
int res = write(index_fd, buf.buf, buf.cur);
|
||||||
|
if (res == -1) {
|
||||||
|
perror("write");
|
||||||
|
}
|
||||||
ScanCtx.stat_index_size += buf.cur;
|
ScanCtx.stat_index_size += buf.cur;
|
||||||
dyn_buffer_destroy(&buf);
|
dyn_buffer_destroy(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serializer_cleanup() {
|
void thread_cleanup() {
|
||||||
close(IndexFd);
|
close(index_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func func) {
|
|
||||||
|
|
||||||
|
void read_index_bin(const char *path, const char *index_id, index_func func) {
|
||||||
line_t line;
|
line_t line;
|
||||||
dyn_buffer_t buf = dyn_buffer_create();
|
dyn_buffer_t buf = dyn_buffer_create();
|
||||||
|
|
||||||
@@ -218,7 +250,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
case MetaMediaBitrate: {
|
case MetaMediaBitrate: {
|
||||||
long value;
|
long value;
|
||||||
fread(&value, sizeof(long), 1, file);
|
fread(&value, sizeof(long), 1, file);
|
||||||
cJSON_AddNumberToObject(document, get_meta_key_text(key), value);
|
cJSON_AddNumberToObject(document, get_meta_key_text(key), (double) value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MetaMediaAudioCodec:
|
case MetaMediaAudioCodec:
|
||||||
@@ -238,6 +270,15 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
case MetaAlbumArtist:
|
case MetaAlbumArtist:
|
||||||
case MetaGenre:
|
case MetaGenre:
|
||||||
case MetaFontName:
|
case MetaFontName:
|
||||||
|
case MetaParent:
|
||||||
|
case MetaExifMake:
|
||||||
|
case MetaExifSoftware:
|
||||||
|
case MetaExifExposureTime:
|
||||||
|
case MetaExifFNumber:
|
||||||
|
case MetaExifFocalLength:
|
||||||
|
case MetaExifUserComment:
|
||||||
|
case MetaExifIsoSpeedRatings:
|
||||||
|
case MetaExifModel:
|
||||||
case MetaTitle: {
|
case MetaTitle: {
|
||||||
buf.cur = 0;
|
buf.cur = 0;
|
||||||
while ((c = getc(file)) != 0) {
|
while ((c = getc(file)) != 0) {
|
||||||
@@ -250,19 +291,102 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
func(document, uuid_str);
|
func(document, uuid_str);
|
||||||
cJSON_free(document);
|
cJSON_Delete(document);
|
||||||
|
}
|
||||||
|
dyn_buffer_destroy(&buf);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *json_type_copy_fields[] = {
|
||||||
|
"mime", "name", "path", "extension", "index", "size", "mtime", "parent",
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
"title", "content", "width", "height", "duration", "audioc", "videoc",
|
||||||
|
"bitrate", "artist", "album", "album_artist", "genre", "title", "font_name",
|
||||||
|
|
||||||
|
// Special
|
||||||
|
"tag", "_url"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *json_type_array_fields[] = {
|
||||||
|
"_keyword", "_text"
|
||||||
|
};
|
||||||
|
|
||||||
|
void read_index_json(const char *path, UNUSED(const char *index_id), index_func func) {
|
||||||
|
|
||||||
|
FILE *file = fopen(path, "r");
|
||||||
|
while (1) {
|
||||||
|
char *line = NULL;
|
||||||
|
size_t len;
|
||||||
|
size_t read = getline(&line, &len, file);
|
||||||
|
if (read == -1) {
|
||||||
|
if (line) {
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *input = cJSON_Parse(line);
|
||||||
|
if (input == NULL) {
|
||||||
|
LOG_FATALF("serialize.c", "Could not parse JSON line: \n%s", line)
|
||||||
|
}
|
||||||
|
if (line) {
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *document = cJSON_CreateObject();
|
||||||
|
const char *uuid_str = cJSON_GetObjectItem(input, "_id")->valuestring;
|
||||||
|
|
||||||
|
for (int i = 0; i < (sizeof(json_type_copy_fields) / sizeof(json_type_copy_fields[0])); i++) {
|
||||||
|
cJSON *value = cJSON_GetObjectItem(input, json_type_copy_fields[i]);
|
||||||
|
if (value != NULL) {
|
||||||
|
cJSON_AddItemReferenceToObject(document, json_type_copy_fields[i], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (sizeof(json_type_array_fields) / sizeof(json_type_array_fields[0])); i++) {
|
||||||
|
cJSON *arr = cJSON_GetObjectItem(input, json_type_array_fields[i]);
|
||||||
|
if (arr != NULL) {
|
||||||
|
cJSON *obj;
|
||||||
|
cJSON_ArrayForEach(obj, arr) {
|
||||||
|
char key[1024];
|
||||||
|
cJSON *k = cJSON_GetObjectItem(obj, "k");
|
||||||
|
cJSON *v = cJSON_GetObjectItem(obj, "v");
|
||||||
|
if (k == NULL || v == NULL || !cJSON_IsString(k) || !cJSON_IsString(v)) {
|
||||||
|
char *str = cJSON_Print(obj);
|
||||||
|
LOG_FATALF("serialize.c", "Invalid %s member: must contain .k and .v string fields: \n%s",
|
||||||
|
json_type_array_fields[i], str)
|
||||||
|
}
|
||||||
|
snprintf(key, sizeof(key), "%s.%s", json_type_array_fields[i], k->valuestring);
|
||||||
|
cJSON_AddStringToObject(document, key, v->valuestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func(document, uuid_str);
|
||||||
|
cJSON_Delete(document);
|
||||||
|
cJSON_Delete(input);
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void read_index(const char *path, const char index_id[UUID_STR_LEN], const char *type, index_func func) {
|
||||||
|
|
||||||
|
if (strcmp(type, INDEX_TYPE_BIN) == 0) {
|
||||||
|
read_index_bin(path, index_id, func);
|
||||||
|
} else if (strcmp(type, INDEX_TYPE_JSON) == 0) {
|
||||||
|
read_index_json(path, index_id, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void incremental_read(GHashTable *table, const char *filepath) {
|
void incremental_read(GHashTable *table, const char *filepath) {
|
||||||
FILE *file = fopen(filepath, "rb");
|
FILE *file = fopen(filepath, "rb");
|
||||||
line_t line;
|
line_t line;
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ void incremental_copy(store_t *store, store_t *dst_store, const char *filepath,
|
|||||||
|
|
||||||
void write_document(document_t *doc);
|
void write_document(document_t *doc);
|
||||||
|
|
||||||
void read_index(const char *path, const char[UUID_STR_LEN], index_func);
|
void read_index(const char *path, const char[UUID_STR_LEN], const char *type, index_func);
|
||||||
|
|
||||||
void incremental_read(GHashTable *table, const char *filepath);
|
void incremental_read(GHashTable *table, const char *filepath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must be called after write_document
|
* Must be called after write_document
|
||||||
*/
|
*/
|
||||||
void serializer_cleanup();
|
void thread_cleanup();
|
||||||
|
|
||||||
void write_index_descriptor(char *path, index_descriptor_t *desc);
|
void write_index_descriptor(char *path, index_descriptor_t *desc);
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ 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) {
|
||||||
fprintf(stderr, "Error while opening store: %s", mdb_strerror(open_ret));
|
fprintf(stderr, "Error while opening store: %s (%s)\n", mdb_strerror(open_ret), path);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include "walk.h"
|
#include "walk.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
parse_job_t *create_parse_job(const char *filepath, const struct stat *info, int base) {
|
__always_inline
|
||||||
|
parse_job_t *create_fs_parse_job(const char *filepath, const struct stat *info, int base) {
|
||||||
int len = (int) strlen(filepath);
|
int len = (int) strlen(filepath);
|
||||||
parse_job_t *job = malloc(sizeof(parse_job_t) + len);
|
parse_job_t *job = malloc(sizeof(parse_job_t) + len);
|
||||||
|
|
||||||
@@ -14,14 +15,22 @@ parse_job_t *create_parse_job(const char *filepath, const struct stat *info, int
|
|||||||
job->ext = len;
|
job->ext = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&(job->info), info, sizeof(struct stat));
|
job->info = *info;
|
||||||
|
|
||||||
|
memset(job->parent, 0, 16);
|
||||||
|
|
||||||
|
job->vfile.filepath = job->filepath;
|
||||||
|
job->vfile.read = fs_read;
|
||||||
|
job->vfile.close = fs_close;
|
||||||
|
job->vfile.fd = -1;
|
||||||
|
job->vfile.is_fs_file = TRUE;
|
||||||
|
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
|
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
|
||||||
if (typeflag == FTW_F && S_ISREG(info->st_mode)) {
|
if (ftw->level <= ScanCtx.depth && typeflag == FTW_F && S_ISREG(info->st_mode)) {
|
||||||
parse_job_t *job = create_parse_job(filepath, info, ftw->base);
|
parse_job_t *job = create_fs_parse_job(filepath, info, ftw->base);
|
||||||
tpool_add_work(ScanCtx.pool, parse, job);
|
tpool_add_work(ScanCtx.pool, parse, job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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(STDERR_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
|
||||||
92
src/main.c
92
src/main.c
@@ -1,16 +1,12 @@
|
|||||||
#include "sist.h"
|
#include "sist.h"
|
||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
#define DESCRIPTION "Lightning-fast file system indexer and search tool."
|
#define DESCRIPTION "Lightning-fast file system indexer and search tool."
|
||||||
#else
|
|
||||||
#define DESCRIPTION "Lightning-fast file system indexer and search tool. (SCAN ONLY)"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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.2";
|
static const char *const Version = "1.2.5";
|
||||||
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",
|
||||||
@@ -19,10 +15,9 @@ static const char *const usage[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void global_init() {
|
void global_init() {
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
curl_global_init(CURL_GLOBAL_NOTHING);
|
curl_global_init(CURL_GLOBAL_NOTHING);
|
||||||
#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) {
|
||||||
@@ -34,17 +29,13 @@ void init_dir(const char *dirpath) {
|
|||||||
uuid_unparse(uuid, ScanCtx.index.desc.uuid);
|
uuid_unparse(uuid, ScanCtx.index.desc.uuid);
|
||||||
time(&ScanCtx.index.desc.timestamp);
|
time(&ScanCtx.index.desc.timestamp);
|
||||||
strcpy(ScanCtx.index.desc.version, Version);
|
strcpy(ScanCtx.index.desc.version, Version);
|
||||||
|
strcpy(ScanCtx.index.desc.type, INDEX_TYPE_BIN);
|
||||||
|
|
||||||
write_index_descriptor(path, &ScanCtx.index.desc);
|
write_index_descriptor(path, &ScanCtx.index.desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
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%d\n", ScanCtx.threads);
|
|
||||||
printf("tn_qscale\t%.1f/31.0\n", ScanCtx.tn_qscale);
|
|
||||||
printf("tn_size\t\t%dpx\n", ScanCtx.tn_size);
|
|
||||||
printf("output\t\t%s\n", ScanCtx.index.path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sist2_scan(scan_args_t *args) {
|
void sist2_scan(scan_args_t *args) {
|
||||||
@@ -53,10 +44,14 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
ScanCtx.tn_size = args->size;
|
ScanCtx.tn_size = args->size;
|
||||||
ScanCtx.content_size = args->content_size;
|
ScanCtx.content_size = args->content_size;
|
||||||
ScanCtx.threads = args->threads;
|
ScanCtx.threads = args->threads;
|
||||||
|
ScanCtx.depth = args->depth;
|
||||||
|
ScanCtx.archive_mode = args->archive_mode;
|
||||||
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
|
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
|
||||||
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
|
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
|
||||||
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
||||||
ScanCtx.index.desc.root_len = (short) strlen(ScanCtx.index.desc.root);
|
ScanCtx.index.desc.root_len = (short) strlen(ScanCtx.index.desc.root);
|
||||||
|
ScanCtx.tesseract_lang = args->tesseract_lang;
|
||||||
|
ScanCtx.tesseract_path = args->tesseract_path;
|
||||||
|
|
||||||
init_dir(ScanCtx.index.path);
|
init_dir(ScanCtx.index.path);
|
||||||
|
|
||||||
@@ -92,7 +87,7 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
printf("Loaded %d items in to mtime table.", g_hash_table_size(ScanCtx.original_table));
|
printf("Loaded %d items in to mtime table.", g_hash_table_size(ScanCtx.original_table));
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanCtx.pool = tpool_create(args->threads, serializer_cleanup);
|
ScanCtx.pool = tpool_create(args->threads, thread_cleanup);
|
||||||
tpool_start(ScanCtx.pool);
|
tpool_start(ScanCtx.pool);
|
||||||
walk_directory_tree(ScanCtx.index.desc.root);
|
walk_directory_tree(ScanCtx.index.desc.root);
|
||||||
tpool_wait(ScanCtx.pool);
|
tpool_wait(ScanCtx.pool);
|
||||||
@@ -124,10 +119,10 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
store_destroy(ScanCtx.index.store);
|
store_destroy(ScanCtx.index.store);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
void sist2_index(index_args_t *args) {
|
void sist2_index(index_args_t *args) {
|
||||||
|
|
||||||
IndexCtx.es_url = args->es_url;
|
IndexCtx.es_url = args->es_url;
|
||||||
|
IndexCtx.batch_size = args->batch_size;
|
||||||
|
|
||||||
if (!args->print) {
|
if (!args->print) {
|
||||||
elastic_init(args->force_reset);
|
elastic_init(args->force_reset);
|
||||||
@@ -137,8 +132,12 @@ void sist2_index(index_args_t *args) {
|
|||||||
snprintf(descriptor_path, PATH_MAX, "%s/descriptor.json", args->index_path);
|
snprintf(descriptor_path, PATH_MAX, "%s/descriptor.json", args->index_path);
|
||||||
|
|
||||||
index_descriptor_t desc = read_index_descriptor(descriptor_path);
|
index_descriptor_t desc = read_index_descriptor(descriptor_path);
|
||||||
if (strcmp(desc.version, Version) != 0) {
|
|
||||||
fprintf(stderr, "Version mismatch! Index is v%s but executable is v%s\n", desc.version, Version);
|
LOG_DEBUGF("main.c", "descriptor version %s (%s)", desc.version, desc.type)
|
||||||
|
|
||||||
|
if (strcmp(desc.version, Version) != 0 && strcmp(desc.version, INDEX_VERSION_EXTERNAL) != 0) {
|
||||||
|
fprintf(stderr, "Version mismatch! Index is %s but executable is %s/%s\n",
|
||||||
|
desc.version, Version, INDEX_VERSION_EXTERNAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,13 +159,14 @@ void sist2_index(index_args_t *args) {
|
|||||||
if (strncmp(de->d_name, "_index_", sizeof("_index_") - 1) == 0) {
|
if (strncmp(de->d_name, "_index_", sizeof("_index_") - 1) == 0) {
|
||||||
char file_path[PATH_MAX];
|
char file_path[PATH_MAX];
|
||||||
snprintf(file_path, PATH_MAX, "%s/%s", args->index_path, de->d_name);
|
snprintf(file_path, PATH_MAX, "%s/%s", args->index_path, de->d_name);
|
||||||
read_index(file_path, desc.uuid, f);
|
read_index(file_path, desc.uuid, desc.type, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
if (!args->print) {
|
if (!args->print) {
|
||||||
elastic_flush();
|
elastic_flush();
|
||||||
destroy_indexer();
|
destroy_indexer(args->script, desc.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +174,7 @@ void sist2_web(web_args_t *args) {
|
|||||||
|
|
||||||
WebCtx.es_url = args->es_url;
|
WebCtx.es_url = args->es_url;
|
||||||
WebCtx.index_count = args->index_count;
|
WebCtx.index_count = args->index_count;
|
||||||
|
WebCtx.b64credentials = args->b64credentials;
|
||||||
|
|
||||||
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]);
|
||||||
@@ -195,7 +196,6 @@ void sist2_web(web_args_t *args) {
|
|||||||
|
|
||||||
serve(args->bind, args->port);
|
serve(args->bind, args->port);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
@@ -203,41 +203,54 @@ int main(int argc, const char *argv[]) {
|
|||||||
global_init();
|
global_init();
|
||||||
|
|
||||||
scan_args_t *scan_args = scan_args_create();
|
scan_args_t *scan_args = scan_args_create();
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
index_args_t *index_args = index_args_create();
|
index_args_t *index_args = index_args_create();
|
||||||
web_args_t *web_args = web_args_create();
|
web_args_t *web_args = web_args_create();
|
||||||
#endif
|
|
||||||
|
|
||||||
char * common_es_url = NULL;
|
int arg_version = 0;
|
||||||
|
|
||||||
|
char *common_es_url = NULL;
|
||||||
|
|
||||||
struct argparse_option options[] = {
|
struct argparse_option options[] = {
|
||||||
OPT_HELP(),
|
OPT_HELP(),
|
||||||
|
|
||||||
|
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"),
|
||||||
OPT_FLOAT('q', "quality", &scan_args->quality,
|
OPT_FLOAT('q', "quality", &scan_args->quality,
|
||||||
"Thumbnail quality, on a scale of 1.0 to 31.0, 1.0 being the best. DEFAULT=15"),
|
"Thumbnail quality, on a scale of 1.0 to 31.0, 1.0 being the best. DEFAULT=5"),
|
||||||
OPT_INTEGER(0, "size", &scan_args->size, "Thumbnail size, in pixels. DEFAULT=200"),
|
OPT_INTEGER(0, "size", &scan_args->size,
|
||||||
|
"Thumbnail size, in pixels. Use negative value to disable. DEFAULT=500"),
|
||||||
OPT_INTEGER(0, "content-size", &scan_args->content_size,
|
OPT_INTEGER(0, "content-size", &scan_args->content_size,
|
||||||
"Number of bytes to be extracted from text documents. DEFAULT=4096"),
|
"Number of bytes to be extracted from text documents. Use negative value to disable. DEFAULT=32768"),
|
||||||
OPT_STRING(0, "incremental", &scan_args->incremental,
|
OPT_STRING(0, "incremental", &scan_args->incremental,
|
||||||
"Reuse an existing index and only scan modified files."),
|
"Reuse an existing index and only scan modified files."),
|
||||||
OPT_STRING('o', "output", &scan_args->output, "Output directory. DEFAULT=index.sist2/"),
|
OPT_STRING('o', "output", &scan_args->output, "Output directory. DEFAULT=index.sist2/"),
|
||||||
OPT_STRING(0, "rewrite-url", &scan_args->rewrite_url, "Serve files from this url instead of from disk."),
|
OPT_STRING(0, "rewrite-url", &scan_args->rewrite_url, "Serve files from this url instead of from disk."),
|
||||||
OPT_STRING(0, "name", &scan_args->name, "Index display name. DEFAULT: (name of the directory)"),
|
OPT_STRING(0, "name", &scan_args->name, "Index display name. DEFAULT: (name of the directory)"),
|
||||||
|
OPT_INTEGER(0, "depth", &scan_args->depth, "Scan up to DEPTH subdirectories deep. "
|
||||||
|
"Use 0 to only scan files in PATH. DEFAULT: -1"),
|
||||||
|
OPT_STRING(0, "archive", &scan_args->archive, "Archive file mode (skip|list|shallow|recurse). "
|
||||||
|
"skip: Don't parse, list: only get file names as text, "
|
||||||
|
"shallow: Don't parse archives inside archives. DEFAULT: recurse"),
|
||||||
|
OPT_STRING(0, "ocr", &scan_args->tesseract_lang, "Tesseract language (use tesseract --list-langs to see "
|
||||||
|
"which are installed on your machine)"),
|
||||||
|
|
||||||
#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_INTEGER(0, "batch-size", &index_args->batch_size, "Index batch size. DEFAULT: 100"),
|
||||||
OPT_BOOLEAN('f', "force-reset", &index_args->force_reset, "Reset Elasticsearch mappings and settings. "
|
OPT_BOOLEAN('f', "force-reset", &index_args->force_reset, "Reset Elasticsearch mappings and settings. "
|
||||||
"(You must use this option the first time you use the index command)"),
|
"(You must use this option the first time you use the index command)"),
|
||||||
|
|
||||||
OPT_GROUP("Web options"),
|
OPT_GROUP("Web 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. DEFAULT=http://localhost:9200"),
|
||||||
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
||||||
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
||||||
#endif
|
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
|
||||||
|
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
};
|
};
|
||||||
@@ -247,10 +260,17 @@ int main(int argc, const char *argv[]) {
|
|||||||
argparse_describe(&argparse, DESCRIPTION, EPILOG);
|
argparse_describe(&argparse, DESCRIPTION, EPILOG);
|
||||||
argc = argparse_parse(&argparse, argc, argv);
|
argc = argparse_parse(&argparse, argc, argv);
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
if (arg_version) {
|
||||||
|
printf(Version);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LogCtx.very_verbose != 0) {
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
argparse_usage(&argparse);
|
argparse_usage(&argparse);
|
||||||
@@ -265,7 +285,6 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
else if (strcmp(argv[0], "index") == 0) {
|
else if (strcmp(argv[0], "index") == 0) {
|
||||||
|
|
||||||
int err = index_args_validate(index_args, argc, argv);
|
int err = index_args_validate(index_args, argc, argv);
|
||||||
@@ -283,12 +302,17 @@ int main(int argc, const char *argv[]) {
|
|||||||
sist2_web(web_args);
|
sist2_web(web_args);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Invalid command: '%s'\n", argv[0]);
|
fprintf(stderr, "Invalid command: '%s'\n", argv[0]);
|
||||||
argparse_usage(&argparse);
|
argparse_usage(&argparse);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
scan_args_destroy(scan_args);
|
||||||
|
|
||||||
|
index_args_destroy(index_args);
|
||||||
|
web_args_destroy(web_args);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
157
src/parsing/arc.c
Normal file
157
src/parsing/arc.c
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
#include "arc.h"
|
||||||
|
#include "src/ctx.h"
|
||||||
|
|
||||||
|
#define ARC_BUF_SIZE 8192
|
||||||
|
|
||||||
|
int should_parse_filtered_file(const char *filepath, int ext) {
|
||||||
|
char tmp[PATH_MAX * 2];
|
||||||
|
|
||||||
|
if (ext == 0) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(tmp, filepath, ext - 1);
|
||||||
|
*(tmp + ext - 1) = '\0';
|
||||||
|
|
||||||
|
char *idx = strrchr(tmp, '.');
|
||||||
|
|
||||||
|
if (idx == NULL) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(idx, ".tar") == 0) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int arc_read(struct vfile *f, void *buf, size_t size) {
|
||||||
|
return archive_read_data(f->arc, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct arc_data {
|
||||||
|
vfile_t *f;
|
||||||
|
char buf[ARC_BUF_SIZE];
|
||||||
|
} arc_data_f;
|
||||||
|
|
||||||
|
int vfile_open_callback(struct archive *a, void *user_data) {
|
||||||
|
arc_data_f *data = user_data;
|
||||||
|
|
||||||
|
if (data->f->is_fs_file && data->f->fd == -1) {
|
||||||
|
data->f->fd = open(data->f->filepath, O_RDONLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ARCHIVE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
long vfile_read_callback(struct archive *a, void *user_data, const void **buf) {
|
||||||
|
arc_data_f *data = user_data;
|
||||||
|
|
||||||
|
*buf = data->buf;
|
||||||
|
return data->f->read(data->f, data->buf, ARC_BUF_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int vfile_close_callback(struct archive *a, void *user_data) {
|
||||||
|
arc_data_f *data = user_data;
|
||||||
|
|
||||||
|
if (data->f->close != NULL) {
|
||||||
|
data->f->close(data->f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ARCHIVE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_archive(vfile_t *f, document_t *doc) {
|
||||||
|
|
||||||
|
struct archive *a;
|
||||||
|
struct archive_entry *entry;
|
||||||
|
|
||||||
|
|
||||||
|
arc_data_f data;
|
||||||
|
data.f = f;
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
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);
|
||||||
|
} 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(
|
||||||
|
a, &data,
|
||||||
|
vfile_open_callback,
|
||||||
|
vfile_read_callback,
|
||||||
|
vfile_close_callback
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != ARCHIVE_OK) {
|
||||||
|
LOG_ERRORF(doc->filepath, "(arc.c) [%d] %s", ret, archive_error_string(a))
|
||||||
|
archive_read_free(a);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ScanCtx.archive_mode == ARC_MODE_LIST) {
|
||||||
|
|
||||||
|
dyn_buffer_t buf = dyn_buffer_create();
|
||||||
|
|
||||||
|
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||||
|
if (S_ISREG(archive_entry_stat(entry)->st_mode)) {
|
||||||
|
|
||||||
|
char *path = (char *) archive_entry_pathname(entry);
|
||||||
|
|
||||||
|
dyn_buffer_append_string(&buf, path);
|
||||||
|
dyn_buffer_write_char(&buf, '\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dyn_buffer_write_char(&buf, '\0');
|
||||||
|
|
||||||
|
meta_line_t *meta_list = malloc(sizeof(meta_line_t) + buf.cur);
|
||||||
|
meta_list->key = MetaContent;
|
||||||
|
strcpy(meta_list->strval, buf.buf);
|
||||||
|
APPEND_META(doc, meta_list);
|
||||||
|
dyn_buffer_destroy(&buf);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
parse_job_t *sub_job = malloc(sizeof(parse_job_t) + PATH_MAX * 2);
|
||||||
|
|
||||||
|
sub_job->vfile.close = NULL;
|
||||||
|
sub_job->vfile.read = arc_read;
|
||||||
|
sub_job->vfile.arc = a;
|
||||||
|
sub_job->vfile.filepath = sub_job->filepath;
|
||||||
|
sub_job->vfile.is_fs_file = FALSE;
|
||||||
|
memcpy(sub_job->parent, doc->uuid, sizeof(uuid_t));
|
||||||
|
|
||||||
|
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||||
|
sub_job->info = *archive_entry_stat(entry);
|
||||||
|
if (S_ISREG(sub_job->info.st_mode)) {
|
||||||
|
sprintf(sub_job->filepath, "%s#/%s", f->filepath, archive_entry_pathname(entry));
|
||||||
|
sub_job->base = (int) (strrchr(sub_job->filepath, '/') - sub_job->filepath) + 1;
|
||||||
|
|
||||||
|
char *p = strrchr(sub_job->filepath, '.');
|
||||||
|
if (p != NULL) {
|
||||||
|
sub_job->ext = (int) (p - sub_job->filepath + 1);
|
||||||
|
} else {
|
||||||
|
sub_job->ext = (int) strlen(sub_job->filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(sub_job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(sub_job);
|
||||||
|
}
|
||||||
|
|
||||||
|
archive_read_free(a);
|
||||||
|
}
|
||||||
12
src/parsing/arc.h
Normal file
12
src/parsing/arc.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef SIST2_ARC_H
|
||||||
|
#define SIST2_ARC_H
|
||||||
|
|
||||||
|
#include "src/sist.h"
|
||||||
|
|
||||||
|
int should_parse_filtered_file(const char *filepath, int ext);
|
||||||
|
|
||||||
|
void parse_archive(vfile_t *f, document_t *doc);
|
||||||
|
|
||||||
|
int arc_read(struct vfile * f, void *buf, size_t size);
|
||||||
|
|
||||||
|
#endif
|
||||||
114
src/parsing/doc.c
Normal file
114
src/parsing/doc.c
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#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 options;
|
||||||
|
if (LogCtx.very_verbose) {
|
||||||
|
options = XML_PARSE_NONET;
|
||||||
|
} else {
|
||||||
|
options = XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = opcXmlReaderOpen(c, &reader, part, NULL, "UTF-8", options);
|
||||||
|
|
||||||
|
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
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
#include "ft2build.h"
|
|
||||||
#include "freetype/freetype.h"
|
|
||||||
|
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
__thread FT_Library library = NULL;
|
__thread FT_Library ft_lib = NULL;
|
||||||
|
|
||||||
|
|
||||||
typedef struct text_dimensions {
|
typedef struct text_dimensions {
|
||||||
@@ -139,16 +137,17 @@ void bmp_format(dyn_buffer_t *buf, text_dimensions_t dimensions, const unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
||||||
if (library == NULL) {
|
if (ft_lib == NULL) {
|
||||||
FT_Init_FreeType(&library);
|
FT_Init_FreeType(&ft_lib);
|
||||||
}
|
}
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_Face face;
|
FT_Face face;
|
||||||
FT_Error err = FT_New_Memory_Face(library, (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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,11 +168,16 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
strcpy(meta_name->strval, font_name);
|
strcpy(meta_name->strval, font_name);
|
||||||
APPEND_META(doc, meta_name)
|
APPEND_META(doc, meta_name)
|
||||||
|
|
||||||
|
if (ScanCtx.tn_size <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int pixel = 64;
|
int pixel = 64;
|
||||||
int num_chars = (int) strlen(font_name);
|
int num_chars = (int) strlen(font_name);
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
#define MIN_SIZE 32
|
#define MIN_SIZE 32
|
||||||
|
#define AVIO_BUF_SIZE 8192
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
AVCodecContext *alloc_jpeg_encoder(int dstW, int dstH, float qscale) {
|
AVCodecContext *alloc_jpeg_encoder(int dstW, int dstH, float qscale) {
|
||||||
@@ -76,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,7 +92,10 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
|
|
||||||
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);
|
||||||
@@ -108,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);
|
||||||
@@ -116,9 +124,10 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define APPEND_TAG_META(doc, tag, keyname) \
|
#define APPEND_TAG_META(doc, tag_, keyname) \
|
||||||
text_buffer_t tex = text_buffer_create(-1); \
|
text_buffer_t tex = text_buffer_create(-1); \
|
||||||
text_buffer_append_string0(&tex, tag->value); \
|
text_buffer_append_string0(&tex, tag_->value); \
|
||||||
|
text_buffer_terminate_string(&tex); \
|
||||||
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
||||||
meta_tag->key = keyname; \
|
meta_tag->key = keyname; \
|
||||||
strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
|
strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
|
||||||
@@ -151,50 +160,65 @@ void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void append_video_meta(AVFormatContext *pFormatCtx, document_t *doc, int include_audio_tags) {
|
void
|
||||||
|
append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) {
|
||||||
|
|
||||||
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
if (is_video) {
|
||||||
meta_duration->key = MetaMediaDuration;
|
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
||||||
meta_duration->longval = pFormatCtx->duration / AV_TIME_BASE;
|
meta_duration->key = MetaMediaDuration;
|
||||||
APPEND_META(doc, meta_duration)
|
meta_duration->longval = pFormatCtx->duration / AV_TIME_BASE;
|
||||||
|
APPEND_META(doc, meta_duration)
|
||||||
|
|
||||||
meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
|
meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
|
||||||
meta_bitrate->key = MetaMediaBitrate;
|
meta_bitrate->key = MetaMediaBitrate;
|
||||||
meta_bitrate->longval = pFormatCtx->bit_rate;
|
meta_bitrate->longval = pFormatCtx->bit_rate;
|
||||||
APPEND_META(doc, meta_bitrate)
|
APPEND_META(doc, meta_bitrate)
|
||||||
|
}
|
||||||
|
|
||||||
AVDictionaryEntry *tag = NULL;
|
AVDictionaryEntry *tag = NULL;
|
||||||
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
if (is_video) {
|
||||||
char key[32];
|
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||||
strncpy(key, tag->key, sizeof(key));
|
if (include_audio_tags && strcmp(tag->key, "title") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaTitle)
|
||||||
char *ptr = key;
|
} else if (strcmp(tag->key, "comment") == 0) {
|
||||||
for (; *ptr; ++ptr) *ptr = (char) tolower(*ptr);
|
APPEND_TAG_META(doc, tag, MetaContent)
|
||||||
|
} else if (include_audio_tags && strcmp(tag->key, "artist") == 0) {
|
||||||
if (strcmp(key, "title") == 0 && include_audio_tags) {
|
APPEND_TAG_META(doc, tag, MetaArtist)
|
||||||
APPEND_TAG_META(doc, tag, MetaTitle)
|
}
|
||||||
} else if (strcmp(key, "comment") == 0) {
|
}
|
||||||
APPEND_TAG_META(doc, tag, MetaContent)
|
} else {
|
||||||
|
// EXIF metadata
|
||||||
|
while ((tag = av_dict_get(frame->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||||
|
if (include_audio_tags && strcmp(tag->key, "Artist") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaArtist)
|
||||||
|
} else if (strcmp(tag->key, "ImageDescription") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaContent)
|
||||||
|
} else if (strcmp(tag->key, "Make") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifMake)
|
||||||
|
} else if (strcmp(tag->key, "Model") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifModel)
|
||||||
|
} else if (strcmp(tag->key, "Software") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifSoftware)
|
||||||
|
} else if (strcmp(tag->key, "FNumber") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifFNumber)
|
||||||
|
} else if (strcmp(tag->key, "FocalLength") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifFocalLength)
|
||||||
|
} else if (strcmp(tag->key, "UserComment") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifUserComment)
|
||||||
|
} else if (strcmp(tag->key, "ISOSpeedRatings") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifIsoSpeedRatings)
|
||||||
|
} else if (strcmp(tag->key, "ExposureTime") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifExposureTime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_media(const char *filepath, document_t *doc) {
|
void parse_media(AVFormatContext *pFormatCtx, document_t *doc) {
|
||||||
|
|
||||||
int video_stream = -1;
|
int video_stream = -1;
|
||||||
int audio_stream = -1;
|
int audio_stream = -1;
|
||||||
|
|
||||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
|
||||||
if (pFormatCtx == NULL) {
|
|
||||||
fprintf(stderr, "Could not allocate AVFormatContext! %s \n", filepath);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
|
||||||
if (res < 0) {
|
|
||||||
fprintf(stderr, "media error: %s %s\n", filepath, av_err2str(res));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
avformat_find_stream_info(pFormatCtx, NULL);
|
avformat_find_stream_info(pFormatCtx, NULL);
|
||||||
|
|
||||||
for (int i = (int) pFormatCtx->nb_streams - 1; i >= 0; i--) {
|
for (int i = (int) pFormatCtx->nb_streams - 1; i >= 0; i--) {
|
||||||
@@ -233,14 +257,9 @@ void parse_media(const char *filepath, document_t *doc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video_stream != -1) {
|
if (video_stream != -1 && ScanCtx.tn_size > 0) {
|
||||||
AVStream *stream = pFormatCtx->streams[video_stream];
|
AVStream *stream = pFormatCtx->streams[video_stream];
|
||||||
|
|
||||||
if (stream->nb_frames > 1) {
|
|
||||||
//This is a video (not a still image)
|
|
||||||
append_video_meta(pFormatCtx, doc, audio_stream == -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stream->codecpar->width <= MIN_SIZE || stream->codecpar->height <= MIN_SIZE) {
|
if (stream->codecpar->width <= MIN_SIZE || stream->codecpar->height <= MIN_SIZE) {
|
||||||
avformat_close_input(&pFormatCtx);
|
avformat_close_input(&pFormatCtx);
|
||||||
avformat_free_context(pFormatCtx);
|
avformat_free_context(pFormatCtx);
|
||||||
@@ -265,7 +284,7 @@ void parse_media(const char *filepath, 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);
|
||||||
@@ -273,6 +292,8 @@ void parse_media(const char *filepath, document_t *doc) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append_video_meta(pFormatCtx, frame, doc, audio_stream == -1, stream->nb_frames > 1);
|
||||||
|
|
||||||
// Scale frame
|
// Scale frame
|
||||||
AVFrame *scaled_frame = scale_frame(decoder, frame, ScanCtx.tn_size);
|
AVFrame *scaled_frame = scale_frame(decoder, frame, ScanCtx.tn_size);
|
||||||
|
|
||||||
@@ -308,3 +329,69 @@ void parse_media(const char *filepath, document_t *doc) {
|
|||||||
avformat_free_context(pFormatCtx);
|
avformat_free_context(pFormatCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_media_filename(const char *filepath, document_t *doc) {
|
||||||
|
|
||||||
|
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||||
|
if (pFormatCtx == NULL) {
|
||||||
|
LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
||||||
|
if (res < 0) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_media(pFormatCtx, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int vfile_read(void *ptr, uint8_t *buf, int buf_size) {
|
||||||
|
struct vfile *f = ptr;
|
||||||
|
|
||||||
|
int ret = f->read(f, buf, buf_size);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
return AVERROR_EOF;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_media_vfile(struct vfile *f, document_t *doc) {
|
||||||
|
|
||||||
|
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||||
|
if (pFormatCtx == NULL) {
|
||||||
|
LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *buffer = (unsigned char *) av_malloc(AVIO_BUF_SIZE);
|
||||||
|
AVIOContext *io_ctx = avio_alloc_context(buffer, AVIO_BUF_SIZE, 0, f, vfile_read, NULL, NULL);
|
||||||
|
|
||||||
|
pFormatCtx->pb = io_ctx;
|
||||||
|
pFormatCtx->flags |= AVFMT_FLAG_CUSTOM_IO;
|
||||||
|
|
||||||
|
int res = avformat_open_input(&pFormatCtx, "", NULL, NULL);
|
||||||
|
if (res == -5) {
|
||||||
|
// 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;
|
||||||
|
} else if (res < 0) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_media(pFormatCtx, doc);
|
||||||
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#define MIN_VIDEO_SIZE 1024 * 64
|
#define MIN_VIDEO_SIZE 1024 * 64
|
||||||
#define MIN_IMAGE_SIZE 1024 * 2
|
#define MIN_IMAGE_SIZE 1024 * 2
|
||||||
|
|
||||||
void parse_media(const char * filepath, document_t *doc);
|
void parse_media_filename(const char * filepath, document_t *doc);
|
||||||
|
|
||||||
|
void parse_media_vfile(struct vfile *f, document_t *doc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#define MIME_EMPTY 1
|
#define MIME_EMPTY 1
|
||||||
|
|
||||||
#define DONT_PARSE 0x80000000
|
#define DONT_PARSE 0x80000000
|
||||||
#define SHOULD_PARSE(mime_id) (mime_id & DONT_PARSE) != DONT_PARSE
|
#define SHOULD_PARSE(mime_id) (mime_id & DONT_PARSE) != DONT_PARSE && mime_id != 0
|
||||||
|
|
||||||
#define PDF_MASK 0x40000000
|
#define PDF_MASK 0x40000000
|
||||||
#define IS_PDF(mime_id) (mime_id & PDF_MASK) == PDF_MASK
|
#define IS_PDF(mime_id) (mime_id & PDF_MASK) == PDF_MASK
|
||||||
@@ -16,6 +16,15 @@
|
|||||||
#define FONT_MASK 0x20000000
|
#define FONT_MASK 0x20000000
|
||||||
#define IS_FONT(mime_id) (mime_id & FONT_MASK) == FONT_MASK
|
#define IS_FONT(mime_id) (mime_id & FONT_MASK) == FONT_MASK
|
||||||
|
|
||||||
|
#define ARC_MASK 0x10000000
|
||||||
|
#define IS_ARC(mime_id) (mime_id & ARC_MASK) == ARC_MASK
|
||||||
|
|
||||||
|
#define ARC_FILTER_MASK 0x08000000
|
||||||
|
#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,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ enum mime {
|
|||||||
application_freeloader=655372,
|
application_freeloader=655372,
|
||||||
application_futuresplash=655373,
|
application_futuresplash=655373,
|
||||||
application_groupwise=655374,
|
application_groupwise=655374,
|
||||||
application_gzip=655375,
|
application_gzip=655375 | 0x08000000,
|
||||||
application_hta=655376,
|
application_hta=655376,
|
||||||
application_i_deas=655377,
|
application_i_deas=655377,
|
||||||
application_iges=655378,
|
application_iges=655378,
|
||||||
@@ -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,
|
||||||
@@ -82,342 +82,346 @@ enum mime {
|
|||||||
application_vnd_xara=655434,
|
application_vnd_xara=655434,
|
||||||
application_vocaltec_media_desc=655435,
|
application_vocaltec_media_desc=655435,
|
||||||
application_vocaltec_media_file=655436,
|
application_vocaltec_media_file=655436,
|
||||||
application_winhelp=655437,
|
application_warc=655437,
|
||||||
application_wordperfect=655438,
|
application_winhelp=655438,
|
||||||
application_wordperfect6_0=655439,
|
application_wordperfect=655439,
|
||||||
application_wordperfect6_1=655440,
|
application_wordperfect6_0=655440,
|
||||||
application_x_123=655441,
|
application_wordperfect6_1=655441,
|
||||||
application_x_7z_compressed=655442,
|
application_x_123=655442,
|
||||||
application_x_aim=655443,
|
application_x_7z_compressed=655443 | 0x10000000,
|
||||||
application_x_apple_diskimage=655444,
|
application_x_aim=655444,
|
||||||
application_x_arc=655445,
|
application_x_apple_diskimage=655445,
|
||||||
application_x_archive=655446,
|
application_x_arc=655446 | 0x10000000,
|
||||||
application_x_atari_7800_rom=655447,
|
application_x_archive=655447,
|
||||||
application_x_authorware_bin=655448,
|
application_x_atari_7800_rom=655448,
|
||||||
application_x_authorware_map=655449,
|
application_x_authorware_bin=655449,
|
||||||
application_x_authorware_seg=655450,
|
application_x_authorware_map=655450,
|
||||||
application_x_avira_qua=655451,
|
application_x_authorware_seg=655451,
|
||||||
application_x_bcpio=655452,
|
application_x_avira_qua=655452,
|
||||||
application_x_bittorrent=655453,
|
application_x_bcpio=655453,
|
||||||
application_x_bsh=655454,
|
application_x_bittorrent=655454,
|
||||||
application_x_bytecode_python=655455,
|
application_x_bsh=655455,
|
||||||
application_x_bzip=655456,
|
application_x_bytecode_python=655456,
|
||||||
application_x_bzip2=655457,
|
application_x_bzip=655457,
|
||||||
application_x_cbr=655458,
|
application_x_bzip2=655458 | 0x08000000,
|
||||||
application_x_cbz=655459 | 0x40000000,
|
application_x_cbr=655459,
|
||||||
application_x_cdlink=655460,
|
application_x_cbz=655460 | 0x40000000,
|
||||||
application_x_chat=655461,
|
application_x_cdlink=655461,
|
||||||
application_x_chrome_extension=655462,
|
application_x_chat=655462,
|
||||||
application_x_cocoa=655463,
|
application_x_chrome_extension=655463,
|
||||||
application_x_conference=655464,
|
application_x_cocoa=655464,
|
||||||
application_x_coredump=655465,
|
application_x_conference=655465,
|
||||||
application_x_cpio=655466,
|
application_x_coredump=655466,
|
||||||
application_x_dbf=655467,
|
application_x_cpio=655467,
|
||||||
application_x_dbt=655468,
|
application_x_dbf=655468,
|
||||||
application_x_debian_package=655469,
|
application_x_dbt=655469,
|
||||||
application_x_deepv=655470,
|
application_x_debian_package=655470,
|
||||||
application_x_director=655471,
|
application_x_deepv=655471,
|
||||||
application_x_dmp=655472,
|
application_x_director=655472,
|
||||||
application_x_dosdriver=655473,
|
application_x_dmp=655473,
|
||||||
application_x_dosexec=655474,
|
application_x_dosdriver=655474,
|
||||||
application_x_dvi=655475,
|
application_x_dosexec=655475,
|
||||||
application_x_elc=655476,
|
application_x_dvi=655476,
|
||||||
|
application_x_elc=655477,
|
||||||
application_x_empty=1,
|
application_x_empty=1,
|
||||||
application_x_envoy=655478,
|
application_x_envoy=655479,
|
||||||
application_x_esrehber=655479,
|
application_x_esrehber=655480,
|
||||||
application_x_excel=655480,
|
application_x_excel=655481,
|
||||||
application_x_executable=655481,
|
application_x_executable=655482,
|
||||||
application_x_font_gdos=655482,
|
application_x_font_gdos=655483,
|
||||||
application_x_font_pf2=655483,
|
application_x_font_pf2=655484,
|
||||||
application_x_font_pfm=655484,
|
application_x_font_pfm=655485,
|
||||||
application_x_font_sfn=655485,
|
application_x_font_sfn=655486,
|
||||||
application_x_font_ttf=655486 | 0x20000000,
|
application_x_font_ttf=655487 | 0x20000000,
|
||||||
application_x_freelance=655487,
|
application_x_freelance=655488,
|
||||||
application_x_gamecube_rom=655488,
|
application_x_gamecube_rom=655489,
|
||||||
application_x_gdbm=655489,
|
application_x_gdbm=655490,
|
||||||
application_x_gettext_translation=655490,
|
application_x_gettext_translation=655491,
|
||||||
application_x_git=655491,
|
application_x_git=655492,
|
||||||
application_x_gsp=655492,
|
application_x_gsp=655493,
|
||||||
application_x_gss=655493,
|
application_x_gss=655494,
|
||||||
application_x_gtar=655494,
|
application_x_gtar=655495,
|
||||||
application_x_gzip=655495,
|
application_x_gzip=655496,
|
||||||
application_x_hdf=655496,
|
application_x_hdf=655497,
|
||||||
application_x_helpfile=655497,
|
application_x_helpfile=655498,
|
||||||
application_x_httpd_imap=655498,
|
application_x_httpd_imap=655499,
|
||||||
application_x_ima=655499,
|
application_x_ima=655500,
|
||||||
application_x_innosetup=655500,
|
application_x_innosetup=655501,
|
||||||
application_x_internett_signup=655501,
|
application_x_internett_signup=655502,
|
||||||
application_x_inventor=655502,
|
application_x_inventor=655503,
|
||||||
application_x_ip2=655503,
|
application_x_ip2=655504,
|
||||||
application_x_java_applet=655504,
|
application_x_java_applet=655505,
|
||||||
application_x_java_commerce=655505,
|
application_x_java_commerce=655506,
|
||||||
application_x_java_image=655506,
|
application_x_java_image=655507,
|
||||||
application_x_java_jmod=655507,
|
application_x_java_jmod=655508,
|
||||||
application_x_java_keystore=655508,
|
application_x_java_keystore=655509,
|
||||||
application_x_kdelnk=655509,
|
application_x_kdelnk=655510,
|
||||||
application_x_koan=655510,
|
application_x_koan=655511,
|
||||||
application_x_latex=655511,
|
application_x_latex=655512,
|
||||||
application_x_livescreen=655512,
|
application_x_livescreen=655513,
|
||||||
application_x_lotus=655513,
|
application_x_lotus=655514,
|
||||||
application_x_lz4=655514,
|
application_x_lz4=655515 | 0x08000000,
|
||||||
application_x_lz4_json=655515,
|
application_x_lz4_json=655516,
|
||||||
application_x_lzh=655516,
|
application_x_lzh=655517,
|
||||||
application_x_lzh_compressed=655517,
|
application_x_lzh_compressed=655518,
|
||||||
application_x_lzx=655518,
|
application_x_lzip=655519 | 0x08000000,
|
||||||
application_x_mach_binary=655519,
|
application_x_lzma=655520 | 0x08000000,
|
||||||
application_x_mach_executable=655520,
|
application_x_lzop=655521 | 0x08000000,
|
||||||
application_x_magic_cap_package_1_0=655521,
|
application_x_lzx=655522,
|
||||||
application_x_mathcad=655522,
|
application_x_mach_binary=655523,
|
||||||
application_x_maxis_dbpf=655523,
|
application_x_mach_executable=655524,
|
||||||
application_x_meme=655524,
|
application_x_magic_cap_package_1_0=655525,
|
||||||
application_x_midi=655525,
|
application_x_mathcad=655526,
|
||||||
application_x_mif=655526,
|
application_x_maxis_dbpf=655527,
|
||||||
application_x_mix_transfer=655527,
|
application_x_meme=655528,
|
||||||
application_x_mobipocket_ebook=655528,
|
application_x_midi=655529,
|
||||||
application_x_ms_compress_szdd=655529,
|
application_x_mif=655530,
|
||||||
application_x_ms_pdb=655530,
|
application_x_mix_transfer=655531,
|
||||||
application_x_ms_reader=655531,
|
application_x_mobipocket_ebook=655532,
|
||||||
application_x_msaccess=655532,
|
application_x_ms_compress_szdd=655533,
|
||||||
application_x_navi_animation=655533,
|
application_x_ms_pdb=655534,
|
||||||
application_x_navidoc=655534,
|
application_x_ms_reader=655535,
|
||||||
application_x_navimap=655535,
|
application_x_msaccess=655536,
|
||||||
application_x_navistyle=655536,
|
application_x_navi_animation=655537,
|
||||||
application_x_nes_rom=655537,
|
application_x_navidoc=655538,
|
||||||
application_x_netcdf=655538,
|
application_x_navimap=655539,
|
||||||
application_x_newton_compatible_pkg=655539,
|
application_x_navistyle=655540,
|
||||||
application_x_nintendo_ds_rom=655540,
|
application_x_nes_rom=655541,
|
||||||
application_x_object=655541,
|
application_x_netcdf=655542,
|
||||||
application_x_omc=655542,
|
application_x_newton_compatible_pkg=655543,
|
||||||
application_x_omcdatamaker=655543,
|
application_x_nintendo_ds_rom=655544,
|
||||||
application_x_omcregerator=655544,
|
application_x_object=655545,
|
||||||
application_x_pagemaker=655545,
|
application_x_omc=655546,
|
||||||
application_x_pcl=655546,
|
application_x_omcdatamaker=655547,
|
||||||
application_x_pgp_keyring=655547,
|
application_x_omcregerator=655548,
|
||||||
application_x_pixclscript=655548,
|
application_x_pagemaker=655549,
|
||||||
application_x_pkcs7_certreqresp=655549,
|
application_x_pcl=655550,
|
||||||
application_x_pkcs7_signature=655550,
|
application_x_pgp_keyring=655551,
|
||||||
application_x_project=655551,
|
application_x_pixclscript=655552,
|
||||||
application_x_qpro=655552,
|
application_x_pkcs7_certreqresp=655553,
|
||||||
application_x_rar=655553,
|
application_x_pkcs7_signature=655554,
|
||||||
application_x_rpm=655554,
|
application_x_project=655555,
|
||||||
application_x_sdp=655555,
|
application_x_qpro=655556,
|
||||||
application_x_sea=655556,
|
application_x_rar=655557 | 0x10000000,
|
||||||
application_x_seelogo=655557,
|
application_x_rpm=655558,
|
||||||
application_x_setupscript=655558,
|
application_x_sdp=655559,
|
||||||
application_x_shar=655559,
|
application_x_sea=655560,
|
||||||
application_x_sharedlib=655560,
|
application_x_seelogo=655561,
|
||||||
application_x_shockwave_flash=655561,
|
application_x_setupscript=655562,
|
||||||
application_x_snappy_framed=655562,
|
application_x_shar=655563,
|
||||||
application_x_sprite=655563,
|
application_x_sharedlib=655564,
|
||||||
application_x_sqlite3=655564,
|
application_x_shockwave_flash=655565,
|
||||||
application_x_sv4cpio=655565,
|
application_x_snappy_framed=655566,
|
||||||
application_x_sv4crc=655566,
|
application_x_sprite=655567,
|
||||||
application_x_tar=655567,
|
application_x_sqlite3=655568,
|
||||||
application_x_tbook=655568,
|
application_x_sv4cpio=655569,
|
||||||
application_x_terminfo=655569,
|
application_x_sv4crc=655570,
|
||||||
application_x_terminfo2=655570,
|
application_x_tar=655571 | 0x10000000,
|
||||||
application_x_tex_tfm=655571,
|
application_x_tbook=655572,
|
||||||
application_x_texinfo=655572,
|
application_x_terminfo=655573,
|
||||||
application_x_ustar=655573,
|
application_x_terminfo2=655574,
|
||||||
application_x_visio=655574,
|
application_x_tex_tfm=655575,
|
||||||
application_x_vnd_audioexplosion_mzz=655575,
|
application_x_texinfo=655576,
|
||||||
application_x_vnd_ls_xpix=655576,
|
application_x_ustar=655577,
|
||||||
application_x_vrml=655577,
|
application_x_visio=655578,
|
||||||
application_x_wais_source=655578,
|
application_x_vnd_audioexplosion_mzz=655579,
|
||||||
application_x_wine_extension_ini=655579,
|
application_x_vnd_ls_xpix=655580,
|
||||||
application_x_wintalk=655580,
|
application_x_vrml=655581,
|
||||||
application_x_world=655581,
|
application_x_wais_source=655582,
|
||||||
application_x_wri=655582,
|
application_x_wine_extension_ini=655583,
|
||||||
application_x_x509_ca_cert=655583,
|
application_x_wintalk=655584,
|
||||||
application_x_xz=655584,
|
application_x_world=655585,
|
||||||
application_x_zip=655585,
|
application_x_wri=655586,
|
||||||
application_x_zstd=655586,
|
application_x_x509_ca_cert=655587,
|
||||||
application_xml=655587,
|
application_x_xz=655588 | 0x08000000,
|
||||||
application_zip=655588,
|
application_x_zip=655589,
|
||||||
application_zlib=655589,
|
application_x_zstd=655590 | 0x08000000,
|
||||||
audio_it=458982,
|
application_xml=655591,
|
||||||
audio_make=458983,
|
application_zip=655592 | 0x10000000,
|
||||||
audio_mid=458984,
|
application_zlib=655593,
|
||||||
audio_midi=458985,
|
audio_it=458986,
|
||||||
audio_mp4=458986,
|
audio_make=458987,
|
||||||
audio_mpeg=458987,
|
audio_mid=458988,
|
||||||
audio_ogg=458988,
|
audio_midi=458989,
|
||||||
audio_s3m=458989,
|
audio_mp4=458990,
|
||||||
audio_tsp_audio=458990,
|
audio_mpeg=458991,
|
||||||
audio_tsplayer=458991,
|
audio_ogg=458992,
|
||||||
audio_vnd_qcelp=458992,
|
audio_s3m=458993,
|
||||||
audio_voxware=458993,
|
audio_tsp_audio=458994,
|
||||||
audio_x_aiff=458994,
|
audio_tsplayer=458995,
|
||||||
audio_x_flac=458995,
|
audio_vnd_qcelp=458996,
|
||||||
audio_x_gsm=458996,
|
audio_voxware=458997,
|
||||||
audio_x_hx_aac_adts=458997,
|
audio_x_aiff=458998,
|
||||||
audio_x_jam=458998,
|
audio_x_flac=458999,
|
||||||
audio_x_liveaudio=458999,
|
audio_x_gsm=459000,
|
||||||
audio_x_m4a=459000,
|
audio_x_hx_aac_adts=459001,
|
||||||
audio_x_midi=459001,
|
audio_x_jam=459002,
|
||||||
audio_x_mod=459002,
|
audio_x_liveaudio=459003,
|
||||||
audio_x_mp4a_latm=459003,
|
audio_x_m4a=459004,
|
||||||
audio_x_mpeg_3=459004,
|
audio_x_midi=459005,
|
||||||
audio_x_mpequrl=459005,
|
audio_x_mod=459006,
|
||||||
audio_x_nspaudio=459006,
|
audio_x_mp4a_latm=459007,
|
||||||
audio_x_pn_realaudio=459007,
|
audio_x_mpeg_3=459008,
|
||||||
audio_x_psid=459008,
|
audio_x_mpequrl=459009,
|
||||||
audio_x_realaudio=459009,
|
audio_x_nspaudio=459010,
|
||||||
audio_x_twinvq=459010,
|
audio_x_pn_realaudio=459011,
|
||||||
audio_x_twinvq_plugin=459011,
|
audio_x_psid=459012,
|
||||||
audio_x_voc=459012,
|
audio_x_realaudio=459013,
|
||||||
audio_x_wav=459013,
|
audio_x_twinvq=459014,
|
||||||
audio_xm=459014,
|
audio_x_twinvq_plugin=459015,
|
||||||
font_otf=327943 | 0x20000000,
|
audio_x_voc=459016,
|
||||||
font_sfnt=327944 | 0x20000000,
|
audio_x_wav=459017,
|
||||||
font_woff=327945 | 0x20000000,
|
audio_xm=459018,
|
||||||
font_woff2=327946 | 0x20000000,
|
font_otf=327947 | 0x20000000,
|
||||||
image_cmu_raster=524555,
|
font_sfnt=327948 | 0x20000000,
|
||||||
image_fif=524556,
|
font_woff=327949 | 0x20000000,
|
||||||
image_florian=524557,
|
font_woff2=327950 | 0x20000000,
|
||||||
image_g3fax=524558,
|
image_cmu_raster=524559,
|
||||||
image_gif=524559,
|
image_fif=524560,
|
||||||
image_heic=524560,
|
image_florian=524561,
|
||||||
image_ief=524561,
|
image_g3fax=524562,
|
||||||
image_jpeg=524562,
|
image_gif=524563,
|
||||||
image_jutvision=524563,
|
image_heic=524564,
|
||||||
image_naplps=524564,
|
image_ief=524565,
|
||||||
image_pict=524565,
|
image_jpeg=524566,
|
||||||
image_png=524566,
|
image_jutvision=524567,
|
||||||
image_svg=524567 | 0x80000000,
|
image_naplps=524568,
|
||||||
image_svg_xml=524568 | 0x80000000,
|
image_pict=524569,
|
||||||
image_tiff=524569,
|
image_png=524570,
|
||||||
image_vnd_adobe_photoshop=524570 | 0x80000000,
|
image_svg=524571 | 0x80000000,
|
||||||
image_vnd_djvu=524571 | 0x80000000,
|
image_svg_xml=524572 | 0x80000000,
|
||||||
image_vnd_fpx=524572,
|
image_tiff=524573,
|
||||||
image_vnd_microsoft_icon=524573,
|
image_vnd_adobe_photoshop=524574 | 0x80000000,
|
||||||
image_vnd_rn_realflash=524574,
|
image_vnd_djvu=524575 | 0x80000000,
|
||||||
image_vnd_rn_realpix=524575,
|
image_vnd_fpx=524576,
|
||||||
image_vnd_wap_wbmp=524576,
|
image_vnd_microsoft_icon=524577,
|
||||||
image_vnd_xiff=524577,
|
image_vnd_rn_realflash=524578,
|
||||||
image_webp=524578,
|
image_vnd_rn_realpix=524579,
|
||||||
image_wmf=524579,
|
image_vnd_wap_wbmp=524580,
|
||||||
image_x_3ds=524580,
|
image_vnd_xiff=524581,
|
||||||
image_x_cmu_raster=524581,
|
image_webp=524582,
|
||||||
image_x_cur=524582,
|
image_wmf=524583,
|
||||||
image_x_dwg=524583,
|
image_x_3ds=524584,
|
||||||
image_x_eps=524584,
|
image_x_cmu_raster=524585,
|
||||||
image_x_exr=524585,
|
image_x_cur=524586,
|
||||||
image_x_gem=524586,
|
image_x_dwg=524587,
|
||||||
image_x_icns=524587,
|
image_x_eps=524588,
|
||||||
image_x_icon=524588 | 0x80000000,
|
image_x_exr=524589,
|
||||||
image_x_jg=524589,
|
image_x_gem=524590,
|
||||||
image_x_jps=524590,
|
image_x_icns=524591,
|
||||||
image_x_ms_bmp=524591,
|
image_x_icon=524592 | 0x80000000,
|
||||||
image_x_niff=524592,
|
image_x_jg=524593,
|
||||||
image_x_pcx=524593,
|
image_x_jps=524594,
|
||||||
image_x_pict=524594,
|
image_x_ms_bmp=524595,
|
||||||
image_x_portable_bitmap=524595,
|
image_x_niff=524596,
|
||||||
image_x_portable_graymap=524596,
|
image_x_pcx=524597,
|
||||||
image_x_portable_pixmap=524597,
|
image_x_pict=524598,
|
||||||
image_x_quicktime=524598,
|
image_x_portable_bitmap=524599,
|
||||||
image_x_rgb=524599,
|
image_x_portable_graymap=524600,
|
||||||
image_x_tga=524600,
|
image_x_portable_pixmap=524601,
|
||||||
image_x_tiff=524601,
|
image_x_quicktime=524602,
|
||||||
image_x_win_bitmap=524602,
|
image_x_rgb=524603,
|
||||||
image_x_xcf=524603 | 0x80000000,
|
image_x_tga=524604,
|
||||||
image_x_xpixmap=524604 | 0x80000000,
|
image_x_tiff=524605,
|
||||||
image_x_xwindowdump=524605,
|
image_x_win_bitmap=524606,
|
||||||
message_news=196926,
|
image_x_xcf=524607 | 0x80000000,
|
||||||
message_rfc822=196927,
|
image_x_xpixmap=524608 | 0x80000000,
|
||||||
model_vnd_dwf=65856,
|
image_x_xwindowdump=524609,
|
||||||
model_vnd_gdl=65857,
|
message_news=196930,
|
||||||
model_vnd_gs_gdl=65858,
|
message_rfc822=196931,
|
||||||
model_vrml=65859,
|
model_vnd_dwf=65860,
|
||||||
model_x_pov=65860,
|
model_vnd_gdl=65861,
|
||||||
text_PGP=590149,
|
model_vnd_gs_gdl=65862,
|
||||||
text_asp=590150,
|
model_vrml=65863,
|
||||||
text_css=590151,
|
model_x_pov=65864,
|
||||||
text_html=590152,
|
text_PGP=590153,
|
||||||
text_javascript=590153,
|
text_asp=590154,
|
||||||
text_mcf=590154,
|
text_css=590155,
|
||||||
text_pascal=590155,
|
text_html=590156,
|
||||||
text_plain=590156,
|
text_javascript=590157,
|
||||||
text_richtext=590157,
|
text_mcf=590158,
|
||||||
text_rtf=590158,
|
text_pascal=590159,
|
||||||
text_scriplet=590159,
|
text_plain=590160,
|
||||||
text_tab_separated_values=590160,
|
text_richtext=590161,
|
||||||
text_troff=590161,
|
text_rtf=590162,
|
||||||
text_uri_list=590162,
|
text_scriplet=590163,
|
||||||
text_vnd_abc=590163,
|
text_tab_separated_values=590164,
|
||||||
text_vnd_fmi_flexstor=590164,
|
text_troff=590165,
|
||||||
text_vnd_wap_wml=590165,
|
text_uri_list=590166,
|
||||||
text_vnd_wap_wmlscript=590166,
|
text_vnd_abc=590167,
|
||||||
text_webviewhtml=590167,
|
text_vnd_fmi_flexstor=590168,
|
||||||
text_x_Algol68=590168,
|
text_vnd_wap_wml=590169,
|
||||||
text_x_asm=590169,
|
text_vnd_wap_wmlscript=590170,
|
||||||
text_x_audiosoft_intra=590170,
|
text_webviewhtml=590171,
|
||||||
text_x_awk=590171,
|
text_x_Algol68=590172,
|
||||||
text_x_bcpl=590172,
|
text_x_asm=590173,
|
||||||
text_x_c=590173,
|
text_x_audiosoft_intra=590174,
|
||||||
text_x_c__=590174,
|
text_x_awk=590175,
|
||||||
text_x_component=590175,
|
text_x_bcpl=590176,
|
||||||
text_x_diff=590176,
|
text_x_c=590177,
|
||||||
text_x_fortran=590177,
|
text_x_c__=590178,
|
||||||
text_x_java=590178,
|
text_x_component=590179,
|
||||||
text_x_la_asf=590179,
|
text_x_diff=590180,
|
||||||
text_x_lisp=590180,
|
text_x_fortran=590181,
|
||||||
text_x_m=590181,
|
text_x_java=590182,
|
||||||
text_x_m4=590182,
|
text_x_la_asf=590183,
|
||||||
text_x_makefile=590183,
|
text_x_lisp=590184,
|
||||||
text_x_ms_regedit=590184,
|
text_x_m=590185,
|
||||||
text_x_msdos_batch=590185,
|
text_x_m4=590186,
|
||||||
text_x_objective_c=590186,
|
text_x_makefile=590187,
|
||||||
text_x_pascal=590187,
|
text_x_ms_regedit=590188,
|
||||||
text_x_perl=590188,
|
text_x_msdos_batch=590189,
|
||||||
text_x_php=590189,
|
text_x_objective_c=590190,
|
||||||
text_x_po=590190,
|
text_x_pascal=590191,
|
||||||
text_x_python=590191,
|
text_x_perl=590192,
|
||||||
text_x_ruby=590192,
|
text_x_php=590193,
|
||||||
text_x_sass=590193,
|
text_x_po=590194,
|
||||||
text_x_scss=590194,
|
text_x_python=590195,
|
||||||
text_x_server_parsed_html=590195,
|
text_x_ruby=590196,
|
||||||
text_x_setext=590196,
|
text_x_sass=590197,
|
||||||
text_x_sgml=590197,
|
text_x_scss=590198,
|
||||||
text_x_shellscript=590198,
|
text_x_server_parsed_html=590199,
|
||||||
text_x_speech=590199,
|
text_x_setext=590200,
|
||||||
text_x_tcl=590200,
|
text_x_sgml=590201,
|
||||||
text_x_tex=590201,
|
text_x_shellscript=590202,
|
||||||
text_x_uil=590202,
|
text_x_speech=590203,
|
||||||
text_x_uuencode=590203,
|
text_x_tcl=590204,
|
||||||
text_x_vcalendar=590204,
|
text_x_tex=590205,
|
||||||
text_x_vcard=590205,
|
text_x_uil=590206,
|
||||||
text_xml=590206,
|
text_x_uuencode=590207,
|
||||||
video_MP2T=393599,
|
text_x_vcalendar=590208,
|
||||||
video_animaflex=393600,
|
text_x_vcard=590209,
|
||||||
video_avi=393601,
|
text_xml=590210,
|
||||||
video_avs_video=393602,
|
video_MP2T=393603,
|
||||||
video_mp4=393603,
|
video_animaflex=393604,
|
||||||
video_mpeg=393604,
|
video_avi=393605,
|
||||||
video_quicktime=393605,
|
video_avs_video=393606,
|
||||||
video_vdo=393606,
|
video_mp4=393607,
|
||||||
video_vivo=393607,
|
video_mpeg=393608,
|
||||||
video_vnd_rn_realvideo=393608,
|
video_quicktime=393609,
|
||||||
video_vosaic=393609,
|
video_vdo=393610,
|
||||||
video_webm=393610,
|
video_vivo=393611,
|
||||||
video_x_amt_demorun=393611,
|
video_vnd_rn_realvideo=393612,
|
||||||
video_x_amt_showrun=393612,
|
video_vosaic=393613,
|
||||||
video_x_atomic3d_feature=393613,
|
video_webm=393614,
|
||||||
video_x_dl=393614,
|
video_x_amt_demorun=393615,
|
||||||
video_x_dv=393615,
|
video_x_amt_showrun=393616,
|
||||||
video_x_fli=393616,
|
video_x_atomic3d_feature=393617,
|
||||||
video_x_flv=393617,
|
video_x_dl=393618,
|
||||||
video_x_isvideo=393618,
|
video_x_dv=393619,
|
||||||
video_x_jng=393619 | 0x80000000,
|
video_x_fli=393620,
|
||||||
video_x_m4v=393620,
|
video_x_flv=393621,
|
||||||
video_x_matroska=393621,
|
video_x_isvideo=393622,
|
||||||
video_x_mng=393622,
|
video_x_jng=393623 | 0x80000000,
|
||||||
video_x_motion_jpeg=393623,
|
video_x_m4v=393624,
|
||||||
video_x_ms_asf=393624,
|
video_x_matroska=393625,
|
||||||
video_x_msvideo=393625,
|
video_x_mng=393626,
|
||||||
video_x_qtc=393626,
|
video_x_motion_jpeg=393627,
|
||||||
video_x_sgi_movie=393627,
|
video_x_ms_asf=393628,
|
||||||
x_epoc_x_sisx_app=721308,
|
video_x_msvideo=393629,
|
||||||
|
video_x_qtc=393630,
|
||||||
|
video_x_sgi_movie=393631,
|
||||||
|
x_epoc_x_sisx_app=721312,
|
||||||
};
|
};
|
||||||
char *mime_get_mime_text(unsigned int mime_id) {switch (mime_id) {
|
char *mime_get_mime_text(unsigned int mime_id) {switch (mime_id) {
|
||||||
case application_arj: return "application/arj";
|
case application_arj: return "application/arj";
|
||||||
@@ -832,6 +836,10 @@ case audio_x_hx_aac_adts: return "audio/x-hx-aac-adts";
|
|||||||
case application_x_chrome_extension: return "application/x-chrome-extension";
|
case application_x_chrome_extension: return "application/x-chrome-extension";
|
||||||
case image_heic: return "image/heic";
|
case image_heic: return "image/heic";
|
||||||
case image_x_gem: return "image/x-gem";
|
case image_x_gem: return "image/x-gem";
|
||||||
|
case application_x_lzma: return "application/x-lzma";
|
||||||
|
case application_warc: return "application/warc";
|
||||||
|
case application_x_lzip: return "application/x-lzip";
|
||||||
|
case application_x_lzop: return "application/x-lzop";
|
||||||
default: return NULL;}}
|
default: return NULL;}}
|
||||||
GHashTable *mime_get_ext_table() {GHashTable *ext_table = g_hash_table_new(g_str_hash, g_str_equal);
|
GHashTable *mime_get_ext_table() {GHashTable *ext_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
g_hash_table_insert(ext_table, "arj", (gpointer)application_arj);
|
g_hash_table_insert(ext_table, "arj", (gpointer)application_arj);
|
||||||
@@ -1182,6 +1190,11 @@ g_hash_table_insert(ext_table, "d", (gpointer)text_plain);
|
|||||||
g_hash_table_insert(ext_table, "cs", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "cs", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "hpp", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "hpp", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "srt", (gpointer)text_plain);
|
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, "sfv", (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);
|
||||||
@@ -1334,6 +1347,10 @@ g_hash_table_insert(ext_table, "z", (gpointer)application_zlib);
|
|||||||
g_hash_table_insert(ext_table, "pf2", (gpointer)application_x_font_pf2);
|
g_hash_table_insert(ext_table, "pf2", (gpointer)application_x_font_pf2);
|
||||||
g_hash_table_insert(ext_table, "jmod", (gpointer)application_x_java_jmod);
|
g_hash_table_insert(ext_table, "jmod", (gpointer)application_x_java_jmod);
|
||||||
g_hash_table_insert(ext_table, "heic", (gpointer)image_heic);
|
g_hash_table_insert(ext_table, "heic", (gpointer)image_heic);
|
||||||
|
g_hash_table_insert(ext_table, "lzma", (gpointer)application_x_lzma);
|
||||||
|
g_hash_table_insert(ext_table, "warc", (gpointer)application_warc);
|
||||||
|
g_hash_table_insert(ext_table, "lz", (gpointer)application_x_lzip);
|
||||||
|
g_hash_table_insert(ext_table, "lzo", (gpointer)application_x_lzop);
|
||||||
return ext_table;}
|
return ext_table;}
|
||||||
GHashTable *mime_get_mime_table() {GHashTable *mime_table = g_hash_table_new(g_str_hash, g_str_equal);
|
GHashTable *mime_get_mime_table() {GHashTable *mime_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
g_hash_table_insert(mime_table, "application/arj", (gpointer)application_arj);
|
g_hash_table_insert(mime_table, "application/arj", (gpointer)application_arj);
|
||||||
@@ -1748,5 +1765,9 @@ g_hash_table_insert(mime_table, "audio/x-hx-aac-adts", (gpointer)audio_x_hx_aac_
|
|||||||
g_hash_table_insert(mime_table, "application/x-chrome-extension", (gpointer)application_x_chrome_extension);
|
g_hash_table_insert(mime_table, "application/x-chrome-extension", (gpointer)application_x_chrome_extension);
|
||||||
g_hash_table_insert(mime_table, "image/heic", (gpointer)image_heic);
|
g_hash_table_insert(mime_table, "image/heic", (gpointer)image_heic);
|
||||||
g_hash_table_insert(mime_table, "image/x-gem", (gpointer)image_x_gem);
|
g_hash_table_insert(mime_table, "image/x-gem", (gpointer)image_x_gem);
|
||||||
|
g_hash_table_insert(mime_table, "application/x-lzma", (gpointer)application_x_lzma);
|
||||||
|
g_hash_table_insert(mime_table, "application/warc", (gpointer)application_warc);
|
||||||
|
g_hash_table_insert(mime_table, "application/x-lzip", (gpointer)application_x_lzip);
|
||||||
|
g_hash_table_insert(mime_table, "application/x-lzop", (gpointer)application_x_lzop);
|
||||||
return mime_table;}
|
return mime_table;}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,7 +3,28 @@
|
|||||||
|
|
||||||
__thread magic_t Magic = NULL;
|
__thread magic_t Magic = NULL;
|
||||||
|
|
||||||
void *read_all(parse_job_t *job, const char *buf, int bytes_read, int *fd) {
|
int fs_read(struct vfile *f, void *buf, size_t size) {
|
||||||
|
|
||||||
|
if (f->fd == -1) {
|
||||||
|
f->fd = open(f->filepath, O_RDONLY);
|
||||||
|
if (f->fd == -1) {
|
||||||
|
LOG_ERRORF(f->filepath, "open(): [%d] %s", errno, strerror(errno))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return read(f->fd, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CLOSE_FILE(f) if (f.close != NULL) {f.close(&f);};
|
||||||
|
|
||||||
|
void fs_close(struct vfile *f) {
|
||||||
|
if (f->fd != -1) {
|
||||||
|
close(f->fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *read_all(parse_job_t *job, const char *buf, int bytes_read) {
|
||||||
|
|
||||||
void *full_buf;
|
void *full_buf;
|
||||||
|
|
||||||
@@ -11,19 +32,12 @@ void *read_all(parse_job_t *job, const char *buf, int bytes_read, int *fd) {
|
|||||||
full_buf = malloc(job->info.st_size);
|
full_buf = malloc(job->info.st_size);
|
||||||
memcpy(full_buf, buf, job->info.st_size);
|
memcpy(full_buf, buf, job->info.st_size);
|
||||||
} else {
|
} else {
|
||||||
if (*fd == -1) {
|
|
||||||
*fd = open(job->filepath, O_RDONLY);
|
|
||||||
if (*fd == -1) {
|
|
||||||
perror("open");
|
|
||||||
printf("%s\n", job->filepath);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
full_buf = malloc(job->info.st_size);
|
full_buf = malloc(job->info.st_size);
|
||||||
memcpy(full_buf, buf, bytes_read);
|
memcpy(full_buf, buf, bytes_read);
|
||||||
int ret = read(*fd, 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,15 +50,14 @@ void parse(void *arg) {
|
|||||||
parse_job_t *job = arg;
|
parse_job_t *job = arg;
|
||||||
document_t doc;
|
document_t doc;
|
||||||
|
|
||||||
if (incremental_get(ScanCtx.original_table, job->info.st_ino) == job->info.st_mtim.tv_sec) {
|
int inc_ts = incremental_get(ScanCtx.original_table, job->info.st_ino);
|
||||||
|
if (inc_ts != 0 && inc_ts == job->info.st_mtim.tv_sec) {
|
||||||
incremental_mark_file_for_copy(ScanCtx.copy_table, job->info.st_ino);
|
incremental_mark_file_for_copy(ScanCtx.copy_table, job->info.st_ino);
|
||||||
free(job);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Magic == NULL) {
|
if (Magic == NULL) {
|
||||||
Magic = magic_open(MAGIC_MIME_TYPE);
|
Magic = magic_open(MAGIC_MIME_TYPE);
|
||||||
magic_load(Magic, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.filepath = job->filepath;
|
doc.filepath = job->filepath;
|
||||||
@@ -60,30 +73,26 @@ 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)) {
|
||||||
doc.mime = mime_get_mime_by_ext(ScanCtx.ext_table, job->filepath + job->ext);
|
doc.mime = mime_get_mime_by_ext(ScanCtx.ext_table, job->filepath + job->ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = -1;
|
|
||||||
int bytes_read = 0;
|
int bytes_read = 0;
|
||||||
|
|
||||||
if (doc.mime == 0) {
|
if (doc.mime == 0) {
|
||||||
// Get mime type with libmagic
|
// Get mime type with libmagic
|
||||||
fd = open(job->filepath, O_RDONLY);
|
bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
|
||||||
if (fd == -1) {
|
|
||||||
perror("open");
|
|
||||||
free(job);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_read = read(fd, buf, PARSE_BUF_SIZE);
|
|
||||||
|
|
||||||
if (bytes_read == -1) {
|
if (bytes_read == -1) {
|
||||||
perror("read");
|
LOG_WARNINGF(job->filepath, "read() Error: %s", strerror(errno))
|
||||||
close(fd);
|
CLOSE_FILE(job->vfile)
|
||||||
free(job);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,11 +110,16 @@ void parse(void *arg) {
|
|||||||
if (!(SHOULD_PARSE(doc.mime))) {
|
if (!(SHOULD_PARSE(doc.mime))) {
|
||||||
|
|
||||||
} else if ((mmime == MimeVideo && doc.size >= MIN_VIDEO_SIZE) ||
|
} else if ((mmime == MimeVideo && doc.size >= MIN_VIDEO_SIZE) ||
|
||||||
(mmime == MimeImage && doc.size >= MIN_IMAGE_SIZE) || mmime == MimeAudio) {
|
(mmime == MimeImage && doc.size >= MIN_IMAGE_SIZE) || mmime == MimeAudio) {
|
||||||
parse_media(job->filepath, &doc);
|
|
||||||
|
if (job->vfile.is_fs_file) {
|
||||||
|
parse_media_filename(job->filepath, &doc);
|
||||||
|
} else {
|
||||||
|
parse_media_vfile(&job->vfile, &doc);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (IS_PDF(doc.mime)) {
|
} else if (IS_PDF(doc.mime)) {
|
||||||
void *pdf_buf = read_all(job, (char *) buf, bytes_read, &fd);
|
void *pdf_buf = read_all(job, (char *) buf, bytes_read);
|
||||||
parse_pdf(pdf_buf, doc.size, &doc);
|
parse_pdf(pdf_buf, doc.size, &doc);
|
||||||
|
|
||||||
if (pdf_buf != buf && pdf_buf != NULL) {
|
if (pdf_buf != buf && pdf_buf != NULL) {
|
||||||
@@ -113,22 +127,42 @@ void parse(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (mmime == MimeText && ScanCtx.content_size > 0) {
|
} else if (mmime == MimeText && ScanCtx.content_size > 0) {
|
||||||
parse_text(bytes_read, &fd, (char *) buf, &doc);
|
parse_text(bytes_read, &job->vfile, (char *) buf, &doc);
|
||||||
|
|
||||||
} else if (IS_FONT(doc.mime)) {
|
} else if (IS_FONT(doc.mime)) {
|
||||||
void *font_buf = read_all(job, (char *) buf, bytes_read, &fd);
|
void *font_buf = read_all(job, (char *) buf, bytes_read);
|
||||||
parse_font(font_buf, doc.size, &doc);
|
parse_font(font_buf, doc.size, &doc);
|
||||||
|
|
||||||
if (font_buf != buf && font_buf != NULL) {
|
if (font_buf != buf && font_buf != NULL) {
|
||||||
free(font_buf);
|
free(font_buf);
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
ScanCtx.archive_mode != ARC_MODE_SKIP && (
|
||||||
|
IS_ARC(doc.mime) ||
|
||||||
|
(IS_ARC_FILTER(doc.mime) && should_parse_filtered_file(doc.filepath, doc.ext))
|
||||||
|
)) {
|
||||||
|
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
|
||||||
|
if (!uuid_is_null(job->parent)) {
|
||||||
|
char tmp[UUID_STR_LEN];
|
||||||
|
uuid_unparse(job->parent, tmp);
|
||||||
|
|
||||||
|
meta_line_t *meta_parent = malloc(sizeof(meta_line_t) + UUID_STR_LEN + 1);
|
||||||
|
meta_parent->key = MetaParent;
|
||||||
|
strcpy(meta_parent->strval, tmp);
|
||||||
|
APPEND_META((&doc), meta_parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
write_document(&doc);
|
write_document(&doc);
|
||||||
|
|
||||||
if (fd != -1) {
|
CLOSE_FILE(job->vfile)
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(job);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#define PARSE_BUF_SIZE 4096
|
#define PARSE_BUF_SIZE 4096
|
||||||
|
|
||||||
|
int fs_read(struct vfile *f, void *buf, size_t size);
|
||||||
|
void fs_close(struct vfile *f);
|
||||||
|
|
||||||
void parse(void *arg);
|
void parse(void *arg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "pdf.h"
|
#include "pdf.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
|
#define MIN_OCR_SIZE 128
|
||||||
|
__thread text_buffer_t thread_buffer;
|
||||||
|
|
||||||
|
|
||||||
fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@@ -14,6 +18,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 +57,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 +82,8 @@ 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 +91,22 @@ 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, UNUSED(const char *message)) {
|
||||||
|
if (LogCtx.verbose) {
|
||||||
|
document_t *doc = (document_t *) user;
|
||||||
|
LOG_WARNINGF(doc->filepath, "FZ: %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__always_inline
|
||||||
void init_ctx(fz_context *ctx) {
|
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) {
|
||||||
@@ -112,6 +128,40 @@ int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
||||||
|
fz_image *img, UNUSED(fz_matrix ctm), UNUSED(float alpha),
|
||||||
|
UNUSED(fz_color_params color_params)) {
|
||||||
|
|
||||||
|
int l2factor = 0;
|
||||||
|
|
||||||
|
if (img->w > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE) {
|
||||||
|
|
||||||
|
fz_pixmap *pix = img->get_pixmap(ctx, img, NULL, img->w, img->h, &l2factor);
|
||||||
|
|
||||||
|
if (pix->h > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE && img->xres != 0) {
|
||||||
|
TessBaseAPI *api = TessBaseAPICreate();
|
||||||
|
TessBaseAPIInit3(api, ScanCtx.tesseract_path, ScanCtx.tesseract_lang);
|
||||||
|
|
||||||
|
TessBaseAPISetImage(api, pix->samples, pix->w, pix->h, pix->n, pix->stride);
|
||||||
|
TessBaseAPISetSourceResolution(api, pix->xres);
|
||||||
|
|
||||||
|
char *text = TessBaseAPIGetUTF8Text(api);
|
||||||
|
size_t len = strlen(text);
|
||||||
|
text_buffer_append_string(&thread_buffer, text, len - 1);
|
||||||
|
LOG_DEBUGF(
|
||||||
|
"pdf.c",
|
||||||
|
"(OCR) %dx%d got %dB from tesseract (%s), buffer:%dB",
|
||||||
|
pix->w, pix->h, len, ScanCtx.tesseract_lang, thread_buffer.dyn_buffer.cur
|
||||||
|
)
|
||||||
|
|
||||||
|
TessBaseAPIEnd(api);
|
||||||
|
TessBaseAPIDelete(api);
|
||||||
|
}
|
||||||
|
fz_drop_pixmap(ctx, pix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
@@ -125,7 +175,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,13 +221,24 @@ 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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fz_page *cover = render_cover(ctx, doc, fzdoc);
|
fz_page *cover = NULL;
|
||||||
|
if (ScanCtx.tn_size > 0) {
|
||||||
|
cover = render_cover(ctx, doc, fzdoc);
|
||||||
|
} else {
|
||||||
|
fz_var(cover);
|
||||||
|
fz_try(ctx)
|
||||||
|
cover = fz_load_page(ctx, fzdoc, 0);
|
||||||
|
fz_catch(ctx)
|
||||||
|
cover = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (cover == NULL) {
|
if (cover == NULL) {
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
fz_drop_document(ctx, fzdoc);
|
fz_drop_document(ctx, fzdoc);
|
||||||
@@ -185,79 +246,91 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fz_stext_options opts = {0};
|
if (ScanCtx.content_size > 0) {
|
||||||
text_buffer_t text_buf = text_buffer_create(ScanCtx.content_size);
|
fz_stext_options opts = {0};
|
||||||
|
thread_buffer = text_buffer_create(ScanCtx.content_size);
|
||||||
|
|
||||||
|
for (int current_page = 0; current_page < page_count; current_page++) {
|
||||||
|
fz_page *page = NULL;
|
||||||
|
if (current_page == 0) {
|
||||||
|
page = cover;
|
||||||
|
} else {
|
||||||
|
fz_var(err);
|
||||||
|
fz_try(ctx)
|
||||||
|
page = fz_load_page(ctx, fzdoc, current_page);
|
||||||
|
fz_catch(ctx)
|
||||||
|
err = ctx->error.errcode;
|
||||||
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
|
text_buffer_destroy(&thread_buffer);
|
||||||
|
fz_drop_page(ctx, page);
|
||||||
|
fz_drop_stream(ctx, stream);
|
||||||
|
fz_drop_document(ctx, fzdoc);
|
||||||
|
fz_drop_context(ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fz_stext_page *stext = fz_new_stext_page(ctx, fz_bound_page(ctx, page));
|
||||||
|
fz_device *dev = fz_new_stext_device(ctx, stext, &opts);
|
||||||
|
dev->stroke_path = NULL;
|
||||||
|
dev->stroke_text = NULL;
|
||||||
|
dev->clip_text = NULL;
|
||||||
|
dev->clip_stroke_path = NULL;
|
||||||
|
dev->clip_stroke_text = NULL;
|
||||||
|
|
||||||
|
if (ScanCtx.tesseract_lang != NULL) {
|
||||||
|
dev->fill_image = fill_image;
|
||||||
|
}
|
||||||
|
|
||||||
for (int current_page = 0; current_page < page_count; current_page++) {
|
|
||||||
fz_page *page = NULL;
|
|
||||||
if (current_page == 0) {
|
|
||||||
page = cover;
|
|
||||||
} else {
|
|
||||||
fz_var(err);
|
fz_var(err);
|
||||||
fz_try(ctx)
|
fz_try(ctx)
|
||||||
page = fz_load_page(ctx, fzdoc, current_page);
|
fz_run_page(ctx, page, dev, fz_identity, NULL);
|
||||||
|
fz_always(ctx)
|
||||||
|
{
|
||||||
|
fz_close_device(ctx, dev);
|
||||||
|
fz_drop_device(ctx, dev);
|
||||||
|
}
|
||||||
fz_catch(ctx)
|
fz_catch(ctx)
|
||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
text_buffer_destroy(&text_buf);
|
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
|
text_buffer_destroy(&thread_buffer);
|
||||||
fz_drop_page(ctx, page);
|
fz_drop_page(ctx, page);
|
||||||
|
fz_drop_stext_page(ctx, stext);
|
||||||
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fz_stext_page *stext = fz_new_stext_page(ctx, fz_bound_page(ctx, page));
|
fz_stext_block *block = stext->first_block;
|
||||||
fz_device *dev = fz_new_stext_device(ctx, stext, &opts);
|
while (block != NULL) {
|
||||||
|
int ret = read_stext_block(block, &thread_buffer);
|
||||||
fz_var(err);
|
if (ret == TEXT_BUF_FULL) {
|
||||||
fz_try(ctx)
|
break;
|
||||||
fz_run_page(ctx, page, dev, fz_identity, NULL);
|
}
|
||||||
fz_always(ctx)
|
block = block->next;
|
||||||
{
|
}
|
||||||
fz_close_device(ctx, dev);
|
|
||||||
fz_drop_device(ctx, dev);
|
|
||||||
}
|
|
||||||
fz_catch(ctx)
|
|
||||||
err = ctx->error.errcode;
|
|
||||||
|
|
||||||
if (err != 0) {
|
|
||||||
text_buffer_destroy(&text_buf);
|
|
||||||
fz_drop_page(ctx, page);
|
|
||||||
fz_drop_stext_page(ctx, stext);
|
fz_drop_stext_page(ctx, stext);
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_page(ctx, page);
|
||||||
fz_drop_document(ctx, fzdoc);
|
|
||||||
fz_drop_context(ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fz_stext_block *block = stext->first_block;
|
if (thread_buffer.dyn_buffer.cur >= thread_buffer.dyn_buffer.size) {
|
||||||
while (block != NULL) {
|
|
||||||
int ret = read_stext_block(block, &text_buf);
|
|
||||||
if (ret == TEXT_BUF_FULL) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
block = block->next;
|
|
||||||
}
|
}
|
||||||
fz_drop_stext_page(ctx, stext);
|
text_buffer_terminate_string(&thread_buffer);
|
||||||
fz_drop_page(ctx, page);
|
|
||||||
|
|
||||||
if (text_buf.dyn_buffer.cur >= text_buf.dyn_buffer.size) {
|
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + thread_buffer.dyn_buffer.cur);
|
||||||
break;
|
meta_content->key = MetaContent;
|
||||||
}
|
memcpy(meta_content->strval, thread_buffer.dyn_buffer.buf, thread_buffer.dyn_buffer.cur);
|
||||||
|
APPEND_META(doc, meta_content)
|
||||||
|
|
||||||
|
text_buffer_destroy(&thread_buffer);
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(&text_buf);
|
|
||||||
|
|
||||||
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + text_buf.dyn_buffer.cur);
|
|
||||||
meta_content->key = MetaContent;
|
|
||||||
memcpy(meta_content->strval, text_buf.dyn_buffer.buf, text_buf.dyn_buffer.cur);
|
|
||||||
APPEND_META(doc, meta_content)
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
text_buffer_destroy(&text_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
void parse_text(int bytes_read, int *fd, char *buf, document_t *doc) {
|
void parse_text(int bytes_read, struct vfile *f, char *buf, document_t *doc) {
|
||||||
|
|
||||||
char *intermediate_buf;
|
char *intermediate_buf;
|
||||||
int intermediate_buf_len;
|
int intermediate_buf_len;
|
||||||
@@ -13,10 +13,6 @@ void parse_text(int bytes_read, int *fd, char *buf, document_t *doc) {
|
|||||||
memcpy(intermediate_buf, buf, to_copy);
|
memcpy(intermediate_buf, buf, to_copy);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (*fd == -1) {
|
|
||||||
*fd = open(doc->filepath, O_RDONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
int to_read = MIN(ScanCtx.content_size, doc->size) - bytes_read;
|
int to_read = MIN(ScanCtx.content_size, doc->size) - bytes_read;
|
||||||
|
|
||||||
intermediate_buf = malloc(to_read + bytes_read);
|
intermediate_buf = malloc(to_read + bytes_read);
|
||||||
@@ -25,10 +21,11 @@ void parse_text(int bytes_read, int *fd, char *buf, document_t *doc) {
|
|||||||
memcpy(intermediate_buf, buf, bytes_read);
|
memcpy(intermediate_buf, buf, bytes_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
read(*fd, intermediate_buf + bytes_read, to_read);
|
f->read(f, intermediate_buf + bytes_read, to_read);
|
||||||
}
|
}
|
||||||
text_buffer_t tex = text_buffer_create(ScanCtx.content_size);
|
text_buffer_t tex = text_buffer_create(ScanCtx.content_size);
|
||||||
text_buffer_append_string(&tex, intermediate_buf, intermediate_buf_len);
|
text_buffer_append_string(&tex, intermediate_buf, intermediate_buf_len);
|
||||||
|
text_buffer_terminate_string(&tex);
|
||||||
|
|
||||||
meta_line_t *meta = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur);
|
meta_line_t *meta = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur);
|
||||||
meta->key = MetaContent;
|
meta->key = MetaContent;
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include "src/sist.h"
|
#include "src/sist.h"
|
||||||
|
|
||||||
void parse_text(int bytes_read, int *fd, char *buf, document_t *doc);
|
void parse_text(int bytes_read, struct vfile *f, char *buf, document_t *doc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
28
src/sist.h
28
src/sist.h
@@ -2,6 +2,7 @@
|
|||||||
#define SIST_H
|
#define SIST_H
|
||||||
|
|
||||||
#define UUID_STR_LEN 37
|
#define UUID_STR_LEN 37
|
||||||
|
#define UNUSED(x) __attribute__((__unused__)) x
|
||||||
|
|
||||||
#include <glib-2.0/glib.h>
|
#include <glib-2.0/glib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -12,11 +13,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>
|
||||||
@@ -26,14 +27,21 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
#include "ft2build.h"
|
||||||
|
#include "freetype/freetype.h"
|
||||||
|
#include <archive.h>
|
||||||
|
#include <archive_entry.h>
|
||||||
|
#include <opc/opc.h>
|
||||||
|
#include <libxml/xmlstring.h>
|
||||||
|
#define BOOL int
|
||||||
|
#include <tesseract/capi.h>
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
#include <onion/onion.h>
|
#include <onion/onion.h>
|
||||||
#include <onion/handler.h>
|
#include <onion/handler.h>
|
||||||
#include <onion/block.h>
|
#include <onion/block.h>
|
||||||
#include <onion/shortcuts.h>
|
#include <onion/shortcuts.h>
|
||||||
|
#include <onion/codecs.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "cJSON/cJSON.h"
|
#include "cJSON/cJSON.h"
|
||||||
|
|
||||||
@@ -49,14 +57,16 @@
|
|||||||
#include "parsing/pdf.h"
|
#include "parsing/pdf.h"
|
||||||
#include "parsing/media.h"
|
#include "parsing/media.h"
|
||||||
#include "parsing/font.h"
|
#include "parsing/font.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
|
|
||||||
#include "src/index/elastic.h"
|
#include "src/index/elastic.h"
|
||||||
#include "index/web.h"
|
#include "index/web.h"
|
||||||
#include "web/serve.h"
|
#include "web/serve.h"
|
||||||
#endif
|
#include "web/auth_basic.h"
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
36
src/tpool.c
36
src/tpool.c
@@ -114,12 +114,19 @@ static void *tpool_worker(void *arg) {
|
|||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
|
|
||||||
if (work != NULL) {
|
if (work != NULL) {
|
||||||
|
if (pool->stop) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
work->func(work->arg);
|
work->func(work->arg);
|
||||||
|
free(work->arg);
|
||||||
free(work);
|
free(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&(pool->work_mutex));
|
pthread_mutex_lock(&(pool->work_mutex));
|
||||||
pool->done_cnt++;
|
if (work != NULL) {
|
||||||
|
pool->done_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
progress_bar_print((double) pool->done_cnt / pool->work_cnt, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
progress_bar_print((double) pool->done_cnt / pool->work_cnt, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
||||||
|
|
||||||
@@ -129,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));
|
||||||
@@ -137,17 +145,24 @@ 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) {
|
||||||
pthread_cond_wait(&(pool->working_cond), &(pool->work_mutex));
|
pthread_cond_wait(&(pool->working_cond), &(pool->work_mutex));
|
||||||
} else {
|
} else {
|
||||||
pool->stop = 1;
|
usleep(500000);
|
||||||
break;
|
if (pool->done_cnt == pool->work_cnt) {
|
||||||
|
pool->stop = 1;
|
||||||
|
usleep(1000000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
progress_bar_print(100.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) {
|
||||||
@@ -155,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) {
|
||||||
@@ -169,10 +186,13 @@ void tpool_destroy(tpool_t *pool) {
|
|||||||
for (size_t i = 0; i < pool->thread_cnt; i++) {
|
for (size_t i = 0; i < pool->thread_cnt; i++) {
|
||||||
pthread_t thread = pool->threads[i];
|
pthread_t thread = pool->threads[i];
|
||||||
if (thread != 0) {
|
if (thread != 0) {
|
||||||
pthread_cancel(thread);
|
void *_;
|
||||||
|
pthread_join(thread, &_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
@@ -208,9 +228,9 @@ 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_t thread = pool->threads[i];
|
pthread_create(&pool->threads[i], NULL, tpool_worker, pool);
|
||||||
pthread_create(&thread, NULL, tpool_worker, pool);
|
|
||||||
pthread_detach(thread);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
49
src/types.h
49
src/types.h
@@ -2,13 +2,19 @@
|
|||||||
#define SIST2_TYPES_H
|
#define SIST2_TYPES_H
|
||||||
|
|
||||||
|
|
||||||
#define META_INT_MASK 0xF0
|
#define META_INT_MASK 0x80
|
||||||
#define META_STR_MASK 0xE0
|
#define META_STR_MASK 0x40
|
||||||
#define META_LONG_MASK 0xD0
|
#define META_LONG_MASK 0x20
|
||||||
#define IS_META_INT(key) (key & META_INT_MASK) == META_INT_MASK
|
#define IS_META_INT(key) (key & META_INT_MASK) == META_INT_MASK
|
||||||
#define IS_META_LONG(key) (key & META_LONG_MASK) == META_LONG_MASK
|
#define IS_META_LONG(key) (key & META_LONG_MASK) == META_LONG_MASK
|
||||||
#define IS_META_STR(meta) (meta->key & META_STR_MASK) == META_STR_MASK
|
#define IS_META_STR(meta) (meta->key & META_STR_MASK) == META_STR_MASK
|
||||||
|
|
||||||
|
#define ARC_MODE_SKIP 0
|
||||||
|
#define ARC_MODE_LIST 1
|
||||||
|
#define ARC_MODE_SHALLOW 2
|
||||||
|
#define ARC_MODE_RECURSE 3
|
||||||
|
typedef int archive_mode_t;
|
||||||
|
|
||||||
// This is written to file as a 8bit char!
|
// This is written to file as a 8bit char!
|
||||||
enum metakey {
|
enum metakey {
|
||||||
MetaContent = 1 | META_STR_MASK,
|
MetaContent = 1 | META_STR_MASK,
|
||||||
@@ -24,8 +30,22 @@ enum metakey {
|
|||||||
MetaGenre = 11 | META_STR_MASK,
|
MetaGenre = 11 | META_STR_MASK,
|
||||||
MetaTitle = 12 | META_STR_MASK,
|
MetaTitle = 12 | META_STR_MASK,
|
||||||
MetaFontName = 13 | META_STR_MASK,
|
MetaFontName = 13 | META_STR_MASK,
|
||||||
|
MetaParent = 14 | META_STR_MASK,
|
||||||
|
MetaExifMake = 15 | META_STR_MASK,
|
||||||
|
MetaExifSoftware = 16 | META_STR_MASK,
|
||||||
|
MetaExifExposureTime = 17 | META_STR_MASK,
|
||||||
|
MetaExifFNumber = 18 | META_STR_MASK,
|
||||||
|
MetaExifFocalLength = 19 | META_STR_MASK,
|
||||||
|
MetaExifUserComment = 20 | META_STR_MASK,
|
||||||
|
MetaExifModel = 21 | META_STR_MASK,
|
||||||
|
MetaExifIsoSpeedRatings = 22 | META_STR_MASK,
|
||||||
|
//Note to self: this will break after 31 entries
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define INDEX_TYPE_BIN "binary"
|
||||||
|
#define INDEX_TYPE_JSON "json"
|
||||||
|
#define INDEX_VERSION_EXTERNAL "_external_v1"
|
||||||
|
|
||||||
typedef struct index_descriptor {
|
typedef struct index_descriptor {
|
||||||
char uuid[UUID_STR_LEN];
|
char uuid[UUID_STR_LEN];
|
||||||
char version[6];
|
char version[6];
|
||||||
@@ -34,6 +54,7 @@ typedef struct index_descriptor {
|
|||||||
char rewrite_url[8196];
|
char rewrite_url[8196];
|
||||||
short root_len;
|
short root_len;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
|
char type[64];
|
||||||
} index_descriptor_t;
|
} index_descriptor_t;
|
||||||
|
|
||||||
typedef struct index_t {
|
typedef struct index_t {
|
||||||
@@ -66,10 +87,32 @@ typedef struct document {
|
|||||||
char *filepath;
|
char *filepath;
|
||||||
} document_t;
|
} document_t;
|
||||||
|
|
||||||
|
typedef struct vfile vfile_t;
|
||||||
|
|
||||||
|
typedef int (*read_func_t)(struct vfile *, void *buf, size_t size);
|
||||||
|
|
||||||
|
typedef void (*close_func_t)(struct vfile *);
|
||||||
|
|
||||||
|
typedef struct vfile {
|
||||||
|
|
||||||
|
union {
|
||||||
|
int fd;
|
||||||
|
struct archive *arc;
|
||||||
|
};
|
||||||
|
|
||||||
|
int is_fs_file;
|
||||||
|
char *filepath;
|
||||||
|
|
||||||
|
read_func_t read;
|
||||||
|
close_func_t close;
|
||||||
|
} vfile_t;
|
||||||
|
|
||||||
typedef struct parse_job_t {
|
typedef struct parse_job_t {
|
||||||
int base;
|
int base;
|
||||||
int ext;
|
int ext;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
struct vfile vfile;
|
||||||
|
uuid_t parent;
|
||||||
char filepath[1];
|
char filepath[1];
|
||||||
} parse_job_t;
|
} parse_job_t;
|
||||||
|
|
||||||
|
|||||||
43
src/util.c
43
src/util.c
@@ -1,4 +1,5 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "src/ctx.h"
|
||||||
|
|
||||||
dyn_buffer_t dyn_buffer_create() {
|
dyn_buffer_t dyn_buffer_create() {
|
||||||
dyn_buffer_t buf;
|
dyn_buffer_t buf;
|
||||||
@@ -46,6 +47,10 @@ void dyn_buffer_write_str(dyn_buffer_t *buf, char *str) {
|
|||||||
dyn_buffer_write_char(buf, '\0');
|
dyn_buffer_write_char(buf, '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dyn_buffer_append_string(dyn_buffer_t *buf, char *str) {
|
||||||
|
dyn_buffer_write(buf, str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
void dyn_buffer_write_int(dyn_buffer_t *buf, int d) {
|
void dyn_buffer_write_int(dyn_buffer_t *buf, int d) {
|
||||||
grow_buffer_small(buf);
|
grow_buffer_small(buf);
|
||||||
|
|
||||||
@@ -86,7 +91,11 @@ text_buffer_t text_buffer_create(int max_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void text_buffer_terminate_string(text_buffer_t *buf) {
|
void text_buffer_terminate_string(text_buffer_t *buf) {
|
||||||
dyn_buffer_write_char(&buf->dyn_buffer, '\0');
|
if (*(buf->dyn_buffer.buf + buf->dyn_buffer.cur - 1) == ' ') {
|
||||||
|
*(buf->dyn_buffer.buf + buf->dyn_buffer.cur - 1) = '\0';
|
||||||
|
} else {
|
||||||
|
dyn_buffer_write_char(&buf->dyn_buffer, '\0');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
@@ -145,7 +154,6 @@ int text_buffer_append_string(text_buffer_t *buf, char *str, size_t len) {
|
|||||||
(0xe0 == (0xf0 & str[0]) && len < 3) ||
|
(0xe0 == (0xf0 & str[0]) && len < 3) ||
|
||||||
(0xc0 == (0xe0 & str[0]) && len == 1) ||
|
(0xc0 == (0xe0 & str[0]) && len == 1) ||
|
||||||
*(str) == 0) {
|
*(str) == 0) {
|
||||||
text_buffer_terminate_string(buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +162,6 @@ int text_buffer_append_string(text_buffer_t *buf, char *str, size_t len) {
|
|||||||
text_buffer_append_char(buf, c);
|
text_buffer_append_char(buf, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,13 +172,12 @@ int text_buffer_append_string0(text_buffer_t *buf, char *str) {
|
|||||||
text_buffer_append_char(buf, c);
|
text_buffer_append_char(buf, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int text_buffer_append_char(text_buffer_t *buf, int c) {
|
int text_buffer_append_char(text_buffer_t *buf, int c) {
|
||||||
|
|
||||||
if (SHOULD_IGNORE_CHAR(c)) {
|
if (SHOULD_IGNORE_CHAR(c) || c == ' ') {
|
||||||
if (!buf->last_char_was_whitespace) {
|
if (!buf->last_char_was_whitespace && buf->dyn_buffer.cur != 0) {
|
||||||
dyn_buffer_write_char(&buf->dyn_buffer, ' ');
|
dyn_buffer_write_char(&buf->dyn_buffer, ' ');
|
||||||
buf->last_char_was_whitespace = TRUE;
|
buf->last_char_was_whitespace = TRUE;
|
||||||
|
|
||||||
@@ -316,4 +322,29 @@ GHashTable *incremental_get_table() {
|
|||||||
return file_table;
|
return file_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *find_file_in_paths(const char *paths[], const char *filename) {
|
||||||
|
|
||||||
|
for (int i = 0; paths[i] != NULL; i++) {
|
||||||
|
|
||||||
|
char *apath = abspath(paths[i]);
|
||||||
|
if (apath == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char path[PATH_MAX];
|
||||||
|
snprintf(path, sizeof(path), "%s%s", apath, filename);
|
||||||
|
|
||||||
|
LOG_DEBUGF("util.c", "Looking for '%s' in folder '%s'", filename, apath)
|
||||||
|
free(apath);
|
||||||
|
|
||||||
|
struct stat info;
|
||||||
|
int ret = stat(path, &info);
|
||||||
|
if (ret != -1) {
|
||||||
|
return paths[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define INITIAL_BUF_SIZE 1024 * 16
|
#define INITIAL_BUF_SIZE 1024 * 16
|
||||||
|
|
||||||
#define SHOULD_IGNORE_CHAR(c) !(SHOULD_KEEP_CHAR(c))
|
#define SHOULD_IGNORE_CHAR(c) !(SHOULD_KEEP_CHAR(c))
|
||||||
#define SHOULD_KEEP_CHAR(c) (c >= (int)'!')
|
#define SHOULD_KEEP_CHAR(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'z') || (c > 127))
|
||||||
|
|
||||||
|
|
||||||
typedef struct dyn_buffer {
|
typedef struct dyn_buffer {
|
||||||
@@ -47,6 +47,8 @@ void dyn_buffer_write_char(dyn_buffer_t *buf, char c);
|
|||||||
|
|
||||||
void dyn_buffer_write_str(dyn_buffer_t *buf, char *str);
|
void dyn_buffer_write_str(dyn_buffer_t *buf, char *str);
|
||||||
|
|
||||||
|
void dyn_buffer_append_string(dyn_buffer_t *buf, char *str);
|
||||||
|
|
||||||
void dyn_buffer_write_int(dyn_buffer_t *buf, int d);
|
void dyn_buffer_write_int(dyn_buffer_t *buf, int d);
|
||||||
|
|
||||||
void dyn_buffer_write_short(dyn_buffer_t *buf, short s);
|
void dyn_buffer_write_short(dyn_buffer_t *buf, short s);
|
||||||
@@ -72,5 +74,6 @@ int incremental_get(GHashTable *table, unsigned long inode_no);
|
|||||||
|
|
||||||
int incremental_mark_file_for_copy(GHashTable *table, unsigned long inode_no);
|
int incremental_mark_file_for_copy(GHashTable *table, unsigned long inode_no);
|
||||||
|
|
||||||
|
const char *find_file_in_paths(const char **paths, const char *filename);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
59
src/web/auth_basic.c
Normal file
59
src/web/auth_basic.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "auth_basic.h"
|
||||||
|
|
||||||
|
#define UNAUTHORIZED_TEXT "Unauthorized"
|
||||||
|
|
||||||
|
typedef struct auth_basic_data {
|
||||||
|
onion_handler *inside;
|
||||||
|
const char *b64credentials;
|
||||||
|
} auth_basic_data_t;
|
||||||
|
|
||||||
|
|
||||||
|
int authenticate(const char *expected, const char *credentials) {
|
||||||
|
|
||||||
|
if (expected == NULL) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (credentials && strncmp(credentials, "Basic ", 6) == 0) {
|
||||||
|
if (strcmp((credentials + 6), expected) == 0) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int auth_basic_handler(auth_basic_data_t *d,
|
||||||
|
onion_request *req,
|
||||||
|
onion_response *res) {
|
||||||
|
|
||||||
|
const char *credentials = onion_request_get_header(req, "Authorization");
|
||||||
|
|
||||||
|
if (authenticate(d->b64credentials, credentials)) {
|
||||||
|
return onion_handler_handle(d->inside, req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
onion_response_set_header(res, "WWW-Authenticate", "Basic realm=\"sist2\"");
|
||||||
|
onion_response_set_code(res, HTTP_UNAUTHORIZED);
|
||||||
|
onion_response_write(res, UNAUTHORIZED_TEXT, sizeof(UNAUTHORIZED_TEXT));
|
||||||
|
onion_response_set_length(res, sizeof(UNAUTHORIZED_TEXT));
|
||||||
|
|
||||||
|
return OCS_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void auth_basic_free(auth_basic_data_t *data) {
|
||||||
|
onion_handler_free(data->inside);
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
onion_handler *auth_basic(const char *b64credentials, onion_handler *inside_level) {
|
||||||
|
|
||||||
|
auth_basic_data_t *privdata = malloc(sizeof(auth_basic_data_t));
|
||||||
|
|
||||||
|
privdata->b64credentials = b64credentials;
|
||||||
|
privdata->inside = inside_level;
|
||||||
|
|
||||||
|
return onion_handler_new((onion_handler_handler) auth_basic_handler, privdata,
|
||||||
|
(onion_handler_private_data_free) auth_basic_free);
|
||||||
|
}
|
||||||
|
|
||||||
4
src/web/auth_basic.h
Normal file
4
src/web/auth_basic.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include "src/sist.h"
|
||||||
|
|
||||||
|
|
||||||
|
onion_handler *auth_basic(const char *b64credentials, onion_handler *inside_level);
|
||||||
@@ -110,7 +110,7 @@ int thumbnail(void *p, onion_request *req, onion_response *res) {
|
|||||||
int written = onion_response_write(res, data, data_len);
|
int written = onion_response_write(res, data, data_len);
|
||||||
onion_response_flush(res);
|
onion_response_flush(res);
|
||||||
if (written != data_len || data_len == 0) {
|
if (written != data_len || data_len == 0) {
|
||||||
printf("Couldn't write thumb\n");
|
LOG_DEBUG("serve.c", "Couldn't write thumbnail");
|
||||||
}
|
}
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ int chunked_response_file(const char *filename, const char *mime,
|
|||||||
return OCS_PROCESSED;
|
return OCS_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int search(void *p, onion_request *req, onion_response *res) {
|
int search(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||||
|
|
||||||
int flags = onion_request_get_flags(req);
|
int flags = onion_request_get_flags(req);
|
||||||
if ((flags & OR_METHODS) != OR_POST) {
|
if ((flags & OR_METHODS) != OR_POST) {
|
||||||
@@ -245,6 +245,8 @@ int search(void *p, onion_request *req, onion_response *res) {
|
|||||||
|
|
||||||
if (r->status_code == 200) {
|
if (r->status_code == 200) {
|
||||||
onion_response_write(res, r->body, r->size);
|
onion_response_write(res, r->body, r->size);
|
||||||
|
} else {
|
||||||
|
onion_response_set_code(res, HTTP_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
free_response(r);
|
free_response(r);
|
||||||
@@ -252,7 +254,7 @@ int search(void *p, onion_request *req, onion_response *res) {
|
|||||||
return OCS_PROCESSED;
|
return OCS_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int scroll(void *p, onion_request *req, onion_response *res) {
|
int scroll(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||||
|
|
||||||
int flags = onion_request_get_flags(req);
|
int flags = onion_request_get_flags(req);
|
||||||
if ((flags & OR_METHODS) != OR_GET) {
|
if ((flags & OR_METHODS) != OR_GET) {
|
||||||
@@ -325,7 +327,7 @@ int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_re
|
|||||||
return chunked_response_file(full_path, mime, 1, req, res);
|
return chunked_response_file(full_path, mime, 1, req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
int index_info(void *p, onion_request *req, onion_response *res) {
|
int index_info(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||||
cJSON *json = cJSON_CreateObject();
|
cJSON *json = cJSON_CreateObject();
|
||||||
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
||||||
|
|
||||||
@@ -351,7 +353,8 @@ int index_info(void *p, onion_request *req, onion_response *res) {
|
|||||||
return OCS_PROCESSED;
|
return OCS_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int file(void *p, onion_request *req, onion_response *res) {
|
|
||||||
|
int document_info(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||||
|
|
||||||
const char *arg_uuid = onion_request_get_query(req, "1");
|
const char *arg_uuid = onion_request_get_query(req, "1");
|
||||||
if (arg_uuid == NULL) {
|
if (arg_uuid == NULL) {
|
||||||
@@ -360,12 +363,56 @@ int file(void *p, onion_request *req, onion_response *res) {
|
|||||||
|
|
||||||
cJSON *doc = elastic_get_document(arg_uuid);
|
cJSON *doc = elastic_get_document(arg_uuid);
|
||||||
cJSON *source = cJSON_GetObjectItem(doc, "_source");
|
cJSON *source = cJSON_GetObjectItem(doc, "_source");
|
||||||
|
|
||||||
cJSON *index_id = cJSON_GetObjectItem(source, "index");
|
cJSON *index_id = cJSON_GetObjectItem(source, "index");
|
||||||
if (index_id == NULL) {
|
if (index_id == NULL) {
|
||||||
cJSON_Delete(doc);
|
cJSON_Delete(doc);
|
||||||
return OCS_NOT_PROCESSED;
|
return OCS_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index_t *idx = get_index_by_id(index_id->valuestring);
|
||||||
|
if (idx == NULL) {
|
||||||
|
cJSON_Delete(doc);
|
||||||
|
return OCS_NOT_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
onion_response_set_header(res, "Content-Type", "application/json");
|
||||||
|
|
||||||
|
char *json_str = cJSON_PrintUnformatted(source);
|
||||||
|
onion_response_write0(res, json_str);
|
||||||
|
free(json_str);
|
||||||
|
cJSON_Delete(doc);
|
||||||
|
|
||||||
|
return OCS_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int file(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||||
|
|
||||||
|
const char *arg_uuid = onion_request_get_query(req, "1");
|
||||||
|
if (arg_uuid == NULL) {
|
||||||
|
return OCS_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *next = arg_uuid;
|
||||||
|
cJSON *doc = NULL;
|
||||||
|
cJSON *index_id = NULL;
|
||||||
|
cJSON *source = NULL;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
doc = elastic_get_document(next);
|
||||||
|
source = cJSON_GetObjectItem(doc, "_source");
|
||||||
|
index_id = cJSON_GetObjectItem(source, "index");
|
||||||
|
if (index_id == NULL) {
|
||||||
|
cJSON_Delete(doc);
|
||||||
|
return OCS_NOT_PROCESSED;
|
||||||
|
}
|
||||||
|
cJSON *parent = cJSON_GetObjectItem(source, "parent");
|
||||||
|
if (parent == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next = parent->valuestring;
|
||||||
|
}
|
||||||
|
|
||||||
index_t *idx = get_index_by_id(index_id->valuestring);
|
index_t *idx = get_index_by_id(index_id->valuestring);
|
||||||
|
|
||||||
if (idx == NULL) {
|
if (idx == NULL) {
|
||||||
@@ -384,6 +431,23 @@ int file(void *p, onion_request *req, onion_response *res) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int status(UNUSED(void *p), UNUSED(onion_request *req), onion_response *res) {
|
||||||
|
set_default_headers(res);
|
||||||
|
|
||||||
|
onion_response_set_header(res, "Content-Type", "application/x-empty");
|
||||||
|
|
||||||
|
char *status = elastic_get_status();
|
||||||
|
if (strcmp(status, "open") == 0) {
|
||||||
|
onion_response_set_code(res, 204);
|
||||||
|
} else {
|
||||||
|
onion_response_set_code(res, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(status);
|
||||||
|
|
||||||
|
return OCS_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
void serve(const char *hostname, const char *port) {
|
void serve(const char *hostname, const char *port) {
|
||||||
onion *o = onion_new(O_POOL);
|
onion *o = onion_new(O_POOL);
|
||||||
onion_set_timeout(o, 3500);
|
onion_set_timeout(o, 3500);
|
||||||
@@ -391,9 +455,11 @@ void serve(const char *hostname, const char *port) {
|
|||||||
onion_set_hostname(o, hostname);
|
onion_set_hostname(o, hostname);
|
||||||
onion_set_port(o, port);
|
onion_set_port(o, port);
|
||||||
|
|
||||||
onion_url *urls = onion_root_url(o);
|
onion_url *urls = onion_url_new();
|
||||||
|
|
||||||
// Static paths
|
// Static paths
|
||||||
|
onion_set_root_handler(o, auth_basic(WebCtx.b64credentials, onion_url_to_handler(urls)));
|
||||||
|
|
||||||
onion_url_add(urls, "", search_index);
|
onion_url_add(urls, "", search_index);
|
||||||
onion_url_add(urls, "css", style);
|
onion_url_add(urls, "css", style);
|
||||||
onion_url_add(urls, "js", javascript);
|
onion_url_add(urls, "js", javascript);
|
||||||
@@ -401,6 +467,7 @@ void serve(const char *hostname, const char *port) {
|
|||||||
|
|
||||||
onion_url_add(urls, "es", search);
|
onion_url_add(urls, "es", search);
|
||||||
onion_url_add(urls, "scroll", scroll);
|
onion_url_add(urls, "scroll", scroll);
|
||||||
|
onion_url_add(urls, "status", status);
|
||||||
onion_url_add(
|
onion_url_add(
|
||||||
urls,
|
urls,
|
||||||
"^t/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/"
|
"^t/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/"
|
||||||
@@ -408,8 +475,10 @@ void serve(const char *hostname, const char *port) {
|
|||||||
thumbnail
|
thumbnail
|
||||||
);
|
);
|
||||||
onion_url_add(urls, "^f/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", file);
|
onion_url_add(urls, "^f/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", file);
|
||||||
|
onion_url_add(urls, "^d/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", document_info);
|
||||||
onion_url_add(urls, "i", index_info);
|
onion_url_add(urls, "i", index_info);
|
||||||
|
|
||||||
|
|
||||||
printf("Starting web server @ http://%s:%s\n", hostname, port);
|
printf("Starting web server @ http://%s:%s\n", hostname, port);
|
||||||
|
|
||||||
onion_listen(o);
|
onion_listen(o);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
187
web/css/dark.css
187
web/css/dark.css
@@ -1,3 +1,44 @@
|
|||||||
|
*:focus {
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-icon {
|
||||||
|
width: 1rem;
|
||||||
|
margin-right: 0.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #757575;
|
||||||
|
line-height: 1rem;
|
||||||
|
height: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-icon:hover {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-title {
|
||||||
|
max-width: calc(100% - 2rem);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.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;
|
||||||
}
|
}
|
||||||
@@ -11,7 +52,7 @@ body {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card, .modal-content {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
background: #212121;
|
background: #212121;
|
||||||
color: #e0e0e0;
|
color: #e0e0e0;
|
||||||
@@ -19,6 +60,54 @@ body {
|
|||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table {
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table td, .table th {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table thead th {
|
||||||
|
border-bottom: 1px solid #646464;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header .close {
|
||||||
|
color: #e0e0e0;
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
border-bottom: 1px solid #646464;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sub-document {
|
||||||
|
background: #37474F !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item.sub-document {
|
||||||
|
border-top: 1px solid #646464 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sub-document .text-muted {
|
||||||
|
color: #8a949c !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
background: #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
|
||||||
|
border-top: 1px solid #424242;
|
||||||
|
border-bottom: none;
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item:first-child {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -85,16 +174,25 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
|
width: 100%;
|
||||||
|
line-height: 1rem;
|
||||||
|
height: 1.1rem;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
color: #00BCD4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
margin-right: 3px;
|
margin-right: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge-user {
|
||||||
|
color: #212529;
|
||||||
|
background-color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
.fit {
|
.fit {
|
||||||
display: block;
|
display: block;
|
||||||
min-width: 64px;
|
min-width: 64px;
|
||||||
@@ -106,6 +204,15 @@ body {
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fit-sm {
|
||||||
|
display: block;
|
||||||
|
max-width: 64px;
|
||||||
|
max-height: 64px;
|
||||||
|
margin: 0 auto 0;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.audio-fit {
|
.audio-fit {
|
||||||
height: 39px;
|
height: 39px;
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
@@ -149,6 +256,8 @@ mark {
|
|||||||
border: 1px solid #616161;
|
border: 1px solid #616161;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin: 3px;
|
margin: 3px;
|
||||||
|
white-space: normal;
|
||||||
|
color: rgb(224, 224, 224);
|
||||||
}
|
}
|
||||||
|
|
||||||
.irs-single, .irs-from, .irs-to {
|
.irs-single, .irs-from, .irs-to {
|
||||||
@@ -164,6 +273,7 @@ mark {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-select {
|
.custom-select {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
background-color: #37474F;
|
background-color: #37474F;
|
||||||
@@ -229,6 +339,7 @@ option {
|
|||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background: #212121;
|
background: #212121;
|
||||||
color: #eee;
|
color: #eee;
|
||||||
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-xs {
|
.btn-xs {
|
||||||
@@ -239,4 +350,76 @@ option {
|
|||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
color: #eee;
|
color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-link {
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-item.show .nav-link, .nav-tabs .nav-link.active {
|
||||||
|
background-color: #212121;
|
||||||
|
border-color: #616161 #616161 #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-link:focus, .nav-tabs .nav-link:focus {
|
||||||
|
border-color: #616161 #616161 #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-link:focus, .nav-tabs .nav-link:hover {
|
||||||
|
border-color: #e0e0e0 #e0e0e0 #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs {
|
||||||
|
border-bottom: #616161;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 800px) {
|
||||||
|
#treeTabs {
|
||||||
|
flex-basis: inherit;
|
||||||
|
flex-grow: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
padding: .25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapper-sm {
|
||||||
|
min-width: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tagline {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.version {
|
||||||
|
color: #00BCD4;
|
||||||
|
margin-left: -18px;
|
||||||
|
margin-top: -14px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|||||||
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}
|
||||||
@@ -1,4 +1,46 @@
|
|||||||
body {overflow-y:scroll;}
|
*:focus {
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-icon {
|
||||||
|
width: 1rem;
|
||||||
|
margin-right: 0.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #757575;
|
||||||
|
line-height: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-icon:hover {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-title {
|
||||||
|
max-width: calc(100% - 2rem);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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 {
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
.progress {
|
.progress {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
@@ -6,15 +48,23 @@ body {overflow-y:scroll;}
|
|||||||
|
|
||||||
.card {
|
.card {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important;
|
box-shadow: 0 .125rem .25rem rgba(0, 0, 0, .075) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sub-document {
|
||||||
|
background: #AB47BC1F !important;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
background: #F7F7F7; border-bottom: solid 1px #dfdfdf;
|
background: #F7F7F7;
|
||||||
|
border-bottom: solid 1px #dfdfdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
.document {
|
.document {
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
@@ -47,6 +97,11 @@ body {overflow-y:scroll;}
|
|||||||
background-color: #FFC107;
|
background-color: #FFC107;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge-user {
|
||||||
|
color: #212529;
|
||||||
|
background-color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
.badge-text {
|
.badge-text {
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
background-color: #FAAB3C;
|
background-color: #FAAB3C;
|
||||||
@@ -63,6 +118,9 @@ body {overflow-y:scroll;}
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
|
width: 100%;
|
||||||
|
line-height: 1rem;
|
||||||
|
height: 1.1rem;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -84,6 +142,15 @@ body {overflow-y:scroll;}
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fit-sm {
|
||||||
|
display: block;
|
||||||
|
max-width: 64px;
|
||||||
|
max-height: 64px;
|
||||||
|
margin: 0 auto 0;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.audio-fit {
|
.audio-fit {
|
||||||
height: 39px;
|
height: 39px;
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
@@ -98,16 +165,17 @@ body {overflow-y:scroll;}
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1500px) {
|
@media (min-width: 1500px) {
|
||||||
.container {
|
.container {
|
||||||
max-width: 1440px;
|
max-width: 1440px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-columns {
|
.card-columns {
|
||||||
column-count: 5;
|
column-count: 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1800px) {
|
@media (min-width: 1800px) {
|
||||||
.container {
|
.container {
|
||||||
max-width: 1550px;
|
max-width: 1550px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,13 +187,15 @@ mark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.content-div {
|
.content-div {
|
||||||
font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
|
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin: 3px;
|
margin: 3px;
|
||||||
|
white-space: normal;
|
||||||
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.irs-single, .irs-from, .irs-to {
|
.irs-single, .irs-from, .irs-to {
|
||||||
@@ -145,8 +215,7 @@ mark {
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inspire-tree .selected > .wholerow, .inspire-tree .selected > .title-wrap:hover + .wholerow
|
.inspire-tree .selected > .wholerow, .inspire-tree .selected > .title-wrap:hover + .wholerow {
|
||||||
{
|
|
||||||
background: none;
|
background: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,10 +231,59 @@ mark {
|
|||||||
line-height: 1rem;
|
line-height: 1rem;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-xs {
|
.btn-xs {
|
||||||
padding: .1rem .3rem;
|
padding: .1rem .3rem;
|
||||||
font-size: .875rem;
|
font-size: .875rem;
|
||||||
border-radius: .2rem;
|
border-radius: .2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 800px) {
|
||||||
|
#treeTabs {
|
||||||
|
flex-basis: inherit;
|
||||||
|
flex-grow: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
padding: .25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapper-sm {
|
||||||
|
min-width: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tagline {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.version {
|
||||||
|
color: #007bff;
|
||||||
|
margin-left: -18px;
|
||||||
|
margin-top: -14px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|||||||
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
439
web/js/dom.js
439
web/js/dom.js
@@ -75,11 +75,122 @@ function shouldPlayVideo(hit) {
|
|||||||
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function makePlaceholder(w, h, small) {
|
||||||
*
|
let calc;
|
||||||
* @param hit
|
if (small) {
|
||||||
* @returns {Element}
|
calc = w > h
|
||||||
*/
|
? (64 / w / h) >= 100
|
||||||
|
? (64 * w / h)
|
||||||
|
: 64
|
||||||
|
: 64;
|
||||||
|
} else {
|
||||||
|
calc = w > h
|
||||||
|
? (175 / w / h) >= 272
|
||||||
|
? (175 * w / h)
|
||||||
|
: 175
|
||||||
|
: 175;
|
||||||
|
}
|
||||||
|
|
||||||
|
const el = document.createElement("div");
|
||||||
|
el.setAttribute("style", `height: ${calc}px`);
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTitle(hit) {
|
||||||
|
let title = document.createElement("div");
|
||||||
|
title.setAttribute("class", "file-title");
|
||||||
|
let extension = hit["_source"].hasOwnProperty("extension") && hit["_source"]["extension"] !== "" ? "." + hit["_source"]["extension"] : "";
|
||||||
|
|
||||||
|
applyNameToTitle(hit, title, extension);
|
||||||
|
|
||||||
|
title.setAttribute("title", hit["_source"]["path"] + "/" + hit["_source"]["name"] + extension);
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTags(hit, mimeCategory) {
|
||||||
|
|
||||||
|
let tags = [];
|
||||||
|
switch (mimeCategory) {
|
||||||
|
case "video":
|
||||||
|
case "image":
|
||||||
|
if (hit["_source"].hasOwnProperty("videoc")) {
|
||||||
|
const formatTag = document.createElement("span");
|
||||||
|
formatTag.setAttribute("class", "badge badge-pill badge-video");
|
||||||
|
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
|
||||||
|
tags.push(formatTag);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "audio": {
|
||||||
|
if (hit["_source"].hasOwnProperty("audioc")) {
|
||||||
|
let formatTag = document.createElement("span");
|
||||||
|
formatTag.setAttribute("class", "badge badge-pill badge-audio");
|
||||||
|
formatTag.appendChild(document.createTextNode(hit["_source"]["audioc"]));
|
||||||
|
tags.push(formatTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// User tags
|
||||||
|
if (hit["_source"].hasOwnProperty("tag")) {
|
||||||
|
hit["_source"]["tag"].forEach(tag => {
|
||||||
|
const userTag = document.createElement("span");
|
||||||
|
userTag.setAttribute("class", "badge badge-pill badge-user");
|
||||||
|
|
||||||
|
const tokens = tag.split("#");
|
||||||
|
|
||||||
|
if (tokens.length > 1) {
|
||||||
|
const bg = "#" + tokens[1];
|
||||||
|
const fg = lum(tokens[1]) > 40 ? "#000" : "#fff";
|
||||||
|
userTag.setAttribute("style", `background-color: ${bg}; color: ${fg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = tokens[0].split(".")[tokens[0].split(".").length - 1];
|
||||||
|
userTag.appendChild(document.createTextNode(name));
|
||||||
|
tags.push(userTag);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
|
function infoButtonCb(hit) {
|
||||||
|
return () => {
|
||||||
|
getDocumentInfo(hit["_id"]).then(doc => {
|
||||||
|
$("#modal-title").text(doc["name"] + (doc["extension"] ? "." + doc["extension"] : ""));
|
||||||
|
|
||||||
|
const tbody = $("<tbody>");
|
||||||
|
$("#modal-body").empty()
|
||||||
|
.append($("<table class='table table-sm'>")
|
||||||
|
.append($("<thead>")
|
||||||
|
.append($("<tr>")
|
||||||
|
.append($("<th>").text("Field"))
|
||||||
|
.append($("<th>").text("Value"))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.append(tbody)
|
||||||
|
);
|
||||||
|
|
||||||
|
const displayFields = new Set([
|
||||||
|
"mime", "size", "mtime", "path", "title", "width", "height", "duration", "audioc", "videoc",
|
||||||
|
"bitrate", "artist", "album", "album_artist", "genre", "title", "font_name", "tag"
|
||||||
|
]);
|
||||||
|
Object.keys(doc)
|
||||||
|
.filter(key => key.startsWith("_keyword.") || key.startsWith("_text.") || displayFields.has(key))
|
||||||
|
.forEach(key => {
|
||||||
|
tbody.append($("<tr>")
|
||||||
|
.append($("<td>").text(key))
|
||||||
|
.append($("<td>").text(doc[key]))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (doc.hasOwnProperty("content") && doc["content"]) {
|
||||||
|
$("#modal-body").append($("<div class='content-div'>").text(doc["content"]))
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#modal").modal();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createDocCard(hit) {
|
function createDocCard(hit) {
|
||||||
let docCard = document.createElement("div");
|
let docCard = document.createElement("div");
|
||||||
docCard.setAttribute("class", "card");
|
docCard.setAttribute("class", "card");
|
||||||
@@ -87,27 +198,26 @@ function createDocCard(hit) {
|
|||||||
let docCardBody = document.createElement("div");
|
let docCardBody = document.createElement("div");
|
||||||
docCardBody.setAttribute("class", "card-body document");
|
docCardBody.setAttribute("class", "card-body document");
|
||||||
|
|
||||||
|
//Title
|
||||||
|
let title = makeTitle(hit);
|
||||||
|
let isSubDocument = false;
|
||||||
|
|
||||||
let link = document.createElement("a");
|
let link = document.createElement("a");
|
||||||
link.setAttribute("href", "f/" + hit["_id"]);
|
link.setAttribute("href", "f/" + hit["_id"]);
|
||||||
link.setAttribute("target", "_blank");
|
link.setAttribute("target", "_blank");
|
||||||
|
link.style.maxWidth = "calc(100% - 1.2rem)";
|
||||||
|
link.appendChild(title);
|
||||||
|
|
||||||
//Title
|
if (hit["_source"].hasOwnProperty("parent")) {
|
||||||
let title = document.createElement("p");
|
docCard.classList.add("sub-document");
|
||||||
title.setAttribute("class", "file-title");
|
isSubDocument = true;
|
||||||
let extension = hit["_source"].hasOwnProperty("extension") && hit["_source"]["extension"] !== "" ? "." + hit["_source"]["extension"] : "";
|
}
|
||||||
|
|
||||||
applyNameToTitle(hit, title, extension);
|
|
||||||
|
|
||||||
title.setAttribute("title", hit["_source"]["path"] + "/" + hit["_source"]["name"] + extension);
|
|
||||||
docCard.appendChild(title);
|
|
||||||
|
|
||||||
let tagContainer = document.createElement("div");
|
let tagContainer = document.createElement("div");
|
||||||
tagContainer.setAttribute("class", "card-text");
|
tagContainer.setAttribute("class", "card-text");
|
||||||
|
|
||||||
if (hit["_source"].hasOwnProperty("mime") && hit["_source"]["mime"] !== null) {
|
if (hit["_source"].hasOwnProperty("mime") && hit["_source"]["mime"] !== null) {
|
||||||
|
|
||||||
let tags = [];
|
|
||||||
let thumbnail = null;
|
|
||||||
let thumbnailOverlay = null;
|
let thumbnailOverlay = null;
|
||||||
let imgWrapper = document.createElement("div");
|
let imgWrapper = document.createElement("div");
|
||||||
imgWrapper.setAttribute("style", "position: relative");
|
imgWrapper.setAttribute("style", "position: relative");
|
||||||
@@ -115,31 +225,7 @@ function createDocCard(hit) {
|
|||||||
let mimeCategory = hit["_source"]["mime"].split("/")[0];
|
let mimeCategory = hit["_source"]["mime"].split("/")[0];
|
||||||
|
|
||||||
//Thumbnail
|
//Thumbnail
|
||||||
if (mimeCategory === "video" && shouldPlayVideo(hit)) {
|
let thumbnail = makeThumbnail(mimeCategory, hit, imgWrapper, false);
|
||||||
thumbnail = document.createElement("video");
|
|
||||||
addVidSrc("f/" + hit["_id"], hit["_source"]["mime"], thumbnail);
|
|
||||||
|
|
||||||
thumbnail.setAttribute("class", "fit");
|
|
||||||
thumbnail.setAttribute("loop", "");
|
|
||||||
thumbnail.setAttribute("controls", "");
|
|
||||||
thumbnail.setAttribute("preload", "none");
|
|
||||||
thumbnail.setAttribute("poster", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
|
||||||
thumbnail.addEventListener("dblclick", function () {
|
|
||||||
thumbnail.webkitRequestFullScreen();
|
|
||||||
});
|
|
||||||
} else if ((hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 20 && hit["_source"]["height"] > 20)
|
|
||||||
|| hit["_source"]["mime"] === "application/pdf"
|
|
||||||
|| hit["_source"]["mime"] === "application/epub+zip"
|
|
||||||
|| hit["_source"]["mime"] === "application/x-cbz"
|
|
||||||
|| hit["_source"].hasOwnProperty("font_name")
|
|
||||||
) {
|
|
||||||
thumbnail = document.createElement("img");
|
|
||||||
thumbnail.setAttribute("class", "card-img-top fit");
|
|
||||||
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
|
||||||
thumbnail.addEventListener("error", () => {
|
|
||||||
imgWrapper.remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//Thumbnail overlay
|
//Thumbnail overlay
|
||||||
switch (mimeCategory) {
|
switch (mimeCategory) {
|
||||||
@@ -149,15 +235,17 @@ function createDocCard(hit) {
|
|||||||
thumbnailOverlay.setAttribute("class", "card-img-overlay");
|
thumbnailOverlay.setAttribute("class", "card-img-overlay");
|
||||||
|
|
||||||
//Resolution
|
//Resolution
|
||||||
let resolutionBadge = document.createElement("span");
|
if (hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 32 && hit["_source"]["height"] > 32) {
|
||||||
resolutionBadge.setAttribute("class", "badge badge-resolution");
|
let resolutionBadge = document.createElement("span");
|
||||||
if (hit["_source"].hasOwnProperty("width")) {
|
resolutionBadge.setAttribute("class", "badge badge-resolution");
|
||||||
resolutionBadge.appendChild(document.createTextNode(hit["_source"]["width"] + "x" + hit["_source"]["height"]));
|
if (hit["_source"].hasOwnProperty("width")) {
|
||||||
|
resolutionBadge.appendChild(document.createTextNode(hit["_source"]["width"] + "x" + hit["_source"]["height"]));
|
||||||
|
}
|
||||||
|
thumbnailOverlay.appendChild(resolutionBadge);
|
||||||
}
|
}
|
||||||
thumbnailOverlay.appendChild(resolutionBadge);
|
|
||||||
|
|
||||||
// Hover
|
// Hover
|
||||||
if (thumbnail && hit["_source"]["videoc"] === "gif") {
|
if (thumbnail && hit["_source"]["videoc"] === "gif" && !isSubDocument) {
|
||||||
gifOver(thumbnail, hit);
|
gifOver(thumbnail, hit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -167,51 +255,34 @@ function createDocCard(hit) {
|
|||||||
if (hit["_source"].hasOwnProperty("duration")) {
|
if (hit["_source"].hasOwnProperty("duration")) {
|
||||||
thumbnailOverlay = document.createElement("div");
|
thumbnailOverlay = document.createElement("div");
|
||||||
thumbnailOverlay.setAttribute("class", "card-img-overlay");
|
thumbnailOverlay.setAttribute("class", "card-img-overlay");
|
||||||
let durationBadge = document.createElement("span");
|
const durationBadge = document.createElement("span");
|
||||||
durationBadge.setAttribute("class", "badge badge-resolution");
|
durationBadge.setAttribute("class", "badge badge-resolution");
|
||||||
durationBadge.appendChild(document.createTextNode(humanTime(hit["_source"]["duration"])));
|
durationBadge.appendChild(document.createTextNode(humanTime(hit["_source"]["duration"])));
|
||||||
thumbnailOverlay.appendChild(durationBadge);
|
thumbnailOverlay.appendChild(durationBadge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tags
|
// Tags
|
||||||
switch (mimeCategory) {
|
let tags = getTags(hit, mimeCategory);
|
||||||
case "video":
|
for (let i = 0; i < tags.length; i++) {
|
||||||
case "image":
|
tagContainer.appendChild(tags[i]);
|
||||||
if (hit["_source"].hasOwnProperty("videoc")) {
|
|
||||||
let formatTag = document.createElement("span");
|
|
||||||
formatTag.setAttribute("class", "badge badge-pill badge-video");
|
|
||||||
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
|
|
||||||
tags.push(formatTag);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "audio": {
|
|
||||||
if (hit["_source"].hasOwnProperty("audioc")) {
|
|
||||||
let formatTag = document.createElement("span");
|
|
||||||
formatTag.setAttribute("class", "badge badge-pill badge-audio");
|
|
||||||
formatTag.appendChild(document.createTextNode(hit["_source"]["audioc"]));
|
|
||||||
tags.push(formatTag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Content
|
//Content
|
||||||
let contentHl = getContentHighlight(hit);
|
let contentHl = getContentHighlight(hit);
|
||||||
if (contentHl !== undefined) {
|
if (contentHl !== undefined) {
|
||||||
let contentDiv = document.createElement("div");
|
const contentDiv = document.createElement("div");
|
||||||
contentDiv.setAttribute("class", "content-div");
|
contentDiv.setAttribute("class", "content-div");
|
||||||
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
|
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
|
||||||
docCard.appendChild(contentDiv);
|
docCard.appendChild(contentDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thumbnail !== null) {
|
if (thumbnail !== null) {
|
||||||
imgWrapper.appendChild(thumbnail);
|
|
||||||
docCard.appendChild(imgWrapper);
|
docCard.appendChild(imgWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Audio
|
//Audio
|
||||||
if (mimeCategory === "audio" && hit["_source"].hasOwnProperty("audioc")) {
|
if (mimeCategory === "audio" && hit["_source"].hasOwnProperty("audioc") && !isSubDocument) {
|
||||||
|
|
||||||
let audio = document.createElement("audio");
|
let audio = document.createElement("audio");
|
||||||
audio.setAttribute("preload", "none");
|
audio.setAttribute("preload", "none");
|
||||||
@@ -226,10 +297,6 @@ function createDocCard(hit) {
|
|||||||
if (thumbnailOverlay !== null) {
|
if (thumbnailOverlay !== null) {
|
||||||
imgWrapper.appendChild(thumbnailOverlay);
|
imgWrapper.appendChild(thumbnailOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < tags.length; i++) {
|
|
||||||
tagContainer.appendChild(tags[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Size tag
|
//Size tag
|
||||||
@@ -238,15 +305,186 @@ function createDocCard(hit) {
|
|||||||
sizeTag.setAttribute("class", "text-muted");
|
sizeTag.setAttribute("class", "text-muted");
|
||||||
tagContainer.appendChild(sizeTag);
|
tagContainer.appendChild(sizeTag);
|
||||||
|
|
||||||
docCardBody.appendChild(link);
|
const titleWrapper = document.createElement("div");
|
||||||
|
titleWrapper.style.display = "flex";
|
||||||
|
|
||||||
|
const infoButton = makeInfoButton(hit);
|
||||||
|
|
||||||
|
titleWrapper.appendChild(infoButton);
|
||||||
|
titleWrapper.appendChild(link);
|
||||||
|
|
||||||
|
docCardBody.appendChild(titleWrapper);
|
||||||
docCard.appendChild(docCardBody);
|
docCard.appendChild(docCardBody);
|
||||||
|
|
||||||
link.appendChild(title);
|
|
||||||
docCardBody.appendChild(tagContainer);
|
docCardBody.appendChild(tagContainer);
|
||||||
|
|
||||||
return docCard;
|
return docCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeThumbnail(mimeCategory, hit, imgWrapper, small) {
|
||||||
|
let thumbnail;
|
||||||
|
let isSubDocument = hit["_source"].hasOwnProperty("parent");
|
||||||
|
|
||||||
|
if (mimeCategory === "video" && shouldPlayVideo(hit) && !isSubDocument) {
|
||||||
|
thumbnail = document.createElement("video");
|
||||||
|
addVidSrc("f/" + hit["_id"], hit["_source"]["mime"], thumbnail);
|
||||||
|
|
||||||
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"], small);
|
||||||
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
|
if (small) {
|
||||||
|
thumbnail.setAttribute("class", "fit-sm");
|
||||||
|
} else {
|
||||||
|
thumbnail.setAttribute("class", "fit");
|
||||||
|
}
|
||||||
|
if (small) {
|
||||||
|
thumbnail.style.cursor = "pointer";
|
||||||
|
thumbnail.title = "Enlarge";
|
||||||
|
thumbnail.addEventListener("click", function () {
|
||||||
|
imgWrapper.classList.remove("wrapper-sm", "mr-1");
|
||||||
|
imgWrapper.parentElement.classList.add("media-expanded");
|
||||||
|
thumbnail.setAttribute("class", "fit");
|
||||||
|
thumbnail.setAttribute("controls", "");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
thumbnail.setAttribute("controls", "");
|
||||||
|
}
|
||||||
|
thumbnail.setAttribute("preload", "none");
|
||||||
|
thumbnail.setAttribute("poster", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
thumbnail.addEventListener("dblclick", function () {
|
||||||
|
thumbnail.setAttribute("controls", "");
|
||||||
|
if (thumbnail.webkitRequestFullScreen) {
|
||||||
|
thumbnail.webkitRequestFullScreen();
|
||||||
|
} else {
|
||||||
|
thumbnail.requestFullscreen();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const poster = new Image();
|
||||||
|
poster.src = thumbnail.getAttribute('poster');
|
||||||
|
poster.addEventListener("load", function () {
|
||||||
|
placeholder.remove();
|
||||||
|
imgWrapper.appendChild(thumbnail);
|
||||||
|
});
|
||||||
|
} else if ((hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 32 && hit["_source"]["height"] > 32)
|
||||||
|
|| hit["_source"]["mime"] === "application/pdf"
|
||||||
|
|| hit["_source"]["mime"] === "application/epub+zip"
|
||||||
|
|| hit["_source"]["mime"] === "application/x-cbz"
|
||||||
|
|| hit["_source"].hasOwnProperty("font_name")
|
||||||
|
) {
|
||||||
|
thumbnail = document.createElement("img");
|
||||||
|
if (small) {
|
||||||
|
thumbnail.setAttribute("class", "fit-sm");
|
||||||
|
} else {
|
||||||
|
thumbnail.setAttribute("class", "card-img-top fit");
|
||||||
|
}
|
||||||
|
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
|
||||||
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"], small);
|
||||||
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
|
thumbnail.addEventListener("error", () => {
|
||||||
|
imgWrapper.remove();
|
||||||
|
});
|
||||||
|
thumbnail.addEventListener("load", () => {
|
||||||
|
placeholder.remove();
|
||||||
|
imgWrapper.appendChild(thumbnail);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeInfoButton(hit) {
|
||||||
|
const infoButton = document.createElement("span");
|
||||||
|
infoButton.appendChild(document.createTextNode("🛈"));
|
||||||
|
infoButton.setAttribute("class", "info-icon");
|
||||||
|
infoButton.addEventListener("click", infoButtonCb(hit));
|
||||||
|
return infoButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDocLine(hit) {
|
||||||
|
|
||||||
|
const mime = hit["_source"]["mime"];
|
||||||
|
let mimeCategory = mime ? mime.split("/")[0] : null;
|
||||||
|
let tags = getTags(hit, mimeCategory);
|
||||||
|
|
||||||
|
let imgWrapper = document.createElement("div");
|
||||||
|
imgWrapper.setAttribute("class", "align-self-start mr-1 wrapper-sm");
|
||||||
|
|
||||||
|
let media = document.createElement("div");
|
||||||
|
media.setAttribute("class", "media");
|
||||||
|
|
||||||
|
const line = document.createElement("div");
|
||||||
|
line.setAttribute("class", "list-group-item flex-column align-items-start");
|
||||||
|
|
||||||
|
if (hit["_source"].hasOwnProperty("parent")) {
|
||||||
|
line.classList.add("sub-document");
|
||||||
|
isSubDocument = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const infoButton = makeInfoButton(hit);
|
||||||
|
|
||||||
|
const title = makeTitle(hit);
|
||||||
|
|
||||||
|
let link = document.createElement("a");
|
||||||
|
link.setAttribute("href", "f/" + hit["_id"]);
|
||||||
|
link.setAttribute("target", "_blank");
|
||||||
|
link.appendChild(title);
|
||||||
|
|
||||||
|
const titleDiv = document.createElement("div");
|
||||||
|
|
||||||
|
const titleWrapper = document.createElement("div");
|
||||||
|
titleWrapper.style.display = "flex";
|
||||||
|
titleWrapper.appendChild(infoButton);
|
||||||
|
titleWrapper.appendChild(link);
|
||||||
|
|
||||||
|
titleDiv.appendChild(titleWrapper);
|
||||||
|
|
||||||
|
line.appendChild(media);
|
||||||
|
|
||||||
|
let thumbnail = makeThumbnail(mimeCategory, hit, imgWrapper, true);
|
||||||
|
if (thumbnail) {
|
||||||
|
media.appendChild(imgWrapper);
|
||||||
|
}
|
||||||
|
media.appendChild(titleDiv);
|
||||||
|
|
||||||
|
// Content
|
||||||
|
let contentHl = getContentHighlight(hit);
|
||||||
|
if (contentHl !== undefined) {
|
||||||
|
const contentDiv = document.createElement("div");
|
||||||
|
contentDiv.setAttribute("class", "content-div");
|
||||||
|
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
|
||||||
|
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");
|
||||||
|
tagContainer.setAttribute("class", "tag-container");
|
||||||
|
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
tagContainer.appendChild(tags[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Size tag
|
||||||
|
let sizeTag = document.createElement("small");
|
||||||
|
sizeTag.appendChild(document.createTextNode(humanFileSize(hit["_source"]["size"])));
|
||||||
|
sizeTag.setAttribute("class", "text-muted");
|
||||||
|
tagContainer.appendChild(sizeTag);
|
||||||
|
|
||||||
|
titleDiv.appendChild(pathLine);
|
||||||
|
pathLine.appendChild(path);
|
||||||
|
pathLine.appendChild(tagContainer);
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
function makePreloader() {
|
function makePreloader() {
|
||||||
const elem = document.createElement("div");
|
const elem = document.createElement("div");
|
||||||
elem.setAttribute("class", "progress");
|
elem.setAttribute("class", "progress");
|
||||||
@@ -271,18 +509,53 @@ function makePageIndicator(searchResult) {
|
|||||||
function makeStatsCard(searchResult) {
|
function makeStatsCard(searchResult) {
|
||||||
|
|
||||||
let statsCard = document.createElement("div");
|
let statsCard = document.createElement("div");
|
||||||
statsCard.setAttribute("class", "card");
|
statsCard.setAttribute("class", "card stat");
|
||||||
let statsCardBody = document.createElement("div");
|
let statsCardBody = document.createElement("div");
|
||||||
statsCardBody.setAttribute("class", "card-body");
|
statsCardBody.setAttribute("class", "card-body");
|
||||||
|
|
||||||
let stat = document.createElement("p");
|
const resultMode = document.createElement("div");
|
||||||
|
resultMode.setAttribute("class", "btn-group btn-group-toggle");
|
||||||
|
resultMode.setAttribute("data-toggle", "buttons");
|
||||||
|
resultMode.style.cssFloat = "right";
|
||||||
|
|
||||||
|
const listMode = document.createElement("label");
|
||||||
|
listMode.setAttribute("class", "btn btn-primary");
|
||||||
|
listMode.appendChild(document.createTextNode("List"));
|
||||||
|
|
||||||
|
const gridMode = document.createElement("label");
|
||||||
|
gridMode.setAttribute("class", "btn btn-primary");
|
||||||
|
gridMode.appendChild(document.createTextNode("Grid"));
|
||||||
|
|
||||||
|
resultMode.appendChild(gridMode);
|
||||||
|
resultMode.appendChild(listMode);
|
||||||
|
|
||||||
|
if (mode === "grid") {
|
||||||
|
gridMode.classList.add("active")
|
||||||
|
} else {
|
||||||
|
listMode.classList.add("active")
|
||||||
|
}
|
||||||
|
|
||||||
|
gridMode.addEventListener("click", () => {
|
||||||
|
mode = "grid";
|
||||||
|
localStorage.setItem("mode", mode);
|
||||||
|
searchDebounced();
|
||||||
|
});
|
||||||
|
listMode.addEventListener("click", () => {
|
||||||
|
mode = "list";
|
||||||
|
localStorage.setItem("mode", mode);
|
||||||
|
searchDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
let stat = document.createElement("span");
|
||||||
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
|
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
|
||||||
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
|
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
|
||||||
stat.appendChild(document.createTextNode(totalHits + " results in " + searchResult["took"] + "ms"));
|
stat.appendChild(document.createTextNode(totalHits + " results in " + searchResult["took"] + "ms"));
|
||||||
|
|
||||||
statsCardBody.appendChild(stat);
|
statsCardBody.appendChild(stat);
|
||||||
|
statsCardBody.appendChild(resultMode);
|
||||||
|
|
||||||
if (totalHits !== 0) {
|
if (totalHits !== 0) {
|
||||||
let sizeStat = document.createElement("span");
|
let sizeStat = document.createElement("div");
|
||||||
sizeStat.appendChild(document.createTextNode(humanFileSize(searchResult["aggregations"]["total_size"]["value"])));
|
sizeStat.appendChild(document.createTextNode(humanFileSize(searchResult["aggregations"]["total_size"]["value"])));
|
||||||
statsCardBody.appendChild(sizeStat);
|
statsCardBody.appendChild(sizeStat);
|
||||||
}
|
}
|
||||||
@@ -294,7 +567,11 @@ function makeStatsCard(searchResult) {
|
|||||||
|
|
||||||
function makeResultContainer() {
|
function makeResultContainer() {
|
||||||
let resultContainer = document.createElement("div");
|
let resultContainer = document.createElement("div");
|
||||||
resultContainer.setAttribute("class", "card-columns");
|
|
||||||
|
|
||||||
|
if (mode === "grid") {
|
||||||
|
resultContainer.setAttribute("class", "card-columns");
|
||||||
|
} else {
|
||||||
|
resultContainer.setAttribute("class", "list-group");
|
||||||
|
}
|
||||||
return resultContainer;
|
return resultContainer;
|
||||||
}
|
}
|
||||||
|
|||||||
165
web/js/search.js
165
web/js/search.js
@@ -1,6 +1,8 @@
|
|||||||
const SIZE = 40;
|
const SIZE = 40;
|
||||||
let mimeMap = [];
|
let mimeMap = [];
|
||||||
let tree;
|
let tagMap = [];
|
||||||
|
let mimeTree;
|
||||||
|
let tagTree;
|
||||||
|
|
||||||
let searchBar = document.getElementById("searchBar");
|
let searchBar = document.getElementById("searchBar");
|
||||||
let pathBar = document.getElementById("pathBar");
|
let pathBar = document.getElementById("pathBar");
|
||||||
@@ -10,6 +12,26 @@ let coolingDown = false;
|
|||||||
let searchBusy = true;
|
let searchBusy = true;
|
||||||
let selectedIndices = [];
|
let selectedIndices = [];
|
||||||
|
|
||||||
|
let mode;
|
||||||
|
if (localStorage.getItem("mode") === null) {
|
||||||
|
mode = "grid";
|
||||||
|
} else {
|
||||||
|
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,
|
||||||
@@ -17,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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -37,18 +60,51 @@ 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 getDocumentInfo(id) {
|
||||||
|
return $.getJSON("d/" + id).fail(e => {
|
||||||
|
console.log(e);
|
||||||
|
showEsError();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleTreeClick(tree) {
|
||||||
|
return (event, node, handler) => {
|
||||||
|
event.preventTreeDefault();
|
||||||
|
|
||||||
|
if (node.id === "any") {
|
||||||
|
if (!node.itree.state.checked) {
|
||||||
|
tree.deselect();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tree.node("any").deselect();
|
||||||
|
}
|
||||||
|
|
||||||
|
handler();
|
||||||
|
searchDebounced();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$.jsonPost("es", {
|
$.jsonPost("es", {
|
||||||
aggs: {
|
aggs: {
|
||||||
mimeTypes: {
|
mimeTypes: {
|
||||||
@@ -85,34 +141,86 @@ $.jsonPost("es", {
|
|||||||
});
|
});
|
||||||
mimeMap.push({"text": "All", "id": "any"});
|
mimeMap.push({"text": "All", "id": "any"});
|
||||||
|
|
||||||
tree = new InspireTree({
|
mimeTree = new InspireTree({
|
||||||
selection: {
|
selection: {
|
||||||
mode: 'checkbox'
|
mode: 'checkbox'
|
||||||
},
|
},
|
||||||
data: mimeMap
|
data: mimeMap
|
||||||
});
|
});
|
||||||
new InspireTreeDOM(tree, {
|
new InspireTreeDOM(mimeTree, {
|
||||||
target: '.tree'
|
target: '#mimeTree'
|
||||||
});
|
});
|
||||||
tree.on("node.click", function (event, node, handler) {
|
mimeTree.on("node.click", handleTreeClick(mimeTree));
|
||||||
event.preventTreeDefault();
|
mimeTree.select();
|
||||||
|
mimeTree.node("any").deselect();
|
||||||
|
});
|
||||||
|
|
||||||
if (node.id === "any") {
|
function leafTag(tag) {
|
||||||
if (!node.itree.state.checked) {
|
const tokens = tag.split(".");
|
||||||
tree.deselect();
|
return tokens[tokens.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tags tree
|
||||||
|
$.jsonPost("es", {
|
||||||
|
aggs: {
|
||||||
|
tags: {
|
||||||
|
terms: {
|
||||||
|
field: "tag",
|
||||||
|
size: 10000
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
tree.node("any").deselect();
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
size: 0,
|
||||||
|
}).then(resp => {
|
||||||
|
resp["aggregations"]["tags"]["buckets"]
|
||||||
|
.sort((a, b) => a["key"].localeCompare(b["key"]))
|
||||||
|
.forEach(bucket => {
|
||||||
|
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
|
||||||
|
});
|
||||||
|
|
||||||
handler();
|
tagMap.push({"text": "All", "id": "any"});
|
||||||
searchDebounced();
|
tagTree = new InspireTree({
|
||||||
|
selection: {
|
||||||
|
mode: 'checkbox'
|
||||||
|
},
|
||||||
|
data: tagMap
|
||||||
});
|
});
|
||||||
tree.select();
|
new InspireTreeDOM(tagTree, {
|
||||||
tree.node("any").deselect();
|
target: '#tagTree'
|
||||||
|
});
|
||||||
|
tagTree.on("node.click", handleTreeClick(tagTree));
|
||||||
|
tagTree.node("any").select();
|
||||||
searchBusy = false;
|
searchBusy = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function addTag(map, tag, id, count) {
|
||||||
|
let tags = tag.split("#")[0].split(".");
|
||||||
|
|
||||||
|
let child = {
|
||||||
|
id: id,
|
||||||
|
text: tags.length !== 1 ? tags[0] : `${tags[0]} (${count})`,
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
|
||||||
|
let found = false;
|
||||||
|
map.forEach(node => {
|
||||||
|
if (node.text === child.text) {
|
||||||
|
found = true;
|
||||||
|
if (tags.length !== 1) {
|
||||||
|
addTag(node.children, tags.slice(1).join("."), id, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!found) {
|
||||||
|
if (tags.length !== 1) {
|
||||||
|
addTag(child.children, tags.slice(1).join("."), id, count);
|
||||||
|
map.push(child);
|
||||||
|
} else {
|
||||||
|
map.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
new autoComplete({
|
new autoComplete({
|
||||||
selector: '#pathBar',
|
selector: '#pathBar',
|
||||||
minChars: 1,
|
minChars: 1,
|
||||||
@@ -140,7 +248,12 @@ new autoComplete({
|
|||||||
|
|
||||||
function insertHits(resultContainer, hits) {
|
function insertHits(resultContainer, hits) {
|
||||||
for (let i = 0; i < hits.length; i++) {
|
for (let i = 0; i < hits.length; i++) {
|
||||||
resultContainer.appendChild(createDocCard(hits[i]));
|
|
||||||
|
if (mode === "grid") {
|
||||||
|
resultContainer.appendChild(createDocCard(hits[i]));
|
||||||
|
} else {
|
||||||
|
resultContainer.appendChild(createDocLine(hits[i]));
|
||||||
|
}
|
||||||
docCount++;
|
docCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,8 +294,8 @@ function doScroll() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedMimeTypes() {
|
function getSelectedNodes(tree) {
|
||||||
let mimeTypes = [];
|
let selectedNodes = [];
|
||||||
|
|
||||||
let selected = tree.selected();
|
let selected = tree.selected();
|
||||||
|
|
||||||
@@ -194,11 +307,11 @@ function getSelectedMimeTypes() {
|
|||||||
|
|
||||||
//Only get children
|
//Only get children
|
||||||
if (selected[i].text.indexOf("(") !== -1) {
|
if (selected[i].text.indexOf("(") !== -1) {
|
||||||
mimeTypes.push(selected[i].id);
|
selectedNodes.push(selected[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mimeTypes
|
return selectedNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
@@ -239,11 +352,16 @@ function search() {
|
|||||||
if (path !== "") {
|
if (path !== "") {
|
||||||
filters.push([{term: {path: path}}])
|
filters.push([{term: {path: path}}])
|
||||||
}
|
}
|
||||||
let mimeTypes = getSelectedMimeTypes();
|
let mimeTypes = getSelectedNodes(mimeTree);
|
||||||
if (!mimeTypes.includes("any")) {
|
if (!mimeTypes.includes("any")) {
|
||||||
filters.push([{terms: {"mime": mimeTypes}}]);
|
filters.push([{terms: {"mime": mimeTypes}}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tags = getSelectedNodes(tagTree);
|
||||||
|
if (!tags.includes("any")) {
|
||||||
|
filters.push([{terms: {"tag": tags}}]);
|
||||||
|
}
|
||||||
|
|
||||||
$.jsonPost("es?scroll=1", {
|
$.jsonPost("es?scroll=1", {
|
||||||
"_source": {
|
"_source": {
|
||||||
excludes: ["content"]
|
excludes: ["content"]
|
||||||
@@ -269,6 +387,7 @@ function search() {
|
|||||||
post_tags: ["</mark>"],
|
post_tags: ["</mark>"],
|
||||||
fields: {
|
fields: {
|
||||||
content: {},
|
content: {},
|
||||||
|
// "content.nGram": {},
|
||||||
name: {},
|
name: {},
|
||||||
"name.nGram": {},
|
"name.nGram": {},
|
||||||
font_name: {},
|
font_name: {},
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
function humanFileSize(bytes) {
|
function humanFileSize(bytes) {
|
||||||
if (bytes === 0) {
|
if (bytes === 0) {
|
||||||
return "? B"
|
return "0 B"
|
||||||
}
|
}
|
||||||
|
|
||||||
let thresh = 1000;
|
let thresh = 1000;
|
||||||
@@ -43,9 +43,9 @@ function humanTime(sec_num) {
|
|||||||
|
|
||||||
function debounce(func, wait) {
|
function debounce(func, wait) {
|
||||||
let timeout;
|
let timeout;
|
||||||
return function() {
|
return function () {
|
||||||
let context = this, args = arguments;
|
let context = this, args = arguments;
|
||||||
let later = function() {
|
let later = function () {
|
||||||
timeout = null;
|
timeout = null;
|
||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
};
|
};
|
||||||
@@ -54,3 +54,13 @@ function debounce(func, wait) {
|
|||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lum(c) {
|
||||||
|
c = c.substring(1);
|
||||||
|
let rgb = parseInt(c, 16);
|
||||||
|
let r = (rgb >> 16) & 0xff;
|
||||||
|
let g = (rgb >> 8) & 0xff;
|
||||||
|
let b = (rgb >> 0) & 0xff;
|
||||||
|
|
||||||
|
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +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.2.5</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>
|
||||||
@@ -24,7 +25,7 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<span onclick="document.getElementById('fuzzyToggle').click()">Fuzzy </span>
|
<span title="Toggle fuzzy searching" onclick="document.getElementById('fuzzyToggle').click()">Fuzzy </span>
|
||||||
<input title="Toggle fuzzy searching" type="checkbox" id="fuzzyToggle"
|
<input title="Toggle fuzzy searching" type="checkbox" id="fuzzyToggle"
|
||||||
onclick="toggleFuzzy()" checked>
|
onclick="toggleFuzzy()" checked>
|
||||||
</div>
|
</div>
|
||||||
@@ -41,11 +42,39 @@
|
|||||||
<select class="custom-select" id="indices" multiple size="6"></select>
|
<select class="custom-select" id="indices" multiple size="6"></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col">
|
<div class="col" id="treeTabs">
|
||||||
<label>Mime types</label>
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
|
<li class="nav-item">
|
||||||
<div class="tree"></div>
|
<a class="nav-link active" data-toggle="tab" href="#mime" role="tab" aria-controls="home" aria-selected="true">Mime Types</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-toggle="tab" href="#tag" role="tab" aria-controls="profile" aria-selected="false" title="User-defined tags">Tags</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content" id="myTabContent">
|
||||||
|
<div class="tab-pane fade show active" id="mime" role="tabpanel" aria-labelledby="home-tab">
|
||||||
|
<div id="mimeTree" class="tree"></div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="tag" role="tabpanel" aria-labelledby="profile-tab">
|
||||||
|
<div id="tagTree" class="tree"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal" id="modal" tabindex="-1" role="dialog" aria-labelledby="modal-title" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-lg modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="modal-title"></h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="modal-body"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user