Ejemplo n.º 1
0
void XmlStore::flush( Object * _obj )
{
    QDomDocument doc( "ItalcXmlStore" );
    const Object::DataMap & data = _obj->data();

    QDomElement root = doc.createElement( configurationNameFromScope() );
    saveXmlTree( data, doc, root );
    doc.appendChild( root );

    QFile outfile( m_file.isEmpty() ? configurationFilePath() : m_file );
    if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
    {
        qCritical() << "XmlStore::flush(): could not write to configuration file"
                    << configurationFilePath();
        return;
    }

    QTextStream( &outfile ) << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    outfile.write( doc.toByteArray( 2 ) );
    //qDebug() << doc.toString( 2 );
}
Ejemplo n.º 2
0
void XmlStore::load( Object * _obj )
{
    QDomDocument doc;
    QFile xmlFile( m_file.isEmpty() ? configurationFilePath() : m_file );
    if( !xmlFile.open( QFile::ReadOnly ) || !doc.setContent( &xmlFile ) )
    {
        qWarning() << "Could not open" << xmlFile.fileName();
        return;
    }

    QDomElement root = doc.documentElement();
    loadXmlTree( _obj, root, QString() );
}
Ejemplo n.º 3
0
    /**
     * Module initialization function. The initialization arguments string should
     * provide the path of a module configuration file that defines what files 
     * are interesting. If the empty string is passed to this function, the module
     * assumes a default config file is present in the output directory.
     *
     * @param args Path of the configuration file that defines what files are 
     * interesting, may be set to the empty string.
     * @return TskModule::OK on success, TskModule::FAIL otherwise. 
     */
    TSK_MODULE_EXPORT TskModule::Status initialize(const char* arguments)
    {
        TskModule::Status status = TskModule::OK;

        const std::string MSG_PREFIX = "InterestingFilesModule::initialize : ";
        try
        {
            // Make sure the file sets are cleared in case initialize() is called more than once.
            fileSets.clear();

            configFilePath.assign(arguments);
            if (configFilePath.empty())
            {
                // Use the default config file path.
                Poco::Path configurationFilePath(Poco::Path::forDirectory(GetSystemProperty(TskSystemProperties::MODULE_CONFIG_DIR)));
                configurationFilePath.pushDirectory(MODULE_NAME);
                configurationFilePath.setFileName(DEFAULT_CONFIG_FILE_NAME);
                configFilePath = configurationFilePath.toString();
            }

            // Compile the contents of the config file into interesting file set definitions.
            Poco::File configFile = Poco::File(configFilePath);
            if (configFile.exists())
            {
                std::ifstream configStream(configFile.path().c_str());
                if (configStream)
                {
                    Poco::XML::InputSource inputSource(configStream);
                    Poco::AutoPtr<Poco::XML::Document> configDoc = Poco::XML::DOMParser().parse(&inputSource);

                    Poco::XML::Element * rootElement = configDoc->documentElement();
                    if (rootElement == NULL)
                    {
                        std::ostringstream msg;
                        msg << MSG_PREFIX << "Root element of config file is NULL.";
                        throw TskException(msg.str());
                    }

                    const std::string& ignoreKnownValue = Poco::XML::fromXMLString(rootElement->getAttribute(IGNORE_KNOWN_TAG));

                    if (!ignoreKnownValue.empty())
                    {
                        knownType = parseKnownType(ignoreKnownValue);
                        ignoreKnown = true;
                    }

                    Poco::AutoPtr<Poco::XML::NodeList> fileSetDefinitions = configDoc->getElementsByTagName(INTERESTING_FILE_SET_ELEMENT_TAG);
                    for (unsigned long i = 0; i < fileSetDefinitions->length(); ++i) 
                    {
                        compileInterestingFilesSet(fileSetDefinitions->item(i));
                    }
                }
                else
                {
                    std::ostringstream msg;
                    msg << MSG_PREFIX << "failed to open config file '" << configFilePath << "'";
                    throw TskException(msg.str());
                }
            }
            else
            {
                std::ostringstream msg;
                msg << MSG_PREFIX << "config file'" << configFilePath << "' does not exist";
                LOGERROR(msg.str());
            }

            // Log the configuration.
            std::ostringstream msg;
            msg << MSG_PREFIX << "configured with " << fileSets.size() << " interesting file set definitions from '" << configFilePath << "'";
            LOGINFO(msg.str());
        }
        catch (TskException &ex)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            std::ostringstream msg;
            msg << MSG_PREFIX << "TskException: " << ex.message();
            LOGERROR(msg.str());
        }
        catch (Poco::Exception &ex)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            std::ostringstream msg;
            msg << MSG_PREFIX << "Poco::Exception: " << ex.displayText();
            LOGERROR(msg.str());
        }
        catch (std::exception &ex)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            std::ostringstream msg;
            msg << MSG_PREFIX << "std::exception: " << ex.what();
            LOGERROR(msg.str());
        }
        catch (...)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            LOGERROR(MSG_PREFIX + "unrecognized exception");
        }

        return status;
    }
Ejemplo n.º 4
0
QString SGMDacqConfigurationFile::configurationFileFullPath() const{
	return configurationFilePath()+"/"+configurationFileName();
}
Ejemplo n.º 5
0
bool XmlStore::isWritable() const
{
    return QFileInfo( m_file.isEmpty() ?
                      configurationFilePath() : m_file ).isWritable();

}