feat: v1.3-konforme API, HTTP-Fixes, Base64, Example erweitert; Makefile & README Setup

This commit is contained in:
2025-08-28 10:32:16 +02:00
parent 29818a5708
commit 23f98c22f5
8 changed files with 209 additions and 95 deletions

View File

@ -3,23 +3,25 @@ project(PrivateBinAPIExample)
set(CMAKE_CXX_STANDARD 17)
# Find the privatebinapi library
find_library(PRIVATEBINAPI_LIB privatebinapi
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../build)
# 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 not found, build it as part of the project
if(NOT PRIVATEBINAPI_LIB)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/privatebinapi)
set(PRIVATEBINAPI_LIB privatebinapi)
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()
# Create example executable
add_executable(example example.cpp)
# Link with the privatebinapi library
target_link_libraries(example ${PRIVATEBINAPI_LIB})
target_link_libraries(example PRIVATE ${PRIVATEBINAPI_LIB} winhttp)
# Include directories
target_include_directories(example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)

View File

@ -31,7 +31,41 @@ int main() {
std::cout << "Paste created successfully!" << std::endl;
std::cout << "URL: " << paste_url << std::endl;
std::cout << "Delete token: " << delete_token << std::endl;
// Parse paste_id and key from URL (format: "/?{pasteID}#{key}")
std::string full_url = paste_url ? paste_url : "";
std::string paste_id;
std::string key;
auto qpos = full_url.find('?');
auto hpos = full_url.find('#');
if (qpos != std::string::npos) {
if (hpos != std::string::npos && hpos > qpos + 1) {
paste_id = full_url.substr(qpos + 1, hpos - (qpos + 1));
key = full_url.substr(hpos + 1);
} else if (qpos + 1 < full_url.size()) {
paste_id = full_url.substr(qpos + 1);
}
}
// Try to fetch paste content back
if (!paste_id.empty() && !key.empty()) {
std::cout << "Fetching paste..." << std::endl;
char* content = nullptr;
int gr = get_paste("https://privatebin.medisoftware.org", paste_id.c_str(), key.c_str(), &content);
std::cout << "get_paste returned: " << gr << std::endl;
if (gr == 0 && content) {
std::cout << "Content: " << content << std::endl;
free_string(content);
}
}
// Try to delete paste
if (!paste_id.empty() && delete_token) {
std::cout << "Deleting paste..." << std::endl;
int dr = delete_paste("https://privatebin.medisoftware.org", paste_id.c_str(), delete_token);
std::cout << "delete_paste returned: " << dr << std::endl;
}
// Clean up allocated memory
free_string(paste_url);
free_string(delete_token);