[calls] sip: media-manager: Include crypto attributes for capabilities



commit 0e57d31c1e1df17c91e5baa44b2ad88bdc888128
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Tue May 3 12:11:24 2022 +0200

    sip: media-manager: Include crypto attributes for capabilities
    
    The API is changed to accept a list of calls_srtp_crypto_attributes
    which get inserted into the SDP line.

 plugins/sip/calls-sip-call.c          |  2 +-
 plugins/sip/calls-sip-media-manager.c | 26 ++++++++++++++++++++------
 plugins/sip/calls-sip-media-manager.h |  8 ++++----
 plugins/sip/calls-sip-origin.c        |  2 +-
 tests/test-media.c                    | 26 +++++++++++++++++++-------
 5 files changed, 45 insertions(+), 19 deletions(-)
---
diff --git a/plugins/sip/calls-sip-call.c b/plugins/sip/calls-sip-call.c
index 3a6d685b..7842ef8d 100644
--- a/plugins/sip/calls-sip-call.c
+++ b/plugins/sip/calls-sip-call.c
@@ -104,7 +104,7 @@ calls_sip_call_answer (CallsCall *call)
                                                         self->ip,
                                                         rtp_port,
                                                         rtcp_port,
-                                                        FALSE,
+                                                        NULL,
                                                         self->codecs);
 
   g_assert (local_sdp);
diff --git a/plugins/sip/calls-sip-media-manager.c b/plugins/sip/calls-sip-media-manager.c
index 05d6a8cd..c6ccbe75 100644
--- a/plugins/sip/calls-sip-media-manager.c
+++ b/plugins/sip/calls-sip-media-manager.c
@@ -27,6 +27,7 @@
 #include "calls-settings.h"
 #include "calls-sip-media-manager.h"
 #include "calls-sip-media-pipeline.h"
+#include "calls-srtp-utils.h"
 #include "gst-rfc3551.h"
 #include "util.h"
 
@@ -212,7 +213,7 @@ calls_sip_media_manager_default (void)
  *
  * @self: A #CallsSipMediaManager
  * @port: Should eventually come from the ICE stack
- * @use_srtp: Whether to use srtp (not really handled)
+ * @crypto_attributes: A #GList of #calls_srtp_crypto_attribute
  * @supported_codecs: A #GList of #MediaCodecInfo
  *
  * Returns: (transfer full): string describing capabilities
@@ -223,10 +224,10 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self,
                                           const char           *own_ip,
                                           gint                  rtp_port,
                                           gint                  rtcp_port,
-                                          gboolean              use_srtp,
+                                          GList                *crypto_attributes,
                                           GList                *supported_codecs)
 {
-  char *payload_type = use_srtp ? "SAVP" : "AVP";
+  char *payload_type = crypto_attributes ? "SAVP" : "AVP";
 
   g_autoptr (GString) media_line = NULL;
   g_autoptr (GString) attribute_lines = NULL;
@@ -260,6 +261,19 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self,
                             "\r\n");
   }
 
+  for (node = crypto_attributes; node != NULL; node = node->next) {
+    calls_srtp_crypto_attribute *attr = node->data;
+    g_autoptr (GError) error = NULL;
+    g_autofree char *crypto_line =
+      calls_srtp_print_sdp_crypto_attribute(attr, &error);
+
+    if (!crypto_line) {
+      g_warning ("Could not print SDP crypto line for tag %d: %s", attr->tag, error->message);
+      continue;
+    }
+    g_string_append_printf (attribute_lines, "%s\r\n", crypto_line);
+  }
+
   g_string_append_printf (attribute_lines, "a=rtcp:%d\r\n", rtcp_port);
 
 done:
@@ -290,7 +304,7 @@ done:
  * @self: A #CallsSipMediaManager
  * @rtp_port: Port to use for RTP. Should eventually come from the ICE stack
  * @rtcp_port: Port to use for RTCP.Should eventually come from the ICE stack
- * @use_srtp: Whether to use srtp (not really handled)
+ * @crypto_attributes: A #GList of #calls_srtp_crypto_attribute
  *
  * Returns: (transfer full): string describing capabilities
  * to be used in the session description (SDP)
@@ -300,7 +314,7 @@ calls_sip_media_manager_static_capabilities (CallsSipMediaManager *self,
                                              const char           *own_ip,
                                              gint                  rtp_port,
                                              gint                  rtcp_port,
-                                             gboolean              use_srtp)
+                                             GList                *crypto_attributes)
 {
   g_return_val_if_fail (CALLS_IS_SIP_MEDIA_MANAGER (self), NULL);
 
@@ -308,7 +322,7 @@ calls_sip_media_manager_static_capabilities (CallsSipMediaManager *self,
                                                    own_ip,
                                                    rtp_port,
                                                    rtcp_port,
-                                                   use_srtp,
+                                                   crypto_attributes,
                                                    self->preferred_codecs);
 }
 
diff --git a/plugins/sip/calls-sip-media-manager.h b/plugins/sip/calls-sip-media-manager.h
index c399bb9e..6c211076 100644
--- a/plugins/sip/calls-sip-media-manager.h
+++ b/plugins/sip/calls-sip-media-manager.h
@@ -34,21 +34,21 @@ G_BEGIN_DECLS
 
 #define CALLS_TYPE_SIP_MEDIA_MANAGER (calls_sip_media_manager_get_type ())
 
-G_DECLARE_FINAL_TYPE (CallsSipMediaManager, calls_sip_media_manager, CALLS, SIP_MEDIA_MANAGER, GObject)
+G_DECLARE_FINAL_TYPE (CallsSipMediaManager, calls_sip_media_manager, CALLS, SIP_MEDIA_MANAGER, GObject);
 
 
-CallsSipMediaManager*   calls_sip_media_manager_default                 (void);
+CallsSipMediaManager  *calls_sip_media_manager_default                 (void);
 gchar                 *calls_sip_media_manager_get_capabilities        (CallsSipMediaManager *self,
                                                                         const char           *own_ip,
                                                                         gint                  rtp_port,
                                                                         gint                  rtcp_port,
-                                                                        gboolean              use_srtp,
+                                                                        GList                
*crypto_attributes,
                                                                         GList                
*supported_codecs);
 gchar                 *calls_sip_media_manager_static_capabilities     (CallsSipMediaManager *self,
                                                                         const char           *own_ip,
                                                                         gint                  rtp_port,
                                                                         gint                  rtcp_port,
-                                                                        gboolean              use_srtp);
+                                                                        GList                
*crypto_attributes);
 gboolean               calls_sip_media_manager_supports_media          (CallsSipMediaManager *self,
                                                                         const char           *media_type);
 GList                 *calls_sip_media_manager_codec_candidates        (CallsSipMediaManager *self);
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index 347841dd..582ab89b 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -280,7 +280,7 @@ add_call (CallsSipOrigin *self,
                                                              self->own_ip,
                                                              rtp_port,
                                                              rtcp_port,
-                                                             FALSE);
+                                                             NULL);
 
     g_assert (local_sdp);
 
diff --git a/tests/test-media.c b/tests/test-media.c
index c261070d..47f8c09b 100644
--- a/tests/test-media.c
+++ b/tests/test-media.c
@@ -8,6 +8,7 @@
 
 #include "calls-sip-call.h"
 #include "calls-sip-media-manager.h"
+#include "calls-srtp-utils.h"
 #include "gst-rfc3551.h"
 
 #include <gtk/gtk.h>
@@ -41,7 +42,15 @@ test_sip_media_manager_caps (void)
   CallsSipMediaManager *manager = calls_sip_media_manager_default ();
   char *sdp_message = NULL;
   GList *codecs = NULL;
+  GList *crypto_attributes;
+  calls_srtp_crypto_attribute *attr;
 
+  attr = calls_srtp_crypto_attribute_new (1);
+  attr->tag = 1;
+  attr->crypto_suite = CALLS_SRTP_SUITE_AES_128_SHA1_80;
+  calls_srtp_crypto_attribute_init_keys (attr);
+
+  crypto_attributes = g_list_append (NULL, attr);
   /* Check single codecs */
   codecs = g_list_append (NULL, media_codec_by_name ("PCMA"));
 
@@ -49,7 +58,7 @@ test_sip_media_manager_caps (void)
 
   /* PCMA RTP */
   sdp_message =
-    calls_sip_media_manager_get_capabilities (manager, NULL, 40002, 40003, FALSE, codecs);
+    calls_sip_media_manager_get_capabilities (manager, NULL, 40002, 40003, NULL, codecs);
 
   g_assert_true (sdp_message);
   g_assert_true (find_string_in_sdp_message (sdp_message,
@@ -65,7 +74,7 @@ test_sip_media_manager_caps (void)
 
   /* PCMA SRTP */
   sdp_message =
-    calls_sip_media_manager_get_capabilities (manager, NULL, 42002, 42003, TRUE, codecs);
+    calls_sip_media_manager_get_capabilities (manager, NULL, 42002, 42003, crypto_attributes, codecs);
   g_assert_true (sdp_message);
   g_assert_true (find_string_in_sdp_message (sdp_message,
                                              "m=audio 42002 RTP/SAVP 8"));
@@ -79,7 +88,7 @@ test_sip_media_manager_caps (void)
   codecs = g_list_append (NULL, media_codec_by_name ("G722"));
 
   sdp_message =
-    calls_sip_media_manager_get_capabilities (manager, NULL, 42042, 55543, FALSE, codecs);
+    calls_sip_media_manager_get_capabilities (manager, NULL, 42042, 55543, NULL, codecs);
 
   g_assert_true (sdp_message);
   g_assert_true (find_string_in_sdp_message (sdp_message,
@@ -100,7 +109,7 @@ test_sip_media_manager_caps (void)
   codecs = g_list_append (codecs, media_codec_by_name ("PCMA"));
 
   sdp_message =
-    calls_sip_media_manager_get_capabilities (manager, NULL, 33340, 33341, FALSE, codecs);
+    calls_sip_media_manager_get_capabilities (manager, NULL, 33340, 33341, NULL, codecs);
 
   g_assert_true (sdp_message);
   g_assert_true (find_string_in_sdp_message (sdp_message,
@@ -124,7 +133,7 @@ test_sip_media_manager_caps (void)
   codecs = g_list_append (codecs, media_codec_by_name ("PCMU"));
 
   sdp_message =
-    calls_sip_media_manager_get_capabilities (manager, NULL, 18098, 18099, TRUE, codecs);
+    calls_sip_media_manager_get_capabilities (manager, NULL, 18098, 18099, crypto_attributes, codecs);
 
   g_assert_true (sdp_message);
   g_assert_true (find_string_in_sdp_message (sdp_message,
@@ -139,7 +148,7 @@ test_sip_media_manager_caps (void)
   g_test_expect_message ("CallsSipMediaManager", G_LOG_LEVEL_WARNING,
                          "No supported codecs found. Can't build meaningful SDP message");
   sdp_message =
-    calls_sip_media_manager_get_capabilities (manager, NULL, 25048, 25049, FALSE, NULL);
+    calls_sip_media_manager_get_capabilities (manager, NULL, 25048, 25049, NULL, NULL);
 
   g_test_assert_expected_messages ();
   g_assert_true (sdp_message);
@@ -149,6 +158,9 @@ test_sip_media_manager_caps (void)
   g_free (sdp_message);
 
   g_debug ("no codecs test OK");
+
+  g_list_free (crypto_attributes);
+  calls_srtp_crypto_attribute_free (attr);
 }
 
 
@@ -270,7 +282,7 @@ main (int   argc,
   g_test_add_func ("/Calls/media/pipeline/start_no_codec", test_media_pipeline_start_no_codec);
   g_test_add_func ("/Calls/media/pipeline/finalized_in_call", test_media_pipeline_finalized_in_call);
 
-  ret = g_test_run();
+  ret = g_test_run ();
 
   g_assert_finalize_object (manager);
 


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