30#include "clientpipe.h"
31#include "longgetopt.h"
34#include <libxml/xpath.h>
35#include <libxml/xmlreader.h>
38static const char *module_str =
"repositorylist_cmd";
41perform_repositorylist(
int sockfd)
43 const char* cfgfile = ODS_SE_CFGFILE;
46 xmlXPathContextPtr xpathCtx = NULL;
47 xmlXPathObjectPtr xpathObj = NULL;
49 const char *fmt =
"%-31s %-13s %-13s\n";
50 char *capacity = NULL;
52 char *repository = NULL;
56 xmlChar *xexpr = (
unsigned char *)
"//Configuration/RepositoryList/Repository";
57 doc = xmlParseFile(cfgfile);
59 ods_log_error(
"[%s] unable to read cfgfile %s", module_str, cfgfile);
63 xpathCtx = xmlXPathNewContext(doc);
64 if (xpathCtx == NULL) {
65 ods_log_error(
"[%s] unable to create new XPath context for cfgfile"
66 "%s expr %s", module_str, cfgfile, xexpr);
71 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
72 if(xpathObj == NULL) {
73 ods_log_error(
"[%s] unable to evaluate required element %s in "
74 "cfgfile %s", module_str, xexpr, cfgfile);
75 xmlXPathFreeContext(xpathCtx);
80 client_printf(sockfd,
"Repositories:\n");
81 client_printf(sockfd, fmt,
"Name:",
"Capacity:",
"RequireBackup:");
83 if (xpathObj->nodesetval){
84 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
85 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
86 repository = (
char*)xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
90 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Capacity"))
91 capacity = (
char*) xmlNodeGetContent(curNode);
92 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup"))
94 curNode = curNode->next;
96 client_printf(sockfd, fmt, repository, capacity?capacity:
"-", backup?
"Yes":
"No");
104 xmlXPathFreeObject(xpathObj);
105 xmlXPathFreeContext(xpathCtx);
115 client_printf(sockfd,
116 "repository list\n");
122 client_printf(sockfd,
"List repositories.\n\n");
126run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
128 int sockfd = context->sockfd;
129 if (perform_repositorylist(sockfd)) {
130 ods_log_error_and_printf(sockfd, module_str,
131 "unable to list repositories ");
138 "repository list", &usage, &help, NULL, NULL, &run, NULL
struct cmd_func_block repositorylist_funcblock