char* cgigetq(long argc, const char **args){ if (argc>= 1){ char *buf = rrdstrip(rrdcgiGetValue(rrdcgiArg,args[0])); char *buf2; char *c,*d; int qc=0; if (buf==NULL) return NULL; for(c=buf;*c != '\0';c++) if (*c == '"') qc++; if ((buf2 = malloc((strlen(buf) + 4 * qc + 4))) == NULL) { perror("Malloc Buffer"); exit(1); }; c=buf; d=buf2; *(d++) = '"'; while(*c != '\0'){ if (*c == '"') { *(d++) = '"'; *(d++) = '\''; *(d++) = '"'; *(d++) = '\''; } *(d++) = *(c++); } *(d++) = '"'; *(d) = '\0'; free(buf); return buf2; } return stralloc("[ERROR: not enough argument for RRD::CV::QUOTE]"); }
char *cgiget( long argc, const char **args) { if (argc >= 1) return rrdstrip(rrdcgiGetValue(rrdcgiArg, args[0])); else return stralloc("[ERROR: not enough arguments for RRD::CV]"); }
char* cgigetqp(long argc, const char **args){ char* buf; char* buf2; char* p; char* d; if (argc < 1) { return stralloc("[ERROR: not enough arguments for RRD::CV::PATH]"); } buf = rrdstrip(rrdcgiGetValue(rrdcgiArg, args[0])); if (!buf) { return NULL; } buf2 = malloc(strlen(buf)+1); if (!buf2) { perror("cgigetqp(): Malloc Path Buffer"); exit(1); }; p = buf; d = buf2; while (*p) { /* prevent mallicious paths from entering the system */ if (p[0] == '.' && p[1] == '.') { p += 2; *d++ = '_'; *d++ = '_'; } else { *d++ = *p++; } } *d = 0; free(buf); /* Make sure the path is relative, e.g. does not start with '/' */ p = buf2; while ('/' == *p) { *p++ = '_'; } return buf2; }