Travis,

I have attached my patches that add rrd_fetch_r() (and make the
strings const char* instead of char*).  The only difference between
rrd_fetch_r() and rrd_fetch_fn() is that rrd_fetch_r() receives the
consolidation function as a string (instead of an enum cf_en).

Tobi and other developers, feel free to include these in the mainline source.

Thanks,
Sam
diff -ru rrdtool-1.2.18.orig/src/fnv.h rrdtool-1.2.18/src/fnv.h
--- rrdtool-1.2.18.orig/src/fnv.h	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/fnv.h	2007-02-16 16:15:31.000000000 -0500
@@ -99,10 +99,10 @@
  */
 #define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)
 
-Fnv32_t fnv_32_buf(void *, size_t, Fnv32_t);
+Fnv32_t fnv_32_buf(const void *, size_t, Fnv32_t);
 
-Fnv32_t fnv_32_str(char *, Fnv32_t );
+Fnv32_t fnv_32_str(const char *, Fnv32_t );
 
-unsigned long FnvHash(char *);
+unsigned long FnvHash(const char *);
 
 #endif /* __FNV_H__ */
diff -ru rrdtool-1.2.18.orig/src/hash_32.c rrdtool-1.2.18/src/hash_32.c
--- rrdtool-1.2.18.orig/src/hash_32.c	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/hash_32.c	2007-02-16 16:15:10.000000000 -0500
@@ -86,10 +86,10 @@
  *	 argument on the first call to either fnv_32_buf() or fnv_32_str().
  */
 Fnv32_t
-fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
+fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
 {
-    unsigned char *bp = (unsigned char *)buf;	/* start of buffer */
-    unsigned char *be = bp + len;		/* beyond end of buffer */
+    const unsigned char *bp = (const unsigned char *)buf;	/* start of buffer */
+    const unsigned char *be = bp + len;		/* beyond end of buffer */
 
     /*
      * FNV-1 hash each octet in the buffer
@@ -125,9 +125,9 @@
  *	 argument on the first call to either fnv_32_buf() or fnv_32_str().
  */
 Fnv32_t
-fnv_32_str(char *str, Fnv32_t hval)
+fnv_32_str(const char *str, Fnv32_t hval)
 {
-    unsigned char *s = (unsigned char *)str;	/* unsigned string */
+    const unsigned char *s = (const unsigned char *)str;	/* unsigned string */
 
     /*
      * FNV-1 hash each octet in the buffer
@@ -146,7 +146,7 @@
 }
 
 /* a wrapper function for fnv_32_str */
-unsigned long FnvHash(char *str)
+unsigned long FnvHash(const char *str)
 {
   return fnv_32_str(str,FNV1_32_INIT);
 }
diff -ru rrdtool-1.2.18.orig/src/rrd_create.c rrdtool-1.2.18/src/rrd_create.c
--- rrdtool-1.2.18.orig/src/rrd_create.c	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_create.c	2007-02-16 16:21:55.000000000 -0500
@@ -10,9 +10,9 @@
 
 #include "rrd_is_thread_safe.h"
 
-unsigned long FnvHash(char *str);
+unsigned long FnvHash(const char *str);
 int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashed_name);
-void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx);
+void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx);
 
 int
 rrd_create(int argc, char **argv) 
@@ -91,9 +91,9 @@
 
 /* #define DEBUG */
 int
-rrd_create_r(char *filename,
+rrd_create_r(const char *filename,
 	     unsigned long pdp_step, time_t last_up,
-	     int argc, char **argv) 
+	     int argc, const char **argv) 
 {
     rrd_t             rrd;
     long              i;
@@ -439,7 +439,7 @@
     return rrd_create_fn(filename, &rrd);
 }
 
-void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx)
+void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx)
 {
     char minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE];	
     /*
@@ -547,7 +547,7 @@
 /* create and empty rrd file according to the specs given */
 
 int
-rrd_create_fn(char *file_name, rrd_t *rrd)
+rrd_create_fn(const char *file_name, rrd_t *rrd)
 {
     unsigned long    i,ii;
     FILE             *rrd_file;
diff -ru rrdtool-1.2.18.orig/src/rrd.h rrdtool-1.2.18/src/rrd.h
--- rrdtool-1.2.18.orig/src/rrd.h	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/rrd.h	2007-02-16 16:11:59.000000000 -0500
@@ -79,14 +79,14 @@
 		 char ***, rrd_value_t **);
 
 /* thread-safe (hopefully) */
