aboutsummaryrefslogtreecommitdiff
path: root/paludis/default_config.cc
blob: 72d3bf6fda6f7a6393c1787a508581ad22d175a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <paludis/config_file.hh>
#include <paludis/default_config.hh>
#include <paludis/util/collection_concrete.hh>
#include <paludis/util/compare.hh>
#include <paludis/util/destringify.hh>
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/iterator.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/is_file_with_extension.hh>
#include <paludis/util/log.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/sr.hh>
#include <paludis/util/system.hh>
#include <paludis/util/tokeniser.hh>

#include <fstream>
#include <algorithm>
#include <sstream>
#include <list>
#include <map>

#include <ctype.h>

/** \file
 * Implementation of default_config.hh classes.
 *
 * \ingroup grpdefaultconfig
 */

using namespace paludis;

#include <paludis/repository_config_entry-sr.cc>
#include <paludis/use_config_entry-sr.cc>

namespace paludis
{
    /**
     * Implementation data for DefaultConfig.
     *
     * \ingroup grpdefaultconfig
     */
    template<>
    struct Implementation<DefaultConfig> :
        InternalCounted<DefaultConfig>,
        InstantiationPolicy<DefaultConfig, instantiation_method::NonCopyableTag>
    {
        static std::string config_suffix;
        static bool config_suffix_can_be_set;
        std::string paludis_command;
        std::string root;
        std::string config_dir;
        std::string bashrc_files;

        std::list<RepositoryConfigEntry> repos;

        std::map<QualifiedPackageName, std::vector<
            std::pair<PackageDepAtom::ConstPointer, KeywordName> > > keywords;

        const std::vector<std::pair<PackageDepAtom::ConstPointer, KeywordName> > empty_keywords;

        std::vector<KeywordName> default_keywords;

        std::map<QualifiedPackageName, std::vector<
            std::pair<PackageDepAtom::ConstPointer, std::string> > > licenses;

        const std::vector<std::pair<PackageDepAtom::ConstPointer, std::string> > empty_licenses;

        std::vector<std::string> default_licenses;

        std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> > user_masks;

        std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> > user_unmasks;

        std::vector<PackageDepAtom::ConstPointer> empty_masks;

        std::map<QualifiedPackageName, std::vector<UseConfigEntry> > use;

        std::vector<UseConfigEntry> empty_use;

        std::vector<std::pair<UseFlagName, UseFlagState> > default_use;

        std::multimap<std::string, std::string> mirrors;

        Implementation();
    };

    Implementation<DefaultConfig>::Implementation() :
        paludis_command("paludis")
    {
    }

    std::string Implementation<DefaultConfig>::config_suffix;
    bool Implementation<DefaultConfig>::config_suffix_can_be_set(true);
}

DefaultConfigError::DefaultConfigError(const std::string & msg) throw () :
    ConfigurationError("Default configuration error: " + msg)
{
}

