diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f52e4..cc3f2d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,9 @@ SET(libdiscid_MAJOR 0) SET(libdiscid_MINOR 6) SET(libdiscid_PATCH 5) +# Build options +OPTION(ENABLE_USE_HTTPS "Enable creating HTTPS URLs" OFF) + SET(libdiscid_VERSION ${libdiscid_MAJOR}.${libdiscid_MINOR}.${libdiscid_PATCH}) SET(libdiscid_SOVERSION ${libdiscid_MAJOR}) @@ -107,6 +110,9 @@ SET_TARGET_PROPERTIES(libdiscid PROPERTIES ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include ${MUSICBRAINZ5_INCLUDE_DIRS}) +IF(ENABLE_USE_HTTPS) + TARGET_COMPILE_DEFINITIONS(libdiscid PUBLIC DISCID_USE_HTTPS) +ENDIF() ADD_EXECUTABLE(discid examples/discid.c) TARGET_LINK_LIBRARIES(discid libdiscid) diff --git a/INSTALL b/INSTALL index 4b53206..986af70 100644 --- a/INSTALL +++ b/INSTALL @@ -29,6 +29,30 @@ Optional API documentation in HTML format is created by Doxygen with: make docs + +Compiler flags +-------------- + +The following defines can be used to change the build: + +DISCID_USE_HTTPS: If set, the functions discid_get_submission_url and + discid_get_webservice_url will generate URLs using the HTTPS protocol instead + of HTTP. This might break existing applications that rely on the exact URL + structure being returned. + +To enable this feature when using CMake, change the cmake command from above to: + + cmake -DENABLE_USE_HTTPS=ON … + +To enable this feature when using Autotools, change the configure command from above to: + + ../configure --enable-use-https=yes + +NOTE: Having DISCID_USE_HTTPS enabled will become the default in a future release. + Please prepare your code to not rely on the specific URL protocol for URLs + generated by libdiscid. + + Building from git repository ---------------------------- If you fetched the source with git, you should either @@ -36,6 +60,7 @@ use Cmake (no difference to the source distribution) or have autoconf, automake and libtool installed and do ./autogen.sh before doing the usual build. + Tips for Windows ---------------- For most systems cmake and autotools work (nearly) "out of the box". @@ -51,6 +76,7 @@ Building with NMake (MS Visual Studio command line): cmake -G "NMake Makefiles" .. nmake + Notes for BSD ------------- With Cmake builds the library version/soname will work the same as on Linux. diff --git a/configure.ac b/configure.ac index 055f5a4..7a5724e 100644 --- a/configure.ac +++ b/configure.ac @@ -13,6 +13,12 @@ define(PATCH, 5) # so we use the library version also as project version AC_INIT([libdiscid],[MAJOR.MINOR.PATCH]) +AC_ARG_ENABLE([use_https], + AS_HELP_STRING([--enable-use-https], [Enable creating HTTPS URLs]), + [use_https=$enableval], + [use_https=no] +) + AC_CONFIG_SRCDIR([src/disc.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_AUX_DIR([build-aux]) # where to put config.guess etc. @@ -42,7 +48,9 @@ dnl Set the host_cpu, host_vendor, and host_os variables. AC_CANONICAL_HOST AC_DEFINE(libdiscid_EXPORTS, [], "the header is used to create the library") - +if test "x$use_https" = "xyes"; then + AC_DEFINE([DISCID_USE_HTTPS], [1], [Define to 1 if use_https is enabled]) +fi case "${host_cpu}-${host_os}" in *-haiku*) os=haiku;; diff --git a/include/discid/discid_private.h b/include/discid/discid_private.h index 4b6d3ae..c84402f 100644 --- a/include/discid/discid_private.h +++ b/include/discid/discid_private.h @@ -27,8 +27,18 @@ #ifndef MUSICBRAINZ_DISC_ID_PRIVATE_H #define MUSICBRAINZ_DISC_ID_PRIVATE_H +#ifdef HAVE_CONFIG_H +#include +#endif + #include "discid/discid.h" +#ifdef DISCID_USE_HTTPS +#define MB_URL_PROTOCOL "https" +#else +#define MB_URL_PROTOCOL "http" +#endif + /* Length of toc string, "xxx+xxx" + 100 tracks 7 bytes each ("+xxxxxx") * The highest possible offset is 90 minutes * 60 seconds/minute * 75 frames/second = 405000. * That is 6 digits plus one plus sign = 7 characters per track. @@ -52,10 +62,10 @@ #define MB_MAX_URL_LENGTH (MB_URL_PREFIX_LENGTH + MB_DISC_ID_LENGTH + MB_TOC_STRING_LENGTH) /* The URL that can be used for submitting DiscIDs (no parameters yet) */ -#define MB_SUBMISSION_URL "https://musicbrainz.org/cdtoc/attach" +#define MB_SUBMISSION_URL MB_URL_PROTOCOL"://musicbrainz.org/cdtoc/attach" /* The URL that can be used for retrieving XML for a CD */ -#define MB_WEBSERVICE_URL "https://musicbrainz.org/ws/1/release" +#define MB_WEBSERVICE_URL MB_URL_PROTOCOL"://musicbrainz.org/ws/1/release" /* Maximum length of a Media Catalogue Number string */ #define MCN_STR_LENGTH 13 @@ -117,7 +127,7 @@ LIBDISCID_INTERNAL int mb_disc_read_unportable(mb_disc_private *disc, const char /* - * This should return the name of the default/preferred CDROM/DVD device + * This should return the name of the default/preferred CDROM/DVD device * on this operating system. It has to be in a format usable for the second * parameter of mb_disc_read_unportable(). */ diff --git a/test/test_put.c b/test/test_put.c index 53b8a32..40ee7f7 100644 --- a/test/test_put.c +++ b/test/test_put.c @@ -24,6 +24,7 @@ #include #include +#include #include "test.h" @@ -100,14 +101,14 @@ int main(int argc, char *argv[]) { /* MusicBrainz web submit URL */ announce("discid_get_submission_url"); - expected = "https://musicbrainz.org/cdtoc/attach?id=xUp1F2NkfP8s8jaeFn_Av3jNEI4-&tracks=22&toc=1+22+303602+150+9700+25887+39297+53795+63735+77517+94877+107270+123552+135522+148422+161197+174790+192022+205545+218010+228700+239590+255470+266932+288750"; + expected = MB_URL_PROTOCOL "://musicbrainz.org/cdtoc/attach?id=xUp1F2NkfP8s8jaeFn_Av3jNEI4-&tracks=22&toc=1+22+303602+150+9700+25887+39297+53795+63735+77517+94877+107270+123552+135522+148422+161197+174790+192022+205545+218010+228700+239590+255470+266932+288750"; evaluate(equal_str(discid_get_submission_url(d), expected)); announce("discid_get_error_msg"); evaluate(strlen(discid_get_error_msg(d)) == 0); discid_free(d); - + return !test_result(); }