Confdump Agent  1.4.0
InittabEntry.cpp
Go to the documentation of this file.
00001 /* 
00002  * Confdump-Agent - Dump static and runtime system configuration
00003  * Copyright (C) 2009-2012  Straton IT, SAS
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include "boost/foreach.hpp"
00019 #include "QRegExp"
00020 
00021 #include "Confdump/System/LinuxDumper.hpp"
00022 #include "Confdump/System/Linux/InittabEntry.hpp"
00023 
00024 using boost::shared_ptr;
00025 
00026 namespace Confdump
00027 {
00028 
00029 namespace System
00030 {
00031 
00032 namespace Linux
00033 {
00034 
00035 InittabEntry::InittabEntry( QString line )
00036 {
00037     QStringList fields = line.split( ':' );
00038 
00039     if ( !fields.isEmpty() )
00040         id_ =  fields.takeFirst();
00041 
00042     if ( !fields.isEmpty() )
00043         runlevels_ = fields.takeFirst();
00044 
00045     if ( !fields.isEmpty() )
00046         action_ = fields.takeFirst();
00047 
00048     if ( !fields.isEmpty() )
00049         path_ = fields.join( ":" );
00050 }
00051 
00052 InittabEntry::~InittabEntry()
00053 {
00054 }
00055 
00056 QString InittabEntry::identifier() const
00057 {
00058     return id_;
00059 }
00060 
00061 QString InittabEntry::runlevels() const
00062 {
00063     return runlevels_;
00064 }
00065 
00066 QString InittabEntry::action() const
00067 {
00068     return action_;
00069 }
00070 
00071 QString InittabEntry::path() const
00072 {
00073     return path_;
00074 }
00075 
00076 std::vector< shared_ptr< InittabEntry > > InittabEntry::allInittabEntries( boost::shared_ptr<LinuxDumper> driver )
00077 {
00078     QByteArray contents = driver->systemContext().slurpConfigurationFile( boost::filesystem::path( "/etc/inittab" ), "CD_InittabEntry" );
00079     QStringList lines = QString::fromLocal8Bit( contents ).split( '\n' );
00080 
00081     std::vector< shared_ptr< InittabEntry > > entries;
00082     QRegExp commentLineDefinition( "\\s*(?:#.*)?" );
00083     BOOST_FOREACH( QString line, lines )
00084     {
00085         if ( !commentLineDefinition.exactMatch( line ) )
00086             entries.push_back( shared_ptr<InittabEntry>( new InittabEntry( line ) ) );
00087     }
00088 
00089     return entries;
00090 }
00091 
00092 } // ns Linux
00093 } // ns System
00094 } // ns Confdump
00095 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends