Rework SOAP response handling.

Rework SOAP response handling.

ews_response_cb() overgeneralizes and tries to do too much for too many
different kinds of SOAP responses.  This results in confusing response
handling and error handling.

Simplify things by just handing the whole ESoapResponse to the response
callback function and let it process it.  This approach results in some
repetitive logic for handling ResponseMessage elements in 20 different
places, but the logic is simple and straightforward.

--- src/server/e-ews-connection.c
+++ src/server/e-ews-connection.c
@@ -48,6 +48,9 @@
 #define QUEUE_LOCK(x) (g_static_rec_mutex_lock(&(x)->priv->queue_lock))
 #define QUEUE_UNLOCK(x) (g_static_rec_mutex_unlock(&(x)->priv->queue_lock))

+#define CHECK_ELEMENT(element_name, expected_name) \
+	(check_element (G_STRFUNC, (element_name), (expected_name)))
+
 G_DEFINE_TYPE (EEwsConnection, e_ews_connection, G_TYPE_OBJECT)

 struct _EwsNode;
@@ -57,9 +60,8 @@
 static gboolean ews_next_request (gpointer _cnc);
 static gint comp_func (gconstpointer a, gconstpointer b);

-typedef void		(*response_cb)		(ESoapParameter *param,
-						 GSimpleAsyncResult *simple,
-						 GError **error);
+typedef void		(*response_cb)		(ESoapResponse *response,
+						 GSimpleAsyncResult *simple);
 static void ews_response_cb (SoupSession *session, SoupMessage *msg, gpointer data);

 static void	ews_connection_authenticate	(SoupSession *sess,
@@ -145,6 +147,27 @@
 async_data_free (EwsAsyncData *async_data)
 {
 	g_free (async_data);
+}
+
+static gboolean
+check_element (const gchar *function_name,
+               const gchar *element_name,
+               const gchar *expected_name)
+{
+	/* Do not call this directory, use CHECK_ELEMENT macro instead. */
+
+	g_return_val_if_fail (function_name != NULL, FALSE);
+	g_return_val_if_fail (element_name != NULL, FALSE);
+	g_return_val_if_fail (expected_name != NULL, FALSE);
+
+	if (!g_str_equal (element_name, expected_name)) {
+		g_warning (
+			"%s: Expected <%s> but got <%s>",
+			function_name, expected_name, element_name);
+		return FALSE;
+	}
+
+	return TRUE;
 }

 static void
@@ -344,6 +367,7 @@
 	EwsNode *node;

 	g_return_if_fail (cnc != NULL);
+	g_return_if_fail (cb != NULL);

 	node = ews_node_new ();
 	node->msg = msg;
@@ -376,9 +400,6 @@
 {
 	EwsNode *enode = (EwsNode *) data;
 	ESoapResponse *response;
-	ESoapParameter *param;
-	ESoapParameter *subparam;
-	GError *error = NULL;

 	if (g_cancellable_is_cancelled (enode->cancellable))
 		goto exit;
@@ -408,56 +429,8 @@
 	if (g_getenv ("EWS_DEBUG") && (atoi (g_getenv ("EWS_DEBUG")) >= 1))
 		e_soap_response_dump_response (response, stdout);

-	param = e_soap_response_get_first_parameter_by_name (
-		response, "ResponseMessages", NULL);
-	if (param == NULL)
-		param = e_soap_response_get_first_parameter_by_name (
-			response, "FreeBusyResponseArray", NULL);
-
-	if (param != NULL) {
-		/* Iterate over all "*ResponseMessage" elements. */
-		for (subparam = e_soap_parameter_get_first_child (param);
-		     subparam != NULL;
-		     subparam = e_soap_parameter_get_next_child (subparam)) {
-			gint l = strlen ((gchar *) subparam->name);
-			if (l < 15 || (strcmp((char *)subparam->name + l - 15, "ResponseMessage") &&
-			    strcmp((char *)subparam->name, "FreeBusyResponse")&&
-					strcmp((char *)subparam->name, "DelegateUserResponseMessageType"))) {
-				g_warning ("Unexpected element '%s' in place of ResponseMessage or FreeBusyResponse or DelegateUserResponseMessageType",
-					   subparam->name);
-				continue;
-			}
-
-			if ((strcmp((char *)subparam->name, "FreeBusyResponse") == 0 && !ews_get_response_status (e_soap_parameter_get_first_child (subparam), &error)) ||
-			 (strcmp((char *)subparam->name, "FreeBusyResponse") && !ews_get_response_status (subparam, &error))) {
-				if (enode->cb) {
-					enode->cb (subparam, enode->simple, &error);
-				} else {
-					g_simple_async_result_set_from_error (enode->simple, error);
-					break;
-				}
-			} else if (enode->cb)
-				enode->cb (subparam, enode->simple, &error);
-		}
-	} else {
-		param = e_soap_response_get_first_parameter_by_name (
-			response, "ResponseMessage", &error);
-
-		if (param != NULL) {
-			/*Parse GetUserOofSettingsResponse and SetUserOofSettingsResponse*/
-			if (!ews_get_response_status (param, &error)) {
-				if (enode->cb)
-					enode->cb (NULL, enode->simple, &error);
-			} else {
-				subparam = e_soap_parameter_get_next_child (param);
-				if (enode->cb)
-					enode->cb (subparam, enode->simple, &error);
-			}
-		}
-	}
-
-	if (error != NULL)
-		g_simple_async_result_take_error (enode->simple, error);
+	if (enode->cb != NULL)
+		enode->cb (response, enode->simple);

 	g_object_unref (response);

@@ -483,13 +456,12 @@

 static void
 sync_xxx_response_cb (ESoapParameter *subparam,
-                      GSimpleAsyncResult *simple,
+                      EwsAsyncData *async_data,
                       ItemParser parser,
                       const gchar *last_tag,
                       const gchar *delete_id_tag)
 {
 	ESoapParameter *node;
-	EwsAsyncData *async_data;
 	gchar *new_sync_state = NULL, *value, *last;
 	GSList *items_created = NULL, *items_updated = NULL, *items_deleted = NULL;
 	gboolean includes_last_item = FALSE;
@@ -546,7 +518,6 @@
 		}
 	}

-	async_data = g_simple_async_result_get_op_res_gpointer (simple);
 	async_data->items_created = items_created;
 	async_data->items_updated = items_updated;
 	async_data->items_deleted = items_deleted;
@@ -555,49 +526,99 @@
 }

 static void
-sync_hierarchy_response_cb (ESoapParameter *subparam,
-                            GSimpleAsyncResult *simple,
-                            GError **error)
-{
-	/* stop on errors */
-	if (error && *error)
+sync_hierarchy_response_cb (ESoapResponse *response,
+                            GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
 		return;
-
-	sync_xxx_response_cb (
-		subparam, simple,
-		(ItemParser) e_ews_folder_new_from_soap_parameter,
-		"IncludesLastFolderInRange", "FolderId");
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "SyncFolderHierarchyResponseMessage"))
+			sync_xxx_response_cb (
+				subparam, async_data,
+				(ItemParser) e_ews_folder_new_from_soap_parameter,
+				"IncludesLastFolderInRange", "FolderId");
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 static void
-sync_folder_items_response_cb (ESoapParameter *subparam,
-                               GSimpleAsyncResult *simple,
-                               GError **error)
-{
-	/* stop on errors */
-	if (error && *error)
+sync_folder_items_response_cb (ESoapResponse *response,
+                               GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
 		return;
-
-	sync_xxx_response_cb (
-		subparam, simple,
-		(ItemParser) e_ews_item_new_from_soap_parameter,
-		"IncludesLastItemInRange", "ItemId");
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "SyncFolderItemsResponseMessage"))
+			sync_xxx_response_cb (
+				subparam, async_data,
+				(ItemParser) e_ews_item_new_from_soap_parameter,
+				"IncludesLastItemInRange", "ItemId");
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 static void
-get_folder_response_cb (ESoapParameter *subparam,
-                        GSimpleAsyncResult *simple,
-                        GError **error)
+ews_handle_folders_param (ESoapParameter *subparam,
+                          EwsAsyncData *async_data)
 {
 	ESoapParameter *node;
-	EwsAsyncData *async_data;
 	EEwsFolder *folder;
-
-	/* stop on errors */
-	if (error && *error)
-		return;
-
-	async_data = g_simple_async_result_get_op_res_gpointer (simple);

 	for (node = e_soap_parameter_get_first_child_by_name (subparam, "Folders");
 	     node; node = e_soap_parameter_get_next_child_by_name (subparam, "Folders")) {
@@ -608,20 +629,55 @@
 }

 static void
-find_folder_items_response_cb (ESoapParameter *subparam,
-                               GSimpleAsyncResult *simple,
-                               GError **error)
+get_folder_response_cb (ESoapResponse *response,
+                        GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "GetFolderResponseMessage"))
+			ews_handle_folders_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}
+
+static void
+ews_handle_root_folder_param (ESoapParameter *subparam,
+                              EwsAsyncData *async_data)
 {
 	ESoapParameter *node, *subparam1;
-	EwsAsyncData *async_data;
 	gchar *last, *total;
 	gint total_items;
 	EEwsItem *item;
 	gboolean includes_last_item = FALSE;
-
-	/* stop on errors */
-	if (error && *error)
-		return;

 	node = e_soap_parameter_get_first_child_by_name (subparam, "RootFolder");
 	total = e_soap_parameter_get_property (node, "TotalItemsInView");
@@ -632,8 +688,6 @@
 		includes_last_item = TRUE;
 	g_free (last);

-	async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
 	node = e_soap_parameter_get_first_child_by_name (node, "Items");
 	for (subparam1 = e_soap_parameter_get_first_child (node);
 	     subparam1; subparam1 = e_soap_parameter_get_next_child (subparam1)) {
@@ -645,17 +699,55 @@
 	async_data->includes_last_item = includes_last_item;
 }

+static void
+find_folder_items_response_cb (ESoapResponse *response,
+                               GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "FindItemResponseMessage"))
+			ews_handle_root_folder_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}
+
 /* Used for CreateItems and GetItems */
 static void
