/**
 * Getter.
 *
 * @return Hex-encoded string representing the private id Yubikey token part.
 */
const string YubikoOtpKeyConfig::getPrivateId() const {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::getPrivateId");
	string myRetVal(K_YBK_PRIVATE_ID_LEN, '.');
	yubikey_hex_encode(&myRetVal[0],
			reinterpret_cast<const char*>(&itsToken.uid), YUBIKEY_UID_SIZE);
	return string(myRetVal);
}
Example #2
0
static rt::rendering::image_t
render(const rt::configuration_t& configuration, const rt::scene::instance_t& scene)
{
	BOOST_LOG_NAMED_SCOPE("Rendering");
	BOOST_LOG_TRIVIAL(info) << "Rendering start";

	std::atomic_size_t done(0);
	const float factor = 100.f / (configuration.width * configuration.height);
	const rt::rendering::renderer_t render = rt::rendering::make_renderer(configuration.width, configuration.height, configuration.depth, configuration.aa, done);
	std::future<rt::rendering::image_t> future = std::async(std::launch::async, render, scene);

	for (;;)
	{
		const std::future_status status = future.wait_for(std::chrono::seconds(5));
		if (status == std::future_status::ready)
			break;
		const float percent = done * factor;
		BOOST_LOG_TRIVIAL(info) << boost::format("%6.2f") % percent << "% done";
	}

	const rt::rendering::image_t image = future.get();

	BOOST_LOG_TRIVIAL(info) << "Rendering done" << std::endl;

	return std::move(image);
}
void KeyListPresenter::deleteKey() {
	BOOST_LOG_NAMED_SCOPE("KeyListPresenter::deleteKey");
	if(checkSelection()) {
		KeyManager& myKeyMan(getFactory().getKeyManager());
		getYubikoOtpKeyPresenter().deleteKey(myKeyMan.getKey(itsSelectedKey));
	}
}
const std::string YubikoOtpKeyConfig::getSecretKey() const {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::getSecretKey()");
	string myRetVal(K_SEC_KEY_SZ, '.');
	yubikey_hex_encode(&myRetVal[0], reinterpret_cast<const char*>(&itsKey),
	YUBIKEY_KEY_SIZE);
	return string(myRetVal);
}
//[ example_tutorial_attributes_named_scope
void named_scope_logging()
{
    BOOST_LOG_NAMED_SCOPE("named_scope_logging");

    src::severity_logger< severity_level > slg;

    BOOST_LOG_SEV(slg, normal) << "Hello from the function named_scope_logging!";
}
/**
 * Just initialize fields, does not loads the data.
 *
 * @param pFilename Where the configuration data will be stored.
 */
YubikoOtpKeyConfig::YubikoOtpKeyConfig(KeyManager& pKeyManager,
		const bfs::path& pFilename) :
		itsKeyManager(pKeyManager), itsChangedFlag(false), itsFilename(
				pFilename) {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::YubikoOtpKeyConfig");
	BOOST_LOG_TRIVIAL(debug)<< "Passed filename:  " << pFilename.native();
	zeroToken();
}
Example #7
0
static void
postprocess(const rt::rendering::writer_t& write, const rt::rendering::image_t& image)
{
	BOOST_LOG_NAMED_SCOPE("Postprocessing");
	BOOST_LOG_TRIVIAL(info) << "Postprocessing start";

	write(image);

	BOOST_LOG_TRIVIAL(info) << "Postprocessing done" << std::endl;
}
/**
 * @param pPswd2check modhex encoded
 */
