Commit 9e813bf4 authored by Pekka Pessi's avatar Pekka Pessi

sres: added ttl parameter to sres_set_cached_srv_priority() and sres_cache_set_srv_priority().

darcs-hash:20080122185738-65a35-adb9cd0941eabe10e13dbda63200593a08f15a46.gz
parent 3655eb78
......@@ -218,21 +218,13 @@ sres_record_t **sres_cached_answers_sockaddr(sres_resolver_t *res,
uint16_t type,
struct sockaddr const *addr);
/**Modify the priority of the specified SRV records.
*
* @param res pointer to resolver object
* @param service domain name of the SRV records to search in cache
* @param target target to lower the prio
* @param port port number to lower the prio
* @param newprio new priority value
*
* @return Number of modified records on success, -1 otherwise
*/
/**Modify the priority of the specified SRV records. */
SRESPUBFUN
int sres_set_cached_srv_priority(sres_resolver_t *res,
char const *domain,
char const *target,
uint16_t port,
uint32_t newttl,
uint16_t newprio);
......
......@@ -107,7 +107,8 @@ SRESPUBFUN int sres_cache_set_srv_priority(sres_cache_t *,
char const *domain,
char const *target,
uint16_t port,
uint16_t prio);
uint32_t newttl,
uint16_t newprio);
#ifdef __cplusplus
}
......
......@@ -1354,6 +1354,7 @@ sres_cached_answers_sockaddr(sres_resolver_t *res,
* @param target SRV target of the SRV record(s) to modify
* @param port port number of SRV record(s) to modify
* (in host byte order)
* @param ttl new ttl for SRV records of the domain
* @param priority new priority value (0=highest, 65535=lowest)
*
* @sa sres_cache_set_srv_priority()
......@@ -1364,6 +1365,7 @@ int sres_set_cached_srv_priority(sres_resolver_t *res,
char const *domain,
char const *target,
uint16_t port,
uint32_t ttl,
uint16_t priority)
{
char rooted_domain[SRES_MAXDNAME];
......@@ -1377,7 +1379,8 @@ int sres_set_cached_srv_priority(sres_resolver_t *res,
return -1;
return sres_cache_set_srv_priority(res->res_cache,
domain, target, port, priority);
domain, target, port,
ttl, priority);
}
......
......@@ -483,6 +483,7 @@ void sres_cache_clean(sres_cache_t *cache, time_t now)
* @param target SRV target of the SRV record(s) to modify
* @param port port number of SRV record(s) to modify
* (in host byte order)
* @param ttl new ttl
* @param priority new priority value (0=highest, 65535=lowest)
*
* @sa sres_set_cached_srv_priority()
......@@ -493,12 +494,14 @@ int sres_cache_set_srv_priority(sres_cache_t *cache,
char const *domain,
char const *target,
uint16_t port,
uint32_t ttl,
uint16_t priority)
{
int ret = 0;
unsigned hash;
sres_rr_hash_entry_t **iter;
time_t expires;
if (cache == NULL || domain == NULL || target == NULL)
return -1;
......@@ -507,6 +510,9 @@ int sres_cache_set_srv_priority(sres_cache_t *cache,
if (!LOCK(cache))
return -1;
time(&expires);
expires += ttl;
for (iter = sres_htable_hash(cache->cache_hash, hash);
iter && *iter;
iter = sres_htable_next(cache->cache_hash, iter)) {
......@@ -514,13 +520,17 @@ int sres_cache_set_srv_priority(sres_cache_t *cache,
if (rr && rr->sr_name &&
sres_type_srv == rr->sr_type &&
(port == 0 || rr->sr_srv->srv_port == port) &&
rr->sr_srv->srv_target &&
strcasecmp(rr->sr_srv->srv_target, target) == 0 &&
strcasecmp(rr->sr_name, domain) == 0) {
/* record found --> change priority of server */
rr->sr_srv->srv_priority = priority;
ret++;
(*iter)->rr_expires = expires;
if ((port == 0 || rr->sr_srv->srv_port == port) &&
rr->sr_srv->srv_target &&
strcasecmp(rr->sr_srv->srv_target, target) == 0) {
/* record found --> change priority of server */
rr->sr_srv->srv_priority = priority;
ret++;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment