00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2005, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * \brief Configuration File Parser 00021 */ 00022 00023 #ifndef _ASTERISK_CONFIG_H 00024 #define _ASTERISK_CONFIG_H 00025 00026 #if defined(__cplusplus) || defined(c_plusplus) 00027 extern "C" { 00028 #endif 00029 00030 #include "asterisk/utils.h" 00031 #include "asterisk/inline_api.h" 00032 00033 struct ast_config; 00034 00035 struct ast_category; 00036 00037 /*! Options for ast_config_load() 00038 */ 00039 enum { 00040 /*! Load the configuration, including comments */ 00041 CONFIG_FLAG_WITHCOMMENTS = (1 << 0), 00042 /*! On a reload, give us a -1 if the file hasn't changed. */ 00043 CONFIG_FLAG_FILEUNCHANGED = (1 << 1), 00044 /*! Don't attempt to cache mtime on this config file. */ 00045 CONFIG_FLAG_NOCACHE = (1 << 2), 00046 }; 00047 00048 #define CONFIG_STATUS_FILEMISSING (void *)0 00049 #define CONFIG_STATUS_FILEUNCHANGED (void *)-1 00050 #define CONFIG_STATUS_FILEINVALID (void *)-2 00051 00052 /*! 00053 * \brief Types used in ast_realtime_require_field 00054 */ 00055 typedef enum { 00056 RQ_INTEGER1, 00057 RQ_UINTEGER1, 00058 RQ_INTEGER2, 00059 RQ_UINTEGER2, 00060 RQ_INTEGER3, 00061 RQ_UINTEGER3, 00062 RQ_INTEGER4, 00063 RQ_UINTEGER4, 00064 RQ_INTEGER8, 00065 RQ_UINTEGER8, 00066 RQ_CHAR, 00067 RQ_FLOAT, 00068 RQ_DATE, 00069 RQ_DATETIME, 00070 } require_type; 00071 00072 /*! \brief Structure for variables, used for configurations and for channel variables 00073 */ 00074 struct ast_variable { 00075 const char *name; 00076 const char *value; 00077 struct ast_variable *next; 00078 00079 char *file; 00080 00081 int lineno; 00082 int object; /*!< 0 for variable, 1 for object */ 00083 int blanklines; /*!< Number of blanklines following entry */ 00084 struct ast_comment *precomments; 00085 struct ast_comment *sameline; 00086 struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */ 00087 char stuff[0]; 00088 }; 00089 00090 typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked); 00091 typedef struct ast_variable *realtime_var_get(const char *database, const char *table, va_list ap); 00092 typedef struct ast_config *realtime_multi_get(const char *database, const char *table, va_list ap); 00093 typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap); 00094 typedef int realtime_update2(const char *database, const char *table, va_list ap); 00095 typedef int realtime_store(const char *database, const char *table, va_list ap); 00096 typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap); 00097 00098 /*! 00099 * \brief Function pointer called to ensure database schema is properly configured for realtime use 00100 * \since 1.6.1 00101 */ 00102 typedef int realtime_require(const char *database, const char *table, va_list ap); 00103 00104 /*! 00105 * \brief Function pointer called to clear the database cache and free resources used for such 00106 * \since 1.6.1 00107 */ 00108 typedef int realtime_unload(const char *database, const char *table); 00109 00110 /*! \brief Configuration engine structure, used to define realtime drivers */ 00111 struct ast_config_engine { 00112 char *name; 00113 config_load_func *load_func; 00114 realtime_var_get *realtime_func; 00115 realtime_multi_get *realtime_multi_func; 00116 realtime_update *update_func; 00117 realtime_update2 *update2_func; 00118 realtime_store *store_func; 00119 realtime_destroy *destroy_func; 00120 realtime_require *require_func; 00121 realtime_unload *unload_func; 00122 struct ast_config_engine *next; 00123 }; 00124 00125 /*! \brief Load a config file 00126 * \param filename path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR 00127 * Create a config structure from a given configuration file. 00128 * \param who_asked The module which is making this request. 00129 * \param flags Optional flags: 00130 * CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact; 00131 * CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or 00132 * CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files). 00133 * 00134 * \return an ast_config data structure on success 00135 * \retval NULL on error 00136 */ 00137 struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags); 00138 00139 #define ast_config_load(filename, flags) ast_config_load2(filename, AST_MODULE, flags) 00140 00141 /*! \brief Destroys a config 00142 * \param config pointer to config data structure 00143 * Free memory associated with a given config 00144 * 00145 */ 00146 void ast_config_destroy(struct ast_config *config); 00147 00148 /*! \brief returns the root ast_variable of a config 00149 * \param config pointer to an ast_config data structure 00150 * \param cat name of the category for which you want the root 00151 * 00152 * Returns the category specified 00153 */ 00154 struct ast_variable *ast_category_root(struct ast_config *config, char *cat); 00155 00156 /*! \brief Goes through categories 00157 * \param config Which config structure you wish to "browse" 00158 * \param prev A pointer to a previous category. 00159 * This function is kind of non-intuitive in it's use. To begin, one passes NULL as the second argument. It will return a pointer to the string of the first category in the file. From here on after, one must then pass the previous usage's return value as the second pointer, and it will return a pointer to the category name afterwards. 00160 * 00161 * \retval a category on success 00162 * \retval NULL on failure/no-more-categories 00163 */ 00164 char *ast_category_browse(struct ast_config *config, const char *prev); 00165 00166 /*! 00167 * \brief Goes through variables 00168 * Somewhat similar in intent as the ast_category_browse. 00169 * List variables of config file category 00170 * 00171 * \retval ast_variable list on success 00172 * \retval NULL on failure 00173 */ 00174 struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category); 00175 00176 /*! 00177 * \brief given a pointer to a category, return the root variable. 00178 * This is equivalent to ast_variable_browse(), but more efficient if we 00179 * already have the struct ast_category * (e.g. from ast_category_get()) 00180 */ 00181 struct ast_variable *ast_category_first(struct ast_category *cat); 00182 00183 /*! 00184 * \brief Gets a variable 00185 * \param config which (opened) config to use 00186 * \param category category under which the variable lies 00187 * \param variable which variable you wish to get the data for 00188 * Goes through a given config file in the given category and searches for the given variable 00189 * 00190 * \retval The variable value on success 00191 * \retval NULL if unable to find it. 00192 */ 00193 const char *ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable); 00194 00195 /*! 00196 * \brief Retrieve a category if it exists 00197 * \param config which config to use 00198 * \param category_name name of the category you're looking for 00199 * This will search through the categories within a given config file for a match. 00200 * 00201 * \retval pointer to category if found 00202 * \retval NULL if not. 00203 */ 00204 struct ast_category *ast_category_get(const struct ast_config *config, const char *category_name); 00205 00206 /*! 00207 * \brief Check for category duplicates 00208 * \param config which config to use 00209 * \param category_name name of the category you're looking for 00210 * This will search through the categories within a given config file for a match. 00211 * 00212 * \return non-zero if found 00213 */ 00214 int ast_category_exist(const struct ast_config *config, const char *category_name); 00215 00216 /*! 00217 * \brief Retrieve realtime configuration 00218 * \param family which family/config to lookup 00219 * This will use builtin configuration backends to look up a particular 00220 * entity in realtime and return a variable list of its parameters. Note 00221 * that unlike the variables in ast_config, the resulting list of variables 00222 * MUST be freed with ast_variables_destroy() as there is no container. 00223 * 00224 * The difference between these two calls is that ast_load_realtime excludes 00225 * fields whose values are NULL, while ast_load_realtime_all loads all columns. 00226 * 00227 * Note that you should use the constant SENTINEL to terminate arguments, in 00228 * order to preserve cross-platform compatibility. 00229 */ 00230 struct ast_variable *ast_load_realtime(const char *family, ...) attribute_sentinel; 00231 struct ast_variable *ast_load_realtime_all(const char *family, ...) attribute_sentinel; 00232 00233 /*! 00234 * \brief Release any resources cached for a realtime family 00235 * \param family which family/config to destroy 00236 * Various backends may cache attributes about a realtime data storage 00237 * facility; on reload, a front end resource may request to purge that cache. 00238 * \retval 0 If any cache was purged 00239 * \retval -1 If no cache was found 00240 * \since 1.6.1 00241 */ 00242 int ast_unload_realtime(const char *family); 00243 00244 /*! 00245 * \brief Inform realtime what fields that may be stored 00246 * \param family which family/config is referenced 00247 * This will inform builtin configuration backends that particular fields 00248 * may be updated during the use of that configuration section. This is 00249 * mainly to be used during startup routines, to ensure that various fields 00250 * exist in the backend. The backends may take various actions, such as 00251 * creating new fields in the data store or warning the administrator that 00252 * new fields may need to be created, in order to ensure proper function. 00253 * 00254 * The arguments are specified in groups of 3: column name, column type, 00255 * and column size. The column types are specified as integer constants, 00256 * defined by the enum require_type. Note that the size is specified as 00257 * the number of equivalent character fields that a field may take up, even 00258 * if a field is otherwise specified as an integer type. This is due to 00259 * the fact that some fields have historically been specified as character 00260 * types, even if they contained integer values. 00261 * 00262 * A family should always specify its fields to the minimum necessary 00263 * requirements to fulfill all possible values (within reason; for example, 00264 * a timeout value may reasonably be specified as an INTEGER2, with size 5. 00265 * Even though values above 32767 seconds are possible, they are unlikely 00266 * to be useful, and we should not complain about that size). 00267 * 00268 * \retval 0 Required fields met specified standards 00269 * \retval -1 One or more fields was missing or insufficient 00270 * 00271 * Note that you should use the constant SENTINEL to terminate arguments, in 00272 * order to preserve cross-platform compatibility. 00273 * 00274 * \since 1.6.1 00275 */ 00276 int ast_realtime_require_field(const char *family, ...) attribute_sentinel; 00277 00278 /*! 00279 * \brief Retrieve realtime configuration 00280 * \param family which family/config to lookup 00281 * 00282 * This will use builtin configuration backends to look up a particular 00283 * entity in realtime and return a variable list of its parameters. Unlike 00284 * the ast_load_realtime, this function can return more than one entry and 00285 * is thus stored inside a traditional ast_config structure rather than 00286 * just returning a linked list of variables. 00287 * 00288 * Note that you should use the constant SENTINEL to terminate arguments, in 00289 * order to preserve cross-platform compatibility. 00290 */ 00291 struct ast_config *ast_load_realtime_multientry(const char *family, ...) attribute_sentinel; 00292 00293 /*! 00294 * \brief Update realtime configuration 00295 * \param family which family/config to be updated 00296 * \param keyfield which field to use as the key 00297 * \param lookup which value to look for in the key field to match the entry. 00298 * This function is used to update a parameter in realtime configuration space. 00299 * \return Number of rows affected, or -1 on error. 00300 * 00301 * Note that you should use the constant SENTINEL to terminate arguments, in 00302 * order to preserve cross-platform compatibility. 00303 */ 00304 int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel; 00305 00306 /*! 00307 * \brief Update realtime configuration 00308 * \param family which family/config to be updated 00309 * This function is used to update a parameter in realtime configuration space. 00310 * It includes the ability to lookup a row based upon multiple key criteria. 00311 * As a result, this function includes two sentinel values, one to terminate 00312 * lookup values and the other to terminate the listing of fields to update. 00313 * \return Number of rows affected, or -1 on error. 00314 * 00315 * Note that you should use the constant SENTINEL to terminate arguments, in 00316 * order to preserve cross-platform compatibility. 00317 */ 00318 int ast_update2_realtime(const char *family, ...) attribute_sentinel; 00319 00320 /*! 00321 * \brief Create realtime configuration 00322 * \param family which family/config to be created 00323 * This function is used to create a parameter in realtime configuration space. 00324 * \return Number of rows affected, or -1 on error. 00325 * On the MySQL engine only, for reasons of backwards compatibility, the return 00326 * value is the insert ID. This value is nonportable and may be changed in a 00327 * future version to match the other engines. 00328 * 00329 * Note that you should use the constant SENTINEL to terminate arguments, in 00330 * order to preserve cross-platform compatibility. 00331 */ 00332 int ast_store_realtime(const char *family, ...) attribute_sentinel; 00333 00334 /*! 00335 * \brief Destroy realtime configuration 00336 * \param family which family/config to be destroyed 00337 * \param keyfield which field to use as the key 00338 * \param lookup which value to look for in the key field to match the entry. 00339 * This function is used to destroy an entry in realtime configuration space. 00340 * Additional params are used as keys. 00341 * \return Number of rows affected, or -1 on error. 00342 * 00343 * Note that you should use the constant SENTINEL to terminate arguments, in 00344 * order to preserve cross-platform compatibility. 00345 */ 00346 int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel; 00347 00348 /*! 00349 * \brief Check if realtime engine is configured for family 00350 * \param family which family/config to be checked 00351 * \return 1 if family is configured in realtime and engine exists 00352 */ 00353 int ast_check_realtime(const char *family); 00354 00355 /*! \brief Check if there's any realtime engines loaded */ 00356 int ast_realtime_enabled(void); 00357 00358 /*! \brief Free variable list 00359 * \param var the linked list of variables to free 00360 * This function frees a list of variables. 00361 */ 00362 void ast_variables_destroy(struct ast_variable *var); 00363 00364 /*! \brief Register config engine 00365 * \retval 1 Always 00366 */ 00367 int ast_config_engine_register(struct ast_config_engine *newconfig); 00368 00369 /*! \brief Deregister config engine 00370 * \retval 0 Always 00371 */ 00372 int ast_config_engine_deregister(struct ast_config_engine *del); 00373 00374 /*!\brief Exposed initialization method for core process 00375 * This method is intended for use only with the core initialization and is 00376 * not designed to be called from any user applications. 00377 */ 00378 int register_config_cli(void); 00379 00380 /*!\brief Exposed re-initialization method for core process 00381 * This method is intended for use only with the core re-initialization and is 00382 * not designed to be called from any user applications. 00383 */ 00384 int read_config_maps(void); 00385 00386 /*!\brief Create a new base configuration structure */ 00387 struct ast_config *ast_config_new(void); 00388 00389 /*!\brief Retrieve the current category name being built. 00390 * API for backend configuration engines while building a configuration set. 00391 */ 00392 struct ast_category *ast_config_get_current_category(const struct ast_config *cfg); 00393 00394 /*!\brief Set the category within the configuration as being current. 00395 * API for backend configuration engines while building a configuration set. 00396 */ 00397 void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat); 00398 00399 /*!\brief Retrieve a configuration variable within the configuration set. 00400 * Retrieves the named variable \p var within category \p cat of configuration 00401 * set \p cfg. If not found, attempts to retrieve the named variable \p var 00402 * from within category \em general. 00403 * \return Value of \p var, or NULL if not found. 00404 */ 00405 const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var); 00406 00407 /*!\brief Create a category structure */ 00408 struct ast_category *ast_category_new(const char *name, const char *in_file, int lineno); 00409 void ast_category_append(struct ast_config *config, struct ast_category *cat); 00410 00411 /*! 00412 * \brief Inserts new category 00413 * \param config which config to use 00414 * \param cat newly created category to insert 00415 * \param match which category to insert above 00416 * This function is used to insert a new category above another category 00417 * matching the match parameter. 00418 */ 00419 void ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match); 00420 int ast_category_delete(struct ast_config *cfg, const char *category); 00421 00422 /*!\brief Removes and destroys all variables within a category 00423 * \retval 0 if the category was found and emptied 00424 * \retval -1 if the category was not found 00425 */ 00426 int ast_category_empty(struct ast_config *cfg, const char *category); 00427 void ast_category_destroy(struct ast_category *cat); 00428 struct ast_variable *ast_category_detach_variables(struct ast_category *cat); 00429 void ast_category_rename(struct ast_category *cat, const char *name); 00430 00431 #ifdef MALLOC_DEBUG 00432 struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno); 00433 #define ast_variable_new(a, b, c) _ast_variable_new(a, b, c, __FILE__, __PRETTY_FUNCTION__, __LINE__) 00434 #else 00435 struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename); 00436 #endif 00437 struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size); 00438 struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file); 00439 void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file); 00440 void ast_variable_append(struct ast_category *category, struct ast_variable *variable); 00441 void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line); 00442 int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line); 00443 00444 /*! \brief Update variable value within a config 00445 * \param category Category element within the config 00446 * \param variable Name of the variable to change 00447 * \param value New value of the variable 00448 * \param match If set, previous value of the variable (if NULL or zero-length, no matching will be done) 00449 * \param object Boolean of whether to make the new variable an object 00450 * \return 0 on success or -1 on failure. 00451 */ 00452 int ast_variable_update(struct ast_category *category, const char *variable, 00453 const char *value, const char *match, unsigned int object); 00454 00455 int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator); 00456 int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator) __attribute__((deprecated)); 00457 00458 struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked); 00459 00460 /*! \brief Support code to parse config file arguments 00461 * 00462 * The function ast_parse_arg() provides a generic interface to parse 00463 * strings (e.g. numbers, network addresses and so on) in a flexible 00464 * way, e.g. by doing proper error and bound checks, provide default 00465 * values, and so on. 00466 * The function (described later) takes a string as an argument, 00467 * a set of flags to specify the result format and checks to perform, 00468 * a pointer to the result, and optionally some additional arguments. 00469 * It returns 0 on success, != 0 otherwise. 00470 * 00471 */ 00472 enum ast_parse_flags { 00473 /* low 4 bits of flags are used for the operand type */ 00474 PARSE_TYPE = 0x000f, 00475 /* numeric types, with optional default value and bound checks. 00476 * Additional arguments are passed by value. 00477 */ 00478 PARSE_INT32 = 0x0001, 00479 PARSE_UINT32 = 0x0002, 00480 PARSE_DOUBLE = 0x0003, 00481 #if 0 /* not supported yet */ 00482 PARSE_INT16 = 0x0004, 00483 PARSE_UINT16 = 0x0005, 00484 #endif 00485 /* Returns a struct sockaddr_in, with optional default value 00486 * (passed by reference) and port handling (accept, ignore, 00487 * require, forbid). The format is 'host.name[:port]' 00488 */ 00489 PARSE_INADDR = 0x000f, 00490 00491 /* Other data types can be added as needed */ 00492 00493 /* If PARSE_DEFAULT is set, next argument is a default value 00494 * which is returned in case of error. The argument is passed 00495 * by value in case of numeric types, by reference in other cases. 00496 */ 00497 PARSE_DEFAULT = 0x0010, /* assign default on error */ 00498 00499 /* Request a range check, applicable to numbers. Two additional 00500 * arguments are passed by value, specifying the low-high end of 00501 * the range (inclusive). An error is returned if the value 00502 * is outside or inside the range, respectively. 00503 */ 00504 PARSE_IN_RANGE = 0x0020, /* accept values inside a range */ 00505 PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */ 00506 00507 /* Port handling, for sockaddr_in. accept/ignore/require/forbid 00508 * port number after the hostname or address. 00509 */ 00510 PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */ 00511 PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */ 00512 PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */ 00513 PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */ 00514 }; 00515 00516 /*! \brief The argument parsing routine. 00517 * \param arg the string to parse. It is not modified. 00518 * \param flags combination of ast_parse_flags to specify the 00519 * return type and additional checks. 00520 * \param result pointer to the result. NULL is valid here, and can 00521 * be used to perform only the validity checks. 00522 * \param ... extra arguments are required according to flags. 00523 * \retval 0 in case of success, != 0 otherwise. 00524 * \retval result returns the parsed value in case of success, 00525 * the default value in case of error, or it is left unchanged 00526 * in case of error and no default specified. Note that in certain 00527 * cases (e.g. sockaddr_in, with multi-field return values) some 00528 * of the fields in result may be changed even if an error occurs. 00529 * 00530 * Examples of use: 00531 * ast_parse_arg("223", PARSE_INT32|PARSE_IN_RANGE, 00532 * &a, -1000, 1000); 00533 * returns 0, a = 223 00534 * ast_parse_arg("22345", PARSE_INT32|PARSE_IN_RANGE|PARSE_DEFAULT, 00535 * &a, 9999, 10, 100); 00536 * returns 1, a = 9999 00537 * ast_parse_arg("22345ssf", PARSE_UINT32|PARSE_IN_RANGE, &b, 10, 100); 00538 * returns 1, b unchanged 00539 * ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa); 00540 * returns 0, sa contains address and port 00541 * ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa); 00542 * returns 1 because port is missing, sa contains address 00543 */ 00544 int ast_parse_arg(const char *arg, enum ast_parse_flags flags, 00545 void *result, ...); 00546 00547 /* 00548 * Parsing config file options in C is slightly annoying because we cannot use 00549 * string in a switch() statement, yet we need a similar behaviour, with many 00550 * branches and a break on a matching one. 00551 * The following somehow simplifies the job: we create a block using 00552 * the CV_START and CV_END macros, and then within the block we can run 00553 * actions such as "if (condition) { body; break; }" 00554 * Additional macros are present to run simple functions (e.g. ast_copy_string) 00555 * or to pass arguments to ast_parse_arg() 00556 * 00557 * As an example: 00558 00559 CV_START(v->name, v->value); // start the block 00560 CV_STR("foo", x_foo); // static string 00561 CV_DSTR("bar", y_bar); // malloc'ed string 00562 CV_F("bar", ...); // call a generic function 00563 CV_END; // end the block 00564 */ 00565 00566 /*! \brief the macro to open a block for variable parsing */ 00567 #define CV_START(__in_var, __in_val) \ 00568 do { \ 00569 const char *__var = __in_var; \ 00570 const char *__val = __in_val; 00571 00572 /*! \brief close a variable parsing block */ 00573 #define CV_END } while (0) 00574 00575 /*! \brief call a generic function if the name matches. */ 00576 #define CV_F(__pattern, __body) if (!strcasecmp((__var), __pattern)) { __body; break; } 00577 00578 /*! \brief helper macros to assign the value to a BOOL, UINT, static string and 00579 * dynamic string 00580 */ 00581 #define CV_BOOL(__x, __dst) CV_F(__x, (__dst) = ast_true(__val) ) 00582 #define CV_UINT(__x, __dst) CV_F(__x, (__dst) = strtoul(__val, NULL, 0) ) 00583 #define CV_STR(__x, __dst) CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst))) 00584 #define CV_DSTR(__x, __dst) CV_F(__x, if (__dst) ast_free(__dst); __dst = ast_strdup(__val)) 00585 #define CV_STRFIELD(__x, __obj, __field) CV_F(__x, ast_string_field_set(__obj, __field, __val)) 00586 00587 /*!\brief Check if require type is an integer type */ 00588 AST_INLINE_API( 00589 int ast_rq_is_int(require_type type), 00590 { 00591 switch (type) { 00592 case RQ_INTEGER1: 00593 case RQ_UINTEGER1: 00594 case RQ_INTEGER2: 00595 case RQ_UINTEGER2: 00596 case RQ_INTEGER3: 00597 case RQ_UINTEGER3: 00598 case RQ_INTEGER4: 00599 case RQ_UINTEGER4: 00600 case RQ_INTEGER8: 00601 case RQ_UINTEGER8: 00602 return 1; 00603 default: 00604 return 0; 00605 } 00606 } 00607 ) 00608 00609 #if defined(__cplusplus) || defined(c_plusplus) 00610 } 00611 #endif 00612 00613 #endif /* _ASTERISK_CONFIG_H */