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_connectivity.hxx"
26 #include "NDriver.hxx"
27 #include "NConnection.hxx"
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include "connectivity/dbexception.hxx"
30 //#ifndef _CONNECTIVITY_EVOAB_CONFIGACCESS_HXX_
31 //#include "LConfigAccess.hxx"
32 //#endif
33 #include <osl/file.hxx>
34 #include "osl/security.hxx"
35 #include <comphelper/processfactory.hxx>
36 #include <com/sun/star/ucb/XContentAccess.hpp>
37 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
38 #include <ucbhelper/content.hxx>
39 #include <tools/debug.hxx>
40 #include "NDebug.hxx"
41 #include <signal.h>
42 #include "resource/common_res.hrc"
43 #include "resource/sharedresources.hxx"
44 
45 using namespace osl;
46 using namespace connectivity::evoab;
47 //using namespace connectivity::file;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::sdbcx;
51 using namespace ::com::sun::star::sdbc;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::ucb;
54 
55 // --------------------------------------------------------------------------------
OEvoabDriver(const Reference<XMultiServiceFactory> & _rxFactory)56 OEvoabDriver::OEvoabDriver(const Reference< XMultiServiceFactory >& _rxFactory) :
57 		ODriver_BASE( m_aMutex ), m_xFactory( _rxFactory )
58 {
59 }
60 // -----------------------------------------------------------------------------
~OEvoabDriver()61 OEvoabDriver::~OEvoabDriver()
62 {
63 }
64 // -----------------------------------------------------------------------------
disposing()65 void OEvoabDriver::disposing()
66 {
67 	::osl::MutexGuard aGuard(m_aMutex);
68 
69 	// when driver will be destroied so all our connections have to be destroied as well
70 	for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
71 	{
72 		Reference< XComponent > xComp(i->get(), UNO_QUERY);
73 		if (xComp.is()) {
74 		    try {
75 			xComp->dispose();
76 			}
77 		    catch (com::sun::star::lang::DisposedException e) {
78 			 xComp.clear();
79 			}
80 		}
81 	}
82 	m_xConnections.clear();
83 	connectivity::OWeakRefArray().swap(m_xConnections); // this really clears
84 
85 	ODriver_BASE::disposing();
86 }
87 
88 // static ServiceInfo
89 //------------------------------------------------------------------------------
getImplementationName_Static()90 rtl::OUString OEvoabDriver::getImplementationName_Static(  ) throw(RuntimeException)
91 {
92 	return rtl::OUString::createFromAscii(EVOAB_DRIVER_IMPL_NAME);
93 	// this name is referenced in the configuration and in the evoab.xml
94 	// Please take care when changing it.
95 }
96 
97 //------------------------------------------------------------------
getSupportedServiceNames_Static()98 Sequence< ::rtl::OUString > OEvoabDriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
99 {
100 	// which service is supported
101 	// for more information @see com.sun.star.sdbc.Driver
102 	Sequence< ::rtl::OUString > aSNS( 1 );
103 	aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
104 	return aSNS;
105 }
106 //------------------------------------------------------------------
getImplementationName()107 ::rtl::OUString SAL_CALL OEvoabDriver::getImplementationName(  ) throw(RuntimeException)
108 {
109 	return getImplementationName_Static();
110 }
111 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)112 sal_Bool SAL_CALL OEvoabDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
113 {
114     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
115 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
116 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
117 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
118 		;
119 
120 	return pSupported != pEnd;
121 }
122 //------------------------------------------------------------------
getSupportedServiceNames()123 Sequence< ::rtl::OUString > SAL_CALL OEvoabDriver::getSupportedServiceNames(  ) throw(RuntimeException)
124 {
125 	return getSupportedServiceNames_Static();
126 }
127 
128 //------------------------------------------------------------------
OEvoabDriver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)129 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  SAL_CALL connectivity::evoab::OEvoabDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
130 {
131 	return *(new OEvoabDriver(_rxFactory));
132 }
133 // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)134 Reference< XConnection > SAL_CALL OEvoabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
135 {
136 	::osl::MutexGuard aGuard( m_aMutex );
137 	if (ODriver_BASE::rBHelper.bDisposed)
138 		throw DisposedException();
139 
140 	if ( ! acceptsURL(url) )
141 		return NULL;
142 
143 	OEvoabConnection* pCon = new OEvoabConnection( *this );
144 	pCon->construct(url,info);
145         Reference< XConnection > xCon = pCon;
146         m_xConnections.push_back(WeakReferenceHelper(*pCon));
147 
148 	return xCon;
149 }
150 // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)151 sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const ::rtl::OUString& url )
152 	throw(SQLException, RuntimeException)
153 {
154 	return acceptsURL_Stat(url);
155 }
156 
157 // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)158 Sequence< DriverPropertyInfo > SAL_CALL OEvoabDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
159 {
160 	if ( ! acceptsURL(url) )
161     {
162         ::connectivity::SharedResources aResources;
163         const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
164 		::dbtools::throwGenericSQLException(sMessage ,*this);
165     } // if ( ! acceptsURL(url) )
166 
167 	// if you have somthing special to say return it here :-)
168 	return Sequence< DriverPropertyInfo >();
169 }
170 
171 // --------------------------------------------------------------------------------
getMajorVersion()172 sal_Int32 SAL_CALL OEvoabDriver::getMajorVersion(  ) throw(RuntimeException)
173 {
174 	return 1;
175 }
176 // --------------------------------------------------------------------------------
getMinorVersion()177 sal_Int32 SAL_CALL OEvoabDriver::getMinorVersion(  ) throw(RuntimeException)
178 {
179 	return 0;
180 }
181 // --------------------------------------------------------------------------------
acceptsURL_Stat(const::rtl::OUString & url)182 sal_Bool OEvoabDriver::acceptsURL_Stat( const ::rtl::OUString& url )
183 {
184 	return (url.equalsAscii("sdbc:address:evolution:local") || url.equalsAscii("sdbc:address:evolution:groupwise")||url.equalsAscii("sdbc:address:evolution:ldap"))&& EApiInit();
185 }
186 // -----------------------------------------------------------------------------
187