C API Documentation

libSzConfigTool - C Shared Library Interface

Overview

The libSzConfigTool C shared library provides 121 C-compatible functions for manipulating Senzing configuration JSON documents. All operations are in-memory JSON transformations with proper memory management.

⚠️ Important: All strings returned by this library must be freed using SzConfigTool_free(). Failure to do so will cause memory leaks.

Library Files

Platform Shared Library Header File
macOS libSzConfigTool.dylib libSzConfigTool.h
Linux libSzConfigTool.so
Windows SzConfigTool.dll

Result Structure

typedef struct SzConfigTool_result {
    char *response;      // Modified config JSON (must free)
    int64_t returnCode;  // 0 = success, negative = error
} SzConfigTool_result;

Memory Management

SzConfigTool_free

Infrastructure
void SzConfigTool_free(char *ptr);

Description: Frees memory allocated by this library. Always call this on response pointers.

Error Handling

SzConfigTool_getLastError

Infrastructure
const char *SzConfigTool_getLastError(void);

Returns: Error message string (do not free), or NULL if no error.

SzConfigTool_getLastErrorCode

Infrastructure
int64_t SzConfigTool_getLastErrorCode(void);

Returns: Error code (0 = no error, negative = error).

SzConfigTool_clearLastError

Infrastructure
void SzConfigTool_clearLastError(void);

Description: Clears the last error state.

Example Usage

C Example

#include "libSzConfigTool.h"
#include <stdio.h>

int main(void) {
    const char *config = "{\"G2_CONFIG\":{\"CFG_DSRC\":[]}}";

    // Add data source
    struct SzConfigTool_result result =
        SzConfigTool_addDataSource(config, "MY_SOURCE");

    if (result.returnCode == 0) {
        printf("Success: %s\n", result.response);
        SzConfigTool_free(result.response);
    } else {
        fprintf(stderr, "Error: %s\n",
                SzConfigTool_getLastError());
    }

    return 0;
}

Rust Example (Using C Library)

use sz_configtool_lib::datasources::{add_data_source, AddDataSourceParams};

// Modern param struct API - only set what you need!
let config = add_data_source(&config, AddDataSourceParams {
    code: "MY_SOURCE",
    ..Default::default()  // All other fields = None
})?;

// Or with specific values
let config = add_data_source(&config, AddDataSourceParams {
    code: "CUSTOMERS",
    retention_level: Some("Remember"),
    reliability: Some(2),
    ..Default::default()  // conversational = None
})?;

Building and Linking

CMake

find_library(SZCONFIGTOOL_LIB NAMES SzConfigTool)
target_link_libraries(your_app PRIVATE ${SZCONFIGTOOL_LIB})

gcc/clang

gcc -o myapp myapp.c -L/path/to/lib -lSzConfigTool -I/path/to/include

Function Categories

Complete Documentation

For the complete list of all 121 functions with detailed signatures and examples, see: