本文整理汇总了C++中ejsToMulti函数的典型用法代码示例。如果您正苦于以下问题:C++ ejsToMulti函数的具体用法?C++ ejsToMulti怎么用?C++ ejsToMulti使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ejsToMulti函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: secure
/*
function secure(keyFile: Path, certFile: Path!, protocols: Array? = null, ciphers: Array? = null): Void
*/
static EjsObj *hs_secure(Ejs *ejs, EjsHttpServer *sp, int argc, EjsObj **argv)
{
#if BIT_PACK_SSL
EjsArray *protocols;
cchar *token;
int mask, protoMask, i;
if (sp->ssl == 0 && ((sp->ssl = mprCreateSsl(1)) == 0)) {
return 0;
}
if (!ejsIs(ejs, argv[0], Null)) {
mprSetSslKeyFile(sp->ssl, ejsToMulti(ejs, argv[0]));
}
if (!ejsIs(ejs, argv[1], Null)) {
mprSetSslCertFile(sp->ssl, ejsToMulti(ejs, argv[1]));
}
if (argc >= 3 && ejsIs(ejs, argv[2], Array)) {
protocols = (EjsArray*) argv[2];
protoMask = 0;
for (i = 0; i < protocols->length; i++) {
token = ejsToMulti(ejs, ejsGetProperty(ejs, protocols, i));
mask = -1;
if (*token == '-') {
token++;
mask = 0;
} else if (*token == '+') {
token++;
}
if (scaselesscmp(token, "SSLv2") == 0) {
protoMask &= ~(MPR_PROTO_SSLV2 & ~mask);
protoMask |= (MPR_PROTO_SSLV2 & mask);
} else if (scaselesscmp(token, "SSLv3") == 0) {
protoMask &= ~(MPR_PROTO_SSLV3 & ~mask);
protoMask |= (MPR_PROTO_SSLV3 & mask);
} else if (scaselesscmp(token, "TLSv1") == 0) {
protoMask &= ~(MPR_PROTO_TLSV1 & ~mask);
protoMask |= (MPR_PROTO_TLSV1 & mask);
} else if (scaselesscmp(token, "ALL") == 0) {
protoMask &= ~(MPR_PROTO_ALL & ~mask);
protoMask |= (MPR_PROTO_ALL & mask);
}
}
mprSetSslProtocols(sp->ssl, protoMask);
}
if (argc >= 4 && ejsIs(ejs, argv[3], Array)) {
mprSetSslCiphers(sp->ssl, ejsToMulti(ejs, argv[3]));
}
#else
ejsThrowReferenceError(ejs, "SSL support was not included in the build");
#endif
return 0;
}
示例2: setCredentials
/*
function setCredentials(username: String?, password: String?, authType: String?): Void
*/
static EjsObj *http_setCredentials(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
cchar *authType, *password, *user;
user = (argc <= 0) ? 0 : ejsToMulti(ejs, argv[0]);
password = (argc <= 1) ? 0 : ejsToMulti(ejs, argv[1]);
authType = (argc <= 2) ? 0 : ejsToMulti(ejs, argv[2]);
if (ejsIs(ejs, argv[0], Null)) {
httpResetCredentials(hp->conn);
} else {
httpSetCredentials(hp->conn, user, password, authType);
}
return 0;
}
示例3: method
/*
function set method(value: String): Void
*/
static EjsObj *http_set_method(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
cchar *method;
method = ejsToMulti(ejs, argv[0]);
if (strcmp(method, "DELETE") != 0 && strcmp(method, "GET") != 0 && strcmp(method, "HEAD") != 0 &&
strcmp(method, "OPTIONS") != 0 && strcmp(method, "POST") != 0 && strcmp(method, "PUT") != 0 &&
strcmp(method, "TRACE") != 0) {
ejsThrowArgError(ejs, "Unknown HTTP method");
return 0;
}
hp->method = ejsToMulti(ejs, argv[0]);
return 0;
}
示例4: component
/*
Encode a Uri component (ECMA Standard)
static function encodeComponent(str: String): String
*/
static EjsObj *encodeURIComponent(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv)
{
char *encoded;
encoded = mprUriEncode(ejsToMulti(ejs, argv[0]), MPR_ENCODE_JS_URI_COMPONENT);
return (EjsObj*) ejsCreateStringFromAsc(ejs, encoded);
}
示例5: exit
/*
Exit the application
static function exit(status: Number, how: String = "default"): void
MOB - status is not implemented
*/
static EjsObj *app_exit(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv)
{
cchar *how;
int status, mode;
if (ejs->dontExit) {
ejsThrowStateError(ejs, "App.exit has been disabled");
return 0;
}
status = argc >= 1 ? ejsGetInt(ejs, argv[0]) : 0;
how = ejsToMulti(ejs, argc >= 2 ? ejsToString(ejs, argv[1]): ESV(empty));
if (scmp(how, "default") == 0) {
mode = MPR_EXIT_DEFAULT;
} else if (scmp(how, "immediate") == 0) {
mode = MPR_EXIT_IMMEDIATE;
} else if (scmp(how, "graceful") == 0) {
mode = MPR_EXIT_GRACEFUL;
} else {
mode = MPR_EXIT_NORMAL;
}
mprTerminate(mode, status);
ejsAttention(ejs);
return 0;
}
示例6: chdir
/*
Set the current working directory
function chdir(value: String|Path): void
*/
static EjsObj *app_chdir(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv)
{
cchar *path;
assert(argc == 1);
if (ejsIs(ejs, argv[0], Path)) {
path = ((EjsPath*) argv[0])->value;
} else if (ejsIs(ejs, argv[0], String)) {
path = ejsToMulti(ejs, argv[0]);
} else {
ejsThrowIOError(ejs, "Bad path");
return NULL;
}
#if WINDOWS
{
MprFileSystem *fs;
fs = mprLookupFileSystem(path);
if (!mprPathExists(path, X_OK) && *path == '/') {
path = sjoin(fs->cygwin, path, NULL);
}
}
#endif
if (chdir((char*) path) < 0) {
ejsThrowIOError(ejs, "Cannot change the current directory");
}
return 0;
}
示例7: assert
static EjsObj *loadXml(Ejs *ejs, EjsXML *xml, int argc, EjsObj **argv)
{
MprFile *file;
MprXml *xp;
cchar *filename;
assert(argc == 1 && ejsIs(ejs, argv[0], String));
filename = ejsToMulti(ejs, argv[0]);
file = mprOpenFile(filename, O_RDONLY, 0664);
if (file == 0) {
ejsThrowIOError(ejs, "Cannot open: %s", filename);
return 0;
}
// TODO - convert to open/close
xp = ejsCreateXmlParser(ejs, xml, filename);
if (xp == 0) {
ejsThrowMemoryError(ejs);
mprCloseFile(file);
return 0;
}
mprXmlSetInputStream(xp, readFileData, (void*) file);
if (mprXmlParse(xp) < 0 && !ejsHasException(ejs)) {
ejsThrowIOError(ejs, "Cannot parse XML file: %s\nDetails %s", filename, mprXmlGetErrorMsg(xp));
}
mprCloseFile(file);
return 0;
}
示例8: createSearch
/*
Get a default search path. NOTE: this does not modify ejs->search.
function get createSearch(searchPaths: String): Array
*/
static EjsArray *app_createSearch(Ejs *ejs, EjsObj *app, int argc, EjsObj **argv)
{
cchar *searchPath;
searchPath = (argc == 0) ? NULL : ejsToMulti(ejs, argv[0]);
return ejsCreateSearchPath(ejs, searchPath);
}
示例9: postMessage
/*
Post a message to this worker. Note: the worker is the destination worker which may be the parent.
function postMessage(data: Object, ports: Array = null): Void
*/
static EjsObj *workerPostMessage(Ejs *ejs, EjsWorker *worker, int argc, EjsObj **argv)
{
EjsString *data;
EjsWorker *target;
MprDispatcher *dispatcher;
Message *msg;
if (worker->state >= EJS_WORKER_CLOSED) {
ejsThrowStateError(ejs, "Worker has completed");
return 0;
}
/*
Create the event with serialized data in the originating interpreter. It owns the data.
*/
ejsBlockGC(ejs);
if ((data = ejsToJSON(ejs, argv[0], NULL)) == 0) {
ejsThrowArgError(ejs, "Cannot serialize message data");
return 0;
}
if ((msg = createMessage()) == 0) {
ejsThrowMemoryError(ejs);
return 0;
}
target = worker->pair;
msg->data = ejsToMulti(ejs, data);
msg->worker = target;
msg->callback = "onmessage";
msg->callbackSlot = ES_Worker_onmessage;
dispatcher = target->ejs->dispatcher;
mprCreateEvent(dispatcher, "postMessage", 0, doMessage, msg, 0);
return 0;
}
示例10: send
/*
function send(...content): Number
*/
static EjsNumber *ws_send(Ejs *ejs, EjsWebSocket *ws, int argc, EjsObj **argv)
{
EjsArray *args;
EjsByteArray *ba;
EjsAny *arg;
ssize nbytes;
int i;
args = (EjsArray*) argv[0];
if (ws->conn->state < HTTP_STATE_PARSED && !waitForHttpState(ws, HTTP_STATE_PARSED, -1, 1)) {
return ESV(null);
}
nbytes = 0;
for (i = 0; i < args->length; i++) {
if ((arg = ejsGetProperty(ejs, args, i)) != 0) {
if (ejsIs(ejs, arg, ByteArray)) {
ba = (EjsByteArray*) arg;
nbytes = ejsGetByteArrayAvailableData(ba);
nbytes = httpSendBlock(ws->conn, WS_MSG_BINARY, (cchar*) &ba->value[ba->readPosition], nbytes, HTTP_BLOCK);
} else {
nbytes = httpSend(ws->conn, ejsToMulti(ejs, arg));
}
if (nbytes < 0) {
return ESV(null);
}
}
}
return ejsCreateNumber(ejs, (MprNumber) nbytes);
}
示例11: File
/*
Constructor
function File(path: Object, options: Object = null)
*/
static EjsFile *fileConstructor(Ejs *ejs, EjsFile *fp, int argc, EjsObj **argv)
{
EjsObj *pp, *options;
cchar *path;
if (argc < 1 || argc > 2) {
ejsThrowArgError(ejs, "Bad args");
return 0;
}
pp = argv[0];
if (ejsIs(ejs, pp, Path)) {
path = ((EjsPath*) pp)->value;
} else if (ejsIs(ejs, pp, String)) {
path = ejsToMulti(ejs, pp);
} else {
ejsThrowIOError(ejs, "Bad path");
return 0;
}
fp->path = mprNormalizePath(path);
if (argc == 2) {
options = (argc >= 2) ? argv[1] : 0;
openFile(ejs, fp, 1, &options);
}
return fp;
}
示例12: memset
EjsString *ejsSerializeWithOptions(Ejs *ejs, EjsAny *vp, EjsObj *options)
{
Json json;
EjsObj *arg;
EjsString *result;
int i;
memset(&json, 0, sizeof(Json));
json.depth = 99;
json.quotes = 1;
json.indent = sclone(" ");
if (options) {
json.options = options;
if ((arg = ejsGetPropertyByName(ejs, options, EN("baseClasses"))) != 0) {
json.baseClasses = (arg == ESV(true));
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("depth"))) != 0) {
json.depth = ejsGetInt(ejs, arg);
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("indent"))) != 0) {
if (ejsIs(ejs, arg, String)) {
json.indent = (char*) ejsToMulti(ejs, arg);
// TODO - get another solution to hold
} else if (ejsIs(ejs, arg, Number)) {
i = ejsGetInt(ejs, arg);
if (0 <= i && i < MPR_MAX_STRING) {
json.indent = mprAlloc(i + 1);
// TODO - get another solution to hold
memset(json.indent, ' ', i);
json.indent[i] = '\0';
}
}
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("commas"))) != 0) {
json.commas = (arg == ESV(true));
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("hidden"))) != 0) {
json.hidden = (arg == ESV(true));
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("namespaces"))) != 0) {
json.namespaces = (arg == ESV(true));
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("quotes"))) != 0) {
json.quotes = (arg != ESV(false));
}
if ((arg = ejsGetPropertyByName(ejs, options, EN("pretty"))) != 0) {
json.pretty = (arg == ESV(true));
}
json.replacer = ejsGetPropertyByName(ejs, options, EN("replacer"));
if (!ejsIsFunction(ejs, json.replacer)) {
json.replacer = NULL;
}
}
mprRelease(json.indent);
mprHold(json.indent);
result = serialize(ejs, vp, &json);
// TODO - get another solution to hold
return result;
}
示例13: form
/*
function form(uri: String = null, formData: Object = null): Http
Issue a POST method with form data
*/
static EjsHttp *http_form(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
EjsObj *data;
if (argc == 2 && !ejsIs(ejs, argv[1], Null)) {
/*
Prep here to reset the state. The ensures the current headers will be preserved.
Users may have called setHeader to define custom headers. Users must call reset if they want to clear
prior headers.
*/
httpPrepClientConn(hp->conn, 1);
mprFlushBuf(hp->requestContent);
data = argv[1];
if (ejsGetLength(ejs, data) > 0) {
prepForm(ejs, hp, NULL, data);
} else {
mprPutStringToBuf(hp->requestContent, ejsToMulti(ejs, data));
}
mprAddNullToBuf(hp->requestContent);
httpSetHeader(hp->conn, "Content-Type", "application/x-www-form-urlencoded");
/* Ensure this gets recomputed */
httpRemoveHeader(hp->conn, "Content-Length");
}
return startHttpRequest(ejs, hp, "POST", argc, argv);
}
示例14: WebSocket
/*
function WebSocket(uri: Uri, protocols = null, options)
options = {
certificate: Path,
verify: Boolean,
}
*/
static EjsWebSocket *wsConstructor(Ejs *ejs, EjsWebSocket *ws, int argc, EjsObj **argv)
{
EjsAny *certificate;
bool verify;
assert(ejsIsPot(ejs, ws));
ejsLoadHttpService(ejs);
ws->ejs = ejs;
verify = 0;
ws->uri = httpUriToString(((EjsUri*) argv[0])->uri, 0);
if (argc >= 2) {
if (ejsIs(ejs, argv[1], Array)) {
ws->protocols = sclone((ejsToString(ejs, argv[1]))->value);
} else if (ejsIs(ejs, argv[1], String)) {
ws->protocols = sclone(((EjsString*) argv[1])->value);
} else {
ws->protocols = sclone("chat");
}
} else {
ws->protocols = sclone("chat");
}
if (*ws->protocols == '\0') {
ejsThrowArgError(ejs, "Bad protocol");
return 0;
}
if (argc >= 3) {
ws->frames = ejsGetPropertyByName(ejs, argv[2], EN("frames")) == ESV(true);
verify = ejsGetPropertyByName(ejs, argv[2], EN("verify")) == ESV(true);
if ((certificate = ejsGetPropertyByName(ejs, argv[2], EN("certificate"))) != 0) {
ws->certFile = ejsToMulti(ejs, argv[0]);
}
}
if ((ws->conn = httpCreateConn(MPR->httpService, NULL, ejs->dispatcher)) == 0) {
ejsThrowMemoryError(ejs);
return 0;
}
httpSetAsync(ws->conn, 1);
httpPrepClientConn(ws->conn, 0);
httpSetConnNotifier(ws->conn, webSocketNotify);
httpSetWebSocketProtocols(ws->conn, ws->protocols);
httpSetConnContext(ws->conn, ws);
if (sstarts(ws->uri, "wss")) {
ws->ssl = mprCreateSsl(0);
mprVerifySslIssuer(ws->ssl, verify);
mprVerifySslPeer(ws->ssl, verify);
#if FUTURE
if (!hp->caFile) {
//MOB - Some define for this.
hp->caFile = mprJoinPath(mprGetAppDir(), "http-ca.crt");
}
mprSetSslCaFile(hp->ssl, hp->caFile);
mprSetSslCaFile(hp->ssl, mprJoinPath(mprGetAppDir(), "http-ca.crt"));
#endif
}
startWebSocketRequest(ejs, ws);
return ws;
}
示例15: provider
/*
function set provider(name: String): Void
*/
static EjsObj *http_set_provider(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
if (!hp->ssl) {
hp->ssl = mprCreateSsl(0);
}
mprSetSslProvider(hp->ssl, ejsToMulti(ejs, argv[0]));
return 0;
}