Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: IIIF URL redirection #417

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 76 additions & 35 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,47 +1,88 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent # New in v14. For earlier clang-format versions, use AlwaysBreak instead.
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
ColumnLimit: 120
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '^".*'
Priority: 2
- Regex: '.*'
Priority: 3
BreakInheritanceList: AfterColon
BreakStringLiterals: false
ColumnLimit: 80
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseBlocks: true
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
InsertNewlineAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PointerAlignment: Left
ReferenceAlignment: Left # New in v13. int &name ==> int& name
ReflowComments: false
SeparateDefinitionBlocks: Always # New in v14.
SortIncludes: CaseSensitive
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
...
UseTab: Never
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cmake-build-debug-remote/
cmake-build-debug-inside-docker/
cmake-build-dockerdebug/
cmake-build-relwithdebinfo-inside-docker/
cmake-build-relwithdebinfo-nix-develop/
# ignore cache
cache/

Expand Down
56 changes: 41 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,44 @@ option(CMAKE_BUILD_TYPE "The default build type is RelWithDebInfo" RelWithDebInf
#
# Here we determine the compiler and compiler version. We need clang >= 15 or g++ >= 13
#
if(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.0")
message(FATAL_ERROR "Clang version must be 15.0.0 or greater! Aborting...")
set(ENV(CXX) "clang++")
set(ENV(CC) "clang")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13.0")
message(FATAL_ERROR "Requires GCC 13.0 or greater.")
set(ENV(CXX) "g++")
set(ENV(CC) "gcc")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.0")
message(FATAL_ERROR "Clang version must be 15.0.0 or greater! Aborting...")
set(ENV(CXX) "clang++")
set(ENV(CC) "clang")
endif()
else()
message(WARNING "You are using an unsupported compiler (${CMAKE_CXX_COMPILER_ID}). Compilation has only been tested with Clang and GCC.")
endif()
#
# Set the C++ standard to C++14 (goal is to move to C++23)
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

# Set C++ standard to C++23
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_REQUIRED_FLAGS "-std=c++23") # or the appropriate flag for your compiler

# Simple C++ test program
set(CXX_TEST_PROGRAM "
#include <expected>
#include <version>
int main() { return 0; }
")

# Check if the test program compiles with C++23
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("${CXX_TEST_PROGRAM}" CXX23_SUPPORTED)

if(CXX23_SUPPORTED)
message(STATUS "C++23 is supported.")
else()
message(FATAL_ERROR "C++23 is not supported.")
endif()

#
# Statically compile the C++ standard library into the executable
Expand Down Expand Up @@ -410,20 +429,26 @@ include_directories(
add_executable(sipi
src/sipi.cpp
src/SipiConf.cpp include/SipiConf.h
src/SipiError.cpp include/SipiError.h
src/SipiError.cpp
src/SipiError.hpp
include/AdobeRGB1998_icc.h include/USWebCoatedSWOP_icc.h
include/CLI11.hpp
src/metadata/SipiIcc.cpp include/metadata/SipiIcc.h
src/metadata/SipiXmp.cpp include/metadata/SipiXmp.h
src/metadata/SipiIptc.cpp include/metadata/SipiIptc.h
src/metadata/SipiExif.cpp include/metadata/SipiExif.h
src/metadata/SipiEssentials.cpp include/metadata/SipiEssentials.h
src/SipiImage.cpp include/SipiImage.h include/SipiImageError.h
src/SipiImage.cpp
src/SipiImage.hpp
src/SipiImageError.hpp
src/formats/SipiIOTiff.cpp include/formats/SipiIOTiff.h
src/formats/SipiIOJ2k.cpp include/formats/SipiIOJ2k.h
src/formats/SipiIOJpeg.cpp include/formats/SipiIOJpeg.h
src/formats/SipiIOPng.cpp include/formats/SipiIOPng.h
src/SipiHttpServer.cpp include/SipiHttpServer.h
src/SipiHttpServer.cpp
src/SipiHttpServer.hpp
src/handlers/iiif_handler.cpp
src/handlers/iiif_handler.hpp
src/SipiCache.cpp include/SipiCache.h
src/SipiLua.cpp include/SipiLua.h
src/iiifparser/SipiRotation.cpp include/iiifparser/SipiRotation.h
Expand All @@ -447,7 +472,8 @@ add_executable(sipi
shttps/makeunique.h
src/SipiFilenameHash.cpp include/SipiFilenameHash.h
include/iiifparser/SipiIdentifier.h src/iiifparser/SipiIdentifier.cpp
include/SipiImageError.h)
src/handlers/iiif_handler.cpp
src/handlers/iiif_handler.hpp)

add_dependencies(sipi icc_profiles)

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ENV BUILD_TAG=${BUILD_TAG}
RUN cmake -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo --log-context \
&& cd build \
&& cmake --build . --parallel 1 \
&& ctest
&& ctest --output-on-failure

# STAGE 2: Setup
FROM $UBUNTU_BASE as final
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.sipi-dev-env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update \
rsync \
tar \
grep \
build-essential \
&& apt-get clean

# Set GCC 13 as the default gcc and g++
Expand Down
2 changes: 1 addition & 1 deletion include/SipiIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <string>
#include <stdexcept>

#include "SipiImage.h"
#include "../src/SipiImage.hpp"
#include "iiifparser/SipiRegion.h"
#include "iiifparser/SipiSize.h"

Expand Down
2 changes: 1 addition & 1 deletion include/formats/SipiIOJ2k.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "tiff.h"
#include "tiffio.h"

#include "SipiImage.h"
#include "../../src/SipiImage.hpp"
//#include "metadata/SipiExif.h"
#include "SipiIO.h"

Expand Down
2 changes: 1 addition & 1 deletion include/formats/SipiIOJpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <string>

#include "SipiImage.h"
#include "../../src/SipiImage.hpp"
#include "SipiIO.h"

namespace Sipi {
Expand Down
2 changes: 1 addition & 1 deletion include/formats/SipiIOPng.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <string>

#include "SipiImage.h"
#include "../../src/SipiImage.hpp"
#include "SipiIO.h"

namespace Sipi {
Expand Down
2 changes: 1 addition & 1 deletion include/formats/SipiIOTiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "tiff.h"
#include "tiffio.h"

#include "SipiImage.h"
#include "../../src/SipiImage.hpp"
//#include "metadata/SipiExif.h"
#include "SipiIO.h"

Expand Down
40 changes: 40 additions & 0 deletions nix-cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

# let's say you have a C++ project in Nix that you want to work on with CLion so that the Nix dependencies are available
# put this script in your project directory
# then, in Settings -> Build, Execution, Deployment -> Toolchains set CMake to this script
# if you need any extra nix-shell arguments, add them to the invocation at the bottom

import os
import sys
import shlex


def is_test_invocation(args):
# This function checks if the current invocation is for testing.
# You might check for specific CTest arguments or a pattern that matches your testing setup.
# For simplicity, this example looks for a '--test' flag which you might need to adjust
return '--test' in args or 'ctest' in args


scriptDir = os.path.dirname(os.path.realpath(__file__))

args = list(map(shlex.quote, sys.argv[1:]))

# Use the cmakeFlags set by Nix if not running --build or tests
if "--build" not in args and not is_test_invocation(args):
args.insert(0, "$cmakeFlags")

cwd = os.getcwd()
cmd = 'cd ' + cwd + ' && cmake ' + ' '.join(args)

if is_test_invocation(args):
# Modify cmd for test execution
# Here you might need to adjust the command to work with CTest specifically.
# This could involve using a different command or altering the existing one to suit test execution.
cmd = 'cd ' + cwd + ' && ctest ' + ' '.join(args) # Adjust this line as necessary

os.chdir(scriptDir)
os.execvp("nix", [
"nix", "develop", "--command", "bash", "-c", cmd
])
3 changes: 1 addition & 2 deletions shttps/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,7 @@ namespace shttps {


// Adds a route to the server. The route is a combination of an HTTP method, a path, and request handler.
void Server::add_route(Connection::HttpMethod method_p, const std::string &path_p, RequestHandler handler_p,
void *handler_data_p) {
void Server::add_route(Connection::HttpMethod method_p, const std::string &path_p, RequestHandler handler_p, void *handler_data_p) {
handler[method_p][path_p] = handler_p;
handler_data[method_p][path_p] = handler_data_p;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SipiCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

#include "SipiCache.h"
#include "shttps/Global.h"
#include "SipiError.h"
#include "SipiError.hpp"

static const char __file__[] = __FILE__;

Expand Down
8 changes: 4 additions & 4 deletions src/SipiError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
* You should have received a copy of the GNU Affero General Public
* License along with Sipi. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <sstream>


#include "SipiError.h"
#include "SipiError.hpp"

namespace Sipi {

Expand All @@ -39,7 +39,7 @@ namespace Sipi {
errno_p) {}
//============================================================================

std::string SipiError::to_string(void) const {
std::string SipiError::to_string() const {
std::ostringstream errStream;
errStream << "Sipi Error at [" << file << ": " << line << "]";
if (sysErrno != 0) errStream << " (system error: " << std::strerror(sysErrno) << ")";
Expand All @@ -49,7 +49,7 @@ namespace Sipi {
//============================================================================

std::ostream &operator<<(std::ostream &outStream, const SipiError &rhs) {
std::string errStr = rhs.to_string();
const std::string errStr = rhs.to_string();
outStream << errStr << std::endl; // TODO: remove the endl, the logging code should do it
return outStream;
}
Expand Down
Loading
Loading