Venkateshwarlu Domakonda | 1c2c435 | 2014-05-26 14:35:12 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 3 | |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer in the |
| 10 | * documentation and/or other materials provided with the distribution. |
| 11 | * * Neither the name of The Linux Foundation nor |
| 12 | * the names of its contributors may be used to endorse or promote |
| 13 | * products derived from this software without specific prior written |
| 14 | * permission. |
| 15 | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | #ifndef __CONF_FILE_PARSER_H__ |
| 31 | #define __CONF_FILE_PARSER_H__ |
| 32 | |
| 33 | #define MAX_LINE_LEN 512 |
| 34 | #define MAX_UNIQ_KEYS 5 |
| 35 | #define MAX_UNIQ_GRPS 10 |
| 36 | #define TRUE 1 |
| 37 | #define FALSE 0 |
| 38 | |
| 39 | struct key_value_pair_list |
| 40 | { |
| 41 | char *key; |
| 42 | char *value; |
| 43 | key_value_pair_list *next; |
| 44 | }; |
| 45 | |
| 46 | struct group |
| 47 | { |
| 48 | char *grp_name; |
| 49 | unsigned int num_of_keys; |
| 50 | unsigned int keys_hash_size; |
| 51 | key_value_pair_list **list; |
| 52 | group *grp_next; |
| 53 | }; |
| 54 | |
| 55 | struct group_table |
| 56 | { |
| 57 | unsigned int grps_hash_size; |
| 58 | unsigned int num_of_grps; |
| 59 | group **grps_hash; |
| 60 | }; |
| 61 | |
| 62 | enum CONF_PARSE_ERRO_CODE |
| 63 | { |
| 64 | PARSE_SUCCESS, |
| 65 | INVALID_FILE_NAME, |
| 66 | FILE_OPEN_FAILED, |
| 67 | FILE_NOT_PROPER, |
| 68 | MEMORY_ALLOC_FAILED, |
| 69 | PARSE_FAILED, |
| 70 | }; |
| 71 | |
| 72 | unsigned int get_hash_code(const char *str); |
| 73 | group_table *get_key_file(); |
| 74 | void free_strs(char **str_array); |
| 75 | void free_key_file(group_table *key_file); |
| 76 | char parse_load_file(group_table *key_file, const char *file); |
| 77 | char **get_grps(const group_table *key_file); |
| 78 | char **get_keys(const group_table *key_file, const char *grp); |
| 79 | char *get_value(const group_table *key_file, const char *grp, |
| 80 | const char *key); |
| 81 | |
| 82 | #endif //__CONF_FILE_PARSER_H__ |