llurlrequest.h

Go to the documentation of this file.
00001 
00034 #ifndef LL_LLURLREQUEST_H
00035 #define LL_LLURLREQUEST_H
00036 
00042 #include <string>
00043 #include "lliopipe.h"
00044 #include "llchainio.h"
00045 
00046 class LLURLRequestDetail;
00047 
00048 class LLURLRequestComplete;
00049 
00063 class LLURLRequest : public LLIOPipe
00064 {
00065 public:
00069         enum ERequestAction
00070         {
00071                 INVALID,
00072                 HTTP_GET,
00073                 HTTP_PUT,
00074                 HTTP_POST,
00075                 HTTP_DELETE,
00076                 REQUEST_ACTION_COUNT
00077         };
00078 
00084         LLURLRequest(ERequestAction action);
00085 
00092         LLURLRequest(ERequestAction action, const std::string& url);
00093 
00097         virtual ~LLURLRequest();
00098 
00099         /* @name Instance methods
00100          */
00102 
00111         void setURL(const std::string& url);
00112 
00122         void addHeader(const char* header);
00123 
00132         void checkRootCertificate(bool check, const char* caBundle = NULL);
00133 
00140         void requestEncoding(const char* encoding);
00141 
00149         void setBodyLimit(U32 size);
00150 
00165         void setCallback(LLURLRequestComplete* callback);
00167 
00171         static void setCertificateAuthorityFile(const std::string& file_name);
00172 
00176         static void setCertificateAuthorityPath(const std::string& path);
00177 
00178         /* @name LLIOPipe virtual implementations
00179          */
00180 
00184     void useProxy(bool use_proxy);
00185 
00186 public:
00190         virtual EStatus handleError(EStatus status, LLPumpIO* pump);
00191         
00192 protected:
00196         virtual EStatus process_impl(
00197                 const LLChannelDescriptors& channels,
00198                 buffer_ptr_t& buffer,
00199                 bool& eos,
00200                 LLSD& context,
00201                 LLPumpIO* pump);
00203 
00204 protected:
00205         enum EState
00206         {
00207                 STATE_INITIALIZED,
00208                 STATE_WAITING_FOR_RESPONSE,
00209                 STATE_PROCESSING_RESPONSE,
00210                 STATE_HAVE_RESPONSE,
00211         };
00212         EState mState;
00213         ERequestAction mAction;
00214         LLURLRequestDetail* mDetail;
00215         LLIOPipe::ptr_t mCompletionCallback;
00216 
00217 private:
00221         void initialize();
00222 
00228         bool configure();
00229 
00233         static size_t downCallback(
00234                 void* data,
00235                 size_t size,
00236                 size_t nmemb,
00237                 void* user);
00238 
00242         static size_t upCallback(
00243                 void* data,
00244                 size_t size,
00245                 size_t nmemb,
00246                 void* user);
00247 
00252         LLURLRequest(const LLURLRequest&);
00253 };
00254 
00255 
00265 class LLContextURLExtractor : public LLIOPipe
00266 {
00267 public:
00268         LLContextURLExtractor(LLURLRequest* req) : mRequest(req) {}
00269         ~LLContextURLExtractor() {}
00270 
00271 protected:
00272         /* @name LLIOPipe virtual implementations
00273          */
00275 
00278         virtual EStatus process_impl(
00279                 const LLChannelDescriptors& channels,
00280                 buffer_ptr_t& buffer,
00281                 bool& eos,
00282                 LLSD& context,
00283                 LLPumpIO* pump);
00285 
00286 protected:
00287         LLURLRequest* mRequest;
00288 };
00289 
00290 
00296 class LLURLRequestComplete : public LLIOPipe
00297 {
00298 public:
00299         
00300         virtual void header(const std::string& header, const std::string& value);
00302 
00303         virtual void httpStatus(U32 status, const std::string& reason);
00305 
00306         virtual void complete(
00307                 const LLChannelDescriptors& channels,
00308                 const buffer_ptr_t& buffer);
00309 
00315         virtual void response(
00316                 const LLChannelDescriptors& channels,
00317                 const buffer_ptr_t& buffer);
00318 
00324         virtual void noResponse();
00325 
00335         void responseStatus(EStatus status);
00336 
00337         // constructor & destructor.
00338         LLURLRequestComplete();
00339         virtual ~LLURLRequestComplete();
00340 
00341 protected:
00342         /* @name LLIOPipe virtual implementations
00343          */
00345 
00348         virtual EStatus process_impl(
00349                 const LLChannelDescriptors& channels,
00350                 buffer_ptr_t& buffer,
00351                 bool& eos,
00352                 LLSD& context,
00353                 LLPumpIO* pump);
00355 
00356         // value to note if we actually got the response. This value
00357         // depends on correct useage from the LLURLRequest instance.
00358         EStatus mRequestStatus;
00359 };
00360 
00361 
00378 #if 0
00379 template<class Client>
00380 class LLURLRequestClientFactory : public LLChainIOFactory
00381 {
00382 public:
00383         LLURLRequestClientFactory(LLURLRequest::ERequestAction action) {}
00384         LLURLRequestClientFactory(
00385                 LLURLRequest::ERequestAction action,
00386                 const std::string& fixed_url) :
00387                 mAction(action),
00388                 mURL(fixed_url)
00389         {
00390         }
00391         virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
00392         {
00393                 lldebugs << "LLURLRequestClientFactory::build" << llendl;
00394                 LLIOPipe::ptr_t service(new Client);
00395                 chain.push_back(service);
00396                 LLURLRequest* http(new LLURLRequest(mAction));
00397                 LLIOPipe::ptr_t http_pipe(http);
00398                 // *FIX: how do we know the content type?
00399                 //http->addHeader("Content-Type: text/llsd");
00400                 if(mURL.empty())
00401                 {
00402                         chain.push_back(LLIOPipe::ptr_t(new LLContextURLExtractor(http)));
00403                 }
00404                 else
00405                 {
00406                         http->setURL(mURL);
00407                 }
00408                 chain.push_back(http_pipe);
00409                 chain.push_back(service);
00410                 return true;
00411         }
00412 
00413 protected:
00414         LLURLRequest::ERequestAction mAction;
00415         std::string mURL;
00416 };
00417 #endif
00418 
00422 extern const std::string CONTEXT_DEST_URI_SD_LABEL;
00423 
00424 #endif // LL_LLURLREQUEST_H

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7