1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ftp.hxx"
26 /**************************************************************************
27 TODO
28 **************************************************************************
29
30 *************************************************************************/
31 #include "ftploaderthread.hxx"
32 #include "curl.hxx"
33
34 using namespace ftp;
35
36
37 /********************************************************************************/
38 /* */
39 /* cleanup function for thread specific data */
40 /* */
41 /********************************************************************************/
42
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
memory_write_dummy(void *,size_t,size_t,void *)48 int memory_write_dummy(void *,size_t,size_t,void *)
49 {
50 return 0;
51 }
52
delete_CURL(void * pData)53 void delete_CURL(void *pData)
54 {
55 // Otherwise response for QUIT will be sent to already destroyed
56 // MemoryContainer via non-dummy memory_write function.
57 curl_easy_setopt(static_cast<CURL*>(pData),
58 CURLOPT_HEADERFUNCTION,
59 memory_write_dummy);
60 curl_easy_cleanup(static_cast<CURL*>(pData));
61 }
62
63 #ifdef __cplusplus
64 }
65 #endif
66
67
68 /********************************************************************************/
69 /* */
70 /* Member part of FTPLoaderThread */
71 /* */
72 /********************************************************************************/
73
74
FTPLoaderThread()75 FTPLoaderThread::FTPLoaderThread()
76 : m_threadKey(osl_createThreadKey(delete_CURL)) {
77 }
78
79
80
~FTPLoaderThread()81 FTPLoaderThread::~FTPLoaderThread() {
82 osl_destroyThreadKey(m_threadKey);
83 }
84
85
86
handle()87 CURL* FTPLoaderThread::handle() {
88 CURL* ret = osl_getThreadKeyData(m_threadKey);
89 if(!ret) {
90 ret = curl_easy_init();
91 if (ret != 0) {
92 // Make sure curl is not internally using environment variables like
93 // "ftp_proxy":
94 if (curl_easy_setopt(ret, CURLOPT_PROXY, "") != CURLE_OK) {
95 curl_easy_cleanup(ret);
96 ret = 0;
97 }
98 }
99 osl_setThreadKeyData(m_threadKey,static_cast<void*>(ret));
100 }
101
102 return ret;
103 }
104
105
106