Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

RCF - Interprocess Communication for C++

, 25 Oct 2011
A server/client IPC framework, using the C++ preprocessor as an IDL compiler.
rcf-04.zip
RCF-0.4
demo
vs2003
RCF
Client
Server
doc
html
class_r_c_f_1_1_exception.png
class_r_c_f_1_1_filter.png
class_r_c_f_1_1_filter_factory.png
class_r_c_f_1_1_filter_service.png
class_r_c_f_1_1_identity_filter.png
class_r_c_f_1_1_identity_filter_factory.png
class_r_c_f_1_1_i___client_transport.png
class_r_c_f_1_1_i___endpoint.png
class_r_c_f_1_1_i___service.png
class_r_c_f_1_1_i___session_manager.png
class_r_c_f_1_1_multicast_client_transport.png
class_r_c_f_1_1_object_factory_service.png
class_r_c_f_1_1_open_ssl_encryption_filter.png
class_r_c_f_1_1_open_ssl_encryption_filter_factory.png
class_r_c_f_1_1_publishing_service.png
class_r_c_f_1_1_rcf_server.png
class_r_c_f_1_1_remote_exception.png
class_r_c_f_1_1_subscription_service.png
class_r_c_f_1_1_tcp_endpoint.png
class_r_c_f_1_1_udp_endpoint.png
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.png
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.png
doxygen.png
ftv2blank.png
ftv2doc.png
ftv2folderclosed.png
ftv2folderopen.png
ftv2lastnode.png
ftv2link.png
ftv2mlastnode.png
ftv2mnode.png
ftv2node.png
ftv2plastnode.png
ftv2pnode.png
ftv2vertline.png
tab_b.gif
tab_l.gif
tab_r.gif
latex
annotated.tex
class_r_c_f_1_1_client_stub.tex
class_r_c_f_1_1_exception.eps
class_r_c_f_1_1_exception.tex
class_r_c_f_1_1_filter.eps
class_r_c_f_1_1_filter.tex
class_r_c_f_1_1_filter_description.tex
class_r_c_f_1_1_filter_factory.eps
class_r_c_f_1_1_filter_factory.tex
class_r_c_f_1_1_filter_service.eps
class_r_c_f_1_1_filter_service.tex
class_r_c_f_1_1_identity_filter.eps
class_r_c_f_1_1_identity_filter.tex
class_r_c_f_1_1_identity_filter_factory.eps
class_r_c_f_1_1_identity_filter_factory.tex
class_r_c_f_1_1_i___client_transport.eps
class_r_c_f_1_1_i___client_transport.tex
class_r_c_f_1_1_i___endpoint.eps
class_r_c_f_1_1_i___endpoint.tex
class_r_c_f_1_1_i___proactor.tex
class_r_c_f_1_1_i___rcf_client.tex
class_r_c_f_1_1_i___server_transport.tex
class_r_c_f_1_1_i___server_transport_ex.tex
class_r_c_f_1_1_i___service.eps
class_r_c_f_1_1_i___service.tex
class_r_c_f_1_1_i___session.tex
class_r_c_f_1_1_i___session_manager.eps
class_r_c_f_1_1_i___session_manager.tex
class_r_c_f_1_1_multicast_client_transport.eps
class_r_c_f_1_1_multicast_client_transport.tex
class_r_c_f_1_1_object_factory_service.eps
class_r_c_f_1_1_object_factory_service.tex
class_r_c_f_1_1_open_ssl_encryption_filter.eps
class_r_c_f_1_1_open_ssl_encryption_filter.tex
class_r_c_f_1_1_open_ssl_encryption_filter_factory.eps
class_r_c_f_1_1_open_ssl_encryption_filter_factory.tex
class_r_c_f_1_1_publishing_service.eps
class_r_c_f_1_1_publishing_service.tex
class_r_c_f_1_1_rcf_server.eps
class_r_c_f_1_1_rcf_server.tex
class_r_c_f_1_1_remote_exception.eps
class_r_c_f_1_1_remote_exception.tex
class_r_c_f_1_1_subscription_service.eps
class_r_c_f_1_1_subscription_service.tex
class_r_c_f_1_1_tcp_endpoint.eps
class_r_c_f_1_1_tcp_endpoint.tex
class_r_c_f_1_1_udp_endpoint.eps
class_r_c_f_1_1_udp_endpoint.tex
class_r_c_f_1_1_zlib_stateful_compression_filter.tex
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.eps
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.tex
class_r_c_f_1_1_zlib_stateless_compression_filter.tex
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.eps
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.tex
dirs.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2F.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2F.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2FProtocol_2F.tex
doxygen.sty
Helvetica.ttf
hierarchy.tex
Makefile
refman.tex
struct_r_c_f_1_1_filter_id_comparison.tex
include
RCF
Marshal.inl
Protocol
RcfServer.inl
ServerStub.inl
test
util
Platform
Machine
SPARC
x86
OS
Unix
Windows
Threads
SF
src
RCF
Protocol
SF
test
borland
Jamfile
Jamrules
Jamfile
Jamrules
vs2003
RCF
RCF
RCFTest
client.pem
server.pem
rcf-09c.zip
RCF-0.9c
demo
vs2003
RCF
Client
Server
include
RCF
Marshal.inl
Protocol
RcfServer.inl
ServerStub.inl
test
util
Platform
Machine
SPARC
x86
OS
Unix
Windows
Threads
SF
src
RCF
Protocol
util
SF
test
bcc
Jamfile
Jamrules
data
caCertA.pem
caCertB.pem
certA.pem
certB.pem
ssCert1.pem
ssCert2.pem
Jamfile
Jamrules
vc6
Jamfile
Jamrules
#include <vector>

