Example #1
0
void QAuServer::play(const QString& filename)
{
    QSound s(filename);
    play(&s);
}
Example #2
0
Spectrum AggregateVolume::sigma_t(const Point &p, const Vector &w, float time) const {
    Spectrum s(0.);
    for (uint32_t i = 0; i < regions.size(); ++i)
        s += regions[i]->sigma_t(p, w, time);
    return s;
}
Example #3
0
void CheckExternalScripts::add_script(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response) {

	namespace po = boost::program_options;
	namespace pf = nscapi::protobuf::functions;
	po::variables_map vm;
	po::options_description desc;
	std::string script, arguments, alias;
	bool wrapped;

	desc.add_options()
		("help", "Show help.")

		("script", po::value<std::string>(&script), 
		"Script to add")

		("alias", po::value<std::string>(&alias), 
		"Name of command to execute script (defaults to basename of script)")

		("arguments", po::value<std::string>(&arguments), 
		"Arguments for script.")

		("wrapped", po::bool_switch(&wrapped), 
		"Add this to add a wrapped script such as ps1, vbs or similar..")

		;

	try {
		nscapi::program_options::basic_command_line_parser cmd(request);
		cmd.options(desc);

		po::parsed_options parsed = cmd.run();
		po::store(parsed, vm);
		po::notify(vm);
	} catch (const std::exception &e) {
			return nscapi::program_options::invalid_syntax(desc, request.command(), "Invalid command line: " + utf8::utf8_from_native(e.what()), *response);
	}

	if (vm.count("help")) {
		nscapi::protobuf::functions::set_response_good(*response, nscapi::program_options::help(desc));
		return;
	}
	boost::filesystem::path file = get_core()->expand_path(script);
	if (!wrapped) {
		if (!boost::filesystem::is_regular(file)) {
			nscapi::protobuf::functions::set_response_bad(*response, "Script not found: " + file.string());
			return;
		}
	}
	if (alias.empty()) {
		alias = boost::filesystem::basename(file.filename());
	}

	nscapi::protobuf::functions::settings_query s(get_id());
	if (!wrapped)
		s.set("/settings/external scripts/scripts", alias, script + " " + arguments);
	else
		s.set("/settings/external scripts/wrapped scripts", alias, script + " " + arguments);
	s.set(MAIN_MODULES_SECTION, "CheckExternalScripts", "enabled");
	s.save();
	get_core()->settings_query(s.request(), s.response());
	if (!s.validate_response()) {
		nscapi::protobuf::functions::set_response_bad(*response, s.get_response_error());
		return;
	}
	std::string actual = "";
	if (wrapped)
		actual = "\nActual command is: " + generate_wrapped_command(script + " " + arguments);
	nscapi::protobuf::functions::set_response_good(*response, "Added " + alias + " as " + script + actual);
}
/// 
/// Main routine
/// 
/// @param argc number of arguments
/// @param argv pointers to arguments
/// 
/// @return error code
///
int main(int argc, char** argv) {
	std::ofstream file_log, file_error;
	try {
		std::locale::global(std::locale("rus"));
		std::cout << "Usage: main_boost_asio.exe [remote_port remote_address local_port local_address number_acceptors numer_executors language_locale]" << std::endl << std::endl;

#ifdef _MSC_VER
		std::cout << "_MSC_VER  = " << _MSC_VER  << std::endl; 
#endif
#ifdef __GNUC__
		std::cout << "__GNUC__  = " << __GNUC__  << ", __GNUC_MINOR__ = " << __GNUC_MINOR__ << std::endl;
#endif

		// Remote address::port
		unsigned short remote_port = 80;
		std::string remote_address = "google.com";

		// Local interface address::port
		unsigned short local_port = 10001;
		std::string local_interface_address = "0.0.0.0";

		// Number of thread for acceptors and executors
		unsigned int thread_num_acceptors = 2;
		unsigned int thread_num_executors = boost::thread::hardware_concurrency();

		std::cout << "(Default: main_boost_asio.exe " << remote_port << " " << remote_address << " " << 
			local_port << " " << local_interface_address << " " << 
			thread_num_acceptors << " " << thread_num_executors << " " << std::locale::global(std::locale()).name() << ")" << std::endl;

		// read remote port number from command line, if provided
		if(argc > 1)
			remote_port = boost::lexical_cast<unsigned short>(argv[1]);
		// read remote address from command line, if provided
		if(argc > 2)
			remote_address = argv[2];

		// read local port number from command line, if provided
		if(argc > 3)
			local_port = boost::lexical_cast<unsigned short>(argv[3]);
		// read local interface address from command line, if provided
		if(argc > 4)
			local_interface_address = argv[4];

		// read number of threads in thread pool from command line, if provided
		if(argc > 5)
			thread_num_acceptors = boost::lexical_cast<unsigned int>(argv[5]);
		if(argc > 6)
			thread_num_executors = boost::lexical_cast<unsigned int>(argv[6]);

		// set language locale
		if(argc > 7)
			setlocale(LC_ALL, argv[7]);
		// ----------------------------------------------------------------------------

		// Enable Windows SEH exceptions. Compile with key: /EHa 
		seh::seh_exception_init();

		if(true) std::cout.rdbuf(NULL);	// switch off std::cout
				
		/// Output errors(exceptions) to file instead of the console (std::cerr)
		if(false) {			
			file_error.open("log_errors.txt", std::ios_base::out | std::ios_base::trunc);	// std::ios_base::ate
			std::cerr.rdbuf(file_error.rdbuf());
		}

		/// Output to file instead of the console (std::clog)
		if(false) {			
			file_log.open("log.txt", std::ios_base::out | std::ios_base::app);
			std::clog.rdbuf(file_log.rdbuf());
		}
		std::clog << "----------------------------------------------------------------------------"  << std::endl;
		// ----------------------------------------------------------------------------


		boost::asio::io_service io_service_acceptors, io_service_executors;
		// construct new server object
		T_server s(io_service_acceptors, io_service_executors, thread_num_acceptors, thread_num_executors,
			remote_port, remote_address, local_port, local_interface_address);
		// run io_service object, that perform all dispatch operations
		io_service_acceptors.run();
	} catch (std::exception& e) {
		std::cerr << e.what() << std::endl;
	} catch (...) {
		std::cerr << "Unknown exception!" << std::endl;
	}
	file_log.close(), file_error.close();

	return 0;
}
Example #5
0
void springMotion::addSpring(particle * a, particle * b)
{
    spring s(a, b);
    springs.push_front(s);
}
Example #6
0
/*
  Writes a JSON config file back to disk. Uses a list of connections
  and the map from which to write back. As well as an additional new pair
  of QStrings. If either of those are missing it will just write the old
  data in to the file.
*/
bool WriteJSONConfigFile(QStringList connection_names, QVariantMap connection_map,
                         QString filename, QString database, QString table)
{
    QFile file(filename);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return false;

    QTextStream s(&file);

    s << "{\n\t";

    // if the connection_names has a size, then it must be a pre-existing
    // config file, pre-existing files should all have version strings.
    if (connection_names.size())
        s << quote("version", connection_map["version"].toString());
    else
        s << quote("version", "0.1");
    s  << ",\n\t";

    // we need x outside the loop, so we declare it here.
    int x;
    for (x = 0; x < connection_names.size(); ++x) {
        // we use the map twice so we'll just store it.
        QVariantMap xmap = connection_map[connection_names[x]].toMap();

        // we're using newlines and tabs because the config file should be
        // human readable.
        s << quote(cxnstring(x)) << ": {\n\t\t";
        s << quote("database", xmap["database"].toString())
          << ",\n\t\t";
        s << quote("table", xmap["table"].toString())
          << "\n\t}";
        s << ",\n\t";
    }

    // we're simply re-writing the config file if we weren't supplied with
    // additional database/table strings.
    //
    // Otherwise we've got an additional database/table combo to store.
    QString empty = QString("");
    if (database != empty) {
        s << quote(cxnstring(x)) << ": {\n\t\t";
        s << quote("database", database) << ",\n\t\t";
        s << quote("table", table) << "\n\t";
        s << "},";
        // we increment x because we need to write out the names of the
        // connections, if we don't increment x it will write out just the
        // names of the pre-existing connections.
        x++;
    }

    s << "\n\t";
    s << quote("connections") << ": [";
    for (int z = 0; z < x; ++z) {
        s << quote(cxnstring(z));
        if (z + 1 != x)
            s << ",";
    }
    s << "]\n}\n";
    s.flush();
    return true;
}
void CSyncServer::AddClient(int id, const string& unitList)
{
	istringstream s(unitList);
	Unit u;
	string name;

	while (s >> name) {
		s >> u.fbi;
		s >> u.cob;
		s >> u.model;

		clientLists[id][name] = u;
	}

	//The time has come, to calculate diffs! ohnoes!
	curDiff.clear();
	lastDiffClient = id;
	lastWasRemove = false;

	for (map<string, Unit>::iterator i = clientLists[id].begin(); i != clientLists[id].end(); ++i) {

		//Check with each other client if they have this unit
		for (map<int, unitlist_t>::iterator clientId = clientLists.begin(); clientId != clientLists.end(); ++clientId) {
			
			//No need to compare with ourselves
			if (clientId->first == id)
				continue;

			//Now, determine if this unit is here, and if so, if it has the same crc
			map<string, Unit>::iterator curUnit = clientLists[clientId->first].find(i->first);
			bool unitOk = false;
			if (curUnit != clientLists[clientId->first].end()) {
				if ((curUnit->second.fbi   == i->second.fbi) &&
				    (curUnit->second.cob   == i->second.cob) &&
				    (curUnit->second.model == i->second.model)) {
					unitOk = true;
				}
			}

			if (unitOk) {
				//No need to say anything about this unit
			}
			else {
				// If a unit has a bad crc, that client is added to the differing list
				map<string, MissingList>::iterator mli = curDiff.find(i->first);
				if (mli != curDiff.end()) {
					curDiff[i->first].clients.insert(clientId->first);
				}
				else {
					MissingList ml;
					ml.clients.insert(clientId->first);
					curDiff[i->first] = ml;
				}
			}
		}
	}

	//Now we need to check the other way around.. If any client had a unit that we did not
	//if we find such a unit, it must be added to the difflist for that client
	//this could possibly be optimized by flagging everything that we do find in the above pass..
	for (map<int, unitlist_t>::iterator client = clientLists.begin(); client != clientLists.end(); ++client) {
		
		//No need to diff with ourselves
		if (client->first == id)
			continue;

		for (map<string, Unit>::iterator unit = client->second.begin(); unit != client->second.end(); ++unit) {
			map<string, Unit>::iterator found = clientLists[id].find(unit->first);

			//If not found, we should do things
			if (found == clientLists[id].end()) {
				map<string, MissingList>::iterator mli = curDiff.find(unit->first);
				if (mli != curDiff.end()) {
					curDiff[unit->first].clients.insert(client->first);
				}
				else {
					MissingList ml;
					ml.clients.insert(client->first);
					curDiff[unit->first] = ml;
				}
			}
		}
	}

	//Alright, now we have a map that for each unit contains id's of clients that need to know that
	//this unit should now be disabled

	// Since we are the server, we should install the diff for ourselves automatically
	string diff = GetClientDiff(localId);
	InstallClientDiff(diff);
}
Example #8
0
void Decode()
{
  Socket s("127.0.0.1", 9091) ;
  std::fstream f("decoded.txt", std::ios::out | std::ios::trunc) ;
  AESCTRDRBG rng("The seed of the demo program for stream coding.", \
      "23ASDFpo34wiasd 98fa$#WR09asdf AW#RsadfASDF a43wrSDFz 902%$#@aweSDF ") ;

  int maxK = 0 ;
  std::vector<TreeCodeDecoder *> code ;
  std::vector<int64_t> pos, len ;
  BlueBerryCode bc ;
  std::vector<uint8_t> data ;

  for(int n=1;n<=maxN;n++)
  {
    while(EncodeR+2<n) usleep(200) ;
    DecodeR = n ;
    data.push_back(0) ;
    if(n==1 || n/log2(n)>maxK+1)
    {
      std::string seed ;
      for(int i=0;i<32;i++)
      {
        uint8_t cur = 0 ;
        std::vector<uint8_t> bits = rng.GetBits(8) ;
        for(int j=0;j<8;j++)
          cur = (cur<<1) | bits[j] ;
        seed += (char) cur ;
      }
      code.push_back(new TreeCodeDecoder(seed)) ;
      pos.push_back(n-1) ;
      len.push_back(0) ;
      maxK++ ;
    }
    for(int r=0;r<c0;r++)
    {
      std::vector<uint8_t> buf ;
      s.Recv(8, buf) ;
      uint64_t cw = 0 ;
      for(int i=7;i>=0;i--)
        cw = (cw<<8) | buf[i] ;
      cw = bc.Decode(cw) ;
      int curK = rng.Next(0, maxK-1) ;
      code[curK]->Decode(cw) ;
      len[curK]++ ;
    }

    for(int i=0;i<maxK;i++)
    {
      int64_t valid = std::min(len[i], std::min(pos[i]+1, (int64_t)floor(c1*log2(n)))) ;
      const std::vector<uint64_t> decoded = code[i]->GetDecoded() ;
      for(int64_t j=0;j<valid;j++)
        data[pos[i]-j] = decoded[j] ;
    }

    for(int i=0;i<n;i++)
      f << (int)data[i] ;

    if(n%1024==0)
      printf("End of Decode round %d\n",n) ;
  }

  f.close() ;
  for(auto ptr: code)
    delete ptr ;
}
Example #9
0
void cveCLAHE(cv::_InputArray* src, double clipLimit, emgu::size* tileGridSize, cv::_OutputArray* dst)
{
   cv::Size s(tileGridSize->width, tileGridSize->height);
   cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit, s);
   clahe->apply(*src, *dst);
}
Example #10
0
void prove_tests::test_proofs_irma_testvec()
{
	////////////////////////////////////////////////////////////////////
	// Issuer public key
	////////////////////////////////////////////////////////////////////
	
	mpz_class n("0x88CC7BD5EAA39006A63D1DBA18BDAF00130725597A0A46F0BACCEF163952833BCBDD4070281CC042B4255488D0E260B4D48A31D94BCA67C854737D37890C7B21184A053CD579176681093AB0EF0B8DB94AFD1812A78E1E62AE942651BB909E6F5E5A2CEF6004946CCA3F66EC21CB9AC01FF9D3E88F19AC27FC77B1903F141049");
	mpz_class Z("0x3F7BAA7B26D110054A2F427939E61AC4E844139CEEBEA24E5C6FB417FFEB8F38272FBFEEC203DB43A2A498C49B7746B809461B3D1F514308EEB31F163C5B6FD5E41FFF1EB2C5987A79496161A56E595BC9271AAA65D2F6B72F561A78DD6115F5B706D92D276B95B1C90C49981FE79C23A19A2105032F9F621848BC57352AB2AC");
	mpz_class S("0x617DB25740673217DF74BDDC8D8AC1345B54B9AEA903451EC2C6EFBE994301F9CABB254D14E4A9FD2CD3FCC2C0EFC87803F0959C9550B2D2A2EE869BCD6C5DF7B9E1E24C18E0D2809812B056CE420A75494F9C09C3405B4550FD97D57B4930F75CD9C9CE0A820733CB7E6FC1EEAF299C3844C1C9077AC705B774D7A20E77BA30");
	std::vector<mpz_class> R;
	
	R.push_back(mpz_class("0x6B4D9D7D654E4B1285D4689E12D635D4AF85167460A3B47DB9E7B80A4D476DBEEC0B8960A4ACAECF25E18477B953F028BD71C6628DD2F047D9C0A6EE8F2BC7A8B34821C14B269DBD8A95DCCD5620B60F64B132E09643CFCE900A3045331207F794D4F7B4B0513486CB04F76D62D8B14B5F031A8AD9FFF3FAB8A68E74593C5D8B"));
	R.push_back(mpz_class("0x177CB93935BB62C52557A8DD43075AA6DCDD02E2A004C56A81153595849A476C515A1FAE9E596C22BE960D3E963ECFAC68F638EBF89642798CCAE946F2F179D30ABE0EDA9A44E15E9CD24B522F6134B06AC09F72F04614D42FDBDB36B09F60F7F8B1A570789D861B7DBD40427254F0336D0923E1876527525A09CDAB261EA7EE"));
	R.push_back(mpz_class("0x12ED9D5D9C9960BACE45B7471ED93572EA0B82C611120127701E4EF22A591CDC173136A468926103736A56713FEF3111FDE19E67CE632AB140A6FF6E09245AC3D6E022CD44A7CC36BCBE6B2189960D3D47513AB2610F27D272924A84154646027B73893D3EE8554767318942A8403F0CD2A41264814388BE4DF345E479EF52A8"));
	R.push_back(mpz_class("0x7AF1083437CDAC568FF1727D9C8AC4768A15912B03A8814839CF053C85696DF3A5681558F06BAD593F8A09C4B9C3805464935E0372CBD235B18686B540963EB9310F9907077E36EED0251D2CF1D2DDD6836CF793ED23D266080BF43C31CF3D304E2055EF44D454F477354664E1025B3F134ACE59272F07D0FD4995BDAACCDC0B"));
	R.push_back(mpz_class("0x614BF5243C26D62E8C7C9B0FAE9C57F44B05714894C3DCF583D9797C423C1635F2E4F1697E92771EB98CF36999448CEFC20CB6E10931DED3927DB0DFF56E18BD3A6096F2FF1BFF1A703F3CCE6F37D589B5626354DF0DB277EF73DA8A2C7347689B79130559FB94B6260C13D8DC7D264BA26953B906488B87CDC9DFD0BC69C551"));
	R.push_back(mpz_class("0x5CAE46A432BE9DB72F3B106E2104B68F361A9B3E7B06BBE3E52E60E69832618B941C952AA2C6EEFFC222311EBBAB922F7020D609D1435A8F3F941F4373E408BE5FEBAF471D05C1B91030789F7FEA450F61D6CB9A4DD8642253327E7EBF49C1600C2A075EC9B9DEC196DDBDC373C29D1AF5CEAD34FA6993B8CDD739D04EA0D253"));
	R.push_back(mpz_class("0x52E49FE8B12BFE9F12300EF5FBDE1800D4611A587E9F4763C11E3476BBA671BFD2E868436C9E8066F96958C897DD6D291567C0C490329793F35E925B77B304249EA6B30241F5D014E1C533EAC27AA9D9FCA7049D3A8D89058969FC2CD4DC63DF38740701D5E2B7299C49EC6F190DA19F4F6BC3834EC1AE145AF51AFEBA027EAA"));
	R.push_back(mpz_class("0x05AA7EE2AD981BEE4E3D4DF8F86414797A8A38706C84C9376D324070C908724BB89B224CB5ADE8CDDB0F65EBE9965F5C710C59704C88607E3C527D57A548E24904F4991383E5028535AE21D11D5BF87C3C5178E638DDF16E666EA31F286D6D1B3251E0B1470E621BEE94CDFA1D2E47A86FD2F900D5DDCB42080DAB583CBEEEDF"));
	R.push_back(mpz_class("0x73D3AB9008DC2BD65161A0D7BFC6C29669C975B54A1339D8385BC7D5DEC88C6D4BD482BFBC7A7DE44B016646B378B6A85FBC1219D351FE475DC178F90DF4961CA980EB4F157B764EC3ECF19604FEDE0551AA42FB12B7F19667AC9F2C46D1185E66072EA709CC0D9689CE721A47D54C028D7B0B01AEEC1C4C9A03979BE9080C21"));
	R.push_back(mpz_class("0x33F10AB2D18B94D870C684B5436B38AC419C08FB065A2C608C4E2E2060FE436945A15F8D80F373B35C3230654A92F99B1A1C8D5BB10B83646A112506022AF7D4D09F7403EC5AECDB077DA945FE0BE661BAFEDDDDC5E43A4C5D1A0B28AE2AA838C6C8A7AE3DF150DBD0A207891F1D6C4001B88D1D91CF380EE15E4E632F33BD02"));
	
	silvia_pub_key pubkey(n, S, Z, R);
	
	////////////////////////////////////////////////////////////////////
	// Test attributes
	////////////////////////////////////////////////////////////////////
	
	silvia_integer_attribute m1(1313);
	silvia_integer_attribute m2(1314);
	silvia_integer_attribute m3(1315);
	silvia_integer_attribute m4(1316);
	
	std::vector<silvia_attribute*> attributes;
	attributes.push_back(&m1);
	attributes.push_back(&m2);
	attributes.push_back(&m3);
	attributes.push_back(&m4);
	
	////////////////////////////////////////////////////////////////////
	// Test credential
	////////////////////////////////////////////////////////////////////
	
	silvia_integer_attribute s(mpz_class("0xB1173E9CFA91149B60B6A3A5822B49FAF79A6EED971469FCABEA79BC82AF36E0"));
	
	mpz_class A("0x37FB456B3D4D38F890F5DECDBE8147DD476A8F951E325EB3E860ABD2CCD4F52A1EF46594ED2D450869328DFFF6ACBD049BB8DD7AE4E256EB501B79BC17E1D68AB224D9CC310EB73CC218C43E860346942D690BBCEE7A3ED392D3933BB8CE6D4539A4D08475738A84B0FFB7D1A0CF25644E6EABC97A52C62BBC507E6885D16373");
	mpz_class e("0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006D093A6A327D0392ED2787DA24BB7D");
	mpz_class v("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD202469CA72461E10DF2A29E7E134760C8C0CAAEC78709119C673665FC5009309CAC9A4BB5361B0494B129D03A9ED84A7AD87DE4B16BDB69F37E09B1F3FE56550F456E04FB78CBE52A577B1A2429A9FB29F41C4716A9F3FCD2C6BBE38925E9E4B088573530901628491F96EAB564C8EC0488BAECB6667E4B48DE715436C8116428766E6F3877DE982AAF48");
	
	silvia_credential testcredential(s, attributes, A, e, v);
	
	////////////////////////////////////////////////////////////////////
	// Initialise prover
	////////////////////////////////////////////////////////////////////
	
	silvia_prover prover(&pubkey, &testcredential);
	
	////////////////////////////////////////////////////////////////////
	// Proof #1:
	// Hide: 1, 2, 3
	// Reveal: 4
	////////////////////////////////////////////////////////////////////
	
	// Test vectors
	mpz_class e_tilde_test("0xBBB5ABB7452E6E1A92DBE48A178BB1D7D432E76930DDDDA5FF6622D76D25B39B9F3FD1B4B1660D69A987D0BB47");
	mpz_class v_prime_tilde_test("0x0D6D04955AC35F1A2D0268816B3946F6C50A82B156888999208BE9DD2757F6862EAD7DBDF598609225DD27F1103A15422710429927CC4CC95F01354DC2AB428E725CF8A27596B7B25EB8BA780A613C81B7506C2A5BECC540B0149B1DFEB4DD3D15B7D6ED14D8F6416C7367C2586300115DC92CC845EA635FF79F9AE0417D5E3F433E55C2E9ECADBA7F7D4F644760A366C04FCB018E45CB3B0F559E08AB159F6E976EBBF36448459F1B9EA5F1F7E71159D79998A8E760432877345416C79B24D184BA72A2E48672EF004895EE907B1BFFD35365D1AA91BEB1E1B12F793EE23635B6BB971C8992C3");
	mpz_class r_A_test("0x01A7B7470063345F87212D62F9D4E8EA4ECA78E6A6A71DE64DBF273970AFD4BAF80568F3BB9878C56EB857F41D34477536B4058A2B88BDCABD515CC2C173646267B952731C6BF8632D333368339611B48112DA7CEBD11281987B040035D6A63E6236C1FF90C7739240D3DDEE905BE73B759712971E124CCB852E9FD454FF9104083A7AF99910B3509289");
	
	std::vector<mpz_class> a_tilde_test;
	a_tilde_test.push_back(mpz_class("0x7622FFA28514B79650D98E49B0C6CD9A558216FE3EE4DDC551405F78E4ACD14C0BA060409DE10AE10600CCAFF6734AC6353BB7246E929997C375E036DDA9")); // s~
	a_tilde_test.push_back(mpz_class("0xE5B5C4B03E78F8C46D637265E57822CD57F70994361CD2BEDF8127FF1092BD3821038A1FE732906DD13A9797CC267E4214D9CB756147838DB334D1E64452")); // a1~
	a_tilde_test.push_back(mpz_class("0xF1DB7871B669CE64D0C75F91ECFBC97C6E8AEE0B9CAE90684D4B800F1B2C650D70559F962572C1434342639B0739557615A58B25B3DA59A1E20592A09091")); // a2~
	a_tilde_test.push_back(mpz_class("0x2230F071F1883E51265E06380C4A59360C35077C4B7B98E33090FA437A23C78FAC7C808CF3D40AE1E2F976AA261E70BC02CAE599173A5D9842346EB88032")); // a3~
	
	// Verifier input to proof
	mpz_class n1_proof1("0x677A2A3F6EB0135F4571");
	mpz_class context("0xB7FC4FCA77E2FA6010F346B2F535F5ACE62B0C84");
	
	std::vector<bool> proof_spec;
	proof_spec.push_back(false);	// don't reveal a1
	proof_spec.push_back(false);	// don't reveal a2
	proof_spec.push_back(true);		// reveal a3
	proof_spec.push_back(false);	// don't reveal a4
	
	// Proof output
	mpz_class c;
	mpz_class A_prime;
	mpz_class e_hat;
	mpz_class v_prime_hat;
	std::vector<mpz_class> a_i_hat;
	std::vector<silvia_attribute*> a_i;
	
	// Generate the proof
	prover.prove(proof_spec, n1_proof1, context, c, A_prime, e_hat, v_prime_hat, a_i_hat, a_i, &e_tilde_test, &v_prime_tilde_test, &r_A_test, &a_tilde_test);
	
	// Check general proof factors
	CPPUNIT_ASSERT(A_prime == mpz_class("0x2533EDE93E23A28A07C7277933166284D9F5BB2C2D0F6ACC9995B164DA597176AD26304455DCFAAA1C973EC69E74559362270322716FC2DABC5F1B5147091DA66731E46F6B2BFC9FE45D65557BA900BFB1177A6A7257C8A756352689D09E33638F9DF9B711027A49D2983E6CE9876AF1C421510A60BC0D3B6E292F0707A078DE"));
	CPPUNIT_ASSERT(c == mpz_class("0x90A81B3A344E8F6707A8845B5277FE82EA9250E6"));
	CPPUNIT_ASSERT(e_hat == mpz_class("0xBBB5ABB7452E6E1A92DC2226E20E87770D63ED25FE4C98954999527F9382BAAE25BF05D731A62199B02EB23D95"));
	CPPUNIT_ASSERT(v_prime_hat == mpz_class("0x0D6D04955AC35F1A2D026E533D5B1100C160309361AFB8A7C43A141DB70230B8062B741B72813155B7F9B4627C2404777F01AF6DBBFD70DBC727E99FCA59AC8CFFA057067E1B7580E2C5280A0975AC1CB08FC6EF440051112353482160110D770726CC1DA4AACA26592D76208DDA8C045A7A85FEA1520B7853AB54BBDD2224DE3CABE5E68F257B8937B831334EBA074326010D188361B8DC452B32398CF4AAA2AF6FC256352BE684726001DA6D1A4479365096993F929D0BA2C65C658ACF511561A72F7AA2BC54D835D3378A24A483C6C603AB65DA5161BA153E5AED11F0383034260FC35A55B5"));
	
	// Check ZKP values for hidden attributes
	CPPUNIT_ASSERT(a_i_hat.size() == 4);
	
	CPPUNIT_ASSERT(a_i_hat[0] == mpz_class("0x7622FFA28514B79650D9F25B0E15E89E2F4D4DC1683EC494539F390E17294A33A8C0084CCB2FCD7CEEFAD1B3FF8E59A1B54D15C4B85888CED98016882AE9")); // ZKP value for s
	CPPUNIT_ASSERT(a_i_hat[1] == mpz_class("0xE5B5C4B03E78F8C46D637265E57822CD57F70994361CD2BEDF8127FF1092BD3821038A1FE732906DD42085CB71ACC52F944812C439A97CFE10A9EA572FF8")); // ZKP value for a1
	CPPUNIT_ASSERT(a_i_hat[2] == mpz_class("0xF1DB7871B669CE64D0C75F91ECFBC97C6E8AEE0B9CAE90684D4B800F1B2C650D70559F962572C1434628E276C7F9D0B2247ADA1D1097A58A3DFD95A3CD1D")); // ZKP value for a2
	CPPUNIT_ASSERT(a_i_hat[3] == mpz_class("0x2230F071F1883E51265E06380C4A59360C35077C4B7B98E33090FA437A23C78FAC7C808CF3D40AE1E5E116D61D535495306E43E17CAE4E709B3246E05E8A")); // ZKP value for a4
	
	// Check revealed attributes
	CPPUNIT_ASSERT(a_i.size() == 1);
	
	CPPUNIT_ASSERT(a_i[0]->rep() == m3.rep());
}
Example #11
0
void Colors::parseArgs(int argc, char *argv[])
{
    // some arguments should be processed before
    // others. Handle them now:
    for (int i=1; i<argc; i++){
        QString s(argv[i]);
        if (s == "-verbose")
            Colors::verbose = true;
    }

    Colors::detectSystemResources();

    // Handle the rest of the arguments. They may
    // override attributes already set:
    for (int i=1; i<argc; i++){
        QString s(argv[i]);
        if (s == "-opengl")
            Colors::openGlRendering = true;
        else if (s == "-software")
            Colors::softwareRendering = true;
        else if (s == "-no-opengl") // support old style
            Colors::softwareRendering = true;
        else if (s == "-no-ticker") // support old style
            Colors::noTicker = true;
        else if (s.startsWith("-ticker"))
            Colors::noTicker = !bool(parseFloat(s, "-ticker"));
        else if (s == "-no-animations")
            Colors::noAnimations = true; // support old style
        else if (s.startsWith("-animations"))
            Colors::noAnimations = !bool(parseFloat(s, "-animations"));
        else if (s == "-no-adapt")
            Colors::noAdapt = true;
        else if (s == "-low")
            Colors::setLowSettings();
        else if (s == "-no-rescale")
            Colors::noRescale = true;
        else if (s == "-use-pixmaps")
            Colors::usePixmaps = true;
        else if (s == "-fullscreen")
            Colors::fullscreen = true;
        else if (s == "-show-br")
            Colors::showBoundingRect = true;
        else if (s == "-show-fps")
            Colors::showFps = true;
        else if (s == "-no-blending")
            Colors::noBlending = true;
        else if (s == "-no-sync")
            Colors::noScreenSync = true;
        else if (s.startsWith("-menu"))
            Colors::menuCount = int(parseFloat(s, "-menu"));
        else if (s.startsWith("-use-timer-update"))
            Colors::noTimerUpdate = !bool(parseFloat(s, "-use-timer-update"));
        else if (s.startsWith("-pause"))
            Colors::pause = bool(parseFloat(s, "-pause"));
        else if (s == "-no-ticker-morph")
            Colors::noTickerMorph = true;
        else if (s == "-use-window-mask")
            Colors::noWindowMask = false;
        else if (s == "-use-loop")
            Colors::useLoop = true;
        else if (s == "-use-8bit")
            Colors::useEightBitPalette = true;
        else if (s.startsWith("-8bit"))
            Colors::useEightBitPalette = bool(parseFloat(s, "-8bit"));
        else if (s == "-use-balls")
            Colors::useButtonBalls = true;
        else if (s.startsWith("-ticker-letters"))
            Colors::tickerLetterCount = int(parseFloat(s, "-ticker-letters"));
        else if (s.startsWith("-ticker-text"))
            Colors::tickerText = parseText(s, "-ticker-text");
        else if (s.startsWith("-ticker-speed"))
            Colors::tickerMoveSpeed = parseFloat(s, "-ticker-speed");
        else if (s.startsWith("-ticker-morph-speed"))
            Colors::tickerMorphSpeed = parseFloat(s, "-ticker-morph-speed");
        else if (s.startsWith("-animation-speed"))
            Colors::animSpeed = parseFloat(s, "-animation-speed");
        else if (s.startsWith("-fps"))
            Colors::fps = int(parseFloat(s, "-fps"));
        else if (s.startsWith("-h") || s.startsWith("-help")){
            QMessageBox::warning(0, "Arguments",
                                 QString("Usage: qtdemo [-verbose] [-no-adapt] [-opengl] [-software] [-fullscreen] [-ticker[0|1]] ")
                                 + "[-animations[0|1]] [-no-blending] [-no-sync] [-use-timer-update[0|1]] [-pause[0|1]]  "
                                 + "[-use-window-mask] [-no-rescale] "
                                 + "[-use-pixmaps] [-show-fps] [-show-br] [-8bit[0|1]] [-menu<int>] [-use-loop] [-use-balls] "
                                 + "[-animation-speed<float>] [-fps<int>] "
                                 + "[-low] [-ticker-letters<int>] [-ticker-speed<float>] [-no-ticker-morph] "
                                 + "[-ticker-morph-speed<float>] [-ticker-text<string>]");
            exit(0);
        } else if (s == "-verbose") {
            // this option was already handled above
        } else{
            QMessageBox::warning(0, "QtDemo", QString("Unrecognized argument:\n") + s);
            exit(0);
        }
    }

    Colors::postConfigure();
}
    void StripedSetHdrTest::Refinable_slist()
    {
        CPPUNIT_MESSAGE( "cmp")   ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::compare< cmp<item> >
        >   set_cmp ;
        test_striped2< set_cmp >()    ;

        CPPUNIT_MESSAGE( "less")   ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::less< less<item> >
        >   set_less ;
        test_striped2< set_less >()    ;

        CPPUNIT_MESSAGE( "cmpmix")   ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::compare< cmp<item> >
            , co::less< less<item> >
        >   set_cmpmix ;
        test_striped2< set_cmpmix >()    ;

        // Spinlock as lock policy
        CPPUNIT_MESSAGE( "spinlock")    ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
            , co::hash< hash_int >
            , co::less< less<item> >
        >   set_spin ;
        test_striped2< set_spin >()    ;

        // Resizing policy
        CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)")   ;
        {
            typedef cc::StripedSet< sequence_t
                ,co::mutex_policy< cc::striped_set::refinable<> >
                , co::hash< hash_int >
                , co::less< less<item> >
                , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
            >   set_less_resizing_lf ;
            set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(8)) ;
            test_striped_with(s)    ;
        }

        CPPUNIT_MESSAGE( "load_factor_resizing<4>")    ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::less< less<item> >
            , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
        >   set_less_resizing_lf16 ;
        test_striped2< set_less_resizing_lf16 >()    ;

        CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)")    ;
        {
            typedef cc::StripedSet< sequence_t
                ,co::mutex_policy< cc::striped_set::refinable<> >
                , co::hash< hash_int >
                , co::less< less<item> >
                , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
            >   set_less_resizing_sbt ;
            set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(8)) ;
            test_striped_with(s)    ;
        }

        CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>")    ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::less< less<item> >
            , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
        >   set_less_resizing_sbt16 ;
        test_striped2< set_less_resizing_sbt16 >()    ;


        // Copy policy
        CPPUNIT_MESSAGE( "copy_item")    ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::compare< cmp<item> >
            , co::copy_policy< cc::striped_set::copy_item >
        >   set_copy_item ;
        test_striped2< set_copy_item >()    ;

        CPPUNIT_MESSAGE( "swap_item")    ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::compare< cmp<item> >
            , co::copy_policy< cc::striped_set::swap_item >
        >   set_swap_item ;
        test_striped2< set_swap_item >()    ;

        CPPUNIT_MESSAGE( "move_item")    ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::compare< cmp<item> >
            , co::copy_policy< cc::striped_set::move_item >
        >   set_move_item ;
        test_striped2< set_move_item >()    ;

        CPPUNIT_MESSAGE( "special copy policy") ;
        typedef cc::StripedSet< sequence_t
            ,co::mutex_policy< cc::striped_set::refinable<> >
            , co::hash< hash_int >
            , co::compare< cmp<item> >
            , co::copy_policy< my_copy_policy >
        >   set_special_copy_item ;
        test_striped2< set_special_copy_item >()    ;
    }
