sip_api.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012, 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. #include "asterisk.h"
  19. #include "asterisk/sip_api.h"
  20. #include "asterisk/logger.h"
  21. static const struct ast_sip_api_tech *api_provider;
  22. int ast_sipinfo_send(struct ast_channel *chan,
  23. struct ast_variable *headers,
  24. const char *content_type,
  25. const char *content,
  26. const char *useragent_filter)
  27. {
  28. if (!api_provider) {
  29. ast_log(LOG_WARNING, "Unable to send custom SIP INFO. No API provider registered\n");
  30. return -1;
  31. }
  32. return api_provider->sipinfo_send(chan, headers, content_type, content, useragent_filter);
  33. }
  34. int ast_sip_api_provider_register(const struct ast_sip_api_tech *provider)
  35. {
  36. if (api_provider) {
  37. ast_log(LOG_WARNING, "SIP provider %s has already registered. Not registering provider %s\n",
  38. api_provider->name, provider->name);
  39. return -1;
  40. }
  41. if (provider->version != AST_SIP_API_VERSION) {
  42. ast_log(LOG_WARNING, "SIP API provider version mismatch: Current version is %d but provider "
  43. "uses version %d\n", AST_SIP_API_VERSION, provider->version);
  44. return -1;
  45. }
  46. api_provider = provider;
  47. return 0;
  48. }
  49. void ast_sip_api_provider_unregister(void)
  50. {
  51. api_provider = NULL;
  52. }