#include <boost/config.hpp>

#include <RCF/test/TestMinimal.hpp>

#include <RCF/Idl.hpp>
#include <RCF/RcfServer.hpp>
#include <RCF/FilterService.hpp>
#include <RCF/ObjectFactoryService.hpp>
#include <RCF/OpenSslEncryptionFilter.hpp>
//#include <RCF/SspiFilter.hpp>
#include <RCF/TcpEndpoint.hpp>
#include <RCF/UdpEndpoint.hpp>
#include <RCF/ZlibCompressionFilter.hpp>

#include <RCF/util/CommandLine.hpp>
#include <RCF/util/PortNumbers.hpp>
#include <RCF/util/Platform/OS/Sleep.hpp>

#include <RCF/test/TransportFactories.hpp>

namespace Test_Filters {

    RCF_BEGIN(X, "X")
        RCF_METHOD_R0(int, func)
    RCF_END(X)

    class ServerImpl
    {
    public:
        ServerImpl() : ret(1)
        {}

        int func()
        {
            return ret++;
        }

    private:
        int ret;
    };

    // consider a filter chain to be removable if all its filters are removable
    bool isFilterChainRemovable(const std::vector<RCF::FilterPtr> &filterChain)
    {
        for (unsigned int i=0; i<filterChain.size(); ++i)
        {
            if (!filterChain[i]->getFilterDescription().getRemovable())
            {
                return false;
            }
        }
        return true;
    }

