OTB  9.0.0
Orfeo Toolbox
otbCurlHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbCurlHelper_h
22 #define otbCurlHelper_h
23 
24 #include "otbCurlHelperInterface.h"
25 #include <string>
26 
27 namespace otb
28 {
40 class OTBCurlAdapters_EXPORT CurlHelper : public CurlHelperInterface
41 {
42 public:
43 
45  typedef CurlHelper Self;
46  typedef itk::SmartPointer<Self> Pointer;
47  typedef itk::SmartPointer<const Self> ConstPointer;
49 
50  itkTypeMacro(CurlHelper, CurlHelperInterface);
51  itkNewMacro(Self);
52 
53  bool TestUrlAvailability(const std::string& url) const override;
54 
55  bool IsCurlReturnHttpError(const std::string& url) const;
56 
57  int RetrieveFile(const std::ostringstream& urlStream, std::string filename) const override;
58 
59  int RetrieveFile(const std::string& urlString, std::string filename) const override;
60 
61  int RetrieveUrlInMemory(const std::string& urlString, std::string& output) const override;
62 
63  int RetrieveFileMulti(const std::vector<std::string>& listURLs, const std::vector<std::string>& listFiles, int maxConnect) const override;
64 
65  itkGetMacro(Timeout, long int);
66 
67  itkSetMacro(Timeout, long int);
68 
69 protected:
71  : m_Browser(
72  "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) "
73  "Gecko/20071127 Firefox/2.0.0.11"),
74  m_Timeout(10)
75  {
76  }
77  ~CurlHelper() override
78  {
79  }
80 
81 private:
82  CurlHelper(const Self&) = delete;
83  void operator=(const Self&) = delete;
84 
85  // Need to use our writing function to handle windows segfaults
86  // Need to be static cause the CURL_OPT is expecting a pure C
87  // function or a static c++ method.
88  static size_t CallbackWriteDataToFile(void* ptr, size_t size, size_t nmemb, void* data);
89 
90  static size_t CallbackWriteDataToStringStream(void* ptr, size_t size, size_t nmemb, void* data);
91 
92  static size_t CallbackWriteDataDummy(void* ptr, size_t size, size_t nmemb, void* data);
93 
94  // Browser Agent used
95  std::string m_Browser;
96  long int m_Timeout;
97 };
98 }
99 #endif
otb::CurlHelper::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbCurlHelper.h:47
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::CurlHelper::m_Timeout
long int m_Timeout
Definition: otbCurlHelper.h:96
otb::CurlHelper::CurlHelper
CurlHelper()
Definition: otbCurlHelper.h:70
otb::CurlHelper::m_Browser
std::string m_Browser
Definition: otbCurlHelper.h:95
otbCurlHelperInterface.h
otb::CurlHelper::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbCurlHelper.h:46
otb::CurlHelper
Class to use the curl capabilities from OTB.
Definition: otbCurlHelper.h:40
otb::CurlHelperInterface
Class to use the curl capabilities from OTB.
Definition: otbCurlHelperInterface.h:41
otb::CurlHelper::Superclass
CurlHelperInterface Superclass
Definition: otbCurlHelper.h:48
otb::CurlHelper::Self
CurlHelper Self
Definition: otbCurlHelper.h:45
otb::CurlHelper::~CurlHelper
~CurlHelper() override
Definition: otbCurlHelper.h:77