tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / dbaccess / source / ui / misc / dsmeta.cxx
blobc25fb8eda16ab8903be89f8cf9a0ed4b67c8c4aa
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>
24 #include <osl/diagnose.h>
26 #include <map>
27 #include <utility>
29 namespace dbaui
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 OUString pAsciiFeatureName;
59 // global tables
60 const FeatureMapping s_aMappings[] = {
61 { DSID_AUTORETRIEVEENABLED, u"GeneratedValues"_ustr },
62 { DSID_AUTOINCREMENTVALUE, u"GeneratedValues"_ustr },
63 { DSID_AUTORETRIEVEVALUE, u"GeneratedValues"_ustr },
64 { DSID_SQL92CHECK, u"UseSQL92NamingConstraints"_ustr },
65 { DSID_APPEND_TABLE_ALIAS, u"AppendTableAliasInSelect"_ustr },
66 { DSID_AS_BEFORE_CORRNAME, u"UseKeywordAsBeforeAlias"_ustr },
67 { DSID_ENABLEOUTERJOIN, u"UseBracketedOuterJoinSyntax"_ustr },
68 { DSID_IGNOREDRIVER_PRIV, u"IgnoreDriverPrivileges"_ustr },
69 { DSID_PARAMETERNAMESUBST, u"ParameterNameSubstitution"_ustr },
70 { DSID_SUPPRESSVERSIONCL, u"DisplayVersionColumns"_ustr },
71 { DSID_CATALOG, u"UseCatalogInSelect"_ustr },
72 { DSID_SCHEMA, u"UseSchemaInSelect"_ustr },
73 { DSID_INDEXAPPENDIX, u"UseIndexDirectionKeyword"_ustr },
74 { DSID_DOSLINEENDS, u"UseDOSLineEnds"_ustr },
75 { DSID_BOOLEANCOMPARISON, u"BooleanComparisonMode"_ustr },
76 { DSID_CHECK_REQUIRED_FIELDS, u"FormsCheckRequiredFields"_ustr },
77 { DSID_IGNORECURRENCY, u"IgnoreCurrency"_ustr },
78 { DSID_ESCAPE_DATETIME, u"EscapeDateTime"_ustr },
79 { DSID_PRIMARY_KEY_SUPPORT, u"PrimaryKeySupport"_ustr },
80 { DSID_RESPECTRESULTSETTYPE, u"RespectDriverResultSetType"_ustr },
81 { DSID_MAX_ROW_SCAN, u"MaxRowScan"_ustr },
85 static const FeatureSet& lcl_getFeatureSet( const OUString& _rURL )
87 typedef std::map< OUString, FeatureSet > FeatureSets;
88 static FeatureSets s_aFeatureSets = []()
90 FeatureSets tmp;
91 ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessComponentContext() );
92 const uno::Sequence< OUString > aPatterns = aDriverConfig.getURLs();
93 for ( auto const & pattern : aPatterns )
95 FeatureSet aCurrentSet;
96 const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( pattern ).getNamedValues() );
98 for ( const FeatureMapping& rFeatureMapping : s_aMappings )
100 if ( aCurrentFeatures.has( rFeatureMapping.pAsciiFeatureName ) )
101 aCurrentSet.put( rFeatureMapping.nItemID );
104 tmp[pattern] = std::move(aCurrentSet);
106 return tmp;
107 }();
109 OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" );
110 return s_aFeatureSets[ _rURL ];
113 static AuthenticationMode getAuthenticationMode( const OUString& _sURL )
115 static std::map< OUString, FeatureSupport > s_aSupport = []()
117 std::map< OUString, FeatureSupport > tmp;
118 ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessComponentContext());
119 for (auto& url : aDriverConfig.getURLs())
121 FeatureSupport aInit( AuthNone );
122 const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(url);
123 if ( aMetaData.has(u"Authentication"_ustr) )
125 OUString sAuth;
126 aMetaData.get(u"Authentication"_ustr) >>= sAuth;
127 if ( sAuth == "UserPassword" )
128 aInit = FeatureSupport(AuthUserPwd);
129 else if ( sAuth == "Password" )
130 aInit = FeatureSupport(AuthPwd);
132 tmp.insert(std::make_pair(url, aInit));
134 return tmp;
135 }();
136 OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!");
137 return s_aSupport[ _sURL ].eAuthentication;
140 // DataSourceMetaData
141 DataSourceMetaData::DataSourceMetaData( const OUString& _sURL )
142 :m_sURL( _sURL )
146 DataSourceMetaData::~DataSourceMetaData()
150 const FeatureSet& DataSourceMetaData::getFeatureSet() const
152 return lcl_getFeatureSet( m_sURL );
155 AuthenticationMode DataSourceMetaData::getAuthentication( const OUString& _sURL )
157 return getAuthenticationMode( _sURL );
160 } // namespace dbaui
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */