indi-starbook-ten-0.1/0000755000175100017510000000000014153174377014147 5ustar debiandebianindi-starbook-ten-0.1/indi_starbook_ten.xml.cmake0000644000175100017510000000053014136175546021443 0ustar debiandebian indi_starbook_ten @STARBOOK_TEN_VERSION_MAJOR@.@STARBOOK_TEN_VERSION_MINOR@ indi-starbook-ten-0.1/README0000644000175100017510000000034314136175546015027 0ustar debiandebianVixen Starbook Ten INDI Driver ================== This package provides the INDI driver for Vixen Starbook Ten (Firmware >= 5.10) Requirements ============ + libindi + libnova Installation ============ See INSTALL indi-starbook-ten-0.1/indi-3rdparty-infos/0000755000175100017510000000000014153174377017754 5ustar debiandebianindi-starbook-ten-0.1/indi-3rdparty-infos/changelog0000644000175100017510000000023114136175546021622 0ustar debiandebianindi-starbook-ten (0.1) unstable; urgency=medium * First upstream version. -- Alex Hornung Sat, 15 May 2021 15:03:25 +0100 indi-starbook-ten-0.1/indi-starbook-ten.spec0000644000175100017510000000274514152245133020350 0ustar debiandebian%define __cmake_in_source_build %{_vpath_builddir} Name: indi-starbook-ten Version:1.9.4.git Release: %(date -u +%%Y%%m%%d%%H%%M%%S)%{?dist} Summary: Instrument Neutral Distributed Interface 3rd party drivers License: LGPLv2 # See COPYRIGHT file for a description of the licenses and files covered URL: https://indilib.org Source0: https://github.com/indilib/indi-3rdparty/archive/master.tar.gz BuildRequires: cmake BuildRequires: libnova-devel BuildRequires: indi-libs BuildRequires: indi-devel %description INDI is a distributed control protocol designed to operate astronomical instrumentation. INDI is small, flexible, easy to parse, and scalable. It supports common DCS functions such as remote control, data acquisition, monitoring, and a lot more. This is a 3rd party driver. %prep -v %setup -n %{name}-%{version} %build # This package tries to mix and match PIE and PIC which is wrong and will # trigger link errors when LTO is enabled. # Disable LTO %define _lto_cflags %{nil} cd indi-starbook-ten %cmake . make VERBOSE=1 %{?_smp_mflags} -j4 %install cd indi-starbook-ten make DESTDIR=%{buildroot} install %files %license indi-starbook-ten/COPYING indi-starbook-ten/COPYING.LESSER indi-starbook-ten/COPYRIGHT %doc indi-starbook-ten/AUTHORS indi-starbook-ten/README %{_bindir}/* %{_datadir}/indi %changelog * Sun Jul 19 2020 Jim Howard 1.8.7.git-1 - update to build from git for copr, credit to Sergio Pascual and Christian Dersch for prior work on spec files indi-starbook-ten-0.1/cmake_modules/0000755000175100017510000000000014136175546016757 5ustar debiandebianindi-starbook-ten-0.1/cmake_modules/FindGPSD.cmake0000644000175100017510000000103614136175546021317 0ustar debiandebian# - Find GPSD # Find the native GPSD includes and library FIND_PATH(GPSD_INCLUDE_DIR libgpsmm.h gps.h) SET(GPSD_NAMES ${GPSD_NAMES} gps) FIND_LIBRARY(GPSD_LIBRARY NAMES ${GPSD_NAMES} ) # handle the QUIETLY and REQUIRED arguments and set JPEG_FOUND to TRUE if # all listed variables are TRUE INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GPSD DEFAULT_MSG GPSD_LIBRARY GPSD_INCLUDE_DIR) IF(GPSD_FOUND) SET(GPSD_LIBRARIES ${GPSD_LIBRARY}) message(STATUS "Found libgps: ${GPSD_LIBRARIES}") ENDIF(GPSD_FOUND) indi-starbook-ten-0.1/cmake_modules/FindFTDI1.cmake0000644000175100017510000000267214136175546021400 0ustar debiandebian# - Try to find FTDI1 # Once done this will define # # FTDI1_FOUND - system has FTDI # FTDI1_INCLUDE_DIR - the FTDI include directory # FTDI1_LIBRARIES - Link these to use FTDI # # N.B. You must include the file as following: # #include # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (FTDI1_INCLUDE_DIR AND FTDI1_LIBRARIES) # in cache already set(FTDI1_FOUND TRUE) message(STATUS "Found libftdi1: ${FTDI1_LIBRARIES}") else (FTDI1_INCLUDE_DIR AND FTDI1_LIBRARIES) find_path(FTDI1_INCLUDE_DIR ftdi.h PATH_SUFFIXES libftdi1 ${_obIncDir} ${GNUWIN32_DIR}/include /usr/local/include ) find_library(FTDI1_LIBRARIES NAMES ftdi1 PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib /usr/local/lib ) if(FTDI1_INCLUDE_DIR AND FTDI1_LIBRARIES) set(FTDI1_FOUND TRUE) else (FTDI1_INCLUDE_DIR AND FTDI1_LIBRARIES) set(FTDI1_FOUND FALSE) endif(FTDI1_INCLUDE_DIR AND FTDI1_LIBRARIES) if (FTDI1_FOUND) if (NOT FTDI1_FIND_QUIETLY) message(STATUS "Found FTDI1: ${FTDI1_LIBRARIES}") endif (NOT FTDI1_FIND_QUIETLY) else (FTDI1_FOUND) if (FTDI1_FIND_REQUIRED) message(FATAL_ERROR "FTDI not found. Please install libftdi1-dev") endif (FTDI1_FIND_REQUIRED) endif (FTDI1_FOUND) mark_as_advanced(FTDI1_INCLUDE_DIR FTDI1_LIBRARIES) endif (FTDI1_INCLUDE_DIR AND FTDI1_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindOpenAL.cmake0000644000175100017510000000660414136175546021706 0ustar debiandebian# Locate OpenAL # This module defines # OPENAL_LIBRARY # OPENAL_FOUND, if false, do not try to link to OpenAL # OPENAL_INCLUDE_DIR, where to find the headers # # $OPENALDIR is an environment variable that would # correspond to the ./configure --prefix=$OPENALDIR # used in building OpenAL. # # Created by Eric Wing. This was influenced by the FindSDL.cmake module. # This makes the presumption that you are include al.h like # #include "al.h" # and not # #include # The reason for this is that the latter is not entirely portable. # Windows/Creative Labs does not by default put their headers in AL/ and # OS X uses the convention . # # For Windows, Creative Labs seems to have added a registry key for their # OpenAL 1.1 installer. I have added that key to the list of search paths, # however, the key looks like it could be a little fragile depending on # if they decide to change the 1.00.0000 number for bug fix releases. # Also, they seem to have laid down groundwork for multiple library platforms # which puts the library in an extra subdirectory. Currently there is only # Win32 and I have hardcoded that here. This may need to be adjusted as # platforms are introduced. # The OpenAL 1.0 installer doesn't seem to have a useful key I can use. # I do not know if the Nvidia OpenAL SDK has a registry key. # # For OS X, remember that OpenAL was added by Apple in 10.4 (Tiger). # To support the framework, I originally wrote special framework detection # code in this module which I have now removed with CMake's introduction # of native support for frameworks. # In addition, OpenAL is open source, and it is possible to compile on Panther. # Furthermore, due to bugs in the initial OpenAL release, and the # transition to OpenAL 1.1, it is common to need to override the built-in # framework. # Per my request, CMake should search for frameworks first in # the following order: # ~/Library/Frameworks/OpenAL.framework/Headers # /Library/Frameworks/OpenAL.framework/Headers # /System/Library/Frameworks/OpenAL.framework/Headers # # On OS X, this will prefer the Framework version (if found) over others. # People will have to manually change the cache values of # OPENAL_LIBRARY to override this selection or set the CMake environment # CMAKE_INCLUDE_PATH to modify the search paths. FIND_PATH(OPENAL_INCLUDE_DIR al.h PATHS $ENV{OPENALDIR} NO_DEFAULT_PATH PATH_SUFFIXES include/AL include/OpenAL include ) FIND_PATH(OPENAL_INCLUDE_DIR al.h PATHS ~/Library/Frameworks /Library/Frameworks /usr/local /usr /sw # Fink /opt/local # DarwinPorts /opt/csw # Blastwave /opt [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] PATH_SUFFIXES include/AL include/OpenAL include ) FIND_LIBRARY(OPENAL_LIBRARY NAMES OpenAL al openal OpenAL32 PATHS $ENV{OPENALDIR} NO_DEFAULT_PATH PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 ) FIND_LIBRARY(OPENAL_LIBRARY NAMES OpenAL al openal OpenAL32 PATHS ~/Library/Frameworks /Library/Frameworks /usr/local /usr /sw /opt/local /opt/csw /opt [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 ) SET(OPENAL_FOUND "NO") IF(OPENAL_LIBRARY AND OPENAL_INCLUDE_DIR) SET(OPENAL_FOUND "YES") ENDIF(OPENAL_LIBRARY AND OPENAL_INCLUDE_DIR) indi-starbook-ten-0.1/cmake_modules/FindFFTW3.cmake0000644000175100017510000000257314136175546021422 0ustar debiandebian# - Try to find FFTW3 # Once done this will define # # FFTW3_FOUND - system has FFTW3 # FFTW3_INCLUDE_DIR - the FFTW3 include directory # FFTW3_LIBRARIES - Link these to use FFTW3 # FFTW3_VERSION_STRING - Human readable version number of fftw3 # FFTW3_VERSION_MAJOR - Major version number of fftw3 # FFTW3_VERSION_MINOR - Minor version number of fftw3 # Copyright (c) 2017, Ilia Platone, # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (FFTW3_LIBRARIES) # in cache already set(FFTW3_FOUND TRUE) message(STATUS "Found FFTW3: ${FFTW3_LIBRARIES}") else (FFTW3_LIBRARIES) find_library(FFTW3_LIBRARIES NAMES fftw3 PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib /usr/local/lib ) if(FFTW3_LIBRARIES) set(FFTW3_FOUND TRUE) else (FFTW3_LIBRARIES) set(FFTW3_FOUND FALSE) endif(FFTW3_LIBRARIES) if (FFTW3_FOUND) if (NOT FFTW3_FIND_QUIETLY) message(STATUS "Found FFTW3: ${FFTW3_LIBRARIES}") endif (NOT FFTW3_FIND_QUIETLY) else (FFTW3_FOUND) if (FFTW3_FIND_REQUIRED) message(FATAL_ERROR "FFTW3 not found. Please install libfftw3-dev") endif (FFTW3_FIND_REQUIRED) endif (FFTW3_FOUND) mark_as_advanced(FFTW3_LIBRARIES) endif (FFTW3_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindMALLINCAM.cmake0000644000175100017510000000301314136175546022054 0ustar debiandebian# - Try to find MALLINCAM Camera Library # Once done this will define # # MALLINCAM_FOUND - system has Levenhuk # MALLINCAM_INCLUDE_DIR - the Levenhuk include directory # MALLINCAM_LIBRARIES - Link these to use Levenhuk # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (MALLINCAM_INCLUDE_DIR AND MALLINCAM_LIBRARIES) # in cache already set(MALLINCAM_FOUND TRUE) message(STATUS "Found libnncam: ${MALLINCAM_LIBRARIES}") else (MALLINCAM_INCLUDE_DIR AND MALLINCAM_LIBRARIES) find_path(MALLINCAM_INCLUDE_DIR mallincam.h PATH_SUFFIXES libmallincam ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(MALLINCAM_LIBRARIES NAMES mallincam PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(MALLINCAM_INCLUDE_DIR AND MALLINCAM_LIBRARIES) set(MALLINCAM_FOUND TRUE) else (MALLINCAM_INCLUDE_DIR AND MALLINCAM_LIBRARIES) set(MALLINCAM_FOUND FALSE) endif(MALLINCAM_INCLUDE_DIR AND MALLINCAM_LIBRARIES) if (MALLINCAM_FOUND) if (NOT MALLINCAM_FIND_QUIETLY) message(STATUS "Found MALLINCAM: ${MALLINCAM_LIBRARIES}") endif (NOT MALLINCAM_FIND_QUIETLY) else (MALLINCAM_FOUND) if (MALLINCAM_FIND_REQUIRED) message(FATAL_ERROR "MALLINCAM not found. Please install MALLINCAM Library http://www.indilib.org") endif (MALLINCAM_FIND_REQUIRED) endif (MALLINCAM_FOUND) mark_as_advanced(MALLINCAM_INCLUDE_DIR MALLINCAM_LIBRARIES) endif (MALLINCAM_INCLUDE_DIR AND MALLINCAM_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindNova.cmake0000644000175100017510000000304614136175546021470 0ustar debiandebian# - Try to find NOVA # Once done this will define # # NOVA_FOUND - system has NOVA # NOVA_INCLUDE_DIR - the NOVA include directory # NOVA_LIBRARIES - Link these to use NOVA # Copyright (c) 2006, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (NOVA_INCLUDE_DIR AND NOVA_LIBRARIES) # in cache already set(NOVA_FOUND TRUE) message(STATUS "Found libnova: ${NOVA_LIBRARIES}") else (NOVA_INCLUDE_DIR AND NOVA_LIBRARIES) find_path(NOVA_INCLUDE_DIR libnova.h PATH_SUFFIXES libnova ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(NOVA_LIBRARIES NAMES nova libnova libnovad PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) set(CMAKE_REQUIRED_INCLUDES ${NOVA_INCLUDE_DIR}) set(CMAKE_REQUIRED_LIBRARIES ${NOVA_LIBRARIES}) if(NOVA_INCLUDE_DIR AND NOVA_LIBRARIES) set(NOVA_FOUND TRUE) else (NOVA_INCLUDE_DIR AND NOVA_LIBRARIES) set(NOVA_FOUND FALSE) endif(NOVA_INCLUDE_DIR AND NOVA_LIBRARIES) if (NOVA_FOUND) if (NOT Nova_FIND_QUIETLY) message(STATUS "Found NOVA: ${NOVA_LIBRARIES}") endif (NOT Nova_FIND_QUIETLY) else (NOVA_FOUND) if (Nova_FIND_REQUIRED) message(FATAL_ERROR "libnova not found. Please install libnova development package.") endif (Nova_FIND_REQUIRED) endif (NOVA_FOUND) mark_as_advanced(NOVA_INCLUDE_DIR NOVA_LIBRARIES) endif (NOVA_INCLUDE_DIR AND NOVA_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindVorbis.cmake0000644000175100017510000000204414136175546022026 0ustar debiandebian# - Find vorbis # Find the native vorbis includes and libraries # # VORBIS_INCLUDE_DIR - where to find vorbis.h, etc. # VORBIS_LIBRARIES - List of libraries when using vorbis(file). # VORBIS_FOUND - True if vorbis found. if(VORBIS_INCLUDE_DIR) # Already in cache, be silent set(VORBIS_FIND_QUIETLY TRUE) endif(VORBIS_INCLUDE_DIR) find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h) find_library(OGG_LIBRARY NAMES ogg) find_library(VORBIS_LIBRARY NAMES vorbis) find_library(VORBISFILE_LIBRARY NAMES vorbisfile) # Handle the QUIETLY and REQUIRED arguments and set VORBIS_FOUND to TRUE if # all listed variables are TRUE. include(FindPackageHandleStandardArgs) find_package_handle_standard_args(VORBIS DEFAULT_MSG VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBIS_LIBRARY) if(VORBIS_FOUND) set(VORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) else(VORBIS_FOUND) set(VORBIS_LIBRARIES) endif(VORBIS_FOUND) mark_as_advanced(VORBIS_INCLUDE_DIR) mark_as_advanced(OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY) indi-starbook-ten-0.1/cmake_modules/FindJPEG.cmake0000644000175100017510000000166314136175546021315 0ustar debiandebian# - Find JPEG # Find the native JPEG includes and library # This module defines # JPEG_INCLUDE_DIR, where to find jpeglib.h, etc. # JPEG_LIBRARIES, the libraries needed to use JPEG. # JPEG_FOUND, If false, do not try to use JPEG. # also defined, but not for general use are # JPEG_LIBRARY, where to find the JPEG library. FIND_PATH(JPEG_INCLUDE_DIR jpeglib.h) SET(JPEG_NAMES ${JPEG_NAMES} jpeg) FIND_LIBRARY(JPEG_LIBRARY NAMES ${JPEG_NAMES} ) # handle the QUIETLY and REQUIRED arguments and set JPEG_FOUND to TRUE if # all listed variables are TRUE INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(JPEG DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR) IF(JPEG_FOUND) SET(JPEG_LIBRARIES ${JPEG_LIBRARY}) ENDIF(JPEG_FOUND) # Deprecated declarations. SET (NATIVE_JPEG_INCLUDE_PATH ${JPEG_INCLUDE_DIR} ) GET_FILENAME_COMPONENT (NATIVE_JPEG_LIB_PATH ${JPEG_LIBRARY} PATH) MARK_AS_ADVANCED(JPEG_LIBRARY JPEG_INCLUDE_DIR ) indi-starbook-ten-0.1/cmake_modules/FindCFITSIO.cmake0000644000175100017510000000434614136175546021671 0ustar debiandebian# - Try to find CFITSIO # Once done this will define # # CFITSIO_FOUND - system has CFITSIO # CFITSIO_INCLUDE_DIR - the CFITSIO include directory # CFITSIO_LIBRARIES - Link these to use CFITSIO # CFITSIO_VERSION_STRING - Human readable version number of cfitsio # CFITSIO_VERSION_MAJOR - Major version number of cfitsio # CFITSIO_VERSION_MINOR - Minor version number of cfitsio # Copyright (c) 2006, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES) # in cache already set(CFITSIO_FOUND TRUE) message(STATUS "Found CFITSIO: ${CFITSIO_LIBRARIES}") else (CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES) # JM: Packages from different distributions have different suffixes find_path(CFITSIO_INCLUDE_DIR fitsio.h PATH_SUFFIXES libcfitsio3 libcfitsio0 cfitsio ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(CFITSIO_LIBRARIES NAMES cfitsio PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES) set(CFITSIO_FOUND TRUE) else (CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES) set(CFITSIO_FOUND FALSE) endif(CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES) if (CFITSIO_FOUND) # Find the version of the cfitsio header file(STRINGS ${CFITSIO_INCLUDE_DIR}/fitsio.h CFITSIO_VERSION_STRING LIMIT_COUNT 1 REGEX "CFITSIO_VERSION") STRING(REGEX REPLACE "[^0-9.]" "" CFITSIO_VERSION_STRING ${CFITSIO_VERSION_STRING}) STRING(REGEX REPLACE "^([0-9]+)[.]([0-9]+)" "\\1" CFITSIO_VERSION_MAJOR ${CFITSIO_VERSION_STRING}) STRING(REGEX REPLACE "^([0-9]+)[.]([0-9]+)" "\\2" CFITSIO_VERSION_MINOR ${CFITSIO_VERSION_STRING}) if (NOT CFITSIO_FIND_QUIETLY) message(STATUS "Found CFITSIO ${CFITSIO_VERSION_STRING}: ${CFITSIO_LIBRARIES}") endif (NOT CFITSIO_FIND_QUIETLY) else (CFITSIO_FOUND) if (CFITSIO_FIND_REQUIRED) message(STATUS "CFITSIO not found.") endif (CFITSIO_FIND_REQUIRED) endif (CFITSIO_FOUND) mark_as_advanced(CFITSIO_INCLUDE_DIR CFITSIO_LIBRARIES) endif (CFITSIO_INCLUDE_DIR AND CFITSIO_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindUSB1.cmake0000644000175100017510000000562314136175546021302 0ustar debiandebian# - Try to find libusb-1.0 # Once done this will define # # USB1_FOUND - system has libusb-1.0 # USB1_INCLUDE_DIRS - the libusb-1.0 include directories # USB1_LIBRARIES - Link these to use libusb-1.0 # USB1_DEFINITIONS - Compiler switches required for using libusb-1.0 # # USB1_HAS_LIBUSB_ERROR_NAME - defined when libusb-1.0 has libusb_error_name() #============================================================================= # Copyright (c) 2017 Pino Toscano # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. #============================================================================= find_package(PkgConfig) pkg_check_modules(PC_LIBUSB1 QUIET libusb-1.0) find_path(USB1_INCLUDE_DIR NAMES libusb.h HINTS ${PC_LIBUSB1_INCLUDE_DIRS} PATH_SUFFIXES libusb-1.0 ) find_library(USB1_LIBRARY NAMES ${PC_LIBUSB1_LIBRARIES} usb-1.0 HINTS ${PC_LIBUSB1_LIBRARY_DIRS} ) set(USB1_INCLUDE_DIRS ${USB1_INCLUDE_DIR}) set(USB1_LIBRARIES ${USB1_LIBRARY}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(USB1 FOUND_VAR USB1_FOUND REQUIRED_VARS USB1_LIBRARY USB1_INCLUDE_DIR VERSION_VAR PC_LIBUSB1_VERSION ) mark_as_advanced(USB1_INCLUDE_DIRS USB1_LIBRARIES) if(USB1_FOUND) include(CheckCXXSourceCompiles) include(CMakePushCheckState) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_INCLUDES ${USB1_INCLUDE_DIRS}) set(CMAKE_REQUIRED_LIBRARIES ${USB1_LIBRARIES}) check_cxx_source_compiles("#include int main() { libusb_error_name(0); return 0; }" USB1_HAS_LIBUSB_ERROR_NAME) cmake_pop_check_state() endif() indi-starbook-ten-0.1/cmake_modules/FindGMock.cmake0000644000175100017510000001162314136175546021565 0ustar debiandebian#.rst: # FindGMock # --------- # # Locate the Google C++ Mocking Framework. # # Defines the following variables: # # :: # # GMOCK_FOUND - Found the Google Mocking framework # GMOCK_INCLUDE_DIRS - Include directories # # # # Also defines the library variables below as normal variables. These # contain debug/optimized keywords when a debugging library is found. # # :: # # GMOCK_LIBRARIES - libgmock # # # # Accepts the following variables as input: # # :: # # GMOCK_ROOT - (as a CMake or environment variable) # The root directory of the gmock install prefix # # # # :: # # GMOCK_MSVC_SEARCH - If compiling with MSVC, this variable can be set to # "MD" or "MT" to enable searching a GMock build tree # (defaults: "MD") # # # # Example Usage: # # :: # # find_package(GMock REQUIRED) # include_directories(${GMOCK_INCLUDE_DIRS}) # # # # :: # # add_executable(foo foo.cc) # target_link_libraries(foo ${GMOCK_LIBRARIES}) # # # # :: # # add_test(AllMocksInFoo foo) # # # # # # If you would like each Google test to show up in CMock as a test you # may use the following macro. NOTE: It will slow down your tests by # running an executable for each test and test fixture. You will also # have to rerun CMake after adding or removing tests or test fixtures. # # GMOCK_ADD_MOCKS(executable extra_args ARGN) # # :: # # executable = The path to the test executable # extra_args = Pass a list of extra arguments to be passed to # executable enclosed in quotes (or "" for none) # ARGN = A list of source files to search for tests & test # fixtures. # # # # :: # # Example: # set(FooMockArgs --foo 1 --bar 2) # add_executable(FooMock FooUnitMock.cc) # GMOCK_ADD_MOCKS(FooMock "${FooMockArgs}" FooUnitMock.cc) #============================================================================= # Copyright 2009 Kitware, Inc. # Copyright 2009 Philip Lowman # Copyright 2009 Daniel Blezek # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) # # Thanks to Daniel Blezek for the GMOCK_ADD_MOCKS code function(GMOCK_ADD_MOCKS executable extra_args) if(NOT ARGN) message(FATAL_ERROR "Missing ARGN: Read the documentation for GMOCK_ADD_MOCKS") endif() foreach(source ${ARGN}) file(READ "${source}" contents) string(REGEX MATCHALL "MOCK_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents}) foreach(hit ${found_tests}) string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit}) add_test(${test_name} ${executable} --gmock_filter=${test_name} ${extra_args}) endforeach() endforeach() endfunction() function(_gmock_append_debugs _endvar _library) if(${_library} AND ${_library}_DEBUG) set(_output optimized ${${_library}} debug ${${_library}_DEBUG}) else() set(_output ${${_library}}) endif() set(${_endvar} ${_output} PARENT_SCOPE) endfunction() function(_gmock_find_library _name) find_library(${_name} NAMES ${ARGN} HINTS ENV GMOCK_ROOT ${GMOCK_ROOT} PATH_SUFFIXES ${_gmock_libpath_suffixes} ) mark_as_advanced(${_name}) endfunction() # if(NOT DEFINED GMOCK_MSVC_SEARCH) set(GMOCK_MSVC_SEARCH MD) endif() set(_gmock_libpath_suffixes lib) if(MSVC) if(GMOCK_MSVC_SEARCH STREQUAL "MD") list(APPEND _gmock_libpath_suffixes msvc/gmock-md/Debug msvc/gmock-md/Release) elseif(GMOCK_MSVC_SEARCH STREQUAL "MT") list(APPEND _gmock_libpath_suffixes msvc/gmock/Debug msvc/gmock/Release) endif() endif() find_path(GMOCK_INCLUDE_DIR gmock/gmock.h HINTS $ENV{GMOCK_ROOT}/include ${GMOCK_ROOT}/include ) mark_as_advanced(GMOCK_INCLUDE_DIR) if(MSVC AND GMOCK_MSVC_SEARCH STREQUAL "MD") # The provided /MD project files for Google Mock add -md suffixes to the # library names. _gmock_find_library(GMOCK_LIBRARY gmock-md gmock) _gmock_find_library(GMOCK_LIBRARY_DEBUG gmock-mdd gmockd) else() _gmock_find_library(GMOCK_LIBRARY gmock) _gmock_find_library(GMOCK_LIBRARY_DEBUG gmockd) endif() FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR) if(GMOCK_FOUND) set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR}) _gmock_append_debugs(GMOCK_LIBRARIES GMOCK_LIBRARY) endif() indi-starbook-ten-0.1/cmake_modules/FindPackageMessage.cmake0000644000175100017510000000375514136175546023434 0ustar debiandebian#.rst: # FindPackageMessage # ------------------ # # # # FIND_PACKAGE_MESSAGE( "message for user" "find result details") # # This macro is intended to be used in FindXXX.cmake modules files. It # will print a message once for each unique find result. This is useful # for telling the user where a package was found. The first argument # specifies the name (XXX) of the package. The second argument # specifies the message to display. The third argument lists details # about the find result so that if they change the message will be # displayed again. The macro also obeys the QUIET argument to the # find_package command. # # Example: # # :: # # if(X11_FOUND) # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") # else() # ... # endif() #============================================================================= # Copyright 2008-2009 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) function(FIND_PACKAGE_MESSAGE pkg msg details) # Avoid printing a message repeatedly for the same find result. if(NOT ${pkg}_FIND_QUIETLY) string(REPLACE "\n" "" details "${details}") set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") # The message has not yet been printed. message(STATUS "${msg}") # Save the find details in the cache to avoid printing the same # message again. set("${DETAILS_VAR}" "${details}" CACHE INTERNAL "Details about finding ${pkg}") endif() endif() endfunction() indi-starbook-ten-0.1/cmake_modules/FindFTDI.cmake0000644000175100017510000000267114136175546021316 0ustar debiandebian# - Try to find FTDI # This finds libFTDI that is compatible with old libusb v 0.1 # For newer libusb > 1.0, use FindFTDI1.cmake # Once done this will define # # FTDI_FOUND - system has FTDI # FTDI_INCLUDE_DIR - the FTDI include directory # FTDI_LIBRARIES - Link these to use FTDI # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (FTDI_INCLUDE_DIR AND FTDI_LIBRARIES) # in cache already set(FTDI_FOUND TRUE) message(STATUS "Found libftdi: ${FTDI_LIBRARIES}") else (FTDI_INCLUDE_DIR AND FTDI_LIBRARIES) find_path(FTDI_INCLUDE_DIR ftdi.h PATH_SUFFIXES libftdi1 ${_obIncDir} ${GNUWIN32_DIR}/include /usr/local/include ) find_library(FTDI_LIBRARIES NAMES ftdi ftdi1 PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib /usr/local/lib ) if(FTDI_INCLUDE_DIR AND FTDI_LIBRARIES) set(FTDI_FOUND TRUE) else (FTDI_INCLUDE_DIR AND FTDI_LIBRARIES) set(FTDI_FOUND FALSE) endif(FTDI_INCLUDE_DIR AND FTDI_LIBRARIES) if (FTDI_FOUND) if (NOT FTDI_FIND_QUIETLY) message(STATUS "Found FTDI: ${FTDI_LIBRARIES}") endif (NOT FTDI_FIND_QUIETLY) else (FTDI_FOUND) if (FTDI_FIND_REQUIRED) message(FATAL_ERROR "FTDI not found. Please install libftdi-dev") endif (FTDI_FIND_REQUIRED) endif (FTDI_FOUND) mark_as_advanced(FTDI_INCLUDE_DIR FTDI_LIBRARIES) endif (FTDI_INCLUDE_DIR AND FTDI_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindMODBUS.cmake0000644000175100017510000000320114136175546021547 0ustar debiandebian# - Try to find libmodbus # Once done this will define # # MODBUS_FOUND - system has MODBUS # MODBUS_INCLUDE_DIR - the MODBUS include directory # MODBUS_LIBRARIES - Link these to use MODBUS # Copyright (c) 2006, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (MODBUS_INCLUDE_DIR AND MODBUS_LIBRARIES) # in cache already set(MODBUS_FOUND TRUE) message(STATUS "Found libmodbus: ${MODBUS_LIBRARIES}") else (MODBUS_INCLUDE_DIR AND MODBUS_LIBRARIES) find_path(MODBUS_INCLUDE_DIR modbus.h PATH_SUFFIXES modbus ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(MODBUS_LIBRARIES NAMES modbus PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) set(CMAKE_REQUIRED_INCLUDES ${MODBUS_INCLUDE_DIR}) set(CMAKE_REQUIRED_LIBRARIES ${MODBUS_LIBRARIES}) if(MODBUS_INCLUDE_DIR AND MODBUS_LIBRARIES) set(MODBUS_FOUND TRUE) else (MODBUS_INCLUDE_DIR AND MODBUS_LIBRARIES) set(MODBUS_FOUND FALSE) endif(MODBUS_INCLUDE_DIR AND MODBUS_LIBRARIES) if (MODBUS_FOUND) if (NOT MODBUS_FIND_QUIETLY) message(STATUS "Found libmodbus: ${MODBUS_LIBRARIES}") endif (NOT MODBUS_FIND_QUIETLY) else (MODBUS_FOUND) if (MODBUS_FIND_REQUIRED) message(FATAL_ERROR "libmodbus not found. Please install libmodbus-devel. https://launchpad.net/libmodbus/") endif (MODBUS_FIND_REQUIRED) endif (MODBUS_FOUND) mark_as_advanced(MODBUS_INCLUDE_DIR MODBUS_LIBRARIES) endif (MODBUS_INCLUDE_DIR AND MODBUS_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindSTARSHOOTG.cmake0000644000175100017510000000307014136175546022257 0ustar debiandebian# - Try to find Starshoot Camera Library # Once done this will define # # STARSHOOTG_FOUND - system has Starshoot # STARSHOOTG_INCLUDE_DIR - the Starshoot include directory # STARSHOOTG_LIBRARIES - Link these to use Starshoot # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (STARSHOOTG_INCLUDE_DIR AND STARSHOOTG_LIBRARIES) # in cache already set(STARSHOOTG_FOUND TRUE) message(STATUS "Found libstarshootg: ${STARSHOOTG_LIBRARIES}") else (STARSHOOTG_INCLUDE_DIR AND STARSHOOTG_LIBRARIES) find_path(STARSHOOTG_INCLUDE_DIR starshootg.h PATH_SUFFIXES libstarshootg ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(STARSHOOTG_LIBRARIES NAMES starshootg PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(STARSHOOTG_INCLUDE_DIR AND STARSHOOTG_LIBRARIES) set(STARSHOOTG_FOUND TRUE) else (STARSHOOTG_INCLUDE_DIR AND STARSHOOTG_LIBRARIES) set(STARSHOOTG_FOUND FALSE) endif(STARSHOOTG_INCLUDE_DIR AND STARSHOOTG_LIBRARIES) if (STARSHOOTG_FOUND) if (NOT STARSHOOTG_FIND_QUIETLY) message(STATUS "Found StarshootG: ${STARSHOOTG_LIBRARIES}") endif (NOT STARSHOOTG_FIND_QUIETLY) else (STARSHOOTG_FOUND) if (STARSHOOTG_FIND_REQUIRED) message(FATAL_ERROR "StarshootG not found. Please install StarshootG Library http://www.indilib.org") endif (STARSHOOTG_FIND_REQUIRED) endif (STARSHOOTG_FOUND) mark_as_advanced(STARSHOOTG_INCLUDE_DIR STARSHOOTG_LIBRARIES) endif (STARSHOOTG_INCLUDE_DIR AND STARSHOOTG_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/InstallImported.cmake0000644000175100017510000000661114136175546023077 0ustar debiandebian function (install_imported) cmake_parse_arguments (ARG "" "DESTINATION" "TARGETS" ${ARGN}) if (NOT DEFINED ARG_DESTINATION) message (FATAL_ERROR "DESTINATION not defined") endif () foreach (target ${ARG_TARGETS}) get_target_property (location ${target} LOCATION) get_target_property (version ${target} VERSION) get_target_property (soversion ${target} SOVERSION) get_target_property (output_name ${target} OUTPUT_NAME) get_target_property (suffix ${target} SUFFIX) get_target_property (type ${target} TYPE) if (NOT ${type} STREQUAL "SHARED_LIBRARY") message (FATAL_ERROR "install_imported: ${type} not supported") endif () if (${location} STREQUAL "${target}-NOTFOUND") return () endif () if (NOT ${version} STREQUAL "version-NOTFOUND") set (version ".${version}") else () set (version "") endif () if (NOT ${soversion} STREQUAL "soversion-NOTFOUND") set (soversion ".${soversion}") else () set (soversion "") endif () if (${output_name} STREQUAL "output_name-NOTFOUND") set (output_name ${target}) endif () set (name_noversion "${CMAKE_SHARED_LIBRARY_PREFIX}${output_name}${CMAKE_SHARED_LIBRARY_SUFFIX}") if (APPLE) set (name_version "${CMAKE_SHARED_LIBRARY_PREFIX}${output_name}${version}${CMAKE_SHARED_LIBRARY_SUFFIX}") set (name_soversion "${CMAKE_SHARED_LIBRARY_PREFIX}${output_name}${soversion}${CMAKE_SHARED_LIBRARY_SUFFIX}") else () set (name_version "${CMAKE_SHARED_LIBRARY_PREFIX}${output_name}${CMAKE_SHARED_LIBRARY_SUFFIX}${version}") set (name_soversion "${CMAKE_SHARED_LIBRARY_PREFIX}${output_name}${CMAKE_SHARED_LIBRARY_SUFFIX}${soversion}") endif () if (NOT IS_ABSOLUTE ${location}) set (location ${CMAKE_CURRENT_SOURCE_DIR}/${location}) endif () if (NOT ${name_noversion} STREQUAL ${name_soversion}) add_custom_command ( OUTPUT ${name_noversion} COMMAND ${CMAKE_COMMAND} -E create_symlink ${name_soversion} ${name_noversion} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} MAIN_DEPENDENCY ${name_soversion} ) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${name_noversion} DESTINATION ${ARG_DESTINATION}) endif () if (NOT ${name_soversion} STREQUAL ${name_version}) add_custom_command ( OUTPUT ${name_soversion} COMMAND ${CMAKE_COMMAND} -E create_symlink ${name_version} ${name_soversion} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} MAIN_DEPENDENCY ${name_version} ) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${name_soversion} DESTINATION ${ARG_DESTINATION}) endif () add_custom_command ( OUTPUT ${name_version} COMMAND ${CMAKE_COMMAND} -E copy "${location}" "${CMAKE_CURRENT_BINARY_DIR}/${name_version}" MAIN_DEPENDENCY ${location} ) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${name_version} DESTINATION ${ARG_DESTINATION}) add_custom_target( imported_${output_name} ALL DEPENDS ${name_version} ${name_noversion} ${name_soversion} ) endforeach () endfunction () indi-starbook-ten-0.1/cmake_modules/FindAHPXC.cmake0000644000175100017510000000273214136175546021431 0ustar debiandebian# - Try to find AHPXC Universal Library # Once done this will define # # AHPXC_FOUND - system has AHPXC # AHPXC_INCLUDE_DIR - the AHPXC include directory # AHPXC_LIBRARIES - Link these to use AHPXC # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (AHPXC_INCLUDE_DIR AND AHPXC_LIBRARIES) # in cache already set(AHPXC_FOUND TRUE) message(STATUS "Found libahp_xc: ${AHPXC_LIBRARIES}") else (AHPXC_INCLUDE_DIR AND AHPXC_LIBRARIES) find_path(AHPXC_INCLUDE_DIR ahp_xc.h PATH_SUFFIXES ahp ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(AHPXC_LIBRARIES NAMES ahp_xc PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(AHPXC_INCLUDE_DIR AND AHPXC_LIBRARIES) set(AHPXC_FOUND TRUE) else (AHPXC_INCLUDE_DIR AND AHPXC_LIBRARIES) set(AHPXC_FOUND FALSE) endif(AHPXC_INCLUDE_DIR AND AHPXC_LIBRARIES) if (AHPXC_FOUND) if (NOT AHPXC_FIND_QUIETLY) message(STATUS "Found AHP XC: ${AHPXC_LIBRARIES}") endif (NOT AHPXC_FIND_QUIETLY) else (AHPXC_FOUND) if (AHPXC_FIND_REQUIRED) message(FATAL_ERROR "AHP XC not found. Please install libahp_xc http://www.indilib.org") endif (AHPXC_FIND_REQUIRED) endif (AHPXC_FOUND) mark_as_advanced(AHPXC_INCLUDE_DIR AHPXC_LIBRARIES) endif (AHPXC_INCLUDE_DIR AND AHPXC_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindFLI.cmake0000644000175100017510000000264514136175546021203 0ustar debiandebian# - Try to find Finger Lakes Instruments Library # Once done this will define # # FLI_FOUND - system has FLI # FLI_INCLUDE_DIR - the FLI include directory # FLI_LIBRARIES - Link these to use FLI # Copyright (c) 2008, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (FLI_INCLUDE_DIR AND FLI_LIBRARIES) # in cache already set(FLI_FOUND TRUE) message(STATUS "Found libfli: ${FLI_LIBRARIES}") else (FLI_INCLUDE_DIR AND FLI_LIBRARIES) find_path(FLI_INCLUDE_DIR libfli.h PATH_SUFFIXES fli ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(FLI_LIBRARIES NAMES fli PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(FLI_INCLUDE_DIR AND FLI_LIBRARIES) set(FLI_FOUND TRUE) else (FLI_INCLUDE_DIR AND FLI_LIBRARIES) set(FLI_FOUND FALSE) endif(FLI_INCLUDE_DIR AND FLI_LIBRARIES) if (FLI_FOUND) if (NOT FLI_FIND_QUIETLY) message(STATUS "Found FLI: ${FLI_LIBRARIES}") endif (NOT FLI_FIND_QUIETLY) else (FLI_FOUND) if (FLI_FIND_REQUIRED) message(FATAL_ERROR "FLI not found. Please install libfli-dev. http://www.indilib.org") endif (FLI_FIND_REQUIRED) endif (FLI_FOUND) mark_as_advanced(FLI_INCLUDE_DIR FLI_LIBRARIES) endif (FLI_INCLUDE_DIR AND FLI_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindASI.cmake0000644000175100017510000000356514136175546021207 0ustar debiandebian# - Try to find ASI Library # Once done this will define # # ASI_FOUND - system has ASI # ASI_INCLUDE_DIR - the ASI include directory # ASI_LIBRARIES - Link these to use ASI # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (ASI_INCLUDE_DIR AND ASI_LIBRARIES) # in cache already set(ASI_FOUND TRUE) message(STATUS "Found libasi: ${ASI_LIBRARIES}") else (ASI_INCLUDE_DIR AND ASI_LIBRARIES) find_path(ASI_INCLUDE_DIR ASICamera2.h PATH_SUFFIXES libasi ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(ASICAM_LIBRARIES NAMES ASICamera2 PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) find_library(ASIEFW_LIBRARIES NAMES EFWFilter PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) find_library(ASIST4_LIBRARIES NAMES USB2ST4Conv PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) find_library(ASIEAF_LIBRARIES NAMES EAFFocuser PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if (ASICAM_LIBRARIES AND ASIEFW_LIBRARIES AND ASIST4_LIBRARIES AND ASIEAF_LIBRARIES) set(ASI_LIBRARIES ${ASICAM_LIBRARIES} ${ASIEFW_LIBRARIES} ${ASIST4_LIBRARIES} ${ASIEAF_LIBRARIES}) endif (ASICAM_LIBRARIES AND ASIEFW_LIBRARIES AND ASIST4_LIBRARIES AND ASIEAF_LIBRARIES) if(ASI_INCLUDE_DIR AND ASI_LIBRARIES) set(ASI_FOUND TRUE) else (ASI_INCLUDE_DIR AND ASI_LIBRARIES) set(ASI_FOUND FALSE) endif(ASI_INCLUDE_DIR AND ASI_LIBRARIES) if (ASI_FOUND) if (NOT ASI_FIND_QUIETLY) message(STATUS "Found ASI: ${ASI_LIBRARIES}") endif (NOT ASI_FIND_QUIETLY) else (ASI_FOUND) if (ASI_FIND_REQUIRED) message(FATAL_ERROR "ASI not found. Please install libasi http://www.indilib.org") endif (ASI_FIND_REQUIRED) endif (ASI_FOUND) mark_as_advanced(ASI_INCLUDE_DIR ASI_LIBRARIES) endif (ASI_INCLUDE_DIR AND ASI_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindINDI.cmake0000644000175100017510000003457414136175546021322 0ustar debiandebian# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # This module can find INDI Library # # Requirements: # - CMake >= 2.8.3 (for new version of find_package_handle_standard_args) # # The following variables will be defined for your use: # - INDI_FOUND : were all of your specified components found (include dependencies)? # - INDI_WEBSOCKET : was INDI compiled with websocket support? # - INDI_INCLUDE_DIR : INDI include directory # - INDI_DATA_DIR : INDI include directory # - INDI_LIBRARIES : INDI libraries # - INDI_DRIVER_LIBRARIES : Same as above maintained for backward compatibility # - INDI_VERSION : complete version of INDI (x.y.z) # - INDI_MAJOR_VERSION : major version of INDI # - INDI_MINOR_VERSION : minor version of INDI # - INDI_RELEASE_VERSION : release version of INDI # - INDI__FOUND : were found? (FALSE for non specified component if it is not a dependency) # # For windows or non standard installation, define INDI_ROOT variable to point to the root installation of INDI. Two ways: # - run cmake with -DINDI_ROOT= # - define an environment variable with the same name before running cmake # With cmake-gui, before pressing "Configure": # 1) Press "Add Entry" button # 2) Add a new entry defined as: # - Name: INDI_ROOT # - Type: choose PATH in the selection list # - Press "..." button and select the root installation of INDI # # Example Usage: # # 1. Copy this file in the root of your project source directory # 2. Then, tell CMake to search this non-standard module in your project directory by adding to your CMakeLists.txt: # set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) # 3. Finally call find_package() once, here are some examples to pick from # # Require INDI 1.4 or later # find_package(INDI 1.4 REQUIRED) # # if(INDI_FOUND) # include_directories(${INDI_INCLUDE_DIR}) # add_executable(myapp myapp.cpp) # target_link_libraries(myapp ${INDI_LIBRARIES}) # endif(INDI_FOUND) # # # Using Components: # # You can search for specific components. Currently, the following components are available # * driver: to build INDI hardware drivers. # * align: to build drivers that use INDI Alignment Subsystem. # * client: to build pure C++ INDI clients. # * clientqt5: to build Qt5-based INDI clients. # * lx200: To build LX200-based 3rd party drivers (you must link with driver above as well). # # By default, if you do not specify any components, driver and align components are searched. # # Example: # # To use INDI Qt5 Client library only in your application: # # find_package(INDI COMPONENTS clientqt5 REQUIRED) # # if(INDI_FOUND) # include_directories(${INDI_INCLUDE_DIR}) # add_executable(myapp myapp.cpp) # target_link_libraries(myapp ${INDI_LIBRARIES}) # endif(INDI_FOUND) # # To use INDI driver + lx200 component in your application: # # find_package(INDI COMPONENTS driver lx200 REQUIRED) # # if(INDI_FOUND) # include_directories(${INDI_INCLUDE_DIR}) # add_executable(myapp myapp.cpp) # target_link_libraries(myapp ${INDI_LIBRARIES}) # endif(INDI_FOUND) # # Notice we still use ${INDI_LIBRARIES} which now should contain both driver & lx200 libraries. #============================================================================================== # Copyright (c) 2011-2013, julp # Copyright (c) 2017-2019 Jasem Mutlaq # # Distributed under the OSI-approved BSD License # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTINDILAR PURPOSE. #============================================================================= find_package(PkgConfig QUIET) ########## Private ########## if(NOT DEFINED INDI_PUBLIC_VAR_NS) set(INDI_PUBLIC_VAR_NS "INDI") # Prefix for all INDI relative public variables endif(NOT DEFINED INDI_PUBLIC_VAR_NS) if(NOT DEFINED INDI_PRIVATE_VAR_NS) set(INDI_PRIVATE_VAR_NS "_${INDI_PUBLIC_VAR_NS}") # Prefix for all INDI relative internal variables endif(NOT DEFINED INDI_PRIVATE_VAR_NS) if(NOT DEFINED PC_INDI_PRIVATE_VAR_NS) set(PC_INDI_PRIVATE_VAR_NS "_PC${INDI_PRIVATE_VAR_NS}") # Prefix for all pkg-config relative internal variables endif(NOT DEFINED PC_INDI_PRIVATE_VAR_NS) function(indidebug _VARNAME) if(${INDI_PUBLIC_VAR_NS}_DEBUG) if(DEFINED ${INDI_PUBLIC_VAR_NS}_${_VARNAME}) message("${INDI_PUBLIC_VAR_NS}_${_VARNAME} = ${${INDI_PUBLIC_VAR_NS}_${_VARNAME}}") else(DEFINED ${INDI_PUBLIC_VAR_NS}_${_VARNAME}) message("${INDI_PUBLIC_VAR_NS}_${_VARNAME} = ") endif(DEFINED ${INDI_PUBLIC_VAR_NS}_${_VARNAME}) endif(${INDI_PUBLIC_VAR_NS}_DEBUG) endfunction(indidebug) set(${INDI_PRIVATE_VAR_NS}_ROOT "") if(DEFINED ENV{INDI_ROOT}) set(${INDI_PRIVATE_VAR_NS}_ROOT "$ENV{INDI_ROOT}") endif(DEFINED ENV{INDI_ROOT}) if (DEFINED INDI_ROOT) set(${INDI_PRIVATE_VAR_NS}_ROOT "${INDI_ROOT}") endif(DEFINED INDI_ROOT) set(${INDI_PRIVATE_VAR_NS}_BIN_SUFFIXES ) set(${INDI_PRIVATE_VAR_NS}_LIB_SUFFIXES ) if(CMAKE_SIZEOF_VOID_P EQUAL 8) list(APPEND ${INDI_PRIVATE_VAR_NS}_BIN_SUFFIXES "bin64") list(APPEND ${INDI_PRIVATE_VAR_NS}_LIB_SUFFIXES "lib64") endif(CMAKE_SIZEOF_VOID_P EQUAL 8) list(APPEND ${INDI_PRIVATE_VAR_NS}_BIN_SUFFIXES "bin") list(APPEND ${INDI_PRIVATE_VAR_NS}_LIB_SUFFIXES "lib") set(${INDI_PRIVATE_VAR_NS}_COMPONENTS ) # ... macro(INDI_declare_component _NAME) list(APPEND ${INDI_PRIVATE_VAR_NS}_COMPONENTS ${_NAME}) set("${INDI_PRIVATE_VAR_NS}_COMPONENTS_${_NAME}" ${ARGN}) endmacro(INDI_declare_component) INDI_declare_component(driver indidriver) INDI_declare_component(align indiAlignmentDriver) INDI_declare_component(client indiclient) INDI_declare_component(clientqt5 indiclientqt5) INDI_declare_component(lx200 indilx200) ########## Public ########## set(${INDI_PUBLIC_VAR_NS}_FOUND TRUE) set(${INDI_PUBLIC_VAR_NS}_LIBRARIES ) set(${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR ) foreach(${INDI_PRIVATE_VAR_NS}_COMPONENT ${${INDI_PRIVATE_VAR_NS}_COMPONENTS}) string(TOUPPER "${${INDI_PRIVATE_VAR_NS}_COMPONENT}" ${INDI_PRIVATE_VAR_NS}_UPPER_COMPONENT) set("${INDI_PUBLIC_VAR_NS}_${${INDI_PRIVATE_VAR_NS}_UPPER_COMPONENT}_FOUND" FALSE) # may be done in the INDI_declare_component macro endforeach(${INDI_PRIVATE_VAR_NS}_COMPONENT) # Check components if(NOT ${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS) # driver and posix client by default set(${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS driver align) else(NOT ${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS) #list(APPEND ${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS uc) list(REMOVE_DUPLICATES ${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS) foreach(${INDI_PRIVATE_VAR_NS}_COMPONENT ${${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS}) if(NOT DEFINED ${INDI_PRIVATE_VAR_NS}_COMPONENTS_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) message(FATAL_ERROR "Unknown INDI component: ${${INDI_PRIVATE_VAR_NS}_COMPONENT}") endif(NOT DEFINED ${INDI_PRIVATE_VAR_NS}_COMPONENTS_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) endforeach(${INDI_PRIVATE_VAR_NS}_COMPONENT) endif(NOT ${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS) # Includes find_path( ${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR indidevapi.h PATH_SUFFIXES libindi include/libindi ${PC_INDI_INCLUDE_DIR} ${_obIncDir} ${GNUWIN32_DIR}/include HINTS ${${INDI_PRIVATE_VAR_NS}_ROOT} DOC "Include directory for INDI" ) find_path( WEBSOCKET_HEADER indiwsserver.h PATH_SUFFIXES libindi ${PC_INDI_INCLUDE_DIR} ${_obIncDir} ${GNUWIN32_DIR}/include ) if (WEBSOCKET_HEADER) SET(INDI_WEBSOCKET TRUE) else() SET(INDI_WEBSOCKET FALSE) endif() find_path(${INDI_PUBLIC_VAR_NS}_DATA_DIR drivers.xml PATH_SUFFIXES share/indi DOC "Data directory for INDI" ) if(${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR) if(EXISTS "${${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR}/indiversion.h") # INDI >= 1.4 file(READ "${${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR}/indiversion.h" ${INDI_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS) else() message(FATAL_ERROR "INDI version header not found") endif() if(${INDI_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS MATCHES ".*INDI_VERSION ([0-9]+).([0-9]+).([0-9]+)") set(${INDI_PUBLIC_VAR_NS}_MAJOR_VERSION "${CMAKE_MATCH_1}") set(${INDI_PUBLIC_VAR_NS}_MINOR_VERSION "${CMAKE_MATCH_2}") set(${INDI_PUBLIC_VAR_NS}_RELEASE_VERSION "${CMAKE_MATCH_3}") else() message(FATAL_ERROR "failed to detect INDI version") endif() set(${INDI_PUBLIC_VAR_NS}_VERSION "${${INDI_PUBLIC_VAR_NS}_MAJOR_VERSION}.${${INDI_PUBLIC_VAR_NS}_MINOR_VERSION}.${${INDI_PUBLIC_VAR_NS}_RELEASE_VERSION}") # Check libraries foreach(${INDI_PRIVATE_VAR_NS}_COMPONENT ${${INDI_PUBLIC_VAR_NS}_FIND_COMPONENTS}) set(${INDI_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES ) set(${INDI_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES ) foreach(${INDI_PRIVATE_VAR_NS}_BASE_NAME ${${INDI_PRIVATE_VAR_NS}_COMPONENTS_${${INDI_PRIVATE_VAR_NS}_COMPONENT}}) list(APPEND ${INDI_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES "${${INDI_PRIVATE_VAR_NS}_BASE_NAME}") list(APPEND ${INDI_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES "${${INDI_PRIVATE_VAR_NS}_BASE_NAME}d") list(APPEND ${INDI_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES "${${INDI_PRIVATE_VAR_NS}_BASE_NAME}${INDI_MAJOR_VERSION}${INDI_MINOR_VERSION}") list(APPEND ${INDI_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES "${${INDI_PRIVATE_VAR_NS}_BASE_NAME}${INDI_MAJOR_VERSION}${INDI_MINOR_VERSION}d") endforeach(${INDI_PRIVATE_VAR_NS}_BASE_NAME) find_library( ${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT} NAMES ${${INDI_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES} HINTS ${${INDI_PRIVATE_VAR_NS}_ROOT} PATH_SUFFIXES ${_INDI_LIB_SUFFIXES} DOC "Release libraries for INDI" ) find_library( ${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT} NAMES ${${INDI_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES} HINTS ${${INDI_PRIVATE_VAR_NS}_ROOT} PATH_SUFFIXES ${_INDI_LIB_SUFFIXES} DOC "Debug libraries for INDI" ) string(TOUPPER "${${INDI_PRIVATE_VAR_NS}_COMPONENT}" ${INDI_PRIVATE_VAR_NS}_UPPER_COMPONENT) if(NOT ${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT} AND NOT ${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) # both not found set("${INDI_PUBLIC_VAR_NS}_${${INDI_PRIVATE_VAR_NS}_UPPER_COMPONENT}_FOUND" FALSE) set("${INDI_PUBLIC_VAR_NS}_FOUND" FALSE) else(NOT ${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT} AND NOT ${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) # one or both found set("${INDI_PUBLIC_VAR_NS}_${${INDI_PRIVATE_VAR_NS}_UPPER_COMPONENT}_FOUND" TRUE) if(NOT ${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) # release not found => we are in debug set(${INDI_PRIVATE_VAR_NS}_LIB_${${INDI_PRIVATE_VAR_NS}_COMPONENT} "${${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT}}") elseif(NOT ${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) # debug not found => we are in release set(${INDI_PRIVATE_VAR_NS}_LIB_${${INDI_PRIVATE_VAR_NS}_COMPONENT} "${${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT}}") else() # both found set( ${INDI_PRIVATE_VAR_NS}_LIB_${${INDI_PRIVATE_VAR_NS}_COMPONENT} optimized ${${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT}} debug ${${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT}} ) endif() list(APPEND ${INDI_PUBLIC_VAR_NS}_LIBRARIES ${${INDI_PRIVATE_VAR_NS}_LIB_${${INDI_PRIVATE_VAR_NS}_COMPONENT}}) endif(NOT ${INDI_PRIVATE_VAR_NS}_LIB_RELEASE_${${INDI_PRIVATE_VAR_NS}_COMPONENT} AND NOT ${INDI_PRIVATE_VAR_NS}_LIB_DEBUG_${${INDI_PRIVATE_VAR_NS}_COMPONENT}) endforeach(${INDI_PRIVATE_VAR_NS}_COMPONENT) # Check find_package arguments include(FindPackageHandleStandardArgs) if(${INDI_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${INDI_PUBLIC_VAR_NS}_FIND_QUIETLY) find_package_handle_standard_args( ${INDI_PUBLIC_VAR_NS} REQUIRED_VARS ${INDI_PUBLIC_VAR_NS}_LIBRARIES ${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR VERSION_VAR ${INDI_PUBLIC_VAR_NS}_VERSION ) else(${INDI_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${INDI_PUBLIC_VAR_NS}_FIND_QUIETLY) find_package_handle_standard_args(${INDI_PUBLIC_VAR_NS} "INDI not found" ${INDI_PUBLIC_VAR_NS}_LIBRARIES ${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR) endif(${INDI_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${INDI_PUBLIC_VAR_NS}_FIND_QUIETLY) else(${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR) set("${INDI_PUBLIC_VAR_NS}_FOUND" FALSE) if(${INDI_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${INDI_PUBLIC_VAR_NS}_FIND_QUIETLY) message(FATAL_ERROR "Could not find INDI include directory") endif(${INDI_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${INDI_PUBLIC_VAR_NS}_FIND_QUIETLY) endif(${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR) mark_as_advanced( ${INDI_PUBLIC_VAR_NS}_INCLUDE_DIR ${INDI_PUBLIC_VAR_NS}_LIBRARIES INDI_WEBSOCKET ) # IN (args) indidebug("FIND_COMPONENTS") indidebug("FIND_REQUIRED") indidebug("FIND_QUIETLY") indidebug("FIND_VERSION") # OUT # Found indidebug("FOUND") indidebug("SERVER_FOUND") indidebug("DRIVERS_FOUND") indidebug("CLIENT_FOUND") indidebug("QT5CLIENT_FOUND") indidebug("LX200_FOUND") # Linking indidebug("INCLUDE_DIR") indidebug("DATA_DIR") indidebug("LIBRARIES") # Backward compatibility set(${INDI_PUBLIC_VAR_NS}_DRIVER_LIBRARIES ${${INDI_PUBLIC_VAR_NS}_LIBRARIES}) indidebug("DRIVER_LIBRARIES") # Version indidebug("MAJOR_VERSION") indidebug("MINOR_VERSION") indidebug("RELEASE_VERSION") indidebug("VERSION") indi-starbook-ten-0.1/cmake_modules/CMakeCommon.cmake0000644000175100017510000001366714136175546022127 0ustar debiandebian include(CheckCCompilerFlag) #IF (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") #ENDIF () # C++14 Support if (NOT ANDROID) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif(NOT ANDROID) # Position Independent Code set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Ccache support IF (ANDROID OR UNIX OR APPLE) FIND_PROGRAM(CCACHE_FOUND ccache) SET(CCACHE_SUPPORT OFF CACHE BOOL "Enable ccache support") IF ((CCACHE_FOUND OR ANDROID) AND CCACHE_SUPPORT MATCHES ON) SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) ENDIF () ENDIF () # Add security (hardening flags) IF (UNIX OR APPLE OR ANDROID) # Older compilers are predefining _FORTIFY_SOURCE, so defining it causes a # warning, which is then considered an error. Second issue is that for # these compilers, _FORTIFY_SOURCE must be used while optimizing, else # causes a warning, which also results in an error. And finally, CMake is # not using optimization when testing for libraries, hence breaking the build. CHECK_C_COMPILER_FLAG("-Werror -D_FORTIFY_SOURCE=2" COMPATIBLE_FORTIFY_SOURCE) IF (${COMPATIBLE_FORTIFY_SOURCE}) SET(SEC_COMP_FLAGS "-D_FORTIFY_SOURCE=2") ENDIF () SET(SEC_COMP_FLAGS "${SEC_COMP_FLAGS} -fstack-protector-all -fPIE") # Make sure to add optimization flag. Some systems require this for _FORTIFY_SOURCE. IF (NOT CMAKE_BUILD_TYPE MATCHES "MinSizeRel" AND NOT CMAKE_BUILD_TYPE MATCHES "Release" AND NOT CMAKE_BUILD_TYPE MATCHES "Debug") SET(SEC_COMP_FLAGS "${SEC_COMP_FLAGS} -O1") ENDIF () IF (NOT ANDROID AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT APPLE AND NOT CYGWIN) SET(SEC_COMP_FLAGS "${SEC_COMP_FLAGS} -Wa,--noexecstack") ENDIF () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SEC_COMP_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SEC_COMP_FLAGS}") SET(SEC_LINK_FLAGS "") IF (NOT APPLE AND NOT CYGWIN) SET(SEC_LINK_FLAGS "${SEC_LINK_FLAGS} -Wl,-z,nodump -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") ENDIF () IF (NOT ANDROID AND NOT APPLE) SET(SEC_LINK_FLAGS "${SEC_LINK_FLAGS} -pie") ENDIF () SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SEC_LINK_FLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SEC_LINK_FLAGS}") ENDIF () # Warning, debug and linker flags SET(FIX_WARNINGS OFF CACHE BOOL "Enable strict compilation mode to turn compiler warnings to errors") IF (UNIX OR APPLE) SET(COMP_FLAGS "") SET(LINKER_FLAGS "") # Verbose warnings and turns all to errors SET(COMP_FLAGS "${COMP_FLAGS} -Wall -Wextra") IF (FIX_WARNINGS) SET(COMP_FLAGS "${COMP_FLAGS} -Werror") ENDIF () # Omit problematic warnings IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET(COMP_FLAGS "${COMP_FLAGS} -Wno-unused-but-set-variable") ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.9.9) SET(COMP_FLAGS "${COMP_FLAGS} -Wno-format-truncation") ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") SET(COMP_FLAGS "${COMP_FLAGS} -Wno-nonnull -Wno-deprecated-declarations") ENDIF () # Minimal debug info with Clang IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") SET(COMP_FLAGS "${COMP_FLAGS} -gline-tables-only") ELSE () SET(COMP_FLAGS "${COMP_FLAGS} -g") ENDIF () # Note: The following flags are problematic on older systems with gcc 4.8 IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9.9)) IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") SET(COMP_FLAGS "${COMP_FLAGS} -Wno-unused-command-line-argument") ENDIF () FIND_PROGRAM(LDGOLD_FOUND ld.gold) SET(LDGOLD_SUPPORT OFF CACHE BOOL "Enable ld.gold support") # Optional ld.gold is 2x faster than normal ld IF (LDGOLD_FOUND AND LDGOLD_SUPPORT MATCHES ON AND NOT APPLE AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES arm) SET(LINKER_FLAGS "${LINKER_FLAGS} -fuse-ld=gold") # Use Identical Code Folding SET(COMP_FLAGS "${COMP_FLAGS} -ffunction-sections") SET(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--icf=safe") # Compress the debug sections # Note: Before valgrind 3.12.0, patch should be applied for valgrind (https://bugs.kde.org/show_bug.cgi?id=303877) IF (NOT APPLE AND NOT ANDROID AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES arm AND NOT CMAKE_CXX_CLANG_TIDY) SET(COMP_FLAGS "${COMP_FLAGS} -Wa,--compress-debug-sections") SET(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--compress-debug-sections=zlib") ENDIF () ENDIF () ENDIF () # Apply the flags SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMP_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMP_FLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}") ENDIF () # Sanitizer support SET(CLANG_SANITIZERS OFF CACHE BOOL "Clang's sanitizer support") IF (CLANG_SANITIZERS AND ((UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR (APPLE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer") ENDIF () # Unity Build support include(UnityBuild) indi-starbook-ten-0.1/cmake_modules/FindINOVASDK.cmake0000644000175100017510000000275314136175546022007 0ustar debiandebian# - Try to find INOVASDK Universal Library # Once done this will define # # INOVASDK_FOUND - system has INOVASDK # INOVASDK_INCLUDE_DIR - the INOVASDK include directory # INOVASDK_LIBRARIES - Link these to use INOVASDK # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (INOVASDK_INCLUDE_DIR AND INOVASDK_LIBRARIES) # in cache already set(INOVASDK_FOUND TRUE) message(STATUS "Found libinovasdk: ${INOVASDK_LIBRARIES}") else (INOVASDK_INCLUDE_DIR AND INOVASDK_LIBRARIES) find_path(INOVASDK_INCLUDE_DIR inovasdk.h PATH_SUFFIXES inovasdk ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(INOVASDK_LIBRARIES NAMES inovasdk PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(INOVASDK_INCLUDE_DIR AND INOVASDK_LIBRARIES) set(INOVASDK_FOUND TRUE) else (INOVASDK_INCLUDE_DIR AND INOVASDK_LIBRARIES) set(INOVASDK_FOUND FALSE) endif(INOVASDK_INCLUDE_DIR AND INOVASDK_LIBRARIES) if (INOVASDK_FOUND) if (NOT INOVASDK_FIND_QUIETLY) message(STATUS "Found INOVASDK: ${INOVASDK_LIBRARIES}") endif (NOT INOVASDK_FIND_QUIETLY) else (INOVASDK_FOUND) if (INOVASDK_FIND_REQUIRED) message(FATAL_ERROR "INOVASDK not found. Please install INOVASDK Library http://www.indilib.org") endif (INOVASDK_FIND_REQUIRED) endif (INOVASDK_FOUND) mark_as_advanced(INOVASDK_INCLUDE_DIR INOVASDK_LIBRARIES) endif (INOVASDK_INCLUDE_DIR AND INOVASDK_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindQHY.cmake0000644000175100017510000000242614136175546021227 0ustar debiandebian# - Try to find QHY Library # Once done this will define # # QHY_FOUND - system has QHY # QHY_INCLUDE_DIR - the QHY include directory # QHY_LIBRARIES - Link these to use QHY # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (QHY_INCLUDE_DIR AND QHY_LIBRARIES) # in cache already set(QHY_FOUND TRUE) message(STATUS "Found libqhyccd: ${QHY_LIBRARIES}") else (QHY_INCLUDE_DIR AND QHY_LIBRARIES) find_path(QHY_INCLUDE_DIR qhyccd.h PATH_SUFFIXES libqhy ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(QHY_LIBRARIES NAMES qhyccd PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(QHY_INCLUDE_DIR AND QHY_LIBRARIES) set(QHY_FOUND TRUE) else (QHY_INCLUDE_DIR AND QHY_LIBRARIES) set(QHY_FOUND FALSE) endif(QHY_INCLUDE_DIR AND QHY_LIBRARIES) if (QHY_FOUND) if (NOT QHY_FIND_QUIETLY) message(STATUS "Found QHY: ${QHY_LIBRARIES}") endif (NOT QHY_FIND_QUIETLY) else (QHY_FOUND) if (QHY_FIND_REQUIRED) message(FATAL_ERROR "QHY not found. Please install libqhy http://www.indilib.org") endif (QHY_FIND_REQUIRED) endif (QHY_FOUND) mark_as_advanced(QHY_INCLUDE_DIR QHY_LIBRARIES) endif (QHY_INCLUDE_DIR AND QHY_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindPENTAX.cmake0000644000175100017510000000553014136175546021564 0ustar debiandebian# - Try to find PENTAX Universal Libraries # Once done this will define # # PENTAX_FOUND - system has PENTAX # PENTAX_INCLUDE_DIR - the PENTAX include directory # PENTAX_LIBRARIES - Link these to use PENTAX # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES) # in cache already set(PENTAX_FOUND TRUE) message(STATUS "Found PENTAX libraries: ${PENTAX_LIBRARIES}") else (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES) find_path(PKTRIGGERCORD_INCLUDE_DIR libpktriggercord.h PATH_SUFFIXES libpktriggercord ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(PKTRIGGERCORD_LIBRARIES NAMES pktriggercord PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib PATH_SUFFIXES indipentax ) #if not armv8, then look for ricoh library; otherwise only use pktriggercord library if(NOT (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch64")) find_path(RICOH_INCLUDE_DIR ricoh_camera_sdk.hpp PATH_SUFFIXES libpentax libricohcamerasdk ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(RICOH_LIBRARIES NAMES RicohCameraSDKCpp PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) find_library(RICOHMTP_LIBRARIES NAMES libmtpricoh.so.9.3.0 PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if (RICOH_INCLUDE_DIR AND PKTRIGGERCORD_INCLUDE_DIR) set(PENTAX_INCLUDE_DIR ${RICOH_INCLUDE_DIR} ${PKTRIGGERCORD_INCLUDE_DIR}) endif (RICOH_INCLUDE_DIR AND PKTRIGGERCORD_INCLUDE_DIR) if (RICOH_LIBRARIES AND RICOHMTP_LIBRARIES AND PKTRIGGERCORD_LIBRARIES) set(PENTAX_LIBRARIES ${RICOH_LIBRARIES} ${RICOHMTP_LIBRARIES} ${PKTRIGGERCORD_LIBRARIES}) endif (RICOH_LIBRARIES AND RICOHMTP_LIBRARIES AND PKTRIGGERCORD_LIBRARIES) else() if (PKTRIGGERCORD_INCLUDE_DIR) set(PENTAX_INCLUDE_DIR ${PKTRIGGERCORD_INCLUDE_DIR}) endif (PKTRIGGERCORD_INCLUDE_DIR) if (PKTRIGGERCORD_LIBRARIES) set(PENTAX_LIBRARIES ${PKTRIGGERCORD_LIBRARIES}) endif (PKTRIGGERCORD_LIBRARIES) endif() if(PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES) set(PENTAX_FOUND TRUE) else (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES) set(PENTAX_FOUND FALSE) endif(PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES) if (PENTAX_FOUND) if (NOT PENTAX_FIND_QUIETLY) message(STATUS "Found PENTAX libraries: ${PENTAX_LIBRARIES}") endif (NOT PENTAX_FIND_QUIETLY) else (PENTAX_FOUND) if (PENTAX_FIND_REQUIRED) message(FATAL_ERROR "One or both of libricohcamersdk and libpktriggercord are not found. Please install them. See http://www.indilib.org.") endif (PENTAX_FIND_REQUIRED) endif (PENTAX_FOUND) mark_as_advanced(PENTAX_INCLUDE_DIR PENTAX_LIBRARIES) endif (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindGLIB2.cmake0000644000175100017510000001327114136175546021365 0ustar debiandebian# - Try to find GLib2 # Once done this will define # # GLIB2_FOUND - system has GLib2 # GLIB2_INCLUDE_DIRS - the GLib2 include directory # GLIB2_LIBRARIES - Link these to use GLib2 # # HAVE_GLIB_GREGEX_H glib has gregex.h header and # supports g_regex_match_simple # # Copyright (c) 2006 Andreas Schneider # Copyright (c) 2006 Philippe Bernery # Copyright (c) 2007 Daniel Gollub # Copyright (c) 2007 Alban Browaeys # Copyright (c) 2008 Michael Bell # Copyright (c) 2008 Bjoern Ricks # # Redistribution and use is allowed according to the terms of the New # BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # IF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS ) # in cache already SET(GLIB2_FOUND TRUE) ELSE (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS ) INCLUDE(FindPkgConfig) ## Glib IF ( GLIB2_FIND_REQUIRED ) SET( _pkgconfig_REQUIRED "REQUIRED" ) ELSE ( GLIB2_FIND_REQUIRED ) SET( _pkgconfig_REQUIRED "" ) ENDIF ( GLIB2_FIND_REQUIRED ) IF ( GLIB2_MIN_VERSION ) PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0>=${GLIB2_MIN_VERSION} ) ELSE ( GLIB2_MIN_VERSION ) PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 ) ENDIF ( GLIB2_MIN_VERSION ) IF ( PKG_CONFIG_FOUND ) IF ( GLIB2_FOUND ) SET ( GLIB2_CORE_FOUND TRUE ) ELSE ( GLIB2_FOUND ) SET ( GLIB2_CORE_FOUND FALSE ) ENDIF ( GLIB2_FOUND ) ENDIF ( PKG_CONFIG_FOUND ) # Look for glib2 include dir and libraries w/o pkgconfig IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND ) FIND_PATH( _glibconfig_include_DIR NAMES glibconfig.h PATHS /opt/gnome/lib64 /opt/gnome/lib /opt/lib/ /opt/local/lib /sw/lib/ /usr/lib64 /usr/lib /usr/local/include ${CMAKE_LIBRARY_PATH} PATH_SUFFIXES glib-2.0/include ) FIND_PATH( _glib2_include_DIR NAMES glib.h PATHS /opt/gnome/include /opt/local/include /sw/include /usr/include /usr/local/include PATH_SUFFIXES glib-2.0 ) #MESSAGE(STATUS "Glib headers: ${_glib2_include_DIR}") FIND_LIBRARY( _glib2_link_DIR NAMES glib-2.0 glib PATHS /opt/gnome/lib /opt/local/lib /sw/lib /usr/lib /usr/local/lib ) IF ( _glib2_include_DIR AND _glib2_link_DIR ) SET ( _glib2_FOUND TRUE ) ENDIF ( _glib2_include_DIR AND _glib2_link_DIR ) IF ( _glib2_FOUND ) SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} ) SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} ) SET ( GLIB2_CORE_FOUND TRUE ) ELSE ( _glib2_FOUND ) SET ( GLIB2_CORE_FOUND FALSE ) ENDIF ( _glib2_FOUND ) # Handle dependencies # libintl IF ( NOT LIBINTL_FOUND ) FIND_PATH(LIBINTL_INCLUDE_DIR NAMES libintl.h PATHS /opt/gnome/include /opt/local/include /sw/include /usr/include /usr/local/include ) FIND_LIBRARY(LIBINTL_LIBRARY NAMES intl PATHS /opt/gnome/lib /opt/local/lib /sw/lib /usr/local/lib /usr/lib ) IF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR) SET (LIBINTL_FOUND TRUE) ENDIF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR) ENDIF ( NOT LIBINTL_FOUND ) # libiconv IF ( NOT LIBICONV_FOUND ) FIND_PATH(LIBICONV_INCLUDE_DIR NAMES iconv.h PATHS /opt/gnome/include /opt/local/include /opt/local/include /sw/include /sw/include /usr/local/include /usr/include PATH_SUFFIXES glib-2.0 ) FIND_LIBRARY(LIBICONV_LIBRARY NAMES iconv PATHS /opt/gnome/lib /opt/local/lib /sw/lib /usr/lib /usr/local/lib ) IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) SET (LIBICONV_FOUND TRUE) ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) ENDIF ( NOT LIBICONV_FOUND ) IF (LIBINTL_FOUND) SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY}) SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR}) ENDIF (LIBINTL_FOUND) IF (LIBICONV_FOUND) SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY}) SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR}) ENDIF (LIBICONV_FOUND) ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND ) ## IF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES) SET (GLIB2_FOUND TRUE) ENDIF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES) IF (GLIB2_FOUND) IF (NOT GLIB2_FIND_QUIETLY) MESSAGE (STATUS "Found GLib2: ${GLIB2_LIBRARIES} ${GLIB2_INCLUDE_DIRS}") ENDIF (NOT GLIB2_FIND_QUIETLY) ELSE (GLIB2_FOUND) IF (GLIB2_FIND_REQUIRED) MESSAGE (SEND_ERROR "Could not find GLib2") ENDIF (GLIB2_FIND_REQUIRED) ENDIF (GLIB2_FOUND) # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view MARK_AS_ADVANCED(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES) MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY) MARK_AS_ADVANCED(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY) ENDIF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS) IF ( GLIB2_FOUND ) # Check if system has a newer version of glib # which supports g_regex_match_simple INCLUDE( CheckIncludeFiles ) SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} ) CHECK_INCLUDE_FILES ( glib/gregex.h HAVE_GLIB_GREGEX_H ) # Reset CMAKE_REQUIRED_INCLUDES SET( CMAKE_REQUIRED_INCLUDES "" ) ENDIF( GLIB2_FOUND ) indi-starbook-ten-0.1/cmake_modules/FindATIK.cmake0000644000175100017510000000254014136175546021313 0ustar debiandebian# - Try to find Atik Camera Library # Once done this will define # # ATIK_FOUND - system has ATIK # ATIK_INCLUDE_DIR - the ATIK include directory # ATIK_LIBRARIES - Link these to use ATIK # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (ATIK_INCLUDE_DIR AND ATIK_LIBRARIES) # in cache already set(ATIK_FOUND TRUE) message(STATUS "Found libatik: ${ATIK_LIBRARIES}") else (ATIK_INCLUDE_DIR AND ATIK_LIBRARIES) find_path(ATIK_INCLUDE_DIR AtikCameras.h PATH_SUFFIXES libatik ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(ATIK_LIBRARIES NAMES atikcameras PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(ATIK_INCLUDE_DIR AND ATIK_LIBRARIES) set(ATIK_FOUND TRUE) else (ATIK_INCLUDE_DIR AND ATIK_LIBRARIES) set(ATIK_FOUND FALSE) endif(ATIK_INCLUDE_DIR AND ATIK_LIBRARIES) if (ATIK_FOUND) if (NOT ATIK_FIND_QUIETLY) message(STATUS "Found Atik Library: ${ATIK_LIBRARIES}") endif (NOT ATIK_FIND_QUIETLY) else (ATIK_FOUND) if (ATIK_FIND_REQUIRED) message(FATAL_ERROR "Atik Library not found. Please install Atik Library http://www.indilib.org") endif (ATIK_FIND_REQUIRED) endif (ATIK_FOUND) mark_as_advanced(ATIK_INCLUDE_DIR ATIK_LIBRARIES) endif (ATIK_INCLUDE_DIR AND ATIK_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindALUT.cmake0000644000175100017510000000504214136175546021330 0ustar debiandebian# - Locate ALUT # This module defines # ALUT_LIBRARY # ALUT_FOUND, if false, do not try to link to OpenAL # ALUT_INCLUDE_DIR, where to find the headers # # $OPENALDIR is an environment variable that would # correspond to the ./configure --prefix=$OPENALDIR # used in building OpenAL. # # Created by Bryan Donlan, based on the FindOpenAL.cmake module by Eric Wang. FIND_PATH(ALUT_INCLUDE_DIR alut.h $ENV{OPENALDIR}/include ~/Library/Frameworks/OpenAL.framework/Headers /Library/Frameworks/OpenAL.framework/Headers /System/Library/Frameworks/OpenAL.framework/Headers # Tiger /usr/local/include/AL /usr/local/include/OpenAL /usr/local/include /usr/include/AL /usr/include/OpenAL /usr/include /sw/include/AL # Fink /sw/include/OpenAL /sw/include /opt/local/include/AL # DarwinPorts /opt/local/include/OpenAL /opt/local/include /opt/csw/include/AL # Blastwave /opt/csw/include/OpenAL /opt/csw/include /opt/include/AL /opt/include/OpenAL /opt/include ) # I'm not sure if I should do a special casing for Apple. It is # unlikely that other Unix systems will find the framework path. # But if they do ([Next|Open|GNU]Step?), # do they want the -framework option also? IF(${ALUT_INCLUDE_DIR} MATCHES ".framework") STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" ALUT_FRAMEWORK_PATH_TMP ${ALUT_INCLUDE_DIR}) IF("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks" ) # String is in default search path, don't need to use -F SET (ALUT_LIBRARY "-framework OpenAL" CACHE STRING "OpenAL framework for OSX") ELSE("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks" ) # String is not /Library/Frameworks, need to use -F SET(ALUT_LIBRARY "-F${ALUT_FRAMEWORK_PATH_TMP} -framework OpenAL" CACHE STRING "OpenAL framework for OSX") ENDIF("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks" ) # Clear the temp variable so nobody can see it SET(ALUT_FRAMEWORK_PATH_TMP "" CACHE INTERNAL "") ELSE(${ALUT_INCLUDE_DIR} MATCHES ".framework") FIND_LIBRARY(ALUT_LIBRARY NAMES alut PATHS $ENV{OPENALDIR}/lib $ENV{OPENALDIR}/libs /usr/local/lib /usr/lib /sw/lib /opt/local/lib /opt/csw/lib /opt/lib ) ENDIF(${ALUT_INCLUDE_DIR} MATCHES ".framework") SET(ALUT_FOUND "NO") IF(ALUT_LIBRARY) SET(ALUT_FOUND "YES") ENDIF(ALUT_LIBRARY) indi-starbook-ten-0.1/cmake_modules/FindD2XX.cmake0000644000175100017510000000262014136175546021307 0ustar debiandebian# - Try to find D2XX # Once done this will define # # D2XX_FOUND - system has FTDI # D2XX_INCLUDE_DIR - the FTDI include directory # D2XX_LIBRARIES - Link these to use FTDI # # N.B. You must include the file as following: # #include # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (D2XX_INCLUDE_DIR AND D2XX_LIBRARIES) # in cache already set(D2XX_FOUND TRUE) message(STATUS "Found libfd2xx: ${D2XX_LIBRARIES}") else (D2XX_INCLUDE_DIR AND D2XX_LIBRARIES) find_path(D2XX_INCLUDE_DIR ftd2xx.h #PATH_SUFFIXES libD2XX ${_obIncDir} ${GNUWIN32_DIR}/include /usr/local/include ) find_library(D2XX_LIBRARIES NAMES ftd2xx PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib /usr/local/lib ) if(D2XX_INCLUDE_DIR AND D2XX_LIBRARIES) set(D2XX_FOUND TRUE) else (D2XX_INCLUDE_DIR AND D2XX_LIBRARIES) set(D2XX_FOUND FALSE) endif(D2XX_INCLUDE_DIR AND D2XX_LIBRARIES) if (D2XX_FOUND) if (NOT D2XX_FIND_QUIETLY) message(STATUS "Found D2XX: ${D2XX_LIBRARIES}") endif (NOT D2XX_FIND_QUIETLY) else (D2XX_FOUND) if (D2XX_FIND_REQUIRED) message(FATAL_ERROR "D2XX not found. Please install libd2xx") endif (D2XX_FIND_REQUIRED) endif (D2XX_FOUND) mark_as_advanced(D2XX_INCLUDE_DIR D2XX_LIBRARIES) endif (D2XX_INCLUDE_DIR AND D2XX_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindARAVIS.cmake0000644000175100017510000000272314136175546021553 0ustar debiandebian# - Find the native sqlite3 includes and library # # This module defines # ARV_INCLUDE_DIR, where to find libgphoto2 header files # ARV_LIBRARIES, the libraries to link against to use libgphoto2 # ARV_FOUND, If false, do not try to use libgphoto2. # ARV_VERSION_STRING, e.g. 2.4.14 # ARV_VERSION_MAJOR, e.g. 2 # ARV_VERSION_MINOR, e.g. 4 # ARV_VERSION_PATCH, e.g. 14 # # also defined, but not for general use are # ARV_LIBRARY, where to find the sqlite3 library. #============================================================================= # Copyright 2010 henrik andersson #============================================================================= SET(ARV_FIND_REQUIRED ${Arv_FIND_REQUIRED}) find_path(ARV_INCLUDE_DIR aravis-0.8/arv.h) mark_as_advanced(ARV_INCLUDE_DIR) set(ARV_NAMES ${ARV_NAMES} aravis-0.8) find_library(ARV_LIBRARY NAMES ${ARV_NAMES} ) mark_as_advanced(ARV_LIBRARY) set(ARV_VERSION_MAJOR "0") set(ARV_VERSION_MINOR "8") set(ARV_VERSION_STRING "${ARV_VERSION_MAJOR}.${ARV_VERSION_MINOR}") # handle the QUIETLY and REQUIRED arguments and set ARV_FOUND to TRUE if # all listed variables are TRUE include(FindPackageHandleStandardArgs) find_package_handle_standard_args(ARV DEFAULT_MSG ARV_LIBRARY ARV_INCLUDE_DIR) IF(ARV_FOUND) #SET(Arv_LIBRARIES ${ARV_LIBRARY}) SET(Arv_LIBRARIES "aravis-0.8") SET(Arv_INCLUDE_DIRS "${ARV_INCLUDE_DIR}/aravis-0.8") MESSAGE (STATUS "Found aravis: ${Arv_LIBRARIES} ${Arv_INCLUDE_DIRS}") ENDIF(ARV_FOUND) indi-starbook-ten-0.1/cmake_modules/FindFISHCAMP.cmake0000644000175100017510000000322514136175546021756 0ustar debiandebian# - Try to find FISHCAMP CCD # Once done this will define # # FISHCAMP_FOUND - system has FISHCAMP # FISHCAMP_LIBRARIES - Link these to use FISHCAMP # FISHCAMP_INCLUDE_DIR - Fishcamp include directory # Copyright (c) 2006, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (FISHCAMP_LIBRARIES AND FISHCAMP_INCLUDE_DIR) # in cache already set(FISHCAMP_FOUND TRUE) message(STATUS "Found FISHCAMP: ${FISHCAMP_LIBRARIES}") else (FISHCAMP_LIBRARIES AND FISHCAMP_INCLUDE_DIR) find_library(FISHCAMP_LIBRARIES NAMES fishcamp PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) find_path(FISHCAMP_INCLUDE_DIR fishcamp.h PATH_SUFFIXES libfishcamp ${_obIncDir} ${GNUWIN32_DIR}/include ) set(CMAKE_REQUIRED_LIBRARIES ${FISHCAMP_LIBRARIES}) if(FISHCAMP_LIBRARIES AND FISHCAMP_INCLUDE_DIR) set(FISHCAMP_FOUND TRUE) else (FISHCAMP_LIBRARIES AND FISHCAMP_INCLUDE_DIR) set(FISHCAMP_FOUND FALSE) endif(FISHCAMP_LIBRARIES AND FISHCAMP_INCLUDE_DIR) if (FISHCAMP_FOUND) if (NOT FISHCAMP_FIND_QUIETLY) message(STATUS "Found FISHCAMP: ${FISHCAMP_LIBRARIES}") endif (NOT FISHCAMP_FIND_QUIETLY) else (FISHCAMP_FOUND) if (FISHCAMP_FIND_REQUIRED) message(FATAL_ERROR "FISHCAMP not found. Please install FISHCAMP library. http://www.indilib.org") endif (FISHCAMP_FIND_REQUIRED) endif (FISHCAMP_FOUND) mark_as_advanced(FISHCAMP_LIBRARIES FISHCAMP_INCLUDE_DIR) endif (FISHCAMP_LIBRARIES AND FISHCAMP_INCLUDE_DIR) indi-starbook-ten-0.1/cmake_modules/FindDC1394.cmake0000644000175100017510000000264314136175546021376 0ustar debiandebian# - Try to find dc1394 library (version 2) and include files # Once done this will define # # DC1394_FOUND - system has DC1394 # DC1394_INCLUDE_DIR - the DC1394 include directory # DC1394_LIBRARIES - Link these to use DC1394 # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (DC1394_INCLUDE_DIR AND DC1394_LIBRARIES) # in cache already set(DC1394_FOUND TRUE) message(STATUS "Found libdc1394: ${DC1394_LIBRARIES}") else (DC1394_INCLUDE_DIR AND DC1394_LIBRARIES) find_path(DC1394_INCLUDE_DIR control.h PATH_SUFFIXES dc1394 ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(DC1394_LIBRARIES NAMES dc1394 PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(DC1394_INCLUDE_DIR AND DC1394_LIBRARIES) set(DC1394_FOUND TRUE) else (DC1394_INCLUDE_DIR AND DC1394_LIBRARIES) set(DC1394_FOUND FALSE) endif(DC1394_INCLUDE_DIR AND DC1394_LIBRARIES) if (DC1394_FOUND) if (NOT DC1394_FIND_QUIETLY) message(STATUS "Found DC1394: ${DC1394_LIBRARIES}") endif (NOT DC1394_FIND_QUIETLY) else (DC1394_FOUND) if (DC1394_FIND_REQUIRED) message(FATAL_ERROR "DC1394 not found. Please install libdc1394 development package.") endif (DC1394_FIND_REQUIRED) endif (DC1394_FOUND) mark_as_advanced(DC1394_INCLUDE_DIR DC1394_LIBRARIES) endif (DC1394_INCLUDE_DIR AND DC1394_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindTIFFXX.cmake0000644000175100017510000000176314136175546021601 0ustar debiandebian# - Try to find TIFFXX Library # Once done this will define # # TIFXX_LIBRARY - Link these to use TIFFXX # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (TIFFXX_LIBRARY) # in cache already set(TIFFXX_FOUND TRUE) message(STATUS "Found libtiffxx: ${TIFFXX_LIBRARY}") else (TIFFXX_LIBRARY) find_library(TIFFXX_LIBRARY NAMES tiffxx PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(TIFFXX_LIBRARY) set(TIFFXX_FOUND TRUE) else (TIFFXX_LIBRARY) set(TIFFXX_FOUND FALSE) endif(TIFFXX_LIBRARY) if (TIFFXX_FOUND) if (NOT TIFFXX_FIND_QUIETLY) message(STATUS "Found tiffxx: ${TIFFXX_LIBRARY}") endif (NOT TIFFXX_FIND_QUIETLY) else (TIFFXX_FOUND) if (TIFFXX_FIND_REQUIRED) message(FATAL_ERROR "tiffxx is not found. Please install it first.") endif (TIFFXX_FIND_REQUIRED) endif (TIFFXX_FOUND) mark_as_advanced(TIFFXX_LIBRARY) endif (TIFFXX_LIBRARY) indi-starbook-ten-0.1/cmake_modules/FindGSL.cmake0000644000175100017510000002224114136175546021210 0ustar debiandebian#.rst: # FindGSL # -------- # # Find the native GSL includes and libraries. # # The GNU Scientific Library (GSL) is a numerical library for C and C++ # programmers. It is free software under the GNU General Public # License. # # Imported Targets # ^^^^^^^^^^^^^^^^ # # If GSL is found, this module defines the following :prop_tgt:`IMPORTED` # targets:: # # GSL::gsl - The main GSL library. # GSL::gslcblas - The CBLAS support library used by GSL. # # Result Variables # ^^^^^^^^^^^^^^^^ # # This module will set the following variables in your project:: # # GSL_FOUND - True if GSL found on the local system # GSL_INCLUDE_DIRS - Location of GSL header files. # GSL_LIBRARIES - The GSL libraries. # GSL_VERSION - The version of the discovered GSL install. # # Hints # ^^^^^ # # Set ``GSL_ROOT_DIR`` to a directory that contains a GSL installation. # # This script expects to find libraries at ``$GSL_ROOT_DIR/lib`` and the GSL # headers at ``$GSL_ROOT_DIR/include/gsl``. The library directory may # optionally provide Release and Debug folders. For Unix-like systems, this # script will use ``$GSL_ROOT_DIR/bin/gsl-config`` (if found) to aid in the # discovery GSL. # # Cache Variables # ^^^^^^^^^^^^^^^ # # This module may set the following variables depending on platform and type # of GSL installation discovered. These variables may optionally be set to # help this module find the correct files:: # # GSL_CLBAS_LIBRARY - Location of the GSL CBLAS library. # GSL_CBLAS_LIBRARY_DEBUG - Location of the debug GSL CBLAS library (if any). # GSL_CONFIG_EXECUTABLE - Location of the ``gsl-config`` script (if any). # GSL_LIBRARY - Location of the GSL library. # GSL_LIBRARY_DEBUG - Location of the debug GSL library (if any). # #============================================================================= # Copyright 2014 Kelly Thompson # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) # Include these modules to handle the QUIETLY and REQUIRED arguments. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) #============================================================================= # If the user has provided ``GSL_ROOT_DIR``, use it! Choose items found # at this location over system locations. if( EXISTS "$ENV{GSL_ROOT_DIR}" ) file( TO_CMAKE_PATH "$ENV{GSL_ROOT_DIR}" GSL_ROOT_DIR ) set( GSL_ROOT_DIR "${GSL_ROOT_DIR}" CACHE PATH "Prefix for GSL installation." ) endif() if( NOT EXISTS "${GSL_ROOT_DIR}" ) set( GSL_USE_PKGCONFIG ON ) endif() #============================================================================= # As a first try, use the PkgConfig module. This will work on many # *NIX systems. See :module:`findpkgconfig` # This will return ``GSL_INCLUDEDIR`` and ``GSL_LIBDIR`` used below. if( GSL_USE_PKGCONFIG ) find_package(PkgConfig) pkg_check_modules( GSL QUIET gsl ) if( EXISTS "${GSL_INCLUDEDIR}" ) get_filename_component( GSL_ROOT_DIR "${GSL_INCLUDEDIR}" DIRECTORY CACHE) endif() endif() #============================================================================= # Set GSL_INCLUDE_DIRS and GSL_LIBRARIES. If we skipped the PkgConfig step, try # to find the libraries at $GSL_ROOT_DIR (if provided) or in standard system # locations. These find_library and find_path calls will prefer custom # locations over standard locations (HINTS). If the requested file is not found # at the HINTS location, standard system locations will be still be searched # (/usr/lib64 (Redhat), lib/i386-linux-gnu (Debian)). find_path( GSL_INCLUDE_DIR NAMES gsl/gsl_sf.h HINTS ${GSL_ROOT_DIR}/include ${GSL_INCLUDEDIR} ) find_library( GSL_LIBRARY NAMES gsl HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} PATH_SUFFIXES Release Debug ) find_library( GSL_CBLAS_LIBRARY NAMES gslcblas cblas HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} PATH_SUFFIXES Release Debug ) # Do we also have debug versions? find_library( GSL_LIBRARY_DEBUG NAMES gsl HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} PATH_SUFFIXES Debug ) find_library( GSL_CBLAS_LIBRARY_DEBUG NAMES gslcblas cblas HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} PATH_SUFFIXES Debug ) set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} ) set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ) # If we didn't use PkgConfig, try to find the version via gsl-config or by # reading gsl_version.h. if( NOT GSL_VERSION ) # 1. If gsl-config exists, query for the version. find_program( GSL_CONFIG_EXECUTABLE NAMES gsl-config HINTS "${GSL_ROOT_DIR}/bin" ) if( EXISTS "${GSL_CONFIG_EXECUTABLE}" ) execute_process( COMMAND "${GSL_CONFIG_EXECUTABLE}" --version OUTPUT_VARIABLE GSL_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) endif() # 2. If gsl-config is not available, try looking in gsl/gsl_version.h if( NOT GSL_VERSION AND EXISTS "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" ) file( STRINGS "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" gsl_version_h_contents REGEX "define GSL_VERSION" ) string( REGEX REPLACE ".*([0-9].[0-9][0-9]).*" "\\1" GSL_VERSION ${gsl_version_h_contents} ) endif() # might also try scraping the directory name for a regex match "gsl-X.X" endif() #============================================================================= # handle the QUIETLY and REQUIRED arguments and set GSL_FOUND to TRUE if all # listed variables are TRUE find_package_handle_standard_args( GSL FOUND_VAR GSL_FOUND REQUIRED_VARS GSL_INCLUDE_DIR GSL_LIBRARY GSL_CBLAS_LIBRARY VERSION_VAR GSL_VERSION ) mark_as_advanced( GSL_ROOT_DIR GSL_VERSION GSL_LIBRARY GSL_INCLUDE_DIR GSL_CBLAS_LIBRARY GSL_LIBRARY_DEBUG GSL_CBLAS_LIBRARY_DEBUG GSL_USE_PKGCONFIG GSL_CONFIG ) #============================================================================= # Register imported libraries: # 1. If we can find a Windows .dll file (or if we can find both Debug and # Release libraries), we will set appropriate target properties for these. # 2. However, for most systems, we will only register the import location and # include directory. # Look for dlls, or Release and Debug libraries. if(WIN32) string( REPLACE ".lib" ".dll" GSL_LIBRARY_DLL "${GSL_LIBRARY}" ) string( REPLACE ".lib" ".dll" GSL_CBLAS_LIBRARY_DLL "${GSL_CBLAS_LIBRARY}" ) string( REPLACE ".lib" ".dll" GSL_LIBRARY_DEBUG_DLL "${GSL_LIBRARY_DEBUG}" ) string( REPLACE ".lib" ".dll" GSL_CBLAS_LIBRARY_DEBUG_DLL "${GSL_CBLAS_LIBRARY_DEBUG}" ) endif() if( GSL_FOUND AND NOT TARGET GSL::gsl ) if( EXISTS "${GSL_LIBRARY_DLL}" AND EXISTS "${GSL_CBLAS_LIBRARY_DLL}") # Windows systems with dll libraries. add_library( GSL::gsl SHARED IMPORTED ) add_library( GSL::gslcblas SHARED IMPORTED ) # Windows with dlls, but only Release libraries. set_target_properties( GSL::gslcblas PROPERTIES IMPORTED_LOCATION_RELEASE "${GSL_CBLAS_LIBRARY_DLL}" IMPORTED_IMPLIB "${GSL_CBLAS_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" IMPORTED_CONFIGURATIONS Release IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) set_target_properties( GSL::gsl PROPERTIES IMPORTED_LOCATION_RELEASE "${GSL_LIBRARY_DLL}" IMPORTED_IMPLIB "${GSL_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" IMPORTED_CONFIGURATIONS Release IMPORTED_LINK_INTERFACE_LANGUAGES "C" INTERFACE_LINK_LIBRARIES GSL::gslcblas ) # If we have both Debug and Release libraries if( EXISTS "${GSL_LIBRARY_DEBUG_DLL}" AND EXISTS "${GSL_CBLAS_LIBRARY_DEBUG_DLL}") set_property( TARGET GSL::gslcblas APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) set_target_properties( GSL::gslcblas PROPERTIES IMPORTED_LOCATION_DEBUG "${GSL_CBLAS_LIBRARY_DEBUG_DLL}" IMPORTED_IMPLIB_DEBUG "${GSL_CBLAS_LIBRARY_DEBUG}" ) set_property( TARGET GSL::gsl APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) set_target_properties( GSL::gsl PROPERTIES IMPORTED_LOCATION_DEBUG "${GSL_LIBRARY_DEBUG_DLL}" IMPORTED_IMPLIB_DEBUG "${GSL_LIBRARY_DEBUG}" ) endif() else() # For all other environments (ones without dll libraries), create # the imported library targets. add_library( GSL::gsl UNKNOWN IMPORTED ) add_library( GSL::gslcblas UNKNOWN IMPORTED ) set_target_properties( GSL::gslcblas PROPERTIES IMPORTED_LOCATION "${GSL_CBLAS_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) set_target_properties( GSL::gsl PROPERTIES IMPORTED_LOCATION "${GSL_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" IMPORTED_LINK_INTERFACE_LANGUAGES "C" INTERFACE_LINK_LIBRARIES GSL::gslcblas ) endif() endif() indi-starbook-ten-0.1/cmake_modules/FindMICAM.cmake0000644000175100017510000000256714136175546021422 0ustar debiandebian# - Try to find Moravian Instruments Camera Library # Once done this will define # # MICAM_FOUND - system has MI # MICAM_INCLUDE_DIR - the MI include directory # MICAM_LIBRARIES - Link these to use MI # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (MICAM_INCLUDE_DIR AND MICAM_LIBRARIES) # in cache already set(MICAM_FOUND TRUE) message(STATUS "Found libmicam: ${MICAM_LIBRARIES}") else (MICAM_INCLUDE_DIR AND MICAM_LIBRARIES) find_path(MICAM_INCLUDE_DIR gxccd.h PATH_SUFFIXES libmicam ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(MICAM_LIBRARIES NAMES gxccd PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(MICAM_INCLUDE_DIR AND MICAM_LIBRARIES) set(MICAM_FOUND TRUE) else (MICAM_INCLUDE_DIR AND MICAM_LIBRARIES) set(MICAM_FOUND FALSE) endif(MICAM_INCLUDE_DIR AND MICAM_LIBRARIES) if (MICAM_FOUND) if (NOT MICAM_FIND_QUIETLY) message(STATUS "Found MI Library: ${MICAM_LIBRARIES}") endif (NOT MICAM_FIND_QUIETLY) else (MICAM_FOUND) if (MICAM_FIND_REQUIRED) message(FATAL_ERROR "MI Library not found. Please install MI Library http://www.indilib.org") endif (MICAM_FIND_REQUIRED) endif (MICAM_FOUND) mark_as_advanced(MICAM_INCLUDE_DIR MICAM_LIBRARIES) endif (MICAM_INCLUDE_DIR AND MICAM_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindPackageHandleStandardArgs.cmake0000644000175100017510000003565714136175546025547 0ustar debiandebian#[=======================================================================[.rst: FindPackageHandleStandardArgs ----------------------------- This module provides a function intended to be used in :ref:`Find Modules` implementing :command:`find_package()` calls. It handles the ``REQUIRED``, ``QUIET`` and version-related arguments of ``find_package``. It also sets the ``_FOUND`` variable. The package is considered found if all variables listed contain valid results, e.g. valid filepaths. .. command:: find_package_handle_standard_args There are two signatures:: find_package_handle_standard_args( (DEFAULT_MSG|) ... ) find_package_handle_standard_args( [FOUND_VAR ] [REQUIRED_VARS ...] [VERSION_VAR ] [HANDLE_COMPONENTS] [CONFIG_MODE] [FAIL_MESSAGE ] ) The ``_FOUND`` variable will be set to ``TRUE`` if all the variables ``...`` are valid and any optional constraints are satisfied, and ``FALSE`` otherwise. A success or failure message may be displayed based on the results and on whether the ``REQUIRED`` and/or ``QUIET`` option was given to the :command:`find_package` call. The options are: ``(DEFAULT_MSG|)`` In the simple signature this specifies the failure message. Use ``DEFAULT_MSG`` to ask for a default message to be computed (recommended). Not valid in the full signature. ``FOUND_VAR `` Obsolete. Specifies either ``_FOUND`` or ``_FOUND`` as the result variable. This exists only for compatibility with older versions of CMake and is now ignored. Result variables of both names are always set for compatibility. ``REQUIRED_VARS ...`` Specify the variables which are required for this package. These may be named in the generated failure message asking the user to set the missing variable values. Therefore these should typically be cache entries such as ``FOO_LIBRARY`` and not output variables like ``FOO_LIBRARIES``. ``VERSION_VAR `` Specify the name of a variable that holds the version of the package that has been found. This version will be checked against the (potentially) specified required version given to the :command:`find_package` call, including its ``EXACT`` option. The default messages include information about the required version and the version which has been actually found, both if the version is ok or not. ``HANDLE_COMPONENTS`` Enable handling of package components. In this case, the command will report which components have been found and which are missing, and the ``_FOUND`` variable will be set to ``FALSE`` if any of the required components (i.e. not the ones listed after the ``OPTIONAL_COMPONENTS`` option of :command:`find_package`) are missing. ``CONFIG_MODE`` Specify that the calling find module is a wrapper around a call to ``find_package( NO_MODULE)``. This implies a ``VERSION_VAR`` value of ``_VERSION``. The command will automatically check whether the package configuration file was found. ``FAIL_MESSAGE `` Specify a custom failure message instead of using the default generated message. Not recommended. Example for the simple signature: .. code-block:: cmake find_package_handle_standard_args(LibXml2 DEFAULT_MSG LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) The ``LibXml2`` package is considered to be found if both ``LIBXML2_LIBRARY`` and ``LIBXML2_INCLUDE_DIR`` are valid. Then also ``LibXml2_FOUND`` is set to ``TRUE``. If it is not found and ``REQUIRED`` was used, it fails with a :command:`message(FATAL_ERROR)`, independent whether ``QUIET`` was used or not. If it is found, success will be reported, including the content of the first ````. On repeated CMake runs, the same message will not be printed again. Example for the full signature: .. code-block:: cmake find_package_handle_standard_args(LibArchive REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR VERSION_VAR LibArchive_VERSION) In this case, the ``LibArchive`` package is considered to be found if both ``LibArchive_LIBRARY`` and ``LibArchive_INCLUDE_DIR`` are valid. Also the version of ``LibArchive`` will be checked by using the version contained in ``LibArchive_VERSION``. Since no ``FAIL_MESSAGE`` is given, the default messages will be printed. Another example for the full signature: .. code-block:: cmake find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) find_package_handle_standard_args(Automoc4 CONFIG_MODE) In this case, a ``FindAutmoc4.cmake`` module wraps a call to ``find_package(Automoc4 NO_MODULE)`` and adds an additional search directory for ``automoc4``. Then the call to ``find_package_handle_standard_args`` produces a proper success/failure message. #]=======================================================================] #============================================================================= # Copyright 2007-2009 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake) include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake) # internal helper macro macro(_FPHSA_FAILURE_MESSAGE _msg) if (${_NAME}_FIND_REQUIRED) message(FATAL_ERROR "${_msg}") else () if (NOT ${_NAME}_FIND_QUIETLY) message(STATUS "${_msg}") endif () endif () endmacro() # internal helper macro to generate the failure message when used in CONFIG_MODE: macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) # _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found: if(${_NAME}_CONFIG) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing: ${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})") else() # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version. # List them all in the error message: if(${_NAME}_CONSIDERED_CONFIGS) set(configsText "") list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) math(EXPR configsCount "${configsCount} - 1") foreach(currentConfigIndex RANGE ${configsCount}) list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) set(configsText "${configsText} ${filename} (version ${version})\n") endforeach() if (${_NAME}_NOT_FOUND_MESSAGE) set(configsText "${configsText} Reason given by package: ${${_NAME}_NOT_FOUND_MESSAGE}\n") endif() _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") else() # Simple case: No Config-file was found at all: _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}") endif() endif() endmacro() function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in # new extended or in the "old" mode: set(options CONFIG_MODE HANDLE_COMPONENTS) set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR) set(multiValueArgs REQUIRED_VARS) set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) if(${INDEX} EQUAL -1) set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) set(FPHSA_REQUIRED_VARS ${ARGN}) set(FPHSA_VERSION_VAR) else() CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) if(FPHSA_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") endif() if(NOT FPHSA_FAIL_MESSAGE) set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") endif() endif() # now that we collected all arguments, process them if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG") set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") endif() # In config-mode, we rely on the variable _CONFIG, which is set by find_package() # when it successfully found the config-file, including version checking: if(FPHSA_CONFIG_MODE) list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) set(FPHSA_VERSION_VAR ${_NAME}_VERSION) endif() if(NOT FPHSA_REQUIRED_VARS) message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") endif() list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) string(TOUPPER ${_NAME} _NAME_UPPER) string(TOLOWER ${_NAME} _NAME_LOWER) if(FPHSA_FOUND_VAR) if(FPHSA_FOUND_VAR MATCHES "^${_NAME}_FOUND$" OR FPHSA_FOUND_VAR MATCHES "^${_NAME_UPPER}_FOUND$") set(_FOUND_VAR ${FPHSA_FOUND_VAR}) else() message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_NAME}_FOUND\" and \"${_NAME_UPPER}_FOUND\" are valid names.") endif() else() set(_FOUND_VAR ${_NAME_UPPER}_FOUND) endif() # collect all variables which were not found, so they can be printed, so the # user knows better what went wrong (#6375) set(MISSING_VARS "") set(DETAILS "") # check if all passed variables are valid set(FPHSA_FOUND_${_NAME} TRUE) foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) if(NOT ${_CURRENT_VAR}) set(FPHSA_FOUND_${_NAME} FALSE) set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") else() set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") endif() endforeach() if(FPHSA_FOUND_${_NAME}) set(${_NAME}_FOUND TRUE) set(${_NAME_UPPER}_FOUND TRUE) else() set(${_NAME}_FOUND FALSE) set(${_NAME_UPPER}_FOUND FALSE) endif() # component handling unset(FOUND_COMPONENTS_MSG) unset(MISSING_COMPONENTS_MSG) if(FPHSA_HANDLE_COMPONENTS) foreach(comp ${${_NAME}_FIND_COMPONENTS}) if(${_NAME}_${comp}_FOUND) if(NOT DEFINED FOUND_COMPONENTS_MSG) set(FOUND_COMPONENTS_MSG "found components: ") endif() set(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}") else() if(NOT DEFINED MISSING_COMPONENTS_MSG) set(MISSING_COMPONENTS_MSG "missing components: ") endif() set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") if(${_NAME}_FIND_REQUIRED_${comp}) set(${_NAME}_FOUND FALSE) set(MISSING_VARS "${MISSING_VARS} ${comp}") endif() endif() endforeach() set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}") set(DETAILS "${DETAILS}[c${COMPONENT_MSG}]") endif() # version handling: set(VERSION_MSG "") set(VERSION_OK TRUE) set(VERSION ${${FPHSA_VERSION_VAR}}) # check with DEFINED here as the requested or found version may be "0" if (DEFINED ${_NAME}_FIND_VERSION) if(DEFINED ${FPHSA_VERSION_VAR}) if(${_NAME}_FIND_VERSION_EXACT) # exact version required # count the dots in the version string string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}") # add one dot because there is one dot more than there are components string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS) if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT) # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT # is at most 4 here. Therefore a simple lookup table is used. if (${_NAME}_FIND_VERSION_COUNT EQUAL 1) set(_VERSION_REGEX "[^.]*") elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2) set(_VERSION_REGEX "[^.]*\\.[^.]*") elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3) set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*") else () set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") endif () string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}") unset(_VERSION_REGEX) if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD) set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") set(VERSION_OK FALSE) else () set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") endif () unset(_VERSION_HEAD) else () if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL VERSION) set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") set(VERSION_OK FALSE) else () set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") endif () endif () unset(_VERSION_DOTS) else() # minimum version specified: if (${_NAME}_FIND_VERSION VERSION_GREATER VERSION) set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") set(VERSION_OK FALSE) else () set(VERSION_MSG "(found suitable version \"${VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") endif () endif() else() # if the package was not found, but a version was given, add that to the output: if(${_NAME}_FIND_VERSION_EXACT) set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") else() set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") endif() endif() else () if(VERSION) set(VERSION_MSG "(found version \"${VERSION}\")") endif() endif () if(VERSION_OK) set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") else() set(${_NAME}_FOUND FALSE) endif() # print the result: if (${_NAME}_FOUND) FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") else () if(FPHSA_CONFIG_MODE) _FPHSA_HANDLE_FAILURE_CONFIG_MODE() else() if(NOT VERSION_OK) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") else() _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") endif() endif() endif () set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) endfunction() indi-starbook-ten-0.1/cmake_modules/FindOggTheora.cmake0000644000175100017510000000247214136175546022446 0ustar debiandebian# # Find the native Ogg/Theora includes and libraries # # This module defines # OGGTHEORA_INCLUDE_DIR, where to find ogg/ogg.h and theora/theora.h # OGGTHEORA_LIBRARIES, the libraries to link against to use Ogg/Theora. # OGGTHEORA_FOUND, If false, do not try to use Ogg/Theora. FIND_PATH(OGGTHEORA_ogg_INCLUDE_DIR ogg/ogg.h) FIND_PATH(OGGTHEORA_theora_INCLUDE_DIR theora/theora.h) FIND_LIBRARY(OGGTHEORA_ogg_LIBRARY ogg) FIND_LIBRARY(OGGTHEORA_theoraenc_LIBRARY theoraenc) FIND_LIBRARY(OGGTHEORA_theoradec_LIBRARY theoradec) SET(OGGTHEORA_INCLUDE_DIRS ${OGGTHEORA_ogg_INCLUDE_DIR} ${OGGTHEORA_theora_INCLUDE_DIR} ) #HACK multiple directories SET(OGGTHEORA_INCLUDE_DIR ${OGGTHEORA_INCLUDE_DIRS}) SET(OGGTHEORA_LIBRARIES ${OGGTHEORA_theoraenc_LIBRARY} ${OGGTHEORA_theoradec_LIBRARY} ${OGGTHEORA_ogg_LIBRARY} ) #HACK multiple libraries SET(OGGTHEORA_LIBRARY ${OGGTHEORA_LIBRARIES}) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGGTHEORA "Could NOT find the ogg and theora libraries" OGGTHEORA_ogg_LIBRARY OGGTHEORA_theoraenc_LIBRARY OGGTHEORA_theoradec_LIBRARY OGGTHEORA_ogg_INCLUDE_DIR OGGTHEORA_theora_INCLUDE_DIR ) MARK_AS_ADVANCED(OGGTHEORA_ogg_INCLUDE_DIR OGGTHEORA_theora_INCLUDE_DIR OGGTHEORA_ogg_LIBRARY OGGTHEORA_theoraenc_LIBRARY OGGTHEORA_theoradec_LIBRARY ) indi-starbook-ten-0.1/cmake_modules/FindMEADE.cmake0000644000175100017510000000247714136175546021407 0ustar debiandebian# - Try to find Meade DSI Library. # Once done this will define # # MEADEDSI_FOUND - system has Meade DSI # MEADEDSI_LIBRARIES - Link these to use Meade DSI # Copyright (c) 2006, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (MEADEDSI_LIBRARIES) # in cache already set(MEADEDSI_FOUND TRUE) message(STATUS "Found MEADEDSI: ${MEADEDSI_LIBRARIES}") else (MEADEDSI_LIBRARIES) find_library(MEADEDSI_LIBRARIES NAMES dsi PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) set(CMAKE_REQUIRED_LIBRARIES ${MEADEDSI_LIBRARIES}) if(MEADEDSI_LIBRARIES) set(MEADEDSI_FOUND TRUE) else (MEADEDSI_LIBRARIES) set(MEADEDSI_FOUND FALSE) endif(MEADEDSI_LIBRARIES) if (MEADEDSI_FOUND) if (NOT MEADEDSI_FIND_QUIETLY) message(STATUS "Found Meade DSI: ${MEADEDSI_LIBRARIES}") endif (NOT MEADEDSI_FIND_QUIETLY) else (MEADEDSI_FOUND) if (MEADEDSI_FIND_REQUIRED) message(FATAL_ERROR "Meade DSI not found. Please install Meade DSI library. http://linuxdsi.sourceforge.net") endif (MEADEDSI_FIND_REQUIRED) endif (MEADEDSI_FOUND) mark_as_advanced(MEADEDSI_LIBRARIES) endif (MEADEDSI_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindTOUPCAM.cmake0000644000175100017510000000267614136175546021705 0ustar debiandebian# - Try to find Toupcam Camera Library # Once done this will define # # TOUPCAM_FOUND - system has Toupcam # TOUPCAM_INCLUDE_DIR - the Toupcam include directory # TOUPCAM_LIBRARIES - Link these to use Toupcam # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (TOUPCAM_INCLUDE_DIR AND TOUPCAM_LIBRARIES) # in cache already set(TOUPCAM_FOUND TRUE) message(STATUS "Found libsbig: ${TOUPCAM_LIBRARIES}") else (TOUPCAM_INCLUDE_DIR AND TOUPCAM_LIBRARIES) find_path(TOUPCAM_INCLUDE_DIR toupcam.h PATH_SUFFIXES libtoupcam ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(TOUPCAM_LIBRARIES NAMES toupcam PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(TOUPCAM_INCLUDE_DIR AND TOUPCAM_LIBRARIES) set(TOUPCAM_FOUND TRUE) else (TOUPCAM_INCLUDE_DIR AND TOUPCAM_LIBRARIES) set(TOUPCAM_FOUND FALSE) endif(TOUPCAM_INCLUDE_DIR AND TOUPCAM_LIBRARIES) if (TOUPCAM_FOUND) if (NOT TOUPCAM_FIND_QUIETLY) message(STATUS "Found Toupcam: ${TOUPCAM_LIBRARIES}") endif (NOT TOUPCAM_FIND_QUIETLY) else (TOUPCAM_FOUND) if (TOUPCAM_FIND_REQUIRED) message(FATAL_ERROR "Toupcam not found. Please install Toupcam Library http://www.indilib.org") endif (TOUPCAM_FIND_REQUIRED) endif (TOUPCAM_FOUND) mark_as_advanced(TOUPCAM_INCLUDE_DIR TOUPCAM_LIBRARIES) endif (TOUPCAM_INCLUDE_DIR AND TOUPCAM_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindSV305.cmake0000644000175100017510000000264614136175546021352 0ustar debiandebian# - Try to find SV305 Library # Once done this will define # # SV305_FOUND - system has QHY # SV305_INCLUDE_DIR - the QHY include directory # SV305_LIBRARIES - Link these to use QHY # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (SV305_INCLUDE_DIR AND SV305_LIBRARIES) # in cache already set(SV305_FOUND TRUE) message(STATUS "Found libsv305: ${SV305_LIBRARIES}") else (SV305_INCLUDE_DIR AND SV305_LIBRARIES) # find headers find_path(SV305_INCLUDE_DIR NAMES SVBCameraSDK.h PATH_SUFFIXES libsv305 ${_obIncDir} ${GNUWIN32_DIR}/include ) # find libraries find_library(SV305_LIBRARIES NAMES SVBCameraSDK PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(SV305_INCLUDE_DIR AND SV305_LIBRARIES) set(SV305_FOUND TRUE) else (SV305_INCLUDE_DIR AND SV305_LIBRARIES) set(SV305_FOUND FALSE) endif(SV305_INCLUDE_DIR AND SV305_LIBRARIES) if (SV305_FOUND) if (NOT SV305_FIND_QUIETLY) message(STATUS "Found SV305 libraries : ${SV305_LIBRARIES}") endif (NOT SV305_FIND_QUIETLY) else (SV305_FOUND) if (SV305_FIND_REQUIRED) message(FATAL_ERROR "SV305 libraries not found. Please install libsv305 http://www.indilib.org") endif (SV305_FIND_REQUIRED) endif (SV305_FOUND) mark_as_advanced(SV305_INCLUDE_DIR SV305_LIBRARIES) endif (SV305_INCLUDE_DIR AND SV305_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindQSI.cmake0000644000175100017510000000245514136175546021224 0ustar debiandebian# - Try to find Quantum Scientific Imaging Library # Once done this will define # # QSI_FOUND - system has QSI # QSI_INCLUDE_DIR - the QSI include directory # QSI_LIBRARIES - Link these to use QSI # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (QSI_INCLUDE_DIR AND QSI_LIBRARIES) # in cache already set(QSI_FOUND TRUE) message(STATUS "Found libqsiapi: ${QSI_LIBRARIES}") else (QSI_INCLUDE_DIR AND QSI_LIBRARIES) find_path(QSI_INCLUDE_DIR qsiapi.h PATH_SUFFIXES qsiapi ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(QSI_LIBRARIES NAMES qsiapi PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(QSI_INCLUDE_DIR AND QSI_LIBRARIES) set(QSI_FOUND TRUE) else (QSI_INCLUDE_DIR AND QSI_LIBRARIES) set(QSI_FOUND FALSE) endif(QSI_INCLUDE_DIR AND QSI_LIBRARIES) if (QSI_FOUND) if (NOT QSI_FIND_QUIETLY) message(STATUS "Found QSI: ${QSI_LIBRARIES}") endif (NOT QSI_FIND_QUIETLY) else (QSI_FOUND) if (QSI_FIND_REQUIRED) message(FATAL_ERROR "QSI not found. Please install libqsi http://www.indilib.org") endif (QSI_FIND_REQUIRED) endif (QSI_FOUND) mark_as_advanced(QSI_INCLUDE_DIR QSI_LIBRARIES) endif (QSI_INCLUDE_DIR AND QSI_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/UnityBuild.cmake0000644000175100017510000001627714136175546022066 0ustar debiandebian# # Copyright (c) 2009-2012 Christoph Heindl # Copyright (c) 2015 Csaba Kertész (csaba.kertesz@gmail.com) # 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 the 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 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. # MACRO (COMMIT_UNITY_FILE UNITY_FILE FILE_CONTENT) SET(DIRTY FALSE) # Check if the build file exists SET(OLD_FILE_CONTENT "") IF (NOT EXISTS ${${UNITY_FILE}} AND NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${${UNITY_FILE}}) SET(DIRTY TRUE) ELSE () # Check the file content FILE(STRINGS ${${UNITY_FILE}} OLD_FILE_CONTENT) STRING(REPLACE ";" "" OLD_FILE_CONTENT "${OLD_FILE_CONTENT}") STRING(REPLACE "\n" "" NEW_CONTENT "${${FILE_CONTENT}}") STRING(COMPARE EQUAL "${OLD_FILE_CONTENT}" "${NEW_CONTENT}" EQUAL_CHECK) IF (NOT EQUAL_CHECK EQUAL 1) SET(DIRTY TRUE) ENDIF () ENDIF () IF (DIRTY MATCHES TRUE) MESSAGE(STATUS "Write Unity Build file: " ${${UNITY_FILE}}) FILE(WRITE ${${UNITY_FILE}} "${${FILE_CONTENT}}") ENDIF () # Create a dummy copy of the unity file to trigger CMake reconfigure if it is deleted. SET(UNITY_FILE_PATH "") SET(UNITY_FILE_NAME "") GET_FILENAME_COMPONENT(UNITY_FILE_PATH ${${UNITY_FILE}} PATH) GET_FILENAME_COMPONENT(UNITY_FILE_NAME ${${UNITY_FILE}} NAME) CONFIGURE_FILE(${${UNITY_FILE}} ${UNITY_FILE_PATH}/CMakeFiles/${UNITY_FILE_NAME}.dummy) ENDMACRO () MACRO (ENABLE_UNITY_BUILD TARGET_NAME SOURCE_VARIABLE_NAME UNIT_SIZE EXTENSION) # Limit is zero based conversion of unit_size MATH(EXPR LIMIT ${UNIT_SIZE}-1) SET(FILES ${SOURCE_VARIABLE_NAME}) # Effectivly ignore the source files from the build, but keep track them for changes. SET_SOURCE_FILES_PROPERTIES(${${FILES}} PROPERTIES HEADER_FILE_ONLY true) # Counts the number of source files up to the threshold SET(COUNTER ${LIMIT}) # Have one or more unity build files SET(FILE_NUMBER 0) SET(BUILD_FILE "") SET(BUILD_FILE_CONTENT "") SET(UNITY_BUILD_FILES "") SET(_DEPS "") FOREACH (SOURCE_FILE ${${FILES}}) IF (COUNTER EQUAL LIMIT) SET(_DEPS "") # Write the actual Unity Build file IF (NOT ${BUILD_FILE} STREQUAL "" AND NOT ${BUILD_FILE_CONTENT} STREQUAL "") COMMIT_UNITY_FILE(BUILD_FILE BUILD_FILE_CONTENT) ENDIF () SET(UNITY_BUILD_FILES ${UNITY_BUILD_FILES} ${BUILD_FILE}) # Set the variables for the current Unity Build file SET(BUILD_FILE ${CMAKE_CURRENT_BINARY_DIR}/unitybuild_${FILE_NUMBER}_${TARGET_NAME}.${EXTENSION}) SET(BUILD_FILE_CONTENT "// Unity Build file generated by CMake\n") MATH(EXPR FILE_NUMBER ${FILE_NUMBER}+1) SET(COUNTER 0) ENDIF () # Add source path to the file name if it is not there yet. SET(FINAL_SOURCE_FILE "") SET(SOURCE_PATH "") GET_FILENAME_COMPONENT(SOURCE_PATH ${SOURCE_FILE} PATH) IF (SOURCE_PATH STREQUAL "" OR NOT EXISTS ${SOURCE_FILE}) SET(FINAL_SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}) ELSE () SET(FINAL_SOURCE_FILE ${SOURCE_FILE}) ENDIF () # Treat only the existing files or moc_*.cpp files STRING(FIND ${SOURCE_FILE} "moc_" MOC_POS) IF (EXISTS ${FINAL_SOURCE_FILE} OR MOC_POS GREATER -1) # Add md5 hash of the source file (except moc files) to the build file content IF (MOC_POS LESS 0) SET(MD5_HASH "") FILE(MD5 ${FINAL_SOURCE_FILE} MD5_HASH) SET(BUILD_FILE_CONTENT "${BUILD_FILE_CONTENT}// md5: ${MD5_HASH}\n") ENDIF () # Add the source file to the build file content IF (MOC_POS GREATER -1) SET(BUILD_FILE_CONTENT "${BUILD_FILE_CONTENT}#include <${SOURCE_FILE}>\n") ELSE () SET(BUILD_FILE_CONTENT "${BUILD_FILE_CONTENT}#include <${FINAL_SOURCE_FILE}>\n") ENDIF () # Add the source dependencies to the Unity Build file GET_SOURCE_FILE_PROPERTY(_FILE_DEPS ${SOURCE_FILE} OBJECT_DEPENDS) IF (_FILE_DEPS) SET(_DEPS ${_DEPS} ${_FILE_DEPS}) SET_SOURCE_FILES_PROPERTIES(${BUILD_FILE} PROPERTIES OBJECT_DEPENDS "${_DEPS}") ENDIF() # Keep counting up to the threshold. Increment counter. MATH(EXPR COUNTER ${COUNTER}+1) ENDIF () ENDFOREACH () # Write out the last Unity Build file IF (NOT ${BUILD_FILE} STREQUAL "" AND NOT ${BUILD_FILE_CONTENT} STREQUAL "") COMMIT_UNITY_FILE(BUILD_FILE BUILD_FILE_CONTENT) ENDIF () SET(UNITY_BUILD_FILES ${UNITY_BUILD_FILES} ${BUILD_FILE}) SET(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${UNITY_BUILD_FILES}) ENDMACRO () MACRO (UNITY_GENERATE_MOC TARGET_NAME SOURCES HEADERS) SET(NEW_SOURCES "") FOREACH (HEADER_FILE ${${HEADERS}}) IF (NOT EXISTS ${HEADER_FILE}) MESSAGE(FATAL_ERROR "Header file does not exist (mocing): ${HEADER_FILE}") ENDIF () FILE(READ ${HEADER_FILE} FILE_CONTENT) STRING(FIND "${FILE_CONTENT}" "Q_OBJECT" QOBJECT_POS) STRING(FIND "${FILE_CONTENT}" "Q_SLOTS" QSLOTS_POS) STRING(FIND "${FILE_CONTENT}" "Q_SIGNALS" QSIGNALS_POS) STRING(FIND "${FILE_CONTENT}" "QObject" OBJECT_POS) STRING(FIND "${FILE_CONTENT}" "slots" SLOTS_POS) STRING(FIND "${FILE_CONTENT}" "signals" SIGNALS_POS) IF (QOBJECT_POS GREATER 0 OR OBJECT_POS GREATER 0 OR QSLOTS_POS GREATER 0 OR Q_SIGNALS GREATER 0 OR SLOTS_POS GREATER 0 OR SIGNALS GREATER 0) # Generate the moc filename GET_FILENAME_COMPONENT(HEADER_BASENAME ${HEADER_FILE} NAME_WE) SET(MOC_FILENAME "moc_${HEADER_BASENAME}.cpp") SET(NEW_SOURCES ${NEW_SOURCES} ; "${CMAKE_CURRENT_BINARY_DIR}/${MOC_FILENAME}") ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${MOC_FILENAME}" DEPENDS ${HEADER_FILE} COMMAND ${QT_MOC_EXECUTABLE} ${HEADER_FILE} -o "${CMAKE_CURRENT_BINARY_DIR}/${MOC_FILENAME}") ENDIF () ENDFOREACH () IF (NEW_SOURCES) SET_SOURCE_FILES_PROPERTIES(${NEW_SOURCES} PROPERTIES GENERATED TRUE) SET(${SOURCES} ${${SOURCES}} ; ${NEW_SOURCES}) ENDIF () ENDMACRO () indi-starbook-ten-0.1/cmake_modules/FindLibRaw.cmake0000644000175100017510000000562514136175546021752 0ustar debiandebian# - Find LibRaw # Find the LibRaw library # This module defines # LibRaw_VERSION_STRING, the version string of LibRaw # LibRaw_INCLUDE_DIR, where to find libraw.h # LibRaw_LIBRARIES, the libraries needed to use LibRaw (non-thread-safe) # LibRaw_r_LIBRARIES, the libraries needed to use LibRaw (thread-safe) # LibRaw_DEFINITIONS, the definitions needed to use LibRaw (non-thread-safe) # LibRaw_r_DEFINITIONS, the definitions needed to use LibRaw (thread-safe) # # Copyright (c) 2013, Pino Toscano # Copyright (c) 2013, Gilles Caulier # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. FIND_PACKAGE(PkgConfig) IF(PKG_CONFIG_FOUND) PKG_CHECK_MODULES(PC_LIBRAW libraw) SET(LibRaw_DEFINITIONS ${PC_LIBRAW_CFLAGS_OTHER}) PKG_CHECK_MODULES(PC_LIBRAW_R libraw_r) SET(LibRaw_r_DEFINITIONS ${PC_LIBRAW_R_CFLAGS_OTHER}) ENDIF() FIND_PATH(LibRaw_INCLUDE_DIR libraw.h HINTS ${PC_LIBRAW_INCLUDEDIR} ${PC_LibRaw_INCLUDE_DIRS} PATH_SUFFIXES libraw ) FIND_LIBRARY(LibRaw_LIBRARIES NAMES raw HINTS ${PC_LIBRAW_LIBDIR} ${PC_LIBRAW_LIBRARY_DIRS} ) FIND_LIBRARY(LibRaw_r_LIBRARIES NAMES raw_r HINTS ${PC_LIBRAW_R_LIBDIR} ${PC_LIBRAW_R_LIBRARY_DIRS} ) IF(LibRaw_INCLUDE_DIR) FILE(READ ${LibRaw_INCLUDE_DIR}/libraw_version.h _libraw_version_content) STRING(REGEX MATCH "#define LIBRAW_MAJOR_VERSION[ \t]*([0-9]*)\n" _version_major_match ${_libraw_version_content}) SET(_libraw_version_major "${CMAKE_MATCH_1}") STRING(REGEX MATCH "#define LIBRAW_MINOR_VERSION[ \t]*([0-9]*)\n" _version_minor_match ${_libraw_version_content}) SET(_libraw_version_minor "${CMAKE_MATCH_1}") STRING(REGEX MATCH "#define LIBRAW_PATCH_VERSION[ \t]*([0-9]*)\n" _version_patch_match ${_libraw_version_content}) SET(_libraw_version_patch "${CMAKE_MATCH_1}") IF(_version_major_match AND _version_minor_match AND _version_patch_match) SET(LibRaw_VERSION_STRING "${_libraw_version_major}.${_libraw_version_minor}.${_libraw_version_patch}") ELSE() IF(NOT LibRaw_FIND_QUIETLY) MESSAGE(STATUS "Failed to get version information from ${LibRaw_INCLUDE_DIR}/libraw_version.h") ENDIF() ENDIF() ENDIF() INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibRaw REQUIRED_VARS LibRaw_LIBRARIES LibRaw_INCLUDE_DIR VERSION_VAR LibRaw_VERSION_STRING ) MARK_AS_ADVANCED(LibRaw_VERSION_STRING LibRaw_INCLUDE_DIR LibRaw_LIBRARIES LibRaw_r_LIBRARIES LibRaw_DEFINITIONS LibRaw_r_DEFINITIONS ) indi-starbook-ten-0.1/cmake_modules/FindALTAIRCAM.cmake0000644000175100017510000000301014136175546022051 0ustar debiandebian# - Try to find Altair Camera Library # Once done this will define # # ALTAIRCAM_FOUND - system has Altair # ALTAIRCAM_INCLUDE_DIR - the Altair include directory # ALTAIRCAM_LIBRARIES - Link these to use Altair # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (ALTAIRCAM_INCLUDE_DIR AND ALTAIRCAM_LIBRARIES) # in cache already set(ALTAIRCAM_FOUND TRUE) message(STATUS "Found libaltaircam: ${ALTAIRCAM_LIBRARIES}") else (ALTAIRCAM_INCLUDE_DIR AND ALTAIRCAM_LIBRARIES) find_path(ALTAIRCAM_INCLUDE_DIR altaircam.h PATH_SUFFIXES libaltaircam ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(ALTAIRCAM_LIBRARIES NAMES altaircam PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(ALTAIRCAM_INCLUDE_DIR AND ALTAIRCAM_LIBRARIES) set(ALTAIRCAM_FOUND TRUE) else (ALTAIRCAM_INCLUDE_DIR AND ALTAIRCAM_LIBRARIES) set(ALTAIRCAM_FOUND FALSE) endif(ALTAIRCAM_INCLUDE_DIR AND ALTAIRCAM_LIBRARIES) if (ALTAIRCAM_FOUND) if (NOT ALTAIRCAM_FIND_QUIETLY) message(STATUS "Found Altaircam: ${ALTAIRCAM_LIBRARIES}") endif (NOT ALTAIRCAM_FIND_QUIETLY) else (ALTAIRCAM_FOUND) if (ALTAIRCAM_FIND_REQUIRED) message(FATAL_ERROR "Altaircam not found. Please install Altaircam Library http://www.indilib.org") endif (ALTAIRCAM_FIND_REQUIRED) endif (ALTAIRCAM_FOUND) mark_as_advanced(ALTAIRCAM_INCLUDE_DIR ALTAIRCAM_LIBRARIES) endif (ALTAIRCAM_INCLUDE_DIR AND ALTAIRCAM_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindSBIG.cmake0000644000175100017510000000251214136175546021306 0ustar debiandebian# - Try to find SBIG Universal Library # Once done this will define # # SBIG_FOUND - system has SBIG # SBIG_INCLUDE_DIR - the SBIG include directory # SBIG_LIBRARIES - Link these to use SBIG # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (SBIG_INCLUDE_DIR AND SBIG_LIBRARIES) # in cache already set(SBIG_FOUND TRUE) message(STATUS "Found libsbig: ${SBIG_LIBRARIES}") else (SBIG_INCLUDE_DIR AND SBIG_LIBRARIES) find_path(SBIG_INCLUDE_DIR sbigudrv.h PATH_SUFFIXES libsbig ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(SBIG_LIBRARIES NAMES sbig PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(SBIG_INCLUDE_DIR AND SBIG_LIBRARIES) set(SBIG_FOUND TRUE) else (SBIG_INCLUDE_DIR AND SBIG_LIBRARIES) set(SBIG_FOUND FALSE) endif(SBIG_INCLUDE_DIR AND SBIG_LIBRARIES) if (SBIG_FOUND) if (NOT SBIG_FIND_QUIETLY) message(STATUS "Found SBIG: ${SBIG_LIBRARIES}") endif (NOT SBIG_FIND_QUIETLY) else (SBIG_FOUND) if (SBIG_FIND_REQUIRED) message(FATAL_ERROR "SBIG not found. Please install SBIG Library http://www.indilib.org") endif (SBIG_FIND_REQUIRED) endif (SBIG_FOUND) mark_as_advanced(SBIG_INCLUDE_DIR SBIG_LIBRARIES) endif (SBIG_INCLUDE_DIR AND SBIG_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/CMakeParseArguments.cmake0000644000175100017510000000164214136175546023625 0ustar debiandebian#.rst: # CMakeParseArguments # ------------------- # # This module once implemented the :command:`cmake_parse_arguments` command # that is now implemented natively by CMake. It is now an empty placeholder # for compatibility with projects that include it to get the command from # CMake 3.4 and lower. #============================================================================= # Copyright 2010 Alexander Neundorf # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) indi-starbook-ten-0.1/cmake_modules/FindGPHOTO2.cmake0000644000175100017510000000562614136175546021655 0ustar debiandebian# - Find the native sqlite3 includes and library # # This module defines # GPHOTO2_INCLUDE_DIR, where to find libgphoto2 header files # GPHOTO2_LIBRARIES, the libraries to link against to use libgphoto2 # GPHOTO2_FOUND, If false, do not try to use libgphoto2. # GPHOTO2_VERSION_STRING, e.g. 2.4.14 # GPHOTO2_VERSION_MAJOR, e.g. 2 # GPHOTO2_VERSION_MINOR, e.g. 4 # GPHOTO2_VERSION_PATCH, e.g. 14 # # also defined, but not for general use are # GPHOTO2_LIBRARY, where to find the sqlite3 library. #============================================================================= # Copyright 2010 henrik andersson #============================================================================= SET(GPHOTO2_FIND_REQUIRED ${Gphoto2_FIND_REQUIRED}) find_path(GPHOTO2_INCLUDE_DIR gphoto2/gphoto2.h) mark_as_advanced(GPHOTO2_INCLUDE_DIR) set(GPHOTO2_NAMES ${GPHOTO2_NAMES} gphoto2 libgphoto2) set(GPHOTO2_PORT_NAMES ${GPHOTO2_PORT_NAMES} gphoto2_port libgphoto2_port) find_library(GPHOTO2_LIBRARY NAMES ${GPHOTO2_NAMES} ) find_library(GPHOTO2_PORT_LIBRARY NAMES ${GPHOTO2_PORT_NAMES} ) mark_as_advanced(GPHOTO2_LIBRARY) mark_as_advanced(GPHOTO2_PORT_LIBRARY) # Detect libgphoto2 version FIND_PROGRAM(GPHOTO2CONFIG_EXECUTABLE NAMES gphoto2-config) IF(GPHOTO2CONFIG_EXECUTABLE) EXEC_PROGRAM(${GPHOTO2CONFIG_EXECUTABLE} ARGS --version RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GPHOTO2_VERSION) string(REGEX REPLACE "^.*libgphoto2 ([0-9]+).*$" "\\1" GPHOTO2_VERSION_MAJOR "${GPHOTO2_VERSION}") string(REGEX REPLACE "^.*libgphoto2 [0-9]+\\.([0-9]+).*$" "\\1" GPHOTO2_VERSION_MINOR "${GPHOTO2_VERSION}") string(REGEX REPLACE "^.*libgphoto2 [0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" GPHOTO2_VERSION_PATCH "${GPHOTO2_VERSION}") set(GPHOTO2_VERSION_STRING "${GPHOTO2_VERSION_MAJOR}.${GPHOTO2_VERSION_MINOR}.${GPHOTO2_VERSION_PATCH}") ENDIF(GPHOTO2CONFIG_EXECUTABLE) # handle the QUIETLY and REQUIRED arguments and set GPHOTO2_FOUND to TRUE if # all listed variables are TRUE include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GPHOTO2 DEFAULT_MSG GPHOTO2_LIBRARY GPHOTO2_INCLUDE_DIR) IF(GPHOTO2_FOUND) SET(Gphoto2_LIBRARIES ${GPHOTO2_LIBRARY} ${GPHOTO2_PORT_LIBRARY}) SET(Gphoto2_INCLUDE_DIRS ${GPHOTO2_INCLUDE_DIR}) # libgphoto2 dynamically loads and unloads usb library # without calling any cleanup functions (since they are absent from libusb-0.1). # This leaves usb event handling threads running with invalid callback and return addresses, # which causes a crash after any usb event is generated, at least in Mac OS X. # libusb1 backend does correctly call exit function, but ATM it crashes anyway. # Workaround is to link against libusb so that it wouldn't get unloaded. IF(APPLE) find_library(USB_LIBRARY NAMES usb-1.0 libusb-1.0) mark_as_advanced(USB_LIBRARY) IF(USB_LIBRARY) SET(Gphoto2_LIBRARIES ${Gphoto2_LIBRARIES} ${USB_LIBRARY}) ENDIF(USB_LIBRARY) ENDIF(APPLE) ENDIF(GPHOTO2_FOUND) indi-starbook-ten-0.1/cmake_modules/FindMMAL.cmake0000644000175100017510000000303214136175546021306 0ustar debiandebian# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # This module can find the MMAL camera libraries. # cmake_minimum_required(VERSION 3.0.0) set (MMAL_LIBS mmal_core mmal_util mmal_vc_client) set (EGL_LIBS brcmGLESv2 brcmEGL) foreach(lib ${MMAL_LIBS} ${EGL_LIBS} vcos bcm_host m dl) find_library(${lib}_LIBRARY NAMES ${lib} HINTS ${MMAL_DIR}/lib /opt/vc/lib ) if (DEFINED ${lib}_LIBRARY) set(MMAL_LIBRARIES ${MMAL_LIBRARIES} ${${lib}_LIBRARY}) else() message(FATAL_ERROR "Failed to find ${${lib}_LIBRARY} library") endif() endforeach(lib) find_path(BCM_INCLUDE_DIR NAMES bcm_host.h HINTS "/opt/vc/include" ) find_path(MMAL_BASE_INCLUDE_DIR NAMES mmal.h HINTS "/opt/vc/include/interface/mmal" ) find_path(MMAL_UTIL_INCLUDE_DIR NAMES mmal_util.h HINTS "/opt/vc/include/interface/mmal/util" ) if (MMAL_BASE_INCLUDE_DIR AND BCM_INCLUDE_DIR AND MMAL_UTIL_INCLUDE_DIR) set(MMAL_INCLUDE_DIR ${MMAL_BASE_INCLUDE_DIR} ${BCM_INCLUDE_DIR} ${MMAL_UTIL_INCLUDE_DIR}) set(MMAL_FOUND TRUE) endif() indi-starbook-ten-0.1/cmake_modules/FindAIOUSB.cmake0000644000175100017510000000371314136175546021550 0ustar debiandebian# - Try to find libaiousb # Once done this will define # # AIOUSB_FOUND - system has AIOUSB # AIOUSB_INCLUDE_DIR - the AIOUSB include directory # AIOUSB_LIBRARIES - Link these to use AIOUSB (C) # AIOUSB_CPP_LIBRARIES - Link these to use AIOUSB (C++) # Copyright (c) 2006, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (AIOUSB_INCLUDE_DIR AND AIOUSB_LIBRARIES AND AIOUSB_CPP_LIBRARIES) # in cache already set(AIOUSB_FOUND TRUE) message(STATUS "Found libaiusb: ${AIOUSB_LIBRARIES}") message(STATUS "Found libaiusbcpp: ${AIOUSB_CPP_LIBRARIES}") else (AIOUSB_INCLUDE_DIR AND AIOUSB_LIBRARIES AND AIOUSB_CPP_LIBRARIES) find_path(AIOUSB_INCLUDE_DIR aiousb.h ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(AIOUSB_LIBRARIES NAMES aiousb PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) find_library(AIOUSB_CPP_LIBRARIES NAMES aiousbcpp PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(AIOUSB_INCLUDE_DIR AND AIOUSB_LIBRARIES AND AIOUSB_CPP_LIBRARIES) set(AIOUSB_FOUND TRUE) else (AIOUSB_INCLUDE_DIR AND AIOUSB_LIBRARIES AND AIOUSB_CPP_LIBRARIES) set(AIOUSB_FOUND FALSE) endif(AIOUSB_INCLUDE_DIR AND AIOUSB_LIBRARIES AND AIOUSB_CPP_LIBRARIES) if (AIOUSB_FOUND) if (NOT AIOUSB_FIND_QUIETLY) message(STATUS "Found libaiousb: ${AIOUSB_LIBRARIES}") message(STATUS "Found libaiusbcpp: ${AIOUSB_CPP_LIBRARIES}") endif (NOT AIOUSB_FIND_QUIETLY) else (AIOUSB_FOUND) if (AIOUSB_FIND_REQUIRED) message(FATAL_ERROR "libaiousb not found. Please install libaiousb. https://www.accesio.com") endif (AIOUSB_FIND_REQUIRED) endif (AIOUSB_FOUND) mark_as_advanced(AIOUSB_INCLUDE_DIR AIOUSB_LIBRARIES AIOUSB_CPP_LIBRARIES) endif (AIOUSB_INCLUDE_DIR AND AIOUSB_LIBRARIES AND AIOUSB_CPP_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindAPOGEE.cmake0000644000175100017510000000311514136175546021522 0ustar debiandebian# - Try to find Apogee Instruments Library # Once done this will define # # APOGEE_FOUND - system has APOGEE # APOGEE_INCLUDE_DIR - the APOGEE include directory # APOGEE_LIBRARY - Link these to use APOGEE # Copyright (c) 2008, Jasem Mutlaq # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (APOGEE_INCLUDE_DIR AND APOGEE_LIBRARY) # in cache already set(APOGEE_FOUND TRUE) message(STATUS "Found libapogee: ${APOGEE_LIBRARY}") else (APOGEE_INCLUDE_DIR AND APOGEE_LIBRARY) find_path(APOGEE_INCLUDE_DIR ApogeeCam.h PATH_SUFFIXES libapogee ${_obIncDir} ${GNUWIN32_DIR}/include ) # Find Apogee Library find_library(APOGEE_LIBRARY NAMES apogee PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(APOGEE_INCLUDE_DIR AND APOGEE_LIBRARY) set(APOGEE_FOUND TRUE) else (APOGEE_INCLUDE_DIR AND APOGEE_LIBRARY) set(APOGEE_FOUND FALSE) endif(APOGEE_INCLUDE_DIR AND APOGEE_LIBRARY) if (APOGEE_FOUND) if (NOT APOGEE_FIND_QUIETLY) message(STATUS "Found APOGEE: ${APOGEE_LIBRARY}") endif (NOT APOGEE_FIND_QUIETLY) else (APOGEE_FOUND) if (APOGEE_FIND_REQUIRED) message(FATAL_ERROR "libapogee not found. Cannot compile Apogee CCD Driver. Please install libapogee and try again. http://www.indilib.org") endif (APOGEE_FIND_REQUIRED) endif (APOGEE_FOUND) mark_as_advanced(APOGEE_INCLUDE_DIR APOGEE_LIBRARY) endif (APOGEE_INCLUDE_DIR AND APOGEE_LIBRARY) indi-starbook-ten-0.1/cmake_modules/FindFFmpeg.cmake0000644000175100017510000001573514136175546021741 0ustar debiandebian# - Try to find ffmpeg libraries (libavcodec, libavdevice, libavformat, libavutil, and libswscale) # Once done this will define # # FFMPEG_FOUND - system has ffmpeg or libav # FFMPEG_INCLUDE_DIR - the ffmpeg include directory # FFMPEG_LIBRARIES - Link these to use ffmpeg # FFMPEG_LIBAVCODEC # FFMPEG_LIBAVDEVICE # FFMPEG_LIBAVFORMAT # FFMPEG_LIBAVUTIL # FFMPEG_LIBSWSCALE # # Copyright (c) 2008 Andreas Schneider # Modified for other libraries by Lasse Kärkkäinen # Modified for Hedgewars by Stepik777 # Modified for INDILIB by rlancaste # # Redistribution and use is allowed according to the terms of the New # BSD license. # macro(_FFMPEG_PACKAGE_check_version) if(EXISTS "${PACKAGE_INCLUDE_DIR}/version.h") file(READ "${PACKAGE_INCLUDE_DIR}/version.h" _FFMPEG_PACKAGE_version_header) string(REGEX MATCH "#define ${PACKAGE_NAME}_VERSION_MAJOR[ \t]+([0-9]+)" _VERSION_MAJOR_match "${_FFMPEG_PACKAGE_version_header}") set(FFMPEG_PACKAGE_VERSION_MAJOR "${CMAKE_MATCH_1}") string(REGEX MATCH "#define ${PACKAGE_NAME}_VERSION_MINOR[ \t]+([0-9]+)" _VERSION_MINOR_match "${_FFMPEG_PACKAGE_version_header}") set(FFMPEG_PACKAGE_VERSION_MINOR "${CMAKE_MATCH_1}") string(REGEX MATCH "#define ${PACKAGE_NAME}_VERSION_MICRO[ \t]+([0-9]+)" _VERSION_MICRO_match "${_FFMPEG_PACKAGE_version_header}") set(FFMPEG_PACKAGE_VERSION_MICRO "${CMAKE_MATCH_1}") set(FFMPEG_PACKAGE_VERSION ${FFMPEG_PACKAGE_VERSION_MAJOR}.${FFMPEG_PACKAGE_VERSION_MINOR}.${FFMPEG_PACKAGE_VERSION_MICRO}) if(${FFMPEG_PACKAGE_VERSION} VERSION_LESS ${FFMPEG_PACKAGE_FIND_VERSION}) set(FFMPEG_PACKAGE_VERSION_OK FALSE) else(${FFMPEG_PACKAGE_VERSION} VERSION_LESS ${FFMPEG_PACKAGE_FIND_VERSION}) set(FFMPEG_PACKAGE_VERSION_OK TRUE) endif(${FFMPEG_PACKAGE_VERSION} VERSION_LESS ${FFMPEG_PACKAGE_FIND_VERSION}) if(NOT FFMPEG_PACKAGE_VERSION_OK) message(STATUS "${PACKAGE_NAME} version ${FFMPEG_PACKAGE_VERSION} found in ${PACKAGE_INCLUDE_DIR}, " "but at least version ${FFMPEG_PACKAGE_FIND_VERSION} is required") else(NOT FFMPEG_PACKAGE_VERSION_OK) mark_as_advanced(FFMPEG_PACKAGE_VERSION_MAJOR FFMPEG_PACKAGE_VERSION_MINOR FFMPEG_PACKAGE_VERSION_MICRO) endif(NOT FFMPEG_PACKAGE_VERSION_OK) else(EXISTS "${PACKAGE_INCLUDE_DIR}/version.h") set(FFMPEG_PACKAGE_VERSION_OK FALSE) message(STATUS "${PACKAGE_NAME}'s version.h file was not found in the include directory: ${PACKAGE_INCLUDE_DIR}, please install this program.") endif(EXISTS "${PACKAGE_INCLUDE_DIR}/version.h") endmacro(_FFMPEG_PACKAGE_check_version) # required ffmpeg library versions, Requiring at least FFMPEG 3.2.11, Hypatia set(_avcodec_ver ">=57.64.101") set(_avdevice_ver ">=57.1.100") set(_avformat_ver ">=57.56.100") set(_avutil_ver ">=55.34.100") set(_swscale_ver ">=4.2.100") if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) # in cache already set(FFMPEG_FOUND TRUE) else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls find_path(FFMPEG_INCLUDE_DIR NAMES libavcodec/avcodec.h PATHS ${FFMPEG_INCLUDE_DIRS} ${CMAKE_INSTALL_PREFIX}/include /usr/include /usr/local/include /opt/local/include /sw/include PATH_SUFFIXES ffmpeg libav ) find_package(PkgConfig) if (PKG_CONFIG_FOUND) pkg_check_modules(AVCODEC libavcodec${_avcodec_ver}) pkg_check_modules(AVDEVICE libavdevice${_avdevice_ver}) pkg_check_modules(AVFORMAT libavformat${_avformat_ver}) pkg_check_modules(AVUTIL libavutil${_avutil_ver}) pkg_check_modules(SWSCALE libswscale${_swscale_ver}) else (PKG_CONFIG_FOUND) # LIBAVCODEC set(PACKAGE_NAME "LIBAVCODEC") set(PACKAGE_INCLUDE_DIR "${FFMPEG_INCLUDE_DIR}/libavcodec") set(FFMPEG_PACKAGE_FIND_VERSION _avcodec_ver) _FFMPEG_PACKAGE_check_version() if(FFMPEG_PACKAGE_VERSION_OK) set(AVCODEC_VERSION FFMPEG_PACKAGE_VERSION) endif(FFMPEG_PACKAGE_VERSION_OK) # LIBAVDEVICE set(PACKAGE_NAME "LIBAVDEVICE") set(PACKAGE_INCLUDE_DIR "${FFMPEG_INCLUDE_DIR}/libavdevice") set(FFMPEG_PACKAGE_FIND_VERSION _avdevice_ver) _FFMPEG_PACKAGE_check_version() if(FFMPEG_PACKAGE_VERSION_OK) set(AVDEVICE_VERSION FFMPEG_PACKAGE_VERSION) endif(FFMPEG_PACKAGE_VERSION_OK) # LIBAVFORMAT set(PACKAGE_NAME "LIBAVFORMAT") set(PACKAGE_INCLUDE_DIR "${FFMPEG_INCLUDE_DIR}/libavformat") set(FFMPEG_PACKAGE_FIND_VERSION _avformat_ver) _FFMPEG_PACKAGE_check_version() if(FFMPEG_PACKAGE_VERSION_OK) set(AVFORMAT_VERSION FFMPEG_PACKAGE_VERSION) endif(FFMPEG_PACKAGE_VERSION_OK) # LIBAVUTIL set(PACKAGE_NAME "LIBAVUTIL") set(PACKAGE_INCLUDE_DIR "${FFMPEG_INCLUDE_DIR}/libavutil") set(FFMPEG_PACKAGE_FIND_VERSION _avutil_ver) _FFMPEG_PACKAGE_check_version() if(FFMPEG_PACKAGE_VERSION_OK) set(AVUTIL_VERSION FFMPEG_PACKAGE_VERSION) endif(FFMPEG_PACKAGE_VERSION_OK) # LIBSWSCALE set(PACKAGE_NAME "LIBSWSCALE") set(PACKAGE_INCLUDE_DIR "${FFMPEG_INCLUDE_DIR}/libswscale") set(FFMPEG_PACKAGE_FIND_VERSION _swscale_ver) _FFMPEG_PACKAGE_check_version() if(FFMPEG_PACKAGE_VERSION_OK) set(SWSCALE_VERSION FFMPEG_PACKAGE_VERSION) endif(FFMPEG_PACKAGE_VERSION_OK) endif (PKG_CONFIG_FOUND) find_library(FFMPEG_LIBAVCODEC NAMES avcodec libavcodec PATHS ${AVCODEC_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}/lib /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) find_library(FFMPEG_LIBAVDEVICE NAMES avdevice libavdevice PATHS ${AVDEVICE_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}/lib /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) find_library(FFMPEG_LIBAVFORMAT NAMES avformat libavformat PATHS ${AVFORMAT_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}/lib /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) find_library(FFMPEG_LIBAVUTIL NAMES avutil libavutil PATHS ${AVUTIL_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}/lib /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) find_library(FFMPEG_LIBSWSCALE NAMES swscale libswscale PATHS ${SWSCALE_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}/lib /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) #Only set FFMPEG to found if all the libraries are found in the right versions. if(AVCODEC_VERSION AND AVDEVICE_VERSION AND AVFORMAT_VERSION AND AVUTIL_VERSION AND SWSCALE_VERSION AND FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVDEVICE AND FFMPEG_LIBAVFORMAT AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE) set(FFMPEG_FOUND TRUE) endif() if (FFMPEG_FOUND) set(FFMPEG_LIBRARIES ${FFMPEG_LIBAVCODEC} ${FFMPEG_LIBAVDEVICE} ${FFMPEG_LIBAVFORMAT} ${FFMPEG_LIBAVUTIL} ${FFMPEG_LIBSWSCALE} ) endif (FFMPEG_FOUND) if (FFMPEG_FOUND) if (NOT FFMPEG_FIND_QUIETLY) message(STATUS "Found FFMPEG: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}") endif (NOT FFMPEG_FIND_QUIETLY) else (FFMPEG_FOUND) message(STATUS "Could not find up to date FFMPEG for INDI Webcam. Up to date versions of these packages are required: libavcodec, libavdevice, libavformat, libavutil, and libswscale") if (FFMPEG_FIND_REQUIRED) message(FATAL_ERROR "Error: FFMPEG is required by this package!") endif (FFMPEG_FIND_REQUIRED) endif (FFMPEG_FOUND) endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) indi-starbook-ten-0.1/cmake_modules/FindIconv.cmake0000644000175100017510000000426114136175546021643 0ustar debiandebian# # Copyright (C) 2010 Michael Bell # 2015-2016 MariaDB Corporation AB # # Redistribution and use is allowed according to the terms of the New # BSD license. # For details see the COPYING-CMAKE-SCRIPTS file. # # ICONV_EXTERNAL - Iconv is an external library (not libc) # ICONV_FOUND - system has Iconv # ICONV_INCLUDE_DIR - the Iconv include directory # ICONV_LIBRARIES - Link these to use Iconv # ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const # ICONV_VERSION - Iconv version string if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) # Already in cache, be silent set(ICONV_FIND_QUIETLY TRUE) endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) find_path(ICONV_INCLUDE_DIR iconv.h) IF(CMAKE_SYSTEM_NAME MATCHES "SunOS") # There is some libiconv.so in /usr/local that must # be avoided, iconv routines are in libc ELSEIF(APPLE) find_library(ICONV_LIBRARIES NAMES iconv libiconv PATHS /usr/lib/ NO_CMAKE_SYSTEM_PATH) SET(ICONV_EXTERNAL TRUE) ELSE() find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2) IF(ICONV_LIBRARIES) SET(ICONV_EXTERNAL TRUE) ENDIF() ENDIF() if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) set (ICONV_FOUND TRUE) endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) IF(ICONV_EXTERNAL) set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES}) ENDIF() if (ICONV_FOUND) include(CheckCSourceCompiles) CHECK_C_SOURCE_COMPILES(" #include int main(){ iconv_t conv = 0; const char* in = 0; size_t ilen = 0; char* out = 0; size_t olen = 0; iconv(conv, &in, &ilen, &out, &olen); return 0; } " ICONV_SECOND_ARGUMENT_IS_CONST ) endif (ICONV_FOUND) set (CMAKE_REQUIRED_INCLUDES) set (CMAKE_REQUIRED_LIBRARIES) if (ICONV_FOUND) if (NOT ICONV_FIND_QUIETLY) message (STATUS "Found Iconv: ${ICONV_LIBRARIES}") endif (NOT ICONV_FIND_QUIETLY) else (ICONV_FOUND) if (Iconv_FIND_REQUIRED) message (FATAL_ERROR "Could not find Iconv") endif (Iconv_FIND_REQUIRED) endif (ICONV_FOUND) MARK_AS_ADVANCED( ICONV_INCLUDE_DIR ICONV_LIBRARIES ICONV_EXTERNAL ICONV_SECOND_ARGUMENT_IS_CONST ) indi-starbook-ten-0.1/cmake_modules/FindLIMESUITE.cmake0000644000175100017510000000301214136175546022116 0ustar debiandebian# - Try to find LIMESUITE # Once done this will define # # LIMESUITE_FOUND - system has LIMESUITE # LIMESUITE_INCLUDE_DIR - the LIMESUITE include directory # LIMESUITE_LIBRARIES - Link these to use LIMESUITE # LIMESUITE_VERSION_STRING - Human readable version number of rtlsdr # LIMESUITE_VERSION_MAJOR - Major version number of rtlsdr # LIMESUITE_VERSION_MINOR - Minor version number of rtlsdr # Copyright (c) 2017, Ilia Platone, # Based on FindLibfacile by Carsten Niehaus, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (LIMESUITE_LIBRARIES) # in cache already set(LIMESUITE_FOUND TRUE) message(STATUS "Found LIMESUITE: ${LIMESUITE_LIBRARIES}") else (LIMESUITE_LIBRARIES) find_library(LIMESUITE_LIBRARIES NAMES LimeSuite PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib /usr/local/lib ) if(LIMESUITE_LIBRARIES) set(LIMESUITE_FOUND TRUE) else (LIMESUITE_LIBRARIES) set(LIMESUITE_FOUND FALSE) endif(LIMESUITE_LIBRARIES) if (LIMESUITE_FOUND) if (NOT LIMESUITE_FIND_QUIETLY) message(STATUS "Found LIMESUITE: ${LIMESUITE_LIBRARIES}") endif (NOT LIMESUITE_FIND_QUIETLY) else (LIMESUITE_FOUND) if (LIMESUITE_FIND_REQUIRED) message(FATAL_ERROR "LIMESUITE not found. Please install libLimeSuite-dev") endif (LIMESUITE_FIND_REQUIRED) endif (LIMESUITE_FOUND) mark_as_advanced(LIMESUITE_LIBRARIES) endif (LIMESUITE_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindPLAYERONE.cmake0000644000175100017510000000322114136175546022116 0ustar debiandebian# - Try to find PlayerOne Library # Once done this will define # # PLAYERONE_FOUND - system has PLAYERONE # PLAYERONE_INCLUDE_DIR - the PLAYERONE include directory # PLAYERONE_LIBRARIES - Link these to use ASI # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (PLAYERONE_INCLUDE_DIR AND PLAYERONE_LIBRARIES) # in cache already set(PLAYERONE_FOUND TRUE) message(STATUS "Found libplayerone: ${PLAYERONE_LIBRARIES}") else (PLAYERONE_INCLUDE_DIR AND PLAYERONE_LIBRARIES) find_path(PLAYERONE_INCLUDE_DIR PlayerOneCamera.h PATH_SUFFIXES libplayerone ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(PLAYERONECAM_LIBRARIES NAMES PlayerOneCamera PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if (PLAYERONECAM_LIBRARIES) set(PLAYERONE_LIBRARIES ${PLAYERONECAM_LIBRARIES}) endif (PLAYERONECAM_LIBRARIES) if(PLAYERONE_INCLUDE_DIR AND PLAYERONE_LIBRARIES) set(PLAYERONE_FOUND TRUE) else (PLAYERONE_INCLUDE_DIR AND PLAYERONE_LIBRARIES) set(PLAYERONE_FOUND FALSE) endif(PLAYERONE_INCLUDE_DIR AND PLAYERONE_LIBRARIES) if (PLAYERONE_FOUND) if (NOT PLAYERONE_FIND_QUIETLY) message(STATUS "Found PLAYERONE: ${PLAYERONE_LIBRARIES}") endif (NOT PLAYERONE_FIND_QUIETLY) else (PLAYERONE_FOUND) if (PLAYERONE_FIND_REQUIRED) message(FATAL_ERROR "PLAYERONE not found. Please install libPlayerOneCamera.2 http://www.indilib.org") endif (PLAYERONE_FIND_REQUIRED) endif (PLAYERONE_FOUND) mark_as_advanced(PLAYERONE_INCLUDE_DIR PLAYERONE_LIBRARIES) endif (PLAYERONE_INCLUDE_DIR AND PLAYERONE_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindNNCAM.cmake0000644000175100017510000000256314136175546021424 0ustar debiandebian# - Try to find NNCAM Camera Library # Once done this will define # # NNCAM_FOUND - system has Levenhuk # NNCAM_INCLUDE_DIR - the Levenhuk include directory # NNCAM_LIBRARIES - Link these to use Levenhuk # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (NNCAM_INCLUDE_DIR AND NNCAM_LIBRARIES) # in cache already set(NNCAM_FOUND TRUE) message(STATUS "Found libnncam: ${NNCAM_LIBRARIES}") else (NNCAM_INCLUDE_DIR AND NNCAM_LIBRARIES) find_path(NNCAM_INCLUDE_DIR nncam.h PATH_SUFFIXES libnncam ${_obIncDir} ${GNUWIN32_DIR}/include ) find_library(NNCAM_LIBRARIES NAMES nncam PATHS ${_obLinkDir} ${GNUWIN32_DIR}/lib ) if(NNCAM_INCLUDE_DIR AND NNCAM_LIBRARIES) set(NNCAM_FOUND TRUE) else (NNCAM_INCLUDE_DIR AND NNCAM_LIBRARIES) set(NNCAM_FOUND FALSE) endif(NNCAM_INCLUDE_DIR AND NNCAM_LIBRARIES) if (NNCAM_FOUND) if (NOT NNCAM_FIND_QUIETLY) message(STATUS "Found NNCAM: ${NNCAM_LIBRARIES}") endif (NOT NNCAM_FIND_QUIETLY) else (NNCAM_FOUND) if (NNCAM_FIND_REQUIRED) message(FATAL_ERROR "NNCAM not found. Please install NNCAM Library http://www.indilib.org") endif (NNCAM_FIND_REQUIRED) endif (NNCAM_FOUND) mark_as_advanced(NNCAM_INCLUDE_DIR NNCAM_LIBRARIES) endif (NNCAM_INCLUDE_DIR AND NNCAM_LIBRARIES) indi-starbook-ten-0.1/cmake_modules/FindRT.cmake0000644000175100017510000000152514136175546021112 0ustar debiandebian# FindRT.cmake - Try to find the RT library # Once done this will define # # RT_FOUND - System has rt # RT_INCLUDE_DIR - The rt include directory # RT_LIBRARIES - The libraries needed to use rt # RT_DEFINITIONS - Compiler switches required for using rt # # Also creates an import target called RT::RT find_path (RT_INCLUDE_DIR NAMES time.h PATHS /usr /usr/local /opt PATH_SUFFIXES ) find_library(RT_LIBRARIES NAMES rt PATHS /usr /usr/local /opt ) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(rt DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR) mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES) if (NOT TARGET RT::RT) add_library(RT::RT INTERFACE IMPORTED) set_target_properties(RT::RT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR} INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES} ) endif()indi-starbook-ten-0.1/COPYING.LESSER0000644000175100017510000006364214136175546016211 0ustar debiandebian GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! indi-starbook-ten-0.1/connectionhttp.cpp0000644000175100017510000000615414136175546017720 0ustar debiandebian/******************************************************************************* Copyright(c) 2017 Jasem Mutlaq. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *******************************************************************************/ #include "connectionhttp.h" #include "indilogger.h" #include "indistandardproperty.h" #include #include namespace Connection { extern const char *CONNECTION_TAB; HTTP::HTTP(INDI::DefaultDevice *dev) : Interface(dev, CONNECTION_CUSTOM) { char defaultHostname[MAXINDINAME] = {0}; IUGetConfigText(dev->getDeviceName(), AddressTP.name, "BASE_URL", defaultHostname, MAXINDINAME); // Address/Port IUFillText(&AddressT[0], "BASE_URL", "Address", defaultHostname); IUFillTextVector(&AddressTP, AddressT, 1, getDeviceName(), "DEVICE_BASE_URL", "Base URL", CONNECTION_TAB, IP_RW, 60, IPS_IDLE); } bool HTTP::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) { if (!strcmp(dev, m_Device->getDeviceName())) { // HTTP Server settings if (!strcmp(name, AddressTP.name)) { IUUpdateText(&AddressTP, texts, names, n); AddressTP.s = IPS_OK; IDSetText(&AddressTP, nullptr); return true; } } return false; } bool HTTP::Connect() { if (AddressT[0].text == nullptr || AddressT[0].text[0] == '\0') { LOG_ERROR("Error! Server address is missing or invalid."); return false; } const char *baseurl = AddressT[0].text; LOGF_INFO("Connecting to %s ...", baseurl); #if 0 if (m_Device->isSimulation() == false) { client = new httplib::Client(baseurl); } #else client = new httplib::Client(baseurl); #endif bool rc = Handshake(); if (rc) { LOGF_INFO("%s is online.", getDeviceName()); #if 0 m_Device->saveConfig(true, "DEVICE_BASE_URL"); #endif } else LOG_DEBUG("Handshake failed."); return rc; } bool HTTP::Disconnect() { delete client; client = nullptr; return true; } void HTTP::Activated() { m_Device->defineProperty(&AddressTP); #if 0 m_Device->loadConfig(true, "DEVICE_BASE_URL"); #endif } void HTTP::Deactivated() { m_Device->deleteProperty(AddressTP.name); } bool HTTP::saveConfigItems(FILE *fp) { IUSaveConfigText(fp, &AddressTP); return true; } void HTTP::setDefaultHost(const char *addressHost) { IUSaveText(&AddressT[0], addressHost); } } indi-starbook-ten-0.1/httplib.h0000644000175100017510000074440514136175546016004 0ustar debiandebian// // httplib.h // // Copyright (c) 2020 Yuji Hirose. All rights reserved. // MIT License // #ifndef CPPHTTPLIB_HTTPLIB_H #define CPPHTTPLIB_HTTPLIB_H /* * Configuration */ #ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND #define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5 #endif #ifndef CPPHTTPLIB_KEEPALIVE_MAX_COUNT #define CPPHTTPLIB_KEEPALIVE_MAX_COUNT 5 #endif #ifndef CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND #define CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND 300 #endif #ifndef CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND #define CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND 0 #endif #ifndef CPPHTTPLIB_READ_TIMEOUT_SECOND #define CPPHTTPLIB_READ_TIMEOUT_SECOND 5 #endif #ifndef CPPHTTPLIB_READ_TIMEOUT_USECOND #define CPPHTTPLIB_READ_TIMEOUT_USECOND 0 #endif #ifndef CPPHTTPLIB_WRITE_TIMEOUT_SECOND #define CPPHTTPLIB_WRITE_TIMEOUT_SECOND 5 #endif #ifndef CPPHTTPLIB_WRITE_TIMEOUT_USECOND #define CPPHTTPLIB_WRITE_TIMEOUT_USECOND 0 #endif #ifndef CPPHTTPLIB_IDLE_INTERVAL_SECOND #define CPPHTTPLIB_IDLE_INTERVAL_SECOND 0 #endif #ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND #ifdef _WIN32 #define CPPHTTPLIB_IDLE_INTERVAL_USECOND 10000 #else #define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0 #endif #endif #ifndef CPPHTTPLIB_REQUEST_URI_MAX_LENGTH #define CPPHTTPLIB_REQUEST_URI_MAX_LENGTH 8192 #endif #ifndef CPPHTTPLIB_REDIRECT_MAX_COUNT #define CPPHTTPLIB_REDIRECT_MAX_COUNT 20 #endif #ifndef CPPHTTPLIB_PAYLOAD_MAX_LENGTH #define CPPHTTPLIB_PAYLOAD_MAX_LENGTH ((std::numeric_limits::max)()) #endif #ifndef CPPHTTPLIB_TCP_NODELAY #define CPPHTTPLIB_TCP_NODELAY false #endif #ifndef CPPHTTPLIB_RECV_BUFSIZ #define CPPHTTPLIB_RECV_BUFSIZ size_t(4096u) #endif #ifndef CPPHTTPLIB_COMPRESSION_BUFSIZ #define CPPHTTPLIB_COMPRESSION_BUFSIZ size_t(16384u) #endif #ifndef CPPHTTPLIB_THREAD_POOL_COUNT #define CPPHTTPLIB_THREAD_POOL_COUNT \ ((std::max)(8u, std::thread::hardware_concurrency() > 0 \ ? std::thread::hardware_concurrency() - 1 \ : 0)) #endif #ifndef CPPHTTPLIB_RECV_FLAGS #define CPPHTTPLIB_RECV_FLAGS 0 #endif #ifndef CPPHTTPLIB_SEND_FLAGS #define CPPHTTPLIB_SEND_FLAGS 0 #endif /* * Headers */ #ifdef _WIN32 #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif //_CRT_SECURE_NO_WARNINGS #ifndef _CRT_NONSTDC_NO_DEPRECATE #define _CRT_NONSTDC_NO_DEPRECATE #endif //_CRT_NONSTDC_NO_DEPRECATE #if defined(_MSC_VER) #ifdef _WIN64 using ssize_t = __int64; #else using ssize_t = int; #endif #if _MSC_VER < 1900 #define snprintf _snprintf_s #endif #endif // _MSC_VER #ifndef S_ISREG #define S_ISREG(m) (((m)&S_IFREG) == S_IFREG) #endif // S_ISREG #ifndef S_ISDIR #define S_ISDIR(m) (((m)&S_IFDIR) == S_IFDIR) #endif // S_ISDIR #ifndef NOMINMAX #define NOMINMAX #endif // NOMINMAX #include #include #include #include #ifndef WSA_FLAG_NO_HANDLE_INHERIT #define WSA_FLAG_NO_HANDLE_INHERIT 0x80 #endif #ifdef _MSC_VER #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "crypt32.lib") #pragma comment(lib, "cryptui.lib") #endif #ifndef strcasecmp #define strcasecmp _stricmp #endif // strcasecmp using socket_t = SOCKET; #ifdef CPPHTTPLIB_USE_POLL #define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) #endif #else // not _WIN32 #include #include #include #include #include #ifdef __linux__ #include #endif #include #ifdef CPPHTTPLIB_USE_POLL #include #endif #include #include #include #include #include using socket_t = int; #define INVALID_SOCKET (-1) #endif //_WIN32 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef CPPHTTPLIB_OPENSSL_SUPPORT #include #include #include #include #if defined(_WIN32) && defined(OPENSSL_USE_APPLINK) #include #endif #include #include #if OPENSSL_VERSION_NUMBER < 0x1010100fL #error Sorry, OpenSSL versions prior to 1.1.1 are not supported #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L #include inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1) { return M_ASN1_STRING_data(asn1); } #endif #endif #ifdef CPPHTTPLIB_ZLIB_SUPPORT #include #endif #ifdef CPPHTTPLIB_BROTLI_SUPPORT #include #include #endif /* * Declaration */ namespace httplib { namespace detail { /* * Backport std::make_unique from C++14. * * NOTE: This code came up with the following stackoverflow post: * https://stackoverflow.com/questions/10149840/c-arrays-and-make-unique * */ template typename std::enable_if::value, std::unique_ptr>::type make_unique(Args &&...args) { return std::unique_ptr(new T(std::forward(args)...)); } template typename std::enable_if::value, std::unique_ptr>::type make_unique(std::size_t n) { typedef typename std::remove_extent::type RT; return std::unique_ptr(new RT[n]); } struct ci { bool operator()(const std::string &s1, const std::string &s2) const { return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), [](unsigned char c1, unsigned char c2) { return ::tolower(c1) < ::tolower(c2); }); } }; } // namespace detail using Headers = std::multimap; using Params = std::multimap; using Match = std::smatch; using Progress = std::function; struct Response; using ResponseHandler = std::function; struct MultipartFormData { std::string name; std::string content; std::string filename; std::string content_type; }; using MultipartFormDataItems = std::vector; using MultipartFormDataMap = std::multimap; class DataSink { public: DataSink() : os(&sb_), sb_(*this) {} DataSink(const DataSink &) = delete; DataSink &operator=(const DataSink &) = delete; DataSink(DataSink &&) = delete; DataSink &operator=(DataSink &&) = delete; std::function write; std::function done; std::function is_writable; std::ostream os; private: class data_sink_streambuf : public std::streambuf { public: explicit data_sink_streambuf(DataSink &sink) : sink_(sink) {} protected: std::streamsize xsputn(const char *s, std::streamsize n) { sink_.write(s, static_cast(n)); return n; } private: DataSink &sink_; }; data_sink_streambuf sb_; }; using ContentProvider = std::function; using ContentProviderWithoutLength = std::function; using ContentReceiverWithProgress = std::function; using ContentReceiver = std::function; using MultipartContentHeader = std::function; class ContentReader { public: using Reader = std::function; using MultipartReader = std::function; ContentReader(Reader reader, MultipartReader multipart_reader) : reader_(std::move(reader)), multipart_reader_(std::move(multipart_reader)) {} bool operator()(MultipartContentHeader header, ContentReceiver receiver) const { return multipart_reader_(std::move(header), std::move(receiver)); } bool operator()(ContentReceiver receiver) const { return reader_(std::move(receiver)); } Reader reader_; MultipartReader multipart_reader_; }; using Range = std::pair; using Ranges = std::vector; struct Request { std::string method; std::string path; Headers headers; std::string body; std::string remote_addr; int remote_port = -1; // for server std::string version; std::string target; Params params; MultipartFormDataMap files; Ranges ranges; Match matches; // for client ResponseHandler response_handler; ContentReceiverWithProgress content_receiver; Progress progress; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT const SSL *ssl = nullptr; #endif bool has_header(const char *key) const; std::string get_header_value(const char *key, size_t id = 0) const; template T get_header_value(const char *key, size_t id = 0) const; size_t get_header_value_count(const char *key) const; void set_header(const char *key, const char *val); void set_header(const char *key, const std::string &val); bool has_param(const char *key) const; std::string get_param_value(const char *key, size_t id = 0) const; size_t get_param_value_count(const char *key) const; bool is_multipart_form_data() const; bool has_file(const char *key) const; MultipartFormData get_file_value(const char *key) const; // private members... size_t redirect_count_ = CPPHTTPLIB_REDIRECT_MAX_COUNT; size_t content_length_ = 0; ContentProvider content_provider_; bool is_chunked_content_provider_ = false; size_t authorization_count_ = 0; }; struct Response { std::string version; int status = -1; std::string reason; Headers headers; std::string body; std::string location; // Redirect location bool has_header(const char *key) const; std::string get_header_value(const char *key, size_t id = 0) const; template T get_header_value(const char *key, size_t id = 0) const; size_t get_header_value_count(const char *key) const; void set_header(const char *key, const char *val); void set_header(const char *key, const std::string &val); void set_redirect(const char *url, int status = 302); void set_redirect(const std::string &url, int status = 302); void set_content(const char *s, size_t n, const char *content_type); void set_content(const std::string &s, const char *content_type); void set_content_provider( size_t length, const char *content_type, ContentProvider provider, const std::function &resource_releaser = nullptr); void set_content_provider( const char *content_type, ContentProviderWithoutLength provider, const std::function &resource_releaser = nullptr); void set_chunked_content_provider( const char *content_type, ContentProviderWithoutLength provider, const std::function &resource_releaser = nullptr); Response() = default; Response(const Response &) = default; Response &operator=(const Response &) = default; Response(Response &&) = default; Response &operator=(Response &&) = default; ~Response() { if (content_provider_resource_releaser_) { content_provider_resource_releaser_(); } } // private members... size_t content_length_ = 0; ContentProvider content_provider_; std::function content_provider_resource_releaser_; bool is_chunked_content_provider_ = false; }; class Stream { public: virtual ~Stream() = default; virtual bool is_readable() const = 0; virtual bool is_writable() const = 0; virtual ssize_t read(char *ptr, size_t size) = 0; virtual ssize_t write(const char *ptr, size_t size) = 0; virtual void get_remote_ip_and_port(std::string &ip, int &port) const = 0; virtual socket_t socket() const = 0; template ssize_t write_format(const char *fmt, const Args &...args); ssize_t write(const char *ptr); ssize_t write(const std::string &s); }; class TaskQueue { public: TaskQueue() = default; virtual ~TaskQueue() = default; virtual void enqueue(std::function fn) = 0; virtual void shutdown() = 0; virtual void on_idle(){}; }; class ThreadPool : public TaskQueue { public: explicit ThreadPool(size_t n) : shutdown_(false) { while (n) { threads_.emplace_back(worker(*this)); n--; } } ThreadPool(const ThreadPool &) = delete; ~ThreadPool() override = default; void enqueue(std::function fn) override { std::unique_lock lock(mutex_); jobs_.push_back(std::move(fn)); cond_.notify_one(); } void shutdown() override { // Stop all worker threads... { std::unique_lock lock(mutex_); shutdown_ = true; } cond_.notify_all(); // Join... for (auto &t : threads_) { t.join(); } } private: struct worker { explicit worker(ThreadPool &pool) : pool_(pool) {} void operator()() { for (;;) { std::function fn; { std::unique_lock lock(pool_.mutex_); pool_.cond_.wait( lock, [&] { return !pool_.jobs_.empty() || pool_.shutdown_; }); if (pool_.shutdown_ && pool_.jobs_.empty()) { break; } fn = pool_.jobs_.front(); pool_.jobs_.pop_front(); } assert(true == static_cast(fn)); fn(); } } ThreadPool &pool_; }; friend struct worker; std::vector threads_; std::list> jobs_; bool shutdown_; std::condition_variable cond_; std::mutex mutex_; }; using Logger = std::function; using SocketOptions = std::function; inline void default_socket_options(socket_t sock) { int yes = 1; #ifdef _WIN32 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&yes), sizeof(yes)); setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, reinterpret_cast(&yes), sizeof(yes)); #else #ifdef SO_REUSEPORT setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast(&yes), sizeof(yes)); #else setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&yes), sizeof(yes)); #endif #endif } class Server { public: using Handler = std::function; using ExceptionHandler = std::function; enum class HandlerResponse { Handled, Unhandled, }; using HandlerWithResponse = std::function; using HandlerWithContentReader = std::function; using Expect100ContinueHandler = std::function; Server(); virtual ~Server(); virtual bool is_valid() const; Server &Get(const char *pattern, Handler handler); Server &Get(const char *pattern, size_t pattern_len, Handler handler); Server &Post(const char *pattern, Handler handler); Server &Post(const char *pattern, size_t pattern_len, Handler handler); Server &Post(const char *pattern, HandlerWithContentReader handler); Server &Post(const char *pattern, size_t pattern_len, HandlerWithContentReader handler); Server &Put(const char *pattern, Handler handler); Server &Put(const char *pattern, size_t pattern_len, Handler handler); Server &Put(const char *pattern, HandlerWithContentReader handler); Server &Put(const char *pattern, size_t pattern_len, HandlerWithContentReader handler); Server &Patch(const char *pattern, Handler handler); Server &Patch(const char *pattern, size_t pattern_len, Handler handler); Server &Patch(const char *pattern, HandlerWithContentReader handler); Server &Patch(const char *pattern, size_t pattern_len, HandlerWithContentReader handler); Server &Delete(const char *pattern, Handler handler); Server &Delete(const char *pattern, size_t pattern_len, Handler handler); Server &Delete(const char *pattern, HandlerWithContentReader handler); Server &Delete(const char *pattern, size_t pattern_len, HandlerWithContentReader handler); Server &Options(const char *pattern, Handler handler); Server &Options(const char *pattern, size_t pattern_len, Handler handler); bool set_base_dir(const char *dir, const char *mount_point = nullptr); bool set_mount_point(const char *mount_point, const char *dir, Headers headers = Headers()); bool remove_mount_point(const char *mount_point); Server &set_file_extension_and_mimetype_mapping(const char *ext, const char *mime); Server &set_file_request_handler(Handler handler); Server &set_error_handler(HandlerWithResponse handler); Server &set_error_handler(Handler handler); Server &set_exception_handler(ExceptionHandler handler); Server &set_pre_routing_handler(HandlerWithResponse handler); Server &set_post_routing_handler(Handler handler); Server &set_expect_100_continue_handler(Expect100ContinueHandler handler); Server &set_logger(Logger logger); Server &set_address_family(int family); Server &set_tcp_nodelay(bool on); Server &set_socket_options(SocketOptions socket_options); Server &set_keep_alive_max_count(size_t count); Server &set_keep_alive_timeout(time_t sec); Server &set_read_timeout(time_t sec, time_t usec = 0); template Server &set_read_timeout(const std::chrono::duration &duration); Server &set_write_timeout(time_t sec, time_t usec = 0); template Server &set_write_timeout(const std::chrono::duration &duration); Server &set_idle_interval(time_t sec, time_t usec = 0); template Server &set_idle_interval(const std::chrono::duration &duration); Server &set_payload_max_length(size_t length); bool bind_to_port(const char *host, int port, int socket_flags = 0); int bind_to_any_port(const char *host, int socket_flags = 0); bool listen_after_bind(); bool listen(const char *host, int port, int socket_flags = 0); bool is_running() const; void stop(); std::function new_task_queue; protected: bool process_request(Stream &strm, bool close_connection, bool &connection_closed, const std::function &setup_request); std::atomic svr_sock_; size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT; time_t keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND; time_t read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND; time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND; time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND; time_t write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND; time_t idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND; time_t idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND; size_t payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH; private: using Handlers = std::vector>; using HandlersForContentReader = std::vector>; socket_t create_server_socket(const char *host, int port, int socket_flags, SocketOptions socket_options) const; int bind_internal(const char *host, int port, int socket_flags); bool listen_internal(); bool routing(Request &req, Response &res, Stream &strm); bool handle_file_request(const Request &req, Response &res, bool head = false); bool dispatch_request(Request &req, Response &res, const Handlers &handlers); bool dispatch_request_for_content_reader(Request &req, Response &res, ContentReader content_reader, const HandlersForContentReader &handlers); bool parse_request_line(const char *s, Request &req); void apply_ranges(const Request &req, Response &res, std::string &content_type, std::string &boundary); bool write_response(Stream &strm, bool close_connection, const Request &req, Response &res); bool write_response_with_content(Stream &strm, bool close_connection, const Request &req, Response &res); bool write_response_core(Stream &strm, bool close_connection, const Request &req, Response &res, bool need_apply_ranges); bool write_content_with_provider(Stream &strm, const Request &req, Response &res, const std::string &boundary, const std::string &content_type); bool read_content(Stream &strm, Request &req, Response &res); bool read_content_with_content_receiver(Stream &strm, Request &req, Response &res, ContentReceiver receiver, MultipartContentHeader multipart_header, ContentReceiver multipart_receiver); bool read_content_core(Stream &strm, Request &req, Response &res, ContentReceiver receiver, MultipartContentHeader mulitpart_header, ContentReceiver multipart_receiver); virtual bool process_and_close_socket(socket_t sock); struct MountPointEntry { std::string mount_point; std::string base_dir; Headers headers; }; std::vector base_dirs_; std::atomic is_running_; std::map file_extension_and_mimetype_map_; Handler file_request_handler_; Handlers get_handlers_; Handlers post_handlers_; HandlersForContentReader post_handlers_for_content_reader_; Handlers put_handlers_; HandlersForContentReader put_handlers_for_content_reader_; Handlers patch_handlers_; HandlersForContentReader patch_handlers_for_content_reader_; Handlers delete_handlers_; HandlersForContentReader delete_handlers_for_content_reader_; Handlers options_handlers_; HandlerWithResponse error_handler_; ExceptionHandler exception_handler_; HandlerWithResponse pre_routing_handler_; Handler post_routing_handler_; Logger logger_; Expect100ContinueHandler expect_100_continue_handler_; int address_family_ = AF_UNSPEC; bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY; SocketOptions socket_options_ = default_socket_options; }; enum class Error { Success = 0, Unknown, Connection, BindIPAddress, Read, Write, ExceedRedirectCount, Canceled, SSLConnection, SSLLoadingCerts, SSLServerVerification, UnsupportedMultipartBoundaryChars, Compression, }; class Result { public: Result(std::unique_ptr &&res, Error err, Headers &&request_headers = Headers{}) : res_(std::move(res)), err_(err), request_headers_(std::move(request_headers)) {} // Response operator bool() const { return res_ != nullptr; } bool operator==(std::nullptr_t) const { return res_ == nullptr; } bool operator!=(std::nullptr_t) const { return res_ != nullptr; } const Response &value() const { return *res_; } Response &value() { return *res_; } const Response &operator*() const { return *res_; } Response &operator*() { return *res_; } const Response *operator->() const { return res_.get(); } Response *operator->() { return res_.get(); } // Error Error error() const { return err_; } // Request Headers bool has_request_header(const char *key) const; std::string get_request_header_value(const char *key, size_t id = 0) const; template T get_request_header_value(const char *key, size_t id = 0) const; size_t get_request_header_value_count(const char *key) const; private: std::unique_ptr res_; Error err_; Headers request_headers_; }; class ClientImpl { public: explicit ClientImpl(const std::string &host); explicit ClientImpl(const std::string &host, int port); explicit ClientImpl(const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path); virtual ~ClientImpl(); virtual bool is_valid() const; Result Get(const char *path); Result Get(const char *path, const Headers &headers); Result Get(const char *path, Progress progress); Result Get(const char *path, const Headers &headers, Progress progress); Result Get(const char *path, ContentReceiver content_receiver); Result Get(const char *path, const Headers &headers, ContentReceiver content_receiver); Result Get(const char *path, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, const Headers &headers, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver); Result Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver); Result Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, const Params ¶ms, const Headers &headers, Progress progress = nullptr); Result Get(const char *path, const Params ¶ms, const Headers &headers, ContentReceiver content_receiver, Progress progress = nullptr); Result Get(const char *path, const Params ¶ms, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress = nullptr); Result Head(const char *path); Result Head(const char *path, const Headers &headers); Result Post(const char *path); Result Post(const char *path, const char *body, size_t content_length, const char *content_type); Result Post(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Post(const char *path, const std::string &body, const char *content_type); Result Post(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Post(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type); Result Post(const char *path, ContentProviderWithoutLength content_provider, const char *content_type); Result Post(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type); Result Post(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type); Result Post(const char *path, const Params ¶ms); Result Post(const char *path, const Headers &headers, const Params ¶ms); Result Post(const char *path, const MultipartFormDataItems &items); Result Post(const char *path, const Headers &headers, const MultipartFormDataItems &items); Result Post(const char *path, const Headers &headers, const MultipartFormDataItems &items, const std::string &boundary); Result Put(const char *path); Result Put(const char *path, const char *body, size_t content_length, const char *content_type); Result Put(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Put(const char *path, const std::string &body, const char *content_type); Result Put(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Put(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type); Result Put(const char *path, ContentProviderWithoutLength content_provider, const char *content_type); Result Put(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type); Result Put(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type); Result Put(const char *path, const Params ¶ms); Result Put(const char *path, const Headers &headers, const Params ¶ms); Result Patch(const char *path); Result Patch(const char *path, const char *body, size_t content_length, const char *content_type); Result Patch(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Patch(const char *path, const std::string &body, const char *content_type); Result Patch(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Patch(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type); Result Patch(const char *path, ContentProviderWithoutLength content_provider, const char *content_type); Result Patch(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type); Result Patch(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type); Result Delete(const char *path); Result Delete(const char *path, const Headers &headers); Result Delete(const char *path, const char *body, size_t content_length, const char *content_type); Result Delete(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Delete(const char *path, const std::string &body, const char *content_type); Result Delete(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Options(const char *path); Result Options(const char *path, const Headers &headers); bool send(Request &req, Response &res, Error &error); Result send(const Request &req); size_t is_socket_open() const; void stop(); void set_default_headers(Headers headers); void set_address_family(int family); void set_tcp_nodelay(bool on); void set_socket_options(SocketOptions socket_options); void set_connection_timeout(time_t sec, time_t usec = 0); template void set_connection_timeout(const std::chrono::duration &duration); void set_read_timeout(time_t sec, time_t usec = 0); template void set_read_timeout(const std::chrono::duration &duration); void set_write_timeout(time_t sec, time_t usec = 0); template void set_write_timeout(const std::chrono::duration &duration); void set_basic_auth(const char *username, const char *password); void set_bearer_token_auth(const char *token); #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void set_digest_auth(const char *username, const char *password); #endif void set_keep_alive(bool on); void set_follow_location(bool on); void set_url_encode(bool on); void set_compress(bool on); void set_decompress(bool on); void set_interface(const char *intf); void set_proxy(const char *host, int port); void set_proxy_basic_auth(const char *username, const char *password); void set_proxy_bearer_token_auth(const char *token); #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void set_proxy_digest_auth(const char *username, const char *password); #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void enable_server_certificate_verification(bool enabled); #endif void set_logger(Logger logger); protected: struct Socket { socket_t sock = INVALID_SOCKET; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT SSL *ssl = nullptr; #endif bool is_open() const { return sock != INVALID_SOCKET; } }; Result send_(Request &&req); virtual bool create_and_connect_socket(Socket &socket, Error &error); // All of: // shutdown_ssl // shutdown_socket // close_socket // should ONLY be called when socket_mutex_ is locked. // Also, shutdown_ssl and close_socket should also NOT be called concurrently // with a DIFFERENT thread sending requests using that socket. virtual void shutdown_ssl(Socket &socket, bool shutdown_gracefully); void shutdown_socket(Socket &socket); void close_socket(Socket &socket); // Similar to shutdown_ssl and close_socket, this should NOT be called // concurrently with a DIFFERENT thread sending requests from the socket void lock_socket_and_shutdown_and_close(); bool process_request(Stream &strm, Request &req, Response &res, bool close_connection, Error &error); bool write_content_with_provider(Stream &strm, const Request &req, Error &error); void copy_settings(const ClientImpl &rhs); // Socket endoint information const std::string host_; const int port_; const std::string host_and_port_; // Current open socket Socket socket_; mutable std::mutex socket_mutex_; std::recursive_mutex request_mutex_; // These are all protected under socket_mutex size_t socket_requests_in_flight_ = 0; std::thread::id socket_requests_are_from_thread_ = std::thread::id(); bool socket_should_be_closed_when_request_is_done_ = false; // Default headers Headers default_headers_; // Settings std::string client_cert_path_; std::string client_key_path_; time_t connection_timeout_sec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND; time_t connection_timeout_usec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND; time_t read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND; time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND; time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND; time_t write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND; std::string basic_auth_username_; std::string basic_auth_password_; std::string bearer_token_auth_token_; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT std::string digest_auth_username_; std::string digest_auth_password_; #endif bool keep_alive_ = false; bool follow_location_ = false; bool url_encode_ = true; int address_family_ = AF_UNSPEC; bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY; SocketOptions socket_options_ = nullptr; bool compress_ = false; bool decompress_ = true; std::string interface_; std::string proxy_host_; int proxy_port_ = -1; std::string proxy_basic_auth_username_; std::string proxy_basic_auth_password_; std::string proxy_bearer_token_auth_token_; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT std::string proxy_digest_auth_username_; std::string proxy_digest_auth_password_; #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT bool server_certificate_verification_ = true; #endif Logger logger_; private: socket_t create_client_socket(Error &error) const; bool read_response_line(Stream &strm, const Request &req, Response &res); bool write_request(Stream &strm, Request &req, bool close_connection, Error &error); bool redirect(Request &req, Response &res, Error &error); bool handle_request(Stream &strm, Request &req, Response &res, bool close_connection, Error &error); std::unique_ptr send_with_content_provider( Request &req, // const char *method, const char *path, const Headers &headers, const char *body, size_t content_length, ContentProvider content_provider, ContentProviderWithoutLength content_provider_without_length, const char *content_type, Error &error); Result send_with_content_provider( const char *method, const char *path, const Headers &headers, const char *body, size_t content_length, ContentProvider content_provider, ContentProviderWithoutLength content_provider_without_length, const char *content_type); virtual bool process_socket(const Socket &socket, std::function callback); virtual bool is_ssl() const; }; class Client { public: // Universal interface explicit Client(const char *scheme_host_port); explicit Client(const char *scheme_host_port, const std::string &client_cert_path, const std::string &client_key_path); // HTTP only interface explicit Client(const std::string &host, int port); explicit Client(const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path); ~Client(); bool is_valid() const; Result Get(const char *path); Result Get(const char *path, const Headers &headers); Result Get(const char *path, Progress progress); Result Get(const char *path, const Headers &headers, Progress progress); Result Get(const char *path, ContentReceiver content_receiver); Result Get(const char *path, const Headers &headers, ContentReceiver content_receiver); Result Get(const char *path, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, const Headers &headers, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver); Result Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver); Result Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress); Result Get(const char *path, const Params ¶ms, const Headers &headers, Progress progress = nullptr); Result Get(const char *path, const Params ¶ms, const Headers &headers, ContentReceiver content_receiver, Progress progress = nullptr); Result Get(const char *path, const Params ¶ms, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress = nullptr); Result Head(const char *path); Result Head(const char *path, const Headers &headers); Result Post(const char *path); Result Post(const char *path, const char *body, size_t content_length, const char *content_type); Result Post(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Post(const char *path, const std::string &body, const char *content_type); Result Post(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Post(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type); Result Post(const char *path, ContentProviderWithoutLength content_provider, const char *content_type); Result Post(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type); Result Post(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type); Result Post(const char *path, const Params ¶ms); Result Post(const char *path, const Headers &headers, const Params ¶ms); Result Post(const char *path, const MultipartFormDataItems &items); Result Post(const char *path, const Headers &headers, const MultipartFormDataItems &items); Result Post(const char *path, const Headers &headers, const MultipartFormDataItems &items, const std::string &boundary); Result Put(const char *path); Result Put(const char *path, const char *body, size_t content_length, const char *content_type); Result Put(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Put(const char *path, const std::string &body, const char *content_type); Result Put(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Put(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type); Result Put(const char *path, ContentProviderWithoutLength content_provider, const char *content_type); Result Put(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type); Result Put(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type); Result Put(const char *path, const Params ¶ms); Result Put(const char *path, const Headers &headers, const Params ¶ms); Result Patch(const char *path); Result Patch(const char *path, const char *body, size_t content_length, const char *content_type); Result Patch(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Patch(const char *path, const std::string &body, const char *content_type); Result Patch(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Patch(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type); Result Patch(const char *path, ContentProviderWithoutLength content_provider, const char *content_type); Result Patch(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type); Result Patch(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type); Result Delete(const char *path); Result Delete(const char *path, const Headers &headers); Result Delete(const char *path, const char *body, size_t content_length, const char *content_type); Result Delete(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type); Result Delete(const char *path, const std::string &body, const char *content_type); Result Delete(const char *path, const Headers &headers, const std::string &body, const char *content_type); Result Options(const char *path); Result Options(const char *path, const Headers &headers); bool send(Request &req, Response &res, Error &error); Result send(const Request &req); size_t is_socket_open() const; void stop(); void set_default_headers(Headers headers); void set_address_family(int family); void set_tcp_nodelay(bool on); void set_socket_options(SocketOptions socket_options); void set_connection_timeout(time_t sec, time_t usec = 0); template void set_connection_timeout(const std::chrono::duration &duration); void set_read_timeout(time_t sec, time_t usec = 0); template void set_read_timeout(const std::chrono::duration &duration); void set_write_timeout(time_t sec, time_t usec = 0); template void set_write_timeout(const std::chrono::duration &duration); void set_basic_auth(const char *username, const char *password); void set_bearer_token_auth(const char *token); #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void set_digest_auth(const char *username, const char *password); #endif void set_keep_alive(bool on); void set_follow_location(bool on); void set_url_encode(bool on); void set_compress(bool on); void set_decompress(bool on); void set_interface(const char *intf); void set_proxy(const char *host, int port); void set_proxy_basic_auth(const char *username, const char *password); void set_proxy_bearer_token_auth(const char *token); #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void set_proxy_digest_auth(const char *username, const char *password); #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void enable_server_certificate_verification(bool enabled); #endif void set_logger(Logger logger); // SSL #ifdef CPPHTTPLIB_OPENSSL_SUPPORT void set_ca_cert_path(const char *ca_cert_file_path, const char *ca_cert_dir_path = nullptr); void set_ca_cert_store(X509_STORE *ca_cert_store); long get_openssl_verify_result() const; SSL_CTX *ssl_context() const; #endif private: std::unique_ptr cli_; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT bool is_ssl_ = false; #endif }; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT class SSLServer : public Server { public: SSLServer(const char *cert_path, const char *private_key_path, const char *client_ca_cert_file_path = nullptr, const char *client_ca_cert_dir_path = nullptr); SSLServer(X509 *cert, EVP_PKEY *private_key, X509_STORE *client_ca_cert_store = nullptr); ~SSLServer() override; bool is_valid() const override; private: bool process_and_close_socket(socket_t sock) override; SSL_CTX *ctx_; std::mutex ctx_mutex_; }; class SSLClient : public ClientImpl { public: explicit SSLClient(const std::string &host); explicit SSLClient(const std::string &host, int port); explicit SSLClient(const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path); explicit SSLClient(const std::string &host, int port, X509 *client_cert, EVP_PKEY *client_key); ~SSLClient() override; bool is_valid() const override; void set_ca_cert_path(const char *ca_cert_file_path, const char *ca_cert_dir_path = nullptr); void set_ca_cert_store(X509_STORE *ca_cert_store); long get_openssl_verify_result() const; SSL_CTX *ssl_context() const; private: bool create_and_connect_socket(Socket &socket, Error &error) override; void shutdown_ssl(Socket &socket, bool shutdown_gracefully) override; bool process_socket(const Socket &socket, std::function callback) override; bool is_ssl() const override; bool connect_with_proxy(Socket &sock, Response &res, bool &success, Error &error); bool initialize_ssl(Socket &socket, Error &error); bool load_certs(); bool verify_host(X509 *server_cert) const; bool verify_host_with_subject_alt_name(X509 *server_cert) const; bool verify_host_with_common_name(X509 *server_cert) const; bool check_host_name(const char *pattern, size_t pattern_len) const; SSL_CTX *ctx_; std::mutex ctx_mutex_; std::once_flag initialize_cert_; std::vector host_components_; std::string ca_cert_file_path_; std::string ca_cert_dir_path_; long verify_result_ = 0; friend class ClientImpl; }; #endif // ---------------------------------------------------------------------------- /* * Implementation */ namespace detail { inline bool is_hex(char c, int &v) { if (0x20 <= c && isdigit(c)) { v = c - '0'; return true; } else if ('A' <= c && c <= 'F') { v = c - 'A' + 10; return true; } else if ('a' <= c && c <= 'f') { v = c - 'a' + 10; return true; } return false; } inline bool from_hex_to_i(const std::string &s, size_t i, size_t cnt, int &val) { if (i >= s.size()) { return false; } val = 0; for (; cnt; i++, cnt--) { if (!s[i]) { return false; } int v = 0; if (is_hex(s[i], v)) { val = val * 16 + v; } else { return false; } } return true; } inline std::string from_i_to_hex(size_t n) { const char *charset = "0123456789abcdef"; std::string ret; do { ret = charset[n & 15] + ret; n >>= 4; } while (n > 0); return ret; } inline size_t to_utf8(int code, char *buff) { if (code < 0x0080) { buff[0] = (code & 0x7F); return 1; } else if (code < 0x0800) { buff[0] = static_cast(0xC0 | ((code >> 6) & 0x1F)); buff[1] = static_cast(0x80 | (code & 0x3F)); return 2; } else if (code < 0xD800) { buff[0] = static_cast(0xE0 | ((code >> 12) & 0xF)); buff[1] = static_cast(0x80 | ((code >> 6) & 0x3F)); buff[2] = static_cast(0x80 | (code & 0x3F)); return 3; } else if (code < 0xE000) { // D800 - DFFF is invalid... return 0; } else if (code < 0x10000) { buff[0] = static_cast(0xE0 | ((code >> 12) & 0xF)); buff[1] = static_cast(0x80 | ((code >> 6) & 0x3F)); buff[2] = static_cast(0x80 | (code & 0x3F)); return 3; } else if (code < 0x110000) { buff[0] = static_cast(0xF0 | ((code >> 18) & 0x7)); buff[1] = static_cast(0x80 | ((code >> 12) & 0x3F)); buff[2] = static_cast(0x80 | ((code >> 6) & 0x3F)); buff[3] = static_cast(0x80 | (code & 0x3F)); return 4; } // NOTREACHED return 0; } // NOTE: This code came up with the following stackoverflow post: // https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c inline std::string base64_encode(const std::string &in) { static const auto lookup = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; std::string out; out.reserve(in.size()); int val = 0; int valb = -6; for (auto c : in) { val = (val << 8) + static_cast(c); valb += 8; while (valb >= 0) { out.push_back(lookup[(val >> valb) & 0x3F]); valb -= 6; } } if (valb > -6) { out.push_back(lookup[((val << 8) >> (valb + 8)) & 0x3F]); } while (out.size() % 4) { out.push_back('='); } return out; } inline bool is_file(const std::string &path) { struct stat st; return stat(path.c_str(), &st) >= 0 && S_ISREG(st.st_mode); } inline bool is_dir(const std::string &path) { struct stat st; return stat(path.c_str(), &st) >= 0 && S_ISDIR(st.st_mode); } inline bool is_valid_path(const std::string &path) { size_t level = 0; size_t i = 0; // Skip slash while (i < path.size() && path[i] == '/') { i++; } while (i < path.size()) { // Read component auto beg = i; while (i < path.size() && path[i] != '/') { i++; } auto len = i - beg; assert(len > 0); if (!path.compare(beg, len, ".")) { ; } else if (!path.compare(beg, len, "..")) { if (level == 0) { return false; } level--; } else { level++; } // Skip slash while (i < path.size() && path[i] == '/') { i++; } } return true; } inline std::string encode_query_param(const std::string &value) { std::ostringstream escaped; escaped.fill('0'); escaped << std::hex; for (auto c : value) { if (std::isalnum(static_cast(c)) || c == '-' || c == '_' || c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') { escaped << c; } else { escaped << std::uppercase; escaped << '%' << std::setw(2) << static_cast(static_cast(c)); escaped << std::nouppercase; } } return escaped.str(); } inline std::string encode_url(const std::string &s) { std::string result; result.reserve(s.size()); for (size_t i = 0; s[i]; i++) { switch (s[i]) { case ' ': result += "%20"; break; case '+': result += "%2B"; break; case '\r': result += "%0D"; break; case '\n': result += "%0A"; break; case '\'': result += "%27"; break; case ',': result += "%2C"; break; // case ':': result += "%3A"; break; // ok? probably... case ';': result += "%3B"; break; default: auto c = static_cast(s[i]); if (c >= 0x80) { result += '%'; char hex[4]; auto len = snprintf(hex, sizeof(hex) - 1, "%02X", c); assert(len == 2); result.append(hex, static_cast(len)); } else { result += s[i]; } break; } } return result; } inline std::string decode_url(const std::string &s, bool convert_plus_to_space) { std::string result; for (size_t i = 0; i < s.size(); i++) { if (s[i] == '%' && i + 1 < s.size()) { if (s[i + 1] == 'u') { int val = 0; if (from_hex_to_i(s, i + 2, 4, val)) { // 4 digits Unicode codes char buff[4]; size_t len = to_utf8(val, buff); if (len > 0) { result.append(buff, len); } i += 5; // 'u0000' } else { result += s[i]; } } else { int val = 0; if (from_hex_to_i(s, i + 1, 2, val)) { // 2 digits hex codes result += static_cast(val); i += 2; // '00' } else { result += s[i]; } } } else if (convert_plus_to_space && s[i] == '+') { result += ' '; } else { result += s[i]; } } return result; } inline void read_file(const std::string &path, std::string &out) { std::ifstream fs(path, std::ios_base::binary); fs.seekg(0, std::ios_base::end); auto size = fs.tellg(); fs.seekg(0); out.resize(static_cast(size)); fs.read(&out[0], static_cast(size)); } inline std::string file_extension(const std::string &path) { std::smatch m; static auto re = std::regex("\\.([a-zA-Z0-9]+)$"); if (std::regex_search(path, m, re)) { return m[1].str(); } return std::string(); } inline bool is_space_or_tab(char c) { return c == ' ' || c == '\t'; } inline std::pair trim(const char *b, const char *e, size_t left, size_t right) { while (b + left < e && is_space_or_tab(b[left])) { left++; } while (right > 0 && is_space_or_tab(b[right - 1])) { right--; } return std::make_pair(left, right); } inline std::string trim_copy(const std::string &s) { auto r = trim(s.data(), s.data() + s.size(), 0, s.size()); return s.substr(r.first, r.second - r.first); } template void split(const char *b, const char *e, char d, Fn fn) { size_t i = 0; size_t beg = 0; while (e ? (b + i < e) : (b[i] != '\0')) { if (b[i] == d) { auto r = trim(b, e, beg, i); if (r.first < r.second) { fn(&b[r.first], &b[r.second]); } beg = i + 1; } i++; } if (i) { auto r = trim(b, e, beg, i); if (r.first < r.second) { fn(&b[r.first], &b[r.second]); } } } // NOTE: until the read size reaches `fixed_buffer_size`, use `fixed_buffer` // to store data. The call can set memory on stack for performance. class stream_line_reader { public: stream_line_reader(Stream &strm, char *fixed_buffer, size_t fixed_buffer_size) : strm_(strm), fixed_buffer_(fixed_buffer), fixed_buffer_size_(fixed_buffer_size) {} const char *ptr() const { if (glowable_buffer_.empty()) { return fixed_buffer_; } else { return glowable_buffer_.data(); } } size_t size() const { if (glowable_buffer_.empty()) { return fixed_buffer_used_size_; } else { return glowable_buffer_.size(); } } bool end_with_crlf() const { auto end = ptr() + size(); return size() >= 2 && end[-2] == '\r' && end[-1] == '\n'; } bool getline() { fixed_buffer_used_size_ = 0; glowable_buffer_.clear(); for (size_t i = 0;; i++) { char byte; auto n = strm_.read(&byte, 1); if (n < 0) { return false; } else if (n == 0) { if (i == 0) { return false; } else { break; } } append(byte); if (byte == '\n') { break; } } return true; } private: void append(char c) { if (fixed_buffer_used_size_ < fixed_buffer_size_ - 1) { fixed_buffer_[fixed_buffer_used_size_++] = c; fixed_buffer_[fixed_buffer_used_size_] = '\0'; } else { if (glowable_buffer_.empty()) { assert(fixed_buffer_[fixed_buffer_used_size_] == '\0'); glowable_buffer_.assign(fixed_buffer_, fixed_buffer_used_size_); } glowable_buffer_ += c; } } Stream &strm_; char *fixed_buffer_; const size_t fixed_buffer_size_; size_t fixed_buffer_used_size_ = 0; std::string glowable_buffer_; }; inline int close_socket(socket_t sock) { #ifdef _WIN32 return closesocket(sock); #else return close(sock); #endif } template inline ssize_t handle_EINTR(T fn) { ssize_t res = false; while (true) { res = fn(); if (res < 0 && errno == EINTR) { continue; } break; } return res; } inline ssize_t select_read(socket_t sock, time_t sec, time_t usec) { #ifdef CPPHTTPLIB_USE_POLL struct pollfd pfd_read; pfd_read.fd = sock; pfd_read.events = POLLIN; auto timeout = static_cast(sec * 1000 + usec / 1000); return handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); }); #else #ifndef _WIN32 if (sock >= FD_SETSIZE) { return 1; } #endif fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); timeval tv; tv.tv_sec = static_cast(sec); tv.tv_usec = static_cast(usec); return handle_EINTR([&]() { return select(static_cast(sock + 1), &fds, nullptr, nullptr, &tv); }); #endif } inline ssize_t select_write(socket_t sock, time_t sec, time_t usec) { #ifdef CPPHTTPLIB_USE_POLL struct pollfd pfd_read; pfd_read.fd = sock; pfd_read.events = POLLOUT; auto timeout = static_cast(sec * 1000 + usec / 1000); return handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); }); #else #ifndef _WIN32 if (sock >= FD_SETSIZE) { return 1; } #endif fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); timeval tv; tv.tv_sec = static_cast(sec); tv.tv_usec = static_cast(usec); return handle_EINTR([&]() { return select(static_cast(sock + 1), nullptr, &fds, nullptr, &tv); }); #endif } inline bool wait_until_socket_is_ready(socket_t sock, time_t sec, time_t usec) { #ifdef CPPHTTPLIB_USE_POLL struct pollfd pfd_read; pfd_read.fd = sock; pfd_read.events = POLLIN | POLLOUT; auto timeout = static_cast(sec * 1000 + usec / 1000); auto poll_res = handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); }); if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) { int error = 0; socklen_t len = sizeof(error); auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error), &len); return res >= 0 && !error; } return false; #else #ifndef _WIN32 if (sock >= FD_SETSIZE) { return false; } #endif fd_set fdsr; FD_ZERO(&fdsr); FD_SET(sock, &fdsr); auto fdsw = fdsr; auto fdse = fdsr; timeval tv; tv.tv_sec = static_cast(sec); tv.tv_usec = static_cast(usec); auto ret = handle_EINTR([&]() { return select(static_cast(sock + 1), &fdsr, &fdsw, &fdse, &tv); }); if (ret > 0 && (FD_ISSET(sock, &fdsr) || FD_ISSET(sock, &fdsw))) { int error = 0; socklen_t len = sizeof(error); return getsockopt(sock, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error), &len) >= 0 && !error; } return false; #endif } class SocketStream : public Stream { public: SocketStream(socket_t sock, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec); ~SocketStream() override; bool is_readable() const override; bool is_writable() const override; ssize_t read(char *ptr, size_t size) override; ssize_t write(const char *ptr, size_t size) override; void get_remote_ip_and_port(std::string &ip, int &port) const override; socket_t socket() const override; private: socket_t sock_; time_t read_timeout_sec_; time_t read_timeout_usec_; time_t write_timeout_sec_; time_t write_timeout_usec_; }; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT class SSLSocketStream : public Stream { public: SSLSocketStream(socket_t sock, SSL *ssl, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec); ~SSLSocketStream() override; bool is_readable() const override; bool is_writable() const override; ssize_t read(char *ptr, size_t size) override; ssize_t write(const char *ptr, size_t size) override; void get_remote_ip_and_port(std::string &ip, int &port) const override; socket_t socket() const override; private: socket_t sock_; SSL *ssl_; time_t read_timeout_sec_; time_t read_timeout_usec_; time_t write_timeout_sec_; time_t write_timeout_usec_; }; #endif class BufferStream : public Stream { public: BufferStream() = default; ~BufferStream() override = default; bool is_readable() const override; bool is_writable() const override; ssize_t read(char *ptr, size_t size) override; ssize_t write(const char *ptr, size_t size) override; void get_remote_ip_and_port(std::string &ip, int &port) const override; socket_t socket() const override; const std::string &get_buffer() const; private: std::string buffer; size_t position = 0; }; inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) { using namespace std::chrono; auto start = steady_clock::now(); while (true) { auto val = select_read(sock, 0, 10000); if (val < 0) { return false; } else if (val == 0) { auto current = steady_clock::now(); auto duration = duration_cast(current - start); auto timeout = keep_alive_timeout_sec * 1000; if (duration.count() > timeout) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); } else { return true; } } } template inline bool process_server_socket_core(socket_t sock, size_t keep_alive_max_count, time_t keep_alive_timeout_sec, T callback) { assert(keep_alive_max_count > 0); auto ret = false; auto count = keep_alive_max_count; while (count > 0 && keep_alive(sock, keep_alive_timeout_sec)) { auto close_connection = count == 1; auto connection_closed = false; ret = callback(close_connection, connection_closed); if (!ret || connection_closed) { break; } count--; } return ret; } template inline bool process_server_socket(socket_t sock, size_t keep_alive_max_count, time_t keep_alive_timeout_sec, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec, T callback) { return process_server_socket_core( sock, keep_alive_max_count, keep_alive_timeout_sec, [&](bool close_connection, bool &connection_closed) { SocketStream strm(sock, read_timeout_sec, read_timeout_usec, write_timeout_sec, write_timeout_usec); return callback(strm, close_connection, connection_closed); }); } template inline bool process_client_socket(socket_t sock, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec, T callback) { SocketStream strm(sock, read_timeout_sec, read_timeout_usec, write_timeout_sec, write_timeout_usec); return callback(strm); } inline int shutdown_socket(socket_t sock) { #ifdef _WIN32 return shutdown(sock, SD_BOTH); #else return shutdown(sock, SHUT_RDWR); #endif } template socket_t create_socket(const char *host, int port, int address_family, int socket_flags, bool tcp_nodelay, SocketOptions socket_options, BindOrConnect bind_or_connect) { // Get address info struct addrinfo hints; struct addrinfo *result; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = address_family; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = socket_flags; hints.ai_protocol = 0; auto service = std::to_string(port); if (getaddrinfo(host, service.c_str(), &hints, &result)) { #ifdef __linux__ res_init(); #endif return INVALID_SOCKET; } for (auto rp = result; rp; rp = rp->ai_next) { // Create a socket #ifdef _WIN32 auto sock = WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol, nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED); /** * Since the WSA_FLAG_NO_HANDLE_INHERIT is only supported on Windows 7 SP1 * and above the socket creation fails on older Windows Systems. * * Let's try to create a socket the old way in this case. * * Reference: * https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketa * * WSA_FLAG_NO_HANDLE_INHERIT: * This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with * SP1, and later * */ if (sock == INVALID_SOCKET) { sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); } #else auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); #endif if (sock == INVALID_SOCKET) { continue; } #ifndef _WIN32 if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; } #endif if (tcp_nodelay) { int yes = 1; setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&yes), sizeof(yes)); } if (socket_options) { socket_options(sock); } if (rp->ai_family == AF_INET6) { int no = 0; setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast(&no), sizeof(no)); } // bind or connect if (bind_or_connect(sock, *rp)) { freeaddrinfo(result); return sock; } close_socket(sock); } freeaddrinfo(result); return INVALID_SOCKET; } inline void set_nonblocking(socket_t sock, bool nonblocking) { #ifdef _WIN32 auto flags = nonblocking ? 1UL : 0UL; ioctlsocket(sock, FIONBIO, &flags); #else auto flags = fcntl(sock, F_GETFL, 0); fcntl(sock, F_SETFL, nonblocking ? (flags | O_NONBLOCK) : (flags & (~O_NONBLOCK))); #endif } inline bool is_connection_error() { #ifdef _WIN32 return WSAGetLastError() != WSAEWOULDBLOCK; #else return errno != EINPROGRESS; #endif } inline bool bind_ip_address(socket_t sock, const char *host) { struct addrinfo hints; struct addrinfo *result; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0; if (getaddrinfo(host, "0", &hints, &result)) { return false; } auto ret = false; for (auto rp = result; rp; rp = rp->ai_next) { const auto &ai = *rp; if (!::bind(sock, ai.ai_addr, static_cast(ai.ai_addrlen))) { ret = true; break; } } freeaddrinfo(result); return ret; } #if !defined _WIN32 && !defined ANDROID #define USE_IF2IP #endif #ifdef USE_IF2IP inline std::string if2ip(const std::string &ifn) { struct ifaddrs *ifap; getifaddrs(&ifap); for (auto ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr && ifn == ifa->ifa_name) { if (ifa->ifa_addr->sa_family == AF_INET) { auto sa = reinterpret_cast(ifa->ifa_addr); char buf[INET_ADDRSTRLEN]; if (inet_ntop(AF_INET, &sa->sin_addr, buf, INET_ADDRSTRLEN)) { freeifaddrs(ifap); return std::string(buf, INET_ADDRSTRLEN); } } } } freeifaddrs(ifap); return std::string(); } #endif inline socket_t create_client_socket( const char *host, int port, int address_family, bool tcp_nodelay, SocketOptions socket_options, time_t connection_timeout_sec, time_t connection_timeout_usec, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec, const std::string &intf, Error &error) { auto sock = create_socket( host, port, address_family, 0, tcp_nodelay, std::move(socket_options), [&](socket_t sock, struct addrinfo &ai) -> bool { if (!intf.empty()) { #ifdef USE_IF2IP auto ip = if2ip(intf); if (ip.empty()) { ip = intf; } if (!bind_ip_address(sock, ip.c_str())) { error = Error::BindIPAddress; return false; } #endif } set_nonblocking(sock, true); auto ret = ::connect(sock, ai.ai_addr, static_cast(ai.ai_addrlen)); if (ret < 0) { if (is_connection_error() || !wait_until_socket_is_ready(sock, connection_timeout_sec, connection_timeout_usec)) { error = Error::Connection; return false; } } set_nonblocking(sock, false); { timeval tv; tv.tv_sec = static_cast(read_timeout_sec); tv.tv_usec = static_cast(read_timeout_usec); setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)); } { timeval tv; tv.tv_sec = static_cast(write_timeout_sec); tv.tv_usec = static_cast(write_timeout_usec); setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)); } error = Error::Success; return true; }); if (sock != INVALID_SOCKET) { error = Error::Success; } else { if (error == Error::Success) { error = Error::Connection; } } return sock; } inline void get_remote_ip_and_port(const struct sockaddr_storage &addr, socklen_t addr_len, std::string &ip, int &port) { if (addr.ss_family == AF_INET) { port = ntohs(reinterpret_cast(&addr)->sin_port); } else if (addr.ss_family == AF_INET6) { port = ntohs(reinterpret_cast(&addr)->sin6_port); } std::array ipstr{}; if (!getnameinfo(reinterpret_cast(&addr), addr_len, ipstr.data(), static_cast(ipstr.size()), nullptr, 0, NI_NUMERICHOST)) { ip = ipstr.data(); } } inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) { struct sockaddr_storage addr; socklen_t addr_len = sizeof(addr); if (!getpeername(sock, reinterpret_cast(&addr), &addr_len)) { get_remote_ip_and_port(addr, addr_len, ip, port); } } inline constexpr unsigned int str2tag_core(const char *s, size_t l, unsigned int h) { return (l == 0) ? h : str2tag_core(s + 1, l - 1, (h * 33) ^ static_cast(*s)); } inline unsigned int str2tag(const std::string &s) { return str2tag_core(s.data(), s.size(), 0); } namespace udl { inline constexpr unsigned int operator"" _(const char *s, size_t l) { return str2tag_core(s, l, 0); } } // namespace udl inline const char * find_content_type(const std::string &path, const std::map &user_data) { auto ext = file_extension(path); auto it = user_data.find(ext); if (it != user_data.end()) { return it->second.c_str(); } using udl::operator""_; switch (str2tag(ext)) { default: return nullptr; case "css"_: return "text/css"; case "csv"_: return "text/csv"; case "txt"_: return "text/plain"; case "vtt"_: return "text/vtt"; case "htm"_: case "html"_: return "text/html"; case "apng"_: return "image/apng"; case "avif"_: return "image/avif"; case "bmp"_: return "image/bmp"; case "gif"_: return "image/gif"; case "png"_: return "image/png"; case "svg"_: return "image/svg+xml"; case "webp"_: return "image/webp"; case "ico"_: return "image/x-icon"; case "tif"_: return "image/tiff"; case "tiff"_: return "image/tiff"; case "jpg"_: case "jpeg"_: return "image/jpeg"; case "mp4"_: return "video/mp4"; case "mpeg"_: return "video/mpeg"; case "webm"_: return "video/webm"; case "mp3"_: return "audio/mp3"; case "mpga"_: return "audio/mpeg"; case "weba"_: return "audio/webm"; case "wav"_: return "audio/wave"; case "otf"_: return "font/otf"; case "ttf"_: return "font/ttf"; case "woff"_: return "font/woff"; case "woff2"_: return "font/woff2"; case "7z"_: return "application/x-7z-compressed"; case "atom"_: return "application/atom+xml"; case "pdf"_: return "application/pdf"; case "js"_: case "mjs"_: return "application/javascript"; case "json"_: return "application/json"; case "rss"_: return "application/rss+xml"; case "tar"_: return "application/x-tar"; case "xht"_: case "xhtml"_: return "application/xhtml+xml"; case "xslt"_: return "application/xslt+xml"; case "xml"_: return "application/xml"; case "gz"_: return "application/gzip"; case "zip"_: return "application/zip"; case "wasm"_: return "application/wasm"; } } inline const char *status_message(int status) { switch (status) { case 100: return "Continue"; case 101: return "Switching Protocol"; case 102: return "Processing"; case 103: return "Early Hints"; case 200: return "OK"; case 201: return "Created"; case 202: return "Accepted"; case 203: return "Non-Authoritative Information"; case 204: return "No Content"; case 205: return "Reset Content"; case 206: return "Partial Content"; case 207: return "Multi-Status"; case 208: return "Already Reported"; case 226: return "IM Used"; case 300: return "Multiple Choice"; case 301: return "Moved Permanently"; case 302: return "Found"; case 303: return "See Other"; case 304: return "Not Modified"; case 305: return "Use Proxy"; case 306: return "unused"; case 307: return "Temporary Redirect"; case 308: return "Permanent Redirect"; case 400: return "Bad Request"; case 401: return "Unauthorized"; case 402: return "Payment Required"; case 403: return "Forbidden"; case 404: return "Not Found"; case 405: return "Method Not Allowed"; case 406: return "Not Acceptable"; case 407: return "Proxy Authentication Required"; case 408: return "Request Timeout"; case 409: return "Conflict"; case 410: return "Gone"; case 411: return "Length Required"; case 412: return "Precondition Failed"; case 413: return "Payload Too Large"; case 414: return "URI Too Long"; case 415: return "Unsupported Media Type"; case 416: return "Range Not Satisfiable"; case 417: return "Expectation Failed"; case 418: return "I'm a teapot"; case 421: return "Misdirected Request"; case 422: return "Unprocessable Entity"; case 423: return "Locked"; case 424: return "Failed Dependency"; case 425: return "Too Early"; case 426: return "Upgrade Required"; case 428: return "Precondition Required"; case 429: return "Too Many Requests"; case 431: return "Request Header Fields Too Large"; case 451: return "Unavailable For Legal Reasons"; case 501: return "Not Implemented"; case 502: return "Bad Gateway"; case 503: return "Service Unavailable"; case 504: return "Gateway Timeout"; case 505: return "HTTP Version Not Supported"; case 506: return "Variant Also Negotiates"; case 507: return "Insufficient Storage"; case 508: return "Loop Detected"; case 510: return "Not Extended"; case 511: return "Network Authentication Required"; default: case 500: return "Internal Server Error"; } } inline bool can_compress_content_type(const std::string &content_type) { return (!content_type.find("text/") && content_type != "text/event-stream") || content_type == "image/svg+xml" || content_type == "application/javascript" || content_type == "application/json" || content_type == "application/xml" || content_type == "application/xhtml+xml"; } enum class EncodingType { None = 0, Gzip, Brotli }; inline EncodingType encoding_type(const Request &req, const Response &res) { auto ret = detail::can_compress_content_type(res.get_header_value("Content-Type")); if (!ret) { return EncodingType::None; } const auto &s = req.get_header_value("Accept-Encoding"); (void)(s); #ifdef CPPHTTPLIB_BROTLI_SUPPORT // TODO: 'Accept-Encoding' has br, not br;q=0 ret = s.find("br") != std::string::npos; if (ret) { return EncodingType::Brotli; } #endif #ifdef CPPHTTPLIB_ZLIB_SUPPORT // TODO: 'Accept-Encoding' has gzip, not gzip;q=0 ret = s.find("gzip") != std::string::npos; if (ret) { return EncodingType::Gzip; } #endif return EncodingType::None; } class compressor { public: virtual ~compressor(){}; typedef std::function Callback; virtual bool compress(const char *data, size_t data_length, bool last, Callback callback) = 0; }; class decompressor { public: virtual ~decompressor() {} virtual bool is_valid() const = 0; typedef std::function Callback; virtual bool decompress(const char *data, size_t data_length, Callback callback) = 0; }; class nocompressor : public compressor { public: ~nocompressor(){}; bool compress(const char *data, size_t data_length, bool /*last*/, Callback callback) override { if (!data_length) { return true; } return callback(data, data_length); } }; #ifdef CPPHTTPLIB_ZLIB_SUPPORT class gzip_compressor : public compressor { public: gzip_compressor() { std::memset(&strm_, 0, sizeof(strm_)); strm_.zalloc = Z_NULL; strm_.zfree = Z_NULL; strm_.opaque = Z_NULL; is_valid_ = deflateInit2(&strm_, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY) == Z_OK; } ~gzip_compressor() { deflateEnd(&strm_); } bool compress(const char *data, size_t data_length, bool last, Callback callback) override { assert(is_valid_); auto flush = last ? Z_FINISH : Z_NO_FLUSH; strm_.avail_in = static_cast(data_length); strm_.next_in = const_cast(reinterpret_cast(data)); int ret = Z_OK; std::array buff{}; do { strm_.avail_out = buff.size(); strm_.next_out = reinterpret_cast(buff.data()); ret = deflate(&strm_, flush); if (ret == Z_STREAM_ERROR) { return false; } if (!callback(buff.data(), buff.size() - strm_.avail_out)) { return false; } } while (strm_.avail_out == 0); assert((last && ret == Z_STREAM_END) || (!last && ret == Z_OK)); assert(strm_.avail_in == 0); return true; } private: bool is_valid_ = false; z_stream strm_; }; class gzip_decompressor : public decompressor { public: gzip_decompressor() { std::memset(&strm_, 0, sizeof(strm_)); strm_.zalloc = Z_NULL; strm_.zfree = Z_NULL; strm_.opaque = Z_NULL; // 15 is the value of wbits, which should be at the maximum possible value // to ensure that any gzip stream can be decoded. The offset of 32 specifies // that the stream type should be automatically detected either gzip or // deflate. is_valid_ = inflateInit2(&strm_, 32 + 15) == Z_OK; } ~gzip_decompressor() { inflateEnd(&strm_); } bool is_valid() const override { return is_valid_; } bool decompress(const char *data, size_t data_length, Callback callback) override { assert(is_valid_); int ret = Z_OK; strm_.avail_in = static_cast(data_length); strm_.next_in = const_cast(reinterpret_cast(data)); std::array buff{}; while (strm_.avail_in > 0) { strm_.avail_out = buff.size(); strm_.next_out = reinterpret_cast(buff.data()); ret = inflate(&strm_, Z_NO_FLUSH); assert(ret != Z_STREAM_ERROR); switch (ret) { case Z_NEED_DICT: case Z_DATA_ERROR: case Z_MEM_ERROR: inflateEnd(&strm_); return false; } if (!callback(buff.data(), buff.size() - strm_.avail_out)) { return false; } } return ret == Z_OK || ret == Z_STREAM_END; } private: bool is_valid_ = false; z_stream strm_; }; #endif #ifdef CPPHTTPLIB_BROTLI_SUPPORT class brotli_compressor : public compressor { public: brotli_compressor() { state_ = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr); } ~brotli_compressor() { BrotliEncoderDestroyInstance(state_); } bool compress(const char *data, size_t data_length, bool last, Callback callback) override { std::array buff{}; auto operation = last ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS; auto available_in = data_length; auto next_in = reinterpret_cast(data); for (;;) { if (last) { if (BrotliEncoderIsFinished(state_)) { break; } } else { if (!available_in) { break; } } auto available_out = buff.size(); auto next_out = buff.data(); if (!BrotliEncoderCompressStream(state_, operation, &available_in, &next_in, &available_out, &next_out, nullptr)) { return false; } auto output_bytes = buff.size() - available_out; if (output_bytes) { callback(reinterpret_cast(buff.data()), output_bytes); } } return true; } private: BrotliEncoderState *state_ = nullptr; }; class brotli_decompressor : public decompressor { public: brotli_decompressor() { decoder_s = BrotliDecoderCreateInstance(0, 0, 0); decoder_r = decoder_s ? BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT : BROTLI_DECODER_RESULT_ERROR; } ~brotli_decompressor() { if (decoder_s) { BrotliDecoderDestroyInstance(decoder_s); } } bool is_valid() const override { return decoder_s; } bool decompress(const char *data, size_t data_length, Callback callback) override { if (decoder_r == BROTLI_DECODER_RESULT_SUCCESS || decoder_r == BROTLI_DECODER_RESULT_ERROR) { return 0; } const uint8_t *next_in = (const uint8_t *)data; size_t avail_in = data_length; size_t total_out; decoder_r = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT; std::array buff{}; while (decoder_r == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) { char *next_out = buff.data(); size_t avail_out = buff.size(); decoder_r = BrotliDecoderDecompressStream( decoder_s, &avail_in, &next_in, &avail_out, reinterpret_cast(&next_out), &total_out); if (decoder_r == BROTLI_DECODER_RESULT_ERROR) { return false; } if (!callback(buff.data(), buff.size() - avail_out)) { return false; } } return decoder_r == BROTLI_DECODER_RESULT_SUCCESS || decoder_r == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; } private: BrotliDecoderResult decoder_r; BrotliDecoderState *decoder_s = nullptr; }; #endif inline bool has_header(const Headers &headers, const char *key) { return headers.find(key) != headers.end(); } inline const char *get_header_value(const Headers &headers, const char *key, size_t id = 0, const char *def = nullptr) { auto rng = headers.equal_range(key); auto it = rng.first; std::advance(it, static_cast(id)); if (it != rng.second) { return it->second.c_str(); } return def; } template inline T get_header_value(const Headers & /*headers*/, const char * /*key*/, size_t /*id*/ = 0, uint64_t /*def*/ = 0) {} template <> inline uint64_t get_header_value(const Headers &headers, const char *key, size_t id, uint64_t def) { auto rng = headers.equal_range(key); auto it = rng.first; std::advance(it, static_cast(id)); if (it != rng.second) { return std::strtoull(it->second.data(), nullptr, 10); } return def; } template inline bool parse_header(const char *beg, const char *end, T fn) { // Skip trailing spaces and tabs. while (beg < end && is_space_or_tab(end[-1])) { end--; } auto p = beg; while (p < end && *p != ':') { p++; } if (p == end) { return false; } auto key_end = p; if (*p++ != ':') { return false; } while (p < end && is_space_or_tab(*p)) { p++; } if (p < end) { fn(std::string(beg, key_end), decode_url(std::string(p, end), false)); return true; } return false; } inline bool read_headers(Stream &strm, Headers &headers) { const auto bufsiz = 2048; char buf[bufsiz]; stream_line_reader line_reader(strm, buf, bufsiz); for (;;) { if (!line_reader.getline()) { return false; } // Check if the line ends with CRLF. if (line_reader.end_with_crlf()) { // Blank line indicates end of headers. if (line_reader.size() == 2) { break; } } else { continue; // Skip invalid line. } // Exclude CRLF auto end = line_reader.ptr() + line_reader.size() - 2; parse_header(line_reader.ptr(), end, [&](std::string &&key, std::string &&val) { headers.emplace(std::move(key), std::move(val)); }); } return true; } inline bool read_content_with_length(Stream &strm, uint64_t len, Progress progress, ContentReceiverWithProgress out) { char buf[CPPHTTPLIB_RECV_BUFSIZ]; uint64_t r = 0; while (r < len) { auto read_len = static_cast(len - r); auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ)); if (n <= 0) { return false; } if (!out(buf, static_cast(n), r, len)) { return false; } r += static_cast(n); if (progress) { if (!progress(r, len)) { return false; } } } return true; } inline void skip_content_with_length(Stream &strm, uint64_t len) { char buf[CPPHTTPLIB_RECV_BUFSIZ]; uint64_t r = 0; while (r < len) { auto read_len = static_cast(len - r); auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ)); if (n <= 0) { return; } r += static_cast(n); } } inline bool read_content_without_length(Stream &strm, ContentReceiverWithProgress out) { char buf[CPPHTTPLIB_RECV_BUFSIZ]; uint64_t r = 0; for (;;) { auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ); if (n < 0) { return false; } else if (n == 0) { return true; } if (!out(buf, static_cast(n), r, 0)) { return false; } r += static_cast(n); } return true; } inline bool read_content_chunked(Stream &strm, ContentReceiverWithProgress out) { const auto bufsiz = 16; char buf[bufsiz]; stream_line_reader line_reader(strm, buf, bufsiz); if (!line_reader.getline()) { return false; } unsigned long chunk_len; while (true) { char *end_ptr; chunk_len = std::strtoul(line_reader.ptr(), &end_ptr, 16); if (end_ptr == line_reader.ptr()) { return false; } if (chunk_len == ULONG_MAX) { return false; } if (chunk_len == 0) { break; } if (!read_content_with_length(strm, chunk_len, nullptr, out)) { return false; } if (!line_reader.getline()) { return false; } if (strcmp(line_reader.ptr(), "\r\n")) { break; } if (!line_reader.getline()) { return false; } } if (chunk_len == 0) { // Reader terminator after chunks if (!line_reader.getline() || strcmp(line_reader.ptr(), "\r\n")) return false; } return true; } inline bool is_chunked_transfer_encoding(const Headers &headers) { return !strcasecmp(get_header_value(headers, "Transfer-Encoding", 0, ""), "chunked"); } template bool prepare_content_receiver(T &x, int &status, ContentReceiverWithProgress receiver, bool decompress, U callback) { if (decompress) { std::string encoding = x.get_header_value("Content-Encoding"); std::unique_ptr decompressor; if (encoding.find("gzip") != std::string::npos || encoding.find("deflate") != std::string::npos) { #ifdef CPPHTTPLIB_ZLIB_SUPPORT decompressor = detail::make_unique(); #else status = 415; return false; #endif } else if (encoding.find("br") != std::string::npos) { #ifdef CPPHTTPLIB_BROTLI_SUPPORT decompressor = detail::make_unique(); #else status = 415; return false; #endif } if (decompressor) { if (decompressor->is_valid()) { ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off, uint64_t len) { return decompressor->decompress(buf, n, [&](const char *buf, size_t n) { return receiver(buf, n, off, len); }); }; return callback(std::move(out)); } else { status = 500; return false; } } } ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off, uint64_t len) { return receiver(buf, n, off, len); }; return callback(std::move(out)); } template bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status, Progress progress, ContentReceiverWithProgress receiver, bool decompress) { return prepare_content_receiver( x, status, std::move(receiver), decompress, [&](const ContentReceiverWithProgress &out) { auto ret = true; auto exceed_payload_max_length = false; if (is_chunked_transfer_encoding(x.headers)) { ret = read_content_chunked(strm, out); } else if (!has_header(x.headers, "Content-Length")) { ret = read_content_without_length(strm, out); } else { auto len = get_header_value(x.headers, "Content-Length"); if (len > payload_max_length) { exceed_payload_max_length = true; skip_content_with_length(strm, len); ret = false; } else if (len > 0) { ret = read_content_with_length(strm, len, std::move(progress), out); } } if (!ret) { status = exceed_payload_max_length ? 413 : 400; } return ret; }); } inline ssize_t write_headers(Stream &strm, const Headers &headers) { ssize_t write_len = 0; for (const auto &x : headers) { auto len = strm.write_format("%s: %s\r\n", x.first.c_str(), x.second.c_str()); if (len < 0) { return len; } write_len += len; } auto len = strm.write("\r\n"); if (len < 0) { return len; } write_len += len; return write_len; } inline bool write_data(Stream &strm, const char *d, size_t l) { size_t offset = 0; while (offset < l) { auto length = strm.write(d + offset, l - offset); if (length < 0) { return false; } offset += static_cast(length); } return true; } template inline bool write_content(Stream &strm, const ContentProvider &content_provider, size_t offset, size_t length, T is_shutting_down, Error &error) { size_t end_offset = offset + length; auto ok = true; DataSink data_sink; data_sink.write = [&](const char *d, size_t l) -> bool { if (ok) { if (write_data(strm, d, l)) { offset += l; } else { ok = false; } } return ok; }; data_sink.is_writable = [&](void) { return ok && strm.is_writable(); }; while (offset < end_offset && !is_shutting_down()) { if (!content_provider(offset, end_offset - offset, data_sink)) { error = Error::Canceled; return false; } if (!ok) { error = Error::Write; return false; } } error = Error::Success; return true; } template inline bool write_content(Stream &strm, const ContentProvider &content_provider, size_t offset, size_t length, const T &is_shutting_down) { auto error = Error::Success; return write_content(strm, content_provider, offset, length, is_shutting_down, error); } template inline bool write_content_without_length(Stream &strm, const ContentProvider &content_provider, const T &is_shutting_down) { size_t offset = 0; auto data_available = true; auto ok = true; DataSink data_sink; data_sink.write = [&](const char *d, size_t l) -> bool { if (ok) { offset += l; if (!write_data(strm, d, l)) { ok = false; } } return ok; }; data_sink.done = [&](void) { data_available = false; }; data_sink.is_writable = [&](void) { return ok && strm.is_writable(); }; while (data_available && !is_shutting_down()) { if (!content_provider(offset, 0, data_sink)) { return false; } if (!ok) { return false; } } return true; } template inline bool write_content_chunked(Stream &strm, const ContentProvider &content_provider, const T &is_shutting_down, U &compressor, Error &error) { size_t offset = 0; auto data_available = true; auto ok = true; DataSink data_sink; data_sink.write = [&](const char *d, size_t l) -> bool { if (ok) { data_available = l > 0; offset += l; std::string payload; if (compressor.compress(d, l, false, [&](const char *data, size_t data_len) { payload.append(data, data_len); return true; })) { if (!payload.empty()) { // Emit chunked response header and footer for each chunk auto chunk = from_i_to_hex(payload.size()) + "\r\n" + payload + "\r\n"; if (!write_data(strm, chunk.data(), chunk.size())) { ok = false; } } } else { ok = false; } } return ok; }; data_sink.done = [&](void) { if (!ok) { return; } data_available = false; std::string payload; if (!compressor.compress(nullptr, 0, true, [&](const char *data, size_t data_len) { payload.append(data, data_len); return true; })) { ok = false; return; } if (!payload.empty()) { // Emit chunked response header and footer for each chunk auto chunk = from_i_to_hex(payload.size()) + "\r\n" + payload + "\r\n"; if (!write_data(strm, chunk.data(), chunk.size())) { ok = false; return; } } static const std::string done_marker("0\r\n\r\n"); if (!write_data(strm, done_marker.data(), done_marker.size())) { ok = false; } }; data_sink.is_writable = [&](void) { return ok && strm.is_writable(); }; while (data_available && !is_shutting_down()) { if (!content_provider(offset, 0, data_sink)) { error = Error::Canceled; return false; } if (!ok) { error = Error::Write; return false; } } error = Error::Success; return true; } template inline bool write_content_chunked(Stream &strm, const ContentProvider &content_provider, const T &is_shutting_down, U &compressor) { auto error = Error::Success; return write_content_chunked(strm, content_provider, is_shutting_down, compressor, error); } template inline bool redirect(T &cli, Request &req, Response &res, const std::string &path, const std::string &location, Error &error) { Request new_req = req; new_req.path = path; new_req.redirect_count_ -= 1; if (res.status == 303 && (req.method != "GET" && req.method != "HEAD")) { new_req.method = "GET"; new_req.body.clear(); new_req.headers.clear(); } Response new_res; auto ret = cli.send(new_req, new_res, error); if (ret) { req = new_req; res = new_res; res.location = location; } return ret; } inline std::string params_to_query_str(const Params ¶ms) { std::string query; for (auto it = params.begin(); it != params.end(); ++it) { if (it != params.begin()) { query += "&"; } query += it->first; query += "="; query += encode_query_param(it->second); } return query; } inline std::string append_query_params(const char *path, const Params ¶ms) { std::string path_with_query = path; const static std::regex re("[^?]+\\?.*"); auto delm = std::regex_match(path, re) ? '&' : '?'; path_with_query += delm + params_to_query_str(params); return path_with_query; } inline void parse_query_text(const std::string &s, Params ¶ms) { std::set cache; split(s.data(), s.data() + s.size(), '&', [&](const char *b, const char *e) { std::string kv(b, e); if (cache.find(kv) != cache.end()) { return; } cache.insert(kv); std::string key; std::string val; split(b, e, '=', [&](const char *b2, const char *e2) { if (key.empty()) { key.assign(b2, e2); } else { val.assign(b2, e2); } }); if (!key.empty()) { params.emplace(decode_url(key, true), decode_url(val, true)); } }); } inline bool parse_multipart_boundary(const std::string &content_type, std::string &boundary) { auto pos = content_type.find("boundary="); if (pos == std::string::npos) { return false; } boundary = content_type.substr(pos + 9); if (boundary.length() >= 2 && boundary.front() == '"' && boundary.back() == '"') { boundary = boundary.substr(1, boundary.size() - 2); } return !boundary.empty(); } inline bool parse_range_header(const std::string &s, Ranges &ranges) try { static auto re_first_range = std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))"); std::smatch m; if (std::regex_match(s, m, re_first_range)) { auto pos = static_cast(m.position(1)); auto len = static_cast(m.length(1)); bool all_valid_ranges = true; split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) { if (!all_valid_ranges) return; static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))"); std::cmatch cm; if (std::regex_match(b, e, cm, re_another_range)) { ssize_t first = -1; if (!cm.str(1).empty()) { first = static_cast(std::stoll(cm.str(1))); } ssize_t last = -1; if (!cm.str(2).empty()) { last = static_cast(std::stoll(cm.str(2))); } if (first != -1 && last != -1 && first > last) { all_valid_ranges = false; return; } ranges.emplace_back(std::make_pair(first, last)); } }); return all_valid_ranges; } return false; } catch (...) { return false; } class MultipartFormDataParser { public: MultipartFormDataParser() = default; void set_boundary(std::string &&boundary) { boundary_ = boundary; } bool is_valid() const { return is_valid_; } bool parse(const char *buf, size_t n, const ContentReceiver &content_callback, const MultipartContentHeader &header_callback) { static const std::regex re_content_disposition( "^Content-Disposition:\\s*form-data;\\s*name=\"(.*?)\"(?:;\\s*filename=" "\"(.*?)\")?\\s*$", std::regex_constants::icase); static const std::string dash_ = "--"; static const std::string crlf_ = "\r\n"; buf_.append(buf, n); // TODO: performance improvement while (!buf_.empty()) { switch (state_) { case 0: { // Initial boundary auto pattern = dash_ + boundary_ + crlf_; if (pattern.size() > buf_.size()) { return true; } auto pos = buf_.find(pattern); if (pos != 0) { return false; } buf_.erase(0, pattern.size()); off_ += pattern.size(); state_ = 1; break; } case 1: { // New entry clear_file_info(); state_ = 2; break; } case 2: { // Headers auto pos = buf_.find(crlf_); while (pos != std::string::npos) { // Empty line if (pos == 0) { if (!header_callback(file_)) { is_valid_ = false; return false; } buf_.erase(0, crlf_.size()); off_ += crlf_.size(); state_ = 3; break; } static const std::string header_name = "content-type:"; const auto header = buf_.substr(0, pos); if (start_with_case_ignore(header, header_name)) { file_.content_type = trim_copy(header.substr(header_name.size())); } else { std::smatch m; if (std::regex_match(header, m, re_content_disposition)) { file_.name = m[1]; file_.filename = m[2]; } } buf_.erase(0, pos + crlf_.size()); off_ += pos + crlf_.size(); pos = buf_.find(crlf_); } if (state_ != 3) { return true; } break; } case 3: { // Body { auto pattern = crlf_ + dash_; if (pattern.size() > buf_.size()) { return true; } auto pos = find_string(buf_, pattern); if (!content_callback(buf_.data(), pos)) { is_valid_ = false; return false; } off_ += pos; buf_.erase(0, pos); } { auto pattern = crlf_ + dash_ + boundary_; if (pattern.size() > buf_.size()) { return true; } auto pos = buf_.find(pattern); if (pos != std::string::npos) { if (!content_callback(buf_.data(), pos)) { is_valid_ = false; return false; } off_ += pos + pattern.size(); buf_.erase(0, pos + pattern.size()); state_ = 4; } else { if (!content_callback(buf_.data(), pattern.size())) { is_valid_ = false; return false; } off_ += pattern.size(); buf_.erase(0, pattern.size()); } } break; } case 4: { // Boundary if (crlf_.size() > buf_.size()) { return true; } if (buf_.compare(0, crlf_.size(), crlf_) == 0) { buf_.erase(0, crlf_.size()); off_ += crlf_.size(); state_ = 1; } else { auto pattern = dash_ + crlf_; if (pattern.size() > buf_.size()) { return true; } if (buf_.compare(0, pattern.size(), pattern) == 0) { buf_.erase(0, pattern.size()); off_ += pattern.size(); is_valid_ = true; state_ = 5; } else { return true; } } break; } case 5: { // Done is_valid_ = false; return false; } } } return true; } private: void clear_file_info() { file_.name.clear(); file_.filename.clear(); file_.content_type.clear(); } bool start_with_case_ignore(const std::string &a, const std::string &b) const { if (a.size() < b.size()) { return false; } for (size_t i = 0; i < b.size(); i++) { if (::tolower(a[i]) != ::tolower(b[i])) { return false; } } return true; } bool start_with(const std::string &a, size_t off, const std::string &b) const { if (a.size() - off < b.size()) { return false; } for (size_t i = 0; i < b.size(); i++) { if (a[i + off] != b[i]) { return false; } } return true; } size_t find_string(const std::string &s, const std::string &pattern) const { auto c = pattern.front(); size_t off = 0; while (off < s.size()) { auto pos = s.find(c, off); if (pos == std::string::npos) { return s.size(); } auto rem = s.size() - pos; if (pattern.size() > rem) { return pos; } if (start_with(s, pos, pattern)) { return pos; } off = pos + 1; } return s.size(); } std::string boundary_; std::string buf_; size_t state_ = 0; bool is_valid_ = false; size_t off_ = 0; MultipartFormData file_; }; inline std::string to_lower(const char *beg, const char *end) { std::string out; auto it = beg; while (it != end) { out += static_cast(::tolower(*it)); it++; } return out; } inline std::string make_multipart_data_boundary() { static const char data[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; // std::random_device might actually be deterministic on some // platforms, but due to lack of support in the c++ standard library, // doing better requires either some ugly hacks or breaking portability. std::random_device seed_gen; // Request 128 bits of entropy for initialization std::seed_seq seed_sequence{seed_gen(), seed_gen(), seed_gen(), seed_gen()}; std::mt19937 engine(seed_sequence); std::string result = "--cpp-httplib-multipart-data-"; for (auto i = 0; i < 16; i++) { result += data[engine() % (sizeof(data) - 1)]; } return result; } inline std::pair get_range_offset_and_length(const Request &req, size_t content_length, size_t index) { auto r = req.ranges[index]; if (r.first == -1 && r.second == -1) { return std::make_pair(0, content_length); } auto slen = static_cast(content_length); if (r.first == -1) { r.first = (std::max)(static_cast(0), slen - r.second); r.second = slen - 1; } if (r.second == -1) { r.second = slen - 1; } return std::make_pair(r.first, static_cast(r.second - r.first) + 1); } inline std::string make_content_range_header_field(size_t offset, size_t length, size_t content_length) { std::string field = "bytes "; field += std::to_string(offset); field += "-"; field += std::to_string(offset + length - 1); field += "/"; field += std::to_string(content_length); return field; } template bool process_multipart_ranges_data(const Request &req, Response &res, const std::string &boundary, const std::string &content_type, SToken stoken, CToken ctoken, Content content) { for (size_t i = 0; i < req.ranges.size(); i++) { ctoken("--"); stoken(boundary); ctoken("\r\n"); if (!content_type.empty()) { ctoken("Content-Type: "); stoken(content_type); ctoken("\r\n"); } auto offsets = get_range_offset_and_length(req, res.body.size(), i); auto offset = offsets.first; auto length = offsets.second; ctoken("Content-Range: "); stoken(make_content_range_header_field(offset, length, res.body.size())); ctoken("\r\n"); ctoken("\r\n"); if (!content(offset, length)) { return false; } ctoken("\r\n"); } ctoken("--"); stoken(boundary); ctoken("--\r\n"); return true; } inline bool make_multipart_ranges_data(const Request &req, Response &res, const std::string &boundary, const std::string &content_type, std::string &data) { return process_multipart_ranges_data( req, res, boundary, content_type, [&](const std::string &token) { data += token; }, [&](const char *token) { data += token; }, [&](size_t offset, size_t length) { if (offset < res.body.size()) { data += res.body.substr(offset, length); return true; } return false; }); } inline size_t get_multipart_ranges_data_length(const Request &req, Response &res, const std::string &boundary, const std::string &content_type) { size_t data_length = 0; process_multipart_ranges_data( req, res, boundary, content_type, [&](const std::string &token) { data_length += token.size(); }, [&](const char *token) { data_length += strlen(token); }, [&](size_t /*offset*/, size_t length) { data_length += length; return true; }); return data_length; } template inline bool write_multipart_ranges_data(Stream &strm, const Request &req, Response &res, const std::string &boundary, const std::string &content_type, const T &is_shutting_down) { return process_multipart_ranges_data( req, res, boundary, content_type, [&](const std::string &token) { strm.write(token); }, [&](const char *token) { strm.write(token); }, [&](size_t offset, size_t length) { return write_content(strm, res.content_provider_, offset, length, is_shutting_down); }); } inline std::pair get_range_offset_and_length(const Request &req, const Response &res, size_t index) { auto r = req.ranges[index]; if (r.second == -1) { r.second = static_cast(res.content_length_) - 1; } return std::make_pair(r.first, r.second - r.first + 1); } inline bool expect_content(const Request &req) { if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" || req.method == "PRI" || req.method == "DELETE") { return true; } // TODO: check if Content-Length is set return false; } inline bool has_crlf(const char *s) { auto p = s; while (*p) { if (*p == '\r' || *p == '\n') { return true; } p++; } return false; } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT template inline std::string message_digest(const std::string &s, Init init, Update update, Final final, size_t digest_length) { using namespace std; std::vector md(digest_length, 0); CTX ctx; init(&ctx); update(&ctx, s.data(), s.size()); final(md.data(), &ctx); stringstream ss; for (auto c : md) { ss << setfill('0') << setw(2) << hex << (unsigned int)c; } return ss.str(); } inline std::string MD5(const std::string &s) { return message_digest(s, MD5_Init, MD5_Update, MD5_Final, MD5_DIGEST_LENGTH); } inline std::string SHA_256(const std::string &s) { return message_digest(s, SHA256_Init, SHA256_Update, SHA256_Final, SHA256_DIGEST_LENGTH); } inline std::string SHA_512(const std::string &s) { return message_digest(s, SHA512_Init, SHA512_Update, SHA512_Final, SHA512_DIGEST_LENGTH); } #endif #ifdef _WIN32 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT // NOTE: This code came up with the following stackoverflow post: // https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store inline bool load_system_certs_on_windows(X509_STORE *store) { auto hStore = CertOpenSystemStoreW((HCRYPTPROV_LEGACY)NULL, L"ROOT"); if (!hStore) { return false; } PCCERT_CONTEXT pContext = NULL; while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != nullptr) { auto encoded_cert = static_cast(pContext->pbCertEncoded); auto x509 = d2i_X509(NULL, &encoded_cert, pContext->cbCertEncoded); if (x509) { X509_STORE_add_cert(store, x509); X509_free(x509); } } CertFreeCertificateContext(pContext); CertCloseStore(hStore, 0); return true; } #endif class WSInit { public: WSInit() { WSADATA wsaData; WSAStartup(0x0002, &wsaData); } ~WSInit() { WSACleanup(); } }; static WSInit wsinit_; #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline std::pair make_digest_authentication_header( const Request &req, const std::map &auth, size_t cnonce_count, const std::string &cnonce, const std::string &username, const std::string &password, bool is_proxy = false) { using namespace std; string nc; { stringstream ss; ss << setfill('0') << setw(8) << hex << cnonce_count; nc = ss.str(); } auto qop = auth.at("qop"); if (qop.find("auth-int") != std::string::npos) { qop = "auth-int"; } else { qop = "auth"; } std::string algo = "MD5"; if (auth.find("algorithm") != auth.end()) { algo = auth.at("algorithm"); } string response; { auto H = algo == "SHA-256" ? detail::SHA_256 : algo == "SHA-512" ? detail::SHA_512 : detail::MD5; auto A1 = username + ":" + auth.at("realm") + ":" + password; auto A2 = req.method + ":" + req.path; if (qop == "auth-int") { A2 += ":" + H(req.body); } response = H(H(A1) + ":" + auth.at("nonce") + ":" + nc + ":" + cnonce + ":" + qop + ":" + H(A2)); } auto field = "Digest username=\"" + username + "\", realm=\"" + auth.at("realm") + "\", nonce=\"" + auth.at("nonce") + "\", uri=\"" + req.path + "\", algorithm=" + algo + ", qop=" + qop + ", nc=\"" + nc + "\", cnonce=\"" + cnonce + "\", response=\"" + response + "\""; auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; return std::make_pair(key, field); } #endif inline bool parse_www_authenticate(const Response &res, std::map &auth, bool is_proxy) { auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate"; if (res.has_header(auth_key)) { static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~"); auto s = res.get_header_value(auth_key); auto pos = s.find(' '); if (pos != std::string::npos) { auto type = s.substr(0, pos); if (type == "Basic") { return false; } else if (type == "Digest") { s = s.substr(pos + 1); auto beg = std::sregex_iterator(s.begin(), s.end(), re); for (auto i = beg; i != std::sregex_iterator(); ++i) { auto m = *i; auto key = s.substr(static_cast(m.position(1)), static_cast(m.length(1))); auto val = m.length(2) > 0 ? s.substr(static_cast(m.position(2)), static_cast(m.length(2))) : s.substr(static_cast(m.position(3)), static_cast(m.length(3))); auth[key] = val; } return true; } } } return false; } // https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c/440240#answer-440240 inline std::string random_string(size_t length) { auto randchar = []() -> char { const char charset[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; const size_t max_index = (sizeof(charset) - 1); return charset[static_cast(std::rand()) % max_index]; }; std::string str(length, 0); std::generate_n(str.begin(), length, randchar); return str; } class ContentProviderAdapter { public: explicit ContentProviderAdapter( ContentProviderWithoutLength &&content_provider) : content_provider_(content_provider) {} bool operator()(size_t offset, size_t, DataSink &sink) { return content_provider_(offset, sink); } private: ContentProviderWithoutLength content_provider_; }; template inline void duration_to_sec_and_usec(const T &duration, U callback) { auto sec = std::chrono::duration_cast(duration).count(); auto usec = std::chrono::duration_cast( duration - std::chrono::seconds(sec)) .count(); callback(sec, usec); } } // namespace detail // Header utilities inline std::pair make_range_header(Ranges ranges) { std::string field = "bytes="; auto i = 0; for (auto r : ranges) { if (i != 0) { field += ", "; } if (r.first != -1) { field += std::to_string(r.first); } field += '-'; if (r.second != -1) { field += std::to_string(r.second); } i++; } return std::make_pair("Range", std::move(field)); } inline std::pair make_basic_authentication_header(const std::string &username, const std::string &password, bool is_proxy = false) { auto field = "Basic " + detail::base64_encode(username + ":" + password); auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; return std::make_pair(key, std::move(field)); } inline std::pair make_bearer_token_authentication_header(const std::string &token, bool is_proxy = false) { auto field = "Bearer " + token; auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; return std::make_pair(key, std::move(field)); } // Request implementation inline bool Request::has_header(const char *key) const { return detail::has_header(headers, key); } inline std::string Request::get_header_value(const char *key, size_t id) const { return detail::get_header_value(headers, key, id, ""); } template inline T Request::get_header_value(const char *key, size_t id) const { return detail::get_header_value(headers, key, id, 0); } inline size_t Request::get_header_value_count(const char *key) const { auto r = headers.equal_range(key); return static_cast(std::distance(r.first, r.second)); } inline void Request::set_header(const char *key, const char *val) { if (!detail::has_crlf(key) && !detail::has_crlf(val)) { headers.emplace(key, val); } } inline void Request::set_header(const char *key, const std::string &val) { if (!detail::has_crlf(key) && !detail::has_crlf(val.c_str())) { headers.emplace(key, val); } } inline bool Request::has_param(const char *key) const { return params.find(key) != params.end(); } inline std::string Request::get_param_value(const char *key, size_t id) const { auto rng = params.equal_range(key); auto it = rng.first; std::advance(it, static_cast(id)); if (it != rng.second) { return it->second; } return std::string(); } inline size_t Request::get_param_value_count(const char *key) const { auto r = params.equal_range(key); return static_cast(std::distance(r.first, r.second)); } inline bool Request::is_multipart_form_data() const { const auto &content_type = get_header_value("Content-Type"); return !content_type.find("multipart/form-data"); } inline bool Request::has_file(const char *key) const { return files.find(key) != files.end(); } inline MultipartFormData Request::get_file_value(const char *key) const { auto it = files.find(key); if (it != files.end()) { return it->second; } return MultipartFormData(); } // Response implementation inline bool Response::has_header(const char *key) const { return headers.find(key) != headers.end(); } inline std::string Response::get_header_value(const char *key, size_t id) const { return detail::get_header_value(headers, key, id, ""); } template inline T Response::get_header_value(const char *key, size_t id) const { return detail::get_header_value(headers, key, id, 0); } inline size_t Response::get_header_value_count(const char *key) const { auto r = headers.equal_range(key); return static_cast(std::distance(r.first, r.second)); } inline void Response::set_header(const char *key, const char *val) { if (!detail::has_crlf(key) && !detail::has_crlf(val)) { headers.emplace(key, val); } } inline void Response::set_header(const char *key, const std::string &val) { if (!detail::has_crlf(key) && !detail::has_crlf(val.c_str())) { headers.emplace(key, val); } } inline void Response::set_redirect(const char *url, int stat) { if (!detail::has_crlf(url)) { set_header("Location", url); if (300 <= stat && stat < 400) { this->status = stat; } else { this->status = 302; } } } inline void Response::set_redirect(const std::string &url, int stat) { set_redirect(url.c_str(), stat); } inline void Response::set_content(const char *s, size_t n, const char *content_type) { body.assign(s, n); auto rng = headers.equal_range("Content-Type"); headers.erase(rng.first, rng.second); set_header("Content-Type", content_type); } inline void Response::set_content(const std::string &s, const char *content_type) { set_content(s.data(), s.size(), content_type); } inline void Response::set_content_provider(size_t in_length, const char *content_type, ContentProvider provider, const std::function &resource_releaser) { assert(in_length > 0); set_header("Content-Type", content_type); content_length_ = in_length; content_provider_ = std::move(provider); content_provider_resource_releaser_ = resource_releaser; is_chunked_content_provider_ = false; } inline void Response::set_content_provider(const char *content_type, ContentProviderWithoutLength provider, const std::function &resource_releaser) { set_header("Content-Type", content_type); content_length_ = 0; content_provider_ = detail::ContentProviderAdapter(std::move(provider)); content_provider_resource_releaser_ = resource_releaser; is_chunked_content_provider_ = false; } inline void Response::set_chunked_content_provider( const char *content_type, ContentProviderWithoutLength provider, const std::function &resource_releaser) { set_header("Content-Type", content_type); content_length_ = 0; content_provider_ = detail::ContentProviderAdapter(std::move(provider)); content_provider_resource_releaser_ = resource_releaser; is_chunked_content_provider_ = true; } // Result implementation inline bool Result::has_request_header(const char *key) const { return request_headers_.find(key) != request_headers_.end(); } inline std::string Result::get_request_header_value(const char *key, size_t id) const { return detail::get_header_value(request_headers_, key, id, ""); } template inline T Result::get_request_header_value(const char *key, size_t id) const { return detail::get_header_value(request_headers_, key, id, 0); } inline size_t Result::get_request_header_value_count(const char *key) const { auto r = request_headers_.equal_range(key); return static_cast(std::distance(r.first, r.second)); } // Stream implementation inline ssize_t Stream::write(const char *ptr) { return write(ptr, strlen(ptr)); } inline ssize_t Stream::write(const std::string &s) { return write(s.data(), s.size()); } template inline ssize_t Stream::write_format(const char *fmt, const Args &...args) { const auto bufsiz = 2048; std::array buf; #if defined(_MSC_VER) && _MSC_VER < 1900 auto sn = _snprintf_s(buf.data(), bufsiz - 1, buf.size() - 1, fmt, args...); #else auto sn = snprintf(buf.data(), buf.size() - 1, fmt, args...); #endif if (sn <= 0) { return sn; } auto n = static_cast(sn); if (n >= buf.size() - 1) { std::vector glowable_buf(buf.size()); while (n >= glowable_buf.size() - 1) { glowable_buf.resize(glowable_buf.size() * 2); #if defined(_MSC_VER) && _MSC_VER < 1900 n = static_cast(_snprintf_s(&glowable_buf[0], glowable_buf.size(), glowable_buf.size() - 1, fmt, args...)); #else n = static_cast( snprintf(&glowable_buf[0], glowable_buf.size() - 1, fmt, args...)); #endif } return write(&glowable_buf[0], n); } else { return write(buf.data(), n); } } namespace detail { // Socket stream implementation inline SocketStream::SocketStream(socket_t sock, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec) : sock_(sock), read_timeout_sec_(read_timeout_sec), read_timeout_usec_(read_timeout_usec), write_timeout_sec_(write_timeout_sec), write_timeout_usec_(write_timeout_usec) {} inline SocketStream::~SocketStream() {} inline bool SocketStream::is_readable() const { return select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0; } inline bool SocketStream::is_writable() const { return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0; } inline ssize_t SocketStream::read(char *ptr, size_t size) { if (!is_readable()) { return -1; } #ifdef _WIN32 if (size > static_cast((std::numeric_limits::max)())) { return -1; } return recv(sock_, ptr, static_cast(size), CPPHTTPLIB_RECV_FLAGS); #else return handle_EINTR( [&]() { return recv(sock_, ptr, size, CPPHTTPLIB_RECV_FLAGS); }); #endif } inline ssize_t SocketStream::write(const char *ptr, size_t size) { if (!is_writable()) { return -1; } #ifdef _WIN32 if (size > static_cast((std::numeric_limits::max)())) { return -1; } return send(sock_, ptr, static_cast(size), CPPHTTPLIB_SEND_FLAGS); #else return handle_EINTR( [&]() { return send(sock_, ptr, size, CPPHTTPLIB_SEND_FLAGS); }); #endif } inline void SocketStream::get_remote_ip_and_port(std::string &ip, int &port) const { return detail::get_remote_ip_and_port(sock_, ip, port); } inline socket_t SocketStream::socket() const { return sock_; } // Buffer stream implementation inline bool BufferStream::is_readable() const { return true; } inline bool BufferStream::is_writable() const { return true; } inline ssize_t BufferStream::read(char *ptr, size_t size) { #if defined(_MSC_VER) && _MSC_VER <= 1900 auto len_read = buffer._Copy_s(ptr, size, size, position); #else auto len_read = buffer.copy(ptr, size, position); #endif position += static_cast(len_read); return static_cast(len_read); } inline ssize_t BufferStream::write(const char *ptr, size_t size) { buffer.append(ptr, size); return static_cast(size); } inline void BufferStream::get_remote_ip_and_port(std::string & /*ip*/, int & /*port*/) const {} inline socket_t BufferStream::socket() const { return 0; } inline const std::string &BufferStream::get_buffer() const { return buffer; } } // namespace detail // HTTP server implementation inline Server::Server() : new_task_queue( [] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }), svr_sock_(INVALID_SOCKET), is_running_(false) { #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif } inline Server::~Server() {} inline Server &Server::Get(const char *pattern, Handler handler) { return Get(pattern, strlen(pattern), handler); } inline Server &Server::Get(const char *pattern, size_t pattern_len, Handler handler) { get_handlers_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Post(const char *pattern, Handler handler) { return Post(pattern, strlen(pattern), handler); } inline Server &Server::Post(const char *pattern, size_t pattern_len, Handler handler) { post_handlers_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Post(const char *pattern, HandlerWithContentReader handler) { return Post(pattern, strlen(pattern), handler); } inline Server &Server::Post(const char *pattern, size_t pattern_len, HandlerWithContentReader handler) { post_handlers_for_content_reader_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Put(const char *pattern, Handler handler) { return Put(pattern, strlen(pattern), handler); } inline Server &Server::Put(const char *pattern, size_t pattern_len, Handler handler) { put_handlers_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Put(const char *pattern, HandlerWithContentReader handler) { return Put(pattern, strlen(pattern), handler); } inline Server &Server::Put(const char *pattern, size_t pattern_len, HandlerWithContentReader handler) { put_handlers_for_content_reader_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Patch(const char *pattern, Handler handler) { return Patch(pattern, strlen(pattern), handler); } inline Server &Server::Patch(const char *pattern, size_t pattern_len, Handler handler) { patch_handlers_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Patch(const char *pattern, HandlerWithContentReader handler) { return Patch(pattern, strlen(pattern), handler); } inline Server &Server::Patch(const char *pattern, size_t pattern_len, HandlerWithContentReader handler) { patch_handlers_for_content_reader_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Delete(const char *pattern, Handler handler) { return Delete(pattern, strlen(pattern), handler); } inline Server &Server::Delete(const char *pattern, size_t pattern_len, Handler handler) { delete_handlers_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Delete(const char *pattern, HandlerWithContentReader handler) { return Delete(pattern, strlen(pattern), handler); } inline Server &Server::Delete(const char *pattern, size_t pattern_len, HandlerWithContentReader handler) { delete_handlers_for_content_reader_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline Server &Server::Options(const char *pattern, Handler handler) { return Options(pattern, strlen(pattern), handler); } inline Server &Server::Options(const char *pattern, size_t pattern_len, Handler handler) { options_handlers_.push_back( std::make_pair(std::regex(pattern, pattern_len), std::move(handler))); return *this; } inline bool Server::set_base_dir(const char *dir, const char *mount_point) { return set_mount_point(mount_point, dir); } inline bool Server::set_mount_point(const char *mount_point, const char *dir, Headers headers) { if (detail::is_dir(dir)) { std::string mnt = mount_point ? mount_point : "/"; if (!mnt.empty() && mnt[0] == '/') { base_dirs_.push_back({mnt, dir, std::move(headers)}); return true; } } return false; } inline bool Server::remove_mount_point(const char *mount_point) { for (auto it = base_dirs_.begin(); it != base_dirs_.end(); ++it) { if (it->mount_point == mount_point) { base_dirs_.erase(it); return true; } } return false; } inline Server & Server::set_file_extension_and_mimetype_mapping(const char *ext, const char *mime) { file_extension_and_mimetype_map_[ext] = mime; return *this; } inline Server &Server::set_file_request_handler(Handler handler) { file_request_handler_ = std::move(handler); return *this; } inline Server &Server::set_error_handler(HandlerWithResponse handler) { error_handler_ = std::move(handler); return *this; } inline Server &Server::set_error_handler(Handler handler) { error_handler_ = [handler](const Request &req, Response &res) { handler(req, res); return HandlerResponse::Handled; }; return *this; } inline Server &Server::set_exception_handler(ExceptionHandler handler) { exception_handler_ = std::move(handler); return *this; } inline Server &Server::set_pre_routing_handler(HandlerWithResponse handler) { pre_routing_handler_ = std::move(handler); return *this; } inline Server &Server::set_post_routing_handler(Handler handler) { post_routing_handler_ = std::move(handler); return *this; } inline Server &Server::set_logger(Logger logger) { logger_ = std::move(logger); return *this; } inline Server & Server::set_expect_100_continue_handler(Expect100ContinueHandler handler) { expect_100_continue_handler_ = std::move(handler); return *this; } inline Server &Server::set_address_family(int family) { address_family_ = family; return *this; } inline Server &Server::set_tcp_nodelay(bool on) { tcp_nodelay_ = on; return *this; } inline Server &Server::set_socket_options(SocketOptions socket_options) { socket_options_ = std::move(socket_options); return *this; } inline Server &Server::set_keep_alive_max_count(size_t count) { keep_alive_max_count_ = count; return *this; } inline Server &Server::set_keep_alive_timeout(time_t sec) { keep_alive_timeout_sec_ = sec; return *this; } inline Server &Server::set_read_timeout(time_t sec, time_t usec) { read_timeout_sec_ = sec; read_timeout_usec_ = usec; return *this; } template inline Server & Server::set_read_timeout(const std::chrono::duration &duration) { detail::duration_to_sec_and_usec( duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); }); return *this; } inline Server &Server::set_write_timeout(time_t sec, time_t usec) { write_timeout_sec_ = sec; write_timeout_usec_ = usec; return *this; } template inline Server & Server::set_write_timeout(const std::chrono::duration &duration) { detail::duration_to_sec_and_usec( duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); }); return *this; } inline Server &Server::set_idle_interval(time_t sec, time_t usec) { idle_interval_sec_ = sec; idle_interval_usec_ = usec; return *this; } template inline Server & Server::set_idle_interval(const std::chrono::duration &duration) { detail::duration_to_sec_and_usec( duration, [&](time_t sec, time_t usec) { set_idle_interval(sec, usec); }); return *this; } inline Server &Server::set_payload_max_length(size_t length) { payload_max_length_ = length; return *this; } inline bool Server::bind_to_port(const char *host, int port, int socket_flags) { if (bind_internal(host, port, socket_flags) < 0) return false; return true; } inline int Server::bind_to_any_port(const char *host, int socket_flags) { return bind_internal(host, 0, socket_flags); } inline bool Server::listen_after_bind() { return listen_internal(); } inline bool Server::listen(const char *host, int port, int socket_flags) { return bind_to_port(host, port, socket_flags) && listen_internal(); } inline bool Server::is_running() const { return is_running_; } inline void Server::stop() { if (is_running_) { assert(svr_sock_ != INVALID_SOCKET); std::atomic sock(svr_sock_.exchange(INVALID_SOCKET)); detail::shutdown_socket(sock); detail::close_socket(sock); } } inline bool Server::parse_request_line(const char *s, Request &req) { const static std::regex re( "(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI) " "(([^? ]+)(?:\\?([^ ]*?))?) (HTTP/1\\.[01])\r\n"); std::cmatch m; if (std::regex_match(s, m, re)) { req.version = std::string(m[5]); req.method = std::string(m[1]); req.target = std::string(m[2]); req.path = detail::decode_url(m[3], false); // Parse query text auto len = std::distance(m[4].first, m[4].second); if (len > 0) { detail::parse_query_text(m[4], req.params); } return true; } return false; } inline bool Server::write_response(Stream &strm, bool close_connection, const Request &req, Response &res) { return write_response_core(strm, close_connection, req, res, false); } inline bool Server::write_response_with_content(Stream &strm, bool close_connection, const Request &req, Response &res) { return write_response_core(strm, close_connection, req, res, true); } inline bool Server::write_response_core(Stream &strm, bool close_connection, const Request &req, Response &res, bool need_apply_ranges) { assert(res.status != -1); if (400 <= res.status && error_handler_ && error_handler_(req, res) == HandlerResponse::Handled) { need_apply_ranges = true; } std::string content_type; std::string boundary; if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); } // Prepare additional headers if (close_connection || req.get_header_value("Connection") == "close") { res.set_header("Connection", "close"); } else { std::stringstream ss; ss << "timeout=" << keep_alive_timeout_sec_ << ", max=" << keep_alive_max_count_; res.set_header("Keep-Alive", ss.str()); } if (!res.has_header("Content-Type") && (!res.body.empty() || res.content_length_ > 0 || res.content_provider_)) { res.set_header("Content-Type", "text/plain"); } if (!res.has_header("Content-Length") && res.body.empty() && !res.content_length_ && !res.content_provider_) { res.set_header("Content-Length", "0"); } if (!res.has_header("Accept-Ranges") && req.method == "HEAD") { res.set_header("Accept-Ranges", "bytes"); } if (post_routing_handler_) { post_routing_handler_(req, res); } // Response line and headers { detail::BufferStream bstrm; if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status, detail::status_message(res.status))) { return false; } if (!detail::write_headers(bstrm, res.headers)) { return false; } // Flush buffer auto &data = bstrm.get_buffer(); strm.write(data.data(), data.size()); } // Body auto ret = true; if (req.method != "HEAD") { if (!res.body.empty()) { if (!strm.write(res.body)) { ret = false; } } else if (res.content_provider_) { if (!write_content_with_provider(strm, req, res, boundary, content_type)) { ret = false; } } } // Log if (logger_) { logger_(req, res); } return ret; } inline bool Server::write_content_with_provider(Stream &strm, const Request &req, Response &res, const std::string &boundary, const std::string &content_type) { auto is_shutting_down = [this]() { return this->svr_sock_ == INVALID_SOCKET; }; if (res.content_length_ > 0) { if (req.ranges.empty()) { return detail::write_content(strm, res.content_provider_, 0, res.content_length_, is_shutting_down); } else if (req.ranges.size() == 1) { auto offsets = detail::get_range_offset_and_length(req, res.content_length_, 0); auto offset = offsets.first; auto length = offsets.second; return detail::write_content(strm, res.content_provider_, offset, length, is_shutting_down); } else { return detail::write_multipart_ranges_data( strm, req, res, boundary, content_type, is_shutting_down); } } else { if (res.is_chunked_content_provider_) { auto type = detail::encoding_type(req, res); std::unique_ptr compressor; if (type == detail::EncodingType::Gzip) { #ifdef CPPHTTPLIB_ZLIB_SUPPORT compressor = detail::make_unique(); #endif } else if (type == detail::EncodingType::Brotli) { #ifdef CPPHTTPLIB_BROTLI_SUPPORT compressor = detail::make_unique(); #endif } else { compressor = detail::make_unique(); } assert(compressor != nullptr); return detail::write_content_chunked(strm, res.content_provider_, is_shutting_down, *compressor); } else { return detail::write_content_without_length(strm, res.content_provider_, is_shutting_down); } } } inline bool Server::read_content(Stream &strm, Request &req, Response &res) { MultipartFormDataMap::iterator cur; if (read_content_core( strm, req, res, // Regular [&](const char *buf, size_t n) { if (req.body.size() + n > req.body.max_size()) { return false; } req.body.append(buf, n); return true; }, // Multipart [&](const MultipartFormData &file) { cur = req.files.emplace(file.name, file); return true; }, [&](const char *buf, size_t n) { auto &content = cur->second.content; if (content.size() + n > content.max_size()) { return false; } content.append(buf, n); return true; })) { const auto &content_type = req.get_header_value("Content-Type"); if (!content_type.find("application/x-www-form-urlencoded")) { detail::parse_query_text(req.body, req.params); } return true; } return false; } inline bool Server::read_content_with_content_receiver( Stream &strm, Request &req, Response &res, ContentReceiver receiver, MultipartContentHeader multipart_header, ContentReceiver multipart_receiver) { return read_content_core(strm, req, res, std::move(receiver), std::move(multipart_header), std::move(multipart_receiver)); } inline bool Server::read_content_core(Stream &strm, Request &req, Response &res, ContentReceiver receiver, MultipartContentHeader mulitpart_header, ContentReceiver multipart_receiver) { detail::MultipartFormDataParser multipart_form_data_parser; ContentReceiverWithProgress out; if (req.is_multipart_form_data()) { const auto &content_type = req.get_header_value("Content-Type"); std::string boundary; if (!detail::parse_multipart_boundary(content_type, boundary)) { res.status = 400; return false; } multipart_form_data_parser.set_boundary(std::move(boundary)); out = [&](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) { /* For debug size_t pos = 0; while (pos < n) { auto read_size = std::min(1, n - pos); auto ret = multipart_form_data_parser.parse( buf + pos, read_size, multipart_receiver, mulitpart_header); if (!ret) { return false; } pos += read_size; } return true; */ return multipart_form_data_parser.parse(buf, n, multipart_receiver, mulitpart_header); }; } else { out = [receiver](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) { return receiver(buf, n); }; } if (req.method == "DELETE" && !req.has_header("Content-Length")) { return true; } if (!detail::read_content(strm, req, payload_max_length_, res.status, nullptr, out, true)) { return false; } if (req.is_multipart_form_data()) { if (!multipart_form_data_parser.is_valid()) { res.status = 400; return false; } } return true; } inline bool Server::handle_file_request(const Request &req, Response &res, bool head) { for (const auto &entry : base_dirs_) { // Prefix match if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) { std::string sub_path = "/" + req.path.substr(entry.mount_point.size()); if (detail::is_valid_path(sub_path)) { auto path = entry.base_dir + sub_path; if (path.back() == '/') { path += "index.html"; } if (detail::is_file(path)) { detail::read_file(path, res.body); auto type = detail::find_content_type(path, file_extension_and_mimetype_map_); if (type) { res.set_header("Content-Type", type); } for (const auto &kv : entry.headers) { res.set_header(kv.first.c_str(), kv.second); } res.status = req.has_header("Range") ? 206 : 200; if (!head && file_request_handler_) { file_request_handler_(req, res); } return true; } } } } return false; } inline socket_t Server::create_server_socket(const char *host, int port, int socket_flags, SocketOptions socket_options) const { return detail::create_socket( host, port, address_family_, socket_flags, tcp_nodelay_, std::move(socket_options), [](socket_t sock, struct addrinfo &ai) -> bool { if (::bind(sock, ai.ai_addr, static_cast(ai.ai_addrlen))) { return false; } if (::listen(sock, 5)) { // Listen through 5 channels return false; } return true; }); } inline int Server::bind_internal(const char *host, int port, int socket_flags) { if (!is_valid()) { return -1; } svr_sock_ = create_server_socket(host, port, socket_flags, socket_options_); if (svr_sock_ == INVALID_SOCKET) { return -1; } if (port == 0) { struct sockaddr_storage addr; socklen_t addr_len = sizeof(addr); if (getsockname(svr_sock_, reinterpret_cast(&addr), &addr_len) == -1) { return -1; } if (addr.ss_family == AF_INET) { return ntohs(reinterpret_cast(&addr)->sin_port); } else if (addr.ss_family == AF_INET6) { return ntohs(reinterpret_cast(&addr)->sin6_port); } else { return -1; } } else { return port; } } inline bool Server::listen_internal() { auto ret = true; is_running_ = true; { std::unique_ptr task_queue(new_task_queue()); while (svr_sock_ != INVALID_SOCKET) { #ifndef _WIN32 if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) { #endif auto val = detail::select_read(svr_sock_, idle_interval_sec_, idle_interval_usec_); if (val == 0) { // Timeout task_queue->on_idle(); continue; } #ifndef _WIN32 } #endif socket_t sock = accept(svr_sock_, nullptr, nullptr); if (sock == INVALID_SOCKET) { if (errno == EMFILE) { // The per-process limit of open file descriptors has been reached. // Try to accept new connections after a short sleep. std::this_thread::sleep_for(std::chrono::milliseconds(1)); continue; } if (svr_sock_ != INVALID_SOCKET) { detail::close_socket(svr_sock_); ret = false; } else { ; // The server socket was closed by user. } break; } { timeval tv; tv.tv_sec = static_cast(read_timeout_sec_); tv.tv_usec = static_cast(read_timeout_usec_); setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)); } { timeval tv; tv.tv_sec = static_cast(write_timeout_sec_); tv.tv_usec = static_cast(write_timeout_usec_); setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)); } #if __cplusplus > 201703L task_queue->enqueue([=, this]() { process_and_close_socket(sock); }); #else task_queue->enqueue([=]() { process_and_close_socket(sock); }); #endif } task_queue->shutdown(); } is_running_ = false; return ret; } inline bool Server::routing(Request &req, Response &res, Stream &strm) { if (pre_routing_handler_ && pre_routing_handler_(req, res) == HandlerResponse::Handled) { return true; } // File handler bool is_head_request = req.method == "HEAD"; if ((req.method == "GET" || is_head_request) && handle_file_request(req, res, is_head_request)) { return true; } if (detail::expect_content(req)) { // Content reader handler { ContentReader reader( [&](ContentReceiver receiver) { return read_content_with_content_receiver( strm, req, res, std::move(receiver), nullptr, nullptr); }, [&](MultipartContentHeader header, ContentReceiver receiver) { return read_content_with_content_receiver(strm, req, res, nullptr, std::move(header), std::move(receiver)); }); if (req.method == "POST") { if (dispatch_request_for_content_reader( req, res, std::move(reader), post_handlers_for_content_reader_)) { return true; } } else if (req.method == "PUT") { if (dispatch_request_for_content_reader( req, res, std::move(reader), put_handlers_for_content_reader_)) { return true; } } else if (req.method == "PATCH") { if (dispatch_request_for_content_reader( req, res, std::move(reader), patch_handlers_for_content_reader_)) { return true; } } else if (req.method == "DELETE") { if (dispatch_request_for_content_reader( req, res, std::move(reader), delete_handlers_for_content_reader_)) { return true; } } } // Read content into `req.body` if (!read_content(strm, req, res)) { return false; } } // Regular handler if (req.method == "GET" || req.method == "HEAD") { return dispatch_request(req, res, get_handlers_); } else if (req.method == "POST") { return dispatch_request(req, res, post_handlers_); } else if (req.method == "PUT") { return dispatch_request(req, res, put_handlers_); } else if (req.method == "DELETE") { return dispatch_request(req, res, delete_handlers_); } else if (req.method == "OPTIONS") { return dispatch_request(req, res, options_handlers_); } else if (req.method == "PATCH") { return dispatch_request(req, res, patch_handlers_); } res.status = 400; return false; } inline bool Server::dispatch_request(Request &req, Response &res, const Handlers &handlers) { for (const auto &x : handlers) { const auto &pattern = x.first; const auto &handler = x.second; if (std::regex_match(req.path, req.matches, pattern)) { handler(req, res); return true; } } return false; } inline void Server::apply_ranges(const Request &req, Response &res, std::string &content_type, std::string &boundary) { if (req.ranges.size() > 1) { boundary = detail::make_multipart_data_boundary(); auto it = res.headers.find("Content-Type"); if (it != res.headers.end()) { content_type = it->second; res.headers.erase(it); } res.headers.emplace("Content-Type", "multipart/byteranges; boundary=" + boundary); } auto type = detail::encoding_type(req, res); if (res.body.empty()) { if (res.content_length_ > 0) { size_t length = 0; if (req.ranges.empty()) { length = res.content_length_; } else if (req.ranges.size() == 1) { auto offsets = detail::get_range_offset_and_length(req, res.content_length_, 0); auto offset = offsets.first; length = offsets.second; auto content_range = detail::make_content_range_header_field( offset, length, res.content_length_); res.set_header("Content-Range", content_range); } else { length = detail::get_multipart_ranges_data_length(req, res, boundary, content_type); } res.set_header("Content-Length", std::to_string(length)); } else { if (res.content_provider_) { if (res.is_chunked_content_provider_) { res.set_header("Transfer-Encoding", "chunked"); if (type == detail::EncodingType::Gzip) { res.set_header("Content-Encoding", "gzip"); } else if (type == detail::EncodingType::Brotli) { res.set_header("Content-Encoding", "br"); } } } } } else { if (req.ranges.empty()) { ; } else if (req.ranges.size() == 1) { auto offsets = detail::get_range_offset_and_length(req, res.body.size(), 0); auto offset = offsets.first; auto length = offsets.second; auto content_range = detail::make_content_range_header_field( offset, length, res.body.size()); res.set_header("Content-Range", content_range); if (offset < res.body.size()) { res.body = res.body.substr(offset, length); } else { res.body.clear(); res.status = 416; } } else { std::string data; if (detail::make_multipart_ranges_data(req, res, boundary, content_type, data)) { res.body.swap(data); } else { res.body.clear(); res.status = 416; } } if (type != detail::EncodingType::None) { std::unique_ptr compressor; std::string content_encoding; if (type == detail::EncodingType::Gzip) { #ifdef CPPHTTPLIB_ZLIB_SUPPORT compressor = detail::make_unique(); content_encoding = "gzip"; #endif } else if (type == detail::EncodingType::Brotli) { #ifdef CPPHTTPLIB_BROTLI_SUPPORT compressor = detail::make_unique(); content_encoding = "br"; #endif } if (compressor) { std::string compressed; if (compressor->compress(res.body.data(), res.body.size(), true, [&](const char *data, size_t data_len) { compressed.append(data, data_len); return true; })) { res.body.swap(compressed); res.set_header("Content-Encoding", content_encoding); } } } auto length = std::to_string(res.body.size()); res.set_header("Content-Length", length); } } inline bool Server::dispatch_request_for_content_reader( Request &req, Response &res, ContentReader content_reader, const HandlersForContentReader &handlers) { for (const auto &x : handlers) { const auto &pattern = x.first; const auto &handler = x.second; if (std::regex_match(req.path, req.matches, pattern)) { handler(req, res, content_reader); return true; } } return false; } inline bool Server::process_request(Stream &strm, bool close_connection, bool &connection_closed, const std::function &setup_request) { std::array buf{}; detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); // Connection has been closed on client if (!line_reader.getline()) { return false; } Request req; Response res; res.version = "HTTP/1.1"; #ifdef _WIN32 // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL). #else #ifndef CPPHTTPLIB_USE_POLL // Socket file descriptor exceeded FD_SETSIZE... if (strm.socket() >= FD_SETSIZE) { Headers dummy; detail::read_headers(strm, dummy); res.status = 500; return write_response(strm, close_connection, req, res); } #endif #endif // Check if the request URI doesn't exceed the limit if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) { Headers dummy; detail::read_headers(strm, dummy); res.status = 414; return write_response(strm, close_connection, req, res); } // Request line and headers if (!parse_request_line(line_reader.ptr(), req) || !detail::read_headers(strm, req.headers)) { res.status = 400; return write_response(strm, close_connection, req, res); } if (req.get_header_value("Connection") == "close") { connection_closed = true; } if (req.version == "HTTP/1.0" && req.get_header_value("Connection") != "Keep-Alive") { connection_closed = true; } strm.get_remote_ip_and_port(req.remote_addr, req.remote_port); req.set_header("REMOTE_ADDR", req.remote_addr); req.set_header("REMOTE_PORT", std::to_string(req.remote_port)); if (req.has_header("Range")) { const auto &range_header_value = req.get_header_value("Range"); if (!detail::parse_range_header(range_header_value, req.ranges)) { res.status = 416; return write_response(strm, close_connection, req, res); } } if (setup_request) { setup_request(req); } if (req.get_header_value("Expect") == "100-continue") { auto status = 100; if (expect_100_continue_handler_) { status = expect_100_continue_handler_(req, res); } switch (status) { case 100: case 417: strm.write_format("HTTP/1.1 %d %s\r\n\r\n", status, detail::status_message(status)); break; default: return write_response(strm, close_connection, req, res); } } // Rounting bool routed = false; try { routed = routing(req, res, strm); } catch (std::exception &e) { if (exception_handler_) { exception_handler_(req, res, e); routed = true; } else { res.status = 500; res.set_header("EXCEPTION_WHAT", e.what()); } } catch (...) { res.status = 500; res.set_header("EXCEPTION_WHAT", "UNKNOWN"); } if (routed) { if (res.status == -1) { res.status = req.ranges.empty() ? 200 : 206; } return write_response_with_content(strm, close_connection, req, res); } else { if (res.status == -1) { res.status = 404; } return write_response(strm, close_connection, req, res); } } inline bool Server::is_valid() const { return true; } inline bool Server::process_and_close_socket(socket_t sock) { auto ret = detail::process_server_socket( sock, keep_alive_max_count_, keep_alive_timeout_sec_, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, [this](Stream &strm, bool close_connection, bool &connection_closed) { return process_request(strm, close_connection, connection_closed, nullptr); }); detail::shutdown_socket(sock); detail::close_socket(sock); return ret; } // HTTP client implementation inline ClientImpl::ClientImpl(const std::string &host) : ClientImpl(host, 80, std::string(), std::string()) {} inline ClientImpl::ClientImpl(const std::string &host, int port) : ClientImpl(host, port, std::string(), std::string()) {} inline ClientImpl::ClientImpl(const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path) // : (Error::Success), host_(host), port_(port), : host_(host), port_(port), host_and_port_(host_ + ":" + std::to_string(port_)), client_cert_path_(client_cert_path), client_key_path_(client_key_path) {} inline ClientImpl::~ClientImpl() { lock_socket_and_shutdown_and_close(); } inline bool ClientImpl::is_valid() const { return true; } inline void ClientImpl::copy_settings(const ClientImpl &rhs) { client_cert_path_ = rhs.client_cert_path_; client_key_path_ = rhs.client_key_path_; connection_timeout_sec_ = rhs.connection_timeout_sec_; read_timeout_sec_ = rhs.read_timeout_sec_; read_timeout_usec_ = rhs.read_timeout_usec_; write_timeout_sec_ = rhs.write_timeout_sec_; write_timeout_usec_ = rhs.write_timeout_usec_; basic_auth_username_ = rhs.basic_auth_username_; basic_auth_password_ = rhs.basic_auth_password_; bearer_token_auth_token_ = rhs.bearer_token_auth_token_; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT digest_auth_username_ = rhs.digest_auth_username_; digest_auth_password_ = rhs.digest_auth_password_; #endif keep_alive_ = rhs.keep_alive_; follow_location_ = rhs.follow_location_; url_encode_ = rhs.url_encode_; tcp_nodelay_ = rhs.tcp_nodelay_; socket_options_ = rhs.socket_options_; compress_ = rhs.compress_; decompress_ = rhs.decompress_; interface_ = rhs.interface_; proxy_host_ = rhs.proxy_host_; proxy_port_ = rhs.proxy_port_; proxy_basic_auth_username_ = rhs.proxy_basic_auth_username_; proxy_basic_auth_password_ = rhs.proxy_basic_auth_password_; proxy_bearer_token_auth_token_ = rhs.proxy_bearer_token_auth_token_; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_; proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_; #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT server_certificate_verification_ = rhs.server_certificate_verification_; #endif logger_ = rhs.logger_; } inline socket_t ClientImpl::create_client_socket(Error &error) const { if (!proxy_host_.empty() && proxy_port_ != -1) { return detail::create_client_socket( proxy_host_.c_str(), proxy_port_, address_family_, tcp_nodelay_, socket_options_, connection_timeout_sec_, connection_timeout_usec_, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, interface_, error); } return detail::create_client_socket( host_.c_str(), port_, address_family_, tcp_nodelay_, socket_options_, connection_timeout_sec_, connection_timeout_usec_, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, interface_, error); } inline bool ClientImpl::create_and_connect_socket(Socket &socket, Error &error) { auto sock = create_client_socket(error); if (sock == INVALID_SOCKET) { return false; } socket.sock = sock; return true; } inline void ClientImpl::shutdown_ssl(Socket & /*socket*/, bool /*shutdown_gracefully*/) { // If there are any requests in flight from threads other than us, then it's // a thread-unsafe race because individual ssl* objects are not thread-safe. assert(socket_requests_in_flight_ == 0 || socket_requests_are_from_thread_ == std::this_thread::get_id()); } inline void ClientImpl::shutdown_socket(Socket &socket) { if (socket.sock == INVALID_SOCKET) { return; } detail::shutdown_socket(socket.sock); } inline void ClientImpl::close_socket(Socket &socket) { // If there are requests in flight in another thread, usually closing // the socket will be fine and they will simply receive an error when // using the closed socket, but it is still a bug since rarely the OS // may reassign the socket id to be used for a new socket, and then // suddenly they will be operating on a live socket that is different // than the one they intended! assert(socket_requests_in_flight_ == 0 || socket_requests_are_from_thread_ == std::this_thread::get_id()); // It is also a bug if this happens while SSL is still active #ifdef CPPHTTPLIB_OPENSSL_SUPPORT assert(socket.ssl == nullptr); #endif if (socket.sock == INVALID_SOCKET) { return; } detail::close_socket(socket.sock); socket.sock = INVALID_SOCKET; } inline void ClientImpl::lock_socket_and_shutdown_and_close() { std::lock_guard guard(socket_mutex_); shutdown_ssl(socket_, true); shutdown_socket(socket_); close_socket(socket_); } inline bool ClientImpl::read_response_line(Stream &strm, const Request &req, Response &res) { std::array buf; detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); if (!line_reader.getline()) { return false; } const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n"); std::cmatch m; if (!std::regex_match(line_reader.ptr(), m, re)) { return req.method == "CONNECT"; } res.version = std::string(m[1]); res.status = std::stoi(std::string(m[2])); res.reason = std::string(m[3]); // Ignore '100 Continue' while (res.status == 100) { if (!line_reader.getline()) { return false; } // CRLF if (!line_reader.getline()) { return false; } // next response line if (!std::regex_match(line_reader.ptr(), m, re)) { return false; } res.version = std::string(m[1]); res.status = std::stoi(std::string(m[2])); res.reason = std::string(m[3]); } return true; } inline bool ClientImpl::send(Request &req, Response &res, Error &error) { std::lock_guard request_mutex_guard(request_mutex_); { std::lock_guard guard(socket_mutex_); // Set this to false immediately - if it ever gets set to true by the end of // the request, we know another thread instructed us to close the socket. socket_should_be_closed_when_request_is_done_ = false; auto is_alive = false; if (socket_.is_open()) { is_alive = detail::select_write(socket_.sock, 0, 0) > 0; if (!is_alive) { // Attempt to avoid sigpipe by shutting down nongracefully if it seems // like the other side has already closed the connection Also, there // cannot be any requests in flight from other threads since we locked // request_mutex_, so safe to close everything immediately const bool shutdown_gracefully = false; shutdown_ssl(socket_, shutdown_gracefully); shutdown_socket(socket_); close_socket(socket_); } } if (!is_alive) { if (!create_and_connect_socket(socket_, error)) { return false; } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT // TODO: refactoring if (is_ssl()) { auto &scli = static_cast(*this); if (!proxy_host_.empty() && proxy_port_ != -1) { bool success = false; if (!scli.connect_with_proxy(socket_, res, success, error)) { return success; } } if (!scli.initialize_ssl(socket_, error)) { return false; } } #endif } // Mark the current socket as being in use so that it cannot be closed by // anyone else while this request is ongoing, even though we will be // releasing the mutex. if (socket_requests_in_flight_ > 1) { assert(socket_requests_are_from_thread_ == std::this_thread::get_id()); } socket_requests_in_flight_ += 1; socket_requests_are_from_thread_ = std::this_thread::get_id(); } for (const auto &header : default_headers_) { if (req.headers.find(header.first) == req.headers.end()) { req.headers.insert(header); } } auto close_connection = !keep_alive_; auto ret = process_socket(socket_, [&](Stream &strm) { return handle_request(strm, req, res, close_connection, error); }); // Briefly lock mutex in order to mark that a request is no longer ongoing { std::lock_guard guard(socket_mutex_); socket_requests_in_flight_ -= 1; if (socket_requests_in_flight_ <= 0) { assert(socket_requests_in_flight_ == 0); socket_requests_are_from_thread_ = std::thread::id(); } if (socket_should_be_closed_when_request_is_done_ || close_connection || !ret) { shutdown_ssl(socket_, true); shutdown_socket(socket_); close_socket(socket_); } } if (!ret) { if (error == Error::Success) { error = Error::Unknown; } } return ret; } inline Result ClientImpl::send(const Request &req) { auto req2 = req; return send_(std::move(req2)); } inline Result ClientImpl::send_(Request &&req) { auto res = detail::make_unique(); auto error = Error::Success; auto ret = send(req, *res, error); return Result{ret ? std::move(res) : nullptr, error, std::move(req.headers)}; } inline bool ClientImpl::handle_request(Stream &strm, Request &req, Response &res, bool close_connection, Error &error) { if (req.path.empty()) { error = Error::Connection; return false; } auto req_save = req; bool ret; if (!is_ssl() && !proxy_host_.empty() && proxy_port_ != -1) { auto req2 = req; req2.path = "http://" + host_and_port_ + req.path; ret = process_request(strm, req2, res, close_connection, error); req = req2; req.path = req_save.path; } else { ret = process_request(strm, req, res, close_connection, error); } if (!ret) { return false; } if (300 < res.status && res.status < 400 && follow_location_) { req = req_save; ret = redirect(req, res, error); } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT if ((res.status == 401 || res.status == 407) && req.authorization_count_ < 5) { auto is_proxy = res.status == 407; const auto &username = is_proxy ? proxy_digest_auth_username_ : digest_auth_username_; const auto &password = is_proxy ? proxy_digest_auth_password_ : digest_auth_password_; if (!username.empty() && !password.empty()) { std::map auth; if (detail::parse_www_authenticate(res, auth, is_proxy)) { Request new_req = req; new_req.authorization_count_ += 1; auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; new_req.headers.erase(key); new_req.headers.insert(detail::make_digest_authentication_header( req, auth, new_req.authorization_count_, detail::random_string(10), username, password, is_proxy)); Response new_res; ret = send(new_req, new_res, error); if (ret) { res = new_res; } } } } #endif return ret; } inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) { if (req.redirect_count_ == 0) { error = Error::ExceedRedirectCount; return false; } auto location = detail::decode_url(res.get_header_value("location"), true); if (location.empty()) { return false; } const static std::regex re( R"(^(?:(https?):)?(?://([^:/?#]*)(?::(\d+))?)?([^?#]*(?:\?[^#]*)?)(?:#.*)?)"); std::smatch m; if (!std::regex_match(location, m, re)) { return false; } auto scheme = is_ssl() ? "https" : "http"; auto next_scheme = m[1].str(); auto next_host = m[2].str(); auto port_str = m[3].str(); auto next_path = m[4].str(); auto next_port = port_; if (!port_str.empty()) { next_port = std::stoi(port_str); } else if (!next_scheme.empty()) { next_port = next_scheme == "https" ? 443 : 80; } if (next_scheme.empty()) { next_scheme = scheme; } if (next_host.empty()) { next_host = host_; } if (next_path.empty()) { next_path = "/"; } if (next_scheme == scheme && next_host == host_ && next_port == port_) { return detail::redirect(*this, req, res, next_path, location, error); } else { if (next_scheme == "https") { #ifdef CPPHTTPLIB_OPENSSL_SUPPORT SSLClient cli(next_host.c_str(), next_port); cli.copy_settings(*this); return detail::redirect(cli, req, res, next_path, location, error); #else return false; #endif } else { ClientImpl cli(next_host.c_str(), next_port); cli.copy_settings(*this); return detail::redirect(cli, req, res, next_path, location, error); } } } inline bool ClientImpl::write_content_with_provider(Stream &strm, const Request &req, Error &error) { auto is_shutting_down = []() { return false; }; if (req.is_chunked_content_provider_) { // TODO: Brotli suport std::unique_ptr compressor; #ifdef CPPHTTPLIB_ZLIB_SUPPORT if (compress_) { compressor = detail::make_unique(); } else #endif { compressor = detail::make_unique(); } return detail::write_content_chunked(strm, req.content_provider_, is_shutting_down, *compressor, error); } else { return detail::write_content(strm, req.content_provider_, 0, req.content_length_, is_shutting_down, error); } } // namespace httplib inline bool ClientImpl::write_request(Stream &strm, Request &req, bool close_connection, Error &error) { // Prepare additional headers if (close_connection) { req.headers.emplace("Connection", "close"); } if (!req.has_header("Host")) { if (is_ssl()) { if (port_ == 443) { req.headers.emplace("Host", host_); } else { req.headers.emplace("Host", host_and_port_); } } else { if (port_ == 80) { req.headers.emplace("Host", host_); } else { req.headers.emplace("Host", host_and_port_); } } } if (!req.has_header("Accept")) { req.headers.emplace("Accept", "*/*"); } if (!req.has_header("User-Agent")) { req.headers.emplace("User-Agent", "cpp-httplib/0.7"); } if (req.body.empty()) { if (req.content_provider_) { if (!req.is_chunked_content_provider_) { auto length = std::to_string(req.content_length_); req.headers.emplace("Content-Length", length); } } else { if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH") { req.headers.emplace("Content-Length", "0"); } } } else { if (!req.has_header("Content-Type")) { req.headers.emplace("Content-Type", "text/plain"); } if (!req.has_header("Content-Length")) { auto length = std::to_string(req.body.size()); req.headers.emplace("Content-Length", length); } } if (!basic_auth_password_.empty()) { req.headers.insert(make_basic_authentication_header( basic_auth_username_, basic_auth_password_, false)); } if (!proxy_basic_auth_username_.empty() && !proxy_basic_auth_password_.empty()) { req.headers.insert(make_basic_authentication_header( proxy_basic_auth_username_, proxy_basic_auth_password_, true)); } if (!bearer_token_auth_token_.empty()) { req.headers.insert(make_bearer_token_authentication_header( bearer_token_auth_token_, false)); } if (!proxy_bearer_token_auth_token_.empty()) { req.headers.insert(make_bearer_token_authentication_header( proxy_bearer_token_auth_token_, true)); } // Request line and headers { detail::BufferStream bstrm; const auto &path = url_encode_ ? detail::encode_url(req.path) : req.path; bstrm.write_format("%s %s HTTP/1.1\r\n", req.method.c_str(), path.c_str()); detail::write_headers(bstrm, req.headers); // Flush buffer auto &data = bstrm.get_buffer(); if (!detail::write_data(strm, data.data(), data.size())) { error = Error::Write; return false; } } // Body if (req.body.empty()) { return write_content_with_provider(strm, req, error); } else { return detail::write_data(strm, req.body.data(), req.body.size()); } return true; } inline std::unique_ptr ClientImpl::send_with_content_provider( Request &req, // const char *method, const char *path, const Headers &headers, const char *body, size_t content_length, ContentProvider content_provider, ContentProviderWithoutLength content_provider_without_length, const char *content_type, Error &error) { // Request req; // req.method = method; // req.headers = headers; // req.path = path; if (content_type) { req.headers.emplace("Content-Type", content_type); } #ifdef CPPHTTPLIB_ZLIB_SUPPORT if (compress_) { req.headers.emplace("Content-Encoding", "gzip"); } #endif #ifdef CPPHTTPLIB_ZLIB_SUPPORT if (compress_ && !content_provider_without_length) { // TODO: Brotli support detail::gzip_compressor compressor; if (content_provider) { auto ok = true; size_t offset = 0; DataSink data_sink; data_sink.write = [&](const char *data, size_t data_len) -> bool { if (ok) { auto last = offset + data_len == content_length; auto ret = compressor.compress( data, data_len, last, [&](const char *data, size_t data_len) { req.body.append(data, data_len); return true; }); if (ret) { offset += data_len; } else { ok = false; } } return ok; }; data_sink.is_writable = [&](void) { return ok && true; }; while (ok && offset < content_length) { if (!content_provider(offset, content_length - offset, data_sink)) { error = Error::Canceled; return nullptr; } } } else { if (!compressor.compress(body, content_length, true, [&](const char *data, size_t data_len) { req.body.append(data, data_len); return true; })) { error = Error::Compression; return nullptr; } } } else #endif { if (content_provider) { req.content_length_ = content_length; req.content_provider_ = std::move(content_provider); req.is_chunked_content_provider_ = false; } else if (content_provider_without_length) { req.content_length_ = 0; req.content_provider_ = detail::ContentProviderAdapter( std::move(content_provider_without_length)); req.is_chunked_content_provider_ = true; req.headers.emplace("Transfer-Encoding", "chunked"); } else { req.body.assign(body, content_length); ; } } auto res = detail::make_unique(); return send(req, *res, error) ? std::move(res) : nullptr; } inline Result ClientImpl::send_with_content_provider( const char *method, const char *path, const Headers &headers, const char *body, size_t content_length, ContentProvider content_provider, ContentProviderWithoutLength content_provider_without_length, const char *content_type) { Request req; req.method = method; req.headers = headers; req.path = path; auto error = Error::Success; auto res = send_with_content_provider( req, // method, path, headers, body, content_length, std::move(content_provider), std::move(content_provider_without_length), content_type, error); return Result{std::move(res), error, std::move(req.headers)}; } inline bool ClientImpl::process_request(Stream &strm, Request &req, Response &res, bool close_connection, Error &error) { // Send request if (!write_request(strm, req, close_connection, error)) { return false; } // Receive response and headers if (!read_response_line(strm, req, res) || !detail::read_headers(strm, res.headers)) { error = Error::Read; return false; } // Body if ((res.status != 204) && req.method != "HEAD" && req.method != "CONNECT") { auto redirect = 300 < res.status && res.status < 400 && follow_location_; if (req.response_handler && !redirect) { if (!req.response_handler(res)) { error = Error::Canceled; return false; } } auto out = req.content_receiver ? static_cast( [&](const char *buf, size_t n, uint64_t off, uint64_t len) { if (redirect) { return true; } auto ret = req.content_receiver(buf, n, off, len); if (!ret) { error = Error::Canceled; } return ret; }) : static_cast( [&](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) { if (res.body.size() + n > res.body.max_size()) { return false; } res.body.append(buf, n); return true; }); auto progress = [&](uint64_t current, uint64_t total) { if (!req.progress || redirect) { return true; } auto ret = req.progress(current, total); if (!ret) { error = Error::Canceled; } return ret; }; int dummy_status; if (!detail::read_content(strm, res, (std::numeric_limits::max)(), dummy_status, std::move(progress), std::move(out), decompress_)) { if (error != Error::Canceled) { error = Error::Read; } return false; } } if (res.get_header_value("Connection") == "close" || (res.version == "HTTP/1.0" && res.reason != "Connection established")) { // TODO this requires a not-entirely-obvious chain of calls to be correct // for this to be safe. Maybe a code refactor (such as moving this out to // the send function and getting rid of the recursiveness of the mutex) // could make this more obvious. // This is safe to call because process_request is only called by // handle_request which is only called by send, which locks the request // mutex during the process. It would be a bug to call it from a different // thread since it's a thread-safety issue to do these things to the socket // if another thread is using the socket. lock_socket_and_shutdown_and_close(); } // Log if (logger_) { logger_(req, res); } return true; } inline bool ClientImpl::process_socket(const Socket &socket, std::function callback) { return detail::process_client_socket( socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, std::move(callback)); } inline bool ClientImpl::is_ssl() const { return false; } inline Result ClientImpl::Get(const char *path) { return Get(path, Headers(), Progress()); } inline Result ClientImpl::Get(const char *path, Progress progress) { return Get(path, Headers(), std::move(progress)); } inline Result ClientImpl::Get(const char *path, const Headers &headers) { return Get(path, headers, Progress()); } inline Result ClientImpl::Get(const char *path, const Headers &headers, Progress progress) { Request req; req.method = "GET"; req.path = path; req.headers = headers; req.progress = std::move(progress); return send_(std::move(req)); } inline Result ClientImpl::Get(const char *path, ContentReceiver content_receiver) { return Get(path, Headers(), nullptr, std::move(content_receiver), nullptr); } inline Result ClientImpl::Get(const char *path, ContentReceiver content_receiver, Progress progress) { return Get(path, Headers(), nullptr, std::move(content_receiver), std::move(progress)); } inline Result ClientImpl::Get(const char *path, const Headers &headers, ContentReceiver content_receiver) { return Get(path, headers, nullptr, std::move(content_receiver), nullptr); } inline Result ClientImpl::Get(const char *path, const Headers &headers, ContentReceiver content_receiver, Progress progress) { return Get(path, headers, nullptr, std::move(content_receiver), std::move(progress)); } inline Result ClientImpl::Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver) { return Get(path, Headers(), std::move(response_handler), std::move(content_receiver), nullptr); } inline Result ClientImpl::Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver) { return Get(path, headers, std::move(response_handler), std::move(content_receiver), nullptr); } inline Result ClientImpl::Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress) { return Get(path, Headers(), std::move(response_handler), std::move(content_receiver), std::move(progress)); } inline Result ClientImpl::Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress) { Request req; req.method = "GET"; req.path = path; req.headers = headers; req.response_handler = std::move(response_handler); req.content_receiver = [content_receiver](const char *data, size_t data_length, uint64_t /*offset*/, uint64_t /*total_length*/) { return content_receiver(data, data_length); }; req.progress = std::move(progress); return send_(std::move(req)); } inline Result ClientImpl::Get(const char *path, const Params ¶ms, const Headers &headers, Progress progress) { if (params.empty()) { return Get(path, headers); } std::string path_with_query = detail::append_query_params(path, params); return Get(path_with_query.c_str(), headers, progress); } inline Result ClientImpl::Get(const char *path, const Params ¶ms, const Headers &headers, ContentReceiver content_receiver, Progress progress) { return Get(path, params, headers, nullptr, content_receiver, progress); } inline Result ClientImpl::Get(const char *path, const Params ¶ms, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress) { if (params.empty()) { return Get(path, headers, response_handler, content_receiver, progress); } std::string path_with_query = detail::append_query_params(path, params); return Get(path_with_query.c_str(), headers, response_handler, content_receiver, progress); } inline Result ClientImpl::Head(const char *path) { return Head(path, Headers()); } inline Result ClientImpl::Head(const char *path, const Headers &headers) { Request req; req.method = "HEAD"; req.headers = headers; req.path = path; return send_(std::move(req)); } inline Result ClientImpl::Post(const char *path) { return Post(path, std::string(), nullptr); } inline Result ClientImpl::Post(const char *path, const char *body, size_t content_length, const char *content_type) { return Post(path, Headers(), body, content_length, content_type); } inline Result ClientImpl::Post(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return send_with_content_provider("POST", path, headers, body, content_length, nullptr, nullptr, content_type); } inline Result ClientImpl::Post(const char *path, const std::string &body, const char *content_type) { return Post(path, Headers(), body, content_type); } inline Result ClientImpl::Post(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return send_with_content_provider("POST", path, headers, body.data(), body.size(), nullptr, nullptr, content_type); } inline Result ClientImpl::Post(const char *path, const Params ¶ms) { return Post(path, Headers(), params); } inline Result ClientImpl::Post(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type) { return Post(path, Headers(), content_length, std::move(content_provider), content_type); } inline Result ClientImpl::Post(const char *path, ContentProviderWithoutLength content_provider, const char *content_type) { return Post(path, Headers(), std::move(content_provider), content_type); } inline Result ClientImpl::Post(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type) { return send_with_content_provider("POST", path, headers, nullptr, content_length, std::move(content_provider), nullptr, content_type); } inline Result ClientImpl::Post(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type) { return send_with_content_provider("POST", path, headers, nullptr, 0, nullptr, std::move(content_provider), content_type); } inline Result ClientImpl::Post(const char *path, const Headers &headers, const Params ¶ms) { auto query = detail::params_to_query_str(params); return Post(path, headers, query, "application/x-www-form-urlencoded"); } inline Result ClientImpl::Post(const char *path, const MultipartFormDataItems &items) { return Post(path, Headers(), items); } inline Result ClientImpl::Post(const char *path, const Headers &headers, const MultipartFormDataItems &items) { return Post(path, headers, items, detail::make_multipart_data_boundary()); } inline Result ClientImpl::Post(const char *path, const Headers &headers, const MultipartFormDataItems &items, const std::string &boundary) { for (size_t i = 0; i < boundary.size(); i++) { char c = boundary[i]; if (!std::isalnum(c) && c != '-' && c != '_') { return Result{nullptr, Error::UnsupportedMultipartBoundaryChars}; } } std::string body; for (const auto &item : items) { body += "--" + boundary + "\r\n"; body += "Content-Disposition: form-data; name=\"" + item.name + "\""; if (!item.filename.empty()) { body += "; filename=\"" + item.filename + "\""; } body += "\r\n"; if (!item.content_type.empty()) { body += "Content-Type: " + item.content_type + "\r\n"; } body += "\r\n"; body += item.content + "\r\n"; } body += "--" + boundary + "--\r\n"; std::string content_type = "multipart/form-data; boundary=" + boundary; return Post(path, headers, body, content_type.c_str()); } inline Result ClientImpl::Put(const char *path) { return Put(path, std::string(), nullptr); } inline Result ClientImpl::Put(const char *path, const char *body, size_t content_length, const char *content_type) { return Put(path, Headers(), body, content_length, content_type); } inline Result ClientImpl::Put(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return send_with_content_provider("PUT", path, headers, body, content_length, nullptr, nullptr, content_type); } inline Result ClientImpl::Put(const char *path, const std::string &body, const char *content_type) { return Put(path, Headers(), body, content_type); } inline Result ClientImpl::Put(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return send_with_content_provider("PUT", path, headers, body.data(), body.size(), nullptr, nullptr, content_type); } inline Result ClientImpl::Put(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type) { return Put(path, Headers(), content_length, std::move(content_provider), content_type); } inline Result ClientImpl::Put(const char *path, ContentProviderWithoutLength content_provider, const char *content_type) { return Put(path, Headers(), std::move(content_provider), content_type); } inline Result ClientImpl::Put(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type) { return send_with_content_provider("PUT", path, headers, nullptr, content_length, std::move(content_provider), nullptr, content_type); } inline Result ClientImpl::Put(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type) { return send_with_content_provider("PUT", path, headers, nullptr, 0, nullptr, std::move(content_provider), content_type); } inline Result ClientImpl::Put(const char *path, const Params ¶ms) { return Put(path, Headers(), params); } inline Result ClientImpl::Put(const char *path, const Headers &headers, const Params ¶ms) { auto query = detail::params_to_query_str(params); return Put(path, headers, query, "application/x-www-form-urlencoded"); } inline Result ClientImpl::Patch(const char *path) { return Patch(path, std::string(), nullptr); } inline Result ClientImpl::Patch(const char *path, const char *body, size_t content_length, const char *content_type) { return Patch(path, Headers(), body, content_length, content_type); } inline Result ClientImpl::Patch(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return send_with_content_provider("PATCH", path, headers, body, content_length, nullptr, nullptr, content_type); } inline Result ClientImpl::Patch(const char *path, const std::string &body, const char *content_type) { return Patch(path, Headers(), body, content_type); } inline Result ClientImpl::Patch(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return send_with_content_provider("PATCH", path, headers, body.data(), body.size(), nullptr, nullptr, content_type); } inline Result ClientImpl::Patch(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type) { return Patch(path, Headers(), content_length, std::move(content_provider), content_type); } inline Result ClientImpl::Patch(const char *path, ContentProviderWithoutLength content_provider, const char *content_type) { return Patch(path, Headers(), std::move(content_provider), content_type); } inline Result ClientImpl::Patch(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type) { return send_with_content_provider("PATCH", path, headers, nullptr, content_length, std::move(content_provider), nullptr, content_type); } inline Result ClientImpl::Patch(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type) { return send_with_content_provider("PATCH", path, headers, nullptr, 0, nullptr, std::move(content_provider), content_type); } inline Result ClientImpl::Delete(const char *path) { return Delete(path, Headers(), std::string(), nullptr); } inline Result ClientImpl::Delete(const char *path, const Headers &headers) { return Delete(path, headers, std::string(), nullptr); } inline Result ClientImpl::Delete(const char *path, const char *body, size_t content_length, const char *content_type) { return Delete(path, Headers(), body, content_length, content_type); } inline Result ClientImpl::Delete(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { Request req; req.method = "DELETE"; req.headers = headers; req.path = path; if (content_type) { req.headers.emplace("Content-Type", content_type); } req.body.assign(body, content_length); return send_(std::move(req)); } inline Result ClientImpl::Delete(const char *path, const std::string &body, const char *content_type) { return Delete(path, Headers(), body.data(), body.size(), content_type); } inline Result ClientImpl::Delete(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return Delete(path, headers, body.data(), body.size(), content_type); } inline Result ClientImpl::Options(const char *path) { return Options(path, Headers()); } inline Result ClientImpl::Options(const char *path, const Headers &headers) { Request req; req.method = "OPTIONS"; req.headers = headers; req.path = path; return send_(std::move(req)); } inline size_t ClientImpl::is_socket_open() const { std::lock_guard guard(socket_mutex_); return socket_.is_open(); } inline void ClientImpl::stop() { std::lock_guard guard(socket_mutex_); // If there is anything ongoing right now, the ONLY thread-safe thing we can // do is to shutdown_socket, so that threads using this socket suddenly // discover they can't read/write any more and error out. Everything else // (closing the socket, shutting ssl down) is unsafe because these actions are // not thread-safe. if (socket_requests_in_flight_ > 0) { shutdown_socket(socket_); // Aside from that, we set a flag for the socket to be closed when we're // done. socket_should_be_closed_when_request_is_done_ = true; return; } // Otherwise, sitll holding the mutex, we can shut everything down ourselves shutdown_ssl(socket_, true); shutdown_socket(socket_); close_socket(socket_); } inline void ClientImpl::set_connection_timeout(time_t sec, time_t usec) { connection_timeout_sec_ = sec; connection_timeout_usec_ = usec; } template inline void ClientImpl::set_connection_timeout( const std::chrono::duration &duration) { detail::duration_to_sec_and_usec(duration, [&](time_t sec, time_t usec) { set_connection_timeout(sec, usec); }); } inline void ClientImpl::set_read_timeout(time_t sec, time_t usec) { read_timeout_sec_ = sec; read_timeout_usec_ = usec; } template inline void ClientImpl::set_read_timeout( const std::chrono::duration &duration) { detail::duration_to_sec_and_usec( duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); }); } inline void ClientImpl::set_write_timeout(time_t sec, time_t usec) { write_timeout_sec_ = sec; write_timeout_usec_ = usec; } template inline void ClientImpl::set_write_timeout( const std::chrono::duration &duration) { detail::duration_to_sec_and_usec( duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); }); } inline void ClientImpl::set_basic_auth(const char *username, const char *password) { basic_auth_username_ = username; basic_auth_password_ = password; } inline void ClientImpl::set_bearer_token_auth(const char *token) { bearer_token_auth_token_ = token; } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void ClientImpl::set_digest_auth(const char *username, const char *password) { digest_auth_username_ = username; digest_auth_password_ = password; } #endif inline void ClientImpl::set_keep_alive(bool on) { keep_alive_ = on; } inline void ClientImpl::set_follow_location(bool on) { follow_location_ = on; } inline void ClientImpl::set_url_encode(bool on) { url_encode_ = on; } inline void ClientImpl::set_default_headers(Headers headers) { default_headers_ = std::move(headers); } inline void ClientImpl::set_address_family(int family) { address_family_ = family; } inline void ClientImpl::set_tcp_nodelay(bool on) { tcp_nodelay_ = on; } inline void ClientImpl::set_socket_options(SocketOptions socket_options) { socket_options_ = std::move(socket_options); } inline void ClientImpl::set_compress(bool on) { compress_ = on; } inline void ClientImpl::set_decompress(bool on) { decompress_ = on; } inline void ClientImpl::set_interface(const char *intf) { interface_ = intf; } inline void ClientImpl::set_proxy(const char *host, int port) { proxy_host_ = host; proxy_port_ = port; } inline void ClientImpl::set_proxy_basic_auth(const char *username, const char *password) { proxy_basic_auth_username_ = username; proxy_basic_auth_password_ = password; } inline void ClientImpl::set_proxy_bearer_token_auth(const char *token) { proxy_bearer_token_auth_token_ = token; } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void ClientImpl::set_proxy_digest_auth(const char *username, const char *password) { proxy_digest_auth_username_ = username; proxy_digest_auth_password_ = password; } #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void ClientImpl::enable_server_certificate_verification(bool enabled) { server_certificate_verification_ = enabled; } #endif inline void ClientImpl::set_logger(Logger logger) { logger_ = std::move(logger); } /* * SSL Implementation */ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT namespace detail { template inline SSL *ssl_new(socket_t sock, SSL_CTX *ctx, std::mutex &ctx_mutex, U SSL_connect_or_accept, V setup) { SSL *ssl = nullptr; { std::lock_guard guard(ctx_mutex); ssl = SSL_new(ctx); } if (ssl) { set_nonblocking(sock, true); auto bio = BIO_new_socket(static_cast(sock), BIO_NOCLOSE); BIO_set_nbio(bio, 1); SSL_set_bio(ssl, bio, bio); if (!setup(ssl) || SSL_connect_or_accept(ssl) != 1) { SSL_shutdown(ssl); { std::lock_guard guard(ctx_mutex); SSL_free(ssl); } set_nonblocking(sock, false); return nullptr; } BIO_set_nbio(bio, 0); set_nonblocking(sock, false); } return ssl; } inline void ssl_delete(std::mutex &ctx_mutex, SSL *ssl, bool shutdown_gracefully) { // sometimes we may want to skip this to try to avoid SIGPIPE if we know // the remote has closed the network connection // Note that it is not always possible to avoid SIGPIPE, this is merely a // best-efforts. if (shutdown_gracefully) { SSL_shutdown(ssl); } std::lock_guard guard(ctx_mutex); SSL_free(ssl); } template bool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl, U ssl_connect_or_accept, time_t timeout_sec, time_t timeout_usec) { int res = 0; while ((res = ssl_connect_or_accept(ssl)) != 1) { auto err = SSL_get_error(ssl, res); switch (err) { case SSL_ERROR_WANT_READ: if (select_read(sock, timeout_sec, timeout_usec) > 0) { continue; } break; case SSL_ERROR_WANT_WRITE: if (select_write(sock, timeout_sec, timeout_usec) > 0) { continue; } break; default: break; } return false; } return true; } template inline bool process_server_socket_ssl(SSL *ssl, socket_t sock, size_t keep_alive_max_count, time_t keep_alive_timeout_sec, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec, T callback) { return process_server_socket_core( sock, keep_alive_max_count, keep_alive_timeout_sec, [&](bool close_connection, bool &connection_closed) { SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec, write_timeout_sec, write_timeout_usec); return callback(strm, close_connection, connection_closed); }); } template inline bool process_client_socket_ssl(SSL *ssl, socket_t sock, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec, T callback) { SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec, write_timeout_sec, write_timeout_usec); return callback(strm); } #if OPENSSL_VERSION_NUMBER < 0x10100000L static std::shared_ptr> openSSL_locks_; class SSLThreadLocks { public: SSLThreadLocks() { openSSL_locks_ = std::make_shared>(CRYPTO_num_locks()); CRYPTO_set_locking_callback(locking_callback); } ~SSLThreadLocks() { CRYPTO_set_locking_callback(nullptr); } private: static void locking_callback(int mode, int type, const char * /*file*/, int /*line*/) { auto &lk = (*openSSL_locks_)[static_cast(type)]; if (mode & CRYPTO_LOCK) { lk.lock(); } else { lk.unlock(); } } }; #endif class SSLInit { public: SSLInit() { #if OPENSSL_VERSION_NUMBER < 0x1010001fL SSL_load_error_strings(); SSL_library_init(); #else OPENSSL_init_ssl( OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); #endif } ~SSLInit() { #if OPENSSL_VERSION_NUMBER < 0x1010001fL ERR_free_strings(); #endif } private: #if OPENSSL_VERSION_NUMBER < 0x10100000L SSLThreadLocks thread_init_; #endif }; // SSL socket stream implementation inline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl, time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, time_t write_timeout_usec) : sock_(sock), ssl_(ssl), read_timeout_sec_(read_timeout_sec), read_timeout_usec_(read_timeout_usec), write_timeout_sec_(write_timeout_sec), write_timeout_usec_(write_timeout_usec) { SSL_clear_mode(ssl, SSL_MODE_AUTO_RETRY); } inline SSLSocketStream::~SSLSocketStream() {} inline bool SSLSocketStream::is_readable() const { return detail::select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0; } inline bool SSLSocketStream::is_writable() const { return detail::select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0; } inline ssize_t SSLSocketStream::read(char *ptr, size_t size) { if (SSL_pending(ssl_) > 0) { return SSL_read(ssl_, ptr, static_cast(size)); } else if (is_readable()) { auto ret = SSL_read(ssl_, ptr, static_cast(size)); if (ret < 0) { auto err = SSL_get_error(ssl_, ret); while (err == SSL_ERROR_WANT_READ) { if (SSL_pending(ssl_) > 0) { return SSL_read(ssl_, ptr, static_cast(size)); } else if (is_readable()) { ret = SSL_read(ssl_, ptr, static_cast(size)); if (ret >= 0) { return ret; } err = SSL_get_error(ssl_, ret); } else { return -1; } } } return ret; } return -1; } inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) { if (is_writable()) { return SSL_write(ssl_, ptr, static_cast(size)); } return -1; } inline void SSLSocketStream::get_remote_ip_and_port(std::string &ip, int &port) const { detail::get_remote_ip_and_port(sock_, ip, port); } inline socket_t SSLSocketStream::socket() const { return sock_; } static SSLInit sslinit_; } // namespace detail // SSL HTTP server implementation inline SSLServer::SSLServer(const char *cert_path, const char *private_key_path, const char *client_ca_cert_file_path, const char *client_ca_cert_dir_path) { ctx_ = SSL_CTX_new(TLS_method()); if (ctx_) { SSL_CTX_set_options(ctx_, SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); // auto ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); // SSL_CTX_set_tmp_ecdh(ctx_, ecdh); // EC_KEY_free(ecdh); if (SSL_CTX_use_certificate_chain_file(ctx_, cert_path) != 1 || SSL_CTX_use_PrivateKey_file(ctx_, private_key_path, SSL_FILETYPE_PEM) != 1) { SSL_CTX_free(ctx_); ctx_ = nullptr; } else if (client_ca_cert_file_path || client_ca_cert_dir_path) { // if (client_ca_cert_file_path) { // auto list = SSL_load_client_CA_file(client_ca_cert_file_path); // SSL_CTX_set_client_CA_list(ctx_, list); // } SSL_CTX_load_verify_locations(ctx_, client_ca_cert_file_path, client_ca_cert_dir_path); SSL_CTX_set_verify( ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, // SSL_VERIFY_CLIENT_ONCE, nullptr); } } } inline SSLServer::SSLServer(X509 *cert, EVP_PKEY *private_key, X509_STORE *client_ca_cert_store) { ctx_ = SSL_CTX_new(SSLv23_server_method()); if (ctx_) { SSL_CTX_set_options(ctx_, SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); if (SSL_CTX_use_certificate(ctx_, cert) != 1 || SSL_CTX_use_PrivateKey(ctx_, private_key) != 1) { SSL_CTX_free(ctx_); ctx_ = nullptr; } else if (client_ca_cert_store) { SSL_CTX_set_cert_store(ctx_, client_ca_cert_store); SSL_CTX_set_verify( ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, // SSL_VERIFY_CLIENT_ONCE, nullptr); } } } inline SSLServer::~SSLServer() { if (ctx_) { SSL_CTX_free(ctx_); } } inline bool SSLServer::is_valid() const { return ctx_; } inline bool SSLServer::process_and_close_socket(socket_t sock) { auto ssl = detail::ssl_new( sock, ctx_, ctx_mutex_, [&](SSL *ssl) { return detail::ssl_connect_or_accept_nonblocking( sock, ssl, SSL_accept, read_timeout_sec_, read_timeout_usec_); }, [](SSL * /*ssl*/) { return true; }); bool ret = false; if (ssl) { ret = detail::process_server_socket_ssl( ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, [this, ssl](Stream &strm, bool close_connection, bool &connection_closed) { return process_request(strm, close_connection, connection_closed, [&](Request &req) { req.ssl = ssl; }); }); // Shutdown gracefully if the result seemed successful, non-gracefully if // the connection appeared to be closed. const bool shutdown_gracefully = ret; detail::ssl_delete(ctx_mutex_, ssl, shutdown_gracefully); } detail::shutdown_socket(sock); detail::close_socket(sock); return ret; } // SSL HTTP client implementation inline SSLClient::SSLClient(const std::string &host) : SSLClient(host, 443, std::string(), std::string()) {} inline SSLClient::SSLClient(const std::string &host, int port) : SSLClient(host, port, std::string(), std::string()) {} inline SSLClient::SSLClient(const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path) : ClientImpl(host, port, client_cert_path, client_key_path) { ctx_ = SSL_CTX_new(SSLv23_client_method()); detail::split(&host_[0], &host_[host_.size()], '.', [&](const char *b, const char *e) { host_components_.emplace_back(std::string(b, e)); }); if (!client_cert_path.empty() && !client_key_path.empty()) { if (SSL_CTX_use_certificate_file(ctx_, client_cert_path.c_str(), SSL_FILETYPE_PEM) != 1 || SSL_CTX_use_PrivateKey_file(ctx_, client_key_path.c_str(), SSL_FILETYPE_PEM) != 1) { SSL_CTX_free(ctx_); ctx_ = nullptr; } } } inline SSLClient::SSLClient(const std::string &host, int port, X509 *client_cert, EVP_PKEY *client_key) : ClientImpl(host, port) { ctx_ = SSL_CTX_new(SSLv23_client_method()); detail::split(&host_[0], &host_[host_.size()], '.', [&](const char *b, const char *e) { host_components_.emplace_back(std::string(b, e)); }); if (client_cert != nullptr && client_key != nullptr) { if (SSL_CTX_use_certificate(ctx_, client_cert) != 1 || SSL_CTX_use_PrivateKey(ctx_, client_key) != 1) { SSL_CTX_free(ctx_); ctx_ = nullptr; } } } inline SSLClient::~SSLClient() { if (ctx_) { SSL_CTX_free(ctx_); } // Make sure to shut down SSL since shutdown_ssl will resolve to the // base function rather than the derived function once we get to the // base class destructor, and won't free the SSL (causing a leak). SSLClient::shutdown_ssl(socket_, true); } inline bool SSLClient::is_valid() const { return ctx_; } inline void SSLClient::set_ca_cert_path(const char *ca_cert_file_path, const char *ca_cert_dir_path) { if (ca_cert_file_path) { ca_cert_file_path_ = ca_cert_file_path; } if (ca_cert_dir_path) { ca_cert_dir_path_ = ca_cert_dir_path; } } inline void SSLClient::set_ca_cert_store(X509_STORE *ca_cert_store) { if (ca_cert_store) { if (ctx_) { if (SSL_CTX_get_cert_store(ctx_) != ca_cert_store) { // Free memory allocated for old cert and use new store `ca_cert_store` SSL_CTX_set_cert_store(ctx_, ca_cert_store); } } else { X509_STORE_free(ca_cert_store); } } } inline long SSLClient::get_openssl_verify_result() const { return verify_result_; } inline SSL_CTX *SSLClient::ssl_context() const { return ctx_; } inline bool SSLClient::create_and_connect_socket(Socket &socket, Error &error) { return is_valid() && ClientImpl::create_and_connect_socket(socket, error); } // Assumes that socket_mutex_ is locked and that there are no requests in flight inline bool SSLClient::connect_with_proxy(Socket &socket, Response &res, bool &success, Error &error) { success = true; Response res2; if (!detail::process_client_socket( socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) { Request req2; req2.method = "CONNECT"; req2.path = host_and_port_; return process_request(strm, req2, res2, false, error); })) { // Thread-safe to close everything because we are assuming there are no // requests in flight shutdown_ssl(socket, true); shutdown_socket(socket); close_socket(socket); success = false; return false; } if (res2.status == 407) { if (!proxy_digest_auth_username_.empty() && !proxy_digest_auth_password_.empty()) { std::map auth; if (detail::parse_www_authenticate(res2, auth, true)) { Response res3; if (!detail::process_client_socket( socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) { Request req3; req3.method = "CONNECT"; req3.path = host_and_port_; req3.headers.insert(detail::make_digest_authentication_header( req3, auth, 1, detail::random_string(10), proxy_digest_auth_username_, proxy_digest_auth_password_, true)); return process_request(strm, req3, res3, false, error); })) { // Thread-safe to close everything because we are assuming there are // no requests in flight shutdown_ssl(socket, true); shutdown_socket(socket); close_socket(socket); success = false; return false; } } } else { res = res2; return false; } } return true; } inline bool SSLClient::load_certs() { bool ret = true; std::call_once(initialize_cert_, [&]() { std::lock_guard guard(ctx_mutex_); if (!ca_cert_file_path_.empty()) { if (!SSL_CTX_load_verify_locations(ctx_, ca_cert_file_path_.c_str(), nullptr)) { ret = false; } } else if (!ca_cert_dir_path_.empty()) { if (!SSL_CTX_load_verify_locations(ctx_, nullptr, ca_cert_dir_path_.c_str())) { ret = false; } } else { #ifdef _WIN32 detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_)); #else SSL_CTX_set_default_verify_paths(ctx_); #endif } }); return ret; } inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) { auto ssl = detail::ssl_new( socket.sock, ctx_, ctx_mutex_, [&](SSL *ssl) { if (server_certificate_verification_) { if (!load_certs()) { error = Error::SSLLoadingCerts; return false; } SSL_set_verify(ssl, SSL_VERIFY_NONE, nullptr); } if (!detail::ssl_connect_or_accept_nonblocking( socket.sock, ssl, SSL_connect, connection_timeout_sec_, connection_timeout_usec_)) { error = Error::SSLConnection; return false; } if (server_certificate_verification_) { verify_result_ = SSL_get_verify_result(ssl); if (verify_result_ != X509_V_OK) { error = Error::SSLServerVerification; return false; } auto server_cert = SSL_get_peer_certificate(ssl); if (server_cert == nullptr) { error = Error::SSLServerVerification; return false; } if (!verify_host(server_cert)) { X509_free(server_cert); error = Error::SSLServerVerification; return false; } X509_free(server_cert); } return true; }, [&](SSL *ssl) { SSL_set_tlsext_host_name(ssl, host_.c_str()); return true; }); if (ssl) { socket.ssl = ssl; return true; } shutdown_socket(socket); close_socket(socket); return false; } inline void SSLClient::shutdown_ssl(Socket &socket, bool shutdown_gracefully) { if (socket.sock == INVALID_SOCKET) { assert(socket.ssl == nullptr); return; } if (socket.ssl) { detail::ssl_delete(ctx_mutex_, socket.ssl, shutdown_gracefully); socket.ssl = nullptr; } assert(socket.ssl == nullptr); } inline bool SSLClient::process_socket(const Socket &socket, std::function callback) { assert(socket.ssl); return detail::process_client_socket_ssl( socket.ssl, socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, std::move(callback)); } inline bool SSLClient::is_ssl() const { return true; } inline bool SSLClient::verify_host(X509 *server_cert) const { /* Quote from RFC2818 section 3.1 "Server Identity" If a subjectAltName extension of type dNSName is present, that MUST be used as the identity. Otherwise, the (most specific) Common Name field in the Subject field of the certificate MUST be used. Although the use of the Common Name is existing practice, it is deprecated and Certification Authorities are encouraged to use the dNSName instead. Matching is performed using the matching rules specified by [RFC2459]. If more than one identity of a given type is present in the certificate (e.g., more than one dNSName name, a match in any one of the set is considered acceptable.) Names may contain the wildcard character * which is considered to match any single domain name component or component fragment. E.g., *.a.com matches foo.a.com but not bar.foo.a.com. f*.com matches foo.com but not bar.com. In some cases, the URI is specified as an IP address rather than a hostname. In this case, the iPAddress subjectAltName must be present in the certificate and must exactly match the IP in the URI. */ return verify_host_with_subject_alt_name(server_cert) || verify_host_with_common_name(server_cert); } inline bool SSLClient::verify_host_with_subject_alt_name(X509 *server_cert) const { auto ret = false; auto type = GEN_DNS; struct in6_addr addr6; struct in_addr addr; size_t addr_len = 0; #ifndef __MINGW32__ if (inet_pton(AF_INET6, host_.c_str(), &addr6)) { type = GEN_IPADD; addr_len = sizeof(struct in6_addr); } else if (inet_pton(AF_INET, host_.c_str(), &addr)) { type = GEN_IPADD; addr_len = sizeof(struct in_addr); } #endif auto alt_names = static_cast( X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr)); if (alt_names) { auto dsn_matched = false; auto ip_mached = false; auto count = sk_GENERAL_NAME_num(alt_names); for (decltype(count) i = 0; i < count && !dsn_matched; i++) { auto val = sk_GENERAL_NAME_value(alt_names, i); if (val->type == type) { auto name = (const char *)ASN1_STRING_get0_data(val->d.ia5); auto name_len = (size_t)ASN1_STRING_length(val->d.ia5); switch (type) { case GEN_DNS: dsn_matched = check_host_name(name, name_len); break; case GEN_IPADD: if (!memcmp(&addr6, name, addr_len) || !memcmp(&addr, name, addr_len)) { ip_mached = true; } break; } } } if (dsn_matched || ip_mached) { ret = true; } } GENERAL_NAMES_free((STACK_OF(GENERAL_NAME) *)alt_names); return ret; } inline bool SSLClient::verify_host_with_common_name(X509 *server_cert) const { const auto subject_name = X509_get_subject_name(server_cert); if (subject_name != nullptr) { char name[BUFSIZ]; auto name_len = X509_NAME_get_text_by_NID(subject_name, NID_commonName, name, sizeof(name)); if (name_len != -1) { return check_host_name(name, static_cast(name_len)); } } return false; } inline bool SSLClient::check_host_name(const char *pattern, size_t pattern_len) const { if (host_.size() == pattern_len && host_ == pattern) { return true; } // Wildcard match // https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/376484 std::vector pattern_components; detail::split(&pattern[0], &pattern[pattern_len], '.', [&](const char *b, const char *e) { pattern_components.emplace_back(std::string(b, e)); }); if (host_components_.size() != pattern_components.size()) { return false; } auto itr = pattern_components.begin(); for (const auto &h : host_components_) { auto &p = *itr; if (p != h && p != "*") { auto partial_match = (p.size() > 0 && p[p.size() - 1] == '*' && !p.compare(0, p.size() - 1, h)); if (!partial_match) { return false; } } ++itr; } return true; } #endif // Universal client implementation inline Client::Client(const char *scheme_host_port) : Client(scheme_host_port, std::string(), std::string()) {} inline Client::Client(const char *scheme_host_port, const std::string &client_cert_path, const std::string &client_key_path) { const static std::regex re(R"(^(?:([a-z]+)://)?([^:/?#]+)(?::(\d+))?)"); std::cmatch m; if (std::regex_match(scheme_host_port, m, re)) { auto scheme = m[1].str(); #ifdef CPPHTTPLIB_OPENSSL_SUPPORT if (!scheme.empty() && (scheme != "http" && scheme != "https")) { #else if (!scheme.empty() && scheme != "http") { #endif std::string msg = "'" + scheme + "' scheme is not supported."; throw std::invalid_argument(msg); return; } auto is_ssl = scheme == "https"; auto host = m[2].str(); auto port_str = m[3].str(); auto port = !port_str.empty() ? std::stoi(port_str) : (is_ssl ? 443 : 80); if (is_ssl) { #ifdef CPPHTTPLIB_OPENSSL_SUPPORT cli_ = detail::make_unique(host.c_str(), port, client_cert_path, client_key_path); is_ssl_ = is_ssl; #endif } else { cli_ = detail::make_unique(host.c_str(), port, client_cert_path, client_key_path); } } else { cli_ = detail::make_unique(scheme_host_port, 80, client_cert_path, client_key_path); } } inline Client::Client(const std::string &host, int port) : cli_(detail::make_unique(host, port)) {} inline Client::Client(const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path) : cli_(detail::make_unique(host, port, client_cert_path, client_key_path)) {} inline Client::~Client() {} inline bool Client::is_valid() const { return cli_ != nullptr && cli_->is_valid(); } inline Result Client::Get(const char *path) { return cli_->Get(path); } inline Result Client::Get(const char *path, const Headers &headers) { return cli_->Get(path, headers); } inline Result Client::Get(const char *path, Progress progress) { return cli_->Get(path, std::move(progress)); } inline Result Client::Get(const char *path, const Headers &headers, Progress progress) { return cli_->Get(path, headers, std::move(progress)); } inline Result Client::Get(const char *path, ContentReceiver content_receiver) { return cli_->Get(path, std::move(content_receiver)); } inline Result Client::Get(const char *path, const Headers &headers, ContentReceiver content_receiver) { return cli_->Get(path, headers, std::move(content_receiver)); } inline Result Client::Get(const char *path, ContentReceiver content_receiver, Progress progress) { return cli_->Get(path, std::move(content_receiver), std::move(progress)); } inline Result Client::Get(const char *path, const Headers &headers, ContentReceiver content_receiver, Progress progress) { return cli_->Get(path, headers, std::move(content_receiver), std::move(progress)); } inline Result Client::Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver) { return cli_->Get(path, std::move(response_handler), std::move(content_receiver)); } inline Result Client::Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver) { return cli_->Get(path, headers, std::move(response_handler), std::move(content_receiver)); } inline Result Client::Get(const char *path, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress) { return cli_->Get(path, std::move(response_handler), std::move(content_receiver), std::move(progress)); } inline Result Client::Get(const char *path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress) { return cli_->Get(path, headers, std::move(response_handler), std::move(content_receiver), std::move(progress)); } inline Result Client::Get(const char *path, const Params ¶ms, const Headers &headers, Progress progress) { return cli_->Get(path, params, headers, progress); } inline Result Client::Get(const char *path, const Params ¶ms, const Headers &headers, ContentReceiver content_receiver, Progress progress) { return cli_->Get(path, params, headers, content_receiver, progress); } inline Result Client::Get(const char *path, const Params ¶ms, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, Progress progress) { return cli_->Get(path, params, headers, response_handler, content_receiver, progress); } inline Result Client::Head(const char *path) { return cli_->Head(path); } inline Result Client::Head(const char *path, const Headers &headers) { return cli_->Head(path, headers); } inline Result Client::Post(const char *path) { return cli_->Post(path); } inline Result Client::Post(const char *path, const char *body, size_t content_length, const char *content_type) { return cli_->Post(path, body, content_length, content_type); } inline Result Client::Post(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return cli_->Post(path, headers, body, content_length, content_type); } inline Result Client::Post(const char *path, const std::string &body, const char *content_type) { return cli_->Post(path, body, content_type); } inline Result Client::Post(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return cli_->Post(path, headers, body, content_type); } inline Result Client::Post(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type) { return cli_->Post(path, content_length, std::move(content_provider), content_type); } inline Result Client::Post(const char *path, ContentProviderWithoutLength content_provider, const char *content_type) { return cli_->Post(path, std::move(content_provider), content_type); } inline Result Client::Post(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type) { return cli_->Post(path, headers, content_length, std::move(content_provider), content_type); } inline Result Client::Post(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type) { return cli_->Post(path, headers, std::move(content_provider), content_type); } inline Result Client::Post(const char *path, const Params ¶ms) { return cli_->Post(path, params); } inline Result Client::Post(const char *path, const Headers &headers, const Params ¶ms) { return cli_->Post(path, headers, params); } inline Result Client::Post(const char *path, const MultipartFormDataItems &items) { return cli_->Post(path, items); } inline Result Client::Post(const char *path, const Headers &headers, const MultipartFormDataItems &items) { return cli_->Post(path, headers, items); } inline Result Client::Post(const char *path, const Headers &headers, const MultipartFormDataItems &items, const std::string &boundary) { return cli_->Post(path, headers, items, boundary); } inline Result Client::Put(const char *path) { return cli_->Put(path); } inline Result Client::Put(const char *path, const char *body, size_t content_length, const char *content_type) { return cli_->Put(path, body, content_length, content_type); } inline Result Client::Put(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return cli_->Put(path, headers, body, content_length, content_type); } inline Result Client::Put(const char *path, const std::string &body, const char *content_type) { return cli_->Put(path, body, content_type); } inline Result Client::Put(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return cli_->Put(path, headers, body, content_type); } inline Result Client::Put(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type) { return cli_->Put(path, content_length, std::move(content_provider), content_type); } inline Result Client::Put(const char *path, ContentProviderWithoutLength content_provider, const char *content_type) { return cli_->Put(path, std::move(content_provider), content_type); } inline Result Client::Put(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type) { return cli_->Put(path, headers, content_length, std::move(content_provider), content_type); } inline Result Client::Put(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type) { return cli_->Put(path, headers, std::move(content_provider), content_type); } inline Result Client::Put(const char *path, const Params ¶ms) { return cli_->Put(path, params); } inline Result Client::Put(const char *path, const Headers &headers, const Params ¶ms) { return cli_->Put(path, headers, params); } inline Result Client::Patch(const char *path) { return cli_->Patch(path); } inline Result Client::Patch(const char *path, const char *body, size_t content_length, const char *content_type) { return cli_->Patch(path, body, content_length, content_type); } inline Result Client::Patch(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return cli_->Patch(path, headers, body, content_length, content_type); } inline Result Client::Patch(const char *path, const std::string &body, const char *content_type) { return cli_->Patch(path, body, content_type); } inline Result Client::Patch(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return cli_->Patch(path, headers, body, content_type); } inline Result Client::Patch(const char *path, size_t content_length, ContentProvider content_provider, const char *content_type) { return cli_->Patch(path, content_length, std::move(content_provider), content_type); } inline Result Client::Patch(const char *path, ContentProviderWithoutLength content_provider, const char *content_type) { return cli_->Patch(path, std::move(content_provider), content_type); } inline Result Client::Patch(const char *path, const Headers &headers, size_t content_length, ContentProvider content_provider, const char *content_type) { return cli_->Patch(path, headers, content_length, std::move(content_provider), content_type); } inline Result Client::Patch(const char *path, const Headers &headers, ContentProviderWithoutLength content_provider, const char *content_type) { return cli_->Patch(path, headers, std::move(content_provider), content_type); } inline Result Client::Delete(const char *path) { return cli_->Delete(path); } inline Result Client::Delete(const char *path, const Headers &headers) { return cli_->Delete(path, headers); } inline Result Client::Delete(const char *path, const char *body, size_t content_length, const char *content_type) { return cli_->Delete(path, body, content_length, content_type); } inline Result Client::Delete(const char *path, const Headers &headers, const char *body, size_t content_length, const char *content_type) { return cli_->Delete(path, headers, body, content_length, content_type); } inline Result Client::Delete(const char *path, const std::string &body, const char *content_type) { return cli_->Delete(path, body, content_type); } inline Result Client::Delete(const char *path, const Headers &headers, const std::string &body, const char *content_type) { return cli_->Delete(path, headers, body, content_type); } inline Result Client::Options(const char *path) { return cli_->Options(path); } inline Result Client::Options(const char *path, const Headers &headers) { return cli_->Options(path, headers); } inline bool Client::send(Request &req, Response &res, Error &error) { return cli_->send(req, res, error); } inline Result Client::send(const Request &req) { return cli_->send(req); } inline size_t Client::is_socket_open() const { return cli_->is_socket_open(); } inline void Client::stop() { cli_->stop(); } inline void Client::set_default_headers(Headers headers) { cli_->set_default_headers(std::move(headers)); } inline void Client::set_address_family(int family) { cli_->set_address_family(family); } inline void Client::set_tcp_nodelay(bool on) { cli_->set_tcp_nodelay(on); } inline void Client::set_socket_options(SocketOptions socket_options) { cli_->set_socket_options(std::move(socket_options)); } inline void Client::set_connection_timeout(time_t sec, time_t usec) { cli_->set_connection_timeout(sec, usec); } template inline void Client::set_connection_timeout( const std::chrono::duration &duration) { cli_->set_connection_timeout(duration); } inline void Client::set_read_timeout(time_t sec, time_t usec) { cli_->set_read_timeout(sec, usec); } template inline void Client::set_read_timeout(const std::chrono::duration &duration) { cli_->set_read_timeout(duration); } inline void Client::set_write_timeout(time_t sec, time_t usec) { cli_->set_write_timeout(sec, usec); } template inline void Client::set_write_timeout(const std::chrono::duration &duration) { cli_->set_write_timeout(duration); } inline void Client::set_basic_auth(const char *username, const char *password) { cli_->set_basic_auth(username, password); } inline void Client::set_bearer_token_auth(const char *token) { cli_->set_bearer_token_auth(token); } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void Client::set_digest_auth(const char *username, const char *password) { cli_->set_digest_auth(username, password); } #endif inline void Client::set_keep_alive(bool on) { cli_->set_keep_alive(on); } inline void Client::set_follow_location(bool on) { cli_->set_follow_location(on); } inline void Client::set_url_encode(bool on) { cli_->set_url_encode(on); } inline void Client::set_compress(bool on) { cli_->set_compress(on); } inline void Client::set_decompress(bool on) { cli_->set_decompress(on); } inline void Client::set_interface(const char *intf) { cli_->set_interface(intf); } inline void Client::set_proxy(const char *host, int port) { cli_->set_proxy(host, port); } inline void Client::set_proxy_basic_auth(const char *username, const char *password) { cli_->set_proxy_basic_auth(username, password); } inline void Client::set_proxy_bearer_token_auth(const char *token) { cli_->set_proxy_bearer_token_auth(token); } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void Client::set_proxy_digest_auth(const char *username, const char *password) { cli_->set_proxy_digest_auth(username, password); } #endif #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void Client::enable_server_certificate_verification(bool enabled) { cli_->enable_server_certificate_verification(enabled); } #endif inline void Client::set_logger(Logger logger) { cli_->set_logger(logger); } #ifdef CPPHTTPLIB_OPENSSL_SUPPORT inline void Client::set_ca_cert_path(const char *ca_cert_file_path, const char *ca_cert_dir_path) { if (is_ssl_) { static_cast(*cli_).set_ca_cert_path(ca_cert_file_path, ca_cert_dir_path); } } inline void Client::set_ca_cert_store(X509_STORE *ca_cert_store) { if (is_ssl_) { static_cast(*cli_).set_ca_cert_store(ca_cert_store); } } inline long Client::get_openssl_verify_result() const { if (is_ssl_) { return static_cast(*cli_).get_openssl_verify_result(); } return -1; // NOTE: -1 doesn't match any of X509_V_ERR_??? } inline SSL_CTX *Client::ssl_context() const { if (is_ssl_) { return static_cast(*cli_).ssl_context(); } return nullptr; } #endif // ---------------------------------------------------------------------------- } // namespace httplib #endif // CPPHTTPLIB_HTTPLIB_H indi-starbook-ten-0.1/CMakeLists.txt0000644000175100017510000000253114136175546016710 0ustar debiandebiancmake_minimum_required(VERSION 3.0) PROJECT(indi-starbook-ten CXX C) LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/") LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/") include(GNUInstallDirs) find_package(INDI REQUIRED) find_package(Nova REQUIRED) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${INDI_INCLUDE_DIR}) include_directories(${NOVA_INCLUDE_DIR}) include(CMakeCommon) set(STARBOOK_TEN_VERSION_MAJOR 0) set(STARBOOK_TEN_VERSION_MINOR 1) set(INDI_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/indi") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/indi_starbook_ten.xml.cmake ${CMAKE_CURRENT_BINARY_DIR}/indi_starbook_ten.xml) ########### Starbook Ten ########### set(indi_starbook_ten_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/connectionhttp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/indi_starbook_ten.cpp ${CMAKE_CURRENT_SOURCE_DIR}/starbook_ten.cpp ) add_executable(indi_starbook_ten ${indi_starbook_ten_SRCS}) target_link_libraries(indi_starbook_ten ${INDI_LIBRARIES} ${NOVA_LIBRARIES}) install(TARGETS indi_starbook_ten RUNTIME DESTINATION bin) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indi_starbook_ten.xml DESTINATION ${INDI_DATA_DIR}) indi-starbook-ten-0.1/COPYING0000644000175100017510000004325414136175546015212 0ustar debiandebian GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. indi-starbook-ten-0.1/config.h.cmake0000644000175100017510000000045114136175546016644 0ustar debiandebian#pragma once #ifndef CONFIG_H #define CONFIG_H /* Define INDI Data Dir */ #cmakedefine INDI_DATA_DIR "@INDI_DATA_DIR@" /* Define Driver version */ #define STARBOOK_TEN_VERSION_MAJOR @STARBOOK_TEN_VERSION_MAJOR@ #define STARBOOK_TEN_VERSION_MINOR @STARBOOK_TEN_VERSION_MINOR@ #endif // CONFIG_H indi-starbook-ten-0.1/connectionhttp.h0000644000175100017510000000365614136175546017371 0ustar debiandebian/******************************************************************************* Copyright(c) 2017 Jasem Mutlaq. All rights reserved. Connection Plugin Interface This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *******************************************************************************/ #pragma once #include "connectionplugins/connectioninterface.h" #include "httplib.h" #include #include #include namespace Connection { class HTTP : public Interface { public: HTTP(INDI::DefaultDevice *dev); virtual ~HTTP() = default; virtual bool Connect() override; virtual bool Disconnect() override; virtual void Activated() override; virtual void Deactivated() override; virtual std::string name() override { return "CONNECTION_HTTP"; } virtual std::string label() override { return "HTTP"; } virtual const char *host() const { return AddressT[0].text; } virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override; virtual bool saveConfigItems(FILE *fp) override; httplib::Client *getClient() const { return client; } void setDefaultHost(const char *addressHost); protected: // IP Address ITextVectorProperty AddressTP; IText AddressT[1] {}; httplib::Client *client; }; } indi-starbook-ten-0.1/COPYRIGHT0000644000175100017510000000137014136175546015443 0ustar debiandebianCopyright (C) 2021 Alex Hornung This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA indi-starbook-ten-0.1/starbook_ten.h0000644000175100017510000000424514136175546017017 0ustar debiandebian#ifndef _STARBOOK_TEN_H_ #define _STARBOOK_TEN_H_ #include #include #include #include "httplib.h" #define STARBOOK_TEN_DEFAULT_PULSE_RATE 288 class StarbookTen { private: httplib::Client *http; bool sendBasicCmd(const char *cmd); std::string sxfmt(double x); public: enum Axis { AXIS_PRIMARY = 0, AXIS_SECONDARY = 1 }; enum PierSide { PIERSIDE_WEST = 0, PIERSIDE_EAST = 1 }; enum State { STATE_INIT, STATE_USER, STATE_CHART, STATE_SCOPE }; enum GuideDirection { GUIDE_NORTH = 0, GUIDE_SOUTH = 1, GUIDE_EAST = 2, GUIDE_WEST = 3 }; enum CoordType { COORD_TYPE_J2000, COORD_TYPE_NOW }; struct MountStatus { double ra; double dec; bool goto_busy; State state; }; static const double slewRates[]; StarbookTen(httplib::Client *http); StarbookTen(const char *base_url); ~StarbookTen(); bool destroyClient; void setHttpClient(httplib::Client *http); std::tuple getFirmwareVersion(); PierSide getPierSide(); PierSide getNewPierSide(double ra, double dec); bool setPierSide(PierSide pierside); ln_zonedate getDateTime(); std::tuple getLatLon(); bool setDateTime(const ln_zonedate& zdt); bool setLatLon(double lat, double lon); bool setLatLonTz(double lat, double lon, long utc_off_secs); CoordType getCoordType(); bool setCoordType(CoordType ct); MountStatus getStatus(); bool isTracking(); std::tuple getGuidingRaDec(); std::tuple getRaDec(); bool setPulseRate(int ra_arcsec_per_sec, int dec_arcsec_per_sec); bool movePulse(GuideDirection dir, uint32_t ms); bool home(); bool park(); bool unpark(); bool setParkCurrent(); bool findHome(); bool start(bool init = true); bool stop(); bool setSlewRate(int index); bool sync(double ra, double dec); bool goTo(double ra, double dec); bool move(Axis axis, double rate); }; #endif /* _STARBOOK_TEN_H_ */ indi-starbook-ten-0.1/indi_starbook_ten.cpp0000644000175100017510000004415014136175546020354 0ustar debiandebian#include "indicom.h" #include "indi_starbook_ten.h" #include "config.h" #define MOUNT_TAB "Mount" template Tr retry(int retries, std::function f) { for (;;) { try { return f(); } catch (std::exception& ex) { if (retries-- > 0) { continue; } else { throw; } } } } template Tr retry(int retries, Tf f, Tc inst, Args&& ... args) { for (;;) { try { return (inst ->* f)(std::forward(args)...); } catch (std::exception& ex) { if (retries-- > 0) { continue; } else { throw; } } } } static std::unique_ptr scope(new INDIStarbookTen()); void ISGetProperties(const char *dev) { scope->ISGetProperties(dev); } void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { scope->ISNewSwitch(dev, name, states, names, n); } void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) { scope->ISNewText(dev, name, texts, names, n); } void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { scope->ISNewNumber(dev, name, values, names, n); } void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) { INDI_UNUSED(dev); INDI_UNUSED(name); INDI_UNUSED(sizes); INDI_UNUSED(blobsizes); INDI_UNUSED(blobs); INDI_UNUSED(formats); INDI_UNUSED(names); INDI_UNUSED(n); } void ISSnoopDevice(XMLEle *root) { scope->ISSnoopDevice(root); } INDIStarbookTen::INDIStarbookTen() { setVersion(STARBOOK_TEN_VERSION_MAJOR, STARBOOK_TEN_VERSION_MINOR); DBG_SCOPE = INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE"); SetTelescopeCapability(TELESCOPE_CAN_GOTO | TELESCOPE_CAN_SYNC | TELESCOPE_CAN_PARK | TELESCOPE_CAN_ABORT | TELESCOPE_HAS_TIME | TELESCOPE_HAS_LOCATION | TELESCOPE_CAN_CONTROL_TRACK | TELESCOPE_HAS_PIER_SIDE, 9); setTelescopeConnection(CONNECTION_NONE); starbook = new StarbookTen(static_cast(nullptr)); } INDIStarbookTen::~INDIStarbookTen() { delete starbook; } const char * INDIStarbookTen::getDefaultName() { return "Starbook Ten"; } bool INDIStarbookTen::initProperties() { INDI::Telescope::initProperties(); httpConnection = new Connection::HTTP(this); httpConnection->registerHandshake([&]() { return callHandshake(); }); registerConnection(httpConnection); httpConnection->setDefaultHost("http://169.254.0.1"); IUFillText(&InfoT[MI_FW_VERSION], "MI_FW_VERSION", "Firmware Version", nullptr); IUFillTextVector(&InfoTP, InfoT, MI_LAST, getDeviceName(), "MOUNT_INFO", "Mount Info", MOUNT_TAB, IP_RO, 60, IPS_IDLE); IUFillText(&StateT[MS_STATE], "STATE", "State", nullptr); IUFillTextVector(&StateTP, StateT, MS_LAST, getDeviceName(), "MOUNT_STATE", "Status", MOUNT_TAB, IP_RO, 60, IPS_IDLE); IUFillSwitch(&SlewRateS[0], "0.5x", "0.5x", ISS_OFF); IUFillSwitch(&SlewRateS[1], "1x", "1x", ISS_OFF); IUFillSwitch(&SlewRateS[2], "2x", "2x", ISS_OFF); IUFillSwitch(&SlewRateS[3], "5x", "5x", ISS_OFF); IUFillSwitch(&SlewRateS[4], "10x", "10x", ISS_OFF); IUFillSwitch(&SlewRateS[5], "30x", "30x", ISS_ON); IUFillSwitch(&SlewRateS[6], "100x", "100x", ISS_OFF); IUFillSwitch(&SlewRateS[7], "300x", "300x", ISS_OFF); IUFillSwitch(&SlewRateS[8], "500x", "500x", ISS_OFF); IUFillSwitchVector(&SlewRateSP, SlewRateS, 9, getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); IUFillNumber(&GuideRateN[GR_RA], "RA_GUIDE_RATE", "RA (arcsec/sec)", "%.0f", 0, 30, 1, 15); IUFillNumber(&GuideRateN[GR_DE], "DE_GUIDE_RATE", "DEC (arcsec/sec)", "%.0f", 0, 30, 1, 15); IUFillNumberVector(&GuideRateNP, GuideRateN, GR_LAST, getDeviceName(), "GUIDE_RATE", "Guiding Rate", GUIDE_TAB, IP_RW, 0, IPS_IDLE); IUFillSwitch(&HomeS[HS_FIND_HOME], "FindHome", "Find Home", ISS_OFF); IUFillSwitchVector(&HomeSP, HomeS, HS_LAST, getDeviceName(), "TELESCOPE_HOME", "Homing", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); INDI::GuiderInterface::initGuiderProperties(getDeviceName(), GUIDE_TAB); setDriverInterface(getDriverInterface() | GUIDER_INTERFACE); addDebugControl(); addConfigurationControl(); return true; } bool INDIStarbookTen::updateProperties() { INDI::Telescope::updateProperties(); if (isConnected()) { defineProperty(&InfoTP); defineProperty(&StateTP); defineProperty(&GuideNSNP); defineProperty(&GuideWENP); defineProperty(&GuideRateNP); defineProperty(&HomeSP); return fetchStartupInfo(); } else { deleteProperty(InfoTP.name); deleteProperty(StateTP.name); deleteProperty(GuideNSNP.name); deleteProperty(GuideWENP.name); deleteProperty(GuideRateNP.name); deleteProperty(HomeSP.name); return true; } } bool INDIStarbookTen::saveConfigItems(FILE *fp) { IUSaveConfigNumber(fp, &GuideRateNP); return INDI::Telescope::saveConfigItems(fp); } bool INDIStarbookTen::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { if (!strcmp(GuideRateNP.name, name)) { IUUpdateNumber(&GuideRateNP, values, names, n); try { int ra_rate = (int)GuideRateN[GR_RA].value; int de_rate = (int)GuideRateN[GR_DE].value; LOGF_INFO("Setting guide rate RA=%d arcsec/sec, DE=%d arcsec/sec", ra_rate, de_rate); retry(1, &StarbookTen::setPulseRate, starbook, ra_rate, de_rate); GuideRateNP.s = IPS_OK; } catch (std::exception &ex) { LOGF_ERROR("Setting guide rate failed: %s", ex.what()); GuideRateNP.s = IPS_ALERT; } IDSetNumber(&GuideRateNP, nullptr); return true; } else if (!strcmp(GuideNSNP.name, name)) { LOG_DEBUG("Prop guiding in DE started"); isPropGuidingDE = true; INDI::GuiderInterface::processGuiderProperties(name, values, names, n); return true; } else if (!strcmp(GuideWENP.name, name)) { LOG_DEBUG("Prop guiding in RA started"); isPropGuidingRA = true; INDI::GuiderInterface::processGuiderProperties(name, values, names, n); return true; } } return INDI::Telescope::ISNewNumber(dev, name, values, names, n); } bool INDIStarbookTen::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { if (!strcmp(HomeSP.name, name)) { if (HomeSP.s == IPS_BUSY) { LOG_WARN("Find home is already in progress."); return true; } try { LOG_INFO("Find home started"); retry(2, &StarbookTen::findHome, starbook); TrackState = SCOPE_SLEWING; HomeS[HS_FIND_HOME].s = ISS_ON; HomeSP.s = IPS_BUSY; } catch (std::exception &ex) { LOGF_ERROR("Find home failed: %s", ex.what()); HomeS[HS_FIND_HOME].s = ISS_OFF; HomeSP.s = IPS_ALERT; } IDSetSwitch(&HomeSP, nullptr); return true; } } return INDI::Telescope::ISNewSwitch(dev, name, states, names, n); } bool INDIStarbookTen::Handshake() { auto http = httpConnection->getClient(); starbook->setHttpClient(http); try { starbook->getFirmwareVersion(); retry(2, &StarbookTen::start, starbook, true); return true; } catch (std::exception& ex) { LOGF_ERROR("Handshake failed: %s", ex.what()); return false; } } bool INDIStarbookTen::updateStarbookState(StarbookTen::MountStatus& stat) { IUSaveText(&StateT[MS_STATE], (stat.state == StarbookTen::STATE_INIT) ? "INIT" : (stat.state == StarbookTen::STATE_USER) ? "USER" : (stat.state == StarbookTen::STATE_CHART) ? "CHART" : "SCOPE"); StateTP.s = IPS_OK; IDSetText(&StateTP, nullptr); return true; } bool INDIStarbookTen::fetchStartupInfo() { try { LOG_INFO("Getting startup data..."); std::tuple ver = starbook->getFirmwareVersion(); auto stat = starbook->getStatus(); ln_zonedate zdt = starbook->getDateTime(); std::tuple loc = starbook->getLatLon(); std::stringstream ver_ss; ver_ss << std::get<0>(ver) << "." << std::get<1>(ver); IUSaveText(&InfoT[MI_FW_VERSION], ver_ss.str().c_str()); InfoTP.s = IPS_OK; IDSetText(&InfoTP, nullptr); double lon = std::get<1>(loc); LocationN[LOCATION_LATITUDE].value = std::get<0>(loc); LocationN[LOCATION_LONGITUDE].value = (lon < 0) ? (lon + 360) : lon; LocationNP.s = IPS_OK; IDSetNumber(&LocationNP, nullptr); char str[128]; snprintf(str, sizeof(str)-1, "%04d-%02d-%02dT%02d:%02d:%02d", zdt.years, zdt.months, zdt.days, zdt.hours, zdt.minutes, (int)zdt.seconds); IUSaveText(&TimeT[0], str); snprintf(str, sizeof(str)-1, "%.2f", (zdt.gmtoff/3600.0)); IUSaveText(&TimeT[1], str); TimeTP.s = IPS_OK; IDSetText(&TimeTP, nullptr); return updateStarbookState(stat); } catch (std::exception &ex) { LOGF_ERROR("fetchStartupInfo failed: %s", ex.what()); return false; } } bool INDIStarbookTen::ReadScopeStatus() { try { auto stat = retry(2, &StarbookTen::getStatus, starbook); bool isTracking = retry(2, &StarbookTen::isTracking, starbook); updateStarbookState(stat); if (stat.goto_busy) { if ((TrackState == SCOPE_IDLE) || (TrackState == SCOPE_TRACKING)) TrackState = SCOPE_SLEWING; } else { if (TrackState == SCOPE_PARKING) { SetParked(true); } else if ((stat.state == StarbookTen::STATE_INIT) || (stat.state == StarbookTen::STATE_USER)) { TrackState = SCOPE_IDLE; } else { TrackState = isTracking ? SCOPE_TRACKING : SCOPE_IDLE; } if (HomeSP.s == IPS_BUSY) { LOG_INFO("Find home completed"); HomeSP.s = IPS_OK; HomeS[HS_FIND_HOME].s = ISS_OFF; IDSetSwitch(&HomeSP, nullptr); } } NewRaDec(stat.ra, stat.dec); auto ps = retry(2, &StarbookTen::getPierSide, starbook); setPierSide((ps == StarbookTen::PIERSIDE_EAST) ? INDI::Telescope::PIER_EAST : INDI::Telescope::PIER_WEST); if (isPropGuidingRA || isPropGuidingDE) { auto gs = retry >(2, &StarbookTen::getGuidingRaDec, starbook); LOGF_DEBUG("Prop guiding status: RA=%d, DEC=%d", !!(std::get<0>(gs)), !!(std::get<1>(gs))); if (isPropGuidingRA && !std::get<0>(gs)) { LOG_DEBUG("Prop guiding in RA finished"); isPropGuidingRA = false; INDI::GuiderInterface::GuideComplete(AXIS_RA); } if (isPropGuidingDE && !std::get<1>(gs)) { LOG_DEBUG("Prop guiding in DE finished"); isPropGuidingDE = false; INDI::GuiderInterface::GuideComplete(AXIS_DE); } } return true; } catch (std::exception &ex) { LOGF_ERROR("ReadScopeStatus failed: %s", ex.what()); return false; } } bool INDIStarbookTen::Goto(double ra, double dec) { try { retry(2, &StarbookTen::goTo, starbook, ra, dec); TrackState = SCOPE_SLEWING; return true; } catch (std::exception &ex) { LOGF_ERROR("Goto failed: %s", ex.what()); return false; } } bool INDIStarbookTen::Sync(double ra, double dec) { try { retry(2, &StarbookTen::sync, starbook, ra, dec); NewRaDec(ra, dec); return true; } catch (std::exception &ex) { LOGF_ERROR("Sync failed: %s", ex.what()); return false; } } bool INDIStarbookTen::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) { try { if (command == MOTION_START) { double absrate = StarbookTen::slewRates[IUFindOnSwitchIndex(&SlewRateSP)]; double rate = (dir == DIRECTION_NORTH) ? absrate : -absrate; return retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_SECONDARY, rate); } else { return retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_SECONDARY, 0); } } catch (std::exception &ex) { LOGF_ERROR("MoveNS failed: %s", ex.what()); return false; } } bool INDIStarbookTen::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) { try { if (command == MOTION_START) { double absrate = StarbookTen::slewRates[IUFindOnSwitchIndex(&SlewRateSP)]; double rate = (dir == DIRECTION_EAST) ? absrate : -absrate; return retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_PRIMARY, rate); } else { return retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_PRIMARY, 0); } } catch (std::exception &ex) { LOGF_ERROR("MoveWE failed: %s", ex.what()); return false; } } bool INDIStarbookTen::Park() { try { retry(2, &StarbookTen::park, starbook); TrackState = SCOPE_PARKING; return true; } catch (std::exception &ex) { LOGF_ERROR("Parking failed: %s", ex.what()); return false; } } bool INDIStarbookTen::UnPark() { try { retry(2, &StarbookTen::unpark, starbook); SetParked(false); retry(2, &StarbookTen::start, starbook, true); TrackState = SCOPE_TRACKING; return true; } catch (std::exception &ex) { LOGF_ERROR("Un-parking failed: %s", ex.what()); return false; } } bool INDIStarbookTen::SetCurrentPark() { try { return retry(2, &StarbookTen::setParkCurrent, starbook); } catch (std::exception &ex) { LOGF_ERROR("SetCurrentPark failed: %s", ex.what()); return false; } } bool INDIStarbookTen::Abort() { try { LOG_INFO("Aborting motion"); retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_PRIMARY, 0); retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_SECONDARY, 0); retry(2, &StarbookTen::stop, starbook); return retry(2, &StarbookTen::start, starbook, true); } catch (std::exception &ex) { LOGF_ERROR("Abort failed: %s", ex.what()); return false; } } bool INDIStarbookTen::SetTrackEnabled(bool enabled) { try { if (enabled) { LOG_INFO("Enabling tracking"); return retry(2, &StarbookTen::start, starbook, true); } else { LOG_INFO("Disabling tracking"); return retry(2, &StarbookTen::stop, starbook); } } catch (std::exception &ex) { LOGF_ERROR("SetTrackEnabled failed: %s", ex.what()); return false; } } bool INDIStarbookTen::updateTime(ln_date *utc, double utc_offset) { try { ln_zonedate zdt; ln_date_to_zonedate(utc, &zdt, utc_offset * 3600.0); return retry(2, &StarbookTen::setDateTime, starbook, zdt); } catch (std::exception &ex) { LOGF_ERROR("UpdateTime failed: %s", ex.what()); return false; } } bool INDIStarbookTen::updateLocation(double latitude, double longitude, double elevation) { INDI_UNUSED(elevation); try { retry(2, &StarbookTen::setLatLon, starbook, latitude, longitude); char l[32], L[32]; fs_sexa(l, latitude, 3, 3600); fs_sexa(L, longitude, 4, 3600); LOGF_INFO("Site location updated to Lat %.32s - Long %.32s", l, L); return true; } catch (std::exception &ex) { LOGF_ERROR("UpdateLocation failed: %s", ex.what()); return false; } } bool INDIStarbookTen::SetSlewRate(int index) { try { LOGF_INFO("Setting slew rate: %d", index); return retry(2, &StarbookTen::setSlewRate, starbook, index); } catch (std::exception &ex) { LOGF_ERROR("SetSlewRate failed: %s", ex.what()); return false; } } IPState INDIStarbookTen::GuideNorth(uint32_t ms) { try { retry(1, &StarbookTen::movePulse, starbook, StarbookTen::GUIDE_NORTH, ms); return IPS_OK; } catch (std::exception &ex) { LOGF_ERROR("GuideNorth failed: %s", ex.what()); return IPS_ALERT; } } IPState INDIStarbookTen::GuideSouth(uint32_t ms) { try { retry(1, &StarbookTen::movePulse, starbook, StarbookTen::GUIDE_SOUTH, ms); return IPS_OK; } catch (std::exception &ex) { LOGF_ERROR("GuideSouth failed: %s", ex.what()); return IPS_ALERT; } } IPState INDIStarbookTen::GuideEast(uint32_t ms) { try { retry(1, &StarbookTen::movePulse, starbook, StarbookTen::GUIDE_EAST, ms); return IPS_OK; } catch (std::exception &ex) { LOGF_ERROR("GuideEast failed: %s", ex.what()); return IPS_ALERT; } } IPState INDIStarbookTen::GuideWest(uint32_t ms) { try { retry(1, &StarbookTen::movePulse, starbook, StarbookTen::GUIDE_WEST, ms); return IPS_OK; } catch (std::exception &ex) { LOGF_ERROR("GuideWest failed: %s", ex.what()); return IPS_ALERT; } } indi-starbook-ten-0.1/AUTHORS0000644000175100017510000000005314136175546015215 0ustar debiandebianAlex Hornung indi-starbook-ten-0.1/starbook_ten.cpp0000644000175100017510000002607314136175546017355 0ustar debiandebian#include #include #include #include "starbook_ten.h" StarbookTen::StarbookTen(httplib::Client *http) : http(http) { setHttpClient(http); } StarbookTen::StarbookTen(const char *base_url) { http = new httplib::Client(base_url); http->set_connection_timeout(2, 0); http->set_read_timeout(3, 0); http->set_write_timeout(3, 0); http->set_keep_alive(true); http->set_url_encode(false); destroyClient = true; } StarbookTen::~StarbookTen() { if (destroyClient) delete http; } void StarbookTen::setHttpClient(httplib::Client *http) { if (http) { http->set_connection_timeout(2, 0); http->set_read_timeout(3, 0); http->set_write_timeout(3, 0); http->set_keep_alive(true); http->set_url_encode(false); } this->http = http; destroyClient = false; } bool StarbookTen::sendBasicCmd(const char *cmd) { auto res = http->Get(cmd); if (!res || res->status != 200) { throw std::runtime_error("sendBasicCmd HTTP error"); } if (res->body.find(R"()") == std::string::npos) { throw std::runtime_error("sendBasicCmd response error"); } return true; } std::tuple StarbookTen::getFirmwareVersion() { auto res = http->Get("/version"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"()"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { int vmaj = std::stoi(sm[1]); int vmin = std::stoi(sm[2]); return std::tuple(vmaj, vmin); } else { throw std::runtime_error("Could not get version"); } } StarbookTen::PierSide StarbookTen::getPierSide() { auto res = http->Get("/get_pierside"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"(PIERSIDE=([01]))"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { return static_cast(std::stoi(sm[1])); } else { throw std::runtime_error("Could not get pier side"); } } StarbookTen::PierSide StarbookTen::getNewPierSide(double ra, double dec) { std::stringstream cmd_ss; cmd_ss << "/calc_sideofpier?ra=" << ra << "&dec=" << dec; auto res = http->Get(cmd_ss.str().c_str()); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"(PIERSIDE=([01]))"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { return static_cast(std::stoi(sm[1])); } else { throw std::runtime_error("Could not get new pier side"); } } bool StarbookTen::setPierSide(PierSide pierside) { std::stringstream cmd_ss; cmd_ss << "/set_pierside?pierside=" << static_cast(pierside); return sendBasicCmd(cmd_ss.str().c_str()); } ln_zonedate StarbookTen::getDateTime() { ln_zonedate zdt; auto res = http->Get("/gettime"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"(TIME=(\d{4})\+(\d{1,2})\+(\d{1,2})\+(\d{1,2})\+(\d{1,2})\+(\d{1,2}))"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { zdt.years = std::stoi(sm[1]); zdt.months = std::stoi(sm[2]); zdt.days = std::stoi(sm[3]); zdt.hours = std::stoi(sm[4]); zdt.minutes = std::stoi(sm[5]); zdt.seconds = std::stoi(sm[6]); } else { throw std::runtime_error("Could not get time"); } res = http->Get("/getplace"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex rtz(R"()"); std::smatch smtz; if (std::regex_search(res->body, smtz, rtz)) { zdt.gmtoff = std::stoi(smtz[1])*3600; } else { throw std::runtime_error("Could not get timezone"); } return zdt; } bool StarbookTen::setDateTime(const ln_zonedate& zdt) { char buf[256]; std::tuple latlon = getLatLon(); snprintf(buf, sizeof(buf)-1, "/settime?TIME=%04d+%02d+%02d+%02d+%02d+%02d", zdt.years, zdt.months, zdt.days, zdt.hours, zdt.minutes, static_cast(zdt.seconds)); sendBasicCmd(buf); return setLatLonTz(std::get<0>(latlon), std::get<1>(latlon), zdt.gmtoff); } bool StarbookTen::setLatLon(double lat, double lon) { ln_zonedate zdt = getDateTime(); return setLatLonTz(lat, lon, zdt.gmtoff); } bool StarbookTen::setLatLonTz(double lat, double lon, long utc_off_secs) { char buf[256]; ln_dms lat_dms, lon_dms; ln_deg_to_dms(lat, &lat_dms); ln_deg_to_dms(lon, &lon_dms); snprintf(buf, sizeof(buf)-1, "/setplace?longitude=%s%d+%d&latitude=%s%d+%d&timezone=%ld", (lon_dms.neg ? "W" : "E"), lon_dms.degrees, lon_dms.minutes, (lat_dms.neg ? "S" : "N"), lat_dms.degrees, lat_dms.minutes, utc_off_secs/3600); return sendBasicCmd(buf); } std::tuple StarbookTen::getLatLon() { auto res = http->Get("/getplace"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"()"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { ln_dms lon_dms, lat_dms; lon_dms.neg = (sm[1].compare("W") == 0) ? 1 : 0; lon_dms.degrees = std::stoi(sm[2]); lon_dms.minutes = std::stoi(sm[3]); lon_dms.seconds = 0; lat_dms.neg = (sm[4].compare("S") == 0) ? 1 : 0; lat_dms.degrees = std::stoi(sm[5]); lat_dms.minutes = std::stoi(sm[6]); lat_dms.seconds = 0; return std::tuple(ln_dms_to_deg(&lat_dms), ln_dms_to_deg(&lon_dms)); } else { throw std::runtime_error("Could not get lat/long"); } } StarbookTen::CoordType StarbookTen::getCoordType() { auto res = http->Get("/getradectype"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"((J2000|NOW))"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { return (sm[1].compare("J2000") == 0) ? COORD_TYPE_J2000 : COORD_TYPE_NOW; } else { throw std::runtime_error("Could not get coordinate type"); } } bool StarbookTen::setCoordType(CoordType ct) { return sendBasicCmd((ct == COORD_TYPE_J2000) ? "/setradectype?type=J2000" : "/setradectype?type=NOW"); } StarbookTen::MountStatus StarbookTen::getStatus() { auto res = http->Get("/getstatus2"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"()"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { MountStatus stat; stat.ra = std::stod(sm[1]); stat.dec = std::stod(sm[2]); stat.goto_busy = !(sm[3].compare("0") == 0); stat.state = (sm[4].compare("USER") == 0) ? STATE_USER : (sm[4].compare("CHART") == 0) ? STATE_CHART : (sm[4].compare("SCOPE") == 0) ? STATE_SCOPE : STATE_INIT; return stat; } else { throw std::runtime_error("Could not get status"); } } bool StarbookTen::isTracking() { auto res = http->Get("/gettrackstatus"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } // TRACK=2 seems to be used during gotos, but since we can already figure // gotos out from the getstatus2 call, there's no need to handle it here. std::regex r(R"()"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { return !(sm[1].compare("1")); } else { throw std::runtime_error("Could not get track status"); } } std::tuple StarbookTen::getGuidingRaDec() { auto res = http->Get("/getguidestatus"); if (!res || res->status != 200) { throw std::runtime_error("HTTP get failed"); } std::regex r(R"()"); std::smatch sm; if (std::regex_search(res->body, sm, r)) { return std::tuple((!(sm[1].compare("1")) || !(sm[2].compare("1"))), (!(sm[3].compare("1")) || !(sm[4].compare("1")))); } else { throw std::runtime_error("Could not get guide status"); } } std::tuple StarbookTen::getRaDec() { auto stat = getStatus(); return std::tuple(stat.ra, stat.dec); } bool StarbookTen::setPulseRate(int ra_arcsec_per_sec, int dec_arcsec_per_sec) { std::stringstream cmd_ss; cmd_ss << "/setpulsespeed?ra=" << ra_arcsec_per_sec << "&dec=" << dec_arcsec_per_sec; return sendBasicCmd(cmd_ss.str().c_str()); } bool StarbookTen::movePulse(GuideDirection dir, uint32_t ms) { std::stringstream cmd_ss; cmd_ss << "/movepulse?direct=" << static_cast(dir) << "&duration=" << ms; return sendBasicCmd(cmd_ss.str().c_str()); } bool StarbookTen::home() { return sendBasicCmd("/home"); } bool StarbookTen::park() { return sendBasicCmd("/goto_park"); } bool StarbookTen::unpark() { return sendBasicCmd("/unpark"); } bool StarbookTen::setParkCurrent() { return sendBasicCmd("/set_park"); } bool StarbookTen::findHome() { return sendBasicCmd("/home"); } bool StarbookTen::start(bool init) { return sendBasicCmd(init ? "/start" : "/start?init=off"); } bool StarbookTen::stop() { return sendBasicCmd("/stop"); } bool StarbookTen::setSlewRate(int index) { if (index < 0 || index > 8) { throw std::runtime_error("Invalid slew rate"); } std::stringstream cmd_ss; cmd_ss << "/setspeed?speed=" << index; return sendBasicCmd(cmd_ss.str().c_str()); } bool StarbookTen::goTo(double ra, double dec) { std::stringstream cmd_ss; cmd_ss << "/gotoradec?ra=" << sxfmt(ra) << "&dec=" << sxfmt(dec); return sendBasicCmd(cmd_ss.str().c_str()); } bool StarbookTen::sync(double ra, double dec) { std::stringstream cmd_ss; cmd_ss << "/align?ra=" << sxfmt(ra) << "&dec=" << sxfmt(dec); return sendBasicCmd(cmd_ss.str().c_str()); } bool StarbookTen::move(StarbookTen::Axis axis, double rate) { if (fabs(rate) > StarbookTen::slewRates[8]) { throw std::runtime_error("Invalid move rate"); } std::stringstream cmd_ss; cmd_ss << "/move_axis?axis=" << static_cast(axis) << "&rate=" << rate; return sendBasicCmd(cmd_ss.str().c_str()); } std::string StarbookTen::sxfmt(double x) { char buf[32]; int w = (int)x; double frac = x-w; double mins = frac * 60.0; snprintf(buf, sizeof(buf)-1, "%d+%02.5lf", w, mins); return std::string(buf); } const double StarbookTen::slewRates[] = { 0.5 * 360.0/86400.0, 1 * 360.0/86400.0, 2 * 360.0/86400.0, 5 * 360.0/86400.0, 10 * 360.0/86400.0, 30 * 360.0/86400.0, 100 * 360.0/86400.0, 300 * 360.0/86400.0, 500 * 360.0/86400.0 }; indi-starbook-ten-0.1/INSTALL0000644000175100017510000000041714136175546015202 0ustar debiandebianCompile & Install ============= Compile & Install from within the indi-3rdparty repository: mkdir build-starbook-ten cd build-starbook-ten cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr . ../indi-starbook-ten make sudo make install indi-starbook-ten-0.1/indi_starbook_ten.h0000644000175100017510000000621214136175546020016 0ustar debiandebian#ifndef _INDI_STARBOOK_TEN_H_ #define _INDI_STARBOOK_TEN_H_ #include "inditelescope.h" #include "indiguiderinterface.h" #include "connectionhttp.h" #include "starbook_ten.h" class INDIStarbookTen : public INDI::Telescope, INDI::GuiderInterface { public: INDIStarbookTen(); ~INDIStarbookTen(); virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; protected: virtual const char *getDefaultName() override; virtual bool initProperties() override; virtual bool updateProperties() override; virtual bool Handshake() override; virtual bool saveConfigItems(FILE *fp) override; /***************************************************/ /*** INDI Telescope interface ***/ /***************************************************/ virtual bool ReadScopeStatus() override; virtual bool Goto(double ra, double dec) override; virtual bool Sync(double ra, double dec) override; virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override; virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override; virtual bool Park() override; virtual bool UnPark() override; virtual bool SetCurrentPark() override; virtual bool Abort() override; virtual bool SetTrackEnabled(bool enabled) override; virtual bool updateTime(ln_date *utc, double utc_offset) override; virtual bool updateLocation(double latitude, double longitude, double elevation) override; virtual bool SetSlewRate(int index) override; /***************************************************/ /*** INDI Guider interface ***/ /***************************************************/ void initGuiderProperties(const char *deviceName, const char *groupName); void processGuiderProperties(const char *name, double values[], char *names[], int n); virtual IPState GuideNorth(uint32_t ms) override; virtual IPState GuideSouth(uint32_t ms) override; virtual IPState GuideEast(uint32_t ms) override; virtual IPState GuideWest(uint32_t ms) override; private: bool fetchStartupInfo(); bool updateStarbookState(StarbookTen::MountStatus& stat); uint8_t DBG_SCOPE { INDI::Logger::DBG_IGNORE }; /* Mount info */ enum { MI_FW_VERSION, MI_LAST } MIProps; IText InfoT[MI_LAST] {}; ITextVectorProperty InfoTP; /* Mount state */ enum { MS_STATE, MS_LAST } MSProps; IText StateT[MS_LAST] {}; ITextVectorProperty StateTP; /* Guide Rate */ enum { GR_RA, GR_DE, GR_LAST } GuideProps; INumber GuideRateN[GR_LAST]; INumberVectorProperty GuideRateNP; bool isPropGuidingRA = false; bool isPropGuidingDE = false; /* Homing */ enum { HS_FIND_HOME, HS_LAST } HomeProps; ISwitch HomeS[HS_LAST]; ISwitchVectorProperty HomeSP; Connection::HTTP *httpConnection = nullptr; StarbookTen *starbook; }; #endif /* _INDI_STARBOOK_TEN_H_ */