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 handles(
const char *cmd, ssize_t n)
131 run(
int sockfd,
engine_type* engine,
const char *cmd, ssize_t n,
134 (void)cmd; (void)n; (void)dbconn; (void)engine;
138 if (perform_repositorylist(sockfd)) {
139 ods_log_error_and_printf(sockfd, module_str,
140 "unable to list repositories ");
void ods_log_debug(const char *format,...)
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
void ods_log_error(const char *format,...)
void(* usage)(int sockfd)
struct cmd_func_block * repositorylist_funcblock(void)
int(* handles)(const char *cmd, ssize_t n)