config_domain_aliases.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@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. #include "asterisk.h"
  19. #include <pjsip.h>
  20. #include <pjlib.h>
  21. #include "asterisk/res_pjsip.h"
  22. #include "include/res_pjsip_private.h"
  23. #include "asterisk/logger.h"
  24. #include "asterisk/sorcery.h"
  25. static void domain_alias_destroy(void *obj)
  26. {
  27. struct ast_sip_domain_alias *alias = obj;
  28. ast_string_field_free_memory(alias);
  29. }
  30. static void *domain_alias_alloc(const char *name)
  31. {
  32. struct ast_sip_domain_alias *alias;
  33. alias = ast_sorcery_generic_alloc(sizeof(*alias), domain_alias_destroy);
  34. if (!alias) {
  35. return NULL;
  36. }
  37. if (ast_string_field_init(alias, 256)) {
  38. ao2_cleanup(alias);
  39. return NULL;
  40. }
  41. return alias;
  42. }
  43. /*! \brief Apply handler for domain_alias type */
  44. static int domain_alias_apply(const struct ast_sorcery *sorcery, void *obj)
  45. {
  46. struct ast_sip_domain_alias *alias = obj;
  47. if (ast_strlen_zero(alias->domain)) {
  48. /*
  49. * What is the point of defining an alias and not saying
  50. * what is being aliased?
  51. */
  52. ast_log(LOG_ERROR, "%s '%s' missing required domain being aliased.\n",
  53. SIP_SORCERY_DOMAIN_ALIAS_TYPE, ast_sorcery_object_get_id(alias));
  54. }
  55. return 0;
  56. }
  57. /*! \brief Initialize sorcery with domain alias support */
  58. int ast_sip_initialize_sorcery_domain_alias(void)
  59. {
  60. struct ast_sorcery *sorcery = ast_sip_get_sorcery();
  61. ast_sorcery_apply_default(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "config", "pjsip.conf,criteria=type=domain_alias");
  62. if (ast_sorcery_object_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE,
  63. domain_alias_alloc, NULL, domain_alias_apply)) {
  64. return -1;
  65. }
  66. ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "type", "",
  67. OPT_NOOP_T, 0, 0);
  68. ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "domain",
  69. "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_domain_alias, domain));
  70. return 0;
  71. }