ts_append.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include "../../sr_module.h"
  25. #include "../../dprint.h"
  26. #include "../../mod_fix.h"
  27. #include "../../route.h"
  28. #include "../../data_lump.h"
  29. #include "../../lib/kcore/kstats_wrapper.h"
  30. #include "../../dset.h"
  31. #include "../../script_cb.h"
  32. #include "../../parser/msg_parser.h"
  33. #include "../../parser/contact/parse_contact.h"
  34. #include "tsilo.h"
  35. #include "ts_hash.h"
  36. #include "ts_append.h"
  37. int ts_append(struct sip_msg* msg, str *ruri, char *table) {
  38. ts_urecord_t* _r;
  39. ts_transaction_t* ptr;
  40. int res;
  41. lock_entry_by_ruri(ruri);
  42. res = get_ts_urecord(ruri, &_r);
  43. if (res != 0) {
  44. LM_ERR("failed to retrieve record for %.*s\n", ruri->len, ruri->s);
  45. unlock_entry_by_ruri(ruri);
  46. return -1;
  47. }
  48. ptr = _r->transactions;
  49. while(ptr) {
  50. LM_DBG("transaction %u:%u found for %.*s, going to append branches\n",ptr->tindex, ptr->tlabel, ruri->len, ruri->s);
  51. ts_append_to(msg, ptr->tindex, ptr->tlabel, table);
  52. ptr = ptr->next;
  53. }
  54. unlock_entry_by_ruri(ruri);
  55. return 1;
  56. }
  57. int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table) {
  58. struct cell *t;
  59. struct sip_msg *orig_msg;
  60. if(_tmb.t_lookup_ident(&t, tindex, tlabel) < 0)
  61. {
  62. LM_ERR("transaction [%u:%u] not found\n",
  63. tindex, tlabel);
  64. return -1;
  65. }
  66. orig_msg = t->uas.request;
  67. if (_regapi.lookup_to_dset(orig_msg, table, NULL) != 1) {
  68. LM_DBG("transaction %u:%u: error updating dset\n", tindex, tlabel);
  69. return -1;
  70. }
  71. return _tmb.t_append_branches();
  72. }