Beispiel #1
0
bool
Parser::parseMinusNumber(
    int& num
    )
{
#ifdef DEBUG_PARSER
    fprintf( stderr, "parseMinusNumber\n" );
#endif /* DEBUG_PARSER */

    switch( peek() )
    {
    case LEXTOK_MINUS:
        if( !match( LEXTOK_MINUS ) )
            return false;

        num = -peekInt();
        return match( LEXTOK_NUMBER );

    case LEXTOK_NUMBER:
        num = peekInt();
        return match( LEXTOK_NUMBER );

    default:
        return error();
    }
}
Beispiel #2
0
/*
 * Execute the ANEWARRAY instruction
 */
void op_anewarray() {
    Ref type = resolve(u16(1), ID_TYPE);
    if (type == NULL) { return; } // rollback, gc done
    Ref arrayType = getRef(type, TYPE_ARRAY_TYPE);

    // resolve array type
    if (arrayType == NULL) {
        Ref target = getRef(core, OBJECT_TYPE);
        Ref method = getRef(core, CORE_RESOLVE_METHOD);
        executeMethod(target, method, 0);
        return; // rollback
    }

    // allocate space
    int length = peekInt(); // don't pop yet in case gc runs
    int numWords = ARRAY_DATA + length;
    Ref array = allocate(numWords, HEADER_OBJECT_ARRAY);
    if (array == NULL) { return; } // rollback, gc done
    popInt(); // pop length

    // initialise array object and push on stack
    int hash = (char*) array - (char*) core;
    setInt(array, OBJECT_HASHCODE, hash);
    setRef(array, OBJECT_TYPE, arrayType);
    setInt(array, ARRAY_LENGTH, length);
    pushRef(array);
    pc += 3;
}
Beispiel #3
0
bool
Parser::parseExpr5(
    AstExprNode*& expr
    )
{
    std::string name;

#ifdef DEBUG_PARSER
    fprintf( stderr, "parseExpr5\n" );
#endif /* DEBUG_PARSER */

    switch( peek() )
    {
        // Expr5:
    case LEXTOK_IDENT:
        name = peekStr();

        return match( LEXTOK_IDENT )
            && parseExpr5Ident( name, expr );

    case LEXTOK_NUMBER:
        expr = new AstIntExprNode( peekInt() );

        return match( LEXTOK_NUMBER );

    case LEXTOK_LPAR:
        return match( LEXTOK_LPAR )
            && parseExpr0( expr )
            && match( LEXTOK_RPAR );

    default:
        return error();
    }
}
Beispiel #4
0
/*
 * Execute the NEWARRAY instruction
 */
void op_newarray() {
    // figure out the required size
    int atype = u8(1);
    int width = getWidth(atype);
    int length = peekInt(); // don't pop in case rolled back later
    int numBytes = length * width;
    int extra = ((numBytes % 4) == 0) ? 0 : 1;
    int numDataWords = (numBytes / 4) + extra;
    int numWords = numDataWords + ARRAY_DATA;

    // allocate space
    Ref array = allocate(numWords, HEADER_DATA_ARRAY);
    if (array == NULL) { return; } // rollback, gc done
    popInt(); // can pop the length now

    // initialise new array and push address on stack
    int hash = (char*) array - (char*) core;
    Ref type = getRef(core, CORE_ARRAYS + atype);
    setInt(array, OBJECT_HASHCODE, hash);
    setRef(array, OBJECT_TYPE, type);
    setInt(array, ARRAY_LENGTH, length);
    pushRef(array);
    pc += 2;
}
Beispiel #5
0
int JConn::readRespHeader( unsigned char *&p, unsigned char *pEnd )
{
    while( m_iNumHeader > 0 )
    {
        if ( pEnd - p < 4 )
            return 0;
        unsigned char id1 = *p;
        unsigned char id2;
        int headerNameLen;
        const char * pHeaderName;
        unsigned char * p1;
        if ( id1 == 0xA0 )
        {
            id2 = *(p+1);
            if (( id2 > 0 )&&( id2 <= AJP_RESP_HEADERS_NUM ))
            {
                pHeaderName = JkAjp13::getRespHeaderById( id2 );
                headerNameLen = JkAjp13::getRespHeaderLenById( id2 );
                p1 = p + 2;
            }
            else
            {
                //invalid header id
                return -1;
            }
        }
        else
        {
            headerNameLen = id1 << 8 | *(p+1);
            if ( pEnd - p < headerNameLen + 5 )
                return 0;
            pHeaderName = (const char *)p + 2;
            p1 = p + headerNameLen + 3;
        }
        int headerValLen = peekInt( p1 );
        if ( pEnd - p1 < headerValLen + 3 )
            return 0;
        char * pHeaderVal = (char *)p1 + 2;
        p = p1 + headerValLen + 3;
        --m_iNumHeader;
        HttpResp * pResp = getConnector()->getHttpConn()->getResp();
        int ret = pResp->appendHeader(
                    pHeaderName, headerNameLen, pHeaderVal, headerValLen );
        if ( ret )
            return ret;
        HttpReq * pReq = getConnector()->getHttpConn()->getReq();
        if ( pReq->gzipAcceptable() )
        {
            if ( *pHeaderName == 'C' || *pHeaderName == 'c' )
            {
                if ( strcasecmp( pHeaderName, "content-type" ) == 0 )
                {
                    char * p = (char *)memchr( pHeaderVal, ';', headerValLen );
                    if ( !p )
                        p = pHeaderVal + headerValLen;
                    register char ch;
                    ch = *p;
                    *p = 0;
                    if ( !HttpGlobals::getMime()->compressable( pHeaderVal ) )
                        pReq->andGzip( ~GZIP_ENABLED );
                    *p = ch;
                }
                else if ( strcasecmp( pHeaderName, "content-encoding" ) == 0 )
                {
                    pReq->andGzip( ~GZIP_ENABLED );
                }
            }
        }
    }
    getConnector()->getRespState() |= HttpReq::HEADER_OK;
    return getConnector()->respHeaderDone( m_pCurPos - p );
}
Beispiel #6
0
int JConn::processPacketContent( unsigned char * &p, unsigned char * pEnd )
{
    int ret = 0;
    switch( m_iPacketState )
    {
    case CHUNK_LEN:
        if ( pEnd - p >= 2 )
        {
            m_chunkLeft = getInt( p );
            assert( m_chunkLeft == m_curPacketSize - 4 );
            m_iPacketState = CHUNK_DATA;
        }
        else
            break;
        //fall through
    case CHUNK_DATA:
        if ( pEnd - p > 0 )
        {
            int len = m_chunkLeft;
            if ( pEnd - p < len )
                len = pEnd - p;
            if ( len > 0 )
            {
                if ( !((getConnector()->getState() &
                     (HEC_ABORT_REQUEST|HEC_ERROR|HEC_COMPLETE|HEC_REDIRECT))) )
                    ret = getConnector()->processRespBodyData( 0, (const char *)p, len );
                p += len;
                m_chunkLeft -= len;
            }
            if ( p < pEnd )
                ++p;
        }
        break;
    case STATUS_CODE:
        if ( pEnd - p >= 2 )
        {
            int code = getInt( p );
            code = HttpStatusCode::codeToIndex( code );
            if ( code != -1 )
            {
                getConnector()->getHttpConn()->getReq()->updateNoRespBodyByStatus( code );
                
            }
            m_iPacketState = STATUS_MSG;
        }
        else
            break;
        //fall through
    case STATUS_MSG:
        if ( pEnd - p > 2 )
        {
            int strLen = peekInt( p );
            if ( strLen + 2 < pEnd - p )
            {
                p += strLen + 3;    //skip status message as we don't use it
                m_iPacketState = NUM_HEADERS;
            }
            else
                break;
        }
        else
            break;
        //fall through
    case NUM_HEADERS:
        if ( pEnd - p >= 2 )
        {
            m_iNumHeader = getInt( p );
            m_iPacketState = RESP_HEADER;
        }
        else
            break;
        //fall through
    case RESP_HEADER:
        ret = readRespHeader( p, pEnd );
    default:
        p = pEnd;
        break;
    }
    return ret;
    
}
Beispiel #7
0
static void peek() {
  if (current.kind == tNONE) {
    while (1) {
      current.value = 0;
      current.ptr = 0;

      const int c = peekChar();
      switch (c) {
        case -1:
          current.kind = tEND;
          return;
        case ';':
          consumeChar();
          current.kind = tSEMI;
          return;
        case '0' ... '9':
          peekInt();
          return;
        case 'a' ... 'z':
          peekId();
          return;
        case '(':
          consumeChar();
          current.kind = tLEFT;
          return;
        case ')':
          consumeChar();
          current.kind = tRIGHT;
          return;
        case '{':
          consumeChar();
          current.kind = tLBRACE;
          return;
        case '}':
          consumeChar();
          current.kind = tRBRACE;
          return;
        case '+':
          consumeChar();
          current.kind = tPLUS;
          return;
        case '*':
          consumeChar();
          current.kind = tMUL;
          return;
        case '=':
          consumeChar();
          if (peekChar() == '=') {
            consumeChar();
            current.kind = tEQEQ;
          } else {
            current.kind = tEQ;
          }
          return;
        case '<':
          consumeChar();
          if (peekChar() == '>') {
            consumeChar();
            current.kind = tNE;
          } else {
            current.kind = tLT;
          }
          return;
        case '>':
          consumeChar();
          current.kind = tGT;
          return;
        case ',':
          consumeChar();
          current.kind = tCOMMA;
          return;
        case ' ':
        case 10:
          consumeChar();
          break;
        default:
          printf("undefined char %d\n", c);
          error();
      }
    }
  }
}