From cadaa6a3e03821f816d2bab999e60c75cbaa3d12 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Tue, 9 Mar 2021 23:58:51 +0100 Subject: [PATCH] sip: use g_return_if_fail and friends only for public functions --- plugins/sip/calls-sip-media-pipeline.c | 8 +++---- plugins/sip/calls-sip-origin.c | 32 ++++++++++++++++---------- plugins/sip/calls-sip-provider.c | 2 +- plugins/sip/gst-rfc3551.c | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/plugins/sip/calls-sip-media-pipeline.c b/plugins/sip/calls-sip-media-pipeline.c index de21b3a..0b11d12 100644 --- a/plugins/sip/calls-sip-media-pipeline.c +++ b/plugins/sip/calls-sip-media-pipeline.c @@ -616,7 +616,7 @@ diagnose_used_ports_in_socket (GSocket *socket) g_warning ("Could not get local address of socket"); return; } - g_return_if_fail (G_IS_INET_SOCKET_ADDRESS (local_addr)); + g_assert (G_IS_INET_SOCKET_ADDRESS (local_addr)); local_port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (local_addr)); g_debug ("Using local port %d", local_port); @@ -625,7 +625,7 @@ diagnose_used_ports_in_socket (GSocket *socket) g_warning ("Could not get remote address of socket"); return; } - g_return_if_fail (G_IS_INET_SOCKET_ADDRESS (remote_addr)); + g_assert (G_IS_INET_SOCKET_ADDRESS (remote_addr)); remote_port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (remote_addr)); g_debug ("Using remote port %d", remote_port); @@ -640,8 +640,8 @@ diagnose_ports_in_use (CallsSipMediaPipeline *self) GSocket *socket_out; gboolean same_socket = FALSE; - g_return_if_fail (CALLS_IS_SIP_MEDIA_PIPELINE (self)); - // TODO also return if pipeline is not started yet + g_assert (CALLS_IS_SIP_MEDIA_PIPELINE (self)); + g_assert (self->is_running); g_object_get (self->rtp_src, "used-socket", &socket_in, NULL); g_object_get (self->rtp_sink, "used-socket", &socket_out, NULL); diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c index 4e0e50e..95e7811 100644 --- a/plugins/sip/calls-sip-origin.c +++ b/plugins/sip/calls-sip-origin.c @@ -219,11 +219,14 @@ sip_i_state (int status, CallsCallState state; CallsSipCall *call; - g_return_if_fail (CALLS_IS_SIP_ORIGIN (origin)); + g_assert (CALLS_IS_SIP_ORIGIN (origin)); call = g_hash_table_lookup (origin->call_handles, nh); - g_return_if_fail (call != NULL); + if (call == NULL) { + g_warning ("No call found for the current handle"); + return; + } g_debug ("The call state has changed: %03d %s", status, phrase); tl_gets (tags, @@ -355,6 +358,15 @@ sip_callback (nua_event_t event, case nua_r_bye: g_debug ("response to BYE: %03d %s", status, phrase); + if (status == 200) { + CallsSipCall *call = + CALLS_SIP_CALL (g_hash_table_lookup (origin->call_handles, nh)); + + if (call == NULL) { + g_warning ("BYE response from an unknown call"); + return; + } + } break; case nua_r_register: @@ -441,8 +453,6 @@ setup_nua (CallsSipOrigin *self) const gchar *uuid = NULL; g_autofree gchar* urn_uuid = NULL; - g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), NULL); - uuid = nua_generate_instance_identifier (self->ctx->home); urn_uuid = g_strdup_printf ("urn:uuid:%s", uuid); @@ -497,7 +507,7 @@ setup_sip_handles (CallsSipOrigin *self) CallsSipHandles *oper; g_autofree gchar *registrar_url = NULL; - g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), NULL); + g_assert (CALLS_IS_SIP_ORIGIN (self)); if (!(oper = su_zalloc (self->ctx->home, sizeof(CallsSipHandles)))) { g_warning ("cannot create handle"); @@ -517,7 +527,7 @@ setup_sip_handles (CallsSipOrigin *self) static void setup_account_for_direct_connection (CallsSipOrigin *self) { - g_return_if_fail (CALLS_IS_SIP_ORIGIN (self)); + g_assert (CALLS_IS_SIP_ORIGIN (self)); /* honour username, if previously set */ if (self->user == NULL) @@ -545,7 +555,7 @@ setup_account_for_direct_connection (CallsSipOrigin *self) static gboolean is_account_complete (CallsSipOrigin *self) { - g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), FALSE); + g_assert (CALLS_IS_SIP_ORIGIN (self)); /* we need only need to check for password if needing to authenticate over a proxy/UAS */ if (self->user == NULL || @@ -565,8 +575,6 @@ init_sip_account (CallsSipOrigin *self, { gboolean recoverable = FALSE; - g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), FALSE); - if (self->use_direct_connection) { g_debug ("Direct connection case. Using user and hostname"); setup_account_for_direct_connection (self); @@ -677,14 +685,14 @@ on_call_state_changed_cb (CallsSipOrigin *self, CallsCallState old_state, CallsCall *call) { + g_assert (CALLS_IS_SIP_ORIGIN (self)); + g_assert (CALLS_IS_CALL (call)); + if (new_state != CALLS_CALL_STATE_DISCONNECTED) { return; } - g_assert (CALLS_IS_SIP_ORIGIN (self)); - g_assert (CALLS_IS_CALL (call)); - remove_call (self, call, "Disconnected"); } diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c index 90f5d47..87ec28b 100644 --- a/plugins/sip/calls-sip-provider.c +++ b/plugins/sip/calls-sip-provider.c @@ -233,7 +233,7 @@ calls_sip_provider_init_sofia (CallsSipProvider *self, { GSource *gsource; - g_return_val_if_fail (CALLS_IS_SIP_PROVIDER (self), FALSE); + g_assert (CALLS_SIP_PROVIDER (self)); self->ctx = g_new0 (CallsSipContext, 1); if (self->ctx == NULL) { diff --git a/plugins/sip/gst-rfc3551.c b/plugins/sip/gst-rfc3551.c index 786a857..2481359 100644 --- a/plugins/sip/gst-rfc3551.c +++ b/plugins/sip/gst-rfc3551.c @@ -40,7 +40,7 @@ static MediaCodecInfo gst_codecs[] = { MediaCodecInfo * media_codec_by_name (const char *name) { - g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (name, NULL); for (guint i = 0; i < G_N_ELEMENTS (gst_codecs); i++) { if (g_strcmp0 (name, gst_codecs[i].name) == 0)