reSIProcate/DialogUsageManager  9694
Public Member Functions | Static Private Member Functions | Private Attributes
resip::CurlHttpProvider::RequestThread Class Reference
Inheritance diagram for resip::CurlHttpProvider::RequestThread:
Inheritance graph
[legend]
Collaboration diagram for resip::CurlHttpProvider::RequestThread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RequestThread (const GenericUri &target, const Data &tid, TransactionUser &tu)
virtual void thread ()
virtual ~RequestThread ()

Static Private Member Functions

static int curlCallback (void *ptr, size_t size, size_t nmemb, void *stream)

Private Attributes

GenericUri mTarget
Data mTid
TransactionUsermTransactionUser
Data mX509Blob
DataStream mStream

Detailed Description

Definition at line 22 of file CurlHttpProvider.hxx.


Constructor & Destructor Documentation

CurlHttpProvider::RequestThread::RequestThread ( const GenericUri target,
const Data tid,
TransactionUser tu 
)

Definition at line 35 of file CurlHttpProvider.cxx.

                                                  :
   mTarget(target),
   mTid(tid),
   mTransactionUser(tu),
   mX509Blob(),
   mStream(mX509Blob)
{}
CurlHttpProvider::RequestThread::~RequestThread ( ) [virtual]

Definition at line 45 of file CurlHttpProvider.cxx.

{
}

Member Function Documentation

int CurlHttpProvider::RequestThread::curlCallback ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  stream 
) [static, private]

Definition at line 107 of file CurlHttpProvider.cxx.

References InfoLog.

Referenced by thread().

{
   DataStream* ds = reinterpret_cast<DataStream*>(stream);
   assert(size == 1);
   ds->write(reinterpret_cast<const char*>(ptr), nmemb);
   InfoLog ( << "Wrote: " << nmemb << " to stream" );   
   return nmemb;
}
void CurlHttpProvider::RequestThread::thread ( ) [virtual]

Implements resip::ThreadIf.

Definition at line 50 of file CurlHttpProvider.cxx.

References curlCallback(), resip::Data::Empty, and InfoLog.

{
   CURL *curl = curl_easy_init();
   if (!curl)
   {
       HttpGetMessage* res = new HttpGetMessage(mTid, false, Data::Empty, Mime());
       mTransactionUser.post(res);
   }

   curl_easy_setopt(curl, CURLOPT_URL, mTarget.uri().c_str());
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, RequestThread::curlCallback);
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, &mStream);
   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
   
   int code = 404;
   curl_easy_perform(curl);
#if ( LIBCURL_VERSION_NUM > 0x070a07 )
   curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
#else
   curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &code);
#endif
   InfoLog ( << "Curl returned: " << code);   

    if (code / 100 == 2) 
    {
        //.dcm.  vodoo to trick the lazy parsers, should add convenience methods to
        //clean this up
        Mime contentType; 
        {
           char* contentTypeString;
           curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &contentTypeString);

           InfoLog ( << "Content type from curl: " << contentTypeString);
           
           if (contentTypeString)
           {
              HeaderFieldValue tmp(contentTypeString, strlen(contentTypeString));
              Mime tempMime(&tmp, Headers::ContentType);
              contentType = tempMime;
              delete contentTypeString;          
           }
        }
        mStream.flush();        
        HttpGetMessage* res = new HttpGetMessage(mTid, true, mX509Blob, contentType);
        mTransactionUser.post(res);
    }
    else
    {
       HttpGetMessage* res = new HttpGetMessage(mTid, false, Data::Empty, Mime());
       mTransactionUser.post(res);
    }
    curl_easy_cleanup(curl);

    delete this;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 33 of file CurlHttpProvider.hxx.

Definition at line 29 of file CurlHttpProvider.hxx.

Definition at line 30 of file CurlHttpProvider.hxx.

Definition at line 31 of file CurlHttpProvider.hxx.

Definition at line 32 of file CurlHttpProvider.hxx.


The documentation for this class was generated from the following files: