Exemplo n.º 1
0
float getNormals(Eigen::Vector3f& a,Eigen::Vector3f& b,Eigen::Vector3f& c,std::string path)
{
	std::ifstream file(path.c_str());
	std::string line;

	std::string words;

	float value;

	float normals[3][3];

	std::getline(file,line);
	std::istringstream streamer(line);

	streamer>>words;

	if(words.compare("VALUE")==0){
		std::string nextline;
		std::getline(file,nextline);
		std::istringstream valuestream(nextline);
		valuestream>>value;
	}
Exemplo n.º 2
0
bool MemcachedSessionManager::load_session(std::string const &sessionid, Session &session)
{
    memcached_return_t rc;
    size_t value_length;
    char *value = memcached_get(memcached_conn,
            sessionid.data(), sessionid.length(),
            &value_length, 0, &rc);
    if (memcached_success(rc))
    {
        std::stringstream valuestream(std::string(value, value_length));
        parse_pairs(valuestream, '\n', session.data());
        uint64_t userid = 0;
        try {
            userid = std::stoi(session.get("userid"));
        } catch (std::exception const &ex)
        {
            LOG_MESSAGE_WARN("Invalid userid in session data");
            return false;
        }
        session.set(User::find(database(), userid), sessionid);
    }
    if (value != NULL) free(value);
    return memcached_success(rc);
}
Exemplo n.º 3
0
int LdifReader::readNextRecord( bool first )
{
    DEBUG(LDAP_DEBUG_TRACE, "-> LdifReader::readRecord()" << std::endl);
    std::string line;
    std::string type;
    std::string value;
    int numLine = 0;
    int recordType = 0;

    if ( (! first) && this->m_currentIsFirst == true )
    {
        this->m_currentIsFirst = false;
        return m_curRecType;
    }

    m_currentRecord.clear();

    while ( !this->getLdifLine(line) )
    {
        DEBUG(LDAP_DEBUG_TRACE, "  Line: " << line << std::endl );

        // skip comments and empty lines between entries
        if ( line[0] == '#' || ( numLine == 0 && line.size() == 0 ) )
        {
            DEBUG(LDAP_DEBUG_TRACE, "skipping empty line or comment" << std::endl );
            continue;
        }
        if ( line.size() == 0 ) 
        {
            // End of Entry
            break;
        }

        this->splitLine(line, type, value);

        if ( numLine == 0 )
        {
            if ( type == "version" )
            {
                std::istringstream valuestream(value);
                valuestream >> this->m_version;
                if ( this->m_version != 1 ) // there is no other Version than LDIFv1 
                {
                    std::ostringstream err;
                    err << "Line " << this->m_lineNumber 
                        << ": Unsuported LDIF Version";
                    throw( std::runtime_error(err.str()) );
                }
                continue;
            }
            if ( type == "dn" ) // Record should start with the DN ...
            {
                DEBUG(LDAP_DEBUG_TRACE, " Record DN:" << value << std::endl);
            }
            else if ( type == "include" ) // ... or it might be an "include" line
            {
                DEBUG(LDAP_DEBUG_TRACE, " Include directive: " << value << std::endl);
                if ( this->m_version == 1 )
                {
                    std::ostringstream err;
                    err << "Line " << this->m_lineNumber 
                        << ": \"include\" not allowed in LDIF version 1.";
                    throw( std::runtime_error(err.str()) );
                }
                else
                {
                    std::ostringstream err;
                    err << "Line " << this->m_lineNumber 
                        << ": \"include\" not yet suppported.";
                    throw( std::runtime_error(err.str()) );
                }
            }
            else
            {
                DEBUG(LDAP_DEBUG_TRACE, " Record doesn't start with a DN" 
                            << std::endl);
                std::ostringstream err;
                err << "Line " << this->m_lineNumber 
                    << ": LDIF record does not start with a DN.";
                throw( std::runtime_error(err.str()) );
            }
        }
        if ( numLine == 1 ) // might contain "changtype" to indicate a change request
        {
            if ( type == "changetype" ) 
            {
                if ( first ) 
                {
                    this->m_ldifTypeRequest = true;
                }
                else if (! this->m_ldifTypeRequest )
                {
                    // Change Request in Entry record LDIF, should we accept it?
                    std::ostringstream err;
                    err << "Line " << this->m_lineNumber 
                        << ": Change Request in an entry-only LDIF.";
                    throw( std::runtime_error(err.str()) );
                }
                if ( value == "modify" )
                {
                    recordType = LDAPMsg::MODIFY_REQUEST;
                }
                else if ( value == "add" )
                {
                    recordType = LDAPMsg::ADD_REQUEST;
                }
                else if ( value == "delete" )
                {
                    recordType = LDAPMsg::DELETE_REQUEST;
                }
                else if ( value == "modrdn" )
                {   
                    recordType = LDAPMsg::MODRDN_REQUEST;
                }
                else
                {
                    DEBUG(LDAP_DEBUG_TRACE, " Unknown change request <" 
                            << value << ">" << std::endl);
                    std::ostringstream err;
                    err << "Line " << this->m_lineNumber 
                        << ": Unknown changetype: \"" << value << "\".";
                    throw( std::runtime_error(err.str()) );
                }
            }
            else
            {
                if ( first ) 
                {
                    this->m_ldifTypeRequest = false;
                }
                else if (this->m_ldifTypeRequest )
                {
                    // Entry record in Change record LDIF, should we accept 
                    // it (e.g. as AddRequest)?
                }
                recordType = LDAPMsg::SEARCH_ENTRY;
            }
        }
        m_currentRecord.push_back( stringpair(type, value) );
        numLine++;
    }