X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_cgi.c;h=7f248ab04f1feac44885bd971bce88bb7d89e889;hb=88ec7a41d5ba332d0a902a17c0ef0cb01d133a30;hp=e79ecb7c1bee78fa1d6ad49a52cbe4b1167cac3e;hpb=5837606887a6d81e8b1f7588525cb1c8783fb62b;p=rrdtool.git diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c index e79ecb7..7f248ab 100644 --- a/src/rrd_cgi.c +++ b/src/rrd_cgi.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000 + * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002 ***************************************************************************** * rrd_cgi.c RRD Web Page Generator *****************************************************************************/ @@ -56,6 +56,9 @@ char* includefile(long, char **); /* for how long is the output of the cgi valid ? */ char* rrdgoodfor(long, char **); +/* format at-time specified times using strftime */ +char* printstrftime(long, char**); + /** http protocol needs special format, and GMT time **/ char *http_time(time_t *); @@ -80,7 +83,11 @@ static void calfree (void){ /* create freeable version of the string */ char * stralloc(char *str){ - char *nstr = malloc((strlen(str)+1)*sizeof(char)); + char *nstr; + if (str == NULL) { + return NULL; + } + nstr = malloc((strlen(str)+1)*sizeof(char)); strcpy(nstr,str); return(nstr); } @@ -128,9 +135,9 @@ int main(int argc, char *argv[]) { server_url = getenv("SERVER_URL"); } - if (optind != argc-1) { - fprintf(stderr, "ERROR: expected a filename\n"); - exit(1); + if ( (optind != argc-2 && strstr(getenv("SERVER_SOFTWARE"),"Apache/2") != NULL) && optind != argc-1) { + fprintf(stderr, "ERROR: expected a filename\n"); + exit(1); } else { length = readfile(argv[optind], &buffer, 1); } @@ -158,6 +165,7 @@ int main(int argc, char *argv[]) { i += parse(&buffer,i,"= 1) { @@ -248,6 +317,7 @@ char* includefile(long argc, char **args){ } } +static char* rrdstrip(char *buf){ char *start; if (buf == NULL) return NULL; @@ -367,7 +437,7 @@ char* drawgraph(long argc, char **args){ optind=0; /* reset gnu getopt */ opterr=0; /* reset gnu getopt */ calfree(); - if( rrd_graph(argc+1, args-1, &calcpr, &xsize, &ysize) != -1 ) { + if( rrd_graph(argc+1, args-1, &calcpr, &xsize, &ysize, NULL) != -1 ) { return stralloc(calcpr[0]); } else { if (rrd_test_error()) { @@ -407,7 +477,7 @@ char* printtimelast(long argc, char **args) { rrd_clear_error(); return err; } - tm_last = *localtime(&last); + localtime_r(&last, &tm_last); strftime(buf,254,args[1],&tm_last); return buf; } @@ -426,7 +496,7 @@ char* printtimenow(long argc, char **args) { if (buf == NULL){ return stralloc("[ERROR: allocating strftime buffer]"); }; - tm_now = *localtime(&now); + localtime_r(&now, &tm_now); strftime(buf,254,args[0],&tm_now); return buf; } @@ -437,6 +507,7 @@ char* printtimenow(long argc, char **args) { } /* scan aLine until an unescaped '>' arives */ +static char* scanargs(char *aLine, long *argc, char ***args) { char *getP, *putP; @@ -454,7 +525,7 @@ char* scanargs(char *aLine, long *argc, char ***args) getP = aLine; putP = aLine; while (*getP && !( !Quote && (braket == 0) && ((*getP) == '>'))){ - if (*getP < ' ') *getP = ' '; /*remove all special chars*/ + if ((unsigned)*getP < ' ') *getP = ' '; /*remove all special chars*/ switch (*getP) { case ' ': if (Quote){ @@ -571,10 +642,10 @@ int parse(char **buf, long i, char *tag, char * http_time(time_t *now) { - struct tm *tmptime; + struct tm tmptime; static char buf[60]; - tmptime=gmtime(now); - strftime(buf,sizeof(buf),"%a, %d %b %Y %H:%M:%S GMT",tmptime); + gmtime_r(now, &tmptime); + strftime(buf,sizeof(buf),"%a, %d %b %Y %H:%M:%S GMT", &tmptime); return(buf); }