ZNC  trunk
CurlSock.h
Go to the documentation of this file.
1 
32 #ifndef HAVE_CURLSOCK_H
33 #define HAVE_CURLSOCK_H
34 
35 #include "Csocket.h"
36 #include <curl/curl.h>
37 
38 #ifndef _NO_CSOCKET_NS
39 namespace Csocket
40 {
41 #endif /* _NO_CSOCKET_NS */
42 
59 {
60 public:
62  virtual ~CCurlSock();
63 
65  virtual bool GatherFDsForSelect( std::map< int, int16_t > & miiReadyFds, long & iTimeoutMS );
67  virtual bool CheckFDs( const std::map< int, int16_t > & miiReadyFds ) { return( m_bEnabled ); }
68 
78  CURL * Retr( const CS_STRING & sURL, const CS_STRING & sReferrer = "" );
79 
80 protected:
82  virtual void OnCURLComplete( CURL * pCURL ) = 0;
83 
85  virtual size_t OnHeader( CURL * pCURL, const char * pData, size_t uBytes ) { return( uBytes ); }
87  virtual size_t OnBody( CURL * pCURL, const char * pData, size_t uBytes ) { return( uBytes ); }
88 
89 private:
90  static size_t WriteData( void * pData, size_t uSize, size_t uNemb, void * pStream );
91  static size_t WriteHeader( void * pData, size_t uSize, size_t uNemb, void * pStream );
92  static int SetupSock( CURL * pCurlHandle, curl_socket_t iFD, int iWhat, void * pcbPtr, void * pSockPtr );
93  static int SetupTimer( CURLM * pMulti, long iTimeout_ms, void * pcdPtr );
94 
95  void SetTimeoutMS( long iTimeoutMS )
96  {
97  m_iTimeout_ms = iTimeoutMS;
98  }
99 
100  long m_iTimeout_ms;
101  CURLM * m_pMultiHandle;
102  std::map< CURL *, bool > m_pcbCurlHandles;
103 };
104 
105 #ifndef _NO_CSOCKET_NS
106 };
107 #endif /* _NO_CSOCKET_NS */
108 
109 #endif /* HAVE_CURLSOCK_H */
110 
#define CS_EXPORT
Definition: Csocket.h:136
Csocket style wrapper around libcurl-multi.
Definition: CurlSock.h:59
virtual ~CCurlSock()
CURL * Retr(const CS_STRING &sURL, const CS_STRING &sReferrer="")
initiates a GET style transfer, but the process doesn't get started until the next GatherFDsForSelect...
virtual bool CheckFDs(const std::map< int, int16_t > &miiReadyFds)
reimplement this to do nothing as its not needed
Definition: CurlSock.h:67
virtual bool GatherFDsForSelect(std::map< int, int16_t > &miiReadyFds, long &iTimeoutMS)
the hook we tie into to get events from csocket
virtual size_t OnHeader(CURL *pCURL, const char *pData, size_t uBytes)
called as header information for the document is returned
Definition: CurlSock.h:85
virtual void OnCURLComplete(CURL *pCURL)=0
called when the transfer associate with this CURL object is completed
virtual size_t OnBody(CURL *pCURL, const char *pData, size_t uBytes)
called as the document is returned
Definition: CurlSock.h:87
Class to tie sockets to for monitoring by Csocket at either the Csock or TSockManager.
Definition: Csocket.h:458
#define CS_STRING
Definition: include/znc/defines.h:27