tm.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Kamailio osp module.
  3. *
  4. * This module enables Kamailio to communicate with an Open Settlement
  5. * Protocol (OSP) server. The Open Settlement Protocol is an ETSI
  6. * defined standard for Inter-Domain VoIP pricing, authorization
  7. * and usage exchange. The technical specifications for OSP
  8. * (ETSI TS 101 321 V4.1.1) are available at www.etsi.org.
  9. *
  10. * Uli Abend was the original contributor to this module.
  11. *
  12. * Copyright (C) 2001-2005 Fhg Fokus
  13. *
  14. * This file is part of Kamailio, a free SIP server.
  15. *
  16. * Kamailio is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version
  20. *
  21. * Kamailio is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  29. *
  30. * History:
  31. * ---------
  32. * 2006-03-13 TM functions are loaded via API function (bogdan)
  33. */
  34. #include "../../modules/tm/tm_load.h"
  35. #include "tm.h"
  36. #include "destination.h"
  37. struct tm_binds osp_tmb;
  38. static void ospOnReq(struct cell* t, int type, struct tmcb_params* ps);
  39. static void ospTmcbFunc(struct cell* t, int type, struct tmcb_params* ps);
  40. /*
  41. * Load TM API
  42. * return 0 success, -1 failure
  43. */
  44. int ospInitTm(void)
  45. {
  46. if (load_tm_api(&osp_tmb) != 0) {
  47. LM_ERR("failed to load TM API\n");
  48. LM_ERR("TM is required for reporting call setup usage\n");
  49. return -1;
  50. }
  51. /* Register callbacks, listen for all incoming requests */
  52. if (osp_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, ospOnReq, 0, 0) <= 0) {
  53. LM_ERR("failed to register TMCB_REQUEST_IN callback\n");
  54. LM_ERR("TM callbacks are required for reporting call set up usage\n");
  55. return -1;
  56. }
  57. return 0;
  58. }
  59. /*
  60. * Register OSP callback function
  61. * param t
  62. * param type
  63. * param ps
  64. */
  65. static void ospOnReq(
  66. struct cell* t,
  67. int type,
  68. struct tmcb_params* ps)
  69. {
  70. int tmcb_types;
  71. /* install addaitional handlers */
  72. tmcb_types =
  73. // TMCB_REQUEST_FWDED |
  74. // TMCB_RESPONSE_FWDED |
  75. TMCB_ON_FAILURE |
  76. // TMCB_LOCAL_COMPLETED |
  77. /* report on completed transactions */
  78. TMCB_RESPONSE_OUT |
  79. /* account e2e acks if configured to do so */
  80. TMCB_E2EACK_IN |
  81. /* report on missed calls */
  82. TMCB_ON_FAILURE_RO |
  83. /* get incoming replies ready for processing */
  84. // TMCB_RESPONSE_IN |
  85. 0;
  86. if (osp_tmb.register_tmcb(0, t, tmcb_types, ospTmcbFunc, 0, 0) <= 0) {
  87. LM_ERR("failed to register TM callbacks\n");
  88. LM_ERR("TM callbacks are required for reporting call setup usage\n");
  89. return;
  90. }
  91. }
  92. /*
  93. * OSP callback function
  94. * param t
  95. * param type
  96. * param ps
  97. */
  98. static void ospTmcbFunc(
  99. struct cell* t,
  100. int type,
  101. struct tmcb_params* ps)
  102. {
  103. if (type & TMCB_RESPONSE_OUT) {
  104. LM_DBG("RESPONSE_OUT\n");
  105. } else if (type & TMCB_E2EACK_IN) {
  106. LM_DBG("E2EACK_IN\n");
  107. } else if (type & TMCB_ON_FAILURE_RO) {
  108. LM_DBG("FAILURE_RO\n");
  109. } else if (type & TMCB_RESPONSE_IN) {
  110. LM_DBG("RESPONSE_IN\n");
  111. } else if (type & TMCB_REQUEST_FWDED) {
  112. LM_DBG("REQUEST_FWDED\n");
  113. } else if (type & TMCB_RESPONSE_FWDED) {
  114. LM_DBG("RESPONSE_FWDED\n");
  115. } else if (type & TMCB_ON_FAILURE) {
  116. LM_DBG("FAILURE\n");
  117. } else if (type & TMCB_LOCAL_COMPLETED) {
  118. LM_DBG("COMPLETED\n");
  119. } else {
  120. LM_DBG("something else '%d'\n", type);
  121. }
  122. if (t) {
  123. ospRecordEvent(t->uac[t->nr_of_outgoings - 1].last_received,
  124. t->uas.status);
  125. } else {
  126. LM_DBG("cell is empty\n");
  127. }
  128. }