Go to the source code of this file.
Classes | |
| struct | configEntry |
Macros | |
| #define | NO_SECTION 0 |
| #define | FOUND_SECTION 10 |
| #define | ERROR_STR 1001 |
| #define | ERROR_MAX_LEN 2 |
| #define | NO_ERROR 0 |
| #define | ERROR_DELIMITER_NOT_FOUND 40 |
| #define | ST_INIT 0 |
| #define | ST_FOUND_LEFT_DELIMITER 1 |
| #define | ST_FOUND_RIGHT_DELIMITER 2 |
| #define | ST_ERROR_NOT_FOUND_RIGHT_DELIMITER 3 |
| #define | ST_ERROR_NOT_FOUND_LEFT_DELIMITER 4 |
| #define | ST_FOUND_SECTION 5 |
| #define | ST_SKIP_READ 6 |
| #define | ST_FINISH 20 |
| #define | ST_ERROR_GETSTRATPOS 30 |
| #define | MAX_LEN_SECTIONNAME 128 |
| #define | ERR_PARSECONFIG_UNKNOWN 201 |
Functions | |
| int | loadConfig (char *file, char **str_entry, char **host, int *intervall, int size) |
| int | checkSection (char *str, char delimiterLeft, char delimiterRight, char **sectionName) |
| Here we check if the given string contains a section for example [SECTIONName] here delimiterLeft is [ and delimiterRight is ] if a section is found, the section name will be written to sectionName. | |
| int | getStrAtPos (char *str, int fromPos, int toPos, char **name, int sizeName) |
| int | getNameValuePair (char *str, char leftDelimiterPos, char rightDelimiterPos, char **name, char **value, int sizeName, int sizeValue) |
| int | parseConfig (char *buffer, struct configEntry **entry, int configSize, int *returnedCount) |
| int checkSection | ( | char * | str, |
| char | delimiterLeft, | ||
| char | delimiterRight, | ||
| char ** | sectionName ) |
Here we check if the given string contains a section for example [SECTIONName] here delimiterLeft is [ and delimiterRight is ] if a section is found, the section name will be written to sectionName.
Input:
| char | **str: the string to check |
| char | delimiterLeft: the left delimiter to check for |
| char | delimiterRight: the right delimiter to check for |
Output:
| char | **sectionName: if found the section Name of the section |
Return:
| int | status_code: one of the following values: |
| int getNameValuePair | ( | char * | str, |
| char | leftDelimiterPos, | ||
| char | rightDelimiterPos, | ||
| char ** | name, | ||
| char ** | value, | ||
| int | sizeName, | ||
| int | sizeValue ) |
Here we get a "pair" of data, parsed from *str, witch consists of a keyname and a keyvalue. These are written to the pointers at char **name and char **value. These pair can be in the form of: ex1: NAME=VALUE ^ ^ | Here we have no delimiter this means rightDelimiterPos must be NULL This is the left delimiter ex2: name(value) ^ ^ | This is the rightDelimiterPos and must be ')' This is leftDelimiterPos which must be '('
Input: char *str: the line in the form of a string where a key value pair is stored char leftDelimiterPos: the left delimiter for example '=' char rightDelimiterPos: the right delimiter can be NULL in most cases, if NULL we assume that there is only one delimiter, which is in this case the leftDelimiterPos Output: char **name: The address where we store the name of the Key char **value: The address where we store the key value int sizeName: for size checking against memory allocated at **name int sizeValue: for size checking against memory allocated at **value
Return: will return NO_ERROR (0) if successfull. If not it will return the error of the subroutine
| int getStrAtPos | ( | char * | str, |
| int | fromPos, | ||
| int | toPos, | ||
| char ** | name, | ||
| int | sizeName ) |
Here we get / cut from fromPos to toPos and write it to an address
Input: char *str: the string to cut int fromPos: from which position we want to copy, the pos is included and zero indexed int toPos: to which position we want to copy, the pos is included and zero indexed Output: char **name: here we will write the section name to Input: int sizeName: the size of the user allocated buffer at **name
| int loadConfig | ( | char * | file, |
| char ** | str_entry, | ||
| char ** | host, | ||
| int * | intervall, | ||
| int | size ) |
| int parseConfig | ( | char * | originalBuffer, |
| struct configEntry ** | entry, | ||
| int | configSizeCount, | ||
| int * | returnedCount ) |
Given a null terminated buffer of content(ex. from a file) an parse it with a default syntax of: Sections -> [SECTIONNAME] name / value -> name=value
Input: char *originalBuffer: the buffer which holds the string for parsing. struct configEntry **entry: a user allocated buffer to which we write the parsed config data. int configSizeCount: the user allocated size of **entry. Output: int *returnedCount: to this variable the function writes the count of struct, which will be required to store all alavaible data.
Note: The funtion returns the maximum allowed data structures, determined by configSizeCount. All data which exceeds will be dropped. To get the whole data we run the funtion a second time with the realloced configSizeCount in the size of [returnedCount] structures.