Esempio n. 1
0
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;
}
Esempio n. 2
0
static DynLock *sslCreateDynLock(cchar *file, int line)
{
    DynLock     *dl;

    dl = mprAllocZeroed(sizeof(DynLock));
    dl->mutex = mprCreateLock(dl);
    mprHold(dl->mutex);
    return dl;
}
Esempio n. 3
0
PUBLIC bool espRenderView(HttpConn *conn, cchar *target, int flags)
{
    HttpRx      *rx;
    HttpRoute   *route;
    EspRoute    *eroute;
    EspViewProc viewProc;

    rx = conn->rx;
    route = rx->route;
    eroute = route->eroute;

#if !ME_STATIC
    if (!eroute->combine && (route->update || !mprLookupKey(eroute->top->views, target))) {
        cchar *errMsg;
        /* WARNING: GC yield */
        target = sclone(target);
        mprHold(target);
        if (espLoadModule(route, conn->dispatcher, "view", mprJoinPath(route->documents, target), &errMsg) < 0) {
            mprRelease(target);
            return 0;
        }
        mprRelease(target);
    }
#endif
    if ((viewProc = mprLookupKey(eroute->views, target)) == 0) {
        return 0;
    }
    if (!(flags & ESP_DONT_RENDER)) {
        if (route->flags & HTTP_ROUTE_XSRF) {
            /* Add a new unique security token */
            httpAddSecurityToken(conn, 1);
        }
        httpSetContentType(conn, "text/html");
        httpSetFilename(conn, mprJoinPath(route->documents, target), 0);
        /* WARNING: may GC yield */
        (viewProc)(conn);
    }
    return 1;
}