2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file SignatureFinder.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Search for author-signature.xml and signatureN.xml files.
22 #include <vcore/SignatureFinder.h>
23 #include <dpl/log/log.h>
33 namespace ValidationCore {
34 static const char *SIGNATURE_AUTHOR = "author-signature.xml";
35 static const char *REGEXP_DISTRIBUTOR_SIGNATURE =
36 "^(signature)([1-9][0-9]*)(\\.xml)";
38 class SignatureFinder::Impl {
40 Impl(const std::string& dir)
42 , m_signatureRegexp(REGEXP_DISTRIBUTOR_SIGNATURE)
47 Result find(SignatureFileInfoSet &set);
51 pcrecpp::RE m_signatureRegexp;
54 SignatureFinder::Result SignatureFinder::Impl::find(SignatureFileInfoSet &set)
62 if ((dp = opendir(m_dir.c_str())) == NULL) {
63 LogError("Error opening directory: " << m_dir);
64 return ERROR_OPENING_DIR;
67 for (errno = 0; (dirp = readdir(dp)) != NULL; errno = 0) {
69 * check if it's author signature
71 if (!strcmp(dirp->d_name, SIGNATURE_AUTHOR)) {
72 set.insert(SignatureFileInfo(std::string(dirp->d_name), -1));
76 std::string sig, num, xml;
77 if (m_signatureRegexp.FullMatch(dirp->d_name, &sig, &num, &xml)) {
78 std::istringstream stream(num);
87 set.insert(SignatureFileInfo(std::string(dirp->d_name), number));
92 LogError("Error in readdir");
94 return ERROR_READING_DIR;
101 SignatureFinder::SignatureFinder(const std::string& dir)
102 : m_impl(new Impl(dir))
105 SignatureFinder::~SignatureFinder()
110 SignatureFinder::Result SignatureFinder::find(SignatureFileInfoSet &set) {
111 return m_impl->find(set);
114 } // namespace ValidationCore