diff --git a/build.sh b/build.sh index 0738f31..9ffda81 100644 --- a/build.sh +++ b/build.sh @@ -1,15 +1,22 @@ #!/bin/bash -echo "Building PrivateBin API C++ DLL..." +set -euo pipefail +echo "Building PrivateBin API C++ (library + example)" -# Create build directory -mkdir -p build -cd build +# Ensure vcpkg exists +VCPKG_ROOT="${VCPKG_ROOT:-$HOME/vcpkg}" +if [ ! -d "$VCPKG_ROOT" ]; then + echo "vcpkg not found under $VCPKG_ROOT, cloning..." + git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT" + "$VCPKG_ROOT/bootstrap-vcpkg.sh" -disableMetrics +fi -# Generate build files with CMake -cmake .. +# Clean and configure +rm -rf build +cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -# Build the project -make +# Build all targets +cmake --build build --config Release -echo "Build completed!" -cd .. \ No newline at end of file +echo "Build completed. Artifacts:" +echo " - Library: build/libprivatebinapi.so" +echo " - Example: build/example/example" \ No newline at end of file diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 738ed33..2589d0c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -3,34 +3,15 @@ project(PrivateBinAPIExample) set(CMAKE_CXX_STANDARD 17) -# Use the prebuilt library from the parent build directory -set(PRIVATEBINAPI_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build") -set(PRIVATEBINAPI_RELEASE_LIB "${PRIVATEBINAPI_BUILD_DIR}/Release/privatebinapi.lib") - -if(EXISTS "${PRIVATEBINAPI_RELEASE_LIB}") - set(PRIVATEBINAPI_LIB "${PRIVATEBINAPI_RELEASE_LIB}") -else() - # Fallback: try the build root (multi-config generators may place libs differently) - find_library(PRIVATEBINAPI_LIB privatebinapi PATHS "${PRIVATEBINAPI_BUILD_DIR}") -endif() - -if(NOT PRIVATEBINAPI_LIB) - message(FATAL_ERROR "privatebinapi library not found. Please run build.bat in the project root first.") -endif() - +# Build example and link against the in-tree target add_executable(example example.cpp) +target_link_libraries(example PRIVATE privatebinapi) -target_link_libraries(example PRIVATE ${PRIVATEBINAPI_LIB} winhttp) - -target_include_directories(example PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/../include -) - -# Install/run helpers for tests: copy DLL next to example on Windows +# On Windows, copy the DLL next to the example for easy execution if(WIN32) add_custom_command(TARGET example POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${PRIVATEBINAPI_BUILD_DIR}/Release/privatebinapi.dll + $ $ ) endif() \ No newline at end of file diff --git a/src/http_client.cpp b/src/http_client.cpp index 0a1de07..2cb9742 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -585,7 +585,7 @@ bool HttpClient::delete_req(const std::string& url, const std::string& data, std } curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + // PrivateBin API erwartet POST für delete curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);