config.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Configuration File Parser
  20. */
  21. #ifndef _ASTERISK_CONFIG_H
  22. #define _ASTERISK_CONFIG_H
  23. #if defined(__cplusplus) || defined(c_plusplus)
  24. extern "C" {
  25. #endif
  26. #include "asterisk/utils.h"
  27. #include "asterisk/inline_api.h"
  28. struct ast_config;
  29. struct ast_category;
  30. /*! Options for ast_config_load()
  31. */
  32. enum {
  33. /*! Load the configuration, including comments */
  34. CONFIG_FLAG_WITHCOMMENTS = (1 << 0),
  35. /*! On a reload, give us a -1 if the file hasn't changed. */
  36. CONFIG_FLAG_FILEUNCHANGED = (1 << 1),
  37. /*! Don't attempt to cache mtime on this config file. */
  38. CONFIG_FLAG_NOCACHE = (1 << 2),
  39. /*! Don't attempt to load from realtime (typically called from a realtime driver dependency) */
  40. CONFIG_FLAG_NOREALTIME = (1 << 3),
  41. };
  42. /*! Flags for ast_config_text_file_save2()
  43. */
  44. enum config_save_flags {
  45. CONFIG_SAVE_FLAG_NONE = (0),
  46. /*! Insure a context doesn't effectively change if a template changes (pre 13.2 behavior) */
  47. CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT = (1 << 0),
  48. };
  49. #define CONFIG_STATUS_FILEMISSING (void *)0
  50. #define CONFIG_STATUS_FILEUNCHANGED (void *)-1
  51. #define CONFIG_STATUS_FILEINVALID (void *)-2
  52. /*!
  53. * \brief Types used in ast_realtime_require_field
  54. */
  55. typedef enum {
  56. RQ_INTEGER1,
  57. RQ_UINTEGER1,
  58. RQ_INTEGER2,
  59. RQ_UINTEGER2,
  60. RQ_INTEGER3,
  61. RQ_UINTEGER3,
  62. RQ_INTEGER4,
  63. RQ_UINTEGER4,
  64. RQ_INTEGER8,
  65. RQ_UINTEGER8,
  66. RQ_CHAR,
  67. RQ_FLOAT,
  68. RQ_DATE,
  69. RQ_DATETIME,
  70. } require_type;
  71. /*! \brief Structure for variables, used for configurations and for channel variables */
  72. struct ast_variable {
  73. /*! Variable name. Stored in stuff[] at struct end. */
  74. const char *name;
  75. /*! Variable value. Stored in stuff[] at struct end. */
  76. const char *value;
  77. /*! Next node in the list. */
  78. struct ast_variable *next;
  79. /*! Filename where variable found. Stored in stuff[] at struct end. */
  80. const char *file;
  81. int lineno;
  82. int object; /*!< 0 for variable, 1 for object */
  83. int blanklines; /*!< Number of blanklines following entry */
  84. int inherited; /*!< 1 for inherited from template or other base */
  85. struct ast_comment *precomments;
  86. struct ast_comment *sameline;
  87. struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */
  88. /*!
  89. * \brief Contents of file, name, and value in that order stuffed here.
  90. * \note File must be stuffed before name because of ast_include_rename().
  91. */
  92. char stuff[0];
  93. };
  94. 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);
  95. typedef struct ast_variable *realtime_var_get(const char *database, const char *table, const struct ast_variable *fields);
  96. typedef struct ast_config *realtime_multi_get(const char *database, const char *table, const struct ast_variable *fields);
  97. typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields);
  98. typedef int realtime_update2(const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
  99. typedef int realtime_store(const char *database, const char *table, const struct ast_variable *fields);
  100. typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields);
  101. /*!
  102. * \brief Function pointer called to ensure database schema is properly configured for realtime use
  103. * \since 1.6.1
  104. */
  105. typedef int realtime_require(const char *database, const char *table, va_list ap);
  106. /*!
  107. * \brief Function pointer called to clear the database cache and free resources used for such
  108. * \since 1.6.1
  109. */
  110. typedef int realtime_unload(const char *database, const char *table);
  111. /*! \brief Configuration engine structure, used to define realtime drivers */
  112. struct ast_config_engine {
  113. char *name;
  114. config_load_func *load_func;
  115. realtime_var_get *realtime_func;
  116. realtime_multi_get *realtime_multi_func;
  117. realtime_update *update_func;
  118. realtime_update2 *update2_func;
  119. realtime_store *store_func;
  120. realtime_destroy *destroy_func;
  121. realtime_require *require_func;
  122. realtime_unload *unload_func;
  123. struct ast_config_engine *next;
  124. };
  125. /*!
  126. * \brief Load a config file
  127. *
  128. * \param filename path of file to open. If no preceding '/' character,
  129. * path is considered relative to AST_CONFIG_DIR
  130. * \param who_asked The module which is making this request.
  131. * \param flags Optional flags:
  132. * CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
  133. * CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
  134. * CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).
  135. *
  136. * \details
  137. * Create a config structure from a given configuration file.
  138. *
  139. * \return an ast_config data structure on success
  140. * \retval NULL on error
  141. */
  142. struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags);
  143. /*!
  144. * \brief Load a config file
  145. *
  146. * \param filename path of file to open. If no preceding '/' character,
  147. * path is considered relative to AST_CONFIG_DIR
  148. * \param flags Optional flags:
  149. * CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
  150. * CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
  151. * CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).
  152. *
  153. * \details
  154. * Create a config structure from a given configuration file.
  155. *
  156. * \return an ast_config data structure on success
  157. * \retval NULL on error
  158. */
  159. #define ast_config_load(filename, flags) ast_config_load2(filename, AST_MODULE, flags)
  160. /*!
  161. * \brief Destroys a config
  162. *
  163. * \param config pointer to config data structure
  164. *
  165. * \details
  166. * Free memory associated with a given config
  167. */
  168. void ast_config_destroy(struct ast_config *config);
  169. /*!
  170. * \brief returns the root ast_variable of a config
  171. *
  172. * \param config pointer to an ast_config data structure
  173. * \param cat name of the category for which you want the root
  174. *
  175. * \return the category specified
  176. */
  177. struct ast_variable *ast_category_root(struct ast_config *config, char *cat);
  178. /*!
  179. * \brief Sorts categories in a config in the order of a numerical value contained within them.
  180. *
  181. * \param config The config structure you wish to sort
  182. * \param comparator variable Which numerical value you wish to sort by
  183. * \param descending If true, we sort highest to lowest instead of lowest to highest
  184. *
  185. * \details
  186. * This function will assume a value of 0 for any non-numerical strings and NULL fields.
  187. */
  188. void ast_config_sort_categories(struct ast_config *config, int descending,
  189. int (*comparator)(struct ast_category *p, struct ast_category *q));
  190. /*!
  191. * \brief Browse categories with filters
  192. *
  193. * \param config Which config structure you wish to "browse"
  194. * \param category_name An optional category name.
  195. * Pass NULL to not restrict by category name.
  196. * \param prev A pointer to the starting category structure.
  197. * Pass NULL to start at the beginning.
  198. * \param filter An optional comma-separated list of <name_regex>=<value_regex>
  199. * pairs. Only categories with matching variables will be returned.
  200. * The special name 'TEMPLATES' can be used with the special values
  201. * 'include' or 'restrict' to include templates in the result or
  202. * restrict the result to only templates.
  203. *
  204. * \retval a category on success
  205. * \retval NULL on failure/no-more-categories
  206. */
  207. struct ast_category *ast_category_browse_filtered(struct ast_config *config,
  208. const char *category_name, struct ast_category *prev, const char *filter);
  209. /*!
  210. * \brief Browse categories
  211. *
  212. * \param config Which config structure you wish to "browse"
  213. * \param prev_name A pointer to a previous category name.
  214. *
  215. * \details
  216. * This function is kind of non-intuitive in it's use.
  217. * To begin, one passes NULL as the second argument.
  218. * It will return a pointer to the string of the first category in the file.
  219. * From here on after, one must then pass the previous usage's return value
  220. * as the second pointer, and it will return a pointer to the category name
  221. * afterwards.
  222. *
  223. * \retval a category name on success
  224. * \retval NULL on failure/no-more-categories
  225. *
  226. * \note ast_category_browse maintains internal state. Therefore is not thread
  227. * safe, cannot be called recursively, and it is not safe to add or remove
  228. * categories while browsing.
  229. * ast_category_browse_filtered does not have these restrictions.
  230. */
  231. char *ast_category_browse(struct ast_config *config, const char *prev_name);
  232. /*!
  233. * \brief Browse variables
  234. * \param config Which config structure you wish to "browse"
  235. * \param category_name Which category to "browse"
  236. * \param filter an optional comma-separated list of <name_regex>=<value_regex>
  237. * pairs. Only categories with matching variables will be browsed.
  238. * The special name 'TEMPLATES' can be used with the special values
  239. * 'include' or 'restrict' to include templates in the result or
  240. * restrict the result to only templates.
  241. *
  242. * \details
  243. * Somewhat similar in intent as the ast_category_browse.
  244. * List variables of config file category
  245. *
  246. * \retval ast_variable list on success
  247. * \retval NULL on failure
  248. */
  249. struct ast_variable *ast_variable_browse_filtered(const struct ast_config *config,
  250. const char *category_name, const char *filter);
  251. struct ast_variable *ast_variable_browse(const struct ast_config *config,
  252. const char *category_name);
  253. /*!
  254. * \brief given a pointer to a category, return the root variable.
  255. *
  256. * \details
  257. * This is equivalent to ast_variable_browse(), but more efficient if we
  258. * already have the struct ast_category * (e.g. from ast_category_get())
  259. */
  260. struct ast_variable *ast_category_first(struct ast_category *cat);
  261. /*!
  262. * \brief Gets a variable by context and variable names
  263. *
  264. * \param config which (opened) config to use
  265. * \param category category under which the variable lies
  266. * \param variable which variable you wish to get the data for
  267. * \param filter an optional comma-separated list of <name_regex>=<value_regex>
  268. * pairs. Only categories with matching variables will be searched.
  269. * The special name 'TEMPLATES' can be used with the special values
  270. * 'include' or 'restrict' to include templates in the result or
  271. * restrict the result to only templates.
  272. *
  273. * \retval The variable value on success
  274. * \retval NULL if unable to find it.
  275. */
  276. const char *ast_variable_retrieve_filtered(struct ast_config *config,
  277. const char *category, const char *variable, const char *filter);
  278. const char *ast_variable_retrieve(struct ast_config *config,
  279. const char *category, const char *variable);
  280. /*!
  281. * \brief Gets a variable value from a specific category structure by name
  282. *
  283. * \param category category structure under which the variable lies
  284. * \param variable which variable you wish to get the data for
  285. *
  286. * \details
  287. * Goes through a given category and searches for the given variable
  288. *
  289. * \retval The variable value on success
  290. * \retval NULL if unable to find it.
  291. */
  292. const char *ast_variable_find(const struct ast_category *category, const char *variable);
  293. /*!
  294. * \brief Gets the value of a variable from a variable list by name
  295. *
  296. * \param list variable list to search
  297. * \param variable which variable you wish to get the data for
  298. *
  299. * \details
  300. * Goes through a given variable list and searches for the given variable
  301. *
  302. * \retval The variable value on success
  303. * \retval NULL if unable to find it.
  304. */
  305. const char *ast_variable_find_in_list(const struct ast_variable *list, const char *variable);
  306. /*!
  307. * \brief Gets the value of the LAST occurrence of a variable from a variable list
  308. *
  309. * \param list The ast_variable list to search
  310. * \param variable The name of the ast_variable you wish to fetch data for
  311. *
  312. * \details
  313. * Iterates over a given ast_variable list to search for the last occurrence of an
  314. * ast_variable entry with a name attribute matching the given name (variable).
  315. * This is useful if the list has duplicate entries (such as in cases where entries
  316. * are created by a template)
  317. *
  318. * \retval The variable value on success
  319. * \retval NULL if unable to find it.
  320. */
  321. const char *ast_variable_find_last_in_list(const struct ast_variable *list, const char *variable);
  322. /*!
  323. * \brief Gets a variable from a variable list by name
  324. * \since 13.9.0
  325. *
  326. * \param list variable list to search
  327. * \param variable name you wish to get the data for
  328. *
  329. * \details
  330. * Goes through a given variable list and searches for the given variable
  331. *
  332. * \retval The variable (not the value) on success
  333. * \retval NULL if unable to find it.
  334. */
  335. const struct ast_variable *ast_variable_find_variable_in_list(const struct ast_variable *list, const char *variable_name);
  336. /*!
  337. * \brief Retrieve a category if it exists
  338. *
  339. * \param config which config to use
  340. * \param category_name name of the category you're looking for
  341. * \param filter If a config contains more than 1 category with the same name,
  342. * you can specify a filter to narrow the search. The filter is a comma-separated
  343. * list of <name_regex>=<value_regex> pairs. Only a category with matching
  344. * variables will be returned. The special name 'TEMPLATES' can be used with the
  345. * special values 'include' or 'restrict' to include templates in the result or
  346. * restrict the result to only templates.
  347. *
  348. * \details
  349. * This will search through the categories within a given config file for a match.
  350. *
  351. * \retval pointer to category if found
  352. * \retval NULL if not.
  353. */
  354. struct ast_category *ast_category_get(const struct ast_config *config,
  355. const char *category_name, const char *filter);
  356. /*!
  357. * \brief Return the name of the category
  358. *
  359. * \param category category structure
  360. *
  361. * \retval pointer to category name if found
  362. * \retval NULL if not.
  363. */
  364. const char *ast_category_get_name(const struct ast_category *category);
  365. /*!
  366. * \brief Check if category is a template
  367. *
  368. * \param category category structure
  369. *
  370. * \retval 1 if a template.
  371. * \retval 0 if not.
  372. */
  373. int ast_category_is_template(const struct ast_category *category);
  374. /*!
  375. * \brief Return the template names this category inherits from
  376. *
  377. * \param category category structure
  378. *
  379. * \return an ast_str (which must be freed after use) with a comma
  380. * separated list of templates names or NULL if there were no templates.
  381. */
  382. struct ast_str *ast_category_get_templates(const struct ast_category *category);
  383. /*!
  384. * \brief Check for category duplicates
  385. *
  386. * \param config which config to use
  387. * \param category_name name of the category you're looking for
  388. * \param filter an optional comma-separated list of <name_regex>=<value_regex>
  389. * pairs. Only categories with matching variables will be returned.
  390. * The special name 'TEMPLATES' can be used with the special values
  391. * 'include' or 'restrict' to include templates in the result or
  392. * restrict the result to only templates.
  393. *
  394. * \details
  395. * This will search through the categories within a given config file for a match.
  396. *
  397. * \return non-zero if found
  398. */
  399. int ast_category_exist(const struct ast_config *config, const char *category_name,
  400. const char *filter);
  401. /*!
  402. * \brief Retrieve realtime configuration
  403. *
  404. * \param family which family/config to lookup
  405. *
  406. * \details
  407. * This will use builtin configuration backends to look up a particular
  408. * entity in realtime and return a variable list of its parameters.
  409. *
  410. * \note
  411. * Unlike the variables in ast_config, the resulting list of variables
  412. * MUST be freed with ast_variables_destroy() as there is no container.
  413. *
  414. * \note
  415. * The difference between these two calls is that ast_load_realtime excludes
  416. * fields whose values are NULL, while ast_load_realtime_all loads all columns.
  417. *
  418. * \note
  419. * You should use the constant SENTINEL to terminate arguments, in
  420. * order to preserve cross-platform compatibility.
  421. */
  422. struct ast_variable *ast_load_realtime_fields(const char *family, const struct ast_variable *fields);
  423. struct ast_variable *ast_load_realtime(const char *family, ...) attribute_sentinel;
  424. struct ast_variable *ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields);
  425. struct ast_variable *ast_load_realtime_all(const char *family, ...) attribute_sentinel;
  426. /*!
  427. * \brief Release any resources cached for a realtime family
  428. * \since 1.6.1
  429. *
  430. * \param family which family/config to destroy
  431. *
  432. * \details
  433. * Various backends may cache attributes about a realtime data storage
  434. * facility; on reload, a front end resource may request to purge that cache.
  435. *
  436. * \retval 0 If any cache was purged
  437. * \retval -1 If no cache was found
  438. */
  439. int ast_unload_realtime(const char *family);
  440. /*!
  441. * \brief Inform realtime what fields that may be stored
  442. * \since 1.6.1
  443. *
  444. * \param family which family/config is referenced
  445. *
  446. * \details
  447. * This will inform builtin configuration backends that particular fields
  448. * may be updated during the use of that configuration section. This is
  449. * mainly to be used during startup routines, to ensure that various fields
  450. * exist in the backend. The backends may take various actions, such as
  451. * creating new fields in the data store or warning the administrator that
  452. * new fields may need to be created, in order to ensure proper function.
  453. *
  454. * The arguments are specified in groups of 3: column name, column type,
  455. * and column size. The column types are specified as integer constants,
  456. * defined by the enum require_type. Note that the size is specified as
  457. * the number of equivalent character fields that a field may take up, even
  458. * if a field is otherwise specified as an integer type. This is due to
  459. * the fact that some fields have historically been specified as character
  460. * types, even if they contained integer values.
  461. *
  462. * A family should always specify its fields to the minimum necessary
  463. * requirements to fulfill all possible values (within reason; for example,
  464. * a timeout value may reasonably be specified as an INTEGER2, with size 5.
  465. * Even though values above 32767 seconds are possible, they are unlikely
  466. * to be useful, and we should not complain about that size).
  467. *
  468. * \retval 0 Required fields met specified standards
  469. * \retval -1 One or more fields was missing or insufficient
  470. *
  471. * \note You should use the constant SENTINEL to terminate arguments, in
  472. * order to preserve cross-platform compatibility.
  473. *
  474. * TODO The return value of this function is routinely ignored. Ignoring
  475. * the return value means that it's mostly pointless to be calling this.
  476. * You'll see some warning messages potentially, but that's it.
  477. *
  478. * XXX This function is super useful for detecting configuration problems
  479. * early, but unfortunately, the latest in configuration management, sorcery,
  480. * doesn't work well with this. Users of sorcery are familiar with the fields
  481. * they will need to write but don't know if realtime is being used. Sorcery
  482. * knows what storage mechanism is being used but has no high-level knowledge
  483. * of what sort of data is going to be written.
  484. */
  485. int ast_realtime_require_field(const char *family, ...) attribute_sentinel;
  486. /*!
  487. * \brief Retrieve realtime configuration
  488. *
  489. * \param family which family/config to lookup
  490. * \param fields list of fields
  491. *
  492. * \details
  493. * This will use builtin configuration backends to look up a particular
  494. * entity in realtime and return a variable list of its parameters. Unlike
  495. * the ast_load_realtime, this function can return more than one entry and
  496. * is thus stored inside a traditional ast_config structure rather than
  497. * just returning a linked list of variables.
  498. *
  499. * \return An ast_config with one or more results
  500. * \retval NULL Error or no results returned
  501. */
  502. struct ast_config *ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields);
  503. /*!
  504. * \brief Retrieve realtime configuration
  505. *
  506. * \param family which family/config to lookup
  507. *
  508. * \details
  509. * This will use builtin configuration backends to look up a particular
  510. * entity in realtime and return a variable list of its parameters. Unlike
  511. * the ast_load_realtime, this function can return more than one entry and
  512. * is thus stored inside a traditional ast_config structure rather than
  513. * just returning a linked list of variables.
  514. *
  515. * \return An ast_config with one or more results
  516. * \retval NULL Error or no results returned
  517. *
  518. * \note You should use the constant SENTINEL to terminate arguments, in
  519. * order to preserve cross-platform compatibility.
  520. */
  521. struct ast_config *ast_load_realtime_multientry(const char *family, ...) attribute_sentinel;
  522. /*!
  523. * \brief Update realtime configuration
  524. *
  525. * \param family which family/config to be updated
  526. * \param keyfield which field to use as the key
  527. * \param lookup which value to look for in the key field to match the entry.
  528. * \param fields fields to update
  529. *
  530. * \details
  531. * This function is used to update a parameter in realtime configuration space.
  532. *
  533. * \return Number of rows affected, or -1 on error.
  534. */
  535. int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields);
  536. /*!
  537. * \brief Update realtime configuration
  538. *
  539. * \param family which family/config to be updated
  540. * \param keyfield which field to use as the key
  541. * \param lookup which value to look for in the key field to match the entry.
  542. *
  543. * \details
  544. * This function is used to update a parameter in realtime configuration space.
  545. *
  546. * \return Number of rows affected, or -1 on error.
  547. *
  548. * \note You should use the constant SENTINEL to terminate arguments, in
  549. * order to preserve cross-platform compatibility.
  550. */
  551. int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel;
  552. /*!
  553. * \brief Update realtime configuration
  554. *
  555. * \param family which family/config to be updated
  556. * \param lookup_fields fields used to look up entries
  557. * \param update_fields fields to update
  558. *
  559. * \details
  560. * This function is used to update a parameter in realtime configuration space.
  561. * It includes the ability to lookup a row based upon multiple key criteria.
  562. * As a result, this function includes two sentinel values, one to terminate
  563. * lookup values and the other to terminate the listing of fields to update.
  564. *
  565. * \return Number of rows affected, or -1 on error.
  566. */
  567. int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
  568. /*!
  569. * \brief Update realtime configuration
  570. *
  571. * \param family which family/config to be updated
  572. *
  573. * \details
  574. * This function is used to update a parameter in realtime configuration space.
  575. * It includes the ability to lookup a row based upon multiple key criteria.
  576. * As a result, this function includes two sentinel values, one to terminate
  577. * lookup values and the other to terminate the listing of fields to update.
  578. *
  579. * \return Number of rows affected, or -1 on error.
  580. *
  581. * \note You should use the constant SENTINEL to terminate arguments, in
  582. * order to preserve cross-platform compatibility.
  583. */
  584. int ast_update2_realtime(const char *family, ...) attribute_sentinel;
  585. /*!
  586. * \brief Create realtime configuration
  587. *
  588. * \param family which family/config to be created
  589. * \param fields fields themselves
  590. *
  591. * \details
  592. * This function is used to create a parameter in realtime configuration space.
  593. *
  594. * \return Number of rows affected, or -1 on error.
  595. *
  596. * \note
  597. * On the MySQL engine only, for reasons of backwards compatibility, the return
  598. * value is the insert ID. This value is nonportable and may be changed in a
  599. * future version to match the other engines.
  600. */
  601. int ast_store_realtime_fields(const char *family, const struct ast_variable *fields);
  602. /*!
  603. * \brief Create realtime configuration
  604. *
  605. * \param family which family/config to be created
  606. *
  607. * \details
  608. * This function is used to create a parameter in realtime configuration space.
  609. *
  610. * \return Number of rows affected, or -1 on error.
  611. *
  612. * \note
  613. * On the MySQL engine only, for reasons of backwards compatibility, the return
  614. * value is the insert ID. This value is nonportable and may be changed in a
  615. * future version to match the other engines.
  616. *
  617. * \note You should use the constant SENTINEL to terminate arguments, in
  618. * order to preserve cross-platform compatibility.
  619. */
  620. int ast_store_realtime(const char *family, ...) attribute_sentinel;
  621. /*!
  622. * \brief Destroy realtime configuration
  623. *
  624. * \param family which family/config to be destroyed
  625. * \param keyfield which field to use as the key
  626. * \param lookup which value to look for in the key field to match the entry.
  627. * \param fields fields themselves
  628. *
  629. * \details
  630. * This function is used to destroy an entry in realtime configuration space.
  631. * Additional params are used as keys.
  632. *
  633. * \return Number of rows affected, or -1 on error.
  634. */
  635. int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields);
  636. /*!
  637. * \brief Destroy realtime configuration
  638. *
  639. * \param family which family/config to be destroyed
  640. * \param keyfield which field to use as the key
  641. * \param lookup which value to look for in the key field to match the entry.
  642. *
  643. * \details
  644. * This function is used to destroy an entry in realtime configuration space.
  645. * Additional params are used as keys.
  646. *
  647. * \return Number of rows affected, or -1 on error.
  648. *
  649. * \note You should use the constant SENTINEL to terminate arguments, in
  650. * order to preserve cross-platform compatibility.
  651. */
  652. int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel;
  653. /*!
  654. * \brief Check if realtime engine is configured for family
  655. * \param family which family/config to be checked
  656. * \return 1 if family is configured in realtime and engine exists
  657. */
  658. int ast_check_realtime(const char *family);
  659. /*! \brief Check if there's any realtime engines loaded */
  660. int ast_realtime_enabled(void);
  661. /*!
  662. * \brief Duplicate variable list
  663. * \param var the linked list of variables to clone
  664. * \return A duplicated list which you'll need to free with
  665. * ast_variables_destroy or NULL when out of memory.
  666. *
  667. * \note Do not depend on this to copy more than just name, value and filename
  668. * (the arguments to ast_variables_new).
  669. */
  670. struct ast_variable *ast_variables_dup(struct ast_variable *var);
  671. /*!
  672. * \brief Reverse a variable list
  673. * \param var the linked list of variables to reverse
  674. * \return The head of the reversed variable list
  675. *
  676. * \note The variable list var is not preserved in this function and should
  677. * not be used after reversing it.
  678. */
  679. struct ast_variable *ast_variables_reverse(struct ast_variable *var);
  680. /*!
  681. * \brief Free variable list
  682. * \param var the linked list of variables to free
  683. *
  684. * \details
  685. * This function frees a list of variables.
  686. */
  687. void ast_variables_destroy(struct ast_variable *var);
  688. /*!
  689. * \brief Register config engine
  690. * \retval 1 Always
  691. */
  692. int ast_config_engine_register(struct ast_config_engine *newconfig);
  693. /*!
  694. * \brief Deregister config engine
  695. * \retval 0 Always
  696. */
  697. int ast_config_engine_deregister(struct ast_config_engine *del);
  698. /*!
  699. * \brief Determine if a mapping exists for a given family
  700. *
  701. * \param family which family you are looking to see if a mapping exists for
  702. * \retval 1 if it is mapped
  703. * \retval 0 if it is not
  704. */
  705. int ast_realtime_is_mapping_defined(const char *family);
  706. #ifdef TEST_FRAMEWORK
  707. /*!
  708. * \brief Add an explicit mapping for a family
  709. *
  710. * \param name Family name
  711. * \param driver Driver to use
  712. * \param database Database to access
  713. * \param table Table to use
  714. * \param priority Priority of this mapping
  715. */
  716. int ast_realtime_append_mapping(const char *name, const char *driver, const char *database, const char *table, int priority);
  717. #endif
  718. /*!
  719. * \brief Exposed initialization method for core process
  720. *
  721. * \details
  722. * This method is intended for use only with the core initialization and is
  723. * not designed to be called from any user applications.
  724. */
  725. int register_config_cli(void);
  726. /*!
  727. * \brief Exposed re-initialization method for core process
  728. *
  729. * \details
  730. * This method is intended for use only with the core re-initialization and is
  731. * not designed to be called from any user applications.
  732. */
  733. int read_config_maps(void);
  734. /*! \brief Create a new base configuration structure */
  735. struct ast_config *ast_config_new(void);
  736. /*!
  737. * \brief Retrieve the current category name being built.
  738. *
  739. * \details
  740. * API for backend configuration engines while building a configuration set.
  741. */
  742. struct ast_category *ast_config_get_current_category(const struct ast_config *cfg);
  743. /*!
  744. * \brief Set the category within the configuration as being current.
  745. *
  746. * \details
  747. * API for backend configuration engines while building a configuration set.
  748. */
  749. void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat);
  750. /*!
  751. * \brief Retrieve a configuration variable within the configuration set.
  752. *
  753. * \details
  754. * Retrieves the named variable \p var within category \p cat of configuration
  755. * set \p cfg. If not found, attempts to retrieve the named variable \p var
  756. * from within category \em general.
  757. *
  758. * \return Value of \p var, or NULL if not found.
  759. */
  760. const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var);
  761. /*!
  762. * \brief Create a category
  763. *
  764. * \param name name of new category
  765. * \param in_file filename which contained the new config
  766. * \param lineno line number
  767. */
  768. struct ast_category *ast_category_new(const char *name, const char *in_file, int lineno);
  769. /*!
  770. * \brief Create a category that is not backed by a file
  771. *
  772. * \param name name of new category
  773. */
  774. #define ast_category_new_dynamic(name) ast_category_new(name, "", -1)
  775. /*!
  776. * \brief Create a nameless category that is not backed by a file
  777. */
  778. #define ast_category_new_anonymous() ast_category_new_dynamic("")
  779. /*!
  780. * \brief Create a category making it a template
  781. *
  782. * \param name name of new template
  783. * \param in_file filename which contained the new config
  784. * \param lineno line number
  785. */
  786. struct ast_category *ast_category_new_template(const char *name, const char *in_file, int lineno);
  787. /*!
  788. * \brief Inserts new category
  789. *
  790. * \param config which config to use
  791. * \param cat newly created category to insert
  792. * \param match which category to insert above
  793. *
  794. * \details
  795. * This function is used to insert a new category above another category
  796. * matching the match parameter.
  797. *
  798. * \retval 0 if succeeded
  799. * \retval -1 if the specified match category wasn't found
  800. */
  801. int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match);
  802. /*!
  803. * \brief Delete a category
  804. *
  805. * \param config which config to use
  806. * \param category category to delete
  807. *
  808. * \return the category after the deleted one which could be NULL.
  809. *
  810. * \note It is not safe to call ast_category_delete while browsing with
  811. * ast_category_browse. It is safe with ast_category_browse_filtered.
  812. */
  813. struct ast_category *ast_category_delete(struct ast_config *cfg, struct ast_category *category);
  814. /*!
  815. * \brief Appends a category to a config
  816. *
  817. * \param config which config to use
  818. * \param cat category to insert
  819. */
  820. void ast_category_append(struct ast_config *config, struct ast_category *cat);
  821. /*!
  822. * \brief Applies base (template) to category.
  823. *
  824. * \param existing existing category
  825. * \param base base category
  826. *
  827. * \details
  828. * This function is used to apply a base (template) to an existing category
  829. *
  830. * \retval 0 if succeeded
  831. * \retval -1 if the memory allocation failed
  832. */
  833. int ast_category_inherit(struct ast_category *existing, const struct ast_category *base);
  834. /*!
  835. * \brief Removes and destroys all variables in a category
  836. *
  837. * \param category category to empty
  838. *
  839. * \retval 0 if succeeded
  840. * \retval -1 if categopry is NULL
  841. */
  842. int ast_category_empty(struct ast_category *category);
  843. void ast_category_destroy(struct ast_category *cat);
  844. struct ast_variable *ast_category_detach_variables(struct ast_category *cat);
  845. void ast_category_rename(struct ast_category *cat, const char *name);
  846. #ifdef __AST_DEBUG_MALLOC
  847. struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno);
  848. #define ast_variable_new(a, b, c) _ast_variable_new(a, b, c, __FILE__, __PRETTY_FUNCTION__, __LINE__)
  849. #else
  850. struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename);
  851. #endif
  852. 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);
  853. struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file);
  854. void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file);
  855. void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
  856. void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line);
  857. int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line);
  858. /*!
  859. * \brief Performs an in-place sort on the variable list by ascending name
  860. *
  861. * \param head The variable list head
  862. *
  863. * \return The new list head
  864. */
  865. struct ast_variable *ast_variable_list_sort(struct ast_variable *head);
  866. /*!
  867. * \brief Appends a variable list to the end of another list
  868. *
  869. * \param head A pointer to an ast_variable * of the existing variable list head. May NOT be NULL
  870. * but the content may be to initialize a new list. If so, upon return, this parameter will be updated
  871. * with a pointer to the new list head.
  872. * \param search_hint The place in the current list to start searching for the end of the list.
  873. * Might help performance on longer lists. If NULL, it defaults to head.
  874. * \param new_var The head of the new variable list to be appended
  875. *
  876. * \return The tail of the resulting list.
  877. *
  878. * \note If the existing *head is NULL, it will be updated to new_var. This allows you to call
  879. * ast_variable_list_append in a loop or callback without initializing the list first.
  880. */
  881. struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint,
  882. struct ast_variable *new_var);
  883. #define ast_variable_list_append(head, new_var) ast_variable_list_append_hint(head, NULL, new_var)
  884. /*!
  885. * \brief Update variable value within a config
  886. *
  887. * \param category Category element within the config
  888. * \param variable Name of the variable to change
  889. * \param value New value of the variable
  890. * \param match If set, previous value of the variable (if NULL or zero-length, no matching will be done)
  891. * \param object Boolean of whether to make the new variable an object
  892. *
  893. * \return 0 on success or -1 on failure.
  894. */
  895. int ast_variable_update(struct ast_category *category, const char *variable,
  896. const char *value, const char *match, unsigned int object);
  897. /*!
  898. * \brief Save a config text file
  899. * \since 13.2.0
  900. *
  901. * \param filename Filename
  902. * \param cfg ast_config
  903. * \param generator generator
  904. * \param flags List of config_save_flags
  905. *
  906. * \return 0 on success or -1 on failure.
  907. */
  908. int ast_config_text_file_save2(const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags);
  909. /*!
  910. * \brief Save a config text file preserving the pre 13.2 behavior
  911. *
  912. * \param filename Filename
  913. * \param cfg ast_config
  914. * \param generator generator
  915. *
  916. * \return 0 on success or -1 on failure.
  917. */
  918. int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
  919. int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator) __attribute__((deprecated));
  920. 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);
  921. /*!
  922. * \brief
  923. * Copies the contents of one ast_config into another
  924. *
  925. * \note
  926. * This creates a config on the heap. The caller of this must
  927. * be prepared to free the memory returned.
  928. *
  929. * \param orig the config to copy
  930. * \return The new config on success, NULL on failure.
  931. */
  932. struct ast_config *ast_config_copy(const struct ast_config *orig);
  933. /*!
  934. * \brief
  935. * Flags that affect the behaviour of config hooks.
  936. */
  937. enum config_hook_flags {
  938. butt,
  939. };
  940. /*
  941. * \brief Callback when configuration is updated
  942. *
  943. * \param cfg A copy of the configuration that is being changed.
  944. * This MUST be freed by the callback before returning.
  945. */
  946. typedef int (*config_hook_cb)(struct ast_config *cfg);
  947. /*!
  948. * \brief
  949. * Register a config hook for a particular file and module
  950. *
  951. * \param name The name of the hook you are registering.
  952. * \param filename The file whose config you wish to hook into.
  953. * \param module The module that is reloading the config. This
  954. * can be useful if multiple modules may possibly
  955. * reload the same file, but you are only interested
  956. * when a specific module reloads the file
  957. * \param flags Flags that affect the way hooks work.
  958. * \param hook The callback to be called when config is loaded.
  959. * return 0 Success
  960. * return -1 Unsuccess, also known as UTTER AND COMPLETE FAILURE
  961. */
  962. int ast_config_hook_register(const char *name,
  963. const char *filename,
  964. const char *module,
  965. enum config_hook_flags flags,
  966. config_hook_cb hook);
  967. /*!
  968. * \brief
  969. * Unregister a config hook
  970. *
  971. * \param name The name of the hook to unregister
  972. */
  973. void ast_config_hook_unregister(const char *name);
  974. /*!
  975. * \brief Support code to parse config file arguments
  976. *
  977. * \details
  978. * The function ast_parse_arg() provides a generic interface to parse
  979. * strings (e.g. numbers, network addresses and so on) in a flexible
  980. * way, e.g. by doing proper error and bound checks, provide default
  981. * values, and so on.
  982. * The function (described later) takes a string as an argument,
  983. * a set of flags to specify the result format and checks to perform,
  984. * a pointer to the result, and optionally some additional arguments.
  985. *
  986. * \return It returns 0 on success, != 0 otherwise.
  987. */
  988. enum ast_parse_flags {
  989. /* low 4 bits of flags are used for the operand type */
  990. PARSE_TYPE = 0x000f,
  991. /* numeric types, with optional default value and bound checks.
  992. * Additional arguments are passed by value.
  993. */
  994. PARSE_INT32 = 0x0001,
  995. PARSE_UINT32 = 0x0002,
  996. PARSE_DOUBLE = 0x0003,
  997. #if 0 /* not supported yet */
  998. PARSE_INT16 = 0x0004,
  999. PARSE_UINT16 = 0x0005,
  1000. #endif
  1001. /* Returns an int processed by ast_app_parse_timelen.
  1002. * The first argument is an enum ast_timelen value (required).
  1003. */
  1004. PARSE_TIMELEN = 0x0006,
  1005. /* Returns a struct ast_sockaddr, with optional default value
  1006. * (passed by reference) and port handling (accept, ignore,
  1007. * require, forbid). The format is 'ipaddress[:port]'. IPv6 address
  1008. * literals need square brackets around them if a port is specified.
  1009. */
  1010. PARSE_ADDR = 0x000e,
  1011. /* Returns a struct sockaddr_in, with optional default value
  1012. * (passed by reference) and port handling (accept, ignore,
  1013. * require, forbid). The format is 'host.name[:port]'
  1014. */
  1015. PARSE_INADDR = 0x000f,
  1016. /* Other data types can be added as needed */
  1017. /* If PARSE_DEFAULT is set, next argument is a default value
  1018. * which is returned in case of error. The argument is passed
  1019. * by value in case of numeric types, by reference in other cases.
  1020. */
  1021. PARSE_DEFAULT = 0x0010, /* assign default on error */
  1022. /* Request a range check, applicable to numbers. Two additional
  1023. * arguments are passed by value, specifying the low-high end of
  1024. * the range (inclusive). An error is returned if the value
  1025. * is outside or inside the range, respectively.
  1026. */
  1027. PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
  1028. PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
  1029. PARSE_RANGE_DEFAULTS = 0x0080, /* default to range min/max on range error */
  1030. /* Port handling, for ast_sockaddr. accept/ignore/require/forbid
  1031. * port number after the hostname or address.
  1032. */
  1033. PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
  1034. PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */
  1035. PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
  1036. PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */
  1037. };
  1038. /*!
  1039. * \brief The argument parsing routine.
  1040. *
  1041. * \param arg the string to parse. It is not modified.
  1042. * \param flags combination of ast_parse_flags to specify the
  1043. * return type and additional checks.
  1044. * \param result pointer to the result. NULL is valid here, and can
  1045. * be used to perform only the validity checks.
  1046. * \param ... extra arguments are required according to flags.
  1047. *
  1048. * \retval 0 in case of success, != 0 otherwise.
  1049. * \retval result returns the parsed value in case of success,
  1050. * the default value in case of error, or it is left unchanged
  1051. * in case of error and no default specified. Note that in certain
  1052. * cases (e.g. sockaddr_in, with multi-field return values) some
  1053. * of the fields in result may be changed even if an error occurs.
  1054. *
  1055. * \details
  1056. * Examples of use:
  1057. * ast_parse_arg("223", PARSE_INT32|PARSE_IN_RANGE, &a, -1000, 1000);
  1058. * returns 0, a = 223
  1059. * ast_parse_arg("22345", PARSE_INT32|PARSE_IN_RANGE|PARSE_DEFAULT, &a, 9999, 10, 100);
  1060. * returns 1, a = 9999
  1061. * ast_parse_arg("22345ssf", PARSE_UINT32|PARSE_IN_RANGE, &b, 10, 100);
  1062. * returns 1, b unchanged
  1063. * ast_parse_arg("12", PARSE_UINT32|PARSE_IN_RANGE|PARSE_RANGE_DEFAULTS, &a, 1, 10);
  1064. * returns 1, a = 10
  1065. * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 1000);
  1066. * returns 0, a = 1000
  1067. * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 250000);
  1068. * returns 0, a = 223000
  1069. * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE|PARSE_DEFAULT, &a, TIMELEN_SECONDS, 9999, -1000, 250000);
  1070. * returns 0, a = 9999
  1071. * ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa);
  1072. * returns 0, sa contains address and port
  1073. * ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa);
  1074. * returns 1 because port is missing, sa contains address
  1075. */
  1076. int ast_parse_arg(const char *arg, enum ast_parse_flags flags,
  1077. void *result, ...);
  1078. /*
  1079. * Parsing config file options in C is slightly annoying because we cannot use
  1080. * string in a switch() statement, yet we need a similar behaviour, with many
  1081. * branches and a break on a matching one.
  1082. * The following somehow simplifies the job: we create a block using
  1083. * the CV_START and CV_END macros, and then within the block we can run
  1084. * actions such as "if (condition) { body; break; }"
  1085. * Additional macros are present to run simple functions (e.g. ast_copy_string)
  1086. * or to pass arguments to ast_parse_arg()
  1087. *
  1088. * As an example:
  1089. CV_START(v->name, v->value); // start the block
  1090. CV_STR("foo", x_foo); // static string
  1091. CV_DSTR("bar", y_bar); // malloc'ed string
  1092. CV_F("bar", ...); // call a generic function
  1093. CV_END; // end the block
  1094. */
  1095. /*! \brief the macro to open a block for variable parsing */
  1096. #define CV_START(__in_var, __in_val) \
  1097. do { \
  1098. const char *__var = __in_var; \
  1099. const char *__val = __in_val;
  1100. /*! \brief close a variable parsing block */
  1101. #define CV_END } while (0)
  1102. /*! \brief call a generic function if the name matches. */
  1103. #define CV_F(__pattern, __body) if (!strcasecmp((__var), __pattern)) { __body; break; }
  1104. /*!
  1105. * \brief helper macros to assign the value to a BOOL, UINT, static string and
  1106. * dynamic string
  1107. */
  1108. #define CV_BOOL(__x, __dst) CV_F(__x, (__dst) = ast_true(__val) )
  1109. #define CV_UINT(__x, __dst) CV_F(__x, (__dst) = strtoul(__val, NULL, 0) )
  1110. #define CV_STR(__x, __dst) CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst)))
  1111. #define CV_DSTR(__x, __dst) CV_F(__x, ast_free(__dst); __dst = ast_strdup(__val))
  1112. #define CV_STRFIELD(__x, __obj, __field) CV_F(__x, ast_string_field_set(__obj, __field, __val))
  1113. /*! \brief Check if require type is an integer type */
  1114. AST_INLINE_API(
  1115. int ast_rq_is_int(require_type type),
  1116. {
  1117. switch (type) {
  1118. case RQ_INTEGER1:
  1119. case RQ_UINTEGER1:
  1120. case RQ_INTEGER2:
  1121. case RQ_UINTEGER2:
  1122. case RQ_INTEGER3:
  1123. case RQ_UINTEGER3:
  1124. case RQ_INTEGER4:
  1125. case RQ_UINTEGER4:
  1126. case RQ_INTEGER8:
  1127. case RQ_UINTEGER8:
  1128. return 1;
  1129. default:
  1130. return 0;
  1131. }
  1132. }
  1133. )
  1134. /*!
  1135. * \brief Remove standard encoding from realtime values, which ensures
  1136. * that a semicolon embedded within a single value is not treated upon
  1137. * retrieval as multiple values.
  1138. * \param chunk Data to be decoded
  1139. * \return The decoded data, in the original buffer
  1140. * \since 1.8
  1141. * \warning This function modifies the original buffer
  1142. */
  1143. char *ast_realtime_decode_chunk(char *chunk);
  1144. /*!
  1145. * \brief Encodes a chunk of data for realtime
  1146. * \param dest Destination buffer
  1147. * \param maxlen Length passed through to ast_str_* functions
  1148. * \param chunk Source data to be encoded
  1149. * \return Buffer within dest
  1150. * \since 1.8
  1151. */
  1152. char *ast_realtime_encode_chunk(struct ast_str **dest, ssize_t maxlen, const char *chunk);
  1153. /*!
  1154. * \brief Tests 2 variable values to see if they match
  1155. * \since 13.9.0
  1156. *
  1157. * \param left Variable to test
  1158. * \param right Variable to match against with an optional realtime-style operator in the name
  1159. *
  1160. * \retval 1 matches
  1161. * \retval 0 doesn't match
  1162. *
  1163. * \details
  1164. *
  1165. * The values of the variables are passed to ast_strings_match.
  1166. * If right->name is suffixed with a space and an operator, that operator
  1167. * is also passed to ast_strings_match.
  1168. *
  1169. * Examples:
  1170. *
  1171. * left->name = "id" (ignored)
  1172. * left->value = "abc"
  1173. * right->name = "id regex" (id is ignored)
  1174. * right->value = "a[bdef]c"
  1175. *
  1176. * will result in ast_strings_match("abc", "regex", "a[bdef]c") which will return 1.
  1177. *
  1178. * left->name = "id" (ignored)
  1179. * left->value = "abc"
  1180. * right->name = "id" (ignored)
  1181. * right->value = "abc"
  1182. *
  1183. * will result in ast_strings_match("abc", NULL, "abc") which will return 1.
  1184. *
  1185. * See the documentation for ast_strings_match for the valid operators.
  1186. */
  1187. int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right);
  1188. /*!
  1189. * \brief Tests 2 variable lists to see if they match
  1190. * \since 13.9.0
  1191. *
  1192. * \param left Variable list to test
  1193. * \param right Variable list with an optional realtime-style operator in the names
  1194. * \param exact_match If true, all variables in left must match all variables in right
  1195. * and vice versa. This does exact value matches only. Operators aren't supported.
  1196. * Except for order, the left and right lists must be equal.
  1197. *
  1198. * If false, every variable in the right list must match some variable in the left list
  1199. * using the operators supplied. Variables in the left list that aren't in the right
  1200. * list are ignored for matching purposes.
  1201. *
  1202. * \retval 1 matches
  1203. * \retval 0 doesn't match
  1204. *
  1205. * \details
  1206. * Iterates over the variable lists calling ast_variables_match. If any match fails
  1207. * or a variable in the right list isn't in the left list, 0 is returned.
  1208. */
  1209. int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right,
  1210. int exact_match);
  1211. #if defined(__cplusplus) || defined(c_plusplus)
  1212. }
  1213. #endif
  1214. #endif /* _ASTERISK_CONFIG_H */