Code

Allow to force overwrite when restoring from xml to rrd.
[rrdtool-all.git] / program / src / rrd_restore.c
1 /*****************************************************************************
2  * RRDtool 1.1.x  Copyright Tobias Oetiker, 1997 - 2002
3  *****************************************************************************
4  * rrd_restore.c  creates new rrd from data dumped by rrd_dump.c
5  *****************************************************************************/
7 #include "rrd_tool.h"
8 #include "rrd_rpncalc.h"
9 #include <fcntl.h>
11 /* Prototypes */
13 void xml_lc(char*);
14 int skip(char **);
15 int eat_tag(char **, char *);
16 int read_tag(char **, char *, char *, void *);
17 int xml2rrd(char*, rrd_t*, char);
18 int rrd_write(char *, rrd_t *, char);
19 void parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index);
20 void parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index);
21 void parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index);
23 /* convert all ocurances of <BlaBlaBla> to <blablabla> */
25 void xml_lc(char* buf){
26   int intag=0;
27   while((*buf)){
28     if (intag ==0 && (*buf) == '<') {
29       intag = 1;
30     }
31     else if (intag ==1 && (*buf) == '>') {
32       intag = 0;
33       continue;
34     } else  if (intag ==1) {
35       *buf = tolower(*buf);
36     }
37     buf++;    
38   }
39 }
41 int skip(char **buf){
42   char *ptr;  
43   ptr=(*buf);
44   do {
45     (*buf)=ptr;
46     while((*(ptr+1)) && ((*ptr)==' ' ||  (*ptr)=='\r' || (*ptr)=='\n' || (*ptr)=='\t')) ptr++;
47     if (strncmp(ptr,"<!--",4) == 0) {
48       ptr= strstr(ptr,"-->");
49       if (ptr) ptr+=3; else {
50         rrd_set_error("Dangling Comment");
51         (*buf) = NULL;
52         return -1;
53       }
54     }
55   } while ((*buf)!=ptr);  
56   return 1;
57 }
59 int eat_tag(char **buf, char *tag){ 
60   if ((*buf)==NULL) return -1;   /* fall though clause */
62   rrd_clear_error();
63   skip(buf);
64   if ((**buf)=='<' 
65       && strncmp((*buf)+1,tag,strlen(tag)) == 0 
66       && *((*buf)+strlen(tag)+1)=='>') {
67     (*buf) += strlen(tag)+2;
68   }
69   else {
70     rrd_set_error("No <%s> tag found",tag);
71     (*buf) = NULL;
72     return -1;
73   }
74   skip(buf);
75   return 1;
76 }
78 int read_tag(char **buf, char *tag, char *format, void *value){
79     char *end_tag;
80     int matches;
81     if ((*buf)==NULL) return -1;   /* fall though clause */
82     rrd_clear_error();
83     if (eat_tag(buf,tag)==1){
84         char *temp;
85         temp = (*buf);
86         while(*((*buf)+1) && (*(*buf) != '<')) (*buf)++; /*find start of endtag*/
87         *(*buf) = '\0';
88         matches =sscanf(temp,format,value);
89         *(*buf) = '<';
90         end_tag = malloc((strlen(tag)+2)*sizeof(char));
91         sprintf(end_tag,"/%s",tag);
92         eat_tag(buf,end_tag);
93         free(end_tag);
94         if (matches == 0 && strcmp(format,"%lf") == 0)
95             (*((double* )(value))) = DNAN;
96         if (matches != 1)       return 0;       
97         return 1;
98     }
99     return -1;
103 /* parse the data stored in buf and return a filled rrd structure */
104 int xml2rrd(char* buf, rrd_t* rrd, char rc){
105   /* pass 1 identify number of RRAs  */
106   char *ptr,*ptr2,*ptr3; /* walks thought the buffer */
107   long rows=0,mempool=0,i=0;
108   int rra_index;
109   xml_lc(buf); /* lets lowercase all active parts of the xml */
110   ptr=buf;
111   ptr2=buf;
112   ptr3=buf;
113   /* start with an RRD tag */
115   eat_tag(&ptr,"rrd");
116   /* allocate static header */
117   if((rrd->stat_head = calloc(1,sizeof(stat_head_t)))==NULL){
118     rrd_set_error("allocating rrd.stat_head");
119     return -1;    
120   };
122   strcpy(rrd->stat_head->cookie,RRD_COOKIE);
123   read_tag(&ptr,"version","%4[0-9]",rrd->stat_head->version);
124   /* added primitive version checking */
125   if (atoi(rrd -> stat_head -> version) > atoi(RRD_VERSION) )
126   {
127     rrd_set_error("Incompatible file version, detected version %s is bigger than supported version %s\n",
128                   rrd -> stat_head -> version, RRD_VERSION );
129     free(rrd -> stat_head);
130     return -1;
131   }
132   if (atoi(rrd -> stat_head -> version) < 2) 
133   {
134     rrd_set_error("Can only restore version >= 2 (Not %s). Dump your rrd using a current rrdtool dump.",  rrd -> stat_head -> version );
135     free(rrd -> stat_head);
136     return -1;
137   }
138   rrd->stat_head->float_cookie = FLOAT_COOKIE;
139   rrd->stat_head->ds_cnt = 0;
140   rrd->stat_head->rra_cnt = 0;
141   read_tag(&ptr,"step","%lu",&(rrd->stat_head->pdp_step));
143   /* allocate live head */
144   if((rrd->live_head = calloc(1,sizeof(live_head_t)))==NULL){
145     rrd_set_error("allocating rrd.live_head");
146     return -1;    
147   }
148   read_tag(&ptr,"lastupdate","%lu",&(rrd->live_head->last_up));
150   /* Data Source Definition Part */
151   ptr2 = ptr;
152   while (eat_tag(&ptr2,"ds") == 1){
153       rrd->stat_head->ds_cnt++;
154       if((rrd->ds_def = rrd_realloc(rrd->ds_def,rrd->stat_head->ds_cnt*sizeof(ds_def_t)))==NULL){
155           rrd_set_error("allocating rrd.ds_def");
156           return -1;
157       };
158       /* clean out memory to make sure no data gets stored from previous tasks */
159       memset(&(rrd->ds_def[rrd->stat_head->ds_cnt-1]), 0, sizeof(ds_def_t));
160       if((rrd->pdp_prep = rrd_realloc(rrd->pdp_prep,rrd->stat_head->ds_cnt
161                                   *sizeof(pdp_prep_t)))==NULL){
162         rrd_set_error("allocating pdp_prep");
163         return(-1);
164       }
165       /* clean out memory to make sure no data gets stored from previous tasks */
166       memset(&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1]), 0, sizeof(pdp_prep_t));
168       read_tag(&ptr2,"name",DS_NAM_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].ds_nam);
170       read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
171       /* test for valid type */
172       if(dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) == -1) return -1;      
174           if (dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) != DST_CDEF)
175           {
176       read_tag(&ptr2,"minimal_heartbeat","%lu",
177                &(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_mrhb_cnt].u_cnt));
178       read_tag(&ptr2,"min","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_min_val].u_val));
179       read_tag(&ptr2,"max","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_max_val].u_val));
180           } else { /* DST_CDEF */
181                  char buffer[1024];
182              read_tag(&ptr2,"cdef","%s",buffer);
183                  parseCDEF_DS(buffer,rrd,rrd -> stat_head -> ds_cnt - 1);
184           }
186       read_tag(&ptr2,"last_ds","%30s",rrd->pdp_prep[rrd->stat_head->ds_cnt-1].last_ds);
187       read_tag(&ptr2,"value","%lf",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_val].u_val));
188       read_tag(&ptr2,"unknown_sec","%lu",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_unkn_sec_cnt].u_cnt));      
189       eat_tag(&ptr2,"/ds");
190       ptr=ptr2;
191   }
192   
193   ptr2 = ptr;
194   while (eat_tag(&ptr2,"rra") == 1){
195       rrd->stat_head->rra_cnt++;
197       /* alocate and reset rra definition areas */
198       if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
199           rrd_set_error("allocating rra_def"); return -1; }      
200       memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
202       /* alocate and reset consolidation point areas */
203       if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
204                                   rrd->stat_head->rra_cnt
205                                   *rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
206           rrd_set_error("allocating cdp_prep"); return -1; }
208       memset(&(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rrd->stat_head->rra_cnt-1)]), 
209              0, rrd->stat_head->ds_cnt*sizeof(cdp_prep_t));
211       
212       read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
213       /* test for valid type */
214       if(cf_conv(rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam) == -1) return -1;
216       read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
217       /* support to read RRA parameters */
218       eat_tag(&ptr2, "params");
219       skip(&ptr2);
220       rra_index = rrd->stat_head->rra_cnt - 1;
221       /* backwards compatibility w/ old patch */
222       if (strncmp(ptr2, "<value>",7) == 0) {
223          parse_patch1028_RRA_params(&ptr2,rrd,rra_index); 
224       } else {
225       switch(cf_conv(rrd -> rra_def[rra_index].cf_nam)) {
226       case CF_HWPREDICT:
227          read_tag(&ptr2, "hw_alpha", "%lf", 
228             &(rrd->rra_def[rra_index].par[RRA_hw_alpha].u_val));
229          read_tag(&ptr2, "hw_beta", "%lf", 
230             &(rrd->rra_def[rra_index].par[RRA_hw_beta].u_val));
231          read_tag(&ptr2, "dependent_rra_idx", "%lu", 
232             &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
233          break;
234       case CF_SEASONAL:
235       case CF_DEVSEASONAL:
236          read_tag(&ptr2, "seasonal_gamma", "%lf", 
237             &(rrd->rra_def[rra_index].par[RRA_seasonal_gamma].u_val));
238          read_tag(&ptr2, "seasonal_smooth_idx", "%lu", 
239             &(rrd->rra_def[rra_index].par[RRA_seasonal_smooth_idx].u_cnt));
240          read_tag(&ptr2, "dependent_rra_idx", "%lu", 
241             &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
242          break;
243       case CF_FAILURES:
244          read_tag(&ptr2, "delta_pos", "%lf", 
245             &(rrd->rra_def[rra_index].par[RRA_delta_pos].u_val));
246          read_tag(&ptr2, "delta_neg", "%lf", 
247             &(rrd->rra_def[rra_index].par[RRA_delta_neg].u_val));
248          read_tag(&ptr2, "window_len", "%lu", 
249             &(rrd->rra_def[rra_index].par[RRA_window_len].u_cnt));
250          read_tag(&ptr2, "failure_threshold", "%lu", 
251             &(rrd->rra_def[rra_index].par[RRA_failure_threshold].u_cnt));
252          /* fall thru */
253       case CF_DEVPREDICT:
254          read_tag(&ptr2, "dependent_rra_idx", "%lu", 
255             &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
256          break;
257       case CF_AVERAGE:
258       case CF_MAXIMUM:
259       case CF_MINIMUM:
260       case CF_LAST:
261       default:
262          read_tag(&ptr2, "xff","%lf",
263             &(rrd->rra_def[rra_index].par[RRA_cdp_xff_val].u_val));
264       }
265       }
266       eat_tag(&ptr2, "/params");
267       eat_tag(&ptr2,"cdp_prep");
268       for(i=0;i<rrd->stat_head->ds_cnt;i++)
269       {
270       eat_tag(&ptr2,"ds");
271       /* support to read CDP parameters */
272       rra_index = rrd->stat_head->rra_cnt-1; 
273       skip(&ptr2);
274       if (strncmp(ptr2, "<value>",7) == 0) {
275          parse_patch1028_CDP_params(&ptr2,rrd,rra_index,i);
276       } else {
277          read_tag(&ptr2, "primary_value","%lf",
278                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
279                +i].scratch[CDP_primary_val].u_val));
280          read_tag(&ptr2, "secondary_value","%lf",
281                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
282                +i].scratch[CDP_secondary_val].u_val));
283          switch(cf_conv(rrd->rra_def[rra_index].cf_nam)) {
284          case CF_HWPREDICT:
285             read_tag(&ptr2,"intercept","%lf", 
286                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
287                +i].scratch[CDP_hw_intercept].u_val));
288             read_tag(&ptr2,"last_intercept","%lf", 
289                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
290                +i].scratch[CDP_hw_last_intercept].u_val));
291             read_tag(&ptr2,"slope","%lf", 
292                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
293                +i].scratch[CDP_hw_slope].u_val));
294             read_tag(&ptr2,"last_slope","%lf", 
295                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
296                +i].scratch[CDP_hw_last_slope].u_val));
297             read_tag(&ptr2,"nan_count","%lu", 
298                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
299                +i].scratch[CDP_null_count].u_cnt));
300             read_tag(&ptr2,"last_nan_count","%lu", 
301                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
302                +i].scratch[CDP_last_null_count].u_cnt));
303             break;
304          case CF_SEASONAL:
305          case CF_DEVSEASONAL:
306             read_tag(&ptr2,"seasonal","%lf", 
307                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
308                +i].scratch[CDP_hw_seasonal].u_val));
309             read_tag(&ptr2,"last_seasonal","%lf", 
310                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
311                +i].scratch[CDP_hw_last_seasonal].u_val));
312             read_tag(&ptr2,"init_flag","%lu", 
313                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
314                +i].scratch[CDP_init_seasonal].u_cnt));
315             break;
316          case CF_DEVPREDICT:
317             break;
318          case CF_FAILURES:
319             parse_FAILURES_history(&ptr2,rrd,rra_index,i); 
320             break;
321          case CF_AVERAGE:
322          case CF_MAXIMUM:
323          case CF_MINIMUM:
324          case CF_LAST:
325          default:
326             read_tag(&ptr2,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
327                *(rra_index) +i].scratch[CDP_val].u_val));
328             read_tag(&ptr2,"unknown_datapoints","%lu",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
329                *(rra_index) +i].scratch[CDP_unkn_pdp_cnt].u_cnt));
330             break;
331          }
332       }
333       eat_tag(&ptr2,"/ds");
334       }
335       eat_tag(&ptr2,"/cdp_prep");
336       rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt=0;
337       eat_tag(&ptr2,"database");
338       ptr3 = ptr2;      
339       while (eat_tag(&ptr3,"row") == 1){
340         
341           if(mempool==0){
342             mempool = 1000;
343             if((rrd->rrd_value = rrd_realloc(rrd->rrd_value,
344                                          (rows+mempool)*(rrd->stat_head->ds_cnt)
345                                          *sizeof(rrd_value_t)))==NULL) {
346               rrd_set_error("allocating rrd_values"); return -1; }
347           }
348           rows++;
349           mempool--;
350           rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt++;
351           for(i=0;i<rrd->stat_head->ds_cnt;i++){
353                   rrd_value_t  * value = &(rrd->rrd_value[(rows-1)*rrd->stat_head->ds_cnt+i]);
355                   read_tag(&ptr3,"v","%lf", value);
356                   
357                   if (
358                           (rc == 1)                     /* do we have to check for the ranges */
359                           &&
360                       (!isnan(*value))  /* not a NAN value */
361                       &&
362                           (dst_conv(rrd->ds_def[i].dst) != DST_CDEF)
363                           &&
364                       (                                 /* min defined and in the range ? */
365                           (!isnan(rrd->ds_def[i].par[DS_min_val].u_val) 
366                                 && (*value < rrd->ds_def[i].par[DS_min_val].u_val)) 
367                           ||                            /* max defined and in the range ? */
368                           (!isnan(rrd->ds_def[i].par[DS_max_val].u_val) 
369                                 && (*value > rrd->ds_def[i].par[DS_max_val].u_val))
370                       )
371                   ) {
372                       fprintf (stderr, "out of range found [ds: %lu], [value : %0.10e]\n", i, *value);
373                       *value = DNAN;
374                   }
375           }
376           eat_tag(&ptr3,"/row");                  
377           ptr2=ptr3;
378       }
379       eat_tag(&ptr2,"/database");
380       eat_tag(&ptr2,"/rra");                  
381       ptr=ptr2;
382   }  
383   eat_tag(&ptr,"/rrd");
385   if((rrd->rra_ptr = calloc(1,sizeof(rra_ptr_t)*rrd->stat_head->rra_cnt)) == NULL) {
386       rrd_set_error("allocating rra_ptr");
387       return(-1);
388   }
390   for(i=0; i <rrd->stat_head->rra_cnt; i++) {
391           /* last row in the xml file is the most recent; as
392            * rrd_update increments the current row pointer, set cur_row
393            * here to the last row. */
394       rrd->rra_ptr[i].cur_row = rrd->rra_def[i].row_cnt-1;
395   }
396   if (ptr==NULL)
397       return -1;
398   return 1;
400   
401     
405 /* create and empty rrd file according to the specs given */
407 int
408 rrd_write(char *file_name, rrd_t *rrd, char force_overwrite)
410     unsigned long    i,ii,val_cnt;
411     FILE             *rrd_file=NULL;
412     int                 fdflags;
413     int                 fd;
415     if (strcmp("-",file_name)==0){
416       rrd_file= stdout;
417     } else {
418       fdflags = O_WRONLY|O_CREAT;
419       if (force_overwrite == 0) {
420         fdflags |= O_EXCL;
421       }
422       fd = open(file_name,fdflags,0666);
423       if (fd == -1 || (rrd_file = fdopen(fd,"wb")) == NULL) {
424         rrd_set_error("creating '%s': %s",file_name,rrd_strerror(errno));
425         if (fd != -1)
426           close(fd);
427         return(-1);
428       }
429     }
430     fwrite(rrd->stat_head,
431            sizeof(stat_head_t), 1, rrd_file);
433     fwrite(rrd->ds_def,
434            sizeof(ds_def_t), rrd->stat_head->ds_cnt, rrd_file);
436     fwrite(rrd->rra_def,
437            sizeof(rra_def_t), rrd->stat_head->rra_cnt, rrd_file);
439          /* maybe the xml hold an old formatted rrd */
440     if (atoi(rrd->stat_head->version) < 3)
441       fwrite(&(rrd->live_head->last_up), sizeof(long),1, rrd_file);
442     else
443       fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
445     fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);
446     
447     fwrite( rrd->cdp_prep, sizeof(cdp_prep_t),rrd->stat_head->rra_cnt*
448             rrd->stat_head->ds_cnt,rrd_file);
449     fwrite( rrd->rra_ptr, sizeof(rra_ptr_t), rrd->stat_head->rra_cnt,rrd_file);
453     /* calculate the number of rrd_values to dump */
454     val_cnt=0;
455     for(i=0; i <  rrd->stat_head->rra_cnt; i++)
456         for(ii=0; ii <  rrd->rra_def[i].row_cnt * rrd->stat_head->ds_cnt;ii++)
457             val_cnt++;
458     fwrite( rrd->rrd_value, sizeof(rrd_value_t),val_cnt,rrd_file);
460     /* lets see if we had an error */
461     if(ferror(rrd_file)){
462         rrd_set_error("a file error occurred while creating '%s'",file_name);
463         fclose(rrd_file);       
464         return(-1);
465     }
466     
467     fclose(rrd_file);    
468     return 0;
472 int
473 rrd_restore(int argc, char **argv) 
475     rrd_t          rrd;
476     char          *buf;
477         char                    rc = 0;
478         char                    force_overwrite = 0;    
480     /* init rrd clean */
481     rrd_init(&rrd);
482     if (argc<3) {
483                 rrd_set_error("usage rrdtool %s [--range-check/-r] [--force-overwrite/-f] file.xml file.rrd",argv[0]);
484                 return -1;
485     }
486         
487         while (1) {
488                 static struct option long_options[] =
489                 {
490                         {"range-check",      required_argument, 0,  'r'},
491                         {"force-overwrite",     required_argument, 0,   'f'},
492                         {0,0,0,0}
493                 };
494                 int option_index = 0;
495                 int opt;
496                 
497                 
498                 opt = getopt_long(argc, argv, "r:f", long_options, &option_index);
499                 
500                 if (opt == EOF)
501                         break;
502                 
503                 switch(opt) {
504                 case 'r':
505                         rc=1;
506                         break;
507                 case 'f':
508                         force_overwrite=1;
509                         break;
510                 default:
511                         rrd_set_error("usage rrdtool %s [--range-check|-r] file.xml file.rrd",argv[0]);
512         return -1;
513                         break;
514                 }
515     }
516         
517     if (readfile(argv[optind],&buf,0)==-1){
518       return -1;
519     }
520     if (xml2rrd(buf,&rrd,rc)==-1) {
521         rrd_free(&rrd);
522         free(buf);
523         return -1;
524     }
525     free(buf);
526     if(rrd_write(argv[optind+1],&rrd,force_overwrite)==-1){
527         rrd_free(&rrd); 
528         return -1;      
529     };
530     rrd_free(&rrd);    
531     return 0;
534 /* a backwards compatibility routine that will parse the RRA params section
535  * generated by the aberrant patch to 1.0.28. */
537 void
538 parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index)
540    int i;
541    for (i = 0; i < MAX_RRA_PAR_EN; i++)
542    {
543    if (i == RRA_dependent_rra_idx ||
544        i == RRA_seasonal_smooth_idx ||
545        i == RRA_failure_threshold)
546       read_tag(buf, "value","%lu",
547          &(rrd->rra_def[rra_index].par[i].u_cnt));
548    else
549       read_tag(buf, "value","%lf",
550          &(rrd->rra_def[rra_index].par[i].u_val));
551    }
554 /* a backwards compatibility routine that will parse the CDP params section
555  * generated by the aberrant patch to 1.0.28. */
556 void
557 parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index)
559    int ii;
560    for (ii = 0; ii < MAX_CDP_PAR_EN; ii++)
561    {
562    if (cf_conv(rrd->rra_def[rra_index].cf_nam) == CF_FAILURES ||
563        ii == CDP_unkn_pdp_cnt ||
564        ii == CDP_null_count ||
565        ii == CDP_last_null_count)
566    {
567       read_tag(buf,"value","%lu",
568        &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index) + ds_index].scratch[ii].u_cnt));
569    } else {
570       read_tag(buf,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt*
571        (rra_index) + ds_index].scratch[ii].u_val));
572    }
573    }
576 void
577 parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index)
579    char history[MAX_FAILURES_WINDOW_LEN + 1];
580    char *violations_array;
581    unsigned short i;
583    /* 28 = MAX_FAILURES_WINDOW_LEN */ 
584    read_tag(buf, "history", "%28[0-1]", history);
585    violations_array = (char*) rrd -> cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
586       + ds_index].scratch;
587    
588    for (i = 0; i < rrd -> rra_def[rra_index].par[RRA_window_len].u_cnt; ++i)
589       violations_array[i] = (history[i] == '1') ? 1 : 0;