int SSIEngine::evalOperator( HttpSession *pSession, ExprToken * &pTok ) { char * p1 = NULL; int len; int ret; if ( !pTok ) return 0; int type = pTok->getType(); ExprToken * pCur = pTok; pTok = pTok->next(); switch( type ) { case ExprToken::EXP_STRING: return ( pCur->getStr()->len() > 0 ); case ExprToken::EXP_FMT: { char achBuf1[40960]; p1 = achBuf1; len = 40960; RequestVars::buildString( pCur->getFormat(), pSession, p1, len, 0, pSession->getReq()->getSSIRuntime()->getRegexResult() ); return len > 0; } case ExprToken::EXP_REGEX: return 0; case ExprToken::EXP_NOT: if ( pTok ) { return !evalOperator( pSession, pTok ); } else return 1; default: break; } if (( type == ExprToken::EXP_AND )|| ( type == ExprToken::EXP_OR )) { ret = evalOperator( pSession, pTok ); if ((( ret )&&( pTok->getType() == ExprToken::EXP_OR ))|| (( !ret )&&( pTok->getType() == ExprToken::EXP_AND ))) { if ( pTok ) { shortCurcuit( pTok ); } return ret; } ret = evalOperator( pSession, pTok ); return ret; } if ( !pTok ) return 0; return compString( pSession, type, pTok ); }
int SSIEngine::evalExpr(HttpSession *pSession, SubstItem *pItem) { int ret = 0; if ((!pItem) || (pItem->getType() != REF_EXPR)) return 0; Expression *pExpr = (Expression *)pItem->getAny(); ExprToken *pTok = pExpr->begin(); ret = evalOperator(pSession, pTok); return ret; }
/** * conditional operators AND and OR */ bool CondParser::parseLevel1() { bool ans = parseLevel2(); int opId = getOperatorId(m_token); while (opId == AND || opId == OR) { getToken(); ans = evalOperator(opId, ans, parseLevel2()); opId = getOperatorId(m_token); } return ans; }