Example #13
0
void EditStyle::setValues()
      {
      staffUpperBorder->setValue(lstyle.valueS(ST_staffUpperBorder).val());
      staffLowerBorder->setValue(lstyle.valueS(ST_staffLowerBorder).val());
      staffDistance->setValue(lstyle.valueS(ST_staffDistance).val());
      akkoladeDistance->setValue(lstyle.valueS(ST_akkoladeDistance).val());
      minSystemDistance->setValue(lstyle.valueS(ST_minSystemDistance).val());
      maxSystemDistance->setValue(lstyle.valueS(ST_maxSystemDistance).val());
      lyricsDistance->setValue(lstyle.valueS(ST_lyricsDistance).val());
      lyricsMinBottomDistance->setValue(lstyle.valueS(ST_lyricsMinBottomDistance).val());
      lyricsLineHeight->setValue(lstyle.value(ST_lyricsLineHeight).toDouble() * 100.0);
      systemFrameDistance->setValue(lstyle.valueS(ST_systemFrameDistance).val());
      frameSystemDistance->setValue(lstyle.valueS(ST_frameSystemDistance).val());
      minMeasureWidth_2->setValue(lstyle.valueS(ST_minMeasureWidth).val());

      barWidth->setValue(lstyle.valueS(ST_barWidth).val());
      endBarWidth->setValue(lstyle.valueS(ST_endBarWidth).val());
      endBarDistance->setValue(lstyle.valueS(ST_endBarDistance).val());
      doubleBarWidth->setValue(lstyle.valueS(ST_doubleBarWidth).val());
      doubleBarDistance->setValue(lstyle.valueS(ST_doubleBarDistance).val());

      showRepeatBarTips->setChecked(lstyle.valueB(ST_repeatBarTips));
      showStartBarlineSingle->setChecked(lstyle.valueB(ST_startBarlineSingle));
      showStartBarlineMultiple->setChecked(lstyle.valueB(ST_startBarlineMultiple));

      measureSpacing->setValue(lstyle.value(ST_measureSpacing).toDouble());
      minNoteDistance->setValue(lstyle.valueS(ST_minNoteDistance).val());
      barNoteDistance->setValue(lstyle.valueS(ST_barNoteDistance).val());
      noteBarDistance->setValue(lstyle.valueS(ST_noteBarDistance).val());

      showMeasureNumber->setChecked(lstyle.valueB(ST_showMeasureNumber));
      showFirstMeasureNumber->setChecked(lstyle.valueB(ST_showMeasureNumberOne));
      intervalMeasureNumber->setValue(lstyle.valueI(ST_measureNumberInterval));
      showIntervalMeasureNumber->setChecked(!lstyle.valueB(ST_measureNumberSystem));
      showAllStaffsMeasureNumber->setChecked(lstyle.valueB(ST_measureNumberAllStaffs));
      showEverySystemMeasureNumber->setChecked(lstyle.valueB(ST_measureNumberSystem));

      clefLeftMargin->setValue(lstyle.valueS(ST_clefLeftMargin).val());
      keysigLeftMargin->setValue(lstyle.valueS(ST_keysigLeftMargin).val());
      timesigLeftMargin->setValue(lstyle.valueS(ST_timesigLeftMargin).val());
      clefKeyRightMargin->setValue(lstyle.valueS(ST_clefKeyRightMargin).val());
      clefBarlineDistance->setValue(lstyle.valueS(ST_clefBarlineDistance).val());
//      beginRepeatLeftMargin->setValue(lstyle.valueS(ST_beginRepeatLeftMargin).val());
      staffLineWidth->setValue(lstyle.valueS(ST_staffLineWidth).val());

      beamWidth->setValue(lstyle.valueS(ST_beamWidth).val());
      beamDistance->setValue(lstyle.value(ST_beamDistance).toDouble());
      beamMinLen->setValue(lstyle.valueS(ST_beamMinLen).val());
      beamMinSlope->setValue(lstyle.value(ST_beamMinSlope).toDouble());
      beamMaxSlope->setValue(lstyle.value(ST_beamMaxSlope).toDouble());

      graceNoteSize->setValue(lstyle.value(ST_graceNoteMag).toDouble() * 100.0);
      smallStaffSize->setValue(lstyle.value(ST_smallStaffMag).toDouble() * 100.0);
      smallNoteSize->setValue(lstyle.value(ST_smallNoteMag).toDouble() * 100.0);
      smallClefSize->setValue(lstyle.value(ST_smallClefMag).toDouble() * 100.0);
//      pageFillThreshold->setValue(lstyle.value(ST_pageFillLimit).toDouble() * 100.0);
      lastSystemFillThreshold->setValue(lstyle.value(ST_lastSystemFillLimit).toDouble() * 100.0);

      hairpinY->setValue(lstyle.valueS(ST_hairpinY).val());
      hairpinLineWidth->setValue(lstyle.valueS(ST_hairpinWidth).val());
      hairpinHeight->setValue(lstyle.valueS(ST_hairpinHeight).val());
      hairpinContinueHeight->setValue(lstyle.valueS(ST_hairpinContHeight).val());

      genClef->setChecked(lstyle.valueB(ST_genClef));
      genKeysig->setChecked(lstyle.valueB(ST_genKeysig));
      genTimesig->setChecked(lstyle.valueB(ST_genTimesig));
      genCourtesyTimesig->setChecked(lstyle.valueB(ST_genCourtesyTimesig));
      genCourtesyKeysig->setChecked(lstyle.valueB(ST_genCourtesyKeysig));
      genCourtesyClef->setChecked(lstyle.valueB(ST_genCourtesyClef));

      QString s(lstyle.valueSt(ST_chordDescriptionFile));
      chordDescriptionFile->setText(s);
      chordsXmlFile->setChecked(lstyle.valueB(ST_chordsXmlFile));
      QString cstyle(lstyle.valueSt(ST_chordStyle));
      if (cstyle == "std") {
            chordsStandard->setChecked(true);
            chordDescriptionGroup->setEnabled(false);
            }
      else if (cstyle == "jazz") {
            chordsJazz->setChecked(true);
            chordDescriptionGroup->setEnabled(false);
            }
      else {
            chordsCustom->setChecked(true);
            chordDescriptionGroup->setEnabled(true);
            }
      useGermanNoteNames->setChecked(lstyle.valueB(ST_useGermanNoteNames));
      concertPitch->setChecked(lstyle.valueB(ST_concertPitch));

      multiMeasureRests->setChecked(lstyle.valueB(ST_createMultiMeasureRests));
      minEmptyMeasures->setValue(lstyle.valueI(ST_minEmptyMeasures));
      minMeasureWidth->setValue(lstyle.valueS(ST_minMMRestWidth).val());
      hideEmptyStaves->setChecked(lstyle.valueB(ST_hideEmptyStaves));
      dontHideStavesInFirstSystem->setChecked(lstyle.valueB(ST_dontHideStavesInFirstSystem));
      dontHideStavesInFirstSystem->setEnabled(hideEmptyStaves->isChecked());

      accidentalNoteDistance->setValue(lstyle.valueS(ST_accidentalNoteDistance).val());
      accidentalDistance->setValue(lstyle.valueS(ST_accidentalDistance).val());
      dotMag->setValue(lstyle.value(ST_dotMag).toDouble() * 100.0);
      noteDotDistance->setValue(lstyle.valueS(ST_dotNoteDistance).val());
      dotDotDistance->setValue(lstyle.valueS(ST_dotDotDistance).val());
      stemWidth->setValue(lstyle.valueS(ST_stemWidth).val());
      ledgerLineWidth->setValue(lstyle.valueS(ST_ledgerLineWidth).val());
      ledgerLineLength->setValue(lstyle.valueS(ST_ledgerLineLength).val());

      bracketWidth->setValue(lstyle.valueS(ST_bracketWidth).val());
      bracketDistance->setValue(lstyle.valueS(ST_bracketDistance).val());
      akkoladeWidth->setValue(lstyle.valueS(ST_akkoladeWidth).val());
      akkoladeBarDistance->setValue(lstyle.valueS(ST_akkoladeBarDistance).val());

      propertyDistanceHead->setValue(lstyle.valueS(ST_propertyDistanceHead).val());
      propertyDistanceStem->setValue(lstyle.valueS(ST_propertyDistanceStem).val());
      propertyDistance->setValue(lstyle.valueS(ST_propertyDistance).val());

      voice1Up->setChecked(lstyle.value(ST_stemDir1).toDirection() == MScore::UP);
      voice2Up->setChecked(lstyle.value(ST_stemDir2).toDirection() == MScore::UP);
      voice3Up->setChecked(lstyle.value(ST_stemDir3).toDirection() == MScore::UP);
      voice4Up->setChecked(lstyle.value(ST_stemDir4).toDirection() == MScore::UP);

      voice1Down->setChecked(lstyle.value(ST_stemDir1).toDirection() != MScore::UP);
      voice2Down->setChecked(lstyle.value(ST_stemDir2).toDirection() != MScore::UP);
      voice3Down->setChecked(lstyle.value(ST_stemDir3).toDirection() != MScore::UP);
      voice4Down->setChecked(lstyle.value(ST_stemDir4).toDirection() != MScore::UP);

      shortenStem->setChecked(lstyle.valueB(ST_shortenStem));
      shortStemProgression->setValue(lstyle.valueS(ST_shortStemProgression).val());
      shortestStem->setValue(lstyle.valueS(ST_shortestStem).val());
      arpeggioNoteDistance->setValue(lstyle.valueS(ST_ArpeggioNoteDistance).val());
      arpeggioLineWidth->setValue(lstyle.valueS(ST_ArpeggioLineWidth).val());
      arpeggioHookLen->setValue(lstyle.valueS(ST_ArpeggioHookLen).val());

      // figured bass
      for(int i = 0; i < comboFBFont->count(); i++)
            if(comboFBFont->itemText(i) == lstyle.valueSt(ST_figuredBassFontFamily)) {
                  comboFBFont->setCurrentIndex(i);
                  break;
            }
      doubleSpinFBSize->setValue(lstyle.value(ST_figuredBassFontSize).toDouble());
      doubleSpinFBVertPos->setValue(lstyle.value(ST_figuredBassYOffset).toDouble());
      spinFBLineHeight->setValue(lstyle.valueS(ST_figuredBassLineHeight).val() * 100.0);
      radioFBTop->setChecked(lstyle.valueI(ST_figuredBassAlignment) == 0);
      radioFBBottom->setChecked(lstyle.valueI(ST_figuredBassAlignment) == 1);
      radioFBModern->setChecked(lstyle.valueI(ST_figuredBassStyle) == 0);
      radioFBHistoric->setChecked(lstyle.valueI(ST_figuredBassStyle) == 1);

      for (int i = 0; i < ARTICULATIONS; ++i) {
            QComboBox* cb = static_cast<QComboBox*>(articulationTable->cellWidget(i, 1));
            if (cb == 0)
                  continue;
            int st  = lstyle.articulationAnchor(i);
            int idx = 0;
            if (st == A_TOP_STAFF)
                  idx = 0;
            else if (st == A_BOTTOM_STAFF)
                  idx = 1;
            else if (st == A_CHORD)
                  idx = 2;
            cb->setCurrentIndex(idx);
            }
//      warnPitchRange->setChecked(lstyleB[ST_warnPitchRange]);

      fixNumberMeasures->setValue(lstyle.valueI(ST_FixMeasureNumbers));
      fixMeasureWidth->setChecked(lstyle.valueB(ST_FixMeasureWidth));

      slurEndLineWidth->setValue(lstyle.valueS(ST_SlurEndWidth).val());
      slurMidLineWidth->setValue(lstyle.valueS(ST_SlurMidWidth).val());
      slurDottedLineWidth->setValue(lstyle.valueS(ST_SlurDottedWidth).val());
      slurBow->setValue(lstyle.valueS(ST_SlurBow).val());
      musicalSymbolFont->setCurrentIndex(lstyle.valueSt(ST_MusicalSymbolFont) == "Emmentaler" ? 0 : 1);

      showHeader->setChecked(lstyle.valueB(ST_showHeader));
      headerStyled->setChecked(lstyle.valueB(ST_headerStyled));
      showHeaderFirstPage->setChecked(lstyle.valueB(ST_headerFirstPage));
      headerOddEven->setChecked(lstyle.valueB(ST_headerOddEven));
      if (headerStyled->isChecked()) {
            evenHeaderL->setPlainText(lstyle.valueSt(ST_evenHeaderL));
            evenHeaderC->setPlainText(lstyle.valueSt(ST_evenHeaderC));
            evenHeaderR->setPlainText(lstyle.valueSt(ST_evenHeaderR));
            oddHeaderL->setPlainText(lstyle.valueSt(ST_oddHeaderL));
            oddHeaderC->setPlainText(lstyle.valueSt(ST_oddHeaderC));
            oddHeaderR->setPlainText(lstyle.valueSt(ST_oddHeaderR));
            }
      else {
            evenHeaderL->setHtml(lstyle.valueSt(ST_evenHeaderL));
            evenHeaderC->setHtml(lstyle.valueSt(ST_evenHeaderC));
            evenHeaderR->setHtml(lstyle.valueSt(ST_evenHeaderR));
            oddHeaderL->setHtml(lstyle.valueSt(ST_oddHeaderL));
            oddHeaderC->setHtml(lstyle.valueSt(ST_oddHeaderC));
            oddHeaderR->setHtml(lstyle.valueSt(ST_oddHeaderR));
            }

      showFooter->setChecked(lstyle.valueB(ST_showFooter));
      footerStyled->setChecked(lstyle.valueB(ST_footerStyled));
      showFooterFirstPage->setChecked(lstyle.valueB(ST_footerFirstPage));
      footerOddEven->setChecked(lstyle.valueB(ST_footerOddEven));
      if (footerStyled->isChecked()) {
            evenFooterL->setPlainText(lstyle.valueSt(ST_evenFooterL));
            evenFooterC->setPlainText(lstyle.valueSt(ST_evenFooterC));
            evenFooterR->setPlainText(lstyle.valueSt(ST_evenFooterR));
            oddFooterL->setPlainText(lstyle.valueSt(ST_oddFooterL));
            oddFooterC->setPlainText(lstyle.valueSt(ST_oddFooterC));
            oddFooterR->setPlainText(lstyle.valueSt(ST_oddFooterR));
            }
      else {
            evenFooterL->setHtml(lstyle.valueSt(ST_evenFooterL));
            evenFooterC->setHtml(lstyle.valueSt(ST_evenFooterC));
            evenFooterR->setHtml(lstyle.valueSt(ST_evenFooterR));
            oddFooterL->setHtml(lstyle.valueSt(ST_oddFooterL));
            oddFooterC->setHtml(lstyle.valueSt(ST_oddFooterC));
            oddFooterR->setHtml(lstyle.valueSt(ST_oddFooterR));
            }

      voltaY->setValue(lstyle.valueS(ST_voltaY).val());
      voltaHook->setValue(lstyle.valueS(ST_voltaHook).val());
      voltaLineWidth->setValue(lstyle.valueS(ST_voltaLineWidth).val());

      ottavaY->setValue(lstyle.valueS(ST_ottavaY).val());
      ottavaHook->setValue(lstyle.valueS(ST_ottavaHook).val());
      ottavaLineWidth->setValue(lstyle.valueS(ST_ottavaLineWidth).val());

      trillY->setValue(lstyle.valueS(ST_trillY).val());
      harmonyY->setValue(lstyle.valueS(ST_harmonyY).val());
      harmonyFretDist->setValue(lstyle.valueS(ST_harmonyFretDist).val());
      minHarmonyDistance->setValue(lstyle.valueS(ST_minHarmonyDistance).val());
      pedalY->setValue(lstyle.valueS(ST_pedalY).val());

      clefTab1->setChecked(lstyle.valueI(ST_tabClef) == CLEF_TAB);
      clefTab2->setChecked(lstyle.valueI(ST_tabClef) == CLEF_TAB2);

      crossMeasureValues->setChecked(lstyle.valueB(ST_crossMeasureValues));
      radioKeySigNatNone->setChecked  (lstyle.valueB(ST_keySigNaturals) == NAT_NONE);
      radioKeySigNatBefore->setChecked(lstyle.valueB(ST_keySigNaturals) == NAT_BEFORE);
      radioKeySigNatAfter->setChecked (lstyle.valueB(ST_keySigNaturals) == NAT_AFTER);
      }
