Example #1
0
    void ReCollocate( std::string  Layout)
    {
        _myLayout.swap(Layout);
        try 
        {
            ReCollocate( );
        }
        catch(std::exception& e)
        {
             (nana::msgbox(*_EdWd_owner, STR("std::exception during EditableWidget ReCollocation: "))
                    .icon(nana::msgbox::icon_error)
                                 <<STR("\n   in widget: ")  << nana::API::window_caption( _thisEdWd)
                                 <<STR("\n   Title: "    )  << _Titel
                                 <<STR("\n   owned by: "  ) << nana::API::window_caption(*_EdWd_owner)
                                 <<STR("\n   trying to layout: \n "  ) << _myLayout
                                 <<STR("\n   ocurred exception: ") << e.what() 
             ).show();
        }
		catch(...)
		{
             (nana::msgbox(*_EdWd_owner, STR("An uncaptured exception during EditableWidget ReCollocation: "))
                    .icon(nana::msgbox::icon_error)
                                 <<STR("\n   in widget: ")  << nana::API::window_caption( _thisEdWd)
                                 <<STR("\n   Title: "    )  << _Titel
                                 <<STR("\n   owned by: "  ) << nana::API::window_caption(*_EdWd_owner)
                                 <<STR("\n   trying to layout: \n "  ) << _myLayout
             ).show();
	    }
        _myLayout.swap(Layout); /// call ReCollocate again???
	}
        /**
          *   Generate 2 blocks of open info and create secret key.
         **/
        void generate_key_infos( const std::string &key,
                                 std::string &s1, std::string &s2,
                                 std::string &result )
        {
            random_device rd( false );

            std::string ts1( rd.generate_block( 256 ) );
            std::string ts2( rd.generate_block( 256 ) );

            create_key( key, ts1, ts2, result );

            s1.swap( ts1 );
            s2.swap( ts2 );
        }
Example #3
0
void DtlsTransport::onHandshakeCompleted(DtlsSocketContext *ctx, std::string clientKey,std::string serverKey, std::string srtp_profile) {
  boost::mutex::scoped_lock lock(sessionMutex_);
  std::string temp;
  if (isServer_){ // If we are server, we swap the keys
    ELOG_DEBUG("It is server, we swap the keys");
    clientKey.swap(serverKey);
  }
  if (ctx == dtlsRtp.get()) {
    ELOG_DEBUG("%s - Setting RTP srtp params, is Server? %d", transport_name.c_str(), this->isServer_);
    srtp_.reset(new SrtpChannel());
    if (srtp_->setRtpParams((char*) clientKey.c_str(), (char*) serverKey.c_str())) {
      readyRtp = true;
    } else {
      updateTransportState(TRANSPORT_FAILED);
    }
    if (dtlsRtcp == NULL) {
      readyRtcp = true;
    }
  }
  if (ctx == dtlsRtcp.get()) {
    ELOG_DEBUG("%s - Setting RTCP srtp params", transport_name.c_str());
    srtcp_.reset(new SrtpChannel());
    if (srtcp_->setRtpParams((char*) clientKey.c_str(), (char*) serverKey.c_str())) {
      readyRtcp = true;
    } else {
      updateTransportState(TRANSPORT_FAILED);
    }
  }
  ELOG_DEBUG("%s - Ready? %d %d", transport_name.c_str(), readyRtp, readyRtcp);
  if (readyRtp && readyRtcp) {
    ELOG_DEBUG("%s - Ready!!!", transport_name.c_str());
    updateTransportState(TRANSPORT_READY);
  }

}
Example #4
0
	void fetch()
	{
		std::string a;
		std::set<std::string> tags,*ptags=0;
		std::string key;
		key.assign(data_in.begin(),data_in.end());
		if(hin.operations.fetch.transfer_triggers)
			ptags=&tags;
		uint64_t generation;
		time_t timeout;
		if(!cache.fetch(key,&a,ptags,&timeout,&generation)) {
			hout.opcode=opcodes::no_data;
			return;
		}
		if(hin.operations.fetch.transfer_if_not_uptodate 
			&& generation==hin.operations.fetch.current_gen)
		{
			hout.opcode=opcodes::uptodate;
			return;
		}
		hout.opcode=opcodes::data;
		data_out.swap(a);
		hout.operations.data.data_len=data_out.size();
		if(ptags) {
			for(std::set<std::string>::iterator p=tags.begin(),e=tags.end();p!=e;++p) {
				data_out.append(p->c_str(),p->size()+1);
			}
		}
		hout.operations.data.triggers_len=data_out.size()-hout.operations.data.data_len;
		hout.size=data_out.size();
		
		hout.operations.data.generation=generation;
		time_t now=time(0);
		hout.operations.data.timeout = timeout > now ? timeout - now : 0;
	}
