// Since the test setup / preconditions for the index, find, // contains and containsReference are all the same, these // tests have been combined into one utility function. Based // on the type argument, the method to be tested is varied. void utlTestIndex_Find_And_Contains(IndexOrContains type) { const int testCount = 7 ; const char* prefixIndex = "Test the index() method when the match " ; const char* prefixFind = "Test the find() method when the match " ; const char* prefixContains = "Test the contains() method when the match " ; const char* prefixContainsRef = "Test the containsReference() method when the match " ; const char* Msgs[] = { \ "is the first element ", \ "is the last element ", \ "is a mid element (unique match) ", \ "has two value matches but a single ref match ", \ "has two ref matches", \ "has a value match but no ref match", \ "has no match at all" \ } ; // insert a clone of the 4th element to the 1st position commonList.insertAt(1, commonContainables_Clone[4]) ; // The new index for a value match of commonContainables[4] must be 1. // insert another copy of the 3rd element to the 2nd position. commonList.insertAt(2, commonContainables[3]) ; // The new index for commonContainables[3] must be 2) ; // what used to be the second element has now moved to 4. UtlString noExist("This cannot and should not exist!!!") ; UtlContainable* searchValues[] = { \ commonContainables[0], commonContainables[5], commonContainables[2], \ commonContainables[4], commonContainables[3], \ commonContainables_Clone[2], &noExist \ } ; size_t expectedValues_Index[] = { 0, 7, 4, 1, 2, 4, UTL_NOT_FOUND } ; bool expectedValues_Contains[] = {true, true, true, true, true, true, false } ; bool expectedValues_ContainsRef[] = {true, true, true, true, true, false, false} ; UtlContainable* searchValuesForFind[] = { \ commonContainables[0], commonContainables[5], commonContainables[2], \ commonContainables[4], commonContainables[3], \ commonContainables_Clone[1], &noExist \ } ; UtlContainable* expectedValuesForFind[] = { \ commonContainables[0], commonContainables[5], commonContainables[2], \ commonContainables_Clone[4], commonContainables[3], \ commonContainables[1], NULL \ } ; for (int i = 0 ; i < testCount ; i++) { string msg ; if (type == TEST_INDEX) { size_t actual = commonList.index(searchValues[i]) ; TestUtilities::createMessage(2, &msg, prefixIndex, Msgs[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_Index[i], actual) ; } else if (type == TEST_FIND) { UtlContainable* actual = commonList.find(searchValuesForFind[i]) ; TestUtilities::createMessage(2, &msg, prefixFind, Msgs[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValuesForFind[i], actual) ; } else if (type == TEST_CONTAINS) { UtlBoolean actual = commonList.contains(searchValues[i]) ; TestUtilities::createMessage(2, &msg, prefixContains, Msgs[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_Contains[i], \ (TRUE == actual)) ; } else if (type == TEST_CONTAINS_REF) { UtlBoolean actual = commonList.containsReference(searchValues[i]) ; TestUtilities::createMessage(2, &msg, prefixContainsRef, Msgs[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_ContainsRef[i], \ (TRUE == actual)) ; } } }//utlTestIndex
UtlBoolean SmimeBody::decrypt(const char* derPkcs12, int derPkcs12Length, const char* pkcs12Password) { UtlBoolean decryptionSucceeded = FALSE; UtlString decryptedData; #ifdef ENABLE_OPENSSL_SMIME decryptionSucceeded = opensslSmimeDecrypt(derPkcs12, derPkcs12Length, pkcs12Password, (mContentEncoding == SMIME_ENODING_BASE64), mBody.data(), mBody.length(), decryptedData); #elif ENABLE_NSS_SMIME Os::Logger::instance().log(FAC_SIP, PRI_ERR, "NSS S/MIME decrypt not implemented"); #endif // Decryption succeeded, so create a HttpBody for the result if(decryptionSucceeded && decryptedData.length() > 0) { HttpBody* newDecryptedBody = NULL; // Need to read the headers before the real body to see // what the content type of the decrypted body is UtlDList bodyHeaders; int parsedBytes = HttpMessage::parseHeaders(decryptedData.data(), decryptedData.length(), bodyHeaders); UtlString contentTypeName(HTTP_CONTENT_TYPE_FIELD); NameValuePair* contentType = (NameValuePair*) bodyHeaders.find(&contentTypeName); UtlString contentEncodingName(HTTP_CONTENT_TRANSFER_ENCODING_FIELD); NameValuePair* contentEncoding = (NameValuePair*) bodyHeaders.find(&contentEncodingName); const char* realBodyStart = decryptedData.data() + parsedBytes; int realBodyLength = decryptedData.length() - parsedBytes; newDecryptedBody = HttpBody::createBody(realBodyStart, realBodyLength, contentType ? contentType->getValue() : NULL, contentEncoding ? contentEncoding->getValue() : NULL); bodyHeaders.destroyAll(); // If one already exists, delete it. This should not typically // be the case. Infact it might make sense to make this method // a no-op if a decrypted body already exists if(mpDecryptedBody) { delete mpDecryptedBody; mpDecryptedBody = NULL; } mpDecryptedBody = newDecryptedBody; } return(decryptionSucceeded); }