-get_items_response_cb (ESoapParameter *subparam,
-                       GSimpleAsyncResult *simple,
-                       GError **error)
+ews_handle_items_param (ESoapParameter *subparam,
+                        EwsAsyncData *async_data,
+                        const GError *error)
 {
 	ESoapParameter *node;
-	EwsAsyncData *async_data;
 	EEwsItem *item;
-
-	async_data = g_simple_async_result_get_op_res_gpointer (simple);

 	for (node = e_soap_parameter_get_first_child_by_name (subparam, "Items");
 	     node; node = e_soap_parameter_get_next_child_by_name (subparam, "Items")) {
@@ -663,14 +755,57 @@
 			item = e_ews_item_new_from_soap_parameter (node);
 		else
 			item = NULL;
-		if (!item && error && *error)
-			item = e_ews_item_new_from_error (*error);
+		if (!item && error != NULL)
+			item = e_ews_item_new_from_error (error);
 		if (!item) continue;
 		async_data->items = g_slist_append (async_data->items, item);
 	}
-
-	/* do not stop on errors here, just use it above */
-	g_clear_error (error);
+}
+
+static void
+get_items_response_cb (ESoapResponse *response,
+                       GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (g_str_has_suffix (name, "ResponseMessage")) {
+			ews_get_response_status (subparam, &error);
+			ews_handle_items_param (subparam, async_data, error);
+		} else {
+			g_warning (
+				"%s: Unexpected element <%s>",
+				G_STRFUNC, name);
+		}
+
+		/* Do not stop on errors. */
+		if (error != NULL)
+			g_clear_error (&error);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 static gchar *
@@ -710,10 +845,10 @@
 }

 static void
-get_oof_settings_response_cb (ESoapParameter *subparam,
-                              GSimpleAsyncResult *simple,
-                              GError **error)
-{
+get_oof_settings_response_cb (ESoapResponse *response,
+                              GSimpleAsyncResult *simple)
+{
+	ESoapParameter *param;
 	ESoapParameter *node, *node_1;
 	EwsAsyncData *async_data;
 	OOFSettings *oof_settings;
@@ -721,18 +856,46 @@
 	gchar *start_tm = NULL, *end_tm = NULL;
 	gchar *ext_msg = NULL, *int_msg = NULL;
 	GTimeVal time_val;
-
-	/* stop on errors */
-	if (error && *error)
+	GError *error = NULL;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessage", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
 		return;
-
-	node = e_soap_parameter_get_first_child_by_name (subparam, "OofState");
+	}
+
+	if (!ews_get_response_status (param, &error)) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "OofSettings", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	node = e_soap_parameter_get_first_child_by_name (param, "OofState");
 	state = e_soap_parameter_get_string_value (node);

-	node = e_soap_parameter_get_first_child_by_name (subparam, "ExternalAudience");
+	node = e_soap_parameter_get_first_child_by_name (param, "ExternalAudience");
 	ext_aud = e_soap_parameter_get_string_value (node);

-	node = e_soap_parameter_get_first_child_by_name (subparam, "Duration");
+	node = e_soap_parameter_get_first_child_by_name (param, "Duration");

 	node_1 = e_soap_parameter_get_first_child_by_name (node, "StartTime");
 	start_tm = e_soap_parameter_get_string_value (node_1);
@@ -740,13 +903,13 @@
 	node_1 = e_soap_parameter_get_first_child_by_name (node, "EndTime");
 	end_tm = e_soap_parameter_get_string_value (node_1);

-	node = e_soap_parameter_get_first_child_by_name (subparam, "InternalReply");
+	node = e_soap_parameter_get_first_child_by_name (param, "InternalReply");
 	node_1 = e_soap_parameter_get_first_child_by_name (node, "Message");
 	int_msg = e_soap_parameter_get_string_value (node_1);
 	if (g_strrstr (int_msg, "") || g_strrstr (int_msg, "BodyFragment"))
 		int_msg = get_text_from_html (int_msg);

-	node = e_soap_parameter_get_first_child_by_name (subparam, "ExternalReply");
+	node = e_soap_parameter_get_first_child_by_name (param, "ExternalReply");
 	node_1 = e_soap_parameter_get_first_child_by_name (node, "Message");
 	ext_msg = e_soap_parameter_get_string_value (node_1);
 	if (g_strrstr (ext_msg, "") || g_strrstr (ext_msg, "BodyFragment"))
@@ -774,19 +937,13 @@
 }

 static void
-resolve_names_response_cb (ESoapParameter *subparam,
-                           GSimpleAsyncResult *simple,
-                           GError **error)
+ews_handle_resolution_set_param (ESoapParameter *subparam,
+                                 EwsAsyncData *async_data)
 {
 	ESoapParameter *node;
+	gchar *prop;
 	gboolean includes_last_item;
 	GSList *mailboxes = NULL, *contact_items = NULL;
-	EwsAsyncData *async_data;
-	gchar *prop;
-
-	/* stop on errors */
-	if (error && *error)
-		return;

 	subparam = e_soap_parameter_get_first_child_by_name (subparam, "ResolutionSet");
 	prop = e_soap_parameter_get_property (subparam, "IncludesLastItemInRange");
@@ -815,8 +972,6 @@
 		}
 	}

-	async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
 	/* Reuse existing variables */
 	async_data->items = g_slist_reverse (mailboxes);
 	async_data->includes_last_item = includes_last_item;
@@ -824,18 +979,53 @@
 }

 static void
-expand_dl_response_cb (ESoapParameter *subparam,
-                       GSimpleAsyncResult *simple,
-                       GError **error)
+resolve_names_response_cb (ESoapResponse *response,
+                           GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "ResolveNamesResponseMessage"))
+			ews_handle_resolution_set_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}
+
+static void
+ews_handle_dl_expansion_param (ESoapParameter *subparam,
+                               EwsAsyncData *async_data)
 {
 	gboolean includes_last_item;
 	GSList *mailboxes = NULL;
-	EwsAsyncData *async_data;
 	gchar *prop;
-
-	/* stop on errors */
-	if (error && *error)
-		return;

 	subparam = e_soap_parameter_get_first_child_by_name (subparam, "DLExpansion");
 	prop = e_soap_parameter_get_property (subparam, "IncludesLastItemInRange");
@@ -854,27 +1044,60 @@
 			mailboxes = g_slist_append (mailboxes, mb);
 	}

-	async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
 	/* Reuse existing variables */
 	async_data->items = mailboxes;
 	async_data->includes_last_item = includes_last_item;
 }

+static void
+expand_dl_response_cb (ESoapResponse *response,
+                       GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "ExpandDLResponseMessage"))
+			ews_handle_dl_expansion_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}
+
 /* TODO scan all folders if we support creating multiple folders in the request */
 static void
-ews_create_folder_response_cb (ESoapParameter *soapparam,
-                               GSimpleAsyncResult *simple,
-                               GError **error)
+ews_handle_create_folders_param (ESoapParameter *soapparam,
+                                 EwsAsyncData *async_data)
 {
 	ESoapParameter *param, *node;
-	EwsAsyncData *async_data;
 	EwsFolderId *fid = NULL;
 	GSList *fids = NULL;
-
-	/* stop on errors */
-	if (error && *error)
-		return;

 	node = e_soap_parameter_get_first_child_by_name (soapparam, "Folders");
 	node = e_soap_parameter_get_first_child_by_name (node, "Folder");
@@ -885,8 +1108,48 @@
 	fid->change_key = e_soap_parameter_get_property (param, "ChangeKey");
 	fids = g_slist_append (fids, fid);

+	async_data->items_created = fids;
+}
+
+static void
+create_folder_response_cb (ESoapResponse *response,
+                           GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
 	async_data = g_simple_async_result_get_op_res_gpointer (simple);
-	async_data->items_created = fids;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "CreateFolderResponseMessage"))
+			ews_handle_create_folders_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 static void
@@ -2577,8 +2840,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, sync_folder_items_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, sync_folder_items_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -2759,8 +3024,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, find_folder_items_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, find_folder_items_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -2868,8 +3135,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, sync_hierarchy_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, sync_hierarchy_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -3023,8 +3292,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_items_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_items_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -3137,6 +3408,39 @@
 	return NULL;
 }