Example #5
0
void Text::replaceAll(
    std::string &source, 
    const std::string &from, 
    const std::string &to)
{
    if (from.empty())
    {
        return;
    }

    std::string str;
    str.reserve(source.length());  // avoids a few memory allocations

    size_t lastPos = 0, findPos;

    while ((findPos = source.find(from, lastPos)) != std::string::npos)
    {
        str.append(source, lastPos, findPos - lastPos);
        str += to;
        lastPos = findPos + from.length();
    }

    // Care for the rest after last occurrence
    str += source.substr(lastPos);

    source.swap(str);
}
Example #6
0
// ////////////////////////////////////////////////////////////////////////////
bool DetermineFileInfo(const std::string &file_name,
	const std::string &file_info_name, WORD lang_code, WORD code_page,
	std::string &file_info_value, bool throw_if_not_found)
{
	VS_FIXEDFILEINFO  version_info;
	OS_VersionInfoSet string_map;

	OS_GetFileVersionInfo(file_name, lang_code, code_page, version_info,
		string_map);

	OS_VersionInfoSetIter iter_b(string_map.begin());
	OS_VersionInfoSetIter iter_e(string_map.end());

	for ( ; iter_b != iter_e; ++iter_b) {
		if (((!lang_code) || (lang_code == iter_b->lang_code_)) &&
			((!code_page) || (code_page == iter_b->code_page_)) &&
			(!stricmp(file_info_name.c_str(), iter_b->info_name_.c_str()))) {
			file_info_value.swap(
				const_cast<OS_VersionInfoKey *>(&(*iter_b))->info_value_);
			return(true);
		}
	}

	if (throw_if_not_found)
		MLB::Utility::ThrowException("Unable to locate file information name '" +
			file_info_name + "' in the file '" + file_name + "'.");

	return(false);
}
Example #7
0
void util::htmlspecialchars(std::string &str)
{
    std::string buf;
    buf.reserve(str.size());
    for (size_t pos = 0; pos != str.size(); ++pos)
    {
        switch (str[pos])
        {
        case '&':
            buf.append("&amp;");
            break;
        case '\"':
            buf.append("&quot;");
            break;
        case '\'':
            buf.append("&apos;");
            break;
        case '<':
            buf.append("&lt;");
            break;
        case '>':
            buf.append("&gt;");
            break;
        default:
            buf.append(&str[pos], 1);
            break;
        }
    }

    str.swap(buf);
}
void TypePrinter::printElaborated(const ElaboratedType *T, std::string &S) {
  std::string MyString;
  
  {
    llvm::raw_string_ostream OS(MyString);
    OS << TypeWithKeyword::getKeywordName(T->getKeyword());
    if (T->getKeyword() != ETK_None)
      OS << " ";
    NestedNameSpecifier* Qualifier = T->getQualifier();
    if (Qualifier)
      Qualifier->print(OS, Policy);
  }
  
  std::string TypeStr;
  PrintingPolicy InnerPolicy(Policy);
  InnerPolicy.SuppressTagKeyword = true;
  InnerPolicy.SuppressScope = true;
  TypePrinter(InnerPolicy).print(T->getNamedType(), TypeStr);
  
  MyString += TypeStr;
  if (S.empty())
    S.swap(MyString);
  else
    S = MyString + ' ' + S;  
}
static void
generateData(CMistTGroup & tGroup, const TMistParameters & parameters,
    std::string& result)
{
    if (mist_tg_clear_values(&tGroup) != MIST_OK 
        || mist_tg_set_values(&tGroup, 
                &parameters[0], parameters.size()) != MIST_OK)
    {
        throw CGenerator::CGeneratorError(errSetValuesFailed);
    }

    const char** presult;
    size_t nvals;
    
    if (mist_tg_evaluate(&tGroup, &presult, &nvals) != MIST_OK) {
        throw CGenerator::CGeneratorError(errGenFailed);
    }
    assert(nvals != 0);
    
    if (nvals > 1) {
        throw CGenerator::CGeneratorError(errMultivaluedMain);
    }
    
    string s = presult[0];
    result.swap(s);
    return;
}
Example #10
0
/**
 * Returns the row/column where the error occured, as well as the current and previous
 * lines for printing some context.
 */
