nfs-ganesha 1.4
|
00001 /* ---------------------------------------------------------------------------- 00002 * Copyright CEA/DAM/DIF (2007) 00003 * contributeur : Thomas LEIBOVICI thomas.leibovici@cea.fr 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 3 of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * --------------------------------------- 00020 */ 00021 #ifndef _CONFIG_PARSING_H 00022 #define _CONFIG_PARSING_H 00023 00024 #include <stdlib.h> 00025 #include <stdio.h> 00026 #include <sys/types.h> 00027 00028 /* opaque type */ 00029 typedef caddr_t config_file_t; 00030 typedef caddr_t config_item_t; 00031 00032 typedef enum 00033 { CONFIG_ITEM_BLOCK = 1, CONFIG_ITEM_VAR } config_item_type; 00034 00035 /* config_ParseFile: 00036 * Reads the content of a configuration file and 00037 * stores it in a memory structure. 00038 * \return NULL on error. 00039 */ 00040 config_file_t config_ParseFile(char *file_path); 00041 00042 /* If config_ParseFile returns a NULL pointer, 00043 * config_GetErrorMsg returns a detailled message 00044 * to indicate the reason for this error. 00045 */ 00046 char *config_GetErrorMsg(); 00047 00053 void config_Print(FILE * output, config_file_t config); 00054 00055 /* Free the memory structure that store the configuration. */ 00056 void config_Free(config_file_t config); 00057 00058 /* Indicates how many main blocks are defined into the config file. 00059 * \return A positive value if no error. 00060 * Else return a negative error code. 00061 */ 00062 int config_GetNbBlocks(config_file_t config); 00063 00064 /* retrieves a given block from the config file, from its index */ 00065 config_item_t config_GetBlockByIndex(config_file_t config, unsigned int block_no); 00066 00067 /* Return the name of a block */ 00068 char *config_GetBlockName(config_item_t block); 00069 00070 /* Indicates how many items are defines in a block */ 00071 int config_GetNbItems(config_item_t block); 00072 00073 /* Retrieves an item from a given block and the subitem index. */ 00074 config_item_t config_GetItemByIndex(config_item_t block, unsigned int item_no); 00075 00076 /* indicates which type of item it is */ 00077 config_item_type config_ItemType(config_item_t item); 00078 00079 /* Retrieves a key-value peer from a CONFIG_ITEM_VAR */ 00080 int config_GetKeyValue(config_item_t item, char **var_name, char **var_value); 00081 00082 /* Returns a block or variable with the specified name. This name can be "BLOCK::SUBBLOCK::SUBBLOCK" */ 00083 config_item_t config_FindItemByName(config_file_t config, const char *name); 00084 00085 /* Returns a block or variable with the specified name, and ensure it is unique. 00086 * The name can be "BLOCK::SUBBLOCK::SUBBLOCK" */ 00087 config_item_t config_FindItemByName_CheckUnique(config_file_t config, const char *name, int * is_unique); 00088 00089 /* Directly returns the value of the key with the specified name. 00090 * This name can be "BLOCK::SUBBLOCK::SUBBLOCK::VARNAME" 00091 */ 00092 char *config_FindKeyValueByName(config_file_t config, const char *key_name); 00093 00094 /* Returns a block or variable with the specified name from the given block" */ 00095 config_item_t config_GetItemByName(config_item_t block, const char *name); 00096 00097 /* Directly returns the value of the key with the specified name 00098 * relative to the given block. 00099 */ 00100 char *config_GetKeyValueByName(config_item_t block, const char *key_name); 00101 00102 #endif