+static void
+delete_item_response_cb (ESoapResponse *response,
+                         GSimpleAsyncResult *simple)
+{
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}
+
 void
 e_ews_connection_delete_items (EEwsConnection *cnc,
                                gint pri,
@@ -3184,8 +3488,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, NULL, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, delete_item_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 void
@@ -3249,8 +3555,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, NULL, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, delete_item_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -3403,8 +3711,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_items_response_cb, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_items_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -3532,8 +3842,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_items_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_items_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -3664,8 +3976,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, resolve_names_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, resolve_names_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -3941,8 +4255,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, expand_dl_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, expand_dl_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 /* includes_last_item does not make sense as expand_dl does not support recursive
@@ -4009,6 +4325,39 @@
 	return result;
 }

+static void
+update_folder_response_cb (ESoapResponse *response,
+                           GSimpleAsyncResult *simple)
+{
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		subparam = e_soap_parameter_get_next_child (param);
+	}
+}
+
 void
 e_ews_connection_update_folder (EEwsConnection *cnc,
                                 gint pri,
@@ -4044,8 +4393,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, NULL, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, update_folder_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -4100,6 +4451,39 @@
 	g_free (sync_data);

 	return result;
+}
+
+static void
+move_folder_response_cb (ESoapResponse *response,
+                         GSimpleAsyncResult *simple)
+{
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 void
@@ -4146,8 +4530,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, NULL, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, move_folder_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -4246,8 +4632,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_folder_response_cb, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_folder_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);

 }

@@ -4363,7 +4751,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, ews_create_folder_response_cb, pri, cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, create_folder_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -4479,8 +4870,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_items_response_cb, pri, cancellable, simple,
-				      callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_items_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -4542,6 +4935,39 @@
 	g_free (sync_data);

 	return result;
+}
+
+static void
+delete_folder_response_cb (ESoapResponse *response,
+                           GSimpleAsyncResult *simple)
+{
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 /**
@@ -4597,7 +5023,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, NULL, pri, cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, delete_folder_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -4670,19 +5099,11 @@
 }

 static void
-create_attachments_response_cb (ESoapParameter *param,
-                                GSimpleAsyncResult *simple,
-                                GError **error)
+ews_handle_create_attachments_param (ESoapParameter *param,
+                                     EwsAsyncData *async_data)
 {
 	/* http://msdn.microsoft.com/en-us/library/aa565877%28v=EXCHG.80%29.aspx */
 	ESoapParameter *subparam, *attspara, *last_relevant = NULL, *attparam;
-	EwsAsyncData *async_data;
-
-	/* stop on errors */
-	if (error && *error)
-		return;
-
-	async_data = g_simple_async_result_get_op_res_gpointer (simple);

 	attspara = e_soap_parameter_get_first_child_by_name (param, "Attachments");

@@ -4697,6 +5118,47 @@

 	if (last_relevant != NULL) {
 		async_data->sync_state = e_soap_parameter_get_property (last_relevant, "RootItemChangeKey");
+	}
+}
+
+static void
+create_attachments_response_cb (ESoapResponse *response,
+                                GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "CreateAttachmentResponseMessage"))
+			ews_handle_create_attachments_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
 	}
 }

@@ -4794,8 +5256,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, create_attachments_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, create_attachments_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 GSList *
@@ -4865,25 +5329,62 @@

 /* Delete attachemnts */
 static void
-delete_attachments_response_cb (ESoapParameter *subparam,
-                                GSimpleAsyncResult *simple,
-                                GError **error)
+ews_handle_root_item_id_param (ESoapParameter *subparam,
+                               EwsAsyncData *async_data)
 {
 	/* http://msdn.microsoft.com/en-us/library/aa580782%28v=EXCHG.80%29.aspx */
 	ESoapParameter *attspara;
+
+	attspara = e_soap_parameter_get_first_child_by_name (
+		subparam, "RootItemId");
+
+	if (attspara == NULL)
+		return;
+
+	async_data->items = g_slist_append (
+		async_data->items,
+		e_soap_parameter_get_property (attspara, "RootItemChangeKey"));
+}
+
+static void
+delete_attachments_response_cb (ESoapResponse *response,
+                                GSimpleAsyncResult *simple)
+{
 	EwsAsyncData *async_data;
-
-	/* stop on errors */
-	if (error && *error)
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
 		return;
-
-	async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-	attspara = e_soap_parameter_get_first_child_by_name (subparam, "RootItemId");
-
-	if (!attspara) return;
-
-	async_data->items = g_slist_append (async_data->items, e_soap_parameter_get_property (attspara, "RootItemChangeKey"));
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "DeleteAttachmentResponseMessage"))
+			ews_handle_root_item_id_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 void
@@ -4923,8 +5424,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, delete_attachments_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, delete_attachments_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 GSList *
@@ -4987,9 +5490,78 @@
 	return parents;
 }

-static void	get_attachments_response_cb	(ESoapParameter *subparam,
-						 GSimpleAsyncResult *simple,
-						 GError **error);
+static void
+ews_handle_attachments_param (ESoapParameter *param,
+                              EwsAsyncData *async_data)
+{
+	ESoapParameter *subparam, *attspara;
+	gchar *uri = NULL, *attach_id = NULL;
+	EEwsItem *item;
+	const gchar *name;
+
+	attspara = e_soap_parameter_get_first_child_by_name (param, "Attachments");
+
+	for (subparam = e_soap_parameter_get_first_child (attspara); subparam != NULL; subparam = e_soap_parameter_get_next_child (subparam)) {
+		name = e_soap_parameter_get_name (subparam);
+
+		if (!g_ascii_strcasecmp (name, "ItemAttachment")) {
+			item = e_ews_item_new_from_soap_parameter (subparam);
+			attach_id = g_strdup (e_ews_item_get_attachment_id (item)->id);
+			uri = e_ews_item_dump_mime_content (item, async_data->directory);
+
+		}
+		else if (!g_ascii_strcasecmp (name, "FileAttachment")) {
+			uri = e_ews_dump_file_attachment_from_soap_parameter (subparam, async_data->directory, async_data->sync_state, &attach_id);
+		}
+		if (uri && attach_id) {
+			async_data->items = g_slist_append (async_data->items, uri);
+			async_data->items_created = g_slist_append (async_data->items_created, attach_id);
+			uri = NULL;
+			attach_id = NULL;
+		}
+	}
+}
+
+static void
+get_attachments_response_cb (ESoapResponse *response,
+                             GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "GetAttachmentResponseMessage"))
+			ews_handle_attachments_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}

 void
 e_ews_connection_get_attachments (EEwsConnection *cnc,
@@ -5046,8 +5618,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_attachments_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_attachments_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 GSList *
@@ -5119,49 +5693,8 @@
 }

 static void
-get_attachments_response_cb (ESoapParameter *param,
-                             GSimpleAsyncResult *simple,
-                             GError **error)
-{
-	ESoapParameter *subparam, *attspara;
-	EwsAsyncData *async_data;
-	gchar *uri = NULL, *attach_id = NULL;
-	EEwsItem *item;
-	const gchar *name;
-
-	/* stop on errors */
-	if (error && *error)
-		return;
-
-	async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-	attspara = e_soap_parameter_get_first_child_by_name (param, "Attachments");
-
-	for (subparam = e_soap_parameter_get_first_child (attspara); subparam != NULL; subparam = e_soap_parameter_get_next_child (subparam)) {
-		name = e_soap_parameter_get_name (subparam);
-
-		if (!g_ascii_strcasecmp (name, "ItemAttachment")) {
-			item = e_ews_item_new_from_soap_parameter (subparam);
-			attach_id = g_strdup (e_ews_item_get_attachment_id (item)->id);
-			uri = e_ews_item_dump_mime_content (item, async_data->directory);
-
-		}
-		else if (!g_ascii_strcasecmp (name, "FileAttachment")) {
-			uri = e_ews_dump_file_attachment_from_soap_parameter (subparam, async_data->directory, async_data->sync_state, &attach_id);
-		}
-		if (uri && attach_id) {
-			async_data->items = g_slist_append (async_data->items, uri);
-			async_data->items_created = g_slist_append (async_data->items_created, attach_id);
-			uri = NULL;
-			attach_id = NULL;
-		}
-	}
-}
-
-static void
-get_free_busy_response_cb (ESoapParameter *param,
-                           GSimpleAsyncResult *simple,
-                           GError **error)
+ews_handle_free_busy_view (ESoapParameter *param,
+                           EwsAsyncData *async_data)
 {
        /*parse the response to create a free_busy data
 	http://msdn.microsoft.com / en - us / library / aa564001 % 28v = EXCHG.140 % 29.aspx */
@@ -5172,11 +5705,6 @@
 	GTimeVal t_val;
 	const gchar *name;
 	gchar *value, *new_val = NULL;
-	EwsAsyncData *async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-	/* stop on errors */
-	if (error && *error)
-		return;

 	viewparam = e_soap_parameter_get_first_child_by_name (param, "FreeBusyView");
 	if (!viewparam) return;
@@ -5244,6 +5772,59 @@
 	async_data->items = g_slist_append (async_data->items, vfb);
 }

