root/src/include/private/ftdm_config.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2007, Anthony Minessale II
   3  * All rights reserved.
   4  * 
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 
   9  * * Redistributions of source code must retain the above copyright
  10  * notice, this list of conditions and the following disclaimer.
  11  * 
  12  * * Redistributions in binary form must reproduce the above copyright
  13  * notice, this list of conditions and the following disclaimer in the
  14  * documentation and/or other materials provided with the distribution.
  15  * 
  16  * * Neither the name of the original author; nor the names of any contributors
  17  * may be used to endorse or promote products derived from this software
  18  * without specific prior written permission.
  19  * 
  20  * 
  21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 
  34 /**
  35  * @defgroup config Config File Parser
  36  * @ingroup config
  37  * This module implements a basic interface and file format parser
  38  * 
  39  * <pre>
  40  *
  41  * EXAMPLE 
  42  * 
  43  * [category1]
  44  * var1 => val1
  45  * var2 => val2
  46  * \# lines that begin with \# are comments
  47  * \#var3 => val3
  48  * </pre>
  49  * @{
  50  */
  51 
  52 #ifndef FTDM_CONFIG_H
  53 #define FTDM_CONFIG_H
  54 
  55 #include "freetdm.h"
  56 #define FTDM_URL_SEPARATOR "://"
  57 
  58 
  59 #ifdef WIN32
  60 #define FTDM_PATH_SEPARATOR "\\"
  61 #ifndef FTDM_CONFIG_DIR
  62 #define FTDM_CONFIG_DIR "c:\\freetdm"
  63 #endif
  64 #define ftdm_is_file_path(file) (*(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))
  65 #else
  66 #define FTDM_PATH_SEPARATOR "/"
  67 #ifndef FTDM_CONFIG_DIR
  68 #define FTDM_CONFIG_DIR "/etc/freetdm"
  69 #endif
  70 #define ftdm_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
  71 #endif
  72 
  73 #ifdef __cplusplus
  74 extern "C" {
  75 #endif
  76 
  77 typedef struct ftdm_config ftdm_config_t;
  78 
  79 /*! \brief A simple file handle representing an open configuration file **/
  80 struct ftdm_config {
  81         /*! FILE stream buffer to the opened file */
  82         FILE *file;
  83         /*! path to the file */
  84         char path[512];
  85         /*! current category */
  86         char category[256];
  87         /*! current section */
  88         char section[256];
  89         /*! buffer of current line being read */
  90         char buf[1024];
  91         /*! current line number in file */
  92         int lineno;
  93         /*! current category number in file */
  94         int catno;
  95         /*! current section number in file */
  96         int sectno;
  97 
  98         int lockto;
  99 };
 100 
 101 /*!
 102   \brief Open a configuration file
 103   \param cfg (ftdm_config_t *) config handle to use
 104   \param file_path path to the file
 105   \return 1 (true) on success 0 (false) on failure
 106 */
 107 int ftdm_config_open_file(ftdm_config_t * cfg, const char *file_path);
 108 
 109 /*!
 110   \brief Close a previously opened configuration file
 111   \param cfg (ftdm_config_t *) config handle to use
 112 */
 113 void ftdm_config_close_file(ftdm_config_t * cfg);
 114 
 115 /*!
 116   \brief Retrieve next name/value pair from configuration file
 117   \param cfg (ftdm_config_t *) config handle to use
 118   \param var pointer to aim at the new variable name
 119   \param val pointer to aim at the new value
 120 */
 121 int ftdm_config_next_pair(ftdm_config_t * cfg, char **var, char **val);
 122 
 123 /*!
 124   \brief Retrieve the CAS bits from a configuration string value
 125   \param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx)
 126   \param outbits pointer to aim at the CAS bits
 127 */
 128 FT_DECLARE (int) ftdm_config_get_cas_bits(char *strvalue, unsigned char *outbits);
 129 
 130 #ifdef __cplusplus
 131 }
 132 #endif
 133 
 134 /** @} */
 135 #endif
 136 /* For Emacs:
 137  * Local Variables:
 138  * mode:c
 139  * indent-tabs-mode:t
 140  * tab-width:4
 141  * c-basic-offset:4
 142  * End:
 143  * For VIM:
 144  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 145  */

/* [<][>][^][v][top][bottom][index][help] */