Example #14
0
void NoVoHT::merge(){
   char buf[300];
   char sec[300];
	sem_wait(&map_lock);
   sem_wait(&write_lock);
   fflush(dbfile);
   rewind(dbfile);
   while (readTabString(dbfile,buf) != NULL){
      if(buf[0] == '~'){
         readTabString(dbfile, sec);
         char * pos;
         pos = strtok(sec, ",");
         while (pos != NULL) {
            fseek(swapFile, (off_t) atoi(pos), SEEK_SET);
            char test[300];
            readTabString(swapFile,test);
            if (strcmp(test,(buf+1)) == 0){
               fseek(swapFile, (off_t) atoi(pos), SEEK_SET);
               fputc('~',swapFile);
            }
            pos = strtok(NULL, ",");
         }
      }
      else{
         //while (map_lock) {}
         //map_lock = true;
         //sem_wait(&map_lock);
         fseek(swapFile, 0, SEEK_END);
         string s(buf);
         readTabString(dbfile,sec);
         kvpair* p = kvpairs[hash(s)%size];
         while (p != NULL){
            if (p->key.compare(s) == 0){
               destroyFposList(p->positions);
               p->positions = new fpos_list;
               p->positions->next = NULL;
               fgetpos(swapFile, &(p->positions->pos));
               fprintf(swapFile, "%s\t%s\t", p->key.c_str(), p->val.c_str());
               printf("%s\t%s\t", p->key.c_str(), p->val.c_str());
               p->diff = false;
               break;
            }
            else
               p = p->next;
         }
         //map_lock = false;
         //sem_post(&map_lock);
      }
   }
	fclose(dbfile);
   fclose(swapFile);
   rename(".novoht.swp", filename.c_str());
   dbfile = fopen(filename.c_str(), "r+");
   //remove(".novoht.mrg");
	int rmrc = unlink(".novoht.mrg");
   if (rmrc) {
      perror("Error deleting merge file");
   }
   rewriting = false;
	sem_post(&map_lock);
   sem_post(&write_lock);
}
Example #15
0
QString quote(QString key, int value) {
    QString ss;
    QTextStream s(&ss);
    s << quote(key) << ":" << quote(value);
    return *s.string();
}
Example #16
0
void cveGetStructuringElement(cv::Mat* mat, int shape, emgu::size* ksize, CvPoint* anchor)
{
   cv::Size s(ksize->width, ksize->height);
   cv::Mat res = cv::getStructuringElement(shape, s, *anchor);
   cv::swap(*mat, res);
}
Example #17
0
QString quote(T toQuote) {
    QString ss;
    QTextStream s(&ss);
    s << dq << toQuote << dq;
    return *s.string();
}
Example #18
0
void cvePyrDown(cv::_InputArray* src, cv::_OutputArray* dst, emgu::size* size, int borderType)
{
   cv::Size s(size->width, size->height);
   cv::pyrDown(*src, *dst, s, borderType);
}
const string CSyncServer::GetClientDiff(int id)
{
	ostringstream s("");

	if (id == lastDiffClient) {
		// For us, we need to know which other clients caused our units to be disabled
		
		// This should not need to be called, but still..
		if (lastWasRemove) {
			s << id << " " << lastWasRemove << " ";
		}
		else {
			// Go through the difflist for each client
			for (map<int, unitlist_t>::iterator client = clientLists.begin(); client != clientLists.end(); ++client) {
				int count = 0;
				ostringstream us("");

				for (map<string, MissingList>::iterator i = curDiff.begin(); i != curDiff.end(); ++i) {
					set<int>::iterator clientId = i->second.clients.find(client->first);

					//If found, add the name of the disabled unit
					if (clientId != i->second.clients.end()) {
						us << i->first << " ";
						count++;
					}
				}

				// Only generate the list if needed
				if (count > 0) {
					s << client->first << " " << lastWasRemove << " " << count << " ";
					s << us.str();
				}
			}
		}

	}
	else {

		// For the others, it is always the new guy's fault
		s << lastDiffClient << " ";

		//and of what they are guilt
		s << lastWasRemove << " ";

		//If remove, we are done now
		if (lastWasRemove)
			return s.str();

		ostringstream us("");
		int count = 0;

		for (map<string, MissingList>::iterator i = curDiff.begin(); i != curDiff.end(); ++i) {
			set<int>::iterator client = i->second.clients.find(id);

			//If found, add the name of the disabled unit
			if (client != i->second.clients.end()) {
				us << i->first << " ";
				count++;
			}
		}

		s << count << " ";
		s << us.str();
	}

	return s.str();
}
Example #20
0
/* number of bits in a word */
#define NUMBITS	   sizeof(long)*8

