30 #include "clientpipe.h"
33 #include <libxml/xpath.h>
34 #include <libxml/xmlreader.h>
37 static const char *module_str =
"repositorylist_cmd";
40 perform_repositorylist(
int sockfd)
42 const char* cfgfile = ODS_SE_CFGFILE;
45 xmlXPathContextPtr xpathCtx = NULL;
46 xmlXPathObjectPtr xpathObj = NULL;
48 const char *fmt =
"%-31s %-13s %-13s\n";
49 char *capacity = NULL;
51 char *repository = NULL;
55 xmlChar *xexpr = (
unsigned char *)
"//Configuration/RepositoryList/Repository";
56 doc = xmlParseFile(cfgfile);
58 ods_log_error(
"[%s] unable to read cfgfile %s", module_str, cfgfile);
62 xpathCtx = xmlXPathNewContext(doc);
63 if (xpathCtx == NULL) {
64 ods_log_error(
"[%s] unable to create new XPath context for cfgfile"
65 "%s expr %s", module_str, cfgfile, xexpr);
70 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
71 if(xpathObj == NULL) {
72 ods_log_error(
"[%s] unable to evaluate required element %s in "
73 "cfgfile %s", module_str, xexpr, cfgfile);
74 xmlXPathFreeContext(xpathCtx);
79 client_printf(sockfd,
"Repositories:\n");
80 client_printf(sockfd, fmt,
"Name:",
"Capacity:",
"RequireBackup:");
82 if (xpathObj->nodesetval){
83 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
84 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
85 repository = (
char*)xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
89 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Capacity"))
90 capacity = (
char*) xmlNodeGetContent(curNode);
91 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup"))
93 curNode = curNode->next;
95 client_printf(sockfd, fmt, repository, capacity?capacity:
"-", backup?
"Yes":
"No");
103 xmlXPathFreeObject(xpathObj);
104 xmlXPathFreeContext(xpathCtx);
114 client_printf(sockfd,
115 "repository list\n");
121 client_printf(sockfd,
"List repositories.\n\n");
125 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
128 ods_log_debug(
"[%s] %s command", module_str,
131 if (perform_repositorylist(sockfd)) {
132 ods_log_error_and_printf(sockfd, module_str,
133 "unable to list repositories ");
140 "repository list", &usage, &help, NULL, &run