From c8fd5cabfc6fbd756c6b1908407e97e50d5cebbe Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Tue, 29 Mar 2011 20:16:29 +0200 Subject: [PATCH] core: Moved repeating code to sipmsg_get_ms_diagnostics_reason() --- src/core/sip-transport.c | 11 ++--------- src/core/sipmsg.c | 8 ++++++++ src/core/sipmsg.h | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/core/sip-transport.c b/src/core/sip-transport.c index e0407d3f..784f582a 100644 --- a/src/core/sip-transport.c +++ b/src/core/sip-transport.c @@ -1213,11 +1213,8 @@ static gboolean process_register_response(struct sipe_core_private *sipe_private case 404: { const gchar *diagnostics = sipmsg_find_header(msg, "ms-diagnostics"); - gchar *reason = NULL; + gchar *reason = sipmsg_get_ms_diagnostics_reason(msg); gchar *warning; - if (diagnostics != NULL) { - reason = sipmsg_find_part_of_header(diagnostics, "reason=\"", "\"", NULL); - } warning = g_strdup_printf(_("Not found: %s. Please contact your Administrator"), diagnostics ? (reason ? reason : _("no reason given")) : _("SIP is either not enabled for the destination URI or it does not exist")); @@ -1241,12 +1238,8 @@ static gboolean process_register_response(struct sipe_core_private *sipe_private /* FALLTHROUGH */ case 503: { - const gchar *diagnostics = sipmsg_find_header(msg, "ms-diagnostics"); - gchar *reason = NULL; + gchar *reason = sipmsg_get_ms_diagnostics_reason(msg); gchar *warning; - if (diagnostics != NULL) { - reason = sipmsg_find_part_of_header(diagnostics, "reason=\"", "\"", NULL); - } warning = g_strdup_printf(_("Service unavailable: %s"), reason ? reason : _("no reason given")); g_free(reason); diff --git a/src/core/sipmsg.c b/src/core/sipmsg.c index 5c386405..b42e73cd 100644 --- a/src/core/sipmsg.c +++ b/src/core/sipmsg.c @@ -652,7 +652,15 @@ gchar *get_html_message(const gchar *ms_text_format_in, const gchar *body_in) return res; } +gchar * +sipmsg_get_ms_diagnostics_reason(struct sipmsg *msg) +{ + const gchar *diagnostics = sipmsg_find_header(msg, "ms-diagnostics"); + if (diagnostics) + return sipmsg_find_part_of_header(diagnostics, "reason=\"", "\"", NULL); + return NULL; +} diff --git a/src/core/sipmsg.h b/src/core/sipmsg.h index 35b9c391..144458b0 100644 --- a/src/core/sipmsg.h +++ b/src/core/sipmsg.h @@ -117,3 +117,12 @@ gchar *sipmsg_get_msgr_string(gchar *x_mms_im_format); * @return The new message. */ void sipe_parse_html(const char *html, char **attributes, char **message); + +/** + * Extracts reason string from ms-diagnostics header of SIP message + * + * @param msg SIP message + * + * @return reason string. Must be g_free()'d after use. + */ +gchar *sipmsg_get_ms_diagnostics_reason(struct sipmsg *msg); -- 2.11.4.GIT