dlg_utils.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "../../parser/parse_rr.h"
  2. #include "dlg_mod_internal.h"
  3. #include "dlg_utils.h"
  4. #include "dlg_request.h"
  5. #include "serialize_dlg.h"
  6. #include <cds/hash_table.h>
  7. /* #include <cds/hash_functions.h> */
  8. int preset_dialog_route(dlg_t* dialog, str *route)
  9. {
  10. rr_t *old_r, *r = NULL;
  11. int res;
  12. /* check parameters */
  13. if ((!dialog) || (is_str_empty(route))) {
  14. ERR("bad parameters\n");
  15. return -1;
  16. }
  17. if (dialog->state != DLG_NEW) {
  18. ERR("Dialog is not in DLG_NEW state\n");
  19. return -1;
  20. }
  21. if (parse_rr_body(route->s, route->len, &r) < 0) {
  22. ERR("can't parse given route\n");
  23. return -1;
  24. }
  25. if (!r) {
  26. ERR("empty route\n");
  27. return -1;
  28. }
  29. old_r = dialog->route_set;
  30. dialog->route_set = NULL;
  31. res = shm_duplicate_rr(&dialog->route_set, r);
  32. if (r) free_rr(&r);
  33. if (res < 0) {
  34. /* return old routeset to its place */
  35. dialog->route_set = old_r;
  36. ERR("can't duplicate route\n");
  37. return -1;
  38. }
  39. /* free old route */
  40. if (old_r) shm_free_rr(&old_r);
  41. res = tmb.calculate_hooks(dialog);
  42. if (res < 0) {
  43. ERR("Error while calculating hooks\n");
  44. return -2;
  45. }
  46. return 0;
  47. }
  48. int bind_dlg_mod(dlg_func_t *dst)
  49. {
  50. if (!dst) return -1;
  51. /* dst->db_store = db_store_dlg;
  52. dst->db_load = db_load_dlg;*/
  53. memset(dst, 0, sizeof(*dst));
  54. dst->serialize = serialize_dlg;
  55. dst->dlg2str = dlg2str;
  56. dst->str2dlg = str2dlg;
  57. dst->preset_dialog_route = preset_dialog_route;
  58. dst->request_outside = request_outside;
  59. dst->request_inside = request_inside;
  60. dst->hash_dlg_id = hash_dlg_id;
  61. dst->cmp_dlg_ids = cmp_dlg_ids;
  62. return 0;
  63. }
  64. int cmp_dlg_ids(dlg_id_t *a, dlg_id_t *b)
  65. {
  66. if (!a) {
  67. if (!b) return -1;
  68. else return 0;
  69. }
  70. if (!b) return 1;
  71. if (str_case_equals(&a->call_id, &b->call_id) != 0) return 1;
  72. if (str_case_equals(&a->rem_tag, &b->rem_tag) != 0) return 1; /* case sensitive ? */
  73. if (str_case_equals(&a->loc_tag, &b->loc_tag) != 0) return 1; /* case sensitive ? */
  74. return 0;
  75. }
  76. unsigned int hash_dlg_id(dlg_id_t *id)
  77. {
  78. char tmp[512];
  79. int len;
  80. if (!id) return 0;
  81. len = snprintf(tmp, sizeof(tmp), "%.*s%.*s%.*s",
  82. FMT_STR(id->call_id),
  83. FMT_STR(id->rem_tag),
  84. FMT_STR(id->loc_tag));
  85. return rshash(tmp, len);
  86. }