+ rrd->pdp_prep = temp;
+ cur_pdp_prep = rrd->pdp_prep + rrd->stat_head->ds_cnt;
+ memset(cur_pdp_prep, '\0', sizeof(pdp_prep_t));
+ } /* }}} */
+
+ /* All allocations successful, let's increment the number of DSes. */
+ rrd->stat_head->ds_cnt++;
+
+ status = 0;
+ while ((element = get_xml_element(reader)) != NULL){
+ if (xmlStrcasecmp(element, (const xmlChar *) "name") == 0){
+ status = get_xml_string(reader,cur_ds_def->ds_nam,sizeof(cur_ds_def->ds_nam));
+ }
+ else if (xmlStrcasecmp(element, (const xmlChar *) "type") == 0)
+ status = parse_tag_ds_type(reader, cur_ds_def);
+ else if (xmlStrcasecmp(element,
+ (const xmlChar *) "minimal_heartbeat") == 0)
+ status = get_xml_ulong(reader,
+ &cur_ds_def->par[DS_mrhb_cnt].
+ u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "min") == 0)
+ status = get_xml_double(reader,
+ &cur_ds_def->par[DS_min_val].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "max") == 0)
+ status = get_xml_double(reader,
+ &cur_ds_def->par[DS_max_val].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "cdef") == 0)
+ status = parse_tag_ds_cdef(reader, rrd);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_ds") == 0)
+ status = get_xml_string(reader,
+ cur_pdp_prep->last_ds,
+ sizeof(cur_pdp_prep->last_ds));
+ else if (xmlStrcasecmp(element, (const xmlChar *) "value") == 0)
+ status = get_xml_double(reader,
+ &cur_pdp_prep->scratch[PDP_val].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "unknown_sec") == 0)
+ status = get_xml_ulong(reader,
+ &cur_pdp_prep->
+ scratch[PDP_unkn_sec_cnt].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "/ds") == 0) {
+ xmlFree(element);
+ break;
+ }
+ else {
+ rrd_set_error("parse_tag_ds: Unknown tag: %s", element);
+ status = -1;
+ }
+ if (status != 0) {
+ xmlFree(element);
+ break;
+ }
+ status = expect_element_end(reader,(char *)element);
+ xmlFree(element);
+ if (status != 0)
+ break;
+ }
+
+ return (status);
+} /* int parse_tag_ds */
+
+/*
+ * Parse root nodes
+ */
+static int parse_tag_rrd(
+ xmlTextReaderPtr reader,
+ rrd_t *rrd)
+{
+ int status;
+ xmlChar *element;
+
+ status = 0;
+ while ((element = get_xml_element(reader)) != NULL ){
+ if (xmlStrcasecmp(element, (const xmlChar *) "version") == 0)
+ status = get_xml_string(reader,
+ rrd->stat_head->version,
+ sizeof(rrd->stat_head->version));
+ else if (xmlStrcasecmp(element, (const xmlChar *) "step") == 0)
+ status = get_xml_ulong(reader,
+ &rrd->stat_head->pdp_step);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "lastupdate") == 0) {
+ status = get_xml_time_t(reader, &rrd->live_head->last_up);
+ }
+ else if (xmlStrcasecmp(element, (const xmlChar *) "ds") == 0){
+ xmlFree(element);
+ status = parse_tag_ds(reader, rrd);
+ /* as we come back the </ds> tag is already gone */
+ if (status == 0)
+ continue;
+ else
+ return status;
+ }
+ else if (xmlStrcasecmp(element, (const xmlChar *) "rra") == 0){
+ xmlFree(element);
+ status = parse_tag_rra(reader, rrd);
+ if (status == 0)
+ continue;
+ else
+ return status;
+ }
+ else if (xmlStrcasecmp(element, (const xmlChar *) "/rrd") == 0) {
+ xmlFree(element);
+ return status;
+ }
+ else {
+ rrd_set_error("parse_tag_rrd: Unknown tag: %s", element);
+ status = -1;
+ }
+
+ if (status != 0){
+ xmlFree(element);
+ break;
+ }
+ status = expect_element_end(reader,(char *)element);
+ xmlFree(element);
+ if (status != 0)
+ break;
+ }
+ return (status);
+} /* int parse_tag_rrd */
+
+static rrd_t *parse_file(
+ const char *filename)
+{
+ xmlTextReaderPtr reader;
+ int status;
+
+ rrd_t *rrd;
+
+ reader = xmlNewTextReaderFilename(filename);
+ if (reader == NULL) {
+ rrd_set_error("Could not create xml reader for: %s",filename);
+ return (NULL);
+ }
+
+ if (expect_element(reader,"rrd") != 0) {
+ xmlFreeTextReader(reader);
+ return (NULL);
+ }
+
+ rrd = (rrd_t *) malloc(sizeof(rrd_t));
+ if (rrd == NULL) {
+ rrd_set_error("parse_file: malloc failed.");
+ xmlFreeTextReader(reader);
+ return (NULL);
+ }
+ memset(rrd, '\0', sizeof(rrd_t));
+
+ rrd->stat_head = (stat_head_t *) malloc(sizeof(stat_head_t));
+ if (rrd->stat_head == NULL) {
+ rrd_set_error("parse_tag_rrd: malloc failed.");
+ xmlFreeTextReader(reader);
+ free(rrd);
+ return (NULL);
+ }
+ memset(rrd->stat_head, '\0', sizeof(stat_head_t));
+
+ strncpy(rrd->stat_head->cookie, "RRD", sizeof(rrd->stat_head->cookie));
+ rrd->stat_head->float_cookie = FLOAT_COOKIE;
+
+ rrd->live_head = (live_head_t *) malloc(sizeof(live_head_t));
+ if (rrd->live_head == NULL) {
+ rrd_set_error("parse_tag_rrd: malloc failed.");
+ xmlFreeTextReader(reader);
+ free(rrd->stat_head);
+ free(rrd);
+ return (NULL);