60aa93a4089175374d92d52c397888e74300f98a
[samba.git] / source / web_server / ejs / ejs.h
1 /*
2  *      @file   ejs.h
3  *      @brief  Primary Embedded Javascript (ECMAScript) header.
4  *      @overview This Embedded Javascript (EJS) header defines the 
5  *              public API. This API should only be used by those directly 
6  *              using EJS without using Embedded Server Pages (ESP). ESP 
7  *              wraps all relevant APIs to expose a single consistent API.
8  *              \n\n
9  *              This API requires the mpr/var.h facilities to create and 
10  *              manage objects and properties. 
11  */
12 /********************************* Copyright **********************************/
13 /*
14  *      @copy   default.g
15  *      
16  *      Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
17  *      Portions Copyright (c) GoAhead Software, 1995-2000. All Rights Reserved.
18  *      
19  *      This software is distributed under commercial and open source licenses.
20  *      You may use the GPL open source license described below or you may acquire 
21  *      a commercial license from Mbedthis Software. You agree to be fully bound 
22  *      by the terms of either license. Consult the LICENSE.TXT distributed with 
23  *      this software for full details.
24  *      
25  *      This software is open source; you can redistribute it and/or modify it 
26  *      under the terms of the GNU General Public License as published by the 
27  *      Free Software Foundation; either version 2 of the License, or (at your 
28  *      option) any later version. See the GNU General Public License for more 
29  *      details at: http://www.mbedthis.com/downloads/gplLicense.html
30  *      
31  *      This program is distributed WITHOUT ANY WARRANTY; without even the 
32  *      implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
33  *      
34  *      This GPL license does NOT permit incorporating this software into 
35  *      proprietary programs. If you are unable to comply with the GPL, you must
36  *      acquire a commercial license to use this software. Commercial licenses 
37  *      for this software and support services are available from Mbedthis 
38  *      Software at http://www.mbedthis.com 
39  *      
40  *      @end
41  */
42 /********************************** Includes **********************************/
43
44 #ifndef _h_EJS
45 #define _h_EJS 1
46
47 #include        "web_server/ejs/miniMpr.h"
48 #include        "web_server/ejs/var.h"
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 /********************************* Prototypes *********************************/
55
56 typedef MprVarHandle    EjsId;
57 typedef MprVarHandle    EjsHandle;
58
59 /*
60  *      Multithreaded lock routines
61  */
62 typedef void (*EjsLock)(void *lockData);
63 typedef void (*EjsUnlock)(void *lockData);
64
65 /********************************* Prototypes *********************************/
66 /*
67  *      Module management
68  */
69 extern int              ejsOpen(EjsLock lock, EjsUnlock unlock, void *lockData);
70 extern void     ejsClose(void);
71 extern EjsId    ejsOpenEngine(EjsHandle primaryHandle, EjsHandle altHandle);
72 extern void             ejsCloseEngine(EjsId eid);
73
74 /*
75  *      Evaluation functions
76  */
77 extern int              ejsEvalFile(EjsId eid, char *path, MprVar *result, char **emsg);
78 extern int              ejsEvalScript(EjsId eid, char *script, MprVar *result, 
79                                         char **emsg);
80 extern int              ejsRunFunction(int eid, MprVar *obj, const char *functionName, 
81                                         MprArray *args);
82
83 /*
84  *      Composite variable get / set routines. Can also use the MPR property
85  *      routines on an object variable.
86  */
87 extern MprVar   ejsCreateObj(const char *name, int hashSize);
88 extern MprVar   ejsCreateArray(const char *name, int hashSize);
89 extern bool             ejsDestroyVar(MprVar *obj);
90 extern int              ejsCopyVar(EjsId eid, const char *var, MprVar *value, bool copyRef);
91 extern int              ejsReadVar(EjsId eid, const char *var, MprVar *value);
92 extern int              ejsWriteVar(EjsId eid, const char *var, MprVar *value);
93 extern int              ejsWriteVarValue(EjsId eid, const char *var, MprVar value);
94 extern int              ejsDeleteVar(EjsId eid, const char *var);
95
96 extern MprVar   *ejsGetLocalObject(EjsId eid);
97 extern MprVar   *ejsGetGlobalObject(EjsId eid);
98
99 /*
100  *      Function routines
101  */
102 extern void     ejsDefineFunction(EjsId eid, const char *functionName, char *args, 
103                                         char *body);
104 extern void     ejsDefineCFunction(EjsId eid, const char *functionName, 
105                                         MprCFunction fn, void *thisPtr, int flags);
106 extern void             ejsDefineStringCFunction(EjsId eid, const char *functionName, 
107                                         MprStringCFunction fn, void *thisPtr, int flags);
108 extern void     *ejsGetThisPtr(EjsId eid);
109 extern MprVar   *ejsGetReturnValue(EjsId eid);
110 extern int              ejsGetLineNumber(EjsId eid);
111 extern int              ejsParseArgs(int argc, char **argv, char *fmt, ...);
112 extern void     ejsSetErrorMsg(EjsId eid, const char* fmt, ...);
113 extern void             ejsSetReturnValue(EjsId eid, MprVar value);
114 extern void             ejsSetReturnString(EjsId eid, const char *str);
115
116 #ifdef __cplusplus
117 }
118 #endif
119 #endif /* _h_EJS */
120
121 /*****************************************************************************/
122
123 /*
124  * Local variables:
125  * tab-width: 4
126  * c-basic-offset: 4
127  * End:
128  * vim:tw=78
129  * vim600: sw=4 ts=4 fdm=marker
130  * vim<600: sw=4 ts=4
131  */