/* get the integral form of a floating point number */
#define v(x)	   *(long *) &(x)

/* get the sign bit of an integer as a value 0 or 1 */
#define s(x)	   (((unsigned long)(x)) >> (NUMBITS-1))

/* get the absolute value of a floating point number in integral form */
#define a(x)	   ((x) & ~(1 << (NUMBITS-1)))

	iw = v(w);
	abs_w = a(iw);
	outcode = s(iw);	  /* 0 or 1 per w's sign */

	ix = v(x);
	diff = s(abs_w - a(ix));
	t = s(ix) + 1;
	outcode |= diff << t;	  /* 0, 2, or 4 or'd with outcode */

	iy = v(y);
	diff = s(abs_w - a(iy));
	t = s(iy) + 3;
	outcode |= diff << t;	  /* 0, 8, or 16 or'd with outcode */

	iz = v(z);
	diff = s(abs_w - a(iz));
	t = s(iz) + 5;
	outcode |= diff << t;	  /* 0, 32, or 64 or'd with outcode */
Example #21
0
void CSimpleFile::WriteStringNull(CString Str)
{
	CT2CA s(Str);
	Write(s, strlen(s.m_psz) + 1);
}
Example #22
0
string toLower(const string & str)
{
	string s(str);
	makeLower(s);
	return s;
}
Example #23
0
Scraper::Scraper(const char* scriptDir)
	: scriptPath(scriptDir), imageDataPath(scriptDir)
{
	imageDataPath.append("\\ImageFiles.data");

	// Read image data
	// Open file
	ifstream f (imageDataPath);
    if (!f.is_open())
	{
		char err[500];
		strerror_s(err, 500, errno);

		string s("Error opening " + imageDataPath + ": " + err);

		logger->WriteLog(s);
		return;
	}

    // Read the file
	ImageGroup newImageGroup;

	string line("");
    while (getline(f, line))
	{
		vector<string> elems;
		split(line, ' ', elems);

		// Comment
		if (line.empty() || elems[0].find("//") != string::npos)
		{
			continue;
		}

		// Find image class
		bool foundImageType = false;
		for (int i = 0; i < imageClassCount; i++)
		{
			if (elems[0].find(imageClasses[i])!=string::npos)
			{
				newImageGroup.iType = (imageType) i;
				foundImageType = true;
				break;
			}
		}

		// Found the right group?
		if (!foundImageType)
		{
			string s("Image group " + elems[0] + " is unrecognized");
			logger->WriteLog(s);
		}

		else
		{
			newImageGroup.imagePaths.clear();
			newImageGroup.mats.clear();
			newImageGroup.imagePaths.resize(elems.size()-1);
			newImageGroup.mats.resize(elems.size()-1);
			imageGroups.push_back(newImageGroup);
			int lastGroup = imageGroups.size()-1;

			// Create a Mat for each path in the group
			for (int i = 1; i < (int) elems.size(); i++)
			{
				imageGroups[lastGroup].imagePaths[i-1] = elems[i];
				
				string path(scriptPath + "\\Images\\" + elems[i]);
				wstring ws = utf8_decode(path);
				imageGroups[lastGroup].mats[i-1] = CGdiPlus::ImgRead(ws.c_str());
			}

			char s[500];
			sprintf_s(s, 500, "Loaded %d images for image group %s.", elems.size()-1, elems[0].c_str());
			logger->WriteLog(s);
		}
	}

	// Handle read error
    if (f.bad())
	{
		char err[500];
		strerror_s(err, 500, errno);

		string s("Error reading " + imageDataPath + ": " + err);

		logger->WriteLog(s);
	}

	f.close();

	logger->WriteLog("Images loaded");
}
Example #24
0
BOOL CSettingsAdvanced::OnInitDialog()
{
	ISettingsPropPage::OnInitDialog();

	m_ListCtrl.DeleteAllItems();
	int c = ((CHeaderCtrl*)(m_ListCtrl.GetDlgItem(0)))->GetItemCount() - 1;
	while (c >= 0)
		m_ListCtrl.DeleteColumn(c--);

	SetWindowTheme(m_ListCtrl.GetSafeHwnd(), L"Explorer", NULL);

	CString temp;
	temp.LoadString(IDS_SETTINGS_CONF_VALUECOL);
	m_ListCtrl.InsertColumn(0, temp);
	temp.LoadString(IDS_SETTINGS_CONF_NAMECOL);
	m_ListCtrl.InsertColumn(1, temp);

	m_ListCtrl.SetRedraw(FALSE);

	int i = 0;
	while (settings[i].type != SettingTypeNone)
	{
		m_ListCtrl.InsertItem(i, settings[i].sName);
		m_ListCtrl.SetItemText(i, 1, settings[i].sName);
		switch (settings[i].type)
		{
		case SettingTypeBoolean:
			{
				CRegDWORD s(_T("Software\\TortoiseGit\\") + settings[i].sName, settings[i].def.b);
				m_ListCtrl.SetItemText(i, 0, DWORD(s) ?	_T("true") : _T("false"));
			}
			break;
		case SettingTypeNumber:
			{
				CRegDWORD s(_T("Software\\TortoiseGit\\") + settings[i].sName, settings[i].def.l);
				temp.Format(_T("%ld"), (DWORD)s);
				m_ListCtrl.SetItemText(i, 0, temp);
			}
			break;
		case SettingTypeString:
			{
				CRegString s(_T("Software\\TortoiseGit\\") + settings[i].sName, settings[i].def.s);
				m_ListCtrl.SetItemText(i, 0, CString(s));
			}
		}

		i++;
	}

	int mincol = 0;
	int maxcol = ((CHeaderCtrl*)(m_ListCtrl.GetDlgItem(0)))->GetItemCount() - 1;
	int col;
	for (col = mincol; col <= maxcol; col++)
	{
		m_ListCtrl.SetColumnWidth(col, LVSCW_AUTOSIZE_USEHEADER);
	}
	int arr[2] = {1,0};
	m_ListCtrl.SetColumnOrderArray(2, arr);
	m_ListCtrl.SetRedraw(TRUE);

	return TRUE;
}
/**
* Static identifier to determine if the netcdf file is a NAM forecast.
* Uses netcdf c api
*
* @param fileName netcdf filename
*
* @return true if the forecast is a NCEP Nam forecast
*/
bool ncepNamSurfInitialization::identify( std::string fileName )
{
    bool identified = true;

    //Acquire a lock to protect the non-thread safe netCDF library
#ifdef _OPENMP
    omp_guard netCDF_guard(netCDF_lock);
#endif

    int status, ncid, ndims, nvars, ngatts, unlimdimid;

    /*
     * Open the dataset
     */

    status = nc_open( fileName.c_str(), 0, &ncid );
    if ( status != NC_NOERR )
        identified = false;

    /*
     * If we can't get simple data from the file, return false
     */
    status = nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
    if ( status != NC_NOERR )
        identified = false;

    /*
     * Check the variable names, return false if any aren't found
     */
    int varid;
    std::vector<std::string> varList = getVariableList();
    for( unsigned int i = 0;i < varList.size();i++ ) {
        status = nc_inq_varid( ncid, varList[i].c_str(), &varid );
        if( status != NC_NOERR )
            identified = false;
    }

    /*
     * Check the global attributes for the following tag:
     * :Generating_Model = "MESO NAM Model""
     */
    size_t len;
    nc_type type;
    char* model;
    status = nc_inq_att( ncid, NC_GLOBAL, "Analysis_or_forecast_generating_process_identifier_defined_by_originating_centre", &type, &len );
    if( status != NC_NOERR )
        identified = false;
    else {
        model = new char[len + 1];
        status = nc_get_att_text( ncid, NC_GLOBAL, "Analysis_or_forecast_generating_process_identifier_defined_by_originating_centre", model );
        model[len] = '\0';
        std::string s( model );
        if( s.find( "MESO NAM Model" ) == s.npos ) {
            identified = false;
        }
        delete[] model;
    }

    /*
     * Check the global attributes for the following tag:
     * :location = "Proto fmrc:NAM_CONUS_12km-noaaport"
     */
    /*
    char* location;
    status = nc_inq_att( ncid, NC_GLOBAL, "location", &type, &len );
    if( status != NC_NOERR )
        identified = false;
    else
    {
        location = new char[len + 1];
        status = nc_get_att_text( ncid, NC_GLOBAL, "location", location );
        location[len] = '\0';
        std::string locationString( location );
        if( locationString != "Proto fmrc:NAM_CONUS_12km-noaaport" ) {
            identified = false;
        }
        delete [] location;
    }
    */
    status = nc_close( ncid );

    return identified;
}
Example #26
0
//----------------------------------------------------------------------------
//  Init
HRESULT CAnchoBackgroundAPI::Init(LPCTSTR lpszThisPath, LPCTSTR lpszRootURL, BSTR bsID, LPCTSTR lpszGUID, LPCTSTR lpszPath)
{
  // set our ID
  m_bsID = bsID;
  m_GUID = lpszGUID;

  m_sRootURL = lpszRootURL;

  CString sPath(lpszPath);

  // create logger window
  IF_FAILED_RET(CLogWindow::CreateLogWindow(&m_LogWindow.p));

  // create a magpie instance
#ifdef MAGPIE_REGISTERED
  IF_FAILED_RET(m_Magpie.CoCreateInstance(CLSID_MagpieApplication));
#else
  // Load magpie from the same path where this exe file is.
  CString s(lpszThisPath);
  s += _T("Magpie.dll");
  HMODULE hModMagpie = ::LoadLibrary(s);
  if (!hModMagpie)
  {
    return E_FAIL;
  }
  fnCreateMagpieInstance CreateMagpieInstance = (fnCreateMagpieInstance)::GetProcAddress(hModMagpie, "CreateMagpieInstance");
  if (!CreateMagpieInstance)
  {
    return E_FAIL;
  }
  IF_FAILED_RET(CreateMagpieInstance(&m_Magpie));
#endif
  // add a loader for scripts in the extension filesystem
  IF_FAILED_RET(m_Magpie->AddFilesystemScriptLoader((LPWSTR)(LPCWSTR)sPath));

  // add a loder for scripts in this exe file
  IF_FAILED_RET(m_Magpie->AddResourceScriptLoader((ULONG)_AtlModule.GetResourceInstance()));

  // advise logger
  IF_FAILED_RET(AtlAdvise(m_Magpie, (IUnknown*)(CAnchoAddonBackgroundLogger*)(this), DIID__IMagpieLoggerEvents, &m_dwMagpieSinkCookie));

  // load manifest
  CString sManifestFilename;
  sManifestFilename.Format(_T("%smanifest.json"), sPath);
  CAtlFile f;
  IF_FAILED_RET(f.Create(sManifestFilename, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING));
  ULONGLONG nLen = 0;
  IF_FAILED_RET(f.GetSize(nLen));
  // limit to 4gb
  if (nLen > 0x00000000ffffffff)
  {
    return E_OUTOFMEMORY;
  }
  DWORD dwLen = (DWORD)nLen;
  CStringA sManifest("exports.manifest = ");
  DWORD strLen = (DWORD)sManifest.GetLength();
  IF_FAILED_RET(f.Read(sManifest.GetBuffer(dwLen + strLen) + strLen, dwLen));
  sManifest.ReleaseBuffer(dwLen + strLen);
  sManifest += _T(';');
  IF_FAILED_RET(m_Magpie->RunScript(L"manifest", (LPWSTR)(LPCWSTR)CA2W(sManifest)));

  // set ourselfs in magpie as a global accessible object
  IF_FAILED_RET(m_Magpie->AddExtension((LPWSTR)s_AnchoGlobalAPIObjectName, (IAnchoBackgroundAPI*)this));

  // initialize Ancho API
  // api.js will do now additional initialization, like looking at the manifest
  // and creating a background page.
  IF_FAILED_RET(m_Magpie->Run((LPWSTR)s_AnchoMainAPIModuleID));

  return S_OK;
}
Example #27
0
    Status Database::dropCollection( TransactionExperiment* txn, const StringData& fullns ) {
        LOG(1) << "dropCollection: " << fullns << endl;
        massertNamespaceNotIndex( fullns, "dropCollection" );

        Collection* collection = getCollection( txn, fullns );
        if ( !collection ) {
            // collection doesn't exist
            return Status::OK();
        }

        {
            NamespaceString s( fullns );
            verify( s.db() == _name );

            if( s.isSystem() ) {
                if( s.coll() == "system.profile" ) {
                    if ( _profile != 0 )
                        return Status( ErrorCodes::IllegalOperation,
                                       "turn off profiling before dropping system.profile collection" );
                }
                else {
                    return Status( ErrorCodes::IllegalOperation, "can't drop system ns" );
                }
            }
        }

        BackgroundOperation::assertNoBgOpInProgForNs( fullns );

        audit::logDropCollection( currentClient.get(), fullns );

        try {
            Status s = collection->getIndexCatalog()->dropAllIndexes(txn, true);
            if ( !s.isOK() ) {
                warning() << "could not drop collection, trying to drop indexes"
                          << fullns << " because of " << s.toString();
                return s;
            }
        }
        catch( DBException& e ) {
            stringstream ss;
            ss << "drop: dropIndexes for collection failed. cause: " << e.what();
            ss << ". See http://dochub.mongodb.org/core/data-recovery";
            warning() << ss.str() << endl;
            return Status( ErrorCodes::InternalError, ss.str() );
        }

        verify( collection->_details->getTotalIndexCount() == 0 );
        LOG(1) << "\t dropIndexes done" << endl;

        Top::global.collectionDropped( fullns );

        Status s = _dropNS( txn, fullns );

        _clearCollectionCache( fullns ); // we want to do this always

        if ( !s.isOK() )
            return s;

        DEV {
            // check all index collection entries are gone
            string nstocheck = fullns.toString() + ".$";
            scoped_lock lk( _collectionLock );
            for ( CollectionMap::const_iterator i = _collections.begin();
                  i != _collections.end();
                  ++i ) {
                string temp = i->first;
                if ( temp.find( nstocheck ) != 0 )
                    continue;
                log() << "after drop, bad cache entries for: "
                      << fullns << " have " << temp;
                verify(0);
            }
        }

        return Status::OK();
    }
