- return -1;
-}
-
-
-/* parse the data stored in buf and return a filled rrd structure */
-int xml2rrd(char* buf, rrd_t* rrd, char rc){
- /* pass 1 identify number of RRAs */
- char *ptr,*ptr2,*ptr3; /* walks thought the buffer */
- long rows=0,mempool=0,i=0;
- int rra_index;
- int input_version;
- xml_lc(buf); /* lets lowercase all active parts of the xml */
- ptr=buf;
- ptr2=buf;
- ptr3=buf;
- /* start with an RRD tag */
-
- skipxml(&ptr);
-
- eat_tag(&ptr,"rrd");
- /* allocate static header */
- if((rrd->stat_head = calloc(1,sizeof(stat_head_t)))==NULL){
- rrd_set_error("allocating rrd.stat_head");
- return -1;
- };
-
- strcpy(rrd->stat_head->cookie,RRD_COOKIE);
- read_tag(&ptr,"version","%4[0-9]",rrd->stat_head->version);
- input_version = atoi(rrd->stat_head->version);
- /* added primitive version checking */
- if (input_version > atoi(RRD_VERSION) || input_version < 1)
- {
- rrd_set_error("Incompatible file version, detected version %s. This is not supported by the version %s restore tool.\n",
- rrd -> stat_head -> version, RRD_VERSION );
- free(rrd -> stat_head);
- rrd->stat_head = NULL;
- return -1;
- }
- /* make sure we output the right version */
- strcpy(rrd->stat_head->version,RRD_VERSION);
-
- /* if (atoi(rrd -> stat_head -> version) < 2)
- {
- rrd_set_error("Can only restore version >= 2 (Not %s). Dump your old rrd using a current rrdtool dump.", rrd -> stat_head -> version );
- return -1;
- } */
-
- rrd->stat_head->float_cookie = FLOAT_COOKIE;
- rrd->stat_head->ds_cnt = 0;
- rrd->stat_head->rra_cnt = 0;
- read_tag(&ptr,"step","%lu",&(rrd->stat_head->pdp_step));
-
- /* allocate live head */
- if((rrd->live_head = calloc(1,sizeof(live_head_t)))==NULL){
- rrd_set_error("allocating rrd.live_head");
- return -1;
- }
- read_tag(&ptr,"lastupdate","%lu",&(rrd->live_head->last_up));
-
- /* Data Source Definition Part */
- ptr2 = ptr;
- while (eat_tag(&ptr2,"ds") == 1){
- rrd->stat_head->ds_cnt++;
- if((rrd->ds_def = rrd_realloc(rrd->ds_def,rrd->stat_head->ds_cnt*sizeof(ds_def_t)))==NULL){
- rrd_set_error("allocating rrd.ds_def");
- return -1;
- };
- /* clean out memory to make sure no data gets stored from previous tasks */
- memset(&(rrd->ds_def[rrd->stat_head->ds_cnt-1]), 0, sizeof(ds_def_t));
- if((rrd->pdp_prep = rrd_realloc(rrd->pdp_prep,rrd->stat_head->ds_cnt
- *sizeof(pdp_prep_t)))==NULL){
- rrd_set_error("allocating pdp_prep");
- return(-1);
- }
- /* clean out memory to make sure no data gets stored from previous tasks */
- memset(&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1]), 0, sizeof(pdp_prep_t));
-
- read_tag(&ptr2,"name",DS_NAM_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].ds_nam);
-
- read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
- /* test for valid type */
- if( (int)dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) == -1) return -1;
-
- if (dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) != DST_CDEF)
- {
- read_tag(&ptr2,"minimal_heartbeat","%lu",
- &(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_mrhb_cnt].u_cnt));
- read_tag(&ptr2,"min","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_min_val].u_val));
- read_tag(&ptr2,"max","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_max_val].u_val));
- } else { /* DST_CDEF */
- char buffer[1024];
- read_tag(&ptr2,"cdef","%1000s",buffer);
- parseCDEF_DS(buffer,rrd,rrd -> stat_head -> ds_cnt - 1);
- if (rrd_test_error()) return -1;
- }
-
- read_tag(&ptr2,"last_ds","%30s",rrd->pdp_prep[rrd->stat_head->ds_cnt-1].last_ds);
- read_tag(&ptr2,"value","%lf",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_val].u_val));
- read_tag(&ptr2,"unknown_sec","%lu",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_unkn_sec_cnt].u_cnt));
- eat_tag(&ptr2,"/ds");
- ptr=ptr2;
- }
-
- ptr2 = ptr;
- while (eat_tag(&ptr2,"rra") == 1){
- rrd->stat_head->rra_cnt++;
-
- /* allocate and reset rra definition areas */
- if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
- rrd_set_error("allocating rra_def"); return -1; }
- memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
-
- /* allocate and reset consolidation point areas */
- if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
- rrd->stat_head->rra_cnt
- *rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
- rrd_set_error("allocating cdp_prep"); return -1; }
-
- memset(&(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rrd->stat_head->rra_cnt-1)]),
- 0, rrd->stat_head->ds_cnt*sizeof(cdp_prep_t));
-
-
- read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
- /* test for valid type */
- if( (int)cf_conv(rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam) == -1) return -1;
-
- read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
- /* support to read RRA parameters */
- rra_index = rrd->stat_head->rra_cnt - 1;
- if ( input_version < 2 ){
- read_tag(&ptr2, "xff","%lf",
- &(rrd->rra_def[rra_index].par[RRA_cdp_xff_val].u_val));
- } else {
- if (eat_tag(&ptr2, "params") != 1) {
- rrd_set_error("could not find params tag to eat and skip");
- return -1;
+
+ end_ptr = NULL;
+ temp = strtod(str_ptr, &end_ptr);
+ xmlFree(str_ptr);
+
+ if (str_ptr == end_ptr) {
+ rrd_set_error
+ ("get_double_from_node: Cannot parse buffer as double: %s",
+ str_ptr);
+ return (-1);
+ }
+
+ *value = temp;
+
+ return (0);
+} /* int get_double_from_node */
+
+static int value_check_range(
+ rrd_value_t *rrd_value,
+ const ds_def_t *ds_def)
+{
+ double min;
+ double max;
+
+ if (opt_range_check == 0)
+ return (0);
+
+ min = ds_def->par[DS_min_val].u_val;
+ max = ds_def->par[DS_max_val].u_val;
+
+ if (((!isnan(min)) && (*rrd_value < min))
+ || ((!isnan(max)) && (*rrd_value > max)))
+ *rrd_value = DNAN;
+
+ return (0);
+} /* int value_check_range */
+
+/*
+ * Parse the <database> block within an RRA definition
+ */
+static int parse_tag_rra_database_row(
+ xmlDoc * doc,
+ xmlNode * node,
+ rrd_t *rrd,
+ rrd_value_t *rrd_value)
+{
+ unsigned int values_count = 0;
+ xmlNode *child;
+ int status;
+
+ status = 0;
+ for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
+ if ((xmlStrcmp(child->name, (const xmlChar *) "comment") == 0)
+ || (xmlStrcmp(child->name, (const xmlChar *) "text") == 0))
+ /* ignore */ ;
+ else if (xmlStrcmp(child->name, (const xmlChar *) "v") == 0) {
+ if (values_count < rrd->stat_head->ds_cnt) {
+ status =
+ get_double_from_node(doc, child,
+ rrd_value + values_count);
+ if (status == 0)
+ value_check_range(rrd_value + values_count,
+ rrd->ds_def + values_count);
+ }
+
+ values_count++;
+ } else {
+ rrd_set_error("parse_tag_rra_database_row: Unknown tag: %s",
+ child->name);
+ status = -1;