| /* |
| * Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are met: |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * * Neither the name of The Linux Foundation nor |
| * the names of its contributors may be used to endorse or promote |
| * products derived from this software without specific prior written |
| * permission. |
| |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| |
| #ifndef __CONF_FILE_PARSER_H__ |
| #define __CONF_FILE_PARSER_H__ |
| |
| #define MAX_LINE_LEN 512 |
| #define MAX_UNIQ_KEYS 5 |
| #define MAX_UNIQ_GRPS 10 |
| #define TRUE 1 |
| #define FALSE 0 |
| |
| struct key_value_pair_list |
| { |
| char *key; |
| char *value; |
| key_value_pair_list *next; |
| }; |
| |
| struct group |
| { |
| char *grp_name; |
| unsigned int num_of_keys; |
| unsigned int keys_hash_size; |
| key_value_pair_list **list; |
| group *grp_next; |
| }; |
| |
| struct group_table |
| { |
| unsigned int grps_hash_size; |
| unsigned int num_of_grps; |
| group **grps_hash; |
| }; |
| |
| enum CONF_PARSE_ERRO_CODE |
| { |
| PARSE_SUCCESS, |
| INVALID_FILE_NAME, |
| FILE_OPEN_FAILED, |
| FILE_NOT_PROPER, |
| MEMORY_ALLOC_FAILED, |
| PARSE_FAILED, |
| }; |
| |
| unsigned int get_hash_code(const char *str); |
| group_table *get_key_file(); |
| void free_strs(char **str_array); |
| void free_key_file(group_table *key_file); |
| char parse_load_file(group_table *key_file, const char *file); |
| char **get_grps(const group_table *key_file); |
| char **get_keys(const group_table *key_file, const char *grp); |
| char *get_value(const group_table *key_file, const char *grp, |
| const char *key); |
| |
| #endif //__CONF_FILE_PARSER_H__ |