Esempio n. 1
0
static KeyValueMap retrieveKeyValuePairs(WebCore::SharedBufferChunkReader* buffer)
{
    KeyValueMap keyValuePairs;
    String line;
    String key;
    StringBuilder value;
    while (!(line = buffer->nextChunkAsUTF8StringWithLatin1Fallback()).isNull()) {
        if (line.isEmpty())
            break; // Empty line means end of key/value section.
        if (line[0] == '\t') {
            ASSERT(!key.isEmpty());
            value.append(line.substring(1));
            continue;
        }
        // New key/value, store the previous one if any.
        if (!key.isEmpty()) {
            if (keyValuePairs.find(key) != keyValuePairs.end())
                LOG_ERROR("Key duplicate found in MIME header. Key is '%s', previous value replaced.", key.ascii().data());
            keyValuePairs.add(key, value.toString().stripWhiteSpace());
            key = String();
            value.clear();
        }
        size_t semiColonIndex = line.find(':');
        if (semiColonIndex == notFound) {
            // This is not a key value pair, ignore.
            continue;
        }
        key = line.substring(0, semiColonIndex).lower().stripWhiteSpace();
        value.append(line.substring(semiColonIndex + 1));
    }
    // Store the last property if there is one.
    if (!key.isEmpty())
        keyValuePairs.set(key, value.toString().stripWhiteSpace());
    return keyValuePairs;
}
Esempio n. 2
0
bool
mitk::TestDICOMLoading::CompareImageInformationDumps( const std::string& referenceDump,
                                                      const std::string& testDump )
{
  KeyValueMap reference = ParseDump(referenceDump);
  KeyValueMap test = ParseDump(testDump);

  bool testResult(true);

  // verify all expected values
  for (KeyValueMap::const_iterator refIter = reference.begin();
       refIter != reference.end();
       ++refIter)
  {
    const std::string& refKey = refIter->first;
    const std::string& refValue = refIter->second;

    if ( test.find(refKey) != test.end() )
    {
      const std::string& testValue = test[refKey];

      bool thisTestResult = CompareSpacedValueFields( refValue, testValue );
      testResult &= thisTestResult;

      MITK_DEBUG << refKey << ": '" << refValue << "' == '" << testValue << "' ? " << (thisTestResult?"YES":"NO");
    }
    else
    {
      MITK_ERROR << "Reference dump contains a key'" << refKey << "' (value '" << refValue << "')." ;
      MITK_ERROR << "This key is expected to be generated for tests (but was not). Most probably you need to update your test data.";
      return false;
    }
  }

  // now check test dump does not contain any additional keys
  for (KeyValueMap::const_iterator testIter = test.begin();
       testIter != test.end();
       ++testIter)
  {
    const std::string& key = testIter->first;
    const std::string& value = testIter->second;

    if ( reference.find(key) == reference.end() )
    {
      MITK_ERROR << "Test dump contains an unexpected key'" << key << "' (value '" << value << "')." ;
      MITK_ERROR << "This key is not expected. Most probably you need to update your test data.";
      return false;
    }
  }

  return testResult;
}
Esempio n. 3
0
PassRefPtr<MIMEHeader> MIMEHeader::parseHeader(SharedBufferChunkReader* buffer)
{
    RefPtr<MIMEHeader> mimeHeader = adoptRef(new MIMEHeader);
    KeyValueMap keyValuePairs = retrieveKeyValuePairs(buffer);
    KeyValueMap::iterator mimeParametersIterator = keyValuePairs.find("content-type");
    if (mimeParametersIterator != keyValuePairs.end()) {
        ParsedContentType parsedContentType(mimeParametersIterator->value);
        mimeHeader->m_contentType = parsedContentType.mimeType();
        if (!mimeHeader->isMultipart())
            mimeHeader->m_charset = parsedContentType.charset().stripWhiteSpace();
        else {
            mimeHeader->m_multipartType = parsedContentType.parameterValueForName("type");
            mimeHeader->m_endOfPartBoundary = parsedContentType.parameterValueForName("boundary");
            if (mimeHeader->m_endOfPartBoundary.isNull()) {
                LOG_ERROR("No boundary found in multipart MIME header.");
                return 0;
            }
            mimeHeader->m_endOfPartBoundary.insert("--", 0);
            mimeHeader->m_endOfDocumentBoundary = mimeHeader->m_endOfPartBoundary;
            mimeHeader->m_endOfDocumentBoundary.append("--");
        }
    }

    mimeParametersIterator = keyValuePairs.find("content-transfer-encoding");
    if (mimeParametersIterator != keyValuePairs.end())
        mimeHeader->m_contentTransferEncoding = parseContentTransferEncoding(mimeParametersIterator->value);

    mimeParametersIterator = keyValuePairs.find("content-location");
    if (mimeParametersIterator != keyValuePairs.end())
        mimeHeader->m_contentLocation = mimeParametersIterator->value;

    return mimeHeader.release();
}
Esempio n. 4
0
void GameSpySupport::DumpKeyValueMapToBuffer(KeyValueMap& theMap, char* outbuf, unsigned int maxlen)
{
	AutoCrit aCrit(mDataCrit);

	unsigned int pos = 0;
	unsigned int pairlength = 0;

	KeyValueMap::iterator anItr = theMap.begin();
	for (; anItr != theMap.end(); ++anItr)
	{
		pairlength = anItr->first.length() + anItr->second.length() + 2; // add 2 for the seperating '\'
		
		if (pairlength < (maxlen-pos))
			sprintf(outbuf+pos, "\\%s\\%s", anItr->first.c_str(), anItr->second.c_str());

		pos += pairlength;
	}
}
ConfigVarPtr ConfigManager::getConfigValue (KeyValueMap &map, const std::string& name, const std::string& defaultValue, unsigned int flags)
{
	const std::string& savedValue = _persister->getValue(name);
	std::string val = savedValue;
	if (val.empty()) {
		KeyValueMap::iterator i = map.find(name);
		if (i != map.end()) {
			val = i->second;
			map.erase(i);
		}
	}
	if (val.empty())
		val = defaultValue;

	if (!savedValue.empty())
		Log::info(LOG_CONFIG, "use stored value '%s' for key '%s'", val.c_str(), name.c_str());
	else
		Log::info(LOG_CONFIG, "use value '%s' for key '%s'", val.c_str(), name.c_str());
	const ConfigVarPtr& p = getConfigVar(name, val, true, flags);
	return p;
}
Esempio n. 6
0
ConfigVarPtr ConfigManager::getConfigValue (KeyValueMap &map, const std::string& name, const std::string& defaultValue, unsigned int flags)
{
	// we need this no-persist check here, because this wasn't available in every version
	const std::string savedValue = (flags & CV_NOPERSIST) != 0 ? "" : _persister->getValue(name);
	std::string val = savedValue;
	if (val.empty()) {
		KeyValueMap::iterator i = map.find(name);
		if (i != map.end()) {
			val = i->second;
			map.erase(i);
		}
	}
	if (val.empty())
		val = defaultValue;

	if (!savedValue.empty())
		Log::info(LOG_COMMON, "use stored value '%s' for key '%s'", val.c_str(), name.c_str());
	else
		Log::info(LOG_COMMON, "use value '%s' for key '%s'", val.c_str(), name.c_str());
	const ConfigVarPtr& p = getConfigVar(name, val, true, flags);
	return p;
}
Esempio n. 7
0
MIMEHeader* MIMEHeader::parseHeader(SharedBufferChunkReader* buffer) {
  MIMEHeader* mimeHeader = MIMEHeader::create();
  KeyValueMap keyValuePairs = retrieveKeyValuePairs(buffer);
  KeyValueMap::iterator mimeParametersIterator =
      keyValuePairs.find("content-type");
  if (mimeParametersIterator != keyValuePairs.end()) {
    ParsedContentType parsedContentType(mimeParametersIterator->value);
    mimeHeader->m_contentType = parsedContentType.mimeType();
    if (!mimeHeader->isMultipart()) {
      mimeHeader->m_charset = parsedContentType.charset().stripWhiteSpace();
    } else {
      mimeHeader->m_multipartType =
          parsedContentType.parameterValueForName("type");
      mimeHeader->m_endOfPartBoundary =
          parsedContentType.parameterValueForName("boundary");
      if (mimeHeader->m_endOfPartBoundary.isNull()) {
        DVLOG(1) << "No boundary found in multipart MIME header.";
        return nullptr;
      }
      mimeHeader->m_endOfPartBoundary.insert("--", 0);
      mimeHeader->m_endOfDocumentBoundary = mimeHeader->m_endOfPartBoundary;
      mimeHeader->m_endOfDocumentBoundary.append("--");
    }
  }

  mimeParametersIterator = keyValuePairs.find("content-transfer-encoding");
  if (mimeParametersIterator != keyValuePairs.end())
    mimeHeader->m_contentTransferEncoding =
        parseContentTransferEncoding(mimeParametersIterator->value);

  mimeParametersIterator = keyValuePairs.find("content-location");
  if (mimeParametersIterator != keyValuePairs.end())
    mimeHeader->m_contentLocation = mimeParametersIterator->value;

  // See rfc2557 - section 8.3 - Use of the Content-ID header and CID URLs.
  mimeParametersIterator = keyValuePairs.find("content-id");
  if (mimeParametersIterator != keyValuePairs.end())
    mimeHeader->m_contentID = mimeParametersIterator->value;

  return mimeHeader;
}
Esempio n. 8
0
 void writeKeyValueMap(KeyValueMap& kv, FILE* file) {
     for(KeyValueMap::iterator it= kv.begin(); it != kv.end(); ++it)
         fprintf(file, "%s = %s\n", it->first.c_str(), it->second.first.c_str());
 }