Don't parse comma separated pool names in attr-sql

We now handle multiple pools at a deeper level, making that special
handling obsolete. Comma separated pools are parsed in stroke.
This commit is contained in:
Martin Willi
2012-08-30 16:43:44 +02:00
parent 7b83cc62e0
commit 13f11ccf46
+6 -57
View File
@@ -233,7 +233,7 @@ static host_t* get_lease(private_sql_attribute_t *this, char *name,
} }
METHOD(attribute_provider_t, acquire_address, host_t*, METHOD(attribute_provider_t, acquire_address, host_t*,
private_sql_attribute_t *this, char *names, identification_t *id, private_sql_attribute_t *this, char *name, identification_t *id,
host_t *requested) host_t *requested)
{ {
host_t *address = NULL; host_t *address = NULL;
@@ -242,60 +242,18 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
identity = get_identity(this, id); identity = get_identity(this, id);
if (identity) if (identity)
{ {
/* check for a single pool first (no concatenation and enumeration) */ pool = get_pool(this, name, &timeout);
if (strchr(names, ',') == NULL)
{
pool = get_pool(this, names, &timeout);
if (pool) if (pool)
{ {
/* check for an existing lease */ /* check for an existing lease */
address = check_lease(this, names, pool, identity); address = check_lease(this, name, pool, identity);
if (address == NULL) if (address == NULL)
{ {
/* get an unallocated address or expired lease */ /* get an unallocated address or expired lease */
address = get_lease(this, names, pool, timeout, identity);
}
}
}
else
{
enumerator_t *enumerator;
char *name;
/* in a first step check for an existing lease over all pools */
enumerator = enumerator_create_token(names, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{
pool = get_pool(this, name, &timeout);
if (pool)
{
address = check_lease(this, name, pool, identity);
if (address)
{
enumerator->destroy(enumerator);
return address;
}
}
}
enumerator->destroy(enumerator);
/* in a second step get an unallocated address or expired lease */
enumerator = enumerator_create_token(names, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{
pool = get_pool(this, name, &timeout);
if (pool)
{
address = get_lease(this, name, pool, timeout, identity); address = get_lease(this, name, pool, timeout, identity);
if (address)
{
break;
} }
} }
} }
enumerator->destroy(enumerator);
}
}
return address; return address;
} }
@@ -303,14 +261,8 @@ METHOD(attribute_provider_t, release_address, bool,
private_sql_attribute_t *this, char *name, host_t *address, private_sql_attribute_t *this, char *name, host_t *address,
identification_t *id) identification_t *id)
{ {
enumerator_t *enumerator;
bool found = FALSE;
time_t now = time(NULL);
enumerator = enumerator_create_token(name, ",", " ");
while (enumerator->enumerate(enumerator, &name))
{
u_int pool, timeout; u_int pool, timeout;
time_t now = time(NULL);
pool = get_pool(this, name, &timeout); pool = get_pool(this, name, &timeout);
if (pool) if (pool)
@@ -329,13 +281,10 @@ METHOD(attribute_provider_t, release_address, bool,
"pool = ? AND address = ?", DB_UINT, time(NULL), "pool = ? AND address = ?", DB_UINT, time(NULL),
DB_UINT, pool, DB_BLOB, address->get_address(address)) > 0) DB_UINT, pool, DB_BLOB, address->get_address(address)) > 0)
{ {
found = TRUE; return TRUE;
break;
} }
} }
} return FALSE;
enumerator->destroy(enumerator);
return found;
} }
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*, METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,