tm.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * ser osp module.
  3. *
  4. * This module enables ser 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 ser, a free SIP server.
  15. *
  16. * ser 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. * For a license to use the ser software under conditions
  22. * other than those described here, or to purchase support for this
  23. * software, please contact iptel.org by e-mail at the following addresses:
  24. * [email protected]
  25. *
  26. * ser is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License
  32. * along with this program; if not, write to the Free Software
  33. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. #include "../../modules/tm/tm_load.h"
  36. #include "tm.h"
  37. #include "destination.h"
  38. struct tm_binds osp_tmb;
  39. static void ospOnReq(struct cell* t, int type, struct tmcb_params* ps);
  40. static void ospTmcbFunc(struct cell* t, int type, struct tmcb_params* ps);
  41. /*
  42. * Load TM API
  43. * return 0 success, -1 failure
  44. */
  45. int ospInitTm(void)
  46. {
  47. load_tm_f load_tm;
  48. LOG(L_DBG, "osp: ospInitTm\n");
  49. if ((load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0)) == 0) {
  50. LOG(L_ERR, "osp: ERROR: failed to import load_tm\n");
  51. return -1;
  52. }
  53. if (load_tm(&osp_tmb) == -1) {
  54. LOG(L_ERR, "osp: ERROR: failed to load TM API\n");
  55. LOG(L_ERR, "osp: ERROR: TM is required for reporting call setup usage\n");
  56. return -1;
  57. }
  58. /* Register callbacks, listen for all incoming requests */
  59. if (osp_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, ospOnReq, 0, 0) <= 0) {
  60. LOG(L_ERR, "osp: ERROR: failed to register TMCB_REQUEST_IN callback\n");
  61. LOG(L_ERR, "osp: ERROR: TM callbacks are required for reporting call set up usage\n");
  62. return -1;
  63. }
  64. return 0;
  65. }
  66. /*
  67. * Register OSP callback function
  68. * param t
  69. * param type
  70. * param ps
  71. */
  72. static void ospOnReq(
  73. struct cell* t,
  74. int type,
  75. struct tmcb_params* ps)
  76. {
  77. int tmcb_types;
  78. LOG(L_DBG, "osp: ospOnReq\n");
  79. /* install addaitional handlers */
  80. tmcb_types =
  81. // TMCB_REQUEST_FWDED |
  82. // TMCB_RESPONSE_FWDED |
  83. TMCB_ON_FAILURE |
  84. // TMCB_LOCAL_COMPLETED |
  85. /* report on completed transactions */
  86. TMCB_RESPONSE_OUT |
  87. /* account e2e acks if configured to do so */
  88. TMCB_E2EACK_IN |
  89. /* report on missed calls */
  90. TMCB_ON_FAILURE_RO |
  91. /* get incoming replies ready for processing */
  92. // TMCB_RESPONSE_IN |
  93. 0;
  94. if (osp_tmb.register_tmcb(0, t, tmcb_types, ospTmcbFunc, 0, 0) <= 0) {
  95. LOG(L_ERR, "osp: ERROR: failed to register TM callbacks\n");
  96. LOG(L_ERR, "osp: ERROR: TM callbacks are required for reporting call setup usage\n");
  97. return;
  98. }
  99. /* Also, if that is INVITE, disallow silent t-drop */
  100. if (ps->req->REQ_METHOD == METHOD_INVITE) {
  101. LOG(L_DBG, "osp: noisy_timer set for accounting\n");
  102. t->flags |= T_NOISY_CTIMER_FLAG;
  103. }
  104. }
  105. /*
  106. * OSP callback function
  107. * param t
  108. * param type
  109. * param ps
  110. */
  111. static void ospTmcbFunc(
  112. struct cell* t,
  113. int type,
  114. struct tmcb_params* ps)
  115. {
  116. LOG(L_DBG, "osp: ospTmcbFunc\n");
  117. if (type & TMCB_RESPONSE_OUT) {
  118. LOG(L_DBG, "osp: RESPONSE_OUT\n");
  119. } else if (type & TMCB_E2EACK_IN) {
  120. LOG(L_DBG, "osp: E2EACK_IN\n");
  121. } else if (type & TMCB_ON_FAILURE_RO) {
  122. LOG(L_DBG, "osp: FAILURE_RO\n");
  123. } else if (type & TMCB_RESPONSE_IN) {
  124. LOG(L_DBG, "osp: RESPONSE_IN\n");
  125. } else if (type & TMCB_REQUEST_FWDED) {
  126. LOG(L_DBG, "osp: REQUEST_FWDED\n");
  127. } else if (type & TMCB_RESPONSE_FWDED) {
  128. LOG(L_DBG, "osp: RESPONSE_FWDED\n");
  129. } else if (type & TMCB_ON_FAILURE) {
  130. LOG(L_DBG, "osp: FAILURE\n");
  131. } else if (type & TMCB_LOCAL_COMPLETED) {
  132. LOG(L_DBG, "osp: COMPLETED\n");
  133. } else {
  134. LOG(L_DBG, "osp: something else '%d'\n", type);
  135. }
  136. if (t) {
  137. ospRecordEvent(t->uac[t->nr_of_outgoings - 1].last_received, t->uas.status);
  138. } else {
  139. LOG(L_DBG, "osp: cell is empty\n");
  140. }
  141. }