app_db.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. * Copyright (C) 2003, Jefferson Noxon
  6. *
  7. * Mark Spencer <markster@digium.com>
  8. * Jefferson Noxon <jeff@debian.org>
  9. *
  10. * See http://www.asterisk.org for more information about
  11. * the Asterisk project. Please do not directly contact
  12. * any of the maintainers of this project for assistance;
  13. * the project provides a web site, mailing lists and IRC
  14. * channels for your use.
  15. *
  16. * This program is free software, distributed under the terms of
  17. * the GNU General Public License Version 2. See the LICENSE file
  18. * at the top of the source tree.
  19. */
  20. /*! \file
  21. *
  22. * \brief Database access functions
  23. *
  24. * \author Mark Spencer <markster@digium.com>
  25. * \author Jefferson Noxon <jeff@debian.org>
  26. *
  27. * \ingroup applications
  28. */
  29. /*** MODULEINFO
  30. <support_level>core</support_level>
  31. ***/
  32. #include "asterisk.h"
  33. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  34. #include "asterisk/file.h"
  35. #include "asterisk/channel.h"
  36. #include "asterisk/pbx.h"
  37. #include "asterisk/module.h"
  38. #include "asterisk/astdb.h"
  39. #include "asterisk/lock.h"
  40. /*** DOCUMENTATION
  41. <application name="DBdel" language="en_US">
  42. <synopsis>
  43. Delete a key from the asterisk database.
  44. </synopsis>
  45. <syntax argsep="/">
  46. <parameter name="family" required="true" />
  47. <parameter name="key" required="true" />
  48. </syntax>
  49. <description>
  50. <para>This application will delete a <replaceable>key</replaceable> from the Asterisk
  51. database.</para>
  52. <note><para>This application has been DEPRECATED in favor of the DB_DELETE function.</para></note>
  53. </description>
  54. <see-also>
  55. <ref type="function">DB_DELETE</ref>
  56. <ref type="application">DBdeltree</ref>
  57. <ref type="function">DB</ref>
  58. </see-also>
  59. </application>
  60. <application name="DBdeltree" language="en_US">
  61. <synopsis>
  62. Delete a family or keytree from the asterisk database.
  63. </synopsis>
  64. <syntax argsep="/">
  65. <parameter name="family" required="true" />
  66. <parameter name="keytree" />
  67. </syntax>
  68. <description>
  69. <para>This application will delete a <replaceable>family</replaceable> or <replaceable>keytree</replaceable>
  70. from the Asterisk database.</para>
  71. </description>
  72. <see-also>
  73. <ref type="function">DB_DELETE</ref>
  74. <ref type="application">DBdel</ref>
  75. <ref type="function">DB</ref>
  76. </see-also>
  77. </application>
  78. ***/
  79. static const char d_app[] = "DBdel";
  80. static const char dt_app[] = "DBdeltree";
  81. static int deltree_exec(struct ast_channel *chan, const char *data)
  82. {
  83. char *argv, *family, *keytree;
  84. argv = ast_strdupa(data);
  85. if (strchr(argv, '/')) {
  86. family = strsep(&argv, "/");
  87. keytree = strsep(&argv, "\0");
  88. if (!family || !keytree) {
  89. ast_debug(1, "Ignoring; Syntax error in argument\n");
  90. return 0;
  91. }
  92. if (ast_strlen_zero(keytree))
  93. keytree = 0;
  94. } else {
  95. family = argv;
  96. keytree = 0;
  97. }
  98. if (keytree) {
  99. ast_verb(3, "DBdeltree: family=%s, keytree=%s\n", family, keytree);
  100. } else {
  101. ast_verb(3, "DBdeltree: family=%s\n", family);
  102. }
  103. if (ast_db_deltree(family, keytree) < 0) {
  104. ast_verb(3, "DBdeltree: Error deleting key from database.\n");
  105. }
  106. return 0;
  107. }
  108. static int del_exec(struct ast_channel *chan, const char *data)
  109. {
  110. char *argv, *family, *key;
  111. static int deprecation_warning = 0;
  112. if (!deprecation_warning) {
  113. deprecation_warning = 1;
  114. ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
  115. }
  116. argv = ast_strdupa(data);
  117. if (strchr(argv, '/')) {
  118. family = strsep(&argv, "/");
  119. key = strsep(&argv, "\0");
  120. if (!family || !key) {
  121. ast_debug(1, "Ignoring; Syntax error in argument\n");
  122. return 0;
  123. }
  124. ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
  125. if (ast_db_del(family, key))
  126. ast_verb(3, "DBdel: Error deleting key from database.\n");
  127. } else {
  128. ast_debug(1, "Ignoring, no parameters\n");
  129. }
  130. return 0;
  131. }
  132. static int unload_module(void)
  133. {
  134. int retval;
  135. retval = ast_unregister_application(dt_app);
  136. retval |= ast_unregister_application(d_app);
  137. return retval;
  138. }
  139. static int load_module(void)
  140. {
  141. int retval;
  142. retval = ast_register_application_xml(d_app, del_exec);
  143. retval |= ast_register_application_xml(dt_app, deltree_exec);
  144. return retval;
  145. }
  146. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");