static GstDtlsAgent * get_agent_by_pem (const gchar * pem) { GstDtlsAgent *agent; if (!pem) { if (g_once_init_enter (&generated_cert_agent)) { GstDtlsAgent *new_agent; new_agent = g_object_new (GST_TYPE_DTLS_AGENT, "certificate", g_object_new (GST_TYPE_DTLS_CERTIFICATE, NULL), NULL); GST_DEBUG_OBJECT (generated_cert_agent, "no agent with generated cert found, creating new"); g_once_init_leave (&generated_cert_agent, new_agent); } else { GST_DEBUG_OBJECT (generated_cert_agent, "using agent with generated cert"); } agent = generated_cert_agent; g_object_ref (agent); } else { G_LOCK (agent_table); if (!agent_table) { agent_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } agent = GST_DTLS_AGENT (g_hash_table_lookup (agent_table, pem)); if (!agent) { agent = g_object_new (GST_TYPE_DTLS_AGENT, "certificate", g_object_new (GST_TYPE_DTLS_CERTIFICATE, "pem", pem, NULL), NULL); g_object_weak_ref (G_OBJECT (agent), (GWeakNotify) agent_weak_ref_notify, (gpointer) g_strdup (pem)); g_hash_table_insert (agent_table, g_strdup (pem), agent); GST_DEBUG_OBJECT (agent, "no agent found, created new"); } else { g_object_ref (agent); GST_DEBUG_OBJECT (agent, "agent found"); } G_UNLOCK (agent_table); } return agent; }
static void gst_dtls_connection_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstDtlsConnection *self = GST_DTLS_CONNECTION (object); GstDtlsAgent *agent; GstDtlsConnectionPrivate *priv = self->priv; SSL_CTX *ssl_context; switch (prop_id) { case PROP_AGENT: g_return_if_fail (!priv->ssl); agent = GST_DTLS_AGENT (g_value_get_object (value)); g_return_if_fail (GST_IS_DTLS_AGENT (agent)); ssl_context = _gst_dtls_agent_peek_context (agent); priv->ssl = SSL_new (ssl_context); g_return_if_fail (priv->ssl); priv->bio = BIO_new (BIO_s_gst_dtls_connection ()); g_return_if_fail (priv->bio); BIO_set_data (priv->bio, self); SSL_set_bio (priv->ssl, priv->bio, priv->bio); SSL_set_verify (priv->ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, openssl_verify_callback); SSL_set_ex_data (priv->ssl, connection_ex_index, self); log_state (self, "connection created"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec); } }