cli: Fix create_invite's expire option.
This commit is contained in:
13
src/ssb.db.c
13
src/ssb.db.c
@ -2182,7 +2182,7 @@ const char* tf_ssb_db_get_profile_name(sqlite3* db, const char* id)
|
||||
static void _tf_ssb_db_invite_cleanup(sqlite3* db)
|
||||
{
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare(db, "DELETE FROM invites WHERE use_count = 0 OR expires < ?", -1, &statement, NULL) == SQLITE_OK)
|
||||
if (sqlite3_prepare(db, "DELETE FROM invites WHERE use_count = 0 OR (expires > 0 AND expires < ?)", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_bind_int64(statement, 1, (int64_t)time(NULL)) == SQLITE_OK)
|
||||
{
|
||||
@ -2190,7 +2190,13 @@ static void _tf_ssb_db_invite_cleanup(sqlite3* db)
|
||||
{
|
||||
if (sqlite3_changes(db))
|
||||
{
|
||||
tf_printf("Cleaned up %d used/expired invites.\n", sqlite3_changes(db));
|
||||
char buffer[2] = { 0 };
|
||||
size_t buffer_size = sizeof(buffer);
|
||||
bool verbose = uv_os_getenv("TF_SSB_VERBOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0;
|
||||
if (verbose)
|
||||
{
|
||||
tf_printf("Cleaned up %d used/expired invites.\n", sqlite3_changes(db));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -2231,7 +2237,8 @@ bool tf_ssb_db_generate_invite(sqlite3* db, const char* id, const char* host, in
|
||||
if (sqlite3_prepare(db, "INSERT INTO invites (invite_public_key, account, use_count, expires) VALUES (?, ?, ?, ?)", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_bind_text(statement, 1, public, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, id, -1, NULL) == SQLITE_OK &&
|
||||
sqlite3_bind_int(statement, 3, use_count) == SQLITE_OK && sqlite3_bind_int64(statement, 4, (int64_t)time(NULL) + expires_seconds) == SQLITE_OK)
|
||||
sqlite3_bind_int(statement, 3, use_count) == SQLITE_OK &&
|
||||
sqlite3_bind_int64(statement, 4, (expires_seconds > 0 ? (int64_t)time(NULL) : 0) + expires_seconds) == SQLITE_OK)
|
||||
{
|
||||
inserted = sqlite3_step(statement) == SQLITE_DONE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user