Commit ab5bf362 authored by Sebastien Jodogne's avatar Sebastien Jodogne
Browse files

New upstream version 2.2

parent a34f6b17
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
repo: 1d7c4b96183115894767b40ed485045665f2c75c
node: 8994bbdbc6d09f0824f789bb02e3d5b1b44e60e2
branch: OrthancPostgreSQL-2.1
repo: 7cea966b682978aa285eb9b3a7a9cff81df464b3
node: 4b2dab49b6ea1f3369e769b0ce94e00c4ea32f1f
branch: OrthancPostgreSQL-2.2
latesttag: null
latesttagdistance: 166
changessincelatesttag: 178
latesttagdistance: 34
changessincelatesttag: 36

.hgignore

0 → 100644
+4 −0
Original line number Diff line number Diff line
build*
PostgreSQL/CMakeLists.txt.user
PostgreSQL/ThirdPartyDownloads/
+2 −2
Original line number Diff line number Diff line
PostgreSQL plugin for Orthanc
=============================
Database plugins for Orthanc
============================


Authors

CMakeLists.txt

deleted100644 → 0
+0 −184
Original line number Diff line number Diff line
# Orthanc - A Lightweight, RESTful DICOM Store
# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
# Department, University Hospital of Liege, Belgium
# Copyright (C) 2017-2018 Osimis S.A., Belgium
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


cmake_minimum_required(VERSION 2.8)

project(OrthancPostgreSQL)

set(ORTHANC_POSTGRESQL_VERSION "2.1")

if (ORTHANC_POSTGRESQL_VERSION STREQUAL "mainline")
  set(ORTHANC_FRAMEWORK_VERSION "mainline")
  set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
else()
  set(ORTHANC_FRAMEWORK_VERSION "1.3.2")
  set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
endif()


# Parameters of the build
set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
set(BUILD_UNIT_TESTS ON CACHE BOOL "Build UnitTests")
set(ORTHANC_FRAMEWORK_SOURCE "${ORTHANC_FRAMEWORK_DEFAULT_SOURCE}" CACHE STRING "Source of the Orthanc source code (can be \"hg\", \"archive\", \"web\" or \"path\")")
set(ORTHANC_FRAMEWORK_ARCHIVE "" CACHE STRING "Path to the Orthanc archive, if ORTHANC_FRAMEWORK_SOURCE is \"archive\"")
set(ORTHANC_FRAMEWORK_ROOT "" CACHE STRING "Path to the Orthanc source directory, if ORTHANC_FRAMEWORK_SOURCE is \"path\"")

# Advanced parameters to fine-tune linking against system libraries
set(USE_SYSTEM_LIBPQ ON CACHE BOOL "Use the system version of the PostgreSQL client library")
set(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK")


# Download and setup the Orthanc framework
include(${CMAKE_SOURCE_DIR}/Resources/Orthanc/DownloadOrthancFramework.cmake)

set(ORTHANC_FRAMEWORK_PLUGIN ON)
include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)

set(ENABLE_LOCALE OFF)         # Disable support for locales (notably in Boost)
set(ENABLE_GOOGLE_TEST ON)

include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkConfiguration.cmake)
include_directories(${ORTHANC_ROOT})


# The CMake script in "Graveyard" was used up to release 2.0. The new
# script makes auto-configuration of the variables.
include(${CMAKE_SOURCE_DIR}/Resources/CMake/PostgreSQLConfiguration.cmake)
#include(${CMAKE_SOURCE_DIR}/Resources/Graveyard/PostgreSQLConfiguration.cmake)


if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK)
  include_directories(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-0.9.5)
else ()
  CHECK_INCLUDE_FILE_CXX(orthanc/OrthancCppDatabasePlugin.h HAVE_ORTHANC_H)
  if (NOT HAVE_ORTHANC_H)
    message(FATAL_ERROR "Please install the headers of the Orthanc plugins SDK")
  endif()
endif()


if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  link_libraries(secur32)

  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py
    ${ORTHANC_POSTGRESQL_VERSION} "PostgreSQL storage plugin" OrthancPostgreSQLStorage.dll
    "PostgreSQL as a database back-end to Orthanc (storage area)"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/StorageVersion.rc
    )

  if (Failure)
    message(FATAL_ERROR "Error while computing the version information: ${Failure}")
  endif()

  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py
    ${ORTHANC_POSTGRESQL_VERSION} "PostgreSQL index plugin" OrthancPostgreSQLIndex.dll
    "PostgreSQL as a database back-end to Orthanc (index area)"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/IndexVersion.rc
    )

  if (Failure)
    message(FATAL_ERROR "Error while computing the version information: ${Failure}")
  endif()

  set(INDEX_RESOURCES ${AUTOGENERATED_DIR}/IndexVersion.rc)
  set(STORAGE_RESOURCES ${AUTOGENERATED_DIR}/StorageVersion.rc)
