コード例 #1
0
void DebugInfoXmlWriter::WriteChildProcessEntry(const Debug::DebugeeInfo& debuggeeInfo, const std::multimap<DWORD, DWORD>& mmapChildProcesses, DWORD dwProcessId)
{
   m_spWriter->WriteStartElement(_T("process"));

   if (dwProcessId == 0)
      m_spWriter->WriteAttributeString(_T("image-name"), _T("debugger"));
   else
   {
      CString cszText; cszText.Format(_T("0x%08x"), dwProcessId);
      m_spWriter->WriteAttributeString(_T("pid"), cszText);

      if (debuggeeInfo.IsProcessInfoAvail(dwProcessId))
      {
         const Debug::ProcessInfo processInfo = debuggeeInfo.GetProcessInfo(dwProcessId);
         m_spWriter->WriteAttributeString(_T("image-name"), processInfo.ImageName());
      }
      else
         m_spWriter->WriteAttributeString(_T("image-name"), _T("unknown"));
   }
   m_spWriter->WriteStartElementEnd();

   // find all child entries
   std::multimap<DWORD, DWORD>::const_iterator iter = mmapChildProcesses.find(dwProcessId);
   while (iter != mmapChildProcesses.end() && iter->first == dwProcessId)
   {
      WriteChildProcessEntry(debuggeeInfo, mmapChildProcesses, iter->second);
      ++iter;
   }

   m_spWriter->WriteEndElement();
}
コード例 #2
0
ファイル: PatternLink.cpp プロジェクト: mcdir/GrammarEngine
void PatternLink::GenerateConnections( const std::multimap<lem::UCString,const Word_Form*> & points, SynPatternResult * cur_result ) const
{
 typedef std::multimap<lem::UCString,const Word_Form*>::const_iterator IT;
 IT it_from = points.find( from_marker );
 if( it_from==points.end() )
  {
   lem::MemFormatter mem;
   mem.printf( "Can not find node %us.%us to create link head", from_marker.c_str(), from_node.c_str() );
   throw lem::E_BaseException( mem.string() );
  }

 const Word_Form * node0 = it_from->second;

 std::pair<IT,IT> pit = points.equal_range( to_marker );
 if( pit.first==points.end() && !optional_to_node )
  {
   lem::MemFormatter mem;
   mem.printf( "Can not find node %us to create link tail", to_marker.c_str() );
   throw lem::E_BaseException( mem.string() );
  }

 for( IT it=pit.first; it!=pit.second; ++it )
  {
   const Solarix::Word_Form * node1 = it->second;

   PatternLinkEdge new_edge( node0, link_type, node1 );

   cur_result->AddLinkageEdge( new_edge );
  }

 return;
}
コード例 #3
0
	virtual int OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
	{
		std::multimap<char, std::string>::const_iterator it = logstreams.find(sno);
		char buf[MAXBUF];

		if (it == logstreams.end())
			return 0;

		snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());

		while (it != logstreams.end())
		{
			if (it->first != sno)
			{
				it++;
				continue;
			}

			Channel *c = ServerInstance->FindChan(it->second);
			if (c)
			{
				c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
				ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
			}

			it++;
		}

		return 0;
	}
コード例 #4
0
		void PeakMatchingResults::GetMatches(std::vector<int> &vectFeatureIndices, std::vector<int> &vectMassTagIndices, 
			std::vector<int> &vectProteinIndices , const std::vector<MultiAlignEngine::MassTags::Protein>* &vectProteins, 
			const std::vector<MultiAlignEngine::MassTags::MassTag>* &vectMasstags) const
		{
			// The mass tag database has stored in it all the proteins and mass tags corresponding to the matches.
			// So thats where we need to get all the data from. 
			int numMatches = (int) mvectPeakMatches.size(); 
			std::set <int> massTagID; 

			stdext::hash_map <int, int > massTagSeen;
			// first get all mass tags in the matches into the set of mass tags. 
			for (int matchNum = 0; matchNum < numMatches; matchNum++)
			{
				PeakMatch match = mvectPeakMatches[matchNum]; 
				massTagSeen.insert(std::pair<int,int>(match.mintMasstagID, matchNum)); 
			}

			// copy hash to mass tag vector
			std::vector<int> vectMassTagIDs; 
			vectMassTagIDs.reserve(massTagSeen.size()); 
			for (stdext::hash_map <int, int >::iterator massTagIter = massTagSeen.begin();
				massTagIter != massTagSeen.end(); massTagIter++)
			{
				vectMassTagIDs.push_back((*massTagIter).first); 
			}


			vectMasstags = mobjMasstagDB.GetMassTagVector(); 
			vectProteins = mobjMasstagDB.GetProteinVector(); 
			const std::multimap<int,int> mapMassTagId2ProteinIndex = mobjMasstagDB.GetMassTagId2ProteinIndexMap(); 
			const stdext::hash_map <int, int > hashMapMassTagId2Index  = mobjMasstagDB.GetMassTagId2IndexHash();

			// now the relevant mass tags are copied, their ids are copied, the protein names are copied. 
			// So lets create the table of matches using the three vectors vectFeatureIndices, vectMassTagIndices and 
			// vectProteinIndices. Basically, vectFeatureIndices will have the index of the ms feature in a peak match.
			// the vectMassTagIndices will have the corresponding massTagID, and vectProteinIndices will have the corresponding
			// parent protein. 
			for (std::multimap<int,int>::const_iterator featureIter = mmapFeatureIndex2PeakMatch.begin(); featureIter != mmapFeatureIndex2PeakMatch.end(); 
				featureIter++)
			{
				int featureIndex = (*featureIter).first; 
				int peakMatchIndex = (*featureIter).second; 
				PeakMatch pkMatch = mvectPeakMatches[peakMatchIndex]; 
				int massTagID = pkMatch.mintMasstagID; 
				stdext::hash_map <int, int>::const_iterator massTagIterHash = hashMapMassTagId2Index.find(massTagID); 
				int massTagIndex = (*massTagIterHash).second; 
				// now go through each of the parent proteins of this massTagID and push the triplet into their 
				// corresponding vectors
				for (std::multimap<int,int>::const_iterator massTagIter = mapMassTagId2ProteinIndex.find(massTagID); 
					massTagIter != mapMassTagId2ProteinIndex.end(); 
					massTagIter++)
				{
					if ((*massTagIter).first != massTagID)
						break; 
					vectFeatureIndices.push_back(featureIndex); 
					vectMassTagIndices.push_back(massTagIndex); 
					vectProteinIndices.push_back((*massTagIter).second); 
				}
			}
		}
