Cluster Project branch, master, updated. cluster-2.99.04-38-gcb69044
fabbione@sourceware.org
fabbione@sourceware.org
Fri Jun 20 05:32:00 GMT 2008
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".
http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=cb690444146f443739976b8795407545666addb1
The branch, master has been updated
via cb690444146f443739976b8795407545666addb1 (commit)
from ccdb6bd23d58be30082e0a4f5686fdbfc4ac92b0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit cb690444146f443739976b8795407545666addb1
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date: Fri Jun 20 07:31:36 2008 +0200
[CCS] Shrink more common code for internal xml queries
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
-----------------------------------------------------------------------
Summary of changes:
ccs/daemon/misc.c | 139 +++++++++++++++++++----------------------------------
1 files changed, 49 insertions(+), 90 deletions(-)
diff --git a/ccs/daemon/misc.c b/ccs/daemon/misc.c
index 1c738d9..167536f 100644
--- a/ccs/daemon/misc.c
+++ b/ccs/daemon/misc.c
@@ -32,12 +32,43 @@ open_doc_t *master_doc = NULL;
LOGSYS_DECLARE_SUBSYS ("CCS", LOG_INFO);
+/**
+ * do_simple_xml_query
+ * @ctx: xml context
+ * @query: "/cluster/@name"
+ *
+ * it only handles this kind of query
+ */
+static char *do_simple_xml_query(xmlXPathContextPtr ctx, char *query) {
+ xmlXPathObjectPtr obj = NULL;
+ xmlNodePtr node = NULL;
+
+ obj = xmlXPathEvalExpression((xmlChar *)query, ctx);
+ if(!obj || !obj->nodesetval || (obj->nodesetval->nodeNr != 1))
+ log_printf(LOG_DEBUG, "Error processing query: %s.\n", query);
+ else {
+ node = obj->nodesetval->nodeTab[0];
+ if(node->type != XML_ATTRIBUTE_NODE)
+ log_printf(LOG_DEBUG, "Object returned is not of attribute type.\n");
+ else {
+ if(!node->children->content || !strlen((char *)node->children->content))
+ log_printf(LOG_DEBUG, "No content found.\n");
+ else
+ return strdup((char *)node->children->content);
+ }
+ }
+
+ if(obj)
+ xmlXPathFreeObject(obj);
+
+ return NULL;
+}
+
int get_doc_version(xmlDocPtr ldoc){
int i;
int error = 0;
- xmlXPathObjectPtr obj = NULL;
xmlXPathContextPtr ctx = NULL;
- xmlNodePtr node = NULL;
+ char *res = NULL;
CCSENTER("get_doc_version");
@@ -48,43 +79,28 @@ int get_doc_version(xmlDocPtr ldoc){
goto fail;
}
- obj = xmlXPathEvalExpression((xmlChar *)"/cluster/@config_version", ctx);
- if(!obj || !obj->nodesetval || (obj->nodesetval->nodeNr != 1)){
- log_printf(LOG_ERR, "Error while retrieving config_version.\n");
- error = -ENODATA;
- goto fail;
- }
-
- node = obj->nodesetval->nodeTab[0];
- if(node->type != XML_ATTRIBUTE_NODE){
- log_printf(LOG_ERR, "Object returned is not of attribute type.\n");
- error = -ENODATA;
- goto fail;
- }
-
- if(!node->children->content || !strlen((char *)node->children->content)){
- log_printf(LOG_DEBUG, "No content found.\n");
- error = -ENODATA;
- goto fail;
- }
-
- for(i=0; i < strlen((char *)node->children->content); i++){
- if(!isdigit(node->children->content[i])){
- log_printf(LOG_ERR, "config_version is not a valid integer.\n");
- error = -EINVAL;
- goto fail;
+ res = do_simple_xml_query(ctx, "/cluster/@config_version");
+ if(res) {
+ for(i=0; i < strlen(res); i++){
+ if(!isdigit(res[i])){
+ log_printf(LOG_ERR, "config_version is not a valid integer.\n");
+ error = -EINVAL;
+ goto fail;
+ }
}
- }
- error = atoi((char *)node->children->content);
+ error = atoi(res);
+ } else
+ error = -EINVAL;
fail:
+ if(res)
+ free(res);
+
if(ctx){
xmlXPathFreeContext(ctx);
}
- if(obj){
- xmlXPathFreeObject(obj);
- }
+
CCSEXIT("get_doc_version");
return error;
}
@@ -101,9 +117,7 @@ fail:
char *get_cluster_name(xmlDocPtr ldoc){
int error = 0;
char *rtn = NULL;
- xmlXPathObjectPtr obj = NULL;
xmlXPathContextPtr ctx = NULL;
- xmlNodePtr node = NULL;
CCSENTER("get_cluster_name");
@@ -114,73 +128,18 @@ char *get_cluster_name(xmlDocPtr ldoc){
goto fail;
}
- obj = xmlXPathEvalExpression((xmlChar *)"/cluster/@name", ctx);
- if(!obj || !obj->nodesetval || (obj->nodesetval->nodeNr != 1)){
- log_printf(LOG_ERR, "Error while retrieving config_version.\n");
- error = -ENODATA;
- goto fail;
- }
-
- node = obj->nodesetval->nodeTab[0];
- if(node->type != XML_ATTRIBUTE_NODE){
- log_printf(LOG_ERR, "Object returned is not of attribute type.\n");
- error = -ENODATA;
- goto fail;
- }
-
- if(!node->children->content || !strlen((char *)node->children->content)){
- log_printf(LOG_DEBUG, "No content found.\n");
- error = -ENODATA;
- goto fail;
- }
-
- rtn = strdup((char *)node->children->content);
+ rtn = do_simple_xml_query(ctx, "/cluster/@name");
fail:
if(ctx){
xmlXPathFreeContext(ctx);
}
- if(obj){
- xmlXPathFreeObject(obj);
- }
CCSEXIT("get_cluster_name");
return rtn;
}
/**
- * do_simple_xml_query
- * @ctx: xml context
- * @query: "/cluster/@name"
- *
- * it only handles this kind of query
- */
-static char *do_simple_xml_query(xmlXPathContextPtr ctx, char *query) {
- xmlXPathObjectPtr obj = NULL;
- xmlNodePtr node = NULL;
-
- obj = xmlXPathEvalExpression((xmlChar *)query, ctx);
- if(!obj || !obj->nodesetval || (obj->nodesetval->nodeNr != 1))
- log_printf(LOG_DEBUG, "Error processing query: %s.\n", query);
- else {
- node = obj->nodesetval->nodeTab[0];
- if(node->type != XML_ATTRIBUTE_NODE)
- log_printf(LOG_DEBUG, "Object returned is not of attribute type.\n");
- else {
- if(!node->children->content || !strlen((char *)node->children->content))
- log_printf(LOG_DEBUG, "No content found.\n");
- else
- return strdup((char *)node->children->content);
- }
- }
-
- if(obj)
- xmlXPathFreeObject(obj);
-
- return NULL;
-}
-
-/**
* set_ccs_logging
* @ldoc:
*
hooks/post-receive
--
Cluster Project
More information about the Cluster-cvs
mailing list