reSIProcate/DialogUsageManager  9694
testCurlHttpProvider.cxx
Go to the documentation of this file.
00001 #include "resip/stack/TransactionUser.hxx"
00002 #include "CurlHttpProvider.hxx"
00003 #include "rutil/Logger.hxx"
00004 #include "resip/stack/external/HttpProvider.hxx"
00005 #include "resip/stack/external/HttpGetMessage.hxx"
00006 
00007 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
00008 
00009 using namespace resip;
00010 
00011 class TestCurlTransactionUser : public TransactionUser
00012 {
00013    public:
00014       virtual const Data& name() const 
00015       { 
00016          static Data n("TestCurlTransactionUser");
00017          return n;
00018       }
00019       TimeLimitFifo<Message>& getFifo() { return mFifo; }
00020    private:
00021 };
00022 
00023 int
00024 main(int argc, char* argv[])
00025 {
00026    Log::initialize(Log::Cout, Log::Debug, argv[0]);
00027    
00028    HttpProvider::setFactory(std::auto_ptr<HttpProviderFactory>(new CurlHttpProviderFactory()));
00029    
00030    GenericUri target;
00031    if (argc == 2)
00032    {
00033       InfoLog ( << "Looking up: " << argv[1]);
00034       target.uri() = argv[1];
00035    }
00036    else
00037    {
00038       target.uri() = "www.google.ca";
00039    }
00040    TestCurlTransactionUser testCurlTu;
00041    HttpProvider::instance()->get(target, "aaa", testCurlTu);
00042    
00043    Message* res = testCurlTu.getFifo().getNext(3000);
00044    if (res)
00045    {
00046       HttpGetMessage* msg = dynamic_cast<HttpGetMessage*>(res);
00047       assert(msg);
00048       InfoLog( << "Received: " << *msg);
00049       delete msg;
00050    }
00051    else
00052    {
00053       InfoLog( << "Reqeust timed out");
00054       exit(-1);
00055    }
00056    return 0;
00057 }
00058 
00059 /* ====================================================================
00060  * The Vovida Software License, Version 1.0 
00061  * 
00062  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00063  * 
00064  * Redistribution and use in source and binary forms, with or without
00065  * modification, are permitted provided that the following conditions
00066  * are met:
00067  * 
00068  * 1. Redistributions of source code must retain the above copyright
00069  *    notice, this list of conditions and the following disclaimer.
00070  * 
00071  * 2. Redistributions in binary form must reproduce the above copyright
00072  *    notice, this list of conditions and the following disclaimer in
00073  *    the documentation and/or other materials provided with the
00074  *    distribution.
00075  * 
00076  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00077  *    and "Vovida Open Communication Application Library (VOCAL)" must
00078  *    not be used to endorse or promote products derived from this
00079  *    software without prior written permission. For written
00080  *    permission, please contact vocal@vovida.org.
00081  *
00082  * 4. Products derived from this software may not be called "VOCAL", nor
00083  *    may "VOCAL" appear in their name, without prior written
00084  *    permission of Vovida Networks, Inc.
00085  * 
00086  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00087  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00088  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00089  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00090  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00091  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00092  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00093  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00094  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00095  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00096  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00097  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00098  * DAMAGE.
00099  * 
00100  * ====================================================================
00101  * 
00102  * This software consists of voluntary contributions made by Vovida
00103  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00104  * Inc.  For more information on Vovida Networks, Inc., please see
00105  * <http://www.vovida.org/>.
00106  *
00107  */