コード例 #1
0
void
Manifest::addKeyValuePair(const uint8_t* key, size_t keySize, const uint8_t* value, size_t valueSize)
{
    std::string keyS(reinterpret_cast<const char*>(key), keySize);
    std::string valueS(reinterpret_cast<const char*>(value), valueSize);
    addKeyValuePair(keyS, valueS);
}
コード例 #2
0
bool DBBComServer::postNotification(const std::string& payload)
{
    if (channelID.empty())
        return false;

    DBBNetThread *postThread = DBBNetThread::DetachThread();
    postThread->currentThread = std::thread([this, postThread, payload]() {
        std::string response;
        long httpStatusCode;
        UniValue jsonOut;

        response = "";
        httpStatusCode = 0;

        // encrypt the payload
        std::string encryptedPayload;
        std::string keyS(encryptionKey.begin(), encryptionKey.end());
        DBB::encryptAndEncodeCommand(payload, keyS, encryptedPayload, false);
        // mem-cleanse the key
        std::fill(keyS.begin(), keyS.end(), 0);
        keyS.clear();

        // send the payload
        SendRequest("post", comServerURL, "c=data&s="+std::to_string(nSequence)+"&uuid="+channelID+"&dt=0&pl="+encryptedPayload, response, httpStatusCode);
        nSequence++; // increase the sequence number

        // ignore the response for now
        postThread->completed();
    });

    return true;
}
コード例 #3
0
ファイル: GuidoCreator.cpp プロジェクト: anttirt/guidolib
void CGuidoCreator::empty(int numerator, int denominator,int dots)
{
	clefS();
	keyS();
	meterS();
	fprintf(file,"empty");
	if(  (numerator!=lastNoteNumerator) || (denominator!=lastNoteDenominator) || (dots!=lastNoteDots) ){
		fprintf(file,"*%i/%i",numerator,denominator);
		lastNoteDenominator=denominator;
		lastNoteNumerator=numerator;
		lastNoteDots=dots;
	}
	for(int i=0;i<dots;i++){fprintf(file,".");}
	fprintf(file," ");
}
コード例 #4
0
ファイル: GuidoCreator.cpp プロジェクト: anttirt/guidolib
void CGuidoCreator::note(char pitch, int chromatic, int octave, int durNumerator, int durDenominator, int dispNumerator, int dispDenominator, int dispDots)
{
	clefS();
	keyS();
	meterS();
	//calculate durations
	float realDuration= (float(durNumerator))/(float(durDenominator));
	float dispDuration= (float(dispNumerator))/(float(dispDenominator));
	if(dispDots==1){dispDuration*=1.5;}
	if(dispDots==2){dispDuration*=1.75;}

	//now we can decide, how the note tag is created
	if(realDuration==dispDuration){
		//the printed duration is the real duration:
		note(pitch,chromatic,octave,dispNumerator,dispDenominator,dispDots);
	} else {
		//the printed duration differs from the real duratioon
		fprintf(file,"\\dispDur<%i,%i,%i>( ",dispNumerator,dispDenominator,dispDots);
		note(pitch,chromatic,octave,durNumerator,durDenominator,0);
		fprintf(file,") ");
	}
}//note
コード例 #5
0
ファイル: GuidoCreator.cpp プロジェクト: anttirt/guidolib
void CGuidoCreator::note(char pitch, int chromatic, int octave, int numerator, int denominator, int dots)
{
	clefS();
	keyS();
	meterS();
	if(inChord){
		notesInChord++;
		if(notesInChord>1){
			fprintf(file,",");
		}
	}

	if(pitch=='_'){
		fprintf(file,"_");
	} else {
		fprintf(file,"%c",pitch);
		switch(chromatic){
		case -2:fprintf(file,"&&");break;
		case -1:fprintf(file,"&"); break;
		case  1:fprintf(file,"#"); break;
		case  2:fprintf(file,"##");break;
		}
		if(lastNoteOctave!=octave){
			fprintf(file,"%i",octave);
			lastNoteOctave=octave;
		}
	}
	if(  (numerator!=lastNoteNumerator) || (denominator!=lastNoteDenominator) || (dots!=lastNoteDots) ){
		fprintf(file,"*%i/%i",numerator,denominator);
		lastNoteDenominator=denominator;
		lastNoteNumerator=numerator;
		lastNoteDots=dots;
	}
	for(int i=0;i<dots;i++){fprintf(file,".");}
	fprintf(file," ");
}//note
コード例 #6
0
void DBBComServer::startLongPollThread()
{
    std::unique_lock<std::mutex> lock(cs_com);

    if (longPollThread)
        return;

    longPollThread = DBBNetThread::DetachThread();
    longPollThread->currentThread = std::thread([this]() {
        std::string response;
        long httpStatusCode;
        long sequence = 0;
        int errorCounts = 0;
        UniValue jsonOut;

        while(1)
        {
            response = "";
            httpStatusCode = 400;
            {
                // we store the channel ID to detect channelID changes during long poll 
                std::unique_lock<std::mutex> lock(cs_com);
                currentLongPollChannelID = channelID;
                currentLongPollURL = comServerURL;
            }
            SendRequest("post", currentLongPollURL, "c=gd&uuid="+currentLongPollChannelID+"&dt=0&s="+std::to_string(sequence), response, httpStatusCode);
            sequence++;

            if (httpStatusCode >= 300)
            {
                errorCounts++;
                if (errorCounts > 5)
                {
                    DBB::LogPrintDebug("Error, can't connect to the smart verification server");
                    // wait 10 seconds before the next try
                    std::this_thread::sleep_for(std::chrono::milliseconds(10000));
                }
                else
                    std::this_thread::sleep_for(std::chrono::milliseconds(2000));
            }
            else
                errorCounts = 0;

            // ignore the response if the channel has been switched (re-pairing)
            {
                std::unique_lock<std::mutex> lock(cs_com);
                if (currentLongPollChannelID != channelID || currentLongPollURL != comServerURL)
                    continue;
            }

            jsonOut.read(response);
            if (jsonOut.isObject())
            {
                UniValue data = find_value(jsonOut, "data");
                if (data.isArray())
                {
                    for (const UniValue& element : data.getValues())
                    {
                        UniValue payload = find_value(element, "payload");
                        if (payload.isStr())
                        {
                            std::string plaintextPayload;
                            std::string keyS(encryptionKey.begin(), encryptionKey.end());
                            if (DBB::decryptAndDecodeCommand(payload.get_str(), keyS, plaintextPayload, false))
                            {
                                std::unique_lock<std::mutex> lock(cs_com);
                                if (parseMessageCB)
                                    parseMessageCB(this, plaintextPayload, ctx);
                            }

                            // mem-cleanse the key
                            std::fill(keyS.begin(), keyS.end(), 0);
                            keyS.clear();
                        }
                    }
                }
            }
        }
        std::unique_lock<std::mutex> lock(cs_com);
        longPollThread->completed();
    });
}