+static void
+get_free_busy_response_cb (ESoapResponse *response,
+                           GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "FreeBusyResponseArray", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		ESoapParameter *subsubparam;
+
+		subsubparam = e_soap_response_get_first_parameter_by_name (
+			response, "ResponseMessage", &error);
+
+		/* Sanity check */
+		g_return_if_fail (
+			(subsubparam != NULL && error == NULL) ||
+			(subsubparam == NULL && error != NULL));
+
+		if (error != NULL) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (!ews_get_response_status (subsubparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		ews_handle_free_busy_view (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
+}
+
 void
 e_ews_connection_get_free_busy (EEwsConnection *cnc,
                                 gint pri,
@@ -5275,8 +5856,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 						   simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_free_busy_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_free_busy_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -5358,20 +5941,12 @@
 }

 static void
-get_delegate_response_cb (ESoapParameter *param,
-                          GSimpleAsyncResult *simple,
-                          GError **error)
+ews_handle_delegate_user_param (ESoapParameter *param,
+                                EwsAsyncData *async_data)
 {
 	ESoapParameter *subparam, *node, *child;
-	EwsAsyncData *async_data;
 	EwsDelegateInfo *data;
 	gchar *value;
-
-	/* stop on errors */
-	if (error && *error)
-		return;
-
-	async_data = g_simple_async_result_get_op_res_gpointer (simple);

 	node = e_soap_parameter_get_first_child_by_name (param, "DelegateUser");

@@ -5430,6 +6005,47 @@
 	async_data->items_created = g_slist_append (async_data->items_created, data);

 	return;
+}
+
+static void
+get_delegate_response_cb (ESoapResponse *response,
+                          GSimpleAsyncResult *simple)
+{
+	EwsAsyncData *async_data;
+	ESoapParameter *param;
+	ESoapParameter *subparam;
+	GError *error = NULL;
+
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessages", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL) {
+		g_simple_async_result_take_error (simple, error);
+		return;
+	}
+
+	subparam = e_soap_parameter_get_first_child (param);
+
+	while (subparam != NULL) {
+		const gchar *name = (const gchar *) subparam->name;
+
+		if (!ews_get_response_status (subparam, &error)) {
+			g_simple_async_result_take_error (simple, error);
+			return;
+		}
+
+		if (CHECK_ELEMENT (name, "DelegateUserResponseMessageType"))
+			ews_handle_delegate_user_param (subparam, async_data);
+
+		subparam = e_soap_parameter_get_next_child (subparam);
+	}
 }

 /**
@@ -5477,7 +6093,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_delegate_response_cb, pri, cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_delegate_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -5590,8 +6209,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, get_oof_settings_response_cb, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, get_oof_settings_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);
 }

 gboolean
@@ -5650,6 +6271,28 @@
 	g_free (sync_data);

 	return result;
+}
+
+static void
+set_oof_settings_response_cb (ESoapResponse *response,
+                              GSimpleAsyncResult *simple)
+{
+	ESoapParameter *param;
+	GError *error = NULL;
+
+	param = e_soap_response_get_first_parameter_by_name (
+		response, "ResponseMessage", &error);
+
+	/* Sanity check */
+	g_return_if_fail (
+		(param != NULL && error == NULL) ||
+		(param == NULL && error != NULL));
+
+	if (error != NULL)
+		g_simple_async_result_take_error (simple, error);
+
+	else if (!ews_get_response_status (param, &error))
+		g_simple_async_result_take_error (simple, error);
 }

 /**
@@ -5722,8 +6365,10 @@
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);

-	ews_connection_queue_request (cnc, msg, NULL, pri,
-				      cancellable, simple, callback == ews_sync_reply_cb);
+	ews_connection_queue_request (
+		cnc, msg, set_oof_settings_response_cb,
+		pri, cancellable, simple,
+		callback == ews_sync_reply_cb);

 	g_free (time_val);
 	g_free (start_tm);


evo-I#831 - Free/Busy times are not in UTC

Related to https://gitlab.gnome.org/GNOME/evolution/issues/831

--- src/server/e-ews-connection.c
+++ src/server/e-ews-connection.c
@@ -8378,6 +8378,7 @@
 	http://msdn.microsoft.com / en - us / library / aa564001 % 28v = EXCHG.140 % 29.aspx */
 	ICalComponent *vfb;
 	ICalProperty *prop = NULL;
+	ICalTimezone *utc_zone = i_cal_timezone_get_utc_timezone ();
 	ESoapParameter *viewparam, *eventarray, *event_param, *subparam;
 	GTimeVal t_val;
 	const gchar *name;
@@ -8417,7 +8418,7 @@
 				g_time_val_from_iso8601 (new_val, &t_val);
 				g_free (new_val);

-				itt = i_cal_time_new_from_timet_with_zone (t_val.tv_sec, 0, NULL);
+				itt = i_cal_time_new_from_timet_with_zone (t_val.tv_sec, 0, utc_zone);
 				i_cal_period_set_start (ipt, itt);
 				g_clear_object (&itt);

@@ -8440,7 +8441,7 @@
 				g_time_val_from_iso8601 (new_val, &t_val);
 				g_free (new_val);

-				itt = i_cal_time_new_from_timet_with_zone (t_val.tv_sec, 0, NULL);
+				itt = i_cal_time_new_from_timet_with_zone (t_val.tv_sec, 0, utc_zone);
 				i_cal_period_set_end (ipt, itt);
 				g_clear_object (&itt);


Minor code style fixes

Minor code style fixes

--- core/net/uip6.c
+++ core/net/uip6.c
@@ -431,7 +431,6 @@
   }
 #endif /* UIP_UDP */
 }
-
 /*---------------------------------------------------------------------------*/
 #if UIP_TCP && UIP_ACTIVE_OPEN
 struct uip_conn *
@@ -503,8 +502,6 @@
   return conn;
 }
 #endif /* UIP_TCP && UIP_ACTIVE_OPEN */
-
-
 /*---------------------------------------------------------------------------*/
 #if UIP_UDP
 struct uip_udp_conn *
@@ -525,7 +522,6 @@
       goto again;
     }
   }
-

   conn = 0;
   for(c = 0; c < UIP_UDP_CONNS; ++c) {
@@ -551,8 +547,6 @@
   return conn;
 }
 #endif /* UIP_UDP */
-
-
 /*---------------------------------------------------------------------------*/
 #if UIP_TCP
 void
@@ -565,8 +559,6 @@
     }
   }
 }
-
-
 /*---------------------------------------------------------------------------*/
 void
 uip_listen(u16_t port)
@@ -580,7 +572,6 @@
 }
 #endif
 /*---------------------------------------------------------------------------*/
-

 #if UIP_CONF_IPV6_REASSEMBLY
 #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
@@ -814,15 +805,16 @@
  * \brief Process the options in Destination and Hop By Hop extension headers
  */
 static u8_t
