00001 #include "uri_ops.h"
00002 #include "../../id.h"
00003 #include "../../parser/parse_from.h"
00004 #include <cds/sstr.h>
00005 #include <stdio.h>
00006
00007 int is_simple_rls_target(struct sip_msg *m, char *_template, char *unused)
00008 {
00009 str from_uid;
00010 struct sip_uri furi, turi;
00011 str from_uri, to_uri;
00012 str tmp;
00013 static str sample = STR_STATIC_INIT("$uid");
00014 static str templ;
00015 int res = 1;
00016
00017 PROF_START(rls_is_simple_rls_target)
00018 if (get_from_uid(&from_uid, m) < 0) {
00019 ERR("can't get From UID\n");
00020 PROF_STOP(rls_is_simple_rls_target)
00021 return -1;
00022 }
00023
00024 if (_template) {
00025 templ.s = _template;
00026 templ.len = strlen(_template);
00027 }
00028 else {
00029 templ.s = NULL;
00030 templ.len = 0;
00031 }
00032
00033 from_uri = get_from(m)->uri;
00034 to_uri = get_to(m)->uri;
00035
00036 if (parse_uri(from_uri.s, from_uri.len, &furi) < 0) {
00037 LOG(L_ERR, "Error while parsing From URI\n");
00038 PROF_STOP(rls_is_simple_rls_target)
00039 return -1;
00040 }
00041 if (parse_uri(to_uri.s, to_uri.len, &turi) < 0) {
00042 LOG(L_ERR, "Error while parsing To URI\n");
00043 PROF_STOP(rls_is_simple_rls_target)
00044 return -1;
00045 }
00046
00047
00048 if (str_nocase_equals(&turi.host, &furi.host) != 0) {
00049
00050 DBG("different domains\n");
00051 PROF_STOP(rls_is_simple_rls_target)
00052 return -1;
00053 }
00054
00055
00056 if (replace_str(&templ, &tmp, &sample, &from_uid) < 0) {
00057 ERR("can't allocate memory\n");
00058 PROF_STOP(rls_is_simple_rls_target)
00059 return -1;
00060 }
00061
00062 if (str_nocase_equals(&turi.user, &tmp) != 0) {
00063
00064 DBG("template doesn't match\n");
00065 res = -1;
00066 }
00067
00068 str_free_content(&tmp);
00069
00070 PROF_STOP(rls_is_simple_rls_target)
00071 return res;
00072 }
00073