Example #28
0
QString cxnstring(int num) {
    QTextStream s(new QString(""));
    s << "connection-" << num;
    return *s.string();
}
Example #29
0
void CheckExternalScripts::configure(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response) {

	namespace po = boost::program_options;
	namespace pf = nscapi::protobuf::functions;
	po::variables_map vm;
	po::options_description desc;
	std::string arguments = "false";
	const std::string path = "/settings/external scripts/server";

	pf::settings_query q(get_id());
	q.get(path, "allow arguments", false);
	q.get(path, "allow nasty characters", false);


	get_core()->settings_query(q.request(), q.response());
	if (!q.validate_response()) {
		nscapi::protobuf::functions::set_response_bad(*response, q.get_response_error());
		return;
	}
	BOOST_FOREACH(const pf::settings_query::key_values &val, q.get_query_key_response()) {
		if (val.path == path && val.key && *val.key == "allow arguments" && val.get_bool())
			arguments = "true";
		else if (val.path == path && val.key && *val.key == "allow nasty characters" && val.get_bool())
			arguments = "safe";
	}
	desc.add_options()
		("help", "Show help.")

		("arguments", po::value<std::string>(&arguments)->default_value(arguments)->implicit_value("safe"), 
		"Allow arguments. false=don't allow, safe=allow non escape chars, all=allow all arguments.")

		;

	try {
		nscapi::program_options::basic_command_line_parser cmd(request);
		cmd.options(desc);

		po::parsed_options parsed = cmd.run();
		po::store(parsed, vm);
		po::notify(vm);
	} catch (const std::exception &e) {
		return nscapi::program_options::invalid_syntax(desc, request.command(), "Invalid command line: " + utf8::utf8_from_native(e.what()), *response);
	}

	if (vm.count("help")) {
		nscapi::protobuf::functions::set_response_good(*response, nscapi::program_options::help(desc));
		return;
	}
	std::stringstream result;

	nscapi::protobuf::functions::settings_query s(get_id());
	s.set(MAIN_MODULES_SECTION, "CheckExternalScripts", "enabled");
	if (arguments == "all" || arguments == "unsafe") {
		result << "UNSAFE Arguments are allowed." << std::endl;
		s.set(path, "allow arguments", "true");
		s.set(path, "allow nasty characters", "true");
	} else if (arguments == "safe" || arguments == "true") {
		result << "SAFE Arguments are allowed." << std::endl;
		s.set(path, "allow arguments", "true");
		s.set(path, "allow nasty characters", "false");
	} else {
		result << "Arguments are NOT allowed." << std::endl;
		s.set(path, "allow arguments", "false");
		s.set(path, "allow nasty characters", "false");
	}
	s.save();
	get_core()->settings_query(s.request(), s.response());
	if (!s.validate_response())
		nscapi::protobuf::functions::set_response_bad(*response, s.get_response_error());
	else
		nscapi::protobuf::functions::set_response_good(*response, result.str());
}
Example #30
0
void credgen_tests::test_credgen_irma_testvec()
{
	mpz_class n("0x88CC7BD5EAA39006A63D1DBA18BDAF00130725597A0A46F0BACCEF163952833BCBDD4070281CC042B4255488D0E260B4D48A31D94BCA67C854737D37890C7B21184A053CD579176681093AB0EF0B8DB94AFD1812A78E1E62AE942651BB909E6F5E5A2CEF6004946CCA3F66EC21CB9AC01FF9D3E88F19AC27FC77B1903F141049");
	mpz_class Z("0x3F7BAA7B26D110054A2F427939E61AC4E844139CEEBEA24E5C6FB417FFEB8F38272FBFEEC203DB43A2A498C49B7746B809461B3D1F514308EEB31F163C5B6FD5E41FFF1EB2C5987A79496161A56E595BC9271AAA65D2F6B72F561A78DD6115F5B706D92D276B95B1C90C49981FE79C23A19A2105032F9F621848BC57352AB2AC");
	mpz_class S("0x617DB25740673217DF74BDDC8D8AC1345B54B9AEA903451EC2C6EFBE994301F9CABB254D14E4A9FD2CD3FCC2C0EFC87803F0959C9550B2D2A2EE869BCD6C5DF7B9E1E24C18E0D2809812B056CE420A75494F9C09C3405B4550FD97D57B4930F75CD9C9CE0A820733CB7E6FC1EEAF299C3844C1C9077AC705B774D7A20E77BA30");
	std::vector<mpz_class> R;
	
	R.push_back(mpz_class("0x6B4D9D7D654E4B1285D4689E12D635D4AF85167460A3B47DB9E7B80A4D476DBEEC0B8960A4ACAECF25E18477B953F028BD71C6628DD2F047D9C0A6EE8F2BC7A8B34821C14B269DBD8A95DCCD5620B60F64B132E09643CFCE900A3045331207F794D4F7B4B0513486CB04F76D62D8B14B5F031A8AD9FFF3FAB8A68E74593C5D8B"));
	R.push_back(mpz_class("0x177CB93935BB62C52557A8DD43075AA6DCDD02E2A004C56A81153595849A476C515A1FAE9E596C22BE960D3E963ECFAC68F638EBF89642798CCAE946F2F179D30ABE0EDA9A44E15E9CD24B522F6134B06AC09F72F04614D42FDBDB36B09F60F7F8B1A570789D861B7DBD40427254F0336D0923E1876527525A09CDAB261EA7EE"));
	R.push_back(mpz_class("0x12ED9D5D9C9960BACE45B7471ED93572EA0B82C611120127701E4EF22A591CDC173136A468926103736A56713FEF3111FDE19E67CE632AB140A6FF6E09245AC3D6E022CD44A7CC36BCBE6B2189960D3D47513AB2610F27D272924A84154646027B73893D3EE8554767318942A8403F0CD2A41264814388BE4DF345E479EF52A8"));
	R.push_back(mpz_class("0x7AF1083437CDAC568FF1727D9C8AC4768A15912B03A8814839CF053C85696DF3A5681558F06BAD593F8A09C4B9C3805464935E0372CBD235B18686B540963EB9310F9907077E36EED0251D2CF1D2DDD6836CF793ED23D266080BF43C31CF3D304E2055EF44D454F477354664E1025B3F134ACE59272F07D0FD4995BDAACCDC0B"));
	R.push_back(mpz_class("0x614BF5243C26D62E8C7C9B0FAE9C57F44B05714894C3DCF583D9797C423C1635F2E4F1697E92771EB98CF36999448CEFC20CB6E10931DED3927DB0DFF56E18BD3A6096F2FF1BFF1A703F3CCE6F37D589B5626354DF0DB277EF73DA8A2C7347689B79130559FB94B6260C13D8DC7D264BA26953B906488B87CDC9DFD0BC69C551"));
	R.push_back(mpz_class("0x5CAE46A432BE9DB72F3B106E2104B68F361A9B3E7B06BBE3E52E60E69832618B941C952AA2C6EEFFC222311EBBAB922F7020D609D1435A8F3F941F4373E408BE5FEBAF471D05C1B91030789F7FEA450F61D6CB9A4DD8642253327E7EBF49C1600C2A075EC9B9DEC196DDBDC373C29D1AF5CEAD34FA6993B8CDD739D04EA0D253"));
	R.push_back(mpz_class("0x52E49FE8B12BFE9F12300EF5FBDE1800D4611A587E9F4763C11E3476BBA671BFD2E868436C9E8066F96958C897DD6D291567C0C490329793F35E925B77B304249EA6B30241F5D014E1C533EAC27AA9D9FCA7049D3A8D89058969FC2CD4DC63DF38740701D5E2B7299C49EC6F190DA19F4F6BC3834EC1AE145AF51AFEBA027EAA"));
	R.push_back(mpz_class("0x05AA7EE2AD981BEE4E3D4DF8F86414797A8A38706C84C9376D324070C908724BB89B224CB5ADE8CDDB0F65EBE9965F5C710C59704C88607E3C527D57A548E24904F4991383E5028535AE21D11D5BF87C3C5178E638DDF16E666EA31F286D6D1B3251E0B1470E621BEE94CDFA1D2E47A86FD2F900D5DDCB42080DAB583CBEEEDF"));
	R.push_back(mpz_class("0x73D3AB9008DC2BD65161A0D7BFC6C29669C975B54A1339D8385BC7D5DEC88C6D4BD482BFBC7A7DE44B016646B378B6A85FBC1219D351FE475DC178F90DF4961CA980EB4F157B764EC3ECF19604FEDE0551AA42FB12B7F19667AC9F2C46D1185E66072EA709CC0D9689CE721A47D54C028D7B0B01AEEC1C4C9A03979BE9080C21"));
	R.push_back(mpz_class("0x33F10AB2D18B94D870C684B5436B38AC419C08FB065A2C608C4E2E2060FE436945A15F8D80F373B35C3230654A92F99B1A1C8D5BB10B83646A112506022AF7D4D09F7403EC5AECDB077DA945FE0BE661BAFEDDDDC5E43A4C5D1A0B28AE2AA838C6C8A7AE3DF150DBD0A207891F1D6C4001B88D1D91CF380EE15E4E632F33BD02"));
	
	silvia_pub_key pubkey(n, S, Z, R);
	
	silvia_credential_generator cred(&pubkey);
	
	silvia_integer_attribute m1(1313);
	silvia_integer_attribute m2(1314);
	silvia_integer_attribute m3(1315);
	silvia_integer_attribute m4(1316);
	
	std::vector<silvia_attribute*> attributes;
	attributes.push_back(&m1);
	attributes.push_back(&m2);
	attributes.push_back(&m3);
	attributes.push_back(&m4);
	
	cred.set_attributes(attributes);
	
	silvia_integer_attribute s(mpz_class("0xB1173E9CFA91149B60B6A3A5822B49FAF79A6EED971469FCABEA79BC82AF36E0"));
	cred.set_secret(s);
	
	// Test computing the commitment
	mpz_class U;
	mpz_class v_prime;
	mpz_class v_prime_test("0xAE472CE185E9484385B2B9D6CA64FD44AC3E45688A780389B73B4F0C266F110291798C303B0C7C28EDFEBCEA0B783F138AB00C873B820B8F77D659127286429A184C28E122743E31731487D6D049C981D09DEC7DB0909223C765E5027C3A4D7B64F61FACDA5FD9D20BDEA131EF2A16ED508E5393C632F28ED603E724ACE9E922410E2D6F85BA4B25DC8C");
	
	cred.compute_commitment(U, v_prime, &v_prime_test);
	
	CPPUNIT_ASSERT(U == mpz_class("0x303150D3557EC3496A6720FC23D5B77A4B6E396D86C130A3BD9B886EE86307D3F12BCE8AEC0D8C46AD20628C4F0C58AFD5E6E699BFFC398712FC202F1EA825FD42AA4D461E5C7C5D7294588331BDE3810E31609A6B963698F8A2F518AA6B58E0F8A7EFE52DB5DCC864AAECF4C817A33342F53BBADDE6EFE247E14CAB2010BEE4"));
	
	// Test proof of commitment
	mpz_class c;
	mpz_class v_prime_hat;
	mpz_class s_hat;
	
	mpz_class s_tilde_test("0x018CB1BFAAD3402714E796B4E2F7DC7246950A074D0A5F782E25005611FC6374FDC395DE21023512990742ACC70FBA8AED6FB68F17A4D84C7A27486E56099C");
	mpz_class v_prime_tilde_test("0xF87EFB6925659CA77DC2247069D84FC7CAA60318C4222A9FA16E303B92234367909AB4E082FCDF66692D98FE019E86DF0347FAD1AF09AE55F7E6C0F736586CBD9B14BC23F556F29DCA1CA79018C8AC611E21202A3FDE1A9FB50C0CD9044271ECA4A0C3595006085FC2891F72C88C63CF79E843F21C9CA426A808BC1A43297112C7C34A125967B85BEB4249EFCC2C16455CF796A0851D50EEEB115AA08A58C2DF86D1F08C40E5C47D");
	mpz_class n1_test("0x80FC58C623C80FC7092D");
	mpz_class context("0xBA45FCF32A16B18C344865A288F4D421A3C5FE03");
	
	cred.prove_commitment(n1_test, context, c, v_prime_hat, s_hat, &s_tilde_test, &v_prime_tilde_test);
	
	CPPUNIT_ASSERT(c == mpz_class("0x7838BDCB7F99A8AC732BC867F800E16A61361D38"));
	CPPUNIT_ASSERT(v_prime_hat == mpz_class("0xF87EFB6925659CA77DC2764867A8ED5370E1B2C5A3D073D1B40AA06A0529D309BF552A2ACE20E9167B1EB661C4FA0CB5398068D58A66AEC0D980C34E2B8CAA260F6720ADF052C4B5AB07E490D84BF4E42A7748EC4148502E1A744CCB42BD2D0C6F20B600E15121F57ED991AC8903A4BF2F2D393BEC08984648FB0B65FD9D3195991E8E1E734C2C45D24BBD7220956780FF48B22E40329E8C44F84C9790FA557BE9A6DC558CB1DF1D"));
	CPPUNIT_ASSERT(s_hat == mpz_class("0x018CB1BFAAD3402714E797080D1D96A8FEC58A0462672573A44ED3993AFA77505089E7F691A7ABE0939129DC3E9D2517361C7135AD7760AE9EB0D351216A9C"));
	
	// Test signature proof validation
	mpz_class n2_test("0x7BAF54ECE6CADE702CB8");
	
	cred.get_prover_nonce(&n2_test);
	
	mpz_class A("0x37FB456B3D4D38F890F5DECDBE8147DD476A8F951E325EB3E860ABD2CCD4F52A1EF46594ED2D450869328DFFF6ACBD049BB8DD7AE4E256EB501B79BC17E1D68AB224D9CC310EB73CC218C43E860346942D690BBCEE7A3ED392D3933BB8CE6D4539A4D08475738A84B0FFB7D1A0CF25644E6EABC97A52C62BBC507E6885D16373");
	mpz_class e("0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006D093A6A327D0392ED2787DA24BB7D");
	mpz_class c_1("0xBE19129671FE5140C1E267A337AB4083C93EBC18");
	mpz_class e_hat("0x0137B079E0B05ADB0F1075005BA70D61EBEEE7A7DCC5DC685354F335FD7B53A6844B3E70E2CFCD38B5DDDD4470E6F520A20C496D6F587D3B8F690E8AA9090217F630481A05FDFC44DFF364574735BAFE4F29874812D4BD73EBDB10B631DA2C91D27059B9D52B679E86C8B6732C9A7020DD6E8B686D179C9767C50F1775215F0A");
	
	CPPUNIT_ASSERT(cred.verify_signature(context, A, e, c_1, e_hat) == true);
	
	// Test credential verification
	mpz_class v_prime_prime("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD153FF6FC59E7898CA6CEFE4A748E26384148C695EFC910E12AFFB16F0299A1F9A1B20BF84FB0E886BC32B135093600B674DCDD82A30595E64063358E18BD012752D21DC1A5657A6F8E466924D596031A8237E5A98F9636AAEFF55FE86A9AF973523611583B5B64E7713B84983759ED517382C9922A04B58BA086D6D121B277B06356041C8F2244D04D2BC");
	
	cred.compute_credential(A, e, v_prime_prime);
	
	CPPUNIT_ASSERT(cred.verify_credential() == true);
	
	silvia_credential* new_cred = cred.get_credential();
	
	mpz_class v_test("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD202469CA72461E10DF2A29E7E134760C8C0CAAEC78709119C673665FC5009309CAC9A4BB5361B0494B129D03A9ED84A7AD87DE4B16BDB69F37E09B1F3FE56550F456E04FB78CBE52A577B1A2429A9FB29F41C4716A9F3FCD2C6BBE38925E9E4B088573530901628491F96EAB564C8EC0488BAECB6667E4B48DE715436C8116428766E6F3877DE982AAF48");
	
	CPPUNIT_ASSERT(new_cred->get_A() == A);
	CPPUNIT_ASSERT(new_cred->get_e() == e);
	CPPUNIT_ASSERT(new_cred->get_v() == v_test);
	CPPUNIT_ASSERT(new_cred->get_secret() == s);
	CPPUNIT_ASSERT(new_cred->num_attributes() == 4);
	CPPUNIT_ASSERT(new_cred->get_attribute(0)->rep() == m1.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(1)->rep() == m2.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(2)->rep() == m3.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(3)->rep() == m4.rep());

	delete new_cred;
}