-ext_hdr_options_process() {
+ext_hdr_options_process(void)
+{
  /*
   * Length field in the extension header: length of th eheader in units of
   * 8 bytes, excluding the first 8 bytes
   * length field in an option : the length of data in the option
   */
   uip_ext_opt_offset = 2;
-  while(uip_ext_opt_offset  < ((UIP_EXT_BUF->len << 3) + 8)) {
-    switch (UIP_EXT_HDR_OPT_BUF->type) {
+  while(uip_ext_opt_offset < ((UIP_EXT_BUF->len << 3) + 8)) {
+    switch(UIP_EXT_HDR_OPT_BUF->type) {
       /*
        * for now we do not support any options except padding ones
        * PAD1 does not make sense as the header must be 8bytes aligned,


Shortened the function version a bit.

Shortened the function version a bit.

--- trifle.h
+++ trifle.h
@@ -39,22 +39,10 @@
 }

 #define COMPARE_FLOATS_CONST_MOD( float1, float2 ) \
-  _Generic((float1), float: compare_floats_const_mod_f, \
-                     double: compare_floats_const_mod_d, \
-                     long double: compare_floats_const_mod_ld, \
-                     default: WRONG_TYPE)(float1, float2)
-
-bool compare_floats_const_mod_f(float float1, float float2) {
-  return ((float1 * 0.999f < float2) && (float2 * 0.999f < float1));
-}
-
-bool compare_floats_const_mod_d(double float1, double float) {
-  return ((float1 * 0.999 < float2) && (float2 * 0.999 < float1));
-}
-
-bool compare_floats_const_mod_ld(long double float1, long double float2) {
-  return ((float1 * 0.999L < float2) && (float2 * 0.999L < float1));
-}
+  _Generic((float1), float: compare_floats_f, \
+                     double: compare_floats_d, \
+                     long double: compare_floats_ld, \
+                     default: WRONG_TYPE)(float1, float2, 0.999L)

 #define WRONG_TYPE( float1, float2 ) \
   _const_assert(true, "Wrong type(s) supplied to COMPARE_FLOATS");


Fix memory leak

Fix memory leak

Credit to OSS-Fuzz

--- src/server/ua_server_binary.c
+++ src/server/ua_server_binary.c
@@ -544,6 +544,8 @@
     UA_LOG_ERROR(server->config.logger, UA_LOGCATEGORY_NETWORK,
                  "Client replied with an error message: %s %.*s",
                  UA_StatusCode_name(errorMessage.error), errorMessage.reason.length, errorMessage.reason.data);
+
+    UA_TcpErrorMessage_deleteMembers(&errorMessage);
 }

 /* Takes decoded messages starting at the nodeid of the content type. Only OPN


Added name and license

Added name and license

--- un_lzw.c
+++ un_lzw.c
@@ -1,3 +1,7 @@
+//
+// Author : Jordan Penard
+// MIT License
+//

 #include <stdio.h>
 #include <stdlib.h>


don't crash when server cannot be found

don't crash when server cannot be found

--- v/http.c
+++ v/http.c
@@ -912,6 +912,7 @@

   if ( !(htp_u = _http_serv_find(rep_u->sev_l)) ) {
     uL(fprintf(uH, "http: server not found: %d\r\n", rep_u->sev_l));
+    return;
   }
   if ( !(hon_u = _http_conn_find(htp_u, rep_u->coq_l)) ) {
     uL(fprintf(uH, "http: connection not found: %d\r\n", rep_u->coq_l));


fixing unitialized variable

fixing unitialized variable

--- src/server/ua_server_binary.c
+++ src/server/ua_server_binary.c
@@ -213,7 +213,7 @@
     }

     /* Read the security header */
-    UA_UInt32 tokenId;
+    UA_UInt32 tokenId = 0;
     UA_SequenceHeader sequenceHeader;
     retval = UA_UInt32_decodeBinary(msg, pos, &tokenId);
     retval |= UA_SequenceHeader_decodeBinary(msg, pos, &sequenceHeader);


Comments

Comments

--- v/raft.c
+++ v/raft.c
@@ -53,6 +53,8 @@
   }
 }

+/* u2_raft_readopt(): parse a string into a list of raft peers.
+*/
 u2_bean
 u2_raft_readopt(u2_ropt* rop_u, const c3_c* arg_c)
 {
@@ -83,6 +85,8 @@
   return ((float) rand() / RAND_MAX) * 150;
 }

+/* _raft_do_rest(): act on an incoming raft RPC request.
+*/
 static void
 _raft_do_rest(u2_rcon* ron_u, struct Raft_Rest res_u)
 {
@@ -114,6 +118,8 @@
   /* TODO */
 }

+/* _raft_do_rasp(): act on an incoming raft RPC response.
+*/
 static void
 _raft_do_rasp(u2_rcon* ron_u, struct Raft_Rasp ras_u)
 {
@@ -126,6 +132,8 @@
   }
 }

+/* _raft_conn_work(): read and write requests and responses.
+*/
 static void
 _raft_conn_work(u2_rcon* ron_u)
 {
@@ -167,6 +175,8 @@

 }

+/* _raft_conn_read_cb(): generic connection read callback.
+*/
 static void
 _raft_conn_read_cb(uv_stream_t* tcp_u,
                    ssize_t      siz_i,
@@ -199,6 +209,8 @@
   u2_lo_shut(u2_no);
 }

+/* _raft_conn_new(): allocate a new raft connection.
+*/
 static void
 _raft_conn_new(u2_raft* raf_u)
 {
@@ -231,6 +243,8 @@
   }
 }

+/* _raft_remove_run(): remove a connection from the list of unknowns.
+*/
 static void
 _raft_remove_run(u2_rcon* ron_u)
 {
@@ -252,6 +266,8 @@
   }
 }

+/* _raft_conn_free(): unlink a connection and free its resources.
+*/
 static void
 _raft_conn_free(uv_handle_t* had_u)
 {
@@ -269,6 +285,8 @@
   free(ron_u);
 }

+/* _raft_conn_dead(): kill a connection.
+*/
 static void
 _raft_conn_dead(u2_rcon* ron_u)
 {
@@ -276,6 +294,8 @@
   uv_close((uv_handle_t*)&ron_u->wax_u, _raft_conn_free);
 }

+/* _raft_listen_cb(): generic listen callback.
+*/
 static void
 _raft_listen_cb(uv_stream_t* str_u, c3_i sas_i)
 {
@@ -290,6 +310,8 @@
   }
 }

+/* _raft_getaddrinfo_cb(): generic getaddrinfo callback, makes connections.
+*/
 static void
 _raft_getaddrinfo_cb(uv_getaddrinfo_t* gaf_u,
                      c3_i              sas_i,
@@ -298,6 +320,8 @@
   /* TODO */
 }

+/* _raft_conn_all(): ensure that we are connected to each peer.
+*/
 static void
 _raft_conn_all(u2_raft* raf_u, void (*con_f)(u2_rcon* ron_u))
 {
@@ -349,18 +373,24 @@
   }
 }

+/* _raft_send_beat(): send a heartbeat (empty AppendEntries) to peer.
+*/
 static void
 _raft_send_beat(u2_rcon* ron_u)
 {
   /* TODO */
 }

+/* _raft_send_revo(): send a RequestVote to peer.
+*/
 static void
 _raft_send_revo(u2_rcon* ron_u)
 {
   /* TODO */
 }

+/* _raft_start_election(): bump term, vote for self, solicit votes from peers.
+*/
 static void
 _raft_start_election(u2_raft* raf_u)
 {
@@ -382,12 +412,19 @@
   _raft_conn_all(raf_u, _raft_send_revo);
 }

+/* _raft_heartbeat(): send a heartbeat to all peers.
+*/
 static void
 _raft_heartbeat(u2_raft* raf_u)
 {
   _raft_conn_all(raf_u, _raft_send_beat);
 }

+/* _raft_time_cb(): generic timer callback.
+**
+** Called on election timeouts for non-leaders, and at heartbeat interval for
+** leaders.
+*/
 static void
 _raft_time_cb(uv_timer_t* tim_u, c3_i sas_i)
 {
@@ -472,6 +509,8 @@
   raf_u->typ_e = u2_raty_lead;
 }

+/* u2_raft_io_init(): begin raft I/O.
+*/
 void
 u2_raft_io_init()
 {


View: Ensure statuscodes are always checked

--- src/server/ua_services_view.c
+++ src/server/ua_services_view.c
@@ -70,7 +70,7 @@
     size_t size;     /* used space */
 } RefTree;

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 RefTree_init(RefTree *rt) {
     size_t space = (sizeof(UA_NodeId) + sizeof(RefEntry)) * UA_BROWSE_INITIAL_SIZE;
     rt->targets = (UA_NodeId*)UA_malloc(space);
@@ -90,7 +90,7 @@
 }

 /* Double the capacity of the reftree */
