Esempio n. 1
0
File: ldml.c Progetto: bigml/mgate
NEOERR* ldml_render(char *filename, char *keyname, HDF *datanode, HDF *outnode)
{
    HASH *datah;
    HDF *confignode;

    MCS_NOT_NULLC(filename, keyname, outnode);

    datah = hash_lookup(g_datah, "runtime_dml");
    MCS_NOT_NULLA(datah);

    confignode = hash_lookupf(datah, "%s.hdf", filename);
    if (!confignode) return nerr_raise(NERR_ASSERT, "data file %s nexist", filename);

    confignode = hdf_get_obj(confignode, keyname);
    if (!confignode) return nerr_raise(NERR_ASSERT, "%s.hdf %s nexist",
                                       filename, keyname);

    return nerr_pass(mcs_data_rend(confignode, datanode, outnode));
}
Esempio n. 2
0
File: ltpl.c Progetto: adderly/cmoon
/*
 * we don't pass tplh parameter to it,
 * because walker don't have it. so, tplh stored in the g_datah
 */
NEOERR* ltpl_render2file(CGI *cgi, char *render, char *fname)
{
    STRING str; string_init(&str);
    HASH *tplh;
    CSPARSE *cs;
    HDF *dhdf;
    NEOERR *err;

    MCS_NOT_NULLC(cgi->hdf, render, fname);
    
    tplh = hash_lookup(g_datah, "runtime_templates");
    MCS_NOT_NULLA(tplh);

    cs = hash_lookup(tplh, render);
    MCS_NOT_NULLA(cs);

    dhdf = hash_lookupf(tplh, "%s_hdf", render);
    if (dhdf) hdf_copy(cgi->hdf, NULL, dhdf);

    ltpl_prepare_rend(cgi->hdf, hdf_get_value(cgi->hdf,
                                              PRE_RESERVE"."PRE_CFG_LAYOUT,
                                              "layout.html"));
    cs->hdf = cgi->hdf;

    err = cs_render(cs, &str, mcs_strcb);
    if (err != STATUS_OK) return nerr_pass(err);

    err = mfile_makesure_dir(fname);
    if (err != STATUS_OK) return nerr_pass(err);
    
    err = mcs_str2file(str, fname);
    if (err != STATUS_OK) return nerr_pass(err);

    string_clear(&str);

    return STATUS_OK;
}
Esempio n. 3
0
File: ltpl.c Progetto: adderly/cmoon
NEOERR* ltpl_render(CGI *cgi, HASH *tplh, session_t *ses)
{
    STRING str; string_init(&str);
    CSPARSE *cs;
    HDF *dhdf;
    NEOERR *err;

    char *render = NULL;

    render = ses->render;
    cs = (CSPARSE*)hash_lookup(tplh, render);
    dhdf = (HDF*)hash_lookupf(tplh, "%s_hdf", render);

    if (!cs) return nerr_raise(LERR_MISS_TPL, "render %s not found", render);
    if (dhdf) hdf_copy(cgi->hdf, NULL, dhdf);
    
    ltpl_prepare_rend(cgi->hdf, hdf_get_value(cgi->hdf,
                                              PRE_RESERVE"."PRE_CFG_LAYOUT,
                                              "layout.html"));
    
    if (ses->tm_cache_browser > 0) {
        hdf_set_valuef(cgi->hdf, "cgiout.other.cache=Cache-Control: max-age=%lu",
                       ses->tm_cache_browser);
    }
    cs->hdf = cgi->hdf;

    err = cs_render(cs, &str, mcs_strcb);
    if (err != STATUS_OK) return nerr_pass(err);

    err = cgi_output(cgi, &str);
    if (err != STATUS_OK) return nerr_pass(err);

    cs->hdf = NULL;
    string_clear(&str);

    return STATUS_OK;
}