dmsc_config_get_string

Function dmsc_config_get_string 

Source
#[unsafe(no_mangle)]
pub extern "C" fn dmsc_config_get_string( config: *mut CDMSCConfig, key: *const c_char, ) -> *mut c_char
Expand description

Retrieves a string configuration value by key.

Looks up the specified key in the configuration hierarchy and returns the associated string value if found. The function performs type-safe retrieval with automatic conversion from compatible types.

§Parameters

  • config: Pointer to CDMSCConfig containing the configuration. Must not be NULL. If NULL, the function returns NULL.
  • key: Pointer to null-terminated C string specifying the configuration key. Keys use dot notation for hierarchical access (e.g., “database.connections.max”). Must not be NULL. If NULL, the function returns NULL.

§Returns

Pointer to newly allocated C string containing the configuration value on success. The caller is responsible for freeing the returned string using dmsc_string_free(). Returns NULL if:

  • config is NULL
  • key is NULL
  • Key does not exist in configuration
  • Value exists but is not a string type
  • String conversion fails (invalid UTF-8)

§Key Format

Configuration keys support hierarchical access:

  • Simple keys: “timeout”
  • Nested keys: “server.http.port”
  • Array indices: “servers.0.host”

§Example

char* database_url = dmsc_config_get_string(config, "database.url");
if (database_url != NULL) {
    printf("Database URL: %s\n", database_url);
    dmsc_string_free(database_url);
} else {
    printf("Database URL not configured\n");
}

§Memory Management

The returned string is newly allocated. Callers must release it using dmsc_string_free() to prevent memory leaks. Do not use free() directly.