Esempio n. 1
0
//-----------------------------------------------------------------------------
// nsHttpHeaderArray <public>
//-----------------------------------------------------------------------------
nsresult
nsHttpHeaderArray::SetHeader(nsHttpAtom header,
                             const nsACString &value,
                             bool merge)
{
    nsEntry *entry = nullptr;
    int32_t index;

    index = LookupEntry(header, &entry);

    // If an empty value is passed in, then delete the header entry...
    // unless we are merging, in which case this function becomes a NOP.
    if (value.IsEmpty()) {
        if (!merge && entry)
            mHeaders.RemoveElementAt(index);
        return NS_OK;
    }

    if (!entry) {
        entry = mHeaders.AppendElement(); // new nsEntry()
        if (!entry)
            return NS_ERROR_OUT_OF_MEMORY;
        entry->header = header;
        entry->value = value;
    } else if (merge && !IsSingletonHeader(header)) {
        MergeHeader(header, entry, value);
    } else {
        // Replace the existing string with the new value
        entry->value = value;
    }

    return NS_OK;
}
Esempio n. 2
0
nsresult
nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, const nsACString &value)
{
    nsEntry *entry = nsnull;
    PRInt32 index;

    index = LookupEntry(header, &entry);

    if (!entry) {
        if (value.IsEmpty())
            return NS_OK; // ignore empty headers
        entry = mHeaders.AppendElement(); //new nsEntry(header, value);
        if (!entry)
            return NS_ERROR_OUT_OF_MEMORY;
        entry->header = header;
        entry->value = value;
    } else if (!IsSingletonHeader(header)) {
        MergeHeader(header, entry, value);
    } else {
        // Multiple instances of non-mergeable header received from network
        // - ignore if same value
        if (!entry->value.Equals(value)) {
            if (IsSuspectDuplicateHeader(header)) {
                // reply may be corrupt/hacked (ex: CLRF injection attacks)
                return NS_ERROR_CORRUPTED_CONTENT;
            } // else silently drop value: keep value from 1st header seen
        }
    }

    return NS_OK;
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// nsHttpHeaderArray <public>
//-----------------------------------------------------------------------------
nsresult
nsHttpHeaderArray::SetHeader(nsHttpAtom header,
                             const nsACString &value,
                             bool merge,
                             nsHttpHeaderArray::HeaderVariety variety)
{
    MOZ_ASSERT((variety == eVarietyResponse) ||
               (variety == eVarietyRequestDefault) ||
               (variety == eVarietyRequestOverride),
               "Net original headers can only be set using SetHeader_internal().");

    nsEntry *entry = nullptr;
    int32_t index;

    index = LookupEntry(header, &entry);

    // If an empty value is passed in, then delete the header entry...
    // unless we are merging, in which case this function becomes a NOP.
    if (value.IsEmpty()) {
        if (!merge && entry) {
            if (entry->variety == eVarietyResponseNetOriginalAndResponse) {
                MOZ_ASSERT(variety == eVarietyResponse);
                entry->variety = eVarietyResponseNetOriginal;
            } else {
                mHeaders.RemoveElementAt(index);
            }
        }
        return NS_OK;
    }

    MOZ_ASSERT(!entry || variety != eVarietyRequestDefault,
               "Cannot set default entry which overrides existing entry!");
    if (!entry) {
        return SetHeader_internal(header, value, variety);
    } else if (merge && !IsSingletonHeader(header)) {
        return MergeHeader(header, entry, value, variety);
    } else {
        // Replace the existing string with the new value
        if (entry->variety == eVarietyResponseNetOriginalAndResponse) {
            MOZ_ASSERT(variety == eVarietyResponse);
            entry->variety = eVarietyResponseNetOriginal;
            return SetHeader_internal(header, value, variety);
        } else {
            entry->value = value;
            entry->variety = variety;
        }
    }

    return NS_OK;
}
//================================================================================
void test_ops(const string& absFilePath)
//================================================================================
{
    //==== parse file content
    output << "parsing file: " << absFilePath << endl;
    
//    StStruct* pou = 0;
    FunctionBlock* pou = 0;
//    Function* pou = 0;


    string SourceFile;
    BOOL grFile = FALSE;

    CString extension = CString(absFilePath.c_str()).Right(4);

    if (extension.Right(4).CompareNoCase(".4gr") == 0)
    {
        grFile = TRUE;
        ExtractHeader(absFilePath, SourceFile);
    }
    else
    {
        SourceFile = absFilePath;
    }

    //=== read file content
    string buf;
    readFileContent(SourceFile, buf);

    string err = parse_string(buf, &pou);

    StringPos insertPos;
    bool sectionExists;
    pou->getVarInsertPos("VAR_INPUT", "", insertPos, sectionExists);
//    pou->getVarInsertPos("STRUCT", "", insertPos, sectionExists);

    string varDecl = "    NewVar : DINT;\n";
    string varDeclSect = "\nVAR_INPUT\n" + varDecl + "END_VAR";
//    string varDeclSect = "\nSTRUCT\n" + varDecl + "END_VAR";

    if ( sectionExists )
    {
        buf.insert(insertPos, varDecl);
    }
    else
    {
        buf.insert(insertPos, varDeclSect);
    }

    output << buf << endl;

    if (grFile == TRUE)
    {
        string MHFile = "c:\\modifiedHeader.txt";
        ofstream modifiedHeader(MHFile.c_str());
        modifiedHeader << buf << endl;
        modifiedHeader.close();
        MergeHeader(absFilePath, MHFile, TRUE);
    }
    
    delete pou;
}
Esempio n. 5
0
nsresult
nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header,
                                    const nsACString &value,
                                    bool response)
{
    // mHeader holds the consolidated (merged or updated) headers.
    // mHeader for response header will keep the original heades as well.
    nsEntry *entry = nullptr;

    LookupEntry(header, &entry);

    if (!entry) {
        if (value.IsEmpty()) {
            if (!gHttpHandler->KeepEmptyResponseHeadersAsEmtpyString() &&
                !TrackEmptyHeader(header)) {
                LOG(("Ignoring Empty Header: %s\n", header.get()));
                if (response) {
                    // Set header as original but not as response header.
                    return SetHeader_internal(header, value,
                                              eVarietyResponseNetOriginal);
                }
                return NS_OK; // ignore empty headers by default
            }
        }
        HeaderVariety variety = eVarietyRequestOverride;
        if (response) {
            variety = eVarietyResponseNetOriginalAndResponse;
        }
        return SetHeader_internal(header, value, variety);

    } else if (!IsSingletonHeader(header)) {
        HeaderVariety variety = eVarietyRequestOverride;
        if (response) {
            variety = eVarietyResponse;
        }
        nsresult rv = MergeHeader(header, entry, value, variety);
        if (NS_FAILED(rv)) {
            return rv;
        }
        if (response) {
            rv = SetHeader_internal(header, value,
                                    eVarietyResponseNetOriginal);
        }
        return rv;
    } else {
        // Multiple instances of non-mergeable header received from network
        // - ignore if same value
        if (!entry->value.Equals(value)) {
            if (IsSuspectDuplicateHeader(header)) {
                // reply may be corrupt/hacked (ex: CLRF injection attacks)
                return NS_ERROR_CORRUPTED_CONTENT;
            } // else silently drop value: keep value from 1st header seen
            LOG(("Header %s silently dropped as non mergeable header\n",
                 header.get()));

        }
        if (response) {
            return SetHeader_internal(header, value,
                                      eVarietyResponseNetOriginal);
        }
    }

    return NS_OK;
}