X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Frrd_cgi.c;h=ee003c96e1cf08ed8f9bc65839244144116cc277;hb=d9822df7ed5e8122cf3a62e4e99678e94007f504;hp=ce619af1022b3c0a3e5e41bb57c26d14b51f69fc;hpb=1559397b94b4af3de73cfa23c04be31d8bee53e7;p=pkg-rrdtool.git diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c index ce619af..ee003c9 100644 --- a/src/rrd_cgi.c +++ b/src/rrd_cgi.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3.7 Copyright by Tobi Oetiker, 1997-2009 + * RRDtool 1.4.8 Copyright by Tobi Oetiker, 1997-2013 ***************************************************************************** * rrd_cgi.c RRD Web Page Generator *****************************************************************************/ @@ -9,6 +9,11 @@ #include #endif +#ifdef WIN32 + #define strcasecmp stricmp + #define strcasencmp strnicmp +#endif + #define MEMBLK 1024 /*#define DEBUG_PARSER #define DEBUG_VARS*/ @@ -374,7 +379,7 @@ static void calfree( if (calcpr) { free(calcpr); } - calcpr=NULL; + calcpr = NULL; } } @@ -453,9 +458,7 @@ int main( int argc, char *argv[]) { - long length; char *buffer; - char *server_url = NULL; long i; long filter = 0; struct option long_options[] = { @@ -497,7 +500,6 @@ int main( if (!filter) { rrdcgiDebug(0, 0); rrdcgiArg = rrdcgiInit(); - server_url = getenv("SERVER_URL"); } /* make sure we have one extra argument, @@ -511,7 +513,7 @@ int main( fprintf(stderr, "ERROR: expected a filename\n"); exit(1); } else { - length = readfile(argv[optind], &buffer, 1); + readfile(argv[optind], &buffer, 1); } if (rrd_test_error()) { @@ -954,7 +956,6 @@ char *drawgraph( DS_NAM_SIZE) * sizeof(char)); sprintf(err, "[ERROR: %s]", rrd_get_error()); rrd_clear_error(); - calfree(); return err; } } @@ -989,7 +990,10 @@ char *printtimelast( 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()) + @@ -1002,10 +1006,7 @@ char *printtimelast( 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 ]"); } char *printtimenow( @@ -1054,7 +1055,7 @@ char *scanargs( int curarg_contains_rrd_directives; /* local array of arguments while parsing */ - int argc = 0; + int argc = 1; char **argv; #ifdef DEBUG_PARSER @@ -1070,6 +1071,7 @@ char *scanargs( if (!argv) { return NULL; } + argv[0] = "rrdcgi"; /* skip leading blanks */ while (isspace((int) *line)) { @@ -1173,7 +1175,7 @@ char *scanargs( 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); @@ -1187,8 +1189,17 @@ char *scanargs( #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; @@ -1242,13 +1253,8 @@ int parse( 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; @@ -1388,7 +1394,8 @@ s_var **rrdcgiReadVariables( length = atoi(ip); if ((line = (char *) malloc(length + 2)) == NULL) return NULL; - fgets(line, length + 1, stdin); + if (fgets(line, length + 1, stdin) == NULL) + return NULL; } else return NULL; } else if (cp && !strcmp(cp, "GET")) {