uri_ops.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "uri_ops.h"
  2. #include "../../id.h"
  3. #include "../../parser/parse_from.h"
  4. #include <cds/sstr.h>
  5. #include <stdio.h>
  6. int is_simple_rls_target(struct sip_msg *m, char *_template, char *unused)
  7. {
  8. str from_uid;
  9. struct sip_uri furi, turi;
  10. str from_uri, to_uri;
  11. str tmp;
  12. static str sample = STR_STATIC_INIT("$uid");
  13. static str templ;
  14. int res = 1;
  15. PROF_START(rls_is_simple_rls_target)
  16. if (get_from_uid(&from_uid, m) < 0) {
  17. ERR("can't get From UID\n");
  18. PROF_STOP(rls_is_simple_rls_target)
  19. return -1;
  20. }
  21. if (_template) {
  22. templ.s = _template;
  23. templ.len = strlen(_template);
  24. }
  25. else {
  26. templ.s = NULL;
  27. templ.len = 0;
  28. }
  29. from_uri = get_from(m)->uri;
  30. to_uri = get_to(m)->uri;
  31. if (parse_uri(from_uri.s, from_uri.len, &furi) < 0) {
  32. LOG(L_ERR, "Error while parsing From URI\n");
  33. PROF_STOP(rls_is_simple_rls_target)
  34. return -1;
  35. }
  36. if (parse_uri(to_uri.s, to_uri.len, &turi) < 0) {
  37. LOG(L_ERR, "Error while parsing To URI\n");
  38. PROF_STOP(rls_is_simple_rls_target)
  39. return -1;
  40. }
  41. /* compare domains */
  42. if (str_nocase_equals(&turi.host, &furi.host) != 0) {
  43. /* not equal */
  44. DBG("different domains\n");
  45. PROF_STOP(rls_is_simple_rls_target)
  46. return -1;
  47. }
  48. /* compare usernames */
  49. if (replace_str(&templ, &tmp, &sample, &from_uid) < 0) {
  50. ERR("can't allocate memory\n");
  51. PROF_STOP(rls_is_simple_rls_target)
  52. return -1;
  53. }
  54. if (str_nocase_equals(&turi.user, &tmp) != 0) {
  55. /* not equal */
  56. DBG("template doesn't match\n");
  57. res = -1;
  58. }
  59. str_free_content(&tmp);
  60. PROF_STOP(rls_is_simple_rls_target)
  61. return res;
  62. }