FS-5841 --resolve

This commit is contained in:
Anthony Minessale
2013-11-22 22:52:59 +05:00
parent 22d31ef55e
commit e771a00964
2 changed files with 47 additions and 29 deletions
+43 -25
View File
@@ -2044,34 +2044,52 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_merged(const char *key, c
{
switch_xml_t xml, domain, group, x_user, x_user_dup;
switch_status_t status = SWITCH_STATUS_FALSE;
char *kdup = NULL;
char *keys[10] = {0};
int i, nkeys;
if ((status = switch_xml_locate_user_cache(key, user_name, domain_name, &x_user)) == SWITCH_STATUS_SUCCESS) {
*user = x_user;
} else if ((status = switch_xml_locate_user(key, user_name, domain_name, ip, &xml, &domain, &x_user, &group, params)) == SWITCH_STATUS_SUCCESS) {
const char *cacheable = NULL;
x_user_dup = switch_xml_dup(x_user);
switch_xml_merge_user(x_user_dup, domain, group);
cacheable = switch_xml_attr(x_user_dup, "cacheable");
if (switch_true(cacheable)) {
switch_time_t expires = 0;
switch_time_t time_now = 0;
if (switch_is_number(cacheable)) {
int cache_ms = atol(cacheable);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s for %d milliseconds\n", user_name, domain_name, cache_ms);
time_now = switch_micro_time_now();
expires = time_now + (cache_ms * 1000);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s indefinitely\n", user_name, domain_name);
}
switch_xml_user_cache(key, user_name, domain_name, x_user_dup, expires);
}
*user = x_user_dup;
switch_xml_free(xml);
if (strchr(key, ':')) {
kdup = strdup(key);
nkeys = switch_split(kdup, ':', keys);
} else {
keys[0] = (char *)key;
nkeys = 1;
}
for(i = 0; i < nkeys; i++) {
if ((status = switch_xml_locate_user_cache(keys[i], user_name, domain_name, &x_user)) == SWITCH_STATUS_SUCCESS) {
*user = x_user;
break;
} else if ((status = switch_xml_locate_user(keys[i], user_name, domain_name, ip, &xml, &domain, &x_user, &group, params)) == SWITCH_STATUS_SUCCESS) {
const char *cacheable = NULL;
x_user_dup = switch_xml_dup(x_user);
switch_xml_merge_user(x_user_dup, domain, group);
cacheable = switch_xml_attr(x_user_dup, "cacheable");
if (switch_true(cacheable)) {
switch_time_t expires = 0;
switch_time_t time_now = 0;
if (switch_is_number(cacheable)) {
int cache_ms = atol(cacheable);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s for %d milliseconds\n",
user_name, domain_name, cache_ms);
time_now = switch_micro_time_now();
expires = time_now + (cache_ms * 1000);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s indefinitely\n", user_name, domain_name);
}
switch_xml_user_cache(keys[i], user_name, domain_name, x_user_dup, expires);
}
*user = x_user_dup;
switch_xml_free(xml);
break;
}
}
switch_safe_free(kdup);
return status;
}