app_db.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. if (ast_db_deltree(family, keytree))
  103. ast_verb(3, "DBdeltree: Error deleting key from database.\n");
  104. return 0;
  105. }
  106. static int del_exec(struct ast_channel *chan, const char *data)
  107. {
  108. char *argv, *family, *key;
  109. static int deprecation_warning = 0;
  110. if (!deprecation_warning) {
  111. deprecation_warning = 1;
  112. ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n");
  113. }
  114. argv = ast_strdupa(data);
  115. if (strchr(argv, '/')) {
  116. family = strsep(&argv, "/");
  117. key = strsep(&argv, "\0");
  118. if (!family || !key) {
  119. ast_debug(1, "Ignoring; Syntax error in argument\n");
  120. return 0;
  121. }
  122. ast_verb(3, "DBdel: family=%s, key=%s\n", family, key);
  123. if (ast_db_del(family, key))
  124. ast_verb(3, "DBdel: Error deleting key from database.\n");
  125. } else {
  126. ast_debug(1, "Ignoring, no parameters\n");
  127. }
  128. return 0;
  129. }
  130. static int unload_module(void)
  131. {
  132. int retval;
  133. retval = ast_unregister_application(dt_app);
  134. retval |= ast_unregister_application(d_app);
  135. return retval;
  136. }
  137. static int load_module(void)
  138. {
  139. int retval;
  140. retval = ast_register_application_xml(d_app, del_exec);
  141. retval |= ast_register_application_xml(dt_app, deltree_exec);
  142. return retval;
  143. }
  144. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions");