Beispiel #1
0
int CLuaHTTPDefs::httpRequestLogin ( lua_State* luaVM )
{
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        CResourceFile * file = pLuaMain->GetResourceFile();
        if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
        {
            CResourceHTMLItem * html = (CResourceHTMLItem *)file;

			char szName[255];
			sprintf ( szName, "Basic realm=\"%s\"", m_pMainConfig->GetServerName ().c_str () );
			html->SetResponseHeader("WWW-Authenticate", szName);
			html->SetResponseCode ( 401 );
            lua_pushboolean ( luaVM, true );
            return 1;
        }
        else
            m_pScriptDebugging->LogError ( luaVM, "httpRequestLogin: Can only be used in HTML scripts" );
    } 
    else
        m_pScriptDebugging->LogError ( luaVM, "httpRequestLogin" );   
    lua_pushboolean ( luaVM, false );
    return 1;
}
Beispiel #2
0
int CLuaHTTPDefs::httpSetResponseCode ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 1 ) == LUA_TNUMBER  )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResourceFile * file = pLuaMain->GetResourceFile();
            if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
            {
                CResourceHTMLItem * html = (CResourceHTMLItem *)file;
                unsigned int responseCode = static_cast < unsigned int > ( lua_tonumber ( luaVM, 1 ) );
				html->SetResponseCode ( responseCode );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "httpSetResponseCode: Can only be used in HTML scripts" );
        } 
        else
            m_pScriptDebugging->LogError ( luaVM, "httpSetResponseCode" );
    }   
    else
        m_pScriptDebugging->LogBadType ( luaVM, "httpSetResponseCode" );
    lua_pushboolean ( luaVM, false );
    return 1;
}