summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/appweb/ejs/ejs.h3
-rw-r--r--source4/lib/appweb/ejs/ejsLib.c27
-rw-r--r--source4/web_server/http.c6
3 files changed, 36 insertions, 0 deletions
diff --git a/source4/lib/appweb/ejs/ejs.h b/source4/lib/appweb/ejs/ejs.h
index 5efdb47192..c7b0c54d8e 100644
--- a/source4/lib/appweb/ejs/ejs.h
+++ b/source4/lib/appweb/ejs/ejs.h
@@ -71,6 +71,9 @@ extern void ejsClose(void);
extern EjsId ejsOpenEngine(EjsHandle primaryHandle, EjsHandle altHandle);
extern void ejsCloseEngine(EjsId eid);
+void *ejs_save_state(void);
+void ejs_restore_state(void *ptr);
+
/*
* Evaluation functions
*/
diff --git a/source4/lib/appweb/ejs/ejsLib.c b/source4/lib/appweb/ejs/ejsLib.c
index b24b2b013c..f6c004592b 100644
--- a/source4/lib/appweb/ejs/ejsLib.c
+++ b/source4/lib/appweb/ejs/ejsLib.c
@@ -58,6 +58,33 @@ static void *lockData;
#define ejsUnlock()
#endif
+
+/*
+ save/restore global ejs state - used to cope with simultaneous ejs requests
+ this is a workaround for the use of global variables in ejs
+*/
+struct ejs_state_ctx {
+ struct MprVar master;
+ struct MprArray *ejsList;
+};
+
+void *ejs_save_state(void)
+{
+ struct ejs_state_ctx *ctx = talloc(talloc_autofree_context(), struct ejs_state_ctx);
+ ctx->master = master;
+ ctx->ejsList = ejsList;
+ return ctx;
+}
+
+void ejs_restore_state(void *ptr)
+{
+ struct ejs_state_ctx *ctx = talloc_get_type(ptr, struct ejs_state_ctx);
+ master = ctx->master;
+ ejsList = ctx->ejsList;
+ talloc_free(ctx);
+}
+
+
/****************************** Forward Declarations **************************/
static char *getNextVarToken(char **next, char *tokBuf, int tokBufLen);
diff --git a/source4/web_server/http.c b/source4/web_server/http.c
index 61e6277800..7bb45afc1e 100644
--- a/source4/web_server/http.c
+++ b/source4/web_server/http.c
@@ -752,6 +752,7 @@ void http_process_input(struct websrv_context *web)
struct esp_data *edata = talloc_get_type(web->task->private, struct esp_data);
char *p;
void *save_mpr_ctx = mprMemCtx();
+ void *ejs_save = ejs_save_state();
int i;
const char *file_type = NULL;
BOOL esp_enable = False;
@@ -802,6 +803,7 @@ void http_process_input(struct websrv_context *web)
if (web->input.url == NULL) {
http_error(web, 400, "You must specify a GET or POST request");
mprSetCtx(save_mpr_ctx);
+ ejs_restore_state(ejs_save);
return;
}
@@ -811,6 +813,7 @@ void http_process_input(struct websrv_context *web)
if (!NT_STATUS_IS_OK(status)) {
http_error(web, 400, "Malformed POST data");
mprSetCtx(save_mpr_ctx);
+ ejs_restore_state(ejs_save);
return;
}
}
@@ -819,6 +822,7 @@ void http_process_input(struct websrv_context *web)
if (!NT_STATUS_IS_OK(status)) {
http_error(web, 400, "Malformed GET data");
mprSetCtx(save_mpr_ctx);
+ ejs_restore_state(ejs_save);
return;
}
}
@@ -899,6 +903,7 @@ void http_process_input(struct websrv_context *web)
talloc_free(esp);
mprSetCtx(save_mpr_ctx);
+ ejs_restore_state(ejs_save);
return;
internal_error:
@@ -906,6 +911,7 @@ internal_error:
talloc_free(esp);
http_error(web, 500, "Internal server error");
mprSetCtx(save_mpr_ctx);
+ ejs_restore_state(ejs_save);
}