config_domain_aliases.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "asterisk/logger.h"
  23. #include "asterisk/sorcery.h"
  24. static void domain_alias_destroy(void *obj)
  25. {
  26. struct ast_sip_domain_alias *alias = obj;
  27. ast_string_field_free_memory(alias);
  28. }
  29. static void *domain_alias_alloc(const char *name)
  30. {
  31. struct ast_sip_domain_alias *alias = ast_sorcery_generic_alloc(sizeof(*alias), domain_alias_destroy);
  32. if (!alias) {
  33. return NULL;
  34. }
  35. if (ast_string_field_init(alias, 256)) {
  36. ao2_cleanup(alias);
  37. return NULL;
  38. }
  39. return alias;
  40. }
  41. /*! \brief Initialize sorcery with domain alias support */
  42. int ast_sip_initialize_sorcery_domain_alias(void)
  43. {
  44. struct ast_sorcery *sorcery = ast_sip_get_sorcery();
  45. ast_sorcery_apply_default(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "config", "pjsip.conf,criteria=type=domain_alias");
  46. if (ast_sorcery_object_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, domain_alias_alloc, NULL, NULL)) {
  47. return -1;
  48. }
  49. ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "type", "",
  50. OPT_NOOP_T, 0, 0);
  51. ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "domain",
  52. "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_domain_alias, domain));
  53. return 0;
  54. }