DefaultConfig::DefaultConfig() :
    PrivateImplementationPattern<DefaultConfig>(new Implementation<DefaultConfig>)
{
    Context context("When loading default configuration:");

    if (! getenv_with_default("PALUDIS_SKIP_CONFIG", "").empty())
    {
        _imp->config_suffix_can_be_set = false;
        return;
    }

    /* indirection */
    std::string root_prefix;
    std::string config_suffix;
    if (! _imp->config_suffix.empty())
        config_suffix = "-" + _imp->config_suffix;

    FSEntry config_dir(FSEntry(getenv_with_default("PALUDIS_HOME", getenv_or_error("HOME"))) /
            (".paludis" + config_suffix)), old_config_dir(config_dir);
    if (! config_dir.exists())
        config_dir = (FSEntry(SYSCONFDIR) / ("paludis" + config_suffix));
    if (! config_dir.exists())
        throw DefaultConfigError("Can't find configuration directory (tried '"
                + stringify(old_config_dir) + "', '" + stringify(config_dir) + "')");

    Log::get_instance()->message(ll_debug, lc_no_context, "DefaultConfig initial directory is '"
            + stringify(config_dir) + "'");

    if ((config_dir / "specpath").exists())
    {
        KeyValueConfigFile specpath(config_dir / "specpath");
        root_prefix = specpath.get("root");
        config_suffix = specpath.get("config-suffix");

        if (! root_prefix.empty() && stringify(FSEntry(root_prefix).realpath()) != "/")
        {
            config_dir = FSEntry(root_prefix) / SYSCONFDIR / ("paludis" + config_suffix);
            if (! config_dir.exists())
                throw DefaultConfigError("Can't find configuration directory under root ("
                        "tried '" + stringify(config_dir) + "'");
        }
    }

    _imp->root = root_prefix;
    _imp->config_dir = stringify(config_dir);

    AssociativeCollection<std::string, std::string>::Pointer conf_vars(
            new AssociativeCollection<std::string, std::string>::Concrete);
    conf_vars->insert("ROOT", root_prefix);

    Log::get_instance()->message(ll_debug, lc_no_context, "DefaultConfig real directory is '"
            + stringify(config_dir) + "', root prefix is '" + root_prefix +
            "', config suffix is '" + config_suffix + "'");

    /* repositories */
    {
        std::list<FSEntry> dirs;
        dirs.push_back(config_dir / "repositories");

        std::list<FSEntry> repo_files;
        for (std::list<FSEntry>::const_iterator dir(dirs.begin()), dir_end(dirs.end()) ;
                dir != dir_end ; ++dir)
        {
            if (! dir->exists())
                continue;

            std::copy(DirIterator(*dir), DirIterator(),
                    filter_inserter(std::back_inserter(repo_files), IsFileWithExtension(".conf")));
        }

        for (std::list<FSEntry>::const_iterator repo_file(repo_files.begin()), repo_file_end(repo_files.end()) ;
                repo_file != repo_file_end ; ++repo_file)
        {
            Context local_context("When reading repository file '" + stringify(*repo_file) + "':");

            KeyValueConfigFile k(*repo_file, conf_vars);

            std::string format(k.get("format"));
            if (format.empty())
                throw DefaultConfigError("Key 'format' not specified or empty");

            int importance(0);
            if (! k.get("importance").empty())
                importance = destringify<int>(k.get("importance"));

            AssociativeCollection<std::string, std::string>::Pointer keys(
                    new AssociativeCollection<std::string, std::string>::Concrete(k.begin(), k.end()));

            keys->erase("repo_file");
            keys->insert("repo_file", stringify(*repo_file));

            keys->erase("root");
            keys->insert("root", root_prefix);

            _imp->repos.push_back(RepositoryConfigEntry(format, importance, keys));
        }

        if (_imp->repos.empty())
            throw DefaultConfigError("No repositories specified");

        /* add virtuals repositories */
        _imp->repos.push_back(RepositoryConfigEntry("installed_virtuals", -1,
                    AssociativeCollection<std::string, std::string>::Pointer(0)));
        _imp->repos.push_back(RepositoryConfigEntry("virtuals", -2,
                    AssociativeCollection<std::string, std::string>::Pointer(0)));

        _imp->repos.sort();
    }

    /* keywords */
    {
        std::list<FSEntry> files;
        files.push_back(config_dir / "keywords.conf");

        for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
                file != file_end ; ++file)
        {
            Context local_context("When reading keywords file '" + stringify(*file) + "':");

            if (! file->is_regular_file())
                continue;

            LineConfigFile f(*file);
            for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
                    line != line_end ; ++line)
            {
                std::vector<std::string> tokens;
                WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(tokens));
                if (tokens.empty())
                    continue;
                if ("*" == tokens.at(0))
                    std::copy(next(tokens.begin()), tokens.end(),
                            create_inserter<KeywordName>(std::back_inserter(_imp->default_keywords)));
                else
                {
                    PackageDepAtom::ConstPointer a(new PackageDepAtom(tokens.at(0)));
                    for (std::vector<std::string>::const_iterator t(next(tokens.begin())), t_end(tokens.end()) ;
                            t != t_end ; ++t)
                        _imp->keywords[a->package()].push_back(std::make_pair(a, *t));
                }
            }
        }

        if (_imp->default_keywords.empty())
            throw DefaultConfigError("No default keywords specified (a keywords.conf file should "
                    "contain an entry in the form '* keyword')");
    }

    /* licenses */
    {
        std::list<FSEntry> files;
        files.push_back(config_dir / "licenses.conf");

        for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
                file != file_end ; ++file)
        {
            Context local_context("When reading licenses file '" + stringify(*file) + "':");

            if (! file->is_regular_file())
                continue;

            LineConfigFile f(*file);
            for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
                    line != line_end ; ++line)
            {
                std::vector<std::string> tokens;
                WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(tokens));
                if (tokens.empty())
                    continue;
                if ("*" == tokens.at(0))
                    std::copy(next(tokens.begin()), tokens.end(), std::back_inserter(_imp->default_licenses));
                else
                {
                    PackageDepAtom::ConstPointer a(new PackageDepAtom(tokens.at(0)));
                    for (std::vector<std::string>::const_iterator t(next(tokens.begin())), t_end(tokens.end()) ;
                            t != t_end ; ++t)
                        _imp->licenses[a->package()].push_back(std::make_pair(a, *t));
                }
            }
        }

        if (_imp->default_licenses.empty())
            throw DefaultConfigError("No default licenses specified (a licenses.conf file should "
                    "contain an entry in the form '* license license', or '* *' if you don't want any "
                    "license filtering)");
    }

    /* user mask */
    {
        std::list<FSEntry> files;
        files.push_back(config_dir / "package_mask.conf");

        for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
                file != file_end ; ++file)
        {
            Context local_context("When reading package_mask file '" + stringify(*file) + "':");

            if (! file->is_regular_file())
                continue;

            LineConfigFile f(*file);
            for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
                    line != line_end ; ++line)
            {
                PackageDepAtom::ConstPointer a(new PackageDepAtom(*line));
                _imp->user_masks[a->package()].push_back(a);
            }
        }
    }

    /* user unmask */
    {
        std::list<FSEntry> files;
        files.push_back(config_dir / "package_unmask.conf");

        for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
                file != file_end ; ++file)
        {
            Context local_context("When reading package_unmask file '" + stringify(*file) + "':");

            if (! file->is_regular_file())
                continue;

            LineConfigFile f(*file);
            for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
                    line != line_end ; ++line)
            {
                PackageDepAtom::ConstPointer a(new PackageDepAtom(*line));
                _imp->user_unmasks[a->package()].push_back(a);
            }
        }
    }

    /* use */
    {
        std::list<FSEntry> files;
        files.push_back(config_dir / "use.conf");

        for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
                file != file_end ; ++file)
        {
            Context local_context("When reading use file '" + stringify(*file) + "':");

            if (! file->is_regular_file())
                continue;

            LineConfigFile f(*file);
            for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
                    line != line_end ; ++line)
            {
                std::vector<std::string> tokens;
                WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(tokens));
                if (tokens.empty())
                    continue;

                std::string prefix;
                if ("*" == tokens.at(0))
                    for (std::vector<std::string>::const_iterator t(next(tokens.begin())), t_end(tokens.end()) ;
                            t != t_end ; ++t)
                    {
                        if ('-' == t->at(0))
                            _imp->default_use.push_back(std::make_pair(UseFlagName(
                                            prefix + t->substr(1)), use_disabled));
                        else if (':' == t->at(t->length() - 1))
                        {
                            prefix.clear();
                            std::transform(t->begin(), previous(t->end()), std::back_inserter(prefix),
                                    &::tolower);
                            prefix.append("_");
                        }
                        else
                            _imp->default_use.push_back(std::make_pair(UseFlagName(
                                            prefix + *t), use_enabled));
                    }
                else
                {
                    PackageDepAtom::ConstPointer a(new PackageDepAtom(tokens.at(0)));
                    for (std::vector<std::string>::const_iterator t(next(tokens.begin())), t_end(tokens.end()) ;
                            t != t_end ; ++t)
                    {
                        if ('-' == t->at(0))
                            _imp->use[a->package()].push_back(UseConfigEntry(
                                        a, UseFlagName(prefix + t->substr(1)), use_disabled));
                        else if (':' == t->at(t->length() - 1))
                        {
                            prefix.clear();
                            std::transform(t->begin(), previous(t->end()), std::back_inserter(prefix),
                                    &::tolower);
                            prefix.append("_");
                        }
                        else
                            _imp->use[a->package()].push_back(UseConfigEntry(
                                        a, UseFlagName(prefix + *t), use_enabled));
                    }
                }
            }
        }

        if (_imp->default_keywords.empty())
            throw DefaultConfigError("No default keywords specified (a keywords.conf file should "
                    "contain an entry in the form '* keyword')");
    }

    /* mirrors */
    {
        std::list<FSEntry> files;
        files.push_back(config_dir / "mirrors.conf");

        for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
                file != file_end ; ++file)
        {
            Context local_context("When reading mirrors file '" + stringify(*file) + "':");

            if (! file->is_regular_file())
                continue;

            LineConfigFile f(*file);
            for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
                    line != line_end ; ++line)
            {
                std::vector<std::string> m;
                WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(m));
                if (m.size() < 2)
                    continue;
                for (std::vector<std::string>::const_iterator mm(next(m.begin())),
                        mm_end(m.end()) ; mm != mm_end ; ++mm)
                    _imp->mirrors.insert(std::make_pair(m.at(0), *mm));
            }
        }
    }

    _imp->bashrc_files = stringify(config_dir / "bashrc");

    _imp->config_suffix_can_be_set = false;
}

