Esempio n. 1
0
static int runLuaFilter(lsi_param_t *rec, int index)
{
    LsLuaUserParam *pUser;
    const char *pFile;
    int iFileLen = 0;
    const lsi_session_t *session = rec->session;
    luaData_t *pData = (luaData_t *)g_api->get_module_data(session, &MNAME,
                       LSI_DATA_HTTP);
    if (pData == NULL)
    {
        pData = allocateLuaData(session, &MNAME, LSI_DATA_HTTP);
        if (pData == NULL)
        {
            g_api->log(NULL, LSI_LOG_ERROR,
                       "FAILED TO ALLOCATE MODULE DATA\n");
            return LSI_ERROR;
        }
    }
    pData->m_pSession = NULL;

    pUser = (LsLuaUserParam *)g_api->get_config(session, &MNAME);
    pFile = pUser->getFilterPath(index, iFileLen);
    if (iFileLen <= 0)
    {
        g_api->log(NULL, LSI_LOG_ERROR, "Invalid Lua Filter file.");
        return LSI_ERROR;
    }
    if (index == LSLUA_HOOK_BODY)
    {
        return LsLuaEngine::runFilterScript(rec, pFile, pUser,
                                            &(pData->m_pSession), index);
    }
    return LsLuaEngine::runScript(session, pFile, pUser,
                                  &(pData->m_pSession), index);
}
Esempio n. 2
0
static int luaHandler(lsi_session_t *session )
{
    luaModuleData_t * pData;

// myTimerStart();
    pData = (luaModuleData_t *) g_api->get_module_data(session, &MNAME, LSI_MODULE_DATA_HTTP);
    if (!pData)
    {
        pData = allocateLuaData(session, &MNAME, LSI_MODULE_DATA_HTTP);
        if (!pData)
        {
            g_api->log( NULL, LSI_LOG_ERROR,  "FAILED TO ALLOCATE MODULE DATA\n");
            return LSI_RET_ERROR;
        }
    }
    pData->pSession = NULL;

    char * uri;
    uri = (char *)g_api->get_req_uri( session, NULL );
    
    char luafile[MAXFILENAMELEN];   /* 4k filenamepath */
    char buf[0x1000];
    register int    n;

    if (g_api->is_req_body_finished(session))
    {
        ;
    }
    else
    {
        g_api->set_req_wait_full_body( session );
    }

    if (g_api->get_uri_file_path( session, uri, strlen(uri), luafile, MAXFILENAMELEN))
    {
        n = snprintf(buf, 0x1000, "luahandler: FAILED TO COMPOSE LUA script path %s\r\n", uri);
        g_api->append_resp_body( session, buf, n);
        g_api->end_resp( session );
        return LSI_RET_OK;
    }
    // g_api->log( NULL, LSI_LOG_NOTICE,  "LUA HANDLER PATH [%s]\n", luafile);

    // set to 1 = continueWrite, 0 = suspendWrite - the default is 1 if onWrite is provied.
    // So I just set this off... 
    g_api->set_handler_write_state( session, 0);
    
    LsLuaEngine::setDebugLevel((int) g_api->_debugLevel);

        LsLuaUserParam * pUser = (LsLuaUserParam *) g_api->get_module_param(session, &MNAME);
        if (LsLuaEngine::api()->jitMode)
        {
            LsLuaEngine::runScriptX(session, luafile, pUser, &(pData->pSession));
        }
        else
        {
            LsLuaEngine::runScript(session, luafile, pUser, &(pData->pSession));
        }
// myTimerStop();
    return LSI_RET_OK;
}
Esempio n. 3
0
static int luaHandler(const lsi_session_t *session)
{
    char *uri;
    char luafile[MAXFILENAMELEN];
    int n;
    LsLuaUserParam *pUser;
    luaData_t *pData;

    pData = (luaData_t *)g_api->get_module_data(session, &MNAME,
            LSI_DATA_HTTP);
    if (pData == NULL)
    {
        pData = allocateLuaData(session, &MNAME, LSI_DATA_HTTP);
        if (pData == NULL)
        {
            g_api->log(NULL, LSI_LOG_ERROR,
                       "FAILED TO ALLOCATE MODULE DATA\n");
            return 500;
        }
    }
    pData->m_pSession = NULL;
    pUser = (LsLuaUserParam *)g_api->get_config(session, &MNAME);
    uri = (char *)g_api->get_req_uri(session, NULL);

    n = g_api->get_req_var_by_id(session, LSI_VAR_DOC_ROOT, luafile,
                                 MAXFILENAMELEN);
    memmove(luafile + n, uri, strlen(uri));
    n += strlen(uri);

    g_api->set_handler_write_state(session, 0);
    int debLevel = 0;
    if (*g_api->_log_level_ptr >= LSI_LOG_DEBUG)
        debLevel = (*g_api->_log_level_ptr - LSI_LOG_DEBUG) / 10; 
    LsLuaEngine::setDebugLevel(debLevel);
    return LsLuaEngine::runScript(session, luafile, pUser,
                                  &(pData->m_pSession), LSLUA_HOOK_HANDLER);

}