global_datastores.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2007, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@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. *
  20. * \brief globally-accessible datastore information and callbacks
  21. *
  22. * \author Mark Michelson <mmichelson@digium.com>
  23. */
  24. #include "asterisk.h"
  25. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  26. #include "asterisk/global_datastores.h"
  27. #include "asterisk/linkedlists.h"
  28. static void dialed_interface_destroy(void *data)
  29. {
  30. struct ast_dialed_interface *di = NULL;
  31. AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;
  32. if (!dialed_interface_list) {
  33. return;
  34. }
  35. AST_LIST_LOCK(dialed_interface_list);
  36. while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
  37. ast_free(di);
  38. AST_LIST_UNLOCK(dialed_interface_list);
  39. AST_LIST_HEAD_DESTROY(dialed_interface_list);
  40. ast_free(dialed_interface_list);
  41. }
  42. static void *dialed_interface_duplicate(void *data)
  43. {
  44. struct ast_dialed_interface *di = NULL;
  45. AST_LIST_HEAD(, ast_dialed_interface) *old_list;
  46. AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
  47. if(!(old_list = data)) {
  48. return NULL;
  49. }
  50. if(!(new_list = ast_calloc(1, sizeof(*new_list)))) {
  51. return NULL;
  52. }
  53. AST_LIST_HEAD_INIT(new_list);
  54. AST_LIST_LOCK(old_list);
  55. AST_LIST_TRAVERSE(old_list, di, list) {
  56. struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
  57. if(!di2) {
  58. AST_LIST_UNLOCK(old_list);
  59. dialed_interface_destroy(new_list);
  60. return NULL;
  61. }
  62. strcpy(di2->interface, di->interface);
  63. AST_LIST_INSERT_TAIL(new_list, di2, list);
  64. }
  65. AST_LIST_UNLOCK(old_list);
  66. return new_list;
  67. }
  68. const struct ast_datastore_info dialed_interface_info = {
  69. .type = "dialed-interface",
  70. .destroy = dialed_interface_destroy,
  71. .duplicate = dialed_interface_duplicate,
  72. };