moved chunk_increment() function to libstrongswan

This commit is contained in:
Martin Willi
2009-08-26 14:07:26 +02:00
parent d4df33f255
commit 500f515a64
3 changed files with 28 additions and 18 deletions
+2 -18
View File
@@ -173,22 +173,6 @@ static void status(void)
exit(0); exit(0);
} }
/**
* increment a chunk, as it would reprensent a network order integer
*/
static void increment_chunk(chunk_t chunk)
{
int i;
for (i = chunk.len - 1; i >= 0; i--)
{
if (++chunk.ptr[i] != 0)
{
return;
}
}
}
/** /**
* ipsec pool --add - add a new pool * ipsec pool --add - add a new pool
*/ */
@@ -233,7 +217,7 @@ static void add(char *name, host_t *start, host_t *end, int timeout)
{ {
break; break;
} }
increment_chunk(cur_addr); chunk_increment(cur_addr);
} }
if (db->get_driver(db) == DB_SQLITE) if (db->get_driver(db) == DB_SQLITE)
{ {
@@ -331,7 +315,7 @@ static void resize(char *name, host_t *end)
} }
while (count-- > 0) while (count-- > 0)
{ {
increment_chunk(cur_addr); chunk_increment(cur_addr);
db->execute(db, NULL, db->execute(db, NULL,
"INSERT INTO addresses (pool, address, identity, acquired, released) " "INSERT INTO addresses (pool, address, identity, acquired, released) "
"VALUES (?, ?, ?, ?, ?)", "VALUES (?, ?, ?, ?, ?)",
+18
View File
@@ -449,6 +449,24 @@ int chunk_compare(chunk_t a, chunk_t b)
return memcmp(a.ptr, b.ptr, len); return memcmp(a.ptr, b.ptr, len);
}; };
/**
* Described in header.
*/
bool chunk_increment(chunk_t chunk)
{
int i;
for (i = chunk.len - 1; i >= 0; i--)
{
if (++chunk.ptr[i] != 0)
{
return FALSE;
}
}
return TRUE;
}
/** /**
* Remove non-printable characters from a chunk. * Remove non-printable characters from a chunk.
*/ */
+8
View File
@@ -238,6 +238,14 @@ static inline bool chunk_equals(chunk_t a, chunk_t b)
a.len == b.len && memeq(a.ptr, b.ptr, a.len); a.len == b.len && memeq(a.ptr, b.ptr, a.len);
} }
/**
* Increment a chunk, as it would reprensent a network order integer.
*
* @param chunk chunk to increment
* @return TRUE if an overflow occured
*/
bool chunk_increment(chunk_t chunk);
/** /**
* Check if a chunk has printable characters only. * Check if a chunk has printable characters only.
* *