2 Commits

4 changed files with 76 additions and 34 deletions

View File

@ -70,6 +70,60 @@ cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release
cmake --build example/build --config Release cmake --build example/build --config Release
``` ```
### Linux (WSL/Ubuntu) Quick start
Prerequisites (Ubuntu/Debian):
```bash
sudo apt-get update -y && sudo apt-get install -y \
build-essential cmake git pkg-config libcurl4-openssl-dev \
curl zip unzip tar ninja-build ca-certificates
```
Bootstrap vcpkg (once):
```bash
git clone https://github.com/microsoft/vcpkg.git "$HOME/vcpkg"
"$HOME/vcpkg/bootstrap-vcpkg.sh" -disableMetrics
```
Build (library, tests, example):
```bash
export VCPKG_ROOT="$HOME/vcpkg"
cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"
cmake --build build --config Release
```
Or simply use the helper script:
```bash
bash ./build.sh
```
Run the example:
```bash
./build/example/example
```
Run tests:
```bash
ctest --test-dir build --output-on-failure
```
Artifacts:
- Library: `build/libprivatebinapi.so`
- Example binary: `build/example/example`
Notes:
- vcpkg dependencies (`cryptopp`, `nlohmann-json`) are installed automatically during CMake configure when the toolchain file is provided.
- On Linux the example links directly against the in-tree target `privatebinapi`. On Windows it additionally copies the DLL next to the example executable after build.
- PrivateBin delete operation is performed via HTTP POST (per API), not HTTP DELETE.
### Windows (PowerShell) Build via build_thinkpad.bat ### Windows (PowerShell) Build via build_thinkpad.bat
For systems with Visual Studio 2022 Build Tools (C++ workload) and vcpkg in the user profile, there is a robust build script: For systems with Visual Studio 2022 Build Tools (C++ workload) and vcpkg in the user profile, there is a robust build script:

View File

@ -1,15 +1,22 @@
#!/bin/bash #!/bin/bash
echo "Building PrivateBin API C++ DLL..." set -euo pipefail
echo "Building PrivateBin API C++ (library + example)"
# Create build directory # Ensure vcpkg exists
mkdir -p build VCPKG_ROOT="${VCPKG_ROOT:-$HOME/vcpkg}"
cd build 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 # Clean and configure
cmake .. 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 # Build all targets
make cmake --build build --config Release
echo "Build completed!" echo "Build completed. Artifacts:"
cd .. echo " - Library: build/libprivatebinapi.so"
echo " - Example: build/example/example"

View File

@ -3,34 +3,15 @@ project(PrivateBinAPIExample)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
# Use the prebuilt library from the parent build directory # Build example and link against the in-tree target
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()
add_executable(example example.cpp) add_executable(example example.cpp)
target_link_libraries(example PRIVATE privatebinapi)
target_link_libraries(example PRIVATE ${PRIVATEBINAPI_LIB} winhttp) # On Windows, copy the DLL next to the example for easy execution
target_include_directories(example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
# Install/run helpers for tests: copy DLL next to example on Windows
if(WIN32) if(WIN32)
add_custom_command(TARGET example POST_BUILD add_custom_command(TARGET example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PRIVATEBINAPI_BUILD_DIR}/Release/privatebinapi.dll $<TARGET_FILE:privatebinapi>
$<TARGET_FILE_DIR:example> $<TARGET_FILE_DIR:example>
) )
endif() endif()

View File

@ -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_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_POSTFIELDS, data.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);