nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / ui / misc / dsmeta.cxx
blob58831f081185470c3ed803ab48497f66c1cbe4f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <dsmeta.hxx>
21 #include <connectivity/DriversConfig.hxx>
22 #include <dsntypes.hxx>
23 #include <comphelper/processfactory.hxx>
25 #include <map>
26 #include <utility>
28 namespace dbaui
31 using namespace dbaccess;
32 using namespace ::com::sun::star;
34 namespace {
36 struct FeatureSupport
38 // authentication mode of the data source
39 AuthenticationMode eAuthentication;
41 FeatureSupport()
42 :eAuthentication( AuthUserPwd )
46 explicit FeatureSupport(AuthenticationMode Auth)
47 :eAuthentication( Auth )
52 struct FeatureMapping
54 /// one of the items from dsitems.hxx
55 ItemID nItemID;
56 const char* pAsciiFeatureName;
61 // global tables
62 static const FeatureMapping* lcl_getFeatureMappings()
64 static const FeatureMapping s_aMappings[] = {
65 { DSID_AUTORETRIEVEENABLED, "GeneratedValues" },
66 { DSID_AUTOINCREMENTVALUE, "GeneratedValues" },
67 { DSID_AUTORETRIEVEVALUE, "GeneratedValues" },
68 { DSID_SQL92CHECK, "UseSQL92NamingConstraints" },
69 { DSID_APPEND_TABLE_ALIAS, "AppendTableAliasInSelect" },
70 { DSID_AS_BEFORE_CORRNAME, "UseKeywordAsBeforeAlias" },
71 { DSID_ENABLEOUTERJOIN, "UseBracketedOuterJoinSyntax" },
72 { DSID_IGNOREDRIVER_PRIV, "IgnoreDriverPrivileges" },
73 { DSID_PARAMETERNAMESUBST, "ParameterNameSubstitution" },
74 { DSID_SUPPRESSVERSIONCL, "DisplayVersionColumns" },
75 { DSID_CATALOG, "UseCatalogInSelect" },
76 { DSID_SCHEMA, "UseSchemaInSelect" },
77 { DSID_INDEXAPPENDIX, "UseIndexDirectionKeyword" },
78 { DSID_DOSLINEENDS, "UseDOSLineEnds" },
79 { DSID_BOOLEANCOMPARISON, "BooleanComparisonMode" },
80 { DSID_CHECK_REQUIRED_FIELDS, "FormsCheckRequiredFields" },
81 { DSID_IGNORECURRENCY, "IgnoreCurrency" },
82 { DSID_ESCAPE_DATETIME, "EscapeDateTime" },
83 { DSID_PRIMARY_KEY_SUPPORT, "PrimaryKeySupport" },
84 { DSID_RESPECTRESULTSETTYPE, "RespectDriverResultSetType" },
85 { DSID_MAX_ROW_SCAN, "MaxRowScan" },
86 { 0, nullptr }
88 return s_aMappings;
91 static const FeatureSet& lcl_getFeatureSet( const OUString& _rURL )
93 typedef std::map< OUString, FeatureSet > FeatureSets;
94 static FeatureSets s_aFeatureSets = [&]()
96 FeatureSets tmp;
97 ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessComponentContext() );
98 const uno::Sequence< OUString > aPatterns = aDriverConfig.getURLs();
99 for ( auto const & pattern : aPatterns )
101 FeatureSet aCurrentSet;
102 const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( pattern ).getNamedValues() );
104 const FeatureMapping* pFeatureMapping = lcl_getFeatureMappings();
105 while ( pFeatureMapping->pAsciiFeatureName )
107 if ( aCurrentFeatures.has( pFeatureMapping->pAsciiFeatureName ) )
108 aCurrentSet.put( pFeatureMapping->nItemID );
109 ++pFeatureMapping;
112 tmp[ pattern ] = aCurrentSet;
114 return tmp;
115 }();
117 OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" );
118 return s_aFeatureSets[ _rURL ];
121 static AuthenticationMode getAuthenticationMode( const OUString& _sURL )
123 static std::map< OUString, FeatureSupport > s_aSupport = [&]()
125 std::map< OUString, FeatureSupport > tmp;
126 ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessComponentContext());
127 const uno::Sequence< OUString > aURLs = aDriverConfig.getURLs();
128 const OUString* pIter = aURLs.getConstArray();
129 const OUString* pEnd = pIter + aURLs.getLength();
130 for(;pIter != pEnd;++pIter)
132 FeatureSupport aInit( AuthNone );
133 const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(*pIter);
134 if ( aMetaData.has("Authentication") )
136 OUString sAuth;
137 aMetaData.get("Authentication") >>= sAuth;
138 if ( sAuth == "UserPassword" )
139 aInit = FeatureSupport(AuthUserPwd);
140 else if ( sAuth == "Password" )
141 aInit = FeatureSupport(AuthPwd);
143 tmp.insert(std::make_pair(*pIter,aInit));
145 return tmp;
146 }();
147 OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!");
148 return s_aSupport[ _sURL ].eAuthentication;
151 // DataSourceMetaData_Impl
152 class DataSourceMetaData_Impl
154 public:
155 explicit DataSourceMetaData_Impl(const OUString& rURL);
157 const OUString& getType() const { return m_sURL; }
159 private:
160 const OUString m_sURL;
163 DataSourceMetaData_Impl::DataSourceMetaData_Impl( const OUString& _sURL )
164 :m_sURL( _sURL )
168 // DataSourceMetaData
169 DataSourceMetaData::DataSourceMetaData( const OUString& _sURL )
170 :m_pImpl( std::make_shared<DataSourceMetaData_Impl>( _sURL ) )
174 DataSourceMetaData::~DataSourceMetaData()
178 const FeatureSet& DataSourceMetaData::getFeatureSet() const
180 return lcl_getFeatureSet( m_pImpl->getType() );
183 AuthenticationMode DataSourceMetaData::getAuthentication( const OUString& _sURL )
185 return getAuthenticationMode( _sURL );
188 } // namespace dbaui
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */