Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "dsmeta.hxx"
21 : #include <connectivity/DriversConfig.hxx>
22 : #include "dsntypes.hxx"
23 : #include <comphelper/processfactory.hxx>
24 :
25 : #include <map>
26 : #include <utility>
27 :
28 : //........................................................................
29 : namespace dbaui
30 : {
31 : //........................................................................
32 :
33 : using namespace dbaccess;
34 : using namespace ::com::sun::star;
35 :
36 : struct FeatureSupport
37 : {
38 : // authentication mode of the data source
39 : AuthenticationMode eAuthentication;
40 :
41 0 : FeatureSupport()
42 0 : :eAuthentication( AuthUserPwd )
43 : {
44 0 : }
45 :
46 0 : FeatureSupport( AuthenticationMode _Auth )
47 0 : :eAuthentication( _Auth )
48 : {
49 0 : }
50 : };
51 :
52 : struct FeatureMapping
53 : {
54 : /// one of the items from dsitems.hxx
55 : ItemID nItemID;
56 : const sal_Char* pAsciiFeatureName;
57 : };
58 :
59 : //====================================================================
60 : //= global tables
61 : //====================================================================
62 : //--------------------------------------------------------------------
63 0 : static const FeatureMapping* lcl_getFeatureMappings()
64 : {
65 : static const FeatureMapping s_aMappings[] = {
66 : { DSID_AUTORETRIEVEENABLED, "GeneratedValues" },
67 : { DSID_AUTOINCREMENTVALUE, "GeneratedValues" },
68 : { DSID_AUTORETRIEVEVALUE, "GeneratedValues" },
69 : { DSID_SQL92CHECK, "UseSQL92NamingConstraints" },
70 : { DSID_APPEND_TABLE_ALIAS, "AppendTableAliasInSelect" },
71 : { DSID_AS_BEFORE_CORRNAME, "UseKeywordAsBeforeAlias" },
72 : { DSID_ENABLEOUTERJOIN, "UseBracketedOuterJoinSyntax" },
73 : { DSID_IGNOREDRIVER_PRIV, "IgnoreDriverPrivileges" },
74 : { DSID_PARAMETERNAMESUBST, "ParameterNameSubstitution" },
75 : { DSID_SUPPRESSVERSIONCL, "DisplayVersionColumns" },
76 : { DSID_CATALOG, "UseCatalogInSelect" },
77 : { DSID_SCHEMA, "UseSchemaInSelect" },
78 : { DSID_INDEXAPPENDIX, "UseIndexDirectionKeyword" },
79 : { DSID_DOSLINEENDS, "UseDOSLineEnds" },
80 : { DSID_BOOLEANCOMPARISON, "BooleanComparisonMode" },
81 : { DSID_CHECK_REQUIRED_FIELDS, "FormsCheckRequiredFields" },
82 : { DSID_IGNORECURRENCY, "IgnoreCurrency" },
83 : { DSID_ESCAPE_DATETIME, "EscapeDateTime" },
84 : { DSID_PRIMARY_KEY_SUPPORT, "PrimaryKeySupport" },
85 : { DSID_RESPECTRESULTSETTYPE, "RespectDriverResultSetType" },
86 : { DSID_MAX_ROW_SCAN, "MaxRowScan" },
87 : { 0, NULL }
88 : };
89 0 : return s_aMappings;
90 : }
91 :
92 : //--------------------------------------------------------------------
93 0 : static const FeatureSet& lcl_getFeatureSet( const OUString _rURL )
94 : {
95 : typedef ::std::map< OUString, FeatureSet, ::comphelper::UStringLess > FeatureSets;
96 0 : static FeatureSets s_aFeatureSets;
97 0 : if ( s_aFeatureSets.empty() )
98 : {
99 0 : ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessComponentContext() );
100 0 : const uno::Sequence< OUString > aPatterns = aDriverConfig.getURLs();
101 0 : for ( const OUString* pattern = aPatterns.getConstArray();
102 0 : pattern != aPatterns.getConstArray() + aPatterns.getLength();
103 : ++pattern
104 : )
105 : {
106 0 : FeatureSet aCurrentSet;
107 0 : const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( *pattern ).getNamedValues() );
108 :
109 0 : const FeatureMapping* pFeatureMapping = lcl_getFeatureMappings();
110 0 : while ( pFeatureMapping->pAsciiFeatureName )
111 : {
112 0 : if ( aCurrentFeatures.has( pFeatureMapping->pAsciiFeatureName ) )
113 0 : aCurrentSet.put( pFeatureMapping->nItemID );
114 0 : ++pFeatureMapping;
115 : }
116 :
117 0 : s_aFeatureSets[ *pattern ] = aCurrentSet;
118 0 : }
119 : }
120 :
121 : OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" );
122 0 : return s_aFeatureSets[ _rURL ];
123 : }
124 :
125 : //--------------------------------------------------------------------
126 0 : static AuthenticationMode getAuthenticationMode( const OUString& _sURL )
127 : {
128 0 : static std::map< OUString, FeatureSupport > s_aSupport;
129 0 : if ( s_aSupport.empty() )
130 : {
131 0 : ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessComponentContext());
132 0 : const uno::Sequence< OUString > aURLs = aDriverConfig.getURLs();
133 0 : const OUString* pIter = aURLs.getConstArray();
134 0 : const OUString* pEnd = pIter + aURLs.getLength();
135 0 : for(;pIter != pEnd;++pIter)
136 : {
137 0 : FeatureSupport aInit( AuthNone );
138 0 : const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(*pIter);
139 0 : if ( aMetaData.has("Authentication") )
140 : {
141 0 : OUString sAuth;
142 0 : aMetaData.get("Authentication") >>= sAuth;
143 0 : if ( sAuth == "UserPassword" )
144 0 : aInit = AuthUserPwd;
145 0 : else if ( sAuth == "Password" )
146 0 : aInit = AuthPwd;
147 : }
148 0 : s_aSupport.insert(std::make_pair(*pIter,aInit));
149 0 : }
150 : }
151 : OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!");
152 0 : return s_aSupport[ _sURL ].eAuthentication;
153 : }
154 :
155 : //====================================================================
156 : //= DataSourceMetaData_Impl
157 : //====================================================================
158 0 : class DataSourceMetaData_Impl
159 : {
160 : public:
161 : DataSourceMetaData_Impl( const OUString& _sURL );
162 :
163 0 : inline OUString getType() const { return m_sURL; }
164 :
165 : private:
166 : const OUString m_sURL;
167 : };
168 :
169 : //--------------------------------------------------------------------
170 0 : DataSourceMetaData_Impl::DataSourceMetaData_Impl( const OUString& _sURL )
171 0 : :m_sURL( _sURL )
172 : {
173 0 : }
174 :
175 : //====================================================================
176 : //= DataSourceMetaData
177 : //====================================================================
178 : //--------------------------------------------------------------------
179 0 : DataSourceMetaData::DataSourceMetaData( const OUString& _sURL )
180 0 : :m_pImpl( new DataSourceMetaData_Impl( _sURL ) )
181 : {
182 0 : }
183 :
184 : //--------------------------------------------------------------------
185 0 : DataSourceMetaData::~DataSourceMetaData()
186 : {
187 0 : }
188 :
189 : //--------------------------------------------------------------------
190 0 : const FeatureSet& DataSourceMetaData::getFeatureSet() const
191 : {
192 0 : return lcl_getFeatureSet( m_pImpl->getType() );
193 : }
194 :
195 : //--------------------------------------------------------------------
196 0 : AuthenticationMode DataSourceMetaData::getAuthentication( const OUString& _sURL )
197 : {
198 0 : return getAuthenticationMode( _sURL );
199 : }
200 :
201 : //........................................................................
202 : } // namespace dbaui
203 : //........................................................................
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|