1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_ucb.hxx"
30 /**************************************************************************
31 								TODO
32  **************************************************************************
33 
34  *************************************************************************/
35 #include "ftploaderthread.hxx"
36 #include "curl.hxx"
37 
38 using namespace ftp;
39 
40 
41 /********************************************************************************/
42 /*                                                                              */
43 /*                cleanup function for thread specific data                     */
44 /*                                                                              */
45 /********************************************************************************/
46 
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52     int memory_write_dummy(void *,size_t,size_t,void *)
53     {
54         return 0;
55     }
56 
57 	void delete_CURL(void *pData)
58 	{
59         // Otherwise response for QUIT will be sent to already destroyed
60         // MemoryContainer via non-dummy memory_write function.
61         curl_easy_setopt(static_cast<CURL*>(pData),
62                          CURLOPT_HEADERFUNCTION,
63                          memory_write_dummy);
64 		curl_easy_cleanup(static_cast<CURL*>(pData));
65 	}
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 
72 /********************************************************************************/
73 /*                                                                              */
74 /*                  Member part of FTPLoaderThread                              */
75 /*                                                                              */
76 /********************************************************************************/
77 
78 
79 FTPLoaderThread::FTPLoaderThread()
80 	: m_threadKey(osl_createThreadKey(delete_CURL)) {
81 }
82 
83 
84 
85 FTPLoaderThread::~FTPLoaderThread() {
86 	osl_destroyThreadKey(m_threadKey);
87 }
88 
89 
90 
91 CURL* FTPLoaderThread::handle() {
92     CURL* ret = osl_getThreadKeyData(m_threadKey);
93     if(!ret) {
94 		ret = curl_easy_init();
95         if (ret != 0) {
96             // Make sure curl is not internally using environment variables like
97             // "ftp_proxy":
98             if (curl_easy_setopt(ret, CURLOPT_PROXY, "") != CURLE_OK) {
99                 curl_easy_cleanup(ret);
100                 ret = 0;
101             }
102         }
103 		osl_setThreadKeyData(m_threadKey,static_cast<void*>(ret));
104 	}
105 
106 	return ret;
107 }
108 
109 
110