bool YubikoOtpKeyConfig::checkOtp(const std::string& pPswd2check) {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::checkPassword");
	yubikey_token_st myToken;
	yubikey_parse(reinterpret_cast<const uint8_t*>(pPswd2check.c_str()),
			this->getSecretKeyArray().data(), &myToken);
	BOOST_LOG_TRIVIAL(debug)<< "Key token:";
	logDebug_token(getToken());
	BOOST_LOG_TRIVIAL(debug)<< "Decrypted token:";
	logDebug_token(myToken);
	if (strncmp(reinterpret_cast<const char*>(&getToken().uid),
			reinterpret_cast<char*>(&myToken.uid), YUBIKEY_UID_SIZE) == 0) {
		BOOST_LOG_TRIVIAL(debug)<< "UID is same.";
		uint16_t myComputedCrc = computeCrc(myToken);
		if(myToken.crc!=myComputedCrc) {
			BOOST_LOG_TRIVIAL(debug)<< "Decrypted CRC is wrong: "
			<< myComputedCrc <<"!=" << myToken.crc;
			return false;
		}
		if(myToken.ctr > getToken().ctr) {
			BOOST_LOG_TRIVIAL(debug)<< "Decrypted counter is bigger than stored value: "
			<< int(myToken.ctr) <<">" << int(getToken().ctr) << " reseting use counter & clock.";
			getToken().use= myToken.use;
			copyAndSaveToken(myToken);
			BOOST_LOG_TRIVIAL(debug)<< "OTP OK (use counter reset)!";
			return true;
		} else {
			if(myToken.ctr < getToken().ctr) {
				BOOST_LOG_TRIVIAL(debug)<< "Decrypted counter is smaller than stored value: "
				<< int(myToken.ctr) <<"<" << int(getToken().ctr) << " returning false.";
				return false;
			}
		}
		BOOST_LOG_TRIVIAL(debug)<< "Counter is "<< int(myToken.ctr)<<".";
		if(myToken.use <= getToken().use) {
			BOOST_LOG_TRIVIAL(debug)<< "Decrypted use counter is wrong: "
			<< int(myToken.use) <<"<=" << int(getToken().use);
			return false;
		}
		UTimestamp myTstmp;
		myTstmp.tstp.tstph=myToken.tstph;
		myTstmp.tstp.tstpl=myToken.tstpl;
		if(myTstmp.tstp_int<=getTimestamp().tstp_int) {
			BOOST_LOG_TRIVIAL(debug)<< "Decrypted timer is smaller than stored value: "
			<< myTstmp.tstp_int <<"<=" << getTimestamp().tstp_int << " returning false.";
			return false;
		} else {
			BOOST_LOG_TRIVIAL(debug)<< "Decrypted timer int value: "
			<< myTstmp.tstp_int <<".";
		}
		copyAndSaveToken(myToken);
		BOOST_LOG_TRIVIAL(debug)<< "OTP OK!";
		return true;
	}
	return false;
}
Example #9
0
//! The function tests logging
void try_logging()
{
    BOOST_LOG_FUNCTION();

    src::severity_logger< >& lg = test_lg::get();

    BOOST_LOG_SEV(lg, critical) << "This is a critical severity record";

    BOOST_LOG_NAMED_SCOPE("random name");
    BOOST_LOG_SEV(lg, error) << "This is a error severity record";
}
void KeyListPresenter::reloadKeyList() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyPresenter::reloadKeyList");
	KeyManager& myKeyMan(getFactory().getKeyManager());
	const size_t myKeySz = myKeyMan.loadKeys();
	getView().clear();
	for (int myRow = 0; myRow < myKeySz; ++myRow) {
		const auto& myKey = myKeyMan.getKey(myRow);
		getView().addRow(getView().createRow(myRow, myKey));
	}
	getView().addedAllRows();
	getView().selectionChangedSig(-1);
}
void KeyListPresenter::selectionChanged(int pIdx) {
	BOOST_LOG_NAMED_SCOPE("KeyListPresenter::selectionChange");
	if(pIdx==-1) {
		getView().getBtnDelKey().setEnabled(false);
		getView().getBtnEditKey().setEnabled(false);
	} else {
		getView().getBtnDelKey().setEnabled(true);
		getView().getBtnEditKey().setEnabled(true);
	}
	itsSelectedKey=pIdx;
	BOOST_LOG_TRIVIAL(debug)<<"Curently selected " << itsSelectedKey;
}
Example #12
0
MockKeyListView::MockKeyListView() {
	BOOST_LOG_NAMED_SCOPE("MockKeyListView::MockKeyListView");

	ON_CALL(*this,getBtnAddKey()) //
	.WillByDefault(ReturnRef(itsMockBtnAddKey));
	ON_CALL(*this,getBtnDelKey()) //
	.WillByDefault(ReturnRef(itsMockBtnDelKey));
	ON_CALL(*this,getBtnEditKey()) //
	.WillByDefault(ReturnRef(itsMockBtnEditKey));
	ON_CALL(*this,getBtnReload()) //
	.WillByDefault(ReturnRef(itsMockBtnReloadKey));

}
/**
 * Setter.
 *
 * @param pPrivateId Hex-encoded string representing the private id Yubikey token part.
 */
