astdb.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /*!
  19. * \file
  20. * \brief Persistant data storage (akin to *doze registry)
  21. */
  22. #ifndef _ASTERISK_ASTDB_H
  23. #define _ASTERISK_ASTDB_H
  24. #if defined(__cplusplus) || defined(c_plusplus)
  25. extern "C" {
  26. #endif
  27. struct ast_db_entry {
  28. struct ast_db_entry *next;
  29. char *key;
  30. char data[0];
  31. };
  32. /*! \brief Get key value specified by family/key */
  33. int ast_db_get(const char *family, const char *key, char *value, int valuelen);
  34. /*!
  35. * \brief Get key value specified by family/key as a heap allocated string.
  36. *
  37. * \details
  38. * Given a \a family and \a key, sets \a out to a pointer to a heap
  39. * allocated string. In the event of an error, \a out will be set to
  40. * NULL. The string must be freed by calling ast_free().
  41. *
  42. * \retval -1 An error occurred
  43. * \retval 0 Success
  44. */
  45. int ast_db_get_allocated(const char *family, const char *key, char **out);
  46. /*! \brief Store value addressed by family/key */
  47. int ast_db_put(const char *family, const char *key, const char *value);
  48. /*! \brief Delete entry in astdb */
  49. int ast_db_del(const char *family, const char *key);
  50. /*!
  51. * \brief Delete one or more entries in astdb
  52. *
  53. * \details
  54. * If both parameters are NULL, the entire database will be purged. If
  55. * only keytree is NULL, all entries within the family will be purged.
  56. * It is an error for keytree to have a value when family is NULL.
  57. *
  58. * \retval -1 An error occurred
  59. * \retval >= 0 Number of records deleted
  60. */
  61. int ast_db_deltree(const char *family, const char *keytree);
  62. /*!
  63. * \brief Get a list of values within the astdb tree
  64. *
  65. * \details
  66. * If family is specified, only those keys will be returned. If keytree
  67. * is specified, subkeys are expected to exist (separated from the key with
  68. * a slash). If subkeys do not exist and keytree is specified, the tree will
  69. * consist of either a single entry or NULL will be returned.
  70. *
  71. * Resulting tree should be freed by passing the return value to ast_db_freetree()
  72. * when usage is concluded.
  73. */
  74. struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree);
  75. /*!
  76. * \brief Get a list of values with the given key prefix
  77. *
  78. * \param family The family to search under
  79. * \param key_prefix The key prefix to search under
  80. *
  81. * \retval NULL An error occurred
  82. */
  83. struct ast_db_entry *ast_db_gettree_by_prefix(const char *family, const char *key_prefix);
  84. /*! \brief Free structure created by ast_db_gettree() */
  85. void ast_db_freetree(struct ast_db_entry *entry);
  86. #if defined(__cplusplus) || defined(c_plusplus)
  87. }
  88. #endif
  89. #endif /* _ASTERISK_ASTDB_H */