From: Emden Gansner Date: Thu, 25 Aug 2011 20:50:01 +0000 (-0400) Subject: Back out initial implementation of imagepath: it assumed a single graph and X-Git-Tag: LAST_LIBGRAPH~32^2~674^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=708f77dc2ddf340c13d53bd15028e25e2b1c8b91;p=graphviz Back out initial implementation of imagepath: it assumed a single graph and a single path, the tests where distributed, and it broke the caching of images in gvusershape.c. It also didn't check for graphviz being used as a web server. --- diff --git a/lib/common/globals.h b/lib/common/globals.h index a0d17cd32..e7b9414b3 100644 --- a/lib/common/globals.h +++ b/lib/common/globals.h @@ -67,7 +67,8 @@ extern "C" { EXTERN char *CmdName; EXTERN char *specificFlags; EXTERN char *specificItems; - EXTERN char *Gvfilepath; /* Path of files allowed in 'shapefile' attrib (also ps libs) */ + EXTERN char *Gvfilepath; /* Per-process path of files allowed in image attributes (also ps libs) */ + EXTERN char *Gvimagepath; /* Per-graph path of files allowed in image attributes (also ps libs) */ EXTERN unsigned char Verbose; EXTERN boolean Reduce, MemTest; diff --git a/lib/common/input.c b/lib/common/input.c index 2f708d711..2c4584e09 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -695,6 +695,12 @@ void graph_init(graph_t * g, boolean use_rankdir) GD_charset(g) = findCharset (g); + if (!HTTPServerEnVar) { + Gvimagepath = agget (g, "imagepath"); + if (!Gvimagepath) + Gvimagepath = Gvfilepath; + } + GD_drawing(g)->quantum = late_double(g, agfindgraphattr(g, "quantum"), 0.0, 0.0); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 2b6ced295..260c7ca05 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -14,12 +14,6 @@ #include "render.h" #include "htmltable.h" #include -#ifdef WIN32 -#include "libltdl/lt_system.h" -#endif -#ifndef WIN32 -#include -#endif #define RBCONST 12 #define RBCURVE .5 @@ -1537,10 +1531,6 @@ static void poly_gencode(GVJ_t * job, node_t * n) boolean pfilled; /* true if fill not handled by user shape */ char *color, *name; int doMap = (obj->url || obj->explicit_tooltip); - static char* ipfilename = NULL; - static char* imagepath = NULL; - static boolean firsttime = TRUE; - char *p; if (doMap && !(job->flags & EMIT_CLUSTERS_LAST)) gvrender_begin_anchor(job, @@ -1623,18 +1613,6 @@ static void poly_gencode(GVJ_t * job, node_t * n) name = agget(n, "shapefile"); usershape_p = TRUE; } else if ((name = agget(n, "image"))) { - - if (firsttime) { - imagepath = agget(agraphof(n),"imagepath"); - firsttime = FALSE; - } - if ((access (safefile(name), R_OK) != 0) && imagepath != NULL){ - if (p = strrchr(name, '/')) - name = ++p; - ipfilename = realloc(ipfilename,(strlen(imagepath) + strlen(name) + 2)); - sprintf (ipfilename, "%s%s%s", imagepath, DIRSEP, name); - name = ipfilename; - } usershape_p = TRUE; } if (usershape_p) { diff --git a/lib/common/utils.c b/lib/common/utils.c index 3d44db954..28da8e647 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -305,7 +305,6 @@ char *Fgets(FILE * fp) /* safefile: * Check to make sure it is okay to read in files. - * For normal uses, it is a no-op, and returns the input. * It returns NULL if the filename is trivial. * * If the application has set the SERVER_NAME environment variable, @@ -324,30 +323,67 @@ char *Fgets(FILE * fp) * If filename contains multiple components, the user is * warned, once, that everything to the left is ignored. * + * For non-server applications, we use the path list in Gvimagepath to + * resolve relative pathnames. + * * N.B. safefile uses a fixed buffer, so functions using it should use the * value immediately or make a copy. */ #ifdef WIN32 -#define DIRSEP "\\" #define PATHSEP ";" #else -#define DIRSEP "/" #define PATHSEP ":" #endif +static char** mkDirlist (const char* list, int* maxdirlen) +{ + int cnt = 0; + char* s = strdup (list); + char* dir; + char** dirs = NULL; + int maxlen = 0; + + for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) { + dirs = ALLOC (cnt+2,dirs,char*); + dirs[cnt++] = dir; + maxlen = MAX(maxlen, strlen (dir)); + } + dirs[cnt] = NULL; + *maxdirlen = maxlen; + return dirs; +} + +static char* findPath (char** dirs, int maxdirlen, const char* str) +{ + static char *safefilename = NULL; + char** dp; + + /* allocate a buffer that we are sure is big enough + * +1 for null character. + * +1 for directory separator character. + */ + safefilename = realloc(safefilename, (maxdirlen + strlen(str) + 2)); + + for (dp = dirs; *dp; dp++) { + sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str); + if (access (safefilename, R_OK) == 0) + return safefilename; + } + return NULL; +} + const char *safefile(const char *filename) { static boolean onetime = TRUE; - static boolean firsttime = TRUE; - static char *safefilename = NULL; + static char *pathlist = NULL; static int maxdirlen; static char** dirs; - char** dp; const char *str, *p; if (!filename || !filename[0]) return NULL; - if (HTTPServerEnVar) { + + if (HTTPServerEnVar) { /* If used as a server */ /* * If we are running in an http server we allow * files only from the directory specified in @@ -363,17 +399,9 @@ const char *safefile(const char *filename) } return NULL; } - if (firsttime) { - int cnt = 0; - char* s = strdup (Gvfilepath); - char* dir; - for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) { - dirs = ALLOC (cnt+2,dirs,char*); - dirs[cnt++] = dir; - maxdirlen = MAX(maxdirlen, strlen (dir)); - } - dirs[cnt] = NULL; - firsttime = FALSE; + if (!pathlist) { + dirs = mkDirlist (Gvfilepath, &maxdirlen); + pathlist = Gvfilepath; } str = filename; @@ -391,23 +419,24 @@ const char *safefile(const char *filename) onetime = FALSE; } - /* allocate a buffer that we are sure is big enough - * +1 for null character. - * +1 for directory separator character. - */ - safefilename = realloc(safefilename, - (maxdirlen + strlen(str) + 2)); + return findPath (dirs, maxdirlen, str); + } - for (dp = dirs; *dp; dp++) { - sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str); - if (access (safefilename, R_OK) == 0) - return safefilename; + if (pathlist != Gvimagepath) { + if (dirs) { + free (dirs[0]); + free (dirs); + dirs = NULL; } - return NULL; + pathlist = Gvimagepath; + if (pathlist && *pathlist) + dirs = mkDirlist (pathlist, &maxdirlen); } - /* else, not in server, use original filename without modification. */ - else + + if ((*filename == DIRSEP[0]) || !dirs) return filename; + + return findPath (dirs, maxdirlen, filename); } int maptoken(char *p, char **name, int *val) diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index b7dba03f4..4f112b6e6 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -19,13 +19,6 @@ #include #include -#ifdef WIN32 -#include "libltdl/lt_system.h" -#endif -#ifndef WIN32 -#include -#endif - #include "types.h" #include "logic.h" #include "memory.h" @@ -59,12 +52,6 @@ typedef struct { #define XML_MAGIC "