void YubikoOtpKeyConfig::setPrivateId(const string &pPrivateId) {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::setPrivateId");
	string myPrivateId(pPrivateId);
	trim(myPrivateId);
	if (myPrivateId.size() != K_YBK_PRIVATE_ID_LEN) {
		throw WrongConfigValue(WrongConfigValue::EYbkPrivateId,
				K_YBK_PRIVATE_ID_LEN, myPrivateId);
	}
	if (getPrivateId() != pPrivateId) {
		yubikey_hex_decode(reinterpret_cast<char*>(itsToken.uid),
				myPrivateId.c_str(), YUBIKEY_UID_SIZE);
		itsChangedFlag = true;
	}
}
Example #14
0
void Worker::run() {
    BOOST_LOG_NAMED_SCOPE("worker run");
    this->jpeg_reader.start();
    while (this->running) {
        //BOOST_LOG_TRIVIAL(debug) << "Waiting frame";
        FrameAnalysis *frame = this->context.get();
        //BOOST_LOG_TRIVIAL(debug) << "Got frame";
        if (this->context.is_finished()) {
            BOOST_LOG_TRIVIAL(debug) << "Worker ready to exit";
            break;
        }
        this->last_frame = QSharedPointer<FrameAnalysis>(frame);
        emit frame_produced();
    }
}
Example #15
0
static rt::scene::instance_t
preprocess(const rt::configuration_t& configuration)
{
	BOOST_LOG_NAMED_SCOPE("Preprocessing");
	BOOST_LOG_TRIVIAL(info) << "Preprocessing start";

	const rt::scene::description_t description = rt::parsing::parse(configuration.input);
	const rt::scene::instance_t instance = rt::scene::make(description);

	BOOST_LOG_TRIVIAL(info) << "Created " << instance.lights().size() << " lights";
	BOOST_LOG_TRIVIAL(info) << "Created " << instance.objects().size() << " objects";
	BOOST_LOG_TRIVIAL(info) << "Preprocessing done" << std::endl;

	return std::move(instance);
}
void MockYubikoOtpKeyView::setupDefaultOnCallHandlers() {
	BOOST_LOG_NAMED_SCOPE("MockYubikoOtpKeyView::setupDefaultOnCallHandlers");

	ON_CALL(*this,getEdtPrivateId()).WillByDefault(
			ReturnRef(itsMockEdtPrivateId));
	ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtPrivateId()).WillByDefault(
			ReturnRef(itsMockEdtPrivateId));

	ON_CALL(*this,getEdtSecretKey()).WillByDefault(
			ReturnRef(itsMockEdtSecretKey));
	ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtSecretKey()).WillByDefault(
			ReturnRef(itsMockEdtSecretKey));

	ON_CALL(*this,getEdtPublicId()).WillByDefault(
			ReturnRef(itsMockEdtPublicId));
	ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtPublicId()).WillByDefault(
			ReturnRef(itsMockEdtPublicId));

	ON_CALL(*this,getEdtDescription()).WillByDefault(
			ReturnRef(itsMockEdtDescription));
	ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtDescription()).WillByDefault(
			ReturnRef(itsMockEdtDescription));

	ON_CALL(*this,getSbxPublicIdLen()).WillByDefault(
			ReturnRef(itsMockSbxPublicIdLen));
	ON_CALL((const MockYubikoOtpKeyView&)(*this),getSbxPublicIdLen()).WillByDefault(
			ReturnRef(itsMockSbxPublicIdLen));

	ON_CALL(*this,getBtnSave()).WillByDefault(ReturnRef(itsMockBtnSave));

	ON_CALL(*this,getEdtSysUser()).WillByDefault(
			ReturnRef(itsMockEdtSysUser));
	ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtSysUser()).WillByDefault(
			ReturnRef(itsMockEdtSysUser));

	ON_CALL(*this,getBtnSelectSysUser()).WillByDefault(
			ReturnRef(itsMockBtnSelectSysUser));


	ON_CALL(*this,getBtnGenPrivateId()).WillByDefault(
			ReturnRef(itsMockBtnGenPrivateId));

	ON_CALL(*this,getBtnGenPublicId()).WillByDefault(
			ReturnRef(itsMockBtnGenPublicId));

	ON_CALL(*this,getBtnGenSecretKey()).WillByDefault(
			ReturnRef(itsMockBtnGenSecretKey));
}
void YubikoOtpKeyConfig::setSecretKey(const std::string& pKey) {
	BOOST_LOG_NAMED_SCOPE(
			"YubikoOtpKeyConfig::setSecretKey( const std::string& pKey)");
	string mySecretKey(pKey);
	trim(mySecretKey);
	if (mySecretKey.size() != K_SEC_KEY_SZ) {
		throw WrongConfigValue(WrongConfigValue::EYbkSecretKey, K_SEC_KEY_SZ,
				mySecretKey);
	}
	if (getSecretKey() != pKey) {
		yubikey_hex_decode(reinterpret_cast<char*>(itsKey.data()),
				mySecretKey.c_str(),
				YUBIKEY_KEY_SIZE);
		itsChangedFlag = true;
	}
}
Example #18
0
static rt::configuration_t
configure(const int argc, const char* const argv[])
{
	const rt::configuration_t configuration = rt::configure(argc, argv);
	rt::logging(configuration.level.at(0));

	BOOST_LOG_NAMED_SCOPE("Configuration");
	BOOST_LOG_TRIVIAL(info) << "Configuration start";
	BOOST_LOG_TRIVIAL(info) << "Input " << '"' << configuration.input << '"';
	BOOST_LOG_TRIVIAL(info) << "Output " << '"' << configuration.output << '"';
	BOOST_LOG_TRIVIAL(info) << "Resolution " << configuration.width << 'x' << configuration.height;
	BOOST_LOG_TRIVIAL(info) << "Recursion " << configuration.depth;
	BOOST_LOG_TRIVIAL(info) << "Antialiasing " << (configuration.aa ? "on" : "off");
	BOOST_LOG_TRIVIAL(info) << "Configuration done" << std::endl;

	return std::move(configuration);
}
/**
 * Save the key data in a JSON like format. The filename is specified in
 * constructor YubikoOtpKeyConfig::YubikoOtpKeyConfig(const string& )
 */