static void get_error_line_column(const char *begin, const char *end, const char *position,
        std::string& out_line_prev, std::string& out_line_cur, int& out_line, int& out_column)
{
    out_line_prev = "";
    out_line_cur = "";
    out_line = 1;
    while (begin < end) {
        const char *line_end = (const char *)memchr(begin, '\n', end - begin);
        out_line_prev.swap(out_line_cur);
        // If no \n was found
        if (line_end == NULL) {
            out_column = int(position - begin + 1);
            out_line_cur = string(begin, end);
            return;
        } else {
            out_line_cur = string(begin, line_end);
            ++line_end;
            if (position < line_end) {
                out_column = int(position - begin + 1);
                return;
            }
        }
        begin = line_end;
        ++out_line;
    }

    throw runtime_error("Cannot get line number of error, its position is out of range");
}
Example #11
0
// ////////////////////////////////////////////////////////////////////////////
bool GetLbmConfigFileFromCmdLine(unsigned int &current_index, int argc,
                                 char **argv, std::string &out_datum, bool require_existence)
{
    std::string tmp_datum;

    if (!MLB::Utility::ParseCmdLineArg::ParseCmdLineFollowingSpec(
                MLB::Utility::MakeInlineVector<std::string>
                ("-LBM_CONFIGURATION_FILE")
                ("-LBM_CONFIGURATIONFILE")
                ("-LBMCONFIGURATION_FILE")
                ("-LBMCONFIGURATIONFILE")
                ("-LBM_CONFIG_FILE")
                ("-LBM_CONFIGFILE")
                ("-LBMCONFIG_FILE")
                ("-LBMCONFIGFILE")
                ("-LBM_CFG_FILE")
                ("-LBM_CFGFILE")
                ("-LBMCFG_FILE")
                ("-LBMCFGFILE")
                ("-LBM_CONFIGURATION")
                ("-LBMCONFIGURATION")
                ("-LBM_CONFIG")
                ("-LBMCONFIG")
                ("-LBM_CFG")
                ("-LBMCFG"),
                current_index, argc, argv, tmp_datum))
        return(false);

    MLB::Utility::ParseCmdLineArg::CheckFilePath("LBM configuration file name",
            tmp_datum, "", require_existence);

    out_datum.swap(tmp_datum);

    return(true);
}
Example #12
0
bool
SecTpm::getImpExpPassWord(std::string& password, const std::string& prompt)
{
  bool isInitialized = false;

#ifdef NDN_CXX_HAVE_GETPASS
  char* pw0 = nullptr;

  pw0 = getpass(prompt.c_str());
  if (pw0 == nullptr)
    return false;
  std::string password1 = pw0;
  memset(pw0, 0, strlen(pw0));

  pw0 = getpass("Confirm:");
  if (pw0 == nullptr) {
    std::fill(password1.begin(), password1.end(), 0);
    return false;
  }

  if (password1.compare(pw0) == 0) {
    isInitialized = true;
    password.swap(password1);
  }

  std::fill(password1.begin(), password1.end(), 0);
  memset(pw0, 0, strlen(pw0));

  if (password.empty())
    return false;

#endif // NDN_CXX_HAVE_GETPASS

  return isInitialized;
}
Example #13
0
static int strHex2Digit( std::string &strHex )
{
    int iLength = strHex.length();
    if( iLength % 2 != 0 )
        return -1;
    
    std::string strTemp;
    char        chDigit;
    
    int iLoop = iLength / 2;
    for( int i = 0; i < iLoop; i++ )
    {
        if( strHex[ i * 2 ] >= 'a' )    // 输入的十六进制串需要是小写字母
            chDigit = strHex[ i * 2 ] - 'a' + 10;
        else
            chDigit = strHex[ i * 2 ] - '0';
        
        chDigit *= 16;
        
        if( strHex[ i * 2 + 1 ] >= 'a' )    // 输入的十六进制串需要是小写字母
            chDigit += strHex[ i * 2 + 1 ] - 'a' + 10;
        else
            chDigit += strHex[ i * 2 + 1 ] - '0';
        
        strTemp.append( 1, chDigit );
    }
    
    strHex.swap( strTemp );
    return 0;
}
Example #14
0
void DtlsTransport::onHandshakeCompleted(DtlsSocketContext *ctx, std::string clientKey, std::string serverKey,
                                         std::string srtp_profile) {
  boost::mutex::scoped_lock lock(sessionMutex_);
  std::string temp;

  if (isServer_) {  // If we are server, we swap the keys
    ELOG_DEBUG("%s message: swapping keys, isServer: %d", toLog(), isServer_);
    clientKey.swap(serverKey);
  }
  if (ctx == dtlsRtp.get()) {
    srtp_.reset(new SrtpChannel());
    if (srtp_->setRtpParams(clientKey, serverKey)) {
      readyRtp = true;
    } else {
      updateTransportState(TRANSPORT_FAILED);
    }
    if (dtlsRtcp == NULL) {
      readyRtcp = true;
    }
  }
  if (ctx == dtlsRtcp.get()) {
    srtcp_.reset(new SrtpChannel());
    if (srtcp_->setRtpParams(clientKey, serverKey)) {
      readyRtcp = true;
    } else {
      updateTransportState(TRANSPORT_FAILED);
    }
  }
  ELOG_DEBUG("%s message:HandShakeCompleted, transportName:%s, readyRtp:%d, readyRtcp:%d",
             toLog(), transport_name.c_str(), readyRtp, readyRtcp);
  if (readyRtp && readyRtcp) {
    updateTransportState(TRANSPORT_READY);
  }
}
void TypePrinter::printDependentTemplateSpecialization(
        const DependentTemplateSpecializationType *T, std::string &S) { 
  IncludeStrongLifetimeRAII Strong(Policy);
  std::string MyString;
  {
    llvm::raw_string_ostream OS(MyString);
  
    OS << TypeWithKeyword::getKeywordName(T->getKeyword());
    if (T->getKeyword() != ETK_None)
      OS << " ";
    
    if (T->getQualifier())
      T->getQualifier()->print(OS, Policy);    
    OS << T->getIdentifier()->getName();
    OS << TemplateSpecializationType::PrintTemplateArgumentList(
                                                            T->getArgs(),
                                                            T->getNumArgs(),
                                                            Policy);
  }
  
  if (S.empty())
    S.swap(MyString);
  else
    S = MyString + ' ' + S;
}
Example #16
0
bool PublicKey::encrypt(std::string& dataInOut) const
{
    std::string cipherText;
    if (!_impl->encrypt<CryptoPP::StringSource, CryptoPP::StringSink>(dataInOut, cipherText))
        return false;
    dataInOut.swap(cipherText);
    return true;
}
Example #17
0
void Type::getAsStringInternal(const Type *ty, std::string &buffer/*,
                               const PrintingPolicy &policy*/) {
  SmallString<256> Buf;
  llvm::raw_svector_ostream StrOS(Buf);
  TypePrinter(/*policy*/).print(ty, StrOS, buffer);
  std::string str = StrOS.str();
  buffer.swap(str);
}
Example #18
0
bool PrivateKey::decrypt(std::string &dataInOut) const
{
    std::string plainText;
    if (!_impl->decrypt<CryptoPP::StringSource, CryptoPP::StringSink>(dataInOut, plainText))
        return false;
    dataInOut.swap(plainText);
    return true;
}
Example #19
0
	void toUtf8(std::string& str) const
	{
		const size_t size = str.size();
		std::string out(size * 2, '\0');
		for (size_t i = 0; i < size; i++) {
			out[i * 2] = str[i];
		}
		str.swap(out);
	}
