feat: Add QR code generation functionality to PrivateBin API library

- Add generate_qr_code() function for creating QR codes from PrivateBin links
- Implement SVG output format for scalable QR code generation
- Add qr_generator.h/cpp with self-contained QR code implementation
- Update CMakeLists.txt to include new QR code source files
- Integrate QR code documentation into README.md
- Update example program to demonstrate QR code generation
- Update CHANGELOG.md with v0.1.1.6 release notes
- Remove separate README_QR_CODE.md file

The implementation provides simplified QR code generation with:
- Position detection patterns for QR code recognition
- Configurable size and border parameters
- No external dependencies
- Comprehensive error handling
- Memory management using existing free_string() function
This commit is contained in:
mbusc
2025-08-28 22:21:00 +02:00
parent 77879e6521
commit f1b791f1f4
8 changed files with 361 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include <cstdlib>
#include <chrono>
#include <thread>
#include <fstream> // Added for file saving
// Helper function to wait between API calls to avoid rate limiting
void wait_between_calls() {
@ -267,6 +268,70 @@ int result = create_paste(server_url, content, password, expiration, format,
}
std::cout << "\nAll format tests completed!" << std::endl;
// Test 5: QR Code generation
std::cout << "\n5. Testing QR Code generation..." << std::endl;
// Create a test paste first
char* qr_paste_url = nullptr;
char* qr_delete_token = nullptr;
const char* qr_content = "This paste will be used to test QR code generation.";
result = create_paste(
"https://privatebin.medisoftware.org", // Server URL
qr_content, // Content
nullptr, // No password
"1hour", // Expire in 1 hour
"plaintext", // Plain text format
0, // Don't burn after reading
0, // No discussion
&qr_paste_url, // Output: paste URL
&qr_delete_token // Output: delete token
);
if (result == 0) {
std::cout << "✓ Test paste created for QR code generation!" << std::endl;
std::cout << "URL: " << qr_paste_url << std::endl;
// Generate QR code for the paste URL
char* qr_code_data = nullptr;
std::cout << "Generating QR code..." << std::endl;
int qr_result = generate_qr_code(qr_paste_url, &qr_code_data, 256, 4);
if (qr_result == 0) {
std::cout << "✓ QR code generated successfully!" << std::endl;
std::cout << "QR code format: SVG" << std::endl;
std::cout << "QR code dimensions: 256x256 pixels" << std::endl;
std::cout << "QR code data length: " << strlen(qr_code_data) << " characters" << std::endl;
// Save QR code to file for demonstration
std::string filename = "privatebin_qr_code.svg";
std::ofstream qr_file(filename);
if (qr_file.is_open()) {
qr_file << qr_code_data;
qr_file.close();
std::cout << "QR code saved to: " << filename << std::endl;
std::cout << "You can open this SVG file in a web browser to view the QR code." << std::endl;
} else {
std::cout << "Warning: Could not save QR code to file." << std::endl;
}
// Clean up QR code data
free_string(qr_code_data);
} else {
std::cout << "✗ QR code generation failed. Error code: " << qr_result << std::endl;
}
// Clean up paste
free_string(qr_paste_url);
free_string(qr_delete_token);
} else {
std::cout << "✗ Test paste creation failed. Error code: " << result << std::endl;
}
std::cout << "\nAll tests completed!" << std::endl;
return 0;
std::cout << "create_paste returned: " << result << std::endl;