1 /* 2 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 3 * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org> 4 * 5 * Version: MPL 1.1 6 * 7 * The contents of this file are subject to the Mozilla Public License Version 8 * 1.1 (the "License"); you may not use this file except in compliance with 9 * the License. You may obtain a copy of the License at 10 * http://www.mozilla.org/MPL/ 11 * 12 * Software distributed under the License is distributed on an "AS IS" basis, 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * for the specific language governing rights and limitations under the 15 * License. 16 * 17 * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 18 * 19 * The Initial Developer of the Original Code is 20 * Anthony Minessale II <anthm@freeswitch.org> 21 * Portions created by the Initial Developer are Copyright (C) 22 * the Initial Developer. All Rights Reserved. 23 * 24 * Contributor(s): 25 * 26 * Anthony Minessale II <anthm@freeswitch.org> 27 * 28 * 29 * switch_config.h -- Configuration File Parser 30 * 31 */ 32 /** 33 * @file switch_config.h 34 * @brief Basic Configuration File Parser 35 * @see config 36 */ 37 38 /** 39 * @defgroup config Config File Parser 40 * @ingroup core1 41 * This module implements a basic interface and file format parser it may be deprecated in favor of database entries 42 * or expanded to tie to external handlers in the future as necessary. 43 * <pre> 44 * 45 * EXAMPLE 46 * 47 * [category1] 48 * var1 => val1 49 * var2 => val2 50 * \# lines that begin with \# are comments 51 * \#var3 => val3 52 * </pre> 53 * @{ 54 */ 55 56 #ifndef SWITCH_CONFIG_H 57 #define SWITCH_CONFIG_H 58 59 #include <switch.h> 60 61 SWITCH_BEGIN_EXTERN_C typedef struct switch_config switch_config_t; 62 63 /*! \brief A simple file handle representing an open configuration file **/ 64 struct switch_config { 65 /*! FILE stream buffer to the opened file */ 66 FILE *file; 67 /*! path to the file */ 68 char path[512]; 69 /*! current category */ 70 char category[256]; 71 /*! current section */ 72 char section[256]; 73 /*! buffer of current line being read */ 74 char buf[1024]; 75 /*! current line number in file */ 76 int lineno; 77 /*! current category number in file */ 78 int catno; 79 /*! current section number in file */ 80 int sectno; 81 82 int lockto; 83 }; 84 85 /*! 86 \brief Open a configuration file 87 \param cfg (switch_config_t *) config handle to use 88 \param file_path path to the file 89 \return 1 (true) on success 0 (false) on failure 90 */ 91 SWITCH_DECLARE(int) switch_config_open_file(switch_config_t *cfg, char *file_path); 92 93 /*! 94 \brief Close a previously opened configuration file 95 \param cfg (switch_config_t *) config handle to use 96 */ 97 SWITCH_DECLARE(void) switch_config_close_file(switch_config_t *cfg); 98 99 /*! 100 \brief Retrieve next name/value pair from configuration file 101 \param cfg (switch_config_t *) config handle to use 102 \param var pointer to aim at the new variable name 103 \param val pointer to aim at the new value 104 */ 105 SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t *cfg, char **var, char **val); 106 107 SWITCH_END_EXTERN_C 108 /** @} */ 109 #endif 110 /* For Emacs: 111 * Local Variables: 112 * mode:c 113 * indent-tabs-mode:t 114 * tab-width:4 115 * c-basic-offset:4 116 * End: 117 * For VIM: 118 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: 119 */ 120