    void testServerErrorHandling()
    {
        std::string ip = "127.0.0.1";
        int port = util::PortNumbers::getSingleton().getNext();
        RCF::RcfServer server(RCF::TcpEndpoint(ip, port));

        ServerImpl serverImpl;
        server.bind( (X*) 0, serverImpl);

        server.start();

        {
            RcfClient<X> client(RCF::TcpEndpoint(ip, port));
            try
            {
                client.getClientStub().requestTransportFilters( RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
                int ret = client.func();
                BOOST_CHECK(1==0);
            }
            catch(RCF::Exception &e)
            {
                BOOST_CHECK(1==1);
            }
        }

        // add a filter service, but no filter factories
        RCF::FilterServicePtr filterServicePtr(new RCF::FilterService);
        server.addService( RCF::ServicePtr(filterServicePtr));

        {
            RcfClient<X> client(RCF::TcpEndpoint(ip, port));
            try
            {
                bool ok = client.getClientStub().queryForTransportFilters( RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
                BOOST_CHECK(!ok);
                client.getClientStub().requestTransportFilters( RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
                BOOST_CHECK(1==0);
                int ret = client.func();
                BOOST_CHECK(1==0);
            }
            catch(RCF::Exception &e)
            {
                BOOST_CHECK(1==1);
            }
        }

        // add a filter factory
        filterServicePtr->addFilterFactory( RCF::FilterFactoryPtr( new RCF::ZlibStatefulCompressionFilterFactory()));

        {
            RcfClient<X> client(RCF::TcpEndpoint(ip, port));
            try
            {
                bool ok = client.getClientStub().queryForTransportFilters( RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
                BOOST_CHECK(ok);
                client.getClientStub().requestTransportFilters( RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
                int ret = client.func();
                BOOST_CHECK(1==1);
            }
            catch(RCF::Exception &e)
            {
                BOOST_CHECK(1==0);
            }
        }

    }

    void testTransportFilters(
        const std::vector< RCF::FilterFactoryPtr > &filterFactories,
        const std::vector< std::vector<RCF::FilterPtr> > &filterChains,
        RCF::ServerTransportPtr serverTransportPtr,
        RCF::ClientTransportAutoPtr clientTransportAutoPtr)
    {

        RCF::RcfServer server(serverTransportPtr);

        RCF::FilterServicePtr filterServicePtr(new RCF::FilterService);
        for (unsigned int i=0; i<filterFactories.size(); ++i)
        {
            filterServicePtr->addFilterFactory(filterFactories[i]);
        }
        server.addService( RCF::ServicePtr(filterServicePtr));

        RCF::ObjectFactoryServicePtr objectFactoryServicePtr( new RCF::ObjectFactoryService(60, 60));
        //objectFactoryServicePtr->bind<X, ServerImpl>();
        objectFactoryServicePtr->bind( (X*) 0, (ServerImpl**) 0);
        server.addService( RCF::ServicePtr(objectFactoryServicePtr));

        ServerImpl serverImpl;
        server.bind( (X*) 0, serverImpl);

        server.start();

        int ret = 0;

        for (unsigned int i=0; i<filterChains.size(); ++i)
        {
            for (unsigned int j=0; j<2; ++j)
            {
                std::auto_ptr< RcfClient<X> > clientAutoPtr( new RcfClient<X>(clientTransportAutoPtr->clone()));
                int ret0 = 0;
                if (j == 0)
                {
                    //bool ok = RCF::createRemoteObject<X>(*clientAutoPtr);
                    bool ok = tryCreateRemoteObject<X>(*clientAutoPtr);
                    BOOST_CHECK(ok);
                }
                int &myret = j == 0 ? ret0 : ret;
                RcfClient<X> &client = *clientAutoPtr;

                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);

                if (j > 0)
                {
                    std::for_each(filterChains[i].begin(), filterChains[i].end(), boost::bind(&RCF::Filter::reset, _1));
                }
                client.getClientStub().requestTransportFilters(filterChains[i]);

                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);

                client.getClientStub().disconnect();

                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);

                if (!isFilterChainRemovable(filterChains[i]))
                {
                    client.getClientStub().clearTransportFilters();
                }
                else
                {
                    client.getClientStub().requestTransportFilters(std::vector<RCF::FilterPtr>());
                }

                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);

                // reinstate the filter chain, have to reset the filters first
                std::for_each(filterChains[i].begin(), filterChains[i].end(), boost::bind(&RCF::Filter::reset, _1));
                client.getClientStub().requestTransportFilters(filterChains[i]);

                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                BOOST_CHECK(client.func(RCF::Twoway) == ++myret);

                // check that auto reconnect works properly
                // can only expect this to work with filters that don't put any extra data on the wire
                if (isFilterChainRemovable(filterChains[i]))
                {
                    //server.stop();
                    server.close();
                    server.start();

                    BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                    BOOST_CHECK(client.func(RCF::Twoway) == ++myret);
                }
            }
        }
    }

    void testTransportFilters(
        const std::vector< RCF::FilterFactoryPtr > &filterFactories,
        const std::vector< std::vector<RCF::FilterPtr> > &filterChains)
    {
        for (unsigned int i=0; i<RCF::getTransportFactories().size(); ++i)
        {
            RCF::TransportFactoryPtr transportFactoryPtr = RCF::getTransportFactories()[i];
            std::pair<RCF::ServerTransportPtr, RCF::ClientTransportAutoPtrPtr> transports = transportFactoryPtr->createTransports();
            RCF::ServerTransportPtr serverTransportPtr( transports.first );
            RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

            if (transportFactoryPtr->isConnectionOriented())
            {
                // reset the client filter chains
                for(std::size_t j=0; j<filterChains.size(); ++j)
                {
                    std::for_each(
                        filterChains[j].begin(),
                        filterChains[j].end(),
                        boost::bind(&RCF::Filter::reset, _1));
                }

                testTransportFilters(
                    filterFactories,
                    filterChains,
                    serverTransportPtr,
                    clientTransportAutoPtr);
            }
        }
    }


    void testStatefulPayloadFilters(
        const std::vector< RCF::FilterFactoryPtr > &filterFactories,
        const std::vector< std::vector<RCF::FilterPtr> > &filterChains)
    {

        std::string ip = "localhost";
        int port = util::PortNumbers::getSingleton().getNext();

        RCF::TcpEndpoint serverEndpoint(port);
        RCF::TcpEndpoint clientEndpoint(ip, port);

        RCF::RcfServer server(serverEndpoint);

        RCF::FilterServicePtr filterServicePtr(new RCF::FilterService);
        for (unsigned int i=0; i<filterFactories.size(); ++i)
        {
            filterServicePtr->addFilterFactory(filterFactories[i]);
        }
        server.addService( RCF::ServicePtr(filterServicePtr));

        ServerImpl serverImpl;
        server.bind( (X*) 0, serverImpl);

        server.start();

        int ret = 0;

        for (unsigned int i=0; i<filterChains.size(); ++i)
        {
            const std::vector<RCF::FilterPtr> &filterChain = filterChains[i];

            RcfClient<X> client(clientEndpoint);
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+1 );

            client.getClientStub().setMessageFilters(filterChain);
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+2 );
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+3 );

            client.getClientStub().setMessageFilters(std::vector<RCF::FilterPtr>());
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+4 );

            client.getClientStub().setMessageFilters(filterChain);
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+5 );
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+6 );
        }

    }

    void testStatelessPayloadFilters(
        const std::vector< RCF::FilterFactoryPtr > &filterFactories,
        const std::vector< std::vector<RCF::FilterPtr> > &filterChains)
    {

        std::string ip = "127.0.0.1";
        int port = util::PortNumbers::getSingleton().getNext();

#ifndef RCF_TEST_NO_UDP
        RCF::UdpEndpoint serverEndpoint(port);
        RCF::UdpEndpoint clientEndpoint(ip, port);
#else
        RCF::TcpEndpoint serverEndpoint(port);
        RCF::TcpEndpoint clientEndpoint(ip, port);
#endif

        RCF::RcfServer server(serverEndpoint);

        RCF::FilterServicePtr filterServicePtr(new RCF::FilterService);
        for (unsigned int i=0; i<filterFactories.size(); ++i)
        {
            filterServicePtr->addFilterFactory(filterFactories[i]);
        }
        server.addService( RCF::ServicePtr(filterServicePtr));

        ServerImpl serverImpl;
        server.bind( (X*) 0, serverImpl);

        server.start();

        int ret = 0;

        for (unsigned int i=0; i<filterChains.size(); ++i)
        {
            const std::vector<RCF::FilterPtr> &filterChain = filterChains[i];

            RcfClient<X> client(clientEndpoint);
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+1 );

            client.getClientStub().setMessageFilters(filterChain);
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+2 );
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+3 );

            client.getClientStub().setMessageFilters(std::vector<RCF::FilterPtr>());
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+4 );

            client.getClientStub().setMessageFilters(filterChain);
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+5 );
            ret = client.func(RCF::Twoway); BOOST_CHECK( ret == 6*i+6 );
        }

    }


    void testOnewayFilters(const std::vector<RCF::FilterPtr> &filterChain1, const std::vector<RCF::FilterPtr> &filterChain2)
    {
        std::string testData = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#�%&/()=";
        for (int i=0; i<256; ++i)
        {
            testData += char(i);
        }
        for (int i=0; i<1000; i++)
        {
            testData += rand() % 256;
        }

        std::string unfilteredData(testData);

        for (int i=0; i<10; ++i)
        {
            unfilteredData = unfilteredData + testData;
            bool ok = false;

            std::vector<RCF::ByteBuffer> unfilteredBuffers;
            std::vector<RCF::ByteBuffer> filteredBuffers;
            RCF::ByteBuffer unfilteredBuffer;
            RCF::ByteBuffer filteredBuffer;

            unfilteredBuffers.push_back( RCF::ByteBuffer(
                (char*) unfilteredData.c_str(),
                unfilteredData.length(),
                true));

            ok = RCF::filterData(unfilteredBuffers, filteredBuffers, filterChain1);
            BOOST_CHECK(ok);
            RCF::copyByteBuffers(filteredBuffers, filteredBuffer);
            ok = RCF::unfilterData(filteredBuffer, unfilteredBuffer, static_cast<int>(unfilteredData.length()), filterChain2);
            BOOST_CHECK(ok);
            std::string result(unfilteredBuffer.getPtr(), unfilteredBuffer.getLength());
            BOOST_CHECK( result == unfilteredData );
        }

    }

    void testOnewayFilters(RCF::FilterPtr filterPtr1, RCF::FilterPtr filterPtr2)
    {
        std::vector<RCF::FilterPtr> filterChain1;
        filterChain1.push_back(filterPtr1);

        std::vector<RCF::FilterPtr> filterChain2;
        filterChain2.push_back(filterPtr2);

        testOnewayFilters(filterChain1, filterChain2);
    }

} // namespace Test_Filters

