[calls] sip: Gather public IP from REGISTER response and use it in SDP



commit 36880c3d34f0781811c396748f31aeddd5128031
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Fri Sep 24 09:33:38 2021 +0200

    sip: Gather public IP from REGISTER response and use it in SDP
    
    Fixes #335

 plugins/sip/calls-sip-media-manager.c | 76 ++++++++++++++++++++++++++++++++---
 plugins/sip/calls-sip-media-manager.h |  2 +
 plugins/sip/calls-sip-origin.c        |  4 ++
 3 files changed, 76 insertions(+), 6 deletions(-)
---
diff --git a/plugins/sip/calls-sip-media-manager.c b/plugins/sip/calls-sip-media-manager.c
index 605bf587..05d945fa 100644
--- a/plugins/sip/calls-sip-media-manager.c
+++ b/plugins/sip/calls-sip-media-manager.c
@@ -39,22 +39,52 @@
  * shall also manage the #CallsSipMediaPipeline objects that are in use.
  */
 
+enum {
+  PROP_0,
+  PROP_SESSION_IP,
+  PROP_LAST_PROP
+};
+static GParamSpec *props[PROP_LAST_PROP];
+
 typedef struct _CallsSipMediaManager
 {
   GObject parent;
 
+  char *session_ip;
   GList *supported_codecs;
 } CallsSipMediaManager;
 
 G_DEFINE_TYPE (CallsSipMediaManager, calls_sip_media_manager, G_TYPE_OBJECT);
 
 
+static void
+calls_sip_media_manager_set_property (GObject      *object,
+                                      guint         property_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec)
+{
+  CallsSipMediaManager *self = CALLS_SIP_MEDIA_MANAGER (object);
+
+  switch (property_id) {
+  case PROP_SESSION_IP:
+    calls_sip_media_manager_set_session_ip (self, g_value_get_string (value));
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
+  }
+}
+
+
 static void
 calls_sip_media_manager_finalize (GObject *object)
 {
+  CallsSipMediaManager *self = CALLS_SIP_MEDIA_MANAGER (object);
   gst_deinit ();
 
-  g_list_free (CALLS_SIP_MEDIA_MANAGER (object)->supported_codecs);
+  g_list_free (self->supported_codecs);
+  g_free (self->session_ip);
 
   G_OBJECT_CLASS (calls_sip_media_manager_parent_class)->finalize (object);
 }
@@ -65,7 +95,17 @@ calls_sip_media_manager_class_init (CallsSipMediaManagerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->set_property = calls_sip_media_manager_set_property;
   object_class->finalize = calls_sip_media_manager_finalize;
+
+  props[PROP_SESSION_IP] =
+    g_param_spec_string ("session-ip",
+                         "Session IP",
+                         "The public IP used as the session line in SDP",
+                         NULL,
+                         G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
 }
 
 
@@ -145,11 +185,21 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self,
   g_string_append_printf (attribute_lines, "a=rtcp:%d\r\n", port + 1);
 
  done:
-  return g_strdup_printf ("v=0\r\n"
-                          "%s\r\n"
-                          "%s\r\n",
-                          media_line->str,
-                          attribute_lines->str);
+  if (self->session_ip && *self->session_ip)
+    return g_strdup_printf ("v=0\r\n"
+                            "s=%s\r\n"
+                            "%s\r\n"
+                            "%s\r\n",
+                            self->session_ip,
+                            media_line->str,
+                            attribute_lines->str);
+  else
+    return g_strdup_printf ("v=0\r\n"
+                            "%s\r\n"
+                            "%s\r\n",
+                            media_line->str,
+                            attribute_lines->str);
+
 }
 
 
@@ -236,3 +286,17 @@ calls_sip_media_manager_get_codecs_from_sdp (CallsSipMediaManager *self,
 
   return codecs;
 }
+
+
+void
+calls_sip_media_manager_set_session_ip (CallsSipMediaManager *self,
+                                        const char           *session_ip)
+{
+  g_return_if_fail (CALLS_IS_SIP_MEDIA_MANAGER (self));
+
+  g_clear_pointer (&self->session_ip, g_free);
+  if (session_ip && *session_ip) {
+    g_debug ("Setting session IP to %s", session_ip);
+    self->session_ip = g_strdup (session_ip);
+  }
+}
diff --git a/plugins/sip/calls-sip-media-manager.h b/plugins/sip/calls-sip-media-manager.h
index 0fecaced..428c49d2 100644
--- a/plugins/sip/calls-sip-media-manager.h
+++ b/plugins/sip/calls-sip-media-manager.h
@@ -51,5 +51,7 @@ MediaCodecInfo*       get_best_codec                                        (Cal
 GList *               calls_sip_media_manager_codec_candidates              (CallsSipMediaManager *self);
 GList *               calls_sip_media_manager_get_codecs_from_sdp           (CallsSipMediaManager *self,
                                                                              sdp_media_t          
*sdp_media);
+void                  calls_sip_media_manager_set_session_ip                (CallsSipMediaManager *self,
+                                                                             const char           
*session_ip);
 
 G_END_DECLS
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index 8c6cbcd0..62b87aa1 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -402,6 +402,10 @@ sip_r_register (int              status,
     g_debug ("REGISTER successful");
     origin->state = CALLS_ACCOUNT_ONLINE;
     nua_get_params (nua, TAG_ANY (), TAG_END());
+    if (sip->sip_contact && sip->sip_contact->m_url && sip->sip_contact->m_url->url_host) {
+      calls_sip_media_manager_set_session_ip (origin->media_manager,
+                                              sip->sip_contact->m_url->url_host);
+    }
 
   } else if (status == 401 || status == 407) {
     sip_authenticate (origin, nh, sip);


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