Wed, 16 Jan 2036 19:55:59 GMT ETag: "af4f020bbbd79d32fa800498a9739a59aadca1f3" /* Copyright (c) 2010-2012 Red Hat, Inc. This file is part of GlusterFS. This file is licensed to you under your choice of the GNU Lesser General Public License, version 3 or any later version (LGPLv3 or later), or the GNU General Public License, version 2 (GPLv2), in all cases as published by the Free Software Foundation. */ #include #include "cli.h" #include "cli1-xdr.h" #include "run.h" #include "compat.h" #include "syscall.h" #include "upcall-utils.h" enum gf_task_types { GF_TASK_TYPE_REBALANCE, GF_TASK_TYPE_REMOVE_BRICK }; /* * IMPORTANT NOTE: * All exported functions in this file which use libxml need use a * #if (HAVE_LIB_XML), #else, #endif * For eg, * int exported_func () { * #if (HAVE_LIB_XML) * * #else * return 0; * #endif * } * * All other functions, which are called internally within this file need to be * within #if (HAVE_LIB_XML), #endif statements * For eg, * #if (HAVE_LIB_XML) * int internal_func () * { * } * #endif * * Following the above formate ensures that all xml related code is compliled * only when libxml2 is present, and also keeps the rest of the codebase free * of #if (HAVE_LIB_XML) */ #if (HAVE_LIB_XML) #include #include #define XML_RET_CHECK_AND_GOTO(ret, label) do { \ if (ret < 0) { \ ret = -1; \ goto label; \ } \ else \ ret = 0; \ }while (0) \ int cli_begin_xml_output (xmlTextWriterPtr *writer, xmlDocPtr *doc) { int ret = -1; *writer = xmlNewTextWriterDoc (doc, 0); if (writer == NULL) { ret = -1; goto out; } ret = xmlTextWriterStartDocument (*writer, "1.0", "UTF-8", "yes"); XML_RET_CHECK_AND_GOTO (ret, out); /* */ ret = xmlTextWriterStartElement (*writer, (xmlChar *)"cliOutput"); XML_RET_CHECK_AND_GOTO (ret, out); out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); return ret; } int cli_end_xml_output (xmlTextWriterPtr writer, xmlDocPtr doc) { int ret = -1; /* */ ret = xmlTextWriterEndElement (writer); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterEndDocument (writer); XML_RET_CHECK_AND_GOTO (ret, out); /* Dump xml document to stdout and pretty format it */ xmlSaveFormatFileEnc ("-", doc, "UTF-8", 1); xmlFreeTextWriter (writer); xmlFreeDoc (doc); out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); return ret; } int cli_xml_output_common (xmlTextWriterPtr writer, int op_ret, int op_errno, char *op_errstr) { int ret = -1; ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"opRet", "%d", op_ret); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"opErrno", "%d", op_errno); XML_RET_CHECK_AND_GOTO (ret, out)