ts_handlers.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2014 Federico Cabiddu ([email protected])
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. #include <string.h>
  22. #include "ts_hash.h"
  23. #include "ts_handlers.h"
  24. extern struct tm_binds _tmb;
  25. /*!
  26. * \brief add transaction structure to tm callbacks
  27. * \param t current transaction
  28. * \param req current sip request
  29. * \param tma_t current transaction
  30. * \return 0 on success, -1 on failure
  31. */
  32. int ts_set_tm_callbacks(struct cell *t, sip_msg_t *req, ts_transaction_t *ts)
  33. {
  34. ts_transaction_t* ts_clone;
  35. if(t==NULL)
  36. return -1;
  37. if ( (ts_clone=clone_ts_transaction(ts)) < 0 ) {
  38. LM_ERR("failed to clone transaction\n");
  39. return -1;
  40. }
  41. if (ts_clone == NULL) {
  42. LM_ERR("transaction clone null\n");
  43. }
  44. if ( _tmb.register_tmcb( req, t,TMCB_DESTROY,
  45. ts_onreply, (void*)ts_clone, free_ts_transaction)<0 ) {
  46. LM_ERR("failed to register TMCB for transaction %d:%d\n", t->hash_index, t->label);
  47. return -1;
  48. }
  49. LM_DBG("registered TMCB for transaction %d:%d\n", ts_clone->tindex, ts_clone->tlabel);
  50. return 0;
  51. }
  52. void ts_onreply(struct cell* t, int type, struct tmcb_params *param)
  53. {
  54. ts_urecord_t* _r;
  55. ts_entry_t* _e;
  56. ts_transaction_t *cb_ptr, *ptr;
  57. cb_ptr = (ts_transaction_t*)(*param->param);
  58. if (cb_ptr == NULL) {
  59. LM_DBG("NULL param for type %d\n", type);
  60. return;
  61. }
  62. if (type &(TMCB_DESTROY)) {
  63. LM_DBG("TMCB_DESTROY called for transaction %u:%u\n", cb_ptr->tindex, cb_ptr->tlabel);
  64. _r = cb_ptr->urecord;
  65. _e = _r->entry;
  66. lock_entry(_e);
  67. ptr = _r->transactions;
  68. while(ptr) {
  69. if ((ptr->tindex == cb_ptr->tindex) && (ptr->tlabel == cb_ptr->tlabel)) {
  70. remove_ts_transaction(ptr);
  71. if (_r->transactions == NULL) {
  72. LM_DBG("last transaction for %.*s, removing urecord\n", _r->ruri.len, _r->ruri.s);
  73. remove_ts_urecord(_r);
  74. }
  75. unlock_entry(_e);
  76. return;
  77. }
  78. ptr = ptr->next;
  79. }
  80. LM_DBG("transaction %u:%u not found\n",ptr->tindex, ptr->tlabel);
  81. unlock_entry(_e);
  82. } else {
  83. LM_DBG("called with uknown type %d\n", type);
  84. }
  85. return;
  86. }