tReadd arguments after realpath after latest printelem() changes. - geomyidae - A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
 (HTM) git clone git://r-36.net/geomyidae
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 3401df4e6802a68dd34581ae0de6b7e34f45ea12
 (DIR) parent 6f22091df20685c8b7a8a89823aa31606bea2be0
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Mon,  5 Apr 2021 22:05:11 +0200
       
       Readd arguments after realpath after latest printelem() changes.
       
       Diffstat:
         ind.c                               |      15 +++++++++++++--
       
       1 file changed, 13 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/ind.c b/ind.c
       t@@ -403,7 +403,7 @@ scanfile(char *fname)
        int
        printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port)
        {
       -        char *path, *p, *argbase, buf[PATH_MAX+1];
       +        char *path, *p, *argbase, buf[PATH_MAX+1], *argp;
                int len, blen;
        
                if (!strcmp(el->e[3], "server")) {
       t@@ -439,6 +439,7 @@ printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port)
                        else
                                len = strlen(path);
        
       +                /* Strip off arguments for realpath. */
                        argbase = strchr(el->e[2], '?');
                        if (argbase != NULL)
                                blen = argbase - el->e[2];
       t@@ -451,8 +452,18 @@ printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port)
                        if ((path = realpath(buf, NULL)) &&
                                        !strncmp(base, path, strlen(base))) {
                                p = path + strlen(base);
       +
       +                        /*
       +                         * Do not forget to readd arguments which were
       +                         * stripped off.
       +                         */
       +                        if (argbase != NULL)
       +                                argp = smprintf("%s%s", p[0]? p : "/", argbase);
       +                        else
       +                                argp = xstrdup(p[0]? p : "/");
       +
                                free(el->e[2]);
       -                        el->e[2] = xstrdup(p[0]? p : "/");
       +                        el->e[2] = argp;
                        }
                        free(path);
                }