Remove CallsCredentials and adapt to changes

The provider knows best which credentials it needs and CallsCredentials
was not generic to begin with, so get rid of it.
This commit is contained in:
Evangelos Ribeiro Tzaras
2021-07-04 00:20:57 +02:00
committed by Evangelos Ribeiro Tzaras
parent 10a2046549
commit babd013bd7
16 changed files with 418 additions and 1184 deletions

View File

@@ -44,75 +44,3 @@ calls_account_provider_default_init (CallsAccountProviderInterface *iface)
{
}
/**
* calls_account_provider_add_account:
* @self: A #CallsAccountProvider
* @credentials: A #CallsCredentials
*
* Add an account.
*
* Returns: %TRUE if successfully added, %FALSE otherwise
*/
gboolean
calls_account_provider_add_account (CallsAccountProvider *self,
CallsCredentials *credentials)
{
CallsAccountProviderInterface *iface;
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (self), FALSE);
iface = CALLS_ACCOUNT_PROVIDER_GET_IFACE (self);
g_return_val_if_fail (iface->add_account != NULL, FALSE);
g_debug ("Trying to add account for %s", calls_credentials_get_name (credentials));
return iface->add_account (self, credentials);
}
/**
* calls_account_provider_remove_account:
* @self: A #CallsAccountProvider
* @credentials: A #CallsCredentials
*
* Removes an account.
*
* Returns: %TRUE if successfully removed, %FALSE otherwise
*/
gboolean
calls_account_provider_remove_account (CallsAccountProvider *self,
CallsCredentials *credentials)
{
CallsAccountProviderInterface *iface;
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (self), FALSE);
iface = CALLS_ACCOUNT_PROVIDER_GET_IFACE (self);
g_return_val_if_fail (iface->remove_account != NULL, FALSE);
g_debug ("Trying to remove account from %s", calls_credentials_get_name (credentials));
return iface->remove_account (self, credentials);
}
/**
* calls_account_provider_get_account:
* @self: A #CallsAccountProvider
* @credentials: A #CallsCredentials
*
* Get the account which is using #CallsCredentials
*/
CallsAccount *
calls_account_provider_get_account (CallsAccountProvider *self,
CallsCredentials *credentials)
{
CallsAccountProviderInterface *iface;
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (self), NULL);
iface = CALLS_ACCOUNT_PROVIDER_GET_IFACE (self);
g_return_val_if_fail (iface->get_account != NULL, NULL);
g_debug ("Trying to get account from %s", calls_credentials_get_name (credentials));
return iface->get_account (self, credentials);
}

View File

@@ -24,8 +24,6 @@
#pragma once
#include "calls-account.h"
#include "calls-credentials.h"
#include "calls-provider.h"
#include <glib-object.h>
@@ -40,19 +38,7 @@ struct _CallsAccountProviderInterface
{
GTypeInterface parent_iface;
gboolean (*add_account) (CallsAccountProvider *self,
CallsCredentials *credentials);
gboolean (*remove_account) (CallsAccountProvider *self,
CallsCredentials *credentials);
CallsAccount *(*get_account) (CallsAccountProvider *self,
CallsCredentials *credentials);
};
gboolean calls_account_provider_add_account (CallsAccountProvider *self,
CallsCredentials *credentials);
gboolean calls_account_provider_remove_account (CallsAccountProvider *self,
CallsCredentials *credentials);
CallsAccount *calls_account_provider_get_account (CallsAccountProvider *self,
CallsCredentials *credentials);
G_END_DECLS

View File

