From a7d11e16d0bc305a9c2a7c4d135e322bacbc5ca1 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Sun, 4 Jul 2010 10:42:00 +0200 Subject: [PATCH] audio: improved handling of SIP error responses Catch and handle all failure responses (code >= 400), present error code and string to the user in a dialog box. --- src/core/sipe-media.c | 32 +++++++++++++++++++++----------- src/core/sipmsg.c | 12 ++++++------ src/core/sipmsg.h | 1 + 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/core/sipe-media.c b/src/core/sipe-media.c index e155472e..edcaf05d 100644 --- a/src/core/sipe-media.c +++ b/src/core/sipe-media.c @@ -924,23 +924,33 @@ sipe_media_process_invite_response(struct sipe_core_private *sipe_private, backend_private = call_private->public.backend_private; with = call_private->dialog->with; - if (msg->response == 603 || msg->response == 605 || msg->response == 480) { - // Call rejected by remote peer - gchar *errmsg; + if (msg->response >= 400) { + // Call rejected by remote peer or an error occurred gchar *title; + GString *desc = g_string_new(""); sipe_backend_media_reject(backend_private, FALSE); sipe_media_send_ack(sipe_private, msg, trans); - if (msg->response > 600) { - title = _("Call rejected"); - errmsg = g_strdup_printf(_("User %s rejected call"), with); - } else { - errmsg = g_strdup_printf(_("User %s is not available"), with); - title = _("User unavailable"); + switch (msg->response) { + case 480: + title = _("User unavailable"); + g_string_append_printf(desc, _("User %s is not available"), with); + case 603: + case 605: + title = _("Call rejected"); + g_string_append_printf(desc, _("User %s rejected call"), with); + break; + default: + title = _("Error occured"); + g_string_append(desc, _("Unable to establish a call")); + break; } - sipe_backend_notify_error(title, errmsg); - g_free(errmsg); + + g_string_append_printf(desc, "\n%d %s", msg->response, msg->responsestr); + + sipe_backend_notify_error(title, desc->str); + g_string_free(desc, TRUE); return TRUE; } diff --git a/src/core/sipmsg.c b/src/core/sipmsg.c index 2db833e7..87749cbd 100644 --- a/src/core/sipmsg.c +++ b/src/core/sipmsg.c @@ -68,7 +68,7 @@ struct sipmsg *sipmsg_parse_header(const gchar *header) { return NULL; } if(strstr(parts[0],"SIP") || strstr(parts[0],"HTTP")) { /* numeric response */ - msg->method = g_strdup(parts[2]); + msg->responsestr = g_strdup(parts[2]); msg->response = strtol(parts[1],NULL,10); } else { /* request */ msg->method = g_strdup(parts[0]); @@ -90,7 +90,6 @@ struct sipmsg *sipmsg_parse_header(const gchar *header) { } if(msg->response) { const gchar *tmp; - g_free(msg->method); tmp = sipmsg_find_header(msg, "CSeq"); if(!tmp) { /* SHOULD NOT HAPPEN */ @@ -108,7 +107,8 @@ struct sipmsg *sipmsg_copy(const struct sipmsg *other) { struct sipmsg *msg = g_new0(struct sipmsg, 1); GSList *list; - msg->response = other->response; + msg->response = other->response; + msg->responsestr = g_strdup(other->responsestr); msg->method = g_strdup(other->method); msg->target = g_strdup(other->target); @@ -127,10 +127,10 @@ struct sipmsg *sipmsg_copy(const struct sipmsg *other) { } msg->bodylen = other->bodylen; - msg->body = g_memdup(other->body, other->bodylen); + msg->body = g_memdup(other->body, other->bodylen); msg->signature = g_strdup(other->signature); - msg->rand = g_strdup(other->rand); - msg->num = g_strdup(other->num); + msg->rand = g_strdup(other->rand); + msg->num = g_strdup(other->num); return msg; } diff --git a/src/core/sipmsg.h b/src/core/sipmsg.h index 55db0653..1ef34566 100644 --- a/src/core/sipmsg.h +++ b/src/core/sipmsg.h @@ -30,6 +30,7 @@ struct sipmsg { int response; /* 0 means request, otherwise response code */ + gchar *responsestr; gchar *method; gchar *target; GSList *headers; -- 2.11.4.GIT