|
@@ -673,7 +673,7 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
|
|
|
|
|
|
memset(query, 0, QUERY_LEN);
|
|
|
query_str.len = snprintf(query, QUERY_LEN,
|
|
|
- "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s",
|
|
|
+ "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())",
|
|
|
user_col.len, user_col.s,
|
|
|
domain_col.len, domain_col.s,
|
|
|
table.len, table.s);
|
|
@@ -690,7 +690,7 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
|
|
|
}
|
|
|
|
|
|
static const char* ul_rpc_db_users_doc[2] = {
|
|
|
- "Tell number of different users (AoRs) in database table (db_mode!=0 only)",
|
|
|
+ "Tell number of different unexpired users (AoRs) in database table (db_mode!=0 only)",
|
|
|
0
|
|
|
};
|
|
|
|
|
@@ -727,7 +727,7 @@ static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx)
|
|
|
}
|
|
|
|
|
|
memset(query, 0, QUERY_LEN);
|
|
|
- query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s",
|
|
|
+ query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())",
|
|
|
table.len, table.s);
|
|
|
query_str.s = query;
|
|
|
if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
|
|
@@ -742,7 +742,59 @@ static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx)
|
|
|
}
|
|
|
|
|
|
static const char* ul_rpc_db_contacts_doc[2] = {
|
|
|
- "Tell number of contacts in database table (db_mode=3 only)",
|
|
|
+ "Tell number of unexpired contacts in database table (db_mode=3 only)",
|
|
|
+ 0
|
|
|
+};
|
|
|
+
|
|
|
+static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx)
|
|
|
+{
|
|
|
+ str table = {0, 0};
|
|
|
+ char query[QUERY_LEN];
|
|
|
+ str query_str;
|
|
|
+ db1_res_t* res;
|
|
|
+ int count;
|
|
|
+
|
|
|
+ if (db_mode == NO_DB) {
|
|
|
+ rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rpc->scan(ctx, "S", &table) != 1) {
|
|
|
+ rpc->fault(ctx, 500, "Not enough parameters (table to lookup)");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (table.len + 22 > QUERY_LEN) {
|
|
|
+ rpc->fault(ctx, 500, "Too long database query");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) {
|
|
|
+ rpc->fault(ctx, 500, "Database does not support raw queries");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ul_dbf.use_table(ul_dbh, &table) < 0) {
|
|
|
+ rpc->fault(ctx, 500, "Failed to use table");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(query, 0, QUERY_LEN);
|
|
|
+ query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) > 0) AND (expires <= NOW())",
|
|
|
+ table.len, table.s);
|
|
|
+ query_str.s = query;
|
|
|
+ if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
|
|
|
+ rpc->fault(ctx, 500, "Failed to query contact count");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
|
|
|
+ ul_dbf.free_result(ul_dbh, res);
|
|
|
+
|
|
|
+ rpc->add(ctx, "d", count);
|
|
|
+}
|
|
|
+
|
|
|
+static const char* ul_rpc_db_expired_contacts_doc[2] = {
|
|
|
+ "Tell number of expired contacts in database table (db_mode=3 only)",
|
|
|
0
|
|
|
};
|
|
|
|
|
@@ -755,6 +807,7 @@ rpc_export_t ul_rpc[] = {
|
|
|
{"ul.add", ul_rpc_add, ul_rpc_add_doc, 0},
|
|
|
{"ul.db_users", ul_rpc_db_users, ul_rpc_db_users_doc, 0},
|
|
|
{"ul.db_contacts", ul_rpc_db_contacts, ul_rpc_db_contacts_doc, 0},
|
|
|
+ {"ul.db_expired_contacts", ul_rpc_db_expired_contacts, ul_rpc_db_expired_contacts_doc, 0},
|
|
|
{0, 0, 0, 0}
|
|
|
};
|
|
|
|