int pi_rrd_save (xml_node_t * base) { xml_node_t *node; rrd_ctxt_t *rrd; rrd_ctxt_datapoint_t *dp; base = xml_node_add (base, "RRDs"); for (rrd = rrdlist.next; rrd != &rrdlist; rrd = rrd->next) { node = xml_node_add (base, "RRD"); xml_node_add_value (node, "Name", XML_TYPE_STRING, rrd->name); xml_node_add_value (node, "File", XML_TYPE_STRING, rrd->filename); xml_node_add_value (node, "Period", XML_TYPE_ULONG, &rrd->period); node = xml_node_add (node, "DataPoints"); for (dp = rrd->points.next; dp != &rrd->points; dp = dp->next) { node = xml_node_add (node, "DataPoint"); xml_node_add_value (node, "Name", XML_TYPE_STRING, dp->elem->name); xml_node_add_value (node, "Specification", XML_TYPE_STRING, dp->spec); node = xml_parent (node); } node = xml_parent (node); node = xml_node_add (node, "RRAs"); for (dp = rrd->rras.next; dp != &rrd->rras; dp = dp->next) xml_node_add_value (node, "RRA", XML_TYPE_STRING, dp->spec); node = xml_parent (node); } return 0; }
void xml_attach_sibling ( XML_ITEM *sibling, XML_ITEM *item) { if (item-> parent) xml_detach (item); item-> parent = xml_parent (sibling); list_relink_before (item, sibling); }
/*! Get database configuration * Same as clicon_proto_change just with a cvec instead of lvec * @param[in] h CLICON handle * @param[in] db Name of database * @param[in] xpath XPath (or "") * @param[out] xt XML tree. Free with xml_free. * Either <config> or <rpc-error>. * @retval 0 OK * @retval -1 Error, fatal or xml * @code * cxobj *xt = NULL; * if (clicon_rpc_get_config(h, "running", "/", &xt) < 0) * err; * if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){ * clicon_rpc_generate_error("", xerr); * err; * } * if (xt) * xml_free(xt); * @endcode * @see clicon_rpc_generate_error */ int clicon_rpc_get_config(clicon_handle h, char *db, char *xpath, cxobj **xt) { int retval = -1; struct clicon_msg *msg = NULL; cbuf *cb = NULL; cxobj *xret = NULL; cxobj *xd; char *username; if ((cb = cbuf_new()) == NULL) goto done; cprintf(cb, "<rpc"); if ((username = clicon_username_get(h)) != NULL) cprintf(cb, " username=\"%s\"", username); cprintf(cb, "><get-config><source><%s/></source>", db); if (xpath && strlen(xpath)) cprintf(cb, "<filter type=\"xpath\" select=\"%s\"/>", xpath); cprintf(cb, "</get-config></rpc>"); if ((msg = clicon_msg_encode("%s", cbuf_get(cb))) == NULL) goto done; if (clicon_rpc_msg(h, msg, &xret, NULL) < 0) goto done; /* Send xml error back: first check error, then ok */ if ((xd = xpath_first(xret, "/rpc-reply/rpc-error")) != NULL) xd = xml_parent(xd); /* point to rpc-reply */ else if ((xd = xpath_first(xret, "/rpc-reply/data")) == NULL) if ((xd = xml_new("data", NULL, NULL)) == NULL) goto done; if (xt){ if (xml_rm(xd) < 0) goto done; *xt = xd; } retval = 0; done: if (cb) cbuf_free(cb); if (xret) xml_free(xret); if (msg) free(msg); return retval; }