- skip(&ptr2);
- /* backwards compatibility w/ old patch */
- if (strncmp(ptr2, "<value>",7) == 0) {
- parse_patch1028_RRA_params(&ptr2,rrd,rra_index);
- } else {
- switch(cf_conv(rrd -> rra_def[rra_index].cf_nam)) {
- case CF_HWPREDICT:
- read_tag(&ptr2, "hw_alpha", "%lf",
- &(rrd->rra_def[rra_index].par[RRA_hw_alpha].u_val));
- read_tag(&ptr2, "hw_beta", "%lf",
- &(rrd->rra_def[rra_index].par[RRA_hw_beta].u_val));
- read_tag(&ptr2, "dependent_rra_idx", "%lu",
- &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
- break;
- case CF_SEASONAL:
- case CF_DEVSEASONAL:
- read_tag(&ptr2, "seasonal_gamma", "%lf",
- &(rrd->rra_def[rra_index].par[RRA_seasonal_gamma].u_val));
- read_tag(&ptr2, "seasonal_smooth_idx", "%lu",
- &(rrd->rra_def[rra_index].par[RRA_seasonal_smooth_idx].u_cnt));
- read_tag(&ptr2, "dependent_rra_idx", "%lu",
- &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
- break;
- case CF_FAILURES:
- read_tag(&ptr2, "delta_pos", "%lf",
- &(rrd->rra_def[rra_index].par[RRA_delta_pos].u_val));
- read_tag(&ptr2, "delta_neg", "%lf",
- &(rrd->rra_def[rra_index].par[RRA_delta_neg].u_val));
- read_tag(&ptr2, "window_len", "%lu",
- &(rrd->rra_def[rra_index].par[RRA_window_len].u_cnt));
- read_tag(&ptr2, "failure_threshold", "%lu",
- &(rrd->rra_def[rra_index].par[RRA_failure_threshold].u_cnt));
- /* fall thru */
- case CF_DEVPREDICT:
- read_tag(&ptr2, "dependent_rra_idx", "%lu",
- &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
- break;
- case CF_AVERAGE:
- case CF_MAXIMUM:
- case CF_MINIMUM:
- case CF_LAST:
- default:
- read_tag(&ptr2, "xff","%lf",
- &(rrd->rra_def[rra_index].par[RRA_cdp_xff_val].u_val));
- }
- }
- eat_tag(&ptr2, "/params");
- }
-
-
- eat_tag(&ptr2,"cdp_prep");
- for(i=0;i< (int)rrd->stat_head->ds_cnt;i++)
- {
- eat_tag(&ptr2,"ds");
- /* support to read CDP parameters */
- rra_index = rrd->stat_head->rra_cnt-1;
- skip(&ptr2);
- if ( input_version < 2 ){
- rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)+i].scratch[CDP_primary_val].u_val = 0.0;
- rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)+i].scratch[CDP_secondary_val].u_val = 0.0;
- read_tag(&ptr2,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
- *(rra_index) +i].scratch[CDP_val].u_val));
- read_tag(&ptr2,"unknown_datapoints","%lu",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
- *(rra_index) +i].scratch[CDP_unkn_pdp_cnt].u_cnt));
- } else {
-
- if (strncmp(ptr2, "<value>",7) == 0) {
- parse_patch1028_CDP_params(&ptr2,rrd,rra_index,i);
- } else {
- read_tag(&ptr2, "primary_value","%lf",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_primary_val].u_val));
- read_tag(&ptr2, "secondary_value","%lf",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_secondary_val].u_val));
- switch(cf_conv(rrd->rra_def[rra_index].cf_nam)) {
- case CF_HWPREDICT:
- read_tag(&ptr2,"intercept","%lf",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_hw_intercept].u_val));
- read_tag(&ptr2,"last_intercept","%lf",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_hw_last_intercept].u_val));
- read_tag(&ptr2,"slope","%lf",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_hw_slope].u_val));
- read_tag(&ptr2,"last_slope","%lf",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_hw_last_slope].u_val));
- read_tag(&ptr2,"nan_count","%lu",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_null_count].u_cnt));
- read_tag(&ptr2,"last_nan_count","%lu",
- &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
- +i].scratch[CDP_last_null_count].u_cnt));
+ }
+ return status;
+} /* int parse_tag_rra_database_row */
+
+static int parse_tag_rra_database(
+ xmlTextReaderPtr reader,
+ rrd_t *rrd )
+{
+ rra_def_t *cur_rra_def;
+ unsigned int total_row_cnt;
+ int status;
+ int i;
+ xmlChar *element;
+
+ total_row_cnt = 0;
+ for (i = 0; i < (((int) rrd->stat_head->rra_cnt) - 1); i++)
+ total_row_cnt += rrd->rra_def[i].row_cnt;
+
+ cur_rra_def = rrd->rra_def + i;
+
+ status = 0;
+ while ((element = get_xml_element(reader)) != NULL){
+ if (xmlStrcasecmp(element,(const xmlChar *)"row") == 0){
+ rrd_value_t *temp;
+ rrd_value_t *cur_rrd_value;
+ unsigned int total_values_count = rrd->stat_head->ds_cnt
+ * (total_row_cnt + 1);
+
+ /* Allocate space for the new values.. */
+ temp = (rrd_value_t *) realloc(rrd->rrd_value,
+ sizeof(rrd_value_t) *
+ total_values_count);
+ if (temp == NULL) {
+ rrd_set_error("parse_tag_rra_database: realloc failed.");
+ status = -1;
+ break;
+ }
+ rrd->rrd_value = temp;
+ cur_rrd_value = rrd->rrd_value
+ + (rrd->stat_head->ds_cnt * total_row_cnt);
+ memset(cur_rrd_value, '\0',
+ sizeof(rrd_value_t) * rrd->stat_head->ds_cnt);
+ total_row_cnt++;
+ cur_rra_def->row_cnt++;
+
+ status =
+ parse_tag_rra_database_row(reader, rrd, cur_rrd_value);
+ if (status == 0)
+ status = expect_element(reader,"/row");
+ } /* if (xmlStrcasecmp(element,"row")) */
+ else {
+ if ( xmlStrcasecmp(element,(const xmlChar *)"/database") == 0){
+ xmlFree(element);
+ break;
+ }
+ else {
+ rrd_set_error("line %d: found unexpected tag: %s",
+ xmlTextReaderGetParserLineNumber(reader),element);
+ status = -1;
+ }
+ }
+ xmlFree(element);
+ if (status != 0)
+ break;
+ }
+ return (status);
+} /* int parse_tag_rra_database */
+
+/*
+ * Parse the <cdp_prep> block within an RRA definition
+ */
+static int parse_tag_rra_cdp_prep_ds_history(
+ xmlTextReaderPtr reader,
+ cdp_prep_t *cdp_prep)
+{
+ /* Make `history_buffer' the same size as the scratch area, plus the
+ * terminating NULL byte. */
+ xmlChar *history;
+ char *history_ptr;
+ int i;
+ if ((history = get_xml_text(reader)) != NULL){
+ history_ptr = (char *) (&cdp_prep->scratch[0]);
+ for (i = 0; history[i] != '\0'; i++)
+ history_ptr[i] = (history[i] == '1') ? 1 : 0;
+ xmlFree(history);
+ return 0;
+ }
+ return -1;
+} /* int parse_tag_rra_cdp_prep_ds_history */
+
+static int parse_tag_rra_cdp_prep_ds(
+ xmlTextReaderPtr reader,
+ rrd_t *rrd,
+ cdp_prep_t *cdp_prep)
+{
+ int status;
+ xmlChar *element;
+ memset(cdp_prep, '\0', sizeof(cdp_prep_t));
+
+ status = -1;
+
+ if (atoi(rrd->stat_head->version) == 1) {
+ cdp_prep->scratch[CDP_primary_val].u_val = 0.0;
+ cdp_prep->scratch[CDP_secondary_val].u_val = 0.0;
+ }
+
+ while ((element = get_xml_element(reader)) != NULL){
+ if (xmlStrcasecmp(element, (const xmlChar *) "primary_value") == 0)
+ status =
+ get_xml_double(reader,&cdp_prep->scratch[CDP_primary_val].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "secondary_value") == 0)
+ status =
+ get_xml_double(reader,&cdp_prep->scratch[CDP_secondary_val].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "intercept") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->
+ scratch[CDP_hw_intercept].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_intercept") ==
+ 0)
+ status =
+ get_xml_double(reader,
+ &cdp_prep->
+ scratch[CDP_hw_last_intercept].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "slope") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->scratch[CDP_hw_slope].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_slope") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->
+ scratch[CDP_hw_last_slope].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "nan_count") == 0)
+ status = get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_null_count].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_nan_count") ==
+ 0)
+ status =
+ get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_last_null_count].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "seasonal") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->scratch[CDP_hw_seasonal].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_seasonal") ==
+ 0)
+ status =
+ get_xml_double(reader,
+ &cdp_prep->scratch[CDP_hw_last_seasonal].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "init_flag") == 0)
+ status = get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_init_seasonal].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "history") == 0)
+ status = parse_tag_rra_cdp_prep_ds_history(reader, cdp_prep);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "value") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->scratch[CDP_val].u_val);
+ else if (xmlStrcasecmp(element,
+ (const xmlChar *) "unknown_datapoints") == 0)
+ status = get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_unkn_pdp_cnt].u_cnt);
+ else if (xmlStrcasecmp(element,
+ (const xmlChar *) "/ds") == 0){
+ xmlFree(element);