-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 RefTree_double(RefTree *rt) {
     size_t capacity = rt->capacity * 2;
     UA_assert(capacity > 0);
@@ -122,7 +122,7 @@
     return UA_STATUSCODE_GOOD;
 }

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 RefTree_add(RefTree *rt, const UA_NodeId *target) {
     UA_StatusCode s = UA_STATUSCODE_GOOD;
     if(rt->capacity <= rt->size) {
@@ -160,7 +160,7 @@
     size_t nki;  /* Index of the reference in the ReferenceKind that is visited */
 };

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 ContinuationPoint_init(ContinuationPoint *cp, UA_UInt32 maxRefs,
                        UA_Boolean recursive) {
     memset(cp, 0, sizeof(ContinuationPoint));
@@ -192,7 +192,7 @@
     UA_ReferenceDescription *descr;
 } RefResult;

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 RefResult_init(RefResult *rr, UA_UInt32 maxRefs) {
     UA_UInt32 initialRes = UA_BROWSE_INITIAL_SIZE;
     if(initialRes > maxRefs)
@@ -207,7 +207,7 @@
     return UA_STATUSCODE_GOOD;
 }

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 RefResult_double(RefResult *rr, UA_UInt32 maxSize) {
     size_t newSize = rr->capacity * 2;
     if(newSize > maxSize)
@@ -231,7 +231,7 @@
 }

 /* Target node on top of the stack */
-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 fillReferenceDescription(UA_Server *server, const UA_NodeReferenceKind *ref, UA_UInt32 mask,
                          const UA_ExpandedNodeId *nodeId, const UA_Node *curr,
                          UA_ReferenceDescription *descr) {
@@ -284,7 +284,7 @@
     return true;
 }

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 browseNodeRefKind(UA_Server *server, UA_Session *session, ContinuationPoint *cp,
                   RefResult *rr, UA_Boolean *maxed, const UA_NodeReferenceKind *rk,
                   const UA_ExpandedNodeId *target) {
@@ -350,7 +350,7 @@
     return retval;
 }

-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 browseNode(UA_Server *server, UA_Session *session,
            ContinuationPoint *cp, RefResult *rr, UA_Boolean *maxed,
            size_t referenceTypesSize, const UA_NodeId *referenceTypes,
@@ -388,7 +388,7 @@
  * Including the BrowseDescription. Returns whether there are remaining
  * references. */
 /* Results for a single browsedescription. Sets all NodeIds for the RefTree. */
-static UA_StatusCode
+static UA_StatusCode UA_FUNC_ATTR_WARN_UNUSED_RESULT
 browseWithCp(UA_Server *server, UA_Session *session, ContinuationPoint *cp,
              RefResult *rr, UA_Boolean *maxed) {
     /* Is the browsedirection valid? */


Now correctly reading all overlapping file descriptors

--- unpack.c
+++ unpack.c
@@ -15,13 +15,21 @@
 #include <sys/types.h>
 #include <dirent.h>

+typedef struct {
+  target_ulong start;
+  target_ulong end;
+  char* filename;
+  FILE* file;
+} vad_descriptor;
+
 int before_block_exec(CPUState *env, TranslationBlock *tb);
 int vmi_pgd_changed(CPUState *env, target_ulong old_pgd, target_ulong new_pgd);
 bool in_module(CPUState *env, TranslationBlock *tb);
 bool seen_code(CPUState *env, TranslationBlock *tb);
-bool isEnclosing(char* filename, target_ulong address);
-void free_file_array(FILE** files);
-FILE** get_enclosing_vad_files(target_ulong address);
+vad_descriptor open_vad(char* filename);
+void free_vad_descriptor_array(vad_descriptor* vads);
+vad_descriptor* get_enclosing_vad_files(target_ulong address);
+

 bool init_plugin(void *);
 void uninit_plugin(void *);
@@ -54,16 +62,17 @@
   return inside;
 }

-bool isEnclosing(char* filename, target_ulong address) {
+vad_descriptor open_vad(char* filename) {
   // Structure of the filenames are:
   //  ProcName.Offset.start-end.dmp
   // So to extract the start and end, first we find the dash
+  vad_descriptor vd;
   int dashIdx = 0;
   for(; filename[dashIdx] != '-' && filename[dashIdx] != '\0'; dashIdx++) {}

   if(filename[dashIdx] == '\0') {
     printf("Malformed VAD filename!  %s", filename);
-    return false;
+    return vd;
   }

   // Now, walk backwards to find the previous .
@@ -84,8 +93,7 @@
   int startLen = dashIdx - startIdx;
   int endLen = endIdx - dashIdx - 1;
   // Copy them to their own buffers and parse them
-  char* startBuff = calloc(startLen, sizeof(char));
-  char* endBuff = calloc(endLen, sizeof(char));
+  char* startBuff = calloc(startLen, sizeof(char)); char* endBuff = calloc(endLen, sizeof(char));

   strncpy(startBuff, filename + startIdx, startLen);
   strncpy(endBuff, filename + dashIdx + 1, endLen);
@@ -96,10 +104,13 @@
   free(startBuff);
   free(endBuff);

-  return startAddr < address && address < endAddr;
-}
-
-FILE** get_enclosing_vad_files(target_ulong address) {
+  vd.start = startAddr;
+  vd.end = endAddr;
+  vd.filename = filename;
+  return vd;
+}
+
+vad_descriptor* get_enclosing_vad_files(target_ulong address) {
   DIR *dp;
   struct dirent *ep;

@@ -110,45 +121,68 @@
   }
   int fileCount = 0;
   while((ep = readdir(dp))) {
-    printf("Checking %s\n", ep->d_name);
     if(ep->d_type == DT_REG) {
-      printf("\tchecking %s for enclosure\n", ep->d_name);
-      if(isEnclosing(ep->d_name, address)) {
-        printf("\t%s encloses %#010llx\n", ep->d_name, (unsigned long long) address);
+      vad_descriptor vd = open_vad(ep->d_name);
+      if( vd.start < address && address < vd.end ) {
         fileCount++;
       }
     }
   }

-  FILE** files = calloc(fileCount + 1, sizeof(FILE*));
-
-  return files;
-}
-
-void free_file_array(FILE** files) {
-  printf("\tfreeing file array\n");
+  vad_descriptor* enclosing_vads = calloc(fileCount + 1, sizeof(vad_descriptor));
+
+  rewinddir(dp);
+  int idx = 0;
+  while((ep = readdir(dp))) {
+    if(ep->d_type == DT_REG) {
+      vad_descriptor vd = open_vad(ep->d_name);
+      if( vd.start < address && address < vd.end ) {
+        enclosing_vads[idx] = vd;
+        char path[100] = "./vads/"; // should be plenty...
+        strcat(path + 7, vd.filename);
+        printf("fopening %s\n", path);
+        enclosing_vads[idx].file = fopen(path, "rb");
+        printf("file %p\n", enclosing_vads[idx].file);
+        idx++;
+      }
+    }
+  }
+
+  return enclosing_vads;
+}
+
+void free_vad_descriptor_array(vad_descriptor* vads) {
   int idx;
-  for(idx = 0; files[idx] != NULL; idx++) {
-    fclose(files[idx]);
-  }
-  free(files);
+  for(idx = 0; vads[idx].filename != NULL; idx++) {
+    fclose(vads[idx].file);
+  }
+  free(vads);
 }

 // Check if we're inside code we've seen before
 bool seen_code(CPUState *env, TranslationBlock *tb) {
   // Grab the memory for this basic block
-  //target_ulong bbStart = tb->pc;
-  //target_ulong bbSize  = tb->size;
-  //unsigned char *buf = calloc(bbSize, sizeof(char));
+  target_ulong bbStart = tb->pc;
+  target_ulong bbSize  = tb->size;
+  unsigned char *buf = calloc(bbSize + 1, sizeof(char));
   // Copy the instructions from this bb to a buffer
-  //cpu_memory_rw_debug(env, bbStart, buf, bbSize, 0);
-
-  printf("\tgetting enclosing vad files\n");
+  //printf("Start: %#010llx Size: %#010llx", (unsigned long long) bbStart, (unsigned long long) bbSize);
+  cpu_memory_rw_debug(env, bbStart, buf, bbSize, 0);
+
   // Find the files that contain this range
-  FILE** files = get_enclosing_vad_files(tb->pc);
-
-  free_file_array(files);
-  //free(buf);
+  vad_descriptor* vads = get_enclosing_vad_files(tb->pc);
+
+  int idx;
+  for(idx = 0; vads[idx].filename != NULL; idx++) {
+    printf("Enclosing VAD: Start %#010llx   End %#010llx   Filename %s   File %p\n", \
+        (unsigned long long) vads[idx].start, \
+        (unsigned long long) vads[idx].end, \
+        vads[idx].filename, \
+        vads[idx].file);
+  }
+
+  free_vad_descriptor_array(vads);
+
   return false;
 }


Include errno properly on OpenBSD

Include errno properly on OpenBSD

--- v/sist.c
+++ v/sist.c
@@ -2,11 +2,11 @@
 **
 ** This file is in the public domain.
 */
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/errno.h>
 #include <unistd.h>
 #include <uv.h>


Update trophy.c

Update trophy.c

Implemented changes suggested by notzecoxao

--- trophy.c
+++ trophy.c
@@ -55,7 +55,7 @@
 u8 ckey[0x10];
 u8 civ[0x10];
 trp_header *header;
-u8 *np_comm_id = NULL;
+u8 np_comm_id[0x10];

 u8 brutforce_npcommid (u8 *ptr, u64 len) {
@@ -63,10 +63,8 @@
 	u8 *out;
 	u8 *str;

-	printf("[!] Bruteforce attack started ... ");
+	// printf("[!] Bruteforce attack started ... ");

-	np_comm_id = malloc(0x10);
-
 	for ( i = 0; i < 99999; i++ ) {
 		memset(np_comm_id, 0, 0x10);
 		sprintf(np_comm_id, "%s%05d_00", "NPWR", i);
@@ -169,4 +167,4 @@
 	}

 	return 0;
-}+}


negotiate about window size properly

negotiate about window size properly

--- v/term.c
+++ v/term.c
@@ -26,7 +26,12 @@
 static void _term_read_tn_cb(uv_stream_t*, ssize_t, uv_buf_t);
 static void _term_read_cb(uv_stream_t*, ssize_t, uv_buf_t);
 static void _term_suck(u2_utty*, const c3_y*, ssize_t);
-static void _tel_event(telnet_nvt* nvt, telnet_event* evt);
+static void _tel_event(telnet_nvt*, telnet_event*);
+static void _tel_opt(telnet_nvt*, telnet_byte, telnet_telopt_event*);
+
+#define _T_ECHO 1    //  local echo
+#define _T_CTIM 3    //  suppress GA/char-at-a-time
+#define _T_NAWS 31   //  negotiate about window size

 /* _term_alloc(): libuv buffer allocator.
 */
@@ -280,9 +285,10 @@
     tty_u->tid_l = u2_Host.uty_u->tid_l + 1;
     tty_u->nex_u = u2_Host.uty_u;
     u2_Host.uty_u = tty_u;
-    pty_u->tel_u = telnet_nvt_new(tty_u, _tel_event, NULL, NULL);
-    telnet_telopt_enable(pty_u->tel_u, 1, TELNET_LOCAL); /* ECHO */
-    telnet_telopt_enable(pty_u->tel_u, 3, TELNET_LOCAL); /* SUPPRESS GA */
+    pty_u->tel_u = telnet_nvt_new(tty_u, _tel_event, _tel_opt, NULL);
+    telnet_telopt_enable(pty_u->tel_u, _T_ECHO, TELNET_LOCAL);
+    telnet_telopt_enable(pty_u->tel_u, _T_CTIM, TELNET_LOCAL);
+    telnet_telopt_enable(pty_u->tel_u, _T_NAWS, TELNET_REMOTE);
     {
       u2_noun tid = u2_dc("scot", c3__ud, tty_u->tid_l);
       u2_noun pax = u2nq(c3__gold, c3__term, tid, u2_nul);
@@ -658,7 +664,7 @@
   u2_reck_plan(u2A, pax, u2nc(c3__belt, blb));
 }

-/* _tel_event: telnet sucker
+/* _tel_event(): telnet sucker
 */
 #define _te_nvt telnet_nvt
 #define _te_evt telnet_event
@@ -691,6 +697,47 @@
   }
 }