int RCF_TEST_MAIN(int argc, char **argv)
{

    printTestHeader(__FILE__);

#if defined(__MINGW32__) && __GNUC__ < 3

    BOOST_CHECK(1==0 && "Bizarre failures (crashes) with mingw 2.95.");
    return boost::exit_success;

#endif

    using namespace Test_Filters;

    util::CommandLineOption<std::string> scert("scert", TEMP_DIR "ssCert2.pem", "OpenSSL server certificate");
    util::CommandLineOption<std::string> spwd("spwd", "mt2316", "OpenSSL server certificate password");
    util::CommandLineOption<std::string> ccert("ccert", TEMP_DIR "ssCert1.pem", "OpenSSL client certificate");
    util::CommandLineOption<std::string> cpwd("cpwd", "mt2316", "OpenSSL client certificate password");

    util::CommandLine::getSingleton().parse(argc, argv);

    std::string clientCertificateFile = ccert;
    std::string clientCertificateFilePassword = cpwd;
    std::string serverCertificateFile = scert;
    std::string serverCertificateFilePassword = spwd;

    testOnewayFilters(RCF::FilterPtr( new RCF::IdentityFilter()), RCF::FilterPtr( new RCF::IdentityFilter()));
    testOnewayFilters(RCF::FilterPtr( new RCF::XorFilter()), RCF::FilterPtr( new RCF::XorFilter()));

    // TODO: figure out why this fails when using certain combinations of small buffer sizes for the zlib filters (<100 bytes)
    testOnewayFilters(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()), RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    testOnewayFilters(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()), RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));

    std::vector<RCF::FilterFactoryPtr> filterFactories;
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::IdentityFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::XorFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::ZlibStatelessCompressionFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::ZlibStatefulCompressionFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::OpenSslEncryptionFilterFactory(serverCertificateFile, serverCertificateFilePassword)));

    std::vector< std::vector<RCF::FilterPtr> > filterChains;
    std::vector<RCF::FilterPtr> filterChain;

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));

    filterChains.push_back(filterChain);

    testStatefulPayloadFilters(filterFactories, filterChains);

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));

    filterChains.push_back(filterChain);

    testStatelessPayloadFilters(filterFactories, filterChains);

    testServerErrorHandling();

    filterFactories.clear();
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::IdentityFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::XorFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::ZlibStatelessCompressionFilterFactory(7)));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::ZlibStatefulCompressionFilterFactory(7)));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::OpenSslEncryptionFilterFactory(serverCertificateFile, serverCertificateFilePassword)));

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(7)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(7)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    // watch out for rapidly growing stack size requirements on the client side, when chaining
    // filters together
    // ...

    testTransportFilters(filterFactories, filterChains/*, serverTransportPtr, clientTransportAutoPtr*/);

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(7)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(7)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    filterChains.clear();
    filterChain.clear();
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::XorFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
#ifndef __BORLANDC__
    // TODO: why does triple openssl fail on borland?
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
#endif
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(7)));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(7)));
    filterChain.push_back(RCF::FilterPtr( new RCF::IdentityFilter()));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(7)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(7)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(4096)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(4096)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    filterFactories.clear();
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::IdentityFilterFactory()));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::ZlibStatelessCompressionFilterFactory(4096)));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::ZlibStatefulCompressionFilterFactory(4096)));
    filterFactories.push_back( RCF::FilterFactoryPtr( new RCF::OpenSslEncryptionFilterFactory(serverCertificateFile, serverCertificateFilePassword)));

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(7)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(7)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter(4096)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter(4096)));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    filterChains.clear();

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

#if defined(BOOST_WINDOWS) && !defined(__BORLANDC__)
    // TODO: why does this test fail on gcc (Solaris, Linux, prob'ly Cygwin, but not mingw), and on borland ?
    std::cout << "testing ->ssl->stateful compression-> transport filter" << std::endl;
    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatefulCompressionFilter()));
    filterChains.push_back(filterChain);
#endif

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChains.push_back(filterChain);

    filterChain.clear();
    filterChain.push_back(RCF::FilterPtr( new RCF::OpenSslEncryptionFilter(clientCertificateFile, clientCertificateFilePassword)));
    filterChain.push_back(RCF::FilterPtr( new RCF::ZlibStatelessCompressionFilter()));
    filterChains.push_back(filterChain);

    testTransportFilters(filterFactories, filterChains);

    return boost::exit_success;

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jarl Lindrud

Australia Australia
Software developer, ex-resident of Sweden and now living in Canberra, Australia, working on distributed C++ applications. Jarl enjoys programming, but prefers skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

| Advertise | Privacy | Mobile
Web01 | 2.8.140902.1 | Last Updated 25 Oct 2011
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid