Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UrlImplCurl.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Cinder Project (http://libcinder.org)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Url.h"
26 
27 typedef void CURL;
28 typedef void CURLM;
29 
30 namespace cinder {
31 
32 class IStreamUrlImplCurl : public IStreamUrlImpl {
33  public:
34  IStreamUrlImplCurl( const std::string &url, const std::string &user, const std::string &password );
36 
37  virtual size_t readDataAvailable( void *dest, size_t maxSize );
38  virtual void seekAbsolute( off_t absoluteOffset );
39  virtual void seekRelative( off_t relativeOffset );
40  virtual off_t tell() const;
41  virtual off_t size() const;
42 
43  virtual bool isEof() const;
44  virtual void IORead( void *t, size_t size );
45 
46  private:
47  int bufferRemaining() const { return mBufferedBytes - mBufferOffset; }
48  void fillBuffer( int wantBytes ) const;
49 
50  static size_t writeCallback( char *buffer, size_t size, size_t nitems, void *userp );
51 
52  CURL *mCurl;
53  CURLM *mMulti;
54 
55  std::string mUserColonPassword;
56 
57  mutable int still_running; // Is background url fetch still in progress
58  mutable bool mStartedRead;
59 
60  mutable off_t mSize;
61  mutable bool mSizeCached;
62  mutable long mResponseCode;
63  mutable char *mEffectiveUrl;
64 
65  mutable uint8_t *mBuffer;
66  mutable int mBufferSize;
67  mutable int mBufferOffset, mBufferedBytes;
68  mutable off_t mBufferFileOffset; // where in the file the buffer starts
69  static const int DEFAULT_BUFFER_SIZE = 4096;
70 };
71 
72 } // namespace cinder
GLsizei const GLchar ** string
Definition: GLee.h:2427
virtual size_t readDataAvailable(void *dest, size_t maxSize)
Definition: UrlImplCurl.cpp:283
virtual bool isEof() const
Definition: UrlImplCurl.cpp:144
~IStreamUrlImplCurl()
Definition: UrlImplCurl.cpp:132
virtual off_t tell() const
Definition: UrlImplCurl.cpp:169
GLuint buffer
Definition: GLee.h:2065
virtual void IORead(void *t, size_t size)
Definition: UrlImplCurl.cpp:271
virtual void seekAbsolute(off_t absoluteOffset)
Definition: UrlImplCurl.cpp:164
Definition: UrlImplCurl.h:32
void CURLM
Definition: UrlImplCurl.h:28
virtual void seekRelative(off_t relativeOffset)
Definition: UrlImplCurl.cpp:149
void CURL
Definition: UrlImplCurl.h:27
GLdouble GLdouble t
Definition: GLee.h:1426
virtual off_t size() const
Definition: UrlImplCurl.cpp:174
IStreamUrlImplCurl(const std::string &url, const std::string &user, const std::string &password)
Definition: UrlImplCurl.cpp:66