[evolution-ews] e_soap_response_get_first_parameter_by_name(): Add GError param.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] e_soap_response_get_first_parameter_by_name(): Add GError param.
- Date: Fri, 13 Jul 2012 12:34:33 +0000 (UTC)
commit ab932c5584b744c05c9c1e62dff9bfc2e7f3d7ae
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Jul 13 07:55:07 2012 -0400
e_soap_response_get_first_parameter_by_name(): Add GError param.
If the requested parameter is not found, the function checks for a
"faultstring" parameter and uses its value to set an error message,
or else sets an error message about the missing parameter.
src/server/e-ews-connection.c | 25 +++----------------------
src/server/e-soap-response.c | 41 ++++++++++++++++++++++++++++++++++++++---
src/server/e-soap-response.h | 3 ++-
3 files changed, 43 insertions(+), 26 deletions(-)
---
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 3765fdf..34d9682 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -202,23 +202,6 @@ comp_func (gconstpointer a,
return 0;
}
-static void
-ews_parse_soap_fault (ESoapResponse *response,
- GError **error)
-{
- ESoapParameter *param;
- gchar *faultstring = NULL;
-
- param = e_soap_response_get_first_parameter_by_name(response, "faultstring");
- if (param)
- faultstring = e_soap_parameter_get_string_value (param);
-
- g_set_error (error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_UNKNOWN,
- "%s", faultstring?:"No <ResponseMessages> or <FreeBusyResponseArray> or SOAP <faultstring> in response");
-
- g_free (faultstring);
-}
-
static gboolean
ews_next_request (gpointer _cnc)
{
@@ -426,10 +409,10 @@ ews_response_cb (SoupSession *session,
e_soap_response_dump_response (response, stdout);
param = e_soap_response_get_first_parameter_by_name (
- response, "ResponseMessages");
+ response, "ResponseMessages", NULL);
if (param == NULL)
param = e_soap_response_get_first_parameter_by_name (
- response, "FreeBusyResponseArray");
+ response, "FreeBusyResponseArray", NULL);
if (param != NULL) {
/* Iterate over all "*ResponseMessage" elements. */
@@ -458,7 +441,7 @@ ews_response_cb (SoupSession *session,
}
} else {
param = e_soap_response_get_first_parameter_by_name (
- response, "ResponseMessage");
+ response, "ResponseMessage", &error);
if (param != NULL) {
/*Parse GetUserOofSettingsResponse and SetUserOofSettingsResponse*/
@@ -470,8 +453,6 @@ ews_response_cb (SoupSession *session,
if (enode->cb)
enode->cb (subparam, enode->simple, &error);
}
- } else {
- ews_parse_soap_fault (response, &error);
}
}
diff --git a/src/server/e-soap-response.c b/src/server/e-soap-response.c
index 748ca54..07e05c4 100644
--- a/src/server/e-soap-response.c
+++ b/src/server/e-soap-response.c
@@ -511,16 +511,22 @@ e_soap_response_get_first_parameter (ESoapResponse *response)
* e_soap_response_get_first_parameter_by_name:
* @response: the #ESoapResponse object.
* @name: the name of the parameter to look for.
+ * @error: return location for a #GError, or %NULL
*
* Retrieves the first parameter contained in the SOAP response whose
- * name is @name.
+ * name is @name. If no parameter is found, the function sets @error
+ * and returns %NULL.
+ *
+ * The function also checks for a SOAP "faultstring" parameter and,
+ * if found, uses it to set the #GError message.
*
* Returns: a #ESoapParameter representing the first parameter
* with the given name, or %NULL.
*/
ESoapParameter *
e_soap_response_get_first_parameter_by_name (ESoapResponse *response,
- const gchar *name)
+ const gchar *name,
+ GError **error)
{
GList *l;
@@ -530,10 +536,39 @@ e_soap_response_get_first_parameter_by_name (ESoapResponse *response,
for (l = response->priv->parameters; l != NULL; l = l->next) {
ESoapParameter *param = (ESoapParameter *) l->data;
- if (!strcmp (name, (const gchar *) param->name))
+ if (strcmp (name, (const gchar *) param->name) == 0)
return param;
}
+ /* XXX These are probably not the best error codes, but
+ * wanted to avoid EWS_CONNECTION_ERROR codes since
+ * this class is potentially reusable. */
+
+ for (l = response->priv->parameters; l != NULL; l = l->next) {
+ ESoapParameter *param = (ESoapParameter *) l->data;
+
+ if (strcmp ("faultstring", (const gchar *) param->name) == 0) {
+ gchar *string;
+
+ string = e_soap_parameter_get_string_value (param);
+
+ g_set_error (
+ error,
+ SOUP_HTTP_ERROR, SOUP_STATUS_IO_ERROR,
+ "%s", (string != NULL) ? string :
+ "<faultstring> in SOAP response");
+
+ g_free (string);
+
+ return NULL;
+ }
+ }
+
+ g_set_error (
+ error,
+ SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED,
+ "Missing <%s> in SOAP response", name);
+
return NULL;
}
diff --git a/src/server/e-soap-response.h b/src/server/e-soap-response.h
index 5967ae4..a570eef 100644
--- a/src/server/e-soap-response.h
+++ b/src/server/e-soap-response.h
@@ -84,7 +84,8 @@ ESoapParameter *
ESoapParameter *
e_soap_response_get_first_parameter_by_name
(ESoapResponse *response,
- const gchar *name);
+ const gchar *name,
+ GError **error);
ESoapParameter *
e_soap_response_get_next_parameter
(ESoapResponse *response,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]