res_pjsip_empty_info.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2016, Digium, Inc.
  5. *
  6. * Bradley Latus <brad.latus@gmail.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. /*** MODULEINFO
  19. <depend>pjproject</depend>
  20. <depend>res_pjsip</depend>
  21. <depend>res_pjsip_session</depend>
  22. <support_level>core</support_level>
  23. ***/
  24. #include "asterisk.h"
  25. ASTERISK_REGISTER_FILE()
  26. #include <pjsip.h>
  27. #include <pjsip_ua.h>
  28. #include "asterisk/res_pjsip.h"
  29. #include "asterisk/res_pjsip_session.h"
  30. #include "asterisk/module.h"
  31. static void send_response(struct ast_sip_session *session,
  32. struct pjsip_rx_data *rdata, int code)
  33. {
  34. pjsip_tx_data *tdata;
  35. pjsip_dialog *dlg = session->inv_session->dlg;
  36. if (pjsip_dlg_create_response(dlg, rdata, code, NULL, &tdata) == PJ_SUCCESS) {
  37. struct pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
  38. pjsip_dlg_send_response(dlg, tsx, tdata);
  39. }
  40. }
  41. static int empty_info_incoming_request(struct ast_sip_session *session,
  42. struct pjsip_rx_data *rdata)
  43. {
  44. if (!rdata->msg_info.ctype) {
  45. /* Need to return 200 OK on empty body */
  46. /* Some SBCs use empty INFO as a KEEPALIVE */
  47. send_response(session, rdata, 200);
  48. return 1;
  49. }
  50. /* Let another module respond */
  51. return 0;
  52. }
  53. static struct ast_sip_session_supplement empty_info_supplement = {
  54. .method = "INFO",
  55. .priority = AST_SIP_SUPPLEMENT_PRIORITY_LAST,
  56. .incoming_request = empty_info_incoming_request,
  57. };
  58. static int load_module(void)
  59. {
  60. CHECK_PJSIP_SESSION_MODULE_LOADED();
  61. ast_sip_session_register_supplement(&empty_info_supplement);
  62. return AST_MODULE_LOAD_SUCCESS;
  63. }
  64. static int unload_module(void)
  65. {
  66. ast_sip_session_unregister_supplement(&empty_info_supplement);
  67. return 0;
  68. }
  69. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Empty INFO Support",
  70. .support_level = AST_MODULE_SUPPORT_CORE,
  71. .load = load_module,
  72. .unload = unload_module,
  73. .load_pri = AST_MODPRI_APP_DEPEND,
  74. );