+#define _to_evt telnet_telopt_event
+#define _to_dvt telnet_telopt_data_event
+#define _to_tvt telnet_telopt_toggle_event
+/* _tel_opt(): telnet event sucker
+*/
+static void
+_tel_opt(_te_nvt* nvt, telnet_byte opt, _to_evt* evt)
+{
+  switch (evt->type)
+  {
+    default: break;
+    case TELNET_EV_TELOPT_DATA:
+    {
+      _to_dvt* dv = (_to_dvt*)evt;
+      u2_utel* tel_u;
+      u2_noun pax;
+      u2_noun blu;
+      u2_noun tid;
+      c3_s col_s;
+      c3_s row_s;
+
+      if ( opt != _T_NAWS ) {
+        return;
+      }
+
+      c3_assert(0 < telnet_get_userdata(nvt, (void**)&tel_u));
+
+      col_s = dv->data[0] | (dv->data[1] << 8);
+      row_s = dv->data[2] | (dv->data[3] << 8);
+
+      tel_u->uty_t.tat_u.siz.col_l = col_s;
+      tel_u->uty_t.tat_u.siz.row_l = row_s;
+
+      tid = u2_dc("scot", c3__ud, tel_u->uty_t.tid_l);
+      pax = u2nq(c3__gold, c3__term, tid, u2_nul);
+      blu = u2nc(col_s, row_s);
+      u2_reck_plan(u2A, pax, u2nc(c3__blew, blu));
+      break;
+    }
+  }
+}
 /* _term_io_suck_char(): process a single character.
 */
 static void


fix 7MB/revision memory leak

fix 7MB/revision memory leak

--- v/unix.c
+++ v/unix.c
@@ -710,6 +710,7 @@
       }

       if ( fln_w == flt_w && 0 == memcmp(pad_y, pat_y, fln_w) ) {
+        free(pad_y);
         free(pat_y);
         return u3_nul;
       }


tstamp: implemented different formatters: decimal (default), time-only (-t) and date-time (-T)

--- tstamp.c
+++ tstamp.c
@@ -19,8 +19,14 @@

 #include "tstamp.h"

+#define FMT_SHOW_TIME		(1 << 0)
+#define FMT_SHOW_DATE		(1 << 1)
+
+#define FMT_DATE	"%04u-%02u-%02u %02u:%02u:%02u.%06u"
+#define FMT_TIME	(FMT_DATE + 15)
+
 static struct tm *(*gen_tm)(const time_t *, struct tm *);
-static size_t (*fmt_tstamp)(char *, size_t);
+static size_t (*fmt_tstamp)(char *, size_t, time_t, suseconds_t);

 static inline void write_all(struct iovec *iov, int iovcnt)
 {
@@ -45,25 +51,38 @@
 	}
 }

-static size_t fmt_tstamp_time(char *buf, size_t buf_len)
+static size_t fmt_tstamp_decimal(char *buf, size_t buf_len, time_t sec, suseconds_t usec)
 {
-	struct timeval timeval;
+	return snprintf(buf, buf_len, "%u.%06u",
+			(unsigned)sec,
+			(unsigned)usec);
+}
+
+static size_t fmt_tstamp_date(char *buf, size_t buf_len, time_t sec, suseconds_t usec)
+{
 	struct tm tm;
+	gen_tm(&sec, &tm);

-	gettimeofday(&timeval, NULL);
-	gen_tm(&timeval.tv_sec, &tm);
+	return snprintf(buf, buf_len, FMT_DATE,
+			1900+tm.tm_year, 1+tm.tm_mon, tm.tm_mday,
+			tm.tm_hour, tm.tm_min, tm.tm_sec,
+			(unsigned)usec);
+}