-int    rrd_create_r(char *filename,
+int    rrd_create_r(const char *filename,
 		    unsigned long pdp_step, time_t last_up,
-		    int argc, char **argv);
+		    int argc, const char **argv);
 /* NOTE: rrd_update_r are only thread-safe if no at-style time
    specifications get used!!! */
 
-int    rrd_update_r(char *filename, char *_template,
-		    int argc, char **argv);
+int    rrd_update_r(const char *filename, const char *_template,
+		    int argc, const char **argv);
 int    rrd_dump_r(const char *filename, char *outname);
 time_t rrd_last_r(const char *filename);
 time_t rrd_first_r(const char *filename, int rraindex);
diff -ru rrdtool-1.2.18.orig/src/rrd_rpncalc.c rrdtool-1.2.18/src/rrd_rpncalc.c
--- rrdtool-1.2.18.orig/src/rrd_rpncalc.c	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_rpncalc.c	2007-02-16 16:24:36.000000000 -0500
@@ -187,7 +187,7 @@
     return 0;
 }
 
-void parseCDEF_DS(char *def,rrd_t *rrd, int ds_idx)
+void parseCDEF_DS(const char *def,rrd_t *rrd, int ds_idx)
 {
     rpnp_t *rpnp = NULL;
     rpn_cdefds_t *rpnc = NULL;
diff -ru rrdtool-1.2.18.orig/src/rrd_rpncalc.h rrdtool-1.2.18/src/rrd_rpncalc.h
--- rrdtool-1.2.18.orig/src/rrd_rpncalc.h	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_rpncalc.h	2007-02-16 16:24:25.000000000 -0500
@@ -47,7 +47,7 @@
 void rpnstack_init(rpnstack_t *rpnstack);
 void rpnstack_free(rpnstack_t *rpnstack);
 
-void parseCDEF_DS(char *def, rrd_t *rrd, int ds_idx);
+void parseCDEF_DS(const char *def, rrd_t *rrd, int ds_idx);
 long lookup_DS(void *rrd_vptr, char *ds_name);
 
 short rpn_compact(rpnp_t *rpnp,rpn_cdefds_t **rpnc,short *count);
diff -ru rrdtool-1.2.18.orig/src/rrd_tool.h rrdtool-1.2.18/src/rrd_tool.h
--- rrdtool-1.2.18.orig/src/rrd_tool.h	2007-01-23 15:54:49.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_tool.h	2007-02-16 16:22:20.000000000 -0500
@@ -161,7 +161,7 @@
 
 int PngSize(FILE *, long *, long *);
 
-int rrd_create_fn(char *file_name, rrd_t *rrd);
+int rrd_create_fn(const char *file_name, rrd_t *rrd);
 int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
 		 time_t *start,time_t *end,
 		 unsigned long *step,
diff -ru rrdtool-1.2.18.orig/src/rrd_update.c rrdtool-1.2.18/src/rrd_update.c
--- rrdtool-1.2.18.orig/src/rrd_update.c	2007-02-16 16:32:47.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_update.c	2007-02-16 16:19:17.000000000 -0500
@@ -87,8 +87,8 @@
 					unsigned short CDP_scratch_idx, FILE *rrd_file,
 					info_t *pcdp_summary, time_t *rra_time);
 #endif
-int rrd_update_r(char *filename, char *tmplt, int argc, char **argv);
-int _rrd_update(char *filename, char *tmplt, int argc, char **argv, 
+int rrd_update_r(const char *filename, const char *tmplt, int argc, const char **argv);
+int _rrd_update(const char *filename, const char *tmplt, int argc, const char **argv, 
 					info_t*);
 
 #define IFDNAN(X,Y) (isnan(X) ? (Y) : (X));
@@ -186,13 +186,13 @@
 }
 
 int
