summaryrefslogtreecommitdiffstats
path: root/lasso/xml
diff options
context:
space:
mode:
authorValery Febvre <vfebvre at easter-eggs.com>2004-07-23 13:28:08 +0000
committerValery Febvre <vfebvre at easter-eggs.com>2004-07-23 13:28:08 +0000
commit5da1b0185ae35cdeb24efd4fc8c642ee3d1f6bd0 (patch)
tree14f6777868da44d4da244bad67f1132cfe045fa5 /lasso/xml
parent25c73745541cd659babe96bbb9daf6872f409479 (diff)
downloadlasso-5da1b0185ae35cdeb24efd4fc8c642ee3d1f6bd0.tar.gz
lasso-5da1b0185ae35cdeb24efd4fc8c642ee3d1f6bd0.tar.xz
lasso-5da1b0185ae35cdeb24efd4fc8c642ee3d1f6bd0.zip
- Added a third arg (GError **err) in lasso_node_get_attr_value()
method to report errors - Replaced some lasso_provider_get_providerID() by direct access to ProviderID attribute of server objects
Diffstat (limited to 'lasso/xml')
-rw-r--r--lasso/xml/errors.c6
-rw-r--r--lasso/xml/errors.h2
-rw-r--r--lasso/xml/xml.c26
-rw-r--r--lasso/xml/xml.h14
4 files changed, 32 insertions, 16 deletions
diff --git a/lasso/xml/errors.c b/lasso/xml/errors.c
index 79402e3d..256d7eba 100644
--- a/lasso/xml/errors.c
+++ b/lasso/xml/errors.c
@@ -29,9 +29,9 @@ const char*
lasso_strerror(int error_code)
{
switch (error_code) {
- case LASSO_ERROR_METADATA_VALUE_NOTFOUND:
- return "Unable to get metadata value %s\n";
+ case LASSO_ERROR_XML_ATTR_VALUE_NOTFOUND:
+ return "Unable to get '%s' attribute value in '%s' element.\n";
default:
- return "Undefined error code !\n";
+ return "Undefined error code !!!\n";
}
}
diff --git a/lasso/xml/errors.h b/lasso/xml/errors.h
index e3c70407..5de7f4ba 100644
--- a/lasso/xml/errors.h
+++ b/lasso/xml/errors.h
@@ -23,6 +23,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#define LASSO_ERROR_METADATA_VALUE_NOTFOUND -1
+#define LASSO_ERROR_XML_ATTR_VALUE_NOTFOUND -1
const char* lasso_strerror(int error_code);
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index c29c70d2..4e567f18 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -24,6 +24,7 @@
*/
#include <string.h>
+#include <lasso/xml/errors.h>
#include <lasso/xml/xml.h>
#include <lasso/xml/ds_signature.h>
#include <xmlsec/base64.h>
@@ -194,6 +195,7 @@ lasso_node_get_attr(LassoNode *node,
* lasso_node_get_attr_value:
* @node: a LassoNode
* @name: the attribute name
+ * @err: return location for an allocated GError, or NULL to ignore errors
*
* Gets the value of an attribute associated to a node.
*
@@ -201,13 +203,14 @@ lasso_node_get_attr(LassoNode *node,
* to free the memory with xmlFree().
**/
xmlChar *
-lasso_node_get_attr_value(LassoNode *node,
- const xmlChar *name)
+lasso_node_get_attr_value(LassoNode *node,
+ const xmlChar *name,
+ GError **err)
{
g_return_val_if_fail (LASSO_IS_NODE(node), NULL);
LassoNodeClass *class = LASSO_NODE_GET_CLASS(node);
- return (class->get_attr_value(node, name));
+ return (class->get_attr_value(node, name, err));
}
/**
@@ -716,13 +719,24 @@ lasso_node_impl_get_attr(LassoNode *node,
}
static xmlChar *
-lasso_node_impl_get_attr_value(LassoNode *node,
- const xmlChar *name)
+lasso_node_impl_get_attr_value(LassoNode *node,
+ const xmlChar *name,
+ GError **err)
{
g_return_val_if_fail (LASSO_IS_NODE(node), NULL);
g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (err == NULL || *err == NULL, NULL);
- return (xmlGetProp(node->private->node, name));
+ xmlChar *value = xmlGetProp(node->private->node, name);
+
+ if (value == NULL) {
+ g_set_error(err, g_quark_from_string("Lasso"),
+ LASSO_ERROR_XML_ATTR_VALUE_NOTFOUND,
+ lasso_strerror(LASSO_ERROR_XML_ATTR_VALUE_NOTFOUND),
+ name, node->private->node->name);
+ }
+
+ return (value);
}
static GPtrArray *
diff --git a/lasso/xml/xml.h b/lasso/xml/xml.h
index ce248567..ab759312 100644
--- a/lasso/xml/xml.h
+++ b/lasso/xml/xml.h
@@ -81,8 +81,9 @@ struct _LassoNodeClass {
xmlChar* (* export_to_soap) (LassoNode *node);
LassoAttr* (* get_attr) (LassoNode *node,
const xmlChar *name);
- xmlChar* (* get_attr_value) (LassoNode *node,
- const xmlChar *name);
+ xmlChar* (* get_attr_value) (LassoNode *node,
+ const xmlChar *name,
+ GError **err);
GPtrArray* (* get_attrs) (LassoNode *node);
LassoNode* (* get_child) (LassoNode *node,
const xmlChar *name,
@@ -154,15 +155,16 @@ LASSO_EXPORT gchar* lasso_node_export_to_query (LassoNode *n
LASSO_EXPORT xmlChar* lasso_node_export_to_soap (LassoNode *node);
-LASSO_EXPORT LassoAttr* lasso_node_get_attr (LassoNode *node,
+LASSO_EXPORT LassoAttr* lasso_node_get_attr (LassoNode *node,
const xmlChar *name);
-LASSO_EXPORT xmlChar* lasso_node_get_attr_value (LassoNode *node,
- const xmlChar *name);
+LASSO_EXPORT xmlChar* lasso_node_get_attr_value (LassoNode *node,
+ const xmlChar *name,
+ GError **err);
LASSO_EXPORT GPtrArray* lasso_node_get_attrs (LassoNode *node);
-LASSO_EXPORT LassoNode* lasso_node_get_child (LassoNode *node,
+LASSO_EXPORT LassoNode* lasso_node_get_child (LassoNode *node,
const xmlChar *name,
const xmlChar *href);