[calls] sip: Store media encryption account preference to disk



commit 50e7c87a4d318794f908c0ba4e6af03aad970c95
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Fri May 13 10:30:04 2022 +0200

    sip: Store media encryption account preference to disk

 plugins/sip/calls-sip-account-widget.c | 19 +++++++++++
 plugins/sip/calls-sip-origin.c         | 21 ++++++------
 plugins/sip/calls-sip-origin.h         | 21 +++++++-----
 plugins/sip/calls-sip-provider.c       | 61 ++++++++++++++++++++++------------
 plugins/sip/calls-sip-provider.h       | 46 +++++++++++++------------
 tests/test-sip.c                       |  3 ++
 6 files changed, 108 insertions(+), 63 deletions(-)
---
diff --git a/plugins/sip/calls-sip-account-widget.c b/plugins/sip/calls-sip-account-widget.c
index 499be6e3..173f252c 100644
--- a/plugins/sip/calls-sip-account-widget.c
+++ b/plugins/sip/calls-sip-account-widget.c
@@ -126,6 +126,23 @@ get_selected_protocol (CallsSipAccountWidget *self)
 }
 
 
+static SipMediaEncryption
+get_selected_media_encryption (CallsSipAccountWidget *self)
+{
+  g_autoptr (HdyValueObject) obj = NULL;
+  SipMediaEncryption media_encryption = SIP_MEDIA_ENCRYPTION_NONE;
+  gint i;
+
+  if ((i = hdy_combo_row_get_selected_index (self->media_encryption)) != -1) {
+    obj = g_list_model_get_item (G_LIST_MODEL (self->media_encryption_store), i);
+    media_encryption = (SipMediaEncryption) GPOINTER_TO_INT (g_object_get_data (G_OBJECT (obj), "value"));
+  }
+
+
+  return media_encryption;
+}
+
+
 static void
 update_media_encryption (CallsSipAccountWidget *self)
 {
@@ -477,6 +494,7 @@ on_login_clicked (CallsSipAccountWidget *self)
                                           gtk_entry_get_text (GTK_ENTRY (self->display_name)),
                                           get_selected_protocol (self),
                                           get_port (self),
+                                          get_selected_media_encryption (self),
                                           TRUE);
 
   self->origin = origin;
@@ -510,6 +528,7 @@ on_apply_clicked (CallsSipAccountWidget *self)
                                     gtk_entry_get_text (self->display_name),
                                     get_selected_protocol (self),
                                     get_port (self),
+                                    get_selected_media_encryption (self),
                                     gtk_switch_get_state (self->tel_switch),
                                     gtk_switch_get_state (self->auto_connect_switch));
 
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index 57451de1..9ac719c5 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -1671,15 +1671,16 @@ calls_sip_origin_init (CallsSipOrigin *self)
 }
 
 void
