[evolution-kolab] libekolabconv: rework of error handling in free/busy conversion



commit a9db6cd28b6542d62e2909eb1f6c83616eecbf62
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Nov 23 17:21:51 2012 +0100

    libekolabconv: rework of error handling in free/busy conversion
    
    * linearized error handling in function call sequence
      inside the kolabconv_cal_util_freebusy_ecalcomp_new_from_ics()
      function

 src/libekolabconv/main/src/kolab-conv.c |   69 ++++++++++++++++---------------
 1 files changed, 36 insertions(+), 33 deletions(-)
---
diff --git a/src/libekolabconv/main/src/kolab-conv.c b/src/libekolabconv/main/src/kolab-conv.c
index 99a26fd..fe56ee6 100644
--- a/src/libekolabconv/main/src/kolab-conv.c
+++ b/src/libekolabconv/main/src/kolab-conv.c
@@ -169,60 +169,66 @@ kolabconv_cal_util_freebusy_ecalcomp_new_from_ics (const gchar *ics_string,
 	ECalComponent *ecalcomp_tmp = NULL;
 	icalcomponent *icalcomp_ics = NULL;
 	icalcomponent *icalcomp_vfb = NULL;
+	GError *tmp_err = NULL;
 	gboolean set_ical_ok = FALSE;
 
 	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
 
 	/* TODO: sanity-check incoming data */
 
-	if (nbytes > 0) {
-		icalcomp_ics = (icalcomponent *) e_cal_util_parse_ics_string(ics_string);
-	} else {
+	if (nbytes <= 0) {
 		g_debug ("kolabconv_cal_util_fb_new_ecalcomp_from_request: empty server response");
-		g_set_error (err,
+		g_set_error (&tmp_err,
 		             KOLABCONV_ERROR_READ_KOLAB,
 		             KOLABCONV_ERROR_READ_KOLAB_INPUT_IS_NULL, /* appropriate? */
 		             _("Empty server response"));
-		goto CLEANUP;
+		goto cleanup;
 	}
 
-	if (icalcomp_ics != NULL) {
-		icalcomp_vfb = icalcomponent_get_first_component (icalcomp_ics, ICAL_VFREEBUSY_COMPONENT);
-	} else {
+	icalcomp_ics = (icalcomponent *) e_cal_util_parse_ics_string (ics_string);
+
+	if (icalcomp_ics == NULL) {
 		g_debug ("kolabconv_cal_util_fb_new_ecalcomp_from_request: cannot parse server response");
-		g_set_error (err,
+		g_set_error (&tmp_err,
 		             KOLABCONV_ERROR_READ_KOLAB,
 		             KOLABCONV_ERROR_READ_KOLAB_MALFORMED_XML, /* appropriate? */
 		             _("Cannot parse server response"));
-		goto CLEANUP;
+		goto cleanup;
 	}
 
-	if (icalcomp_vfb != NULL) {
-		ecalcomp_tmp = e_cal_component_new ();
-		set_ical_ok = e_cal_component_set_icalcomponent (ecalcomp_tmp, icalcomp_vfb);
-		if (set_ical_ok) {
-			/* need to copy ecalcomp_tmp since it will become
-			 * invalid once icalcomp_[iv]fb are destroyed
-			 */
-			ecalcomp = e_cal_component_clone (ecalcomp_tmp);
-		} else {
-			g_debug ("kolabconv_cal_util_fb_new_ecalcomp_from_request: unsupported component type");
-			g_set_error (err,
-			             KOLABCONV_ERROR_READ_KOLAB,
-			             KOLABCONV_ERROR_READ_KOLAB_INVALID_KOLAB_XML, /* appropriate? */
-			             _("Unsupported component type"));
-		}
-		g_object_unref (ecalcomp_tmp);
-		ecalcomp_tmp = NULL;
-	} else {
+	icalcomp_vfb = icalcomponent_get_first_component (icalcomp_ics, ICAL_VFREEBUSY_COMPONENT);
+
+	if (icalcomp_vfb == NULL) {
 		g_debug ("kolabconv_cal_util_fb_new_ecalcomp_from_request: missing component part");
-		g_set_error (err,
+		g_set_error (&tmp_err,
 		             KOLABCONV_ERROR_READ_KOLAB,
 		             KOLABCONV_ERROR_READ_KOLAB_MISSING_XML_PART, /* appropriate? */
 		             _("Unsupported component type"));
+		goto cleanup;
+	}
+
+	ecalcomp_tmp = e_cal_component_new ();
+	set_ical_ok = e_cal_component_set_icalcomponent (ecalcomp_tmp, icalcomp_vfb);
+
+	if (! set_ical_ok) {
+		g_debug ("kolabconv_cal_util_fb_new_ecalcomp_from_request: unsupported component type");
+		g_set_error (&tmp_err,
+		             KOLABCONV_ERROR_READ_KOLAB,
+		             KOLABCONV_ERROR_READ_KOLAB_INVALID_KOLAB_XML, /* appropriate? */
+		             _("Unsupported component type"));
+		goto cleanup;
 	}
 
- CLEANUP:
+	/* need to copy ecalcomp_tmp since it will become
+	 * invalid once icalcomp_[iv]fb are destroyed
+	 */
+	ecalcomp = e_cal_component_clone (ecalcomp_tmp);
+
+ cleanup:
+	if (tmp_err != NULL)
+		g_propagate_error (err, tmp_err);
+	if (ecalcomp_tmp != NULL)
+		g_object_unref (ecalcomp_tmp);
 	if (icalcomp_vfb != NULL)
 		icalcomponent_free (icalcomp_vfb);
 	if (icalcomp_ics != NULL)
@@ -231,9 +237,6 @@ kolabconv_cal_util_freebusy_ecalcomp_new_from_ics (const gchar *ics_string,
 	return ecalcomp;
 }
 
-
-
-
 /**
  * Initialize this library.
  */



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