/usr/include/ini_configmod.h is in libini-config-dev 0.6.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | /*
INI LIBRARY
Interface that allows modification of the INI file.
Copyright (C) Dmitri Pal <dpal@redhat.com> 2014
INI Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
INI Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with INI Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INI_CONFIGMOD_H
#define INI_CONFIGMOD_H
/**
* @defgroup insflags Flags used in add_xxx_value functions
*
* These flags control the behavior of the add_xxx_value functions.
* Use these flags to specify how you want to process the key.
* Do you want the function to replace an existing key? Or may be you want to
* generate an error when function sees that there is a duplicate key?
* Or may be you do not want to check anything and just add the key
* to the section?
*
* Individual values provide more details about use.
*
* @{
*/
enum INI_VA {
/** @brief No check
*
* This is the default mode. Function will not perform
* any checks for duplicates and will just add a key.
*/
INI_VA_NOCHECK = 0,
/**
* @brief Update a specific value (best effort).
*
* Value of the index is used to determine which one of the duplicates
* needs to be updated. Index is 0-based. If the index is out of range
* the function will do best effort and return the last instance of the key.
* For example if you have five duplicates and you are searching for the tenth
* the function will find and return the fifth instance.
*/
INI_VA_MOD = 1,
/**
* @brief Update a specific value (with error).
*
* Value of the index is used to determine which one of the duplicates
* needs to be updated. Index is 0-based. If the value is not found or
* the index is out of range the function returns ENOENT.
* For example if you have five duplicates and you are searching for the tenth
* the error ENOENT will be returned.
*/
INI_VA_MOD_E = 2,
/**
* @brief Update or add if not found (best effort).
*
* Function will check for duplicates and would overwrite the specified
* key if found.
* Value of the index is used to determine which one of the duplicates
* needs to be updated. Index is 0-based. If the value is not found
* the new value will be added following other position related arguments.
* This option performs best effort search.
* For example if you have five duplicates and you are searching for the tenth
* the function will find and return fifth instance.
*/
INI_VA_MODADD = 3,
/**
* @brief Update or add if not found (with error).
*
* Function will check for duplicates and would overwrite the specified
* key if found.
* Value of the index is used to determine which one of the duplicates
* needs to be updated. Index is 0-based. If the value is not found
* the new value will be added following other position related arguments.
* This option performs an exact search.
* For example if you have five duplicates and you are searching for tenth
* the error ENOENT will be returned.
*/
INI_VA_MODADD_E = 4,
/** @brief Clean all duplicates.
*
* Find all instances of the specific key and remove them first.
* Then add the new key respecting the position related arguments.
*/
INI_VA_CLEAN = 5,
/** @brief Error if duplicate
*
* Return error EEXIST if an entry with the same key exists.
*/
INI_VA_DUPERROR = 6
};
/**
* @}
*/
/**
* @defgroup ini_mod API to create and modify configuration objects
*
* Functions in this section allow creation, modification
* and deletion of sections and keys.
*
* Explanation of some of the common arguments:
*
* @param[in] position Specifies the position a key or a section
* should be added to.\n\n
* Options include:
* - Last in the list
* - First in the list
* - N-th element of the list
* - Before a specific element of the list
* - After a specific element of the list
* - As a first duplicate of a specific element
* - As a last duplicate of a specific element
* - As an N-th duplicate of a specific element
* \n\n
* Duplicates can be sequential or not, so there
* are different constants that specify whether
* to count all duplicates or just the ones that
* go together.\n
* @param[in] other_xxx Used in conjunction with 'position' constant.
* In some cases it is convenient to add
* a section or key immediately before
* or after another section or key.
* While 'position' defines
* where it should be added, this parameter defines
* the section or key to relate to.
* @param[in] idx Index allows treating set of sections or keys
* as an array and add Nth section or key.
* @{
*
*/
/**
* @brief Function to add a section.
*
* Function creates a new section in the specified position.
* The position is relative to other sections. Duplicate sections
* are not allowed. In case a duplicate section is detected function
* will return error EEXIST.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to add.
* @param[in] comments Array of comments. Can be NULL, if no comment is
* needed for the section. It is expected that
* comment lines start with the correct comment
* symbol. Function does not check this.
* Use empty string to express an empty line.
* @param[in] count_comment Count of comments in the array. If 0,
* the array is expected to be NULL terminated
* and function will traverse array until its end.
* @param[in] position A constant that specifies the way the
* section should be added. For more information
* see "disposition constants" section of
* the collection (collection.h) interface.
* The value is used only in the add operation
* so see the explanation in the "insert" paragraph.
* Since duplicate sections are not allowed
* any constants that request addition of
* a duplicate will cause function
* to return an error.
* @param[in] other_section Used in conjunction with position constant.
* In some cases it is convenient to add
* a section that is immediately before
* or after another section. While position defines
* where it should be added, this parameter defines
* the section to relate to.
* @param[in] idx Index, allows treating set of sections as
* an array and add Nth section.
*
* @return 0 - Success.
* @return EEXIST - Section already exists.
* @return ENOSYS - Unknown position value.
* @return ENOMEM - No memory to add value.
* @return EINVAL - Invalid argument.
*/
int ini_config_add_section(struct ini_cfgobj *ini_config,
const char *section,
const char *comments[],
size_t count_comment,
int position,
const char *other_section,
int idx);
/**
* @brief Function to update a comment for a section.
*
* Function finds a section and updates or removes its comment.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to change the comment for.
* @param[in] comments Array of comments. Can be NULL if no comment is
* needed for the section. It is expected that
* comment lines start with the correct comment
* symbol. Function does not check this.
* Use empty string to express an empty line.
* @param[in] count_comment Count of comments in the array. If 0
* the array is expected to be NULL terminated
* and function will traverse array until its end.
*
* @return 0 - Success.
* @return ENOENT - Section is not found.
* @return ENOMEM - No memory to add value.
* @return EINVAL - Invalid argument.
*/
int ini_config_comment_section(struct ini_cfgobj *ini_config,
const char *section,
const char *comments[],
size_t count_comment);
/**
* @brief Function to rename a section.
*
* Function finds a section and renames it.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to find.
* @param[in] newname New section name.
*
* @return 0 - Success.
* @return ENOENT - Section is not found.
* @return ENOMEM - No memory to add value.
* @return EINVAL - Invalid argument.
*/
int ini_config_rename_section(struct ini_cfgobj *ini_config,
const char *section,
const char *newname);
/**
* @brief Function to delete a section by name.
*
* Function is a convenience wrapper around
* \ref ini_config_delete_section_by_position function.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to delete.
*
* @return 0 - Success.
* @return ENOENT - Section is not found.
* @return ENOMEM - No memory to add value.
* @return EINVAL - Invalid argument.
*/
int ini_config_delete_section_by_name(struct ini_cfgobj *ini_config,
const char *section);
/**
* @brief Function to delete a section by position or name.
*
* Function allows removing a specific section by its relative position
* in the list of sections or by its name.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] position A constant that specifies the way the
* section should be deleted. For more information
* see "disposition constants" section of
* the collection interface. The value is used
* only in delete operation so see the explanation
* in the "delete" paragraph.
* There can't be duplicate sections. However
* function respects all of the listed constants.
* To find and delete a particular section
* one can use COL_DSP_FIRSTDUP constant.
* One should just expect that there is only
* one instance of every section if any.
* @param[in] section Used in conjunction with position constant.
* In some cases it is convenient to add
* a section immediately before
* or after another value. While position defines
* where it should be added, this parameter defines
* the section to relate to.
* @param[in] idx Index of the position.
* For example one can specify
* that the third section should be deleted.
*
* @return 0 - Success.
* @return ENOENT - Section is not found.
* @return ENOMEM - No memory to add value.
* @return EINVAL - Invalid argument.
*/
int ini_config_delete_section_by_position(struct ini_cfgobj *ini_config,
int position,
const char *section,
int idx);
/**
* @brief Function to a add string value to a particular section.
*
* Depending on the flags function adds, or deletes and adds, or just modifies
* the configuration value stored in the configuration object.
*
* \b NOTE: all other ini_config_add_xxx_value functions are implemented
* as wrappers around this function so they have the same
* behavior and logic.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to modify.
* @param[in] key Key of the value to add or modify.
* @param[in] value String that represents the value.
* @param[in] comments Array of comments. Can be NULL if no comment is
* needed for the section. It is expected that
* comment lines start with the correct comment
* symbol. Function does not check this.
* Use empty string to express an empty line.
* @param[in] count_comment Count of comments in the array. If 0,
* the array is expected to be NULL terminated
* and function will traverse array until its end.
* @param[in] border The boundary the value should be wrapped at.
* The usual value is 80 characters.
* @param[in] position A constant that specifies the way the
* value should be added. For more information
* see "disposition constants" section of
* the collection interface. The value is used
* only in add operation so see the explanation
* in the "insert" paragraph.
* @param[in] other_key Used in conjunction with 'position' constant.
* In some cases it is convenient to add
* a value that should be placed immediately before
* or after another value. While position defines
* where it should be added, this parameter defines
* the key to relate to.
* @param[in] idx Index in the whole section or among
* duplicates. For example one can specify
* that the value should be added as a third
* duplicate. This is convenient if INI file allows
* duplicate keys.
* @param[in] flags These constants define the main behavior of
* the function. The function can thus be used
* to build configuration object from scratch
* (in this case no checks would be needed),
* to modify a specific key which can be identified
* by index among duplicate keys in the same
* section. For more information see \ref insflags.
*
* @return 0 - Success.
* @return EEXIST - The value already exists.
* @return ENOENT - The value not found.
* @return ENOSYS - Unknown flag or position value.
* @return ENOMEM - No memory to add value.
* @return EINVAL - Invalid argument.
*/
int ini_config_add_str_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
const char *value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an integer value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an integer argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_int_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
int value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a long value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a long integer argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_long_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
long value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an unsigned long value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an unsigned long integer argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_ulong_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
unsigned long value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an unsigned value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an unsigned argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_unsigned_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
unsigned value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an int32 value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an int32 argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_int32_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
int32_t value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an uint32 value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an uint32 argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_uint32_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
uint32_t value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an int64 value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an int64 argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_int64_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
int64_t value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add an uint64 value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* an uint64 argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_uint64_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
uint64_t value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a double value to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a double argument for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_double_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
double value,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a binary value to a particular section.
*
* Binary values are represented by a HEX string where two HEX digits
* represent one byte of the source data. The value is surrounded
* by a pair of single quotes.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a void argument for the value input. The length of the data is specified by
* by the value_len argument.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_bin_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
void *value,
size_t value_len,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a value that consists of an array of constant strings
* to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a string array argument and a count for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_const_str_arr_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
const char *value_str_arr[],
size_t count_str,
char sep,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a value that consists of an array of strings
* to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a string array argument and a count for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_str_arr_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
char *value_str_arr[],
size_t count_str,
char sep,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a value that consists of an array of integers
* to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a integer array argument and a count for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_int_arr_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
int *value_int_arr,
size_t count_int,
char sep,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a value that consists of an array of long integers
* to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a long integer array argument and a count for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_long_arr_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
long *value_long_arr,
size_t count_long,
char sep,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to add a value that consists of an array of doubles
* to a particular section.
*
* Function is similar to \ref ini_config_add_str_value except it uses
* a double array argument and a count for the value input.
*
* For logic, behavior and return values see \ref ini_config_add_str_value.
*/
int ini_config_add_double_arr_value(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
double *value_double_arr,
size_t count_double,
char sep,
const char *comments[],
size_t count_comment,
int border,
int position,
const char *other_key,
int idx,
enum INI_VA flags);
/**
* @brief Function to delete a value.
*
* Function deletes a value specified either by key or by position.
* For example the caller can remove first or last key of the section as well
* as first, last or specific instance of a specific key. If key is searched
* by index and index is out of range the function would return ENOENT
* indicating that specifically requested key is not found.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to remove the key from.
* @param[in] position A constant that specifies the way the
* key should be removed. For more information
* see "disposition constants" section of
* the collection interface, and specifically
* the "delete" paragraph.
* @param[in] key Used in conjunction with 'position' constant.
* Depending on the value of the position
* argument the key argument can specify
* the key to delete or the key that the delete
* operation should be relative to.
* @param[in] idx Index of duplicates. For example one can specify
* that he wants to delete the third duplicate
* of a specific key. If there are less duplicates,
* i.e. the index is out of range, the function
* will return ENOENT.
*
* @return 0 - Value was removed.
* @return ENOENT - The value not found.
*/
int ini_config_delete_value(struct ini_cfgobj *ini_config,
const char *section,
int position,
const char *key,
int idx);
/**
* @brief Function to update a comment.
*
* Function can be used to find and modify a comment for a specific
* key in a specific section.
*
* @param[in] ini_config Configuration object to modify.
* @param[in] section Name of the section to find the key.
* @param[in] key The key to find.
* @param[in] comments The array of comments. Can be NULL. If NULL,
* the existing comment will be removed if any.
* The comment lines are expected to start with a
* standard comment symbol. The function does not
check this.
* Use empty string to express an empty line.
* @param[in] count_comment Count of comments. If 0 the comment is
* constructed using array of strings above.
* It is expected to be NULL terminated.
* @param[in] idx Index of duplicates. For example one can specify
* that he wants to find the third duplicate
* of a specific key. If there are less duplicates,
* i.e. the index is out of range, the function
* will return ENOENT.
*
* @return 0 - Value was removed.
* @return ENOENT - The value not found.
*/
int ini_config_update_comment(struct ini_cfgobj *ini_config,
const char *section,
const char *key,
const char *comments[],
size_t count_comment,
int idx);
/**
* @}
*/
#endif
|