global_datastores.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/global_datastores.h"
  30. #include "asterisk/linkedlists.h"
  31. static void dialed_interface_destroy(void *data)
  32. {
  33. struct ast_dialed_interface *di = NULL;
  34. AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;
  35. if (!dialed_interface_list) {
  36. return;
  37. }
  38. AST_LIST_LOCK(dialed_interface_list);
  39. while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
  40. ast_free(di);
  41. AST_LIST_UNLOCK(dialed_interface_list);
  42. AST_LIST_HEAD_DESTROY(dialed_interface_list);
  43. ast_free(dialed_interface_list);
  44. }
  45. static void *dialed_interface_duplicate(void *data)
  46. {
  47. struct ast_dialed_interface *di = NULL;
  48. AST_LIST_HEAD(, ast_dialed_interface) *old_list;
  49. AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
  50. if(!(old_list = data)) {
  51. return NULL;
  52. }
  53. if(!(new_list = ast_calloc(1, sizeof(*new_list)))) {
  54. return NULL;
  55. }
  56. AST_LIST_HEAD_INIT(new_list);
  57. AST_LIST_LOCK(old_list);
  58. AST_LIST_TRAVERSE(old_list, di, list) {
  59. struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
  60. if(!di2) {
  61. AST_LIST_UNLOCK(old_list);
  62. dialed_interface_destroy(new_list);
  63. return NULL;
  64. }
  65. strcpy(di2->interface, di->interface);
  66. AST_LIST_INSERT_TAIL(new_list, di2, list);
  67. }
  68. AST_LIST_UNLOCK(old_list);
  69. return new_list;
  70. }
  71. const struct ast_datastore_info dialed_interface_info = {
  72. .type = "dialed-interface",
  73. .destroy = dialed_interface_destroy,
  74. .duplicate = dialed_interface_duplicate,
  75. };
  76. static void secure_call_store_destroy(void *data)
  77. {
  78. struct ast_secure_call_store *store = data;
  79. ast_free(store);
  80. }
  81. static void *secure_call_store_duplicate(void *data)
  82. {
  83. struct ast_secure_call_store *old = data;
  84. struct ast_secure_call_store *new;
  85. if (!(new = ast_calloc(1, sizeof(*new)))) {
  86. return NULL;
  87. }
  88. new->signaling = old->signaling;
  89. new->media = old->media;
  90. return new;
  91. }
  92. const struct ast_datastore_info secure_call_info = {
  93. .type = "encrypt-call",
  94. .destroy = secure_call_store_destroy,
  95. .duplicate = secure_call_store_duplicate,
  96. };