aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-18 06:31:17 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-18 06:31:17 +0000
commita6a9e5928371523e784171ca8a025514df1c6509 (patch)
tree861ec390dc1a3715dc28c55cd1696c2c43223768
parentcf84ad282eca676d3411b4edf548eadd82d2731e (diff)
downloadpaludis-a6a9e5928371523e784171ca8a025514df1c6509.tar.gz
paludis-a6a9e5928371523e784171ca8a025514df1c6509.tar.xz
Check SRC_URI
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/src_uri_check.cc141
-rw-r--r--paludis/qa/src_uri_check.hh51
3 files changed, 193 insertions, 0 deletions
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index e2dcffd..6d33b51 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -36,6 +36,7 @@ add(`package_dir_check', `hh', `cc')
add(`package_name_check', `hh', `cc', `test', `testscript')
add(`parse_deps_check', `hh', `cc')
add(`rdepend_packages_check', `hh', `cc')
+add(`src_uri_check', `hh', `cc')
add(`pdepend_overlap_check', `hh', `cc')
add(`qa', `hh', `cc')
add(`slot_check', `hh', `cc')
diff --git a/paludis/qa/src_uri_check.cc b/paludis/qa/src_uri_check.cc
new file mode 100644
index 0000000..bd0e67d
--- /dev/null
+++ b/paludis/qa/src_uri_check.cc
@@ -0,0 +1,141 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.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 "src_uri_check.hh"
+#include <paludis/nest_atom.hh>
+#include <paludis/nest_parser.hh>
+#include <paludis/tokeniser.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+namespace
+{
+ struct Checker :
+ NestAtomVisitorTypes::ConstVisitor
+ {
+ CheckResult & result;
+ bool fetch_restrict;
+
+ Checker(CheckResult & rr, bool f) :
+ result(rr),
+ fetch_restrict(f)
+ {
+ }
+
+ void visit(const TextNestAtom * const a)
+ {
+ if (a->text().empty())
+ return;
+
+ std::string::size_type p(std::string::npos);
+ if ((! fetch_restrict) && std::string::npos == ((p = a->text().find("://"))))
+ result << Message(qal_major, "No protocol found for '" + a->text() +
+ "' and not fetch restricted");
+
+ else if (("http" != a->text().substr(0, p)) &&
+ ("https" != a->text().substr(0, p)) &&
+ ("mirror" != a->text().substr(0, p)) &&
+ ("ftp" != a->text().substr(0, p)))
+ result << Message(qal_major, "Unrecognised protocol for '" + a->text() + "'");
+
+ else if ((std::string::npos != a->text().find("dev.gentoo.org")) ||
+ (std::string::npos != a->text().find("cvs.gentoo.org")) ||
+ (std::string::npos != a->text().find("toucan.gentoo.org")) ||
+ (std::string::npos != a->text().find("emu.gentoo.org")) ||
+ (std::string::npos != a->text().find("geocities.com")))
+ result << Message(qal_major, "Unreliable host for '" + a->text() + "'");
+ }
+
+ void visit(const AllNestAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const UseNestAtom * const u)
+ {
+ std::for_each(u->begin(), u->end(), accept_visitor(this));
+ }
+ };
+}
+
+SrcUriCheck::SrcUriCheck()
+{
+}
+
+CheckResult
+SrcUriCheck::operator() (const EbuildCheckData & e) const
+{
+ CheckResult result(stringify(e.get<ecd_name>()) + "-" + stringify(e.get<ecd_version>()),
+ identifier());
+
+ try
+ {
+ do
+ {
+ PackageDatabaseEntry ee(e.get<ecd_name>(), e.get<ecd_version>(),
+ e.get<ecd_environment>()->package_database()->favourite_repository());
+ VersionMetadata::ConstPointer metadata(
+ e.get<ecd_environment>()->package_database()->fetch_metadata(ee));
+
+ std::string src_uri(metadata->get(vmk_src_uri));
+
+ NestAtom::ConstPointer src_uri_parts(0);
+ try
+ {
+ src_uri_parts = NestParser::parse(src_uri);
+
+ std::set<std::string> restricts;
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser(" \t\n");
+ tokeniser.tokenise(metadata->get(vmk_restrict),
+ std::inserter(restricts, restricts.begin()));
+
+ bool fetch_restrict(restricts.end() != restricts.find("fetch"));
+ Checker checker(result, fetch_restrict);
+ src_uri_parts->accept(&checker);
+ }
+ catch (const DepStringError & e)
+ {
+ result << Message(qal_major, "Invalid SRC_URI: '" + e.message() + "' ("
+ + e.what() + ")");
+ break;
+ }
+ } while (false);
+ }
+ catch (const InternalError &)
+ {
+ throw;
+ }
+ catch (const Exception & e)
+ {
+ result << Message(qal_fatal, "Caught Exception '" + e.message() + "' ("
+ + e.what() + ")");
+ }
+
+ return result;
+}
+
+const std::string &
+SrcUriCheck::identifier()
+{
+ static const std::string id("src_uri");
+ return id;
+}
+
+
diff --git a/paludis/qa/src_uri_check.hh b/paludis/qa/src_uri_check.hh
new file mode 100644
index 0000000..58e8bfc
--- /dev/null
+++ b/paludis/qa/src_uri_check.hh
@@ -0,0 +1,51 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_QA_SRC_URI_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_SRC_URI_CHECK_HH 1
+
+#include <paludis/qa/ebuild_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class SrcUriCheck :
+ public EbuildCheck
+ {
+ public:
+ SrcUriCheck();
+
+ CheckResult operator() (const EbuildCheckData &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks that SRC_URI is sane";
+ }
+ };
+
+ static const EbuildCheckMaker::RegisterMaker register_src_uri_check(
+ SrcUriCheck::identifier(), &MakeEbuildCheck<SrcUriCheck>::make_ebuild_check);
+ }
+}
+
+#endif