-rrd_update_r(char *filename, char *tmplt, int argc, char **argv)
+rrd_update_r(const char *filename, const char *tmplt, int argc, const char **argv)
 {
    return _rrd_update(filename, tmplt, argc, argv, NULL);
 }
 
 int
-_rrd_update(char *filename, char *tmplt, int argc, char **argv, 
+_rrd_update(const char *filename, const char *tmplt, int argc, const char **argv, 
    info_t *pcdp_summary)
 {
 
@@ -364,13 +364,13 @@
     	/* we should work on a writeable copy here */
 	char *dsname;
 	unsigned int tmpl_len;
-    	tmplt = strdup(tmplt);
-	dsname = tmplt;
+    	char *tmplt_copy = strdup(tmplt);
+	dsname = tmplt_copy;
 	tmpl_cnt = 1; /* the first entry is the time */
-	tmpl_len = strlen(tmplt);
+	tmpl_len = strlen(tmplt_copy);
 	for(i=0;i<=tmpl_len ;i++) {
-	    if (tmplt[i] == ':' || tmplt[i] == '\0') {
-		tmplt[i] = '\0';
+	    if (tmplt_copy[i] == ':' || tmplt_copy[i] == '\0') {
+		tmplt_copy[i] = '\0';
 		if (tmpl_cnt>rrd.stat_head->ds_cnt){
   		    rrd_set_error("tmplt contains more DS definitions than RRD");
 		    free(updvals); free(pdp_temp);
@@ -380,23 +380,23 @@
 		if ((tmpl_idx[tmpl_cnt++] = ds_match(&rrd,dsname)) == -1){
   		    rrd_set_error("unknown DS name '%s'",dsname);
 		    free(updvals); free(pdp_temp);
-		    free(tmplt);
+		    free(tmplt_copy);
 		    free(tmpl_idx); rrd_free(&rrd);
 		    fclose(rrd_file); return(-1);
 		} else {
 		  /* the first element is always the time */
 		  tmpl_idx[tmpl_cnt-1]++; 
-		  /* go to the next entry on the tmplt */
-		  dsname = &tmplt[i+1];
+		  /* go to the next entry on the tmplt_copy */
+		  dsname = &tmplt_copy[i+1];
                   /* fix the damage we did before */
                   if (i<tmpl_len) {
-                     tmplt[i]=':';
+                     tmplt_copy[i]=':';
                   } 
 
 		}
 	    }	    
 	}
-	free(tmplt);
+	free(tmplt_copy);
     }
     if ((pdp_new = malloc(sizeof(rrd_value_t)
 			  *rrd.stat_head->ds_cnt))==NULL){
diff -ru rrdtool-1.2.18.orig/doc/rrdthreads.pod rrdtool-1.2.18/doc/rrdthreads.pod
--- rrdtool-1.2.18.orig/doc/rrdthreads.pod	2007-02-19 16:15:38.000000000 -0500
+++ rrdtool-1.2.18/doc/rrdthreads.pod	2007-02-19 09:24:43.000000000 -0500
@@ -137,7 +137,7 @@
 =head2 CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS
 
 Currently there exist thread-safe variants of C<rrd_update>,
-C<rrd_create>, C<rrd_dump>, C<rrd_info> and C<rrd_last>.
+C<rrd_create>, C<rrd_dump>, C<rrd_info>, C<rrd_last>, and C<rrd_fetch>.
 
 =head1 AUTHOR
 
diff -ru rrdtool-1.2.18.orig/src/rrd_fetch.c rrdtool-1.2.18/src/rrd_fetch.c
--- rrdtool-1.2.18.orig/src/rrd_fetch.c	2007-02-19 16:15:38.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_fetch.c	2007-02-19 16:17:21.000000000 -0500
@@ -53,6 +53,8 @@
  *****************************************************************************/
 
 #include "rrd_tool.h"
+
+#include "rrd_is_thread_safe.h"
 /*#define DEBUG*/
 
 int
@@ -71,7 +73,7 @@
 
     long     step_tmp =1;
     time_t   start_tmp=0, end_tmp=0;
-    enum     cf_en cf_idx;
+    const char *cf;
 
     struct rrd_time_value start_tv, end_tv;
     char     *parsetime_error = NULL;
@@ -148,19 +150,39 @@
 	rrd_set_error("not enough arguments");
 	return -1;
     }
-    
-    if ((int)(cf_idx=cf_conv(argv[optind+1])) == -1 ){
-	return -1;
-    }
 
-    if (rrd_fetch_fn(argv[optind],cf_idx,start,end,step,ds_cnt,ds_namv,data) == -1)
+    cf = argv[optind+1];
+
+    if (rrd_fetch_r(argv[optind],cf,start,end,step,ds_cnt,ds_namv,data) == -1)
 	return(-1);
     return (0);
 }
 
 int
+rrd_fetch_r(
+    const char           *filename,  /* name of the rrd */
+    const char           *cf,        /* which consolidation function ?*/
+    time_t         *start,
+    time_t         *end,       /* which time frame do you want ?
+                                * will be changed to represent reality */
+    unsigned long  *step,      /* which stepsize do you want? 
+                                * will be changed to represent reality */
+    unsigned long  *ds_cnt,    /* number of data sources in file */
+    char           ***ds_namv, /* names of data_sources */
+    rrd_value_t    **data)     /* two dimensional array containing the data */
+{
+    enum     cf_en cf_idx;
+
+    if ((int)(cf_idx=cf_conv(cf)) == -1 ){
+        return -1;
+    }
+
+    return (rrd_fetch_fn(filename,cf_idx,start,end,step,ds_cnt,ds_namv,data));
+}
+
+int
 rrd_fetch_fn(
-    char           *filename,  /* name of the rrd */
+    const char     *filename,  /* name of the rrd */
     enum cf_en     cf_idx,         /* which consolidation function ?*/
     time_t         *start,
     time_t         *end,       /* which time frame do you want ?
diff -ru rrdtool-1.2.18.orig/src/rrd_format.c rrdtool-1.2.18/src/rrd_format.c
--- rrdtool-1.2.18.orig/src/rrd_format.c	2007-02-19 16:15:38.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_format.c	2007-02-16 16:40:33.000000000 -0500
@@ -65,7 +65,7 @@
 }
 
 
-enum cf_en cf_conv(char *string)
+enum cf_en cf_conv(const char *string)
 {
 
     converter(AVERAGE,CF_AVERAGE)
diff -ru rrdtool-1.2.18.orig/src/rrd.h rrdtool-1.2.18/src/rrd.h
--- rrdtool-1.2.18.orig/src/rrd.h	2007-02-19 16:16:57.000000000 -0500
+++ rrdtool-1.2.18/src/rrd.h	2007-02-19 16:16:52.000000000 -0500
@@ -87,6 +87,12 @@
 
 int    rrd_update_r(const char *filename, const char *_template,
 		    int argc, const char **argv);
+int    rrd_fetch_r(const char *filename, const char* cf,
+                   time_t *start, time_t *end,
+                   unsigned long *step,
+                   unsigned long *ds_cnt,
+                   char        ***ds_namv,
+                   rrd_value_t **data);
 int    rrd_dump_r(const char *filename, char *outname);
 time_t rrd_last_r(const char *filename);
 time_t rrd_first_r(const char *filename, int rraindex);
diff -ru rrdtool-1.2.18.orig/src/rrd_tool.h rrdtool-1.2.18/src/rrd_tool.h
--- rrdtool-1.2.18.orig/src/rrd_tool.h	2007-02-19 16:15:38.000000000 -0500
+++ rrdtool-1.2.18/src/rrd_tool.h	2007-02-16 16:41:23.000000000 -0500
@@ -162,7 +162,7 @@
 int PngSize(FILE *, long *, long *);
 
 int rrd_create_fn(const char *file_name, rrd_t *rrd);
-int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
+int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
 		 time_t *start,time_t *end,
 		 unsigned long *step,
 		 unsigned long *ds_cnt,
@@ -179,7 +179,7 @@
 #define RRD_READONLY    0
 #define RRD_READWRITE   1
 
-enum cf_en cf_conv(char *string);
+enum cf_en cf_conv(const char *string);
 enum dst_en dst_conv(char *string);
 long ds_match(rrd_t *rrd,char *ds_nam);
 double rrd_diff(char *a, char *b);
_______________________________________________
rrd-users mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

Reply via email to