[Oval-commits] r94 - in trunk/Interpreters/src: linux probes/independent solaris windows

Pavel Vinogradov blaze-guest at alioth.debian.org
Thu Jul 19 19:40:39 UTC 2007


Author: blaze-guest
Date: 2007-07-19 19:40:39 +0000 (Thu, 19 Jul 2007)
New Revision: 94

Modified:
   trunk/Interpreters/src/linux/ProbeFactory.cpp
   trunk/Interpreters/src/probes/independent/TextFileContentProbe.cpp
   trunk/Interpreters/src/probes/independent/TextFileContentProbe.h
   trunk/Interpreters/src/solaris/ProbeFactory.cpp
   trunk/Interpreters/src/windows/ProbeFactory.cpp
Log:
Work on implementation of TextFileContentProbe. Currently unfisished

Modified: trunk/Interpreters/src/linux/ProbeFactory.cpp
===================================================================
--- trunk/Interpreters/src/linux/ProbeFactory.cpp	2007-07-19 19:36:12 UTC (rev 93)
+++ trunk/Interpreters/src/linux/ProbeFactory.cpp	2007-07-19 19:40:39 UTC (rev 94)
@@ -54,7 +54,7 @@
 	} else if(objectName.compare("environmentvariable_object") == 0) {
 		probe = EnvironmentVariableProbe::Instance();
 	} else if(objectName.compare("textfilecontent_object") == 0) {
-		//probe = TextFileContentProbe::Instance();
+		probe = TextFileContentProbe::Instance();
 	} else if(objectName.compare("variable_object") == 0) {
 		probe = VariableProbe::Instance();
 	} else if(objectName.compare("xmlfilecontent_object") == 0) {

Modified: trunk/Interpreters/src/probes/independent/TextFileContentProbe.cpp
===================================================================
--- trunk/Interpreters/src/probes/independent/TextFileContentProbe.cpp	2007-07-19 19:36:12 UTC (rev 93)
+++ trunk/Interpreters/src/probes/independent/TextFileContentProbe.cpp	2007-07-19 19:40:39 UTC (rev 94)
@@ -115,6 +115,7 @@
 		}
 
 	} else {
+
 		// if no filepaths check if the code should report that the path does not exist
 		StringVector paths;
 		if(fileFinder.ReportPathDoesNotExist(path, &paths)) {
@@ -165,14 +166,81 @@
 		filePath.append(fileName.substr(1, fileName.length()-2));
 	}
 
+
 	// read the file line by line
+	StringVector* results = new StringVector();
+	string buffer;
+	ifstream infile;
+	infile.open (filePath.c_str());
+	if (infile.is_open())
+	{
+		while (! infile.eof())
+		{
+			// call the GetSubstrings method	
+			getline (infile, buffer);
+			if (this->GetSubstrings (buffer, line, results))
+			{
+				StringVector::iterator iterator;
+				for (iterator = results->begin(); iterator != results->end(); iterator++) 
+				{
+					Log::Debug ("Good string: " + (*iterator));
+					item = this->CreateItem();
+					item->SetStatus(OvalEnum::STATUS_EXISTS);
+					item->AppendElement(new ItemEntity("path", path, OvalEnum::DATATYPE_STRING, true, OvalEnum::STATUS_EXISTS));
+					item->AppendElement(new ItemEntity("filename", fileName, OvalEnum::DATATYPE_STRING, true, OvalEnum::STATUS_EXISTS));
+					item->AppendElement(new ItemEntity("line", line->GetValue(), OvalEnum::DATATYPE_STRING, true, OvalEnum::STATUS_EXISTS));
+					item->AppendElement(new ItemEntity("value_of", (*iterator), OvalEnum::DATATYPE_STRING, false, OvalEnum::STATUS_EXISTS));
+				}
+			} else {
+				Log::Debug ("Bad string: " + buffer);
+			}
+		}
+		infile.close();
+	}
 
-	// call the GetSubstrings method	
-
 	return item;
 }
 
-bool TextFileContentProbe::GetSubsrtings(string lineFromFile, ObjectEntity* line, StringVector* substrings) {
+bool TextFileContentProbe::GetSubstrings(string lineFromFile, ObjectEntity* line, StringVector* substrings) {
+	bool retVal = false;
+	string pattern = line->GetValue();
 
-	return false;
-}
\ No newline at end of file
+	switch (line->GetOperation()) {
+
+		case OvalEnum::OPERATION_EQUALS:
+			Log::Debug ("Test equals of " + lineFromFile + " and " + pattern);
+			if (this->IsMatch (pattern, lineFromFile, false) )
+			{
+				substrings->push_back (lineFromFile);
+				retVal = true;
+			}
+			break;
+
+		case OvalEnum::OPERATION_NOT_EQUAL:
+			Log::Debug ("Test not equal of " + lineFromFile + " and " + pattern);
+			if (not this->IsMatch (pattern, lineFromFile, false) )
+			{
+				substrings->push_back (lineFromFile);
+				retVal = true;
+			}
+			break;
+
+		case OvalEnum::OPERATION_PATTERN_MATCH:
+			Log::Debug ("Test pattern match of " + lineFromFile + " and " + pattern);
+			if (this->IsMatch (pattern, lineFromFile, true) )
+			{
+				Log::Debug ("Pass");
+				substrings->push_back (lineFromFile);
+				retVal = true;
+			} else {
+				Log::Debug ("Miss");
+				Log::Debug ("Line " + lineFromFile); Log::Debug (" not match to " + pattern);
+			}
+			break;
+
+		default:
+			retVal = false;
+	}
+
+	return retVal;
+}

Modified: trunk/Interpreters/src/probes/independent/TextFileContentProbe.h
===================================================================
--- trunk/Interpreters/src/probes/independent/TextFileContentProbe.h	2007-07-19 19:36:12 UTC (rev 93)
+++ trunk/Interpreters/src/probes/independent/TextFileContentProbe.h	2007-07-19 19:40:39 UTC (rev 94)
@@ -34,7 +34,7 @@
 
 #include "FileFinder.h"
 #include "AbsProbe.h"
-
+#include <fstream>
 #ifdef WIN32
 	#define SNPRINTF _snprintf
 #else
@@ -45,7 +45,7 @@
 
 /**
 	This class is responsible for collecting date for the :ind-sctextfilecontent_item definied OVAL System Characteristics Schema.
-	This class should be platform independant.
+	This class should be platform independent.
 */
 class TextFileContentProbe : public AbsProbe {
 
@@ -71,7 +71,7 @@
 
 		TODO: need to implement
 	*/
-	bool GetSubsrtings(string lineFromFile, ObjectEntity* line, StringVector* substrings);
+	bool GetSubstrings(string lineFromFile, ObjectEntity* line, StringVector* substrings);
 
 	/** Read the specified file one line at time and add matching lines to the resultiong Item.
 		Call out to the GetSubstrings function to determine if a given line in a file matches the criteria

Modified: trunk/Interpreters/src/solaris/ProbeFactory.cpp
===================================================================
--- trunk/Interpreters/src/solaris/ProbeFactory.cpp	2007-07-19 19:36:12 UTC (rev 93)
+++ trunk/Interpreters/src/solaris/ProbeFactory.cpp	2007-07-19 19:40:39 UTC (rev 94)
@@ -65,7 +65,8 @@
 		// SOLARIS PORT NOTICE: This probe was written for linux and windows systems and needs to be tested on solaris systems
 		probe = EnvironmentVariableProbe::Instance();
 	} else if(objectName.compare("textfilecontent_object") == 0) {
-		// not currently implemented
+		// SOLARIS PORT NOTICE: This probe was written for linux and windows systems and needs to be tested on solaris systems
+		probe = TextFileContentProbe::Instance();
 	} else if(objectName.compare("variable_object") == 0) {
 		// SOLARIS PORT NOTICE: This probe was written for linux and windows systems and needs to be tested on solaris systems
 		probe = VariableProbe::Instance();

Modified: trunk/Interpreters/src/windows/ProbeFactory.cpp
===================================================================
--- trunk/Interpreters/src/windows/ProbeFactory.cpp	2007-07-19 19:36:12 UTC (rev 93)
+++ trunk/Interpreters/src/windows/ProbeFactory.cpp	2007-07-19 19:40:39 UTC (rev 94)
@@ -61,7 +61,7 @@
 	} else if(objectName.compare("variable_object") == 0) {
 		probe = VariableProbe::Instance();
 	} else if(objectName.compare("textfilecontent_object") == 0) {
-		//probe = TextFileContentProbe::Instance();
+		probe = TextFileContentProbe::Instance();
 	} else if(objectName.compare("xmlfilecontent_object") == 0) {
 		probe = XmlFileContentProbe::Instance();
 	} else if(objectName.compare("filehash_object") == 0) {
@@ -126,6 +126,9 @@
 	probe = VariableProbe::Instance();
 	delete probe;
 
+	probe = TextFileContentProbe::Instance();
+	delete probe;
+
 	probe = XmlFileContentProbe::Instance();
 	delete probe;
 




More information about the Oval-commits mailing list