Example #20
0
void read_member<std::string>(std::string& t, std::istream& in) {
    std::string::size_type size;
    read_member(size, in);
    char* buf = new char[size];
    in.read(buf, size);
    std::string temp(buf, size);
    delete [] buf;
    t.swap(temp);
}
Example #21
0
bool
IOChannel::GetCommandFromQueue (std::string &cmd)
{
    if (m_command_queue.empty())
        return false;
    cmd.swap(m_command_queue.front());
    m_command_queue.pop ();
    return true;
}
void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
                                   std::string &buffer,
                                   const PrintingPolicy &policy) {
  SmallString<256> Buf;
  llvm::raw_svector_ostream StrOS(Buf);
  TypePrinter(policy).print(ty, qs, StrOS, buffer);
  std::string str = StrOS.str();
  buffer.swap(str);
}
Example #23
0
	void SetPolicy(const std::string& newhost, unsigned long duration, unsigned int port, bool preload)
	{
		// To enforce an STS upgrade policy, servers MUST send this key to insecurely connected clients. Servers
		// MAY send this key to securely connected clients, but it will be ignored.
		std::string newplaintextpolicy("port=");
		newplaintextpolicy.append(ConvToStr(port));

		// To enforce an STS persistence policy, servers MUST send this key to securely connected clients. Servers
		// MAY send this key to all clients, but insecurely connected clients MUST ignore it.
		std::string newsecurepolicy("duration=");
		newsecurepolicy.append(ConvToStr(duration));

		// Servers MAY send this key to all clients, but insecurely connected clients MUST ignore it.
		if (preload)
			newsecurepolicy.append(",preload");

		// Apply the new policy.
		bool changed = false;
		if (!irc::equals(host, newhost))
		{
			ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Changing STS SNI hostname from \"%s\" to \"%s\"", host.c_str(), newhost.c_str());
			host = newhost;
			changed = true;
		}

		if (plaintextpolicy != newplaintextpolicy)
		{
			ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Changing plaintext STS policy from \"%s\" to \"%s\"", plaintextpolicy.c_str(), newplaintextpolicy.c_str());
			plaintextpolicy.swap(newplaintextpolicy);
			changed = true;
		}

		if (securepolicy != newsecurepolicy)
		{
			ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Changing secure STS policy from \"%s\" to \"%s\"", securepolicy.c_str(), newsecurepolicy.c_str());
			securepolicy.swap(newsecurepolicy);
			changed = true;
		}

		// If the policy has changed then notify all clients via cap-notify.
		if (changed)
			NotifyValueChange();
	}
