Commit 4d68b475 authored by Marco De Marco's avatar Marco De Marco
Browse files

Properties importer methods and minor changes

parent ca098181
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public:
	std::string getDatabasePassword() const { return m_databasePassword; };
    ExportedTablesMap& getExportedTablesMap() const { return m_exportedTablesMap; }

    bool find(const std::string schema, const std::string table)
    bool isTableExported(const std::string schema, const std::string table)
    {
        std::pair<ExportedTablesMap::const_iterator, ExportedTablesMap::const_iterator > ret;

@@ -150,7 +150,6 @@ protected:

    //Authorised users map [user password]
	AuthorisedUsersMap m_authorisedUsersMap;

};

}   //End of namespace
+66 −48
Original line number Diff line number Diff line
@@ -156,9 +156,9 @@ void MetadataExporter::init_device()
        try
        {
            if(enableSSL)
                m_server_sp = SSLServer::create(this, configuration_sp);
                m_server_sp = SSLServer::create(this, m_configuration_sp);
            else
                m_server_sp = PlainServer::create(this, configuration_sp);
                m_server_sp = PlainServer::create(this, m_configuration_sp);
        }
        catch(std::exception& ex)
        {
@@ -409,56 +409,14 @@ void MetadataExporter::get_device_property()
        if(exportedTables.empty())
            throw(invalid_argument("ExportedTables property is empty or not defined"));

        for(unsigned int i=0; i<exportedTables.size(); ++i)
        {
            std::size_t found;

            if((found=exportedTables.at(i).find(' '))==std::string::npos)
            {
                std::stringstream errorStream;
                errorStream << "ExportedTables property has invalid key at "
                    << i << " position" << std::endl;
                throw(errorStream.str());
            }

            std::string schema = exportedTables.at(i).substr(0, found);
            std::string table = exportedTables.at(i).substr(found+1, std::string::npos);

            #ifdef VERBOSE_DEBUG
                INFO_STREAM << "SCHEMA: " << schema << " TABLE: " << table << endl;
                INFO_STREAM << "-------------------------------------------------" << endl;
            #endif

            exportedTablesMap.insert(std::pair<const std::string, const std::string> (schema, table));
        }
        importExportedTables(exportedTables, exportedTablesMap);

        if(authorisedUsers.empty())
            throw(invalid_argument("AuthorisedUsers property is empty or not defined"));

        for(unsigned int i=0; i<authorisedUsers.size(); ++i)
        {
            std::size_t found;

            if((found=authorisedUsers.at(i).find(' '))==std::string::npos)
            {
                std::stringstream errorStream;
                errorStream << "AuthorisedUsers property has invalid key at "
                    << i << " position" << std::endl;
                throw(errorStream.str());
            }

            std::string user = authorisedUsers.at(i).substr(0, found);
            std::string password = authorisedUsers.at(i).substr(found+1, std::string::npos);
        importAuthorisedUsers(authorisedUsers, authorisedUsersMap);

            #ifdef VERBOSE_DEBUG
                INFO_STREAM << "USER: " << user << " PASSWORD: " << password << endl;
                INFO_STREAM << "-------------------------------------------------" << endl;
            #endif

            authorisedUsersMap.insert(std::pair<const std::string, const std::string>(user, password));
        }

        configuration_sp = Configuration::create(certificateFile,
        m_configuration_sp = Configuration::create(certificateFile,
            privateKeyFile, dHTempFile, localHost, localPort, workerNumber,
            databaseHost, databasePort, databaseUsername, databasePassword,
            exportedTablesMap, authorisedUsersMap);
@@ -598,7 +556,67 @@ void MetadataExporter::off()

/*----- PROTECTED REGION ID(MetadataExporter::namespace_ending) ENABLED START -----*/

//	Additional Methods
//==============================================================================
//      MetadataExporter::importExportedTables()
//==============================================================================
void MetadataExporter::importExportedTables(std::vector<std::string>& exportedTables,
    std::multimap<const std::string, const std::string>& exportedTablesMap)
    throw(std::invalid_argument)
{
    for(unsigned int i=0; i<exportedTables.size(); ++i)
    {
        std::size_t found;

        if((found=exportedTables.at(i).find(' '))==std::string::npos)
        {
            std::stringstream errorStream;
            errorStream << "ExportedTables property has invalid key at "
                << i << " position" << std::endl;
            throw std::invalid_argument(errorStream.str());
        }

        std::string schema = exportedTables.at(i).substr(0, found);
        std::string table = exportedTables.at(i).substr(found+1, std::string::npos);

        #ifdef VERBOSE_DEBUG
            INFO_STREAM << "SCHEMA: " << schema << " TABLE: " << table << endl;
            INFO_STREAM << "-------------------------------------------------" << endl;
        #endif

        exportedTablesMap.insert(std::pair<const std::string, const std::string> (schema, table));
    }
}

//==============================================================================
//      MetadataExporter::importAuthorisedUsers()
//==============================================================================
void MetadataExporter::importAuthorisedUsers(std::vector<std::string>& authorisedUsers,
    std::map<const std::string, const std::string>& authorisedUsersMap)
    throw(std::invalid_argument)
{
        for(unsigned int i=0; i<authorisedUsers.size(); ++i)
        {
            std::size_t found;

            if((found=authorisedUsers.at(i).find(' '))==std::string::npos)
            {
                std::stringstream errorStream;
                errorStream << "AuthorisedUsers property has invalid key at "
                    << i << " position" << std::endl;
                throw std::invalid_argument(errorStream.str());
            }

            std::string user = authorisedUsers.at(i).substr(0, found);
            std::string password = authorisedUsers.at(i).substr(found+1, std::string::npos);

            #ifdef VERBOSE_DEBUG
                INFO_STREAM << "USER: " << user << " PASSWORD: " << password << endl;
                INFO_STREAM << "-------------------------------------------------" << endl;
            #endif

            authorisedUsersMap.insert(std::pair<const std::string, const std::string>(user, password));
        }
}

/*----- PROTECTED REGION END -----*/	//	MetadataExporter::namespace_ending
} //	namespace
+8 −2
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class MetadataExporter : public TANGO_BASE_CLASS
//  [Private] Class variables
//------------------------------------------------------------------------------
    //Configuration class shared pointer
    Configuration::SP configuration_sp;
    Configuration::SP m_configuration_sp;

    //Server base class shared pointer
    Server::SP m_server_sp;
@@ -207,7 +207,13 @@ public:

/*----- PROTECTED REGION ID(MetadataExporter::Additional Method prototypes) ENABLED START -----*/

//	Additional Method prototypes
    virtual void importExportedTables(std::vector<std::string>&,
        std::multimap<const std::string, const std::string>&)
        throw(std::invalid_argument);

    virtual void importAuthorisedUsers(std::vector<std::string>&,
        std::map<const std::string, const std::string>&)
        throw(std::invalid_argument);

/*----- PROTECTED REGION END -----*/	//	MetadataExporter::Additional Method prototypes
};
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ void PlainSession::handleRequest()

    response_sp->SerializeToArray(&writeBuff[HEADER_SIZE], bodySize);

    //TODO: srand!!!! FIXME
    //TODO: strand!!!! FIXME
    boost::asio::write(m_plainSocket, boost::asio::buffer(writeBuff));
}

+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ Tango::DevState Server::readState()
}

//==============================================================================
//      Client::getStatus()
//      Client::readStatus()
//==============================================================================
std::string Server::readStatus()
{
Loading