@@ -22,7 +22,6 @@
*
*/
#include "calls-credentials.h"
#include "calls-account.h"
#include "enum-types.h"
@@ -31,37 +30,15 @@
* @short_description: An interface for online accounts
* @Title: CallsAccount
*
* #CallsAccount is meant to be implemented by a #CallsOrigin when
* the #CallsOrigin uses #CallsCredentials to connect to the internet.
* #CallsAccount is a type of #CallsOrigin for online accounts.
*/
enum {
SIGNAL_ACCOUNT_STATE_CHANGED,
SIGNAL_LAST_SIGNAL
};
static guint signals[SIGNAL_LAST_SIGNAL];
G_DEFINE_INTERFACE (CallsAccount, calls_account, CALLS_TYPE_ORIGIN)
static void
calls_account_default_init (CallsAccountInterface *iface)
{
signals[SIGNAL_ACCOUNT_STATE_CHANGED] =
g_signal_new ("account-state-changed",
G_TYPE_FROM_INTERFACE (iface),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
2, CALLS_TYPE_ACCOUNT_STATE, CALLS_TYPE_ACCOUNT_STATE);
g_object_interface_install_property (iface,
g_param_spec_object ("account-credentials",
"Account credentials",
"The credentials to be used for authentication",
CALLS_TYPE_CREDENTIALS,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property (iface,
g_param_spec_enum ("account-state",
"Account state",

View File

@@ -1,417 +0,0 @@
/*
* Copyright (C) 2021 Purism SPC
*
* This file is part of Calls.
*
* Calls is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calls is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#define G_LOG_DOMAIN "CallsCredentials"
#include "calls-credentials.h"
/**
* SECTION:Credentials
* @short_description: Credentials for online accounts
* @Title: CallsCredentials
*
* #CallsCredentials represents account credentials f.e. for SIP.
*/
enum {
PROP_0,
PROP_NAME,
PROP_ACC_HOST,
PROP_ACC_DISPLAY_NAME,
PROP_ACC_USER,
PROP_ACC_PASSWORD,
PROP_ACC_PORT,
PROP_ACC_PROTOCOL,
PROP_ACC_AUTO_CONNECT,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
enum {
SIGNAL_ACCOUNT_UPDATED,
SIGNAL_LAST_SIGNAL,
};
static guint signals[SIGNAL_LAST_SIGNAL];
struct _CallsCredentials
{
GObject parent_instance;
char *name;
/* Account information */
char *host;
char *display_name;
char *user;
char *password;
gint port;
char *transport_protocol;
gboolean auto_connect;
};
G_DEFINE_TYPE (CallsCredentials, calls_credentials, G_TYPE_OBJECT)
static gboolean
check_required_keys (GKeyFile *key_file,
const gchar *group_name)
{
gchar *keys[] = {
"User",
"Password",
"Host",
};
g_assert (group_name);
g_assert (g_key_file_has_group (key_file, group_name));
for (gsize i = 0; i < G_N_ELEMENTS (keys); i++) {
if (!g_key_file_has_key (key_file, group_name, keys[i], NULL))
return FALSE;
}
return TRUE;
}
static void
calls_credentials_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CallsCredentials *self = CALLS_CREDENTIALS (object);
switch (property_id) {
case PROP_NAME:
g_free (self->name);
self->name = g_value_dup_string (value);
break;
case PROP_ACC_HOST:
g_free (self->host);
self->host = g_value_dup_string (value);
break;
case PROP_ACC_DISPLAY_NAME:
g_free (self->display_name);
self->display_name = g_value_dup_string (value);
break;
case PROP_ACC_USER:
g_free (self->user);
self->user = g_value_dup_string (value);
break;
case PROP_ACC_PASSWORD:
g_free (self->password);
self->password = g_value_dup_string (value);
break;
case PROP_ACC_PORT:
self->port = g_value_get_int (value);
break;
case PROP_ACC_PROTOCOL:
g_free (self->transport_protocol);
self->transport_protocol = g_value_dup_string (value);
break;
case PROP_ACC_AUTO_CONNECT:
self->auto_connect = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
calls_credentials_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsCredentials *self = CALLS_CREDENTIALS (object);
switch (property_id) {
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_ACC_HOST:
g_value_set_string (value, self->host);
break;
case PROP_ACC_DISPLAY_NAME:
g_value_set_string (value, self->display_name);
break;
case PROP_ACC_USER:
g_value_set_string (value, self->user);
break;
case PROP_ACC_PASSWORD:
g_value_set_string (value, self->password);
break;
case PROP_ACC_PORT:
g_value_set_int (value, self->port);
break;
case PROP_ACC_PROTOCOL:
g_value_set_string (value, self->transport_protocol);
break;
case PROP_ACC_AUTO_CONNECT:
g_value_set_boolean (value, self->auto_connect);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
calls_credentials_finalize (GObject *object)
{
CallsCredentials *self = CALLS_CREDENTIALS (object);
g_free (self->name);
g_free (self->host);
g_free (self->display_name);
g_free (self->user);
g_free (self->password);
g_free (self->transport_protocol);
G_OBJECT_CLASS (calls_credentials_parent_class)->finalize (object);
}
static void
calls_credentials_class_init (CallsCredentialsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = calls_credentials_set_property;
object_class->get_property = calls_credentials_get_property;
object_class->finalize = calls_credentials_finalize;
props[PROP_NAME] =
g_param_spec_string ("name",
"Name",
"The name for this set of credentials",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_HOST] =
g_param_spec_string ("host",
"Host",
"The host to connect to",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_DISPLAY_NAME] =
g_param_spec_string ("display-name",
"Display name",
"The display name",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_USER] =
g_param_spec_string ("user",
"User",
"The username",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_PASSWORD] =
g_param_spec_string ("password",
"Password",
"The password",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_PORT] =
g_param_spec_int ("port",
"Port",
"The port to connect to",
0, 65535, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_PROTOCOL] =
g_param_spec_string ("protocol",
"Protocol",
"The transport protocol to use for the connection",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_ACC_AUTO_CONNECT] =
g_param_spec_boolean ("auto-connect",
"Auto connect",
"Whether to connect automatically",
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
signals[SIGNAL_ACCOUNT_UPDATED] =
g_signal_new ("account-updated",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
0);
}
static void
calls_credentials_init (CallsCredentials *self)
{
}
CallsCredentials *
calls_credentials_new (void)
{
return g_object_new (CALLS_TYPE_CREDENTIALS, NULL);
}
/**
* calls_credentials_update_from_keyfile:
* @self: A #CallsCredentials
* @key_file: A #GKeyFile
* @name: The name of the credentials which doubles as the option group
*
* Updates the credentials from a given keyfile.
*
* Returns: %TRUE if credentials were updated, %FALSE otherwise
*/
gboolean
calls_credentials_update_from_keyfile (CallsCredentials *self,
GKeyFile *key_file,
const char *name)
{
char *user = NULL;
char *password = NULL;
char *host = NULL;
char *protocol = NULL;
char *display_name = NULL;
gint port = 0;
gboolean auto_connect = TRUE;
g_return_val_if_fail (CALLS_IS_CREDENTIALS (self), FALSE);
g_return_val_if_fail (name, FALSE);
g_return_val_if_fail (g_key_file_has_group (key_file, name), FALSE);
if (!check_required_keys (key_file, name)) {
g_warning ("Not all required keys found in section %s", name);
return FALSE;
}
user = g_key_file_get_string (key_file, name, "User", NULL);
password = g_key_file_get_string (key_file, name, "Password", NULL);
host = g_key_file_get_string (key_file, name, "Host", NULL);
protocol = g_key_file_get_string (key_file, name, "Protocol", NULL);
port = g_key_file_get_integer (key_file, name, "Port", NULL);
display_name = g_key_file_get_string (key_file, name, "DisplayName", NULL);
if (g_key_file_has_key (key_file, name, "AutoConnect", NULL))
auto_connect = g_key_file_get_boolean (key_file, name, "AutoConnect", NULL);
if (protocol == NULL)
protocol = g_strdup ("UDP");
if (g_strcmp0 (host, "") == 0 ||
g_strcmp0 (user, "") == 0 ||
g_strcmp0 (password, "") == 0) {
g_warning ("Host, user and password must not be empty");
g_free (user);
g_free (password);
g_free (host);
g_free (protocol);
g_free (display_name);
return FALSE;
}
g_free (self->name);
self->name = g_strdup (name);
g_free (self->host);
self->host = host;
g_free (self->user);
self->user = user;
g_free (self->password);
self->password = password;
g_free (self->transport_protocol);
self->transport_protocol = protocol;
g_free (self->display_name);
self->display_name = display_name;
self->port = port;
self->auto_connect = auto_connect;
g_debug ("Updated credentials with name %s", name);
g_signal_emit (self, signals[SIGNAL_ACCOUNT_UPDATED], 0);
return TRUE;
}
const char *
calls_credentials_get_name (CallsCredentials *self)
{
g_return_val_if_fail (CALLS_IS_CREDENTIALS (self), NULL);
return self->name;
}
void
calls_credentials_set_name (CallsCredentials *self,
const char *name)
{
g_return_if_fail (CALLS_IS_CREDENTIALS (self));
if (!name)
return;
if (g_strcmp0 (name, self->name) == 0)
return;
g_free (self->name);
self->name = g_strdup (name);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]);
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (C) 2021 Purism SPC
*
* This file is part of Calls.
*
* Calls is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calls is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#pragma once
#include <glib-object.h>
G_BEGIN_DECLS
#define CALLS_TYPE_CREDENTIALS (calls_credentials_get_type ())
G_DECLARE_FINAL_TYPE (CallsCredentials, calls_credentials, CALLS, CREDENTIALS, GObject);
CallsCredentials *calls_credentials_new (void);
gboolean calls_credentials_update_from_keyfile (CallsCredentials *self,
GKeyFile *key_file,
const char *name);
void calls_credentials_set_name (CallsCredentials *self,
const char *name);
const char *calls_credentials_get_name (CallsCredentials *self);
G_END_DECLS

View File

@@ -17,6 +17,7 @@
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Julian Sparber <julian.sparber@puri.sm>
* Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
@@ -791,58 +792,6 @@ calls_manager_is_modem_provider (CallsManager *self,
return calls_provider_is_modem (provider);
}
/**
* calls_manager_provder_add_accounts:
* @self: A #CallsManager
* @name: The name of the provider to add the account to
* @credentials: A #CallsCredentials storing the credentials of the account
*
* Returns: %TRUE if account successfully added, %FALSE otherwise
*/
gboolean
calls_manager_provider_add_account (CallsManager *self,
const char *name,
CallsCredentials *credentials)
{
CallsProvider *provider = NULL;
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
g_return_val_if_fail (name, FALSE);
g_return_val_if_fail (CALLS_IS_CREDENTIALS (credentials), FALSE);
provider = g_hash_table_lookup (self->providers, name);
g_return_val_if_fail (CALLS_IS_PROVIDER (provider), FALSE);
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (provider), FALSE);
return calls_account_provider_add_account (CALLS_ACCOUNT_PROVIDER (provider),
credentials);
}
/**
* calls_manager_provder_remove_accounts:
* @self: A #CallsManager
* @name: The name of the provider to add the account to
* @credentials: A #CallsCredentials storing the credentials of the account
*
* Returns: %TRUE if account successfully removed, %FALSE otherwise
*/
gboolean
calls_manager_provider_remove_account (CallsManager *self,
const char *name,
CallsCredentials *credentials)
{
CallsProvider *provider = NULL;
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
g_return_val_if_fail (name, FALSE);
g_return_val_if_fail (CALLS_IS_CREDENTIALS (credentials), FALSE);
provider = g_hash_table_lookup (self->providers, name);
g_return_val_if_fail (CALLS_IS_PROVIDER (provider), FALSE);
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (provider), FALSE);
return calls_account_provider_remove_account (CALLS_ACCOUNT_PROVIDER (provider),
credentials);
}
CallsManagerState
calls_manager_get_state (CallsManager *self)

View File

@@ -1,6 +1,6 @@
/* calls-manager.c
*
* Copyright (C) 2020 Purism SPC
* Copyright (C) 2020, 2021 Purism SPC
*
* This file is part of Calls.
*
@@ -18,6 +18,7 @@
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Julian Sparber <julian.sparber@puri.sm>
* Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -26,7 +27,6 @@
#include "calls-contacts-provider.h"
#include "calls-origin.h"
#include "calls-credentials.h"
#include <glib-object.h>
@@ -49,34 +49,28 @@ typedef enum
CallsManager *calls_manager_new (void);
CallsManager *calls_manager_get_default (void);
CallsContactsProvider *calls_manager_get_contacts_provider (CallsManager *self);
void calls_manager_add_provider (CallsManager *self,
const char *name);
void calls_manager_remove_provider (CallsManager *self,
const char *name);
gboolean calls_manager_has_provider (CallsManager *self,
const char *name);
gboolean calls_manager_is_modem_provider (CallsManager *self,
const char *name);
gboolean calls_manager_provider_add_account (CallsManager *self,
const char *provider,
CallsCredentials *credentials);
gboolean calls_manager_provider_remove_account (CallsManager *self,
const char *provider,
CallsCredentials *credentials);
CallsManagerState calls_manager_get_state (CallsManager *self);
GListModel *calls_manager_get_origins (CallsManager *self);
GList *calls_manager_get_calls (CallsManager *self);
void calls_manager_dial (CallsManager *self,
CallsOrigin *origin,
const char *target);
GListModel *calls_manager_get_suitable_origins (CallsManager *self,
const char *target);
const gchar *calls_manager_get_contact_name (CallsCall *call);
gboolean calls_manager_has_active_call (CallsManager *self);
void calls_manager_hang_up_all_calls (CallsManager *self);
gboolean calls_manager_has_any_provider (CallsManager *self);
const char **calls_manager_get_provider_names (CallsManager *self,
guint *length);
CallsContactsProvider *calls_manager_get_contacts_provider (CallsManager *self);
void calls_manager_add_provider (CallsManager *self,
const char *name);
void calls_manager_remove_provider (CallsManager *self,
const char *name);
gboolean calls_manager_has_provider (CallsManager *self,
const char *name);
gboolean calls_manager_is_modem_provider (CallsManager *self,
const char *name);
CallsManagerState calls_manager_get_state (CallsManager *self);
GListModel *calls_manager_get_origins (CallsManager *self);
GList *calls_manager_get_calls (CallsManager *self);
void calls_manager_dial (CallsManager *self,
CallsOrigin *origin,
const char *target);
GListModel *calls_manager_get_suitable_origins (CallsManager *self,
const char *target);
const gchar *calls_manager_get_contact_name (CallsCall *call);
gboolean calls_manager_has_active_call (CallsManager *self);
void calls_manager_hang_up_all_calls (CallsManager *self);
gboolean calls_manager_has_any_provider (CallsManager *self);
const char **calls_manager_get_provider_names (CallsManager *self,
guint *length);
G_END_DECLS

View File

@@ -106,7 +106,6 @@ calls_sources = files(['calls-message-source.c', 'calls-message-source.h',
'calls-notifier.c', 'calls-notifier.h',
'calls-contacts-box.c', 'calls-contacts-box.h',
'calls-contacts-row.c', 'calls-contacts-row.h',
'calls-credentials.c', 'calls-credentials.h',
'calls-account.c', 'calls-account.h',
'calls-account-provider.c', 'calls-account-provider.h',
'calls-settings.c', 'calls-settings.h',