wmi-1.3.16 from opsview.com

This commit is contained in:
Are Casilla
2019-02-16 00:16:52 +01:00
parent 163fdd3d1b
commit 17b3af2911
2146 changed files with 678824 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+277
View File
@@ -0,0 +1,277 @@
/**
* @file esp.h
* @brief Header for Embedded Server Pages (ESP)
*/
/********************************* Copyright **********************************/
/*
* @copy default
*
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
*
* This software is distributed under commercial and open source licenses.
* You may use the GPL open source license described below or you may acquire
* a commercial license from Mbedthis Software. You agree to be fully bound
* by the terms of either license. Consult the LICENSE.TXT distributed with
* this software for full details.
*
* This software is open source; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See the GNU General Public License for more
* details at: http://www.mbedthis.com/downloads/gplLicense.html
*
* This program is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* This GPL license does NOT permit incorporating this software into
* proprietary programs. If you are unable to comply with the GPL, you must
* acquire a commercial license to use this software. Commercial licenses
* for this software and support services are available from Mbedthis
* Software at http://www.mbedthis.com
*
* @end
*/
/********************************** Includes **********************************/
#ifndef _h_ESP_h
#define _h_ESP_h 1
#include "lib/appweb/ejs/ejs.h"
#include "lib/appweb/esp/espEnv.h"
#include "lib/appweb/mpr/var.h"
#include "lib/appweb/mpr/miniMpr.h"
/*********************************** Defines **********************************/
#if BLD_FEATURE_SQUEEZE
#define ESP_TOK_INCR 1024
#define ESP_MAX_HEADER 1024
#else
#define ESP_TOK_INCR 4096
#define ESP_MAX_HEADER 4096
#endif
/*
* ESP lexical analyser tokens
*/
#define ESP_TOK_ERR -1 /* Any input error */
#define ESP_TOK_EOF 0 /* End of file */
#define ESP_TOK_START_ESP 1 /* <% */
#define ESP_TOK_END_ESP 2 /* %> */
#define ESP_TOK_ATAT 3 /* @@var */
#define ESP_TOK_LITERAL 4 /* literal HTML */
#define ESP_TOK_INCLUDE 5 /* include file.esp */
#define ESP_TOK_EQUALS 6 /* = var */
/*
* ESP parser states
*/
#define ESP_STATE_BEGIN 1 /* Starting state */
#define ESP_STATE_IN_ESP_TAG 2 /* Inside a <% %> group */
/*********************************** Types ************************************/
typedef void* EspHandle; /* Opaque Web server handle type */
/*
* Per request control block
*/
typedef struct EspRequest {
MprStr docPath; /* Physical path for ESP page */
EjsId eid; /* EJS instance handle */
const struct Esp *esp; /* Pointer to ESP control block */
EspHandle requestHandle; /* Per request web server handle */
MprStr uri; /* Request URI */
MprVar *variables; /* Pointer to variables */
} EspRequest;
/*
* Master ESP control block. This defines the function callbacks for a
* web server handler to implement. ESP will call these functions as
* required.
*/
typedef struct Esp {
int maxScriptSize;
void (*createSession)(EspHandle handle, int timeout);
void (*destroySession)(EspHandle handle);
const char *(*getSessionId)(EspHandle handle);
int (*mapToStorage)(EspHandle handle, char *path, int len, const char *uri,
int flags);
int (*readFile)(EspHandle handle, char **buf, int *len, const char *path);
void (*redirect)(EspHandle handle, int code, char *url);
void (*setCookie)(EspHandle handle, const char *name, const char *value,
int lifetime, const char *path, bool secure);
void (*setHeader)(EspHandle handle, const char *value, bool allowMultiple);
void (*setResponseCode)(EspHandle handle, int code);
int (*writeBlock)(EspHandle handle, const char *buf, int size);
int (*writeFmt)(EspHandle handle, char *fmt, ...);
#if BLD_FEATURE_MULTITHREAD
void (*lock)(void *lockData);
void (*unlock)(void *lockData);
void *lockData;
#endif
} Esp;
/*
* ESP parse context
*/
typedef struct {
char *inBuf; /* Input data to parse */
char *inp; /* Next character for input */
char *endp; /* End of storage (allow for null) */
char *tokp; /* Pointer to current parsed token */
char *token; /* Storage buffer for token */
int tokLen; /* Length of buffer */
} EspParse;
/******************************** Private APIs ********************************/
extern void espRegisterProcs(void);
/******************************** Published API *******************************/
#ifdef __cplusplus
extern "C" {
#endif
/*
* Function callback signatures
*/
typedef int (*EspCFunction)(EspRequest *ep, int argc,
struct MprVar **argv);
typedef int (*EspStringCFunction)(EspRequest *ep, int argc,
char **argv);
/*
* APIs for those hosting the ESP module
*/
extern int espOpen(const Esp *control);
extern void espClose(void);
extern EspRequest *espCreateRequest(EspHandle webServerRequestHandle,
char *uri, MprVar *envObj);
extern void espDestroyRequest(EspRequest *ep);
extern int espProcessRequest(EspRequest *ep, const char *docPath,
char *docBuf, char **errMsg);
/*
* Method invocation
*/
extern void espDefineCFunction(EspRequest *ep, const char *functionName,
EspCFunction fn, void *thisPtr);
extern void espDefineFunction(EspRequest *ep, const char *functionName,
char *args, char *body);
extern void espDefineStringCFunction(EspRequest *ep,
const char *functionName, EspStringCFunction fn,
void *thisPtr);
extern int espRunFunction(EspRequest *ep, MprVar *obj,
char *functionName, MprArray *args);
extern void espSetResponseCode(EspRequest *ep, int code);
extern void espSetReturn(EspRequest *ep, MprVar value);
extern void *espGetThisPtr(EspRequest *ep);
/*
* Utility routines to use in C methods
*/
extern void espError(EspRequest *ep, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
extern int espEvalFile(EspRequest *ep, char *path, MprVar *result,
char **emsg);
extern int espEvalScript(EspRequest *ep, char *script, MprVar *result,
char **emsg);
extern MprVar *espGetLocalObject(EspRequest *ep);
extern MprVar *espGetGlobalObject(EspRequest *ep);
extern EspHandle espGetRequestHandle(EspRequest *ep);
extern MprVar *espGetResult(EspRequest *ep);
extern EjsId espGetScriptHandle(EspRequest *ep);
extern void espRedirect(EspRequest *ep, int code, char *url);
extern void espSetHeader(EspRequest *ep, char *header,
bool allowMultiple);
extern void espSetReturnString(EspRequest *ep, const char *str);
extern int espWrite(EspRequest *ep, char *buf, int size);
extern int espWriteString(EspRequest *ep, char *buf);
extern int espWriteFmt(EspRequest *ep, char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
/*
* ESP array[] variable access (set will update/create)
*/
extern int espGetVar(EspRequest *ep, EspEnvType oType, char *var,
MprVar *value);
extern char *espGetStringVar(EspRequest *ep, EspEnvType oType,
char *var, char *defaultValue);
extern void espSetVar(EspRequest *ep, EspEnvType oType, char *var,
MprVar value);
extern void espSetStringVar(EspRequest *ep, EspEnvType oType,
const char *var, const char *value);
extern int espUnsetVar(EspRequest *ep, EspEnvType oType, char *var);
/*
* Object creation and management
*/
extern MprVar espCreateObjVar(char *name, int hashSize);
extern MprVar espCreateArrayVar(char *name, int size);
extern bool espDestroyVar(MprVar *var);
extern MprVar *espCreateProperty(MprVar *obj, char *property,
MprVar *newValue);
extern MprVar *espCreatePropertyValue(MprVar *obj, char *property,
MprVar newValue);
extern int espDeleteProperty(MprVar *obj, char *property);
/*
* JavaScript variable management. Set will create/update a property.
* All return a property reference. GetProperty will optionally return the
* property in value.
*/
extern MprVar *espGetProperty(MprVar *obj, char *property,
MprVar *value);
extern MprVar *espSetProperty(MprVar *obj, char *property,
MprVar *newValue);
extern MprVar *espSetPropertyValue(MprVar *obj, char *property,
MprVar newValue);
#if 0
/*
* Low-level direct read and write of properties.
* FUTURE: -- Read is not (dest, src). MUST WARN IN DOC ABOUT COPY/READ
* Will still cause triggers to run.
*/
extern int espReadProperty(MprVar *dest, MprVar *prop);
extern int espWriteProperty(MprVar *prop, MprVar *newValue);
extern int espWritePropertyValue(MprVar *prop, MprVar newValue);
#endif
/*
* Access JavaScript variables by their full name. Can use "." or "[]". For
* example: "global.request['REQUEST_URI']"
* For Read/write, the variables must exist.
*/
extern int espCopyVar(EspRequest *ep, char *var, MprVar *value,
int copyDepth);
extern int espDeleteVar(EspRequest *ep, char *var);
extern int espReadVar(EspRequest *ep, char *var, MprVar *value);
extern int espWriteVar(EspRequest *ep, char *var, MprVar *value);
extern int espWriteVarValue(EspRequest *ep, char *var, MprVar value);
/*
* Object property enumeration
*/
extern MprVar *espGetFirstProperty(MprVar *obj, int includeFlags);
extern MprVar *espGetNextProperty(MprVar *obj, MprVar *currentProperty,
int includeFlags);
extern int espGetPropertyCount(MprVar *obj, int includeFlags);
#ifdef __cplusplus
}
#endif
/******************************************************************************/
#endif /* _h_ESP_h */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim:tw=78
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
+128
View File
@@ -0,0 +1,128 @@
/*
* @file espEnv.h
* @brief ESP Environment Variables
*/
/********************************* Copyright **********************************/
/*
* @copy default
*
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
*
* This software is distributed under commercial and open source licenses.
* You may use the GPL open source license described below or you may acquire
* a commercial license from Mbedthis Software. You agree to be fully bound
* by the terms of either license. Consult the LICENSE.TXT distributed with
* this software for full details.
*
* This software is open source; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See the GNU General Public License for more
* details at: http://www.mbedthis.com/downloads/gplLicense.html
*
* This program is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* This GPL license does NOT permit incorporating this software into
* proprietary programs. If you are unable to comply with the GPL, you must
* acquire a commercial license to use this software. Commercial licenses
* for this software and support services are available from Mbedthis
* Software at http://www.mbedthis.com
*
* @end
*/
/******************************************************************************/
#ifndef _h_ESP_ENV_h
#define _h_ESP_ENV_h 1
/*
* @brief Scripting environment variable array types
*/
typedef enum EspEnvType {
ESP_UNDEFINED_OBJ = -1,
/**
* Elements for server[]:
* DOCUMENT_ROOT GATEWAY_INTERFACE SERVER_ADDR SERVER_PORT SERVER_NAME
* SERVER_PROTOCOL SERVER_SOFTWARE SERVER_URL UPLOAD_DIR
* FUTURE: SERVER_ADMIN
* FUTURE: this could be shared across all hosts and be made read-only.
*/
ESP_SERVER_OBJ = 0, /*! server[] data */
/**
* Elements for session[]: are user defined
*/
ESP_SESSION_OBJ = 1, /*! session[] data */
/**
* Elements for request[]:
* AUTH_TYPE CONTENT_LENGTH CONTENT_TYPE QUERY_STRING PATH_INFO
* PATH_TRANSLATED REMOTE_ADDR REMOTE_HOST REMOTE_USER REQUEST_METHOD
* REQUEST_URI SCRIPT_FILENAME SCRIPT_NAME
* FUTURE: FILEPATH_INFO REDIRECT_URL SELF REMOTE_PORT AUTH_USER
* AUTH_GROUP AUTH_ACL
*/
ESP_REQUEST_OBJ = 2, /*! request[] data */
/**
* Elements for headers[]:
* HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_CONNECTION HTTP_HOST
* HTTP_REFERER HTTP_USER_AGENT and any other custom headers
*/
ESP_HEADERS_OBJ = 3, /*! header [] data */
/**
* Elements for cookies[]: are defined by the HTTP request
*/
ESP_COOKIES_OBJ = 4, /*! cookies[] data */
/**
* Elements for files[]: are defined by the HTTP request
* CLIENT_FILENAME CONTENT_TYPE FILENAME SIZE
*/
ESP_FILES_OBJ = 5, /*! files[] data */
/**
* Elements for form[]: are defined by the HTTP request
*/
ESP_FORM_OBJ = 6, /*! form[] data */
/**
* Elements for application[]: are user defined
*/
ESP_APPLICATION_OBJ = 7, /*! application[] data */
/**
* Elements for global[]: are defined by ESP/EJS
*/
ESP_GLOBAL_OBJ = 8, /*! global [] data */
/*
* Elements for local[]: are defined by ESP/EJS
*/
ESP_LOCAL_OBJ = 9, /*! local [] data */
} EspEnvType;
#define ESP_OBJ_MAX 10 /* Total objects */
#if BLD_SQUEEZE
#define ESP_HASH_SIZE 19 /* Size of hash tables */
#else
#define ESP_HASH_SIZE 37
#endif
/******************************************************************************/
#endif /* _h_ESP_ENV_h */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim:tw=78
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
+249
View File
@@ -0,0 +1,249 @@
/*
* @file espProcs.c
* @brief Embedded Server Pages (ESP) Procedures.
* @overview These ESP procedures can be used in ESP pages for common tasks.
*/
/********************************* Copyright **********************************/
/*
* @copy default
*
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
*
* This software is distributed under commercial and open source licenses.
* You may use the GPL open source license described below or you may acquire
* a commercial license from Mbedthis Software. You agree to be fully bound
* by the terms of either license. Consult the LICENSE.TXT distributed with
* this software for full details.
*
* This software is open source; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See the GNU General Public License for more
* details at: http://www.mbedthis.com/downloads/gplLicense.html
*
* This program is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* This GPL license does NOT permit incorporating this software into
* proprietary programs. If you are unable to comply with the GPL, you must
* acquire a commercial license to use this software. Commercial licenses
* for this software and support services are available from Mbedthis
* Software at http://www.mbedthis.com
*
* @end
*/
/********************************** Includes **********************************/
#include "esp.h"
/************************************ Code ************************************/
#if BLD_FEATURE_ESP_MODULE
#if BLD_FEATURE_SESSION
/*
* destroySession
*/
static int destroySessionProc(EspRequest *ep, int argc, char **argv)
{
ep->esp->destroySession(ep->requestHandle);
return 0;
}
#endif /* BLD_FEATURE_SESSION */
/******************************************************************************/
/*
* include
*
* This includes javascript libraries. For example:
*
* <% include("file", ...); %>
*
* Don't confuse with ESP includes:
*
* <% include file.esp %>
*
* Filenames are relative to the base document including the file.
* FUTURE -- move back to EJS. Only here now because we need ep->readFile.
*/
static int includeProc(EspRequest *ep, int argc, char **argv)
{
const Esp *esp;
char path[MPR_MAX_FNAME], dir[MPR_MAX_FNAME];
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]);
} else {
mprSprintf(path, sizeof(path), "%s", argv[i]);
}
if (esp->readFile(ep->requestHandle, &buf, &size, path) < 0) {
espError(ep, "Can't read include file: %s", path);
return MPR_ERR_CANT_ACCESS;
}
buf[size] = '\0';
extension = strrchr(argv[i], '.');
/*
* Allow nested inclusion of ESP requests
*/
if (extension && mprStrCmpAnyCase(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);
}
return 0;
}
/******************************************************************************/
/*
* redirect
*
* This implemements <% redirect(url, code); %> command. The redirection
* code is optional.
*/
static int redirectProc(EspRequest *ep, int argc, char **argv)
{
char *url;
int code;
if (argc < 1) {
espError(ep, "Bad args");
return MPR_ERR_BAD_ARGS;
}
url = argv[0];
if (argc == 2) {
code = atoi(argv[1]);
} else {
code = 302;
}
espRedirect(ep, code, url);
return 0;
}
/******************************************************************************/
#if BLD_FEATURE_SESSION
/*
* useSession
*/
static int useSessionProc(EspRequest *ep, int argc, char **argv)
{
int timeout;
if (argc > 1) {
espError(ep, "Bad args");
return MPR_ERR_BAD_ARGS;
} else if (argc == 1) {
timeout = atoi(argv[0]);
} else {
timeout = 0;
}
ep->esp->createSession(ep->requestHandle, timeout);
espSetReturnString(ep, ep->esp->getSessionId(ep->requestHandle));
return 0;
}
#endif /* BLD_FEATURE_SESSION */
/******************************************************************************/
/*
* setHeader
*
* This implemements <% setHeader("key: value", allowMultiple); %> command.
*/
static int setHeaderProc(EspRequest *ep, int argc, char **argv)
{
mprAssert(argv);
if (argc != 2) {
espError(ep, "Bad args");
return MPR_ERR_BAD_ARGS;
}
ep->esp->setHeader(ep->requestHandle, argv[0], atoi(argv[1]));
return 0;
}
/******************************************************************************/
/*
* write
*
* This implemements <% write("text"); %> command.
*/
static int writeProc(EspRequest *ep, int argc, char **argv)
{
char *s;
int i, len;
mprAssert(argv);
for (i = 0; i < argc; i++) {
s = argv[i];
len = strlen(s);
if (len > 0) {
if (espWrite(ep, s, len) != len) {
espError(ep, "Can't write to client");
return -1;
}
}
}
return 0;
}
/******************************************************************************/
void espRegisterProcs()
{
espDefineStringCFunction(0, "write", writeProc, 0);
espDefineStringCFunction(0, "setHeader", setHeaderProc, 0);
espDefineStringCFunction(0, "redirect", redirectProc, 0);
espDefineStringCFunction(0, "include", includeProc, 0);
#if BLD_FEATURE_SESSION
/*
* Create and use are synonomous
*/
espDefineStringCFunction(0, "useSession", useSessionProc, 0);
espDefineStringCFunction(0, "createSession", useSessionProc, 0);
espDefineStringCFunction(0, "destroySession", destroySessionProc, 0);
#endif
}
/******************************************************************************/
#else
void mprEspControlsDummy() {}
#endif /* BLD_FEATURE_ESP_MODULE */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim:tw=78
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/