void
nsHttpResponseHead::ParseHeaderLine(const char *line)
{
    nsHttpAtom hdr = {0};
    char *val;

    mHeaders.ParseHeaderLine(line, &hdr, &val);
    // leading and trailing LWS has been removed from |val|

    // handle some special case headers...
    if (hdr == nsHttp::Content_Length) {
        PRInt64 len;
        // permit only a single value here.
        if (nsHttp::ParseInt64(val, &len))
            mContentLength = len;
        else
            LOG(("invalid content-length!\n"));
    }
    else if (hdr == nsHttp::Content_Type) {
        LOG(("ParseContentType [type=%s]\n", val));
        PRBool dummy;
        net_ParseContentType(nsDependentCString(val),
                             mContentType, mContentCharset, &dummy);
    }
    else if (hdr == nsHttp::Cache_Control)
        ParseCacheControl(val);
    else if (hdr == nsHttp::Pragma)
        ParsePragma(val);
}
Ejemplo n.º 2
0
void DoPragma (void)
/* Handle pragmas. These come always in form of the new C99 _Pragma() operator. */
{
    /* Skip the token itself */
    NextToken ();

    /* We expect an opening paren */
    if (!ConsumeLParen ()) {
        return;
    }

    /* String literal */
    if (CurTok.Tok != TOK_SCONST) {

        /* Print a diagnostic */
        Error ("String literal expected");

        /* Try some smart error recovery: Skip tokens until we reach the
         * enclosing paren, or a semicolon.
         */
        PragmaErrorSkip ();

    } else {

        /* Parse the _Pragma statement */
        ParsePragma ();
    }

    /* Closing paren needed */
    ConsumeRParen ();
}
Ejemplo n.º 3
0
bool ppPragma::Check(int token, const std::string &args)
{
    if (token == PRAGMA)
    {
        ParsePragma(args);
        return true;
    }
    return false;
}
Ejemplo n.º 4
0
nsresult
nsHttpResponseHead::SetHeader(nsHttpAtom hdr,
                              const nsACString &val,
                              bool merge)
{
    nsresult rv = mHeaders.SetHeader(hdr, val, merge);
    if (NS_FAILED(rv)) return rv;

    // respond to changes in these headers.  we need to reparse the entire
    // header since the change may have merged in additional values.
    if (hdr == nsHttp::Cache_Control)
        ParseCacheControl(mHeaders.PeekHeader(hdr));
    else if (hdr == nsHttp::Pragma)
        ParsePragma(mHeaders.PeekHeader(hdr));

    return NS_OK;
}
Ejemplo n.º 5
0
nsresult
nsHttpResponseHead::ParseHeaderLine(const char *line)
{
    nsHttpAtom hdr = {0};
    char *val;
    nsresult rv;

    rv = mHeaders.ParseHeaderLine(line, &hdr, &val);
    if (NS_FAILED(rv))
        return rv;

    // leading and trailing LWS has been removed from |val|

    // handle some special case headers...
    if (hdr == nsHttp::Content_Length) {
        int64_t len;
        const char *ignored;
        // permit only a single value here.
        if (nsHttp::ParseInt64(val, &ignored, &len)) {
            mContentLength = len;
        }
        else {
            // If this is a negative content length then just ignore it
            LOG(("invalid content-length! %s\n", val));
        }
    }
    else if (hdr == nsHttp::Content_Type) {
        LOG(("ParseContentType [type=%s]\n", val));
        bool dummy;
        net_ParseContentType(nsDependentCString(val),
                             mContentType, mContentCharset, &dummy);
    }
    else if (hdr == nsHttp::Cache_Control)
        ParseCacheControl(val);
    else if (hdr == nsHttp::Pragma)
        ParsePragma(val);
    return NS_OK;
}
nsresult
nsHttpResponseHead::ParseHeaderLine(const char *line)
{
    nsHttpAtom hdr = {0};
    char *val;
    nsresult rv;
    
    rv = mHeaders.ParseHeaderLine(line, &hdr, &val);
    if (NS_FAILED(rv))
        return rv;
    
    // leading and trailing LWS has been removed from |val|

    // handle some special case headers...
    if (hdr == nsHttp::Content_Length) {
        PRInt64 len;
        // permit only a single value here.
        if (nsHttp::ParseInt64(val, &len)) {
            mContentLength = len;
        }
        else {
            LOG(("invalid content-length!\n"));
            return NS_ERROR_CORRUPTED_CONTENT;
        }
    }
    else if (hdr == nsHttp::Content_Type) {
        LOG(("ParseContentType [type=%s]\n", val));
        PRBool dummy;
        net_ParseContentType(nsDependentCString(val),
                             mContentType, mContentCharset, &dummy);
    }
    else if (hdr == nsHttp::Cache_Control)
        ParseCacheControl(val);
    else if (hdr == nsHttp::Pragma)
        ParsePragma(val);
    return NS_OK;
}
void Preprocessor::RecursivePreprocess( std::string filename, FileLoader& file_source, LexemList& lexems, DefineTable& define_table )
{
    unsigned int start_line = CurrentLine;
    LinesThisFile = 0;
    CurrentFile = filename;
    SetFileMacro( define_table, CurrentFile );
    SetLineMacro( define_table, LinesThisFile );

    // Path formatting must be done in main application
    std::string CurrentFileRoot = RootPath + CurrentFile;
    if( std::find( FilesPreprocessed.begin(), FilesPreprocessed.end(), CurrentFileRoot ) == FilesPreprocessed.end() )
        FilesPreprocessed.push_back( CurrentFileRoot );

    std::vector<char> data;
    bool              loaded = file_source.LoadFile( RootPath, filename, data );
    if( !loaded )
    {
        PrintErrorMessage( std::string( "Could not open file " ) + RootPath + filename );
        return;
    }

    if( data.size() == 0 )
        return;
    char* d_end = &data[data.size() - 1];
    ++d_end;
    Lex( &data[0], d_end, lexems );

    LexemList::iterator itr = lexems.begin();
    LexemList::iterator end = lexems.end();
    LLITR               old = end;
    while( itr != end )
    {
        if( itr->Type == Lexem::NEWLINE )
        {
            if( itr != old )
            {
                CurrentLine++;
                LinesThisFile++;
                SetLineMacro( define_table, LinesThisFile );
            }
            old = itr;
            ++itr;
        }
        else if( itr->Type == Lexem::PREPROCESSOR )
        {
            LLITR     start_of_line = itr;
            LLITR     end_of_line = ParsePreprocessor( lexems, itr, end );

            LexemList directive( start_of_line, end_of_line );

            if( SkipPragmas && directive.begin()->Value == "#pragma" )
            {
                itr = end_of_line;
                Lexem wspace;
                wspace.Type = Lexem::WHITESPACE;
                wspace.Value = " ";
                for( LLITR it = start_of_line; it != end_of_line;)
                {
                    ++it;
                    it = lexems.insert( it, wspace );
                    ++it;
                }
                continue;
            }

            itr = lexems.erase( start_of_line, end_of_line );

            std::string value = directive.begin()->Value;
            if( value == "#define" )
            {
                ParseDefine( define_table, directive );
            }
            else if( value == "#ifdef" )
            {
                std::string           def_name;
                ParseIf( directive, def_name );
                DefineTable::iterator dti = define_table.find( def_name );
                if( dti == define_table.end() )
                {
                    LLITR splice_to = ParseIfDef( itr, end );
                    itr = lexems.erase( itr, splice_to );
                }
            }
            else if( value == "#ifndef" )
            {
                std::string           def_name;
                ParseIf( directive, def_name );
                DefineTable::iterator dti = define_table.find( def_name );
                if( dti != define_table.end() )
                {
                    LLITR splice_to = ParseIfDef( itr, end );
                    itr = lexems.erase( itr, splice_to );
                }
            }
            else if( value == "#if" )
            {
                bool satisfied = EvaluateExpression( define_table, directive ) != 0;
                if( !satisfied )
                {
                    LLITR splice_to = ParseIfDef( itr, end );
                    itr = lexems.erase( itr, splice_to );
                }
            }
            else if( value == "#endif" )
            {
                // ignore
            }
            else if( value == "#include" )
            {
                if( LNT )
                    LNT->AddLineRange( PrependRootPath( filename ), start_line, CurrentLine - LinesThisFile );
                unsigned int save_lines_this_file = LinesThisFile;
                std::string  file_name;
                ParseIf( directive, file_name );

                std::string file_name_ = RemoveQuotes( file_name );
                if( IncludeTranslator )
                    IncludeTranslator->Call( file_name_ );
                if( std::find( FileDependencies.begin(), FileDependencies.end(), file_name_ ) == FileDependencies.end() )
                    FileDependencies.push_back( file_name_ );

                LexemList next_file;
                RecursivePreprocess( AddPaths( filename, file_name_ ), file_source, next_file, define_table );
                lexems.splice( itr, next_file );
                start_line = CurrentLine;
                LinesThisFile = save_lines_this_file;
                CurrentFile = filename;
                SetFileMacro( define_table, CurrentFile );
                SetLineMacro( define_table, LinesThisFile );
            }
            else if( value == "#pragma" )
            {
                ParsePragma( directive );
            }
            else if( value == "#message" )
            {
                std::string message;
                ParseTextLine( directive, message );
                PrintMessage( message );
            }
            else if( value == "#warning" )
            {
                std::string warning;
                ParseTextLine( directive, warning );
                PrintWarningMessage( warning );
            }
            else if( value == "#error" )
            {
                std::string error;
                ParseTextLine( directive, error );
                PrintErrorMessage( error );
            }
            else
            {
                PrintErrorMessage( "Unknown directive '" + value + "'." );
            }
        }
        else if( itr->Type == Lexem::IDENTIFIER )
        {
            itr = ExpandDefine( itr, end, lexems, define_table );
        }
        else
        {
            ++itr;
        }
    }

    if( LNT )
        LNT->AddLineRange( PrependRootPath( filename ), start_line, CurrentLine - LinesThisFile );
}