Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Youssefi
otb
Commits
cfe201f4
Commit
cfe201f4
authored
14 years ago
by
Otmane Lahlou
Browse files
Options
Downloads
Patches
Plain Diff
ENH : curlHelper to avoid windows crash when passing a pointer on a file descriptor in libcurl
parent
0a025d46
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/IO/otbCurlHelper.cxx
+18
-15
18 additions, 15 deletions
Code/IO/otbCurlHelper.cxx
Code/IO/otbCurlHelper.h
+20
-1
20 additions, 1 deletion
Code/IO/otbCurlHelper.h
with
38 additions
and
16 deletions
Code/IO/otbCurlHelper.cxx
100644 → 100755
+
18
−
15
View file @
cfe201f4
...
...
@@ -35,13 +35,9 @@ int CurlHelper::TestUrlAvailability(const std::string& url) const
CURLcode
res
=
CURL_LAST
;
curl
=
curl_easy_init
();
// Set up the browser
std
::
string
browser
=
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
;
if
(
curl
)
{
curl_easy_setopt
(
curl
,
CURLOPT_USERAGENT
,
b
rowser
.
data
());
curl_easy_setopt
(
curl
,
CURLOPT_USERAGENT
,
m_B
rowser
.
data
());
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
.
data
());
// Set the dummy write function
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
Self
::
curlDummyWriteFunction
);
...
...
@@ -69,26 +65,32 @@ int CurlHelper::RetrieveFile(const std::string& urlString, std::string filename)
CURLcode
res
=
CURL_LAST
;
FILE
*
output_file
=
fopen
(
filename
.
c_str
(),
"w"
);
curl
=
curl_easy_init
();
char
url
[
256
];
strcpy
(
url
,
urlString
.
data
());
strcpy
(
url
,
urlString
.
c_str
());
// std::cout << url << std::endl;
if
(
curl
)
{
std
::
vector
<
char
>
chunk
;
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
// Set 5s timeout
curl_easy_setopt
(
curl
,
CURLOPT_TIMEOUT
,
5
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
output_file
);
// Use our writing static function to avoid file descriptor
// pointer crash on windows
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
Self
::
write_data
);
// Say the file where to write the received data
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
(
void
*
)
output_file
);
res
=
curl_easy_perform
(
curl
);
fclose
(
output_file
);
/* always cleanup */
curl_easy_cleanup
(
curl
);
fclose
(
output_file
);
}
return
res
;
#else
...
...
@@ -105,7 +107,7 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
#ifdef OTB_USE_CURL
#ifdef OTB_CURL_MULTI_AVAILABLE
otbMsgDevMacro
(
<<
"Using curl multi"
);
std
::
string
m_Browser
=
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
;
//
std::string m_Browser = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11";
CURLM
*
multiHandle
;
std
::
vector
<
CURL
*>
listCurlHandles
;
...
...
@@ -155,7 +157,8 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
// Param easy handle
curl_easy_setopt
(
lEasyHandle
,
CURLOPT_USERAGENT
,
m_Browser
.
data
());
curl_easy_setopt
(
lEasyHandle
,
CURLOPT_URL
,
(
*
url
).
data
());
curl_easy_setopt
(
lEasyHandle
,
CURLOPT_WRITEDATA
,
*
file
);
curl_easy_setopt
(
lEasyHandle
,
CURLOPT_WRITEFUNCTION
,
&
Self
::
write_data
);
curl_easy_setopt
(
lEasyHandle
,
CURLOPT_WRITEDATA
,
(
void
*
)(
*
file
));
// Add easy handle to multi handle
curl_multi_add_handle
(
multiHandle
,
lEasyHandle
);
...
...
@@ -166,7 +169,7 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
++
file
;
}
//fetch tiles
//fetch tiles
// Configure multi handle - set the maximum connections
curl_multi_setopt
(
multiHandle
,
CURLMOPT_MAXCONNECTS
,
maxConnect
);
curl_multi_setopt
(
multiHandle
,
CURLMOPT_PIPELINING
,
0
);
...
...
This diff is collapsed.
Click to expand it.
Code/IO/otbCurlHelper.h
+
20
−
1
View file @
cfe201f4
...
...
@@ -49,7 +49,10 @@ public:
const
std
::
vector
<
std
::
string
>&
listFiles
,
int
maxConnect
)
const
;
protected:
CurlHelper
()
{}
CurlHelper
()
{
m_Browser
=
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
;
}
~
CurlHelper
()
{}
...
...
@@ -61,7 +64,23 @@ private:
{
return
nmemb
;
}
// Need to use our writing function to handle windows segfaults
// Need to be static cause the CURL_OPT is excpecting a pure C
// function or a static c++ method.
static
size_t
write_data
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
{
size_t
written
;
FILE
*
fDescriptor
=
(
FILE
*
)(
data
);
written
=
fwrite
(
ptr
,
size
,
nmemb
,
fDescriptor
);
return
written
;
}
// Browser Agent used
std
::
string
m_Browser
;
};
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment