r7086: make include() recognise the ".esp" extension and include the file as
authorAndrew Tridgell <tridge@samba.org>
Mon, 30 May 2005 06:07:23 +0000 (06:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:14 +0000 (13:17 -0500)
an esp script instead of as a ejs script

source/web_server/esp/espProcs.c

index ff1751a7ef0fa1cc9490d094512a4289571483d4..28b69a8a6f1484634279ffc3f8a78f4a02252084 100644 (file)
@@ -71,12 +71,14 @@ static int includeProc(EspRequest *ep, int argc, char **argv)
 {
        const Esp               *esp;
        char    path[MPR_MAX_FNAME], dir[MPR_MAX_FNAME];
-       char    *emsg, *buf;
+       char    *emsg=NULL, *buf;
        int             size, i;
 
        esp = ep->esp;
        mprAssert(argv);
        for (i = 0; i < argc; i++) {
+               const char *extension;
+
                if (argv[i][0] != '/') {
                        mprGetDirName(dir, sizeof(dir), ep->docPath);
                        mprSprintf(path, sizeof(path), "%s/%s", dir, argv[i]);
@@ -90,10 +92,20 @@ static int includeProc(EspRequest *ep, int argc, char **argv)
                }
                buf[size] = '\0';
 
-               if (ejsEvalScript(espGetScriptHandle(ep), buf, 0, &emsg) < 0) {
-                       espError(ep, "Cant evaluate script");
-                       mprFree(buf);
-                       return -1;
+               extension = strrchr(argv[i], '.');
+               /* this makes handling include files in esp scripts much more convenient */
+               if (extension && strcasecmp(extension, ".esp") == 0) {
+                       if (espProcessRequest(ep, path, buf, &emsg) != 0) {
+                               espError(ep, "Cant evaluate script - %s", emsg?emsg:"");
+                               mprFree(buf);
+                               return -1;
+                       }
+               } else {
+                       if (ejsEvalScript(espGetScriptHandle(ep), buf, 0, &emsg) < 0) {
+                               espError(ep, "Cant evaluate script - %s", emsg?emsg:"");
+                               mprFree(buf);
+                               return -1;
+                       }
                }
                mprFree(buf);
        }