Ejemplo n.º 1
0
    /*!a Test case to test the destroyAll()
    *    method.
    */
    void testClearAndDestroy()
    {
        const char* prefix  = "test the destroyAll() method " ;

        const char* suffix1 = ":- Verify that all entries are removed" ; 
        const char* suffix2 = ":- The objects are deleted" ;

        UtlContainableTestStub* uStub ;
        UtlContainableTestStub* uStubPtr ;
        uStub = new UtlContainableTestStub(0) ; 
        uStubPtr = new UtlContainableTestStub(1) ;
        emptyList.append(uStub) ;
        emptyList.append(uStubPtr) ;

        emptyList.destroyAll() ;
        int cCountAfter = UtlContainableTestStub::getCount() ; 

        string msg ;
        TestUtilities::createMessage(2, &msg, prefix, suffix1) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ; 

        // Since the TestStub has been implemented such that destructor
        // decrements the static counter, to verify that the objects have
        // been deleted, verify that the static counter has been decremented. 
        TestUtilities::createMessage(2, &msg, prefix, suffix2) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;

    } //testClearAndDestroy
Ejemplo n.º 2
0
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);
}