1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "NDriver.hxx"
27cdf0e10cSrcweir #include "NConnection.hxx"
28cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
29cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
30cdf0e10cSrcweir //#ifndef _CONNECTIVITY_EVOAB_CONFIGACCESS_HXX_
31cdf0e10cSrcweir //#include "LConfigAccess.hxx"
32cdf0e10cSrcweir //#endif
33cdf0e10cSrcweir #include <osl/file.hxx>
34cdf0e10cSrcweir #include "osl/security.hxx"
35cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
36cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
38cdf0e10cSrcweir #include <ucbhelper/content.hxx>
39cdf0e10cSrcweir #include <tools/debug.hxx>
40cdf0e10cSrcweir #include "NDebug.hxx"
41cdf0e10cSrcweir #include <signal.h>
42cdf0e10cSrcweir #include "resource/common_res.hrc"
43cdf0e10cSrcweir #include "resource/sharedresources.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace osl;
46cdf0e10cSrcweir using namespace connectivity::evoab;
47cdf0e10cSrcweir //using namespace connectivity::file;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir using namespace ::com::sun::star::beans;
50cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
51cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
52cdf0e10cSrcweir using namespace ::com::sun::star::lang;
53cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // --------------------------------------------------------------------------------
OEvoabDriver(const Reference<XMultiServiceFactory> & _rxFactory)56cdf0e10cSrcweir OEvoabDriver::OEvoabDriver(const Reference< XMultiServiceFactory >& _rxFactory) :
57cdf0e10cSrcweir 		ODriver_BASE( m_aMutex ), m_xFactory( _rxFactory )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir }
60cdf0e10cSrcweir // -----------------------------------------------------------------------------
~OEvoabDriver()61cdf0e10cSrcweir OEvoabDriver::~OEvoabDriver()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir }
64cdf0e10cSrcweir // -----------------------------------------------------------------------------
disposing()65cdf0e10cSrcweir void OEvoabDriver::disposing()
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	// when driver will be destroied so all our connections have to be destroied as well
70cdf0e10cSrcweir 	for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		Reference< XComponent > xComp(i->get(), UNO_QUERY);
73cdf0e10cSrcweir 		if (xComp.is()) {
74cdf0e10cSrcweir 		    try {
75cdf0e10cSrcweir 			xComp->dispose();
76cdf0e10cSrcweir 			}
77cdf0e10cSrcweir 		    catch (com::sun::star::lang::DisposedException e) {
78cdf0e10cSrcweir 			 xComp.clear();
79cdf0e10cSrcweir 			}
80cdf0e10cSrcweir 		}
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	m_xConnections.clear();
83cdf0e10cSrcweir 	connectivity::OWeakRefArray().swap(m_xConnections); // this really clears
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	ODriver_BASE::disposing();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir // static ServiceInfo
89cdf0e10cSrcweir //------------------------------------------------------------------------------
getImplementationName_Static()90cdf0e10cSrcweir rtl::OUString OEvoabDriver::getImplementationName_Static(  ) throw(RuntimeException)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	return rtl::OUString::createFromAscii(EVOAB_DRIVER_IMPL_NAME);
93cdf0e10cSrcweir 	// this name is referenced in the configuration and in the evoab.xml
94cdf0e10cSrcweir 	// Please take care when changing it.
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //------------------------------------------------------------------
getSupportedServiceNames_Static()98cdf0e10cSrcweir Sequence< ::rtl::OUString > OEvoabDriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	// which service is supported
101cdf0e10cSrcweir 	// for more information @see com.sun.star.sdbc.Driver
102cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSNS( 1 );
103cdf0e10cSrcweir 	aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
104cdf0e10cSrcweir 	return aSNS;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir //------------------------------------------------------------------
getImplementationName()107cdf0e10cSrcweir ::rtl::OUString SAL_CALL OEvoabDriver::getImplementationName(  ) throw(RuntimeException)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	return getImplementationName_Static();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)112cdf0e10cSrcweir sal_Bool SAL_CALL OEvoabDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
115cdf0e10cSrcweir 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
116cdf0e10cSrcweir 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
117cdf0e10cSrcweir 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
118cdf0e10cSrcweir 		;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	return pSupported != pEnd;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir //------------------------------------------------------------------
getSupportedServiceNames()123cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OEvoabDriver::getSupportedServiceNames(  ) throw(RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir //------------------------------------------------------------------
OEvoabDriver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)129cdf0e10cSrcweir ::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 )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	return *(new OEvoabDriver(_rxFactory));
132cdf0e10cSrcweir }
133cdf0e10cSrcweir // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)134cdf0e10cSrcweir Reference< XConnection > SAL_CALL OEvoabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
137cdf0e10cSrcweir 	if (ODriver_BASE::rBHelper.bDisposed)
138cdf0e10cSrcweir 		throw DisposedException();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	if ( ! acceptsURL(url) )
141cdf0e10cSrcweir 		return NULL;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	OEvoabConnection* pCon = new OEvoabConnection( *this );
144cdf0e10cSrcweir 	pCon->construct(url,info);
145cdf0e10cSrcweir         Reference< XConnection > xCon = pCon;
146cdf0e10cSrcweir         m_xConnections.push_back(WeakReferenceHelper(*pCon));
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	return xCon;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)151cdf0e10cSrcweir sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const ::rtl::OUString& url )
152cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	return acceptsURL_Stat(url);
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)158cdf0e10cSrcweir Sequence< DriverPropertyInfo > SAL_CALL OEvoabDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	if ( ! acceptsURL(url) )
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         ::connectivity::SharedResources aResources;
163cdf0e10cSrcweir         const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
164cdf0e10cSrcweir 		::dbtools::throwGenericSQLException(sMessage ,*this);
165cdf0e10cSrcweir     } // if ( ! acceptsURL(url) )
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	// if you have somthing special to say return it here :-)
168cdf0e10cSrcweir 	return Sequence< DriverPropertyInfo >();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // --------------------------------------------------------------------------------
getMajorVersion()172cdf0e10cSrcweir sal_Int32 SAL_CALL OEvoabDriver::getMajorVersion(  ) throw(RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	return 1;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir // --------------------------------------------------------------------------------
getMinorVersion()177cdf0e10cSrcweir sal_Int32 SAL_CALL OEvoabDriver::getMinorVersion(  ) throw(RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	return 0;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir // --------------------------------------------------------------------------------
acceptsURL_Stat(const::rtl::OUString & url)182cdf0e10cSrcweir sal_Bool OEvoabDriver::acceptsURL_Stat( const ::rtl::OUString& url )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	return (url.equalsAscii("sdbc:address:evolution:local") || url.equalsAscii("sdbc:address:evolution:groupwise")||url.equalsAscii("sdbc:address:evolution:ldap"))&& EApiInit();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir // -----------------------------------------------------------------------------
187