Add sessions_alarm

Introduce new feature: sessions_alarm.

Added new account setting: max_connections. On exceeding this number,
user will get an alert. If number is less than 1, no alert will happen.

Tests altered to fit new feature.
This commit is contained in:
John Hernandez
2023-04-13 17:16:24 +02:00
parent 9bce23e075
commit 07cc19ce10
17 changed files with 179 additions and 24 deletions

View File

@@ -57,7 +57,7 @@ account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboo
gchar* omemo_policy, GList* omemo_enabled, GList* omemo_disabled,
GList* ox_enabled, GList* pgp_enabled, gchar* pgp_keyid,
gchar* startscript, gchar* theme, gchar* tls_policy, gchar* auth_policy,
gchar* client)
gchar* client, int max_sessions)
{
ProfAccount* new_account = calloc(1, sizeof(ProfAccount));
@@ -140,6 +140,8 @@ account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboo
new_account->auth_policy = auth_policy;
new_account->max_sessions = max_sessions;
return new_account;
}

View File

@@ -72,6 +72,7 @@ typedef struct prof_account_t
gchar* tls_policy;
gchar* auth_policy;
gchar* client;
int max_sessions;
} ProfAccount;
ProfAccount* account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboolean enabled,
@@ -82,7 +83,7 @@ ProfAccount* account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_p
gchar* omemo_policy, GList* omemo_enabled, GList* omemo_disabled,
GList* ox_enabled, GList* pgp_enabled, gchar* pgp_keyid,
gchar* startscript, gchar* theme, gchar* tls_policy, gchar* auth_policy,
gchar* client);
gchar* client, int max_sessions);
char* account_create_connect_jid(ProfAccount* account);
gboolean account_eval_password(ProfAccount* account);
void account_free(ProfAccount* account);

View File

@@ -347,13 +347,15 @@ accounts_get_account(const char* const name)
gchar* auth_policy = g_key_file_get_string(accounts, name, "auth.policy", NULL);
int max_sessions = g_key_file_get_integer(accounts, name, "max.sessions", 0);
ProfAccount* new_account = account_new(g_strdup(name), jid, password, eval_password, enabled,
server, port, resource, last_presence, login_presence,
priority_online, priority_chat, priority_away, priority_xa,
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
omemo_disabled, ox_enabled, pgp_enabled, pgp_keyid,
startscript, theme, tls_policy, auth_policy, client);
startscript, theme, tls_policy, auth_policy, client, max_sessions);
return new_account;
}
@@ -568,6 +570,12 @@ accounts_set_theme(const char* const account_name, const char* const value)
_accounts_set_string_option(account_name, "theme", value);
}
void
accounts_set_max_sessions(const char* const account_name, const int value)
{
_accounts_set_int_option(account_name, "max.sessions", value);
}
void
accounts_clear_password(const char* const account_name)
{
@@ -634,6 +642,12 @@ accounts_clear_otr(const char* const account_name)
_accounts_clear_string_option(account_name, "otr.policy");
}
void
accounts_clear_max_sessions(const char* const account_name)
{
_accounts_clear_string_option(account_name, "max.sessions");
}
void
accounts_add_otr_policy(const char* const account_name, const char* const contact_jid, const char* const policy)
{
@@ -865,6 +879,24 @@ accounts_get_last_activity(const char* const account_name)
}
}
char*
accounts_get_resource(const char* const account_name)
{
if (!accounts_account_exists(account_name)) {
return NULL;
}
return g_key_file_get_string(accounts, account_name, "resource", NULL);
}
int
accounts_get_max_sessions(const char* const account_name)
{
if (!accounts_account_exists(account_name)) {
return 0;
}
return g_key_file_get_integer(accounts, account_name, "max.sessions", 0);
}
void
accounts_set_login_presence(const char* const account_name, const char* const value)
{

View File

@@ -61,6 +61,7 @@ void accounts_set_jid(const char* const account_name, const char* const value);
void accounts_set_server(const char* const account_name, const char* const value);
void accounts_set_port(const char* const account_name, const int value);
void accounts_set_resource(const char* const account_name, const char* const value);
char* accounts_get_resource(const char* const account_name);
void accounts_set_password(const char* const account_name, const char* const value);
void accounts_set_eval_password(const char* const account_name, const char* const value);
void accounts_set_muc_service(const char* const account_name, const char* const value);
@@ -89,6 +90,8 @@ void accounts_set_pgp_keyid(const char* const account_name, const char* const va
void accounts_set_script_start(const char* const account_name, const char* const value);
void accounts_set_client(const char* const account_name, const char* const value);
void accounts_set_theme(const char* const account_name, const char* const value);
void accounts_set_max_sessions(const char* const account_name, const int value);
int accounts_get_max_sessions(const char* const account_name);
void accounts_clear_password(const char* const account_name);
void accounts_clear_eval_password(const char* const account_name);
void accounts_clear_server(const char* const account_name);
@@ -100,6 +103,7 @@ void accounts_clear_client(const char* const account_name);
void accounts_clear_theme(const char* const account_name);
void accounts_clear_muc(const char* const account_name);
void accounts_clear_resource(const char* const account_name);
void accounts_clear_max_sessions(const char* const account_name);
void accounts_add_otr_policy(const char* const account_name, const char* const contact_jid, const char* const policy);
void accounts_add_omemo_state(const char* const account_name, const char* const contact_jid, gboolean enabled);
void accounts_add_ox_state(const char* const account_name, const char* const contact_jid, gboolean enabled);