view Resources/CMake/MongooseConfiguration.cmake @ 2248:69b0f4e8a49b

Escape multipart type parameter value in Content-Type header ## Summary Multipart responses do not quote/escape the value of their type parameter (the subtype) even though it always contains at least one special character (the slash "/"), which confuses standard-compliant HTTP clients. ## Details The Content-Type header in HTTP is in RFC 7231, Section 3.1.1.5: https://tools.ietf.org/html/rfc7231#section-3.1.1.5 The section defers to the media type section (3.1.1.1) for the syntax of the media type: https://tools.ietf.org/html/rfc7231#section-3.1.1.1 This states that a parameter value can be quoted: parameter = token "=" ( token / quoted-string ) A parameter value that matches the token production can be transmitted either as a token or within a quoted-string. The quoted and unquoted values are equivalent. Tokens are defined in RFC 7230, Section 3.2.6 (via RFC 7231, appendix C): https://tools.ietf.org/html/rfc7231#appendix-C https://tools.ietf.org/html/rfc7230#section-3.2.6 Here we observe that tokens cannot contain a slash "/" character: token = 1*tchar tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA ; any VCHAR, except delimiters Delimiters are chosen from the set of US-ASCII visual characters not allowed in a token (DQUOTE and "(),/:;<=>?@[\]{}"). However, the current implementation does not quote/escape the value of the type parameter: multipart/related; type=application/dicom Instead, it should be: multipart/related; type="application/dicom" All of this also seems to apply to the MIME Content-Type header definition, even though it is a little different: https://www.iana.org/assignments/message-headers https://tools.ietf.org/html/rfc2045#section-5.1 https://tools.ietf.org/html/rfc2387
author Thibault Nélis <tn@osimis.io>
date Mon, 16 Jan 2017 13:07:11 +0100
parents 8b51b133bb8b
children 741bb76634d3
line wrap: on
line source

if (STATIC_BUILD OR NOT USE_SYSTEM_MONGOOSE)
  SET(MONGOOSE_SOURCES_DIR ${CMAKE_BINARY_DIR}/mongoose)

  if (IS_DIRECTORY "${MONGOOSE_SOURCES_DIR}")
    set(FirstRun OFF)
  else()
    set(FirstRun ON)
  endif()

  if (0)
    # Use Mongoose 3.1
    DownloadPackage(
      "e718fc287b4eb1bd523be3fa00942bb0"
      "http://www.orthanc-server.com/downloads/third-party/mongoose-3.1.tgz"
      "${MONGOOSE_SOURCES_DIR}")
    
    add_definitions(-DMONGOOSE_USE_CALLBACKS=0)
    set(MONGOOSE_PATCH ${ORTHANC_ROOT}/Resources/Patches/mongoose-3.1-patch.diff)

  else() 
    # Use Mongoose 3.8
    DownloadPackage(
      "7e3296295072792cdc3c633f9404e0c3"
      "http://www.orthanc-server.com/downloads/third-party/mongoose-3.8.tgz"
      "${MONGOOSE_SOURCES_DIR}")
    
    add_definitions(-DMONGOOSE_USE_CALLBACKS=1)
    set(MONGOOSE_PATCH ${ORTHANC_ROOT}/Resources/Patches/mongoose-3.8-patch.diff)
  endif()

  # Patch mongoose
  execute_process(
    COMMAND ${PATCH_EXECUTABLE} -N mongoose.c 
    INPUT_FILE ${MONGOOSE_PATCH}
    WORKING_DIRECTORY ${MONGOOSE_SOURCES_DIR}
    RESULT_VARIABLE Failure
    )

  if (Failure AND FirstRun)
    message(FATAL_ERROR "Error while patching a file")
  endif()

  include_directories(
    ${MONGOOSE_SOURCES_DIR}
    )

  set(MONGOOSE_SOURCES
    ${MONGOOSE_SOURCES_DIR}/mongoose.c
    )


  if (ENABLE_SSL)
    add_definitions(
      -DNO_SSL_DL=1
      )
    if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
        ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
      link_libraries(dl)
    endif()

  else()
    add_definitions(
      -DNO_SSL=1   # Remove SSL support from mongoose
      )
  endif()


  if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
    if (CMAKE_COMPILER_IS_GNUCXX)
      # This is a patch for MinGW64
      add_definitions(-D_TIMESPEC_DEFINED=1)
    endif()
  endif()

  source_group(ThirdParty\\Mongoose REGULAR_EXPRESSION ${MONGOOSE_SOURCES_DIR}/.*)

else()
  CHECK_INCLUDE_FILE_CXX(mongoose.h HAVE_MONGOOSE_H)
  if (NOT HAVE_MONGOOSE_H)
    message(FATAL_ERROR "Please install the mongoose-devel package")
  endif()

  CHECK_LIBRARY_EXISTS(mongoose mg_start "" HAVE_MONGOOSE_LIB)
  if (NOT HAVE_MONGOOSE_LIB)
    message(FATAL_ERROR "Please install the mongoose-devel package")
  endif()

  if (SYSTEM_MONGOOSE_USE_CALLBACKS)
    add_definitions(-DMONGOOSE_USE_CALLBACKS=1)
  else()
    add_definitions(-DMONGOOSE_USE_CALLBACKS=0)
  endif()

  link_libraries(mongoose)
endif()