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