Exemplo n.º 1
0
void FctnDialog::nextLine(){
    if(line2->isVisible()){
        line2->setFocus();
    }
    else{
        agree();
    }
}
Exemplo n.º 2
0
CRulesReview1::CRulesReview1(QWidget *parent)
	: QWidget(parent)
{
	setupUi(this);

	connect(pbAgree, SIGNAL(clicked()),this, SLOT(agree()));
	connect(pbQuery, SIGNAL(clicked()),this, SLOT(query()));
	connect(pbReject, SIGNAL(clicked()),this, SLOT(reject()));
	/*connect(pbXaclAgree, SIGNAL(clicked()),this, SLOT(agreeAcl()));
	connect(pbXaclQuery, SIGNAL(clicked()),this, SLOT(queryAcl()));
	connect(pbXaclReject, SIGNAL(clicked()),this, SLOT(rejectAcl()));
	connect(pbPLAgree, SIGNAL(clicked()),this, SLOT(agreeAcl()));
	connect(pbPLQuery, SIGNAL(clicked()),this, SLOT(queryAcl()));
	connect(pbPLReject, SIGNAL(clicked()),this, SLOT(rejectAcl()));*/

	model=new QSqlTableModel(this);
	model->setEditStrategy(QSqlTableModel::OnManualSubmit);
	model->setTable("rule");
	QString filter1 = QString("ispassed=0 and usrgid=%1").arg(g_clientId);
	model->setFilter(filter1);
	model->select();
	tvRule->setModel(model);

	// modelXacl=new QSqlTableModel(this);
	// modelXacl->setEditStrategy(QSqlTableModel::OnManualSubmit);
	// modelXacl->setTable("xaclrules");
	// filter1 = QString("ispassed=0");
	// modelXacl->setFilter(filter1);
	// modelXacl->select();
	// tvXacl->setModel(modelXacl);

	// modelPL=new QSqlTableModel(this);
	// modelPL->setEditStrategy(QSqlTableModel::OnManualSubmit);
	// modelPL->setTable("plrules");
	// filter1 = QString("ispassed=0");
	// modelPL->setFilter(filter1);
	// modelPL->select();
	// tvPL->setModel(modelPL);
}
Exemplo n.º 3
0
std::string Identity::decrypt(const Identity &from,const void *cdata,unsigned int len) const
{
	unsigned char key[64];
	unsigned char mac[32];

	if (len < 16)
		return std::string();

	if (!agree(from,key,sizeof(key)))
		return std::string();

	for(int i=0;i<8;++i)
		key[i + 32] ^= ((const unsigned char *)cdata)[i]; // apply IV to HMAC key
	HMAC::sha256(key + 32,32,((const char *)cdata) + 16,(unsigned int)(len - 16),mac);
	for(int i=0;i<8;++i) {
		if (((const unsigned char *)cdata)[i + 8] != mac[i])
			return std::string();
	}

	char *decbuf = new char[len - 16];
	try {
		Salsa20 s20(key,256,cdata); // first 8 bytes are IV
		len -= 16;
		s20.decrypt((const char *)cdata + 16,decbuf,len);

		std::string decompressed;
		if (Utils::decompress((const char *)decbuf,(const char *)decbuf + len,Utils::StringAppendOutput(decompressed))) {
			delete [] decbuf;
			return decompressed;
		} else {
			delete [] decbuf;
			return std::string();
		}
	} catch ( ... ) {
		delete [] decbuf;
		return std::string();
	}
}
Exemplo n.º 4
0
std::string Identity::encrypt(const Identity &to,const void *data,unsigned int len) const
{
	unsigned char key[64];
	unsigned char mac[32];
	unsigned char iv[8];

	if (!agree(to,key,sizeof(key)))
		return std::string();
	Utils::getSecureRandom(iv,8);
	for(int i=0;i<8;++i)
		key[i + 32] ^= iv[i]; // perturb HMAC key with IV so IV is effectively included in HMAC
	Salsa20 s20(key,256,iv);

	std::string compressed;
	compressed.reserve(len);
	Utils::compress((const char *)data,(const char *)data + len,Utils::StringAppendOutput(compressed));
	if (!compressed.length())
		return std::string();

	char *encrypted = new char[compressed.length() + 16];
	try {
		s20.encrypt(compressed.data(),encrypted + 16,(unsigned int)compressed.length());
		HMAC::sha256(key + 32,32,encrypted + 16,(unsigned int)compressed.length(),mac);
		for(int i=0;i<8;++i)
			encrypted[i] = iv[i];
		for(int i=0;i<8;++i)
			encrypted[i + 8] = mac[i];

		std::string s(encrypted,compressed.length() + 16);
		delete [] encrypted;
		return s;
	} catch ( ... ) {
		delete [] encrypted;
		return std::string();
	}
}
Exemplo n.º 5
0
main() {
   int x, y, loop = 1, fact = 0;
   char instring[200], outstring[200], sub[200], vrb[200], rst[200], qwd[200];
   char osub[200], ovrb[200], orst[200];
   fam = 0;
   printf("Hello there.  My name is Eliza and I was written by Mohan Embar.\n");
   printf("Please type \"END\" to end this session.\n");
   printf("I'm here to help you if I can.  What seems to be the trouble?\n");
   while (loop) {
      printf("\n");
      gets(instring);
      printf("\n");
      parse(instring);
      if (numwords == 0) {
         switch (x = randnum(2)) {
            case 1 : printf("Don't you have anything to say?\n");
               break;
            case 2 : printf("Cat got your tongue?\n");
               break;
         }
         continue;
      }
      if (!strcmp(s[1],"END")) {
         printf("Goodbye.  Please come again.\n");
         break;
      }
      agree();
      if (bad_word())
         printf(b_word_resp());
      else if (naughty_word())
         printf(n_word_resp());
      else if (x = family()) {
         fam = x;
         printf(fam_resp());
         strcpy(fam_member,s[fam]);
      }
      else if (sword("ALIKE",1))
         printf(alike_resp());
      else if (sword("ALWAYS",1))
         printf(always_resp());
      else if (sword("BECAUSE",1))
         printf(because_resp());
      else if (sword("YES",1))
         printf(yes_resp());
      else if (sword("NO",1) || sword("NOT",1))
         printf(neg_resp());
      else if (x = i_am()) { /* If occurrence of I AM x.. */
         get_til_stop(x,outstring);    /* Get I AM x .. into outstring */
         printf(i_am_resp(),outstring); /* Print reponse for this */
      }
      else if (real_quest() ||
              (is_helper(s[1]) && is_sub_pronoun(s[2])) ||
              sub_and_helper()) {
         if (real_quest()) {
            strcpy(qwd,s[1]);
            strcpy(vrb,s[2]);
            strcpy(sub,s[3]);
            get_til_stop(4,rst);
         }
         else if (is_helper(s[1]) && is_sub_pronoun(s[2])) {
            strcpy(vrb,s[1]);
            strcpy(sub,s[2]);
            get_til_stop(3,rst);
            strcpy(qwd,"YES");
         }
         else if (sub_and_helper()) {
            x = find_helper();
            y = search_back_sub(x);
            strcpy(vrb,s[x]);
            get_til_stop(x+1,rst);
            getrange(y,x-1,sub);
            strcpy(qwd,"NO");
         }
         make_lower(qwd);
         if (strcmp(sub,"I")) make_lower(sub);
         make_lower(vrb);
         make_lower(rst);
         /* First do x verb y responses */

         /*
	 printf("\n*** %s\n",sub);
         */
	 
	 if (!strcmp(sub," I") || !strcmp(sub,"I")) {
            printf(you_resp());
         }
         else if (!strcmp(qwd,"no")) {
            /* Record this statement for later use. */
            fact = 1;
            strcpy(osub,sub); strcpy(ovrb,vrb); strcpy(orst,rst);
            if (is_be(vrb) && !strcmp(sub," you") && (y = sad_word())) {
               getrange(y,y,outstring);
               x = randnum(5)+6;
            }
            else if (is_be(vrb) && (y = sad_word())) {
               getrange(y,y,outstring);
               x = randnum(2)+11;
            }
            else if (is_be(vrb))
               x = randnum(6);
            else x = randnum(4);
            switch (x) {
               case 1 : printf("How do you feel about%s?\n",cnnv(sub));
                  break;
               case 2 : printf("Why %s%s%s?\n",vrb,sub,rst);
                  break;
               case 3 : for (y=1;sub[y]=sub[y--];y=y+2);
                  sub[0] = toupper(sub[0]);
                  printf("%s %s%s?\n",sub,vrb,rst);
                  break;
               case 4 : printf("Could you describe%s for me?\n",cnnv(sub));
                  break;
               case 5 : printf("What if%s were not%s?\n",sub,rst);
                  break;
               case 6 : printf("Would you be happy if%s were not%s?\n",sub,
                                rst);
                  break;
               case 7 : printf("I'm sorry to hear that you are%s.\n",outstring);
                  break;
               case 8 : printf("Do you think that coming here will help you not to be%s?\n",outstring);
                  break;
               case 9 : printf("Let's talk about why you feel%s.\n",outstring);
                  break;
               case 10 : printf("What happened that made you feel%s?\n",outstring);
                  break;
               case 11 : printf("What could be the reason for your feeling%s?\n",outstring);
                  break;
               case 12 : printf("What could cause%s to be%s?\n",cnnv(sub),outstring);
                  break;
               case 13 : printf("If%s came here, would it help%s not to be%s?\n",sub,cnnv(sub),outstring);
                  break;
            }
         }
         else if (!strcmp(sub,"you"))
            printf(you_know());
         else if (!strcmp(qwd,"yes")) {
            x = randnum(8);
            switch (x) {
               case 1 : printf("You want to know if %s %s%s.\n",sub,vrb,rst);
                  break;
               case 2 : printf("If %s %s%s, does that concern you?\n",sub,vrb,rst);
                  break;
               case 3 : printf("What are the consequences if %s %s%s?\n",sub,vrb,rst);
                  break;
               case 4 : printf("Why does %s concern you?\n",sub);
                  break;
               case 5 : printf("Why are you thinking of %s?\n",cnnv(sub));
                  break;
               case 6 : printf("Tell me more about %s.\n",cnnv(sub));
                  break;
               case 7 : printf("To answer that, I'd need to know more about %s.\n",cnnv(sub));
                  break;
               case 8 : printf("What is the relationship between you and %s?\n",cnnv(sub));
                  break;
               case 9 : printf("Why don't you ask %s?\n",cnnv(sub));
                  break;
            }
         }
         else {
            x = randnum(8);
            switch (x) {
               case 1 : printf("You want to know %s %s %s%s.\n",qwd,sub,vrb,rst);
                  break;
               case 2 : printf("If %s %s%s, does that concern you?\n",sub,vrb,rst);
                  break;
               case 3 : printf("What are the consequences if %s %s%s?\n",sub,vrb,rst);
                  break;
               case 4 : printf("Why does %s concern you?\n",sub);
                  break;
               case 5 : printf("Why are you thinking of %s?\n",cnnv(sub));
                  break;
               case 6 : printf("Tell me more about %s.\n",cnnv(sub));
                  break;
               case 7 : printf("To answer that, I'd need to know more about %s.\n",cnnv(sub));
                  break;
               case 8 : printf("What is the relationship between you and %s?\n",cnnv(sub));
                  break;
               case 9 : printf("Why don't you ask %s?\n",cnnv(sub));
                  break;
            }
         }
      }
      else if (is_command())
         printf(command_resp());
      else if (vague_quest())
         printf(question());
      else if ((s[numwords][0] == '?') && !real_quest())
         printf(question());
      else if (x = sad_word()) {
         getrange(x,x,outstring);
         for (y=1;outstring[y]=outstring[y--];y=y+2);
         outstring[0] = toupper(outstring[0]);
         printf("%s?\n",outstring);
      }
      else if (x = can_spit_out()) {
         if (x<=(numwords-2) && is_sub_pronoun(s[x])
                             && (matches("NEED",s[x+1]) ||
                                 matches("WANT",s[x+1]))) {
            get_til_stop(x+2,outstring);
            strcpy(sub,s[x]);
            if (strcmp(sub,"I")) make_lower(sub);
            if (strcmp(s[x],"I")) make_lower(s[x]);
            x = randnum(6);
            switch (x) {
               case 1 : printf("What would it mean to %s if %s got%s?\n",cnnv2(s[x]),sub,outstring);
                  break;
               case 2 : printf("Would %s really be happy if %s got%s?\n",sub,sub,outstring);
                  break;
               case 3 : printf("Why is getting%s so desirable?\n",outstring);
                  break;
               case 4 : printf("Okay.  Suppose %s got%s.  Then what?\n",sub,outstring);
                  break;
               case 5 : printf("Why is this important to %s?\n",cnnv2(sub));
                  break;
               case 6 : printf("What price would %s pay to achieve this?\n",sub);
                  break;
            }
         }
         else {
            get_til_stop(x,outstring);
            outstring[1]=toupper(outstring[1]);
            printf("%s.\n",outstring+1);
         }
      }
      else if (fam) {
         make_lower(fam_member);
         printf(family_resp(),fam_member);
         fam = 0;
      }
      else if (fact && (randnum(5)==3)) {
         printf(old_fact(),osub,ovrb,orst);
         fact = 0;
      }
      else {
         printf(go_on());
      }
   }
}
Exemplo n.º 6
0
void uart_run_macro(const uint16_t macro) {
  switch (macro) {
  case UART_MACRO_MENU:
    MSG_UART_MACRO_MENU;
    break;

  case UART_MACRO_BRIDGE_WITH_FLOW_CONTROL:
#ifdef BUSPIRATEV3
    /* FTDI CTS and RTS setup. */
    FTDI_CTS_DIR = OUTPUT;
    FTDI_RTS_DIR = INPUT;

    /* External CTS and RTS setup. */
    BP_CS_DIR = INPUT;
    BP_CLK_DIR = OUTPUT;
#else
/* Do nothing for v4? */
#endif /* BUSPIRATEV3 */

  /* Intentional fall-through. */

  case UART_MACRO_TRANSPARENT_BRIDGE:
    MSG_UART_BRIDGE;
    MSG_UART_BRIDGE_EXIT;

    if (!agree()) {
      break;
    }

    /* Make terminal speed match target speed to avoid overruns? */

    /* Clear overrun flag. */
    U2STAbits.OERR = OFF;

    for (;;) {
#ifdef BUSPIRATEV4
      if (BP_BUTTON_ISDOWN()) {
        break;
      }

      if (U2STAbits.URXDA == ON) {
        user_serial_transmit_character(U2RXREG);
      }
#else
      if ((U2STAbits.URXDA == ON) && (U1STAbits.UTXBF == OFF)) {
        U1TXREG = U2RXREG;
      }
#endif /* BUSPIRATEV4 */

      if (user_serial_ready_to_read() && (U2STAbits.UTXBF == OFF)) {
        U2TXREG = user_serial_read_byte();
      }

#ifdef BUSPIRATEV3
      if (U2STAbits.OERR || U1STAbits.OERR) {
        U2STAbits.OERR = OFF;
        U1STAbits.OERR = OFF;
        BP_LEDMODE = LOW;
      }
#else
      if (U2STAbits.OERR) {
        U2STAbits.OERR = OFF;
        BP_LEDMODE = LOW;
      }
#endif /* BUSPIRATEV3 */

#ifdef BUSPIRATEV3
      if (macro == UART_MACRO_BRIDGE_WITH_FLOW_CONTROL) {
        /* Relay flow control bits. */
        BP_CLK = FTDI_RTS;
        FTDI_CTS = BP_CS;
      }
#endif /* BUSPIRATEV3 */
    }
    break;

  case UART_MACRO_RAW_UART:
    MSG_UART_RAW_UART_INPUT;
    MSG_ANY_KEY_TO_EXIT_PROMPT;

    U2STAbits.OERR = OFF;
    for (;;) {
#ifdef BUSPIRATEV4
      if (BP_BUTTON_ISDOWN()) {
        break;
      }

      if (uart2_rx_ready()) {
        user_serial_transmit_character(uart2_rx());
      }
#else
      if ((U2STAbits.URXDA == ON) && (U1STAbits.UTXBF == OFF)) {
        U1TXREG = U2RXREG;
      }
#endif /* BUSPIRATEV4 */

      if (user_serial_ready_to_read()) {
        volatile uint16_t dummy;

        dummy = user_serial_read_byte();
        break;
      }
    }
    break;

  case UART_MACRO_AUTO_BAUD_RATE_DETECTION:
    uart2_disable();
    uart_get_baud_rate(false);
    uart2_enable();
#ifdef BUSPIRATEV3
    if (U2BRG < U1BRG) {
      MSG_UART_POSSIBLE_OVERFLOW;
    }
#endif /* BUSPIRATEV3 */
    break;

  default:
    MSG_UNKNOWN_MACRO_ERROR;
    break;
  }
}
Exemplo n.º 7
0
FctnDialog::FctnDialog(stringFactory *fac, QWidget *parent) :
    QDialog(parent)
{
    setWindowTitle("Mace");
    setWindowIcon(QIcon("icons/MaceLogo.png"));

    vbox = new QVBoxLayout;
    funcVars = new QVBoxLayout;
    hbox = new QHBoxLayout;
    grid = new QGridLayout;
    radioGrid = new QGridLayout;

    radioBox = new QVBoxLayout;
    mlay = new QHBoxLayout;

    pBox = new QSpinBox;
    pBox2 = new QSpinBox;

    pdf = new QRadioButton("pdf (probability density function)");
    cdf = new QRadioButton("cdf (cumulative distribution function)");
    hazard = new QRadioButton("haz (hazard function)");
    quantile = new QRadioButton("qua (quantile)");
    pdf->setChecked(true);

    kurt = new QRadioButton("kurtosis");
    kurtex = new QRadioButton("kurtosis excess");
    mean = new QRadioButton("mean");
    median = new QRadioButton("median");
    mode = new QRadioButton("mode");
    skewness = new QRadioButton("skewness");
    standdev = new QRadioButton("standard deviation");
    variance = new QRadioButton("variance");
    mean->setChecked(true);

    tab = new QTabWidget;

    statFunc = new QGroupBox("");
    statVars = new QGroupBox("");

    help = new QPushButton("Help");
    but = new QPushButton("Ok");
    but2 = new QPushButton("No");

    line1 = new MaceLineEdit;
    line2 = new MaceLineEdit;
    line3 = new MaceLineEdit;
    line4 = new MaceLineEdit;

    label1 = new QLabel;
    label2 = new QLabel;
    label3 = new QLabel;
    label4 = new QLabel;

    pLabel = new QLabel;
    pLabel2 = new QLabel;

    grid->addWidget(label1,0,0,1,1);
    grid->addWidget(line1,0,1,1,1);
    grid->addWidget(label2,1,0,1,1);
    grid->addWidget(line2,1,1,1,1);
    grid->addWidget(label3,2,0,1,1);
    grid->addWidget(line3,2,1,1,1);
    grid->addWidget(label4,3,0,1,1);
    grid->addWidget(line4,3,1,1,1);
    grid->addWidget(pLabel,4,0,1,1);
    grid->addWidget(pBox,4,1,1,1);
    grid->addWidget(pLabel2,5,0,1,1);
    grid->addWidget(pBox2,5,1,1,1);

    info = new QTextEdit;
    vertic = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);

    factory = fac;

    label = new QLabel(labelStr);

    vbox->addWidget(label);

    vbox->addLayout(grid);

    info->setMaximumSize(237,120);
    info->setReadOnly(true);
    info->setHidden(true);

    vbox->addWidget(info);
    vbox->addItem(vertic);

    hbox->addWidget(but);
    hbox->addWidget(but2);
    hbox->addWidget(help);
    vbox->addLayout(hbox);

    radioBox->addWidget(pdf);
    radioBox->addWidget(cdf);
    radioBox->addWidget(hazard);
    radioBox->addWidget(quantile);
    statFunc->setLayout(radioBox);

    radioGrid->addWidget(mean,0,0,1,1);
    radioGrid->addWidget(skewness,0,1,1,1);
    radioGrid->addWidget(median,1,0,1,1);
    radioGrid->addWidget(standdev,1,1,1,1);
    radioGrid->addWidget(mode,2,0,1,1);
    radioGrid->addWidget(variance,2,1,1,1);
    radioGrid->addWidget(kurt,3,0,1,1);
    radioGrid->addWidget(kurtex,3,1,1,1);
    statVars->setLayout(radioGrid);

    mlay->addLayout(vbox);

    statFunc->setFlat(true);
    statVars->setFlat(true);

    tab->addTab(statFunc,"Functions");
    tab->addTab(statVars,"Properties");

    mlay->addWidget(tab);
    setLayout(mlay);

    quantile->setHidden(true);
    kurt->setHidden(true);
    kurtex->setHidden(true);

    this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);

    QWidget::connect(but2,SIGNAL(clicked()),this,SLOT(close()));
    QWidget::connect(but,SIGNAL(clicked()),this,SLOT(agree()));
    QWidget::connect(help,SIGNAL(clicked()),this,SLOT(show_info()));
    QWidget::connect(tab,SIGNAL(currentChanged(int)),this,SLOT(statSwitch(int)));

    QObject::connect(line2,SIGNAL(entered()),this,SLOT(agree()));
    QObject::connect(line1,SIGNAL(entered()),this,SLOT(nextLine()));
}