ts_store.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_store.h"
  37. int ts_store(struct sip_msg* msg) {
  38. struct cell *t;
  39. str ruri;
  40. ts_urecord_t* r;
  41. int res;
  42. t = _tmb.t_gett();
  43. ruri = msg->first_line.u.request.uri;
  44. LM_DBG("storing transaction %u:%u for r-uri: %.*s\n", t->hash_index, t->label, ruri.len, ruri.s);
  45. lock_entry_by_ruri(&ruri);
  46. res = get_ts_urecord(&ruri, &r);
  47. if (res < 0) {
  48. LM_ERR("failed to retrieve record for %.*s\n", ruri.len, ruri.s);
  49. unlock_entry_by_ruri(&ruri);
  50. return -1;
  51. }
  52. if (res != 0) { /* entry not found for the ruri */
  53. if (insert_ts_urecord(&ruri, &r) < 0) {
  54. LM_ERR("failed to insert new record structure\n");
  55. unlock_entry_by_ruri(&ruri);
  56. return -1;
  57. }
  58. }
  59. insert_ts_transaction(t, msg, r);
  60. unlock_entry_by_ruri(&ruri);
  61. LM_DBG("transaction %u:%u (ruri: %.*s) inserted\n", t->hash_index, t->label, ruri.len, ruri.s);
  62. return 1;
  63. }