コード例 #5
0
ファイル: ins3.cpp プロジェクト: shail-dave/cml-cgra
//get the node id for the source operation of this routing node
int getRouteSrc(int id)
{
  std::multimap<int, int>::iterator it = in_edge.find(id);
  if(getNodeType(it->second) != route)
    return it->second;
  else
    getRouteSrc(it->second);
}
コード例 #6
0
 bool Semantic::search(string name){
 	
     
 	for(mi = Symbols.find(name);mi != Symbols.end();mi++){
 		return true;
 	}
 	return false;
 }
コード例 #7
0
 string Semantic::checkScope(string name, string currScope){
 	
 	for(mi=Symbols.find(name);mi!= Symbols.end();++mi){
               
 	    if(mi->second.scope==currScope){
  		     return mi->second.type;
  	    }
 	}
 	return "Error";
 }
コード例 #8
0
 string Semantic::getScope(string name){
   mi = Symbols.find(name);
  	
	if(mi!=Symbols.end()){
        return mi->second.scope;
   }
   else{
   	    return "Error";
   }
 }
コード例 #9
0
ファイル: World.cpp プロジェクト: mstram/dfhack-40d
PersistentDataItem World::GetPersistentData(const std::string &key)
{
    if (!BuildPersistentCache())
        return PersistentDataItem();

    auto it = persistent_index.find(key);
    if (it != persistent_index.end())
        return GetPersistentData(it->second);

    return PersistentDataItem();
}
コード例 #10
0
 static void sort_by_location(std::multimap<std::string, Species> location_map,
         std::vector<Species>& species, const std::string location="")
 {
     std::multimap<std::string, Species>::iterator itr;
     while ((itr = location_map.find(location)) != location_map.end())
     {
         const Species sp((*itr).second);
         species.push_back(sp);
         sort_by_location(location_map, species, sp.serial());
         location_map.erase(itr);
     }
 }
コード例 #11
0
std::size_t NodeListT::value_of(const std::multimap<UnitID, NodeListT::SuperInfoT> &supersets, const UnitID &train, const NodeListT::times_t &value, bool neg) const
{
	std::size_t length = lengths.find(train)->second;
	const SuperInfoT& sinf = supersets.find(train)->second;

	// actually, it's just (value - sinf.station_no % length),
	// but lenght is added to avoid % on negative numbers
	// the associate braces avoid getting negative temporaries
	return (neg)
		? (((length + sinf.station_no) - value) % length)
		: (((length + value) - sinf.station_no) % length);
}
コード例 #12
0
 static void save_molecular_type_recursively(const Species& location,
         std::multimap<Species, const MolecularTypeBase*>& location_map,
         Tspace_& space, H5::Group* root)
 {
     std::multimap<Species, const MolecularTypeBase*>::iterator itr;
     while ((itr = location_map.find(location)) != location_map.end())
     {
         const MolecularTypeBase* mtb((*itr).second);
         const Species species(mtb->species());
         save_molecular_type(mtb, space.list_voxels_exact(species), root);
         save_molecular_type_recursively(species, location_map, space, root);
         location_map.erase(itr);
     }
 }
コード例 #13
0
  //Checks declaration and unicity of variables
 bool Semantic::search(string name, string scope){
    
	
 	for(mi = Symbols.find(name);mi!= Symbols.end();++mi){
       
	   //cout<<mi->first<<":"<<mi->second.scope<<"\n";
	           
 	    if(mi->second.scope==scope){
  		     return true;
  	    }
      
 	}
 	return false;	
 }
コード例 #14
0
  string Semantic::getType(string name,string scope){
   
  	mi = Symbols.find(name);
	
 	for(mi=Symbols.begin();mi!= Symbols.end();++mi){
       
	   cout<<mi->first<<":"<<mi->second.scope<<"\n";
	           
 	    if(mi->second.scope==scope){
  		     return mi->second.type;
  	    }
      
 	}
 	return "Error";
 }
