X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_cgi.c;h=27b4884b2e5b416c483f9ce598104d6911aa5203;hp=75dabf4a7eecf5000518282d7e54a4c2b05b5dec;hb=5052175ab8c3ce994df281cee4aa1f8c3df1b70c;hpb=58a8f90229ee1625e0270256683b048da1b1df24 diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c index 75dabf4..27b4884 100644 --- a/src/rrd_cgi.c +++ b/src/rrd_cgi.c @@ -1,11 +1,13 @@ /***************************************************************************** - * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 + * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_cgi.c RRD Web Page Generator *****************************************************************************/ #include "rrd_tool.h" - +#ifdef HAVE_STDLIB_H +#include +#endif #define MEMBLK 1024 /*#define DEBUG_PARSER @@ -221,7 +223,7 @@ static size_t varheap_size = 0; /* allocate and initialize variable heap */ static int initvar( - ) + void) { varheap = (vardata *) malloc(sizeof(vardata) * INIT_VARSTORE_SIZE); if (varheap == NULL) { @@ -235,7 +237,7 @@ static int initvar( /* cleanup: free allocated memory */ static void donevar( - ) + void) { int i; @@ -288,13 +290,13 @@ static const char *putvar( if (0 == strcmp(name, varheap[i].name)) { /* overwrite existing entry */ if (varheap[i].is_const) { -#ifdef DEBUG_VARS +#ifdef DEBUG_VARS printf("\n", name, value); -# endif +#endif return varheap[i].value; } -#ifdef DEBUG_VARS +#ifdef DEBUG_VARS printf("\n", name, value, varheap[i].value); #endif @@ -372,6 +374,7 @@ static void calfree( if (calcpr) { free(calcpr); } + calcpr = NULL; } } @@ -389,6 +392,63 @@ char *stralloc( return (nstr); } +static int readfile( + const char *file_name, + char **buffer, + int skipfirst) +{ + long writecnt = 0, totalcnt = MEMBLK; + long offset = 0; + FILE *input = NULL; + char c; + + if ((strcmp("-", file_name) == 0)) { + input = stdin; + } else { + if ((input = fopen(file_name, "rb")) == NULL) { + rrd_set_error("opening '%s': %s", file_name, rrd_strerror(errno)); + return (-1); + } + } + if (skipfirst) { + do { + c = getc(input); + offset++; + } while (c != '\n' && !feof(input)); + } + if (strcmp("-", file_name)) { + fseek(input, 0, SEEK_END); + /* have extra space for detecting EOF without realloc */ + totalcnt = (ftell(input) + 1) / sizeof(char) - offset; + if (totalcnt < MEMBLK) + totalcnt = MEMBLK; /* sanitize */ + fseek(input, offset * sizeof(char), SEEK_SET); + } + if (((*buffer) = (char *) malloc((totalcnt + 4) * sizeof(char))) == NULL) { + perror("Allocate Buffer:"); + exit(1); + }; + do { + writecnt += + fread((*buffer) + writecnt, 1, + (totalcnt - writecnt) * sizeof(char), input); + if (writecnt >= totalcnt) { + totalcnt += MEMBLK; + if (((*buffer) = + rrd_realloc((*buffer), + (totalcnt + 4) * sizeof(char))) == NULL) { + perror("Realloc Buffer:"); + exit(1); + }; + } + } while (!feof(input)); + (*buffer)[writecnt] = '\0'; + if (strcmp("-", file_name) != 0) { + fclose(input); + }; + return writecnt; +} + int main( int argc, char *argv[]) @@ -398,6 +458,10 @@ int main( char *server_url = NULL; long i; long filter = 0; + struct option long_options[] = { + {"filter", no_argument, 0, 'f'}, + {0, 0, 0, 0} + }; #ifdef MUST_DISABLE_SIGFPE signal(SIGFPE, SIG_IGN); @@ -412,10 +476,6 @@ int main( for (i=0;iname, cp, esp - cp) - || !(strlen(result[k]->name) == esp - cp)); - k++); + || !(strlen(result[k]->name) == + (size_t) (esp - cp))); k++); if (k == i) { /* No such variable yet */ if ((result[i] = (s_var *) malloc(sizeof(s_var))) == NULL)