void YubikoOtpKeyConfig::save() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::save");
	const string myOutFile = checkFileName(true);
	ptree myTree;
	myTree.put(K_NM_DOC_PRIV_ID /*--->*/, getPrivateId());
	myTree.put(K_NM_DOC_PUB_ID /*---->*/, getPublicId());
	myTree.put(K_NM_DOC_SEC_KEY /*--->*/, getSecretKey());
	myTree.put(K_NM_DOC_TIMESTAMP /*->*/, getTimestamp().tstp_int);
	myTree.put(K_NM_DOC_SES_CNTR /*-->*/, getCounter());
	myTree.put(K_NM_DOC_CRC /*------->*/, getCrc());
	myTree.put(K_NM_DOC_RANDOM /*---->*/, getRandom());
	myTree.put(K_NM_DOC_USE_CNTR /*-->*/, getUseCounter());
	myTree.put(K_NM_DOC_DESC /*------>*/, getDescription());
	myTree.put(K_NM_DOC_SYS_USER /*-->*/, getSysUser());
	myTree.put(K_NM_DOC_VERS /*------>*/, K_VL_VERS);
	write_json(myOutFile, myTree);
	itsChangedFlag = false;
}
Example #20
0
void Worker::run() {
    BOOST_LOG_NAMED_SCOPE("worker run");
    this->jpeg_reader.start();
    while (this->running) {
        BOOST_LOG_TRIVIAL(debug) << "Waiting frame";
        FrameAnalysis *frame = this->context.get();
        BOOST_LOG_TRIVIAL(debug) << "Got frame";
        if (this->context.is_finished()) {
            BOOST_LOG_TRIVIAL(debug) << "Worker ready to exit";
            break;
        }
        if (frame->does_have_fix()) {
            this->out_stream << frame->gen_csv_line() << "\n";
        }
        this->last_frame = QSharedPointer<FrameAnalysis>(frame);
        BOOST_LOG_TRIVIAL(debug) << "Emitting frame produced";
        emit frame_produced();
    }
}
Example #21
0
bool ns::Lvl4SM::process_lvl4_data(int s, uint32_t navail, Target const& target, HostSM& hsm)
{
	_D(BOOST_LOG_NAMED_SCOPE("Lvl4SM::process_lvl4_data"));

	uint32_t prev_pos = _buf.size();
	unsigned char* buf_read = _buf.grow_by(navail);
	int nread = read(s, buf_read, navail);
	if (nread <= 0) {
		// TODO: callback
		_D(BOOST_LOG_TRIVIAL(trace) << s << "invalid read size: " << strerror(errno) << std::endl);
		return false;
	}
	int ret;
	do {
		ret = _trigger.process_buffer(ConnectedTarget(s, target), *this, hsm, _buf, prev_pos);
		prev_pos = 0;
	}
	while (ret == DataTrigger::CanProcessAgain);
	return ret == DataTrigger::NoMoreToProcess;
}
const string YubikoOtpKeyConfig::checkFileName(bool pIsOut) const {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::checkFileName");
	std::string myRetVal;
	if (is_directory(getFilename())) {
		const string myMsg =
				(format("File %1% is a directory.") % getFilename()).str();
		BOOST_LOG_TRIVIAL(error)<< myMsg;
		throw out_of_range(myMsg);
	}
	if (pIsOut) {
		if (exists(getFilename())) {
			const string myMsg = (format("File %1% already exists.")
					% getFilename()).str();
			BOOST_LOG_TRIVIAL(error)<< myMsg;
			ptime myTime = microsec_clock::universal_time();
			stringstream myStrStr;
			myStrStr << "." << myTime;
			path myBackup(getFilename());
			myBackup += (myStrStr.str());
			BOOST_LOG_TRIVIAL(debug)<< "Moving "<< getFilename() << " to "<<myBackup;
			rename(getFilename(), myBackup);
		}
		myRetVal = getFilename().native();
	} else {
		if (!exists(getFilename())) {
			const string myMsg = (format("Couldn't open save file %1%.")
					% getFilename()).str();
			BOOST_LOG_TRIVIAL(error)<< myMsg;
			throw out_of_range(myMsg);
		}
		uintmax_t myFSz = file_size(getFilename());
		if (myFSz > K_MX_KEY_FILE_SZ) {
			const string myMsg = (format("File %1% is too big: %2%.")
					% getFilename() % myFSz).str();
			BOOST_LOG_TRIVIAL(error)<< myMsg;
			throw out_of_range(myMsg);
		}
		myRetVal = getFilename().native();
	}
	return myRetVal;
}
void YubikoOtpKeyConfig::load() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::load");
	const string myInFile = checkFileName(false);
	ptree myTree;
	read_json(myInFile, myTree);
	const string myVer(myTree.get<string>(K_NM_DOC_VERS));
	BOOST_LOG_TRIVIAL(info)<< K_NM_VERS << ":" << myVer;
	setPrivateId(myTree.get<string>(K_NM_DOC_PRIV_ID));
	setPublicId(myTree.get<string>(K_NM_DOC_PUB_ID));
	setSecretKey(myTree.get<string>(K_NM_DOC_SEC_KEY));
	setTimestamp(UTimestamp(myTree.get<uint64_t>(K_NM_DOC_TIMESTAMP)));
	setCounter(myTree.get<uint8_t>(K_NM_DOC_SES_CNTR));
	setCrc(myTree.get<uint16_t>(K_NM_DOC_CRC));
	setRandom(myTree.get<uint16_t>(K_NM_DOC_RANDOM));
	setUseCounter(myTree.get<uint8_t>(K_NM_DOC_USE_CNTR));
	setDescription(myTree.get<string>(K_NM_DOC_DESC));
	if (myVer != "0.0.1") {
		const string mySysUser { myTree.get<string>(K_NM_DOC_SYS_USER) };
		if (!mySysUser.empty())
			setSysUser(mySysUser);
	}
	itsChangedFlag = false;
}
Example #24
0
/** Burning vegetation and soil organic C */
void WildFire::burn(int year) {
  BOOST_LOG_NAMED_SCOPE("burning");
  BOOST_LOG_SEV(glg, note) << "HELP!! - WILD FIRE!! RUN FOR YOUR LIFE!";

  BOOST_LOG_SEV(glg, debug) << fd->report_to_string("Before WildFire::burn(..)");
  BOOST_LOG_SEV(glg, note) << "Burning (simply clearing?) the 'FireData object...";
  fd->burn();
  BOOST_LOG_SEV(glg, debug) << fd->report_to_string("After FirData::burn(..)");
  
  // for soil part and root burning
  // FIX: there isn't really a reason for getBurnOrgSoilthick to return a value
  // as it has already set the "burn thickness" value in FirData...
  double burndepth = getBurnOrgSoilthick(year);
  BOOST_LOG_SEV(glg, debug) << fd->report_to_string("After WildFire::getBurnOrgSoilthick(..)");

  BOOST_LOG_SEV(glg, note) << "Setup some temporary pools for tracking various burn related attributes (depths, C, N)";
  double totbotdepth = 0.0;
  double burnedsolc = 0.0;
  double burnedsoln = 0.0;
  double r_burn2bg_cn[NUM_PFT]; // ratio of dead veg. after burning
  for (int ip=0; ip<NUM_PFT; ip++) {
    r_burn2bg_cn[ip] = 0.; //  used for vegetation below-ground (root) loss,
                           //  and calculated below
  }

  BOOST_LOG_SEV(glg, debug) << "Handle burning the soil (loop over all soil layers)...";
  for (int il = 0; il < cd->m_soil.numsl; il++) {

    BOOST_LOG_SEV(glg, debug) << "== Layer Info == "
                              << "   type:" << cd->m_soil.type[il] // 0:moss 1:shlwpeat 2:deeppeat 3:mineral
                              << "   dz:" << cd->m_soil.dz[il]
                              << "   top:" << cd->m_soil.z[il]
                              << "   bottom:"<< cd->m_soil.z[il] + cd->m_soil.dz[il];

    if(cd->m_soil.type[il] <= 2) {

      totbotdepth += cd->m_soil.dz[il];

      double ilsolc =  bdall->m_sois.rawc[il] + bdall->m_sois.soma[il] +
                       bdall->m_sois.sompr[il] + bdall->m_sois.somcr[il];

      double ilsoln =  bdall->m_sois.orgn[il] + bdall->m_sois.avln[il];

      if(totbotdepth <= burndepth) { //remove all the orgc/n in this layer
        BOOST_LOG_SEV(glg, debug) << "Haven't reached burndepth (" << burndepth << ") yet. Remove all org C and N in this layer";
        burnedsolc += ilsolc;
        burnedsoln += ilsoln;
        bdall->m_sois.rawc[il] = 0.0;
        bdall->m_sois.soma[il] = 0.0;
        bdall->m_sois.sompr[il]= 0.0;
        bdall->m_sois.somcr[il]= 0.0;
        bdall->m_sois.orgn[il] = 0.0;
        bdall->m_sois.avln[il] = 0.0;

        for (int ip=0; ip<NUM_PFT; ip++) {
          if (cd->m_veg.vegcov[ip]>0.) {
            r_burn2bg_cn[ip] += cd->m_soil.frootfrac[il][ip];
            cd->m_soil.frootfrac[il][ip] = 0.0;
          }
        }
      } else {
        BOOST_LOG_SEV(glg, debug) << "The bottom of this layer (il: " << il << ") is past the 'burndepth'. Find the remaining C and N as a fraction of layer thickness";
        double partleft = totbotdepth - burndepth;

        // Calculate the remaining C, N
        if (partleft < cd->m_soil.dz[il]) { // <-- Maybe this should be an assert instead of an if statement??
          BOOST_LOG_SEV(glg, debug) << "Burning all but "<<partleft<<"of layer "<<il;
          burnedsolc += (1.0-partleft/cd->m_soil.dz[il]) * ilsolc;
          burnedsoln += (1.0-partleft/cd->m_soil.dz[il]) * ilsoln;
          bdall->m_sois.rawc[il] *= partleft/cd->m_soil.dz[il];
          bdall->m_sois.soma[il] *= partleft/cd->m_soil.dz[il];
          bdall->m_sois.sompr[il] *= partleft/cd->m_soil.dz[il];
          bdall->m_sois.somcr[il] *= partleft/cd->m_soil.dz[il];
          bdall->m_sois.orgn[il] *= partleft/cd->m_soil.dz[il];
          bdall->m_sois.avln[il] *= partleft/cd->m_soil.dz[il];

          for (int ip=0; ip<NUM_PFT; ip++) {
            if (cd->m_veg.vegcov[ip] > 0.0) {
              r_burn2bg_cn[ip] += (1-partleft/cd->m_soil.dz[il])
                                * cd->m_soil.frootfrac[il][ip];
              cd->m_soil.frootfrac[il][ip] *= partleft/cd->m_soil.dz[il];
            }
          }
        } else {
          // should never get here??
          BOOST_LOG_SEV(glg, err) << "The remaining soil after a burn is greater than the thickness of this layer. Something is wrong??";
          BOOST_LOG_SEV(glg, err) << "partleft: " << partleft << "cd->m_soil.dz["<<il<<"]: " << cd->m_soil.dz[il];
          break;
        }
      }
    } else {   //Mineral soil layers
      BOOST_LOG_SEV(glg, note) << "Layer type:" << cd->m_soil.type[il] << ". Should be a non-organic soil layer? (greater than type 2)";
      BOOST_LOG_SEV(glg, note) << "Not much to do here. Can't really burn non-organic layers.";

      if(totbotdepth <= burndepth) { //may not be needed, but just in case
        BOOST_LOG_SEV(glg, note) << "For some reason totbotdepth <= burndepth, so we are setting fd->fire_soid.burnthick = totbotdepth??";
        fd->fire_soid.burnthick = totbotdepth;
      }
    }
  } // end soil layer loop

  //Setting relative organic layer burn (rolb) value
  fd->fire_soid.rolb = fd->fire_soid.burnthick / totbotdepth;

  // needs to re-do the soil rootfrac for each pft which was modified above
  //   (in burn soil layer)
  BOOST_LOG_SEV(glg, note) << "Re-do the soil root fraction for each PFT modified by burning?";
  for (int ip = 0; ip < NUM_PFT; ip++) {
    double rootfracsum = 0.0;

    for (int il = 0; il < cd->m_soil.numsl; il++) {
      rootfracsum += cd->m_soil.frootfrac[il][ip];
    }

    for (int il =0; il <cd->m_soil.numsl; il++) {
      cd->m_soil.frootfrac[il][ip] /= rootfracsum;
    }
  }

  // all woody debris will burn out
  BOOST_LOG_SEV(glg, note) << "Handle burnt woody debris...";
  double wdebrisc = bdall->m_sois.wdebrisc; //
  double wdebrisn = bdall->m_sois.wdebrisn; //
  bdall->m_sois.wdebrisc = 0.0;
  bdall->m_sois.wdebrisn = 0.0;

  // summarize
  BOOST_LOG_SEV(glg, note) << "Summarize...?";
  double vola_solc = burnedsolc * (1.0 - firpar.r_retain_c) + wdebrisc;
  double vola_soln = burnedsoln * (1.0 - firpar.r_retain_n) + wdebrisn;
  double reta_solc = burnedsolc * firpar.r_retain_c;   //together with veg.-burned C return, This will be put into soil later
  double reta_soln = burnedsoln * firpar.r_retain_n;   //together with veg.-burned N return, This will be put into soil later

  BOOST_LOG_SEV(glg, note) << "Handle Vegetation burning and mortality...";
  double comb_vegc = 0.0;  // summed for all PFTs
  double comb_vegn = 0.0;
  double comb_deadc = 0.0;
  double comb_deadn = 0.0;
  double dead_bg_vegc = 0.0;
  double dead_bg_vegn = 0.0;
  double veg_2_dead_C = 0.0;
  double veg_2_dead_N = 0.0;

  bdall->m_vegs.deadc0 = 0.0;//Zeroing the standing dead pools
  bdall->m_vegs.deadn0 = 0.0;

  for (int ip = 0; ip < NUM_PFT; ip++) {

    if (cd->m_veg.vegcov[ip] > 0.0) {
      BOOST_LOG_SEV(glg, note) << "Some of PFT"<<ip<<" exists (coverage > 0). Burn it!";

      // vegetation burning/dead/living fraction for above-ground
      getBurnAbgVegetation(ip, year);

      // root death ratio: must be called after both above-ground and
      // below-ground burning. r_live_cn is same for both above-ground
      // and below-ground
      double r_dead2bg_cn = 1.0-r_burn2bg_cn[ip]-r_live_cn;

      // Dead veg C, N. Assuming all previous deadc burned.
      comb_deadc += bd[ip]->m_vegs.deadc;
      // Assuming all previous deadn burned
      comb_deadn += bd[ip]->m_vegs.deadn;
      
      //Zeroing the standing dead pools
      bd[ip]->m_vegs.deadc0 = 0.0;
      bd[ip]->m_vegs.deadn0 = 0.0;

      veg_2_dead_C = (bd[ip]->m_vegs.c[I_leaf] + bd[ip]->m_vegs.c[I_stem]) * r_dead2ag_cn;
      veg_2_dead_N = (bd[ip]->m_vegs.strn[I_leaf] + bd[ip]->m_vegs.strn[I_stem]) * r_dead2ag_cn;

      // Above-ground veg. burning/death during fire
      // when summing, needs adjusting by 'vegcov'
      comb_vegc += bd[ip]->m_vegs.c[I_leaf] * r_burn2ag_cn;

      // We define dead c/n as the not-falling veg (or binding with living veg)
      // during fire,
      bd[ip]->m_vegs.deadc = bd[ip]->m_vegs.c[I_leaf] * r_dead2ag_cn;
      // Which then is the source of ground debris (this is for woody plants
      // only, others could be set deadc/n to zero)
      bd[ip]->m_vegs.c[I_leaf] *= (1.0 - r_burn2ag_cn - r_dead2ag_cn);

      comb_vegc += bd[ip]->m_vegs.c[I_stem] * r_burn2ag_cn;
      bd[ip]->m_vegs.deadc += bd[ip]->m_vegs.c[I_stem] * r_dead2ag_cn;
      bd[ip]->m_vegs.c[I_stem] *= (1.0 - r_burn2ag_cn-r_dead2ag_cn);

      comb_vegn += bd[ip]->m_vegs.strn[I_leaf] * r_burn2ag_cn;
      bd[ip]->m_vegs.deadn += bd[ip]->m_vegs.strn[I_leaf] * r_dead2ag_cn;
      bd[ip]->m_vegs.strn[I_leaf] *= (1.0 - r_burn2ag_cn-r_dead2ag_cn);

      comb_vegn += bd[ip]->m_vegs.strn[I_stem] * r_burn2ag_cn;
      bd[ip]->m_vegs.deadn += bd[ip]->m_vegs.strn[I_stem] * r_dead2ag_cn;
      bd[ip]->m_vegs.strn[I_stem] *= (1.0 - r_burn2ag_cn - r_dead2ag_cn);

      // Below-ground veg. (root) burning/death during fire
      comb_vegc += bd[ip]->m_vegs.c[I_root] * r_burn2bg_cn[ip];
      comb_vegn += bd[ip]->m_vegs.strn[I_root] * r_burn2bg_cn[ip];

      // For the dead below-ground C caused by fire, they are put into original layer
      double deadc_tmp = bd[ip]->m_vegs.c[I_root]*r_dead2bg_cn;
      for (int il = 0; il < cd->m_soil.numsl; il++) {
        if (cd->m_soil.frootfrac[il][ip] > 0.0) {
          //for this, 'rootfrac' must be updated above
          bdall->m_sois.somcr[il] += deadc_tmp * cd->m_soil.frootfrac[il][ip];
        }
      }
      dead_bg_vegc += deadc_tmp;
      bd[ip]->m_vegs.c[I_root] *= (1.0 - r_burn2bg_cn[ip] - r_dead2bg_cn);

      // For the dead below-ground N caused by fire, they are put into original layer
      double deadn_tmp = bd[ip]->m_vegs.strn[I_root] * r_dead2bg_cn; //this is needed below
      for (int il =0; il <cd->m_soil.numsl; il++) {
        if (cd->m_soil.frootfrac[il][ip] > 0.0) {
          //for this, 'rootfrac' must be updated above
          bdall->m_sois.somcr[il] += deadn_tmp*cd->m_soil.frootfrac[il][ip];
        }
      }
      dead_bg_vegn +=deadn_tmp;
      bd[ip]->m_vegs.strn[I_root] *= (1.0 - r_burn2bg_cn[ip] - r_dead2bg_cn);

      // one more veg N pool (labile N)
      comb_vegn += bd[ip]->m_vegs.labn * (1.0 - r_live_cn);//assuming all labn emitted, leaving none into deadn
      bd[ip]->m_vegs.labn *= r_live_cn;

      // finally, we have:
      bd[ip]->m_vegs.call = bd[ip]->m_vegs.c[I_leaf]
                            + bd[ip]->m_vegs.c[I_stem]
                            + bd[ip]->m_vegs.c[I_root];
      bd[ip]->m_vegs.nall = bd[ip]->m_vegs.strn[I_leaf]
                            + bd[ip]->m_vegs.strn[I_stem]
                            + bd[ip]->m_vegs.strn[I_root]
                            + bd[ip]->m_vegs.labn;

    } // end of 'cd->m_veg.vegcov[ip] > 0.0' (no coverage, nothing to do)

    //Writing out initial standing dead pools. These values will be
    //used to compute the rate of decomposition of the standing dead - 
    //1/9th of the original value per year.
    bd[ip]->m_vegs.deadc0 = veg_2_dead_C;
    bd[ip]->m_vegs.deadn0 = veg_2_dead_N;

    //Writing out initial values of standing dead pools to the pools
    //actually used for computation. These values will be decremented
    //by 1/9th the original value per year.
    bd[ip]->m_vegs.deadc = veg_2_dead_C;
    bd[ip]->m_vegs.deadn = veg_2_dead_N;

  } // end pft loop

  double reta_vegc = (comb_vegc + comb_deadc) * firpar.r_retain_c;
  double reta_vegn = (comb_vegn + comb_deadn) * firpar.r_retain_n;

  //Writing out initial standing dead pools. These values will be
  //used to compute the rate of decomposition of the standing dead - 
  //1/9th of the original value per year.
  //bdall->m_vegs.deadc0 = veg_2_dead_C;
  //bdall->m_vegs.deadn0 = veg_2_dead_N;

  //Writing out initial values of standing dead pools to the pools
  //actually used for computation. These values will be decremented
  //by 1/9th the original value per year.
  //bdall->m_vegs.deadc = veg_2_dead_C;
  //bdall->m_vegs.deadn = veg_2_dead_N;

  BOOST_LOG_SEV(glg, note) << "Save the fire emission and return data into 'fd'...";
  //Summing the PFT specific fluxes to dead standing
  for(int ip=0; ip<NUM_PFT; ip++){
    fd->fire_v2dead.vegC += bd[ip]->m_vegs.deadc;
    fd->fire_v2dead.strN += bd[ip]->m_vegs.deadn;
  }
  //fd->fire_v2dead.vegC = veg_2_dead_C; 
  //fd->fire_v2dead.strN = veg_2_dead_N;
  fd->fire_v2a.orgc =  comb_vegc - reta_vegc;
  fd->fire_v2a.orgn =  comb_vegn - reta_vegn;
  fd->fire_v2soi.abvc = reta_vegc;
  fd->fire_v2soi.abvn = reta_vegn;
  fd->fire_v2soi.blwc = dead_bg_vegc;
  fd->fire_v2soi.blwn = dead_bg_vegn;
  fd->fire_soi2a.orgc = vola_solc;
  fd->fire_soi2a.orgn = vola_soln;

  // the above 'v2a.orgn' and 'soi2a.orgn', will be as one of N source,
  // which is depositing into soil evenly in one FRI
  //- this will let the system -N balanced in a long-term, if NO
  //  open-N cycle included
  //This should occur every month post-fire. FIX
  fd->fire_a2soi.orgn = (fd->fire_soi2a.orgn + fd->fire_v2a.orgn) / this->fri;


  //put the retained C/N into the first unburned soil layer's
  //  chemically-resistant SOMC pool
  // Note - this 'retained C' could be used as char-coal, if need to do so.
  //        Then define the 'r_retain_c' in the model shall be workable
  for (int il = 0; il < cd->m_soil.numsl; il++) {
    double tsomc = bdall->m_sois.rawc[il] + bdall->m_sois.soma[il]
                   + bdall->m_sois.sompr[il] + bdall->m_sois.somcr[il];

    if(tsomc > 0. || il==cd->m_soil.numsl-1) {
      // this may possibly put retac/n in the first mineral soil
      bdall->m_sois.somcr[il] += reta_vegc + reta_solc;
      bdall->m_sois.orgn[il]  += reta_vegn + reta_soln;
      break;
    }
  }

  //Need to copy 'bdall->m_soils' to other PFTs, because above
  //  soil portion of 'bd' is done on 'bdall'
  for (int ip=1; ip<NUM_PFT; ip++) {
    if (cd->m_veg.vegcov[ip]>0.) {
      bd[ip]->m_sois = bdall->m_sois;
    }
  }
};
YubikoOtpKeyConfig::YubikoOtpKeyConfig(KeyManager& pKeyManager) :
		itsKeyManager(pKeyManager), itsChangedFlag(false) {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::YubikoOtpKeyConfig");
	generateFilename();
	zeroToken();
}
MockYubikoOtpKeyView::~MockYubikoOtpKeyView() {
	BOOST_LOG_NAMED_SCOPE("MockYubikoOtpKeyView::~MockYubikoOtpKeyView");
}
void YubikoOtpKeyConfig::setFilename(const string &value) {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::setFilename");
	itsFilename = value;
}
YubikoOtpKeyConfig::~YubikoOtpKeyConfig() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::~YubikoOtpKeyConfig");
}