コード例 #15
0
    void AudioOutputDeviceManager::addDeviceEventProc(
        int                                                 _card
        , std::multimap< int, const AudioOutputDevice * > & _devices
    )
    {
        if( _devices.find( _card ) != _devices.end() ) {
            return;
        }

        DeviceNameHints hints(
            _card
        );

        const auto &    HINTS = hints.get();

        for( int i = 0 ; HINTS[ i ] != nullptr ; i++ ) {
            const auto  HINT = HINTS[ i ];

            if( isOutputDevice( HINT ) == false ) {
                continue;
            }

            DeviceDescription   description(
                HINT
            );

            DeviceName  name(
                HINT
            );

            const auto  DEVICE = new AudioOutputDevice(
                description.get()
                , name.get()
            );

            _devices.insert(
                std::multimap< int, const AudioOutputDevice * >::value_type(
                    _card
                    , DEVICE
                )
            );

            this->callConnectEventHandler(
                *DEVICE
            );
        }
    }
コード例 #16
0
std::vector<std::pair<ReducedFraction, ReducedFraction> > findMatchedLyricTimes(
            const std::multimap<ReducedFraction, MidiChord> &chords,
            const std::multimap<ReducedFraction, std::string> &lyricTrack)
      {
                  // <chord quantized on time, chord original on time>
      std::vector<std::pair<ReducedFraction, ReducedFraction> > matchedLyricTimes;

      for (const auto &chord: chords) {
            for (const auto &note: chord.second.notes) {
                  if (lyricTrack.find(note.origOnTime) != lyricTrack.end()) {
                        matchedLyricTimes.push_back({chord.first, note.origOnTime});
                        break;
                        }
                  }
            }
      return matchedLyricTimes;
      }
コード例 #17
0
static void dfs_visit(MetaClass *u, const std::multimap<MetaClass*, MetaClass*> &adjacents,
                      std::set<MetaClass*> &visited, std::list<MetaClass*> &sorted)
{
  visited.insert(u);
  
  std::multimap<MetaClass*, MetaClass*>::const_iterator iter= adjacents.find(u);
  
  while (iter != adjacents.end() && iter->first == u)
  {
    MetaClass *v= iter->second;
    
    if (visited.find(v) == visited.end())
      dfs_visit(v, adjacents, visited, sorted);
    ++iter;
  }
  
  sorted.push_front(u);
}
コード例 #18
0
ファイル: xbmc-xml2po.cpp プロジェクト: KB3NZQ/xbmc-xml2po
void WriteComments(int comm_id, bool bInterLine)
{
  itComments = mapComments.find(comm_id);
  if (itComments == mapComments.end()) // check if we have at least one comment for the xml id
    return;

  itRangeComments = mapComments.equal_range(comm_id);
  for (itComments = itRangeComments.first; itComments != itRangeComments.second;++itComments)
  {
    if (bInterLine == itComments->second.bInterLineComment)
    {
      WriteLF(pPOTFile);
      fprintf(pPOTFile,bInterLine ? "#%s\n": "#. %s\n", itComments->second.text.c_str());
    }
  }

  return;
};
コード例 #19
0
 __declspec(noinline) void save_stack_trace()
 {
     if (!g_mem_alloc_gather_stats)
         return;
     if (::Random.randF() >= g_mem_alloc_gather_stats_frequency)
         return;
     StackTrace.Count = xrDebug::BuildStackTrace(StackTrace.Frames, StackTrace.Capacity, StackTrace.LineCapacity);
     const int skipFrames = 2;
     if (StackTrace.Count <= skipFrames)
         return;
     int frameCount = StackTrace.Count - skipFrames;
     int totalSize = 0;
     int* lengths = (int*)_alloca(frameCount*sizeof(int));
     for (int i = 0; i < frameCount; i++)
     {
         lengths[i] = strlen(StackTrace.GetFrame(i + skipFrames));
         totalSize += lengths[i]+1;
     }
     char* stackTrace = (char*)malloc(totalSize);
     {
         auto ptr = stackTrace;
         for (int i = 0; i < frameCount; i++)
         {
             memcpy(ptr, StackTrace.GetFrame(i), lengths[i]);
             ptr += lengths[i];
             *ptr = '\n';
         }
         *ptr = 0;
     }
     boost::crc_32_type temp;
     temp.process_block(stackTrace, stackTrace+totalSize);
     uint crc = temp.checksum();
     for (auto it = stats.find(crc); it != stats.end(); it++)
     {
         auto& pair = *it;
         if (pair.first != crc)
             break;
         if (strcmp(pair.second.StackTrace, stackTrace))
             continue;
         pair.second.Calls++;
         return;
     }
     stats.insert({crc, {stackTrace, 1}});
 }
コード例 #20
0
ファイル: m_alias.cpp プロジェクト: thepaul/inspircd-deb
	virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
	{
		std::multimap<std::string, Alias>::iterator i, upperbound;

		/* If theyre not registered yet, we dont want
		 * to know.
		 */
		if (user->registered != REG_ALL)
			return 0;

		/* We dont have any commands looking like this? Stop processing. */
		i = Aliases.find(command);
		if (i == Aliases.end())
			return 0;
		/* Avoid iterating on to different aliases if no patterns match. */
		upperbound = Aliases.upper_bound(command);

		irc::string c = command.c_str();
		/* The parameters for the command in their original form, with the command stripped off */
		std::string compare = original_line.substr(command.length());
		while (*(compare.c_str()) == ' ')
			compare.erase(compare.begin());

		while (i != upperbound)
		{
			if (i->second.UserCommand)
			{
				if (DoAlias(user, NULL, &(i->second), compare, original_line))
				{
					return 1;
				}
			}

			i++;
		}

		// If we made it here, no aliases actually matched.
		return 0;
	}
コード例 #21
0
ファイル: wfips_data_load.cpp プロジェクト: firelab/wfips
int
WfipsData::AssociateHelitack( std::multimap<std::string, CResource*>&resc_map )
{
    sqlite3_stmt *stmt;
    int rc;
    rc = sqlite3_prepare_v2( db, "SELECT heli FROM heli_assign WHERE hel=?",
                             -1, &stmt, NULL );
    std::string key;
    std::multimap<string, CResource*>::iterator it = resc_map.begin();
    std::multimap<string, CResource*>::iterator find;
    for( ; it != resc_map.end(); it++ )
    {
        if( EQUAL( it->second->GetRescType().GetRescType().c_str(), "HELI" ) )
        {
            continue;
        }

        sqlite3_bind_text( stmt, 1, it->first.c_str(), -1, SQLITE_TRANSIENT );
        while( sqlite3_step( stmt ) == SQLITE_ROW )
        {
            key = (const char*)sqlite3_column_text( stmt, 0 );
            find = resc_map.find( key );
            if( find == resc_map.end() )
            {
                continue;
            }
            CHelicopter* poHelic = dynamic_cast<CHelicopter*>( it->second );
            if( poHelic )
            {
                poHelic->AddAttachedCrew( find->second );
            }
        }
        sqlite3_reset( stmt );
    }
    sqlite3_finalize( stmt );
    stmt = NULL;
    return 0;
}
コード例 #22
0
bool CZMQAbstractPublishNotifier::Initialize(void *pcontext)
{
    assert(!psocket);

    // check if address is being used by other publish notifier
    std::multimap<std::string, CZMQAbstractPublishNotifier*>::iterator i = mapPublishNotifiers.find(address);

    if (i==mapPublishNotifiers.end())
    {
        psocket = zmq_socket(pcontext, ZMQ_PUB);
        if (!psocket)
        {
            zmqError("Failed to create socket");
            return false;
        }

        int rc = zmq_bind(psocket, address.c_str());
        if (rc!=0)
        {
            zmqError("Failed to bind address");
            zmq_close(psocket);
            return false;
        }

        // register this notifier for the address, so it can be reused for other publish notifier
        mapPublishNotifiers.insert(std::make_pair(address, this));
        return true;
    }
    else
    {
        LogPrint(BCLog::ZMQ, "zmq: Reusing socket for address %s\n", address);

        psocket = i->second->psocket;
        mapPublishNotifiers.insert(std::make_pair(address, this));

        return true;
    }
}
コード例 #23
0
bool AMQPAbstractPublishNotifier::Initialize()
{
    std::multimap<std::string, AMQPAbstractPublishNotifier*>::iterator i = mapPublishNotifiers.find(address);

    if (i == mapPublishNotifiers.end()) {
        try {
            handler_ = std::make_shared<AMQPSender>(address);
            thread_ = std::make_shared<std::thread>(&AMQPAbstractPublishNotifier::SpawnProtonContainer, this);
        }
        catch (std::exception &e) {
            LogPrint("amqp", "amqp: initialization error: %s\n", e.what());
            return false;
        }
        mapPublishNotifiers.insert(std::make_pair(address, this));
    } else {
        // copy the shared ptrs to the message handler and the thread where the proton container is running
        handler_ = i->second->handler_;
        thread_ = i->second->thread_;
        mapPublishNotifiers.insert(std::make_pair(address, this));
    }

    return true;
}
コード例 #24
0
BestTrack findBestTrack(
            const QList<MTrack> &tracks,
            const std::multimap<ReducedFraction, std::string> &lyricTrack,
            const std::set<int> &usedTracks)
      {
      BestTrack bestTrack;
      int maxMatches = 0;

      Q_ASSERT_X(areEqualIndexesSuccessive(tracks),
                 "MidiLyrics::findBestTrack", "Equal indexes of operations are not successive");

      for (int i = 0; i != tracks.size(); ++i) {
            if (tracks[i].mtrack->drumTrack() || usedTracks.find(i) != usedTracks.end())
                  continue;
                        // due to staff split there can be equal indexes of operation
            if (i > 0 && tracks[i].indexOfOperation == tracks[i - 1].indexOfOperation)
                  continue;

            int matches = 0;
            for (const auto &chord: tracks[i].chords) {
                  for (const auto &note: chord.second.notes) {
                        if (lyricTrack.find(note.origOnTime) != lyricTrack.end()) {
                              ++matches;
                              bestTrack.matchedLyricTimes.push_back({chord.first,
                                                                     note.origOnTime});
                              break;
                              }
                        }
                  }
            if (matches > maxMatches) {
                  maxMatches = matches;
                  bestTrack.index = tracks[i].indexOfOperation;
                  }
            }

      return bestTrack;
      }
コード例 #25
0
ファイル: main.cpp プロジェクト: RLED/ProjectRichelBilderbeek
const std::map<Key,Value> MultimapToMap(
  const std::multimap<Key,Value> m)
{
  std::map<Key,Value> n;
  const auto end = m.end();
  for (auto begin = m.begin(); begin != end; )
  {
    assert(begin != m.end());
    const auto key = (*begin).first;
    assert(m.find(key) != m.end());

    //Must the average be calculated?
    const auto r = m.equal_range(key);
    assert(r.first != m.end());

    if (r.first != r.second )
    {
      Value sum(0.0);
      int cnt = 0;
      for (auto i = r.first; i!=r.second; ++i)
      {
        sum += (*i).second;
        ++cnt;
      }
      const Value result( sum / static_cast<double>(cnt));
      n[ key ] = result;
    }
    else
    {
      const Value result((*r.first).second);
      n[ key ] = result;
    }
    begin = r.second;
  }
  return n;
}
コード例 #26
0
void addLyricsToScore(
            const std::multimap<ReducedFraction, std::string> &lyricTrack,
            const std::vector<std::pair<ReducedFraction, ReducedFraction>> &matchedLyricTimes,
            const Staff *staffAddTo)
      {
      Score *score = staffAddTo->score();

      addTitleIfAny(lyricTrack, score);

      for (const auto &timePair: matchedLyricTimes) {
            const auto quantizedTime = timePair.first;
            const auto originalTime = timePair.second;
            const auto it = lyricTrack.find(originalTime);

            Q_ASSERT_X(it != lyricTrack.end(),
                       "MidiLyrics::addLyricsToScore", "Lyric time not found");

            QString text = MidiCharset::convertToCharset(it->second);
            if (originalTime != ReducedFraction(0, 1) || !isTitlePrefix(text)) { // not title
                  score->addLyrics(quantizedTime.ticks(), staffAddTo->idx(),
                                   removeSlashes(text).toHtmlEscaped());
                  }
            }
      }
コード例 #27
0
ファイル: OpenID.cpp プロジェクト: ibd1279/logjammin
    bool AssociatedRelayConsumer::check_authentication(const std::multimap<std::string, std::string> &params) {
        // Try to find our assoc handle.
        const std::string *assoc_handle_ptr = lookup_assoc_handle(openid_provider());
        if(!assoc_handle_ptr)
            assoc_handle_ptr = associate();
        
        // If the handle is "DUMB", we have to fall back to the dumb consumer.
        if(assoc_handle_ptr->compare("DUMB") == 0) {
            delete assoc_handle_ptr;
            return DumbRelayConsumer::check_authentication(params);
        }
        
        // Move the string to the stack, so that return can free it.
        std::string assoc_handle(*assoc_handle_ptr);
        delete assoc_handle_ptr;
        
        // Not possible to be missing the assoc_handle
        std::multimap<std::string, std::string>::const_iterator assoc_iter = params.find(std::string("openid.assoc_handle"));
        if(assoc_iter == params.end())
            return false;

        if(assoc_handle.compare(assoc_iter->second) == 0) {
            // make sure this request was signed.
            std::multimap<std::string, std::string>::const_iterator sig_iter = params.find(std::string("openid.sig"));
            if(sig_iter == params.end())
                return false;
            std::string their_signature(sig_iter->second);
            
            // Look for the signed fields.
            sig_iter = params.find(std::string("openid.signed"));
            if(sig_iter == params.end())
                return false;
            std::string signed_params(sig_iter->second), key;
            
            // construct the message that was signed.
            std::ostringstream message;
            std::string::const_iterator iter = signed_params.begin();
            while(iter != signed_params.end()) {
                char c = *iter;
                ++iter;
                
                // We hit a non-key character, 
                if(c == '\n' || c == ',' || iter == signed_params.end()) {
                    // store the last char in the string.
                    if(iter == signed_params.end()) key.push_back(c);
                    // look for the param
                    std::string key_to_find("openid.");
                    key_to_find.append(key);
                    sig_iter = params.find(key_to_find);
                    if(sig_iter == params.end())
                        return false;
                    
                    // add to the message data.
                    message << key << ":" << sig_iter->second << "\n";
                    
                    // clear the key to start over.
                    key.clear();
                } else {
                    key.push_back(c);
                }
            }
            
            // attempt to recreate the signature.
            Association *assoc = lookup_association(assoc_handle);
            if(!assoc)
                return false;
            std::string our_signature(create_signature(message.str(), assoc->secret));
            delete assoc;

            // Test that the signature created matches the one given.
            return (their_signature.compare(our_signature) == 0);
            
        } else if(assoc_handle.compare(assoc_iter->second) != 0 &&
           (assoc_iter = params.find("openid.invalidate_handle")) != params.end()) {
            
            // Prepare the verification post data.
            std::ostringstream data;
            CURL *curl = new_curl_handle();
            data << "openid.mode=check_authentication";
            for(std::multimap<std::string, std::string>::const_iterator iter = params.begin();
                iter != params.end();
                ++iter) {
                if(iter->first.compare("openid.mode") == 0) continue;
                
                char *tmp;
                tmp = curl_easy_escape(curl, iter->first.c_str(), iter->first.size());
                data << "&" << tmp << "=";
                curl_free(tmp);
                
                tmp = curl_easy_escape(curl, iter->second.c_str(), iter->second.size());
                data << tmp;
                curl_free(tmp);
            }
            // Clean up after curl.
            curl_easy_cleanup(curl);
            
            // execute.
            std::string content = contact_openid_provider(data.str());
            
            // Check for invalidating the handle.
            std::string invalidate_substring("\ninvalidate_handle:");
            invalidate_substring.append(assoc_iter->second).append("\n");
            if(content.find(invalidate_substring) != content.npos)
                invalidate_assoc_handle(assoc_iter->second);
            
            // Test for is_valid.
            return content.find("\nis_valid:true\n") != content.npos;
        }
        
        // If we didn't match any other cases, return false.
        return false;
    }
コード例 #28
0
ファイル: ins3.cpp プロジェクト: shail-dave/cml-cgra
//This function is responsible for returning the register number that will act
//as operand 1
int getReg1Address(int nodeID,PEInputMux LMux,exec_state state)
{
  /*
   *************Memory Operations*******************
   if the instruction is ld_add, st_add
   result = register number this node is mapped to in mem_node_regNum

   if the instruction is a ld_data
   result = 0

   if the instruction is st_data
   {
   get the node id of the operand other than the varname and st_add
   if they are scheduled more than a cycle apart
   {
   reg=get the register that operand writes to
   result = getRotatingRegNum(reg,operandID,nodeID);
   }
   else
   result = 0
   }
   ***************Alu Operations**************
   Get the first operand (lets call it op)
   If(op is Constant)
   result = 0
   if(op is scheduled more than 1 cycle apart)
   reg=get the register that operand writes to
   result = getRotatingRegNum(reg,operandID,nodeID);
   else
   result =0

   *****************Route Operation************
   get the source node of the only incoming edge to this node
   if(src node is scheduled more than 1 cycle apart)
   reg=get the register that operand writes to
   result = getRotatingRegNum(reg,operandID,nodeID);
   else
   result =0

*/
  int result = 0;
  if(LMux == Register)
  {
    int opType = getNodeType(nodeID);

    //there will be atmost 1 incoming edge to the routing node
    std::multimap<int, int>::iterator it_inedge = in_edge.find(nodeID);
    vector<int> operands = getOperands(nodeID);

    switch(opType){
      //MEMORY OPERATIONS
      case ld_add:
      case st_add:
        result = mem_node_regNum[nodeID];
        return result;
        break;
      case ld_data:
        result = 0;
        return result;
        break;
      case st_data:
        int op;
        for(int i=0;i<operands.size();++i)
        {
          int type = getNodeType(operands[i]);
          if(type!=constant && type!=st_add)
          {
            op = operands[i];
            break;
          }    
        }
        if(isScheduledMoreThanACycleApart(nodeID,op))
        {
          int srcReg = getOutputRegisterNumber(op);
          result = getRotatingRegNum(srcReg,op,nodeID,state);
          return result;
        }
        else
        {
          result = 0;	
          return result;
        } 
        //ROUTING NODE        
      case route:
        if(isScheduledMoreThanACycleApart(nodeID,it_inedge->second))
        {
          int srcReg = getOutputRegisterNumber(it_inedge->second);
          result = getRotatingRegNum(srcReg,it_inedge->second,nodeID,state);
        }
        else
        {
          result = 0;
        }
        return result;
        break;

    }
    /*   ***************Alu Operations**************
         Get the first operand (lets call it op)
         If(op is Constant)
         result = 0
         if(op is scheduled more than 1 cycle apart)
         reg=get the register that operand writes to
         result = getRotatingRegNum(reg,operandID,nodeID);
         else
         result =0
         */
    if(operands.size() > 0)
    {
      int op1 = operands[0];
      int opType = getNodeType(op1);
      if(opType == constant)
        result == 0;

      if(isScheduledMoreThanACycleApart(nodeID,op1))
      {
        int srcReg = getOutputRegisterNumber(op1);
        result = getRotatingRegNum(srcReg,op1,nodeID,state);
      }
      else
      {
        result = 0;
      }

      return result;
    }

  }
  else
  {
    return 0;
  }

}
コード例 #29
0
	bool hasExampleHandlers(T eventName) {
		return map.find(eventName) != map.end();
	}
コード例 #30
0
ファイル: commands.cpp プロジェクト: stefanludlow/shadows2011
void
command_interpreter (CHAR_DATA * ch, char *argument)
{
	char buf[MAX_STRING_LENGTH];
	char *command_args, *p, *social_args;
	int cmd_level = 0;
	int i = 0, echo = 1;
	AFFECTED_TYPE *craft_affect = NULL;
	AFFECTED_TYPE *af;
	ALIAS_DATA *alias;
	extern int second_affect_active;

	if (!ch)
		return;

	*buf = '\0';

	p = argument;

	while (*p == ' ')
		p++;

	if (strchr (p, '%'))
	{
		send_to_char ("Input with the '%' character is not permitted.\n", ch);
		return;
	}

	if (strchr (p, '#') && IS_MORTAL (ch) && strncmp (p, "ge", 2) != 0
		&& strncmp (p, "buy", 3) != 0)
	{
		send_to_char ("Input with the '#' character is not permitted.\n", ch);
		return;
	}

	if (IS_MORTAL (ch) && strchr (p, '$'))
	{
		send_to_char ("Input with the '$' character is not permitted.\n", ch);
		return;
	}

	std::multimap<int, room_prog>::iterator it;
	if (IS_NPC(ch))
		it = mob_prog_list.find(ch->mob->nVirtual); 
	if (IS_NPC(ch) && !get_second_affect (ch, SA_DOANYWAY, 0) && it != mob_prog_list.end())
	{
		if (m_prog(ch, p))
		{
			return;
		}
	}
	std::pair<std::multimap<int, room_prog>::iterator, std::multimap<int, room_prog>::iterator> pair;

	if (ch->right_hand && !get_second_affect (ch, SA_DOANYWAY, 0))
	{
		pair = obj_prog_list.equal_range(ch->right_hand->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 1 && it->second.type != 3 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}
	}
	if (ch->left_hand && !get_second_affect (ch, SA_DOANYWAY, 0))
	{
		pair = obj_prog_list.equal_range(ch->left_hand->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 1 && it->second.type != 3 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}
	}
	for (OBJ_DATA *tobj = ch->equip; tobj; tobj = tobj->next_content)
	{
		if (get_second_affect (ch, SA_DOANYWAY, 0))
			break;

		pair = obj_prog_list.equal_range(tobj->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 2 && it->second.type != 3 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}

	}

	/* this is where it crashes on the hour - Grommit */

	if (!ch->room )
	{
		std::ostringstream stream;
		stream << "Error in command_interpreter:commands.cpp. Command \"" << 
			argument << "\" called by \"" << ch->tname << "\" with null room. Previously in "
			<< (ch->last_room) << " entering null room from the " << (dirs[ch->from_dir]) << ".";

		system_log(stream.str().c_str(),true);
		return;
	}

	/* end grommit diagnostics to avoid segfaulting on the below for loop */

	for (OBJ_DATA *tobj = ch->room->contents; tobj; tobj = tobj->next_content)
	{
		if (get_second_affect (ch, SA_DOANYWAY, 0))
			break;

		pair = obj_prog_list.equal_range(tobj->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 4 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}

	}

	for (CHAR_DATA *temp_char = ch->room->people; temp_char; temp_char = temp_char->next_in_room)
	{
		if (get_second_affect (ch, SA_DOANYWAY, 0))
			break;

		if (temp_char == ch)
			continue;

		if (!IS_NPC(temp_char))
			continue;

		pair = mob_prog_list.equal_range(temp_char->mob->nVirtual);

		for (it = pair.first; it != pair.second; ++it)
		{
			if (m_prog(ch, p, it->second))
				return;
		}
	}

	if (ch->room && ch->room->prg && !get_second_affect(ch, SA_DOANYWAY, 0) && r_program (ch, p))
	{
		if (!IS_NPC (ch)
			|| (ch->desc && (ch->pc && str_cmp (ch->pc->account_name, "Guest"))))
		{
			player_log (ch, "[RPROG]", p);
		}
		if (!IS_SET (commands[i].flags, C_NWT))
			show_to_watchers (ch, argument);
		return;
	}
	if (get_second_affect(ch, SA_DOANYWAY, 0))
		remove_second_affect(get_second_affect(ch, SA_DOANYWAY, 0));

	if (!IS_MORTAL (ch) && !str_cmp (argument, "sho wl"))
	{
		send_to_char
			("Heh heh. Glad I added in this check, aren't we? No shouting for you.\n",
			ch);
		return;
	}

	if (ch->desc)
	{
		last_descriptor = ch->desc;
		sprintf (full_last_command, "Last Command Issued, by %s [%d]: %s",
			ch->tname, ch->in_room, argument);
		sprintf (last_command, "%s", argument);
	}

	social_args = argument;

	command_args = one_argument (argument, buf);

	if (!*buf)
		return;

	while (*command_args == ' ')
		command_args++;

	if (ch->pc && !GET_FLAG (ch, FLAG_ALIASING))
	{

		if ((alias = is_alias (ch, buf)))
		{

			ch->flags |= FLAG_ALIASING;

			while (alias)
			{

				command_interpreter (ch, alias->line);

				if (ch->deleted)
					return;

				alias = alias->next_line;
			}

			ch->flags &= ~FLAG_ALIASING;

			return;
		}
	}

	for (i = 1; *commands[i].command; i++)
		if (is_abbrev (buf, commands[i].command))
			break;

	if ((craft_affect = is_craft_command (ch, argument)))
		i = 0;

	if (IS_SET (commands[i].flags, C_IMP)) {
		cmd_level = 6;
	}
	else if (IS_SET (commands[i].flags, C_LV5)) {
		cmd_level = 5;
	}
	else if (IS_SET (commands[i].flags, C_LV4)) {
		cmd_level = 4;
	}
	else if (IS_SET (commands[i].flags, C_LV3)) {
		cmd_level = 3;
	}
	else if (IS_SET (commands[i].flags, C_LV2)) {
		cmd_level = 2;
	}
	else if (IS_SET (commands[i].flags, C_LV1)) {
		cmd_level = 1;
	}

	if (IS_SET (commands[i].flags, C_GDE)
		&& (IS_NPC (ch) || (!ch->pc->is_guide && !ch->pc->level)))
	{
		send_to_char ("Eh?\n\r", ch);
		return;
	}
	/* 
	Need to pass the CHAR_DATA pointer for the person who made the command and modify
	the following line to test the commanding char's trust against the trust level for
	the command.  - Methuselah
	*/

	if ((!*commands[i].command) 
		|| (cmd_level > GET_TRUST (ch)))
	{
		if (!social (ch, argument))
		{
			echo = number (1, 9);
			if (echo == 1)
				send_to_char ("Eh?\n\r", ch);
			else if (echo == 2)
				send_to_char ("Huh?\n\r", ch);
			else if (echo == 3)
				send_to_char ("I'm afraid that just isn't possible...\n\r", ch);
			else if (echo == 4)
				send_to_char ("I don't recognize that command.\n\r", ch);
			else if (echo == 5)
				send_to_char ("What?\n\r", ch);
			else if (echo == 6)
				send_to_char
				("Perhaps you should try typing it a different way?\n\r", ch);
			else if (echo == 7)
				send_to_char
				("Try checking your typing - I don't recognize it.\n\r", ch);
			else if (echo == 8)
				send_to_char
				("That isn't a recognized command, craft, or social.\n\r", ch);
			else
				send_to_char ("Hmm?\n\r", ch);
		}
		else
		{
			if (!IS_SET (commands[i].flags, C_NWT))
				show_to_watchers (ch, argument);
		}
		return;
	}

	if (ch->stun)
	{
		send_to_char ("You're still reeling.\n", ch);
		return;
	}

	if (ch->roundtime)
	{
		sprintf (buf, "You'll need to wait another %d seconds.\n",
			ch->roundtime);
		send_to_char (buf, ch);
		return;
	}

	if (IS_SET (commands[i].flags, C_WLK) &&
		(ch->moves || GET_FLAG (ch, FLAG_LEAVING)
		|| GET_FLAG (ch, FLAG_ENTERING)))
	{
		send_to_char ("Stop traveling first.\n\r", ch);
		return;
	}

	if (IS_SET (commands[i].flags, C_MNT) && IS_RIDER (ch))
	{
		send_to_char ("Get off your mount first.\n", ch);
		return;
	}

	if (commands[i].min_position > GET_POS (ch))
	{
		switch (GET_POS (ch))
		{
		case DEAD:
			if (IS_MORTAL (ch))
			{
				send_to_char ("You are dead.  You can't do that.\n\r", ch);
				return;
			}
		case UNCON:
		case MORT:
			send_to_char ("You're seriously wounded and unconscious.\n\r", ch);
			return;

		case STUN:
			send_to_char ("You're too stunned to do that.\n\r", ch);
			return;

		case SLEEP:
			send_to_char ("You can't do that while sleeping.\n\r", ch);
			return;

		case REST:
			send_to_char ("You can't do that while lying down.\n\r", ch);
			return;

		case SIT:
			send_to_char ("You can't do that while sitting.\n\r", ch);
			return;

		case FIGHT:
			send_to_char ("No way! You are fighting for your life!\n\r", ch);
			return;
		}

		return;
	}

	if (!IS_NPC (ch) && ch->pc->create_state == STATE_DIED &&
		!IS_SET (commands[i].flags, C_DOA))
	{
		send_to_char ("You can't do that when you're dead.\n\r", ch);
		return;
	}

	if (!IS_SET (commands[i].flags, C_BLD) && is_blind (ch))
	{
		if (get_equip (ch, WEAR_BLINDFOLD))
			send_to_char ("You can't do that while blindfolded.\n\r", ch);
		else
			send_to_char ("You can't do that while blind.\n\r", ch);
		return;
	}

	if ((af = get_affect (ch, MAGIC_AFFECT_PARALYSIS)) &&
		!IS_SET (commands[i].flags, C_PAR) && IS_MORTAL (ch))
	{
		send_to_char ("You can't move.\n", ch);
		return;
	}

	if (IS_SUBDUEE (ch) && !IS_SET (commands[i].flags, C_SUB) && !cmd_level)
	{
		act ("$N won't let you.", false, ch, 0, ch->subdue, TO_CHAR);
		return;
	}

	/* Most commands break delays */

	if (ch->delay && !IS_SET (commands[i].flags, C_DEL))
		break_delay (ch);

	/* Send this command to the log */
	if (!second_affect_active && (!IS_NPC (ch) || ch->desc))
	{
		if (IS_SET (commands[i].flags, C_NLG))
			;
		else if (i > 0)
		{			/* Log craft commands separately. */
			if (!str_cmp (commands[i].command, "."))
				player_log (ch, "say", command_args);
			else if (!str_cmp (commands[i].command, ","))
				player_log (ch, "emote", command_args);
			else if (!str_cmp (commands[i].command, ":"))
				player_log (ch, "emote", command_args);
			else if (!str_cmp (commands[i].command, ";"))
				player_log (ch, "wiznet", command_args);
			else
				player_log (ch, commands[i].command, command_args);
		}
	}

	if (IS_MORTAL (ch) && get_affect (ch, MAGIC_HIDDEN) &&
		!IS_SET (commands[i].flags, C_HID) &&
		skill_level (ch, SKILL_SNEAK, 0) < number (1, MAX(100, skill_level(ch, SKILL_SNEAK, 0))) &&
		would_reveal (ch))
	{
		remove_affect_type (ch, MAGIC_HIDDEN);
		act ("$n reveals $mself.", true, ch, 0, 0, TO_ROOM | _ACT_FORMAT);
		act ("Your actions have compromised your concealment.", true, ch, 0, 0,
			TO_CHAR);
	}

	/* Execute command */

	if (!IS_SET (commands[i].flags, C_NWT))
		show_to_watchers (ch, social_args);

	if (!i)			/* craft_command */
		craft_command (ch, command_args, craft_affect);
	else

		(*commands[i].proc) (ch, command_args, 0);

	last_descriptor = NULL;
}