-calls_sip_origin_set_credentials (CallsSipOrigin *self,
-                                  const char     *host,
-                                  const char     *user,
-                                  const char     *password,
-                                  const char     *display_name,
-                                  const char     *transport_protocol,
-                                  gint            port,
-                                  gboolean        can_tel,
-                                  gboolean        auto_connect)
+calls_sip_origin_set_credentials (CallsSipOrigin    *self,
+                                  const char        *host,
+                                  const char        *user,
+                                  const char        *password,
+                                  const char        *display_name,
+                                  const char        *transport_protocol,
+                                  gint               port,
+                                  SipMediaEncryption media_encryption,
+                                  gboolean           can_tel,
+                                  gboolean           auto_connect)
 {
   g_return_if_fail (CALLS_IS_SIP_ORIGIN (self));
 
@@ -1715,8 +1716,8 @@ calls_sip_origin_set_credentials (CallsSipOrigin *self,
     self->transport_protocol = g_strdup ("UDP");
 
   self->port = port;
-
   self->can_tel = can_tel;
+  self->media_encryption = media_encryption;
 
   update_name (self);
 
diff --git a/plugins/sip/calls-sip-origin.h b/plugins/sip/calls-sip-origin.h
index 95b35fef..faadfa73 100644
--- a/plugins/sip/calls-sip-origin.h
+++ b/plugins/sip/calls-sip-origin.h
@@ -24,6 +24,8 @@
 
 #pragma once
 
+#include "calls-sip-util.h"
+
 #include <glib-object.h>
 
 G_BEGIN_DECLS
@@ -32,14 +34,15 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (CallsSipOrigin, calls_sip_origin, CALLS, SIP_ORIGIN, GObject)
 
-void calls_sip_origin_set_credentials          (CallsSipOrigin *self,
-                                                const char     *host,
-                                                const char     *user,
-                                                const char     *password,
-                                                const char     *display_name,
-                                                const char     *transport_protocol,
-                                                gint            port,
-                                                gboolean        use_for_tel,
-                                                gboolean        auto_connect);
+void calls_sip_origin_set_credentials          (CallsSipOrigin    *self,
+                                                const char        *host,
+                                                const char        *user,
+                                                const char        *password,
+                                                const char        *display_name,
+                                                const char        *transport_protocol,
+                                                gint               port,
+                                                SipMediaEncryption media_encryption,
+                                                gboolean           use_for_tel,
+                                                gboolean           auto_connect);
 
 G_END_DECLS
diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c
index 6bad5ecf..1caaf76d 100644
--- a/plugins/sip/calls-sip-provider.c
+++ b/plugins/sip/calls-sip-provider.c
@@ -128,6 +128,7 @@ on_origin_pw_looked_up (GObject      *source,
   gboolean auto_connect = TRUE;
   gboolean direct_mode = FALSE;
   gboolean can_tel = FALSE;
+  SipMediaEncryption media_encryption = SIP_MEDIA_ENCRYPTION_NONE;
 
   g_assert (user_data);
 
@@ -159,6 +160,10 @@ on_origin_pw_looked_up (GObject      *source,
     can_tel =
       g_key_file_get_boolean (data->key_file, data->name, "CanTel", NULL);
 
+  if (g_key_file_has_key (data->key_file, data->name, "MediaEncryption", NULL))
+    media_encryption =
+      (SipMediaEncryption) g_key_file_get_integer (data->key_file, data->name, "MediaEncryption", NULL);
+
   /* PW */
   password = secret_password_lookup_finish (result, &error);
   if (!direct_mode && error) {
@@ -185,6 +190,7 @@ on_origin_pw_looked_up (GObject      *source,
                                       display_name,
                                       protocol,
                                       port,
+                                      media_encryption,
                                       auto_connect,
                                       direct_mode,
                                       local_port,
@@ -292,6 +298,7 @@ origin_to_keyfile (CallsSipOrigin *origin,
   gboolean auto_connect;
   gboolean direct_mode;
   gboolean can_tel;
+  SipMediaEncryption media_encryption;
 
   g_assert (CALLS_IS_SIP_ORIGIN (origin));
   g_assert (key_file);
@@ -308,6 +315,7 @@ origin_to_keyfile (CallsSipOrigin *origin,
                 "direct-mode", &direct_mode,
                 "local-port", &local_port,
                 "can-tel", &can_tel,
+                "media-encryption", &media_encryption,
                 NULL);
 
   g_key_file_set_string (key_file, name, "Id", id);
@@ -320,6 +328,7 @@ origin_to_keyfile (CallsSipOrigin *origin,
   g_key_file_set_boolean (key_file, name, "DirectMode", direct_mode);
   g_key_file_set_integer (key_file, name, "LocalPort", local_port);
   g_key_file_set_boolean (key_file, name, "CanTel", can_tel);
+  g_key_file_set_integer (key_file, name, "MediaEncryption", media_encryption);
 
   label_secret = g_strdup_printf ("Calls Password for %s", id);
 
@@ -648,6 +657,8 @@ 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"
+ * @port: The port of the host
+ * @media_encryption: A #SipMediaEncryption specifying if media should be encrypted
  * @store_credentials: Whether to store credentials for this origin to disk
  *
  * Adds a new origin (SIP account)
@@ -655,15 +666,16 @@ calls_sip_provider_init (CallsSipProvider *self)
  * Return: (transfer none): A #CallsSipOrigin
  */
 CallsSipOrigin *
-calls_sip_provider_add_origin (CallsSipProvider *self,
-                               const char       *id,
-                               const char       *host,
-                               const char       *user,
-                               const char       *password,
-                               const char       *display_name,
-                               const char       *transport_protocol,
-                               gint              port,
-                               gboolean          store_credentials)
+calls_sip_provider_add_origin (CallsSipProvider  *self,
+                               const char        *id,
+                               const char        *host,
+                               const char        *user,
+                               const char        *password,
+                               const char        *display_name,
+                               const char        *transport_protocol,
+                               gint               port,
+                               SipMediaEncryption media_encryption,
+                               gboolean           store_credentials)
 {
   return calls_sip_provider_add_origin_full (self,
                                              id,
@@ -673,6 +685,7 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
                                              display_name,
                                              transport_protocol,
                                              port,
+                                             media_encryption,
                                              TRUE,
                                              FALSE,
                                              0,
@@ -689,6 +702,8 @@ calls_sip_provider_add_origin (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"
+ * @port: The port of the host
+ * @media_encryption: A #SipMediaEncryption specifying if media should be encrypted
  * @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.
@@ -701,19 +716,20 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
  * Return: (transfer none): A #CallsSipOrigin
  */
 CallsSipOrigin *
-calls_sip_provider_add_origin_full (CallsSipProvider *self,
-                                    const char       *id,
-                                    const char       *host,
-                                    const char       *user,
-                                    const char       *password,
-                                    const char       *display_name,
-                                    const char       *transport_protocol,
-                                    gint              port,
-                                    gboolean          auto_connect,
-                                    gboolean          direct_mode,
-                                    gint              local_port,
-                                    gboolean          can_tel,
-                                    gboolean          store_credentials)
+calls_sip_provider_add_origin_full (CallsSipProvider  *self,
+                                    const char        *id,
+                                    const char        *host,
+                                    const char        *user,
+                                    const char        *password,
+                                    const char        *display_name,
+                                    const char        *transport_protocol,
+                                    gint               port,
+                                    SipMediaEncryption media_encryption,
+                                    gboolean           auto_connect,
+                                    gboolean           direct_mode,
+                                    gint               local_port,
+                                    gboolean           can_tel,
+                                    gboolean           store_credentials)
 {
   g_autoptr (CallsSipOrigin) origin = NULL;
   g_autofree char *protocol = NULL;
@@ -743,6 +759,7 @@ calls_sip_provider_add_origin_full (CallsSipProvider *self,
                          "display-name", display_name,
                          "transport-protocol", protocol ?: "UDP",
                          "port", port,
+                         "media-encryption", media_encryption,
                          "auto-connect", auto_connect,
                          "direct-mode", direct_mode,
                          "local-port", local_port,
diff --git a/plugins/sip/calls-sip-provider.h b/plugins/sip/calls-sip-provider.h
index de095d6e..d3b8313e 100644
--- a/plugins/sip/calls-sip-provider.h
+++ b/plugins/sip/calls-sip-provider.h
@@ -37,28 +37,30 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (CallsSipProvider, calls_sip_provider, CALLS, SIP_PROVIDER, CallsProvider);
 
 CallsSipProvider *calls_sip_provider_new           (void);
-CallsSipOrigin   *calls_sip_provider_add_origin    (CallsSipProvider *self,
-                                                    const char       *id,
-                                                    const char       *host,
-                                                    const char       *user,
-                                                    const char       *password,
-                                                    const char       *display_name,
-                                                    const char       *transport_protocol,
-                                                    gint              port,
-                                                    gboolean          store_credentials);
-CallsSipOrigin *calls_sip_provider_add_origin_full (CallsSipProvider *self,
-                                                    const char       *id,
-                                                    const char       *host,
-                                                    const char       *user,
-                                                    const char       *password,
-                                                    const char       *display_name,
-                                                    const char       *transport_protocol,
-                                                    gint              port,
-                                                    gboolean          auto_connect,
-                                                    gboolean          direct_mode,
-                                                    gint              local_port,
-                                                    gboolean          use_for_tel,
-                                                    gboolean          store_credentials);
+CallsSipOrigin   *calls_sip_provider_add_origin    (CallsSipProvider  *self,
+                                                    const char        *id,
+                                                    const char        *host,
+                                                    const char        *user,
+                                                    const char        *password,
+                                                    const char        *display_name,
+                                                    const char        *transport_protocol,
+                                                    gint               port,
+                                                    SipMediaEncryption media_encryption,
+                                                    gboolean           store_credentials);
+CallsSipOrigin *calls_sip_provider_add_origin_full (CallsSipProvider  *self,
+                                                    const char        *id,
+                                                    const char        *host,
+                                                    const char        *user,
+                                                    const char        *password,
+                                                    const char        *display_name,
+                                                    const char        *transport_protocol,
+                                                    gint               port,
+                                                    SipMediaEncryption media_encryption,
+                                                    gboolean           auto_connect,
+                                                    gboolean           direct_mode,
+                                                    gint               local_port,
+                                                    gboolean           use_for_tel,
+                                                    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 bbbe880d..d16a036b 100644
--- a/tests/test-sip.c
+++ b/tests/test-sip.c
@@ -371,6 +371,7 @@ setup_sip_origins (SipFixture   *fixture,
                                         NULL,
                                         NULL,
                                         0,
+                                        SIP_MEDIA_ENCRYPTION_NONE,
                                         FALSE,
                                         TRUE,
                                         5060,
@@ -386,6 +387,7 @@ setup_sip_origins (SipFixture   *fixture,
                                         NULL,
                                         NULL,
                                         0,
+                                        SIP_MEDIA_ENCRYPTION_NONE,
                                         FALSE,
                                         TRUE,
                                         5061,
@@ -401,6 +403,7 @@ setup_sip_origins (SipFixture   *fixture,
                                         NULL,
                                         "UDP",
                                         0,
+                                        SIP_MEDIA_ENCRYPTION_NONE,
                                         FALSE,
                                         FALSE,
                                         0,


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