diff --git a/program/src/rrd_cgi.c b/program/src/rrd_cgi.c
index 27b4884b2e5b416c483f9ce598104d6911aa5203..df4a9dcdfbd5b14dccaa4b9eb7875c22d89d970b 100644 (file)
--- a/program/src/rrd_cgi.c
+++ b/program/src/rrd_cgi.c
/*****************************************************************************
- * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010
*****************************************************************************
* rrd_cgi.c RRD Web Page Generator
*****************************************************************************/
#include <stdlib.h>
#endif
+#ifdef WIN32
+ #define strcasecmp stricmp
+ #define strcasencmp strnicmp
+#endif
+
#define MEMBLK 1024
/*#define DEBUG_PARSER
#define DEBUG_VARS*/
if (buf == NULL) {
return stralloc("[ERROR: allocating strftime buffer]");
};
- last = rrd_last(argc + 1, (char **) args - 1);
+ /* not raising argc in step with args - 1 since the last argument
+ will be used below for strftime */
+
+ last = rrd_last(argc, (char **) args - 1);
if (rrd_test_error()) {
char *err =
malloc((strlen(rrd_get_error()) +
strftime(buf, 254, args[1], &tm_last);
return buf;
}
- if (argc < 2) {
- return stralloc("[ERROR: too few arguments for RRD::TIME::LAST]");
- }
- return stralloc("[ERROR: not enough arguments for RRD::TIME::LAST]");
+ return stralloc("[ERROR: expected <RRD::TIME::LAST file.rrd strftime-format>]");
}
char *printtimenow(
int curarg_contains_rrd_directives;
/* local array of arguments while parsing */
- int argc = 0;
+ int argc = 1;
char **argv;
#ifdef DEBUG_PARSER
if (!argv) {
return NULL;
}
+ argv[0] = "rrdcgi";
/* skip leading blanks */
while (isspace((int) *line)) {
argv[argc - 1] = rrd_expand_vars(stralloc(argv[argc - 1]));
}
#ifdef DEBUG_PARSER
- if (argc > 0) {
+ if (argc > 1) {
int n;
printf("<-- arguments found [%d]\n", argc);
#endif
/* update caller's notion of the argument array and it's size */
- *arguments = argv;
- *argument_count = argc;
+
+ /* note this is a bit of a hack since the rrd_cgi code used to just put
+ its arguments into a normal array starting at 0 ... since the rrd_*
+ commands expect and argc/argv array we used to just shift everything
+ by -1 ... this in turn exploded when a rrd_* function tried to print
+ argv[0] ... hence we are now doing everything in argv style but hand
+ over seemingly the old array ... but doing argv-1 will actually end
+ up in a 'good' place now. */
+
+ *arguments = argv+1;
+ *argument_count = argc-1;
if (Quote) {
return NULL;
if (end) {
/* got arguments, call function for 'tag' with arguments */
val = func(argc, (const char **) args);
- free(args);
+ free(args-1);
} else {
- /* unable to parse arguments, undo 0-termination by scanargs */
- for (; argc > 0; argc--) {
- *((args[argc - 1]) - 1) = ' ';
- }
-
/* next call, try parsing at current offset +1 */
end = (*buf) + i + 1;