[calls] sip: provider: Add argument to _add_origin() whether to store credentials



commit 3f12b3fcd5d794be7fabeeab581f0c626ec4b234
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Thu Jul 8 17:27:09 2021 +0200

    sip: provider: Add argument to _add_origin() whether to store credentials
    
    This allows us to avoid unnecessary saving to disk during initial account
    loading.

 plugins/sip/calls-sip-account-widget.c |  3 ++-
 plugins/sip/calls-sip-provider.c       | 16 +++++++++++-----
 plugins/sip/calls-sip-provider.h       |  6 ++++--
 tests/test-sip.c                       |  9 ++++++---
 4 files changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/plugins/sip/calls-sip-account-widget.c b/plugins/sip/calls-sip-account-widget.c
index 8bca7b96..032c0876 100644
--- a/plugins/sip/calls-sip-account-widget.c
+++ b/plugins/sip/calls-sip-account-widget.c
@@ -259,7 +259,8 @@ on_login_clicked (CallsSipAccountWidget *self)
                                           gtk_entry_get_text (GTK_ENTRY (self->password)),
                                           gtk_entry_get_text (GTK_ENTRY (self->display_name)),
                                           "UDP",
-                                          0);
+                                          0,
+                                          TRUE);
 
   self->origin = origin;
   update_header (self);
diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c
index c437907a..a0a184d9 100644
--- a/plugins/sip/calls-sip-provider.c
+++ b/plugins/sip/calls-sip-provider.c
@@ -147,7 +147,8 @@ new_origin_from_keyfile (CallsSipProvider *self,
                                       port,
                                       auto_connect,
                                       direct_mode,
-                                      local_port);
+                                      local_port,
+                                      FALSE);
 }
 
 
@@ -505,6 +506,7 @@ calls_sip_provider_init (CallsSipProvider *self)
  * @password: The password to use
  * @display_name: The display name
  * @transport_protocol: The transport protocol to use, can be one of "UDP", "TCP" or "TLS"
+ * @store_credentials: Whether to store credentials for this origin to disk
  *
  * Adds a new origin (SIP account)
  *
@@ -517,7 +519,8 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
                                const char       *password,
                                const char       *display_name,
                                const char       *transport_protocol,
-                               gint              port)
+                               gint              port,
+                               gboolean          store_credentials)
 {
   return calls_sip_provider_add_origin_full (self,
                                              host,
@@ -528,7 +531,8 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
                                              port,
                                              TRUE,
                                              FALSE,
-                                             0);
+                                             0,
+                                             store_credentials);
 }
 
 /**
@@ -542,6 +546,7 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
  * @auto_connect: Whether to automatically try going online
  * @direct_mode: Whether to use direct connection mode. Useful when you don't want to
  * connect to a SIP server. Mostly useful for testing and debugging.
+ * @store_credentials: Whether to store credentials for this origin to disk
  *
  * Adds a new origin (SIP account). If @direct_mode is %TRUE then @host, @user and
  * @password do not have to be set.
@@ -558,7 +563,8 @@ calls_sip_provider_add_origin_full (CallsSipProvider *self,
                                     gint              port,
                                     gboolean          auto_connect,
                                     gboolean          direct_mode,
-                                    gint              local_port)
+                                    gint              local_port,
+                                    gboolean          store_credentials)
 {
   g_autoptr (CallsSipOrigin) origin = NULL;
   g_autofree char *protocol = NULL;
@@ -593,7 +599,7 @@ calls_sip_provider_add_origin_full (CallsSipProvider *self,
 
   g_list_store_append (self->origins, origin);
 
-  if (!self->use_memory_backend)
+  if (store_credentials && !self->use_memory_backend)
     save_to_disk (self);
 
   return origin;
diff --git a/plugins/sip/calls-sip-provider.h b/plugins/sip/calls-sip-provider.h
index 348a8a72..8317bf6e 100644
--- a/plugins/sip/calls-sip-provider.h
+++ b/plugins/sip/calls-sip-provider.h
@@ -43,7 +43,8 @@ CallsSipOrigin   *calls_sip_provider_add_origin             (CallsSipProvider *s
                                                              const char       *password,
                                                              const char       *display_name,
                                                              const char       *transport_protocol,
-                                                             gint              port);
+                                                             gint              port,
+                                                             gboolean          store_credentials);
 CallsSipOrigin   *calls_sip_provider_add_origin_full        (CallsSipProvider *self,
                                                              const char       *host,
                                                              const char       *user,
@@ -53,7 +54,8 @@ CallsSipOrigin   *calls_sip_provider_add_origin_full        (CallsSipProvider *s
                                                              gint              port,
                                                              gboolean          auto_connect,
                                                              gboolean          direct_mode,
-                                                             gint              local_port);
+                                                             gint              local_port,
+                                                             gboolean          store_credentials);
 gboolean          calls_sip_provider_remove_origin          (CallsSipProvider *self,
                                                              CallsSipOrigin   *origin);
 void              calls_sip_provider_load_accounts          (CallsSipProvider *self,
diff --git a/tests/test-sip.c b/tests/test-sip.c
index d01504fb..441b6891 100644
--- a/tests/test-sip.c
+++ b/tests/test-sip.c
@@ -370,7 +370,8 @@ setup_sip_origins (SipFixture   *fixture,
                                         0,
                                         FALSE,
                                         TRUE,
-                                        5060);
+                                        5060,
+                                        FALSE);
 
   fixture->origin_bob =
     calls_sip_provider_add_origin_full (fixture->provider,
@@ -382,7 +383,8 @@ setup_sip_origins (SipFixture   *fixture,
                                         0,
                                         FALSE,
                                         TRUE,
-                                        5061);
+                                        5061,
+                                        FALSE);
 
   fixture->origin_offline =
     calls_sip_provider_add_origin_full (fixture->provider,
@@ -394,7 +396,8 @@ setup_sip_origins (SipFixture   *fixture,
                                         0,
                                         FALSE,
                                         FALSE,
-                                        0);
+                                        0,
+                                        FALSE);
 
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]