Example #24
0
		void swap(data &other)
		{
			expression.swap(other.expression);
			std::swap(flags,	other.flags);
			std::swap(re,		other.re);
			std::swap(are,		other.are);
			std::swap(re_size,	other.re_size);
			std::swap(are_size,	other.are_size);
			std::swap(match_size,	other.match_size);
		}
Example #25
0
	//! This is fundamental to avoid crash, otherwise
	// we copy pointer and we do double delete
	my_struct & operator=(my_struct && my)
	{
		size = my.size;
		my.size = 0;
		str.swap(my.str);
		v.swap(my.v);
		ptr = my.ptr;
		my.ptr = 0;

		return *this;
	}
Example #26
0
FileError FileManager::Load(const std::string &url, std::string &data) {

	
  if(IsLocal(url))
    {
      std::ifstream fin(url.c_str());


      if(fin.is_open()) {

	int length;
	char * buffer;

	// get length of file:
	fin.seekg (0, ios::end);
	length = fin.tellg();
	fin.seekg (0, ios::beg);

	// allocate memory:
	buffer = new char [length];
	memset(buffer,0,length);

	// read data as a block:
	fin.read (buffer,length);
	fin.close();

	std::string temp(buffer,&buffer[length]);
	if (buffer)
	  {
	    delete[] buffer;
	    buffer = NULL;
	  }

	data.swap(temp);

	return FILEOK;
      }
      else return FILENOTFOUND;
    }
  else
    {

      //this is for remote access
      std::string proxy = "";
      bool isSSLAddress = false;
      bool result = GetMap(url, isSSLAddress, data, proxy);
		
      if(result) return FILEOK;
      else return FILENOTFOUND; //return (int)data.size();
    }
}
Example #27
0
bool
getPassword(std::string& password, const std::string& prompt, bool shouldConfirm)
{
#ifdef NDN_CXX_HAVE_GETPASS
  char* pw0 = getpass(prompt.c_str());
  if (!pw0 || strlen(pw0) == 0) {
    return false;
  }
  std::string password1 = pw0;
  OPENSSL_cleanse(pw0, strlen(pw0));

  if (!shouldConfirm) {
    password.swap(password1);
    return true;
  }

  pw0 = getpass("Confirm: ");
  if (!pw0) {
    OPENSSL_cleanse(&password1.front(), password1.size());
    return false;
  }

  bool isReady = false;
  if (password1.size() == strlen(pw0) &&
      CRYPTO_memcmp(password1.data(), pw0, password1.size()) == 0) {
    isReady = true;
    password.swap(password1);
  }
  else {
    OPENSSL_cleanse(&password1.front(), password1.size());
  }
  OPENSSL_cleanse(pw0, strlen(pw0));

  return isReady;
#else
  return false;
#endif // NDN_CXX_HAVE_GETPASS
}
Example #28
0
void BfcpService::handleGetConferenceInfoResult(std::string &info, 
                                                bfcp::ControlError error, 
                                                void *data)
{
  muduo::MutexLockGuard lock(mutex_);
  error_ = error;
  callFinished_ = true;
  if (data)
  {
    bfcp::string *res = static_cast<bfcp::string*>(data);
    info.swap(*res);
  }
  cond_.notify();
}
void HTMLEncode(std::string& data) {
    std::string buffer;
    buffer.reserve((int)(data.size()*1.1));
    for(size_t pos = 0; pos != data.size(); ++pos) {
        switch(data[pos]) {
            case '&':  buffer.append("&amp;");       break;
            case '\"': buffer.append("&quot;");      break;
            case '\'': buffer.append("&apos;");      break;
            case '<':  buffer.append("&lt;");        break;
            case '>':  buffer.append("&gt;");        break;
            default:   buffer.append(1, data[pos]); break;
        }
    }
    data.swap(buffer);
}
Example #30
0
void NxsString::add_nxs_quotes(std::string &s)
	{
	std::string withQuotes;
	unsigned len = (unsigned)s.length();
	withQuotes.reserve(len + 4);
	withQuotes.append(1,'\'');
	for (std::string::const_iterator sIt = s.begin(); sIt != s.end(); sIt++)
		{
		withQuotes.append(1, *sIt);
		if (*sIt == '\'')
			withQuotes.append(1,'\'');
		}
	withQuotes.append(1,'\'');
	s.swap(withQuotes);
	}