Skip to main content

🛠️ Integration Example

This example demonstrates how to integrate the ATS CodeCheck library into a C application to validate Colombian identity card barcodes.

1. Activate the License

Before using the library, you must activate it by downloading the license file based on your user identifier (UID). This will save a license.lic file in the current working directory.

#include "libatscodecheck.h"

const char* uid = "your_email@example.com";
const char* workingDir = ".";
char activationResponse[1024];
int activateResult = ATS_Activate(uid, workingDir, activationResponse, sizeof(activationResponse));
if (activateResult != 0) {
printf("❌ License activation failed: %s\n", activationResponse);
} else {
printf("✅ License activated: %s\n", activationResponse);
}

2. Initialize the Library

#include "libatscodecheck.h"

const char* uid = "your_email@example.com";
const char* workingDir = ".";
char initResponse[1024];
int result = ATS_Init(uid, workingDir, initResponse, sizeof(initResponse));
if (result != 0) {
printf("❌ Initialization failed: %s\n", initResponse);
} else {
printf("✅ Initialization successful: %s\n", initResponse);
}

3. Validate a Barcode

const char* jsonRequest = "{ \"base64Barcode\": \"...\", \"requestFields\": [\"CEDNUM\", \"NUMPREP\"] }";

char responseBuffer[2048];
int code = ATS_CheckCode(jsonRequest, responseBuffer, sizeof(responseBuffer));

if (code == 0) {
printf("✅ Response: %s\n", responseBuffer);
} else {
printf("❌ ATS_CheckCode failed with code: %d\n", code);
}

4. Full Example

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// External functions from the Go shared library
extern int ATS_Init(const char* uid, const char* workingDir, char* initResponseBuffer, int bufferSize);
extern int ATS_Activate(const char* uid, const char* workingDir, char* activationResponseBuffer, int bufferSize);
extern int ATS_CheckCode(const char* jsonRequest, char* jsonResponseBuffer, int bufferSize);
extern int ATS_GetVersion(char* versionBuffer, int bufferSize);

int main() {
const char* uid = "your_email@example.com";
const char* workingDir = ".";
char activationResponse[1024] = {0};
if (ATS_Activate(uid, workingDir, activationResponse, sizeof(activationResponse)) != 0) {
printf("❌ Failed to activate license: %s\n", activationResponse);
return 1;
} else {
printf("✅ License activated: %s\n", activationResponse);
}

// Initialize the Go library
char initResponse[1024] = {0};
if (ATS_Init(uid, workingDir, initResponse, sizeof(initResponse)) != 0) {
printf("❌ Failed to initialize ATSCodeCheck: %s\n", initResponse);
return 1;
} else {
printf("✅ ATSCodeCheck Initialized: %s\n", initResponse);
}

// Get library version
char version[256] = {0};
if (ATS_GetVersion(version, sizeof(version)) == 0) {
printf("📦 Library Version: %s\n", version);
}

// Example Base64-encoded barcode (replace with real one for testing)
const char* base64Input = "REPLACE_WITH_VALID_BASE64_BARCODE";

// Create JSON request payload
const char* fieldList = "\"NUMPREP\"";
char jsonRequest[1024];
snprintf(jsonRequest, sizeof(jsonRequest),
"{ \"base64Barcode\": \"%s\", \"requestFields\": [%s] }",
base64Input, fieldList);

// Prepare response buffer
char response[2048] = {0};

// Run verification
int result = ATS_CheckCode(jsonRequest, response, sizeof(response));
if (result == 0) {
printf("✅ Response: %s\n", response);
} else {
printf("❌ ATS_CheckCode failed with code: %d\n", result);
}

return 0;
}