diff options
author | Ross Burton <ross@linux.intel.com> | 2009-08-04 11:22:47 +0100 |
---|---|---|
committer | Ross Burton <ross@linux.intel.com> | 2009-08-04 11:26:55 +0100 |
commit | 7eaf297442976646b1e09249a77dc2b0b2b78ca7 (patch) | |
tree | 5fe6db33c1f1bbdda36894d8ff169dfecce6d057 /rest | |
parent | 1ee3c83da377dad02601bfe895a3549161fac255 (diff) |
Add flickr_proxy_is_successful
Diffstat (limited to 'rest')
-rw-r--r-- | rest/flickr-proxy.c | 36 | ||||
-rw-r--r-- | rest/flickr-proxy.h | 3 |
2 files changed, 39 insertions, 0 deletions
diff --git a/rest/flickr-proxy.c b/rest/flickr-proxy.c index cff2588..8172373 100644 --- a/rest/flickr-proxy.c +++ b/rest/flickr-proxy.c @@ -30,6 +30,7 @@ */ #include <config.h> +#include <stdlib.h> #include <string.h> #include <rest/rest-proxy.h> #include <libsoup/soup.h> @@ -331,3 +332,38 @@ flickr_proxy_build_login_url (FlickrProxy *proxy, const char *frob) return s; } + +/** + * flickr_proxy_is_successful: + * @root: The root node of a parsed Flickr response + * @error: #GError to set if the response was an error + * + * Examines the Flickr response and if it not a successful reply, set @error and + * return FALSE. + * + * Returns: %TRUE if this response is successful, %FALSE otherwise. + */ +gboolean +flickr_proxy_is_successful (RestXmlNode *root, GError **error) +{ + RestXmlNode *node; + + g_return_val_if_fail (root, FALSE); + + if (strcmp (root->name, "rsp") != 0) { + g_set_error (error, FLICKR_PROXY_ERROR, 0, + "Unexpected response from Flickr (root node %s)", + root->name); + return FALSE; + } + + if (strcmp (rest_xml_node_get_attr (root, "stat"), "ok") != 0) { + node = rest_xml_node_find (root, "err"); + g_set_error_literal (error,FLICKR_PROXY_ERROR, + atoi (rest_xml_node_get_attr (node, "code")), + rest_xml_node_get_attr (node, "msg")); + return FALSE; + } + + return TRUE; +} diff --git a/rest/flickr-proxy.h b/rest/flickr-proxy.h index 7104735..9369434 100644 --- a/rest/flickr-proxy.h +++ b/rest/flickr-proxy.h @@ -24,6 +24,7 @@ #define _FLICKR_PROXY #include <rest/rest-proxy.h> +#include <rest/rest-xml-parser.h> G_BEGIN_DECLS @@ -83,6 +84,8 @@ char * flickr_proxy_sign (FlickrProxy *proxy, GHashTable *params); char * flickr_proxy_build_login_url (FlickrProxy *proxy, const char *frob); +gboolean flickr_proxy_is_successful (RestXmlNode *root, GError **error); + G_END_DECLS #endif /* _FLICKR_PROXY */ |