DefaultConfig::~DefaultConfig()
{
}

void
DefaultConfig::set_config_suffix(const std::string & s)
{
    if (! Implementation<DefaultConfig>::config_suffix_can_be_set)
        throw InternalError(PALUDIS_HERE, "DefaultConfig::set_config_suffix called after "
                "DefaultConfig has been instantiated.");

    static const std::string allowed_chars(
            "abcdefghijklmnopqrstuvwxyz"
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            "0123456789-_+:");

    if (std::string::npos != s.find_first_not_of(allowed_chars))
        throw DefaultConfigError("Invalid config suffix '" + s + "'");

    if (! s.empty())
        if ('-' == s.at(0) || '-' == s.at(s.length() - 1))
            throw DefaultConfigError("Invalid config suffix '" + s + "'");

    Implementation<DefaultConfig>::config_suffix = s;
}

std::string
DefaultConfig::bashrc_files() const
{
    return _imp->bashrc_files;
}

std::string
DefaultConfig::config_suffix()
{
    return Implementation<DefaultConfig>::config_suffix;
}

DefaultConfig::RepositoryIterator
DefaultConfig::begin_repositories() const
{
    return RepositoryIterator(_imp->repos.begin());
}

DefaultConfig::RepositoryIterator
DefaultConfig::end_repositories() const
{
    return RepositoryIterator(_imp->repos.end());
}

DefaultConfig::PackageKeywordsIterator
DefaultConfig::begin_package_keywords(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<
        std::pair<PackageDepAtom::ConstPointer, KeywordName> > >::const_iterator r;
    if (_imp->keywords.end() != ((r = _imp->keywords.find(d))))
        return PackageKeywordsIterator(r->second.begin());
    else
        return PackageKeywordsIterator(_imp->empty_keywords.begin());
}

DefaultConfig::PackageKeywordsIterator
DefaultConfig::end_package_keywords(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<
        std::pair<PackageDepAtom::ConstPointer, KeywordName> > >::const_iterator r;
    if (_imp->keywords.end() != ((r = _imp->keywords.find(d))))
        return PackageKeywordsIterator(r->second.end());
    else
        return PackageKeywordsIterator(_imp->empty_keywords.end());
}

DefaultConfig::DefaultKeywordsIterator
DefaultConfig::begin_default_keywords() const
{
    return DefaultKeywordsIterator(_imp->default_keywords.begin());
}

DefaultConfig::DefaultKeywordsIterator
DefaultConfig::end_default_keywords() const
{
    return DefaultKeywordsIterator(_imp->default_keywords.end());
}

DefaultConfig::PackageLicensesIterator
DefaultConfig::begin_package_licenses(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<
        std::pair<PackageDepAtom::ConstPointer, std::string> > >::const_iterator r;
    if (_imp->licenses.end() != ((r = _imp->licenses.find(d))))
        return PackageLicensesIterator(r->second.begin());
    else
        return PackageLicensesIterator(_imp->empty_licenses.begin());
}

DefaultConfig::PackageLicensesIterator
DefaultConfig::end_package_licenses(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<
        std::pair<PackageDepAtom::ConstPointer, std::string> > >::const_iterator r;
    if (_imp->licenses.end() != ((r = _imp->licenses.find(d))))
        return PackageLicensesIterator(r->second.end());
    else
        return PackageLicensesIterator(_imp->empty_licenses.end());
}

DefaultConfig::DefaultLicensesIterator
DefaultConfig::begin_default_licenses() const
{
    return DefaultLicensesIterator(_imp->default_licenses.begin());
}

DefaultConfig::DefaultLicensesIterator
DefaultConfig::end_default_licenses() const
{
    return DefaultLicensesIterator(_imp->default_licenses.end());
}

DefaultConfig::UserMasksIterator
DefaultConfig::begin_user_masks(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> >::const_iterator r;
    if (_imp->user_masks.end() != ((r = _imp->user_masks.find(d))))
        return UserMasksIterator(indirect_iterator<const PackageDepAtom>(r->second.begin()));
    else
        return UserMasksIterator(indirect_iterator<const PackageDepAtom>(_imp->empty_masks.begin()));
}

DefaultConfig::UserMasksIterator
DefaultConfig::end_user_masks(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> >::const_iterator r;
    if (_imp->user_masks.end() != ((r = _imp->user_masks.find(d))))
        return UserMasksIterator(indirect_iterator<const PackageDepAtom>(r->second.end()));
    else
        return UserMasksIterator(indirect_iterator<const PackageDepAtom>(_imp->empty_masks.end()));
}

DefaultConfig::UserUnmasksIterator
DefaultConfig::begin_user_unmasks(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> >::const_iterator r;
    if (_imp->user_unmasks.end() != ((r = _imp->user_unmasks.find(d))))
        return UserUnmasksIterator(indirect_iterator<const PackageDepAtom>(r->second.begin()));
    else
        return UserUnmasksIterator(indirect_iterator<const PackageDepAtom>(_imp->empty_masks.begin()));
}

DefaultConfig::UserUnmasksIterator
DefaultConfig::end_user_unmasks(const QualifiedPackageName & d) const
{
    std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> >::const_iterator r;
    if (_imp->user_unmasks.end() != ((r = _imp->user_unmasks.find(d))))
        return UserUnmasksIterator(indirect_iterator<const PackageDepAtom>(r->second.end()));
    else
        return UserUnmasksIterator(indirect_iterator<const PackageDepAtom>(_imp->empty_masks.end()));
}

DefaultConfig::UseConfigIterator
DefaultConfig::begin_use_config(const QualifiedPackageName & q) const
{
    std::map<QualifiedPackageName, std::vector<UseConfigEntry> >::const_iterator r;
    if (_imp->use.end() != ((r = _imp->use.find(q))))
        return UseConfigIterator(r->second.begin());
    else
        return UseConfigIterator(_imp->empty_use.begin());
}

DefaultConfig::UseConfigIterator
DefaultConfig::end_use_config(const QualifiedPackageName & q) const
{
    std::map<QualifiedPackageName, std::vector<UseConfigEntry> >::const_iterator r;
    if (_imp->use.end() != ((r = _imp->use.find(q))))
        return UseConfigIterator(r->second.end());
    else
        return UseConfigIterator(_imp->empty_use.end());
}

DefaultConfig::DefaultUseIterator
DefaultConfig::begin_default_use() const
{
    return DefaultUseIterator(_imp->default_use.begin());
}

DefaultConfig::DefaultUseIterator
DefaultConfig::end_default_use() const
{
    return DefaultUseIterator(_imp->default_use.end());
}

std::string
DefaultConfig::paludis_command() const
{
    return _imp->paludis_command;
}

void
DefaultConfig::set_paludis_command(const std::string & s)
{
    _imp->paludis_command = s;
}

std::string
DefaultConfig::root() const
{
    return _imp->root;
}

std::string
DefaultConfig::config_dir() const
{
    return _imp->config_dir;
}

DefaultConfig::MirrorIterator
DefaultConfig::begin_mirrors(const std::string & m) const
{
    return MirrorIterator(_imp->mirrors.lower_bound(m));
}

DefaultConfig::MirrorIterator
DefaultConfig::end_mirrors(const std::string & m) const
{
    return MirrorIterator(_imp->mirrors.upper_bound(m));
}