endif()



# Embed the SQL files into the binaries
EmbedResources(
  --system-exception 
  --namespace=OrthancPlugins
  POSTGRESQL_PREPARE ${CMAKE_CURRENT_SOURCE_DIR}/IndexPlugin/PostgreSQLPrepare.sql
  POSTGRESQL_PREPARE_V5 ${CMAKE_CURRENT_SOURCE_DIR}/IndexPlugin/PostgreSQLVersion5.sql
  POSTGRESQL_PREPARE_V6 ${CMAKE_CURRENT_SOURCE_DIR}/IndexPlugin/PostgreSQLVersion6.sql
  )

set(CORE_SOURCES
  ${CMAKE_SOURCE_DIR}/Core/PostgreSQLConnection.cpp
  ${CMAKE_SOURCE_DIR}/Core/PostgreSQLLargeObject.cpp
  ${CMAKE_SOURCE_DIR}/Core/PostgreSQLResult.cpp
  ${CMAKE_SOURCE_DIR}/Core/PostgreSQLStatement.cpp
  ${CMAKE_SOURCE_DIR}/Core/PostgreSQLTransaction.cpp
  ${CMAKE_SOURCE_DIR}/Core/Configuration.cpp
  ${CMAKE_SOURCE_DIR}/Core/GlobalProperties.cpp
  ${AUTOGENERATED_DIR}/EmbeddedResources.cpp

  ${ORTHANC_CORE_SOURCES}
  ${LIBPQ_SOURCES}
  )

add_library(OrthancPostgreSQLStorage
  SHARED
  ${CORE_SOURCES}
  ${CMAKE_SOURCE_DIR}/StoragePlugin/PostgreSQLStorageArea.cpp
  ${CMAKE_SOURCE_DIR}/StoragePlugin/Plugin.cpp
  ${STORAGE_RESOURCES}
  )

add_library(OrthancPostgreSQLIndex
  SHARED
  ${CORE_SOURCES}
  ${CMAKE_SOURCE_DIR}/IndexPlugin/PostgreSQLWrapper.cpp
  ${CMAKE_SOURCE_DIR}/IndexPlugin/Plugin.cpp
  ${INDEX_RESOURCES}
  )


message("Setting the version of the libraries to ${ORTHANC_POSTGRESQL_VERSION}")

add_definitions(-DORTHANC_POSTGRESQL_VERSION="${ORTHANC_POSTGRESQL_VERSION}")

set_target_properties(OrthancPostgreSQLStorage PROPERTIES 
  VERSION ${ORTHANC_POSTGRESQL_VERSION} 
  SOVERSION ${ORTHANC_POSTGRESQL_VERSION}
  )

set_target_properties(OrthancPostgreSQLIndex PROPERTIES 
  VERSION ${ORTHANC_POSTGRESQL_VERSION} 
  SOVERSION ${ORTHANC_POSTGRESQL_VERSION}
  )

install(
  TARGETS OrthancPostgreSQLStorage OrthancPostgreSQLIndex
  RUNTIME DESTINATION lib    # Destination for Windows
  LIBRARY DESTINATION share/orthanc/plugins    # Destination for Linux
  )

if (BUILD_UNIT_TESTS)
  add_executable(UnitTests
    ${CORE_SOURCES}
    ${CMAKE_SOURCE_DIR}/IndexPlugin/PostgreSQLWrapper.cpp
    ${CMAKE_SOURCE_DIR}/StoragePlugin/PostgreSQLStorageArea.cpp
    ${CMAKE_SOURCE_DIR}/UnitTestsSources/UnitTestsMain.cpp
    ${CMAKE_SOURCE_DIR}/UnitTestsSources/PostgreSQLTests.cpp
    ${CMAKE_SOURCE_DIR}/UnitTestsSources/PostgreSQLWrapperTests.cpp
    ${GOOGLE_TEST_SOURCES}
    )

  target_link_libraries(UnitTests ${GOOGLE_TEST_LIBRARIES})
endif()

Core/Configuration.cpp

deleted100644 → 0
+0 −203
Original line number Diff line number Diff line
/**
 * Orthanc - A Lightweight, RESTful DICOM Store
 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
 * Department, University Hospital of Liege, Belgium
 * Copyright (C) 2017-2018 Osimis S.A., Belgium
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 **/


#include "Configuration.h"

#include "PostgreSQLException.h"

#include <fstream>
#include <json/reader.h>
#include <memory>


// For UUID generation
extern "C"
{
#ifdef WIN32
#include <rpc.h>
#else
#include <uuid/uuid.h>
#endif
}


namespace OrthancPlugins
{
  bool ReadConfiguration(Json::Value& configuration,
                         OrthancPluginContext* context)
  {
    std::string s;

    {
      char* tmp = OrthancPluginGetConfiguration(context);
      if (tmp == NULL)
      {
        OrthancPluginLogError(context, "Error while retrieving the configuration from Orthanc");
        return false;
      }

      s.assign(tmp);
      OrthancPluginFreeString(context, tmp);      
    }

    Json::Reader reader;
    if (reader.parse(s, configuration))
    {
      return true;
    }
    else
    {
      OrthancPluginLogError(context, "Unable to parse the configuration");
      return false;
    }
  }


  std::string GetStringValue(const Json::Value& configuration,
                             const std::string& key,
                             const std::string& defaultValue)
  {
    if (configuration.type() != Json::objectValue ||
        !configuration.isMember(key) ||
        configuration[key].type() != Json::stringValue)
    {
      return defaultValue;
    }
    else
    {
      return configuration[key].asString();
    }
  }


  int GetIntegerValue(const Json::Value& configuration,
                      const std::string& key,
                      int defaultValue)
  {
    if (configuration.type() != Json::objectValue ||
        !configuration.isMember(key) ||
        configuration[key].type() != Json::intValue)
    {
      return defaultValue;
    }
    else
    {
      return configuration[key].asInt();
    }
  }


  bool GetBooleanValue(const Json::Value& configuration,
                       const std::string& key,
                       bool defaultValue)
  {
    if (configuration.type() != Json::objectValue ||
        !configuration.isMember(key) ||
        configuration[key].type() != Json::booleanValue)
    {
      return defaultValue;
    }
    else
    {
      return configuration[key].asBool();
    }
  }


  PostgreSQLConnection* CreateConnection(bool& useLock,
                                         OrthancPluginContext* context,
                                         const Json::Value& configuration)
  {
    useLock = true;  // Use locking by default
    std::auto_ptr<PostgreSQLConnection> connection(new PostgreSQLConnection);

    if (configuration.isMember("PostgreSQL"))
    {
      Json::Value c = configuration["PostgreSQL"];
      if (c.isMember("ConnectionUri"))
      {
        connection->SetConnectionUri(c["ConnectionUri"].asString());
      }
      else
      {
        connection->SetHost(GetStringValue(c, "Host", "localhost"));
        connection->SetPortNumber(GetIntegerValue(c, "Port", 5432));
        connection->SetDatabase(GetStringValue(c, "Database", "orthanc"));
        connection->SetUsername(GetStringValue(c, "Username", "orthanc"));
        connection->SetPassword(GetStringValue(c, "Password", "orthanc"));
      }

      useLock = GetBooleanValue(c, "Lock", useLock);
    }

    if (!useLock)
    {
      OrthancPluginLogWarning(context, "Locking of the PostgreSQL database is disabled");
    }

    connection->Open();

    return connection.release();
  }


  std::string GenerateUuid()
  {
#ifdef WIN32
    UUID uuid;
    UuidCreate ( &uuid );

    unsigned char * str;
    UuidToStringA ( &uuid, &str );

    std::string s( ( char* ) str );

    RpcStringFreeA ( &str );
#else
    uuid_t uuid;
    uuid_generate_random ( uuid );
    char s[37];
    uuid_unparse ( uuid, s );
#endif
    return s;
  }


  bool IsFlagInCommandLineArguments(OrthancPluginContext* context,
                                    const std::string& flag)
  {
    uint32_t count = OrthancPluginGetCommandLineArgumentsCount(context);

    for (uint32_t i = 0; i < count; i++)
    {
      char* tmp = OrthancPluginGetCommandLineArgument(context, i);
      std::string arg(tmp);
      OrthancPluginFreeString(context, tmp);

      if (arg == flag)
      {
        return true;
      }
    }

    return false;
  }
}
Loading