-	return snprintf(buf, buf_len, "%02u:%02u:%02u.%06lu",
-			tm.tm_hour,
-			tm.tm_min,
-			tm.tm_sec,
-			(unsigned long)timeval.tv_usec);
+static size_t fmt_tstamp_time(char *buf, size_t buf_len, time_t sec, suseconds_t usec)
+{
+	struct tm tm;
+	gen_tm(&sec, &tm);
+
+	return snprintf(buf, buf_len, FMT_TIME,
+			tm.tm_hour, tm.tm_min, tm.tm_sec,
+			(unsigned)usec);
 }

 static inline void dump(FILE *f, /*const*/ char *del)
 {
 	char buf[MAXBUF];
-	char tstamp_buf[20];
+	char tstamp_buf[32];

 	struct iovec iov[] = {
 		{tstamp_buf, 0},
@@ -71,7 +90,12 @@
 		{buf, 0} };

 	while (fgets(buf, sizeof(buf), f) != NULL) {
-		iov[0].iov_len = fmt_tstamp(tstamp_buf, sizeof(tstamp_buf));
+		struct timeval timeval;
+		gettimeofday(&timeval, NULL);
+
+		iov[0].iov_len = fmt_tstamp(tstamp_buf, sizeof(tstamp_buf),
+					    timeval.tv_sec,
+					    timeval.tv_usec);
 		iov[2].iov_len = strlen(buf);

 		write_all(iov, 3);
@@ -82,11 +106,11 @@
 {
 	int opt;
 	char *del = ": ";
+	unsigned flag = 0;

 	gen_tm = gmtime_r;
-	fmt_tstamp = fmt_tstamp_time;

-	while ((opt = getopt(argc, argv, "?Vld:")) != -1) {
+	while ((opt = getopt(argc, argv, "?VltTd:")) != -1) {
 		switch (opt) {
 		case 'V':
 			fputs("tstamp v" VERSION " <" HOME ">\n"
@@ -96,6 +120,11 @@
 			return 0;
 		case 'l':
 			gen_tm = localtime_r;
+		case 't':
+			flag |= FMT_SHOW_TIME;
+			break;
+		case 'T':
+			flag |= FMT_SHOW_DATE;
 			break;
 		case 'd':
 			del = optarg;
@@ -103,15 +132,24 @@
 		default:
 			fprintf(stderr,
 				"tstamp v" VERSION "\n" DESCRIPTION "\n\n"
-				"Usage: %s [-V] [-l] [-d <del>]\n\n"
+				"Usage: %s [-V] [-ltT] [-d <del>]\n\n"
 				"  -V   print version and exit\n"
 				"  -d   delimiter (default: \": \")\n"
+				"  -t   show time\n"
+				"  -T   show date and time\n"
 				"  -l   use localtime instead of GMT/UTC/Z\n",
 				argv[0]);
 			return 1;
 		}
 	}

+	if (flag & FMT_SHOW_DATE)
+		fmt_tstamp = fmt_tstamp_date;
+	else if (flag & FMT_SHOW_TIME)
+		fmt_tstamp = fmt_tstamp_time;
+	else
+		fmt_tstamp = fmt_tstamp_decimal;
+
 	dump(stdin, del);
 	return 0;
 }


Replace setlinebuf with setvbuf.

Replace setlinebuf with setvbuf.

--- ttylog.c
+++ ttylog.c
@@ -68,7 +68,7 @@

 	if ((lg = fopen(logfile, "w")) == NULL)
 		err(1, "fopen %s", logfile);
-	if (setlinebuf(lg) != 0)
+	if (setvbuf(lg, NULL, _IOLBF, 0) != 0)
 		err(1, "setlinebuf");

 	memset(&act, 0, sizeof(act));


Delete utSort.h

Delete utSort.h

--- utSort.h
+++ utSort.h
@@ -1,120 +0,0 @@
-#ifndef UTSORT_H
-#define UTSORT_H
-#include "include/Shapes.h"
-#include "include/Media.h"
-#include "include/Sort.h"
-
-TEST (Sort, sortByIncreasingPerimeter) {
-	vertex vertex_1 = {0, 0};
-	vertex vertex_2 = {3, 0};
-	vertex vertex_3 = {3, 4};
-	Triangle tri(vertex_1, vertex_2, vertex_3);
-	Circle cir(0, 0, 12);
-	Rectangle rect(0, 0, 8, 9);
-
-	std::list<Shape *> shapeList;
-	shapeList.push_back(&cir);//2*Pi*12
-	shapeList.push_back(&tri);//12
-	shapeList.push_back(&rect);//34
-
-	Sort sort1;
-	sort1.sortByIncreasingPerimeter(&shapeList);
-
-	ASSERT_EQ(tri.perimeter(), shapeList.front()->perimeter());
-	shapeList.pop_front();
-	ASSERT_EQ(rect.perimeter(), shapeList.front()->perimeter());
-	ASSERT_EQ(cir.perimeter(), shapeList.back()->perimeter());
-
-}
-
-TEST (Sort, sortByDecreasingPerimeter) {
-	vertex vertex_1 = {0, 0};
-	vertex vertex_2 = {3, 0};
-	vertex vertex_3 = {3, 4};
-	Triangle tri(vertex_1, vertex_2, vertex_3);
-	Circle cir(0, 0, 12);
-	Rectangle rect(0, 0, 8, 9);
-
-	std::list<Shape *> shapeList;
-	shapeList.push_back(&cir);//2*PI*12
-	shapeList.push_back(&tri);//12
-	shapeList.push_back(&rect);//34
-
-	Sort sort1;
-	sort1.sortByDecreasingPerimeter(&shapeList);
-
-	ASSERT_EQ(cir.perimeter(), shapeList.front()->perimeter());
-	shapeList.pop_front();
-	ASSERT_EQ(rect.perimeter(), shapeList.front()->perimeter());
-	ASSERT_EQ(tri.perimeter(), shapeList.back()->perimeter());
-}
-
-TEST (Sort, sortByIncreasingArea) {
-	vertex vertex_1 = {0, 0};
-	vertex vertex_2 = {3, 0};
-	vertex vertex_3 = {3, 4};
-	Triangle tri(vertex_1, vertex_2, vertex_3);
-	Circle cir(0, 0, 12);
-	Rectangle rect(0, 0, 8, 9);
-
-	std::list<Shape *> shapeList;
-	shapeList.push_back(&cir);//12*12*PI
-	shapeList.push_back(&tri);//6
-	shapeList.push_back(&rect);//72
-
-	Sort sort1;
-	sort1.sortByIncreasingArea(&shapeList);
-
-	ASSERT_EQ(tri.area(), shapeList.front()->area());
-	shapeList.pop_front();
-	ASSERT_EQ(rect.area(), shapeList.front()->area());
-	ASSERT_EQ(cir.area(), shapeList.back()->area());
-}
-
-TEST (Sort, sortByDecreasingArea) {
-	vertex vertex_1 = {0, 0};
-	vertex vertex_2 = {3, 0};
-	vertex vertex_3 = {3, 4};
-	Triangle tri(vertex_1, vertex_2, vertex_3);
-	Circle cir(0, 0, 12);
-	Rectangle rect(0, 0, 8, 9);
-
-	std::list<Shape *> shapeList;
-	shapeList.push_back(&cir);//12*12*PI
-	shapeList.push_back(&tri);//6
-	shapeList.push_back(&rect);//72
-
-	Sort sort1;
-	sort1.sortByDecreasingArea(&shapeList);
-
-	ASSERT_EQ(cir.area(), shapeList.front()->area());
-	shapeList.pop_front();
-	ASSERT_EQ(rect.area(), shapeList.front()->area());
-	ASSERT_EQ(tri.area(), shapeList.back()->area());
-
-}
-
-
-TEST (Sort, sortByIncreasingCompactness) {
-	vertex vertex_1 = {0, 0};
-	vertex vertex_2 = {3, 0};
-	vertex vertex_3 = {3, 4};
-	Triangle tri(vertex_1, vertex_2, vertex_3);
-	Circle cir(0, 0, 12);
-	Rectangle rect(0, 0, 8, 9);
-
-	std::list<Shape *> shapeList;
-	shapeList.push_back(&cir);//6
-	shapeList.push_back(&tri);//0.5
-	shapeList.push_back(&rect);//2.11764705882
-
-	Sort sort1;
-	sort1.sortByIncreasingCompactness(&shapeList);
-
-	ASSERT_EQ(tri.Compactness(), shapeList.front()->Compactness());
-	shapeList.pop_front();
-	ASSERT_EQ(rect.Compactness(), shapeList.front()->Compactness());
-	ASSERT_EQ(cir.Compactness(), shapeList.back()->Compactness());
-}
-
-#endif


uthash.h: fix clang fallthrough warnings

Signed-off-by: Yuxuan Shui <7f7e1535bcd10fa942d56a3436533af20f33203f@gmail.com>

--- uthash.h
+++ uthash.h
@@ -660,6 +660,16 @@
   c -= a; c -= b; c ^= ( b >> 15 );                                              \
 } while (0)

+#ifdef __has_attribute
+#if __has_attribute(fallthrough)
+#define fallthrough() __attribute__((fallthrough))
+#else
+#define fallthrough()
+#endif
+#else
+#define fallthrough()
+#endif
+
 #define HASH_JEN(key,keylen,hashv)                                               \
 do {                                                                             \
   unsigned _hj_i,_hj_j,_hj_k;                                                    \
@@ -685,16 +695,16 @@
   }                                                                              \
   hashv += (unsigned)(keylen);                                                   \
   switch ( _hj_k ) {                                                             \
-    case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); /* FALLTHROUGH */         \
-    case 10: hashv += ( (unsigned)_hj_key[9] << 16 );  /* FALLTHROUGH */         \
-    case 9:  hashv += ( (unsigned)_hj_key[8] << 8 );   /* FALLTHROUGH */         \
-    case 8:  _hj_j += ( (unsigned)_hj_key[7] << 24 );  /* FALLTHROUGH */         \
-    case 7:  _hj_j += ( (unsigned)_hj_key[6] << 16 );  /* FALLTHROUGH */         \
-    case 6:  _hj_j += ( (unsigned)_hj_key[5] << 8 );   /* FALLTHROUGH */         \
-    case 5:  _hj_j += _hj_key[4];                      /* FALLTHROUGH */         \
-    case 4:  _hj_i += ( (unsigned)_hj_key[3] << 24 );  /* FALLTHROUGH */         \
-    case 3:  _hj_i += ( (unsigned)_hj_key[2] << 16 );  /* FALLTHROUGH */         \
-    case 2:  _hj_i += ( (unsigned)_hj_key[1] << 8 );   /* FALLTHROUGH */         \
+    case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); fallthrough();            \
+    case 10: hashv += ( (unsigned)_hj_key[9] << 16 );  fallthrough();            \
+    case 9:  hashv += ( (unsigned)_hj_key[8] << 8 );   fallthrough();            \
+    case 8:  _hj_j += ( (unsigned)_hj_key[7] << 24 );  fallthrough();            \
+    case 7:  _hj_j += ( (unsigned)_hj_key[6] << 16 );  fallthrough();            \
+    case 6:  _hj_j += ( (unsigned)_hj_key[5] << 8 );   fallthrough();            \
+    case 5:  _hj_j += _hj_key[4];                      fallthrough();            \
+    case 4:  _hj_i += ( (unsigned)_hj_key[3] << 24 );  fallthrough();            \
+    case 3:  _hj_i += ( (unsigned)_hj_key[2] << 16 );  fallthrough();            \
+    case 2:  _hj_i += ( (unsigned)_hj_key[1] << 8 );   fallthrough();            \
     case 1:  _hj_i += _hj_key[0];                                                \
   }                                                                              \
   HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                             \


[txt2ff] draw splines

[txt2ff] draw splines