@@ -238,69 +238,69 @@ int toml_parse_string(const char *toml_string, size_t length, toml_document_t *d |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /* Get string value from TOML document */ |
| 241 | | -int toml_get_string(const toml_document_t *doc, const char *section, |
| 241 | +int toml_get_string(const toml_document_t *doc, const char *section, |
| 242 | 242 | const char *key, char *value, size_t value_size) { |
| 243 | 243 | const toml_section_t *sec; |
| 244 | 244 | const toml_keyvalue_t *kv; |
| 245 | | - |
| 245 | + |
| 246 | 246 | if (!doc || !section || !key || !value || value_size == 0) { |
| 247 | 247 | set_error(ERR_INVALID_ARGS, "Invalid arguments to toml_get_string"); |
| 248 | 248 | return -1; |
| 249 | 249 | } |
| 250 | | - |
| 250 | + |
| 251 | 251 | if (!doc->is_valid) { |
| 252 | 252 | set_error(ERR_CONFIG_INVALID, "TOML document is not valid"); |
| 253 | 253 | return -1; |
| 254 | 254 | } |
| 255 | | - |
| 255 | + |
| 256 | 256 | sec = find_section((toml_document_t *)doc, section); |
| 257 | 257 | if (!sec) { |
| 258 | | - set_error(ERR_CONFIG_INVALID, "Section not found: %s", section); |
| 258 | + /* Section not found - return silently, caller handles missing data */ |
| 259 | 259 | return -1; |
| 260 | 260 | } |
| 261 | | - |
| 261 | + |
| 262 | 262 | kv = find_key((toml_section_t *)sec, key); |
| 263 | 263 | if (!kv || !kv->is_set) { |
| 264 | | - set_error(ERR_CONFIG_INVALID, "Key not found: %s.%s", section, key); |
| 264 | + /* Key not found - return silently, caller handles missing data */ |
| 265 | 265 | return -1; |
| 266 | 266 | } |
| 267 | | - |
| 267 | + |
| 268 | 268 | if (kv->type != TOML_TYPE_STRING) { |
| 269 | 269 | set_error(ERR_CONFIG_INVALID, "Key %s.%s is not a string", section, key); |
| 270 | 270 | return -1; |
| 271 | 271 | } |
| 272 | | - |
| 272 | + |
| 273 | 273 | /* Sanitize the value before returning */ |
| 274 | 274 | return toml_sanitize_string(kv->value, value, value_size); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /* Get integer value from TOML document */ |
| 278 | | -int toml_get_integer(const toml_document_t *doc, const char *section, |
| 278 | +int toml_get_integer(const toml_document_t *doc, const char *section, |
| 279 | 279 | const char *key, int *value) { |
| 280 | 280 | const toml_section_t *sec; |
| 281 | 281 | const toml_keyvalue_t *kv; |
| 282 | 282 | char *endptr; |
| 283 | 283 | long parsed_value; |
| 284 | | - |
| 284 | + |
| 285 | 285 | if (!doc || !section || !key || !value) { |
| 286 | 286 | set_error(ERR_INVALID_ARGS, "Invalid arguments to toml_get_integer"); |
| 287 | 287 | return -1; |
| 288 | 288 | } |
| 289 | | - |
| 289 | + |
| 290 | 290 | if (!doc->is_valid) { |
| 291 | 291 | set_error(ERR_CONFIG_INVALID, "TOML document is not valid"); |
| 292 | 292 | return -1; |
| 293 | 293 | } |
| 294 | | - |
| 294 | + |
| 295 | 295 | sec = find_section((toml_document_t *)doc, section); |
| 296 | 296 | if (!sec) { |
| 297 | | - set_error(ERR_CONFIG_INVALID, "Section not found: %s", section); |
| 297 | + /* Section not found - return silently, caller handles missing data */ |
| 298 | 298 | return -1; |
| 299 | 299 | } |
| 300 | | - |
| 300 | + |
| 301 | 301 | kv = find_key((toml_section_t *)sec, key); |
| 302 | 302 | if (!kv || !kv->is_set) { |
| 303 | | - set_error(ERR_CONFIG_INVALID, "Key not found: %s.%s", section, key); |
| 303 | + /* Key not found - return silently, caller handles missing data */ |
| 304 | 304 | return -1; |
| 305 | 305 | } |
| 306 | 306 | |
@@ -327,30 +327,30 @@ int toml_get_integer(const toml_document_t *doc, const char *section, |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /* Get boolean value from TOML document */ |
| 330 | | -int toml_get_boolean(const toml_document_t *doc, const char *section, |
| 330 | +int toml_get_boolean(const toml_document_t *doc, const char *section, |
| 331 | 331 | const char *key, bool *value) { |
| 332 | 332 | const toml_section_t *sec; |
| 333 | 333 | const toml_keyvalue_t *kv; |
| 334 | | - |
| 334 | + |
| 335 | 335 | if (!doc || !section || !key || !value) { |
| 336 | 336 | set_error(ERR_INVALID_ARGS, "Invalid arguments to toml_get_boolean"); |
| 337 | 337 | return -1; |
| 338 | 338 | } |
| 339 | | - |
| 339 | + |
| 340 | 340 | if (!doc->is_valid) { |
| 341 | 341 | set_error(ERR_CONFIG_INVALID, "TOML document is not valid"); |
| 342 | 342 | return -1; |
| 343 | 343 | } |
| 344 | | - |
| 344 | + |
| 345 | 345 | sec = find_section((toml_document_t *)doc, section); |
| 346 | 346 | if (!sec) { |
| 347 | | - set_error(ERR_CONFIG_INVALID, "Section not found: %s", section); |
| 347 | + /* Section not found - return silently, caller handles missing data */ |
| 348 | 348 | return -1; |
| 349 | 349 | } |
| 350 | | - |
| 350 | + |
| 351 | 351 | kv = find_key((toml_section_t *)sec, key); |
| 352 | 352 | if (!kv || !kv->is_set) { |
| 353 | | - set_error(ERR_CONFIG_INVALID, "Key not found: %s.%s", section, key); |
| 353 | + /* Key not found - return silently, caller handles missing data */ |
| 354 | 354 | return -1; |
| 355 | 355 | } |
| 356 | 356 | |