]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/SchemesConfig.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / auth / SchemesConfig.cc
1 /*
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "auth/Config.h"
11 #include "fatal.h"
12 #include "parser/Tokenizer.h"
13
14 static void
15 addUnique(const SBuf &scheme, std::vector<SBuf> &vec)
16 {
17 static const SBuf all("ALL");
18 if (scheme == all) {
19 for (const auto config: Auth::TheConfig.schemes)
20 addUnique(SBuf(config->type()), vec);
21 } else if (std::find(vec.begin(), vec.end(), scheme) == vec.end())
22 vec.push_back(scheme);
23 }
24
25 void
26 Auth::SchemesConfig::expand()
27 {
28 static const CharacterSet delimiters("delimiters", ",");
29 static const CharacterSet quotedDelimiters("quotedDelimiters", ", ");
30 const CharacterSet *resultDelimiters = quoted ? &quotedDelimiters : &delimiters;
31 std::vector<SBuf> expanded;
32 Parser::Tokenizer t(schemes);
33 SBuf scheme;
34 while (t.token(scheme, *resultDelimiters))
35 addUnique(scheme, expanded);
36 t.skipAllTrailing(CharacterSet::SP + CharacterSet::HTAB);
37 if (!t.remaining().isEmpty())
38 addUnique(t.remaining(), expanded);
39
40 authConfigs.clear();
41 transform(expanded.begin(), expanded.end(),
42 back_inserter(authConfigs), [](SBuf &s) {
43 return Auth::SchemeConfig::GetParsed(s.c_str());
44 });
45 }
46