Ejemplo n.º 1
0
void Scene::receiveUseRequest(){
    if(getSpecial() != "chest"){
        QVariant verdict("There's nothing to use here.");
        sendUseVerdict(verdict);
    }
    else{
        relayUseRequest();
    }
}
Ejemplo n.º 2
0
void Scene::receiveTalkRequest(){
    if(getSpecial() != "old man"){
        QVariant verdict("There's no one here to talk to.");
        sendTalkVerdict(verdict);
    }
    else{
        relayTalkRequest();
    }
}
Ejemplo n.º 3
0
enum TVerdict CTest03AllocLeave::doTestStepL(void)
	{
	__UHEAP_MARK;
			
#ifdef __CFLOG_ACTIVE
	__CFLOG_CREATEL;
	__CFLOG_OPEN;
#endif
	
	TVerdict verdict(EFail);
	//-------------- substep 1 --------------------
	Log(_L("  01 Create CMBufManager (with 15K alloc memory) and install active scheduler:"));
	CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
	CActiveScheduler::Install(iActSch);

	CleanupStack::PushL(CreateInstanceMBufMgrL(65536));
	if (!iMBMngr)
		{
		Log(_L("Error:Could not create MBuf manager"));

#ifdef __CFLOG_ACTIVE
		__CFLOG_CLOSE;
		__CFLOG_DELETE;
#endif
		User::Leave(EFail);
		}

	//-------------- substep 2 --------------------
	RMBuf* mbufs[14];
	TInt i;
	TInt ret;
	Log(_L("  02 Allocate 42000-bytes long worth of mbufs"));
	for (i = 0; i < sizeof(mbufs)/sizeof(mbufs[0]); ++i)
		{
		TRAP(ret,mbufs[i] = iMBMngr->AllocL(3000));
		Log(_L("  Heap Size after %d allocs : %d"),i,iMBMngr->__DbgGetHeapSize());
		if (ret != KErrNone)
			{
			Log(_L("Error: Couldn't allocate RMBuf:"));

#ifdef __CFLOG_ACTIVE
			__CFLOG_CLOSE;
			__CFLOG_DELETE;
#endif
			User::Leave(EFail);
			}
		}


	//-------------- substep 3 --------------------
	Log(_L("  03 Allocate 8192-bytes long RMBuf2:"));
	RMBuf* aMBuf2=0;
	TRAP(ret,aMBuf2 = iMBMngr->AllocL(16384);)
	if (ret != KErrNone)
Ejemplo n.º 4
0
verdict test_randomized()
{
#if !defined(NO_RANDOMIZATION)
    srand (unsigned(get_time_stamp()/get_frequency())); // Randomize pseudo random number generator
#endif
    std::cout << "=================== Randomized Test ===================" << std::endl;

    size_t a1 = 0, a2 = 0;
    std::vector<long long> mediansV(K); // Final verdict of medians for each of the K experiments with visitors
    std::vector<long long> mediansM(K); // Final verdict of medians for each of the K experiments with matching
    std::vector<long long> timingsV(M);
    std::vector<long long> timingsM(M);
    std::vector<Shape*>    shapes(N);

    for (size_t k = 0; k < K; ++k)
    {
        for (size_t i = 0; i < N; ++i)
            shapes[i] = make_shape(rand());

        run_timings(shapes, timingsV, timingsM, a1, a2);
        mediansV[k] = display("AreaVisRnd", timingsV);
        mediansM[k] = display("AreaMatRnd", timingsM);
        std::cout << "\t\t" << verdict(mediansV[k], mediansM[k]) << std::endl;

        for (size_t i = 0; i < N; ++i)
        {
            delete shapes[i];
            shapes[i] = 0;
        }
    }

    if (a1 != a2)
    {
        std::cout << "ERROR: Invariant " << a1 << "==" << a2 << " doesn't hold." << std::endl;
        exit(42);
    }

    std::sort(mediansV.begin(), mediansV.end());
    std::sort(mediansM.begin(), mediansM.end());
    return verdict(mediansV[K/2],mediansM[K/2]);
}
Ejemplo n.º 5
0
verdict test_repetitive()
{
    std::cout << "=================== Repetitive Test ===================" << std::endl;

    size_t a1 = 0, a2 = 0;
    std::vector<long long> mediansV(K); // Final verdict of medians for each of the K experiments with visitors
    std::vector<long long> mediansM(K); // Final verdict of medians for each of the K experiments with matching
    std::vector<long long> timingsV(M);
    std::vector<long long> timingsM(M);
    std::vector<Shape*>    shapes(N);

    for (size_t k = 0; k < K; ++k)
    {
        for (size_t i = 0; i < N; ++i)
            shapes[i] = make_shape((k+i)*2-k-2*i);

        run_timings(shapes, timingsV, timingsM, a1, a2);
        mediansV[k] = display("AreaVisRep", timingsV);
        mediansM[k] = display("AreaMatRep", timingsM);
        std::cout << "\t\t" << verdict(mediansV[k], mediansM[k]) << std::endl;

        for (size_t i = 0; i < N; ++i)
        {
            delete shapes[i];
            shapes[i] = 0;
        }
    }

    if (a1 != a2)
    {
        std::cout << "ERROR: Invariant " << a1 << "==" << a2 << " doesn't hold." << std::endl;
        exit(42);
    }

    std::sort(mediansV.begin(), mediansV.end());
    std::sort(mediansM.begin(), mediansM.end());
    return verdict(mediansV[K/2],mediansM[K/2]);
}
Ejemplo n.º 6
0
void* main_rules(void *arg)
{
   uint32_t idx = 0;
   struct timeval tv;
   BufEcode ecode = 0;
   struct buffer__ data_arg;
   struct mq_attr mqattr;
   mqd_t msqid;
   uint8_t ret = 0;
   uint8_t *payload_data = NULL;
   uint16_t payload_len = 0;
   struct iphdr *ip_header = NULL;
   union {
      struct tcphdr *tcp_header;
      struct udphdr *udp_header;
   } u;
   
   memset(&tv, 0, sizeof(tv));
   memset(&mqattr, 0, sizeof(mqattr));
   
   mqattr.mq_flags |= O_NONBLOCK;
   mqattr.mq_maxmsg = 512;
   mqattr.mq_msgsize = sizeof(struct msgbuf);
   
   msqid = mq_open("/sialan_firewall",  O_WRONLY | O_CREAT, 0644, &mqattr);
   
   while (!stop) {
      if (disable) {
         tv.tv_sec = 1;
         tv.tv_usec = 0;
         select (0, NULL, NULL, NULL, &tv);
         continue;
      }
      
      memset(&data_arg, 0, sizeof(data_arg));
      ecode = buffer_get(&data_arg, idx);
      
      if (ecode == BUF_CONTINUE) {
         tv.tv_sec = 0;
         tv.tv_usec = 10000;
         select (0, NULL, NULL, NULL, &tv);
         continue;
      }

      ip_header = (struct iphdr *) data_arg.packet;

      if (ip_header->protocol == IPPROTO_TCP) {
         u.tcp_header = (struct tcphdr *) (data_arg.packet + (ip_header->ihl << 2));
         payload_data = (uint8_t *) (data_arg.packet + (ip_header->ihl << 2 ) +
                           (u.tcp_header->th_off << 2));
         payload_len = htons(ip_header->tot_len) - ((ip_header->ihl << 2) +
                           (u.tcp_header->th_off << 2));
         //-------- tcp rules ------------------
         ret = is_http_blacklist(payload_data, payload_len,
                  data_arg.ip_db, data_arg.domain_db);

         if (ret == 1)
            sendto_error_queue(ip_header, u.tcp_header, NULL, NULL,
                        payload_len, msqid, data_arg.in_device);
      } else if (ip_header->protocol == IPPROTO_UDP) {
         u.udp_header = (struct udphdr *) (data_arg.packet + (ip_header->ihl << 2));
         payload_data = (uint8_t *) (data_arg.packet + (ip_header->ihl << 2 ) +
                  sizeof(struct udphdr));
         payload_len = ntohs(u.udp_header->uh_ulen) - sizeof(struct udphdr);
         //-------- udp rules --------------------
         ret = is_dns_blacklist(payload_data, payload_len, data_arg.domain_db);
         
         if (ret == 1)
            sendto_error_queue(ip_header, NULL, u.udp_header,
                  payload_data, payload_len, msqid, data_arg.in_device);
      }

      if ((ret == 2) || (ret == 1))
         verdict(data_arg.id, data_arg.qh, NF_DROP);
      else
         verdict(data_arg.id, data_arg.qh, NF_ACCEPT);
         
      pthread_mutex_lock(&mutex);
      buffer_del(idx);
      pthread_mutex_unlock(&mutex);
      
      idx++;
      if (idx >= buffer_get_size())
         idx = 0;
   }
   
   mq_close(msqid);
   mq_unlink("/sialan_firewall");
   
   pthread_exit(NULL);
}
Ejemplo n.º 7
0
;int _tmain(int argc, _TCHAR* argv[])
{
	;//           ((((ga?)+l?)*(ga?)+)*((m(((ga?)+l?)*(ga?)+)*n)+l?)*(((ga?)+l?)*(ga?)+)*)*
	;//char* exp = "((((ga?)+l?)*(ga?)+)*((m(((ga?)+l?)*(ga?)+)*n)+a?l?)*(((ga?)+l?)*(ga?)+)*)*"//(((m(((ga?)+l?)*(ga?)+)*n)+l?)*(((ga?)+l?)*(ga?)+)*)* (((a?|b?)*(a?|b?)?)*)*
	;//((((ga?)+l?)*(ga?)+)*(m(((ga?)+l?)*(ga?)+)*n)+l?)*((((ga?)+l?)*(ga?)+)*)*
	;//char* exp = "(a|b)*-a-b"temp
	;char* exp = getString()
	;
	;int temp = 0
	;bool operate = false
	;while (!verdict(exp, criterion_Define, temp, false))
	{
		;temp = 0
		;delete exp
		;cout<<"You give me wrong expresstion !"<<endl
		;exp = getString()
	;}
	;int index = charLen(exp)
	;cout<<"You input expression is : "<<exp<<endl
	;TFactory* nodeFactory = new TFactory()
	;DefineToPoland* toPoland = new DefineToPoland(nodeFactory)
	;PolandToTree* NFATree = new PolandToTree(nodeFactory)
	;TreeToNFA* makeNFAList = new TreeToNFA()
	;NFAToDFA* makeDFAList = new NFAToDFA(nodeFactory)
	;CommonalityTree* NFARoot = NULL
	;bool*** NFAList = NULL
	;char* outUnPoland = toPoland->unPolandExp(exp, index)
	;cout<<"UnPoland is :"<<outUnPoland<<endl
	;char* outPoland = toPoland->polandExp(exp, index)
	;cout<<"Poland is :  "<<outPoland<<endl
	;int p = 0
	;NFARoot = NFATree->expToNFA(outPoland, p)
	;int conNum
	;NFAList = makeNFAList->makeNFAList(NFATree, outPoland, conNum)
	;int** DFAList = makeDFAList->NFAListToDFAList(NFATree->getPublicNum(), conNum, NFAList)
	;char* condition = makeNFAList->nodeCondition(NFATree, exp, conNum)
	;cout<<condition<<endl
	;temp = 0
	;while (true)
	{
		;cout<<"Input the string you want to match :"<<endl
		;
		;char* input = getString()
		;
		;int way = 1
		;int inputIndex = 0
		;int tempCha = 0
		;while (('\0' != input[inputIndex]) && (way != 0))//trans()
		{
			;tempCha = 0
			;while (tempCha < conNum)
			{
				;if (condition[tempCha] == input[inputIndex])//trans()
				{
					;++tempCha
					;break
				;}
				;++tempCha
			;}
			;way = DFAList[way - 1][tempCha - 1]
			;++inputIndex
		;}
		;
		;if ((0 != way) && (1 == DFAList[way - 1][conNum]))
		{
			;cout<<"Match !"<<endl
		;}else
		{
			;cout<<"Donn't match !"<<endl
		;}
		;/*
		;if (verdict(input, criterion, temp, operate))
		{
			;cout<<"Match !"<<endl
		;}else
		{
			;cout<<"Donn't match !"<<endl
		;}
		;*///
	;}
	;delete outUnPoland
	;delete outPoland
	;delete toPoland
	;delete NFATree
	;delete nodeFactory
	;cin.get()
	;return 0
;}