1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <connectivity/DriversConfig.hxx>
22 #include "dsntypes.hxx"
23 #include <comphelper/processfactory.hxx>
31 using namespace dbaccess
;
32 using namespace ::com::sun::star
;
36 // authentication mode of the data source
37 AuthenticationMode eAuthentication
;
40 :eAuthentication( AuthUserPwd
)
44 FeatureSupport( AuthenticationMode _Auth
)
45 :eAuthentication( _Auth
)
52 /// one of the items from dsitems.hxx
54 const sal_Char
* pAsciiFeatureName
;
58 static const FeatureMapping
* lcl_getFeatureMappings()
60 static const FeatureMapping s_aMappings
[] = {
61 { DSID_AUTORETRIEVEENABLED
, "GeneratedValues" },
62 { DSID_AUTOINCREMENTVALUE
, "GeneratedValues" },
63 { DSID_AUTORETRIEVEVALUE
, "GeneratedValues" },
64 { DSID_SQL92CHECK
, "UseSQL92NamingConstraints" },
65 { DSID_APPEND_TABLE_ALIAS
, "AppendTableAliasInSelect" },
66 { DSID_AS_BEFORE_CORRNAME
, "UseKeywordAsBeforeAlias" },
67 { DSID_ENABLEOUTERJOIN
, "UseBracketedOuterJoinSyntax" },
68 { DSID_IGNOREDRIVER_PRIV
, "IgnoreDriverPrivileges" },
69 { DSID_PARAMETERNAMESUBST
, "ParameterNameSubstitution" },
70 { DSID_SUPPRESSVERSIONCL
, "DisplayVersionColumns" },
71 { DSID_CATALOG
, "UseCatalogInSelect" },
72 { DSID_SCHEMA
, "UseSchemaInSelect" },
73 { DSID_INDEXAPPENDIX
, "UseIndexDirectionKeyword" },
74 { DSID_DOSLINEENDS
, "UseDOSLineEnds" },
75 { DSID_BOOLEANCOMPARISON
, "BooleanComparisonMode" },
76 { DSID_CHECK_REQUIRED_FIELDS
, "FormsCheckRequiredFields" },
77 { DSID_IGNORECURRENCY
, "IgnoreCurrency" },
78 { DSID_ESCAPE_DATETIME
, "EscapeDateTime" },
79 { DSID_PRIMARY_KEY_SUPPORT
, "PrimaryKeySupport" },
80 { DSID_RESPECTRESULTSETTYPE
, "RespectDriverResultSetType" },
81 { DSID_MAX_ROW_SCAN
, "MaxRowScan" },
87 static const FeatureSet
& lcl_getFeatureSet( const OUString
& _rURL
)
89 typedef ::std::map
< OUString
, FeatureSet
> FeatureSets
;
90 static FeatureSets s_aFeatureSets
;
91 if ( s_aFeatureSets
.empty() )
93 ::connectivity::DriversConfig
aDriverConfig( ::comphelper::getProcessComponentContext() );
94 const uno::Sequence
< OUString
> aPatterns
= aDriverConfig
.getURLs();
95 for ( const OUString
* pattern
= aPatterns
.getConstArray();
96 pattern
!= aPatterns
.getConstArray() + aPatterns
.getLength();
100 FeatureSet aCurrentSet
;
101 const ::comphelper::NamedValueCollection
aCurrentFeatures( aDriverConfig
.getFeatures( *pattern
).getNamedValues() );
103 const FeatureMapping
* pFeatureMapping
= lcl_getFeatureMappings();
104 while ( pFeatureMapping
->pAsciiFeatureName
)
106 if ( aCurrentFeatures
.has( pFeatureMapping
->pAsciiFeatureName
) )
107 aCurrentSet
.put( pFeatureMapping
->nItemID
);
111 s_aFeatureSets
[ *pattern
] = aCurrentSet
;
115 OSL_ENSURE( s_aFeatureSets
.find( _rURL
) != s_aFeatureSets
.end(), "invalid URL/pattern!" );
116 return s_aFeatureSets
[ _rURL
];
119 static AuthenticationMode
getAuthenticationMode( const OUString
& _sURL
)
121 static std::map
< OUString
, FeatureSupport
> s_aSupport
;
122 if ( s_aSupport
.empty() )
124 ::connectivity::DriversConfig
aDriverConfig(::comphelper::getProcessComponentContext());
125 const uno::Sequence
< OUString
> aURLs
= aDriverConfig
.getURLs();
126 const OUString
* pIter
= aURLs
.getConstArray();
127 const OUString
* pEnd
= pIter
+ aURLs
.getLength();
128 for(;pIter
!= pEnd
;++pIter
)
130 FeatureSupport
aInit( AuthNone
);
131 const ::comphelper::NamedValueCollection
& aMetaData
= aDriverConfig
.getMetaData(*pIter
);
132 if ( aMetaData
.has("Authentication") )
135 aMetaData
.get("Authentication") >>= sAuth
;
136 if ( sAuth
== "UserPassword" )
138 else if ( sAuth
== "Password" )
141 s_aSupport
.insert(std::make_pair(*pIter
,aInit
));
144 OSL_ENSURE(s_aSupport
.find(_sURL
) != s_aSupport
.end(),"Illegal URL!");
145 return s_aSupport
[ _sURL
].eAuthentication
;
148 // DataSourceMetaData_Impl
149 class DataSourceMetaData_Impl
152 DataSourceMetaData_Impl( const OUString
& _sURL
);
154 inline OUString
getType() const { return m_sURL
; }
157 const OUString m_sURL
;
160 DataSourceMetaData_Impl::DataSourceMetaData_Impl( const OUString
& _sURL
)
165 // DataSourceMetaData
166 DataSourceMetaData::DataSourceMetaData( const OUString
& _sURL
)
167 :m_pImpl( new DataSourceMetaData_Impl( _sURL
) )
171 DataSourceMetaData::~DataSourceMetaData()
175 const FeatureSet
& DataSourceMetaData::getFeatureSet() const
177 return lcl_getFeatureSet( m_pImpl
->getType() );
180 AuthenticationMode
DataSourceMetaData::getAuthentication( const OUString
& _sURL
)
182 return getAuthenticationMode( _sURL
);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */