/* function setLimits(limits: Object): Void */ static EjsObj *hs_setLimits(Ejs *ejs, EjsHttpServer *sp, int argc, EjsObj **argv) { EjsObj *vp, *app, *cache, *cacheLimits; HttpLimits *limits; if (sp->limits == 0) { sp->limits = ejsCreateEmptyPot(ejs); limits = (sp->endpoint) ? sp->endpoint->limits : ejs->http->serverLimits; assert(limits); ejsGetHttpLimits(ejs, sp->limits, limits, 1); } ejsBlendObject(ejs, sp->limits, argv[0], EJS_BLEND_OVERWRITE); if (sp->endpoint) { limits = (sp->endpoint) ? sp->endpoint->limits : ejs->http->serverLimits; ejsSetHttpLimits(ejs, limits, sp->limits, 1); } if ((vp = ejsGetPropertyByName(ejs, sp->limits, EN("sessionTimeout"))) != 0) { app = ejsGetPropertyByName(ejs, ejs->global, N("ejs", "App")); cache = ejsGetPropertyByName(ejs, app, N("ejs", "cache")); if (cache && cache != ESV(null)) { cacheLimits = ejsCreateEmptyPot(ejs); ejsSetPropertyByName(ejs, cacheLimits, EN("lifespan"), vp); ejsCacheSetLimits(ejs, cache, cacheLimits); } } return 0; }
EjsArray *ejsCaptureStack(Ejs *ejs, int uplevels) { EjsFrame *fp; EjsState *state; EjsArray *stack; wchar *source; EjsObj *frame; char *filename; int index, lineNumber; assert(ejs); stack = ejsCreateArray(ejs, 0); index = 0; for (state = ejs->state; state; state = state->prev) { for (fp = state->fp; fp; fp = fp->caller) { if (uplevels-- <= 0) { frame = ejsCreateEmptyPot(ejs); if (ejsGetDebugInfo(ejs, (EjsFunction*) fp, fp->pc, &filename, &lineNumber, &source) >= 0) { ejsSetPropertyByName(ejs, frame, EN("filename"), ejsCreatePathFromAsc(ejs, filename)); ejsSetPropertyByName(ejs, frame, EN("lineno"), ejsCreateNumber(ejs, lineNumber)); ejsSetPropertyByName(ejs, frame, EN("code"), ejsCreateString(ejs, source, wlen(source))); } else { ejsSetPropertyByName(ejs, frame, EN("filename"), EST(undefined)); } ejsSetPropertyByName(ejs, frame, EN("func"), fp->function.name); ejsSetProperty(ejs, stack, index++, frame); } } } return stack; }
static void lcd_strobe(void) { EN(1); udelay(1); EN(0); udelay(1); }
/* 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; }
static EjsObj *getFileOptions(Ejs *ejs, EjsFile *fp, int argc, EjsObj **argv) { EjsObj *options; options = (EjsObj*) ejsCreateEmptyPot(ejs); ejsSetPropertyByName(ejs, options, EN("mode"), ejsCreateStringFromAsc(ejs, fp->modeString)); ejsSetPropertyByName(ejs, options, EN("permissions"), ejsCreateNumber(ejs, fp->perms)); return options; }
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; }
PUBLIC int ejsSetupHttpTrace(Ejs *ejs, HttpTrace *trace, EjsObj *options) { EjsObj *rx, *tx; if ((rx = ejsGetPropertyByName(ejs, options, EN("rx"))) != 0) { setupTrace(ejs, trace, HTTP_TRACE_RX, rx); } if ((tx = ejsGetPropertyByName(ejs, options, EN("tx"))) != 0) { setupTrace(ejs, trace, HTTP_TRACE_TX, tx); } return 0; }
/* function sendBlock(content, options): Number */ static EjsNumber *ws_sendBlock(Ejs *ejs, EjsWebSocket *ws, int argc, EjsObj **argv) { EjsByteArray *ba; EjsAny *content, *vp; ssize nbytes; cchar *str; int last, mode, type, flags; assert(argc == 2); if (ws->conn->state < HTTP_STATE_PARSED && !waitForHttpState(ws, HTTP_STATE_PARSED, -1, 1)) { return ESV(null); } content = argv[0]; last = ejsGetPropertyByName(ejs, argv[1], EN("last")) != ESV(false); if ((vp = ejsGetPropertyByName(ejs, argv[1], EN("mode"))) != 0) { mode = (int) ejsGetNumber(ejs, vp); if (mode != HTTP_BUFFER && mode != HTTP_BLOCK && mode != HTTP_NON_BLOCK) { ejsThrowArgError(ejs, "Bad message mode"); return 0; } } else { mode = HTTP_BUFFER; } if ((vp = ejsGetPropertyByName(ejs, argv[1], EN("type"))) != 0) { type = (int) ejsGetNumber(ejs, vp); if (type != WS_MSG_CONT && type != WS_MSG_TEXT && type != WS_MSG_BINARY) { ejsThrowArgError(ejs, "Bad message type"); return 0; } } else { type = WS_MSG_TEXT; } flags = mode; if (!last) { flags |= HTTP_MORE; } if (ejsIs(ejs, content, ByteArray)) { ba = (EjsByteArray*) content; nbytes = ejsGetByteArrayAvailableData(ba); nbytes = httpSendBlock(ws->conn, type, (cchar*) &ba->value[ba->readPosition], nbytes, flags); } else { str = ejsToMulti(ejs, content); nbytes = httpSendBlock(ws->conn, type, str, slen(str), flags); } if (nbytes < 0) { ejsThrowIOError(ejs, "Cannot send block"); return 0; } return ejsCreateNumber(ejs, (MprNumber) nbytes); }
/* Just used write commands while Initialization of CLCD */ void write(unsigned char bit_value) { unsigned char nibble; unsigned short wait; RS(LOW); for (nibble = 0; nibble < 2; nibble++) { LCD_PORT = (LCD_PORT & 0x0F) | ((bit_value << (4 * nibble)) & 0xF0); EN(1); for (wait = 1000; wait--; ); EN(0); } }
PUBLIC void ejsCreateArrayType(Ejs *ejs) { EjsType *type; EjsHelpers *helpers; type = ejsCreateCoreType(ejs, N("ejs", "Array"), sizeof(EjsArray), S_Array, ES_Array_NUM_CLASS_PROP, manageArray, EJS_TYPE_POT | EJS_TYPE_NUMERIC_INDICIES | EJS_TYPE_VIRTUAL_SLOTS | EJS_TYPE_MUTABLE_INSTANCES | EJS_TYPE_DYNAMIC_INSTANCES); helpers = &type->helpers; helpers->cast = (EjsCastHelper) castArray; helpers->clone = (EjsCloneHelper) ejsCloneArray; helpers->create = (EjsCreateHelper) createArray; helpers->getProperty = (EjsGetPropertyHelper) getArrayProperty; helpers->getPropertyCount = (EjsGetPropertyCountHelper) getArrayPropertyCount; helpers->getPropertyByName = (EjsGetPropertyByNameHelper) getArrayPropertyByName; helpers->deleteProperty = (EjsDeletePropertyHelper) deleteArrayProperty; helpers->deletePropertyByName = (EjsDeletePropertyByNameHelper) deleteArrayPropertyByName; helpers->invokeOperator = (EjsInvokeOperatorHelper) invokeArrayOperator; helpers->lookupProperty = (EjsLookupPropertyHelper) lookupArrayProperty; helpers->setProperty = (EjsSetPropertyHelper) setArrayProperty; helpers->setPropertyByName = (EjsSetPropertyByNameHelper) setArrayPropertyByName; ejsAddImmutable(ejs, S_length, EN("length"), ejsCreateStringFromAsc(ejs, "length")); }
/* WARNING: the inside interpreter owns the exception object. Must fully extract all fields */ static void handleError(Ejs *ejs, EjsWorker *worker, EjsObj *exception, int throwOutside) { Ejs *inside; EjsObj *e; MprDispatcher *dispatcher; Message *msg; assert(!worker->inside); assert(exception); assert(ejs == worker->ejs); ejsBlockGC(ejs); if ((msg = createMessage()) == 0) { ejsThrowMemoryError(ejs); return; } msg->worker = worker; msg->callback = "onerror"; msg->callbackSlot = ES_Worker_onerror; inside = worker->pair->ejs; inside->exception = 0; e = ejsDeserialize(ejs, ejsSerialize(inside, exception, 0)); inside->exception = exception; /* Inside interpreter owns the exception object, so must fully extract all exception. Allocate into the outside worker's interpreter. */ if (ejsIsError(inside, exception)) { msg->message = ejsGetPropertyByName(ejs, e, EN("message")); msg->stack = ejsGetPropertyByName(ejs, e, EN("stack")); } else { msg->message = e; msg->stack = 0; } if (throwOutside) { if (msg->stack) { ejsThrowStateError(ejs, "%@\n%@", ejsToString(ejs, msg->message), ejsToString(ejs, msg->stack)); } else { ejsThrowStateError(ejs, "%@", ejsToString(ejs, msg->message)); } } dispatcher = ejs->dispatcher; mprCreateEvent(dispatcher, "doMessage-error", 0, (MprEventProc) doMessage, msg, 0); }
static void setupTrace(Ejs *ejs, HttpTrace *trace, int dir, EjsObj *options) { EjsArray *extensions; EjsObj *ext; HttpTrace *tp; int i, level, *levels; tp = &trace[dir]; levels = tp->levels; if ((level = getNumOption(ejs, options, "all")) >= 0) { for (i = 0; i < HTTP_TRACE_MAX_ITEM; i++) { levels[i] = level; } } else { levels[HTTP_TRACE_CONN] = getNumOption(ejs, options, "conn"); levels[HTTP_TRACE_FIRST] = getNumOption(ejs, options, "first"); levels[HTTP_TRACE_HEADER] = getNumOption(ejs, options, "headers"); levels[HTTP_TRACE_BODY] = getNumOption(ejs, options, "body"); } tp->size = getNumOption(ejs, options, "size"); if ((extensions = (EjsArray*) ejsGetPropertyByName(ejs, options, EN("include"))) != 0) { if (!ejsIs(ejs, extensions, Array)) { ejsThrowArgError(ejs, "include is not an array"); return; } tp->include = mprCreateHash(0, 0); for (i = 0; i < extensions->length; i++) { if ((ext = ejsGetProperty(ejs, extensions, i)) != 0) { mprAddKey(tp->include, ejsToMulti(ejs, ejsToString(ejs, ext)), ""); } } } if ((extensions = (EjsArray*) ejsGetPropertyByName(ejs, options, EN("exclude"))) != 0) { if (!ejsIs(ejs, extensions, Array)) { ejsThrowArgError(ejs, "exclude is not an array"); return; } tp->exclude = mprCreateHash(0, 0); for (i = 0; i < extensions->length; i++) { if ((ext = ejsGetProperty(ejs, extensions, i)) != 0) { mprAddKey(tp->exclude, ejsToMulti(ejs, ejsToString(ejs, ext)), MPR->emptyString); } } } }
static int getNumOption(Ejs *ejs, EjsObj *options, cchar *field) { EjsObj *obj; if ((obj = ejsGetPropertyByName(ejs, options, EN(field))) != 0) { return ejsGetInt(ejs, obj); } return -1; }
/* Break a uri into components function components(): Object */ static EjsObj *uri_components(Ejs *ejs, EjsUri *up, int argc, EjsObj **argv) { EjsObj *obj; HttpUri *uri; uri = up->uri; obj = ejsCreateEmptyPot(ejs); if (uri->scheme) { ejsSetPropertyByName(ejs, obj, EN("scheme"), ejsCreateStringFromAsc(ejs, uri->scheme)); } if (uri->host) { ejsSetPropertyByName(ejs, obj, EN("host"), ejsCreateStringFromAsc(ejs, uri->host)); } if (uri->port > 0) { ejsSetPropertyByName(ejs, obj, EN("port"), ejsCreateNumber(ejs, uri->port)); } if (uri->path) { ejsSetPropertyByName(ejs, obj, EN("path"), ejsCreateStringFromAsc(ejs, uri->path)); } if (uri->reference) { ejsSetPropertyByName(ejs, obj, EN("reference"), ejsCreateStringFromAsc(ejs, uri->reference)); } if (uri->query) { ejsSetPropertyByName(ejs, obj, EN("query"), ejsCreateStringFromAsc(ejs, uri->query)); } return obj; }
/* Return the (proposed) request headers function getRequestHeaders(): Object */ static EjsPot *http_getRequestHeaders(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv) { MprKey *kp; HttpConn *conn; EjsPot *headers; conn = hp->conn; headers = ejsCreateEmptyPot(ejs); for (kp = 0; conn->tx && (kp = mprGetNextKey(conn->tx->headers, kp)) != 0; ) { ejsSetPropertyByName(ejs, headers, EN(kp->key), ejsCreateStringFromAsc(ejs, kp->data)); } return headers; }
static EjsWorker *workerConstructor(Ejs *ejs, EjsWorker *worker, int argc, EjsObj **argv) { EjsArray *search; EjsObj *options, *value; cchar *name, *scriptFile; ejsBlockGC(ejs); scriptFile = (argc >= 1 && argv[0] != ESV(null)) ? ((EjsPath*) argv[0])->value : 0; options = (argc == 2 && argv[1] != ESV(null)) ? (EjsObj*) argv[1]: NULL; name = 0; search = 0; if (options) { search = ejsGetPropertyByName(ejs, options, EN("search")); value = ejsGetPropertyByName(ejs, options, EN("name")); if (ejsIs(ejs, value, String)) { name = ejsToMulti(ejs, value); } } worker->ejs = ejs; worker->state = EJS_WORKER_BEGIN; return initWorker(ejs, worker, 0, name, search, scriptFile); }
PUBLIC void ejsCreateVoidType(Ejs *ejs) { EjsType *type; type = ejsCreateCoreType(ejs, N("ejs", "Void"), sizeof(EjsVoid), S_Void, ES_Void_NUM_CLASS_PROP, NULL, EJS_TYPE_OBJ); type->helpers.cast = (EjsCastHelper) castVoid; type->helpers.invokeOperator = (EjsInvokeOperatorHelper) invokeVoidOperator; type->helpers.getProperty = (EjsGetPropertyHelper) getVoidProperty; ejsAddImmutable(ejs, ES_undefined, EN("undefined"), ejsCreateObj(ejs, type, 0)); mprSetName(ESV(undefined), "undefined"); }
/* function get info(): Object */ static EjsObj *http_info(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv) { EjsObj *obj; char *key, *next, *value; if (hp->conn && hp->conn->sock) { obj = ejsCreateEmptyPot(ejs); for (key = stok(mprGetSocketState(hp->conn->sock), ",", &next); key; key = stok(NULL, ",", &next)) { stok(key, "=", &value); ejsSetPropertyByName(ejs, obj, EN(key), ejsCreateStringFromAsc(ejs, value)); } return obj; } return ESV(null); }
/* Get all environment vars function get env(): Object */ static EjsAny *app_env(Ejs *ejs, EjsObj *app, int argc, EjsObj **argv) { #if VXWORKS return ESV(null); #else EjsPot *result; char **ep, *pair, *key, *value; result = ejsCreatePot(ejs, ESV(Object), 0); for (ep = environ; ep && *ep; ep++) { pair = sclone(*ep); key = ssplit(pair, "=", &value); ejsSetPropertyByName(ejs, result, EN(key), ejsCreateStringFromAsc(ejs, value)); } return result; #endif }
// TODO - rename static int ejsGetNumOption(Ejs *ejs, EjsObj *options, cchar *field, int defaultValue, bool optional) { EjsObj *vp; EjsNumber *num; vp = ejsGetPropertyByName(ejs, options, EN(field)); if (vp == 0) { if (optional) { return defaultValue; } ejsThrowArgError(ejs, "Required option \"%s\" is missing", field); return 0; } num = ejsToNumber(ejs, vp); if (!ejsIs(ejs, num, Number)) { ejsThrowArgError(ejs, "Bad option type for field \"%s\"", field); return 0; } return (int) num->value; }
static cchar *getStrOption(Ejs *ejs, EjsObj *options, cchar *field, cchar *defaultValue, bool optional) { EjsObj *vp; EjsString *str; vp = ejsGetPropertyByName(ejs, options, EN(field)); if (vp == 0) { if (optional) { return sclone(defaultValue); } ejsThrowArgError(ejs, "Required option %s is missing", field); return 0; } str = ejsToString(ejs, vp); if (!ejsIs(ejs, str, String)) { ejsThrowArgError(ejs, "Bad option type for field \"%s\"", field); return 0; } return ejsToMulti(ejs, str); }
/* function get headers(): Object */ static EjsPot *http_headers(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv) { MprHash *hash; MprKey *kp; EjsPot *results; int i; if (!waitForResponseHeaders(hp)) { return 0; } results = ejsCreateEmptyPot(ejs); hash = httpGetHeaderHash(hp->conn); if (hash == 0) { return results; } for (i = 0, kp = mprGetFirstKey(hash); kp; kp = mprGetNextKey(hash, kp), i++) { ejsSetPropertyByName(ejs, results, EN(kp->key), ejsCreateStringFromAsc(ejs, kp->data)); } return results; }
/* This function is to be called in Timer ISR */ void update_clcd_screen(void) { static unsigned char data = 0; static unsigned char nibble = 0; /* Start pushing the data on port only when the enable line is Low */ if(EN_PIN_LOW) { /* The below line is to change the line to be printed on CLCD */ /* The clcd_buff containes the line addresses of the CLCD on start */ RS(!!(data_offset % CLCD_LINE_LEN)); data = clcd_buff[data_offset / CLCD_LINE_LEN][data_offset % CLCD_LINE_LEN]; /* Send char data to the LCD */ if (nibble) { /* LSB nibble */ if ((data_offset + 1) < (NO_OF_LINES * CLCD_LINE_LEN)) { data_offset += 1; } else { /* Screen updated so no need of refreshing again */ update_clcd = 0; data_offset = 0; } LCD_PORT = (LCD_PORT & 0x0F) | ((data << 4) & 0xF0); } else { LCD_PORT = (LCD_PORT & 0x0F) | (data & 0xF0); } nibble = !nibble; } /* Once the data is on port, Enable the CLCD to process the data */ /* This line also makes sure that is enable pulse generated for two overflows */ EN(PIN_TOGGLE); }
void CWndDmm::DrawDigit(int x, int y, int width, int size, int space, int nDigit, ui16 clrOn, ui16 clrOff) { ui32 decoder[] = {0x1111110, 0x0110000, 0x1101101, 0x1111001, 0x0110011, 0x1011011, 0x1011111, 0x1110000, 0x1111111, 0x1111011}; ui32 dec = 0; if ( (nDigit&127) >= '0' && (nDigit&127) <= '9' ) { dec = decoder[nDigit&15]; if ( nDigit & 128 ) dec |= 0x10000000; } else { switch (nDigit) { case ' ': dec = 0; break; case '?': dec = 0; break; case '-': dec = 0x0000001; break; case 'E': dec = 0x1001111; break; case 'r': dec = 0x0000101; break; case 'o': dec = 0x0011101; break; case 'f': dec = 0x1000111; break; } } #define EN(n) ( dec>>(28-n*4)&1 ) ? clrOn : clrOff _DrawDigitHT( x+space, y, width, size, EN(1) ); _DrawDigitHC( x+space, y+width/2+size+2*space-1, width, size, EN(7) ); _DrawDigitHB( x+space, y+size*2+width+4*space, width, size, EN(4) ); _DrawDigitVR( x+size+2*space, y+space, width, size, EN(2) ); _DrawDigitVR( x+size+2*space, y+size+width+3*space, width, size, EN(3) ); _DrawDigitVL( x, y+space, width, size, EN(6) ); _DrawDigitVL( x, y+size+width+3*space, width, size, EN(5) ); _DrawDot0(x+size+width+5*space, y+size*2+width+6*space, width, size, space, EN(0)); #undef EN }
static HttpUri *createHttpUriFromHash(Ejs *ejs, EjsObj *arg, int flags) { EjsObj *schemeObj, *hostObj, *portObj, *pathObj, *referenceObj, *queryObj, *uriObj; cchar *scheme, *host, *path, *reference, *query; int port; /* This permits a uri property override. Used in ejs.web::View.getOptions() */ uriObj = ejsGetPropertyByName(ejs, arg, EN("uri")); if (uriObj) { return toHttpUri(ejs, uriObj, 1); } schemeObj = ejsGetPropertyByName(ejs, arg, EN("scheme")); scheme = ejsIs(ejs, schemeObj, String) ? ejsToMulti(ejs, schemeObj) : 0; hostObj = ejsGetPropertyByName(ejs, arg, EN("host")); host = ejsIs(ejs, hostObj, String) ? ejsToMulti(ejs, hostObj) : 0; port = 0; if ((portObj = ejsGetPropertyByName(ejs, arg, EN("port"))) != 0) { if (ejsIs(ejs, portObj, Number)) { port = ejsGetInt(ejs, portObj); } else if (ejsIs(ejs, portObj, String)) { port = (int) stoi(ejsToMulti(ejs, portObj)); } } pathObj = ejsGetPropertyByName(ejs, arg, EN("path")); path = ejsIs(ejs, pathObj, String) ? ejsToMulti(ejs, pathObj) : 0; referenceObj = ejsGetPropertyByName(ejs, arg, EN("reference")); reference = ejsIs(ejs, referenceObj, String) ? ejsToMulti(ejs, referenceObj) : 0; queryObj = ejsGetPropertyByName(ejs, arg, EN("query")); query = ejsIs(ejs, queryObj, String) ? ejsToMulti(ejs, queryObj) : 0; return httpCreateUriFromParts(scheme, host, port, path, reference, query, flags); }
loop_xmit, NULLP_FUNC, NULLP_FUNC, loop_statistics, NULLP_FUNC, LOOP_DEVICE, "LOOPBACK", MINOR_0, LOOP_IFACE, SNMP_DEVICE_INFO(CFG_OID_LOOP, CFG_SPEED_LOOP) CFG_ETHER_MAX_MTU, CFG_ETHER_MAX_MSS, CFG_ETHER_MAX_WIN_IN, CFG_ETHER_MAX_WIN_OUT, IOADD(0), EN(0), EN(0) }; } /* extern "C" */ /* ******************************************************************** EXTERNS ******************************************************************** */ /* Pointer to the interface structure. We look at this inside the xmit routine */ extern PIFACE RTP_FAR loop_pi; extern unsigned long RTP_FAR loop_packets_in;
static void onWebSocketEvent(EjsWebSocket *ws, int event, EjsAny *data, HttpPacket *packet) { Ejs *ejs; EjsAny *eobj; EjsFunction *fn; HttpRx *rx; cchar *eventName, *reason; int slot, status; ejs = ws->ejs; rx = ws->conn->rx; eobj = ejsCreateObj(ejs, ESV(Object), 0); slot = -1; eventName = 0; switch(event) { case HTTP_EVENT_READABLE: slot = ES_WebSocket_onmessage; eventName = "readable"; assert(data); ejsSetPropertyByName(ejs, eobj, EN("data"), data); ejsSetPropertyByName(ejs, eobj, EN("last"), ejsCreateBoolean(ejs, packet->last)); ejsSetPropertyByName(ejs, eobj, EN("type"), ejsCreateNumber(ejs, packet->type)); break; case HTTP_EVENT_ERROR: eventName = "error"; slot = ES_WebSocket_onerror; break; case HTTP_EVENT_APP_OPEN: slot = ES_WebSocket_onopen; eventName = "headers"; if (rx->webSocket) { httpSetWebSocketPreserveFrames(ws->conn, ws->frames); } break; case HTTP_EVENT_DESTROY: if (ws->closed) { break; } ws->closed = 1; /* Fall through to close */ case HTTP_EVENT_APP_CLOSE: eventName = "complete"; slot = ES_WebSocket_onclose; status = rx ? rx->webSocket->closeStatus: WS_STATUS_COMMS_ERROR; reason = rx ? rx->webSocket->closeReason: 0; ejsSetPropertyByName(ejs, eobj, EN("code"), ejsCreateNumber(ejs, status)); ejsSetPropertyByName(ejs, eobj, EN("reason"), ejsCreateStringFromAsc(ejs, reason)); ejsSetPropertyByName(ejs, eobj, EN("wasClean"), ejsCreateBoolean(ejs, status != WS_STATUS_COMMS_ERROR)); break; } if (slot >= 0) { if (ws->emitter) { ejsSendEvent(ejs, ws->emitter, eventName, ws, data); } fn = ejsGetProperty(ejs, ws, slot); if (ejsIsFunction(ejs, fn) && !ejs->exception) { ejsRunFunction(ejs, fn, ws, 1, &eobj); } } }
#include "pgpNetServiceErrors.h" typedef struct ErrorEntry { PGPnetServiceError const number; const char * const string; } ErrorEntry; #define EN(number, string) { number, string } static const ErrorEntry sErrors[] = { EN( kPGPnetSrvcError_NoErr, "not an error"), EN( kPGPnetSrvcError_NoAuthPassphrase, "Unable to obtain passphrase for authentication key"), EN( kPGPnetSrvcError_NoAuthKey, "Unable to obtain authentication key"), EN( kPGPnetSrvcError_NTon95, "The IKE service installed on this machine is designed for Windows NT only"), EN( kPGPnetSrvcError_ReadConfig, "Unable to read PGPnet configuration"), EN( kPGPnetSrvcError_NoNetwork, "PGPnet unable to start networking"), EN( kPGPnetSrvcError_NoDriver, "The PGPnet driver is not installed"), EN( kPGPnetSrvcError_DrvEvent, "Unable to communicate with PGPnet driver"), EN( kPGPnetSrvcError_DrvSharedMemory, "Unable to communicate with PGPnet driver"), EN( kPGPnetSrvcError_DrvCommunication, "Unable to communicate with PGPnet driver"), EN( kPGPnetSrvcError_SAFailed, "Unable to establish Security Association with peer"), EN( kPGPnetSrvcError_95onNT, "The IKE service installed on this machine is designed for Windows 95/98 only"), EN( kPGPnetSrvcError_AuthenticatedKey, "Authenticated Key ID "), EN( kPGPnetSrvcError_AuthenticatedCert, "Authenticated X.509 certificate"), EN( kPGPnetSrvcError_RevokedCert, "Remote X.509 certificate is revoked"), EN( kPGPnetSrvcError_ExpiredCert, "Remote X.509 certificate is expired"),
#if (DECLARING_DATA || BUILD_NEW_BINARY) /* ******************************************************************** */ /* GLOBAL DATA */ /* ******************************************************************** */ /* DAVICOM_SOFTC KS_FAR davicom_softc[CFG_NUM_DAVICOM]; */ PDAVICOM_SOFTC KS_FAR davicom_softc[CFG_NUM_DAVICOM]; EDEVTABLE KS_FAR davicom_device = { davicom_open, davicom_close, davicom_xmit, davicom_xmit_done, NULLP_FUNC, davicom_statistics, davicom_setmcast, DAVICOM_DEVICE, "DAVICOM", MINOR_0, ETHER_IFACE, SNMP_DEVICE_INFO(CFG_OID_DAVICOM, CFG_SPEED_DAVICOM) CFG_ETHER_MAX_MTU, CFG_ETHER_MAX_MSS, CFG_ETHER_MAX_WIN_IN, CFG_ETHER_MAX_WIN_OUT, EN(0x300), EN(0x0), EN(5) }; #endif /* DECLARING_DATA */ #if (!DECLARING_DATA) /* exclude rest of file */ /* ******************************************************************** */ /* EXTERNS */ /* ******************************************************************** */ #if (!BUILD_NEW_BINARY) extern PDAVICOM_SOFTC KS_FAR davicom_softc[CFG_NUM_DAVICOM]; extern EDEVTABLE KS_FAR davicom_device; #endif /* ******************************************************************** */ /* DEFINES */ /* ******************************************************************** */
/* Process a message sent from postMessage. This may run inside the worker or outside in the parent depending on the direction of the message. But it ALWAYS runs in the appropriate thread for the interpreter. */ static int doMessage(Message *msg, MprEvent *mprEvent) { Ejs *ejs; EjsObj *event, *frame; EjsWorker *worker; EjsFunction *callback; EjsObj *argv[1]; worker = msg->worker; worker->gotMessage = 1; ejs = worker->ejs; assert(!ejs->exception); event = 0; ejsBlockGC(ejs); callback = ejsGetProperty(ejs, worker, msg->callbackSlot); switch (msg->callbackSlot) { case ES_Worker_onerror: event = ejsCreateObj(ejs, ESV(ErrorEvent), 0); break; case ES_Worker_onclose: case ES_Worker_onmessage: event = ejsCreateObj(ejs, ESV(Event), 0); break; default: assert(msg->callbackSlot == 0); return 0; } worker->event = event; if (msg->data) { ejsSetProperty(ejs, event, ES_Event_data, ejsCreateStringFromAsc(ejs, msg->data)); } if (msg->message) { ejsSetProperty(ejs, event, ES_ErrorEvent_message, msg->message); } if (msg->stack) { ejsSetProperty(ejs, event, ES_ErrorEvent_stack, msg->stack); if ((frame = ejsGetProperty(ejs, msg->stack, 0)) != 0 && !ejsIs(ejs, frame, Void)) { ejsSetProperty(ejs, event, ES_ErrorEvent_filename, ejsGetPropertyByName(ejs, frame, EN("filename"))); ejsSetProperty(ejs, event, ES_ErrorEvent_lineno, ejsGetPropertyByName(ejs, frame, EN("lineno"))); } } assert(!ejs->exception); if (callback == 0 || ejsIs(ejs, callback, Null)) { if (msg->callbackSlot == ES_Worker_onmessage) { mprTrace(6, "Discard message as no onmessage handler defined for worker"); } else if (msg->callbackSlot == ES_Worker_onerror) { if (ejsIs(ejs, msg->message, String)) { ejsThrowError(ejs, "Exception in Worker: %@", ejsToString(ejs, msg->message)); } else { ejsThrowError(ejs, "Exception in Worker: %s", ejsGetErrorMsg(worker->pair->ejs, 1)); } } else { /* Ignore onclose message */ } } else if (!ejsIsFunction(ejs, callback)) { ejsThrowTypeError(ejs, "Worker callback %s is not a function", msg->callback); } else { assert(!ejs->exception); argv[0] = event; ejsRunFunction(ejs, callback, worker, 1, argv); } if (msg->callbackSlot == ES_Worker_onclose) { assert(!worker->inside); worker->state = EJS_WORKER_COMPLETE; mprTrace(5, "Worker.doMessage: complete"); /* Worker and insider interpreter are now eligible for garbage collection */ removeWorker(worker); } mprSignalDispatcher(ejs->dispatcher); worker->event = 0; return 0; }