int Check_Timer()
{
    int hasTimer = 0;
    
    //Check module timer here and trigger timeout ones
    LinkedObj *headPos = HttpGlobals::s_ModuleTimerList.head();
    ModuleTimer *pNext = NULL;
    while(1)
    {
        pNext = (ModuleTimer *)(headPos->next());
        if (pNext)
            hasTimer = 1;
        
        if (pNext && pNext->m_tmExpire <= DateTime::s_curTime)
        {
            pNext->m_TimerCb(pNext->m_pTimerCbParam);
            headPos->removeNext();
            delete pNext;
        }
        else
            break;
    }
    
    
    return hasTimer;
}
int SubstFormat::parse( const char * pCurLine, const char * pFormatStr, const char * pEnd, int isSSI, char varChar )
{
    while(( pFormatStr < pEnd )&&( isspace( *pFormatStr )))
        ++pFormatStr;
    int err = 0;
    char achVarChar[2];
    LinkedObj * pLast = head();
    SubstItem * pItem;
    achVarChar[0] = varChar;
    achVarChar[1] = 0;
    while( pFormatStr < pEnd )
    {
        pItem = new SubstItem();
        if ( !pItem )
        {
            ERR_NO_MEM( "new SubstItem()" );
            return -1;
        }
        
        if (  *pFormatStr == varChar )
        {
            if ( pFormatStr + 1 == pEnd )
            {
                HttpLog::parse_error( pCurLine ,  "Line ended with '$'" );
                err = 1;
            }
            if ( isdigit( *( pFormatStr + 1 ) ) )
            {
                pItem->setType( REF_RULE_SUBSTR );
                pItem->setIndex( *(pFormatStr + 1) - '0' );
                pFormatStr += 2;
            }
            else 
            {
                ++pFormatStr;
                if ( pItem->parseServerVar( pCurLine, pFormatStr, pEnd, isSSI ) )
                {
                    err = 1;
                }

            }
        }
        else
        {
            pItem->parseString( pFormatStr, pEnd, achVarChar );
        }
        if ( err )
        {
            delete pItem;
            return -1;
        }
        else
        {
            pLast->addNext( pItem );
            pLast = pItem;
        }
    }
    return 0;
}
int RewriteEngine::parseRules( char * &pRules, RewriteRuleList * pRuleList,
                        const RewriteMapList * pMapList )
{
    LinkedObj * pLast = pRuleList->tail();
    if ( !pLast )
        pLast = pRuleList->head();
    while( *pRules )
    {
        while( isspace( *pRules ) )
            ++pRules;
        if ( !*pRules )
            break;
        if ((( strncasecmp( pRules, "RewriteCond", 11 ) == 0 )&&
             ( isspace( *(pRules + 11)) ))||
            (( strncasecmp( pRules, "RewriteRule", 11 ) == 0 )&&
             ( isspace( *(pRules + 11)) )))
        {
            RewriteRule * pRule = new RewriteRule();
            if ( !pRule )
            {
                ERR_NO_MEM( "new RewriteRule()" );
                return -1;
            }
            int ret = pRule->parse( pRules, pMapList );
            if ( ret )
            {
                delete pRule;
                return 0;
            }
            pLast->addNext( pRule );
            pLast = pRule;
        }
        else
        {
            char * pLineEnd = strchr( pRules, '\n' );
            if ( pLineEnd )
                *pLineEnd = 0;
            if ( *pRules != '#' )
            {
                LOG_ERR(( "Invalid rewrite directive: %s", pRules ));
            }
            if ( pLineEnd )
                *pLineEnd = '\n';
            else
                break;
            pRules = pLineEnd + 1;
        }
    }
    return 0;
}
Exemple #4
0
const double* LinkedObj::getSchemeDoublePtr( const QString &nm, int *lt,
        const LinkedObj **src_ob, int lev) const
{
  int clt = LinkNone;
  int *plt = ( lt ) ? lt : &clt;  // failsafe link

  if( isIgnored() || nm.isEmpty() ) {
    *plt = LinkNone;
    return nullptr;
  }

  LinkedObj *ds = qobject_cast<LinkedObj*>( par );  // parent-less object or root
  if( !ds ) {
    *plt = LinkBad;
    return nullptr;
  }
  return ds->getSchemeDoublePtr( nm, lt, src_ob, lev );
}
int RewriteSubstFormat::parse( const char * pFormatStr, const char * pEnd, const RewriteMapList * pMaps )
{
    while(( pFormatStr < pEnd )&&( isspace( *pFormatStr )))
        ++pFormatStr;
    int err = 0;
    LinkedObj * pLast = head();
    RewriteSubstItem * pItem;
    while( pFormatStr < pEnd )
    {
        pItem = new RewriteSubstItem();
        if ( !pItem )
        {
            ERR_NO_MEM( "new SubstItem()" );
            return -1;
        }
        
        switch( *pFormatStr )
        {
        case '$':
            if ( pFormatStr + 1 == pEnd )
            {
                HttpLog::parse_error( s_pCurLine,  "Line ended with '$'" );
                err = 1;
                break;
            }
            if ( *( pFormatStr + 1 ) == '{' )
            {
                if ( !pMaps )
                {
                    HttpLog::parse_error( s_pCurLine,  "No rewrite map defined" );
                    err = 1;
                    break;
                }
                pItem->setType( REF_MAP );
                MapRefItem * pMapRef = new MapRefItem();
                if ( !pMapRef )
                {
                    ERR_NO_MEM( "new MapRefItem()" );
                    err = 1;
                    break;
                }
                if ( pMapRef->parse( pFormatStr, pEnd, pMaps ) )
                {
                    delete pMapRef;
                    err = 1;
                    break;
                }
                pItem->setMapRef( pMapRef );
            }
            else if ( isdigit( *( pFormatStr + 1 ) ) )
            {
                pItem->setType( REF_RULE_SUBSTR );
                pItem->setIndex( *(pFormatStr + 1) - '0' );
                pFormatStr += 2;
            }
            else
            {
                HttpLog::parse_error( s_pCurLine,  "'$' should be followed by a digit for a RewriteRule backreference." );
                pItem->setType( REF_STRING );
                pItem->setStr( pFormatStr, 1 );
                ++pFormatStr;
            }
            break;
        case '%':
            if ( pFormatStr + 1 == pEnd )
            {
                HttpLog::parse_error( s_pCurLine,  "Line ended with '%'" );
                err = 1;
                break;
            }
            if ( *( pFormatStr + 1 ) == '{' )
            {
                ++pFormatStr;
                if ( pItem->parseServerVar( s_pCurLine, pFormatStr, pEnd ) )
                {
                    err = 1;
                    break;
                }
            }
            else if ( isdigit( *( pFormatStr + 1 ) ) )
            {
                pItem->setType( REF_COND_SUBSTR );
                pItem->setIndex( *(pFormatStr + 1) - '0' );
                pFormatStr += 2;
            }
            else
            {
                HttpLog::parse_error( s_pCurLine,  "'%' should be followed by a digit for a RewriteCond backreference." );
                pItem->setType( REF_STRING );
                pItem->setStr( pFormatStr, 1 );
                ++pFormatStr;
            }
            break;
        case '\\':
        default:
            pItem->parseString( pFormatStr, pEnd, "$%" );
            break;
        }
        if ( err )
        {
            delete pItem;
            return -1;
        }
        else
        {
            pLast->addNext( pItem );
            pLast = pItem;
        }
    }
    return 0;
}
int RewriteRule::parse( char * &pRule, const RewriteMapList * pMaps )
{
    char * pCur;
    char * pLineEnd;
    LinkedObj * pLast = m_conds.head();
    assert( pLast->next() == NULL );
    while( *pRule )
    {
        while( isspace( *pRule ) )
            ++pRule;
        if ( !*pRule )
            break;
        pCur = pRule;
        pLineEnd = strchr( pCur, '\n' );
        if ( !pLineEnd )
        {
            pLineEnd = pCur + strlen( pCur );
            pRule = pLineEnd;
        }
        else
        {
            pRule = pLineEnd + 1;
            *pLineEnd = 0;
        }
        s_pCurLine = pCur;
        if ( *pCur != '#' )
        {
            if (( strncasecmp( pCur, "RewriteCond", 11 ) == 0 )&&
                ( isspace( *(pCur + 11)) ))
            {
                RewriteCond * pCond = new RewriteCond();
                if ( !pCond )
                {
                    ERR_NO_MEM( "new RewriteCond()" );
                    return -1;
                }
                
                if ( pCond->parse( pCur+12, pLineEnd, pMaps ) )
                {
                    delete pCond;
                    HttpLog::parse_error( s_pCurLine,  "invalid rewrite condition" );
                    return -1;
                }
                pLast->addNext( pCond );
                pLast = pCond;
            }
            else if (( strncasecmp( pCur, "RewriteRule", 11 ) == 0 )&&
                     ( isspace( *(pCur + 11)) ))
            {
                int ret = parseRule( pCur+12, pLineEnd, pMaps );
                pCur = pLineEnd+1;
                return ret;
            }
            else
            {
                HttpLog::parse_error( s_pCurLine,  "invalid rewrite directive " );
                return -1;
            }
        }
    }

    return -1;
}
Exemple #7
0
const double* LinkedObj::getDoublePtr( const QString &nm, int *lt,
              const LinkedObj **targ, int lev  ) const
{
  static int clt;
  int *plt = lt ? lt : &clt;
  if( nm.isEmpty() ) {
    *plt = LinkNone; return nullptr;
  }
  if( isIgnored() ) {
    *plt = LinkBad;
    return nullptr;
  }
  QString nmf = nm, first, rest;

  int idx;
  NameType nm_type = splitName( nmf, first, rest, idx );
  if( nm_type == badName ) {
    *plt = LinkBad;
    qWarning() << "bad source name " << nmf << NWHE;
    return nullptr;
  }

  HolderData *ho = getObj( first );

  if( !ho ) {
    *plt = LinkBad;
    // qWarning() << "elem" << first << "not found, nmf= " << nmf << NWHE;
    return nullptr;
  }

  if( nm_type == simpleName ) { // -- simple name ----- first only -----
    LinkedObj *ds= qobject_cast<LinkedObj*>(ho);
    if( ds ) {
      return ds->getDoublePtr( QSL("out0"), plt, targ, lev+1 ); // default output
    }

    HolderDouble *hod = qobject_cast<HolderDouble*>(ho);
    if( hod ) {
      *plt = ( lev == 1 ) ? LinkElm : LinkSpec;
      if( targ ) {  *targ = this;   }
      return hod->caddr();
    }

    auto *hoda = qobject_cast<HolderDoubleArray*>(ho); // array special case
    if( hoda ) {
      int na = hoda->arrSize();
      if( idx >= na ) {
        qWarning() << "Bad index " << idx << " while access to " << hoda->getFullName()
                   << " size " << na << NWHE;
        *plt = LinkBad;
        return nullptr;
      }
      *plt = ( lev == 1 ) ? LinkElm : LinkSpec;
      if( targ ) {  *targ = this;   }
      return & ( hoda->operator[](idx) );
    }

    return nullptr;
  } // -------------------- simple name end ----------------------------

  // both part of name exists
  LinkedObj *ds = qobject_cast<LinkedObj*>(ho);
  if( !ds ) {
    *plt = LinkBad;
    qWarning() << "Complex name " << nm << " is given for simple object "
               << ho->getFullName() << NWHE;
    return nullptr;
  }
  return ds->getDoublePtr( rest, plt, targ, lev+1 ); // pass to child

}